Page 1 of 1

Calculate stack sizes for FreeRTOS

Posted: Wed Feb 16, 2022 2:11 pm
by d.romeo
Hi, I wanted to know if there is a criterion or function to calculate the correct stack size for a FreeRTOS task for ESP32 (Arduino framework). Thank you.

Re: Calculate stack sizes for FreeRTOS

Posted: Thu Feb 17, 2022 3:00 am
by ESP_Sprite
Not per se; the easiest way is to assign a stack size that is generous to the stack, then run the program while periodically printing out uxTaskGetStackHighWaterMark() to see how many stack bytes remain unused. Make sure you get the program through most use cases so you can be pretty sure that number is the absolute maximum the stack will ever use. Then lower the stack assigned to the task by that value, plus a few hundred byte as buffer if there's a situation you missed.

Re: Calculate stack sizes for FreeRTOS

Posted: Sat Feb 19, 2022 2:50 pm
by d.romeo
Ok, thanks, much simpler than I thought.