TinyUSB is an open-source cross-platform USB Host/Device stack for embedded systems, designed to be memory-safe with no dynamic allocation and thread-safe with all interrupt events deferred to non-ISR task functions.
Always reference these instructions first and fallback to search or bash commands only when you encounter unexpected information that does not match the info here.
sudo apt-get update && sudo apt-get install -y gcc-arm-none-eabipython3 tools/get_deps.py -- takes <1 second. NEVER CANCEL.python3 tools/get_deps.py FAMILY_NAME (e.g., rp2040, stm32f4)lib/ and hw/mcu/ directoriesChoose ONE of these approaches:
Option 1: Individual Example with CMake (RECOMMENDED)
cd examples/device/cdc_msc mkdir -p build && cd build cmake -DBOARD=raspberry_pi_pico -DCMAKE_BUILD_TYPE=MinSizeRel .. cmake --build . -j4
-- takes 1-2 seconds. NEVER CANCEL. Set timeout to 5+ minutes.
CMake with Ninja (Alternative)
cd examples/device/cdc_msc mkdir build && cd build cmake -G Ninja -DBOARD=raspberry_pi_pico .. ninja
Option 2: Individual Example with Make
cd examples/device/cdc_msc make BOARD=raspberry_pi_pico all
-- takes 2-3 seconds. NEVER CANCEL. Set timeout to 5+ minutes.
Option 3: All Examples for a Board
python3 tools/build.py -b BOARD_NAME
-- takes 15-20 seconds, may have some objcopy failures that are non-critical. NEVER CANCEL. Set timeout to 30+ minutes.
-DCMAKE_BUILD_TYPE=DebugDEBUG=1-DLOG=2LOG=2-DLOG=2 -DLOGGER=rttLOG=2 LOGGER=rtt-DRHPORT_DEVICE=1RHPORT_DEVICE=1-DRHPORT_DEVICE_SPEED=OPT_MODE_FULL_SPEEDRHPORT_DEVICE_SPEED=OPT_MODE_FULL_SPEEDninja cdc_msc-jlinkmake BOARD=raspberry_pi_pico flash-jlinkninja cdc_msc-openocdmake BOARD=raspberry_pi_pico flash-openocdninja cdc_msc-uf2make BOARD=raspberry_pi_pico all uf2ninja -t targetssudo gem install ceedlingcd test/unit-test && ceedling or cd test/unit-test && ceedling test:all -- takes 4 seconds. NEVER CANCEL. Set timeout to 10+ minutes.cd test/unit-test && ceedling test:test_fifopip install -r docs/requirements.txtcd docs && sphinx-build -b html . _build -- takes 2-3 seconds. NEVER CANCEL. Set timeout to 10+ minutes.clang-format -i path/to/file.c (uses .clang-format config)pip install codespell && codespell (uses .codespellrc config)pre-commit run --all-filespip install pre-commit && pre-commit installcd examples/device/cdc_msc make BOARD=raspberry_pi_pico all
stm32f407disco - no external SDK required, good for testingraspberry_pi_pico - requires Pico SDK, commonly usedhw/bsp/FAMILY/boards/ for available boards├── src/ # Core TinyUSB stack │ ├── class/ # USB device classes (CDC, HID, MSC, Audio, etc.) │ ├── portable/ # MCU-specific drivers (organized by vendor) │ ├── device/ # USB device stack core │ ├── host/ # USB host stack core │ └── common/ # Shared utilities (FIFO, etc.) ├── examples/ # Example applications │ ├── device/ # Device examples (cdc_msc, hid_generic, etc.) │ ├── host/ # Host examples │ └── dual/ # Dual-role examples ├── hw/bsp/ # Board Support Packages │ └── FAMILY/boards/ # Board-specific configurations ├── test/unit-test/ # Unit tests using Ceedling ├── tools/ # Build and utility scripts └── docs/ # Sphinx documentation
tools/get_deps.py: Manages dependencies for MCU familiestools/build.py: Builds multiple examples, supports make/cmakesrc/tusb.h: Main TinyUSB header filesrc/tusb_config.h: Configuration templateexamples/device/cdc_msc/: Most commonly used example for testingtest/unit-test/project.yml: Ceedling test configurationgcc-arm-none-eabi packagepython3 tools/get_deps.py FAMILYhw/bsp/FAMILY/boards/ for valid board namessrc/class/cdc/ - Virtual serial portsrc/class/hid/ - Human Interface Device (keyboard, mouse, etc.)src/class/msc/ - Mass Storage Class (USB drive)src/class/audio/ - USB Audio Class*_device.c) and host (*_host.c) implementationshw/bsp/ for complete list and docs/reference/boards.rst for detailsRemember: TinyUSB is designed for embedded systems - builds are fast, tests are focused, and the codebase is optimized for resource-constrained environments.