Skip to content

Commit 04437f8

Browse files
committed
feat(usb): Add ESP32-S31 support
Add ESP32-S31 as a supported MCU in TinyUSB and wire it into build/runtime, BSP, docs, examples, and CI. - Define OPT_MCU_ESP32S31 (911) with DWC2 HS-only, UTMI PHY, 16 endpoints - Add DWC2 controller entry (reg base 0x20300000, 4096 FIFO) - Exclude USB_WRAP peripheral (not present on S31) - Force high-speed mode for Port 0 in family.cmake - Enable CI builds for esp32s31 target - Update idf_component.yml, README, and changelog Also: - Fix missing TUP_MCU_MULTIPLE_CORE for ESP32-H4 - Remove unused tusb_family variable from CMakeLists.txt - Remove empty preprocessor guard block in family.c
1 parent bb1ed9c commit 04437f8

File tree

12 files changed

+61
-21
lines changed

12 files changed

+61
-21
lines changed

.github/workflows/build_and_run_esp_usb_test_apps.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ jobs:
5353
# Config and manifest files for idf-build-apps are used from the esp-usb repository automatically
5454
# Here we only overload path using CLI parameter -p to build only device test apps
5555
cd ${{ env.ESP_USB_PATH }}
56-
idf-build-apps find -p device --disable-targets esp32s31
57-
idf-build-apps build -p device --disable-targets esp32s31
56+
idf-build-apps find -p device
57+
idf-build-apps build -p device
5858
- uses: actions/upload-artifact@v6
5959
with:
6060
# Test apps builds live under the repository workspace, we use workspace-relative glob

.github/workflows/build_and_run_idf_examples.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ jobs:
5858
. ${IDF_PATH}/export.sh
5959
cd ${IDF_PATH}
6060
61-
idf-build-apps find --config-file ${CONFIG_PATH} --manifest-file ${MANIFEST_PATH} --disable-targets esp32s31
62-
idf-build-apps build --config-file ${CONFIG_PATH} --manifest-file ${MANIFEST_PATH} --disable-targets esp32s31
61+
idf-build-apps find --config-file ${CONFIG_PATH} --manifest-file ${MANIFEST_PATH}
62+
idf-build-apps build --config-file ${CONFIG_PATH} --manifest-file ${MANIFEST_PATH}
6363
- uses: actions/upload-artifact@v6
6464
with:
6565
# We upload only USB Device example binaries to run them on the target

CMakeLists.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@ idf_build_get_property(target IDF_TARGET)
22

33
if(${target} STREQUAL "esp32s3")
44
set(tusb_mcu "OPT_MCU_ESP32S3")
5-
set(tusb_family "esp32sx")
65
elseif(${target} STREQUAL "esp32s2")
76
set(tusb_mcu "OPT_MCU_ESP32S2")
8-
set(tusb_family "esp32sx")
97
elseif(${target} STREQUAL "esp32p4")
108
set(tusb_mcu "OPT_MCU_ESP32P4")
11-
set(tusb_family "esp32px")
129
elseif(${target} STREQUAL "esp32h4")
1310
set(tusb_mcu "OPT_MCU_ESP32H4")
14-
set(tusb_family "esp32sx")
11+
elseif(${target} STREQUAL "esp32s31")
12+
set(tusb_mcu "OPT_MCU_ESP32S31")
1513
endif()
1614

