From c5ebea590f1f7cf04966697afb0f2a05644f6626 Mon Sep 17 00:00:00 2001 From: Thomas Altenbach Date: Thu, 25 Nov 2021 13:49:17 +0100 Subject: [PATCH] drivers/flash: stm32h7: fix fault when cache disabled Add a check to avoid invalidating the cache when the latter is disabled. Indeed, doing so can lead to a bus fault. Signed-off-by: Thomas Altenbach --- drivers/flash/flash_stm32h7x.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/flash/flash_stm32h7x.c b/drivers/flash/flash_stm32h7x.c index a474586475a..6365486c9d2 100644 --- a/drivers/flash/flash_stm32h7x.c +++ b/drivers/flash/flash_stm32h7x.c @@ -449,6 +449,11 @@ static void flash_stm32h7_flush_caches(const struct device *dev, off_t offset, size_t len) { ARG_UNUSED(dev); + + if (!(SCB->CCR & SCB_CCR_DC_Msk)) { + return; /* Cache not enabled */ + } + SCB_InvalidateDCache_by_Addr((uint32_t *)(CONFIG_FLASH_BASE_ADDRESS + offset), len); }