Skip to content

Commit 7d6744b

Browse files
committed
feat(usb): add initial ESP32-H4 support in tinyusb
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.
1 parent 63c21ab commit 7d6744b

File tree

9 files changed

+36
-7
lines changed

9 files changed

+36
-7
lines changed

CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
idf_build_get_property(target IDF_TARGET)
22

3+
34
if(${target} STREQUAL "esp32s3")
45
set(tusb_mcu "OPT_MCU_ESP32S3")
56
set(tusb_family "esp32sx")
@@ -9,8 +10,14 @@ elseif(${target} STREQUAL "esp32s2")
910
elseif(${target} STREQUAL "esp32p4")
1011
set(tusb_mcu "OPT_MCU_ESP32P4")
1112
set(tusb_family "esp32px")
13+
elseif(${target} STREQUAL "esp32h4")
14+
set(tusb_mcu OPT_MCU_ESP32H4)
15+
set(tusb_family "esp32sx")
1216
endif()
1317

18+
message(STATUS "tusb_mcu: ${tusb_mcu}")
19+
message(STATUS "tusb_family: ${tusb_family}")
20+
1421
set(compile_options
1522
"-DCFG_TUSB_MCU=${tusb_mcu}"
1623
)

hw/bsp/espressif/boards/family.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ void board_init(void) {
8888
gpio_set_direction(BUTTON_PIN, GPIO_MODE_INPUT);
8989
gpio_set_pull_mode(BUTTON_PIN, BUTTON_STATE_ACTIVE ? GPIO_PULLDOWN_ONLY : GPIO_PULLUP_ONLY);
9090

91-
#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3, OPT_MCU_ESP32P4)
91+
#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3, OPT_MCU_ESP32H4, OPT_MCU_ESP32P4)
9292
usb_init();
9393
#endif
9494

@@ -103,7 +103,7 @@ void board_init(void) {
103103
#endif
104104
}
105105

106-
#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
106+
#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3, OPT_MCU_ESP32H4)
107107

108108
#endif
109109

@@ -158,7 +158,7 @@ int board_getchar(void) {
158158
// PHY Init
159159
//--------------------------------------------------------------------
160160

161-
#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3, OPT_MCU_ESP32P4)
161+
#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3, OPT_MCU_ESP32H4, OPT_MCU_ESP32P4)
162162
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 3, 0)
163163

164164
#include "esp_private/usb_phy.h"

idf_component.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
name: tinyusb
12
description: TinyUSB ported to Espressif's SoCs
23
url: https://docs.tinyusb.org/en/latest/
34
documentation: "https://docs.tinyusb.org/en/latest/"
@@ -9,3 +10,4 @@ targets:
910
- esp32s2
1011
- esp32s3
1112
- esp32p4
13+
- esp32h4

src/class/audio/audio_device.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
// Only STM32 and dcd_transdimension use non-linear buffer for now
8383
// dwc2 except esp32sx (since it may use dcd_esp32sx)
8484
// Ring buffer is incompatible with dcache, since neither address nor size is aligned to cache line
85-
#if (defined(TUP_USBIP_DWC2) && !TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)) || \
85+
#if (defined(TUP_USBIP_DWC2) && !TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3, OPT_MCU_ESP32H4)) || \
8686
defined(TUP_USBIP_FSDEV) || \
8787
CFG_TUSB_MCU == OPT_MCU_RX63X || \
8888
CFG_TUSB_MCU == OPT_MCU_RX65X || \

src/common/tusb_mcu.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@
363363
//--------------------------------------------------------------------+
364364
// Espressif
365365
//--------------------------------------------------------------------+
366-
#elif TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
366+
#elif TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3, OPT_MCU_ESP32H4)
367367
#define TUP_USBIP_DWC2
368368
#define TUP_USBIP_DWC2_ESP32
369369
#define TUP_DCD_ENDPOINT_MAX 7 // only 5 TX FIFO for endpoint IN

src/portable/espressif/esp32sx/dcd_esp32sx.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
#include "tusb_option.h"
3030

31-
#if (((CFG_TUSB_MCU == OPT_MCU_ESP32S2) || (CFG_TUSB_MCU == OPT_MCU_ESP32S3)) && CFG_TUD_ENABLED)
31+
#if (((CFG_TUSB_MCU == OPT_MCU_ESP32S2) || (CFG_TUSB_MCU == OPT_MCU_ESP32S3) || (CFG_TUSB_MCU == OPT_MCU_ESP32H4)) && CFG_TUD_ENABLED)
3232

3333
// Espressif
3434
#include "xtensa/xtensa_api.h"
@@ -886,4 +886,4 @@ void dcd_int_disable (uint8_t rhport)
886886
esp_intr_free(usb_ih);
887887
}
888888

