cancel
Showing results for 
Search instead for 
Did you mean: 

Possible bug in STM32L4S9 USB CDC, transmitting 832 bytes does not work properly

DTeun
Associate II

I am using a STM32L4S9 microcontroller and used CubeMX (L4 V1.13.0 Firmware) to generate code for the USB to communicate with the device as a serial port.

When sending an exact amount of bytes, 832 to be precise, the data is not send through to the PC. When using less, 831, or more, 833, the data is send immediately. It also gets send when i send another transaction over the USB. No data is lost when this happens, but when waiting for the data to appear in the terminal it can be very frustrating.

I could not find any reference to this exact number of bytes. Perhaps this is an oversight on my part, but is there a reason why the data is not send through?

Thanks in advance.

Best regards,

Danny

1 ACCEPTED SOLUTION

Accepted Solutions
Kraal
Senior III

Hi there,

First thing I notice is that 832 equals 13 times 64 bytes. I am no expert in USB but I believe that you need to send a zero length packet (ZLP) in such cases where the number of bytes to send equals the size of the endpoint. Does the same behaviour show up with a stream of 64 bytes ?

View solution in original post

2 REPLIES 2
Kraal
Senior III

Hi there,

First thing I notice is that 832 equals 13 times 64 bytes. I am no expert in USB but I believe that you need to send a zero length packet (ZLP) in such cases where the number of bytes to send equals the size of the endpoint. Does the same behaviour show up with a stream of 64 bytes ?

DTeun
Associate II

Hi Kraal,

I did not notice the 13 x 64, thanks for pointing this out, thought it was a strange/random number.

I tried the same thing with 64 bytes and it does behave the same way.

Also when you mention zero length packet, it triggered me to search for this and found the reason why this behavior is there. The USB is not sending the data because the data could be incomplete, so it needs to know the data is complete. More information is explained here: https://stackoverflow.com/a/48982843

Thanks allot!

Best regards,

Danny