From 242f9b524a4d7e4ccd900a6fe7125cd71b73801a Mon Sep 17 00:00:00 2001 From: Koen Zandberg Date: Mon, 17 Apr 2023 15:40:15 +0200 Subject: [PATCH] drivers/usbdev_synopsys_dwc2: Set even/odd flag on isochronous transfers --- .../usbdev_synopsys_dwc2/usbdev_synopsys_dwc2.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/usbdev_synopsys_dwc2/usbdev_synopsys_dwc2.c b/drivers/usbdev_synopsys_dwc2/usbdev_synopsys_dwc2.c index 8bfc4338e3..4b1b31497b 100644 --- a/drivers/usbdev_synopsys_dwc2/usbdev_synopsys_dwc2.c +++ b/drivers/usbdev_synopsys_dwc2/usbdev_synopsys_dwc2.c @@ -1338,7 +1338,14 @@ static int _usbdev_ep_xmit(usbdev_ep_t *ep, uint8_t *buf, size_t len) _device_regs(conf)->DAINTMSK |= 1 << ep->num; _device_regs(conf)->DIEPEMPMSK |= 1 << ep->num; + uint32_t eonum = 0; + if (ep->type == USB_EP_TYPE_ISOCHRONOUS) { + bool odd_frame = _device_regs(conf)->DSTS & (1 << 8); + eonum = !odd_frame ? USB_OTG_DIEPCTL_SD0PID_SEVNFRM : USB_OTG_DIEPCTL_SODDFRM; + } + _in_regs(conf, ep->num)->DIEPCTL |= USB_OTG_DIEPCTL_CNAK | + eonum | USB_OTG_DIEPCTL_EPENA; if (len > 0 && !_uses_dma(conf)) { @@ -1355,11 +1362,17 @@ static int _usbdev_ep_xmit(usbdev_ep_t *ep, uint8_t *buf, size_t len) } } else { + /* Abort when the endpoint is not active, prevents hangs, * could be an assert in the future maybe */ if (!(_out_regs(conf, ep->num)->DOEPCTL & USB_OTG_DOEPCTL_USBAEP)) { return -1; } + uint32_t eonum = 0; + if (ep->type == USB_EP_TYPE_ISOCHRONOUS) { + bool odd_frame = _device_regs(conf)->DSTS & (1 << 8); + eonum = odd_frame ? USB_OTG_DOEPCTL_SD0PID_SEVNFRM : USB_OTG_DOEPCTL_SODDFRM; + } if (_uses_dma(conf)) { _out_regs(conf, ep->num)->DOEPDMA = (uint32_t)(intptr_t)buf; @@ -1382,6 +1395,7 @@ static int _usbdev_ep_xmit(usbdev_ep_t *ep, uint8_t *buf, size_t len) _out_regs(conf, ep->num)->DOEPTSIZ = doeptsiz; _out_regs(conf, ep->num)->DOEPCTL |= USB_OTG_DOEPCTL_CNAK | USB_OTG_DOEPCTL_EPENA | + eonum | _type_to_reg(ep->type); }