Files
tinyusb/examples
hathach ae7f10b0d3 usbtest: support CH32V203 (fsdev + usbfs ports), both pass tier-4 30/30
Neither of the CH32V203's two USB device IPs could run the usbtest tier-4 battery.

usbfs (port 1):
- 128 B iso doesn't fit its fixed 64 B/ep buffers -> drop iso mps to 64 on CH32
  (usb_descriptors.h).
- dcd_ch32_usbfs.c: clear-halt on an armed OUT endpoint forced it to NAK, so a
  submitted read NAK'd forever and the host timed out. Re-assert ACK when a
  receive is still armed (usbtest toggle test 29).

fsdev (port 0, the shared stm32_fsdev driver):
- The descriptor hard-coded the interrupt mps, so USBTEST_INT_EP_MPS never took
  effect; all six tier-4 endpoints then overflowed the 512 B PMA and SET_CONFIG
  timed out. Wire the interrupt mps to the macro and use 16 on the fsdev port.
- The USBD raises three IRQ lines (LP/HP/WakeUp) into one non-reentrant handler
  and they nest (HP preempts LP) with QingKe HWSTK enabled. The mainline
  toolchain's plain __attribute__((interrupt)) emits a software prologue that
  fights the hardware context stack and corrupts the return on nesting -> wild
  jump / illegal-instruction crash. Emit naked handlers that rely on HWSTK for
  context save/restore -- the equivalent of WCH's "WCH-Interrupt-fast", which
  mainline riscv-none-elf-gcc ignores -- so nesting is safe.
- Single-buffered iso IN can't stay fed under load; double-buffer it
  (CFG_TUD_FSDEV_DOUBLE_BUFFERED_ISO_EP in the example tusb_config.h). iso mps
  32 x2 = 64 B/ep keeps the same PMA budget. Left single for other fsdev parts
  (audio's larger iso would overflow their PMA too).

Verified on nanoch32v203 (CH32V203D6): Linux testusb tier-4 (30 cases across
bulk/control/interrupt/isochronous) = 30/30 on both the fsdev and usbfs variant,
each across 5 reflash cycles. Full CH32V20X example set builds; cdc_msc still
enumerates CDC+MSC on the fsdev port (naked-handler regression check). Drop
CH32V20X from the usbtest skip list.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HeF2gZ1M7GWkz6Av4BpKPg
2026-07-05 22:18:21 +07:00
..