Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


Loading

Create a task uses how much heap?

Posted by Bonanza35 on January 8, 2009

Where can I find out how much heap is used in creating a task, and what things affect the amount of heap used? I know it's going to be different for different platforms. I'm using an ARM7 and it seems like the minimum is 404 bytes, often 532 or 660 bytes, and one of my tasks uses 812 bytes off the heap on creation. Do these all look reasonable, and why the differences?

RE: Create a task uses how much heap?

Posted by Dave on January 8, 2009
Ram used = sizeof( tskTCB ) + ( usStackSize * sizeof( portSTACK_TYPE ) )

usStackSize is the parameter passed to xTaskCreate().
portSTACK_TYPE is unsigned long on an ARM7.

There may also be a couple of extra bytes to ensure the correct alignment.




RE: Create a task uses how much heap?

Posted by Bonanza35 on January 8, 2009

>>> Ram used = sizeof( tskTCB ) + ( usStackSize * sizeof( portSTACK_TYPE ) )

Good afternoon, Dave.

How much of that comes from the heap? I assume (usStackSize * sizeof(portSTACK_TYPE)) goes in the stack area, right?

Heap usage for tasks startups for three representative tasks are 404, 532, and 660 bytes. Stack allocations are 64, 96, and 128 respectively. Per the formula above, then, the RAM usage should be 396, 524, and 652 respectively. Each calculated value is 8 bytes below the actual value, so I assume the extra 8 bytes are overhead plus alignment.

It does look like each task is taking heap memory for its stack. Project configuration for the IAR compiler has a STACKS segment (576 bytes) and a HEAP segment (10752 bytes). If the tasks build their stacks on the heap, what is the STACKS segment for?

RE: Create a task uses how much heap?

Posted by Dave on January 9, 2009
>How much of that comes from the heap? I assume (usStackSize
>* sizeof(portSTACK_TYPE)) goes in the stack area, right?


The memory is used as the stack for the task but comes from the FreeRTOS heap - heap_1, heap_2, heap_3, or whatever you have used.

The stack segment is used for main() before the kernel starts but can be used for whatever you like after that. You can use it for the IRQ stack to avoid allocating memory for both.

The heap segment setup by the compiler is only used if you are using heap_3 or calling malloc() directory (instead of pvPortMalloc). If you are not doing either of these then set it to its minimum value, probably 4.


[ Back to the top ]    [ About FreeRTOS ]    [ Privacy ]    [ Sitemap ]    [ ]


Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

Meet Richard Barry and learn about running FreeRTOS on RISC-V at FOSDEM 2019

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


Careers

FreeRTOS and other embedded software careers at AWS.



FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Renesas

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

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

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner