-
Notifications
You must be signed in to change notification settings - Fork 7.4k
[DNM] drivers: spi: Add shim for nrfx SPI driver #6458
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #6458 +/- ##
==========================================
+ Coverage 54.96% 54.96% +<.01%
==========================================
Files 450 450
Lines 43408 43408
Branches 8160 8160
==========================================
+ Hits 23858 23859 +1
+ Misses 16236 16235 -1
Partials 3314 3314
Continue to review full report at Codecov.
|
5da31c9
to
71a212d
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.
I have tested this driver successfully with a modified samples/drivers/led_ws2812 on nrf52_pca10040 using SPI_0 on the Arduino headers.
I've got some coding style comments
drivers/spi/Kconfig.nrf5
Outdated
|
||
if SPI_1_NRF5_SPI || SPI_1_NRF5_SPIM || SPI_1_NRF5_SPIS | ||
|
||
config SPI_1_NRF5 |
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.
Neither SPI_0 nor SPI_2 have an analogous option. Should this be here?
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.
It should not, of course. This option was supposed to be replaced by SPI_1_NRF5_SPI
. I somehow failed to remove this entry after inserting the choice
section above.
drivers/spi/spi_nrf5.c
Outdated
|
||
#include "spi_context.h" | ||
|
||
#ifdef __cplusplus |
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.
Isn't this unnecessary in the .c file? C++ code can access it via an extern "C" declaration in a header, no?
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.
Right, it's completely unnecessary here. I'm surprised that I didn't notice its presence. It must have been present in the source file that I started with as a base and I got used to it so much that it just became transparent to me. Thank for pointing this out!
drivers/spi/spi_nrf5.c
Outdated
return -EINVAL; | ||
} | ||
|
||
struct spi_context *ctx = &get_dev_data(spi_cfg->dev)->ctx; |
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.
Zephyr code style puts variable declarations at top of function body, all in one block (this applies below in the file as well)
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.
Corrected.
drivers/spi/spi_nrf5.c
Outdated
if (result != NRFX_SUCCESS) { | ||
SYS_LOG_ERR("Failed to initialize device: %s", | ||
dev->config->name); | ||
assert(false); |
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 can just return an error instead, no?
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.
Yes, it should return an error. But this value is currently ignored.
Added a return
statement, and 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.
Still: return a valid error code.
I have plans to check these and do something about it (I may introduce it in the relevant pr actually), so it's preferable that all drivers conforms to the signature, even if it's not handled right now. The day it will be: it will be seamless (no need to fix any drivers).
@@ -29,6 +29,7 @@ struct spi_cs_control spi_cs = { | |||
#else | |||
#define SPI_CS NULL | |||
#define CS_CTRL_GPIO_DRV_NAME "" | |||
|
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 should probably be removed from this patch
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.
Right.
drivers/spi/spi_nrf5.c
Outdated
get_nrf_spi_bit_order(spi_cfg->operation)); | ||
} | ||
|
||
nrf_spi_frequency_set(spi->p_reg, |
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 should go into the if {} block above.
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 thought that frequency could be changed between transceive
calls. Looks like I misunderstood the "rest of the attributes" in the note describing spi_config
. I thought it referred to operation
field only. I'll correct it.
drivers/spi/spi_nrf5.c
Outdated
if (result != NRFX_SUCCESS) { | ||
SYS_LOG_ERR("Failed to initialize device: %s", | ||
dev->config->name); | ||
assert(false); |
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.
Still: return a valid error code.
I have plans to check these and do something about it (I may introduce it in the relevant pr actually), so it's preferable that all drivers conforms to the signature, even if it's not handled right now. The day it will be: it will be seamless (no need to fix any drivers).
@mbolivar Thanks for looking into this. I addressed your comments. |
@tbursztyka Applied corrections. |
ea2c164
to
f51fb85
Compare
@tbursztyka great! |
Split QMSI relevant part into its own file. Some config where using prompt, some not: normalizing it by removing the prompt keyword where relevant. Reducing the file by using if/endif when relevant. However, it still not fully clean default: cfg and default baudrate should disappear. There is no default configuration to apply as long as the controller is not configured to run from any part using spi API. Signed-off-by: Tomasz Bursztyka <[email protected]>
This will be useful on Quark_SE ARC core which can access x86 core SPI controller. Signed-off-by: Tomasz Bursztyka <[email protected]>
s/u32_s/u32t obviously Signed-off-by: Tomasz Bursztyka <[email protected]>
As QMSI driver does not support new SPI API. Signed-off-by: Tomasz Bursztyka <[email protected]>
As QMSI driver does not support new SPI API. Signed-off-by: Tomasz Bursztyka <[email protected]>
Native DW driver is relevantly used instead. Signed-off-by: Tomasz Bursztyka <[email protected]>
These now support the new API through SPI DW native driver. Signed-off-by: Tomasz Bursztyka <[email protected]>
Ditch any legacy API support altogether. Signed-off-by: Tomasz Bursztyka <[email protected]>
Adds support for the new spi api to the mcux dspi shim driver. Does not remove support for the legacy spi api since there are still consumers of that api, particularly the mcr20a 802.15.4 driver. Signed-off-by: Maureen Helm <[email protected]>
Adds a board-specific configuration for the frdm_k64f to the spi_loopback test. Signed-off-by: Maureen Helm <[email protected]>
And adding support for GPIO CS as well. It looks like the driver could benefit from centralizing all SPI access into a unique function, the protocol does not seem too convoluted to do so, like CC2520 or CC1200. Signed-off-by: Tomasz Bursztyka <[email protected]>
Now that MCR20A supports the new API, legacy support from mcux dspi driver can be safely removed. Signed-off-by: Tomasz Bursztyka <[email protected]>
It involves a minor change on which register is configured. Most of the change is with threshold handling. Handling the Kconfig based supported mode per-port. Signed-off-by: Tomasz Bursztyka <[email protected]>
This port is a slave SPI port only. Signed-off-by: Tomasz Bursztyka <[email protected]>
Quark SE provides a slave SPI. Signed-off-by: Tomasz Bursztyka <[email protected]>
No need to test it twice then in completed(). Signed-off-by: Tomasz Bursztyka <[email protected]>
No need to check on busy bit from hardware. Signed-off-by: Tomasz Bursztyka <[email protected]>
SPI API is reentrant. Signed-off-by: Tomasz Bursztyka <[email protected]>
SPI API is reentrant. Signed-off-by: Tomasz Bursztyka <[email protected]>
Removing old API usage. Signed-off-by: Tomasz Bursztyka <[email protected]>
This adds a translation layer to make the nrfx driver for the legacy (i.e. without EasyDMA) nRF SPI peripheral accessible via the updated Zephyr's API of the SPI driver. Configuration files are already prepared for adding support for SPIM (Master with EasyDMA) and SPIS (Slave with EasyDMA) peripherals. Signed-off-by: Andrzej Głąbek <[email protected]>
This adds to the spi_loopback test board-specific configurations for the following boards: - nrf51_pca10028 - nrf52_pca10040 - nrf52840_pca10056 Signed-off-by: Andrzej Głąbek <[email protected]>
As legacy SPI API is being removed. Signed-off-by: Tomasz Bursztyka <[email protected]>
No drivers nor samples are using it anymore. Signed-off-by: Tomasz Bursztyka <[email protected]>
Merged via #5921. |
This adds a translation layer to make the nrfx driver for the legacy
(i.e. without EasyDMA) nRF SPI peripheral accessible via the updated
Zephyr's API of the SPI driver.
Slave mode (i.e. the SPIS peripheral) is not supported yet.
Board-specific configurations for a few nRF5 boards are also added
to the "spi_loopback" test.
Depends on #5921