Finding CSTACK and HEAP for FreeRTOS embedded application ?

davinderpro wrote on Monday, February 05, 2018:

Our embedded application keep crashing VListinsertend after some time of operations.

Is this due to CSTACK and HEAP size ?

**FreeRTOS details
**

FreeRTOS 8.2 with heap 4 , Systick timer

osThreadDef(Task1, StartTask1, osPriorityRealtime, 0, 256);
osThreadDef(Task2, StartTask2, osPriorityHigh, 0, 196);
osThreadDef(Task3,StartTask3, osPriorityRealtime, 0, 256);
osThreadDef(Task4, StartTask4, osPriorityAboveNormal, 0, 196);

**MicroController is STM32F303CC
**
256 Kbytes of Flash memory
40 Kbytes of SRAM,
Routine booster: 8 Kbytes of SRAM on instruction and data bus, with HW parity check (CCM)

** Custom CSTACK and HEAP settings
**
CSTACK : 0X600
HEAP : 0X300

What should be the ideal CSTACK and HEAP size for the this kind of appilcations ?

rtel wrote on Monday, February 05, 2018:

Is this due to CSTACK and HEAP size ?

Could be, or it could be one of a number of different things, the level
of detail in your post only allows us to guess.

FreeRTOS 8.2 with heap 4 , Systick timer

I would recommend upgrading to a much newer version of FreeRTOS because
the later the version there more configASSERT()
calls there are to check you are configuring the system correctly. You
may find with a later version of FreeRTOS and configASSERT() defined to
something that halts execution you find the cause of your problem
immediately.

osThreadDef(Task1, StartTask1, osPriorityRealtime, 0, 256);
osThreadDef(Task2, StartTask2, osPriorityHigh, 0, 196);
osThreadDef(Task3,StartTask3, osPriorityRealtime, 0, 256);
osThreadDef(Task4, StartTask4, osPriorityAboveNormal, 0, 196);

This is not the native FreeRTOS API.

*MicroController is STM32F303CC

As this is an STM32 did you note the ‘special note for STM32 users’ on
this page: https://www.freertos.org/RTOS-Cortex-M3-M4.html that says you
must call NVIC_PriorityGroupConfig( NVIC_PriorityGroup_4 ); before
starting the scheduler?

256 Kbytes of Flash memory
40 Kbytes of SRAM,
Routine booster: 8 Kbytes of SRAM on instruction and data bus, with HW
parity check (CCM)

*Custom CSTACK and HEAP settings
*
CSTACK : 0X600
HEAP : 0X300

The cause won’t be one of these as the CStack is only used by interrupts
after the scheduler has started and if you are using heap_4 then the
heap set up by the compiler/linker will only be used if you call
malloc() directly yourself - FreeRTOS won’t call it.

Some links you might find helpful:
https://www.freertos.org/a00111.html
https://www.freertos.org/FAQHelp.html
https://www.freertos.org/Documentation/RTOS_book.html