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

How to configure and setup an SPI device to nRF5340

Hello,

I am trying to setup a device (Semtech LR1110) connected to SPI 1 peripheral on the nRF5340pdk.

I have a driver code for it. My question is this.

How can I set it up in the .dts file and keep the code that drives it with my source code on my local drive without having to put it the C:\Zypher\v1.3.0\zephyr\drivers\LR1110?

Q1/ Will the proposed Device Tree fragment do the job?
...
...
spi1: spi@9000 {
   compatible = "nordic,nrf5340";
   status = "okay";
   reg = < 0x9000 0x1000 >;
   interrupts = < 0x9 0x1 >;
   label = "SPI_1";
   sck-pin = < 0x?? >;
   mosi-pin = < 0x?? >;
   miso-pin = < 0x?? >;
};      
Q2/ How do I get the device binding to work?
Will this work?
device_get_binding( DT_PROP( DT_NODELABEL(spi1), label );

Thank you.

Kind regards

  • Thank you Hakon,

    However, I am having other problems with SES when sometimes, at random times, SES (v452c and v510d) cannot open a project that has not been changed for a while and was working fine before. If I keep trying few times it eventually works.

    Above is the actual problem that I wanted you to help me solve. I am still not clear what causes it. See error log I posted few days ago above. 

    Kind regards

    Mohamed

  • Has anything outside of the project changed since it was last opened up? If so, then you should always re-import the project to ensure that the underlying cmake configuration/output is correct.

     

    Kind regards,

    Håkon

  • HI Hakon,

              just wanted to say thanks for this code! I have been struggling with the SPI for a while and this example explains it perfectly!!

  • Hi,

     

    I'm glad to hear that the sample was helpful! Hope you have a wonderful day

     

    Cheers,

    Håkon

  • Hi Hakon,

    thank for the example. 

    When I try to build it, I get an error message: /prj.conf:9: warning: attempt to assign the value 'y' to the undefined symbol SPI_1

    My experience with zephyr is very limited, so I am wondering if I made a mistake or the way zephyr is using the prj.conf during buildtime has changed during the last two years.

    Here is what i have done: I extracted spi_test.zip to samples/basic/spi_test/ within my zephyr installation. Then I run west build -p auto -b nrf5340dk_nrf5340_cpuapp samples/basic/spi_test/

    I use archlinux and my zephyr manifest git tag is “zephyr-v3.2.0-2474-g1aebcec02f”.

    If I delete CONFIG_SPI_1=y in prj.conf, I am able to compile, but the SPI_1 device is not available so I get the “Could not get SPI_1 device” on my terminal.

    To compile the main.c I have done some smaller changes:

    • add a zephyr/ in every #include <>
    • replace u8_t with uint8_t

    This is the compile log. 

    -- west build: generating a build system
    Loading Zephyr default modules (Zephyr base (cached)).
    -- Application: /home/user/zephyrproject/zephyr/samples/basic/spi_test
    -- Cache files will be written to: /home/user/.cache/zephyr
    -- Zephyr version: 3.2.99 (/home/user/zephyrproject/zephyr)
    -- Found west (found suitable version "0.14.0", minimum required is "0.7.1")
    -- Board: nrf5340dk_nrf5340_cpuapp
    -- Found host-tools: zephyr 0.15.2 (/home/user/zephyr-sdk-0.15.2)
    -- Found toolchain: zephyr 0.15.2 (/home/user/zephyr-sdk-0.15.2)
    -- Found BOARD.dts: /home/user/zephyrproject/zephyr/boards/arm/nrf5340dk_nrf5340/nrf5340dk_nrf5340_cpuapp.dts
    -- Generated zephyr.dts: /home/user/zephyrproject/zephyr/build/zephyr/zephyr.dts
    -- Generated devicetree_generated.h: /home/user/zephyrproject/zephyr/build/zephyr/include/generated/devicetree_generated.h
    -- Including generated dts.cmake file: /home/user/zephyrproject/zephyr/build/zephyr/dts.cmake
    
    /home/user/zephyrproject/zephyr/samples/basic/spi_test/prj.conf:9: warning: attempt to assign the value 'y' to the undefined symbol SPI_1
    Parsing /home/user/zephyrproject/zephyr/Kconfig
    Loaded configuration '/home/user/zephyrproject/zephyr/boards/arm/nrf5340dk_nrf5340/nrf5340dk_nrf5340_cpuapp_defconfig'
    Merged configuration '/home/user/zephyrproject/zephyr/samples/basic/spi_test/prj.conf'
    
    error: Aborting due to Kconfig warnings
    
    CMake Error at /home/user/zephyrproject/zephyr/cmake/modules/kconfig.cmake:328 (message):
      command failed with return code: 1
    Call Stack (most recent call first):
      /home/user/zephyrproject/zephyr/cmake/modules/zephyr_default.cmake:108 (include)
      /home/user/zephyrproject/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:66 (include)
      /home/user/zephyrproject/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:97 (include_boilerplate)
      CMakeLists.txt:13 (find_package)
    
    
    -- Configuring incomplete, errors occurred!
    FATAL ERROR: command exited with status 1: /usr/bin/cmake -DWEST_PYTHON=/home/user/zephyrproject/.venv/bin/python3 -B/home/user/zephyrproject/zephyr/build -GNinja -S/home/user/zephyrproject/zephyr/samples/basic/spi_test

    I hope you or someone else is able to help me,

    kind regards.

Related