feat(esp_tinyusb): Support ESP32-S31 as HS-only single-port device#467
Conversation
|
@igi540 I tested with tinyusb 0.19.0~3-rc1 and all seems to work correctly. I did not test VBUS yet |
37a22c4 to
2be871f
Compare
There was a problem hiding this comment.
Pull request overview
This PR updates esp_tinyusb to support ESP32-S31, a single-port HS-only USB-OTG target, by decoupling “HS support” from the prior “multi-port” assumption and aligning configuration/descriptor handling accordingly.
Changes:
- Add ESP32-S31 target support and bump TinyUSB dependency to a version that includes S31 support.
- Introduce HS-port selection helpers for default config and HS descriptor selection to support both multi-port HS chips (e.g., P4) and HS-only single-port chips (S31).
- Refine DMA DCache-maintenance enablement and extend software VBUS monitoring to ESP32-S31.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| device/esp_tinyusb/tinyusb_task.c | Sets task init speed for ESP32-S31 to HS unconditionally. |
| device/esp_tinyusb/tinyusb.c | Adjusts PHY configuration for S31 and extends software VBUS monitoring init/deinit logic. |
| device/esp_tinyusb/include/tusb_config.h | Enables HS max speed for S31 and tightens DCache-maintenance gating for DMA buffers. |
| device/esp_tinyusb/include/tinyusb_default_config.h | Adds a default HS port helper and uses it in TINYUSB_CONFIG_HIGH_SPEED(). |
| device/esp_tinyusb/idf_component.yml | Adds esp32s31 target and bumps TinyUSB dependency version. |
| device/esp_tinyusb/descriptors_control.c | Adds TINYUSB_PORT_IS_HS() helper to select HS descriptors correctly on S31 and multi-port HS chips. |
| device/esp_tinyusb/Kconfig | Updates FIFO defaults/ranges to include ESP32-S31. |
| device/esp_tinyusb/CMakeLists.txt | Builds software VBUS monitoring module for ESP32-S31 in addition to ESP32-P4. |
Comments suppressed due to low confidence (1)
device/esp_tinyusb/tinyusb.c:209
- On ESP32-S31, VBUS monitoring is initialized for any
self_poweredconfig, but there is no validation thatconfig->phy.vbus_monitor_iois set to a valid GPIO (default is-1). If left at the default,tinyusb_vbus_monitor_init()will useBIT64(-1)and attempt to configure an invalid pin. Please add an explicit argument check (e.g. rejectvbus_monitor_io < 0/GPIO_NUM_NC) before callingUSB_PHY_SELF_POWERED_DEVICE()/tinyusb_vbus_monitor_init()whenself_poweredis true.
// Initialize VBUS monitoring only for High-Speed ports and self-powered devices
#if (CONFIG_IDF_TARGET_ESP32P4)
if (config->port == TINYUSB_PORT_HIGH_SPEED_0 && config->phy.self_powered) {
#else
if (config->phy.self_powered) {
#endif
const tinyusb_vbus_monitor_config_t vbus_cfg = {
.gpio_num = config->phy.vbus_monitor_io,
.port = (int)config->port,
};
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
peter-marcisovsky
left a comment
There was a problem hiding this comment.
BTW, no esp32s31 apps are built in this CI. Both builds, the device test apps and esp-idf exaples are disabled for esp32s31.
@igi540 @peter-marcisovsky So we merge #469 now and then rebase this? |
2be871f to
6a23893
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 6a23893. Configure here.
6a23893 to
1b3a39f
Compare
Treat ESP32-S31 as a high-speed-only, single-port USB-OTG target and refactor HS handling so single-port HS chips are no longer special-cased via SOC_USB_OTG_PERIPH_NUM > 1. - add esp32s31 to the component manifest - bump tinyusb dependency to >=0.19.0~3-rc1 - force UTMI PHY and TUSB_SPEED_HIGH on S31 (no internal FSLS PHY) - introduce TINYUSB_PORT_IS_HS() and TINYUSB_PORT_DEFAULT_HS helpers for HS descriptor selection and default config on single-port HS chips - align MSC/Vendor FIFO and endpoint defaults with other HS targets - extend software VBUS monitoring to the S31 HS peripheral - gate CFG_TUD_MEM_DCACHE_ENABLE on SOC_CACHE_INTERNAL_MEM_VIA_L1CACHE so S31 (L1 cache present but internal SRAM not cached) keeps DCache maintenance disabled for USB DMA buffers - exclude test_apps from published component package
1b3a39f to
5eb9b4d
Compare
tore-espressif
left a comment
There was a problem hiding this comment.
@igi540 @peter-marcisovsky I could not reproduce the example build failure locally... If all other tests pass, IMO we can merge this to unblock CI for other PRs and double check everthing during esp_tinyusb v2.2.0 release
|
I have the same "error" locally, even thought it's just and warning during build, but warnings are treated as errors in CI (cmake) App examples/network/sta2eth, target esp32s2, sdkconfig (default), build in examples/network/sta2eth/build_esp32s2_default, build failed in 83.471661s: build succeeded with warningsThe app built fine. I suppose we can continue and catch this problem during |

Description
This PR enables
esp_tinyusbon ESP32-S31, which has a single HS-only USB-OTG peripheral (UTMI PHY, no internal FSLS PHY).Previously, HS handling in
esp_tinyusbassumed that HS implies a multi-port chip (checked viaSOC_USB_OTG_PERIPH_NUM > 1, with the HS port beingTINYUSB_PORT_HIGH_SPEED_0). ESP32-S31 breaks that assumption: it has only one port, and that port is always HS. The refactor replaces those checks with two small helpers:TINYUSB_PORT_IS_HS(port)— used during descriptor selection indescriptors_control.cTINYUSB_PORT_DEFAULT_HS— used as the default port value inTINYUSB_CONFIG_HIGH_SPEED()so both multi-port HS chips (e.g. ESP32-P4) and single-port HS-only chips (e.g. ESP32-S31) are handled uniformly.
Other notable changes:
>=0.19.0~3-rc1, which is required for ESP32-S31 support.tusb_config.his tightened: having an L1 cache (CONFIG_CACHE_L1_CACHE_LINE_SIZE != 0) is no longer sufficient — internal SRAM must also be routed through it (CONFIG_SOC_CACHE_INTERNAL_MEM_VIA_L1CACHE). Otherwise DCache clean/invalidate calls on TinyUSB DMA buffers (which live in internal SRAM) are unnecessary and incorrect on S31.Related
IDF-14703
Testing
Manually verified on hardware:
msc device example— MSC device enumerates and works at high speed.hid device example— HID device enumerates and works at high speed.msc device example— MSC device still enumerates and works at full speed, confirming the HS refactor does not break existing FS-only single-port targets.Note
Medium Risk
Extends core USB init/descriptor and DMA-cache configuration logic to handle an HS-only target and bumps the TinyUSB dependency, which could affect enumeration and DMA behavior across supported chips if assumptions are wrong.
Overview
Adds ESP32-S31 as a supported target for
esp_tinyusb, updating default config macros and descriptor selection to treat the single port as always high-speed (vs. the previous “HS implies multi-port” assumption).Updates runtime init to use the UTMI PHY and HS speed on S31, enables software VBUS monitoring for S31 (and includes the GPIO dependency), and adjusts TinyUSB task port-speed selection accordingly.
Bumps the
tinyusbcomponent requirement to>=0.19.0~3-rc1, tightens the DMA DCache enable condition to requireCONFIG_SOC_CACHE_INTERNAL_MEM_VIA_L1CACHE, and updates Kconfig buffer-size defaults/ranges for HS-capable targets.Reviewed by Cursor Bugbot for commit 5eb9b4d. Bugbot is set up for automated code reviews on this repo. Configure here.