aboutsummaryrefslogtreecommitdiffstats
path: root/src/stm32/usbotg.c
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2019-08-31 15:04:31 -0400
committerKevin O'Connor <kevin@koconnor.net>2019-08-31 15:16:46 -0400
commitc380d4639b61042e53e1c2b98c3f45105f55bbf0 (patch)
tree1f6c017d5319dee1beda184ed31b1516bbdf6cd0 /src/stm32/usbotg.c
parentf7f6680bf649e90be9453cb32c74f429827d570a (diff)
downloadkutter-c380d4639b61042e53e1c2b98c3f45105f55bbf0.tar.gz
kutter-c380d4639b61042e53e1c2b98c3f45105f55bbf0.tar.xz
kutter-c380d4639b61042e53e1c2b98c3f45105f55bbf0.zip
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 <kevin@koconnor.net>
Diffstat (limited to 'src/stm32/usbotg.c')
-rw-r--r--src/stm32/usbotg.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/stm32/usbotg.c b/src/stm32/usbotg.c
index c9a29a38..cf04ea5d 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);
}