embedded
runtime_error
ai_generated
true
HardFault: Unaligned flash write at address 0xNNNNNNNN
ID: embedded/flash-write-alignment
85%Fix Rate
84%Confidence
3Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| any | active | — | — | — |
Root Cause
Flash memory write failed due to incorrect alignment (most MCUs require word-aligned writes).
genericWorkarounds
-
90% success Ensure write address is aligned to flash word size
addr & ~(FLASH_WORD_SIZE-1) for alignment check
-
85% success Use HAL flash programming functions that handle alignment
HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, aligned_addr, data)
Dead Ends
Common approaches that don't work:
-
Write individual bytes to flash
88% fail
Most flash controllers require 32-bit or 64-bit aligned writes.
-
Cast any pointer to flash write address
85% fail
Misaligned address causes HardFault on Cortex-M.