2

I am using FreeRTOS to develop Firmware on STM32 MCU.

What are the techniques I can use to determine stack size required for individual task which is created using FreeRTOS xTaskCreate API?

I know this depends on work done by individual task but I need to know how can I find out nearby stackdepth value to make sure my Task will work without any stack overflow error during runtime.

raj123
  • 564
  • 2
  • 10
  • 27

1 Answers1

2

The easiest way is to use a FreeRTOS aware IDE plug-in that tells you the stack usage. Failing that, you can calculate it - or get GCC to calculate it for you - but my preference is a bit more pragmatic. First ensure you have a stack overflow hook defined, in case the stack is too small. Then assign a stack you think is too large, let the code execute through what is assume to be the highest stack usage code path, then call uxStackGetHighWaterMark() to see how much stack was actually used and adjust accordingly - remembering to add anything necessary for whatever the likely interrupt nesting stack usage will be. You can also use more invasive functions such as uxTaskGetSystemStack() to see the stack usage of all tasks.

Richard
  • 3,081
  • 11
  • 9