sekigon-gonnoc / Pico-PIO-USB

USB host/device implementation using PIO of raspberry pi pico (RP2040).
MIT License
1.36k stars 145 forks source link

🪲[BUG] RX path issues #142

Open shuffle2 opened 1 month ago

shuffle2 commented 1 month ago

I'm using pico-pio-usb as host on rp2040 on gpio pins 2,3. I've noticed a few issues which prevented the library from working correctly out of the box.

I've noticed that sometimes the code locks up. This is because there are infinite loops in the RX path. This is because the following code does not handle timeouts: https://github.com/sekigon-gonnoc/Pico-PIO-USB/blob/fe9133fc513b82cc3dc62c67cb51f2339cf29ef7/src/pio_usb.c#L161 https://github.com/sekigon-gonnoc/Pico-PIO-USB/blob/fe9133fc513b82cc3dc62c67cb51f2339cf29ef7/src/pio_usb.c#L195 https://github.com/sekigon-gonnoc/Pico-PIO-USB/blob/fe9133fc513b82cc3dc62c67cb51f2339cf29ef7/src/pio_usb.c#L215

Both these functions have same issue, where t is no longer used to prevent inf loops after the first 2 bytes. I made a change locally to prevent inf loops here and it works well. As an aside, these functions have some other problems: