Task crashes after X hours

I am working on a Freertos non arm based project. And running in to an issue that my task crashes this could be because the task overflows however this only happens after X hours I used the watermark feature to check how much my task has left this seems to be in a valid range.

I also used memory leak tools to detect memory leaks in the implementation no issues found.

During debugging when you stepback at the crash I can see that my tasks stack is inside a different task.

How can I find the reason why this is happening i tried to use hardware breackpoints on the end of the task but no luck.

Hi @Dumpie124,
This page gives some options for detecting stack overflows FreeRTOS stack usage and stack overflow checking - FreeRTOS™.

Could you supply any example code, version of FreeRTOS-Kernel, and architecture you are using FreeRTOS on?

Have you tried simply increasing the stack size of the task that is overflowing?

Hi @jasonpcarroll,

I am using a PowerPC architecture, milticore architecture, the free rtot version is 10.4.6 version 4.0.

To answer your question I am indeed using stackoverflow detection however I am using option 2. Did not try option 1yet. Increasing the stack will only help a slight bit, i have the feeling I am heaving a fragmentation issue.

Tried to rule out some things with advanced linters but i would love to see the stack pointer just 1 step before the crash.

What would you do with that information? I would examine the SP at the time of crash and see if it is out of bounds. Another way is to create the task using xTaskCreateStatic and reserve some memory before and after the stack space used for the task. You can then put data breakpoints at the reserved memory locations to catch stack overflows.

#define STACK_SIZE 512

StaticTask_t xTaskBuffer;
StackType_t xStack[ STACK_SIZE + 2 ]; /* Reserve 2 extra slots - xStack[ 0 ]
                                       * and xStack[ STACK_SIZE ]. */

xHandle = xTaskCreateStatic( TaskFunction,
                             "Task_Name",
                             STACK_SIZE, /* The 2 extra slots are not used for
                                          * stack and therefore, should not
                                          * change unless there is an overflow.
                                          * */
                             NULL,
                             tskIDLE_PRIORITY,
                             &( xStack[ 1 ] ), /* xStack[ 0 ] is reserved. */
                             &( xTaskBuffer ) );

/* Now put data breakpoints on &( xStack[ 0 ] ) and &( xStack[ STACK_SIZE ] ).
 */

1 Like