Skip to content

Commit 126f0b5

Browse files
authored
Create tinyusb_dcd_dwc2.diff
1 parent 9a97b17 commit 126f0b5

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed

patches/tinyusb_dcd_dwc2.diff

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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)
8+
+// Keep count of how many FIFOs are in use
9+
+static uint8_t _allocated_fifos = 1; //FIFO0 is always in use
10+
+
11+
+// Will either return an unused FIFO number, or 0 if all are used.
12+
+static uint8_t get_free_fifo(void)
13+
+{
14+
+ if (_allocated_fifos < 5) return _allocated_fifos++;
15+
+ return 0;
16+
+}
17+
+#endif
18+
+
19+
static void edpt_activate(uint8_t rhport, tusb_desc_endpoint_t const * p_endpoint_desc) {
20+
dwc2_regs_t* dwc2 = DWC2_REG(rhport);
21+
uint8_t const epnum = tu_edpt_number(p_endpoint_desc->bEndpointAddress);
22+
@@ -205,7 +217,18 @@
23+
dwc2->epout[epnum].doepctl = dxepctl;
24+
dwc2->daintmsk |= TU_BIT(DAINTMSK_OEPM_Pos + epnum);
25+
} else {
26+
- dwc2->epin[epnum].diepctl = dxepctl | (epnum << DIEPCTL_TXFNUM_Pos);
27+
+ uint8_t fifo_num = epnum;
28+
+#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
29+
+ // Special Case for EP5, which is used by CDC but not actually called by the driver
30+
+ // we can give it a fake FIFO
31+
+ if (epnum == 5) {
32+
+ fifo_num = epnum;
33+
+ } else {
34+
+ fifo_num = get_free_fifo();
35+
+ }
36+
+ TU_ASSERT(fifo_num != 0);
37+
+#endif
38+
+ dwc2->epin[epnum].diepctl = dxepctl | (fifo_num << DIEPCTL_TXFNUM_Pos);
39+
dwc2->daintmsk |= (1 << (DAINTMSK_IEPM_Pos + epnum));
40+
}
41+
}
42+
@@ -728,6 +751,10 @@
43+
// reset allocated fifo IN
44+
_allocated_fifo_words_tx = 16;
45+
46+
+#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
47+
+ _allocated_fifos = 1;
48+
+#endif
49+
+
50+
fifo_flush_tx(dwc2, 0x10); // all tx fifo
51+
fifo_flush_rx(dwc2);
52+
}
53+
@@ -1096,6 +1123,9 @@
54+
if (int_status & GINTSTS_USBRST) {
55+
// USBRST is start of reset.
56+
dwc2->gintsts = GINTSTS_USBRST;
57+
+#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
58+
+ _allocated_fifos = 1;
59+
+#endif
60+
bus_reset(rhport);
61+
}
62+
63+
@@ -1127,7 +1157,11 @@
64+
65+
if (int_status & GINTSTS_USBSUSP) {
66+
dwc2->gintsts = GINTSTS_USBSUSP;
67+
- dcd_event_bus_signal(rhport, DCD_EVENT_SUSPEND, true);
68+
+ //dcd_event_bus_signal(rhport, DCD_EVENT_SUSPEND, true);
69+
+ dcd_event_bus_signal(rhport, DCD_EVENT_UNPLUGGED, true);
70+
+#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
71+
+ _allocated_fifos = 1;
72+
+#endif
73+
}
74+
75+
if (int_status & GINTSTS_WKUINT) {
76+
@@ -1144,6 +1178,9 @@
77+
78+
if (otg_int & GOTGINT_SEDET) {
79+
dcd_event_bus_signal(rhport, DCD_EVENT_UNPLUGGED, true);
80+
+#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
81+
+ _allocated_fifos = 1;
82+
+#endif
83+
}
84+
85+
dwc2->gotgint = otg_int;

0 commit comments

Comments
 (0)