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.
src, MCU/BSP support in hw/{mcu,bsp}, examples under examples/{device,host,dual}, docs in docs, tests under test/{unit-test,fuzz,hil}.tud_/tuh_ for public APIs, TU_ for macros, and keep headers self-contained with #if CFG_TUSB_MCU guards where needed..clang-format for C/C++ formatting, run pre-commit run --all-files before submitting, and document board/HIL coverage when applicable.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), or python3 tools/get_deps.py -b BOARD_NAMElib/ and hw/mcu/ directoriesChoose ONE of these approaches:
Option 1: Individual Example with CMake and Ninja (RECOMMENDED)
cd examples/device/cdc_msc mkdir -p build && cd build cmake -DBOARD=raspberry_pi_pico -G Ninja -DCMAKE_BUILD_TYPE=MinSizeRel .. cmake --build .
-- takes 1-2 seconds. NEVER CANCEL. Set timeout to 5+ minutes.
Option 2: All Examples for a Board
different folder than Option 1
cd examples/ mkdir -p build && cd build cmake -DBOARD=raspberry_pi_pico -G Ninja -DCMAKE_BUILD_TYPE=MinSizeRel .. cmake --build .
-- takes 15-20 seconds, may have some objcopy failures that are non-critical. NEVER CANCEL. Set timeout to 30+ minutes.
Option 3: 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.
-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_fifopython test/hil/hil_test.py -b BOARD_NAME -B examples local.jsonpython test/hil/hil_test.py -B examples local.json-v flag for detailed logs. Also try to observe script output, and try to modify hil_test.py (temporarily) to add more debug prints to pinpoint the issue.take 2-5 minutes. NEVER CANCEL. Set timeout to 20+ minutes.
pip 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)pvs-studio-analyzer analyze -f examples/cmake-build-raspberry_pi_pico/compile_commands.json -R .PVS-Studio/.pvsconfig -o pvs-report.log -j12 --dump-files --misra-cpp-version 2008 --misra-c-version 2023 --use-old-parser
pvs-studio-analyzer analyze -f examples/cmake-build-raspberry_pi_pico/compile_commands.json -R .PVS-Studio/.pvsconfig -S path/to/file.c -o pvs-report.log -j12 --dump-files --misra-cpp-version 2008 --misra-c-version 2023 --use-old-parser
pvs-studio-analyzer analyze -f examples/cmake-build-raspberry_pi_pico/compile_commands.json -R .PVS-Studio/.pvsconfig -S src/file1.c -S src/file2.c -o pvs-report.log -j12 --dump-files --misra-cpp-version 2008 --misra-c-version 2023 --use-old-parser
compile_commands.json in the build directory (generated by CMake with -DCMAKE_EXPORT_COMPILE_COMMANDS=ON)-f option to specify path to compile_commands.json-R .PVS-Studio/.pvsconfig to specify rule configuration file-j12 for parallel analysis with 12 threads--dump-files saves preprocessed files for debugging--misra-c-version 2023 enables MISRA C:2023 checks--misra-cpp-version 2008 enables MISRA C++:2008 checks--use-old-parser uses legacy parser for compatibilityplog-converter -a GA:1,2 -t errorfile pvs-report.log or open in PVS-Studio GUIpre-commit run --all-filespip install pre-commit && pre-commit installstm32f407disco - no external SDK required, good for testingraspberry_pi_pico - requires Pico SDK, commonly usedhw/bsp/FAMILY/boards/ for available boardsDO NOT commit files automatically - only modify files and let the maintainer review before committing.
tools/make_release.py.python3 tools/make_release.py to refresh:src/tusb_option.h (version defines)repository.yml (version mapping)library.json (PlatformIO version)sonar-project.properties (SonarQube version)docs/reference/boards.rst (generated board documentation)hw/bsp/BoardPresets.json (CMake presets)docs/info/changelog.rst:git log <last-release-tag>..HEAD --onelinegithub-mcp-server-list_pull_requests, github-mcp-server-pull_request_read0.20.0 followed by ======)*November 19, 2024*)cd test/unit-test && ceedling test:allcd examples/device/cdc_msc && make BOARD=stm32f407disco allgit diff --statBump version to X.Y.Zgit tag -a vX.Y.Z -m "Release X.Y.Z"git push origin <branch> && git push origin vX.Y.Z├── 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.