I am currently working with a SoC based on a Cortex-M7 (r0p1) core. The specific chip is the S32K344 MCU but I doubt I will get anyone who has worked with this chip, so I’ll try to generalize it.
We want to use the MPU available in the chip, which has 16 regions. I downloaded the latest version of FreeRTOS, navigated to the demos folder, and opened the demo application:
I just ordered this board to try to run this demo, but I found something rather interesting.
Under the Source folder of FreeRTOS, there’s no folder for the Cortex-M7 with MPU support, there’s only support for Cortex-M4. The demo application actually uses this M4 port to run on the M7.
I’ve read through the forums that the Cortex-M4 MPU has 8 regions. I want to use this port on my Cortex-M7 chip, with a 16-region MPU.
Is it worth pursuing trying to “add” the 16 region functionality?
What are the downsides of using the M4 port (other than less regions)?
Why is there no support for Cortex-M7 + MPU in the FreeRTOS source yet? There are plenty of chips that use this architecture now, I feel like I’m not the only person asking this
Any help, guidance, and lessons are much appreciated
I have one last question. If I use the MPU port, but decide to use xTaskCreate() with dynamic allocation, is there any overhead added?
In other words, if I do NOT use the MPU functionality, but I do use the MPU kernel port, will there be context switch performance hits, or any other technicalities I should be aware of?
Yes there is a performance hit as the mpu regions are saved and restored even if they are not used. That is faster (a couple of asm instructions) than testing to see if they are used, and needed anyway to clear any mpu regions used by the task being switched out.
I spent a bit of time working with FreeRTOS + MPU on an arm cortex-a. In the end, I felt like the value of the whole MPU thing wasn’t worth it, the overhead isn’t trivial, and if your code is going to crash, having an MPU really only would help some in the development phase.
Yes, “Just” an MPU isn’t enough to let your whole program just ignore pieces that “crash”. It just lets you fail more gracefully in a safer manner.
If the task never trips the MPU, then the MPU wasn’t actually needed, which means for most programs, the MPU is really just a development phase support, perhaps kept in the application to avoid major changes at release, and to make safer the fail mode if something does go wrong. This can be important, but still, only affect things if something goes wrong.
At microchip, we changed FreeRTOS to update one MPU entry as a red-zone for the bottom of stack every task switch,… this is one memory write,… and that allows us to remove the optional freertos stack overflow checking which checks that the bottom of stack hasn’t been modified, which is faster if you were going to enable stack checking.
we also created a program to configure the MPU in a slightly simpler way than the CMSIS macros, and created a program to display the resulting memory map after the MPU entries are programmed.
here’s a git repo of our code for displaying & calculating memory maps (I still have to sanitize the code for public consumption, and show the freertos patch).