From c6f32f436391b6c14dd1df94614f336a174a7f58 Mon Sep 17 00:00:00 2001 From: zhangyuan21 Date: Sat, 1 Jul 2023 06:05:37 +0800 Subject: [PATCH] arm-m: Check the dcache status before enabling dcache If the cache is already enabled before NuttX starts up, enabling the cache in NuttX will cause the cache to be re-invalidated, then resulting in data that is already in the cache being flushed out. Signed-off-by: zhangyuan21 --- arch/arm/src/armv7-m/arm_cache.c | 8 ++++++++ arch/arm/src/armv8-m/arm_cache.c | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/arch/arm/src/armv7-m/arm_cache.c b/arch/arm/src/armv7-m/arm_cache.c index f326316f1d..cfe27dfd25 100644 --- a/arch/arm/src/armv7-m/arm_cache.c +++ b/arch/arm/src/armv7-m/arm_cache.c @@ -496,6 +496,14 @@ void up_enable_dcache(void) uint32_t sets; uint32_t ways; + /* If dcache is already enabled, disable it first. */ + + ccr = getreg32(NVIC_CFGCON); + if ((ccr & NVIC_CFGCON_DC) != 0) + { + up_disable_dcache(); + } + /* Get the characteristics of the D-Cache */ ccsidr = getreg32(NVIC_CCSIDR); diff --git a/arch/arm/src/armv8-m/arm_cache.c b/arch/arm/src/armv8-m/arm_cache.c index e7a7e504ed..12a4078be0 100644 --- a/arch/arm/src/armv8-m/arm_cache.c +++ b/arch/arm/src/armv8-m/arm_cache.c @@ -496,6 +496,14 @@ void up_enable_dcache(void) uint32_t sets; uint32_t ways; + /* If dcache is already enabled, disable it first. */ + + ccr = getreg32(NVIC_CFGCON); + if ((ccr & NVIC_CFGCON_DC) != 0) + { + up_disable_dcache(); + } + /* Get the characteristics of the D-Cache */ ccsidr = getreg32(NVIC_CCSIDR);