0
votes

I'm using STM32F103R8T6 with RTOS with 2 threads

osThreadDef(ManagerTask, ManagerThread, osPriorityNormal, 0, 128);
  ManagerTaskHandle = osThreadCreate(osThread(ManagerTask), NULL);
  osThreadDef(RFIDTask, RFIDThread, osPriorityNormal, 0, 256);
  RFIDTaskHandle = osThreadCreate(osThread(RFIDTask), NULL);

when i try to give the any thread a stack size of >512, neither of the tasks run, but when using 128 and 256 as the above example everything is fine.

So how to i know the max total stack size that i can allocate for my threads ?

in my RTOS Config

#define configMINIMAL_STACK_SIZE                 ((uint16_t)128)
#define configTOTAL_HEAP_SIZE                    ((size_t)3072)
1
Do you create anything else provided by FreeRTOS like queues, mutexes or semaphores? Also, which heap implementation do you use? - Jacek Ślimok
I used STM32CubeMX to generate the RTOS config and TRUESTUDIO code template, i will use semaphores but not for now, the code doesn't include any queues or mutexes or semaphores - mustafabarakat
also i'm using HEAP3 for memory managment - mustafabarakat
If you use heap3 then configTOTAL_HEAP_SIZE has no effect, as heap3 is a simple wrapper for malloc and free, which uses your regular heap. - Jacek Ślimok
so i have to switch to another heap ? if so, what do you recommend ? - mustafabarakat

1 Answers

0
votes

If you use FreeRTOS keep in the mind that stack size value in words not in bytes! But configTOTAL_HEAP_SIZE in bytes!

In this conditions:

  • TaskA 512 words = 2048b
  • TaskB 128 words = 512b
  • Totaly have = 2560b

Almost 3072 :) so if you don't use other objects it will work but if you some increase stack or will use additional objects the heap will be depleted

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