@@ -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 */
183183void 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 ;
0 commit comments