sekigon-gonnoc/Pico-PIO-USB

🪲[BUG] First RX fails with bits shifted by one.

tannewt opened this issue · 1 comments

Describe the bug you encountered:

The capture of the response to the very first setup packet fails. I think this is the very first time anything is captured by the RX PIO. Maybe its initial state is incorrect?

What did you expect to happen instead?

The RX PIO should capture the SYNC and ACK packets (0x80 and 0xd2).

What actually happened in your case?

Instead, it errors because it captured 0x01 and 0xa5. Note that this is (0xd2 << 1 | 1).

Additional information

This is using USB Host via CircuitPython for testing. However, this is low level enough that I don't think it's the issue. Subsequent ACKs are captured correctly.

Serial console setup       << Start of CircuitPython
Get 8 byte of Device Descriptor
ctrl xfer 0x20009f58 cb 0x1009b471 << TinyUSB control transfer for getting device desc
setup send 06
pio SETUP error 202 01 a5 delay 0  << Errors due to not matching SYNC and ACK
pio error
Enumeration attempt 1 failed 1 << TinyUSB fails
ctrl xfer 0x20009f58 cb 0x1009b471 << Tries again
setup send 06
pio SETUP ok 33e 80 d2 << Captures ACK correctly
ctrl setup 00 00
[1:0] Control data len 8
Set Address = 1 << Set address works ok too
ctrl xfer 0x0 cb 0x1009b471
setup send 05
pio SETUP ok 3ed 80 d2

This causes issues when using a device running TinyUSB because it can't handle two SETUP packets in a row. It (currently) expects to finish the first control transaction before the second setup packet.

Also, I've used a Saleae to verify that the data on the wire looks correct. I did have to add a small glitch filter so that could be the problem. However, I'd expect signal integrity to cause other ACK reads to fail too and it doesn't seem to.