Cheat sheet: Cortex-M fault registers

Every fault status bit in one place, with the steps to read a fault. Made to be printed.

Reading a fault in five steps

  1. Read HFSR. If FORCED is set, another fault was escalated: the cause is in CFSR.
  2. Read CFSR and split it: bits 7:0 are MemManage, 15:8 are BusFault, 31:16 are UsageFault.
  3. If MMARVALID or BFARVALID is set, read MMFAR or BFAR for the address that faulted.
  4. Find the stacked registers. Bit 2 of EXC_RETURN (the value in LR on handler entry) tells you which stack holds them: 0 means MSP, 1 means PSP.
  5. On Armv8-M with TrustZone, also read SFSR, and SFAR if SFARVALID is set.

Registers

RegisterAddressContent
CFSR0xE000ED28Configurable Fault Status: MMFSR, BFSR and UFSR
HFSR0xE000ED2CHardFault Status
MMFAR0xE000ED34MemManage Fault Address
BFAR0xE000ED38BusFault Address
SFSR0xE000EDE4SecureFault Status (Armv8-M with TrustZone)
SFAR0xE000EDE8SecureFault Address (Armv8-M with TrustZone)

Stacked frame

The processor pushes these eight registers on exception entry. Offsets are from the stack pointer selected in step 4.

OffsetRegisterUse
0x00 to 0x0CR0 to R3Arguments of the interrupted function
0x10R12
0x14LRWhere the interrupted function would have returned
0x18PCThe instruction that faulted, for precise faults
0x1CxPSRProgram status at the time

MemManage: CFSR bits 7:0

BitNameMeaning
0IACCVIOLInstruction fetched from a location that does not allow execution
1DACCVIOLData read or written at a location the MPU does not allow
3MUNSTKERRAccess violation while unstacking on exception return
4MSTKERRAccess violation while stacking on exception entry
5MLSPERRAccess violation during lazy floating-point state saving
7MMARVALIDMMFAR holds the faulting address

BusFault: CFSR bits 15:8

BitNameMeaning
8IBUSERRBus error on an instruction fetch
9PRECISERRBus error on a data access; the stacked PC points to the instruction
10IMPRECISERRBus error reported after the access; the stacked PC is not the cause
11UNSTKERRBus error while unstacking on exception return
12STKERRBus error while stacking on exception entry
13LSPERRBus error during lazy floating-point state saving
15BFARVALIDBFAR holds the faulting address

UsageFault: CFSR bits 31:16

BitNameMeaning
16UNDEFINSTRUndefined instruction executed
17INVSTATEInvalid execution state, often a branch to an address without the Thumb bit
18INVPCInvalid value loaded into the PC on exception return
19NOCPCoprocessor used while disabled or absent, typically the FPU
20STKOFStack limit exceeded (Armv8-M Mainline)
24UNALIGNEDUnaligned memory access
25DIVBYZERODivision by zero, when that trap is enabled

HardFault: HFSR

BitNameMeaning
1VECTTBLBus error while reading the vector table
30FORCEDA configurable fault was escalated to HardFault; read CFSR
31DEBUGEVTA debug event occurred while debug was not enabled

SecureFault: SFSR (Armv8-M with TrustZone)

BitNameMeaning
0INVEPInvalid entry point: a branch into Secure code that is not a valid gateway
1INVISInvalid integrity signature in the exception stack frame
2INVERInvalid exception return
3AUVIOLAttribution unit violation: Non-secure access to a Secure address
4INVTRANInvalid transition from Secure to Non-secure code
5LSPERRLazy floating-point state preservation error
6SFARVALIDSFAR holds the faulting address
7LSERRLazy state error

References

To decode a value without reading the tables, use the fault decoder.