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 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.
Asked
Active
Viewed 559 times
1

Christopher Theriault
- 113
- 2
- 9
-
`while(CDC_Transmit_FS()==USBD_BUSY);` should work unless you call it in an interrupt handler. The CDC transmit state is also updated in an interrupt handler. – Codo Oct 28 '22 at 07:52
-
@David Grayson I don't see where the USB stack is available from ST as a separate download. If you have access to their Cube IDE you can make any project with USB enabled and see the implementation of these functions. There are no examples of this code being used online I can find where anyone does anything but call the transmit function, for the simplest, see https://stackoverflow.com/questions/44256745/stm32-usb-cdc-did-not-work. @Codo it does not matter where you call the transmit function, ```while(CDC_Transmit_FS()==USBD_BUSY);``` never exits when placed in the main body of the code. – Christopher Theriault Oct 28 '22 at 14:04