Skip to content

Commit 0232d0a

Browse files
committed
Add support for HighSpeed USB in arduino_tinyusb
1 parent 8fb7dff commit 0232d0a

File tree

4 files changed

+36
-21
lines changed

4 files changed

+36
-21
lines changed

Diff for: components/arduino_tinyusb/Kconfig.projbuild

+17-9
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,16 @@ menu "Arduino TinyUSB"
2828

2929
config TINYUSB_CDC_RX_BUFSIZE
3030
int "CDC FIFO size of RX"
31-
default 64
31+
default 64 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3
32+
default 512 if IDF_TARGET_ESP32P4
3233
depends on TINYUSB_CDC_ENABLED
3334
help
3435
CDC FIFO size of RX
3536

3637
config TINYUSB_CDC_TX_BUFSIZE
3738
int "CDC FIFO size of TX"
38-
default 64
39+
default 64 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3
40+
default 512 if IDF_TARGET_ESP32P4
3941
depends on TINYUSB_CDC_ENABLED
4042
help
4143
CDC FIFO size of TX
@@ -86,7 +88,8 @@ menu "Arduino TinyUSB"
8688

8789
config TINYUSB_HID_BUFSIZE
8890
int "HID Buffer size"
89-
default 64
91+
default 64 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3
92+
default 512 if IDF_TARGET_ESP32P4
9093
depends on TINYUSB_HID_ENABLED
9194
help
9295
HID Buffer size. Should be sufficient to hold ID (if any) + Data
@@ -111,14 +114,16 @@ menu "Arduino TinyUSB"
111114

112115
config TINYUSB_MIDI_RX_BUFSIZE
113116
int "MIDI FIFO size of RX"
114-
default 64
117+
default 64 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3
118+
default 512 if IDF_TARGET_ESP32P4
115119
depends on TINYUSB_MIDI_ENABLED
116120
help
117121
MIDI FIFO size of RX
118122

119123
config TINYUSB_MIDI_TX_BUFSIZE
120124
int "MIDI FIFO size of TX"
121-
default 64
125+
default 64 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3
126+
default 512 if IDF_TARGET_ESP32P4
122127
depends on TINYUSB_MIDI_ENABLED
123128
help
124129
MIDI FIFO size of TX
@@ -143,8 +148,9 @@ menu "Arduino TinyUSB"
143148

144149
config TINYUSB_VIDEO_STREAMING_BUFSIZE
145150
int "VIDEO streaming endpoint size"
146-
range 0 64
147-
default 64
151+
range 0 512
152+
default 64 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3
153+
default 512 if IDF_TARGET_ESP32P4
148154
depends on TINYUSB_VIDEO_ENABLED
149155
help
150156
VIDEO streaming endpoint size
@@ -219,14 +225,16 @@ menu "Arduino TinyUSB"
219225

220226
config TINYUSB_VENDOR_RX_BUFSIZE
221227
int "VENDOR FIFO size of RX"
222-
default 64
228+
default 64 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3
229+
default 512 if IDF_TARGET_ESP32P4
223230
depends on TINYUSB_VENDOR_ENABLED
224231
help
225232
VENDOR FIFO size of RX
226233

227234
config TINYUSB_VENDOR_TX_BUFSIZE
228235
int "VENDOR FIFO size of TX"
229-
default 64
236+
default 64 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3
237+
default 512 if IDF_TARGET_ESP32P4
230238
depends on TINYUSB_VENDOR_ENABLED
231239
help
232240
VENDOR FIFO size of TX

Diff for: components/arduino_tinyusb/include/tusb_config.h

