-
Notifications
You must be signed in to change notification settings - Fork 6.6k
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: RPi Pico PIO SPI code size and byte order. #74117
drivers: spi: RPi Pico PIO SPI code size and byte order. #74117
Conversation
688ac59
to
7e8401d
Compare
cc1b85d
to
bf2842d
Compare
Drat and darn: Testing revealed a timing issue in 3-wire/SIO mode. Previously, the TX logic could count on PIO instruction address being at the stalled pull instruction after the FIFO is empty, but that's not true with the refactored PIO code. Due to the asynchronous nature of the PIO vs the CPU clocks, the test would sometimes fail and the RX logic would reset the state machine before the TX had completed. The fix is to wait until the TX FIFO is empty, then sleep the number of clock ticks necessary to shift out all the data before starting the RX stage. |
This fix is also needed for the next maintenance release of 3.7. |
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.
Sensor changes are ok, but would like @yonsch to review the RPi SPI driver changes.
@yonsch - Do you have any further comments on this pull request? |
@yonsch |
Added. |
bf2842d
to
d714f07
Compare
d714f07
to
d64af43
Compare
@yonsch - Please take a look when you get a chance and see if the changes to drivers/spi/spi_rpi_pico_pio.c meet your approval. I took another look at the problem and redid the wait loop between the send and receive in 3-wire mode. |
@MaureenHelm @soburi - I had to rebase my changes onto the tip of the main branch for the mainline code. There's one update to samples/sensor/magn_polling/README.rst to fix a merge conflict, and the redone synchronization loop in drivers/spi/spi_rpi_pico_pio.c. Can you please review my changes when you have an opportunity? |
d64af43
to
b80299e
Compare
@yonsch - Have you had a chance to look at this again? |
LGTM. Whilst a concern has been raised about the use of |
7af5c53
to
7e57bee
Compare
Use minimized PIO code for 3-wire operation. Input and output buffers are conventionally stored in bus byte order. For 16 and 32 bit transfers, this is effectively big-endian, so txbuf and rxbuf need to be read as such. Those pointers also need to be declared uint8_t * instead of void *. In addition, tx_count and rx_count are based on dts, and refer to whole transfers (8, 16, or 32 bits), not bytes. Added rpi_pico.overlay to samples/sensor/magn_polling to demonstrate 32-bit word size, and updated the README.rst to make it independent of the specific sensor. Clean up compliance check failures. Fix typos. Synchronize 3-wire TX and RX cycles. Simplify state machine synchronization Minimize SPI bus delay time in 3-wire mode Move clock delay to PIO code and remove k_sleep Signed-off-by: Steve Boylan <[email protected]>
7e57bee
to
072b7b3
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 the late response.
I was busy preparing to speak at the open-source summit in Japan.
LGTM
Use minimized PIO code for 3-wire operation.
Input and output buffers are conventionally stored in bus byte order. For 16 and 32 bit transfers, this is effectively big-endian, so txbuf and rxbuf need to be read as such. Those pointers also need to be declared uint8_t * instead of void *.
In addition, tx_count and rx_count are based on dts, and refer to whole transfers (8, 16, or 32 bits), not bytes.
Added rpi_pico.overlay to samples/sensor/magn_polling to demonstrate 32-bit word size, and updated the README.rst to make it independent of the specific sensor.
Fixes #72954