How to detect when CDC device is not busy using STM32 USB stack
Using the STM32 USB stack in a project for the STM32 CubeMX IDE on a STM32L062 processor, there are issues with trying to get the CDC device to send data back up to the host at maximum throughput. If CDC_Transmit_FS() is called twice in a row, then the first packet goes through but the second does not. If you look into the implementation of this function you come across the line
if (hcdc->TxState != 0) return USBD_BUSY;
However, if you do
while(CDC_Transmit_FS()==USBD_BUSY);
then the code never breaks out of this loop and no data ever gets to the host. What is the proper way to detect that the USB pipe is available for the device to transmit with ST's USB stack? So far the only way I can get multiple packets to arrive at the host is to do
CDC_Transmit_FS(); HAL_Delay(); CDC_Transmit_FS();
which is not the way this kind of code should be written and still doesn't guarantee me that all packets should be expected to arrive at the host.