I have a simple test application for an STM32L4 microcontroller. It uses the code for the virtual COM port provided by STM32CubeMX. It does the following in an endless loop:
- wait until TxState in (USBD_CDC_HandleTypeDef*)hUsbDeviceFS.pClassData is zero
- generate random string
- call USBD_CDC_SetTxBuffer
- call USBD_CDC_TransmitPacket
The data sent is a randomly generated string, which includes a terminating newline character.
On the PC (Windows), a python script reads the data, line by line, and checks the links for consistency.
Turns out, that if the python script reads fast enough, data is consistent. However, if the python script sleeps randomly (with 5% probability) for 100ms before reading a line, then data is inconsistent. In that case, the microcontroller sends faster than the PC is reading the data.
The obvious conclusion seems to be, that the USB driver code doesn't re-transmit data. However, when the PC does not send an ACK in response to a bulk data packet, then the USB peripheral must re-transmit the data when the host asks for the next data packet.
Anyhow, USB has built-in flow control. There should not be any data loss here.
Can somebody point me to the location in the CubeMX's USB code that handles the re-transmission of bulk data? I can't seem to find it.
My project, unfortunately, is still based on STM32L4 package version 1.8.1. I switched a test project to 1.12.0, but then the virtual COM port won't work on Windows anymore. I cannot open the COM port. The same issue was reported here recently by another person.
Is there ChaneLog for the STM32L4 packages, so I can study what was changed between 1.8.1 and 1.12.0?