Skip to content

Commit

Permalink
Update TinyUSB DCD
Browse files Browse the repository at this point in the history
  • Loading branch information
me-no-dev committed Nov 18, 2024
1 parent 94d6ca7 commit 8bcf3eb
Show file tree
Hide file tree
Showing 2 changed files with 402 additions and 377 deletions.
41 changes: 20 additions & 21 deletions components/arduino_tinyusb/patches/dcd_dwc2.patch
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
--- a/components/arduino_tinyusb/src/dcd_dwc2.c 2024-10-02 12:17:40.000000000 +0300
+++ b/components/arduino_tinyusb/src/dcd_dwc2.c 2024-10-02 12:19:48.000000000 +0300
@@ -209,6 +209,17 @@
@@ -215,6 +215,17 @@
//--------------------------------------------------------------------
// Endpoint
//--------------------------------------------------------------------
Expand All @@ -17,13 +17,13 @@
+
static void edpt_activate(uint8_t rhport, tusb_desc_endpoint_t const * p_endpoint_desc) {
dwc2_regs_t* dwc2 = DWC2_REG(rhport);
uint8_t const epnum = tu_edpt_number(p_endpoint_desc->bEndpointAddress);
@@ -224,7 +235,19 @@
(p_endpoint_desc->bmAttributes.xfer != TUSB_XFER_ISOCHRONOUS ? DOEPCTL_SD0PID_SEVNFRM : 0) |
(xfer->max_size << DOEPCTL_MPSIZ_Pos);
const uint8_t epnum = tu_edpt_number(p_endpoint_desc->bEndpointAddress);
@@ -238,7 +249,18 @@
depctl.bm.set_data0_iso_even = 1;
}
if (dir == TUSB_DIR_IN) {
- epctl |= (epnum << DIEPCTL_TXFNUM_Pos);
+ //epctl |= (epnum << DIEPCTL_TXFNUM_Pos);
- depctl.bm.tx_fifo_num = epnum;
+ //depctl.bm.tx_fifo_num = epnum;
+ uint8_t fifo_num = epnum;
+#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
+ // Special Case for EP5, which is used by CDC but not actually called by the driver
Expand All @@ -33,13 +33,12 @@
+ } else {
+ fifo_num = get_free_fifo();
+ }
+ //TU_ASSERT(fifo_num != 0);
+#endif
+ epctl |= (fifo_num << DIEPCTL_TXFNUM_Pos);
+ depctl.bm.tx_fifo_num = fifo_num;
}

dwc2_dep_t* dep = &dwc2->ep[1 - dir][epnum];
@@ -304,6 +327,10 @@
dwc2_dep_t* dep = &dwc2->ep[dir == TUSB_DIR_IN ? 0 : 1][epnum];
@@ -523,6 +545,10 @@
}
}

Expand All @@ -50,35 +49,35 @@
dfifo_flush_tx(dwc2, 0x10); // all tx fifo
dfifo_flush_rx(dwc2);

@@ -908,6 +935,9 @@
if (int_status & GINTSTS_USBRST) {
@@ -959,6 +985,9 @@
if (gintsts & GINTSTS_USBRST) {
// USBRST is start of reset.
dwc2->gintsts = GINTSTS_USBRST;
+#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
+ _allocated_fifos = 1;
+ allocated_fifos = 1;
+#endif
bus_reset(rhport);
handle_bus_reset(rhport);
}

@@ -939,7 +969,11 @@
@@ -970,7 +999,11 @@

if (int_status & GINTSTS_USBSUSP) {
if (gintsts & GINTSTS_USBSUSP) {
dwc2->gintsts = GINTSTS_USBSUSP;
- dcd_event_bus_signal(rhport, DCD_EVENT_SUSPEND, true);
+ //dcd_event_bus_signal(rhport, DCD_EVENT_SUSPEND, true);
+ dcd_event_bus_signal(rhport, DCD_EVENT_UNPLUGGED, true);
+#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
+ _allocated_fifos = 1;
+ allocated_fifos = 1;
+#endif
}

if (int_status & GINTSTS_WKUINT) {
@@ -956,6 +990,9 @@
if (gintsts & GINTSTS_WKUINT) {
@@ -987,6 +1020,9 @@

if (otg_int & GOTGINT_SEDET) {
dcd_event_bus_signal(rhport, DCD_EVENT_UNPLUGGED, true);
+#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
+ _allocated_fifos = 1;
+ allocated_fifos = 1;
+#endif
}

Expand Down
Loading

0 comments on commit 8bcf3eb

Please sign in to comment.