Recover from SW Errors in FreeRTOS Tasks

Hello,
I just started using FreeRTOS, and whenever I have the slightest sw_fault (e.g. NULL Pointer Dereference, Task that have returned instead of vTaskDelete() it halts my entire system, and not just the Task that caused the error.

also, my try{}catch(...){} blocks don’t seem to work.

How can I Tell FreeRTOS to be more kind to me:

  1. keep running the remaining Tasks (so I can get monitoring info and debug what happened)
  2. throw an exception to the CATCH block
  3. emit to console and skip the problematic code
  4. some global handler to see where does it come from ?

anything would be super.

First, you need to make sure your compiler generates thread-safe exception processing, or exceptions may not work correctly.

Also, if you want to catch an exception in a task, you need the try() … catch() structure in the task itself, as tasks don’t have the context to let an exception escape out of them.

Also, because FreeRTOS is a lightweight system, it isn’t keeping tasks isolated well enough to let you abort one and let the rest continue. Comparing to a “big” OS, FreeRTOS tasks are more like Threads than Processes.

Depending on the processor, sometimes it is possible to insert code in the processor exception traps (for things that cause HARDWARE exceptions) that can tell you where the exception came from, like the PC address that faulted, and you can look at the current task control block to see what task was running. Normally I set a breakpoint in the exception vector and use the debugger to try to figure out what went wrong.

For this one, some ports provide configTASK_RETURN_ADDRESS which you can set to a function of your choice and put an assert in that function. This is for debugging aid during development.