On investigating the use of the USB device drivers provided for the STM32Lx series chips (CDC) I found an issue when trying to transfer a packet to the PC which is an exact multiple of 64 bytes. In such a case the data is not transferred as desired because the low level USB driver decides that it can send the 64 bytes in a single packet, which does not work.
The behaviour that I observed is described in the post here: STM32 USB Library
- CubeMX version 4.18.0
- STM32L4 Firmware version 1.6.0
- SW4STM32 (AC6)
- Tera Term
If I send more that 64 bytes the driver code correctly splits this into more packets, which works fine as long as is not a multiple of 64 and that there is an empty byte for the PC side to pick up on. Specifically this is done on line.559 of stm32l4xx_ll_usb.c:
USBx_INEP(ep->num)->DIEPTSIZ |= (USB_OTG_DIEPTSIZ_PKTCNT & (((ep->xfer_len + ep->maxpacket -1)/ ep->maxpacket) << 19)) ;
My question is, should the driver code not check to see if the transfer size is an exact multiple of 64, then handle this accordingly? If not, is there a reason why?