Quality RTOS & Embedded Software

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




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) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

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

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

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

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists