forked from Jason2866/esp32-arduino-lib-builder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtinyusb_dcd_esp32sx.diff
119 lines (109 loc) · 4.52 KB
/
tinyusb_dcd_esp32sx.diff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
--- a/components/arduino_tinyusb/tinyusb/src/portable/espressif/esp32sx/dcd_esp32sx.c 2024-06-10 20:45:02.000000000 +0300
+++ b/components/arduino_tinyusb/tinyusb/src/portable/espressif/esp32sx/dcd_esp32sx.c 2024-06-10 22:25:05.000000000 +0300
@@ -282,6 +281,7 @@
xfer->interval = desc_edpt->bInterval;
if (dir == TUSB_DIR_OUT) {
+ out_ep[epnum].doepctl &= ~(USB_D_EPTYPE0_M | USB_D_MPS0_M);
out_ep[epnum].doepctl |= USB_USBACTEP1_M |
desc_edpt->bmAttributes.xfer << USB_EPTYPE1_S |
(desc_edpt->bmAttributes.xfer != TUSB_XFER_ISOCHRONOUS ? USB_DO_SETD0PID1_M : 0) |
@@ -311,7 +311,14 @@
// - Offset: GRXFSIZ + 16 + Size*(epnum-1)
// - IN EP 1 gets FIFO 1, IN EP "n" gets FIFO "n".
- uint8_t fifo_num = get_free_fifo();
+ uint8_t fifo_num = 0;
+ // Special Case for EP5, which is used by CDC but not actually called by the driver
+ // we can give it a fake FIFO
+ if (epnum == 5) {
+ fifo_num = EP_FIFO_NUM;
+ } else {
+ fifo_num = get_free_fifo();
+ }
TU_ASSERT(fifo_num != 0);
in_ep[epnum].diepctl &= ~(USB_D_TXFNUM1_M | USB_D_EPTYPE1_M | USB_DI_SETD0PID1 | USB_D_MPS1_M);
@@ -442,7 +449,8 @@
} else {
// Stop transmitting packets and NAK IN xfers.
in_ep[epnum].diepctl |= USB_DI_SNAK1_M;
- while ((in_ep[epnum].diepint & USB_DI_SNAK1_M) == 0) ;
+ // while ((in_ep[epnum].diepint & USB_DI_SNAK1_M) == 0) ;
+ while ((in_ep[epnum].diepint & USB_D_INEPNAKEFF1_M) == 0) ;
// Disable the endpoint. Note that both SNAK and STALL are set here.
in_ep[epnum].diepctl |= (USB_DI_SNAK1_M | USB_D_STALL1_M | USB_D_EPDIS1_M);
@@ -452,9 +460,16 @@
// Flush the FIFO, and wait until we have confirmed it cleared.
uint8_t const fifo_num = ((in_ep[epnum].diepctl >> USB_D_TXFNUM1_S) & USB_D_TXFNUM1_V);
- USB0.grstctl |= (fifo_num << USB_TXFNUM_S);
- USB0.grstctl |= USB_TXFFLSH_M;
+ // USB0.grstctl |= (fifo_num << USB_TXFNUM_S);
+ // USB0.grstctl |= USB_TXFFLSH_M;
+ // while ((USB0.grstctl & USB_TXFFLSH_M) != 0) ;
+ uint32_t rstctl_last = USB0.grstctl;
+ uint32_t rstctl = USB_TXFFLSH_M;
+ rstctl |= (fifo_num << USB_TXFNUM_S);
+ USB0.grstctl = rstctl;
while ((USB0.grstctl & USB_TXFFLSH_M) != 0) ;
+ USB0.grstctl = rstctl_last;
+ // TODO: Clear grstctl::fifo_num after fifo flsh
} else {
// Only disable currently enabled non-control endpoint
if ((epnum == 0) || !(out_ep[epnum].doepctl & USB_EPENA0_M)) {
@@ -730,11 +745,21 @@
if (USB0.daint & (1 << (0 + n))) {
ESP_EARLY_LOGV(TAG, "TUSB IRQ - EP IN %u", n);
+
+ if (USB0.in_ep_reg[n].diepint & BIT(15)) {
+ USB0.in_ep_reg[n].diepint = BIT(15);
+ ESP_EARLY_LOGE(TAG, "Unknown Condition");//todo:
+ bus_reset();
+ }
+
// IN XFER complete (entire xfer).
if (USB0.in_ep_reg[n].diepint & USB_D_XFERCOMPL0_M) {
ESP_EARLY_LOGV(TAG, "TUSB IRQ - IN XFER complete!");
USB0.in_ep_reg[n].diepint = USB_D_XFERCOMPL0_M;
dcd_event_xfer_complete(0, n | TUSB_DIR_IN_MASK, xfer->total_len, XFER_RESULT_SUCCESS, true);
+ if (!(USB0.in_ep_reg[n].diepint & USB_D_TXFEMP0_M)) {
+ ESP_EARLY_LOGE(TAG, "Complete but not empty: %u/%u", xfer->queued_len, xfer->total_len);//todo:
+ }
}
// XFER FIFO empty
@@ -754,6 +779,7 @@
if (USB0.in_ep_reg[n].diepint & USB_D_TIMEOUT0_M) {
// Clear interrupt or endpoint will hang.
USB0.in_ep_reg[n].diepint = USB_D_TIMEOUT0_M;
+ ESP_EARLY_LOGE(TAG, "XFER Timeout");//todo:
// Maybe retry?
}
}
@@ -781,8 +807,12 @@
if (int_status & USB_RESETDET_M) {
ESP_EARLY_LOGV(TAG, "dcd_int_handler - reset while suspend");
USB0.gintsts = USB_RESETDET_M;
- bus_reset();
- }
+ // no need to double reset
+ if ((int_status & USB_USBRST_M) == 0) {
+ _allocated_fifos = 1;
+ bus_reset();
+ }
+ }
if (int_status & USB_ENUMDONE_M) {
// ENUMDNE detects speed of the link. For full-speed, we
@@ -796,7 +826,9 @@
if(int_status & USB_USBSUSP_M)
{
USB0.gintsts = USB_USBSUSP_M;
- 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);
+ _allocated_fifos = 1;
}
if(int_status & USB_WKUPINT_M)
@@ -815,6 +847,7 @@
if (otg_int & USB_SESENDDET_M)
{
dcd_event_bus_signal(rhport, DCD_EVENT_UNPLUGGED, true);
+ _allocated_fifos = 1;
}
USB0.gotgint = otg_int;