embedded runtime_error ai_generated partial

HardFault_Handler: FORCED, bus fault at address 0x00000000

ID: embedded/hardfault-handler

Also available as: JSON · Markdown
55%Fix Rate
85%Confidence
3Evidence
2023-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
32 active

Root Cause

ARM Cortex-M hard fault. Null pointer, stack overflow, unaligned access, or invalid memory.

generic

Workarounds

  1. 85% success Read stacked PC/LR from exception frame to find faulting instruction
    In handler: read SP, stacked_pc = *(SP+24), look up in .map file
  2. 88% success Enable BusFault, MemManage, UsageFault handlers for specific info
    SCB->SHCSR |= (BUSFAULTENA | MEMFAULTENA | USGFAULTENA);
  3. 80% success Check stack size and add overflow detection
    FreeRTOS: configCHECK_FOR_STACK_OVERFLOW=2; Bare metal: fill stack with 0xDEADBEEF

Dead Ends

Common approaches that don't work:

  1. Add while(1) in HardFault handler and inspect PC in debugger 72% fail

    PC in handler points to handler itself, not faulting instruction. Read stacked PC from exception frame.

  2. Increase heap size assuming memory allocation failure 78% fail

    Hard faults are usually stack overflow or dangling pointers. Heap failures return NULL.

  3. Disable fault handlers to prevent stopping 92% fail

    Without handlers, faults escalate to lockup; processor halts until hardware reset