Description
I am working on a TinyUSB-free USB Host library for the rp2040, called https://github.com/shreeve/pico-usb and am seeing an issue that I can't seem to resolve. I really like the TinyUSB library, but it is very large and pretty confusing. I'd like to create a much simpler, canonical pico-sdk based library.
In the following screenshot, the following registers are defined as:
INTR = raw USB IRQ interrupts
INTS = USB IRQ interrupts that we've requested
SSR = sie_status register
SCR = sie_ctrl register
DAR = addr_endp register (device and endpoint address)
ECR = EPX control register
BCR = EPX buffer control register

The issue that I'm having is that in the setup packet being transferred at the top of the image, bcr
is set to 0x2462
which means that: the next packet is a DATA1 (the leading 2), that buf0 is AVAILABLE (the 4), and I'm requesting 0x62
(98 decimal) bytes. This should raise the BUFF_STATUS
interrupt when the initial packet completes, but it should not raise the TRANS_COMPLETE
interrupt, since bcr
did not include USB_BUF_CTRL_LAST
.
After the initial 0x40
(64 decimal) bytes are received, when I process this initial BUFF_STATUS
, I set the bcr
(shown as ~bcr~
) to 0x6422
to indicate that the following packet will be the last one (since we only need to transfer the remaining 0x22
(34 decimal) bytes. The leading 6
includes the USB_BUF_CTRL_LAST
bit (itself being a 4
). I would expect the resulting packet based on the bcr
of 0x6422
to raise the TRANS_COMPLETE
interrupt and let me finish this request. However, the first packet raises TRANS_COMPLETE
and I can't figure out why.
The datasheet shows that there are supposed to be only FOUR conditions that raise TRANS_COMPLETE
:

I don't think these four conditions apply to the first screenshot above.
My code is found at: https://github.com/shreeve/pico-usb/blob/main/host/host.c
If there's a way to not have TRANS_COMPLETE
not be raised when it shouldn't, I would greatly appreciate the help. I hope it isn't some lower level issue like one of the few USB errata. My guess is that I'm just doing something wrong, but given that I have found absolutely zero other USB Host libraries for the rp2040 outside of TinyUSB, it's hard to know.
I'm not sure if this is even the correct place to post this question, but @lurch mentioned it might be worth a shot. If @kilograham or @aallan have any input that would be great also! Ideally, if this can be fixed, the code could be helpful to have a more flexible and lighter USB Host library to offer on the rp2040.
Thanks!