Skip to content
Tech Interview Prep
Technical interview guide

Microcontroller Architecture & Memory-Mapped I/O

How a microcontroller's CPU, memory, and peripherals are organized around a single address space, and the architectural tradeoffs between common MCU families.

Minutes to read
4
Practice MCQs
25
Interview Q&A
25
Edition
v4
Editorial status
Reviewed

Scope: Arm CMSIS 6 and Cortex-M programmer guidance; Linux MMIO ordering/accessor guidance; STM32 Cortex-M4 programming manual reviewed 2026-09-04.

Overview

Curated: · Written: · Reviewed:

Microcontroller Architecture & Memory-Mapped I/O

In one line

A microcontroller puts the CPU, flash, SRAM and peripherals in one address space, and a bus decoder routes each load or store to whatever answers at that address. Reach for this model whenever a question asks what a register access actually does, where it lands, and whether it has completed.

Key definitions

  • Bus decoder: logic that compares an address against region ranges and routes the transaction to flash, SRAM, a bridge or a device.
  • Device memory: memory type with no caching, merging or speculation. Every read and write is a side effect.
  • Posted write: a store that retires once the bridge accepts it, before the device has applied it.
  • W1C: write-one-to-clear. Writing 1 clears the flag, writing 0 leaves it alone.
  • Set/clear alias: a second address where a write touches only the bits set to 1, so no read-modify-write is needed.
  • VTOR: the register holding the vector table base. On ARMv7-M the base must align to the exception count rounded up to a power of two, minimum 128 bytes.

Formulas and complexity

Per APB transfer, with SETUP and ACCESS in PCLK cycles and bridge sync in HCLK cycles:

Txfer=2TPCLK+THCLKT_{xfer}=2 T_{PCLK}+T_{HCLK}

Worked (hypothetical SoC, HCLK 100 MHz): UART on PCLK 50 MHz costs 2 x 20 ns + 10 ns = 50 ns. Watchdog on PCLK 25 MHz costs 2 x 40 ns + 10 ns = 90 ns. One polling iteration is 140 ns. Stack check: Soverflow=2100−2048=52BS_{overflow}=2100-2048=52 B (ISR nesting 1200 B plus call chain 900 B, against a 2048 B MSP).

How it works

The core issues a load or store. The address and control signals go to the decoder, which picks the target. Bridges and wait states add latency, and the write may sit in a buffer.

Core load/store Bus decoder Flash 0x0800_0000 SRAM 0x2000_0000 AHB to APB bridge UART 0x4000_4000 Watchdog 0x4000_5000 System space 0xE000_0000

The address alone decides which device answers. Clock gating, reset and pin mux are prerequisites the decoder does not check, so an access can complete against a dead block.

When to use and when not to

SituationUseWhy
Plain config register, single ownervolatile pointer, one storeNo race, no side effect on the write
W1C status shared with an ISRWrite only the target bitRMW can clear an event that arrived in between
Single bit set or clear, sharedSet/clear alias or critical sectionOne bus write, no lost update
Next step depends on the writeDSB, then readback of a side-effect-free bitA posted write is only a request
FIFO data registerRead the full word onceEach read pops one entry
Polled peripheral bufferDevice attribute in the MPUNormal cacheable memory serves stale data

Traps interviewers probe

  1. volatile means atomic or ordered. It does neither. Fix: name the three layers (compiler, CPU/store buffer, bus completion) and cover each one with the right mechanism.
  2. Read-modify-write on a W1C register. The write-back clears flags you never read. Fix: write 1 to the target bit only, or use the clear alias.
  3. Assuming a store has taken effect. Fix: DSB, then read a side-effect-free register in the same block, and confirm on a logic analyzer.
  4. Shrinking the register struct. Deleting RESERVED0 moves SR from offset 0x10 to offset 0x04, so reads hit the wrong register. Fix: take offsets from the reference manual and add static asserts on offsetof.
  5. Globals used before startup copies .data. SystemInit runs before the .data copy and the BSS clear, so a value it reads is zero on cold boot and survives only a warm reset. Fix: do not read initialized globals before the copy, or use a hard-coded value.

Interview tips

Open with the three layers: volatile fixes compiler caching and ordering among volatile accesses, barriers fix CPU reordering, and only a completed device access (readback after DSB) shows the hardware did it.

Expect these follow-ups: a W1C race with an ISR (single owner, alias or critical section), why a debugger read can clear a flag or pop a FIFO, MPU Device attributes for a polled buffer, DMA coherency with cacheable memory, and what evidence you accept that a write worked (logic analyzer, readback, high-water mark).

30-second outline: "volatile stops the compiler caching or dropping the access, but it is not atomic and does not order the CPU or the bus. For a shared W1C register I write only the target bit or use the alias. For the next step I issue a DSB and read back a side-effect-free bit, then confirm on a probe. I check offsets against the reference manual and mark the region Device."

Feedback on this overview

Log in free to save your progress and keep bookmarks and notes for a quick revision before your interview.