On ARM Cortex-R4F, when I disable instruction and data cache using SCTLR register bits I and C, what happens to MPU region that defines region attribute as cachable (write-back)? Would it be ignored since global cache is disabled or would it result in unknown behavior?
1 Answers
Under the ARMv7-A/R architecture, it's actually implementation-defined whether or not the SCTLR C and I bits affect the attributes generated by an enabled MMU/MPU. However, judging by the description of the default memory map attributes in the Cortex-R4 TRM, it looks to be in the "behaves as expected" camp, where SCTLR.C = 0 means accesses to any Normal memory region come out as Non-cacheable.
Even if that weren't the case, the alternative would just be that the bit has no effect, and the MMU/MPU attributes are used. Fortunately there's no scope for completely unpredictable behaviour here.
That said, the hairier aspect to consider is that whilst Non-cacheable accesses are guaranteed not to allocate in the cache, it is implementation defined whether they can still hit if a valid entry for that location happens to be present. Thus if you're turning the cache off after making any Cacheable accesses you'll want to immediately clean and invalidate the whole thing before going any further - I'm not sure which side of that implementation choice Cortex-R4 falls, but either way I wouldn't take the risk of not doing so.