Files
tinyusb/examples/host/bare_api
hathach b646a9decf examples: restore host builds on samd2x_l2x
Nine examples/host/*/only.txt gate on family:samd21, but 2a8811ebb merged the
samd2x and saml2x BSPs into hw/bsp/samd2x_l2x. skip_example takes `family:` from
the directory name, so since that rename every one of these examples has been
skipped on every board of the family, under make as well as cmake - although
hw/bsp/samd2x_l2x/family.cmake wires src/portable/microchip/samd/hcd_samd.c.
107 host firmware images were being compiled nowhere.

The merged family is wider than the old samd21 one, so three boards need an
explicit skip rather than the rename alone:

  atsaml21_xpro, saml22_feather, sensorwatch_m0 - not samd21, so hcd_samd.c is
    not compiled for them (previous commit); SAML22 has no host controller at all
  curiosity_nano - SAMD21 with 16 KB RAM; msc_file_explorer_freertos overflows it
    by 3688 bytes (ram 122.51%). Only that one example; the other eight fit.

Verified across the whole family: cmake 11 boards x 9/9 examples + curiosity_nano
8/9, three boards skipped, 0 failures; make 98 OK / 0 failed (was 98/9 before).
Device examples on saml21 and saml22 are unaffected.
2026-08-21 11:06:38 +07:00
..

Host: Bare API

A USB host example that drives the TinyUSB host stack through its low-level API directly, without the higher-level class-driver application layer.

What it does

  • Enumerates any attached device and, on mount, fetches and prints the full device descriptor (VID/PID, USB version, class, max packet size, etc.) over the debug UART.
  • Reads and prints the manufacturer, product, and serial-number string descriptors (UTF-16 to UTF-8).
  • Fetches and walks the configuration descriptor with a small hand-written parser.
  • For any HID interface found, opens its interrupt IN endpoint with the raw endpoint API (tuh_edpt_open / tuh_edpt_xfer) and continuously prints the incoming HID reports as raw hex bytes.
  • Blinks the board LED once per second.

Requirements

The board must support USB host mode (provide VBUS to the connected device); some boards need an external USB-A port / host adapter.

Configuration

Notable tusb_config.h settings:

#define CFG_TUH_ENABLED             1
#define CFG_TUH_HUB                 1
#define CFG_TUH_DEVICE_MAX          (3*CFG_TUH_HUB + 1)
#define CFG_TUH_ENUMERATION_BUFSIZE 256
#define CFG_TUH_API_EDPT_XFER       1

Building

CMake:

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

Make:

make BOARD=raspberry_pi_pico all

How to use

Plug any USB device (a HID keyboard/mouse works well) into the board's USB host port. On attach you should see Device attached followed by the full device/string/configuration descriptor dump on the debug UART. If the device exposes a HID interface, its interrupt-IN reports are printed as hex as they arrive (e.g. when you press a key or move the mouse).