From c380d4639b61042e53e1c2b98c3f45105f55bbf0 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Sat, 31 Aug 2019 15:04:31 -0400 Subject: [PATCH] stm32: Work around stm32f407 usbotg chip errata It appears bogus entries can get placed on the rxqueue - detect and clear them. Signed-off-by: Kevin O'Connor --- src/stm32/usbotg.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/stm32/usbotg.c b/src/stm32/usbotg.c index c9a29a387..cf04ea5de 100644 --- a/src/stm32/usbotg.c +++ b/src/stm32/usbotg.c @@ -124,15 +124,22 @@ peek_rx_queue(uint32_t ep) if (!(sts & USB_OTG_GINTSTS_RXFLVL)) // No packet ready return 0; - uint32_t grx = OTG->GRXSTSR; + uint32_t grx = OTG->GRXSTSR, grx_ep = grx & USB_OTG_GRXSTSP_EPNUM_Msk; uint32_t pktsts = ((grx & USB_OTG_GRXSTSP_PKTSTS_Msk) >> USB_OTG_GRXSTSP_PKTSTS_Pos); - if (pktsts != 1 && pktsts != 3 && pktsts != 4) { + if ((grx_ep == 0 || grx_ep == USB_CDC_EP_BULK_OUT) + && (pktsts == 2 || pktsts == 6)) { // A packet is ready - if ((grx & USB_OTG_GRXSTSP_EPNUM_Msk) != ep) + if (grx_ep != ep) return 0; return grx; } + if ((grx_ep != 0 && grx_ep != USB_CDC_EP_BULK_OUT) + || (pktsts != 1 && pktsts != 3 && pktsts != 4)) { + // Rx queue has bogus value - just pop it + sts = OTG->GRXSTSP; + continue; + } // Discard informational entries from queue fifo_read_packet(NULL, 0); }