1715
set(compile_options

README.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ Supported CPUs
127127
| | P4 |||| dwc2 | |
128128
| +-----------------------------+--------+------+-----------+------------------------+-------------------+
129129
| | H4 |||| dwc2 | |
130+
| +-----------------------------+--------+------+-----------+------------------------+-------------------+
131+
| | S31 |||| dwc2 | |
130132
+--------------+-----------------------------+--------+------+-----------+------------------------+-------------------+
131133
| GigaDevice | GD32VF103 || || dwc2 | |
132134
+--------------+-----------------------------+--------+------+-----------+------------------------+-------------------+

docs/info/changelog.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ General
1010

1111
- New MCUs and Boards:
1212

13+
- Add ESP32-S31 OTG high-speed support
1314
- Add ESP32-H4, ESP32-C5, ESP32-C61 support
1415
- Add STM32U0, STM32WBA, STM32N6
1516
- Add AT32F405, AT32F403A, AT32F415, AT32F423 support

hw/bsp/espressif/boards/family.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ static led_strip_handle_t led_strip;
4949
static void max3421_init(void);
5050
#endif
5151

52-
#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3, OPT_MCU_ESP32H4, OPT_MCU_ESP32P4)
52+
#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3, OPT_MCU_ESP32H4, OPT_MCU_ESP32P4, OPT_MCU_ESP32S31)
5353
static bool usb_init(void);
5454
#endif
5555

@@ -90,7 +90,7 @@ void board_init(void) {
9090
gpio_set_direction(BUTTON_PIN, GPIO_MODE_INPUT);
9191
gpio_set_pull_mode(BUTTON_PIN, BUTTON_STATE_ACTIVE ? GPIO_PULLDOWN_ONLY : GPIO_PULLUP_ONLY);
9292

93-
#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3, OPT_MCU_ESP32H4, OPT_MCU_ESP32P4)
93+
#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3, OPT_MCU_ESP32H4, OPT_MCU_ESP32P4, OPT_MCU_ESP32S31)
9494
usb_init();
9595
#endif
9696

@@ -105,10 +105,6 @@ void board_init(void) {
105105
#endif
106106
}
107107

108-
#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3, OPT_MCU_ESP32H4)
109-
110-
#endif
111-
112108
//--------------------------------------------------------------------+
113109
// Board porting API
114110
//--------------------------------------------------------------------+
@@ -172,7 +168,7 @@ void board_reset_to_bootloader(void) {
172168
// PHY Init
173169
//--------------------------------------------------------------------
174170

175-
#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3, OPT_MCU_ESP32H4, OPT_MCU_ESP32P4)
171+
#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3, OPT_MCU_ESP32H4, OPT_MCU_ESP32P4, OPT_MCU_ESP32S31)
176172
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 3, 0)
177173

178174
#include "esp_private/usb_phy.h"
@@ -183,7 +179,11 @@ bool usb_init(void) {
183179
// Configure USB PHY
184180
usb_phy_config_t phy_conf = {
185181
.controller = USB_PHY_CTRL_OTG,
182+
#if TU_CHECK_MCU(OPT_MCU_ESP32S31)
183+
.target = USB_PHY_TARGET_UTMI,
184+
#else
186185
.target = USB_PHY_TARGET_INT,
186+
#endif
187187

188188
// maybe we can use USB_OTG_MODE_DEFAULT and switch using dwc2 driver
189189
#if CFG_TUD_ENABLED

hw/bsp/espressif/family.cmake

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
include("${CMAKE_CURRENT_LIST_DIR}/boards/${BOARD}/board.cmake")
33
string(TOUPPER ${IDF_TARGET} FAMILY_MCUS)
44

5-
# Device port default to Port1 for P4 (highspeed), Port0 for others (fullspeed)
5+
# Device/host port defaults:
6+
# - ESP32-P4 uses Port1 (highspeed)
7+
# - ESP32-S31 uses Port0 (highspeed)
8+
# - Other targets use Port0 and derive the default speed from RHPORT_SPEED
69
set(RHPORT_SPEED OPT_MODE_FULL_SPEED OPT_MODE_HIGH_SPEED)
710

811
if (NOT DEFINED RHPORT_DEVICE)
@@ -22,10 +25,18 @@ if (NOT DEFINED RHPORT_HOST)
2225
endif()
2326

2427
if (NOT DEFINED RHPORT_DEVICE_SPEED)
25-
list(GET RHPORT_SPEED ${RHPORT_DEVICE} RHPORT_DEVICE_SPEED)
28+
if (IDF_TARGET STREQUAL "esp32s31")
29+
set(RHPORT_DEVICE_SPEED OPT_MODE_HIGH_SPEED)
30+
else ()
31+
list(GET RHPORT_SPEED ${RHPORT_DEVICE} RHPORT_DEVICE_SPEED)
32+
endif ()
2633
endif ()
2734
if (NOT DEFINED RHPORT_HOST_SPEED)
28-
list(GET RHPORT_SPEED ${RHPORT_HOST} RHPORT_HOST_SPEED)
35+
if (IDF_TARGET STREQUAL "esp32s31")
36+
set(RHPORT_HOST_SPEED OPT_MODE_HIGH_SPEED)
37+
else ()
38+
list(GET RHPORT_SPEED ${RHPORT_HOST} RHPORT_HOST_SPEED)
39+
endif ()
2940
endif ()
3041

3142
# Add example src and bsp directories

idf_component.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ targets:
1717
- esp32s3
1818
- esp32p4
1919
- esp32h4
20+
- esp32s31
2021
tags:
2122
- usb
2223
- usb_device

src/common/tusb_mcu.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@
393393
#define TUP_DCD_ENDPOINT_MAX 7 // only 5 TX FIFO for endpoint IN
394394
#define CFG_TUSB_OS_INC_PATH_DEFAULT freertos/
395395

396-
#if CFG_TUSB_MCU == OPT_MCU_ESP32S3
396+
#if CFG_TUSB_MCU == OPT_MCU_ESP32S3 || CFG_TUSB_MCU == OPT_MCU_ESP32H4
397397
#define TUP_MCU_MULTIPLE_CORE 1
398398
#endif
399399

@@ -420,6 +420,20 @@
420420
#define CFG_TUH_MEM_DCACHE_ENABLE_DEFAULT CFG_TUH_DWC2_DMA_ENABLE
421421
#define CFG_TUSB_MEM_DCACHE_LINE_SIZE_DEFAULT 64
422422

423+
#elif TU_CHECK_MCU(OPT_MCU_ESP32S31)
424+
#define TUP_USBIP_DWC2
425+
#define TUP_USBIP_DWC2_ESP32
426+
#define TUP_RHPORT_HIGHSPEED 1
427+
#define TUP_DCD_ENDPOINT_MAX 16
428+
429+
#define CFG_TUSB_OS_INC_PATH_DEFAULT freertos/
430+
431+
#define TUP_MCU_MULTIPLE_CORE 1
432+
433+
// Disable slave if DMA is enabled
434+
#define CFG_TUD_DWC2_SLAVE_ENABLE_DEFAULT !CFG_TUD_DWC2_DMA_ENABLE
435+
#define CFG_TUH_DWC2_SLAVE_ENABLE_DEFAULT !CFG_TUH_DWC2_DMA_ENABLE
436+
423437
#elif TU_CHECK_MCU(OPT_MCU_ESP32, OPT_MCU_ESP32C2, OPT_MCU_ESP32C3, OPT_MCU_ESP32C5, OPT_MCU_ESP32C6, OPT_MCU_ESP32C61, OPT_MCU_ESP32H2)
424438
#if (CFG_TUD_ENABLED || !(defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421))
425439
#error "MCUs are only supported with CFG_TUH_MAX3421 enabled"

src/portable/synopsys/dwc2/dcd_dwc2.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ void dcd_connect(uint8_t rhport) {
488488
(void) rhport;
489489
dwc2_regs_t* dwc2 = DWC2_REG(rhport);
490490

491-
#ifdef TUP_USBIP_DWC2_ESP32
491+
#if defined(TUP_USBIP_DWC2_ESP32) && !TU_CHECK_MCU(OPT_MCU_ESP32S31)
492492
usb_wrap_otg_conf_reg_t conf = USB_WRAP.otg_conf;
493493
conf.pad_pull_override = 0;
494494
conf.dp_pullup = 0;
@@ -505,7 +505,7 @@ void dcd_disconnect(uint8_t rhport) {
505505
(void) rhport;
506506
dwc2_regs_t* dwc2 = DWC2_REG(rhport);
507507

508-
#ifdef TUP_USBIP_DWC2_ESP32
508+
#if defined(TUP_USBIP_DWC2_ESP32) && !TU_CHECK_MCU(OPT_MCU_ESP32S31)
509509
usb_wrap_otg_conf_reg_t conf = USB_WRAP.otg_conf;
510510
conf.pad_pull_override = 1;
511511
conf.dp_pullup = 0;

0 commit comments

Comments
 (0)