Calculate stack sizes for FreeRTOS

d.romeo
Posts: 5
Joined: Mon Nov 29, 2021 5:02 pm

Calculate stack sizes for FreeRTOS

Postby d.romeo » Wed Feb 16, 2022 2:11 pm

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.

ESP_Sprite
Posts: 9746
Joined: Thu Nov 26, 2015 4:08 am

Re: Calculate stack sizes for FreeRTOS

Postby ESP_Sprite » Thu Feb 17, 2022 3:00 am

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.

d.romeo
Posts: 5
Joined: Mon Nov 29, 2021 5:02 pm

Re: Calculate stack sizes for FreeRTOS

Postby d.romeo » Sat Feb 19, 2022 2:50 pm

Ok, thanks, much simpler than I thought.

Who is online

Users browsing this forum: No registered users and 110 guests