Files
tinyusb/examples/device/cdc_msc_throughput
hathach 36cd9f9f46 dcd_lpc17_40: fix stale EP0 out_received, add isochronous support
EP0 control-OUT fix (usbtest 14/21, errno 110/-74): usbd queues the
status-stage OUT ZLP of every control read with buffer=NULL, so the ISR's
`if (out_buffer)` check missed it and marked the arriving ZLP as
out_received instead. The stale flag poisoned the next control-OUT with
data: its first chunk "completed" instantly from an empty EP0 buffer and
the host's real DATA NAKed forever. Track queued transfers with an
explicit out_queued flag and void half-finished control state on a new
SETUP.

Isochronous support (UM10562 12.15.6): 5-word DMA descriptors with
per-packet size memory, buflen/present_count in packets, one packet per
FRAME (no DMARSet/EpIntEn involvement), completion at EOT for both
directions. Details that matter:
- the iso machinery (5th DD word + packet-size memory) is compiled only
  when an iso-capable class is enabled (CFG_TUD_AUDIO/VIDEO/VENDOR), so
  non-iso builds pay nothing: _dcd stays 648 B vs 1032 B with iso
- ISR dispatch keys on the hardware's fixed ep-number/type map
  (ep_id_is_iso), never on dd fields that thread mode rebuilds
- iso OUT honors Packet_valid (bit 16) and prefills the hardware
  writeback slots with 0, so a missed frame counts as 0 bytes instead of
  reading back stale buffer contents as data
- packet count is validated (tu_div_ceil <= ISO_MAX_PACKETS) before the
  DD is touched, so an oversized transfer is refused without leaving a
  serviceable half-built descriptor armed for the frame engine
- dcd_edpt_iso_alloc and iso_activate both enforce the fixed iso endpoint
  numbers (3/6/9/12); classes ignore alloc's return value, so activate
  must not trust it

Un-skip LPC40XX in the usbtest example; tier 4 now enumerates and passes
iso cases 15/16/22/23. cdc_msc_throughput and printer_to_cdc had bulk on
iso-only EP3 (SET_CONFIGURATION failed with -32); add the LPC17/40 EPNUM
block (bulk on EP2/EP5) like other fixed-EP examples.

Verified on ea4088_quickstart: usbtest tier-4 battery 30/30 repeatedly
and the full device HIL suite 14/14 (incl. audio_test iso).
2026-07-17 16:48:01 +07:00
..
2026-04-23 23:38:54 +07:00
2026-05-23 19:37:47 +02:00
2026-04-23 23:38:54 +07:00

CDC + MSC Throughput

A deliberately minimal CDC + MSC composite device for measuring pure USB bulk throughput — the ceiling set by the USB link and the TinyUSB driver, with no backing storage or per-byte work in the way.

How it measures the ceiling, not storage

  • MSC advertises a 1 GiB logical disk (2 Mi × 512-byte blocks) but has no real backing store. Writes are discarded; reads zero-fill only the low LBAs the host scans during enumeration (partition table / GPT header) and otherwise return whatever is already in the transfer buffer — so no memset/copy cost skews the result.
  • CDC drains its RX in tud_cdc_rx_cb and sources TX from a static zero filler, so dd can push data in either direction over /dev/ttyACMx.

The 1 GiB capacity lets dd run long enough for the rate to stabilise; high-speed peripherals show the most headroom.

USB Descriptors

Interface Class driver
01 CDC (virtual serial)
2 MSC (mass storage)

Configuration

Notable tusb_config.h settings (tuned for throughput):

#define CFG_TUD_CDC              1
#define CFG_TUD_MSC              1
#define CFG_TUD_MSC_EP_BUFSIZE   (TUD_OPT_HIGH_SPEED  ? 4096 : 1024)  // large MSC bulk buffer
#define CFG_TUD_CDC_RX_EPSIZE    (TUD_OPT_HIGH_SPEED ? 2*512 : 2*64)
#define CFG_TUD_CDC_TX_EPSIZE    CFG_TUD_CDC_RX_EPSIZE
#define CFG_TUD_CDC_RX_BUFSIZE   (TUD_OPT_HIGH_SPEED ? 2*512 : 2*64)
#define CFG_TUD_CDC_TX_BUFSIZE   CFG_TUD_CDC_RX_BUFSIZE

Building

CMake:

mkdir build && cd build
cmake -DBOARD=raspberry_pi_pico ..
cmake --build .

Make:

make BOARD=raspberry_pi_pico all

Measuring throughput (Linux)

The MSC disk appears as a raw block device (e.g. /dev/sdX); the CDC port as /dev/ttyACMx.

# MSC read (device → host)
sudo dd if=/dev/sdX of=/dev/null bs=1M count=256 iflag=direct

# MSC write (host → device, discarded)
sudo dd if=/dev/zero of=/dev/sdX bs=1M count=256 oflag=direct

# CDC read (device → host)
dd if=/dev/ttyACM0 of=/dev/null bs=64k count=4096

Pick the right /dev/sdX carefully — writing to the wrong block device destroys data.