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


Calculating portMINIMAL_STACK_SIZE

Posted by Marcel van Lieshout on February 7, 2005
In the port I'm working on, the portMINIMAL_STACK_SIZE depends on several things. The compiler, however calculates this size and makes it available as an assembler-definition.

What I am currently missing is a way to influence the task-requested-stacksize just before it is allocated in task.c.

Add a line to sTaskCreate() like:
usStackDepth = portCalcStack(usStackDepth);

The function (or macro) portCalcStack() can then modify the requested stackdepth as needed.

RE: Calculating portMINIMAL_STACK_SIZE

Posted by Richard on February 7, 2005

I'm not sure what you mean when you say the compiler calculates this size.

When your application starts (before the scheduler has been started) the stack that is used is that allocated by the compiler/linker. Normally you can influence it's size using a linker command - or something similar as per your particular compiler.

The size of the stack used by each task is passed as a parameter to sTaskCreate(), so you could use your portCalcStack() function to generate the parameter value.

The only task that is out of the applications control that uses portMINIMAL_STACK_SIZE is the idle task. Normally the idle task does not require much stack so this can be set small. The demo application tasks sometimes use portMINIMAL_STACK_SIZE but this is just for convenience - they could use any appropriate stack size.

One issue for very memory constrained systems is how to recover the memory used by the original - linker assigned - stack. Once the scheduler has started this is not required any more so is wasted RAM [unless you have the scheduler end function implemented, in which case you need a stack to return to. A nice solution to this is to turn your main() function into a task before the scheduler starts and use this in place of one of your application tasks. I have not implemented this as part of the standard kernel as it uses more ROM for the extra functionality, maybe it should be a conditional compilation option?


RE: Calculating portMINIMAL_STACK_SIZE

Posted by Marcel van Lieshout on February 7, 2005
compare it to math-sections of the mplab port: WizC also has these ram-regions of varying size. Due to the nature of wizC, the size of this area is available as an assembler-definition.

When I would add this varying size to the size of the context-specific registers (sfr's, fixed size) and add the stack the task needs, I get a total size the new stack should be able to hold.

I am looking for a convenient way (without users that write tasks need to know about it) to do this calculation. I could, of course, define a wrapper for sTaskCreate(), but then I am sure confusion will arise when people read the freertos-api-docs (they won't use the wrapper but call sTaskCreate() directly.

About the original stack: use it as stack for the idle task??

RE: Calculating portMINIMAL_STACK_SIZE

Posted by Richard on February 7, 2005
>About the original stack: use it as stack for the idle task??

That might be a simpler alternative.

[ 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