Updated Jul 2025
vTaskAllocateMPURegions
task. h
1void vTaskAllocateMPURegions(2 TaskHandle_t xTaskToModify,3 const MemoryRegion_t * const xRegions );
Memory regions are assigned to a restricted task when the task is created using a call to
xTaskCreateRestricted()
vTaskAllocateMPURegions()
vTaskAllocateMPURegions()
vTaskAllocateMPURegions()
Parameters:
-
xTask
The handle of the task being updated.
-
xRegions
A pointer to an array of
structures, each of which contains a single new memory region definitions. The array should be dimensioned using the constantMemoryRegion_t, which on the ARM Cortex-M3 is set to 3.portNUM_CONFIGURABLE_REGIONS
MemoryRegion_t
1typedef struct xMEMORY_REGION2{3 void *pvBaseAddress;4 unsigned long ulLengthInBytes;5 unsigned long ulParameters;6} MemoryRegion_t;
The
pvBaseAddress
ulLengthInBytes
ulParameters
1 portMPU_REGION_READ_WRITE2 portMPU_REGION_PRIVILEGED_READ_ONLY3 portMPU_REGION_READ_ONLY4 portMPU_REGION_PRIVILEGED_READ_WRITE5 portMPU_REGION_CACHEABLE_BUFFERABLE6 portMPU_REGION_EXECUTE_NEVER
Example usage (please refer to the FreeRTOS-MPU demo applications for a much more complete and comprehensive example):
1/* Define an array that the task will both read from and write to. Make sure2 the size and alignment are appropriate for an MPU region (note this uses GCC3 syntax). */4static unsigned char ucOneKByte[ 1024 ] __attribute__((align( 1024 )));56/* Define an array of MemoryRegion\_t structures that configures an MPU region7 allowing read/write access for 1024 bytes starting at the beginning of the8 ucOneKByte array. The other two of the maximum 3 definable regions are9 unused so set to zero. */10static const MemoryRegion_t xAltRegions[ portNUM_CONFIGURABLE_REGIONS ] =11{12 /* Base address Length Parameters */13 { ucOneKByte, 1024, portMPU_REGION_READ_WRITE },14 { 0, 0, 0 },15 { 0, 0, 0 }16};1718void vATask( void *pvParameters )19{20 /* This task was created such that it has access to certain regions of21 memory as defined by the MPU configuration. At some point it is22 desired that these MPU regions are replaced with that defined in the23 xAltRegions const struct above. Use a call to vTaskAllocateMPURegions()24 for this purpose. NULL is used as the task handle to indicate that this25 function should modify the MPU regions of the calling task. */26 vTaskAllocateMPURegions( NULL, xAltRegions );2728 /* Now the task can continue its function, but from this point on can only29 access its stack and the ucOneKByte array (unless any other statically30 defined or shared regions have been declared elsewhere). */31}