diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2019-09-07 16:07:54 -0400 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2019-09-08 00:07:16 -0400 |
commit | 4fa41d9c6165ec4ac18e1c5ce54e59c00079ea1a (patch) | |
tree | 3839a91bce5b09ce714f0c59bc1b16f9f6c041a2 /src | |
parent | ccb8db5ea17387601e6e22d7aed00c73b45f5b94 (diff) | |
download | kutter-4fa41d9c6165ec4ac18e1c5ce54e59c00079ea1a.tar.gz kutter-4fa41d9c6165ec4ac18e1c5ce54e59c00079ea1a.tar.xz kutter-4fa41d9c6165ec4ac18e1c5ce54e59c00079ea1a.zip |
stm32: Rework usbotg transmit interrupts
Use the XFRC interrupt instead of TXFE. Don't mask/unmask the tx
interrupts during runtime. This fixes some race conditions where a tx
notification may have previously gotten lost.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'src')
-rw-r--r-- | src/stm32/usbotg.c | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/src/stm32/usbotg.c b/src/stm32/usbotg.c index cf04ea5d..bf8513dc 100644 --- a/src/stm32/usbotg.c +++ b/src/stm32/usbotg.c @@ -169,11 +169,9 @@ usb_send_bulk_in(void *data, uint_fast8_t len) if (!(ctl & USB_OTG_DIEPCTL_USBAEP)) // Controller not enabled - discard data return len; - if (ctl & USB_OTG_DIEPCTL_EPENA) { + if (ctl & USB_OTG_DIEPCTL_EPENA) // Wait for space to transmit - OTGD->DIEPEMPMSK |= (1 << USB_CDC_EP_BULK_IN); return -1; - } return fifo_write_packet(USB_CDC_EP_BULK_IN, data, len); } @@ -235,7 +233,6 @@ usb_send_ep0(const void *data, uint_fast8_t len) } if (EPIN(0)->DIEPCTL & USB_OTG_DIEPCTL_EPENA) { // Wait for space to transmit - OTGD->DIEPEMPMSK |= (1 << 0); OTG->GINTMSK |= USB_OTG_GINTMSK_RXFLVLM; return -1; } @@ -323,11 +320,16 @@ OTG_FS_IRQHandler(void) if (sts & USB_OTG_GINTSTS_IEPINT) { // Can transmit data - disable irq and notify endpoint uint32_t daint = OTGD->DAINT; - OTGD->DIEPEMPMSK &= ~daint; - if (daint & (1 << 0)) + if (daint & (1 << 0)) { + USB_OTG_INEndpointTypeDef *epi = EPIN(0); + epi->DIEPINT = epi->DIEPINT; usb_notify_ep0(); - if (daint & (1 << USB_CDC_EP_BULK_IN)) + } + if (daint & (1 << USB_CDC_EP_BULK_IN)) { + USB_OTG_INEndpointTypeDef *epi = EPIN(USB_CDC_EP_BULK_IN); + epi->DIEPINT = epi->DIEPINT; usb_notify_bulk_in(); + } } } @@ -370,6 +372,7 @@ usb_init(void) // Enable interrupts OTGD->DAINTMSK = (1 << 0) | (1 << USB_CDC_EP_BULK_IN); + OTGD->DIEPMSK = USB_OTG_DIEPMSK_XFRCM; OTG->GINTMSK = USB_OTG_GINTMSK_RXFLVLM | USB_OTG_GINTMSK_IEPINT; OTG->GAHBCFG = USB_OTG_GAHBCFG_GINT; armcm_enable_irq(OTG_FS_IRQHandler, OTG_FS_IRQn, 1); |