cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L4 USB CDC (VCP) Max packet transfer

Ant M
Associate II
Posted on January 26, 2017 at 11:29

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:

http://electronics.stackexchange.com/questions/170572/stm32-usb-library-transmit-fails-with-specific-data-lengths

My setup:

  • STM32L476G-DISCO
  • 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?

Best Regards,

Anthony

#stm32l4 #vcp #usb-cdc #max-packet #usb-cdc-max-packet
2 REPLIES 2
Ant M
Associate II
Posted on October 27, 2017 at 15:54

To add to this, discovered a document which details this:

https://blog.brichacek.net/wp-content/uploads/2015/10/STM32F4-and-USB.pdf

 

Ant

Jim Kaz
Associate II
Posted on November 07, 2017 at 18:07

I'm having the exact same problem on an L496 using the 1.8 framework. 

Looking back in the source control commits, I fixed this exact same error two years on an L1 processor using the 1.4 framework but using a less than ideal workaround at the layer above the HAL.

This issue seems like a glaring oversight, Anthony and I can't be the only ones that have been bitten by this.