FreeRTOS cannot allocate enough RAM for all tasks

Hello, I already tried the solutions proposed in the following topic. https://www.freertos.org/FreeRTOSSupportForumArchive/February2016/freertosFreeRTOScannotallocateenoughRAMforalltasks_4f578a67j.html I am using the following setup: * Controller: Infineon TLE9879QXA40 with 128 kB Flash and 6kB ROM (Cortex M-3) * Compiler: Arm Compiler 5 In the uvision project is also the segger systemviewer included. I tried to start two tasks, one for feeding the watchdog and another for toggling a LED. In the following you can see the value of configTOTALHEAPSIZE -> 2500 (it’s the maximum setting that works) and the size of Systemviewer. I the value for the stack that is used for creating the tasks is 30. As soon as I want to create a third task I get the error “errCOULDNOTALLOCATEREQUIREDMEMORY” because FreeRTOS can not create the idle task.
  Code (inc. data)   RO Data    RW Data    ZI Data      Debug   Object Name

     0          0         92          0          0       2226   bootrom.o
     0          0          0          0          0       9280   event_groups.o
   316         46          0         24       2500       3626   heap_2.o
   156         30          0          0          0        499   int.o
     8          0          0          0          0       1680   isr.o
   148          0          0          0          0       2822   list.o
   418         94          0         48          0      24952   main.o
   758         76          0         16          0       9694   port.o
   196          4          0          0          0        568   port_1.o
   604         16          0          0          0       1093   scu.o
   776         54          0          0       1208       7577   segger_rtt.o
  2930        178         26         13       1291      24177   segger_sysview.o
   172         86          0          0          0       1482   segger_sysview_config_freertos.o
   368         30         88          4        160       3533   segger_sysview_freertos.o
    36          8        128          0        512        796   startup_tle987x.o
    40         14          4          0          0       1104   system_tle987x.o
  2590        326          0         60        200      17882   tasks.o
    16          0          0          0          0        455   tle_device.o
Can someone tell me why these “simple” tasks already need so much stack or what could be the problem in my project ? Thanks in advance

FreeRTOS cannot allocate enough RAM for all tasks

The table you posted does not tell you anything about the amount of run time stack the tasks will use, only the amount of compile time allocated RAM the different modules use. However, on the Cortex-M I think the minimum stack size is 70 words (so 70*4 bytes). If you have only allocated 30 words then I don’t think the tasks will run anyway. From a quick Google it looks like the TLE9879QXA40 has 6K of RAM, 2.4K of which is consumed by your SystemView configuration, 0.5K is consumed by your startup code (which is odd for startup code), and 200 bytes by FreeRTOS. That leaves you very approximately 3K (actually less) of RAM for everything else – hence you can’t have a heap much more then 2.5K. Of that 3K the Idle task stack will use at least 70*4 bytes, leaving something like 2.7K for everything else. Is that going to be enough for you? I would suggest removing dynamic allocation completely and instead statically allocate all your RTOS objects (https://www.freertos.org/StaticVsDynamicMemoryAllocation.html) – that way you will see at compile time, rather than run time, if you have enough memory.

FreeRTOS cannot allocate enough RAM for all tasks

With only 6KiB of RAM, an RTOS is NOT a good fit for your problem. Have you considered using Dunkel’s Protothreads? http://dunkels.com/adam/pt/ It is a way to implement state machines, without having to know how to implement statemachines.