Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/stm32_platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ void Stm32Platform::restart()

uint8_t* Stm32Platform::getEepromBuffer(uint32_t size)
{
#if !defined(DATA_EEPROM_BASE)
// check if the buffer already exists
if (_eepromPtr == nullptr) // we need to initialize the buffer first
{
Expand All @@ -51,12 +52,32 @@ uint8_t* Stm32Platform::getEepromBuffer(uint32_t size)
for (uint16_t i = 0; i < size; ++i)
_eepromPtr[i] = eeprom_buffered_read_byte(i);
}
#else

if (_eepromPtr == nullptr) // we need to initialize the buffer first
{
if (size > E2END + 1)
{
fatalError();
}

_eepromSize = size;

_eepromPtr = new uint8_t[size];

for (uint16_t i = 0; i < size; ++i)
_eepromPtr[i] = EEPROM.read(i);
}

#endif

return _eepromPtr;
}

void Stm32Platform::commitToEeprom()
{
#if !defined(DATA_EEPROM_BASE)

if (_eepromPtr == nullptr || _eepromSize == 0)
return;

Expand All @@ -69,6 +90,16 @@ void Stm32Platform::commitToEeprom()
// does nothing.
HAL_FLASH_Unlock();
eeprom_buffer_flush();

#else

if (_eepromPtr == nullptr || _eepromSize == 0)
return;

for (uint16_t i = 0; i < _eepromSize; ++i)
EEPROM.write(i, _eepromPtr[i]);

#endif
}

#endif
Loading