Skip to content

[EEPROM] Wrong E2END definition #400

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 4, 2019
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
8 changes: 4 additions & 4 deletions cores/arduino/stm32/stm32_eeprom.c
Original file line number Diff line number Diff line change
@@ -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)
@@ -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);
}

/**
@@ -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) {
@@ -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;
2 changes: 1 addition & 1 deletion cores/arduino/stm32/stm32_eeprom.h
Original file line number Diff line number Diff line change
@@ -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 ------------------------------------------------------- */
2 changes: 1 addition & 1 deletion libraries/EEPROM/src/EEPROM.h
Original file line number Diff line number Diff line change
@@ -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 ){