Hard fault handler
Posted: Wed Oct 02, 2019 9:23 pm
Hi, I've contributed a generic fault handler mechanism, particularly for ARMv7m (Cortex M3/M4(F)/M7).
The fault handlers include:
- HardFault handler, which decodes the fault registers and generates a description string.
- _unhandled_exception handler, which decodes the active vector, so you can effectively see which interrupt was triggered.
The HardFault handler (here) does the following:
- Switches to a separate stack (in case of a corrupt SP).
- Decodes the hard fault registers (done in C).
- Calls an application-defined hook
- Creates an artificial stack frame for the debugger and causes a breakpoint, in order for GDB to show a meaningful stack unwind, so you can see the whereabouts of the instruction that caused the fault.
- If no debugger is attached, restores the separate stack and calls chSysHalt("hard fault")
The _unhandled_exception handler:
- Decodes the active vector, so you can effectively see which interrupt was triggered.
- If no debugger is attached, calls chSysHalt("unhandled exception")
Also, I included a demo project (here). Any suggestions are welcome!
Cheers,
Diego.
The fault handlers include:
- HardFault handler, which decodes the fault registers and generates a description string.
- _unhandled_exception handler, which decodes the active vector, so you can effectively see which interrupt was triggered.
The HardFault handler (here) does the following:
- Switches to a separate stack (in case of a corrupt SP).
- Decodes the hard fault registers (done in C).
- Calls an application-defined hook
- Creates an artificial stack frame for the debugger and causes a breakpoint, in order for GDB to show a meaningful stack unwind, so you can see the whereabouts of the instruction that caused the fault.
- If no debugger is attached, restores the separate stack and calls chSysHalt("hard fault")
The _unhandled_exception handler:
- Decodes the active vector, so you can effectively see which interrupt was triggered.
- If no debugger is attached, calls chSysHalt("unhandled exception")
Also, I included a demo project (here). Any suggestions are welcome!
Cheers,
Diego.