Arduino-esp32: Task stack size... how much?

Created on 21 Sep 2018  路  3Comments  路  Source: espressif/arduino-esp32

I am experimenting with multitasking on ESP32 using Arduino IDE and I have a question about stack size when creating tasks with xTaskCreate or xTaskCreatePinnedToCore functions.

Is there a way to calculate how much stack is needed?

According to https://www.freertos.org/uxTaskGetStackHighWaterMark.html I have tried to determine the maximum stack size effectively used by my task and noticed that if I lower the value of the stack size when I create the task, then the value returned by uxTaskGetStackHighWaterMark lowers too.
As an example I created a task with stack size = 4000, max stack used was 3700.
So I edited the progam and lowered the stack size to 3800, started the program and uxTaskGetStackHighWaterMark reported 3600 max stack used.
Repeated the procedure and everytime the used stack size was Always lower according to the stack size parameter of xTaskCreate function.

So, how do I determine the minimum required stack size? (If I am correct it's 1024)
Do I have to lower it and check until I get a stack overflow error?

Thanks in advance for support.

Most helpful comment

uxTaskGetStackHighWaterMark shows how much stack was never used not the value of used stack. It should have to report as close as possible to 0 (with some margin).

All 3 comments

uxTaskGetStackHighWaterMark shows how much stack was never used not the value of used stack. It should have to report as close as possible to 0 (with some margin).

uxTaskGetStackHighWaterMark shows how much stack was never used not the value of used stack. It should have to report as close as possible to 0 (with some margin).

I see, my mistake then, many thanks.
So considering it in the right way it works as expected, stack used is almost 200 and lowering the maximum stack lowers the unused size. This is correct then, nice.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ComputerLag picture ComputerLag  路  3Comments

merlinschumacher picture merlinschumacher  路  4Comments

AsafFisher picture AsafFisher  路  4Comments

mpatafio picture mpatafio  路  4Comments

docloulou picture docloulou  路  3Comments