-
Notifications
You must be signed in to change notification settings - Fork 7.3k
drivers: usb: Add RP2040 USB device support. #42506
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: usb: Add RP2040 USB device support. #42506
Conversation
drivers/usb/device/usb_dc_rpi_pico.c
Outdated
|
||
/* Helper macros to make it easier to work with endpoint numbers */ | ||
#define EP0_IDX 0 | ||
#define EP0_IN (EP0_IDX | USB_EP_DIR_IN) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use USB_CONTROL_EP_OUT, USB_CONTROL_EP_OUT, USB_CONTROL_EP_MPS from include/usb/usb_ch9.h
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Did keep the separate DATA_BUFFER_SIZE
define, since that's used beyond just EP0 usage.
drivers/usb/device/usb_dc_rpi_pico.c
Outdated
if (status & USB_INTS_SETUP_REQ_BITS) { | ||
handled |= USB_INTS_SETUP_REQ_BITS; | ||
usb_hw_clear->sie_status = USB_SIE_STATUS_SETUP_REC_BITS; | ||
usb_dc_rpi_pico_handle_setup(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Status and endpoint callbacks processing should be offloaded to a thread/workqueue, otherwise device stack, class or application code would be executed in drivers ISR context, see usb_dc_mcux or usb_dc_kinetis driver
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before doing this.... Any reason to use a dedicated thread, versus submitting to the main system work queue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed this, and went w/ a dedicated thread, like the other drivers. Feedback welcome.
651d0af
to
0dd4490
Compare
c71e9b9
to
5f0b8d8
Compare
ac931af
to
38fb1d0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for delay, I finally had time to prepare the hardware so that I can flash it using DAPLink probe and pyOCD and test this driver. Basically it seems to work, let it polish and get in ASAP.
drivers/usb/device/usb_dc_rpi_pico.c
Outdated
msg.cb = usb_hw->sie_status & USB_SIE_STATUS_CONNECTED_BITS ? | ||
USB_DC_CONNECTED : | ||
USB_DC_DISCONNECTED; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This, CONNECTED vs. DISCONNECTED, seems to be reversed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure it is? Seems like the connected status bit being present should be USB_DC_CONNECTED
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I observed it like this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I will swap, I haven't had a chance to test this myself directly.
drivers/usb/device/usb_dc_rpi_pico.c
Outdated
} else if (state.status_cb) { | ||
switch (msg.cb) { | ||
case USB_DC_RESET: | ||
state.status_cb(USB_DC_RESET, NULL); | ||
break; | ||
case USB_DC_ERROR: | ||
state.status_cb(USB_DC_ERROR, NULL); | ||
break; | ||
case USB_DC_SUSPEND: | ||
state.status_cb(USB_DC_SUSPEND, NULL); | ||
break; | ||
case USB_DC_RESUME: | ||
state.status_cb(USB_DC_RESUME, NULL); | ||
break; | ||
default: | ||
LOG_ERR("unknown msg"); | ||
break; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
diff --git a/drivers/usb/device/usb_dc_rpi_pico.c b/drivers/usb/device/usb_dc_rpi_pico.c
index 84bc8f0cbea..48577e668be 100644
--- a/drivers/usb/device/usb_dc_rpi_pico.c
+++ b/drivers/usb/device/usb_dc_rpi_pico.c
@@ -793,26 +793,12 @@ static void udc_rpi_thread_main(void *arg1, void *unused1, void *unused2)
}
break;
default:
- LOG_ERR("unknown msg");
+ LOG_ERR("unknown ep msg");
break;
}
- } else if (state.status_cb) {
- switch (msg.cb) {
- case USB_DC_RESET:
- state.status_cb(USB_DC_RESET, NULL);
- break;
- case USB_DC_ERROR:
- state.status_cb(USB_DC_ERROR, NULL);
- break;
- case USB_DC_SUSPEND:
- state.status_cb(USB_DC_SUSPEND, NULL);
- break;
- case USB_DC_RESUME:
- state.status_cb(USB_DC_RESUME, NULL);
- break;
- default:
- LOG_ERR("unknown msg");
- break;
+ } else {
+ if (state.status_cb) {
+ state.status_cb(msg.cb, NULL);
}
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactored this to simplify greatly. Leaving open until you review again.
Please also add USB to the table of supported features in the board docs |
drivers/usb/device/usb_dc_rpi_pico.c
Outdated
|
||
if (data) { | ||
memcpy(ep_state->buf, data, len); | ||
val |= USB_BUF_CTRL_FULL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
val |= USB_BUF_CTRL_FULL;
should go outside of the condition, otherwise, if the packet size is a multiplicity of the buffer size then the transfer will stall. This is a zero-length-packet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved this out. Thanks!
38fb1d0
to
588084f
Compare
53665e1
to
7c73b26
Compare
7c73b26
to
bab74cb
Compare
bab74cb
to
119f26d
Compare
Summary for the dev-review:
rpi_pico postfix can be confusing if someone is explicitly looking for the SoC name. Should we keep naming scheme or rename? dev-review result: overwhelming majority has voted to keep |
@jfischer-no nudge? Anything else you'd like to see here? |
Sorry, too busy. I will try to finish my review today or tomorrow. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, just few comments, see petejohanson#4, please squash without my comments if you agree with the changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a few minor things
@petejohanson today last chance to get it in v3.1.0 (I do not want to push you, just as a hint 😄) |
119f26d
to
4872dc7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed the comments @jfischer-no
Thanks for the nudge on the timing!
Actually, missed the other comments. Working on those now. |
a414774
to
1d4c746
Compare
@jfischer-no Ok, now all the comments have actually been resolved. Thanks again for the review and the nudge. |
1d4c746
to
a8f6bef
Compare
Add USB device driver for Rasberry Pico family of controllers. Signed-off-by: Peter Johanson <[email protected]>
a8f6bef
to
0593f37
Compare
(my last few pushes were just to make the compliance check happy, FYI) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Initial work on the USB device driver for RaspberryPi Pico SoC.
I'm quite certain there are some gaps and missing bits, and some that just need cleaning up, perhaps with feedback from others that know the stack better than I.