FreeRTOS stack overflow hook [closed]

According to FreeRTOS documentation regarding stack overflow:

The application must provide a stack overflow hook function if configCHECK_FOR_STACK_OVERFLOW is not set to 0. The hook function must be called vApplicationStackOverflowHook(), and have the prototype below:

void vApplicationStackOverflowHook( TaskHandle_t xTask,signed char *pcTaskName );

And in FreeRTOS the following prototype is defined inside tasks.h file:

 /* Callback function prototypes. --------------------------*/ extern void vApplicationStackOverflowHook( xTaskHandle pxTask, signed char *pcTaskName );

So, I set configCHECK_FOR_STACK_OVERFLOW to 2 and implement the function in my application code:

void vApplicationStackOverflowHook( xTaskHandle pxTask, signed char *pcTaskName )
{ while (1) { /* my code. Prints stuff directly to the console*/ }
}

My question is whether or not this implementation is correct? i.e, the hook implementation is in my application code, and the declaration in tasks.h remains untouched.

3

1 Answer

Looks right to me. You will find many, many, many examples in the FreeRTOS/Demo directory of the FreeRTOS download. The rationale for using 2 rather than 1 is here:

You Might Also Like