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


HEAP utilization

Posted by Anu123 on June 16, 2011

Can anyone explain the relationship among the following three.
1. configTOTAL_HEAP_SIZE defined in FreeRTOSConfig.h

2. STACK_SIZE given when creating a task using xTaskCreate( vTaskCode, "NAME", STACK_SIZE, &ucParameterToPass, tskIDLE_PRIORITY, &xHandle );

3. Min Free Stack value given by the FreeRTOS state viewer Tasks during debugging with IAR

I am using STM32L

Thank you.

RE: HEAP utilization

Posted by Richard on June 16, 2011
See http://www.freertos.org/a00111.html for configTOTAL_HEAP_SIZE and how task stacks use it. Also, but less useful http://www.freertos.org/a00110.html

http://www.freertos.org/a00125.html gives the prototype for the xTaskCreate() function, and says how stack sizes are specified. The stack is allocated from the heap as per the first link above.

The minimum free stack size is I think explained in the application note that comes with the IAR plug-in, but is the same as described here: http://www.freertos.org/uxTaskGetStackHighWaterMark.html


RE: HEAP utilization

Posted by Anu123 on June 16, 2011
Thanks for your immediate reply Richard.

Still having problems and needs clarifications.

My RAM is 10KBytes.
From that 1KB has to be reserved for the CSTACK.

13 tasks are created in my application. Total of 3328 bytes are allocated for the stack size of those tasks during xTaskCreate() function calls. Each task was given different stack sizes so that they will not have excess memory. (All having less than 100 minimum free stack each)

According to the map file the aggregation of RAM of all other files are around 1Kbytes.

Total of all above is (1K + 3.3K + 1K) 5.3K. However we cannot run the system with configTOTAL_HEAP_SIZE less than 8Kbytes.

Please explain what happens to the (8K - 5.3K) RAM, which is not used by my files/functions.

Note that I am using heap_2.c


RE: HEAP utilization

Posted by Dave on June 16, 2011
Do you really need the CSTACK once the tasks have started? CSTACK is normally used by main(), but after the scheduler has started each tasks have their own stacks and CSTACK is not required any more. You can then recycle CSTACK for other uses, and normally find its start address from the variables defined in the linker script. If that is the case or not depends on the port and microcontroller you are using. Some ports reuse CSTACK as an interrupt stack.

RE: HEAP utilization

Posted by Dave on June 16, 2011
I was a bit hot on the add reply button there...

You cannot magic more RAM into a microcontroller, but you can select one from the same family that has more unless minimum recurring production code is really vital. However, another thing to consider is if you can cut down the number of tasks you have running. If some of the tasks perform periodic or run to completion functionality then you could implement them as timer callback functions instead of a task. All timer callbacks use the same stack as the timer task. If you can implement two tasks as timer callback functions, but add the timer task, overall you have still saved one entire stack of RAM.

[ 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