diff options
| author | Peter Lawrence <[email protected]> | 2020-01-15 21:40:24 -0600 |
|---|---|---|
| committer | Peter Lawrence <[email protected]> | 2020-01-15 21:40:24 -0600 |
| commit | 2ed395bde313ad7d2591dc23c686469d16884e79 (patch) | |
| tree | 591b9bc5d62a3d77104b3fe71f4ea7b0c72103a1 /src | |
| parent | f28fad7bbfd85238d7bd10a9a24e7d8d9fe4bbc2 (diff) | |
nuc121: survive USB bus reset
Diffstat (limited to 'src')
| -rw-r--r-- | src/portable/nuvoton/nuc121/dcd_nuc121.c | 61 |
1 files changed, 33 insertions, 28 deletions
diff --git a/src/portable/nuvoton/nuc121/dcd_nuc121.c b/src/portable/nuvoton/nuc121/dcd_nuc121.c index 71211af0c..9c0cefd74 100644 --- a/src/portable/nuvoton/nuc121/dcd_nuc121.c +++ b/src/portable/nuvoton/nuc121/dcd_nuc121.c @@ -148,30 +148,15 @@ static void dcd_in_xfer(struct xfer_ctl_t *xfer, USBD_EP_T *ep) ep->MXPLD = bytes_now;
}
-/* centralized location for USBD interrupt enable bit mask */
-static const uint32_t enabled_irqs = USBD_INTSTS_VBDETIF_Msk | USBD_INTSTS_BUSIF_Msk | USBD_INTSTS_SETUP_Msk | USBD_INTSTS_USBIF_Msk | USBD_INTSTS_SOFIF_Msk;
-
-/*
- NUC121/NUC125/NUC126 TinyUSB API driver implementation
-*/
-
-void dcd_init(uint8_t rhport)
+/* called by dcd_init() as well as by the ISR during a USB bus reset */
+static void bus_reset(void)
{
- (void) rhport;
-
-#ifdef SUPPORT_LPM
- USBD->ATTR = 0x7D0 | USBD_LPMACK;
-#else
- USBD->ATTR = 0x7D0;
-#endif
-
- usb_detach();
-
USBD->STBUFSEG = PERIPH_SETUP_BUF_BASE;
for (enum ep_enum ep_index = PERIPH_EP0; ep_index < PERIPH_MAX_EP; ep_index++)
{
- USBD->EP[ep_index].CFGP &= ~USBD_CFG_STATE_Msk;
+ USBD->EP[ep_index].CFG = 0;
+ USBD->EP[ep_index].CFGP = 0;
}
/* allocate the default EP0 endpoints */
@@ -187,6 +172,34 @@ void dcd_init(uint8_t rhport) /* USB RAM beyond what we've allocated above is available to the user */
bufseg_addr = PERIPH_EP2_BUF_BASE;
+ /* Reset USB device address */
+ USBD->FADDR = 0;
+
+ /* reset EP0_IN flag */
+ active_ep0_xfer = false;
+}
+
+/* centralized location for USBD interrupt enable bit mask */
+static const uint32_t enabled_irqs = USBD_INTSTS_VBDETIF_Msk | USBD_INTSTS_BUSIF_Msk | USBD_INTSTS_SETUP_Msk | USBD_INTSTS_USBIF_Msk | USBD_INTSTS_SOFIF_Msk;
+
+/*
+ NUC121/NUC125/NUC126 TinyUSB API driver implementation
+*/
+
+void dcd_init(uint8_t rhport)
+{
+ (void) rhport;
+
+#ifdef SUPPORT_LPM
+ USBD->ATTR = 0x7D0 | USBD_LPMACK;
+#else
+ USBD->ATTR = 0x7D0;
+#endif
+
+ usb_detach();
+
+ bus_reset();
+
usb_attach();
USBD->INTSTS = enabled_irqs;
@@ -329,15 +342,7 @@ void USBD_IRQHandler(void) /* USB bus reset */
USBD->ATTR |= USBD_ATTR_USBEN_Msk | USBD_ATTR_PHYEN_Msk;
- /* Reset all endpoints to DATA0 */
- for(enum ep_enum ep_index = PERIPH_EP0; ep_index < PERIPH_MAX_EP; ep_index++)
- USBD->EP[ep_index].CFG &= ~USBD_CFG_DSQSYNC_Msk;
-
- /* Reset USB device address */
- USBD->FADDR = 0;
-
- /* reset EP0_IN flag */
- active_ep0_xfer = false;
+ bus_reset();
dcd_event_bus_signal(0, DCD_EVENT_BUS_RESET, true);
}
|
