0

Context: Cortex-M7 STM32F746 Disco, writing own RTOS. Implementing memory policies for different memory regions for threads.

I've been writing my own RTOS kernel for the sake of understanding how things work (successfully until this point), and got to the point where I assign memory access policies for my threads using memory protection unit (MPU), since I want a complex kernel with bells and whistles and data safety. I got to the point where I need to set inner and outer cache policies. So the question emerged natually, what exactly inner and outer cache policies are.

Obviously, I went for ARM documentation on Cortex-M7. Here is a piece from this page on cache:

These custom cache policies are further divided into inner and outer policies, and you can choose different policies for each one. The caches inside the processor respond to the inner policy settings. The outer policy is signaled on the memory bus. The outer policy is used by extra levels of caching that are implemented outside of the processor in the memory system. An example of this type of extra level of caching is a level 2 cache controller. However, Cortex-M7 also exposes the inner cache policy settings as external signals. As a result, a chip designer can apply the inner settings to an external level of cache. Changing the settings in this way is a chip-specific implementation feature. For more information about this feature, read the chip-specific documentation.

I'll be honest, I didn't understand it very much. I believe I lack some knowledge on cache, and documentation is written in a very dry language, which only causes more questions.

The caches inside the processor respond to the inner policy settings. The outer policy is signaled on the memory bus.

As far as I understand, the inner policy applies to cache inside the MCU between internal SRAM and core, while outer is applied to...what? What memory bus? External SDRAM? Also, the outer policy is "signaled". Funny choice of verb. Why is it signaled? What signals to where?

And further down it goes about a possibility of exposing inner policy to the outside, which is implementation-specific, which, I guess, for STM32 is controlled by System Control Block or Cache Maintenance core peripherals?

I would be grateful if someone "dumbed down" this with a little simpler language, so that I can make sure I understand how it works correctly. I'm familiar with general cache concepts, write-through, write-back, cache lines, hits and misses, allocation policies and so on, but no material I read ever covered outer and inner cache policies.

If I'm choosing policy for the internal SRAM memory region, then outer policy should not matter, is this correct?

If I'm choosing policy for the external SDRAM without external L2 cache controller (about the existence of which I learned from this very text, never knew such thing exists), then internal policies apply to external SDRAM? Or external? Because I do plan to use external SDRAM eventually.

Frant
  • 5,382
  • 1
  • 16
  • 22
Ilya
  • 992
  • 7
  • 14
  • Some time ago I was learning about caching for ARMv8 and wrote up [an answer](https://stackoverflow.com/questions/70635862/synchronizing-caches-for-jit-self-modifying-code-on-arm/70684882#70684882) with some of it. Perhaps it may help a little. – Nate Eldredge Nov 03 '22 at 04:08
  • Thanks for the link. Unfortunately, I don't know half the terminology used there, microcontroller architecture is much simpler and doesn't have cache of different levels. Even the one and only L1 is unified for data and instructions, I think (don't have the documentation at hand rn). In any case, thank you for your attention. Maybe I'll understand at least something useful of it. – Ilya Nov 03 '22 at 08:13
  • For some STM32F, these attributes are meaningless as there is no cache. As Nate says for systems with L1/L2 they map inner/outer. From your comment the Cortex-M7 also only has a single unified cache. The only attribute is 'device' which says 'don't' ever cache. Also there is sometimes a 'buffer' where multiple writes are ganged. These matter for hardware. RAM will have other attributes. Most likely you need to look at multiple manuals. The STM32F746 will give some details that will make sense in ARM documents. The MPU is generic HDL which came with generic 'documentation'. – artless noise Nov 03 '22 at 16:53

1 Answers1

0

Cortex-M7 also exposes the inner cache policy settings as external signals. As a result, a chip designer ...

To use L2 cache in your RTOS you will need to design your IC too.

External cache controller in this context means "external to the core" not to the chip itself.

So, if you write the RTOS for STM32 uC you do not have to worry about the L2 as STM chip designers did not implement it in their uCs.

0___________
  • 60,014
  • 4
  • 34
  • 74
  • Are you saying that outer cache policy doesn't do anything at all in STM32 MCU? What policy matters for the external SDRAM? Inner or outer? – Ilya Nov 04 '22 at 09:00
  • @Ilya have you found anything about it in the STM32 documentation? – 0___________ Nov 04 '22 at 09:10
  • PM0253 programming manual covers the M7 core peripherals (NVIC, MPU, Cache Maintenance). However, it only briefly mentions inner and outer policy in the context of "this is how you set them" without a detailed explanation of what they are. This is how I got to asking this question in the first place. – Ilya Nov 04 '22 at 09:16
  • I have just run into AN4839. On page 4 it talks about QuadSPI and FMC (incl SDRAM) caching on AXIM line (just like SRAM - sorry I'm not an expert on internal busses yet). It seems to me this would mean they follow the same inner policy, and in this implementation of M7, external policy doesn't do anything at all. Do my words make sense? https://www.st.com/resource/en/application_note/an4839-level-1-cache-on-stm32f7-series-and-stm32h7-series-stmicroelectronics.pdf – Ilya Nov 04 '22 at 09:44
  • Yes, QSPI is included as you can map QSPI FLASH into the address space and for example execute code from there. – 0___________ Nov 04 '22 at 09:47
  • I know I can execute code from QSPI or external SDRAM (FMC). They question is, whether external or internal cache policy applies. I mean, in theory I could test it, but it would require to write a whole project that involves a function I never used before, so I can't guarantee I can test it correctly. – Ilya Nov 04 '22 at 09:55