+7
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,18 @@ extern "C" {
100100
# define CFG_TUSB_MEM_ALIGN TU_ATTR_ALIGNED(4)
101101
#endif
102102

103+
#if CONFIG_IDF_TARGET_ESP32P4
104+
#define CFG_TUD_MAX_SPEED OPT_MODE_HIGH_SPEED
105+
#else
106+
#define CFG_TUD_MAX_SPEED OPT_MODE_FULL_SPEED
107+
#endif
108+
103109
/* */
104110
/* DRIVER CONFIGURATION */
105111
/* */
106112

107113
#define CFG_TUD_MAINTASK_SIZE 4096
114+
#define CFG_TUD_ENDOINT_SIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
108115
#define CFG_TUD_ENDOINT0_SIZE 64
109116

110117
// Enabled Drivers

Diff for: components/arduino_tinyusb/patches/dcd_dwc2.patch

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//--------------------------------------------------------------------
55
// Endpoint
66
//--------------------------------------------------------------------
7-
+#if defined(TUP_USBIP_DWC2_ESP32)
7+
+#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
88
+// Keep count of how many FIFOs are in use
99
+static uint8_t _allocated_fifos = 1; //FIFO0 is always in use
1010
+
@@ -23,7 +23,7 @@
2323
} else {
2424
- dwc2->epin[epnum].diepctl = dxepctl | (epnum << DIEPCTL_TXFNUM_Pos);
2525
+ uint8_t fifo_num = epnum;
26-
+#if defined(TUP_USBIP_DWC2_ESP32)
26+
+#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
2727
+ // Special Case for EP5, which is used by CDC but not actually called by the driver
2828
+ // we can give it a fake FIFO
2929
+ if (epnum == 5) {
@@ -41,7 +41,7 @@
4141
xfer_status[n][TUSB_DIR_IN].max_size = 0;
4242
}
4343

44-
+#if defined(TUP_USBIP_DWC2_ESP32)
44+
+#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
4545
+ _allocated_fifos = 1;
4646
+#endif
4747
+
@@ -52,7 +52,7 @@
5252
if (int_status & GINTSTS_USBRST) {
5353
// USBRST is start of reset.
5454
dwc2->gintsts = GINTSTS_USBRST;
55-
+#if defined(TUP_USBIP_DWC2_ESP32)
55+
+#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
5656
+ _allocated_fifos = 1;
5757
+#endif
5858
bus_reset(rhport);
@@ -65,7 +65,7 @@
6565
- dcd_event_bus_signal(rhport, DCD_EVENT_SUSPEND, true);
6666
+ //dcd_event_bus_signal(rhport, DCD_EVENT_SUSPEND, true);
6767
+ dcd_event_bus_signal(rhport, DCD_EVENT_UNPLUGGED, true);
68-
+#if defined(TUP_USBIP_DWC2_ESP32)
68+
+#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
6969
+ _allocated_fifos = 1;
7070
+#endif
7171
}
@@ -75,7 +75,7 @@
7575

7676
if (otg_int & GOTGINT_SEDET) {
7777
dcd_event_bus_signal(rhport, DCD_EVENT_UNPLUGGED, true);
78-
+#if defined(TUP_USBIP_DWC2_ESP32)
78+
+#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
7979
+ _allocated_fifos = 1;
8080
+#endif
8181
}

Diff for: components/arduino_tinyusb/src/dcd_dwc2.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ static void dfifo_write_packet(uint8_t rhport, uint8_t fifo_num, uint8_t const*
316316
//--------------------------------------------------------------------
317317
// Endpoint
318318
//--------------------------------------------------------------------
319-
#if defined(TUP_USBIP_DWC2_ESP32)
319+
#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
320320
// Keep count of how many FIFOs are in use
321321
static uint8_t _allocated_fifos = 1; //FIFO0 is always in use
322322

@@ -347,7 +347,7 @@ static void edpt_activate(uint8_t rhport, tusb_desc_endpoint_t const * p_endpoin
347347
dwc2->daintmsk |= TU_BIT(DAINTMSK_OEPM_Pos + epnum);
348348
} else {
349349
uint8_t fifo_num = epnum;
350-
#if defined(TUP_USBIP_DWC2_ESP32)
350+
#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
351351
// Special Case for EP5, which is used by CDC but not actually called by the driver
352352
// we can give it a fake FIFO
353353
if (epnum == 5) {
@@ -871,7 +871,7 @@ void dcd_edpt_close_all(uint8_t rhport) {
871871
xfer_status[n][TUSB_DIR_IN].max_size = 0;
872872
}
873873

874-
#if defined(TUP_USBIP_DWC2_ESP32)
874+
#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
875875
_allocated_fifos = 1;
876876
#endif
877877

@@ -1229,7 +1229,7 @@ void dcd_int_handler(uint8_t rhport) {
12291229
if (int_status & GINTSTS_USBRST) {
12301230
// USBRST is start of reset.
12311231
dwc2->gintsts = GINTSTS_USBRST;
1232-
#if defined(TUP_USBIP_DWC2_ESP32)
1232+
#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
12331233
_allocated_fifos = 1;
12341234
#endif
12351235
bus_reset(rhport);
@@ -1265,7 +1265,7 @@ void dcd_int_handler(uint8_t rhport) {
12651265
dwc2->gintsts = GINTSTS_USBSUSP;
12661266
//dcd_event_bus_signal(rhport, DCD_EVENT_SUSPEND, true);
12671267
dcd_event_bus_signal(rhport, DCD_EVENT_UNPLUGGED, true);
1268-
#if defined(TUP_USBIP_DWC2_ESP32)
1268+
#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
12691269
_allocated_fifos = 1;
12701270
#endif
12711271
}
@@ -1284,7 +1284,7 @@ void dcd_int_handler(uint8_t rhport) {
12841284

12851285
if (otg_int & GOTGINT_SEDET) {
12861286
dcd_event_bus_signal(rhport, DCD_EVENT_UNPLUGGED, true);
1287-
#if defined(TUP_USBIP_DWC2_ESP32)
1287+
#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
12881288
_allocated_fifos = 1;
12891289
#endif
12901290
}

0 commit comments

Comments
 (0)