Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT




Loading

Exact task stack size

Posted by shockwaver-one on 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.


Exact task stack size

Posted by bowerymarc on 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/


Exact task stack size

Posted by shockwaver-one on 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 + ... ?


Exact task stack size

Posted by rtel on 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.


Exact task stack size

Posted by shockwaver-one on April 13, 2014

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

Thank you again.


Exact task stack size

Posted by alainm3 on 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!


Exact task stack size

Posted by wella on 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.


[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]




Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

FreeRTOS kernel V10 is available for immediate download. Now MIT licensed.


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS