Page 1 of 1

Task stack size

Posted: Mon Jan 22, 2018 9:38 am
by s.allasia
Hi,

How I can determine a stack size when I create a task (xTaskCreate)?
Can you tell me what factors need to be consider for calculating a task stack size?

Thanks!

Re: Task stack size

Posted: Mon Jan 22, 2018 10:24 am
by f.h-f.s.
You need the stack space for all the variables in the scope of that task. (not including malloc, which goes on the heap)
You can see how much of that space is/was used by calling "uxTaskGetStackHighWaterMark(NULL)" inside the task. Or passing the task handle instead of NULL, calling the function from anywhere.

Re: Task stack size

Posted: Mon Jan 22, 2018 2:15 pm
by s.allasia
Ok, thanks I tried that you suggested to me.
So do I have to find the value empirically?

Re: Task stack size

Posted: Thu Jan 25, 2018 11:55 am
by Gfast2
I start with a safe / big enough stack size, then try to call
uxTaskGetStackHighWaterMark(NULL)
monitor how is the "High Water Mark", then lastely I shrink down the stack size I allocated before. 8192 is what I tried first normally.

Cheers

Gfast2

Re: Task stack size

Posted: Thu Jan 25, 2018 12:25 pm
by s.allasia
Ok, thanks a lot Gfast2!
I do in your way.