From cf3c26533cadf4e6739dbc9117caad01df2fa5e3 Mon Sep 17 00:00:00 2001 From: Nick Brassel Date: Fri, 2 Dec 2022 21:55:28 +1100 Subject: Fixup EFL and F4's sector selection. (#19221) --- .../boards/BLACKPILL_STM32_F401/configs/config.h | 14 ++++++++-- .../boards/BLACKPILL_STM32_F411/configs/config.h | 14 ++++++++-- .../boards/GENERIC_STM32_F401XC/configs/config.h | 10 ++++++++ .../boards/GENERIC_STM32_F411XE/configs/config.h | 10 ++++++++ .../drivers/wear_leveling/wear_leveling_efl.c | 30 ++++++++++------------ 5 files changed, 58 insertions(+), 20 deletions(-) (limited to 'platforms') diff --git a/platforms/chibios/boards/BLACKPILL_STM32_F401/configs/config.h b/platforms/chibios/boards/BLACKPILL_STM32_F401/configs/config.h index e181422eba..6d132ea6f3 100644 --- a/platforms/chibios/boards/BLACKPILL_STM32_F401/configs/config.h +++ b/platforms/chibios/boards/BLACKPILL_STM32_F401/configs/config.h @@ -19,12 +19,22 @@ #ifndef STM32_LSECLK # define STM32_LSECLK 32768U -#endif // STM32_LSECLK +#endif // STM32_LSECLK #ifndef STM32_HSECLK # define STM32_HSECLK 25000000U -#endif // STM32_HSECLK +#endif // STM32_HSECLK #ifndef EARLY_INIT_PERFORM_BOOTLOADER_JUMP # define EARLY_INIT_PERFORM_BOOTLOADER_JUMP TRUE #endif + +#ifdef WEAR_LEVELING_EMBEDDED_FLASH +# ifndef WEAR_LEVELING_EFL_FIRST_SECTOR +# ifdef BOOTLOADER_TINYUF2 +# define WEAR_LEVELING_EFL_FIRST_SECTOR 3 +# else +# define WEAR_LEVELING_EFL_FIRST_SECTOR 1 +# endif +# endif +#endif diff --git a/platforms/chibios/boards/BLACKPILL_STM32_F411/configs/config.h b/platforms/chibios/boards/BLACKPILL_STM32_F411/configs/config.h index e181422eba..6d132ea6f3 100644 --- a/platforms/chibios/boards/BLACKPILL_STM32_F411/configs/config.h +++ b/platforms/chibios/boards/BLACKPILL_STM32_F411/configs/config.h @@ -19,12 +19,22 @@ #ifndef STM32_LSECLK # define STM32_LSECLK 32768U -#endif // STM32_LSECLK +#endif // STM32_LSECLK #ifndef STM32_HSECLK # define STM32_HSECLK 25000000U -#endif // STM32_HSECLK +#endif // STM32_HSECLK #ifndef EARLY_INIT_PERFORM_BOOTLOADER_JUMP # define EARLY_INIT_PERFORM_BOOTLOADER_JUMP TRUE #endif + +#ifdef WEAR_LEVELING_EMBEDDED_FLASH +# ifndef WEAR_LEVELING_EFL_FIRST_SECTOR +# ifdef BOOTLOADER_TINYUF2 +# define WEAR_LEVELING_EFL_FIRST_SECTOR 3 +# else +# define WEAR_LEVELING_EFL_FIRST_SECTOR 1 +# endif +# endif +#endif diff --git a/platforms/chibios/boards/GENERIC_STM32_F401XC/configs/config.h b/platforms/chibios/boards/GENERIC_STM32_F401XC/configs/config.h index e06ca0b725..9865311018 100644 --- a/platforms/chibios/boards/GENERIC_STM32_F401XC/configs/config.h +++ b/platforms/chibios/boards/GENERIC_STM32_F401XC/configs/config.h @@ -20,3 +20,13 @@ #ifndef EARLY_INIT_PERFORM_BOOTLOADER_JUMP # define EARLY_INIT_PERFORM_BOOTLOADER_JUMP TRUE #endif + +#ifdef WEAR_LEVELING_EMBEDDED_FLASH +# ifndef WEAR_LEVELING_EFL_FIRST_SECTOR +# ifdef BOOTLOADER_TINYUF2 +# define WEAR_LEVELING_EFL_FIRST_SECTOR 3 +# else +# define WEAR_LEVELING_EFL_FIRST_SECTOR 1 +# endif +# endif +#endif diff --git a/platforms/chibios/boards/GENERIC_STM32_F411XE/configs/config.h b/platforms/chibios/boards/GENERIC_STM32_F411XE/configs/config.h index e06ca0b725..9865311018 100644 --- a/platforms/chibios/boards/GENERIC_STM32_F411XE/configs/config.h +++ b/platforms/chibios/boards/GENERIC_STM32_F411XE/configs/config.h @@ -20,3 +20,13 @@ #ifndef EARLY_INIT_PERFORM_BOOTLOADER_JUMP # define EARLY_INIT_PERFORM_BOOTLOADER_JUMP TRUE #endif + +#ifdef WEAR_LEVELING_EMBEDDED_FLASH +# ifndef WEAR_LEVELING_EFL_FIRST_SECTOR +# ifdef BOOTLOADER_TINYUF2 +# define WEAR_LEVELING_EFL_FIRST_SECTOR 3 +# else +# define WEAR_LEVELING_EFL_FIRST_SECTOR 1 +# endif +# endif +#endif 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; -- cgit v1.2.3