diff --git a/.github/workflows/build_and_run_esp_usb_test_apps.yml b/.github/workflows/build_and_run_esp_usb_test_apps.yml index abd3e02619..f249c742f6 100644 --- a/.github/workflows/build_and_run_esp_usb_test_apps.yml +++ b/.github/workflows/build_and_run_esp_usb_test_apps.yml @@ -53,8 +53,8 @@ jobs: # Config and manifest files for idf-build-apps are used from the esp-usb repository automatically # Here we only overload path using CLI parameter -p to build only device test apps cd ${{ env.ESP_USB_PATH }} - idf-build-apps find -p device --disable-targets esp32s31 - idf-build-apps build -p device --disable-targets esp32s31 + idf-build-apps find -p device + idf-build-apps build -p device - uses: actions/upload-artifact@v6 with: # Test apps builds live under the repository workspace, we use workspace-relative glob diff --git a/.github/workflows/build_and_run_idf_examples.yml b/.github/workflows/build_and_run_idf_examples.yml index 217b7128db..dcc9dcd263 100644 --- a/.github/workflows/build_and_run_idf_examples.yml +++ b/.github/workflows/build_and_run_idf_examples.yml @@ -58,8 +58,8 @@ jobs: . ${IDF_PATH}/export.sh cd ${IDF_PATH} - idf-build-apps find --config-file ${CONFIG_PATH} --manifest-file ${MANIFEST_PATH} --disable-targets esp32s31 - idf-build-apps build --config-file ${CONFIG_PATH} --manifest-file ${MANIFEST_PATH} --disable-targets esp32s31 + idf-build-apps find --config-file ${CONFIG_PATH} --manifest-file ${MANIFEST_PATH} + idf-build-apps build --config-file ${CONFIG_PATH} --manifest-file ${MANIFEST_PATH} - uses: actions/upload-artifact@v6 with: # We upload only USB Device example binaries to run them on the target diff --git a/CMakeLists.txt b/CMakeLists.txt index b868f49b61..ba3975f758 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,16 +2,14 @@ idf_build_get_property(target IDF_TARGET) if(${target} STREQUAL "esp32s3") set(tusb_mcu "OPT_MCU_ESP32S3") - set(tusb_family "esp32sx") elseif(${target} STREQUAL "esp32s2") set(tusb_mcu "OPT_MCU_ESP32S2") - set(tusb_family "esp32sx") elseif(${target} STREQUAL "esp32p4") set(tusb_mcu "OPT_MCU_ESP32P4") - set(tusb_family "esp32px") elseif(${target} STREQUAL "esp32h4") set(tusb_mcu "OPT_MCU_ESP32H4") - set(tusb_family "esp32sx") +elseif(${target} STREQUAL "esp32s31") + set(tusb_mcu "OPT_MCU_ESP32S31") endif() set(compile_options diff --git a/README.rst b/README.rst index 03ad3744cb..901a5c3440 100644 --- a/README.rst +++ b/README.rst @@ -127,6 +127,8 @@ Supported CPUs | | P4 | ✔ | ✔ | ✔ | dwc2 | | | +-----------------------------+--------+------+-----------+------------------------+-------------------+ | | H4 | ✔ | ✔ | ✖ | dwc2 | | +| +-----------------------------+--------+------+-----------+------------------------+-------------------+ +| | S31 | ✔ | ✔ | ✔ | dwc2 | | +--------------+-----------------------------+--------+------+-----------+------------------------+-------------------+ | GigaDevice | GD32VF103 | ✔ | | ✖ | dwc2 | | +--------------+-----------------------------+--------+------+-----------+------------------------+-------------------+ diff --git a/docs/info/changelog.rst b/docs/info/changelog.rst index b4423f81e1..3719d3b506 100644 --- a/docs/info/changelog.rst +++ b/docs/info/changelog.rst @@ -10,6 +10,7 @@ General - New MCUs and Boards: + - Add ESP32-S31 OTG high-speed support - Add ESP32-H4, ESP32-C5, ESP32-C61 support - Add STM32U0, STM32WBA, STM32N6 - Add AT32F405, AT32F403A, AT32F415, AT32F423 support diff --git a/hw/bsp/espressif/boards/family.c b/hw/bsp/espressif/boards/family.c index a29415cc0e..9e337da6a9 100644 --- a/hw/bsp/espressif/boards/family.c +++ b/hw/bsp/espressif/boards/family.c @@ -49,7 +49,7 @@ static led_strip_handle_t led_strip; static void max3421_init(void); #endif -#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3, OPT_MCU_ESP32H4, OPT_MCU_ESP32P4) +#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3, OPT_MCU_ESP32H4, OPT_MCU_ESP32P4, OPT_MCU_ESP32S31) static bool usb_init(void); #endif @@ -90,7 +90,7 @@ void board_init(void) { gpio_set_direction(BUTTON_PIN, GPIO_MODE_INPUT); gpio_set_pull_mode(BUTTON_PIN, BUTTON_STATE_ACTIVE ? GPIO_PULLDOWN_ONLY : GPIO_PULLUP_ONLY); -#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3, OPT_MCU_ESP32H4, OPT_MCU_ESP32P4) +#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3, OPT_MCU_ESP32H4, OPT_MCU_ESP32P4, OPT_MCU_ESP32S31) usb_init(); #endif @@ -105,10 +105,6 @@ void board_init(void) { #endif } -#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3, OPT_MCU_ESP32H4) - -#endif - //--------------------------------------------------------------------+ // Board porting API //--------------------------------------------------------------------+ @@ -172,7 +168,7 @@ void board_reset_to_bootloader(void) { // PHY Init //-------------------------------------------------------------------- -#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3, OPT_MCU_ESP32H4, OPT_MCU_ESP32P4) +#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3, OPT_MCU_ESP32H4, OPT_MCU_ESP32P4, OPT_MCU_ESP32S31) #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 3, 0) #include "esp_private/usb_phy.h" @@ -183,7 +179,11 @@ bool usb_init(void) { // Configure USB PHY usb_phy_config_t phy_conf = { .controller = USB_PHY_CTRL_OTG, +#if TU_CHECK_MCU(OPT_MCU_ESP32S31) + .target = USB_PHY_TARGET_UTMI, +#else .target = USB_PHY_TARGET_INT, +#endif // maybe we can use USB_OTG_MODE_DEFAULT and switch using dwc2 driver #if CFG_TUD_ENABLED diff --git a/hw/bsp/espressif/family.cmake b/hw/bsp/espressif/family.cmake index ca9eadaf62..30d5a6ac97 100644 --- a/hw/bsp/espressif/family.cmake +++ b/hw/bsp/espressif/family.cmake @@ -2,7 +2,10 @@ include("${CMAKE_CURRENT_LIST_DIR}/boards/${BOARD}/board.cmake") string(TOUPPER ${IDF_TARGET} FAMILY_MCUS) -# Device port default to Port1 for P4 (highspeed), Port0 for others (fullspeed) +# Device/host port defaults: +# - ESP32-P4 uses Port1 (highspeed) +# - ESP32-S31 uses Port0 (highspeed) +# - Other targets use Port0 and derive the default speed from RHPORT_SPEED set(RHPORT_SPEED OPT_MODE_FULL_SPEED OPT_MODE_HIGH_SPEED) if (NOT DEFINED RHPORT_DEVICE) @@ -22,10 +25,18 @@ if (NOT DEFINED RHPORT_HOST) endif() if (NOT DEFINED RHPORT_DEVICE_SPEED) - list(GET RHPORT_SPEED ${RHPORT_DEVICE} RHPORT_DEVICE_SPEED) + if (IDF_TARGET STREQUAL "esp32s31") + set(RHPORT_DEVICE_SPEED OPT_MODE_HIGH_SPEED) + else () + list(GET RHPORT_SPEED ${RHPORT_DEVICE} RHPORT_DEVICE_SPEED) + endif () endif () if (NOT DEFINED RHPORT_HOST_SPEED) - list(GET RHPORT_SPEED ${RHPORT_HOST} RHPORT_HOST_SPEED) + if (IDF_TARGET STREQUAL "esp32s31") + set(RHPORT_HOST_SPEED OPT_MODE_HIGH_SPEED) + else () + list(GET RHPORT_SPEED ${RHPORT_HOST} RHPORT_HOST_SPEED) + endif () endif () # Add example src and bsp directories diff --git a/idf_component.yml b/idf_component.yml index 0ebcb65f01..7b4f9ef8ca 100644 --- a/idf_component.yml +++ b/idf_component.yml @@ -17,6 +17,7 @@ targets: - esp32s3 - esp32p4 - esp32h4 + - esp32s31 tags: - usb - usb_device diff --git a/src/common/tusb_mcu.h b/src/common/tusb_mcu.h index 1c11df114c..dd37868429 100644 --- a/src/common/tusb_mcu.h +++ b/src/common/tusb_mcu.h @@ -393,7 +393,7 @@ #define TUP_DCD_ENDPOINT_MAX 7 // only 5 TX FIFO for endpoint IN #define CFG_TUSB_OS_INC_PATH_DEFAULT freertos/ - #if CFG_TUSB_MCU == OPT_MCU_ESP32S3 + #if CFG_TUSB_MCU == OPT_MCU_ESP32S3 || CFG_TUSB_MCU == OPT_MCU_ESP32H4 #define TUP_MCU_MULTIPLE_CORE 1 #endif @@ -420,6 +420,20 @@ #define CFG_TUH_MEM_DCACHE_ENABLE_DEFAULT CFG_TUH_DWC2_DMA_ENABLE #define CFG_TUSB_MEM_DCACHE_LINE_SIZE_DEFAULT 64 +#elif TU_CHECK_MCU(OPT_MCU_ESP32S31) + #define TUP_USBIP_DWC2 + #define TUP_USBIP_DWC2_ESP32 + #define TUP_RHPORT_HIGHSPEED 1 + #define TUP_DCD_ENDPOINT_MAX 16 + + #define CFG_TUSB_OS_INC_PATH_DEFAULT freertos/ + + #define TUP_MCU_MULTIPLE_CORE 1 + + // Disable slave if DMA is enabled + #define CFG_TUD_DWC2_SLAVE_ENABLE_DEFAULT !CFG_TUD_DWC2_DMA_ENABLE + #define CFG_TUH_DWC2_SLAVE_ENABLE_DEFAULT !CFG_TUH_DWC2_DMA_ENABLE + #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) #if (CFG_TUD_ENABLED || !(defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421)) #error "MCUs are only supported with CFG_TUH_MAX3421 enabled" diff --git a/src/portable/synopsys/dwc2/dcd_dwc2.c b/src/portable/synopsys/dwc2/dcd_dwc2.c index 1cb7e6e201..e9fb847aa7 100644 --- a/src/portable/synopsys/dwc2/dcd_dwc2.c +++ b/src/portable/synopsys/dwc2/dcd_dwc2.c @@ -488,7 +488,7 @@ void dcd_connect(uint8_t rhport) { (void) rhport; dwc2_regs_t* dwc2 = DWC2_REG(rhport); -#ifdef TUP_USBIP_DWC2_ESP32 +#if defined(TUP_USBIP_DWC2_ESP32) && !TU_CHECK_MCU(OPT_MCU_ESP32S31) usb_wrap_otg_conf_reg_t conf = USB_WRAP.otg_conf; conf.pad_pull_override = 0; conf.dp_pullup = 0; @@ -505,7 +505,7 @@ void dcd_disconnect(uint8_t rhport) { (void) rhport; dwc2_regs_t* dwc2 = DWC2_REG(rhport); -#ifdef TUP_USBIP_DWC2_ESP32 +#if defined(TUP_USBIP_DWC2_ESP32) && !TU_CHECK_MCU(OPT_MCU_ESP32S31) usb_wrap_otg_conf_reg_t conf = USB_WRAP.otg_conf; conf.pad_pull_override = 1; conf.dp_pullup = 0; diff --git a/src/portable/synopsys/dwc2/dwc2_esp32.h b/src/portable/synopsys/dwc2/dwc2_esp32.h index a4e0d1770e..66f99c377e 100644 --- a/src/portable/synopsys/dwc2/dwc2_esp32.h +++ b/src/portable/synopsys/dwc2/dwc2_esp32.h @@ -37,7 +37,11 @@ #include "esp_intr_alloc.h" #include "soc/periph_defs.h" + +// ESP32-S31 does not have USB_WRAP peripheral (HS-only with UTMI PHY) +#if !TU_CHECK_MCU(OPT_MCU_ESP32S31) #include "soc/usb_wrap_struct.h" +#endif #if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3) #define DWC2_FS_REG_BASE 0x60080000UL @@ -75,6 +79,14 @@ static const dwc2_controller_t _dwc2_controller[] = { { .reg_base = DWC2_FS_REG_BASE, .irqnum = ETS_USB_OTG11_CH0_INTR_SOURCE, .ep_count = 7, .ep_in_count = 5, .ep_fifo_size = 1024 }, { .reg_base = DWC2_HS_REG_BASE, .irqnum = ETS_USB_OTG_INTR_SOURCE, .ep_count = 16, .ep_in_count = 8, .ep_fifo_size = 4096 } }; + +#elif TU_CHECK_MCU(OPT_MCU_ESP32S31) +#define DWC2_HS_REG_BASE 0x20300000UL +#define DWC2_EP_MAX 16 + +static const dwc2_controller_t _dwc2_controller[] = { + { .reg_base = DWC2_HS_REG_BASE, .irqnum = ETS_USB_OTGHS_INTR_SOURCE, .ep_count = 16, .ep_in_count = 8, .ep_fifo_size = 4096 } +}; #endif //--------------------------------------------------------------------+ diff --git a/src/tusb_option.h b/src/tusb_option.h index 378b5607eb..38f71650ef 100644 --- a/src/tusb_option.h +++ b/src/tusb_option.h @@ -132,6 +132,7 @@ #define OPT_MCU_ESP32C5 908 ///< Espressif ESP32-C5 #define OPT_MCU_ESP32C61 909 ///< Espressif ESP32-C61 #define OPT_MCU_ESP32H4 910 ///< Espressif ESP32-H4 +#define OPT_MCU_ESP32S31 911 ///< Espressif ESP32-S31 #define TUSB_MCU_VENDOR_ESPRESSIF (CFG_TUSB_MCU >= 900 && CFG_TUSB_MCU < 1000) // check if Espressif MCU #define TUP_MCU_ESPRESSIF TUSB_MCU_VENDOR_ESPRESSIF // for backward compatibility