ARM Cortex-M

# Cortex-M HardFault Decoder

Paste 32-bit hex dumps from SCB fault registers (`0xE000ED28`–`0xE000ED38`) to unpack active MemManage, BusFault, UsageFault and HardFault bits.

CFSR (0xE000ED28)Configurable Fault Status Register (32-bit hex)

HFSR (0xE000ED2C)HardFault Status Register (32-bit hex)

MMFAR (0xE000ED34)Ignored unless MMARVALID (bit 7) is 1

BFAR (0xE000ED38)VALID (BFARVALID=1)

Presets:

MMFSR \[7:0\] 0x00 MemManage byte

BFSR \[15:8\] 0x82 BFAR = 0x40005400

UFSR \[31:16\] 0x0000 UsageFault halfword

Active Flags 3 PRECISERR, BFARVALID, FORCED

| Register | Bit | Flag                                                       | Root cause                                                                                                                                                                                                                            | GDB check                                                          |
| -------- | --- | ---------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------ |
| BFSR     | 9   | **PRECISERR** Precise data bus error                       | Synchronous bus error on a data load/store: accessing an unclocked peripheral (RCC clock disabled), invalid MMIO offset, or bad pointer. Stacked PC points to the faulting instruction; BFAR holds the address when BFARVALID is set. | p/x \*(uint32\_t\*)0xE000ED38 # BFAR; x/2i \*(uint32\_t\*)($sp+24) |
| BFSR     | 15  | **BFARVALID** BFAR holds a valid faulting bus address      | Hardware latched the exact faulting MMIO or memory address in SCB->BFAR (0xE000ED38).                                                                                                                                                 | p/x \*(uint32\_t\*)0xE000ED38                                      |
| HFSR     | 30  | **FORCED** Forced HardFault (escalated configurable fault) | A MemManage, BusFault or UsageFault escalated to HardFault because its dedicated handler was disabled or priority was too low. Inspect CFSR bits above.                                                                               | p/x \*(uint32\_t\*)0xE000ED28 # CFSR                               |

## SCB fault register map (ARMv7-M / ARMv8-M)

| Register | Address    | Width  | What it holds                                                                             |
| -------- | ---------- | ------ | ----------------------------------------------------------------------------------------- |
| CFSR     | 0xE000ED28 | 32-bit | Packed MMFSR \[7:0\], BFSR \[15:8\], UFSR \[31:16\]. Write 1 to clear bits.               |
| HFSR     | 0xE000ED2C | 32-bit | Escalation status: bit 30 FORCED, bit 1 VECTTBL, bit 31 DEBUGEVT.                         |
| MMFAR    | 0xE000ED34 | 32-bit | Faulting data address for MemManage faults. Only trust when CFSR bit 7 (MMARVALID) is 1.  |
| BFAR     | 0xE000ED38 | 32-bit | Faulting bus address for precise BusFaults. Only trust when CFSR bit 15 (BFARVALID) is 1. |
| ACTLR    | 0xE000E008 | 32-bit | Set bit 1 (DISDEFWBUF) to disable write buffering when chasing IMPRECISERR.               |

## Quick GDB dump snippet

arm-none-eabi-gdb

```
# Print CFSR, HFSR, DFSR, MMFAR, BFAR, AFSR in one shot
x/6wx 0xE000ED28

# Inspect stacked exception frame (r0, r1, r2, r3, r12, lr, pc, xpsr)
# Check EXC_RETURN bit 2 in $lr: 1 = PSP, 0 = MSP
x/8wx ($lr & 4) ? $psp : $msp

# Disassemble the exact faulting instruction at stacked PC (+24 bytes)
x/4i *(uint32_t*)((($lr & 4) ? $psp : $msp) + 24)
```

## Reproducing HardFaults deterministically

Hardware probes show the wreckage after the fault lands. Under CircuitTwin GDB, run `reverse-stepi` from `HardFault_Handler` to walk straight back to the store or branch that corrupted the stack or hit an unclocked peripheral.

[Guide: Cortex-M HardFault CI triage](https://circuittwin.ai/guides/cortex-m-hardfault-ci-triage) [Board: NUCLEO-F767ZI](https://circuittwin.ai/boards/nucleo-f767zi) [Board: STM32F4-Discovery](https://circuittwin.ai/boards/stm32f4-discovery) [Tool: UART Baud Calculator](https://circuittwin.ai/tools/uart-baud-calculator) [Docs: GDB reverse execution](https://circuittwin.ai/docs/ide)

> ## Catch HardFaults before flashing silicon
>
> Run your compiled Cortex-M ELF on a deterministic board twin and step backward out of HardFault\_Handler in GDB.
>
> [Start now](https://app.circuittwin.ai/try) [GDB server docs](https://circuittwin.ai/docs/ide) [Connect a coding agent](https://circuittwin.ai/docs/agents)
