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


FreeRTOS heap and stack

Posted by nth0x on April 28, 2010
I do not understand how FreeRTOS manages memory. When new thread is created, where is his stack allocated, and how stacks for thread are organized. Is stack for thread localized in the heap, and what FreeRTOS do there when switch context. How FreeRTOS set thread stack pointer and handler stack pointer. I use Cortex-M3 and heap_3. I need some information for property handling _sbrk function, as that heap do not hook stack.

RE: FreeRTOS heap and stack

Posted by Richard Damon on April 28, 2010
While I am not familiar with anything special about the Cortex port, but in general FreeRTOS allocates memory from its heap, which if you are using heap_3 is the main program heap. Task stacks will be allocated from that heap. For task switching, inside the TCB buffer for each task is a saved copy of that tasks Stack pointer, which is restored when that task becomes active.

If you do not want task stacks to be placed on the heap, then you need to either change to heap_1 or heap_2 to allocate FreeRTOS items from a separate heap that FreeRTOS will manage. (This heap will include not just the stacks, but all FreeRTOS data structures). If you want just the stacks to go into a separate area, you will need to modify task.c to use a different function to allocate the stack space from the memory you want it to come out of.

RE: FreeRTOS heap and stack

Posted by nth0x on April 29, 2010
Thank you for reply richard_damon.

Cortex M3 has two modes Handle Mode (default mode after launch, a single stack pointer), and Handler Mode (non-privileged mode, additional stack pointer). I do not know whether FreeRTOS use it, which the index is saved when switching contexts. Initially when you start the program stack pointer points at the end of SRAM, later FreeRTOS already manages? What determines the value of configMINIMAL_STACK_SIZE (RTOSconfig), or is there still need some additional stack outside the reserved memory on the heap?

[ 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