Skip to content

Commit 5cc5415

Browse files
authored
Merge pull request #400 from fpistm/E2END
[EEPROM] Wrong E2END definition
2 parents 7b48eff + 93c5d89 commit 5cc5415

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

Diff for: cores/arduino/stm32/stm32_eeprom.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ static inline uint32_t get_flash_end(void) {
133133
#endif
134134
#endif /* FLASH_BASE_ADDRESS */
135135

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

138138
/**
139139
* @brief Function reads a byte from emulated eeprom (flash)
@@ -181,7 +181,7 @@ void eeprom_buffered_write_byte(uint32_t pos, uint8_t value) {
181181
* @retval none
182182
*/
183183
void eeprom_buffer_fill(void) {
184-
memcpy(eeprom_buffer, (uint8_t*)(FLASH_BASE_ADDRESS), E2END);
184+
memcpy(eeprom_buffer, (uint8_t*)(FLASH_BASE_ADDRESS), E2END + 1);
185185
}
186186

187187
/**
@@ -230,7 +230,7 @@ void eeprom_buffer_flush(void) {
230230
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP|FLASH_FLAG_WRPERR|FLASH_FLAG_PGERR);
231231
#endif
232232
if(HAL_FLASHEx_Erase(&EraseInitStruct, &pageError) == HAL_OK) {
233-
while(address < address_end) {
233+
while(address <= address_end) {
234234
#if defined(STM32L0xx) || defined(STM32L1xx)
235235
memcpy(&data, eeprom_buffer + offset, sizeof(uint32_t));
236236
if(HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, address, data) == HAL_OK) {
@@ -263,7 +263,7 @@ void eeprom_buffer_flush(void) {
263263
HAL_FLASH_Unlock();
264264

265265
if(HAL_FLASHEx_Erase(&EraseInitStruct, &SectorError) == HAL_OK) {
266-
while(address < address_end) {
266+
while(address <= address_end) {
267267
memcpy(&data, eeprom_buffer + offset, sizeof(uint32_t));
268268
if(HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, address, data) == HAL_OK) {
269269
address += 4;

Diff for: cores/arduino/stm32/stm32_eeprom.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
*/
5656
#define FLASH_PAGE_SIZE ((uint32_t)(16*1024)) /* 16kB page */
5757
#endif
58-
#define E2END FLASH_PAGE_SIZE
58+
#define E2END (FLASH_PAGE_SIZE - 1)
5959

6060
/* Exported macro ------------------------------------------------------------*/
6161
/* Exported functions ------------------------------------------------------- */

Diff for: libraries/EEPROM/src/EEPROM.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ struct EEPROMClass{
122122
//STL and C++11 iteration capability.
123123
EEPtr begin() { return 0x00; }
124124
EEPtr end() { return length(); } //Standards requires this to be the item after the last valid entry. The returned pointer is invalid.
125-
uint16_t length() { return E2END; }
125+
uint16_t length() { return E2END + 1; }
126126

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

0 commit comments

Comments
 (0)