-
Notifications
You must be signed in to change notification settings - Fork 789
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
Random data corruption in outTransfer #403
Comments
I have seen this problem sending to a slow printer which generates lots of NAKs. The root cause is the SPI.transfer function reads AND writes the data buffer so in Usb.cpp|USB::OutTransfer the following line sends garbage instead of the correct value. Line 376 in 49421b6
bytesWr() calls SPI.transfer() which sends data to the USB out FIFO but also reads from the SPI bus thus over writing the original values at data_p. Line 337 in 49421b6
My fix is to save the first byte of data_p before bytesWr() then use it for NAK retry, if needed.
#238 might also be related. |
Fixed in #473 |
Hi,
I'm a super beginner in Arduino, usb and these drivers stuff, not sure if I understand the problem correctly. :(
I was trying to write a Android Adb host using this library, and I found that the messages that I sent sometimes (or always) corrupted. (The bytes in Usb.outTransfer does not match what's being received).
Here's my thought: (correct me if i'm wrong :) )
In UsbTransfer, due to nak bug, if nak limit is > 1, it will retry when it receives nak.
To restore it from nak, we do "regWr(rSNDFIFO, *data_p);".
However, *data_p is corrupted (the content is not the original content anymore), as in bytesWr(), we do "USB_SPI.transfer(data_p, nbytes);", which read AND write bytes in data_p by SPI.
Hence, "regWr(rSNDFIFO, *data_p);" does not write the original first byte anymore, it writes a value read from SPI.
Does it make sense or if I misunderstood sth?
Thanks a lot!
The text was updated successfully, but these errors were encountered: