This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Using nRF5340-PDK with zephyr adxl372 sensor sample project

I'm new to the nRF5340 and zephyr and ncs, but I have gone through the tutorial series https://devzone.nordicsemi.com/nordic/nrf-connect-sdk-guides/b/getting-started/posts/nrf-connect-sdk-tutorial 

We're developing a product that will use the SPIS peripheral on the nRF5340 and I have a few nRF5340-PDK boards

Since I haven't found any SPIS sample projects, I started with the zephyr adxl372 sensor sample project.

I wanted to get it to a point where the SPIM peripheral was working (wiggling pins as expected) then create my own sensor and change it to SPIS.

I re-mapped the SPI pins to pins on port 1.

I started by using the non-secure build, but couldn't get any SPI activity on the pins.

It looked like the chip select pin was being handled as a GPIO pin (rather than as part of the SPIM peripheral) and when I tried to manually change registers in the GPIO1 peripheral through the SES through the registers view, all the SPIM1 registers showed as 0 and I couldn't change them.

I wondered if GPIO1 was not under the application processor's control, because the NRF_P1 is missing from the peripheral domain status printed at bootup.

Peripheral Domain Status
00 NRF_P0 Non-Secure OK
01 NRF_CLOCK Non-Secure OK
02 NRF_RTC0 Non-Secure OK
03 NRF_RTC1 Non-Secure OK
04 NRF_NVMC Non-Secure OK
05 NRF_UARTE1 Non-Secure OK
06 NRF_UARTE2 Secure SKIP
07 NRF_TWIM2 Non-Secure OK
08 NRF_SPIM3 Non-Secure OK
09 NRF_TIMER0 Non-Secure OK
10 NRF_TIMER1 Non-Secure OK
11 NRF_TIMER2 Non-Secure OK
12 NRF_SAADC Non-Secure OK
13 NRF_PWM0 Non-Secure OK
14 NRF_PWM1 Non-Secure OK
15 NRF_PWM2 Non-Secure OK
16 NRF_PWM3 Non-Secure OK
17 NRF_IPC Non-Secure OK
18 NRF_VMC Non-Secure OK
19 NRF_FPU Non-Secure OK
20 NRF_EGU1 Non-Secure OK
21 NRF_EGU2 Non-Secure OK
22 NRF_DPPIC Non-Secure OK
23 NRF_GPIOTE1 Non-Secure OK
24 NRF_REGULATORS Non-Secure OK

When I choose Project > Configure nRF Connect SDK Project (in the non-secure project) it shows two options - menuconfig and spm_menuconfig

I tried the secure build, and then I saw SPI activity.

But when I try to view the configuration with Project > Configure nRF Connect SDK Project (in the secure project) it does not show me two options.  It just takes me to a config.

Q1:  Why doesn't the non-secure project work to control the SPI pins?

