❓ Why Do Microcontrollers Use Memory-Mapped I/O?

In most microcontrollers, peripherals like GPIO, UART, SPI, and Timers are accessed as if they were normal memory locations.
Example:
C
GPIO->OUT |= LED1;
Behind the scenes, the CPU is simply reading or writing a specific memory address assigned to that register.
Example memory map:

0x00000000 → Flash  
0x20000000 → SRAM  
0x40000000 → Peripherals
So when firmware accesses:

0x40020014
the CPU is actually talking to a GPIO register, not RAM.
Why this design?
✔ Simplifies CPU design — same instructions for memory and peripherals
✔ Allows standard load/store instructions to control hardware
✔ Makes firmware development easier
✔ Enables compilers to generate simple and efficient code
💡 Key insight
Peripherals are not accessed with special instructions.
They are simply memory addresses mapped to hardware registers.
That’s why embedded firmware often looks like:

Memory → Register → Processing → Memory
#EmbeddedSystems #Firmware #Microcontrollers #EmbeddedLearning 

Comments

Popular posts from this blog

Why Do Microcontrollers Start with an Internal Oscillator?

What Happens Inside a Microcontroller in the First Few Microseconds After Power-On?

Why RISC is ideal for embedded systems