5.5.1 · D1Embedded Systems & Real-Time Software

Foundations — Microcontroller architecture — ARM Cortex-M series (M0, M3, M4, M7)

3,028 words14 min readBack to topic

Before you can read the parent note ARM Cortex-M Series, you need every word and symbol it throws at you. We build each one from nothing, in an order where each idea leans on the one before it.


1. Bit, byte, and "32-bit"

Picture it: imagine 8 light switches in a row. Each switch is a bit; the whole row is a byte. The pattern of ON/OFF switches is the number stored.

Figure — Microcontroller architecture — ARM Cortex-M series (M0, M3, M4, M7)

Why "32-bit"? When the parent says Cortex-M is a 32-bit core, it means the CPU's basic "hands" — the registers it does math with, and the addresses it points at — are 32 wires wide. That gives:


2. Hexadecimal — reading 0x40020000

Why does embedded code love hex? Because one hex digit is exactly 4 bits. So two hex digits = 1 byte, and 8 hex digits = 32 bits. An address like 0x40020000 is 32 bits written compactly.

Question: how many bits does the hex number 0x40020000 represent?
8 hex digits × 4 bits = 32 bits.

3. Memory as a giant numbered street

Figure — Microcontroller architecture — ARM Cortex-M series (M0, M3, M4, M7)

Why the topic needs this: the parent says peripherals are memory-mapped — a GPIO control register "lives at" 0x40020000. That means one specific house on this street is wired not to a memory cell but to a physical pin controller. Writing a number into that house toggles hardware. See Memory-mapped I/O and GPIO.


3b. Multi-byte values: endianness and alignment

A single house holds one byte. But a 32-bit value needs four houses in a row. Two low-level rules decide how those four bytes sit — and getting them wrong corrupts every load and store.

Figure — Microcontroller architecture — ARM Cortex-M series (M0, M3, M4, M7)

Why it matters here: when you read a peripheral register or a value in memory, the CPU reassembles the bytes using this order. If you assumed the wrong order (say, sharing data with a big-endian device), the number comes out scrambled. So "little-endian" is a fact you must carry into every memory-mapped I/O discussion.

Recall On a little-endian Cortex-M, where does the least-significant byte of a word go?

Into the lowest address of the four houses.


4. Registers — the CPU's pockets

Picture it: if memory is a warehouse across town, registers are the few items in your pockets — instant to reach, but you only have a handful. The CPU can only do math on values sitting in registers, so work is a constant shuttle: load from memory → compute in registers → store back.

The named registers the parent lists (and you must recognise):

Name Plain meaning
R0R12 general-purpose pockets for your data
PC (Program Counter) address of the next instruction to run
LR (Link Register) the "return address" — where to go back to after a function
xPSR status flags (was the last result zero? negative? etc.)
MSP / PSP two different Stack Pointers (see §7)
Recall Why can't the CPU compute directly on memory?

Because arithmetic hardware is wired only to the registers. Memory is reached only through explicit load/store steps — this simplicity keeps the core small and low-power.


5. Instruction, and the Fetch–Decode–Execute rhythm

The CPU repeats a three-beat rhythm forever:

  1. Fetch — read the next instruction from memory (address given by PC).
  2. Decode — figure out what it means.
  3. Execute — actually do it.
Figure — Microcontroller architecture — ARM Cortex-M series (M0, M3, M4, M7)

Why the topic needs this: if each instruction waited for all three beats, one instruction = 3 clock ticks. The pipeline (parent §1) overlaps them like an assembly line — this rhythm is exactly what a pipeline speeds up. See Pipelining and superscalar execution.


6. Thumb / Thumb-2 — the language the CPU speaks

Why smaller matters here: embedded chips have tiny memories. A shorter encoding means more program fits in the same flash, and fetching costs fewer bytes. RISC (Reduced Instruction Set Computer) means the vocabulary is deliberately small and regular — simpler to build, easier to pipeline.


7. The stack, and why there are two

Figure — Microcontroller architecture — ARM Cortex-M series (M0, M3, M4, M7)

First, one hardware term we are about to lean on:

