MCU cores and clocking
Cortex-M families, RISC-V, PLLs and power modes.
Choosing a core is choosing a budget
The CPU core sets the ceiling for speed, the floor for power, and which software ecosystem you can use. Most microcontrollers today use an Arm Cortex-M core; RISC-V is growing quickly; a few vendor-specific architectures remain (Xtensa in older ESP32s, AVR in classic Arduinos, MSP430, 8051 in some radios).
The Cortex-M family
| Core | Architecture | Typical use | Notable features |
|---|---|---|---|
| Cortex-M0 / M0+ | Armv6-M | Cheapest, lowest power: sensors, simple controllers | ~56 instructions, no divide, no unaligned access; M0+ has a 2-stage pipeline and optional MPU |
| Cortex-M3 | Armv7-M | General purpose (older designs) | Hardware divide, bit-banding, full Thumb-2 |
| Cortex-M4 | Armv7E-M | Control loops, audio, sensor fusion | DSP (SIMD, saturating) instructions, optional single-precision FPU |
| Cortex-M7 | Armv7E-M | High performance: 200 to 1000 MHz | 6-stage dual-issue pipeline, caches, TCM, optional double-precision FPU |
| Cortex-M23 | Armv8-M Baseline | Secure low-end | TrustZone for M0-class parts |
| Cortex-M33 / M35P | Armv8-M Mainline | Modern general purpose, IoT | TrustZone, DSP, FPU, improved MPU |
| Cortex-M55 / M85 | Armv8.1-M | Machine learning at the edge | Helium vector extension (MVE) |
Rules of thumb: M0+ for cost and battery, M4 or M33 for most products, M7 or M85 when you need raw speed or ML. Security-sensitive IoT products increasingly require Armv8-M with TrustZone.
Features that matter in practice
- Hardware divide. M0/M0+ call a library routine for every
/and%, taking tens of cycles. Prefer shifts and multiplies by reciprocals in hot code on those parts. - FPU. Without one, each
floatoperation is a library call (around 20 to 100 cycles). With a single-precision FPU,floatis fast butdoubleis still emulated. Watch fordoubleconstants:x * 0.5is a double multiply; write0.5f. - DSP instructions. Single-cycle multiply-accumulate and SIMD on 8 and 16-bit values; used through CMSIS-DSP.
- MPU. Memory protection regions: catch stack overflows and null-pointer writes, isolate RTOS tasks.
- TrustZone-M. Splits the chip into secure and non-secure worlds so keys and boot code cannot be reached by application code.
- Caches and TCM (M7). Huge speed-up, but caches must be managed when DMA is involved.
RISC-V
RISC-V is an open instruction-set architecture: anyone can implement it without a licence fee. It is modular; a core is described by its base and extensions:
| Letter | Meaning |
|---|---|
| RV32I / RV32E | 32-bit base integer ISA (E: 16 registers, for the smallest cores) |
| M | Multiply and divide |
| A | Atomic instructions |
| F / D | Single / double precision float |
| C | Compressed 16-bit instructions (like Thumb, for code density) |
| Zicsr, Zifencei | Control registers, instruction-fetch fence |
So "RV32IMAC" is a common microcontroller core. Examples: ESP32-C3/C6, GD32V, CH32V, the Raspberry Pi RP2350 (which has both Cortex-M33 and RISC-V cores). Interrupt controllers vary between vendors (CLIC, PLIC, vendor-specific), which is the biggest practical difference from the uniform Cortex-M NVIC.
Clocking
The core clock frequency comes from a PLL fed by an internal RC oscillator or an external crystal (see the boot and clock bring-up guide). Points that come up in design:
- PLL maths.
f_out = f_in / M * N / P. Each stage has allowed ranges (for example the VCO between 100 and 432 MHz), so not every target frequency is reachable. Vendor tools (STM32CubeMX clock tree) solve this. - Peripheral clocks. Each bus (AHB, APB1, APB2) has its own prescaler and maximum frequency. Timers on a divided APB bus often get double the bus clock: a classic source of wrong PWM frequencies.
- Clock accuracy. UART tolerates about ±2% total error; USB needs ±0.25%, so needs a crystal or a clock-recovery system; CAN needs a crystal.
- Clock security system. Detects a failed external crystal and falls back to the internal oscillator, raising an NMI.
Power modes
Every vendor names them differently, but the ladder is the same:
| Mode (generic) | Core | Clocks | RAM | Wake-up | Typical current |
|---|---|---|---|---|---|
| Run | Executing | On | Kept | — | 50 to 300 µA/MHz |
| Sleep | Stopped (WFI) | Peripherals on | Kept | Any interrupt, µs | ~30% of run |
| Stop / Deep sleep | Stopped | Most off, regulator low-power | Kept | EXTI, RTC, some peripherals; tens of µs | 1 to 50 µA |
| Standby / Shutdown | Off | Off | Lost (except backup domain) | Wake pin, RTC; acts like a reset | 0.1 to 2 µA |
Dynamic power scales roughly with frequency and with the square of voltage, so running fast and then sleeping ("race to sleep") often uses less energy than running slowly all the time. Many parts also offer voltage scaling: a lower core voltage that caps the maximum frequency.
The calculation below compares two strategies for a task that needs one million cycles every second:
#include <stdio.h>
int main(void) {
/* Illustrative numbers for a Cortex-M4-class part. */
double run_ua_per_mhz = 100.0; /* µA per MHz while running */
double run_fixed_ua = 1500.0; /* flash, regulator and clocks: paid whenever awake */
double stop_ua = 5.0; /* µA in stop mode */
double cycles = 1e6; /* work per second */
for (int mhz = 4; mhz <= 64; mhz *= 4) {
double busy_s = cycles / (mhz * 1e6);
double run_ua = run_fixed_ua + run_ua_per_mhz * mhz;
double avg_ua = run_ua * busy_s + stop_ua * (1.0 - busy_s);
printf("%2d MHz: busy %5.1f%% of the time, average %6.1f uA\n", mhz, busy_s * 100, avg_ua);
}
return 0;
}
The part of the run current that scales with frequency costs the same charge whichever speed you pick, because the work takes proportionally less time. The fixed part (flash, regulator, oscillators) is paid for every microsecond awake, so finishing sooner wins. That is why measured "race to sleep" usually beats running slowly, until wait states or a higher-voltage range eat the gain.
Interview question: How would you choose a microcontroller core for a new battery-powered sensor?
Answer: Start from the workload and the energy budget. If the work is light (read a sensor, filter, transmit), a Cortex-M0+ or a low-power M33 gives the lowest active and sleep currents; check stop-mode current with RAM retention, wake-up time and the RTC current, since the device sleeps most of the time. If there is significant signal processing, an M4 or M33 with DSP and FPU finishes faster and sleeps sooner. Then consider required peripherals (radio, ADC quality), security (TrustZone, secure boot), ecosystem and toolchain, price and availability.
Interview question: What are typical microcontroller low-power modes and what does each keep?
Answer: Sleep stops the core clock but leaves peripherals and RAM running, and any interrupt wakes it in microseconds. Stop or deep sleep turns off most clocks and puts the regulator in low-power mode while keeping RAM and registers, waking on external or RTC interrupts in tens of microseconds. Standby or shutdown removes power from the core and most RAM; only a backup domain (RTC, a few registers) survives, and waking is effectively a reset. Lower modes save more current but cost wake-up time and lost state.
Going deeper
Interview question: How would you choose the MCU for a smart plug that comes in a basic and a premium model?
Answer: List each model's requirements (connectivity, energy metering accuracy, memory for features and updates, security, cost target), then choose a family that scales between them with the same peripherals and toolchain, so one codebase serves both. Leave headroom in flash and RAM for over-the-air updates and future features.
Interview question: What does TrustZone for Armv8-M provide?
Answer: It splits the processor and memory into secure and non-secure states. Secure code, such as the bootloader, cryptographic keys and secure services, runs in the secure world, and the non-secure application can only reach it through defined entry points (secure gateway functions); hardware attribution units block non-secure accesses to secure memory and peripherals. A compromised application therefore cannot read keys or alter secure firmware.
Interview question: Why might a Cortex-M7 at 400 MHz run some code slower than expected?
Answer: Its speed depends on caches and tightly coupled memory: code or data that misses the caches waits on slower flash or external memory, DMA buffers need cache maintenance, and peripheral accesses go through slower buses. Branchy code also defeats its dual-issue pipeline. Placing hot code and data in TCM, enabling and managing caches correctly, and profiling with the cycle counter are needed to get the advertised performance.
Explain it: In your own words, explain why running faster and then sleeping can use less energy than running slowly all the time.
Answer: Part of a microcontroller's run current scales with clock frequency, and that part costs about the same total charge for a given amount of work whatever the speed, because a faster clock finishes the work in proportionally less time. But another part, from flash, regulators and oscillators, is a fixed overhead paid for every moment the chip is awake. Running fast finishes sooner, so that overhead is paid for less time before the chip drops into a deep sleep drawing microamps.