From Silicon Labs: "Detecting Task Stack Overflows Through the Kernel's Red Zone Feature"
The following blog explains a simple way of detecting task stack overflows while debugging your Micrium OS application.
Micrium OS Kernel Red Zone
The kernel's red zone is a feature that, when enabled through OS_CFG_TASK_STK_REDZONE_EN in os_cfg.hcreates a monitored zone at the end of a task's stack. The length of the red zone is user-configurable via the #define OS_CFG_TASK_STK_REDZONE_DEPTH in os_cfg.h. By default, this is set to 8 stack elements (CPU_STK).
When the red zone is enabled, every time a task is switched out, either at the task level or at the interrupt level, the kernel checks if the red zone has been hit. By default, a software exception is thrown with the use of the CPU_SW_EXCEPTION macro in the ARMv7m port. However, if you want more control over what your application should do in the event that the red zone is hit, you can turn on the application hooks by setting OS_CFG_APP_HOOKS_EN to DEF_ENABLED in os_cfg.h.
Using the Red Zone Application Hook
If you decided that you want your application to determine what to do in the event that a task hits the red zone instead of throwing a software exception, then you will have to define a hook function to do so.
A simple example:
|
With that, you can tell that if you see LED0 permanently on and with your code trapped at the while loop you have hit the red zone. You can then check p_tcp->NamePtr in your local variables panel and find what was the task that hit the limit.
Don't forget to assign the red zone hit hook pointer to your custom function. Using the example above:
|
Make sure that this is added prior to calling OSStart() otherwise the pointer is never assigned to your application hook.
For more details about detecting stack overflows and the red zone, visit the following link: https://www.micrium.com/detecting-stack-overflows-part-2-of-2/
Source: https://www.silabs.com/community/blog.entry.html/2018/11/15/detecting_task_stack-n5rs