Skip to content

[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

Closed
wants to merge 51 commits into from

Conversation

anangl
Copy link
Member

@anangl anangl commented Mar 5, 2018

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

@codecov-io
Copy link

codecov-io commented Mar 5, 2018

Codecov Report

Merging #6458 into master will increase coverage by <.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
kernel/posix/pthread.c 70% <0%> (+0.5%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5e6c2c3...f013ba9. Read the comment docs.

@anangl anangl force-pushed the nrfx_shim_spi branch 7 times, most recently from 5da31c9 to 71a212d Compare March 6, 2018 18:03
Copy link
Contributor

@mbolivar mbolivar left a 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


if SPI_1_NRF5_SPI || SPI_1_NRF5_SPIM || SPI_1_NRF5_SPIS

config SPI_1_NRF5
Copy link
Contributor

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?

Copy link
Member Author

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.


#include "spi_context.h"

#ifdef __cplusplus
Copy link
Contributor

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?

Copy link
Member Author

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!

return -EINVAL;
}

struct spi_context *ctx = &get_dev_data(spi_cfg->dev)->ctx;
Copy link
Contributor

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)

Copy link
Member Author

Choose a reason for hiding this comment

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

Corrected.

if (result != NRFX_SUCCESS) {
SYS_LOG_ERR("Failed to initialize device: %s",
dev->config->name);
assert(false);
Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Collaborator

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 ""

Copy link
Contributor

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Right.

get_nrf_spi_bit_order(spi_cfg->operation));
}

nrf_spi_frequency_set(spi->p_reg,
Copy link
Collaborator

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.

Copy link
Member Author

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.

if (result != NRFX_SUCCESS) {
SYS_LOG_ERR("Failed to initialize device: %s",
dev->config->name);
assert(false);
Copy link
Collaborator

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).

@anangl
Copy link
Member Author

anangl commented Mar 7, 2018

@mbolivar Thanks for looking into this. I addressed your comments.

@anangl
Copy link
Member Author

anangl commented Mar 7, 2018

@tbursztyka Applied corrections.

@tbursztyka tbursztyka dismissed their stale review March 7, 2018 08:30

comments applied

@anangl anangl force-pushed the nrfx_shim_spi branch 5 times, most recently from ea2c164 to f51fb85 Compare March 13, 2018 13:12
@tbursztyka
Copy link
Collaborator

@anangl I just put you patches in #5921

@anangl
Copy link
Member Author

anangl commented Mar 19, 2018

@tbursztyka great!

@nashif nashif added the DNM This PR should not be merged (Do Not Merge) label Mar 28, 2018
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]>
Tomasz Bursztyka and others added 11 commits April 3, 2018 14:28
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]>
Tomasz Bursztyka added 8 commits April 3, 2018 17:30
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]>
anangl and others added 4 commits April 3, 2018 18:25
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]>
@anangl anangl changed the title [DNM] drivers: nrf5: Add shim for nrfx SPI driver [DNM] drivers: spi: Add shim for nrfx SPI driver Apr 4, 2018
@anangl
Copy link
Member Author

anangl commented Apr 4, 2018

Merged via #5921.

@anangl anangl closed this Apr 4, 2018
@anangl anangl deleted the nrfx_shim_spi branch April 13, 2018 09:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DNM This PR should not be merged (Do Not Merge)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants