1.15 FreeRTOS with MPU
FreeRTOS with MPU enables microcontroller applications to be more robust and more secure by first, enabling tasks to run in either privileged or unprivileged mode; and second by restricting access to resources such as RAM, executable code, peripherals, and memory beyond the limit of a task's stack
Description
This demonstration enables MPU support in FreeRTOS. It then creates three tasks as shown below:
- Task1: rdonly_task
This task runs in un-privileged (user) mode. It has read-only access to the ucSharedMemory memory buffer and read-write access to the fault_testing memory.
- Task2: rw_task
This task runs in un-privileged (user) mode. It has read-write access to the ucSharedMemory memory buffer.
- Task3: priv_task
This task runs in privileged mode and has access to all the memory regions.
Downloading and Building the Application
To clone or download this application from Github, go to the main page of this repository and then click Clone button to clone this repository or download as zip file. This content can also be downloaded using content manager by following these instructions.
Path of the application within the repository is apps/rtos/freertos/freertos_mpu/firmware.
To build the application, refer to the following table and open the project using its IDE.
Project Name | Description |
---|---|
sam_e54_xpro.X | MPLABX project for SAM E54 Xplained Pro Evaluation Kit |
Setting Up the Hardware
The following table shows the target hardware for the application projects.
Project Name | Description |
---|---|
sam_e54_xpro.X | SAM E54 Xplained Pro Evaluation Kit |
Setting Up SAM E54 Xplained Pro Evaluation Kit
- Connect the Debug USB port on the board to the computer using a micro USB cable
Running the Application
- Open the Terminal application (Ex.:Tera Term) on the computer.
- Connect to the EDBG Virtual COM port and configure the serial settings as
follows:
- Baud : 115200
- Data : 8 Bits
- Parity : None
- Stop : 1 Bit
- Flow Control : None
- Build and program the application using its IDE.
- Observe the following output on the terminal. Notice the address of ucSharedMemory[1].
- Enter '1' to force the rdonly_task to write to ucSharedMemory[1] to which it only has read only access in user mode. This should generate a MPU fault and print the MPU fault address as shown below.
- Enter '2' to temporarily switch the rdonly_task to privileged mode and write to ucSharedMemory[1]. Once the write is done, it switches itself back to the user mode. Observe the value at ucSharedMemory[1] increment by 1 everytime this option is excercised.
- Enter '3' to print the value of ucSharedMemory[0] which is incremented by the priv_task that has access to the entire memory region.