E21 — Clock builds inside the datasheet and RM limits
| ID | E21 |
| Date | 2026-12-03 |
| Status | done |
| Decisions | D99 (DECISIONS.md) |
| Board | #1 (rev A, 12 MHz HSE), RP on the direct PC port |
| Firmware + results | fw/tests/2026-12-03-1-clocks-v5fdvp-sdorder (final sources, 7 CH32 builds, results.txt) |
| Scripts | clockspec.py, clockspeed.py |
Summary: The ×40 build ran the V5F at 480 MHz (limit 400) and the 156 MHz build reads flash above the RM’s 150 MHz: builds now refuse out-of-spec clocks, the flash clock follows the RM, and ×24 (V3F 144, V5F 288 MHz) is the fastest in-spec build; default stays ×32.
What
Clock chain (RM V1.8 §3 clock tree): SYSCLK → HPRE → V5F → FPRE → V3F/HCLK. New RP417_HPRE; #error for V5F > 400
or HCLK > 160 MHz (DS V1.9). Flash interface clock SCK_CFG from HCLK per RM 46.4.1 (/1 ≤ 75 MHz, /2 ≤ 150 MHz, /4 “HCLK
max 150, not recommended for reads”). Per build: V5F clock measured (mcycle vs SysTick); for each SCK, flashsum
(FNV over the image, 32 reps, loop in RAM) vs the host, V3F flash and RAM loop; then the clockspeed.py suite.
Results
| build | V3F / V5F MHz (measured V5F) | default SCK | flash loop ms at /4, /2, /1 | RAM loop ms | suite |
|---|---|---|---|---|---|
| ×32 (default) | 96 / 384 (384.00) | /2 | 415, 218, 120* | 17.75 | all pass, 11/11 |
| ×40 + HPRE 2 + FPRE 2 | 120 / 240 (240.00) | /2 | 332, 175, hangs | 14.20 | all pass |
| ×24 + FPRE 2 | 144 / 288 (288.00) | /2 | 277, 146, chip resets | 11.83 | all pass, ADC1 5.13 MS/s, HSADC 96 MHz |
| ×26 + FPRE 2 (E19) | 156 / 312 (312.00) | /4 (out of RM range) | 255, 134, chip resets | 10.93 | all pass |
- Flash checksum correct at every SCK that keeps the chip running.
- * SCK /1 at 96 MHz (flash at 96 MHz, RM ≤ 75) is marginal: one boot ran with
fcntreading 102.7 MHz for 12.5 MHz, another hung; the final run ran it with a correct checksum (120 ms loop). Not reliable either way: stay at /2. - ×24 SCK /1 (flash at 144 MHz): the chip resets on the write (the V5F found stopped, ACTLR back to the build value).
- Final run, selftest: 0 failures for ×24, ×26, ×32; the debug-module (SWD) check failed for ×40 and for the default
build’s two closing runs (SWIO intermittent on rev A, LESSONS / E8, not clock-related: the same ×32 binary passed it
earlier in the run; after a CH32 power cycle: 3/3 selftests pass, SWD included, E25). A first build of this experiment had that setting by mistake (an undefined macro read as 0 in
#if).
Lesson
Read the RM register description for every clock you raise, not only the datasheet’s core limits: the flash has its own (150 MHz HCLK) limit below the core’s (160 MHz). Make out-of-spec builds fail at compile time.
Chip facts and numbers: fw/LEARNINGS.md. All experiments: index.