E27 — CH32 USB2 high speed on J1 (E2)
| ID | E27 (the E2 proposal) |
| Date | 2026-12-03 |
| Status | done (480 Mb/s, bulk data clean; throughput streaming test still open) |
| Decisions | D105, D106 (DECISIONS.md) |
| Board | #1 (rev A, Y2 = 12 MHz); RP on the PC (J3), J1 (silk “USB3”) on the bench hub (sysfs 1-5.4.1), RP usbsel usb |
| Firmware + results | fw/tests/2026-12-03-4-usbhs (main firmware pair, usbhs_ch372.bin + its patched WCH sources and build.sh, results.txt) |
| Scripts | usbhstest.py, fw/usbhs/build.sh, udev rule fw/tools/60-rp417.rules |
Summary: The CH32 runs USB2 high speed on J1 from the 12 MHz crystal. It enumerates at 480 Mb/s and passes 12 MiB of verified bulk loopback per run with 0 errors. The first build did not enumerate. The cause was a bug in WCH’s own clock library: RCC_USBHSPLLReferConfig() never sets the 24 MHz reference, so the PLL ran at 460.8 MHz while reporting “locked”.
What
- Firmware: WCH EVT
USBHS/DEVICE/CH372Device(vendor bulk device 1a86:5537), V3F only, stock GCC (fw/usbhs/build.sh, asfw/usb3). Patch 5 feeds the USBHS PLL from PLLCLK / 8 = 24 MHz with REFSEL = 24 MHz (the D84 clock, proven earlier by MCO scaling only) and prints the bounded lock wait. - Test:
usbhstest.pysets RPusbsel usb, flashes over UART ISP, power-cycles the CH32 through the RP and logs the UART. It waits for 1a86:5537 and reads the link speed from sysfs. It then loops random data through EP1 → EP1 (as is) and EP3 → EP4, EP5 → EP6 (inverted), at 512 B–4 KiB per transfer, and checks every byte. At the end it flashes the main firmware back.
Results
| run | build | UART | host | data |
|---|---|---|---|---|
| 0a | EVT RCC_USBHSPLLReferConfig(Refer_24M) |
(not captured) | nothing | — |
| 0b | PLLCFGR2 written directly | (not captured) | 480 Mb/s, bcdUSB 2.00 | blocked: no udev permission for 1a86:5537 |
| 1 | same | (not captured) | 480 Mb/s | 0 wrong / 12 MiB |
| 2 | same | rp417 USBHS_PLL LOCKED after 1170 polls (PLLCFGR2 0008072b) |
480 Mb/s | 0 wrong / 12 MiB |
Loopback rate, Python ping-pong (one write, then one read; MB/s counted both ways), runs 1 / 2:
| endpoints | transfer | rate |
|---|---|---|
| 0x01 → 0x81 | 512 B | 11.6 / 12.0 MB/s |
| 0x03 → 0x84 (inverted) | 512 B | 4.2 / 3.9 MB/s |
| 0x05 → 0x86 (inverted) | 512 B | 4.3 / 4.0 MB/s |
| 0x01 → 0x81 | 2 KiB | 15.3 / 14.4 MB/s |
| 0x01 → 0x81 | 4 KiB | 16.4 / 14.2 MB/s |
- The library bug: the EVT sets the reference with
PLLCFGR2 |= RCC_USBHSPLLRefer_24M(= 2, unshifted). But REFSEL is bits [3:2]: the 2 lands in the source field, which already held 3. REFSEL stays at 25 MHz (0x00080723), so the PLL makes 480 × 24/25 = 460.8 MHz. Writing2 << 2gives 0x0008072b, and the device enumerates. The bug cannot show on WCH’s own 25 MHz boards (Refer_25M = 0). - These rates are bounded by the round trips and by the example’s echo code (the inverting endpoints copy byte by byte on the V3F). They are not the link ceiling (≈ 40–50 MB/s for HS bulk). Measuring that needs a source/sink firmware.
- The board was found by USB identity throughout (RP serial 12A716003B085081, CH32 at hub port 1-5.4.1).
- Side fix:
usb3test.board()reloadsdvpcap, so a second board session in the same script gets fresh ports.
Lesson
A vendor library is not a reference: check the bits it writes against the RM when the board differs from the vendor’s (here: a 12 MHz instead of a 25 MHz crystal). A lock flag is again no frequency check (E25). Next on USB2 HS: a streaming source/sink endpoint for one-way throughput, then port USBHS into fw/ch32 if the project needs it.
Chip facts and numbers: fw/LEARNINGS.md. All experiments: index.