USB CDC ACM and 64 bytes transaction
Posted: Sun Oct 20, 2024 10:50 pm
Hi.
While working with RusEFI project we have found that sometimes we get communication errors while working with PC tool over USB interface. We are using ChibiOS implementation of CDC ACM interface to emulate serial device. So PC tool works with our device as with serial device.
Sometimes during uploading a lot of data communication freezes for few seconds and protocol error is detected.
Log digging shows that issue happens when application sends 64 bytes packet.
Long story goes short - after few days with USB analyzer and debuger I decided to reproduce same problem with default CDC ACM demo.
ChibiOS from github master (acc9fb63bc4c1ea4644296deb8dc04e9b92ee15a)
Board: STM32F429I-DISCO
Code: RT-STM32F429-DISCOVERY example.
Host OS: Linux (but also reported as reproduced on Windows)
Steps to reproduce:
1. Run demo, wait for USB enumeration. /dev/ttyACM0 appears.
2. Write some random data to device using dd:
dd if=/dev/urandom of=/dev/ttyACM0 count=1 bs=63
No issue.
3. Write exactly 64 bytes to device using dd:
dd if=/dev/urandom of=/dev/ttyACM0 count=1 bs=64
If you are lucky and this write happens with single USB transaction then you will see:
And timeout counter will increase by 1:
What I also found:
1. If i set SERIAL_USB_BUFFERS_SIZE to 64 (equal to EP size) this issue is not reproduced.
2. Data is actually received by device but with a loooong delay. It seems to me that data is stuck somewhere in internal buffer (or HW?) and finally poped when another packet (!= 64 bytes) is received.
What I observe in PC tool log is it tries to send this 64 bytes chunk two times with 3 second timeout, then app restarts communication process, sends some "who are you" request and at this point our device receives all three packets.
I have few STM32 based devices, Total Phase USB analyzer and some time I'd like to spend on this bug. So any suggestion on what else I can try are welcome.
While working with RusEFI project we have found that sometimes we get communication errors while working with PC tool over USB interface. We are using ChibiOS implementation of CDC ACM interface to emulate serial device. So PC tool works with our device as with serial device.
Sometimes during uploading a lot of data communication freezes for few seconds and protocol error is detected.
Log digging shows that issue happens when application sends 64 bytes packet.
Long story goes short - after few days with USB analyzer and debuger I decided to reproduce same problem with default CDC ACM demo.
ChibiOS from github master (acc9fb63bc4c1ea4644296deb8dc04e9b92ee15a)
Board: STM32F429I-DISCO
Code: RT-STM32F429-DISCOVERY example.
Host OS: Linux (but also reported as reproduced on Windows)
Steps to reproduce:
1. Run demo, wait for USB enumeration. /dev/ttyACM0 appears.
2. Write some random data to device using dd:
dd if=/dev/urandom of=/dev/ttyACM0 count=1 bs=63
No issue.
3. Write exactly 64 bytes to device using dd:
dd if=/dev/urandom of=/dev/ttyACM0 count=1 bs=64
If you are lucky and this write happens with single USB transaction then you will see:
And timeout counter will increase by 1:
What I also found:
1. If i set SERIAL_USB_BUFFERS_SIZE to 64 (equal to EP size) this issue is not reproduced.
2. Data is actually received by device but with a loooong delay. It seems to me that data is stuck somewhere in internal buffer (or HW?) and finally poped when another packet (!= 64 bytes) is received.
What I observe in PC tool log is it tries to send this 64 bytes chunk two times with 3 second timeout, then app restarts communication process, sends some "who are you" request and at this point our device receives all three packets.
I have few STM32 based devices, Total Phase USB analyzer and some time I'd like to spend on this bug. So any suggestion on what else I can try are welcome.