### CMakeLists.txt for Device Info Example Source: https://github.com/hathach/tinyusb/blob/master/examples/host/device_info/CMakeLists.txt This CMakeLists.txt file configures the build for the device_info example. It includes family-specific setup and defines the executable, source files, and include directories. ```cmake cmake_minimum_required(VERSION 3.20) include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/family_support.cmake) project(device_info C CXX ASM) # Checks this example is valid for the family and initializes the project family_initialize_project(${PROJECT_NAME} ${CMAKE_CURRENT_LIST_DIR}) # Espressif has its own cmake build system if(FAMILY STREQUAL "espressif") return() endif() add_executable(${PROJECT_NAME}) # Example source target_sources(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c ) # Example include target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src ) # Configure compilation flags and libraries for the example without RTOS. # See the corresponding function in hw/bsp/FAMILY/family.cmake for details. family_configure_host_example(${PROJECT_NAME} noos) ``` -------------------------------- ### Build Simple Host Example with Make Source: https://github.com/hathach/tinyusb/blob/master/docs/getting_started.md Build and flash the cdc_msc_hid host example using Make. This example acts as a USB host for CDC, MSC, and HID devices. ```bash $ cd examples/host/cdc_msc_hid $ make BOARD=stm32h743eval all $ make BOARD=stm32h743eval flash-jlink ``` -------------------------------- ### Navigate to Example Directory Source: https://github.com/hathach/tinyusb/blob/master/examples/device/audio_4_channel_mic_freertos/README.md Change the current directory to the audio 4-channel microphone FreeRTOS example. ```bash cd /tinyusb/examples/device/audio_4_channel_mic_freertos ``` -------------------------------- ### Navigate to Example Directory Source: https://github.com/hathach/tinyusb/blob/master/examples/device/audio_test_freertos/README.md Change the current directory to the audio_test_freertos example within the TinyUSB project. ```bash cd /tinyusb/examples/device/audio_test_freertos ``` -------------------------------- ### Basic CMake Project Setup Source: https://github.com/hathach/tinyusb/blob/master/examples/device/cdc_uac2/CMakeLists.txt Initializes the CMake build system, sets the minimum version, and includes family-specific support scripts. This is a standard starting point for CMake projects. ```cmake cmake_minimum_required(VERSION 3.20) include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/family_support.cmake) project(cdc_uac2 C CXX ASM) ``` -------------------------------- ### Build Simple Device Example with Make Source: https://github.com/hathach/tinyusb/blob/master/docs/getting_started.md Build and flash the cdc_msc example using Make. This example creates a USB device with a virtual serial port and mass storage. ```bash $ cd examples/device/cdc_msc $ make BOARD=stm32h743eval all $ make BOARD=stm32h743eval flash-jlink ``` -------------------------------- ### CMakeLists.txt for Dynamic Dual USB Example Source: https://github.com/hathach/tinyusb/blob/master/examples/dual/dynamic_switch/CMakeLists.txt Configures the build for the dynamic dual USB example. It includes family support, sets up the project, and adds source files. This configuration is specifically for examples without an RTOS. ```cmake cmake_minimum_required(VERSION 3.20) include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/family_support.cmake) project(dynamic_switch C CXX ASM) # Checks this example is valid for the family and initializes the project family_initialize_project(${PROJECT_NAME} ${CMAKE_CURRENT_LIST_DIR}) # Espressif has its own cmake build system if(FAMILY STREQUAL "espressif") return() endif() add_executable(${PROJECT_NAME}) # Example source target_sources(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c ) # Example include target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src ) # Configure compilation flags and libraries for the example without RTOS. # See the corresponding function in hw/bsp/FAMILY/family.cmake for details. family_configure_dual_usb_example(${PROJECT_NAME} noos) ``` -------------------------------- ### Build TinyUSB Example Source: https://github.com/hathach/tinyusb/blob/master/docs/porting.md Use this command to build a TinyUSB device example for a specific board. This command is run from the root of the TinyUSB repository. ```bash make -C examples/device/cdc_msc BOARD= ``` -------------------------------- ### Build Simple Host Example with CMake Source: https://github.com/hathach/tinyusb/blob/master/docs/getting_started.md Build the cdc_msc_hid host example using CMake. This example creates a USB host that can enumerate and communicate with CDC, MSC, and HID devices. ```bash $ cd examples/host/cdc_msc_hid $ cmake -DBOARD=stm32h743eval -B build $ cmake --build build ``` -------------------------------- ### Install ARM Toolchain and Fetch Dependencies Source: https://github.com/hathach/tinyusb/blob/master/CLAUDE.md Installs the necessary ARM toolchain and fetches project dependencies. Run this once before building. ```bash sudo apt-get install -y gcc-arm-none-eabi # ARM toolchain (2-5 min, one-time) python3 tools/get_deps.py [FAMILY|-b BOARD] # fetch deps into lib/, hw/mcu/ (<1 s) ``` -------------------------------- ### Build Simple Device Example with CMake Source: https://github.com/hathach/tinyusb/blob/master/docs/getting_started.md Build the cdc_msc example, which creates a USB device with a virtual serial port and mass storage, using CMake. Ensure you are in the example's directory. ```bash $ cd examples/device/cdc_msc $ cmake -DBOARD=stm32h743eval -B build # add "-G Ninja" to use Ninja build $ cmake --build build # cmake --build build --target cdc_msc-jlink ``` -------------------------------- ### Example Output Log Source: https://github.com/hathach/tinyusb/blob/master/hw/bsp/espressif/components/led_strip/examples/led_strip_rmt_ws2812/README.md This is a sample of the expected output logs when the example is running. It indicates GPIO configuration and LED strip initialization. ```text I (299) gpio: GPIO[8]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 I (309) example: Created LED strip object with RMT backend I (309) example: Start blinking LED strip ``` -------------------------------- ### Build Single Example with Make Source: https://github.com/hathach/tinyusb/blob/master/CLAUDE.md Builds a single example using the Make build system. Specify the board using the BOARD variable. ```bash cd examples/device/cdc_msc && make BOARD=raspberry_pi_pico all ``` -------------------------------- ### Build Single Example with CMake Source: https://github.com/hathach/tinyusb/blob/master/CLAUDE.md Builds a single example using CMake and Ninja. Recommended for most use cases due to speed. ```bash cd examples/device/cdc_msc && mkdir -p build && cd build cmake -DBOARD=raspberry_pi_pico -G Ninja -DCMAKE_BUILD_TYPE=MinSizeRel .. cmake --build . ``` -------------------------------- ### Minimal TinyUSB Integration Example Source: https://github.com/hathach/tinyusb/blob/master/docs/integration.md This example demonstrates the basic initialization and task handling for both device and host stacks. Ensure your board initialization and application logic are implemented separately. ```c #include "tusb.h" int main(void) { board_init(); // Your board initialization // Init device stack on roothub port 0 for highspeed device tusb_rhport_init_t dev_init = { .role = TUSB_ROLE_DEVICE, .speed = TUSB_SPEED_HIGH }; tusb_init(0, &dev_init); // init host stack on roothub port 1 for fullspeed host tusb_rhport_init_t host_init = { .role = TUSB_ROLE_HOST, .speed = TUSB_SPEED_FULL }; tusb_init(1, &host_init); while (1) { tud_task(); // device task tuh_task(); // host task app_task(); // Your application logic } } void USB0_IRQHandler(void) { // forward interrupt port 0 to TinyUSB stack tusb_int_handler(0, true); } void USB1_IRQHandler(void) { // forward interrupt port 1 to TinyUSB stack tusb_int_handler(1, true); } ``` -------------------------------- ### Build Espressif ESP-IDF Example Source: https://github.com/hathach/tinyusb/blob/master/CLAUDE.md Builds an example specifically for Espressif devices using the ESP-IDF build system. Ensure the ESP-IDF environment is sourced first. ```bash . $HOME/code/esp-idf/export.sh cd examples/device/cdc_msc_freertos idf.py -DBOARD=espressif_s3_devkitc build ``` -------------------------------- ### Start OpenOCD Server Source: https://github.com/hathach/tinyusb/blob/master/CLAUDE.md Starts the OpenOCD server for debugging. Specify the interface and target configuration files. ```bash openocd -f interface/stlink.cfg -f target/stm32h7x.cfg # or with a J-Link interface: openocd -f interface/jlink.cfg -f target/stm32h7x.cfg # rp2040/rp2350 via CMSIS-DAP: openocd -f interface/cmsis-dap.cfg -f target/rp2040.cfg -c "adapter speed 5000" ``` -------------------------------- ### CMakeLists.txt Configuration for Audio Example Source: https://github.com/hathach/tinyusb/blob/master/examples/device/audio_4_channel_mic_freertos/CMakeLists.txt This CMakeLists.txt file sets up the build environment for the audio 4-channel microphone example. It includes family support, initializes the project, defines the executable, specifies source files and include directories, and links necessary libraries like 'm' for GCC. It also configures the example for FreeRTOS using a family-specific function. ```cmake cmake_minimum_required(VERSION 3.20) include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/family_support.cmake) project(audio_4_channel_mic_freertos C CXX ASM) # Checks this example is valid for the family and initializes the project family_initialize_project(${PROJECT_NAME} ${CMAKE_CURRENT_LIST_DIR}) # Espressif has its own cmake build system if(FAMILY STREQUAL "espressif") return() endif() add_executable(${PROJECT_NAME}) # Example source target_sources(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c ) # Example include target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src ) # Add libm for GCC if (CMAKE_C_COMPILER_ID STREQUAL "GNU") target_link_libraries(${PROJECT_NAME} PUBLIC m) endif() # Configure compilation flags and libraries for the example with FreeRTOS. # See the corresponding function in hw/bsp/FAMILY/family.cmake for details. family_configure_device_example(${PROJECT_NAME} freertos) ``` -------------------------------- ### CMakeLists.txt for MIDI Example Source: https://github.com/hathach/tinyusb/blob/master/examples/device/midi_test/CMakeLists.txt This CMakeLists.txt file sets up the build environment for the MIDI example. It includes necessary family support, defines the executable, and specifies source files and include directories. ```cmake cmake_minimum_required(VERSION 3.20) include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/family_support.cmake) project(midi_test C CXX ASM) # Checks this example is valid for the family and initializes the project family_initialize_project(${PROJECT_NAME} ${CMAKE_CURRENT_LIST_DIR}) # Espressif has its own cmake build system if(FAMILY STREQUAL "espressif") return() endif() add_executable(${PROJECT_NAME}) # Example source target_sources(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c ) # Example include target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src ) # Configure compilation flags and libraries for the example without RTOS. # See the corresponding function in hw/bsp/FAMILY/family.cmake for details. family_configure_device_example(${PROJECT_NAME} noos) ``` -------------------------------- ### Device Example Configuration Source: https://github.com/hathach/tinyusb/blob/master/examples/device/cdc_uac2/CMakeLists.txt Configures compilation flags and libraries specific to the device example, utilizing family-specific settings. This function handles platform-dependent build configurations. ```cmake # Configure compilation flags and libraries for the example... see the corresponding function # in hw/bsp/FAMILY/family.cmake for details. family_configure_device_example(${PROJECT_NAME} noos) ``` -------------------------------- ### Configure Device Example (No RTOS) Source: https://github.com/hathach/tinyusb/blob/master/test/fuzz/device/net/CMakeLists.txt Configures compilation flags and libraries for a device example without an RTOS. Consult the family-specific CMake file for details. ```cmake family_configure_device_example(${PROJECT_NAME} noos) ``` -------------------------------- ### CMakeLists.txt for CDC Example Source: https://github.com/hathach/tinyusb/blob/master/test/fuzz/device/cdc/CMakeLists.txt Defines the build configuration for the CDC example, including executable name, source files, include directories, and device-specific settings. ```cmake cmake_minimum_required(VERSION 3.5) include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/family_support.cmake) project(cdc) # Checks this example is valid for the family and initializes the project family_initialize_project(${PROJECT_NAME} ${CMAKE_CURRENT_LIST_DIR}) add_executable(${PROJECT_NAME}) # Example source target_sources(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c ${CMAKE_CURRENT_SOURCE_DIR}/src/msc_disk.c ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c ) # Example include target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src ) # Configure compilation flags and libraries for the example without RTOS. # See the corresponding function in hw/bsp/FAMILY/family.cmake for details. family_configure_device_example(${PROJECT_NAME} noos) ``` -------------------------------- ### Build Example for Raspberry Pi Pico Source: https://github.com/hathach/tinyusb/blob/master/examples/host/msc_file_explorer/README.md Build the MSC File Explorer example for a specific board like Raspberry Pi Pico using CMake. Ensure you have the correct board and family defined. ```bash cmake -B build -DBOARD=raspberry_pi_pico -DFAMILY=rp2040 examples/host/msc_file_explorer cmake --build build ``` -------------------------------- ### Install Build Tools (Ubuntu/Debian) Source: https://github.com/hathach/tinyusb/blob/master/docs/troubleshooting.md Installs essential build tools like make and CMake on Ubuntu or Debian systems. ```bash # Ubuntu/Debian $ sudo apt-get install build-essential cmake ``` -------------------------------- ### CMakeLists.txt for HID Generic In/Out Example Source: https://github.com/hathach/tinyusb/blob/master/examples/device/hid_generic_inout/CMakeLists.txt Configures the build for the HID Generic In/Out example. It sets the minimum CMake version, includes family support, initializes the project, and defines the executable with its source files and include directories. It also includes a conditional return for Espressif family to use its own build system. ```cmake cmake_minimum_required(VERSION 3.20) include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/family_support.cmake) project(hid_generic_inout C CXX ASM) # Checks this example is valid for the family and initializes the project family_initialize_project(${PROJECT_NAME} ${CMAKE_CURRENT_LIST_DIR}) # Espressif has its own cmake build system if(FAMILY STREQUAL "espressif") return() endif() add_executable(${PROJECT_NAME}) # Example source target_sources(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c ) # Example include target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src ) # Configure compilation flags and libraries for the example without RTOS. # See the corresponding function in hw/bsp/FAMILY/family.cmake for details. family_configure_device_example(${PROJECT_NAME} noos) ``` -------------------------------- ### CMakeLists.txt for UAC2 Headset Example Source: https://github.com/hathach/tinyusb/blob/master/examples/device/uac2_headset/CMakeLists.txt This is the main CMakeLists.txt file for the UAC2 headset example. It sets up the project, includes family-specific support, and defines the executable and its sources. ```cmake cmake_minimum_required(VERSION 3.20) include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/family_support.cmake) project(uac2_headset C CXX ASM) # Checks this example is valid for the family and initializes the project family_initialize_project(${PROJECT_NAME} ${CMAKE_CURRENT_LIST_DIR}) # Espressif has its own cmake build system if(FAMILY STREQUAL "espressif") return() endif() add_executable(${PROJECT_NAME}) # Example source target_sources(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c ) # Example include target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src ) # Configure compilation flags and libraries for the example without RTOS. # See the corresponding function in hw/bsp/FAMILY/family.cmake for details. family_configure_device_example(${PROJECT_NAME} noos) ``` -------------------------------- ### Build All Examples for a Board with CMake Source: https://github.com/hathach/tinyusb/blob/master/CLAUDE.md Builds all examples for a specified board using CMake. The build directory is named 'cmake-build-' as expected by HIL tests. ```bash cd examples cmake -B cmake-build-raspberry_pi_pico -DBOARD=raspberry_pi_pico -G Ninja -DCMAKE_BUILD_TYPE=MinSizeRel . cmake --build cmake-build-raspberry_pi_pico ``` -------------------------------- ### Device Setup Functions Source: https://github.com/hathach/tinyusb/blob/master/docs/porting.md Functions for initializing and managing the USB peripheral in device mode. ```APIDOC ## `dcd_init()` ### Description Initializes the USB peripheral for device mode and enables it. This function should enable internal D+/D- pull-up for enumeration. ### Method `dcd_init()` ### Endpoint N/A (Device-level function) ### Parameters None ### Request Example ```c dcd_init(); ``` ### Response None ``` ```APIDOC ## `dcd_int_enable()` / `dcd_int_disable()` ### Description Enables or disables the USB device interrupt(s). May be used to prevent concurrency issues when mutating data structures shared between main code and the interrupt handler. ### Method `dcd_int_enable()` or `dcd_int_disable()` ### Endpoint N/A (Device-level function) ### Parameters None ### Request Example ```c dcd_int_enable(); dcd_int_disable(); ``` ### Response None ``` ```APIDOC ## `dcd_int_handler()` ### Description Processes all hardware-generated events (e.g., Bus reset, new data packet from host). It will be called by the application in the MCU USB interrupt handler. ### Method `dcd_int_handler()` ### Endpoint N/A (Device-level function) ### Parameters None ### Request Example ```c // Called from MCU's USB interrupt handler dcd_int_handler(); ``` ### Response None ``` ```APIDOC ## `dcd_set_address()` ### Description Called when the device is given a new bus address. If your peripheral automatically changes address during enumeration (like the nrf52), you may leave this empty and also not queue an event for the corresponding SETUP packet. ### Method `dcd_set_address()` ### Endpoint N/A (Device-level function) ### Parameters - **address** (uint8_t) - The new bus address assigned to the device. ### Request Example ```c dcd_set_address(my_new_address); ``` ### Response None ``` ```APIDOC ## `dcd_remote_wakeup()` ### Description Called to remote wake up the host when the device is suspended (e.g., for a HID keyboard). ### Method `dcd_remote_wakeup()` ### Endpoint N/A (Device-level function) ### Parameters None ### Request Example ```c dcd_remote_wakeup(); ``` ### Response None ``` ```APIDOC ## `dcd_connect()` / `dcd_disconnect()` ### Description Connect or disconnect the data-line pull-up resistor. Define only if the MCU has an internal pull-up. (BSP may define for MCUs without internal pull-up.) ### Method `dcd_connect()` or `dcd_disconnect()` ### Endpoint N/A (Device-level function) ### Parameters None ### Request Example ```c dcd_connect(); dcd_disconnect(); ``` ### Response None ``` -------------------------------- ### Configure HID Controller Project with CMake Source: https://github.com/hathach/tinyusb/blob/master/examples/host/hid_controller/CMakeLists.txt Sets up the project, includes family support, and defines executable sources and include directories for the HID controller example. It also configures host example compilation flags and libraries. ```cmake cmake_minimum_required(VERSION 3.20) include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/family_support.cmake) project(hid_controller C CXX ASM) # Checks this example is valid for the family and initializes the project family_initialize_project(${PROJECT_NAME} ${CMAKE_CURRENT_LIST_DIR}) # Espressif has its own cmake build system if(FAMILY STREQUAL "espressif") return() endif() add_executable(${PROJECT_NAME}) # Example source target_sources(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src/hid_app.c ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c ) # Example include target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src ) # Configure compilation flags and libraries for the example without RTOS. # See the corresponding function in hw/bsp/FAMILY/family.cmake for details. family_configure_host_example(${PROJECT_NAME} noos) ``` -------------------------------- ### Build Documentation with Sphinx Source: https://github.com/hathach/tinyusb/blob/master/CLAUDE.md Installs documentation dependencies and builds the HTML documentation using Sphinx. ```bash pip install -r docs/requirements.txt cd docs && sphinx-build -b html . _build # ~2.5 s ``` -------------------------------- ### CMakeLists.txt for Dual USB CDC Example Source: https://github.com/hathach/tinyusb/blob/master/examples/dual/host_info_to_device_cdc/CMakeLists.txt This CMakeLists.txt file configures the build for the dual USB CDC example. It includes family-specific support, sets project properties, adds executable sources, and configures include directories and compilation flags, with special handling for the RP2040 family. ```cmake cmake_minimum_required(VERSION 3.20) include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/family_support.cmake) project(host_info_to_device_cdc C CXX ASM) # Checks this example is valid for the family and initializes the project family_initialize_project(${PROJECT_NAME} ${CMAKE_CURRENT_LIST_DIR}) # Espressif has its own cmake build system if(FAMILY STREQUAL "espressif") return() endif() add_executable(${PROJECT_NAME}) # Example source target_sources(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c ) # Example include target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src ) # Configure compilation flags and libraries for the example without RTOS. # See the corresponding function in hw/bsp/FAMILY/family.cmake for details. family_configure_dual_usb_example(${PROJECT_NAME} ${RTOS}) # due to warnings from Pico-PIO-USB if (FAMILY STREQUAL rp2040) target_compile_options(${PROJECT_NAME} PUBLIC -Wno-error=shadow -Wno-error=cast-align -Wno-error=cast-qual -Wno-error=redundant-decls -Wno-error=sign-conversion -Wno-error=conversion -Wno-error=sign-compare -Wno-error=unused-function ) endif () ``` -------------------------------- ### Family-Specific Device Example Configuration Source: https://github.com/hathach/tinyusb/blob/master/examples/device/net_lwip_webserver/CMakeLists.txt Configures compilation flags and libraries for the example, specifically for a no-RTOS environment. This function is typically defined in the family's CMake configuration file. ```cmake # Configure compilation flags and libraries for the example without RTOS. # See the corresponding function in hw/bsp/FAMILY/family.cmake for details. family_configure_device_example(${PROJECT_NAME} noos) ``` -------------------------------- ### CMakeLists.txt Configuration for Audio Test Multi-Rate Source: https://github.com/hathach/tinyusb/blob/master/examples/device/audio_test_multi_rate/CMakeLists.txt Configures the CMake build system for the audio test multi-rate example. It sets the minimum CMake version, includes family support, defines the project, initializes the project for the specific family, and adds the executable with its source files and include directories. It also configures device example settings, specifically for a no-RTOS environment. ```cmake cmake_minimum_required(VERSION 3.20) include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/family_support.cmake) project(audio_test_multi_rate C CXX ASM) # Checks this example is valid for the family and initializes the project family_initialize_project(${PROJECT_NAME} ${CMAKE_CURRENT_LIST_DIR}) # Espressif has its own cmake build system if(FAMILY STREQUAL "espressif") return() endif() add_executable(${PROJECT_NAME}) # Example source target_sources(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c ) # Example include target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src ) # Configure compilation flags and libraries for the example without RTOS. # See the corresponding function in hw/bsp/FAMILY/family.cmake for details. family_configure_device_example(${PROJECT_NAME} noos) ``` -------------------------------- ### Initial Device Connection Prompt Source: https://github.com/hathach/tinyusb/blob/master/examples/host/msc_file_explorer/README.md This is the initial output displayed when a USB flash drive is connected and automatically mounted by the MSC File Explorer example. ```text TinyUSB MSC File Explorer Example Device connected Vendor : Kingston Product : DataTraveler 2.0 Rev : 1.0 Capacity: 1.9 GB 0:/> _ ``` -------------------------------- ### CMakeLists.txt for CDC MSC Example Source: https://github.com/hathach/tinyusb/blob/master/examples/device/cdc_msc/CMakeLists.txt Sets up the CMake build for the CDC MSC example. It defines the project, executable name, source files, and include directories. It also includes conditional logic for different RTOS and family configurations. ```cmake cmake_minimum_required(VERSION 3.20) include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/family_support.cmake) project(cdc_msc C CXX ASM) # Checks this example is valid for the family and initializes the project family_initialize_project(${PROJECT_NAME} ${CMAKE_CURRENT_LIST_DIR}) # Espressif has its own cmake build system if(FAMILY STREQUAL "espressif") return() endif() if (RTOS STREQUAL zephyr) set(EXE_NAME app) else() set(EXE_NAME ${PROJECT_NAME}) add_executable(${EXE_NAME}) endif() # Example source target_sources(${EXE_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c ${CMAKE_CURRENT_SOURCE_DIR}/src/msc_disk.c ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c ) # Example include target_include_directories(${EXE_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src ) # Configure compilation flags and libraries for the example without RTOS. # See the corresponding function in hw/bsp/FAMILY/family.cmake for details. family_configure_device_example(${EXE_NAME} ${RTOS}) ``` -------------------------------- ### Install Missing Dependencies Source: https://github.com/hathach/tinyusb/blob/master/CLAUDE.md Installs missing dependencies for a specific family of boards. ```bash python3 tools/get_deps.py FAMILY ``` -------------------------------- ### Install Missing Dependencies Source: https://github.com/hathach/tinyusb/blob/master/AGENTS.md Installs necessary dependencies for building TinyUSB, such as the ARM GCC compiler or project-specific libraries. ```bash install gcc-arm-none-eabi ``` ```bash python3 tools/get_deps.py FAMILY ``` -------------------------------- ### Install ARM GCC Toolchain (macOS) Source: https://github.com/hathach/tinyusb/blob/master/docs/troubleshooting.md Installs the ARM GCC toolchain on macOS using Homebrew. Ensure this is in your PATH. ```bash # macOS with Homebrew $ brew install --cask gcc-arm-embedded ``` -------------------------------- ### Install ARM GCC Toolchain (Ubuntu/Debian) Source: https://github.com/hathach/tinyusb/blob/master/docs/troubleshooting.md Installs the ARM GCC toolchain on Ubuntu or Debian-based systems. Ensure this is in your PATH. ```bash # Ubuntu/Debian $ sudo apt-get update && sudo apt-get install gcc-arm-none-eabi ``` -------------------------------- ### Install ARM GCC Toolchain Source: https://github.com/hathach/tinyusb/blob/master/docs/faq.md Installs the ARM GCC toolchain on Ubuntu/Debian. Download from ARM's website for other platforms. ```bash sudo apt-get install gcc-arm-none-eabi ``` -------------------------------- ### Project Setup and Source Inclusion Source: https://github.com/hathach/tinyusb/blob/master/examples/device/audio_4_channel_mic/CMakeLists.txt Configures the project name, includes family support, and adds source files for the main application and USB descriptors. Links the math library for GCC. ```cmake cmake_minimum_required(VERSION 3.20) include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/family_support.cmake) project(audio_4_channel_mic C CXX ASM) # Checks this example is valid for the family and initializes the project family_initialize_project(${PROJECT_NAME} ${CMAKE_CURRENT_LIST_DIR}) # Espressif has its own cmake build system if(FAMILY STREQUAL "espressif") return() endif() add_executable(${PROJECT_NAME}) # Example source target_sources(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c ) # Example include target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src ) # Add libm for GCC if (CMAKE_C_COMPILER_ID STREQUAL "GNU") target_link_libraries(${PROJECT_NAME} PUBLIC m) endif() # Configure compilation flags and libraries for the example without RTOS. # See the corresponding function in hw/bsp/FAMILY/family.cmake for details. family_configure_device_example(${PROJECT_NAME} noos) ``` -------------------------------- ### Start JLink GDB Server Source: https://github.com/hathach/tinyusb/blob/master/CLAUDE.md Starts the JLink GDB Server for debugging. Configure device, interface, and ports as needed. ```bash JLinkGDBServer -device stm32h743xi -if SWD -speed 4000 -port 2331 -swoport 2332 -telnetport 2333 -nogui ``` -------------------------------- ### Build and Flash Project Source: https://github.com/hathach/tinyusb/blob/master/hw/bsp/espressif/components/led_strip/examples/led_strip_rmt_ws2812/README.md Use this command to build, flash, and monitor the project. Ensure the correct PORT is specified. ```bash idf.py -p PORT build flash monitor ``` -------------------------------- ### Install Build Tools (macOS) Source: https://github.com/hathach/tinyusb/blob/master/docs/troubleshooting.md Installs essential build tools like CMake on macOS. Xcode command-line tools are also required. ```bash # macOS $ xcode-select --install $ brew install cmake ``` -------------------------------- ### Configure and Build Project with CMake and Ninja Source: https://github.com/hathach/tinyusb/blob/master/examples/device/audio_4_channel_mic_freertos/README.md Use CMake to configure the project for the espressif_s3_devkitc board and then use Ninja to build the project. Ensure the ESP-IDF environment is sourced. ```bash cmake -DBOARD=espressif_s3_devkitc -B build -G Ninja . ninja.exe -C build ``` -------------------------------- ### Signal SETUP Packet Received Source: https://github.com/hathach/tinyusb/blob/master/docs/porting.md Call this function when a SETUP packet is received on the control endpoint. The `true` argument indicates the call originates from an interrupt handler. ```c dcd_event_setup_received(0, setup, true); ``` -------------------------------- ### Compare Code Size Metrics Source: https://github.com/hathach/tinyusb/blob/master/CLAUDE.md Compares code size metrics between the current branch and the base, for a single example or all examples on a board. Use --bloaty for detailed breakdown. ```bash # Single example, one board: python3 tools/metrics_compare_base.py -b raspberry_pi_pico -e device/cdc_msc # Add --bloaty for section/symbol breakdown. # All examples, one board: python3 tools/metrics_compare_base.py -b raspberry_pi_pico # All arm-gcc CI families combined (pre-merge sweep, 4-8 min): python3 tools/metrics_compare_base.py --ci ``` -------------------------------- ### Project Configuration and Source Inclusion Source: https://github.com/hathach/tinyusb/blob/master/examples/device/midi_test_freertos/CMakeLists.txt Sets up the CMake minimum version, includes family support, defines the project name and languages, and adds source files for the MIDI example. ```cmake cmake_minimum_required(VERSION 3.20) include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/family_support.cmake) project(midi_test_freertos C CXX ASM) # Checks this example is valid for the family and initializes the project family_initialize_project(${PROJECT_NAME} ${CMAKE_CURRENT_LIST_DIR}) # Espressif has its own cmake build system if(FAMILY STREQUAL "espressif") return() endif() add_executable(${PROJECT_NAME}) # Example source target_sources(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c ) # Example include target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src ) # Configure compilation flags and libraries for the example with FreeRTOS. # See the corresponding function in hw/bsp/FAMILY/family.cmake for details. family_configure_device_example(${PROJECT_NAME} freertos) ``` -------------------------------- ### Configure Project and Sources Source: https://github.com/hathach/tinyusb/blob/master/examples/device/uac2_speaker_fb/CMakeLists.txt Sets up the CMake build for the UAC2 Speaker FB example. It defines the project name, includes family support, and adds the main and USB descriptor source files. ```cmake cmake_minimum_required(VERSION 3.20) include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/family_support.cmake) project(uac2_speaker_fb C CXX ASM) # Checks this example is valid for the family and initializes the project family_initialize_project(${PROJECT_NAME} ${CMAKE_CURRENT_LIST_DIR}) # Espressif has its own cmake build system if(FAMILY STREQUAL "espressif") return() endif() add_executable(${PROJECT_NAME}) # Example source target_sources(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c ) # Example include target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src ) # Configure compilation flags and libraries for the example without RTOS. # See the corresponding function in hw/bsp/FAMILY/family.cmake for details. family_configure_device_example(${PROJECT_NAME} noos) ``` -------------------------------- ### Start GDB Session Source: https://github.com/hathach/tinyusb/blob/master/docs/troubleshooting.md Launch a GDB session with the built application's ELF file. This allows for interactive debugging, setting breakpoints, and inspecting program state. ```bash # Use with debugger arm-none-eabi-gdb build/your_app.elf ``` -------------------------------- ### Build CDC + UAC2 Composite Device on Pico Source: https://github.com/hathach/tinyusb/blob/master/examples/device/cdc_uac2/README.md Instructions for building the CDC + UAC2 composite device example on a Raspberry Pi Pico. Ensure the PICO_SDK_PATH is correctly set. ```bash cd examples/device/cdc_uac2 export PICO_SDK_PATH=$HOME/pico-sdk cmake -DFAMILY=rp2040 pico . cmake -DFAMILY=rp2040 -DCMAKE_BUILD_TYPE=Debug # use this for debugging make BOARD=raspberry_pi_pico all ```