USB buffer overflow on clear stall operation #9
Labels
bug
Something isn't working
hal
HAL-LL driver-related issue or pull-request.
internal bug tracker
Issue confirmed and logged into the internal bug tracking system
pcd
USB Peripheral Control Driver
usb
Universal Serial Bus
Inside
stm32f0xx_hal_pcd.c
, on normal operation, when the receive buffer is not full, the receive callbackCDC_Receive_FS
callsUSBD_CDC_ReceivePacket
, which re-arms the endpoint to receive new data and setsep->xfer_count
to zero.In the case of a full buffer, the host may reach a timeout and request a Clear Stall.
USBD_LL_ClearStallEP
will callHAL_PCD_EP_ClrStall
to re-arm the endpoint WITHOUT resettingep->xfer_count
, which will cause a buffer overflow when receiving the next packet.IMHO,
HAL_PCD_EP_ClrStall()
should include anep->xfer_count = 0
. The tricky part: the host can send Clear Stalls at any time, even when the buffer isn't full and the device isn't Stalled, in this case the buffer index shouldn't be cleared.So maybe the solution is something like that:
The text was updated successfully, but these errors were encountered: