Fault exceptions

Arm® Cortex®-M processors implement an efficient exception model that traps illegal memory accesses and several incorrect program conditions.

The HardFault exception is always enabled and has a fixed priority (higher than other interrupts and exceptions, but lower than non-maskable interrupt NMI). The HardFault exception is therefore executed in cases where a fault exception is disabled or when a fault occurs during the execution of a fault exception handler.

All other fault exceptions (MemManage fault, BusFault, UsageFault…) have a programmable priority. After reset, these exceptions are disabled and may be enabled in the system or application software using the registers in the System Control Block (SCB).

In the examples, main.c provides a specific HardFault handler. All faults are escalated here by default. This handler updates the example execution status and can be used to track back the origin of the fault.

120/** Redefines the HardFault handler from the startup file.
121  * brief:  Hard Fault Handler
122  * retval: None (infinite loop)
123  *
124  * The default handler is redefined here so that:
125  * 1. The example status can be updated.
126  * 2. You can easily set a breakpoint to investigate the issue.
127  */
128void HardFault_Handler(void)
129{
130  /* The example encountered an unrecoverable error */
131  ExecStatus = EXEC_STATUS_ERROR;
132
133  /* Take a chance to turn the status LED off (this might fail) */
134  led_off(MX_STATUS_LED);
135
136  /* Unrecoverable error: infinite loop */
137  while (1);
138}

Note

The line numbers in the code snippet above are indicative. The actual line numbers may vary depending on the example you are using. This function is usually the last one in the file.