Feat/tinyusb esp32h4 support#3244
Conversation
…ounter fix(usbd/dcd_dwc2): Fixed epin counter assert, update buffer name for usbd_control debug
…_build_check feature(ci): Added esp-iot-solution USB Device examples build verification
…st_apps ci(tinyusb): Added esp-usb test_apps build and run (esp32s2)
Upstream synchronization
…_class feature(uvc): Applied proprietary changes in UVC Device class
Upstream synchronization
feature(tusb): Added tusb_teardown()
ci(tinyusb): Added esp-idf run (esp32s2)
* fixed unit test with ceedling 1.0.0
fix(ci): Fixed CI workflows
Upstream synchronization
ci(workflow): Update ubuntu runners to ubuntu-latest
TinyUSB does not provide any locking means to protect the DCD variables. This can lead to race conditions when the user is trying to submit a transfer while the device is being disconnected. This can cause the device to be in an inconsistent state, leading to a crash or undefined behavior. This commit adds a spin-lock to protect the DCD variables during device disconnect. Closes espressif/esp-idf#9691 Also reported in espressif/esp-usb#131
fix(dcd): Fixed race condition on device disconnect
Upstream synchronization
feature(usbtmc): add usbtmc device class
Add `OPT_MCU_ESP32H4` and integrate it into TinyUSB build and runtime logic. Updates include: - CMakeLists: add esp32h4 target mapping to `OPT_MCU_ESP32H4` - tusb_option.h: define `OPT_MCU_ESP32H4` - tusb_mcu.h, dwc2_esp32.h: extend DWC2 USBIP support - dcd_esp32sx.c: enable DCD for ESP32-H4 - family.c: include ESP32-H4 in USB init/PHY setup - idf_component.yml: add esp32h4 to supported targets This enables TinyUSB examples to build for ESP32-H4 using the ESP32-Sx USB backend as a base.
There was a problem hiding this comment.
Pull Request Overview
This PR adds support for the ESP32-H4 microcontroller to TinyUSB, enabling USB functionality on this new Espressif chip. The changes extend the existing ESP32 family support by adding H4-specific configurations and drivers.
Key changes:
- Add ESP32-H4 MCU definition and configuration in TinyUSB option files
- Extend DWC2 controller support for H4's specific register mapping and interrupt sources
- Update component files to include H4 in build targets and workflows
Reviewed Changes
Copilot reviewed 25 out of 25 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/tusb_option.h | Defines OPT_MCU_ESP32H4 constant for H4 MCU identification |
| src/tusb.h | Adds teardown functionality with backward compatibility macros |
| src/tusb.c | Implements tusb_rhport_teardown() function for proper cleanup |
| src/portable/synopsys/dwc2/dwc2_esp32.h | Adds H4-specific DWC2 controller configuration |
| src/portable/synopsys/dwc2/dwc2_critical.h | New critical section macros for thread safety |
| src/portable/synopsys/dwc2/dcd_dwc2.c | Enhanced DWC2 driver with H4 field mappings and critical sections |
| src/portable/espressif/esp32sx/dcd_esp32sx.c | Extends ESP32SX driver to support H4 |
| src/common/tusb_mcu.h | Adds H4 to ESP32 DWC2 MCU definitions |
| src/class/video/video_device.c | Fixes uninitialized variable warnings |
| src/class/audio/audio_device.c | Updates DWC2 MCU checks to include H4 |
| Multiple config/workflow files | Build system and CI integration for H4 support |
| uint_fast32_t interval = 0; | ||
| uint_fast32_t interval_ms = 0; |
There was a problem hiding this comment.
Initialize variables at declaration to prevent potential use of uninitialized values. While these variables are assigned in all switch cases, the initialization provides better safety and clarity.
| if (xfer->max_size == 0) { | ||
| DCD_EXIT_CRITICAL(); | ||
| return false; // Endpoint is closed | ||
| } |
There was a problem hiding this comment.
The check for endpoint closure (xfer->max_size == 0) should be documented more clearly. Consider adding a comment explaining when and why max_size would be zero, as this is not immediately obvious from the context.
|
|
||
| // Clear A override, force B Valid | ||
| dwc2->gotgctl = (dwc2->gotgctl & ~GOTGCTL_AVALOEN) | GOTGCTL_BVALOEN | GOTGCTL_BVALOVAL; | ||
| // No overrides |
There was a problem hiding this comment.
The change from setting specific override bits to clearing all override bits is a significant behavioral change. This should be documented explaining why "No overrides" is the correct approach for H4, as it differs from the previous implementation.
| // No overrides | |
| /* | |
| * Clear all override bits in GOTGCTL ("No overrides"). | |
| * | |
| * For ESP32-H4 (and similar MCUs), the USB controller's override bits (BVALOEN, BVALOVAL, VBVALOVAL) | |
| * should be cleared during device initialization. Setting these bits can interfere with the controller's | |
| * normal operation and may cause incorrect device detection or enumeration failures. | |
| * | |
| * Previous implementations may have set specific override bits to force certain line states or behaviors. | |
| * However, for H4, the hardware expects no overrides to be active, allowing the controller to manage | |
| * line states automatically. This change is based on the ESP32-H4 Technical Reference Manual and | |
| * observed behavior during device bring-up. | |
| * | |
| * If porting to other MCUs, verify their requirements for GOTGCTL overrides, as this may differ. | |
| */ |
Describe the PR
A clear and concise description of what this PR solve.
Additional context
If applicable, add any other context about the PR and/or screenshots here.