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
src/device/**-> USB device stack- src/tusb.h -> USB device stack
- src/…/usbd.c -> Device core lifecycle
- src/…/usbd_pvt.h -> Device core lifecycle
src/host/**-> USB host stack- src/…/usbh.c -> Host core lifecycle
- src/…/hub.c -> Host core lifecycle
src/class/**-> USB class driverssrc/class/cdc/**-> Serial and human-interface classessrc/class/hid/**-> Serial and human-interface classessrc/class/audio/**-> Media, storage, and connectivity classessrc/class/msc/**-> Media, storage, and connectivity classessrc/class/net/**-> Media, storage, and connectivity classessrc/class/bth/**-> Specialized peripheral classessrc/class/dfu/**-> Specialized peripheral classessrc/class/midi/**-> Specialized peripheral classessrc/class/mtp/**-> Specialized peripheral classessrc/class/printer/**-> Specialized peripheral classessrc/class/usbtmc/**-> Specialized peripheral classessrc/class/vendor/**-> Specialized peripheral classessrc/class/video/**-> Specialized peripheral classeshw/bsp/**-> Platform integrationfamily/**-> Platform integrationsrc/portable/**-> USB controller drivershw/bsp/**-> Board support and build targetsfamily/**/family.cmake-> Board support and build targetssrc/osal/**-> OS abstraction and runtime servicessrc/common/**-> OS abstraction and runtime services- src/tusb_option.h -> OS abstraction and runtime services
src/typec/**-> USB Type-C and Power Deliverysrc/class/usbtmc/**-> USB Type-C and Power Deliveryexamples/**-> Application examplesexamples/device/**-> Device application examplesexamples/dual/**-> Host, dual-role, and Type-C examplesexamples/host/**-> Host, dual-role, and Type-C examplesexamples/typec/**-> Host, dual-role, and Type-C examplestest/**-> Verification and automation.github/workflows/**-> Verification and automationtools/**-> Verification and automation