mirror of
https://github.com/hathach/tinyusb.git
synced 2026-08-18 11:02:16 +00:00
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).
Printer to CDC
This example demonstrates a USB composite device with a Printer class interface and a CDC serial interface. Data flows bidirectionally between the two:
- Data sent to the Printer (from host) is forwarded to the CDC serial port
- Data sent to the CDC serial port (from host) is forwarded to the Printer IN endpoint
This is useful for debugging printer class communication or as a reference for implementing printer class devices.
USB Descriptors
| Interface | Class | Description |
|---|---|---|
| 0 | CDC ACM | Virtual serial port |
| 2 | Printer | USB Printer (bidirectional, protocol 2) |
Configuration
Notable tusb_config.h settings:
#define CFG_TUD_CDC 1
#define CFG_TUD_PRINTER 1
#define CFG_TUD_CDC_RX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
#define CFG_TUD_CDC_TX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
#define CFG_TUD_PRINTER_RX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
#define CFG_TUD_PRINTER_TX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
How to Test
The device exposes two endpoints on the host:
/dev/ttyACM0(CDC serial port)/dev/usb/lp0(USB printer)
Note: the actual device numbers may vary depending on your system.
Prerequisites (Linux):
# Load the USB printer kernel module if not already loaded
sudo modprobe usblp
# Check devices exist
ls /dev/ttyACM* /dev/usb/lp*
Test Printer to CDC (host writes to printer, reads from CDC):
# Terminal 1: read from CDC
cat /dev/ttyACM0
# Terminal 2: write to printer
echo "hello from printer" > /dev/usb/lp0
# "hello from printer" appears in Terminal 1
Test CDC to Printer (host writes to CDC, reads from printer):
# Terminal 1: read from printer IN endpoint
cat /dev/usb/lp0
# Terminal 2: write to CDC
echo "hello from cdc" > /dev/ttyACM0
# "hello from cdc" appears in Terminal 1
Interactive bidirectional test:
# Terminal 1: open CDC serial port
minicom -D /dev/ttyACM0
# Terminal 2: send to printer
echo "tinyusb print example" > /dev/usb/lp0
# Text appears in minicom. Type in minicom to send data back through printer TX.
IEEE 1284 Device ID
The device responds to GET_DEVICE_ID requests with:
MFG:TinyUSB;MDL:Printer to CDC;CMD:PS;CLS:PRINTER;
Verify with:
cat /sys/class/usbmisc/lp0/device/ieee1284_id