FreeRTOS MPU Demo

This example demonstrates unprivileged task execution using the Memory Protection Unit (MPU) with FreeRTOS.

Two unprivileged user tasks and one privileged sys task run concurrently:

  • user1 (unprivileged): prints a message over UART every 1 s using UART HAL APIs; the UART instance registers are mapped as an MPU device-memory region.

  • user2 (unprivileged): toggles LED1 every 500 ms using GPIO driverlib APIs; the GPIO registers are mapped as an MPU device-memory region.

  • sys (privileged): initialises peripherals, creates the user tasks, and prints a heartbeat message over UART every 2 s.

Each user task is configured with three MPU regions:

Region

Content

Access

1

Peripheral registers (UART or GPIO)

Device memory, RW, XN

2

Full unprivileged SRAM

Normal memory, RW, XN

3

Task text section

Normal memory, RO+execute

Note: Region 2 covers the full unprivileged SRAM for simplicity. Alternatively, each task can be given access to only a contiguous sub-region of SRAM containing just its required data.

Region 4 (task stack) is assigned automatically by FreeRTOS.

Key concepts demonstrated:

  • xTaskCreateRestrictedStatic() with per-task TaskParameters_t / xRegions[3]

  • tskMPU_REGION_DEVICE_MEMORY flag for peripheral access from user mode

  • Peripheral register writes from unprivileged context

  • Privileged sys task creating unprivileged user tasks

External Connections

  • UART output on PA0 (TX) / PA1 (RX) at 115200 baud (connect a USB-to-UART adapter)

  • LED1 blinks at 1 Hz (500 ms toggle period)