Skip to content

Commit 6edcc1e

Browse files
committed
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.
1 parent 43f4b67 commit 6edcc1e

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

targets/TARGET_STM/mbed_overrides.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,16 @@ void mbed_sdk_init()
3535
HAL_Init();
3636

3737
#if TARGET_STM32F7
38-
// Enable CPU L1-Cache
39-
SCB_EnableICache();
40-
SCB_EnableDCache();
38+
// The mbed_sdk_init can be called either during cold boot or during
39+
// application boot after bootloader has been executed.
40+
// In case the bootloader has already enabled the cache,
41+
// is is needed to not enable it again.
42+
if (SCB->CCR & (uint32_t)SCB_CCR_IC_Msk == 0) { // If ICache is disabled
43+
SCB_EnableICache();
44+
}
45+
if (SCB->CCR & (uint32_t)SCB_CCR_DC_Msk == 0) { // If DCache is disabled
46+
SCB_EnableDCache();
47+
}
4148
#endif /* TARGET_STM32F7 */
4249

4350
/* Configure the System clock source, PLL Multiplier and Divider factors,

0 commit comments

Comments
 (0)