static StackType_t xTaskStack[ 256 ] _attribute_((aligned(256*4)));
/* Declare an array that will be accessed by the task. The task should only
be able to read from the array, and not write to it. */
// ASILD_MEM_DATA volatile char cReadOnlyArray[32] _attribute_((aligned(32))) = {0};
// ASILD_MEM_DATA volatile char cReadWriteArray[32] _attribute_((aligned(32))) = {0};
static uint8_t cReadOnlyArray[32];
static uint8_t cReadWriteArray[32];
StaticTask_t pxTaskBuffer;TaskHandle_t * pxCreatedTask = NULL;
void vTaskFunction(void* p) {
myprintf("MPU_Task privilege = %s\\n", portIS_TASK_PRIVILEGED() ? "privileged" : "unprivileged"); //Verify read-only area volatile uint32_t var = cReadOnlyArray\[0\]; myprintf("the read-only array value is %d\\n", var); //Verify read-write area cReadWriteArray\[0\] = 0XBB; volatile uint32_t wr_var = cReadWriteArray\[0\]; /\*\* Verify whether the read-only area permission has been configured successfully\*/ // myprintf("start write read-only array value\\n"); // cReadOnlyArray\[0\] = 0XAA; // myprintf("the read-only array value is %d\\n", cReadOnlyArray\[0\]); vTaskDelete(NULL);}
/* Fill in a TaskParameters_t structure to define the task - this is the
structure passed to the xTaskCreateRestricted() function. */
static const TaskParameters_t xTaskDefinition =
{
vTaskFunction, /* pvTaskCode */
“MPU_Task”, /* pcName */
256, /* usStackDepth - defined in words, not bytes. */
NULL, /* pvParameters */
(configMAX_PRIORITIES - 4), /* uxPriority - priority 1, start in User mode. */
xTaskStack, /* puxStackBuffer - the array to use as the task stack. *//\* xRegions - In this case only one of the three user definable regions is actually used. The parameters are used to set the region to read only. \*/ { /\* Base address Length Parameters \*/ { cReadOnlyArray, 32, tskMPU_REGION_READ_ONLY }, { cReadWriteArray, 32, tskMPU_REGION_READ_WRITE }, }, &pxTaskBuffer};
// then it must be aligned to ( 128 * 4 ) bytes. This example used GCC syntax. */
static StackType_t xTaskStack_two[ 256 ] _attribute_((aligned(256*4)));/* Declare an array that will be accessed by the task. The task should only
be able to read from the array, and not write to it. */
ASILD_MONITOR_DATA volatile char cReadOnlyArray2[32] _attribute_((aligned(32))) = {0};
ASILD_MONITOR_DATA volatile char cReadWriteArray2[32] _attribute_((aligned(32))) = {0};StaticTask_t pxTaskBuffer_two;
TaskHandle_t * pxCreatedTask_two = NULL;
//read cread or cwrite
void vTaskFunction_two(void* p) {myprintf("MPU_Task_two privilege = %s\\n", portIS_TASK_PRIVILEGED() ? "privileged" : "unprivileged"); //Verify read-only area myprintf("=======start read other task xregion=====\\n"); volatile uint32_t var = cReadOnlyArray\[0\]; myprintf(" read other task read-only array value is %d\\n", var); var = cReadWriteArray\[0\]; myprintf(" read other task creadwrite0 array value is %0x\\n", var); //Verify read-write area myprintf(" set other task creadwrite0 array value is 0XBC\\n"); cReadWriteArray\[0\] = 0XBC; volatile uint32_t wr_var = cReadWriteArray\[0\]; myprintf(" read other task creadwrite0 value is %0x\\n", wr_var); myprintf("=========== end read other xregion task===============\\n"); /\*\* Verify whether the read-only area permission has been configured successfully\*/ // myprintf("start write read-only array value\\n"); // cReadOnlyArray\[0\] = 0XAA; // myprintf("the read-only array value is %d\\n", cReadOnlyArray\[0\]); vTaskDelete(NULL);}
static const TaskParameters_t xTaskDefinition_two =
{
vTaskFunction_two, /* pvTaskCode */
“MPU_Task_two”, /* pcName */
256, /* usStackDepth - defined in words, not bytes. */
NULL, /* pvParameters */
(configMAX_PRIORITIES - 5), /* uxPriority - priority 1, start in User mode. */
xTaskStack_two, /* puxStackBuffer - the array to use as the task stack. *//\* xRegions - In this case only one of the three user definable regions is actually used. The parameters are used to set the region to read only. \*/ { /\* Base address Length Parameters \*/ { cReadOnlyArray2, 32, tskMPU_REGION_READ_ONLY }, { cReadWriteArray2, 32, tskMPU_REGION_READ_WRITE }, }, &pxTaskBuffer_two};
FUNC(void, OS_CODE)
StartupTask(void)
{
//LOG(DBG_INFO,“BSWInt”, “%s\r\n%s\r\n%s”, s_bst_man_name,s_bst_pro_name,s_bst_ver_string);
LOG(DBG_INFO,“SOCR5 BSWInt”, “%s”, s_bst_ver_info);BaseType_t ret = xTaskCreateRestrictedStatic(&xTaskDefinition, &pxCreatedTask); if (ret != pdPASS) { myprintf("Failed to create restricted task\\n"); } else { myprintf("Successfully created restricted task\\n"); } BaseType_t ret2 = xTaskCreateRestrictedStatic(&xTaskDefinition_two, &pxCreatedTask_two); if (ret2 != pdPASS) { myprintf("Failed to create restricted task2\\n"); } else { myprintf("Successfully created restricted task2\\n"); } vTaskStartScheduler();}
Hello, above is my test codes. I’d like to ask a few questions
- After porting the MPU function to cortexR5, it was found that non-privileged Task A and non-privileged Task B can access each other’s configured Xregions. Is there a problem with this?
- How should the code segment and data segment of Task A and Task B be isolated?
- Can FreeRtos MPU only isolate privileged and non-privileged memory?