Skip to main content
DTeun
Associate II
November 12, 2018
Solved

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

  • November 12, 2018
  • 2 replies
  • 790 views

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

    This topic has been closed for replies.
    Best answer by Kraal

    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 ?

    2 replies

    KraalBest answer
    Senior III
    November 12, 2018

    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
    DTeunAuthor
    Associate II
    November 12, 2018

    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