What's the order of MPU regions?

Hey,

I am using FreeRTOS V10.5.1 with MPU option on STM32F4.

I’m facing the issue that when I want to do an internal flash (flash ROM during runtime) the software runs into Hard fault handler.

When creating the task that does the flashing, I set the portPRIVILEGE_BIT and configured the flash region as portMPU_REGION_PRIVILEGED_READ_WRITE in xRegions of the task.
According to https://www.freertos.org/MPU_Chapter.pdf page 191 the user defined regions have the highest number and priority.

In fact when checking port.c and portmacro.h I see the configurable regions are defined with numbers 0 to 2.

So I have to change the configurtation for portUNPRIVILEGED_FLASH_REGION which has a higher number. Now flash is possible.

Is there a reason why there is a difference between docu (of LCP17xx) and port settings for ARM_CM4_MPU? Is it by update of FreeRTOS version or controller specific?
In my eyes it does not make so much sense if the user region setting are less powerful then default setting?!

That was changed recently. We now use highest numbered region for kernel protections to ensure that those cannot be overridden.

Is it possible for you to crave out the section of flash that you want to write and not have it part of the unprivileged flash?

Thanks for clarification.

Changing the location of the section is not so easy in our project. But I get the idea. Thank you.