Skip to content

Commit

Permalink
stm32: use consistent and correct database size everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
paradajz committed Mar 10, 2021
1 parent 0b42303 commit ed180b9
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 17 deletions.
3 changes: 2 additions & 1 deletion src/board/stm32/common/NVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion src/flashgen/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 3 additions & 10 deletions tests/Defines.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions tests/Sources.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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"./" \
Expand Down
5 changes: 5 additions & 0 deletions tests/stubs/database/DB_ReadWrite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 8 additions & 5 deletions tests/stubs/database/DB_ReadWrite.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include <string.h>
#include "dbms/src/LESSDB.h"
#include "EmuEEPROM/src/EmuEEPROM.h"
#include "board/Board.h"
#include "board/Internal.h"

class DBstorageMock : public LESSDB::StorageAccess
{
Expand Down Expand Up @@ -33,6 +35,7 @@ class DBstorageMock : public LESSDB::StorageAccess

bool init() override
{
pageArray.resize(pageSize() * 2, 0xFF);
return true;
}

Expand All @@ -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;
}
Expand Down Expand Up @@ -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<uint8_t> pageArray;
};

EmuEEPROMStorageAccess storageMock;
Expand Down

0 comments on commit ed180b9

Please sign in to comment.