### CMake Project Setup Source: https://github.com/espressif/tinyusb/blob/master/test/fuzz/device/net/CMakeLists.txt Sets up the CMake build system for the example project. Includes family support and initializes the project. ```cmake cmake_minimum_required(VERSION 3.5) include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/family_support.cmake) # gets PROJECT name for the example (e.g. -) family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) project(${PROJECT}) # Checks this example is valid for the family and initializes the project family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR}) ``` -------------------------------- ### Basic CMake Project Setup for TinyUSB Example Source: https://github.com/espressif/tinyusb/blob/master/examples/typec/power_delivery/CMakeLists.txt Sets up a basic CMake project for a TinyUSB example. Includes essential commands for project definition, source inclusion, and directory configuration. ```cmake cmake_minimum_required(VERSION 3.20) include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/family_support.cmake) # gets PROJECT name for the example (e.g. -) family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) project(${PROJECT} C CXX ASM) # Checks this example is valid for the family and initializes the project family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR}) # Espressif has its own cmake build system if(FAMILY STREQUAL "espressif") return() endif() add_executable(${PROJECT}) # Example source target_sources(${PROJECT} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c ) # Example include target_include_directories(${PROJECT} 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} noos) ``` -------------------------------- ### Get Dependencies from Example Source: https://github.com/espressif/tinyusb/blob/master/CLAUDE.md Fetch dependencies for a specific example using its Makefile. Ensure you are in the example's directory. ```bash cd examples/device/cdc_msc && make BOARD=raspberry_pi_pico get-deps ``` -------------------------------- ### Example Output Log Source: https://github.com/espressif/tinyusb/blob/master/hw/bsp/espressif/components/led_strip/examples/led_strip_rmt_ws2812/README.md This is the expected output log when running the LED strip example. It shows GPIO initialization, LED strip object creation, and the start of the blinking process. ```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 ``` -------------------------------- ### Navigate to Example Directory Source: https://github.com/espressif/tinyusb/blob/master/examples/device/audio_test_freertos/README.md Change the current directory to the desired TinyUSB example. Ensure your ESP-IDF environment is loaded. ```bash cd /tinyusb/examples/device/audio_test_freertos ``` -------------------------------- ### Download Dependencies from Example Directory Source: https://github.com/espressif/tinyusb/blob/master/docs/troubleshooting.md Navigates to an example directory and downloads dependencies using make. Replace 'your_board' with your target board. ```bash cd examples/device/cdc_msc make BOARD=your_board get-deps ``` -------------------------------- ### Build Individual Example with Make Source: https://github.com/espressif/tinyusb/blob/master/AGENTS.md Builds an individual example using Make. Ensure to specify the BOARD. ```bash cd examples/device/cdc_msc make BOARD=raspberry_pi_pico all ``` -------------------------------- ### Adding Example Sources and Includes Source: https://github.com/espressif/tinyusb/blob/master/examples/device/board_test/CMakeLists.txt Specifies the source files and include directories for the example. Ensure that 'main.c' is correctly referenced. ```cmake # Example source target_sources(${EXE_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c ) # Example include target_include_directories(${EXE_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src ) ``` -------------------------------- ### CMake Project Setup for TinyUSB Example Source: https://github.com/espressif/tinyusb/blob/master/test/fuzz/device/cdc/CMakeLists.txt Configures the CMake build system for a TinyUSB example, including project name, executable target, source files, include directories, and device-specific settings for a no-RTOS environment. ```cmake cmake_minimum_required(VERSION 3.5) include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/family_support.cmake) # gets PROJECT name for the example (e.g. -) family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) project(${PROJECT}) # Checks this example is valid for the family and initializes the project family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR}) add_executable(${PROJECT}) # Example source target_sources(${PROJECT} 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} 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} noos) ``` -------------------------------- ### Build Example with CMake and Ninja Source: https://github.com/espressif/tinyusb/blob/master/CLAUDE.md Use this command to build a TinyUSB example project with the CMake build system and Ninja generator. Ensure you are in the example's build directory. ```bash cd examples/device/cdc_msc mkdir build && cd build cmake -G Ninja -DBOARD=raspberry_pi_pico .. ninja ``` -------------------------------- ### Basic CMake Project Setup for TinyUSB Source: https://github.com/espressif/tinyusb/blob/master/examples/host/cdc_msc_hid/CMakeLists.txt Sets up the minimum required CMake version and includes family-specific support scripts. This is a foundational step for building TinyUSB examples. ```cmake cmake_minimum_required(VERSION 3.20) include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/family_support.cmake) ``` -------------------------------- ### Adding Example Source Files Source: https://github.com/espressif/tinyusb/blob/master/examples/device/mtp/CMakeLists.txt Specifies the source files for the example executable. This includes main application logic, MTP file system example, and USB descriptor definitions. ```cmake # Example source target_sources(${EXE_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c ${CMAKE_CURRENT_SOURCE_DIR}/src/mtp_fs_example.c ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c ) ``` -------------------------------- ### Build Example with Make Source: https://github.com/espressif/tinyusb/blob/master/CLAUDE.md Build a TinyUSB example project using the Make build system. Specify the board using the BOARD variable. ```bash cd examples/device/cdc_msc && make BOARD=raspberry_pi_pico all ``` -------------------------------- ### Navigate to Example Directory Source: https://github.com/espressif/tinyusb/blob/master/examples/device/audio_4_channel_mic_freertos/README.md Change the current directory to the specific TinyUSB example you wish to build. Ensure your ESP-IDF environment is sourced. ```bash cd /tinyusb/examples/device/audio_4_channel_mic_freertos ``` -------------------------------- ### Build Specific Example with Make Source: https://github.com/espressif/tinyusb/blob/master/CLAUDE.md Build a specific example within the device, host, or dual directories using Make. Ensure you set the BOARD variable. ```bash cd examples/{device|host|dual}/{example_name} && make BOARD=raspberry_pi_pico all ``` -------------------------------- ### TinyUSB Example CMake Configuration Source: https://github.com/espressif/tinyusb/blob/master/examples/device/cdc_msc/CMakeLists.txt Sets up the CMake build for a TinyUSB example. Includes family support, project initialization, and source file definitions. This configuration is used for examples that are not Espressif-specific. ```cmake cmake_minimum_required(VERSION 3.20) #set_property(GLOBAL PROPERTY USE_FOLDERS ON) include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/family_support.cmake) # gets PROJECT name for the example (e.g. -) family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) project(${PROJECT} C CXX ASM) # Checks this example is valid for the family and initializes the project family_initialize_project(${PROJECT} ${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}) 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}) ``` -------------------------------- ### Flash Example with OpenOCD using Make Source: https://github.com/espressif/tinyusb/blob/master/CLAUDE.md Flash the built example to the target board using OpenOCD with the Make build system. ```bash make BOARD=raspberry_pi_pico flash-openocd ``` -------------------------------- ### Build Individual Example with CMake Source: https://github.com/espressif/tinyusb/blob/master/AGENTS.md Builds an individual example using CMake. Recommended approach. Ensure to set the BOARD and CMAKE_BUILD_TYPE. ```bash cd examples/device/cdc_msc mkdir -p build && cd build cmake -DBOARD=raspberry_pi_pico -DCMAKE_BUILD_TYPE=MinSizeRel .. cmake --build . -j4 ``` -------------------------------- ### Define Project Name in TinyUSB Example Source: https://github.com/espressif/tinyusb/blob/master/examples/host/cdc_msc_hid/CMakeLists.txt Gets the project name for the example, typically combining the board and directory name. This helps in uniquely identifying build targets. ```cmake # gets PROJECT name for the example (e.g. -) family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) ``` -------------------------------- ### Build CDC MSC HID Host Example with Make Source: https://github.com/espressif/tinyusb/blob/master/docs/getting_started.md Build the CDC MSC HID host example using Make. This example creates a USB host that can connect to devices with CDC, MSC, or HID interfaces. ```bash $ cd examples/host/cdc_msc_hid $ make BOARD=stm32h743eval all $ make BOARD=stm32h743eval flash-jlink ``` -------------------------------- ### Install Documentation Requirements Source: https://github.com/espressif/tinyusb/blob/master/AGENTS.md Installs the Python package requirements for building the documentation. ```bash pip install -r docs/requirements.txt ``` -------------------------------- ### Flash Example with OpenOCD using Ninja Source: https://github.com/espressif/tinyusb/blob/master/CLAUDE.md Flash the built example to the target board using OpenOCD with the Ninja build system. ```bash ninja cdc_msc-openocd ``` -------------------------------- ### Build CDC MSC Example with Make Source: https://github.com/espressif/tinyusb/blob/master/docs/getting_started.md Build the CDC MSC example using Make. This example creates a USB device with both a virtual serial port and mass storage. ```bash $ cd examples/device/cdc_msc $ make BOARD=stm32h743eval all $ make BOARD=stm32h743eval flash-jlink ``` -------------------------------- ### Install Pre-commit Hooks Source: https://github.com/espressif/tinyusb/blob/master/AGENTS.md Install the pre-commit framework and its hooks into your local repository. This enables automated checks before committing. ```bash pip install pre-commit && pre-commit install ``` -------------------------------- ### Build All Examples for a Board Source: https://github.com/espressif/tinyusb/blob/master/AGENTS.md Builds all examples for a specified board using the build script. This process may take longer and might produce non-critical objcopy failures. ```bash python3 tools/build.py -b BOARD_NAME ``` -------------------------------- ### Minimal TinyUSB Initialization Example Source: https://github.com/espressif/tinyusb/blob/master/docs/integration.md This example demonstrates the basic initialization of both device and host stacks on different ports, along with the necessary interrupt handlers and main loop tasks. Ensure board initialization and application logic are handled 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_DEVICE, .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); } ``` -------------------------------- ### Flash Example with JLink using Make Source: https://github.com/espressif/tinyusb/blob/master/CLAUDE.md Flash the built example to the target board using a JLink debugger with the Make build system. ```bash make BOARD=raspberry_pi_pico flash-jlink ``` -------------------------------- ### Example Source and Include Directories Source: https://github.com/espressif/tinyusb/blob/master/examples/device/msc_dual_lun/CMakeLists.txt Specifies the source files and include directories for the example. This ensures all necessary code is compiled and headers are accessible. ```cmake # Example source target_sources(${EXE_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c ${CMAKE_CURRENT_SOURCE_DIR}/src/msc_disk_dual.c ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c ) # Example include target_include_directories(${EXE_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src ) ``` -------------------------------- ### Device Example Configuration Source: https://github.com/espressif/tinyusb/blob/master/examples/device/board_test/CMakeLists.txt Configures compilation flags and libraries for the example, particularly for scenarios without an RTOS. Refer to the family-specific CMake files for detailed options. ```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(${EXE_NAME} ${RTOS}) ``` -------------------------------- ### CMakeLists.txt Configuration for TinyUSB Example Source: https://github.com/espressif/tinyusb/blob/master/examples/device/cdc_uac2/CMakeLists.txt This CMakeLists.txt file sets up a TinyUSB example project. It defines the project name, includes necessary family support, specifies source and include directories, and configures device-specific settings. 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) # gets PROJECT name for the example (e.g. -) family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) project(${PROJECT} C CXX ASM) # Checks this example is valid for the family and initializes the project family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR}) # Espressif has its own cmake build system if(FAMILY STREQUAL "espressif") return() endif() add_executable(${PROJECT}) # Example source target_sources(${PROJECT} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src/cdc_app.c ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c ${CMAKE_CURRENT_SOURCE_DIR}/src/uac2_app.c ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c ) # Example include target_include_directories(${PROJECT} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src ) # 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} noos) # Uncomment me to enable UART based debugging # pico_enable_stdio_uart(${PROJECT} 1) ``` -------------------------------- ### Flash Example with JLink using Ninja Source: https://github.com/espressif/tinyusb/blob/master/CLAUDE.md Flash the built example to the target board using a JLink debugger with the Ninja build system. ```bash ninja cdc_msc-jlink ``` -------------------------------- ### Dual USB Example Configuration Source: https://github.com/espressif/tinyusb/blob/master/examples/dual/host_info_to_device_cdc/CMakeLists.txt Configures compilation flags and libraries for dual USB examples without an RTOS. Consult the family-specific CMake file for details. ```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_dual_usb_example(${PROJECT} ${RTOS}) ``` -------------------------------- ### Build CDC MSC HID Host Example with CMake Source: https://github.com/espressif/tinyusb/blob/master/docs/getting_started.md Build the CDC MSC HID host example using CMake. This example creates a USB host that can connect to devices with CDC, MSC, or HID interfaces. ```bash $ cd examples/host/cdc_msc_hid $ cmake -DBOARD=stm32h743eval -B build $ cmake --build build ``` -------------------------------- ### Basic CMake Configuration for TinyUSB Example Source: https://github.com/espressif/tinyusb/blob/master/examples/device/audio_4_channel_mic/CMakeLists.txt Sets up the minimum required CMake version, includes family support, and defines the project name. This is a foundational configuration for TinyUSB examples. ```cmake cmake_minimum_required(VERSION 3.20) include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/family_support.cmake) # gets PROJECT name for the example (e.g. -) family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) project(${PROJECT} C CXX ASM) ``` -------------------------------- ### Build TinyUSB CDC MSC Example Source: https://github.com/espressif/tinyusb/blob/master/docs/porting.md Use this command to build the cdc_msc device example from the TinyUSB root directory. Replace with your specific board name. ```bash make -C examples/device/cdc_msc BOARD= ``` -------------------------------- ### Example: RTT Menu Application Source: https://github.com/espressif/tinyusb/blob/master/lib/SEGGER_RTT/README.md Demonstrates RTT bi-directional functionality with a menu-driven interface. This example showcases interactive use of RTT. ```c Main_RTT_MenuApp.c ``` -------------------------------- ### Configure TinyUSB Example Project Source: https://github.com/espressif/tinyusb/blob/master/examples/dual/host_hid_to_device_cdc/CMakeLists.txt This CMake script configures a TinyUSB example project. It sets the minimum CMake version, includes family support, determines the project name, and adds the executable with specified source files and include directories. It also configures the project for dual USB examples without an RTOS. ```cmake cmake_minimum_required(VERSION 3.20) include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/family_support.cmake) # gets PROJECT name for the example (e.g. -) family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) project(${PROJECT} C CXX ASM) # Checks this example is valid for the family and initializes the project family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR}) add_executable(${PROJECT}) # Example source target_sources(${PROJECT} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c ) # Example include target_include_directories(${PROJECT} 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} noos) # due to warnings from Pico-PIO-USB if (FAMILY STREQUAL rp2040) target_compile_options(${PROJECT} 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 () ``` -------------------------------- ### Install Build Tools and CMake Source: https://github.com/espressif/tinyusb/blob/master/docs/troubleshooting.md Installs essential build tools and CMake on Ubuntu/Debian systems. Required for building projects. ```bash # Ubuntu/Debian $ sudo apt-get install build-essential cmake ``` -------------------------------- ### Configure ESP32 Device Example (No RTOS) Source: https://github.com/espressif/tinyusb/blob/master/examples/device/dfu_runtime/CMakeLists.txt Configures the device example for the ESP32 family without using an RTOS. This function is part of the family-specific build system. ```cmake cmake_minimum_required(VERSION 3.20) include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/family_support.cmake) # gets PROJECT name for the example (e.g. -) family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) project(${PROJECT} C CXX ASM) # Checks this example is valid for the family and initializes the project family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR}) # Espressif has its own cmake build system if(FAMILY STREQUAL "espressif") return() endif() add_executable(${PROJECT}) # Example source target_sources(${PROJECT} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c ) # Example include target_include_directories(${PROJECT} 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} noos) ``` -------------------------------- ### Generate UF2 File with Make Source: https://github.com/espressif/tinyusb/blob/master/CLAUDE.md Generate a UF2 bootloader file for the example using the Make build system. ```bash make BOARD=raspberry_pi_pico all uf2 ``` -------------------------------- ### Build Example CDC MSC for STM32F4 Source: https://github.com/espressif/tinyusb/blob/master/AGENTS.md Build the CDC MSC example for the stm32f407disco board. This is part of the validation process before committing. ```bash cd examples/device/cdc_msc && make BOARD=stm32f407disco all ``` -------------------------------- ### Configure ESP32 Example Build Source: https://github.com/espressif/tinyusb/blob/master/examples/host/hid_controller/CMakeLists.txt This CMake script sets up the build for an ESP32 TinyUSB example. It includes project initialization, source file inclusion, and specific configuration for the ESP32 family, including a conditional return for Espressif's native build system. ```cmake cmake_minimum_required(VERSION 3.20) include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/family_support.cmake) # gets PROJECT name for the example (e.g. -) family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) project(${PROJECT} C CXX ASM) # Checks this example is valid for the family and initializes the project family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR}) # Espressif has its own cmake build system if(FAMILY STREQUAL "espressif") return() endif() add_executable(${PROJECT}) # Example source target_sources(${PROJECT} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src/hid_app.c ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c ) # Example include target_include_directories(${PROJECT} 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} noos) ``` -------------------------------- ### Host Example Configuration with FreeRTOS Source: https://github.com/espressif/tinyusb/blob/master/examples/host/cdc_msc_hid_freertos/CMakeLists.txt Configures the host example to use FreeRTOS. This function is defined in the family's CMake support scripts. ```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_host_example(${PROJECT} freertos) ``` -------------------------------- ### ESP32-S3 Example CMakeLists.txt Configuration Source: https://github.com/espressif/tinyusb/blob/master/examples/device/video_capture/CMakeLists.txt This CMakeLists.txt file configures the build for the ESP32-S3 TinyUSB example. It sets up the project, includes necessary source files, and applies family-specific configurations. ```cmake cmake_minimum_required(VERSION 3.20) include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/family_support.cmake) # gets PROJECT name for the example (e.g. -) family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) project(${PROJECT} C CXX ASM) # Checks this example is valid for the family and initializes the project family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR}) # Espressif has its own cmake build system if(FAMILY STREQUAL "espressif") return() endif() add_executable(${PROJECT}) if (FORCE_READONLY) target_compile_definitions(${PROJECT} PRIVATE CFG_EXAMPLE_VIDEO_READONLY ) endif() # Example source target_sources(${PROJECT} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c ) # Example include target_include_directories(${PROJECT} 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} noos) ``` -------------------------------- ### Configure ESP32-S3 TinyUSB MSC Example Source: https://github.com/espressif/tinyusb/blob/master/examples/device/cdc_msc_freertos/CMakeLists.txt This CMakeLists.txt file sets up the build environment for the TinyUSB MSC example on ESP32-S3. It includes setting the project name, adding source and include directories, and configuring FreeRTOS. ```cmake cmake_minimum_required(VERSION 3.20) include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/family_support.cmake) # gets PROJECT name for the example (e.g. -) family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) project(${PROJECT} C CXX ASM) # Checks this example is valid for the family and initializes the project family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR}) # Espressif has its own cmake build system if(FAMILY STREQUAL "espressif") return() endif() add_executable(${PROJECT}) # Example source target_sources(${PROJECT} 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} 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} freertos) ``` -------------------------------- ### ESP32 TinyUSB Example CMakeLists Source: https://github.com/espressif/tinyusb/blob/master/examples/device/webusb_serial/CMakeLists.txt This CMakeLists.txt file configures the build for the ESP32 TinyUSB example. It sets up the project, includes necessary source files, and applies device-specific configurations. ```cmake cmake_minimum_required(VERSION 3.20) include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/family_support.cmake) # gets PROJECT name for the example (e.g. -) family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) project(${PROJECT} C CXX ASM) # Checks this example is valid for the family and initializes the project family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR}) # Espressif has its own cmake build system if(FAMILY STREQUAL "espressif") return() endif() add_executable(${PROJECT}) # Example source target_sources(${PROJECT} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c ) # Example include target_include_directories(${PROJECT} 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} noos) ``` -------------------------------- ### Generate UF2 File with Ninja Source: https://github.com/espressif/tinyusb/blob/master/CLAUDE.md Generate a UF2 bootloader file for the example using the Ninja build system. ```bash ninja cdc_msc-uf2 ``` -------------------------------- ### Device Setup API Source: https://github.com/espressif/tinyusb/blob/master/docs/porting.md Functions for initializing and configuring the USB peripheral in device mode. ```APIDOC ## Device Setup API ### Description Functions for initializing and configuring the USB peripheral in device mode. ### `dcd_init()` #### Description Initializes the USB peripheral for device mode and enables it. This function should enable internal D+/D- pull-up for enumeration. ### `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. ### `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. ### `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. ### `dcd_remote_wakeup()` #### Description Called to remote wake up the host when suspended (e.g., HID keyboard). ### `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.) ``` -------------------------------- ### Configure ESP32-S3 TinyUSB Example Build Source: https://github.com/espressif/tinyusb/blob/master/examples/device/audio_test/CMakeLists.txt This CMakeLists.txt file sets up the build environment for a TinyUSB example on ESP32-S3. It includes project initialization, source file inclusion, and device-specific configuration for a no-RTOS environment. ```cmake cmake_minimum_required(VERSION 3.20) include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/family_support.cmake) # gets PROJECT name for the example (e.g. -) family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) project(${PROJECT} C CXX ASM) # Checks this example is valid for the family and initializes the project family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR}) # Espressif has its own cmake build system if(FAMILY STREQUAL "espressif") return() endif() add_executable(${PROJECT}) # Example source target_sources(${PROJECT} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c ) # Example include target_include_directories(${PROJECT} 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} noos) ``` -------------------------------- ### Specify Source Files for TinyUSB Example Source: https://github.com/espressif/tinyusb/blob/master/examples/host/cdc_msc_hid/CMakeLists.txt Adds the source files for the TinyUSB example to the build target. This includes application logic for CDC, HID, and MSC classes, along with the main entry point. ```cmake # Example source target_sources(${PROJECT} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src/cdc_app.c ${CMAKE_CURRENT_SOURCE_DIR}/src/hid_app.c ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c ${CMAKE_CURRENT_SOURCE_DIR}/src/msc_app.c ) ``` -------------------------------- ### Configure TinyUSB Example with FreeRTOS Source: https://github.com/espressif/tinyusb/blob/master/examples/device/audio_4_channel_mic_freertos/CMakeLists.txt Configures the compilation flags and libraries for an example using FreeRTOS. Refer to the family-specific CMake file for detailed function implementations. ```cmake cmake_minimum_required(VERSION 3.20) include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/family_support.cmake) # gets PROJECT name for the example (e.g. -) family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) project(${PROJECT} C CXX ASM) # Checks this example is valid for the family and initializes the project family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR}) # Espressif has its own cmake build system if(FAMILY STREQUAL "espressif") return() endif() add_executable(${PROJECT}) # Example source target_sources(${PROJECT} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c ) # Example include target_include_directories(${PROJECT} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src ) # Add libm for GCC if (CMAKE_C_COMPILER_ID STREQUAL "GNU") target_link_libraries(${PROJECT} 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} freertos) ``` -------------------------------- ### Setting Include Directories Source: https://github.com/espressif/tinyusb/blob/master/examples/device/mtp/CMakeLists.txt Configures the include directories for the example, making the 'src' directory publicly accessible for header files. ```cmake # Example include target_include_directories(${EXE_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src ) ``` -------------------------------- ### Configuring Device Example without RTOS in CMake Source: https://github.com/espressif/tinyusb/blob/master/examples/device/audio_4_channel_mic/CMakeLists.txt Configures the device example for a non-RTOS environment using the `family_configure_device_example` function. Refer to the family's CMake file for detailed options. ```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} noos) ``` -------------------------------- ### Configure ESP32 Example Build Source: https://github.com/espressif/tinyusb/blob/master/examples/host/device_info/CMakeLists.txt This CMake script configures the build for an ESP32 example without an RTOS. It includes family support, sets the project name, adds source files, and specifies include directories. ```cmake cmake_minimum_required(VERSION 3.20) include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/family_support.cmake) # gets PROJECT name for the example family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) project(${PROJECT} C CXX ASM) # Checks this example is valid for the family and initializes the project family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR}) # Espressif has its own cmake build system if(FAMILY STREQUAL "espressif") return() endif() add_executable(${PROJECT}) # Example source target_sources(${PROJECT} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c ) # Example include target_include_directories(${PROJECT} 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} noos) ``` -------------------------------- ### Configure ESP32-S3 TinyUSB Example with FreeRTOS Source: https://github.com/espressif/tinyusb/blob/master/examples/device/audio_test_freertos/CMakeLists.txt This CMake script configures a TinyUSB example for the ESP32-S3. It sets the project name, includes necessary family support, adds source and include directories, and configures FreeRTOS support. ```cmake cmake_minimum_required(VERSION 3.20) include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/family_support.cmake) # gets PROJECT name for the example (e.g. -) family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) project(${PROJECT} C CXX ASM) # Checks this example is valid for the family and initializes the project family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR}) # Espressif has its own cmake build system if(FAMILY STREQUAL "espressif") return() endif() add_executable(${PROJECT}) # Example source target_sources(${PROJECT} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c ) # Example include target_include_directories(${PROJECT} 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} freertos) ``` -------------------------------- ### Clone TinyUSB and Get Dependencies Source: https://github.com/espressif/tinyusb/blob/master/docs/getting_started.md Clone the TinyUSB repository and fetch necessary dependencies for a specific board. Ensure you have Python installed. ```bash $ git clone https://github.com/hathach/tinyusb tinyusb $ cd tinyusb $ python tools/get_deps.py -b stm32h743eval # or python tools/get_deps.py stm32h7 ``` -------------------------------- ### Build CDC MSC Example with CMake Source: https://github.com/espressif/tinyusb/blob/master/docs/getting_started.md Build the CDC MSC example using CMake. This example creates a USB device with both a virtual serial port and mass storage. ```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 ``` -------------------------------- ### Basic CMake Project Setup Source: https://github.com/espressif/tinyusb/blob/master/examples/device/mtp/CMakeLists.txt Sets the minimum CMake version, includes family support, and defines the project name based on board and directory. Initializes the project for the specific hardware family. ```cmake cmake_minimum_required(VERSION 3.20) include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/family_support.cmake) # gets PROJECT name for the example (e.g. -) family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) project(${PROJECT} C CXX ASM) # Checks this example is valid for the family and initializes the project family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR}) ``` -------------------------------- ### Install Pre-commit Hook Source: https://github.com/espressif/tinyusb/blob/master/CLAUDE.md Install the pre-commit Git hook to automatically run checks before each commit. ```bash pre-commit install ``` -------------------------------- ### Install ARM GCC Toolchain Source: https://github.com/espressif/tinyusb/blob/master/AGENTS.md Installs the necessary ARM GCC toolchain for building embedded projects. ```bash sudo apt-get update && sudo apt-get install -y gcc-arm-none-eabi ``` -------------------------------- ### Install ARM GCC Toolchain Source: https://github.com/espressif/tinyusb/blob/master/docs/troubleshooting.md Installs the ARM GCC toolchain on Ubuntu/Debian systems. Ensure this is in your PATH. ```bash # Ubuntu/Debian $ sudo apt-get update && sudo apt-get install gcc-arm-none-eabi ``` -------------------------------- ### Install Ceedling for Unit Testing Source: https://github.com/espressif/tinyusb/blob/master/AGENTS.md Installs Ceedling, a build system for C unit testing, using RubyGems. ```bash sudo gem install ceedling ``` -------------------------------- ### Install Build Tools on macOS Source: https://github.com/espressif/tinyusb/blob/master/docs/troubleshooting.md Installs essential build tools and CMake on macOS. Required for building projects. ```bash # macOS $ xcode-select --install $ brew install cmake ``` -------------------------------- ### Install ARM GCC Toolchain on macOS Source: https://github.com/espressif/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 Source: https://github.com/espressif/tinyusb/blob/master/docs/faq.md Install the ARM GCC toolchain on Ubuntu/Debian systems. For other platforms, download from ARM's website. ```bash sudo apt-get install gcc-arm-none-eabi ``` -------------------------------- ### Build Documentation Source: https://github.com/espressif/tinyusb/blob/master/AGENTS.md Builds the HTML documentation using Sphinx. This process is quick and should not be cancelled. ```bash cd docs && sphinx-build -b html . _build ``` -------------------------------- ### Signal Setup Packet Received Event Source: https://github.com/espressif/tinyusb/blob/master/docs/porting.md Call this function when a SETUP packet is received on the control endpoint. The first argument is the USB peripheral number, and the third argument (`true`) signals it's called from an interrupt handler. The middle argument is an 8-byte array containing the SETUP packet data. ```c dcd_event_setup_received(0, setup, true); ``` -------------------------------- ### Example: RTT Input Echo Application Source: https://github.com/espressif/tinyusb/blob/master/lib/SEGGER_RTT/README.md An example application that echoes input received on RTT Channel 0. This demonstrates basic bi-directional communication with RTT. ```c Main_RTT_InputEchoApp.c ``` -------------------------------- ### Configure and Build with CMake Source: https://github.com/espressif/tinyusb/blob/master/examples/device/audio_4_channel_mic_freertos/README.md Use CMake to configure the build for the ESP32-S3 DevKitC board and then use Ninja to compile the project. This generates the necessary binaries. ```bash cmake -DBOARD=espressif_s3_devkitc -B build -G Ninja . ninja.exe -C build ``` -------------------------------- ### Project Naming and Initialization Source: https://github.com/espressif/tinyusb/blob/master/examples/dual/host_info_to_device_cdc/CMakeLists.txt Determines the project name based on the board and directory, then initializes the project for the specific family. This ensures proper project setup. ```cmake # gets PROJECT name for the example (e.g. -) family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) project(${PROJECT} C CXX ASM) # Checks this example is valid for the family and initializes the project family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR}) ``` -------------------------------- ### Initialize TinyUSB Project with Family Support Source: https://github.com/espressif/tinyusb/blob/master/examples/device/hid_generic_inout/CMakeLists.txt Initializes the project based on the specific hardware family and checks its validity. This ensures the project is correctly set up for the target platform. ```cmake # Checks this example is valid for the family and initializes the project family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR}) ```