Skip to content

Commit 96b3a22

Browse files
FRASTMkartben
authored andcommitted
drivers: flash: stm32H5 flash driver gives the flash size
Use the LL_GetFlashSize to retrieve the size of the flash, reading the system flash OTP of the stm32h5 serie. This operation requires Icache disable/re-enable to access the 0x08FF F80C memory area Signed-off-by: Francois Ramu <francois.ramu@st.com>
1 parent eea1b82 commit 96b3a22

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

drivers/flash/flash_stm32.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
#define DT_DRV_COMPAT st_stm32_flash_controller
1414

1515
#include <string.h>
16+
#if defined(CONFIG_SOC_SERIES_STM32H5X)
17+
#include <zephyr/cache.h>
18+
#endif /* CONFIG_SOC_SERIES_STM32H5X */
1619
#include <zephyr/drivers/flash.h>
1720
#include <zephyr/drivers/flash/stm32_flash_api_extensions.h>
1821
#include <zephyr/init.h>
@@ -360,8 +363,21 @@ static int flash_stm32_get_size(const struct device *dev, uint64_t *size)
360363
{
361364
ARG_UNUSED(dev);
362365

366+
#if defined(CONFIG_SOC_SERIES_STM32H5X)
367+
/* Disable the ICACHE to ensure all memory accesses are non-cacheable.
368+
* This is required on STM32H5, where the manufacturing flash must be
369+
* accessed in non-cacheable mode - otherwise, a bus error occurs.
370+
*/
371+
cache_instr_disable();
372+
#endif /* CONFIG_SOC_SERIES_STM32H5X */
373+
363374
*size = (uint64_t)LL_GetFlashSize() * 1024U;
364375

376+
#if defined(CONFIG_SOC_SERIES_STM32H5X)
377+
/* Re-enable the ICACHE (unconditonally - it should always be turned on) */
378+
cache_instr_enable();
379+
#endif /* CONFIG_SOC_SERIES_STM32H5X */
380+
365381
return 0;
366382
}
367383

0 commit comments

Comments
 (0)