RIOT icon indicating copy to clipboard operation
RIOT copied to clipboard

cpu/rpx0xx: add periph_usbus support

Open fengelhardt opened this issue 1 year ago • 18 comments

Contribution description

This is a WIP contribution to add USB support for the rpx0xx MCU.

Testing procedure

The code is in a quite early stage. It compiles with examples/usbus_minimal, but it hangs somewhere quite early in the initialization. I will debug it as we go, please do not look all to deeply into it yet.

With this PR I primarily want to clarify some question I have regarding the USB stack.

Issues/PRs references

#15822 is for RPx0xx feature tracking.

fengelhardt avatar Aug 18 '24 19:08 fengelhardt

With these changes, I can now receive the setup request from the host. Its interrupt is fired but never served by _usbdev_esr() and it loops forever so we never response to the setup request.

dylad avatar Aug 29 '24 14:08 dylad

With these changes, I can now receive the setup request from the host. Its interrupt is fired but never served by _usbdev_esr() and it loops forever so we never response to the setup request.

I already wondered how to handle setup packets. usbdev_event_t has no event defined for this case, so I can not notify usbus. Do I have to handle it here in the periph driver?

fengelhardt avatar Aug 31 '24 11:08 fengelhardt

Added a fixup with your suggestions @dylad, and improved handling of INTS in isr_usbctrl(). Now the line reset seems to work, and the EP 0 is initialized.

I had no time to test further yet. Maybe tomorrow I can also check my packet flow.

fengelhardt avatar Aug 31 '24 12:08 fengelhardt

Now the setup requests are recognized by usbus, but control flow is still garbage.

fengelhardt avatar Sep 01 '24 10:09 fengelhardt

From what I can tell this is normal. Setup packets are not put in EP0 buffer but at the beginning of DPSRAM (offset 0). Currently, you try to pass DPSRAM + 0x100 to USBUS which contains garbage, thus USBUS doesn't recognize the setup packets. However, if you pass the right offset when you received a setup packet I can clearly see that the host is requesting the device descriptor :tada: Unfortunately it's seem there is an issue when responding to the request. I'm not even sure the host sees the response yet. I'll try to check with wireshark next debugging session.

dylad avatar Sep 04 '24 11:09 dylad

Setup packets are not put in EP0 buffer but at the beginning of DPSRAM (offset 0).

Wow, I guess I misread the data sheet here...

Some tinkering today did not work so far, but I have an idea for solving that. Sadly I have not time over the weekend. Might take me some time to figure that out.

fengelhardt avatar Sep 05 '24 17:09 fengelhardt

Still garbage, unfortunately. But I have found a few bugs.

I might simply have a race condition between the setup request handling and data packet handling. Not sure how to handle that with usbus. The USB controller treats setup request differently from normal data, which makes it difficult to hand over to usbus.

Maybe my endpoint initialization is not correct, too.

fengelhardt avatar Sep 12 '24 18:09 fengelhardt

I'll see if I can find some times this weekend to help you with that.

dylad avatar Sep 12 '24 19:09 dylad

I have made some progress based on @dylad 's comments. I think I figured out the usb controller more or less. I get the setup requests and some control flow afterwards. However, I totally misunderstood how RIOT's usbus works and there is is still a problem. It seems I do not receive any packets and the control flow looks wrong.

fengelhardt avatar Oct 04 '24 19:10 fengelhardt

I'm making small progress on my side. I am now stuck halfway through the enumeration process. I'll prepare a more in-depth review once the enumeration process works flawlessly.

dylad avatar Dec 18 '24 08:12 dylad

Thank you very much @dylad for your effort. I recently thought that it could only be an issue of setting the PID correctly. I tried hardcoding the PID and I could then receive at least one correct packet from the device. Maybe I find some time to study the PID handling of the tinyUSB driver to implement that here.

Wish everyone a happy new year btw.

fengelhardt avatar Jan 01 '25 17:01 fengelhardt

Hi @fengelhardt Happy new year to you too. I wasn't able to work on this lately so no progress on my side. I was planning to start the next round of review once I got enumeration fully working but that's not the case yet. If you want I can do the next round of review now so you can also work on this on your side in the meantime. Basically, ISR management and PID need rework + a few errors here and there. What do you prefer ?

dylad avatar Jan 02 '25 08:01 dylad

