From ed180b9ab0001b36cce8da19698f725ecd562157 Mon Sep 17 00:00:00 2001 From: paradajz <2544094+paradajz@users.noreply.github.com> Date: Wed, 10 Mar 2021 19:14:52 +0100 Subject: [PATCH] stm32: use consistent and correct database size everywhere --- src/board/stm32/common/NVM.cpp | 3 ++- src/flashgen/main.cpp | 3 ++- tests/Defines.mk | 13 +++---------- tests/Sources.mk | 4 ++++ tests/stubs/database/DB_ReadWrite.cpp | 5 +++++ tests/stubs/database/DB_ReadWrite.h | 13 ++++++++----- 6 files changed, 24 insertions(+), 17 deletions(-) diff --git a/src/board/stm32/common/NVM.cpp b/src/board/stm32/common/NVM.cpp index 432d26b99..8bc800904 100644 --- a/src/board/stm32/common/NVM.cpp +++ b/src/board/stm32/common/NVM.cpp @@ -119,7 +119,8 @@ namespace Board uint32_t size() { - return stm32EEPROM.pageSize(); + //first 4 bytes are reserved for page status + return stm32EEPROM.pageSize() - 4; } bool read(uint32_t address, int32_t& value, parameterType_t type) diff --git a/src/flashgen/main.cpp b/src/flashgen/main.cpp index fbde94e0b..a2614c7e7 100644 --- a/src/flashgen/main.cpp +++ b/src/flashgen/main.cpp @@ -219,7 +219,8 @@ namespace uint32_t size() override { - return emuEEPROMstorage.pageSize(); + //first 4 bytes are reserved for page status + return emuEEPROMstorage.pageSize() - 4; } bool clear() override diff --git a/tests/Defines.mk b/tests/Defines.mk index 07f6406d3..08f982177 100644 --- a/tests/Defines.mk +++ b/tests/Defines.mk @@ -6,22 +6,15 @@ DEFINES += TEST include ../src/Defines.mk -#db size is determined in run time in application firmware, for -#test purposes hardcode it +#needed for AVR only since this info is normally pulled from AVR headers +#which aren't present in tests +#for stm32 this is determined in runtime ifeq ($(MCU),at90usb1286) DATABASE_SIZE := 4093 else ifeq ($(MCU),atmega16u2) DATABASE_SIZE := 509 else ifeq ($(MCU),atmega2560) DATABASE_SIZE := 4093 -else ifeq ($(MCU),stm32f405rg) - DATABASE_SIZE := 131068 -else ifeq ($(MCU),stm32f407vg) - DATABASE_SIZE := 131068 -else ifeq ($(MCU),stm32f401ce) - DATABASE_SIZE := 65536 -else ifeq ($(MCU),stm32f411ce) - DATABASE_SIZE := 65536 endif ifeq ($(ARCH), stm32) diff --git a/tests/Sources.mk b/tests/Sources.mk index 54582a5a1..749d5eb00 100644 --- a/tests/Sources.mk +++ b/tests/Sources.mk @@ -22,6 +22,10 @@ modules/u8g2/csrc/u8x8_gpio.c \ modules/u8g2/csrc/u8x8_d_ssd1306_128x64_noname.c \ modules/u8g2/csrc/u8x8_d_ssd1306_128x32.c +ifeq ($(ARCH),stm32) + SOURCES_COMMON += board/$(ARCH)/variants/$(MCU_FAMILY)/$(MCU)/FlashPages.cpp +endif + #common include dirs INCLUDE_DIRS_COMMON := \ -I"./" \ diff --git a/tests/stubs/database/DB_ReadWrite.cpp b/tests/stubs/database/DB_ReadWrite.cpp index d03f87580..aa949572d 100644 --- a/tests/stubs/database/DB_ReadWrite.cpp +++ b/tests/stubs/database/DB_ReadWrite.cpp @@ -3,7 +3,12 @@ uint32_t DBstorageMock::size() { +#ifdef STM32_EMU_EEPROM + //first 4 bytes are reserved for page status + return storageMock.pageSize() - 4; +#else return DATABASE_SIZE; +#endif } size_t DBstorageMock::paramUsage(LESSDB::sectionParameterType_t type) diff --git a/tests/stubs/database/DB_ReadWrite.h b/tests/stubs/database/DB_ReadWrite.h index 5ad454f8e..9070ef6f4 100644 --- a/tests/stubs/database/DB_ReadWrite.h +++ b/tests/stubs/database/DB_ReadWrite.h @@ -4,6 +4,8 @@ #include #include "dbms/src/LESSDB.h" #include "EmuEEPROM/src/EmuEEPROM.h" +#include "board/Board.h" +#include "board/Internal.h" class DBstorageMock : public LESSDB::StorageAccess { @@ -33,6 +35,7 @@ class DBstorageMock : public LESSDB::StorageAccess bool init() override { + pageArray.resize(pageSize() * 2, 0xFF); return true; } @@ -41,15 +44,15 @@ class DBstorageMock : public LESSDB::StorageAccess if (page == EmuEEPROM::page_t::page1) return 0; else - return DATABASE_SIZE; + return pageSize(); } bool erasePage(EmuEEPROM::page_t page) override { if (page == EmuEEPROM::page_t::page1) - memset(pageArray, 0xFF, DATABASE_SIZE); + std::fill(pageArray.begin(), pageArray.end() - pageSize(), 0xFF); else - memset(&pageArray[DATABASE_SIZE], 0xFF, DATABASE_SIZE); + std::fill(pageArray.begin() + pageSize(), pageArray.end(), 0xFF); return true; } @@ -96,11 +99,11 @@ class DBstorageMock : public LESSDB::StorageAccess uint32_t pageSize() override { - return DATABASE_SIZE; + return Board::detail::map::flashPageDescriptor(Board::detail::map::eepromFlashPage1()).size; } private: - uint8_t pageArray[DATABASE_SIZE * 2]; + std::vector pageArray; }; EmuEEPROMStorageAccess storageMock;