-
Notifications
You must be signed in to change notification settings - Fork 8.2k
drivers: spi: spi_pico_pio: Add basic support for SPI via PIO #60395
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: spi: spi_pico_pio: Add basic support for SPI via PIO #60395
Conversation
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.
Hello @ThreeEights, and thank you very much for your first pull request to the Zephyr project!
A project maintainer just triggered our CI pipeline to run it against your PR and ensure it's compliant and doesn't cause any issues. You might want to take this opportunity to review the project's Contributor Expectations and make any updates to your pull request if necessary. 😊
|
I have a sample based on the zephyr/samples/sensor/bme280 sample that demonstrates using the PIO SPI driver. I thought that ought to be a separate commit, but that requires approval of this commit first. One option is to create a new samples/boards/rpi_pico/spi_pio sample, though the only change is the addition of the rpi_pico.overlay and updating the prj.cfg. |
|
@ThreeEights I am curious, why PIO instead of using the Pico's native SPI IP? Regarding your sample questions, @yonsch should be able to answer that. |
a244c6e to
813d35f
Compare
|
@carlescufi - There are 3 main reasons for adding PIO SPI support, in addition to the two built-in SPI devices:
|
|
@iocapa - Would you be willing to join the review for this pull request? |
|
@fabiobaltieri - I saw you triggered a re-run of the Coding Guidelines checks, but that failed due to apt-get not being able to access the Ubuntu repositories. Is there a way I can restart the job, or do I need assistance from the build team? Thanks, |
Hey, I retried it again, not sure what level of permissions you need to retry the individual checks but you can always do a dummy |
|
Hey while we are at it...
Does this actually work on the pico W? Thought it was some odd single-wire SPI-ish thing. |
drivers/spi/spi_pico_pio.c
Outdated
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.
Is it cannot obtain frequencies from clock-control?
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.
@soburi - clock-control is not supported on the Raspberry Pi Pico (or Pico W). Those boards use a fixed clock. However, looking back at this, it makes more sense to just use the clock frequency from the devicetree, so I've updated those functions to use that instead of calling into the Pico SDK and pushed the change to GitHub. Thanks for pointing this out.
|
@fabiobaltieri - Thanks! That run completed successfully. You asked:
Not yet. This is a work in progress. I wanted to get this baseline out there for review while adding the other pieces needed for the Pico W. |
|
@soburi - Thanks for the pointer. Since clock-control didn't appear in any of the SPI drivers I was using for references, I didn't know about it. (There are so many parts of Zephyr I don't know about!) I'll try getting the system clock speed through the API and, if that succeeds, I'll push an update. |
0a41457 to
bede792
Compare
|
@ThreeEights Thanks for this PR, I will take a look later. In the meantime:
The SPI used for the wifi module is a special one wire version of SPI, which I haven't looked at thoroughly enough to say how different it is from normal SPI. It may be similar enough to share code with notmal SPI, but not necessarily so. In any case, there's another use for a PIO SPI - the PL022 SPI peripheral only supports MSB first communication. The only way to add LSB first SPI is via PIO. So I think any PIO implementation of SPI should support both. |
|
@yonsch - Thanks. So far, other than needing 3-wire support, it looks like the CYW43439 SPI is pretty conventional. And LSB support is on my longer list of features to add, though that will be a number of pull requests in the future. For now, I wanted to get this first version of the driver reviewed while I add the additional features needed to support the Pico W. |
|
@yonsch - Turns out supporting LSB first just involves flipping one bit in a control register. Do you know of any (inexpensive, readily acquired) peripherals that use SPI in LSB mode? Changing the driver is simple, but I don't want to push a change without being able to test it. Thanks, |
I think @petejohanson has a keyboard with LSB first SPI |
|
Adafruit sells sharp memory display breakouts that use the ls0xx driver and are LSB: https://github.com/zephyrproject-rtos/zephyr/blob/main/drivers/display/ls0xx.c#L306 https://www.adafruit.com/product/3502 Can often be found on Mouser/DigiKey too. |
drivers/spi/spi_rpi_pico_pio.c
Outdated
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.
Why is this not handled by pinctrl?
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.
Turns out you're right - it IS handled by pinctrl. That code is redundant; I deleted it.
de17a1d to
738d0ae
Compare
|
@soburi @fabiobaltieri @yonsch - Yet another update to incorporate review comments from @yonsch. Can someone restart the workflows now that the git conflicts have been resolved? |
b8e6563 to
5fec1a6
Compare
|
@yonsch - Can you please take a look at my changes and let me know if there's anything else required? |
|
@yonsch - Could you please review the changes made in response to your review comments? Thanks! |
|
@yonsch - I'd like to complete this pull request, preferably before another merge conflict shows up. The last response was over 2 weeks ago. This driver makes minimal use of zephyr/drivers/misc/pio_rpi_pico, so it should be possible to quickly adapt to any changes in #56678. I'm going to ask dev-review to look at this PR and get their recommendation. |
95ad4a6 to
6d91c10
Compare
yonsch
left a comment
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 seems to need a rebase but otherwise looks good
Add fundamental feature support for RP2040 PIO SPI peripherals. This commit implements synchronous transfer with 8-bit MSB format. Using PIO allows any GPIO pins to be assigned the roles of CS, CLK, MOSI, and MISO. Optional features not implemented yet: - Interrupt based transfer - DMA transfer - Slave mode - Varying word size - 3-wire SPI support - LSB-first Updated in response to review comments. Further updates from second round of review. Rename spi_pico_pio.c source to match zephyr/MAINTAINERS.yml Remove unnecessary initialization code. Resolve merge conflicts Signed-off-by: Steve Boylan <[email protected]>
6d91c10 to
4704ba7
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.
Hi @ThreeEights!
Congratulations on getting your very first Zephyr pull request merged 🎉🥳. This is a fantastic achievement, and we're thrilled to have you as part of our community!
To celebrate this milestone and showcase your contribution, we'd love to award you the Zephyr Technical Contributor badge. If you're interested, please claim your badge by filling out this form: Claim Your Zephyr Badge.
Thank you for your valuable input, and we look forward to seeing more of your contributions in the future! 🪁
Add fundamental feature support for RP2040 PIO SPI peripherals. This commit implements synchronous transfer with 8-bit MSB format. Using PIO allows any GPIO pins to be assigned the roles of CS, CLK, MOSI, and MISO.
Optional features not implemented yet: