Phase 1 of 4 · Study weeks 1-4
Board, boot, clocks and a measured baseline
This phase lets you build, flash, debug and measure the chip from a clean checkout, so Phase 2 has a number to beat. Read the board user manual (UM2505), the datasheet (DS12712) and the chip's reference manual (RM0440, st.com/resource/en/reference_manual/rm0440-stm32g4-series-advanced-armbased-32bit-mcus-stmicroelectronics.pdf) as you go, and the Interrupt blog's linker-script and map-file posts (interrupt.memfault.com) in Week 2.
Topics every week
- Week 18 h
- The board: Cortex-M4F, memory map, 3.3 V rules, ST-LINK/V3E (debug, virtual serial port, mass storage)
- tools: Arm GNU Toolchain 15.x, CMake, OpenOCD or STM32CubeProgrammer, or the IDE of your choice
- option bytes
Hand inA blink built from a clean checkout by one script, plus a record of the factory option bytes (
DBANK, readout protection, boot bits) - Week 28 h
- What runs before
main: vector table, reset handler,.dataand.bsssetup, linker script, map file
Hand inYour own startup file and linker script for a blink using only CMSIS headers, plus an annotated map file
- What runs before
- Week 38 h
- Clocks and power: 24 MHz crystal, PLL to 170 MHz, boost mode, flash wait states, instruction cache and prefetch, MCO output, SysTick, DWT cycle counter
Hand inA clock report: configured against measured (analyzer on MCO), and a loop benchmark at each wait-state setting you can safely run
- Week 48 h
- Timers, ADC and DMA: center-aligned PWM, a timer-triggered ADC, circular DMA, interrupts, where in the PWM period you sample
Hand inCheckpoint 1, built in five steps: PWM only; timer-triggered ADC with DMA; the hardware pulse counter and stop; DWT interval statistics; the flagging script and seeded stall (then the captures)
Practice projects
- Blink three ways (registers, LL, HAL) and compare code size and speed in a table. Done when each build is under a stated size and you can explain each difference from the map file.
- Serial logger over the virtual serial port with DMA transmit, no blocking calls and no
printfin an interrupt. Done when 1,000 lines per second print with no loss and no call blocks (you will reuse it as the load in Checkpoint 1). - (Optional for a fresher) Interrupt latency against wait states and cache on and off. Done when a table gives cycles for each setting and you explain the largest step.
GitHub repos to study
| Repo | What to read | Week |
|---|---|---|
| STMicroelectronics/STM32CubeG4 | Projects/NUCLEO-G474RE/Examples for TIM, ADC, DMA and UART; the release is v1.6.3 | 1 to 4 |
| STMicroelectronics/cmsis-device-g4 | The device header and startup file that Week 2 compares against | 2 |
| libopencm3/libopencm3 | lib/stm32/g4: a register-level style without HAL (read for style; check its G4 coverage before relying on it) | 3 |
| memfault/interrupt | _posts: the linker script, map file and Cortex-M exception posts | 2, 4 |
Milestone checkpoint
Build the harness and capture all three builds. Done when the Checkpoint 1 row passes. Evidence: the capture table, raw files, the flagged seeded stall, ADR-1 (timer-triggered DMA against interrupt-triggered conversion, and your sampling point, with a ripple capture).
Check yourself
Answer each question in your head first, then open it to check.
Which instruction runs first after reset, and where does the CPU find its address?
The CPU loads the stack pointer from the first word of the vector table and jumps to the address in the second word (the reset handler).Why does 170 MHz need wait states, and what does the cache do about them?
Flash cannot answer at 170 MHz in one cycle, so reads wait. The instruction cache and prefetch hide most waits for code that repeats.How many CPU cycles are in one 10 kHz period at 170 MHz?
17,000.Why does the PWM sampling point change the reading?
The filtered node has ripple at the PWM frequency; you see a different part of it at the peak, the valley or the middle of the period.Why trigger the ADC from a timer and not from software?
A hardware trigger has no software jitter, so the sample interval depends only on the crystal.