Skip to content
Merged
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions cores/arduino/stm32/stm32_eeprom.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ static inline uint32_t get_flash_end(void) {
#endif
#endif /* FLASH_BASE_ADDRESS */

static uint8_t eeprom_buffer[E2END] = {0};
static uint8_t eeprom_buffer[E2END + 1] = {0};

/**
* @brief Function reads a byte from emulated eeprom (flash)
Expand Down Expand Up @@ -181,7 +181,7 @@ void eeprom_buffered_write_byte(uint32_t pos, uint8_t value) {
* @retval none
*/
void eeprom_buffer_fill(void) {
memcpy(eeprom_buffer, (uint8_t*)(FLASH_BASE_ADDRESS), E2END);
memcpy(eeprom_buffer, (uint8_t*)(FLASH_BASE_ADDRESS), E2END + 1);
}

/**
Expand Down Expand Up @@ -230,7 +230,7 @@ void eeprom_buffer_flush(void) {
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP|FLASH_FLAG_WRPERR|FLASH_FLAG_PGERR);
#endif
if(HAL_FLASHEx_Erase(&EraseInitStruct, &pageError) == HAL_OK) {
while(address < address_end) {
while(address <= address_end) {
#if defined(STM32L0xx) || defined(STM32L1xx)
memcpy(&data, eeprom_buffer + offset, sizeof(uint32_t));
if(HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, address, data) == HAL_OK) {
Expand Down Expand Up @@ -263,7 +263,7 @@ void eeprom_buffer_flush(void) {
HAL_FLASH_Unlock();

if(HAL_FLASHEx_Erase(&EraseInitStruct, &SectorError) == HAL_OK) {
while(address < address_end) {
while(address <= address_end) {
memcpy(&data, eeprom_buffer + offset, sizeof(uint32_t));
if(HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, address, data) == HAL_OK) {
address += 4;
Expand Down
2 changes: 1 addition & 1 deletion cores/arduino/stm32/stm32_eeprom.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
*/
#define FLASH_PAGE_SIZE ((uint32_t)(16*1024)) /* 16kB page */
#endif
#define E2END FLASH_PAGE_SIZE
#define E2END (FLASH_PAGE_SIZE - 1)

/* Exported macro ------------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */
Expand Down
2 changes: 1 addition & 1 deletion libraries/EEPROM/src/EEPROM.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ struct EEPROMClass{
//STL and C++11 iteration capability.
EEPtr begin() { return 0x00; }
EEPtr end() { return length(); } //Standards requires this to be the item after the last valid entry. The returned pointer is invalid.
uint16_t length() { return E2END; }
uint16_t length() { return E2END + 1; }

//Functionality to 'get' and 'put' objects to and from EEPROM.
template< typename T > T &get( int idx, T &t ){
Expand Down