Skip to content

Commit

Permalink
fix(eeprom): ensure to have the correct FLASH_END
Browse files Browse the repository at this point in the history
FLASH_END which is defined in CMSIS file doesn't take
into account the real flash size of a the device,
(it is just the maximum possible within the productline).

Fixes stm32duino#1316, fixes stm32duino#1500

Signed-off-by: Frederic Pillon <[email protected]>
  • Loading branch information
fpistm committed Sep 21, 2021
1 parent 6dec3b6 commit 5c11191
Showing 1 changed file with 2 additions and 20 deletions.
22 changes: 2 additions & 20 deletions libraries/EEPROM/src/utility/stm32_eeprom.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,25 +52,6 @@ extern "C" {
#define FLASH_PAGE_NUMBER ((uint32_t)(((LL_GetFlashSize() * 1024) / FLASH_PAGE_SIZE) - 1))
#endif /* !FLASH_PAGE_NUMBER */

/* Be able to change FLASH_END to use */
#if !defined(FLASH_END)
#if defined(EEPROM_RETRAM_MODE)
#define FLASH_END ((uint32_t)(EEPROM_RETRAM_START_ADDRESS + EEPROM_RETRAM_MODE_SIZE -1))
#elif defined(DATA_EEPROM_END)
#define FLASH_END DATA_EEPROM_END
#elif defined (FLASH_BANK2_END) && (FLASH_BANK_NUMBER == FLASH_BANK_2)
#define FLASH_END FLASH_BANK2_END
#elif defined (FLASH_BANK1_END) && (FLASH_BANK_NUMBER == FLASH_BANK_1)
#define FLASH_END FLASH_BANK1_END
#elif defined(FLASH_BASE) && defined(FLASH_PAGE_NUMBER) && defined (FLASH_PAGE_SIZE)
/* If FLASH_PAGE_NUMBER is defined by user, this is not really end of the flash */
#define FLASH_END ((uint32_t)(FLASH_BASE + (((FLASH_PAGE_NUMBER +1) * FLASH_PAGE_SIZE))-1))
#endif
#ifndef FLASH_END
#error "FLASH_END could not be defined"
#endif
#endif /* FLASH_END */

/* Be able to change FLASH_BASE_ADDRESS to use */
#ifndef FLASH_BASE_ADDRESS
/*
Expand All @@ -81,7 +62,8 @@ extern "C" {
#if defined(EEPROM_RETRAM_MODE)
#define FLASH_BASE_ADDRESS EEPROM_RETRAM_START_ADDRESS
#else
#define FLASH_BASE_ADDRESS ((uint32_t)((FLASH_END + 1) - FLASH_PAGE_SIZE))
/* If FLASH_PAGE_NUMBER is defined by user, this is not really end of the flash */
#define FLASH_BASE_ADDRESS ((uint32_t)(FLASH_BASE + (FLASH_PAGE_NUMBER * FLASH_PAGE_SIZE)))
#endif
#ifndef FLASH_BASE_ADDRESS
#error "FLASH_BASE_ADDRESS could not be defined"
Expand Down

0 comments on commit 5c11191

Please sign in to comment.