From 17e418bce4ae25a009b283d5475bec85ad1650ac Mon Sep 17 00:00:00 2001 From: "William D. Jones" Date: Wed, 23 Jan 2019 00:44:55 -0500 Subject: [PATCH] stm32f4: Fix incorrect xfer length for short packet IN xfers. --- src/portable/stm/stm32f4/dcd_stm32f4.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/portable/stm/stm32f4/dcd_stm32f4.c b/src/portable/stm/stm32f4/dcd_stm32f4.c index b2d308d7..4adb52a7 100644 --- a/src/portable/stm/stm32f4/dcd_stm32f4.c +++ b/src/portable/stm/stm32f4/dcd_stm32f4.c @@ -488,7 +488,8 @@ void OTG_FS_IRQHandler(void) { uint16_t remaining = (in_ep[n].DIEPTSIZ & USB_OTG_DIEPTSIZ_XFRSIZ_Msk) >> USB_OTG_DIEPTSIZ_XFRSIZ_Pos; xfer->queued_len = xfer->total_len - remaining; - for(uint8_t i = 0; i < xfer->max_size; i++) { + uint16_t to_xfer_size = (remaining > xfer->max_size) ? xfer->max_size : remaining; + for(uint16_t i = 0; i < to_xfer_size; i++) { (* tx_fifo) = xfer->buffer[xfer->queued_len + i]; } }