Skip to the content.

E28 — RP counter → CH32 DVP → USB2 high speed → PC: maximum verified stream rate

   
ID E28
Date 2026-12-03
Status done: 20 MS/s of 10-bit samples (40 MB/s) sustained for 30 s, 21.5 MS/s peak, every sample checked; the limit is the USB2 link/PC, not the CH32. Test suite: 37/37 pass
Decisions D107, D108, D109 (DECISIONS.md)
Board #1 (rev A, Y2 = 12 MHz); RP on the PC (J3), J1 (silk “USB3”) on the bench hub (1-5.4.1), RP usbsel usb, capsel rp
Firmware + results Suite run (final): fw/tests/2026-12-03-6-streamsuite: both chips’ sources and binaries (RP rp/ + rp417_rp.uf2; CH32 usbhs/ + usbhs_stream.bin, A/B variants, main rp417_ch32.bin), the pytest suite, results/. First exploration: fw/tests/2026-12-03-5-dvpusb
Scripts test suite fw/tools/streamtest (pytest), dvpusb.py, fw/usbhs/stream.c, fw/usbhs/build.sh (APP=stream)

Summary: The RP’s PIO counter feeds the CH32’s camera port (DVP), and the CH32 streams those samples to the PC over USB2 high speed. The PC checks every sample. The path holds 20 MS/s of 10-bit samples (40 MB/s) for 30 s, with a 21.5 MS/s peak over 2 s (the test suite below, 384 KB ring). The first sweep (256 KB ring) gave 20.5 MS/s, but only over 2 s. The CH32 alone can send 42.7 MB/s over this link to this PC, so the limit is the link and the PC, not the CH32. Two problems turned up along the way:

What

Results

USB alone (gen, 64 MiB per size, all counters correct, PC reads into buffers allocated beforehand):

burst 2 KB 8 KB 16 KB 32 KB 62 KB
MB/s, 1 MiB reads 30.5 37.7 40.3 41.1 41.7
MB/s, 4 MiB reads 30.8 38.2 40.9 42.1 42.7

DVP → USB (chunk 4096 samples, 32 KB bursts, 4 MiB preallocated reads, 2 s per rate, 256 KB ring = 32 slots):

PCLK (RP counter) rate received samples checked wrong max backlog
5 MHz 10.0 MB/s 10.0 M 0 7/32
10 MHz 20.0 MB/s 20.0 M 0 14/32
15 MHz 30.0 MB/s 30.0 M 0 24/32
18.75 MHz 37.5 MB/s 37.5 M 0 25/32
20 MHz 40.0 MB/s 40.0 M 0 29/32
20.5 MHz 41.0 MB/s 41.0 M 0 29/32
21 / 21.5 MHz — — 0 in what arrived OVERRUN after 4–8 MiB (with a 384 KB ring: after 44 MiB)

Test suite (D109)

fw/tools/streamtest is a pytest suite that runs on the board and checks every sample: RP417_BOARD_LOCK=… python3 -m pytest fw/tools/streamtest -v --with-ab (7 min 40 s). Its rule for every DVP run is lossless or loud: either the run is complete and clean, or the CH32 stopped with OVERRUN, and in both cases the data that reached the PC is clean. Final run (archive 2026-12-03-6): 37/37 pass.

test result
link, firmware 480 Mb/s, bcdUSB 2.00; USBHS PLL locked, PLLCFGR2 0008072b
RP counter PCLK (1 / 10 / 20.5 MHz) RP’s own count on GPIO30: 0 / −6 / −8 ppm from the setting
USB alone, 64 MiB per burst size 31.6 / 39.5 / 42.2 / 43.3 / 44.0 MB/s (2 / 8 / 16 / 32 / 62 KB), 0 wrong
USB alone, 512 MiB 43.2 MB/s, 0 wrong
DVP → USB, 1 … 20.5 MS/s all complete, 0 wrong, rate = 2 × PCLK; backlog ≤ 15/48 slots
maximum 2 s rate (0.25 MHz steps) 21.5 MS/s = 43 MB/s clean; 21.75 overruns
chunk sizes 256 … 4096 at 10 MS/s all complete and clean (256-sample rows: 39 k DMA rows/s, backlog 73/768)
burst caps 8 … 64 KB at 18.75 MS/s all complete and clean
overrun at 23 MS/s OVERRUN reported, 2.7 M samples received, 0 wrong
restart after overrun, 5 streams + RAM burst all clean
endurance: 20 MS/s for 30 s 600 M samples (1.2 GB), 0 wrong, backlog peak 26/48
bad commands (unknown, chunk 100, chunk 3000, gen len 1000) err replies with the run id; link still in step
alignment A/B (ring 16 B off) 225 bad steps = 9 × 25 ring passes, all at the ring’s last 9 indices; default clean

What the suite changed:

Device class: vendor bulk kept (D108)

The CH32 could also look like a standard webcam (UVC) or sound card (UAC2), so the PC’s own driver would read the stream. These options were compared on paper, not built:

  vendor bulk (E28, kept) UVC over bulk UVC isochronous UAC2 isochronous
PC side libusb (dvpusb.py) uvcvideo, /dev/videoN, ffmpeg/V4L2 same ALSA/CoreAudio, arecord/Audacity
Ceiling on USB2 HS 41.0 MB/s measured (42.7 MB/s USB alone) ≈ the same bulk rate, minus a 12-byte header per transfer 24.6 MB/s cap (3 × 1024 B per 125 µs microframe) MHz sample rates unusual (driver/tool limits to verify)
Lost data none: bulk retries, the CH32 stops with OVERRUN none (bulk), dropped frames on driver errors lossy: no retries lossy
Extra firmware none UVC descriptors + probe/commit requests + payload headers + isochronous set-up UAC2 descriptors, clock source, rate feedback

The requirement is the highest lossless bandwidth, and that rules out both isochronous classes (no retries, ≈ 60 % of the bulk ceiling). UVC over bulk would add work and a frame layer without adding rate. The stream stays vendor bulk with a libusb reader. The rate left to gain is on the PC side: an async reader that keeps several transfers queued (41 → ≈ 43 MB/s). A sound card class could later suit a slow, decimated channel; it is not on the list.

Lesson

DMA buffers on the CH32H417 must start (and every slot must end) on 32-byte boundaries. Check a stream at its ends and at its wrap points, not only in the middle. Throughput tests over USB measure the reading program as much as the device: allocate the buffers beforehand, and log the device’s backlog to see who is late.

Chip facts and numbers: fw/LEARNINGS.md. All experiments: index.