E29 — RP ↔ CH32 QSPI link (QSPI2 ↔ RP PIO)
| ID | E29 |
| Date | 2026-12-04 |
| Status | done: CH32 → RP 0 errors up to SCK 48 MHz (24 MB/s); RP → CH32 0 errors up to 19.2 MHz, 32 MHz (16 MB/s) with the RP input synchronisers bypassed; 1.1 MB soak each way at those settings, 0 errors |
| Decisions | D112, D113 (DECISIONS.md) |
| Board | #1 (rev A, Y2 = 12 MHz), CH32 ×32 build (HCLK 96 MHz), RP clk_sys 150 MHz |
| Firmware + results | fw/tests/2026-12-04-1-links (both chips; CH32 = bin/rp417_ch32.bin), raw: docs/bench/2026-12-04-links/qspi.txt |
| Scripts | links_qspi.py, links_lib.py; firmware fw/ch32/links.c (qspiw, qspir), fw/rp/src/links.c + links.pio (qspi rx/tx/chk/stop) |
Summary: The CH32’s QSPI2 controller (PE10–PE15, AF7) is the master. The RP plays the “flash” with two PIO programs:
qspi_rx samples 4 bits on each SCK rising edge while nCS is low, and qspi_tx drives 4 bits on each falling edge. DMA
fills or drains a 64 KB buffer. Both sides generate the same xorshift32 byte pattern, so every byte is checked. The
CH32 → RP direction is clean up to SCK = HCLK/2 = 48 MHz. The RP → CH32 direction is clean up to 19.2 MHz with the RP
input synchronisers on, and up to 32 MHz with them bypassed. Three CH32 behaviours had to be found first: SIOXEN, a
stuck BUSY flag, and the pin state after release.
What
- CH32: QSPI2 in indirect mode, quad data phase only (no instruction, address or dummy phase): CCR DMODE = 11,
FMODE = 00 write / 01 read, DLR = n − 1, CR prescaler
pre→ SCK = 96 MHz / (pre + 1). Data is fed and read through the FIFO on FTF, and the CPU loop runs from RAM. - RP:
qspi rx <n> [byp]arms the sampler,qspi chk <seed>compares.qspi tx <n> <seed> [byp]preloads and arms the driver, which drives on the falling edge so the CH32 samples on the rising edge.bypsetspio2->input_sync_bypassfor GPIO6–11. - Sweep: pre 11 … 0 (8 … 96 MHz), 3 × 32 KB per point, synchronisers on and off. Then a soak at the best setting of each direction: 20 × 56 KB.
Results
| SCK | CH32 → RP (write), sync on | sync bypassed | RP → CH32 (read), sync on | sync bypassed |
|---|---|---|---|---|
| 8 MHz | 0 / 98304 | 61165 bad | 0 | 0 |
| 12 MHz | 0 | 75232 bad | 0 | 0 |
| 16 MHz | 0 | 72572 bad | 0 | 0 |
| 19.2 MHz | 0 | 56137 bad | 0 | 0 |
| 24 MHz | 0 | 61106 bad | 93574 bad | 0 |
| 32 MHz | 0 | 66774 bad | 94920 bad | 0 |
| 48 MHz | 0 (23.97 MB/s) | 50677 bad | 97900 bad | 97936 bad |
| 96 MHz | all bad | all bad | — | — |
Soak: write 48 MHz (sync on) 0 bad of 1 146 880 bytes; read 32 MHz (sync bypassed) 0 bad of 1 146 880 bytes.
- SIOXEN (CR bit 13) is required for quad mode. Without it only IO0/IO1 carried data, although CCR asked for 4 lines. RM V1.8 does not say this in the QSPI chapter: see bug list.
- A failed transfer leaves QSPI2 BUSY for good. At SCK = HCLK/1 the write never completes. Waiting for BUSY to clear then hangs the CH32, and every later read in the sweep failed. Fix: reset the block through RCC (HB1PRSTR QSPI2RST) at every set-up. Abort alone was not enough.
- Released pins must be pulled. After a transfer the pins go back to inputs. A floating nCS read as low and started the RP’s next armed transfer early, so the first read after a failed write was all wrong. Now nCS is pulled up and SCK pulled down.
- Why bypassing the synchronisers helps reads but breaks writes (likely, not measured): the 2-flop synchroniser adds 2 RP cycles (13 ns) before the PIO sees the falling edge, so the RP’s data change comes later. For RP → CH32 that delay eats the CH32’s setup time above 19.2 MHz; without it, 32 MHz fits. For CH32 → RP sampling, unsynchronised inputs see SCK and data with metastable or skewed timing at any speed.
Lesson
A result that is the same at every setting points at the test, not the link. “All reads bad” came from a hang left by the 96 MHz write. Rerun one failing point by hand right after the step before it, rather than theorising on the table.
Chip facts and numbers: fw/LEARNINGS.md. All experiments: index.