AnsweredAssumed Answered

HAL USB odd/even issue for OUT endpoints

Question asked by shamaev.eugene on Jan 5, 2016
Latest reply on Jan 5, 2016 by shamaev.eugene
When preparing to receive the data on OUT isochronous endpoint, the HAL sets up the even/odd flag once when you call the PrepareReceive for that specific frame that is active at that moment.
However the data may come on other odd/even frame than was expected and thus the first transfer will be lost 50% of the time.
In the EOPF interrupt the odd/even flag needs to be updated for all active endpoints.
The EOPF should also be unmasked in init section as well.

This change to HAL_PCD_IRQHandler is working for me:

if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_EOPF))
          {
               /* End of frame */


             uint8_t i;
             for(i = 0; i < 16; i++)
             {
                    ep = &hpcd->OUT_ep[i];


                    // Check if there are enabled endpoints
                    if((USBx_OUTEP(ep->num)->DOEPCTL & USB_OTG_DOEPCTL_EPENA) == USB_OTG_DOEPCTL_EPENA)
                    {
                         if ((ep->type & EP_TYPE_ISOC) == EP_TYPE_ISOC)
                         {
                              if ((USBx_DEVICE->DSTS & ( 1 << 8 )) == 0)
                              {
                                   USBx_OUTEP(ep->num)->DOEPCTL |= USB_OTG_DOEPCTL_SODDFRM;
                              }
                              else
                              {
                                   USBx_OUTEP(ep->num)->DOEPCTL |= USB_OTG_DOEPCTL_SD0PID_SEVNFRM;
                              }
                         }
                    }
             }


               __HAL_PCD_CLEAR_FLAG(hpcd, USB_OTG_GINTSTS_EOPF);
          }

Outcomes