volatile
Understand why volatile is required when a value can change outside normal program flow, especially hardware registers and ISR-shared variables.
Use volatile for hardware-visible state; it does not make operations atomic and does not replace synchronization.
Embedded firmware sits directly between C language rules and hardware behavior.
Check the compiler, architecture reference manual and peripheral documentation together.
Verify the generated behavior with registers, debugger state and physical measurements.
Engineer’s checklist
- Read the MCU reference manual before coding.
- Identify the exact register, field, access width and reset value.
- Protect unrelated bits and respect reserved-bit rules.
- Build with warnings enabled and inspect diagnostics.
- Verify the result on the target hardware.
Use volatile for hardware-visible state; it does not make operations atomic and does not replace synchronization.