Skip to content

Commit 5c2510f

Browse files
authored
Merge branch 'master' into release/v5.3
2 parents 8bc7ec5 + 42f7e46 commit 5c2510f

File tree

7 files changed

+451
-1422
lines changed

7 files changed

+451
-1422
lines changed

Diff for: components/arduino_tinyusb/CMakeLists.txt

+15-11
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,18 @@ if(CONFIG_TINYUSB_ENABLED)
1515
"-DCFG_TUSB_DEBUG=${CONFIG_TINYUSB_DEBUG_LEVEL}"
1616
"-Wno-type-limits" # needed for the vanila tinyusb with turned off classes
1717
)
18+
elseif(IDF_TARGET STREQUAL "esp32p4")
19+
set(compile_options
20+
"-DCFG_TUSB_MCU=OPT_MCU_ESP32P4"
21+
"-DCFG_TUSB_DEBUG=${CONFIG_TINYUSB_DEBUG_LEVEL}"
22+
"-Wno-type-limits" # needed for the vanila tinyusb with turned off classes
23+
)
1824
endif()
1925

2026
set(srcs
2127
# espressif:
22-
#"${COMPONENT_DIR}/src/dcd_esp32sx.c"
2328
"${COMPONENT_DIR}/src/dcd_dwc2.c"
2429
# tusb:
25-
#"${COMPONENT_DIR}/tinyusb/src/portable/espressif/esp32sx/dcd_esp32sx.c"
2630
#"{COMPONENT_DIR}/tinyusb/src/portable/synopsys/dwc2/dcd_dwc2.c"
2731
"${COMPONENT_DIR}/tinyusb/src/class/cdc/cdc_device.c"
2832
"${COMPONENT_DIR}/tinyusb/src/class/hid/hid_device.c"
@@ -32,6 +36,7 @@ if(CONFIG_TINYUSB_ENABLED)
3236
"${COMPONENT_DIR}/tinyusb/src/class/dfu/dfu_rt_device.c"
3337
"${COMPONENT_DIR}/tinyusb/src/class/dfu/dfu_device.c"
3438
"${COMPONENT_DIR}/tinyusb/src/class/vendor/vendor_device.c"
39+
"${COMPONENT_DIR}/tinyusb/src/class/net/ncm_device.c"
3540
"${COMPONENT_DIR}/tinyusb/src/common/tusb_fifo.c"
3641
"${COMPONENT_DIR}/tinyusb/src/device/usbd_control.c"
3742
"${COMPONENT_DIR}/tinyusb/src/device/usbd.c"
@@ -56,16 +61,15 @@ if(CONFIG_TINYUSB_ENABLED)
5661

5762
set(requires esp_rom freertos soc)
5863
set(priv_requires arduino main)
59-
### tinyusb lib ###
60-
###################
61-
idf_component_register(INCLUDE_DIRS ${includes_public} PRIV_INCLUDE_DIRS ${includes_private} SRCS ${srcs} REQUIRES ${requires} PRIV_REQUIRES ${priv_requires})
62-
# add_library(${COMPONENT_TARGET} STATIC ${srcs})
63-
# target_include_directories(
64-
# ${COMPONENT_TARGET}
65-
# PUBLIC ${includes_public}
66-
# PRIVATE ${includes_private})
64+
65+
idf_component_register(
66+
INCLUDE_DIRS ${includes_public}
67+
PRIV_INCLUDE_DIRS ${includes_private}
68+
SRCS ${srcs}
69+
REQUIRES ${requires}
70+
PRIV_REQUIRES ${priv_requires}
71+
)
6772
target_compile_options(${COMPONENT_TARGET} PRIVATE ${compile_options})
68-
#target_link_libraries(${COMPONENT_TARGET} INTERFACE ${COMPONENT_TARGET})
6973

7074
else()
7175

Diff for: components/arduino_tinyusb/Kconfig.projbuild

+11
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,17 @@ menu "Arduino TinyUSB"
233233

234234
endmenu
235235

236+
menu "NCM driver"
237+
depends on TINYUSB_ENABLED
238+
239+
config TINYUSB_NCM_ENABLED
240+
bool "Enable USB NCM TinyUSB driver"
241+
default y
242+
help
243+
Enable USB NCM TinyUSB driver.
244+
245+
endmenu
246+
236247
config TINYUSB_DEBUG_LEVEL
237248
int "TinyUSB log level (0-3)"
238249
default 0

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

+5
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ extern "C" {
7272
# define CONFIG_TINYUSB_VENDOR_ENABLED 0
7373
#endif
7474

75+
#ifndef CONFIG_TINYUSB_NCM_ENABLED
76+
# define CONFIG_TINYUSB_NCM_ENABLED 0
77+
#endif
78+
7579
/* */
7680
/* COMMON CONFIGURATION */
7781
/* */
@@ -113,6 +117,7 @@ extern "C" {
113117
#define CFG_TUD_DFU_RUNTIME CONFIG_TINYUSB_DFU_RT_ENABLED
114118
#define CFG_TUD_DFU CONFIG_TINYUSB_DFU_ENABLED
115119
#define CFG_TUD_VENDOR CONFIG_TINYUSB_VENDOR_ENABLED
120+
#define CFG_TUD_NCM CONFIG_TINYUSB_NCM_ENABLED
116121

117122
// CDC FIFO size of TX and RX
118123
#define CFG_TUD_CDC_RX_BUFSIZE CONFIG_TINYUSB_CDC_RX_BUFSIZE

Diff for: patches/tinyusb_dcd_dwc2.diff renamed to components/arduino_tinyusb/patches/dcd_dwc2.patch

+26-28
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,81 @@
1-
--- a/components/arduino_tinyusb/tinyusb/src/portable/synopsys/dwc2/dcd_dwc2.c 2024-06-10 22:10:55.000000000 +0300
2-
+++ b/components/arduino_tinyusb/tinyusb/src/portable/synopsys/dwc2/dcd_dwc2.c 2024-06-10 22:20:01.000000000 +0300
3-
@@ -186,6 +186,18 @@
4-
return true;
5-
}
6-
7-
+#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
1+
--- a/components/arduino_tinyusb/src/dcd_dwc2.c 2024-10-02 12:17:40.000000000 +0300
2+
+++ b/components/arduino_tinyusb/src/dcd_dwc2.c 2024-10-02 12:19:48.000000000 +0300
3+
@@ -316,6 +316,16 @@
4+
//--------------------------------------------------------------------
5+
// Endpoint
6+
//--------------------------------------------------------------------
7+
+#if defined(TUP_USBIP_DWC2_ESP32)
88
+// Keep count of how many FIFOs are in use
99
+static uint8_t _allocated_fifos = 1; //FIFO0 is always in use
1010
+
1111
+// Will either return an unused FIFO number, or 0 if all are used.
12-
+static uint8_t get_free_fifo(void)
13-
+{
12+
+static uint8_t get_free_fifo(void) {
1413
+ if (_allocated_fifos < 5) return _allocated_fifos++;
1514
+ return 0;
1615
+}
1716
+#endif
18-
+
17+
1918
static void edpt_activate(uint8_t rhport, tusb_desc_endpoint_t const * p_endpoint_desc) {
2019
dwc2_regs_t* dwc2 = DWC2_REG(rhport);
21-
uint8_t const epnum = tu_edpt_number(p_endpoint_desc->bEndpointAddress);
22-
@@ -205,7 +217,18 @@
20+
@@ -336,7 +346,18 @@
2321
dwc2->epout[epnum].doepctl = dxepctl;
2422
dwc2->daintmsk |= TU_BIT(DAINTMSK_OEPM_Pos + epnum);
2523
} else {
2624
- dwc2->epin[epnum].diepctl = dxepctl | (epnum << DIEPCTL_TXFNUM_Pos);
2725
+ uint8_t fifo_num = epnum;
28-
+#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
26+
+#if defined(TUP_USBIP_DWC2_ESP32)
2927
+ // Special Case for EP5, which is used by CDC but not actually called by the driver
3028
+ // we can give it a fake FIFO
3129
+ if (epnum == 5) {
3230
+ fifo_num = epnum;
3331
+ } else {
3432
+ fifo_num = get_free_fifo();
3533
+ }
36-
+ TU_ASSERT(fifo_num != 0);
34+
+ //TU_ASSERT(fifo_num != 0);
3735
+#endif
3836
+ dwc2->epin[epnum].diepctl = dxepctl | (fifo_num << DIEPCTL_TXFNUM_Pos);
39-
dwc2->daintmsk |= (1 << (DAINTMSK_IEPM_Pos + epnum));
37+
dwc2->daintmsk |= TU_BIT(DAINTMSK_IEPM_Pos + epnum);
4038
}
4139
}
42-
@@ -728,6 +751,10 @@
43-
// reset allocated fifo IN
44-
_allocated_fifo_words_tx = 16;
40+
@@ -850,6 +871,10 @@
41+
xfer_status[n][TUSB_DIR_IN].max_size = 0;
42+
}
4543

46-
+#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
44+
+#if defined(TUP_USBIP_DWC2_ESP32)
4745
+ _allocated_fifos = 1;
4846
+#endif
4947
+
50-
fifo_flush_tx(dwc2, 0x10); // all tx fifo
51-
fifo_flush_rx(dwc2);
52-
}
53-
@@ -1096,6 +1123,9 @@
48+
dfifo_flush_tx(dwc2, 0x10); // all tx fifo
49+
dfifo_flush_rx(dwc2);
50+
51+
@@ -1204,6 +1229,9 @@
5452
if (int_status & GINTSTS_USBRST) {
5553
// USBRST is start of reset.
5654
dwc2->gintsts = GINTSTS_USBRST;
57-
+#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
55+
+#if defined(TUP_USBIP_DWC2_ESP32)
5856
+ _allocated_fifos = 1;
5957
+#endif
6058
bus_reset(rhport);
6159
}
6260

63-
@@ -1127,7 +1157,11 @@
61+
@@ -1235,7 +1263,11 @@
6462

6563
if (int_status & GINTSTS_USBSUSP) {
6664
dwc2->gintsts = GINTSTS_USBSUSP;
6765
- dcd_event_bus_signal(rhport, DCD_EVENT_SUSPEND, true);
6866
+ //dcd_event_bus_signal(rhport, DCD_EVENT_SUSPEND, true);
6967
+ dcd_event_bus_signal(rhport, DCD_EVENT_UNPLUGGED, true);
70-
+#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
68+
+#if defined(TUP_USBIP_DWC2_ESP32)
7169
+ _allocated_fifos = 1;
7270
+#endif
7371
}
7472

7573
if (int_status & GINTSTS_WKUINT) {
76-
@@ -1144,6 +1178,9 @@
74+
@@ -1252,6 +1284,9 @@
7775

7876
if (otg_int & GOTGINT_SEDET) {
7977
dcd_event_bus_signal(rhport, DCD_EVENT_UNPLUGGED, true);
80-
+#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
78+
+#if defined(TUP_USBIP_DWC2_ESP32)
8179
+ _allocated_fifos = 1;
8280
+#endif
8381
}

0 commit comments

Comments
 (0)