Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drivers: udc_rpi_pico: replace message queue with k_events and minor fixes #87506

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

jfischer-no
Copy link
Collaborator

Replace message queue with k_events, support VBUS state change detection, fix clear/set endpoint halt.

Set suspended state on suspend/resume ISR.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
@jfischer-no jfischer-no added area: Drivers area: USB Universal Serial Bus Experimental Experimental features not enabled by default labels Mar 22, 2025
@jfischer-no jfischer-no requested a review from tmon-nordic March 22, 2025 12:06
tmon-nordic
tmon-nordic previously approved these changes Mar 24, 2025
@kartben kartben requested review from soburi and ajf58 March 24, 2025 08:46
Using k_events eliminates the drawback of the queue potentially dropping
messages and provides a reliable event notification mechanism. It is
similar to commit c2f2d8c
("drivers: usb: udc_dwc2: Replace queue with events")

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Support VBUS state change detection and enable/disable DP pull-up
according to VBUS state when pinctrl property is provided.

It brings the similar functionality introduced in commit 4c0317f
("drivers: usb_dc_rpi_pico: Implemented vbus detection handling")
for the legacy device controller driver.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Mark endpoint as not busy after transfer is canceled.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
For the IN endpoint, we only need to set/reset the STALL bit in the
endpoint control register.
To set halt on the OUT endpoint, the AVAILABLE bit must also be set,
which is similar to starting a new transfer, but first any transfer in
progress must be canceled.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Do not check if the tailroom is greater than or equal to MPS because the
controller does not write directly to the buffer and therefore cannot
write outside the buffer.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
At high throughput, the controller sometimes fails to start a new
transaction. Clearing the corresponding endpoint bit in the BUFF_STATUS
completion register before initiating a new transaction solves this
problem.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Fix USB controller base address.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Copy link
Collaborator

@ajf58 ajf58 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not at USB expert, so I'm reviewing this as a general "if I had to fix it, would I be able to grok it?".

On that note, I think this is well-written, and the changes are clear. One small clarification question/comment from me.


k_msgq_get(&drv_msgq, &evt, K_FOREVER);
ep_cfg = udc_get_ep_cfg(dev, evt.ep);
evt = k_event_wait(&priv->events, UINT32_MAX, false, K_FOREVER);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be either:

  1. The bitmask of all the defined events (e.g. (RPI_PICO_EVT_XFER_FINISHED << 1) - 1) or similar. Or:
  2. Should there be some checking (maybe an assert) that at the bottom of this function all events bits have been handled?

Inspection of the code says "yes, everything defined in the enum is covered below", but it feels like it'd be possible to get out of sync here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Drivers area: USB Universal Serial Bus Experimental Experimental features not enabled by default platform: Raspberry Pi Pico Raspberry Pi Pico (RPi Pico)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants