Skip to content

NRF52 SPI master for new SPI API #5670

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

vanwinkeljan
Copy link
Member

@vanwinkeljan vanwinkeljan commented Jan 14, 2018

NRF52 SPI Master implementation following new SPI API.
Based on legacy NRF52 SPIM driver.

@codecov-io
Copy link

codecov-io commented Jan 14, 2018

Codecov Report

Merging #5670 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #5670   +/-   ##
=======================================
  Coverage   53.28%   53.28%           
=======================================
  Files         424      424           
  Lines       40729    40729           
  Branches     7845     7845           
=======================================
  Hits        21702    21702           
  Misses      15817    15817           
  Partials     3210     3210

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 4d72e48...78577b1. Read the comment docs.

@carlescufi carlescufi requested a review from anangl January 14, 2018 18:26
Copy link
Collaborator

@tbursztyka tbursztyka left a comment

Choose a reason for hiding this comment

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

tiny comments


if ((config->cs != NULL) || (cfg->psel.cs == CS_UNUSED)) {
/* Disable HW based CS */
spim->PSEL.CSN |= SPIM_PSEL_CSN_CONNECT_Msk;
Copy link
Collaborator

Choose a reason for hiding this comment

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

isn't spi_context_cs_configure() missing here?


ret = spi_context_wait_for_completion(&data->ctx);

spi_context_release(&data->ctx, ret);
Copy link
Collaborator

Choose a reason for hiding this comment

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

you could move that line before return ret, so line 225 would be move as line 222. but it's cosmetic

u32_t tx_count, struct spi_buf *rx_bufs, u32_t rx_count,
bool asynchronous, struct k_poll_signal *signal)
{
int ret;
Copy link
Collaborator

Choose a reason for hiding this comment

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

usually, pre-assigned variable declaration come first, so here ret would be the last

@@ -14,7 +14,7 @@ config SOC

config NUM_IRQS
int
default 46
default 48
Copy link
Collaborator

Choose a reason for hiding this comment

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

you commit message does not say why you increase this number (and how it relates to spi actually)

Copy link
Member Author

Choose a reason for hiding this comment

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

updated commit message to indicate number was increased as per documentation

The lower number of interrupts was causing a build error as the last SPI device has number 47

Copy link
Collaborator

@galak galak left a comment

Choose a reason for hiding this comment

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

Should have also introduce device tree support for SPI

@@ -60,6 +60,7 @@
#define NRF52_IRQ_RTC2_IRQn 36
#define NRF52_IRQ_I2S_IRQn 37
#define NRF52_IRQ_FPU_IRQn 38
#define NRF52_IRQ_SPIM3_IRQn 47
Copy link
Collaborator

Choose a reason for hiding this comment

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

should come from Device Tree

@vanwinkeljan
Copy link
Member Author

updated code after testing

@vanwinkeljan
Copy link
Member Author

@galak added initial attempt for dts

@vanwinkeljan vanwinkeljan changed the title [RFC] NRF52 SPI master for new SPI API NRF52 SPI master for new SPI API Feb 6, 2018
@vanwinkeljan
Copy link
Member Author

Addresses NRF52 SPI master part of #4713

@carlescufi
Copy link
Member

@vanwinkeljan I know @anangl is preparing to submit a driver based on nrfx which now lives in ext/hal/nordic. There's also a rework of the SPI API that @tbursztyka is leading and that will affect this. I think we should join efforts here and provide an nrfx-powered driver that complies with the new API. @anangl will be back next week from holiday and can discuss this further.

@mbolivar
Copy link
Contributor

I'm trying to get this to build for nrf52_pca10040 by adding the following to hello_world's prj.conf:

# CONFIG_SPI_LEGACY_API is not set
CONFIG_SPI=y
CONFIG_SPI_0=y
CONFIG_SPI_NRF5=y
CONFIG_SPI0_NRF52_MASTER=y

I get a lot of warnings and errors: https://gist.github.com/mbolivar/13d9da829fd5d0d6501c604fc0380d29

Am I missing something?

@vanwinkeljan
Copy link
Member Author

@mbolivar I will have a look at it.

For now I know there is a problem for SPI0 if I switch to SPI1 I do not seen the warnings.
But even then I get compile errors for nrf52_pca10040 due to missing declarations (I tested with nrf52840_pca10056).

One further remark is that you will also need to add a DTS overlay (nrf52_pca10040.overlay) to the hello_world directory that enables the SPI port and declares which pins it will use.
e.g.
&spi1 {
status = "ok";
clk-pin = <3>;
mosi-pin = <28>;
miso-pin = <29>;
};

Increased the number of interrupts from 46 to 48 according to nrf52840
documentation.

Signed-off-by: Jan Van Winkel <[email protected]>
Added NRF52 SPI master using new SPI API.

Signed-off-by: Jan Van Winkel <[email protected]>
Added DTS support for NRF52 master SPI driver

Signed-off-by: Jan Van Winkel <[email protected]>
@vanwinkeljan vanwinkeljan force-pushed the nrf52_spi_master_pull_req branch from 1eba990 to 78577b1 Compare February 22, 2018 07:54
@vanwinkeljan
Copy link
Member Author

  1. Corrected SPI Kconfig to take in account that DTS can be used for SPI0
  2. Take in account that there is only a psel CSN for nrf52840

@mbolivar this should fix your build issues

@mbolivar
Copy link
Contributor

@vanwinkeljan looks like the PR from @anangl (#6458) got taken in #5921 -- earlier @carlescufi mentioned this code as a potential place to work together. Any comments on where you want this PR to go? Sorry that I haven't gotten around to re-testing, as the patches in 6458 did the trick for me.

@vanwinkeljan
Copy link
Member Author

@mbolivar I noticed @anangl PR and skimmed through and had no remarks.
I will close this PR

@vanwinkeljan vanwinkeljan deleted the nrf52_spi_master_pull_req branch March 24, 2018 20:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants