Hi guys.
I’ve tried to look this up in the forum. I’ve come close and even saw an answer that allocating memory via the pvPortMalloc() function is possible from an unprivileged task. To give you an idea of my environment:
- ARM Cortex M33 (nRF9160) running in the unsecure domain
- Using gcc
- MPU enabled
- Heap 4 utilized
- Running an unsecure and unprivileged task
- Requesting a small amount of memory (16 bytes) from the heap
The code compiles with no errors. When I configure the task in question as a privileged task:
TaskParameters_t task_parameters =
{
.pvTaskCode = fs_Thread,
.pcName = "FS",
.usStackDepth = configMINIMAL_STACK_SIZE,
.pvParameters = NULL,
.uxPriority = tskIDLE_PRIORITY | portPRIVILEGE_BIT,
.puxStackBuffer = task_stack,
.xRegions =
{
{ ( void *)shared_mem, SHAREDMEM_SIZE, tskMPU_REGION_READ_WRITE | tskMPU_REGION_EXECUTE_NEVER },
{ ( void *)NRF_NVMC, sizeof( NRF_NVMC_Type ), tskMPU_REGION_READ_WRITE | tskMPU_REGION_EXECUTE_NEVER },
{ ( void *)nvdata, NVDATA_SIZE, tskMPU_REGION_READ_WRITE | tskMPU_REGION_EXECUTE_NEVER },
{ 0, 0, 0 },
{ 0, 0, 0 },
{ 0, 0, 0 },
{ 0, 0, 0 },
{ 0, 0, 0 },
{ 0, 0, 0 },
{ 0, 0, 0 },
{ 0, 0, 0 },
}
};
…all is well and the task executes as expected.
However, when the task is configured as unprivileged:
.uxPriority = tskIDLE_PRIORITY,
… I get a memory fault as soon as pvPortMalloc() is called. Looking at the heap_4.c file, I can see that ucHeap is declared as privileged data. I suspect that is the reason for the memory fault.
Please forgive my ignorance. I’m sure this has been brought up countless times.
Thanks,
Johnas