diff options
Diffstat (limited to 'platforms/chibios/drivers')
-rw-r--r-- | platforms/chibios/drivers/wear_leveling/wear_leveling_efl.c | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/platforms/chibios/drivers/wear_leveling/wear_leveling_efl.c b/platforms/chibios/drivers/wear_leveling/wear_leveling_efl.c index cdd1e26a7d..3e4f5ffb89 100644 --- a/platforms/chibios/drivers/wear_leveling/wear_leveling_efl.c +++ b/platforms/chibios/drivers/wear_leveling/wear_leveling_efl.c @@ -17,27 +17,25 @@ static flash_sector_t first_sector = UINT16_MAX; static flash_sector_t sector_count = UINT16_MAX; static BaseFlash * flash; -#ifndef WEAR_LEVELING_EFL_FIRST_SECTOR // "Automatic" detection of the flash size -- ideally ChibiOS would have this already, but alas, it doesn't. static inline uint32_t detect_flash_size(void) { -# if defined(WEAR_LEVELING_EFL_FLASH_SIZE) +#if defined(WEAR_LEVELING_EFL_FLASH_SIZE) return WEAR_LEVELING_EFL_FLASH_SIZE; -# elif defined(FLASH_BANK_SIZE) +#elif defined(FLASH_BANK_SIZE) return FLASH_BANK_SIZE; -# elif defined(FLASH_SIZE) +#elif defined(FLASH_SIZE) return FLASH_SIZE; -# elif defined(FLASHSIZE_BASE) -# if defined(QMK_MCU_SERIES_STM32F0XX) || defined(QMK_MCU_SERIES_STM32F1XX) || defined(QMK_MCU_SERIES_STM32F3XX) || defined(QMK_MCU_SERIES_STM32F4XX) || defined(QMK_MCU_SERIES_STM32G4XX) || defined(QMK_MCU_SERIES_STM32L0XX) || defined(QMK_MCU_SERIES_STM32L4XX) || defined(QMK_MCU_SERIES_GD32VF103) +#elif defined(FLASHSIZE_BASE) +# if defined(QMK_MCU_SERIES_STM32F0XX) || defined(QMK_MCU_SERIES_STM32F1XX) || defined(QMK_MCU_SERIES_STM32F3XX) || defined(QMK_MCU_SERIES_STM32F4XX) || defined(QMK_MCU_SERIES_STM32G4XX) || defined(QMK_MCU_SERIES_STM32L0XX) || defined(QMK_MCU_SERIES_STM32L4XX) || defined(QMK_MCU_SERIES_GD32VF103) return ((*(uint32_t *)FLASHSIZE_BASE) & 0xFFFFU) << 10U; // this register has the flash size in kB, so we convert it to bytes -# elif defined(QMK_MCU_SERIES_STM32L1XX) -# error This MCU family has an uncommon flash size register definition and has not been implemented. Perhaps try using the true EEPROM on the MCU instead? -# endif -# else -# error Unknown flash size definition. - return 0; +# elif defined(QMK_MCU_SERIES_STM32L1XX) +# error This MCU family has an uncommon flash size register definition and has not been implemented. Perhaps try using the true EEPROM on the MCU instead? # endif +#else +# error Unknown flash size definition. + return 0; +#endif } -#endif // WEAR_LEVELING_EFL_FIRST_SECTOR bool backing_store_init(void) { bs_dprintf("Init\n"); @@ -46,8 +44,9 @@ bool backing_store_init(void) { // Need to re-lock the EFL, as if we've just had the bootloader executing it'll already be unlocked. backing_store_lock(); - const flash_descriptor_t *desc = flashGetDescriptor(flash); - uint32_t counter = 0; + const flash_descriptor_t *desc = flashGetDescriptor(flash); + uint32_t counter = 0; + uint32_t flash_size = detect_flash_size(); #if defined(WEAR_LEVELING_EFL_FIRST_SECTOR) @@ -68,7 +67,6 @@ bool backing_store_init(void) { #else // defined(WEAR_LEVELING_EFL_FIRST_SECTOR) // Work out how many sectors we want to use, working backwards from the end of the flash - uint32_t flash_size = detect_flash_size(); flash_sector_t last_sector = desc->sectors_count; for (flash_sector_t i = 0; i < desc->sectors_count; ++i) { first_sector = desc->sectors_count - i - 1; |