E37 — Why ×40 builds hung at boot: flash clocked out of spec inside SystemInit
| ID | E37 |
| Date | 2026-12-04 |
| Status | done: cause found and fixed. ch32fun’s SystemInit switches to the PLL with the flash interface clock still at its reset value (SCK_CFG = 0, flash at HCLK/1 = 120 MHz at ×40; RM: ≤ 75 MHz). main() now sets SCK before SystemInit. ×40 with RAM loops: 50/50 boots, 2 min soak at V5F 480 MHz with 0 errors |
| Decisions | D117 (DECISIONS.md) |
| Board | #1 (rev A, Y2 = 12 MHz) |
| Firmware + results | fw/tests/2026-12-04-2-x40fix (before/after binaries), raw: perf.txt |
| Scripts | links_perf.py, RP pwrt on (boot timing) |
Summary: In E35, ×40 builds of the new firmware stayed silent after power-on (no banner, no MCO), while the same
settings from older source booted, and RP417_RAMLOOPS=0 made them boot. The flash access control register resets
with SCK_CFG = 0, i.e. the flash is clocked at HCLK (RM V1.8 46.4.1: reads recommended at ≤ 75 MHz at /1, ≤ 150 MHz at
/2). ch32fun’s SystemInit for the H41x only sets EHMOD, then switches SYSCLK to the PLL with FPRE /4, so HCLK becomes
120 MHz (×40) or 96 MHz (×32) with the flash still at /1. Our main() set SCK only after SystemInit returned. The
instructions fetched in between ran from flash out of spec. Whether a wrong fetch hit depended on what code sat at those
addresses: adding links.c or moving loops between RAM and flash changed the layout, which is why the symptom looked like a
“RAM code size” problem.
Evidence
| build (×40 unless noted) | flash SCK during the SystemInit → main window | boots |
|---|---|---|
| E21 binary (2026-12-03), HPRE 2 / FPRE 2 | /1 at 120 MHz | yes (layout luck) |
| HEAD before E29–E36, HPRE 2 / FPRE 2 | /1 at 120 MHz | yes |
| E35 source, any LDO setting, HPRE 1 or 2 | /1 at 120 MHz | no |
E35 source, RP417_FLASH_SCK=2 |
/1 at 120 MHz (main sets /4 too late) | no |
E35 source without links.c |
/1 at 120 MHz | yes |
E35 source, RP417_RAMLOOPS=0 |
/1 at 120 MHz | yes |
E37 source (SCK set before SystemInit), HPRE 1 + RP417_VDDK=5 |
/2 at 60 MHz | yes, 50/50 power cycles |
| E37 source, HPRE 2 / FPRE 2 | /2 | yes |
| E37 source, ×32 | /2 | yes |
RP417_FLASH_SCK=2 not helping was the clue: it only changes the value main() writes, after the window.
With the fix, V5F 480 MHz (performance LDO setting, RAM loops on) ran 396 checksummed V3F/V5F passes in 2 min with 0
mismatches, die 36.8 → 45.6 °C. Boot banner: 66.23–66.25 ms after PWR_EN at ×40; 65.93 ms at ×32, 0.45 ms later than
in E33 (not investigated).
Lesson
When a setting changes the outcome only through code layout, look for a window where the chip runs out of spec before your own initialisation: vendor or library start-up code may switch clocks without setting what depends on them.
Chip facts and numbers: fw/LEARNINGS.md. All experiments: index.