2024-08-19 09:33 AM - edited 2024-08-19 09:54 AM
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?