Issue with allocating FreeRTOS task stack memory

Hi,

I am finding one weird issue while the task get scheduled. Appreciate any help in this regard.
I am using FreeRTOS v10.4.3 MPU port on ARM v8 M55 based system. Here is the code snippet to create task:

void create_task(struct thread_attr *attr)
{
    . . .
    TaskParameters_t task_cfg_params =
    {
        .pvTaskCode = (TaskFunction_t)attr->entrypoint,
        .pcName = arrt->name,
        .usStackDepth = (attr->stack_size / sizeof(StackType_t)),
        .pvParameters = arg,
        .uxPriority = 0x80000000U | attr->priority,
        .puxStackBuffer = (StackType_t *)attr->stack_addr,
        .xRegions =
        {
            {(void *)__heap_start__, /* 32 byte aligned */
            heap_size, /* multiple of 32 bytes */
            tskMPU_REGION_READ_WRITE},
            {0, 0, 0},
            {0, 0, 0},
        }
    };

    xRunningPrivileged = xPortRaisePrivilege();
    ret = xTaskCreateRestricted(&(task_cfg_params), (TaskHandle_t *)thread_id);
    vPortResetPrivilege( xRunningPrivileged );
}

If task stack (stack_addr) is reserved in “privileged_data” section, task gets scheduled perfectly. However, if stack buffer is allocated in any other data section (say, heap or bss), a fault occurs during the MPU configuration when the particular task gets scheduled.

Here are few configs defined in FreeRTOSConfg.h:

configENABLE_MPU = 1
configENABLE_TRUSTZONE  = 0
configRUN_FREERTOS_SECURE_ONLY  = 1
configSUPPORT_STATIC_ALLOCATION  = 1
configSUPPORT_DYNAMIC_ALLOCATION  = 1
etc.

Could some one point me what I am missing?

Thanks and regards,
Sandip

Looking into this - but as a first comment the FreeRTOS heap is also placed in the privileged data region: FreeRTOS-Kernel/heap_4.c at main · FreeRTOS/FreeRTOS-Kernel · GitHub

How do you ensure that the stack is located in those regions? v8M does not allow overlapping MPU regions - Is it possible that you are trying to create overlapping regions? For example, if your stack happens to be located in __heap_start__ region, it will result in overlapping MPU regions - one used to protect task stack and other used to protect __heap_start__. Can you share complete code showing the problem?