cancel
Showing results for 
Search instead for 
Did you mean: 

FreeRTOS Tasks stack size on STM32L4

Dev1
Associate II

Hi all,

I am working on stm32l486 chip.

When I created (using CubeMx) two tasks with a stack size equal to 256 words. The project is running well:

osThreadDef(Task1, vTask1, osPriorityNormal, 0, 256);
Task1Handle = osThreadCreate(osThread(Task1), NULL);
 
osThreadDef(Task2, vTask2, osPriorityNormal, 0, 256);
Task2Handle = osThreadCreate(osThread(Task2), NULL);

The problem appears when I added a third task with a stack size equal to 256:

osThreadDef(Task3, vTask3, osPriorityNormal, 0, 256);
Task3Handle = osThreadCreate(osThread(Task3), NULL);

If I reduce the stack size of each Task to 128, the problem disappear.

Why I can't use 3 tasks with a stack size equal to 256 for each task ?

3 REPLIES 3
Piranha
Chief II

https://www.freertos.org/a00125.html

If a task is created using xTaskCreate() then the required RAM is automatically allocated from the FreeRTOS heap.

Look for configTOTAL_HEAP_SIZE configuration parameter in FreeRTOSConfig.h or corresponding CubeMX setting.

Sorry, "the problem" is a super vague/non-specific description.

If it can't allocate a stack look at the heap and related settings that might be limiting/constraining that.

The stack size needs to reflect your expected usage via call tree depth and local/auto variable usage in called subroutines.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Dev1
Associate II

Ok Thanks Piranha and Clive.