Exact task stack size

shockwaver-one wrote on Sunday, April 13, 2014:

Hello everyone.
I was wandering how to calculate the exact (or closest to it) stack size I should pass to the xTaskCreate macro function. Is it the sum of all the bytes required by the task function viariables or is there more?

Thanks in advance.

bowerymarc wrote on Sunday, April 13, 2014:

Hard to do, because it’s not just those variables but any stack used by any other functions called by the task…. usually you do it empirically with high water marks (or crash/hangs!)

Also be aware of alignment for the processor - e.g. on an ARM, an 8 bit variable still takes up 4 bytes of stack.

On Apr 13, 2014, at 1:22 PMEDT, Shockwaver wrote:

Hello everyone.
I was wandering how to calculate the exact (or closest to it) stack size I should pass to the xTaskCreate macro function. Is it the sum of all the bytes required by the task function viariables or is there more?

Thanks in advance.

Exact task stack size

Sent from sourceforge.net because you indicated interest in https://sourceforge.net/p/freertos/discussion/382005/

To unsubscribe from further messages, please visit https://sourceforge.net/auth/subscriptions/

shockwaver-one wrote on Sunday, April 13, 2014:

Thanks for the reply.
Well then it comes to me if there is a way to calculate the size of the stack of a function. Variables used + … ?

rtel wrote on Sunday, April 13, 2014:

The stack is managed by the compiler, not FreeRTOS. If you have a C function that, when called from main() takes ‘n’ bytes of stack space, then when you call the function from a FreeRTOS task it will still take ‘n’ bytes of stack space.

How big ‘n’ is depends on the architecture you are using, the compiler you are using, the optimisation level you set for the compiler, etc. etc.

As already mentioned, the easiest/normal way of doing it is to set a stack size you think is big enough, then turn on stack overflow checking. If the overflow hook is called you know the stack was not large enough. If the overflow hook was not called then you can call uxTaskGetStackHighWaterMark() to see how much space remains unused.

Regards.

shockwaver-one wrote on Sunday, April 13, 2014:

Thanks for the reply.
Fine by me then, I’ll go empirically.

Thank you again.

alainm3 wrote on Sunday, April 13, 2014:

I have been testing the stack overflow hook and most of the time I got an exception intead of a warning. The reason is that if it is a relatively big stack overflow it will crash befor being detected.

But I have adapted the afore mentioned function throu my serial debug output and it is really very helpfull. After runing and exercising the sistem I could adjust all my different stacks!

wella wrote on Monday, April 14, 2014:

Are you using GCC compiler? If yes, try to use the -fstack-usage parameters. The compiler will generate stack usage for your source code, resp. every function. Unfortunately not for the standard library. By generating a function call-tree you can estimate the stack usage of your functions in andvance.