Quality RTOS & Embedded Software

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




Loading

Stack and Heap Explanation

Posted by Franz on July 4, 2012
Hi!
I am using FreeRTOS and Keil with my STM32 Discovery Board.
It works fine but I just wanted to know why i have to change the Stack_Size from 0x00000400 to 0x00000200 and the Heap_Size from 0x00000200 to 0x00000000 for FreeRTOS to work. Also I cannot use the heap_3.c file in my poject, it always keeps hanging on the vApplicationMallocFailedHook() function. Unfortunately I didn't found anything about the Stack and Heap Configuration, except of http://www.freertos.org/a00111.html but this article didn't answer my questions.
Maybe someone can tell me more about how this works?

Thanks and best regards,
Franz

RE: Stack and Heap Explanation

Posted by MEdwards on July 4, 2012
“Stack_Size from 0x00000400 to 0x00000200 and the Heap_Size from 0x00000200 to 0x00000000”


You don't have to do that to get FreeRTOS to run, but you might have to do that to get your application to link if it is trying to use more RAM that the STM32 actually has.

Setting the heap to 0 is a good idea if you are using heap_1.c or heap_2.c, and the linker's allocated heap is not used. You must not set it to 0 if you are using heap_3.c though because heap_3 does use the linker's allocated heap.

Setting the stack size down just reduces the amount of RAM the linker is trying to allocate. On the STM32 that stack is used by main(), and then re-used by interrupts. 0x200 could be too small. The interrupt stack is not checked for overflow like the tasks stacks are. If you are using heap_1.c or heap_2.c then you can reduce configTOTAL_HEAP_SIZE a little to reduce the RAM that that consumes, to free up some room to allow you to increase the stack size a bit.

RE: Stack and Heap Explanation

Posted by Franz on July 5, 2012
Thanks for your answer! Now it becomes a little clearer.
As explained above I cannot use the heap_3.c file because it always hangs at the vApplicationMallocFailedHook() function. Thats because malloc() returns always NULL. I tried it with the Stack_Size of 0x00000400 and Heap_Size of 0x00000200 (default Setting of ST Microelectronics) . Is there any suggestion whats the problem here? Respectively is there any document which explains the Stack and Heap Management of FreeRTOS in detail?

Thank you, regards.
Franz


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




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

Latest News

FreeRTOS kernel V10 is available for immediate download. Now MIT licensed.


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

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