STM32U5[Ax] Usb Host Multi-Packet Data Toggling
Hi all,
I am not able to fully understand how the DATA0/DATA1 toggling works when performing multi-packets transmissions.
For "multi-packet" transmission I mean that the "num_packets" in USB_OTG_HCTSIZ_PKTCNT register is greater than 1, (i.e. I want to send 2x512 OUT packets on a bulk endpoint])
[stm32u5xx_ll_usb.c - l.1941]
USBx_HC(ch_num)->HCTSIZ = (hc->XferSize & USB_OTG_HCTSIZ_XFRSIZ) |
(((uint32_t)num_packets << 19) & USB_OTG_HCTSIZ_PKTCNT) |
(((uint32_t)hc->data_pid << 29) & USB_OTG_HCTSIZ_DPID);
In this case, is the data0/data1 toggling between the two sent packets, performed by the HW?
If this is true,
I think that a bug in the HAL exist when num_packets is even, since the negation of the data_toggle attribute in the HCD_HC_OUT_IRQHandler is performed only on the XFRC event (which is triggered when PKTCNT reaches zero).
In this case the next submitted request starts with a wrong DATA0/DATA1 PID, not taking into account the fact that the hardware performed an additional toggling.
Actually, after moving the following lines of HCD_HC_OUT_IRQHandler
if (hhcd->Init.dma_enable == 0U && !hhcd->hc[chnum].do_ping)
{
hhcd->hc[chnum].toggle_out ^= 1U;
}
from the following condition
else if (__HAL_HCD_GET_CH_FLAG(hhcd, chnum, USB_OTG_HCINT_XFRC))
to this one
else if (__HAL_HCD_GET_CH_FLAG(hhcd, chnum, USB_OTG_HCINT_ACK))
allowed me to properly perform an acked multi-packet transmission, but I am not absolutely sure if this is correct, since I do not own an USB Protocol analyzer.
Does this should be applied also in the HCD_HC_IN_IRQHandler ?
@TDJ Many thanks for collecting a lot of really bad bugs of this library, I think that you could be interested in this.
Someone from ST can help me?
