D

DIY Electronics

— Building circuits, programming microcontrollers, and making things blink
49 members Created Jun 2026

LiPo charging and protection circuit from scratch

Debugging Firmware Crashes with GDB

A HardFault on an ARM Cortex-M processor without a debugger attached is frustrating. Here's how to extract meaningful information.

With a J-Link or STLink attached, OpenOCD plus GDB lets you catch the fault and inspect registers. The key registers: CFSR (Configurable Fault Status Register) at 0xE000ED28 tells you what kind of fault occurred (bus fault, usage fault, memory management fault). BFAR (Bus Fault Address Register) at 0xE000ED38 tells you the address that caused a bus fault — often a null pointer dereference.

For production systems without a debugger, implement a HardFault handler that saves key registers (PC, SP, LR, CFSR) to a reserved region of non-volatile memory (Flash or EEPROM), then reboots. On next boot, check if the fault region has valid data and log it. This gives you post-mortem crash diagnostics from deployed hardware.

12

Report thread

Why are you reporting this thread?

Restore the redacted content?

This will make it visible to everyone again. The clear action is logged in the mod log.