Skip to content

Commit ce1d37a

Browse files
authored
Merge pull request #3612 from espressif/feat/esp32s31_support
Add ESP32-S31 as a supported MCU in TinyUSB
2 parents 723e016 + 776f613 commit ce1d37a

7 files changed

Lines changed: 54 additions & 14 deletions

File tree

README.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ Supported CPUs
157157
| Espressif | S2, S3, H4 |||| dwc2 | |
158158
| ESP32 +-----------------------------+--------+------+-----------+------------------------+--------------------+
159159
| | P4 |||| dwc2 | |
160+
| +-----------------------------+--------+------+-----------+------------------------+--------------------+
161+
| | S31 |||| dwc2 | |
160162
+--------------+-----------------------------+--------+------+-----------+------------------------+--------------------+
161163
| GigaDevice | GD32VF103 || || dwc2 | |
162164
+--------------+-----------------------------+--------+------+-----------+------------------------+--------------------+

hw/bsp/espressif/boards/family.c

Lines changed: 2 additions & 6 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(uint8_t rhport, bool is_host);
5454
#endif
5555

@@ -111,10 +111,6 @@ void board_init(void) {
111111
#endif
112112
}
113113

114-
#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3, OPT_MCU_ESP32H4)
115-
116-
#endif
117-
118114
//--------------------------------------------------------------------+
119115
// Board porting API
120116
//--------------------------------------------------------------------+
@@ -178,7 +174,7 @@ void board_reset_to_bootloader(void) {
178174
// PHY Init
179175
//--------------------------------------------------------------------
180176

181-
#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3, OPT_MCU_ESP32H4, OPT_MCU_ESP32P4)
177+
#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3, OPT_MCU_ESP32H4, OPT_MCU_ESP32P4, OPT_MCU_ESP32S31)
182178
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 3, 0)
183179

184180
#include "esp_private/usb_phy.h"

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

src/common/tusb_mcu.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@
455455
#define CFG_TUSB_OS_INC_PATH_DEFAULT freertos/
456456
// clang-format on
457457

458-
#if CFG_TUSB_MCU == OPT_MCU_ESP32S3
458+
#if CFG_TUSB_MCU == OPT_MCU_ESP32S3 || CFG_TUSB_MCU == OPT_MCU_ESP32H4
459459
#define TUP_MCU_MULTIPLE_CORE 1
460460
#endif
461461

@@ -476,6 +476,22 @@
476476
#define CFG_TUH_MEM_DCACHE_ENABLE_DEFAULT CFG_TUH_DWC2_DMA_ENABLE
477477
#define CFG_TUSB_MEM_DCACHE_LINE_SIZE_DEFAULT 64
478478

479+
#elif TU_CHECK_MCU(OPT_MCU_ESP32S31)
480+
#define TUP_USBIP_DWC2
481+
#define TUP_USBIP_DWC2_ESP32
482+
#define TUP_RHPORT_HIGHSPEED 1
483+
#define TUP_DCD_ENDPOINT_MAX 16
484+
485+
// clang-format off
486+
#define CFG_TUSB_OS_INC_PATH_DEFAULT freertos/
487+
// clang-format on
488+
489+
#define TUP_MCU_MULTIPLE_CORE 1
490+
491+
// Disable slave if DMA is enabled
492+
#define CFG_TUD_DWC2_SLAVE_ENABLE_DEFAULT !CFG_TUD_DWC2_DMA_ENABLE
493+
#define CFG_TUH_DWC2_SLAVE_ENABLE_DEFAULT !CFG_TUH_DWC2_DMA_ENABLE
494+
479495
#elif TU_CHECK_MCU(OPT_MCU_ESP32, OPT_MCU_ESP32C2, OPT_MCU_ESP32C3, OPT_MCU_ESP32C5, OPT_MCU_ESP32C6, \
480496
OPT_MCU_ESP32C61, OPT_MCU_ESP32H2)
481497
#if (CFG_TUD_ENABLED || !(defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421))

