0Pricing
C++ Academy · Lesson

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

  1. Constraints in Embedded No RTTI No Exceptions
  2. Memory Mapped IO and Volatile
  3. Real-Time Considerations and Latency
  4. Cross-Compilation for ARM Targets
← Back to C++ Academy