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

Parents
  • Hi,

     

    I would recommend that you check with semtech if they have a native driver that they recommend. There are drivers for semtech ICs in zephyr already, but I'm not familiar with their devices.

     

    Will the proposed Device Tree fragment do the job?

     You can set up SPI1 like this in a $(BOARD).overlay file:

    &spi1 {
            compatible = "nordic,nrf-spim";
            status = "okay";
            sck-pin = <10>;
            mosi-pin = <11>;
            miso-pin = <12>;
    };

     

    Then enable it in prj.conf:

    CONFIG_SPI=y
    CONFIG_SPI_1=y

     

     

    How do I get the device binding to work?

    Like this for instance: 

    	const char* const spiName = "SPI_1";
    	spi_dev = device_get_binding(spiName);

     

    All those DT_ aliases basically boil down to an ascii string, like above.

     

    Here's a test example with overlay for nrf5340pdk_nrf5340_cpuapp:

    7357.spi_test.zip

     

    Kind regards,

    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.

  • Hi,

     

    CONFIG_SPI_($number) is set by the device tree in newer ncs versions, so you can remove this from the prj.conf.

    Provided the zephyr tag that you're using, you're on a newer ncs version, which also uses pinctrl for allowing different sets of gpios for bus peripherals, which also requires different definitions as shown here:

    https://github.com/nrfconnect/sdk-zephyr/blob/main/boards/arm/nrf5340dk_nrf5340/nrf5340_cpuapp_common-pinctrl.dtsi#L102-L117

    and here: 

    https://github.com/nrfconnect/sdk-zephyr/blob/main/boards/arm/nrf5340dk_nrf5340/nrf5340_cpuapp_common.dts#L223-L229

     

    Kind regards,

    Håkon

  • Thank you very much. With these definitions i got a working SPI interface. 

Reply Children
No Data
Related