mirror of
https://github.com/hathach/tinyusb.git
synced 2026-08-18 11:02:16 +00:00
Fourth view in the USB debugging toolset (usbmon = host URBs, usb-debug = host reasoning, usb-target-debug = device firmware, usb-sniffer = what actually crossed D+/D-). Covers the ataradov/usb-sniffer analyzer: headless pcapng capture (--speed ls/fs/hs, --fold, --limit self-exit), Wireshark/tshark analysis recipes, and the wire realities that bite: downstream broadcast, sniffer self-capture noise, xHCI devnum != wire address, tap-point-dependent reset visibility (hub choreography anchors), FS-behind-HS-hub splits. Every recipe hardware-validated on the rig, including the capture-window floor (a 3 s window provably misses the enumeration ladder; 3M packets minimum). Two udev files with distinct audiences, not one: - examples/device/99-tinyusb-examples.rules (renamed from 99-tinyusb.rules): the user-facing rules the examples need — cafe VID access, hidraw, the ModemManager blacklist, a couple of board probes. getting_started.rst, the webusb_serial README and its source comment point here. - tools/88-tinyusb.rules: the HIL rig's private probe/analyzer allowlist, now with the sniffer (6666:6620 + blank FX2LP 04b4:8613). Installed on the rig only; the usb-sniffer skill references it.
WebUSB Serial
A WebUSB device that acts as a web serial bridge, reachable directly from a WebUSB-capable browser (e.g. Chrome). It also exposes a standard CDC virtual serial port, and bridges traffic between the two.
What it does
- Exposes a Vendor (WebUSB) interface plus a CDC virtual serial port.
- Echoes any data received on either the WebUSB or the CDC interface back to both of them.
- Serves a WebUSB landing-page URL (
example.tinyusb.org/webusb-serial/index.html) via a BOS descriptor, so a supporting browser can offer to open the page. - Provides a Microsoft OS 2.0 descriptor so Windows auto-binds the WinUSB driver to the WebUSB interface.
- Treats a vendor control request as a connect/disconnect signal from the browser; lights the on-board LED solid while the web serial is connected.
- Blinks the on-board LED to reflect bus state: 250 ms unmounted, 1000 ms mounted, 2500 ms suspended.
USB Descriptors
| Interface | Class driver |
|---|---|
| 0–1 | CDC (virtual serial) |
| 2 | Vendor (WebUSB) |
Configuration
Notable tusb_config.h settings:
#define CFG_TUD_CDC 1
#define CFG_TUD_VENDOR 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_VENDOR_RX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
#define CFG_TUD_VENDOR_TX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
Building
CMake:
mkdir build && cd build
cmake -DBOARD=raspberry_pi_pico ..
cmake --build .
Make:
make BOARD=raspberry_pi_pico all
Try it
After flashing, open the landing page (https://example.tinyusb.org/webusb-serial/index.html) in a WebUSB-capable browser such as Chrome, click Connect, and select the device — the on-board LED lights solid once connected. Characters typed in the web page are echoed back, and are also mirrored to the CDC serial port (e.g. /dev/ttyACM0) and vice versa.
On Linux/macOS you may need to install the udev rules from examples/device/99-tinyusb-examples.rules for the browser to access the device.