From 194b068eeab0264d74610ce6fcc276e3390a7815 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Wed, 4 Mar 2020 19:16:45 +0200 Subject: [PATCH] Fix hardfault on disable D cache. * Disable and clean caches only if they're enabled. --- src/omv/stm32fxxx_hal_msp.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/omv/stm32fxxx_hal_msp.c b/src/omv/stm32fxxx_hal_msp.c index 23a513df0..95bc80de3 100644 --- a/src/omv/stm32fxxx_hal_msp.c +++ b/src/omv/stm32fxxx_hal_msp.c @@ -68,13 +68,17 @@ void HAL_MspInit(void) /* Enable I/D cache */ #if defined(MCU_SERIES_F7) ||\ defined(MCU_SERIES_H7) - /* Disable and Invalidate I-Cache */ - SCB_DisableICache(); - SCB_InvalidateICache(); + if (SCB->CCR & (uint32_t)SCB_CCR_IC_Msk) { + /* Disable and Invalidate I-Cache */ + SCB_DisableICache(); + SCB_InvalidateICache(); + } - /* Disable, Clean and Invalidate D-Cache */ - SCB_DisableDCache(); - SCB_CleanInvalidateDCache(); + if (SCB->CCR & (uint32_t)SCB_CCR_DC_Msk) { + /* Disable, Clean and Invalidate D-Cache */ + SCB_DisableDCache(); + SCB_CleanInvalidateDCache(); + } // Enable the CPU Caches SCB_EnableICache();