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


About Stack and Heap

Posted by Nobody/Anonymous on January 3, 2007
Have been struggling with stack and heap for days.
Now just want to some firm answers from somebody.
1) what's the maximum size of the stack for the task. (when you create a task, you need to pass a number into the function. somebody said this number cannot be more than 255).
2) when the program is running, what is the stack? Is the stack just used for function calls, or all so store all the temperary variables? My understanding is all the temperary variables and the local variables are in heap?
3) The heap and the stack, are they located in different location, or they overlap?

Please help, i am sinking..........

RE: About Stack and Heap

Posted by Richard on January 3, 2007
The maximum stack size that can be specified is 0xffff as the parameter in the xTaskCreate() function used to set the stack size is 16bits. Of coarse you are limited by the amount of RAM available in your system.

Note that the stack is specified as the number of variables that can be saved to the stack - so the number of bytes allocated depends on the size of the stack variables. For example, on a machine with a 32bit wide stack, requesting a stack size of 100 will result in 32*100 bytes being allocated for the stack.

How the stack is used is dependent on your compiler. Generally it holds function call return addresses, parameter values, local variables, etc. Just like any other C program.

The FreeRTOS.org heap is the area of memory you allocated for use by the kernel. When a task is created the memory used by the task comes from the heap (the task stack and the TCB structure). Likewise when you create a queue the memory used by the queue comes from the heap.

You may also setup a separate heap for use by your C program through the use of malloc and free library functions.


RE: About Stack and Heap

Posted by Nobody/Anonymous on January 3, 2007
Thank you very much Richard!

You are the man.

Your answer is very helpful.

More questions coming... (that's happens when you are trying to help people ... :-D)

I am using LPC2138, with 32K RAM.
I am using heap_1.c
What is the maximum size of heap I can use.
I have 9 tasks running. the total stack size is 40 * 128 * 4 = 20480 bytes.
#define configMINIMAL_STACK_SIZE( ( unsigned portSHORT ) 128 ) (portSTACK_TYPE is long , 4 bytes)

Does that mean i just need to set up the configTOTAL_HEAP_SIZE to 20480 bytes?

And what does the RTOS do with the (32K - configTOTAL_HEAP_SIZE)?



[ 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