Using a Memory Protection Unit (MPU) can protect applications from a number of potential errors, ranging from undetected programming errors to errors introduced by system or hardware failures. FreeRTOS-MPU can be used to protect the kernel itself from invalid execution by tasks and protect data from corruption. It can also protect system peripherals from unintended modification by tasks and guarantee the detection of task stack overflows.
The LPC17xx edition of the FreeRTOS eBook contains a chapter on using FreeRTOS-MPU. The demo projects located in the FreeRTOS/Demo/CORTEX_MPU_LPC1768_GCC_RedSuite and FreeRTOS/Demo/CORTEX_MPU_LM3Sxxxx_Rowley directories of the main FreeRTOS download demonstrate the use of FreeRTOS-MPU on NXP LPC1768 and Luminary Micro/TI Stellaris microcontrollers respectively.
If a task wants to use the MPU then the following additional information has to be provided:
Tasks created using xTaskCreateRestricted() can also be created to execute in either Privileged mode or User mode - but this time User mode tasks have access to their user defined memory regions in addition to their stack. A Privileged mode task can call portSWITCH_TO_USER_MODE() to set itself into User mode. A task that is running in User mode cannot set itself into Privileged mode.
The memory regions allocated to a task can be changed using vTaskAllocateMPURegions(). See the xTaskCreateRestricted() and vTaskAllocateMPURegions() API documentation for more information.
Another way of learning more about FreeRTOS-MPU is to inspect and hopefully step through one of the heavily commented FreeRTOS-MPU demonstration projects. These can be located in the FreeRTOS/Demo/CORTEX_MPU_LM3Sxxxx_Rowley and FreeRTOS/Demo/CORTEX_MPU_LPC1768_GCC_RedSuite directories for Rowley CrossWorks and Red Suite IDEs respectively. Both projects demonstrate how to configure, create and use restricted mode tasks and contain code that can be uncommented to see the MPU working in practice.
A couple of points to note in the demo projects: