Introducing a new way to review your PRs.

Read the announcement

hathach / tinyusb

An open source cross-platform USB stack for embedded system

View on GitHub

18 documents · Updated Nov 23, 2026

overview

Knowledge Base updated: 2026-11-22

TinyUSB knowledge base

TinyUSB is a portable embedded USB Host, Device, dual-role, and Type-C/Power Delivery stack. Its public configuration and API surface joins role-specific cores, class drivers, and MCU controller drivers into board-targeted applications.

The central runtime state lives in the device core (src/device/), host core and hub manager (src/host/), class-driver state (src/class/), and portable controller implementations (src/portable/). Compile-time selection and shared runtime facilities are concentrated in src/tusb_option.h, src/common/, and src/osal/.

Examples combine board/build metadata with tusb_config.h and application callbacks. Unit, fuzz, HIL, and CI assets validate the cross-product of supported roles, classes, and controller implementations.

flowchart TD
  App[Application / examples] --> Config[tusb_config.h and tusb_option.h]
  Config --> Core[TinyUSB public API]
  Core --> Device[Device stack]
  Core --> Host[Host stack]
  Core --> TypeC[Type-C / PD]
  Device --> DCore[Device core]
  Host --> HCore[Host core and hubs]
  DCore --> Classes[USB class drivers]
  HCore --> Classes
  DCore --> DCD[Device controller drivers]
  HCore --> HCD[Host controller drivers]
  TypeC --> TCPC[Type-C controller interface]
  DCD --> MCU[MCU USB hardware]
  HCD --> MCU
  Classes --> App
  Core --> OSAL[OSAL and common runtime]
  OSAL --> MCU

Glossary

  • DCD/HCD — TinyUSB device-controller and host-controller driver interfaces implemented by portable MCU/IP backends.
  • USBD/USBH — the device and host core subsystems that own enumeration, transfer lifecycle, and event dispatch.
  • RHPORT — a root-port index used to select a USB controller instance and its role.
  • XFER — a controller-to-core transfer completion event carrying endpoint, result, and byte-count information.
  • TU_VERIFY — common guard macro pattern used to validate conditions and return early through TinyUSB’s error-handling conventions.

Codebase-wide invariants

  • Role and class enablement is compile-time configured; src/tusb_option.h and each application tusb_config.h must agree on enabled stack features.
  • Controller drivers report asynchronous completion to their owning core rather than invoking application logic directly; see DCD/HCD event patterns in src/portable/** and core processing in src/…/usbd.c and src/…/usbh.c.
  • USB protocol work is progressed through the TinyUSB task/event model; applications must service the configured tasking model rather than assuming transfers complete synchronously.
  • Device descriptors and class interfaces must match the enabled device class drivers, as evidenced by descriptor callbacks and configuration parsing in src/…/usbd.c.
  • Host topology is maintained by core and hub state, with attach/removal and hub port events flowing through src/…/usbh.c and src/…/hub.c.

Routing table