Why the topic needs it: when an interrupt fires, the CPU must push your current registers onto the stack so it can restore them later — the "automatic stacking" the NVIC does. And functions push their return address (LR) and locals here.

Why TWO stacks (MSP + PSP)? So a normal task's scratch pile (PSP) is kept separate from the interrupt/kernel pile (MSP). If one task overflows its stack, it cannot smash the kernel's. This split powers RTOS isolation — see RTOS task scheduling and context switching.


8. Interrupt — being tapped on the shoulder

Picture it: you're reading a book (main program). The doorbell rings (interrupt). You bookmark the page (push registers), answer the door (run handler), then return to your exact line (pop registers). The bookmark is the stack push from §7.

Why it defines real-time: the whole selling point of Cortex-M is that this "answer the door" time is bounded and knowable. That controller is the NVIC defined above — see Interrupts and the NVIC.


9. Number kinds: integer, fixed-point, floating-point

Before the next paragraph, one control-loop term the parent uses:


10. Cache and TCM — fast vs predictable memory

Why both exist: cache is fast on average but a "miss" is slow, so timing becomes unpredictable — bad for hard deadlines. TCM trades size for guaranteed timing. This tension is the M7 story: Cache vs TCM in real-time systems.


Prerequisite map

bit and byte

hexadecimal 0x

32-bit registers

memory addresses

endianness and alignment

memory-mapped IO

load and store

instructions

fetch decode execute

clock cycles

pipeline throughput

the stack MSP PSP

interrupts and NVIC

integer fixed float FPU

MAC SIMD DSP

cache vs TCM

Cortex-M topic

Each arrow means "you need the left box before the right box makes sense." Notice everything funnels into the single Cortex-M topic node — that is the parent page.


Equipment checklist

Cover the right side and answer each before reading the parent note.

A "byte" holds how many bits, and how many patterns?
8 bits, giving patterns.
What does the 0x prefix mean and how many bits does one hex digit encode?
0x marks a hexadecimal number; each hex digit encodes exactly 4 bits.
Why can a 32-bit CPU give every peripheral its own address?
Because billion addresses exist — far more than there are peripherals to name.
What is a peripheral?
Any controllable hardware block around the CPU (timer, serial port, ADC, GPIO), seen by the CPU as a set of read/write slots.
What byte order do Cortex-M cores use by default?
Little-endian — the least-significant byte sits at the lowest address.
What is the alignment rule for a 32-bit word, and what happens if you break it on M0+?
A word should start at an address divisible by 4; an unaligned access on M0/M0+ raises a HardFault.
What is the difference between a register and memory?
Registers are a few ultra-fast slots inside the CPU where math happens; memory is the large, slower numbered street reached via load/store.
Name the three beats of the CPU's rhythm.
Fetch, Decode, Execute.
What is a clock cycle, and why measure work in cycles?
One tick of the CPU metronome; cycles × tick-time = real time, so cycles let us compare cores independent of clock speed.
What is a stack, and what do push/pop do?
A last-in-first-out scratch pile of memory; push adds a value on top, pop removes the top value.
Why does Cortex-M have two stack pointers (MSP and PSP)?
To isolate task scratch space (PSP) from kernel/interrupt scratch space (MSP), so one task's overflow cannot corrupt the kernel.
What does the NVIC do?
It manages interrupts — priority ordering, nesting, and automatic register stacking before jumping to a handler.
What does the MPU do?
Marks memory regions read-only / no-execute / off-limits and faults on violations, enforcing task isolation.
What is an interrupt, and what is jitter?
A hardware "handle me now" signal; jitter is how much the response time varies between events.
Define integer, fixed-point, and floating-point.
Integer = whole number; fixed-point = integer with a fixed imaginary decimal point; floating-point = fraction plus a movable exponent-scale.
What is PID and why does it need fast fractional math?
Proportional–Integral–Derivative control; it multiplies errors by fractional gains, so it needs fast float or fixed-point math.
Why is a cache fast but bad for hard real-time, and what fixes it?
A cache hit is fast but a miss is slow, making timing data-dependent; TCM gives fixed-time access instead.

Next: with this vocabulary in pocket, read the parent Cortex-M Series and every symbol will already be earned.