I got a question on the use of the heap of freertos.
I have configured the total heap size to 4200 bytes :
define configTOTALHEAPSIZE ((size_t)(4200))
I us all this space since when I call xPortGetFreeHeapSize() I got 10 so
only 10 bytes are unused.
However, I don't understand how this space is used. In fact if I sum the
sizes of the tasks stacks, I get only 2000 bytes :
task1 -> 125 words -> 500 bytes
task2 -> 125 words -> 500 bytes
task3 -> 100 words -> 400 bytes
idleTask -> 50 words -> 200 bytes (configMINIMALSTACKSIZE = 50)
timers -> 100 words -> 400 bytes (configTIMERTASKSTACK_DEPTH = 100)
TOTAL 2000 bytes
Is it normal ? Is there any way to knwow what use the other half of the
freeRTOS heap ?
Thank you for your help
When you create a task both the task stack and the task control block (TCB) come from the heap. If you creates queues or semaphores then the memory from those comes from the heap also. Direct to task notifications are faster than semaphores and do not use memory from the heap. http://www.freertos.org/a00111.html
Thank you a lot for this quick and clear answer.
I use :
- 1 queue of 6 elements of 1 byte
- 4 binary semaphores
- 1 mutex
- 3 timers
Do you think it explains the 2kB use of heap ?
If so, is there anyway to evaluate the size of each one to replace the bigger elements ?
You can use FreeRTOS+Trace to see memory allocations.
I didnt manage to make the openOCD work on my target, so bumping the memory to get the freeRTOS+trace output is a problem.
Is there any other way ?
Other than using the trace, I think you would have to add code, or put a break point in pvPortMalloc() to see what was calling it.