src/portable/synopsys/dwc2/dcd_dwc2.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -541,8 +541,9 @@ void dcd_remote_wakeup(uint8_t rhport) {
541541
void dcd_connect(uint8_t rhport) {
542542
dwc2_regs_t* dwc2 = DWC2_REG(rhport);
543543

544-
#ifdef TUP_USBIP_DWC2_ESP32
545-
// On ESP32-P4 HS PHY, do not write to USB_WRAP register which belongs to FS PHY
544+
#if defined(TUP_USBIP_DWC2_ESP32) && !TU_CHECK_MCU(OPT_MCU_ESP32S31)
545+
// S31 is excluded at compile time (no USB_WRAP peripheral).
546+
// On P4, the HS PHY (port 1) must not touch USB_WRAP which belongs to the FS PHY.
546547
if (rhport == 0) {
547548
usb_wrap_otg_conf_reg_t conf = USB_WRAP.otg_conf;
548549
conf.pad_pull_override = 0;
@@ -560,8 +561,9 @@ void dcd_connect(uint8_t rhport) {
560561
void dcd_disconnect(uint8_t rhport) {
561562
dwc2_regs_t* dwc2 = DWC2_REG(rhport);
562563

563-
#ifdef TUP_USBIP_DWC2_ESP32
564-
// On ESP32-P4 HS PHY, do not write to USB_WRAP register which belongs to FS PHY
564+
#if defined(TUP_USBIP_DWC2_ESP32) && !TU_CHECK_MCU(OPT_MCU_ESP32S31)
565+
// S31 is excluded at compile time (no USB_WRAP peripheral).
566+
// On P4, the HS PHY (port 1) must not touch USB_WRAP which belongs to the FS PHY.
565567
if (rhport == 0) {
566568
usb_wrap_otg_conf_reg_t conf = USB_WRAP.otg_conf;
567569
conf.pad_pull_override = 1;

src/portable/synopsys/dwc2/dwc2_esp32.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@
3737

3838
#include "esp_intr_alloc.h"
3939
#include "soc/periph_defs.h"
40+
41+
// ESP32-S31 does not have USB_WRAP peripheral (HS-only with UTMI PHY)
42+
#if !TU_CHECK_MCU(OPT_MCU_ESP32S31)
4043
#include "soc/usb_wrap_struct.h"
44+
#endif
4145

4246
#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
4347
#define DWC2_FS_REG_BASE 0x60080000UL
@@ -75,6 +79,14 @@ static const dwc2_controller_t _dwc2_controller[] = {
7579
{ .reg_base = DWC2_FS_REG_BASE, .irqnum = ETS_USB_OTG11_CH0_INTR_SOURCE, .ep_count = 7, .ep_in_count = 5, .otg_dfifo_depth = 256 },
7680
{ .reg_base = DWC2_HS_REG_BASE, .irqnum = ETS_USB_OTG_INTR_SOURCE, .ep_count = 16, .ep_in_count = 8, .otg_dfifo_depth = 1024 }
7781
};
82+
83+
#elif TU_CHECK_MCU(OPT_MCU_ESP32S31)
84+
#define DWC2_HS_REG_BASE 0x20300000UL
85+
#define DWC2_EP_MAX 16
86+
87+
static const dwc2_controller_t _dwc2_controller[] = {
88+
{ .reg_base = DWC2_HS_REG_BASE, .irqnum = ETS_USB_OTGHS_INTR_SOURCE, .ep_count = 16, .ep_in_count = 8, .otg_dfifo_depth = 1024 }
89+
};
7890
#endif
7991

8092
//--------------------------------------------------------------------+

src/tusb_option.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@
134134
#define OPT_MCU_ESP32C5 908 ///< Espressif ESP32-C5
135135
#define OPT_MCU_ESP32C61 909 ///< Espressif ESP32-C61
136136
#define OPT_MCU_ESP32H4 910 ///< Espressif ESP32-H4
137+
#define OPT_MCU_ESP32S31 911 ///< Espressif ESP32-S31
137138

138139
// Dialog
139140
#define OPT_MCU_DA1469X 1000 ///< Dialog Semiconductor DA1469x

0 commit comments

Comments
 (0)