Is there support for using DTCM memory for task stack allocations in FreeRTOS while
using standard OCRAM for heap allocations.
It seems that pvPortMalloc always gets both stack and heap allocations from ucHeap.
It would be nice if there was a ucStack and pvPortMalloc knew it was allocating task stack…
or a separate stack malloc function??
Has anyone achieved this easily, is there a best practice or must one write their own pvPortMalloc?
Maybe the easiest way would be to use static allocation rather than dynamic allocation? That way you can place the statically allocated stack where ever you like within the memory map.
Yes, I did think of static, but I use C++ so I would like to keep using Heap4 and will most likely switch to heap5 due to the complex memory model
of the i.MXRT10xx cpu’s
I will leave as is for now but it does prevent taking advantage of TCM speed for stack operations.
Currently I use DTCM for static allocation of non-cacheable objects.
There is no problem with using static task allocation and C++. It just means that you create your tasks with xTaskCreateStatic instead of xTaskCreate, and statically allocate the memory for the TCB and the Stack frames (and using compiler extensions and the linker to control where the stack frames are placed).
The only issue with that structure would be if you need to dynamically change your task selection, which is a fairly rare requirement (and people think they need it more often then they really do). In that case you can make the ‘fixed’ task use the higher speed memory and only the dynamically created tasks need to get the ram from the heap.
I changed my settings to use static allocation as below:
Please Note: I am using your FreeRTOScpp wrapper classes.
I created functions vApplicationGetIdleTaskMemory and the timer equivalent.
The static buffers for those functions now come from DTCM (noncacheable TCM ram)
So idle and timer tasks now benefit from DTCM memory.
I set configSUPPORT_STATIC_ALLOCATION=1 and configSUPPORT_DYNAMIC_ALLOCATION=1
configAPPLICATION_ALLOCATED_HEAP=0 as I am happy having the heap in OCRAM.
I am using Heap4.
It all compiles and tasks/rtos objects appear to function as expected.
However, the task stack is still allocated from the RTOS heap obviously and Local variables are
not placed in DTCM. How do I get them there? What am I missing? is it possible?
Mr Barry stated that I can “place the statically allocated stack wherever I like”. But my issue is
about separating stack and heap allocations.
DTCM = 0x20000000-0x20020000 Tightly coupled non cacheable memory (for all stack)
OCRAM = 0x20200000-0x202C0000 (for all heap)
What I would like is for stack variables to be in DTCM and everything else in OCRAM.
On the i.MXRT 1/2 the OCRAM can be TCM. I can split it how I like. I would like to take
advantage of TCM using FreeRTOS.
When creating tasks, FreeRTOS allows you to statically allocate the TCB and the Stack in separate blocks (using xTaskCreateStatic) so you could put the TCB in normal memory and the Stack in the DTCM. My wrapper currently doesn’t support this (if it is statically creating the task, both the TCB and Stack are members of the object, so together), but you could have it create the task statically and place the TCB and the Stack together in the DTCM. At some point, I might see about making a way to statically allocate both separately (making the stack space be a parameter to a statically allocated TCB). This will be needed if/when I add support for creating restricted tasks.
I understand now; hence the need to use the TaskCreateStatic function…
But… I’m back to leaving as is then, as I like the FreeRTOScpp wrappers and my current project
is too far along to abandon them. I dont want both TCB and Stack in DTCM.
I look forward to future FreeRTOScpp enhancements.