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.

Read
54 min
Practice MCQs
25
Interview Q&A
25
Edition
v3
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.

Curated: · Written: · Reviewed:

25 questions

MCQ-2A Cortex-M4 board's memory map is: 0x0000_0000–0x1FFF_FFFF code, 0x2000_0000–0x3FFF_FFFF SRAM, 0x4000_0000–0x5FFF_FFFF peripherals, 0xE000_0000–0xE00F_FFFF system. A firmware declares `volatile uint32_t status;` and the linker script places it at 0x4000_1000. At runtime, `status` reads back a value that changes on its own, and writing 0 to it drives a hardware output low. The same source with `status` at 0x2000_1000 behaves as an ordinary variable. What explains the difference?
MCQ-1A team ports motor-control firmware from an STM32G474 (Cortex-M4 MCU) to a custom SoC built around a licensed Cortex-M4 core. On the SoC, the SPI NOR flash holding the firmware is mapped at 0x0800_0000, and the address decoder leaves 0x0000_0000 unmapped. The core locks up immediately after reset; the debugger reports a bus error on a fetch at 0x0000_0000. The same binary runs on the STM32G474. What explains the difference?
MCQ-9A firmware team ports a driver to a new MCU. The vendor's CMSIS device header declares `typedef struct { volatile uint32_t CR; uint32_t RESERVED0[3]; volatile uint32_t SR; } TIM_TypeDef;` and `#define TIM2 ((TIM_TypeDef *) 0x40000000UL)`. The reference manual lists TIM2_CR at offset 0x00 and TIM2_SR at offset 0x10. A teammate proposes deleting the `RESERVED0` array to shrink the struct, arguing the compiler will place `SR` right after `CR` anyway. What is the actual consequence of that edit?
MCQ-10A team is choosing between `volatile uint32_t` and `volatile const uint32_t` for a read-only status register mapped at a fixed address. What does adding `const` actually change?
MCQ-11An MMIO control register is reached through a `volatile uint32_t *` lvalue. The main loop sets bits with `*ctrl |= ENABLE;` while an interrupt handler sets other bits in the same register. In ISO C11, what does the `volatile` qualifier by itself guarantee about those accesses?
MCQ-13On a little-endian CPU, a driver reads a 32-bit device register with a plain load: `uint32_t v = *(volatile uint32_t *)reg;`. The device is big-endian and the register holds 0x0A1B2C3D, transmitted most-significant byte first on the bus. What does v contain?
MCQ-23A driver writes a 32-bit value to the MMIO address 0x40004001 on a Cortex-M4. The MPU maps that region as Device memory, and CCR.UNALIGN_TRP is 0. The compiler emitted a single STR for the write. What does the core do when it executes that STR?
MCQ-12An ARM Cortex-M driver polls a UART's RXFIFO at 0x4000_4000. The register is 32 bits wide and holds four received bytes per entry; the datasheet states that a read returns the oldest entry and advances the FIFO by one entry. The driver executes `uint8_t b = *(volatile uint8_t *)0x40004000;` and stores b. The link runs at 115200 baud, 8N1 (11,520 bytes/s), and the polling loop spins far faster than that, yet the application receives about 2,880 bytes/s and the overrun flag sets. What explains the loss?
MCQ-5A Cortex-M3 board boots on its 8 MHz internal oscillator, and a C function clock_init() switches it to 72 MHz by reading g_pll_cfg, a global initialized to 0x00040002 in .data. After a cold power-on the board stays at 8 MHz because clock_init() read 0x00000000. After NVIC_SystemReset() the same image reaches 72 MHz. SRAM on this device powers up as zeros. Why does the cold boot read 0x00000000 while the warm reset gets the correct value?
MCQ-7A Cortex-M firmware is ported to a new board and the linker script is rewritten for the new map: FLASH at 0x08000000 (1 MB), RAM at 0x20000000 (256 KB). The build links cleanly, the image is flashed, and the firmware runs. Every initialized global (`int counter = 7;`) reads back as 0, while `const` tables in flash read correctly. The map file shows `.data` at 0x20000000 (0x40 bytes) and `.bss` at 0x20000040 (0x100 bytes). The startup copy loop uses `_sidata`, `_sdata` and `_edata`. Which linker-script change explains the symptom?
MCQ-8On a Cortex-M4 board the vendor startup file's Reset_Handler calls SystemInit() and then branches to __main. An engineer adds a file-scope `volatile static uint8_t use_hse = 1;` to system_<device>.c and branches on it inside SystemInit() to select HSE or HSI as the PLL source. After a cold power-up the board runs from HSI; after NVIC_SystemReset() it runs from HSE. What explains the difference?
MCQ-6A firmware team relocates the Cortex-M4 vector table to SRAM at 0x20000000 for a bootloader handoff. Their copy routine writes the table to SRAM starting at 0x20000000, then the code sets VTOR = 0x20000000. The first interrupt after the handoff (IRQ 47, the last entry in the table) jumps to a garbage address. Dumping the copied table shows word 0 = 0x080001A5, word 1 = 0x08000211, word 2 = 0x0800022F, all odd flash addresses, and the stack top 0x20008000 appears nowhere in the table. What is the most likely cause?
MCQ-22A Cortex-M7 SoC maps SPI1's control register SPI1_CR at 0x40013000 and UART4's control register UART4_CR at 0x40004C00; both sit on APB2. Bring-up code runs: *(volatile uint32_t *)0x40013000 = 1; /* SPI1_CR */ v = *(volatile uint32_t *)0x40013000; /* read back */ v is 0x00000000 and no bus error is reported. On this SoC the APB2 bridge still completes an access to a peripheral whose clock gate is closed: the read data is 0x00000000 and the write is discarded. The MPU maps both register blocks as Device memory, neither peripheral's pins have been configured, and UART4_CR written and read back by the same code in the same mode returns the value written. The debugger reads CLK_APB2_EN as 0x00002000 and CLK_APB2_RST as 0x00000000; in this bit map SPI1's clock-enable is bit 12 and UART4's is bit 13. What should the driver do next?
MCQ-3An SoC runs HCLK (the AHB clock) at 100 MHz. Two status registers sit 4 KB apart in the same 64 KB peripheral window: a UART at 0x4000_4000 on APB1, whose PCLK is HCLK/2, and a watchdog at 0x4000_5000 on APB2, whose PCLK is HCLK/4. Both peripherals are clocked and both return correct data. In this SoC a single APB transfer costs two PCLK cycles (SETUP + ACCESS), and the AHB-to-APB bridge adds one HCLK cycle of synchronization per transfer. A polling loop reads the UART status register and then the watchdog status register, once per iteration. How long does one iteration take?
MCQ-16A timer block exposes EVENT_COUNT at 0x4000_4000. Each timer tick increments it by 1, and reading it returns the accumulated count and clears it to 0. Ticks arrive at 1 kHz. Firmware reads EVENT_COUNT once per second, at t = 1.000 s and t = 2.000 s, and adds each returned value to a running total. A debug probe also reads EVENT_COUNT once per second, at t = 0.500 s and t = 1.500 s, and discards its value. No other code reads EVENT_COUNT. What is the firmware's running total after its read at t = 2.000 s?
MCQ-14A driver brings up a peripheral whose 32-bit control/status register CTRL_STAT sits at 0x4003_0000. The reference manual defines it as: bits 31:16 reserved and required to be written as 1; bits 15:8 the MODE field; bits 7:0 W1C event flags, where writing a 1 clears that flag and writing a 0 leaves it unchanged. The register currently reads 0xFFFF_1205 (MODE = 0x12, flags 2 and 0 pending). The driver must set MODE to 0x2A and clear only flag 0. Which value should it write?
MCQ-15A UART status register at 0x4000_0010 is write-one-to-clear: bit 0 is RX_OVERRUN, bit 1 is TX_DONE, bit 3 is CRC_ERR. An interrupt handler reads 0x0000_000B, services only CRC_ERR, then executes `write32(STATUS, v & ~(1u << 3))`. What does that write do?
MCQ-17A 32-bit MCU has a status register at 0x4000'1000 whose bit 3 (READY) is set by the DMA controller in hardware and bit 0 (ENABLE) is written by firmware. The firmware ISR runs this on every transfer completion: ```c volatile uint32_t *STATUS = (uint32_t *)0x40001000; *STATUS |= (1u << 0); /* set ENABLE */ ``` A logic analyzer shows ENABLE sometimes stays 0 after the ISR returns, and READY occasionally reads 0 in the ISR even though the DMA has finished. The reference manual documents a write-1-to-set alias at 0x4000'1004 and a write-1-to-clear alias at 0x4000'1008. What is the correct fix?
MCQ-18A Cortex-M4 board drives eight status LEDs and one fault LED from a single GPIO output register. The main loop repaints the LED bits about 2,000 times a second, a fault ISR sets the fault bit, and both paths are written as a read-modify-write of the whole register (ODR = (ODR & ~mask) | value). On a scope, the LED pattern falls back to its previous value for roughly half a millisecond every time the ISR fires. The same port also exposes SET and CLR registers that alias the output latch (a 1 in a bit position acts on it, a 0 leaves it alone). Routing both paths through those aliases removes the snap-back because:
MCQ-24An interrupt service routine (ISR) on an ARM Cortex-M microcontroller clears a peripheral interrupt status flag via an MMIO write. Why must the firmware perform a read-after-write (or execute a memory barrier) before returning from the ISR?
MCQ-21An STM32H7 (Cortex-M7) driver polls a 32-bit FIFO data register at 0x40020100, and every read strobe to that address pops one word out of the FIFO. The MPU is enabled, the D-cache is enabled, and the 8 KB region 0x40020000-0x40021FFF is programmed with the Normal write-back, no-write-allocate attributes (TEX=0b000, C=1, B=1). The register pointer is volatile and the disassembly shows the LDR inside the polling loop. The loop reads the same word on every iteration even though a logic analyzer confirms the FIFO holds new data, and a bus trace shows exactly one 32-byte read covering 0x40020100-0x4002011F at the start, then no further accesses to that block. Why does the loop keep seeing that word?
MCQ-4A Cortex-M7 at 600 MHz runs with its I-cache and D-cache enabled, and the SRAM at 0x2001_0000 is mapped as normal cacheable memory. The CPU has already executed the 256-byte routine at that address, whose result is an immediate encoded in its instructions. A DMA engine then copies a new version of the routine into the same address, and the harness waits for the DMA transfer-complete flag before returning. The CPU calls the routine again through a function pointer and still gets the old result. What is the most likely cause?
MCQ-20A driver writes a doorbell register over MMIO to start an endpoint's DMA, then sets a flag in shared memory that a peer core polls, and the peer reads the DMA buffer as soon as the flag is set. The write is posted: the CPU store retires as soon as the transaction reaches the root complex, and the root complex may hold it for an unbounded time, since the platform manual documents no upper bound. The driver needs the endpoint itself to have seen the doorbell before the flag goes up. What should it do?
MCQ-19An ARM64 SoC (Cortex-A72, Linux 6.6) fronts an accelerator over PCIe. Per request the driver (1) fills a 64-byte descriptor in Normal Inner-Shareable cacheable memory, with the device marked DMA-coherent so no cache maintenance is needed, then (2) writes 1 to the doorbell at BAR0 + 0x0008, mapped Device-nGnRnE. The same code has run for years on x86_64 servers without a single failure. On the ARM64 board roughly 1 request in 10^4 is serviced from the previous descriptor (the accelerator logs len = 0), and the rate climbs with load; disassembly shows the descriptor stores and the doorbell store in program order. Which change fixes it?
MCQ-25An ARM Cortex-M7 MCU has a multi-layer AHB bus matrix. A multi-channel DMA controller with its own AHB master port streams ADC samples into a buffer in SRAM1, while the CPU runs a tight polling loop on a timer's MMIO registers; the loop's code and stack also live in SRAM1. Under heavy DMA traffic the polling loop and timer ISR entry show multi-cycle stalls that scale with DMA throughput and vanish when the DMA is idle. What causes the stalls?