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);