@@ -42,8 +42,8 @@ extern "C" {
4242/* Be able to change FLASH_BANK_NUMBER to use if relevant */
4343#if !defined(FLASH_BANK_NUMBER ) && \
4444 (defined(STM32F0xx ) || defined(STM32F1xx ) || defined(STM32G4xx ) || \
45- defined(STM32H7xx ) || defined(STM32L1xx ) || defined( STM32L4xx ))
46- /* Fo STM32F0xx, FLASH_BANK_1 is not defined only FLASH_BANK1_END is defined */
45+ defined(STM32H7xx ) || defined(STM32L4xx ))
46+ /* For STM32F0xx, FLASH_BANK_1 is not defined only FLASH_BANK1_END is defined */
4747#if defined(STM32F0xx )
4848#define FLASH_BANK_1 1U
4949#endif
@@ -58,7 +58,7 @@ extern "C" {
5858#endif /* !FLASH_BANK_NUMBER */
5959
6060/* Be able to change FLASH_DATA_SECTOR to use if relevant */
61- #if defined(STM32F2xx ) || defined(STM32F4xx ) || defined(STM32F7xx ) || \
61+ #if defined(STM32F2xx ) || defined(STM32F4xx ) || defined(STM32F7xx ) || \
6262 defined(STM32H7xx )
6363#if !defined(FLASH_DATA_SECTOR )
6464#define FLASH_DATA_SECTOR ((uint32_t)(FLASH_SECTOR_TOTAL - 1))
@@ -77,8 +77,8 @@ extern "C" {
7777#endif /* !FLASH_PAGE_NUMBER */
7878
7979/* Be able to change FLASH_END to use */
80- #if !defined(FLASH_END ) && !defined( STM32L0xx )
81- #if defined (STM32F0xx ) || defined (STM32F1xx ) || defined( STM32L1xx )
80+ #if !defined(FLASH_END )
81+ #if defined (STM32F0xx ) || defined (STM32F1xx )
8282#if defined (FLASH_BANK2_END ) && (FLASH_BANK_NUMBER == FLASH_BANK_2 )
8383#define FLASH_END FLASH_BANK2_END
8484#elif defined (FLASH_BANK1_END ) && (FLASH_BANK_NUMBER == FLASH_BANK_1 )
@@ -117,6 +117,8 @@ static inline uint32_t get_flash_end(void)
117117#define FLASH_END ((uint32_t)(FLASH_BASE + (((FLASH_PAGE_NUMBER +1) * FLASH_PAGE_SIZE))-1))
118118#elif defined(EEPROM_RETRAM_MODE )
119119#define FLASH_END ((uint32_t)(EEPROM_RETRAM_START_ADDRESS + EEPROM_RETRAM_MODE_SIZE -1))
120+ #elif defined(DATA_EEPROM_END )
121+ #define FLASH_END DATA_EEPROM_ENu
120122#endif
121123#ifndef FLASH_END
122124#error "FLASH_END could not be defined"
@@ -130,7 +132,7 @@ static inline uint32_t get_flash_end(void)
130132 * in order to prevent overwritting
131133 * program data
132134 */
133- #if defined(STM32L0xx )
135+ #if defined(DATA_EEPROM_BASE )
134136#define FLASH_BASE_ADDRESS ((uint32_t)(DATA_EEPROM_BASE))
135137#elif defined(EEPROM_RETRAM_MODE )
136138#define FLASH_BASE_ADDRESS EEPROM_RETRAM_START_ADDRESS
@@ -223,7 +225,7 @@ void eeprom_buffer_fill(void)
223225 memcpy (eeprom_buffer , (uint8_t * )(DATA_EEPROM_BASE ), E2END + 1 );
224226#else
225227 memcpy (eeprom_buffer , (uint8_t * )(FLASH_BASE_ADDRESS ), E2END + 1 );
226- #endif /* STM32L0xx */
228+ #endif /* DATA_EEPROM_BASE */
227229}
228230
229231#if defined(EEPROM_RETRAM_MODE )
@@ -268,8 +270,8 @@ void eeprom_buffer_flush(void)
268270 uint32_t address = FLASH_BASE_ADDRESS ;
269271 uint32_t address_end = FLASH_BASE_ADDRESS + E2END ;
270272#if defined (STM32F0xx ) || defined (STM32F1xx ) || defined (STM32F3xx ) || \
271- defined (STM32G0xx ) || defined (STM32G4xx ) || defined ( STM32L0xx ) || \
272- defined (STM32L1xx ) || defined ( STM32L4xx ) || defined (STM32WBxx )
273+ defined (STM32G0xx ) || defined (STM32G4xx ) || \
274+ defined (STM32L4xx ) || defined (STM32WBxx )
273275 uint32_t pageError = 0 ;
274276 uint64_t data = 0 ;
275277
@@ -287,38 +289,20 @@ void eeprom_buffer_flush(void)
287289 EraseInitStruct .NbPages = 1 ;
288290
289291 if (HAL_FLASH_Unlock () == HAL_OK ) {
290- #if defined(STM32L0xx )
291- __HAL_FLASH_CLEAR_FLAG (FLASH_FLAG_EOP | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | \
292- FLASH_FLAG_SIZERR | FLASH_FLAG_OPTVERR | FLASH_FLAG_RDERR | \
293- FLASH_FLAG_FWWERR | FLASH_FLAG_NOTZEROERR );
294- #elif defined(STM32L1xx )
295- #if defined(FLASH_SR_RDERR )
296- __HAL_FLASH_CLEAR_FLAG (FLASH_FLAG_EOP | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | \
297- FLASH_FLAG_SIZERR | FLASH_FLAG_OPTVERR | FLASH_FLAG_RDERR );
298- #else
299- __HAL_FLASH_CLEAR_FLAG (FLASH_FLAG_EOP | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | \
300- FLASH_FLAG_SIZERR | FLASH_FLAG_OPTVERR );
301- #endif
302- #elif defined (STM32G0xx ) || defined (STM32G4xx ) || defined (STM32L4xx ) || \
292+ #if defined (STM32G0xx ) || defined (STM32G4xx ) || defined (STM32L4xx ) || \
303293 defined (STM32WBxx )
304294 __HAL_FLASH_CLEAR_FLAG (FLASH_FLAG_ALL_ERRORS );
305295#else
306296 __HAL_FLASH_CLEAR_FLAG (FLASH_FLAG_EOP | FLASH_FLAG_WRPERR | FLASH_FLAG_PGERR );
307297#endif
308298 if (HAL_FLASHEx_Erase (& EraseInitStruct , & pageError ) == HAL_OK ) {
309299 while (address <= address_end ) {
310- #if defined(STM32L0xx ) || defined(STM32L1xx )
311- memcpy (& data , eeprom_buffer + offset , sizeof (uint32_t ));
312- if (HAL_FLASH_Program (FLASH_TYPEPROGRAM_WORD , address , data ) == HAL_OK ) {
313- address += 4 ;
314- offset += 4 ;
315- #else
300+
316301 data = * ((uint64_t * )((uint8_t * )eeprom_buffer + offset ));
317302
318303 if (HAL_FLASH_Program (FLASH_TYPEPROGRAM_DOUBLEWORD , address , data ) == HAL_OK ) {
319304 address += 8 ;
320305 offset += 8 ;
321- #endif
322306 } else {
323307 address = address_end + 1 ;
324308 }
0 commit comments