-
Notifications
You must be signed in to change notification settings - Fork 18
Fix for control transfers that exceed the max packet len #7
Conversation
@hathach Is this a problem only with our fork of tinyusb, or does it affect your upstream version too? |
It looks more like the pico hcd port issue and shouldn't be fixed at usbh as proposed by this PR.
Reason is that this mouse has control packet size = 8 which is typical for mouse ( not 64 as most other). So 8 bytes here is not short packet here, and pico should continue to read more until 0x0022 bytes is read, or a short packet (len < 8) is received. Note: control packet size can be saved by rp2040 by the Note: you will notice that host stack (usbh) initially open control endpoint with only 8 bytes for new device (addr = 0) Sumup: we should fix rp2040 hcd instead. |
I think this might be a better fix: https://github.com/raspberrypi/pico-sdk/issues/361#issuecomment-826465401 |
Yes, you're right. I came to a similar conclusion after reading hathach's comment above. However, although fixing the issue in that way does result in the correct use of the rp2040 host buffer, it uncovers a further problem. In my case, with the log in the issue I raised, this should result in a transfer containing three data packets of size 8, 8 and 2 bytes. The first two packets are received ok but the third packet always results in a data sequence error in the IRQ handler. These are the values of the buffer control for the endpoint that I captured illustrating this:
In fact, I couldn't get past this problem using the USB controller as intended. I ended up creating a workaround where I set the LAST_BUFFER flag on each packet and restarted the next packet using SIE. I suspect a bug on the RP2040 itself but would be interested to hear what others think. I'll push the changes to this PR for inspection as the original PR solution is incorrect. |
It looks like my original patch was also missing
When I do that, I see the second 8 byte packet fail:
|
Yes, I was seeing something similar. Take a look at the the code around the |
So looking at my error case, my device sends a stall after the second packet. This is fine from the protocol perspective, but the pico code doesn't seem to handle it well:
I also found a bug in |
Do we need to do the following so we get the correct rx length?
|
I tested your patch + #7 (comment) and it works! Can you squash your two commits. The CLs touch the core tinyusb core. Once you squash them it should only touch the rp2040: code. Also can you prefix your commit with rp2040: to match the existing style. Thanks! |
…karound for apparent HW bug on data sequencing.
dbbc297
to
f87186b
Compare
Ok, done. |
No, I don't believe so. It seems the HW bug where the wrong half of the buffer control variable is updated only affects the status bits, not the length. |
LGTM Thanks! |
After looking more closely with rp2040 host mode, this is not an additional hardware bug. It is due to driver incorrectly update the Data Toggle (PID). For this instance, 64 bytes is 8 packets, and the next 9th packet should not have PID toggled. There is another bug with panic already available as well (based on RP2040-E4). These are fixed by hathach/tinyusb#862 |
I'm not sure if the latest d49938d tinyusb fixes this:
I'm only getting back 8 bytes for each transfer... I'm going to try and rebase this PR onto the latest tinyusb and see if that fixes the problem. |
It's this line
Why do we have the 64 byte limit? An endpoint can only transfer as much as the max packet size. |
ISO can have up to 1023 bytes. |
Right, |
This PR fixes Issue #6 where connecting a device to a tinyusb host that has a max control transfer packet size that is less than the descriptor being transferred causes incorrect parsing of the descriptor. This normally results in execution of a never ending tight loop in the tinyusb descriptor parsing code.
The issue has been fixed by detecting the case where more DATA packets are required to complete the transfer and remaining in the DATA state until the transfer has completed and the destination buffer contains the full set of data.