cancel
Showing results for 
Search instead for 
Did you mean: 

Receiving multiple usb isochronous packets in one SOF (USB Audio): wrong handling in the USB HAL library

krezo107
Associate II

I am making a sound card using stm32h750 and usb3300 PHY for high-speed USB. In some USB ports everything works fine, but on linux and "bad" usb ports with something else plugged into the hub it seems like I am receiving multiple packets in one SOF.

So, I am trying to receive more than one packet at a time. USBD_LL_PrepareReceive calls USBD_LL_PrepareReceive, which in turn calls HAL_PCD_EP_Receive, which calls USB_EPStartXfer in the end. In USB_EPStartXfer, certain line suggests that multiple packets, in fact, can be received at once in the buffer:

 

 

 

      pktcnt = (uint16_t)((ep->xfer_len + ep->maxpacket - 1U) / ep->maxpacket);
      USBx_OUTEP(epnum)->DOEPTSIZ |= USB_OTG_DOEPTSIZ_PKTCNT & ((uint32_t)pktcnt << 19);
      USBx_OUTEP(epnum)->DOEPTSIZ |= USB_OTG_DOEPTSIZ_XFRSIZ & (ep->maxpacket * pktcnt);

 

 

 

Where xfer_len is the reception buffer length. This suggests that multiple packet can, in fact, be received, but then in PCD_EP_OutXfrComplete_int, which is called when data arrives, we see

 

 

 

        hpcd->OUT_ep[epnum].xfer_count =
          hpcd->OUT_ep[epnum].maxpacket -
          (USBx_OUTEP(epnum)->DOEPTSIZ & USB_OTG_DOEPTSIZ_XFRSIZ);

 

 

 

In case if multiple packets are received, xfer_count is negative (it flips around to ~2^32). Shouldn't it be xfer_len (the expected length) instead of maxpacket?

Are there other considerations to such a reception?

0 REPLIES 0