Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task stack size... how much? #1884

Closed
Darkhub opened this issue Sep 21, 2018 · 4 comments
Closed

Task stack size... how much? #1884

Darkhub opened this issue Sep 21, 2018 · 4 comments

Comments

@Darkhub
Copy link

Darkhub commented Sep 21, 2018

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.

@lbernstone
Copy link
Contributor

This is an ESP-IDF issue, not arduino. RTFM at https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/system/freertos.html and https://www.freertos.org/a00111.html.

@chegewara
Copy link
Contributor

chegewara commented Sep 21, 2018

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).

@Darkhub
Copy link
Author

Darkhub commented Sep 22, 2018

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.

@jandolina
Copy link

My app is running LoRa and OTA on a separate core from my main logic. Do any of you know if the OTA update size will affect the stack size required?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants