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