Memory Mapped IO and Volatile
Talk to hardware registers safely with volatile and memory-mapped I/O.
Memory-Mapped I/O
On microcontrollers and embedded systems, hardware registers appear as memory addresses. Read or write them like normal memory — but the compiler must not optimize the accesses away.
Why volatile?
The volatile qualifier tells the compiler that a variable s value can change outside the program (interrupts, hardware). Every access must happen exactly as written.
volatile uint32_t* GPIO = (uint32_t*)0x40020000;
*GPIO = 0x01; // write must happen
uint32_t v = *GPIO;All lessons in this course
- Constraints in Embedded No RTTI No Exceptions
- Memory Mapped IO and Volatile
- Real-Time Considerations and Latency
- Cross-Compilation for ARM Targets