Skip to content

Commit cd0993b

Browse files
committed
drivers: flash_stm32h7: fix flash size detection
Commit cded9b7 ("drivers : flash: update way to get flash size") changed the way to get flash size from the LL_FLASH_GetSize() HAL function to the current DT_REG_SIZE() macro. However, they are not equivalent: - With LL_FLASH_GetSize(), REAL_FLASH_SIZE_KB returned the *total* size of the Flash memory, reading it from a ROM register of the CPU. For example, it was 2048 (2MB) for a STM32H747xI. - The current DT_REG_SIZE() applies to a flash *bank*, therefore it only returns half of the total Flash size on dual bank devices. This mismatch causes issues with the DISCONTINUOUS_BANKS logic below, incorrectly matching partitions close to the end of the first bank as appearing to span both and triggering the "range overlaps discontinuity" check later. Fix it by doubling the size when appropriate, in the same way it is already done for the M4 core. Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
1 parent d851814 commit cd0993b

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

drivers/flash/flash_stm32h7x.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,12 @@ LOG_MODULE_REGISTER(LOG_DOMAIN);
4545
#define REAL_FLASH_SIZE_KB (KB(STM32H7_M4_FLASH_SIZE * 2))
4646
#endif
4747
#else
48+
#if defined(DUAL_BANK)
49+
#define REAL_FLASH_SIZE_KB (DT_REG_SIZE(DT_INST(0, st_stm32_nv_flash)) * 2)
50+
#else
4851
#define REAL_FLASH_SIZE_KB DT_REG_SIZE(DT_INST(0, st_stm32_nv_flash))
4952
#endif
53+
#endif
5054
#define SECTOR_PER_BANK ((REAL_FLASH_SIZE_KB / FLASH_SECTOR_SIZE) / 2)
5155
#if defined(DUAL_BANK)
5256
#define STM32H7_SERIES_MAX_FLASH_KB KB(2048)

0 commit comments

Comments
 (0)