Catch a Cortex-M HardFault on the target

Stop the core when it faults (vector catch), read CFSR, HFSR and the fault address, unwind the stacked frame and name the faulting function from the ELF.

How to use it

  1. Connect the probe and load the ELF.
  2. Tick “Stop on faults”: the core then halts at the first instruction of the fault handler.
  3. When it faults, the fault registers and the stacked frame are read and explained: what kind of fault, at which address, in which function, called from where.

Questions

What if the core is already stuck in the handler?

Use “Halt and read”. If the handler is a plain endless loop, LR still holds EXC_RETURN and the frame is found. If the handler called functions, LR has changed: use the fault decoder with the values your handler saved.

Does vector catch survive a reset?

Yes: the debug registers are only cleared by a power cycle, and the reset buttons here keep the setting.

Related tools

  • Cortex-M debugger in the browser (ST-LINK, CMSIS-DAP): Halt, step and reset an Arm Cortex-M; watch and write global variables from the ELF live with plots; SEGGER RTT terminal; live SVD peripheral registers; breakpoints, watchpoints and HardFault capture. Over WebUSB, nothing to install.
  • Live variable watch and plot from an ELF: Pick global variables from the ELF and read them through ST-LINK or CMSIS-DAP while the firmware runs: values, min/max, writes, strip-chart plots and CSV recording.
  • SEGGER RTT viewer in the browser: Find the RTT control block in RAM and read every up channel while the core runs; send input to the down buffer. Works with ST-LINK and CMSIS-DAP, not only J-Link.
  • Live peripheral registers from an SVD: Read every register of a peripheral through the probe and decode its fields and enumerations from the SVD, live; write a field.
  • Microcontroller memory viewer and editor: Read RAM, flash or peripheral space through the probe as a hex dump that highlights what changed; write 8, 16 or 32-bit values; save a dump.
  • Flash STM32, ESP32 and RP2040 from the browser: Program HEX/S19/BIN/UF2 into an STM32 (UART bootloader, USB DFU, ST-LINK or CMSIS-DAP), an ESP32 or ESP8266 (ROM loader) or an RP2040/RP2350 (PICOBOOT or UF2); verify and read back.
  • Register viewer (SVD): CMSIS-SVD peripherals, registers and bit fields; decode a value; find the register at an address; C defines.

Also useful for: hardfault debug, catch hardfault, vector catch, cfsr, bus fault, stacked pc, fault handler.