From 8ed0f26d80a204fecff4ff107231cc6d4b560150 Mon Sep 17 00:00:00 2001 From: bcostm Date: Tue, 9 Jan 2018 17:06:48 +0100 Subject: [PATCH] Check cache before enabling it The mbed_sdk_init can be called either during cold boot or during application boot after bootloader has been executed. In case the bootloader has already enabled the cache, is is needed to not enable it again. --- targets/TARGET_STM/mbed_overrides.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/targets/TARGET_STM/mbed_overrides.c b/targets/TARGET_STM/mbed_overrides.c index fbdccb8c5f..8df4ff2958 100644 --- a/targets/TARGET_STM/mbed_overrides.c +++ b/targets/TARGET_STM/mbed_overrides.c @@ -35,9 +35,16 @@ void mbed_sdk_init() HAL_Init(); #if TARGET_STM32F7 - // Enable CPU L1-Cache - SCB_EnableICache(); - SCB_EnableDCache(); + // The mbed_sdk_init can be called either during cold boot or during + // application boot after bootloader has been executed. + // In case the bootloader has already enabled the cache, + // is is needed to not enable it again. + if (SCB->CCR & (uint32_t)SCB_CCR_IC_Msk == 0) { // If ICache is disabled + SCB_EnableICache(); + } + if (SCB->CCR & (uint32_t)SCB_CCR_DC_Msk == 0) { // If DCache is disabled + SCB_EnableDCache(); + } #endif /* TARGET_STM32F7 */ /* Configure the System clock source, PLL Multiplier and Divider factors,