Maybe let me first try to get it running. The PID handling I need to rework a lot, I think. I hope to find time in he coming days.

fengelhardt avatar Jan 02 '25 17:01 fengelhardt

@fengelhardt Finally I've got some good news !

Copie d'écran_20250108_212408

You may find all the changes I've made on my work branch.

dylad avatar Jan 08 '25 20:01 dylad

Nice, I will have a look!

08.01.2025 21:30:19 Dylan Laduranty @.***>:

@fengelhardt[https://github.com/fengelhardt] Finally I've got some good news !

Copie.d.ecran_20250108_212408.png (view on web)[https://github.com/user-attachments/assets/3d5e2da5-49b8-43ff-bb09-83736f470f6e]

You may find all the changes I've made on my work branch.

fengelhardt avatar Jan 08 '25 20:01 fengelhardt

Nice, I will have a look! 08.01.2025 21:30:19 Dylan Laduranty @.***>: @fengelhardt[https://github.com/fengelhardt] Finally I've got some good news ! Copie.d.ecran_20250108_212408.png (view on web)[https://github.com/user-attachments/assets/3d5e2da5-49b8-43ff-bb09-83736f470f6e] You may find all the changes I've made on my work branch.

Hey, just wanted to ask, is this something you are still working on / have there been updates to this outside of this PR? I'm looking into potentially doing something similar for the rp2350 and don't want to redo any efforts that were already finished

AnnsAnns avatar Sep 15 '25 15:09 AnnsAnns

Hi, I think I have to give up on this project. I think I have a bit more code on my local mashine where I tried to integrate Dylan's work. I can push that, but it still does not work. Maybe you are more lucky thank me.

15.09.2025 17:53:41 Ann🐸 @.***>:

 [Bild]*AnnsAnns* left a comment (RIOT-OS/RIOT#20817)[https://github.com/RIOT-OS/RIOT/pull/20817#issuecomment-3292868305]

Nice, I will have a look! 08.01.2025 21:30:19 Dylan Laduranty /@/.***>: …[#] @fengelhardt[https://github.com/fengelhardt][https://github.com/fengelhardt] Finally I've got some good news ! Copie.d.ecran_20250108_212408.png (view on web)[https://github.com/user-attachments/assets/3d5e2da5-49b8-43ff-bb09-83736f470f6e] You may find all the changes I've made on my work branch. — Reply to this email directly, view it on GitHub[#20817 (comment)[https://github.com/RIOT-OS/RIOT/pull/20817#issuecomment-2578597687]], or unsubscribe[https://github.com/notifications/unsubscribe-auth/AAY3EV6U3ZYJD3OIZVDGV4D2JWDFLAVCNFSM6AAAAABMWTG35GVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKNZYGU4TONRYG4]. You are receiving this because you were mentioned. [Verfolgungsbild][https://github.com/notifications/beacon/AAY3EV67TUCPEZCSOIXQMTT2JWDFLA5CNFSM6AAAAABMWTG35GWGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTUZWJDTO.gif]

Hey, just wanted to ask, is this something you are still working on / have there been updates to this outside of this PR? I'm looking into potentially doing something similar for the rp2350

— Reply to this email directly, view it on GitHub[https://github.com/RIOT-OS/RIOT/pull/20817#issuecomment-3292868305], or unsubscribe[https://github.com/notifications/unsubscribe-auth/AAY3EV6ANT3AXMVKMKF3C7T3S3OH7AVCNFSM6AAAAACGR32TNCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTEOJSHA3DQMZQGU]. You are receiving this because you were mentioned. [Verfolgungsbild][https://github.com/notifications/beacon/AAY3EV5NB7TNW5N2N6HBB3D3S3OH7A5CNFSM6AAAAACGR32TNCWGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTWEIUXNC.gif]

fengelhardt avatar Sep 22 '25 10:09 fengelhardt

Hi, I think I have to give up on this project. I think I have a bit more code on my local mashine where I tried to integrate Dylan's work. I can push that, but it still does not work. Maybe you are more lucky thank me. 15.09.2025 17:53:41 Ann🐸 @.***>:

Hey no worries, thank you for your work on this, would be happy to look at your local changes. Ty, for the response :)

AnnsAnns avatar Sep 22 '25 11:09 AnnsAnns