USB CDC communication problem with Windows/Ubuntu default drivers

Report here problems in any of ChibiOS components. This forum is NOT for support.
User avatar
Eliot Ferragni
Posts: 1
Joined: Fri May 03, 2019 7:51 am

USB CDC communication problem with Windows/Ubuntu default drivers

Postby Eliot Ferragni » Mon May 06, 2019 8:53 am


First of all, it's not really a bug since the OTGv1 driver of ChibiOS does what it should.
The problem is that I discovered at least Windows 7/10 and Ubuntu 16.04 don't appear to follow correctly the USB bulk transmission protocol while working on our implementation of an onboard programmer for the e-puck2 educational robot made by us at the EPFL.
It took me some time to understand why my communications were not working in some specific cases. After catching the USB frames with Wireshark and a physical USB analyser I found out they (windows and Ubuntu) don't send a ZLP (Zero-length packet) when a communication is terminated with a maximum length packet (64 Bytes for an STM32 with USB FS). It means that the USB state machine of the STM32 USB peripheral is stuck forever waiting the end of the transmission because it thinks it's not over.

Maybe I missed something but from what I know, the condition to have a bulk transmission finished is either having received the maximum number of bytes the endpoint can receive (that's one trigger for the STM32), either having received a packet with less than the maximum packet size. It's why when the last packet has a size of 64 bytes, the computer should send a packet with no data to notify the transmission of datas is finished. Something interesting about this is that MacOS is doing it correctly and the problem doesn't appear whit it. ChibiOS too sends the ZLP when needed.

I implemented an ugly workaround for my code which adds a timeout when we receive a packet of size 64 Bytes and if we receive nothing after it, then it triggers the _usb_isr_invoke_out_cb() to let the USB SERIAL driver read the datas. I don't really see another way to do it since we need to handle something that should not happen.

- I tested it on ChibiOS stable 18.2.x
- Compiler : arm-none-eabi-gcc 7.2.1
- Platform and board : Tested on a Nucleo F746 and on a F413 on the e-puck2 robot
- Problem : In specific cases, the code don't receive the data since the OUT transmission is not considered as finished.

I don't ask you to change the OTGv1 driver immediately, the problem is solved on my side. It's just to let you know this problem exists and can block some USB communications in some specific cases.

Thank you
Eliot Ferragni

User avatar
Site Admin
Posts: 12021
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 543 times
Been thanked: 455 times

Re: USB CDC communication problem with Windows/Ubuntu default drivers

Postby Giovanni » Mon May 06, 2019 9:48 am


The behavior of the OTG peripheral is that a transaction is over when 1) All requested bytes have been received or 2) a zero size packet has been received.

Your workaround of just calling the callback is probably problematic because from the OTG point of view the transaction is still ongoing. I am not yet sure about how this should be handled.

You could try to use the USB API directly without the buffering system, see the "USB RAW" demo under \testhal\STM32\STM32F7xx\USB_RAW, use the API to read exactly the size of a packet, this should avoid the problem but performance would not be great.


Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 1 guest