-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dcd_synopsis driver fails to flush data of length 256 bytes when in HS mode #968
Comments
Unsigned overflow/changing requirements strikes again :(. This is definitely wrong, and was probably there since the initial PR. When I originally wrote the driver, I wrote it for a board without a HS PHY. HS was completely out of scope, and I don't think tinyusb supported it at all. In FS, the max xfer is 64 (IIRC), so I used a Good catch! Even if that's not the cause of your woes, it's a bug/oversight that should be changed. |
@BennyEvans ah great, thanks, these are spot-on, as @cr1901 mentioned, this is originally written for FS. I did an update to support HS, but didn't update it properly. Would you like to submit an PR for the fix. If you don't have time, no problem, I could fix it myself. |
Cheers, no problem. I've just created the PR. |
Fix for dcd_synopsys driver integer overflow in HS mode (issue #968).
Operating System
Windows 10
Board
STM32H7
Firmware
examples/device/dcd_msc (tinyUSB 10.1)
What happened ?
The dcd_synopsys.c driver fails to flush when the data to flush is exactly 256 bytes in length in HS mode. Writing more data will eventually cause a flush but calling to flush with 256 bytes of data does not actually perform the transfer.
The line that I believe causes the issue is:
tinyusb/src/portable/st/synopsys/dcd_synopsys.c
Line 659 in 21bfd11
When total_bytes is 256 and xfer->max_size is 512, this line will evaluate to 256, but as the result type is a uin8_t, the result is 0. Further on in the code, this prevents num_packets from being incremented.
I'll do more testing but I believe the soultion to this might simply be to change the line to:
uint16_t const short_packet_size = total_bytes % xfer->max_size;
Please let me know if you require anymore information. I'll try to perform some more testing and put together a pull request over the next week or so when I have some free time.
UPDATE:
There are two instances of this by the look of it:
tinyusb/src/portable/st/synopsys/dcd_synopsys.c
Line 659 in 21bfd11
tinyusb/src/portable/st/synopsys/dcd_synopsys.c
Line 690 in 21bfd11
How to reproduce ?
Debug Log
Logs after sending data of length 256 bytes and 257 bytes below. Note that the 256 byte transfer is not completed.
256 byte transfer:
257 byte transfer:
Screenshots
No response
The text was updated successfully, but these errors were encountered: