Reputation: 59
I am running FreeRTOS on STM32F103 and using IAR workbench. I am trying to understand the relationship between 'general stack size set by the linker' and 'stack size for each task in FreeRTOS'. For instance, when the FreeRTOS creates tasks, does it use the stack defined by linker or define its own in the free RAM? I am trying to determine stack size for the project. I understand that I can use waterMark function call to determine stack of each task. Thoughts?
Upvotes: 2
Views: 3105
Reputation: 1653
First of all you have to understand that when you create task in FreeRTOS memory (TCB and Stack) for this task is allocated on FreeRTOS heap which size is defined in FreeRTOSConfig.h.
The linker heap is the C library heap, not the FreeRTOS heap. The linker stack is normally only used for your startup code, and in some ports, for the interrupt stack. It is NOT used by any of the tasks.
For example imagine that you have FreeRTOS based system with one custom thread called DEMO. Your heap layout might look like schema below. The most important lesson from this picture for you is that each task stack is unrelated to the stack defined in the linker. Task stack is allocated on the FreeRTOS heap which is unrelated to the heap defined in the linker as I have already mentioned!
Example Heap Layout:
+-------------------+ <----------+
| | |
| FREE HEAP MEMORY | FREE SPACE
| | |
+-------------------+ <----------+
| TIMER TASK TCB | |
+-------------------+ |
| TIMER TASK STACK | |
+-------------------+ |
| IDLE TASK TCB | |
+-------------------+ |
| IDLE TASK STACK | ALLOCATED SPACE
+-------------------+ |
| DEMO TASK TCB | |
+-------------------+ |
| DEMO TASK STACK | |
+-------------------+ |
| MUTEXES, SETS ETC.| |
+-------------------+ <----------+
Upvotes: 1