Q2: Why doesn't the secure project show both menuconfig and spm_menuconfig?

  • According to the errata, SPI_3 does not work on nRF5340, so I tried the other option.

    I added these lines to nrf/subsys/spm/Kconfig

    config SPM_NRF_P1_NS
    bool "GPIO is Non-Secure"
    default y

    config SPM_NRF_SPIM1_NS
    bool "SPIM1 is Non-Secure"
    default y

    I added these lines to nrf/subsys/spm/spm.c

    #ifdef NRF_P1
    PERIPH("NRF_P1", NRF_P1, CONFIG_SPM_NRF_P1_NS),
    #endif

    #ifdef NRF_SPIM1
    PERIPH("NRF_SPIM1", NRF_SPIM1, CONFIG_SPM_NRF_SPIM1_NS),
    #endif

    But I still don't get any SPI activity on the non-secure build.

    Did I miss something?

    I also tried the other SPI example you provided, but it looks like the formatting of the nRF Connect SDK has changed a lot since that example was written.  I tried fixing each issue as I got warning messages, but I wasn't able to get the secure build to build successfully, and the non-secure build does not produce any SPI activity.

    Here is the current state of that sample project (with my edits)

    spi-20200519.zip

  • I managed to get your modified SPI sample from Rallare SPI sample to work. I did the following to make it work:

    • Started with the SPI sample you uploaded in your latest reply
    • Removed CONFIG_TRUSTED_EXECUTION_NONSECURE=y from prj.conf
    • Changed the pin values in nrf5340_dk_nrf5340_cpuapp.overlay from hexadecimal format into decimal format:

    &spi1 {
    	status = "okay";
    	compatible = "nordic,nrf-spim";
    	sck-pin = <26>; //sck-pin = <0x26>;
    	//Had to use pin 30 since pin 28 was not accessible on my nRF53DK for some reason
    	mosi-pin = <30>; //mosi-pin = <0x28>;
    	miso-pin = <27>; //miso-pin = <0x27>;
    	cs-gpios = <&gpio1 5 0>;
    	clock-frequency = <4000000>;
    };
    &spi2 {
    	status = "disabled";
    };
    

    • Then I connected P0.27 with P0.30 on the nRF53 DK
    • Built the sample, turned on the nRF53 DK, and flashed it.

    If it works, you should see the following log:

    *** Booting Zephyr OS build v2.1.99-ncs1  ***
    SPIM Example
    TX sent: 0
    RX recv: 0
    TX sent: 1
    RX recv: 1
    TX sent: 2
    RX recv: 2
    TX sent: 3
    RX recv: 3
    TX sent: 4
    RX recv: 4
    TX sent: 5
    RX recv: 5
    TX sent: 6
    RX recv: 6
    TX sent: 7
    RX recv: 7
    TX sent: 8
    RX recv: 8
    TX sent: 9
    RX recv: 9
    TX sent: a
    RX recv: a
    

    Best regards,

    Simon


    Here is the working sample: spi.zip

  • With the changes you suggested, I was able to get the SPI sample from Rallare SPI sample to work as you described.

    It seems like your step "Removed CONFIG_TRUSTED_EXECUTION_NONSECURE=y from prj.conf" was necessary to get the secure build to build successfully.

    I don't understand why it was necessary to change the pins.  I had planned to use:

    CS: P1.05

    SCK: P1.06

    MISO: P1.07

    MOSI: P1.08

    Which you changed to:

    CS: P1.05

    SCK: P0.26

    MISO: P0.27

    MOSI: P0.30

    But why was this change necessary?

    The modified adxl372 example (secure build) I mentioned above uses the original pins successfully.

    By the way, the CS pin did not go low during transmissions even after implementing your changes, so is there some problem with the sample code that makes port 1 pins not work?  (You have to use port 0?)

    I also don't understand why the non-secure builds for the SPI sample or the adxl372 sample don't produce any SPI activity on the SPI port.

    Can you provide any insight?

  • DBT said:
    I don't understand why it was necessary to change the pins.  I had planned to use:

    No, that shouldn't be necessary. Just forget my comment about that.

     

    Have you seen this ticket, where a colleague has provided a working modified version of rallare SPI using SPI_1 and the non-secure version of the board (nrf5340_dk_nrf5340_cpuappns).

    It seems like you have to disable i2c1 in the overlay file.

    Best regards,

    Simon

  • OK if I download the rallare_spi.zip file from the link you provided, it seems to work as-is with a non-secure build.

    If I try to change the SPI pins to the ones I want to use, it stops working.  Do you have any insight?

    nrf5340_dk_nrf5340_cpuappns.overlay
    
    
    BEFORE 
    
    &spi1 {
    	compatible = "nordic,nrf-spim";
    	status = "ok";
    	mosi-pin = <4>;
    	miso-pin = <5>;
    	sck-pin = <6>;
    };
    
    
    &spi2 {
    	status = "disabled";
    };
    
    &i2c1 {
        status = "disabled";
    };
    
    
    AFTER
    
    &spi1 {
    	compatible = "nordic,nrf-spim";
    	status = "ok";
    	mosi-pin = <0x28>;
    	miso-pin = <0x27>;
    	sck-pin = <0x26>;
    };
    
    
    &spi2 {
    	status = "disabled";
    };
    
    &i2c1 {
        status = "disabled";
    };
    

Related