Skip to content

Commit

Permalink
stm32: Rework usbotg transmit interrupts
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
KevinOConnor committed Sep 8, 2019
1 parent ccb8db5 commit 4fa41d9
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/stm32/usbotg.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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();
}
}
}

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 4fa41d9

Please sign in to comment.