2019-12-25 04:34 AM
I'm running USB CDC in HS with STM32F405.
Receiving data from PC is very good.
But, sending data to PC has problem sometimes.
To send data, I'm using CDC_Transmit_HS ( *Buf, Len )
There is no error in the function at all. But, data is not sent to PC.
To see if there is any error in CDC_Transmit_HS ( ), I checked
the hierarchical calls in CDC_Transmit_HS ().
But, even when the data is not sent, there is no error inside at all.
- Is there any known issue or possible problem that I had made ?
- Is there any relationship between USB CDC IN functions and OUT functions ?
- EX: when OUT is disabled (by not sending USBD_CDC_ReceivePacket), IN with CDC_Transmit_HS doesn't work.
* Windows10 home
* Driver for USB CDC (from device manager) : System32/Drivers/usbser.sys MS 10.0.18362.1 2006-06-21
============================================================================
Added #1.
The problem occurs when MCU sends 512 x n bytes to the host.
After an internet searching for few hours, I found articles that zero-length-packet (ZLP) is required after sending the multiple of 512 in HS mode. (in FS, it would be 64Bytes)
So, I updated CDC_Transmit_HS caller function to send ZLP if ((Len%512)==0)
( When sending ZLP CDC_Transmit_HS, return value should be checked. USBD_BUSY can be returned.)
After updating, sending any bytes of data into PC works fine.
Is this an appropriate way to fix this ?
Thanks.
Solved! Go to Solution.
2019-12-26 01:23 AM
Yes, USB requires a ZLP if the last data packet in a sequence is exactly the maximum packet size for the endpoint. The end of the sequence is indicated by a short (less than max) size packet and zero works correctly.
Congratulations on finding this out after only a few hours of internet searching. It took me a lot longer than that.
I don't know what library you're using and if CDC_Transmit_HS function is part of it or from your own code. (Or if you modified CDC_Transmit_HS itself vs your calls to it). I know the ST library for the STM32F10xxx series before CubeMX generated the ZLP internally/automatically, and I'd be surprised if current CubeMX doesn't also.
2019-12-26 01:23 AM
Yes, USB requires a ZLP if the last data packet in a sequence is exactly the maximum packet size for the endpoint. The end of the sequence is indicated by a short (less than max) size packet and zero works correctly.
Congratulations on finding this out after only a few hours of internet searching. It took me a lot longer than that.
I don't know what library you're using and if CDC_Transmit_HS function is part of it or from your own code. (Or if you modified CDC_Transmit_HS itself vs your calls to it). I know the ST library for the STM32F10xxx series before CubeMX generated the ZLP internally/automatically, and I'd be surprised if current CubeMX doesn't also.