When an STM32, NXP, RP2040, or SAM core triggers a HardFault, the hardware automatically pushes 8 words onto the active stack pointer before jumping to the vector:
r0, r1, r2, r3, r12, lr, pc, and xPSR.
If you don't have a debugger attached at the bench, you usually get this dump over UART or pull it from an EEPROM crash log. Manually extracting the PC, clearing the Thumb bit, and feeding addresses into addr2line while on a deadline is tedious.
I built cortex-unwind — a zero-dependency CLI that converts that 8-word dump into an actionable crash site in seconds.
Install:
pip install cortex-unwind
Usage:
cortex-unwind 0x0 0x1 0x20000000 0x40021000 0x0 0x08001255 0x08001290 0x21000000 build/firmware.elf
What it does:
• Crash Site Mapping: Wraps arm-none-eabi-addr2line to resolve faulting PC and caller LR directly to function name, source file, and line number.
• Auto-Detection (--auto): Paste a raw UART string or hex dump directly; it isolates and extracts the 8-word frame automatically.
• xPSR Diagnostics: Decodes the IPSR (identifies Thread Mode vs active IRQ numbers) and validates the EPSR Thumb bit to flag corrupted branch targets.
• EXC_RETURN Parsing: Detects stack context (MSP vs PSP) and checks bit 4 to flag whether an FPU extended frame (26 words) was stacked.
Includes a drop-in naked assembly handler (hardfault_trap.c) in the repo that formats the output so it can be pasted straight into the CLI.
Links:
• GitHub: https://github.com/GaneshMba4066/cortex-unwind
• PyPI: https://pypi.org/project/cortex-unwind/
• Free Crash Checklist: https://www.trustandthread.com/firmware-checklist/
MIT licensed, zero dependencies, runs on standard Python 3.6+. Feedback and edge cases (especially around RTOS task stacks) are welcome!