Memory Mapped I/O

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/20

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 10:52 PM on 5/21/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

21 Terms

1
New cards

What is a flip flop?

  • Fundamental unit of digital memory

  • Registers are rows of flip flops

  • Register: small storage very close to CPU for quick access

2
New cards

What are control registers?

  • Sets of flip flops whose inputs/outputs connect to other system components

  • Mapped directly to specific hardware (unlike normal registers for computation)

  • Example: bit 3 of GPIO register might mean "pin is output mode", bit 7 might mean "pin is currently HIGH"

3
New cards

What are the two methods for interacting with control registers?

  • Special IO Instructions (dedicated IO commands like x86 IN/OUT)

  • Memory Mapped IO (IO registers have addresses in main memory space)

  • Some CPUs use a mix of both

4
New cards

What are characteristics of Special IO Instructions?

  • IO registers live in separate IO address space (no main memory consumed)

  • Separate space typically much smaller than main memory space

  • Dedicated IO instructions increase ISA size; instruction bits are precious

  • Only specific IO addressing modes available (no pointer arithmetic or array indexing)

  • IO instructions bypass cache by design (no cache coherency headaches)

5
New cards

What are characteristics of Memory Mapped IO?

  • IO registers sit in reserved regions of main address space (consumes addresses that cannot be used for RAM)

  • Any normal load/store instruction works (all addressing modes available for free)

  • No new instructions needed (keeps ISA lean)

  • Cache complications: IO regions must be marked non-cacheable (use volatile)

6
New cards

What is the typical microcontroller memory layout pattern?

  • General-purpose registers at bottom

  • I/O registers immediately above

  • Internal RAM above that

  • Optionally external RAM at top

  • Even CPU registers mapped into memory address space (accessible by address and register name)

7
New cards

What is the GPIO three-register pattern?

  • Data register (PORTF): value to drive on output pins

  • Data direction register (DDRF): per-bit, sets pin as input (0) or output (1)

  • Input pins register (PINF): read-only, reflects actual electrical state of pins

  • Each bit corresponds to one physical pin (same pattern on every microcontroller)

8
New cards

How are registers accessed in C without hardcoding hex addresses?

  • Vendor's io.h header provides #define statements

  • Human-readable labels (e.g., DDRF) resolve to correct address for target chip

  • Same C source can target different chips by including different header (portability through indirection)

9
New cards

What are the standard C bitwise patterns for register manipulation?

  • Set bit: REG |= (1 << n)

  • Clear bit: REG &= ~(1 << n)

  • Toggle bit: REG ^= (1 << n)

  • Test bit: (REG >> n) & 1 or REG & (1 << n)

10
New cards

What is a bit mask used for?

  • Operate on multiple bits at once

  • Example: REG |= 0b00001100 sets bits 2 and 3

  • Compiles to read–modify–write sequence (CPU loads register, modifies bits, writes back)

11
New cards

Why is volatile necessary for MMIO register accesses?

  • Without volatile, compiler can cache value in CPU register (missing hardware updates)

  • Compiler can eliminate "redundant" writes never read by program

  • Compiler can reorder accesses for performance (breaking required hardware sequencing)

  • volatile forces every read and write in source to actually be emitted

12
New cards

What is the typical pattern for a raw MMIO pointer?

  • volatile uint32_t *reg = (volatile uint32_t *)0x40014000;

  • *reg = 0x01 (guaranteed write to hardware)

  • uint32_t v = *reg (guaranteed read from hardware)

13
New cards

What are the two situations where volatile must be used?

  • Memory-mapped hardware registers

  • Variables shared between an ISR and the main code

  • Cost is loss of optimisation for that variable (every access goes to memory - intentional)

14
New cards

What goes wrong without volatile in while (*PORT)?

  • Compiler can read PORT once, cache it, turn loop into infinite loop

  • For hardware register, value can change behind compiler's back (set by hardware or interrupt)

  • volatile tells compiler never cache: re-read every time

15
New cards

What are the differences between MMIO and PMIO for Access?

  • MMIO: Normal load/store

  • PMIO: Special IN / OUT instructions

16
New cards

MMIO vs PMIO: Addressing modes

  • MMIO: All available

  • PMIO: Port address only

17
New cards

MMIO vs PMIO: Risk of accidental writes

  • MMIO: Higher (stray pointer can corrupt I/O)

  • PMIO: Lower

18
New cards

MMIO vs PMIO: Cacheable?

  • MMIO: No (peripheral state changes outside CPU)

  • PMIO: N/A

  • Device memory must never be cached (UART receive register would forever read same byte)

19
New cards

MMIO vs PMIO: Used by

  • MMIO: AVR, ARM

  • PMIO: x86 legacy

20
New cards

What are the four GPIO bit manipulation idioms?

  • REG |= (1 << PIN) (set bit, output high)

  • REG &= ~(1 << PIN) (clear bit, output low)

  • REG ^= (1 << PIN) (toggle)

  • if (REG & (1 << PIN)) (test if bit is set)

21
New cards

How do you enable internal pull-up resistor for GPIO inputs?

  • Write a 1 to the corresponding PORT bit

  • Otherwise unconnected pin floats and reads random voltages

  • For inputs: pull-up prevents floating pin behaviour