889-
#endif // #if OPT_MCU_ESP32S2 || OPT_MCU_ESP32S3
889+
#endif // #if OPT_MCU_ESP32S2 || OPT_MCU_ESP32S3 || OPT_MCU_ESP32H4

src/portable/synopsys/dwc2/dcd_dwc2.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,17 @@
4242
#include "dwc2_common.h"
4343
#include "dwc2_critical.h"
4444

45+
#if TU_CHECK_MCU(OPT_MCU_ESP32H4)
46+
// H4's USB_WRAP register block uses "wrap_*" field names. Map them to the
47+
// names used by TinyUSB's DWC2 port to keep the source unchanged.
48+
#define otg_conf wrap_otg_conf
49+
#define pad_pull_override wrap_pad_pull_override
50+
#define dp_pullup wrap_dp_pullup
51+
#define dp_pulldown wrap_dp_pulldown
52+
#define dm_pullup wrap_dm_pullup
53+
#define dm_pulldown wrap_dm_pulldown
54+
#endif
55+
4556
#if TU_CHECK_MCU(OPT_MCU_GD32VF103)
4657
#define DWC2_EP_COUNT(_dwc2) DWC2_EP_MAX
4758
#else

src/portable/synopsys/dwc2/dwc2_esp32.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ static const dwc2_controller_t _dwc2_controller[] = {
4747
{ .reg_base = DWC2_FS_REG_BASE, .irqnum = ETS_USB_INTR_SOURCE, .ep_count = 7, .ep_in_count = 5, .ep_fifo_size = 1024 }
4848
};
4949

50+
#elif TU_CHECK_MCU(OPT_MCU_ESP32H4)
51+
#define DWC2_FS_REG_BASE 0x60040000UL
52+
#define DWC2_EP_MAX 7
53+
54+
static const dwc2_controller_t _dwc2_controller[] = {
55+
{ .reg_base = DWC2_FS_REG_BASE, .irqnum = ETS_USB_OTG11_INTR_SOURCE, .ep_count = 7, .ep_in_count = 5, .ep_fifo_size = 1024 }
56+
};
57+
5058
#elif TU_CHECK_MCU(OPT_MCU_ESP32P4)
5159
#define DWC2_FS_REG_BASE 0x50040000UL
5260
#define DWC2_HS_REG_BASE 0x50000000UL

src/tusb_option.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@
127127
#define OPT_MCU_ESP32C2 905 ///< Espressif ESP32-C2
128128
#define OPT_MCU_ESP32H2 906 ///< Espressif ESP32-H2
129129
#define OPT_MCU_ESP32P4 907 ///< Espressif ESP32-P4
130+
#define OPT_MCU_ESP32H4 908 ///< Espressif ESP32-H4
130131
#define TUSB_MCU_VENDOR_ESPRESSIF (CFG_TUSB_MCU >= 900 && CFG_TUSB_MCU < 1000) // check if Espressif MCU
131132
#define TUP_MCU_ESPRESSIF TUSB_MCU_VENDOR_ESPRESSIF // for backward compatibility
132133

0 commit comments

Comments
 (0)