knaxuslearn · build · ship

Roadmaps / STM32 / The milestone project

Read first

The milestone project

Scenario. A pump-speed controller inside a small appliance, 2,000 units in the field. A 20 kHz PWM output drives a pump stage; the speed sensor is an analog voltage read at 10 kHz. On the bench, an RC filter (10 kΩ and 100 nF, a time constant of 1 ms, which you measure) stands in for the pump and sensor: PWM goes in, the filtered voltage is the "speed". A 10 kΩ load resistor from the filter node to a GPIO stands in for a changing load: the pin is driven low (open-drain) to switch the load on and released to switch it off. The firmware also answers a command protocol over a serial link and reports telemetry. The safe state here is a defined state on a bench, not a certified safety function: certification (IEC 61508, for example) needs far more than this roadmap covers. Two bad outcomes matter: a stuck control loop must put the output in a safe state within 20 ms, and a field update that loses power must never leave a unit unbootable. Assumed numbers, to be replaced with yours: one update a year, 1% of updates interrupted by a power loss, and a US$150 service visit per bricked unit. That is 20 visits and about US$3,000 a year for this base; across 100,000 units it is about US$150,000 a year.

PhaseCheckpointDone when
1Timing baselinePWM at 20 kHz and an ADC sample every 100 µs (10 kHz) triggered by a timer in hardware, read by DMA. The loop ISR is the DMA transfer-complete interrupt, one per sample (a one-sample DMA buffer). A 10-minute run gives exactly 6,000,000 samples: a second, 32-bit timer (6,000,000 does not fit in 16 bits) counts the trigger pulses in hardware (external clock mode fed by the first timer's trigger output); at 6,000,000 a compare event disables the trigger, you wait for the last interrupt, and the ISR count then equals it, with no ADC overrun or DMA error flag. The analyzer measures the PWM frequency over a 1-second capture within 0.1% of 20 kHz. The report gives min, p50 and max of the interval between consecutive ISR entries, in CPU cycles read from the DWT counter (17,000 cycles at 170 MHz is the ideal), for three conditions (fresher: the first two): idle, the Phase 1 serial logger at 1,000 lines a second, and instruction cache and prefetch switched off. A test build that disables interrupts for 200 µs once a second is flagged by the script, and a clean run raises no flag with a threshold per condition fixed before the run (measure the min-to-max spread of each condition with caches off, then set the threshold above it; ±50 cycles is only a starting guess).
2Control loop and RTOSA 10 kHz PI loop in a high-priority interrupt, with FreeRTOS tasks for commands (a minimal text command over the serial link: set the setpoint, read status; the framed protocol arrives in Phase 3) and telemetry. A setpoint step from 20% to 40% of full scale settles to ±5% within 10 ms with at most 10% overshoot, and steady-state error is at most 1% of full scale. The load resistor is switched at 1 Hz for 10 minutes, and each disturbance is recovered within 10 ms. The loop ISR uses at most 50% of its period (8,500 cycles) with the Phase 1 harness still running and the serial link flooded. Control latency (ADC trigger to new duty written) is at most 10 µs at p99.9 and is reported at max. Measure it by reading the PWM timer's counter right after the duty write (the trigger is the counter's valley, so the count is the latency in 5.9 ns ticks), and check a sample against a marker pin on the analyzer. With preload on, the pin changes at the next timer update; ADR-1 records that delay. Seeded faults caught: a task stack overflow trips the stack hook and the board enters the safe state; an ISR at the wrong priority calling a FreeRTOS FromISR function trips configASSERT.
3Interfaces and faultsA framed binary protocol over the virtual serial port (UART with DMA, hardware CRC) and telemetry over FDCAN in internal loopback. A host script sends 100,000 random frames and 10,000 valid frames with one bit flipped. Frames are at most 64 bytes, and the parser restarts after 5 ms of silence. With a 5 ms gap after each bad frame, every good frame is acknowledged. With no gap, the parser rescans from the byte after the bad frame's start, so a corrupted length loses at most as many good frames as fit in 64 bytes at the spec's minimum frame size (derive the number, for example 8 frames of 8 bytes), and every later one is acknowledged. The board never resets (the reset counter does not move), and counts every frame with a failed CRC or invalid length and each resynchronisation. A frame parser written without hardware calls runs the same tests on the laptop. A stuck loop (seeded while(1) in the loop ISR) triggers an independent-watchdog reset within 20 ms, measured from the stall to the pin going low. The output holds its last duty until the reset, which the 20 ms budget allows, and is pulled low after it. Four seeded faults (bus error at an unmapped address, unaligned access with trapping on, divide by zero with trapping on, a jump through a corrupted function pointer, where the culprit is found from the stacked link register because the stacked program counter is garbage) each leave a fault record that a script decodes to the right fault class and the faulting function (a precise fault also gives the line; an imprecise fault, caused by a buffered write, can point at a later instruction). The reset reason survives the reset and is reported.
4Bootloader and updateA bootloader (16 KB; larger if you add signature checks), two firmware slots (one per flash bank) and an append-only metadata log in a reserved page at the end of each bank. A 64 KB image arrives over the serial link, is written to the idle slot while the loop runs, is checked and trial-booted. Apart from the confirm write, the loop misses no samples during the update. The confirm record is two doublewords written into the bank the loop runs from, a stall of a few hundred microseconds (read the datasheet programming time), longer than the 100 µs sample period. Either run the loop ISR and its data from SRAM during that write, or write down before the test how many samples the confirm may cost (at most 3) and show the count stays inside it. The bootloader's decision logic also runs on the laptop against a simulated flash that fails after the N-th program or erase operation: for every N across one whole update, the result is a bootable slot (this, with the ADR-5 argument, is the guarantee). On the board, 20 power cuts (fresher: 5) are triggered by the board through the delay relay. The test build raises a GPIO phase marker and knows the relay's latency (measured with the analyzer), so it triggers the relay that much before the target moment. Cuts are split by what a relay can aim at: 8 during page erase, 8 during page programming (a 2 KB page takes tens of milliseconds to program) and 4 torn metadata records (the test build waits 20 ms between the two doublewords of a record); fresher: 2, 2 and 1. A tear inside one doubleword program lasts about 100 µs and cannot be aimed; the simulator covers it, and the boot scan treats an ECC error on read as a torn word. A cut counts only if a spare analyzer channel on the 3.3 V rail shows the rail below 0.5 V for at least 100 ms and the next boot reports a power-on or brown-out reset; other cuts are discarded and repeated. Each cut ends with a bootable slot within 2 s of power-up, and the update then completes on retry; the host script waits for the serial port to reappear. Twenty clean cuts only bound the failure rate below about 14% at 95% confidence: they find design bugs, and the simulator carries the proof. The watchdog never fires during a normal update, because the erase runs in the other bank while the supervisor keeps checking in. A seeded image with a valid CRC whose application hangs is given three boot attempts without a confirm (the bootloader starts the independent watchdog before the jump, so a hang becomes a reset), and then the bootloader marks it failed and boots the previous slot. A slot programmed with one payload bit flipped (use the programmer) is refused at boot. The boot scan must survive a doubleword left half-programmed by a cut (see the flash facts). A 24-hour soak (fresher: 8 hours) shows no missed samples beyond the budgeted confirm stall and no unexplained reset. Two clean builds from the same checkout and pinned toolchain give byte-identical images (same SHA-256).
WWork version (Staff and Principal)On a real product: a baseline of one thing the product cannot yet answer (for example the cause of field resets, a loop's worst-case latency, or whether an update survives a power cut), one change, and a second measurement. Pass: the target agreed in writing with the stakeholder before the change is met in the second measurement on the same fleet or bench. The ADR is signed by a named stakeholder, scored by someone other than you, and a recheck is booked three months later (outside the 16 weeks). Level 4 also needs evidence that another team reused your checklist and recorded a finding with it. Timebox: about 30 hours of work time; allow ten to sixteen weeks if the second measurement needs a fleet release.

| W-P | Principal scope | Apply W across a product line. Deliverable: a one-page decision memo (options, a measured comparison, the choice, who signs, and the triggers that reopen it) that sets the fleet contract: what every product logs at reset, what an update must guarantee and how it is tested. Pass: at least two other teams adopt the contract in writing with named owners, and a measured outcome (unexplained-reset share or failed-update rate across them) improves against a target set beforehand. Recheck at three and twelve months. |

Senior-only items, Done when. Signed image: the bootloader refuses an image with a valid CRC and a wrong or missing signature (seeded), accepts a correctly signed one, and the private key never touches the board or the repository (ADR-6 says where it lives). CI fault suite: one command on a laptop with the board attached (a self-hosted runner) runs the four seeded faults, the fuzz run and five cuts, and exits non-zero on any miss. Cycle budget table: the loop's cycles by function from the DWT counter add up to the measured maximum within 5%.

Terms. The loop ISR runs the PI controller at the highest interrupt priority, above configMAX_SYSCALL_INTERRUPT_PRIORITY, so FreeRTOS can never delay it and it never calls FreeRTOS. It hands data to tasks through a double buffer. Safe state: PWM off and the enable pin low. After any reset the pins are inputs, so a 100 kΩ pull-down on the PWM line makes reset itself safe; the timer's break input (hardware) can force the output off faster than software. A slot is one firmware image area. Trial boot: the bootloader boots a new image once, and the image must call confirm() after its self-test (the loop has run 5 seconds and the serial link answers) before it becomes permanent. Without a confirm, the image gets three boot attempts, and then the bootloader marks it failed and boots the previous slot. A CRC finds accidental corruption and says nothing about who wrote the image.

Flash facts that shape the design (RM0440, AN4767, ST community; checked 22 Nov 2026). Cat. 3 devices such as the G474RE have a dual-bank mode (DBANK=1): two 256 KB banks of 2 KB pages, bank 2 at 0x08040000, and you can read one bank while the other is erased or programmed. Programming or erasing the bank you are executing from stalls instruction fetch, so the running slot never writes its own bank during the loop: the update writes the other bank, and each bank holds one slot and one metadata page (the app writes only the other bank's page, apart from the one confirm record). Single-bank mode has 4 KB pages. Users report that parts ship with DBANK=1 while CubeMX and the VS Code extension generate a single-bank linker script (ST community, Nov 2025): read your option bytes in Week 1 and check your script. Flash is written in 64-bit doublewords with 8 ECC bits, so treat each doubleword as write-once between erases. A power cut during programming can leave a doubleword whose ECC no longer matches. Reading it can raise a non-maskable interrupt with an ECC-detect flag (a user thread on an STM32L4 describes it; check RM0440 for the G4), and with no handler the unit hangs. The boot scan needs an NMI handler that clears the flag and treats the word as torn, and the cut table counts the NMIs it survived. The log is append-only with 16-byte records; when its page is full, the bootloader (at boot, before the loop runs) copies the latest state to the other page and erases the full one, in an order a cut cannot break. Fresher scope: 128 records per page is enough, so skip compaction. ST documents a software bank-swap bit, FB_MODE in SYSCFG_MEMRMP (AN4767), and the Cube FLASH_DualBoot example uses BFB2 and an option-byte launch; community threads report inconsistent behaviour, so the core path avoids both (ADR-5). A power cut is a slow supply decay, not an instant zero: the brown-out reset (Week 11) has to hold the CPU in reset cleanly before the cut can corrupt anything.

Evidence to hand in. A repository whose README opens with the problem and the numbers above; one ADR (architecture decision record) per decision, each naming a rejected option; raw captures and a test report; a one-page design doc; a memory-map diagram, a timing diagram and a boot state diagram. Skeletons: Checkpoint 1 is one table (build, run, samples, min, p50, max cycles, flagged intervals) plus the raw files and the flagged seeded stall. Checkpoint 3 is the protocol spec, the fuzz log with counts, and four decoded fault records. Checkpoint 4 is a 20-row power-cut table (cut phase, slot booted, retry result), a soak report and the rollback log.

LevelWhat you build and hand in
FresherCore scope: floating-point PI, CRC-32 image check, one trial-boot rollback, four checkpoints, ADRs 1 to 5.
SeniorAdds a signed image (Ed25519 or ECDSA P-256 with a library you choose, key kept off the device), a fault-injection suite run from CI, a cycle budget table, and ADRs 6 and 7.
StaffAdds written decisions with numbers: ISR against task, update strategy (own bootloader, dual-bank swap, MCUboot, ST's secure-update packages), field diagnostics, and a platform memo (when a G4 is enough and when a part with secure boot is needed).
PrincipalAdds a product-line decision memo, a review checklist for "firmware that must not brick" that other teams reuse, and a measured outcome from the work version.

Do this at work. A solo lab is not promotion evidence. Take a real firmware product and run Checkpoint W: measure the baseline, make one change, measure again. Good candidates are resets with unknown cause (add the fault record and reset reason), a loop with an unmeasured worst case (add the DWT harness), or an update path never tested with power cuts (add the relay drill). A promotion committee accepts: the real decision and who made it, the named stakeholder who relied on it (for example the hardware lead or the support manager), before and after numbers, and a result checked again three months later. Write the decision as an ADR the stakeholder signed, and put the recheck in the calendar. Illustrative example: baseline, 14% of 300 field resets had an unknown cause; change, a fault record and reset reason; target agreed in advance, under 2% unknown; second measurement, 1.1%; recheck booked for three months later.

Solo version. With no product or stakeholder, read an open-source update path (the MCUboot design documents, or the Cube FLASH_DualBoot example) and write a one-page review of how it survives a power cut. Ask a peer or mentor to review your measurements. The relay drill and the analyzer replace a production fleet.

Laptop scale. All builds and tests run on a laptop and the board. Nothing needs cloud spend.

Honest sizing. Phase 4 gets four weeks (32 hours) for a bootloader, an update protocol and a power-cut campaign, and an experienced firmware engineer can build the bootloader alone in a few days. A fresher should plan five weeks for each phase (see the time model), take the reduced counts in the Checkpoint 4 row and skip the optional items.

Worked reference: what a "3 Proven" hand-in for Checkpoint 2 looks like

The numbers below are illustrative. The shape (task latency grows under load, the interrupt's does not) is what you should expect, but hand in your own captures. Do not copy these figures.

Control latency, 10 minutes per columnPolled in main loopFreeRTOS task (top priority)Loop ISR above the syscall priority
Idle: max latency140 µs22 µs3.1 µs
Loaded (serial flood, FDCAN at 1 kHz, telemetry): max latency2,300 µs180 µs3.4 µs
Result against the 10 µs budget (10% of the 100 µs period)FailsFails, idle and loadedPasses

ADR-2 excerpt: The PI loop runs in an interrupt, not in a task. The budget is 10 µs, 10% of the loop period, the delay the plant is assumed to tolerate. If the plant tolerated 200 µs, a top-priority task would pass and this ADR would choose it, because tasks can use RTOS objects and are easier to test. The task missed the budget by 18 times under load because of the tick, critical sections and the DMA interrupts ahead of it. A hardware-timer-driven DMA that updates the compare register with no CPU involved removes the CPU but removes the controller too. Consequences: the ISR cannot call FreeRTOS, so it shares data through a double buffer with a sequence counter; its worst case is 8,500 cycles at most, so the loop's cycle count is a tested budget; and testing needs hardware. Revisit if the loop passes 50% of its period or needs an RTOS object.