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,

    I would recommend that you check with semtech if they have a native driver that they recommend.

    Thank you for your suggestions. As I said in my initial post I already have the source code to drive the Semtech LR1110 device. All I need to do is implement the low level HAL functions.

    I did not think the first line in prj.conf file was necessary so I commented it out.

    CONFIG_BOARD_ENABLE_CPUNET=n

    However, this caused the project to fail loading in SES. Is the default, 

    CONFIG_BOARD_ENABLE_CPUNET=y

    Could you please explain why the project failed to load?

    Kind regards

    Mohamed

  • Hi Hakon,

    I've  re-downloaded the zip file and extracted ok. 

    I opened the project spi_example and built it ok.

    I then commented out the line CONFIG_BOARD_ENABLE_CPUNET=n in prj.conf.

    I tried to open the project but failed as with the old SES version.

    I re-instated the line CONFIG_BOARD_ENABLE_CPUNET=n in prj.conf again in prj.conf but I still cannot reload the project. Below is the error.

    This is very bizarre. SES seems to be very moody, one minute it is happy the next it is not.

    Thank you for your help.

    Kind regards

    Mohamed

  • Hi,

     

    Learner said:
    I re-instated the line CONFIG_BOARD_ENABLE_CPUNET=n in prj.conf again in prj.conf but I still cannot reload the project. Below is the error.

     Could you click on "OK" and paste the full output from the build-window in SES? I can see that the failure is in line 35 of ZephyrConfig.cmake, but it would be good to see if there's anything interesting before that.

     

    Kind regards,

    Håkon

  • As I said in my previous post, SES v5.10d is very moody. Guess what? I can open and build the solution now. This is with the line CONFIG_BOARD_ENABLE_CPUNET=n enabled. However, when I commented it out I could not open the project. Below is the error log.

    Creating solution spi_test.emProject
    cmake -GNinja -DBOARD=nrf5340pdk_nrf5340_cpuapp -DBOARD_DIR=C:\Zypher\v1.3.0\zephyr\boards\arm\PID4_nRF5340 -BC:\Dev\NCS_projects\spi_example\spi_test\build_SESv510d_nrf5340pdk_nrf5340_cpuapp -SC:\Dev\NCS_projects\spi_example\spi_test -DZEPHYR_TOOLCHAIN_VARIANT=gnuarmemb -DGNUARMEMB_TOOLCHAIN_PATH=C:\Zypher\v1.3.0\toolchain\opt -DDTC_OVERLAY_FILE=C:\Dev\NCS_projects\spi_example\spi_test/nrf5340pdk_nrf5340_cpuapp.overlay -DEXTRA_KCONFIG_TARGETS=menuconfig_ses -DEXTRA_KCONFIG_TARGET_COMMAND_FOR_menuconfig_ses=C:\Program Files\SEGGER_V5.10c\arm_segger_embedded_studio_v510d_win_x64_nordic/html/configure_nordic_project_menuconfig.py
    -- Application: C:/Dev/NCS_projects/spi_example/spi_test
    -- Zephyr version: 2.3.0-rc1 (C:/Zypher/v1.3.0/zephyr)
    -- Found Python3: C:/Program Files/WindowsApps/PythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64__qbz5n2kfra8p0/python3.8.exe (found suitable version "3.8.6", minimum required is "3.6") found components: Interpreter
    -- Board: nrf5340pdk_nrf5340_cpuapp
    -- Found west: C:/Zypher/v1.3.0/toolchain/opt/bin/Scripts/west.exe (found suitable version "0.7.3", minimum required is "0.7.1")
    -- Found toolchain: gnuarmemb (C:/Zypher/v1.3.0/toolchain/opt)
    -- Found BOARD.dts: C:/Zypher/v1.3.0/zephyr/boards/arm/PID4_nRF5340/nrf5340pdk_nrf5340_cpuapp.dts
    -- Found devicetree overlay: C:\Dev\NCS_projects\spi_example\spi_test/nrf5340pdk_nrf5340_cpuapp.overlay
    -- Configuring incomplete, errors occurred!
    Including boilerplate (Zephyr base): C:/Zypher/v1.3.0/zephyr/cmake/app/boilerplate.cmake
    In file included from C:/Zypher/v1.3.0/zephyr/boards/arm/PID4_nRF5340/nrf5340pdk_nrf5340_cpuapp.dts:9,
    from <command-line>:
    C:/Zypher/v1.3.0/zephyr/boards/arm/PID4_nRF5340/nrf5340_cpuapp_common.dts:179:10: fatal error: nrf5340_cpuapp_partition_conf.dts: No such file or directory
    179 | #include "nrf5340_cpuapp_partition_conf.dts"
    | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    compilation terminated.
    CMake Error at C:/Zypher/v1.3.0/zephyr/cmake/dts.cmake:146 (message):
    command failed with return code: 1
    Call Stack (most recent call first):
    C:/Zypher/v1.3.0/zephyr/cmake/app/boilerplate.cmake:505 (include)
    C:/Zypher/v1.3.0/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:24 (include)
    C:/Zypher/v1.3.0/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:35 (include_boilerplate)
    CMakeLists.txt:13 (find_package)

    error: cmake failed
    create_nordic_project.py failed (1)

    Thank you

    Kind regards

    Mohamed

  • Hi,

     

    Learner said:
    -- Found BOARD.dts: C:/Zypher/v1.3.0/zephyr/boards/arm/PID4_nRF5340/nrf5340pdk_nrf5340_cpuapp.dts

    Is this a board that you have defined?

    Learner said:
    C:/Zypher/v1.3.0/zephyr/boards/arm/PID4_nRF5340/nrf5340_cpuapp_common.dts:179:10: fatal error: nrf5340_cpuapp_partition_conf.dts: No such file or directory
    179 | #include "nrf5340_cpuapp_partition_conf.dts"

    Does this file exist in your PID4_nRF5340/ folder?

     

    Kind regards,

    Håkon 

  • Hi Hakon,

    Learner said:
    -- Found BOARD.dts: C:/Zypher/v1.3.0/zephyr/boards/arm/PID4_nRF5340/nrf5340pdk_nrf5340_cpuapp.dts

    Is this a board that you have defined?

    It is a board that is being defined but not complete yet.  It is work in progress and I was not expecting this board to be picked up. The board intended to be used is the nRF5340pdk_nRF5340.                     C:\Zypher\v1.3.0\zephyr\boards\arm\nrf5340pdk_nrf5340

    Learner said:
    C:/Zypher/v1.3.0/zephyr/boards/arm/PID4_nRF5340/nrf5340_cpuapp_common.dts:179:10: fatal error: nrf5340_cpuapp_partition_conf.dts: No such file or directory
    179 | #include "nrf5340_cpuapp_partition_conf.dts"

    Does this file exist in your PID4_nRF5340/ folder?

    No, it does not exist.

    Kind regards

    Mohamed

Reply
  • Hi Hakon,

    Learner said:
    -- Found BOARD.dts: C:/Zypher/v1.3.0/zephyr/boards/arm/PID4_nRF5340/nrf5340pdk_nrf5340_cpuapp.dts

    Is this a board that you have defined?

    It is a board that is being defined but not complete yet.  It is work in progress and I was not expecting this board to be picked up. The board intended to be used is the nRF5340pdk_nRF5340.                     C:\Zypher\v1.3.0\zephyr\boards\arm\nrf5340pdk_nrf5340

    Learner said:
    C:/Zypher/v1.3.0/zephyr/boards/arm/PID4_nRF5340/nrf5340_cpuapp_common.dts:179:10: fatal error: nrf5340_cpuapp_partition_conf.dts: No such file or directory
    179 | #include "nrf5340_cpuapp_partition_conf.dts"

    Does this file exist in your PID4_nRF5340/ folder?

    No, it does not exist.

    Kind regards

    Mohamed

Children
  • Hi,

     

    Do you still get the same issue if you move this board out of the boards/arm folder? If it is work-in-progress, it might be that the build system picks it up, especially if the names within the folder isn't changed.

     

    Kind regards,

    Håkon

  • Hi Hakon,

    Both SES v452c and v510d are behaving themselves now :), meaning I can open and build the project with this commented out line 

    #CONFIG_BOARD_ENABLE_CPUNET=n

    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. See pictures and error log below.

    Have you come across this problem before?

    What am I doing wrong?

    Could it be something to do with my laptop because I have not restarted it for over a week now?

    Loading solution light_controller-Pot.emProject
    Executing load commands
    cmake -GNinja -DBOARD=nrf5340pdk_nrf5340_cpuapp -DBOARD_DIR=C:/Zypher/v1.3.0/zephyr/boards/arm/nrf5340pdk_nrf5340 -DZEPHYR_TOOLCHAIN_VARIANT=gnuarmemb -DGNUARMEMB_TOOLCHAIN_PATH=C:/Zypher/v1.3.0/toolchain/opt -BC:/Dev/NCS_projects/light_controller-Pot/build_nrf5340pdk_nrf5340_cpuapp -HC:/Dev/NCS_projects/light_controller-Pot -DEXTRA_KCONFIG_TARGETS=menuconfig_ses -DEXTRA_KCONFIG_TARGET_COMMAND_FOR_menuconfig_ses=C:/Zypher/v1.3.0/toolchain/segger_embedded_studio/html/configure_nordic_project_menuconfig.py
    Including boilerplate (Zephyr base (cached)): C:/Zypher/v1.3.0/zephyr/cmake/app/boilerplate.cmake
    -- Application: C:/Dev/NCS_projects/light_controller-Pot
    -- Zephyr version: 2.3.0-rc1 (C:/Zypher/v1.3.0/zephyr)
    CMake Error at C:/Zypher/v1.3.0/zephyr/cmake/extensions.cmake:926 (file):
      file failed to open for writing (Permission denied):
    
        C:/Dev/NCS_projects/light_controller-Pot/build_nrf5340pdk_nrf5340_cpuapp/zephyr/include/generated/snippets-sections.ld
    Call Stack (most recent call first):
      C:/Zypher/v1.3.0/zephyr/cmake/app/boilerplate.cmake:134 (zephyr_linker_sources)
      C:/Zypher/v1.3.0/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:24 (include)
      C:/Zypher/v1.3.0/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:40 (include_boilerplate)
      CMakeLists.txt:3 (find_package)
    
    
    CMake Error at C:/Zypher/v1.3.0/zephyr/cmake/extensions.cmake:927 (file):
      file failed to open for writing (Permission denied):
    
        C:/Dev/NCS_projects/light_controller-Pot/build_nrf5340pdk_nrf5340_cpuapp/zephyr/include/generated/snippets-ram-sections.ld
    Call Stack (most recent call first):
      C:/Zypher/v1.3.0/zephyr/cmake/app/boilerplate.cmake:134 (zephyr_linker_sources)
      C:/Zypher/v1.3.0/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:24 (include)
      C:/Zypher/v1.3.0/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:40 (include_boilerplate)
      CMakeLists.txt:3 (find_package)
    
    
    CMake Error at C:/Zypher/v1.3.0/zephyr/cmake/extensions.cmake:928 (file):
      file failed to open for writing (Permission denied):
    
        C:/Dev/NCS_projects/light_controller-Pot/build_nrf5340pdk_nrf5340_cpuapp/zephyr/include/generated/snippets-rom-start.ld
    Call Stack (most recent call first):
      C:/Zypher/v1.3.0/zephyr/cmake/app/boilerplate.cmake:134 (zephyr_linker_sources)
      C:/Zypher/v1.3.0/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:24 (include)
      C:/Zypher/v1.3.0/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:40 (include_boilerplate)
      CMakeLists.txt:3 (find_package)
    
    
    CMake Error at C:/Zypher/v1.3.0/zephyr/cmake/extensions.cmake:929 (file):
      file failed to open for writing (Permission denied):
    
        C:/Dev/NCS_projects/light_controller-Pot/build_nrf5340pdk_nrf5340_cpuapp/zephyr/include/generated/snippets-noinit.ld
    Call Stack (most recent call first):
      C:/Zypher/v1.3.0/zephyr/cmake/app/boilerplate.cmake:134 (zephyr_linker_sources)
      C:/Zypher/v1.3.0/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:24 (include)
      C:/Zypher/v1.3.0/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:40 (include_boilerplate)
      CMakeLists.txt:3 (find_package)
    
    
    CMake Error at C:/Zypher/v1.3.0/zephyr/cmake/extensions.cmake:930 (file):
      file failed to open for writing (Permission denied):
    
        C:/Dev/NCS_projects/light_controller-Pot/build_nrf5340pdk_nrf5340_cpuapp/zephyr/include/generated/snippets-rwdata.ld
    Call Stack (most recent call first):
      C:/Zypher/v1.3.0/zephyr/cmake/app/boilerplate.cmake:134 (zephyr_linker_sources)
      C:/Zypher/v1.3.0/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:24 (include)
      C:/Zypher/v1.3.0/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:40 (include_boilerplate)
      CMakeLists.txt:3 (find_package)
    
    
    CMake Error at C:/Zypher/v1.3.0/zephyr/cmake/extensions.cmake:931 (file):
      file failed to open for writing (Permission denied):
    
        C:/Dev/NCS_projects/light_controller-Pot/build_nrf5340pdk_nrf5340_cpuapp/zephyr/include/generated/snippets-rodata.ld
    Call Stack (most recent call first):
      C:/Zypher/v1.3.0/zephyr/cmake/app/boilerplate.cmake:134 (zephyr_linker_sources)
    -- Board: nrf5340pdk_nrf5340_cpuapp
      C:/Zypher/v1.3.0/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:24 (include)
      C:/Zypher/v1.3.0/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:40 (include_boilerplate)
      CMakeLists.txt:3 (find_package)
    
    
    -- Found west: C:/Zypher/v1.3.0/toolchain/opt/bin/Scripts/west.exe (found suitable version "0.7.3", minimum required is "0.7.1")
    -- Found toolchain: gnuarmemb (C:/Zypher/v1.3.0/toolchain/opt)
    CMake Error at C:/Zypher/v1.3.0/zephyr/cmake/dts.cmake:3 (file):
      file problem creating directory:
      C:/Dev/NCS_projects/light_controller-Pot/build_nrf5340pdk_nrf5340_cpuapp/zephyr/include/generated
    Call Stack (most recent call first):
      C:/Zypher/v1.3.0/zephyr/cmake/app/boilerplate.cmake:505 (include)
      C:/Zypher/v1.3.0/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:24 (include)
      C:/Zypher/v1.3.0/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:40 (include_boilerplate)
      CMakeLists.txt:3 (find_package)
    
    
    -- Found BOARD.dts: C:/Zypher/v1.3.0/zephyr/boards/arm/nrf5340pdk_nrf5340/nrf5340pdk_nrf5340_cpuapp.dts
    cc1.exe: fatal error: opening output file C:/Dev/NCS_projects/light_controller-Pot/build_nrf5340pdk_nrf5340_cpuapp/zephyr/nrf5340pdk_nrf5340_cpuapp.dts.pre.tmp: Permission denied
    compilation terminated.
    CMake Error at C:/Zypher/v1.3.0/zephyr/cmake/dts.cmake:146 (message):
      command failed with return code: 1
    Call Stack (most recent call first):
      C:/Zypher/v1.3.0/zephyr/cmake/app/boilerplate.cmake:505 (include)
      C:/Zypher/v1.3.0/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:24 (include)
      C:/Zypher/v1.3.0/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:40 (include_boilerplate)
      CMakeLists.txt:3 (find_package)
    
    
    -- Configuring incomplete, errors occurred!
    Project load failed
    Reported error: solution load command failed (1)
    

    Kind regards

    Mohamed

  • Hi,

      

    Learner said:
    Both SES v452c and v510d are behaving themselves now :),

    Great!

       

    Learner said:

    Have you come across this problem before?

    What am I doing wrong?

    The log states that you have permission error:

    "file failed to open for writing (Permission denied)" 

     

    Try deleting the build folder and re-import the project.

     

    Kind regards,

    Håkon

  • Hi Hakon,

    The log states that you have permission error:

    This does not make sense since I have admin rights on my machine. Plus, this problem is intermittent, one minute I don't have permission and the next I have full permission. It is frustrating and time consuming.

    ry deleting the build folder and re-import the project.

    I do try to delete the build folder, again it does not make sense, sometimes I can and at other times I am not allowed to delete the folder build/zephyr. I can delete its content but not the folder itself Disappointed.

    Has this type pf problems been reported by other users? I know a colleague of mine is having similar issues.

    It would be greatly appreciated if you could help us come to the bottom of this and find the root cause. Because I  know I will be facing the same problem soon.

    Kind regards

    Mohamed

  • Hi,

     

    Learner said:
    This does not make sense since I have admin rights on my machine. Plus, this problem is intermittent, one minute I don't have permission and the next I have full permission. It is frustrating and time consuming.

    If there's some program (notepad or similar) that has opened up one of the files in the build folder, windows will not allow you to delete the file.

    Could this be the case here? There's a process keeping one of the files open?

     

    Learner said:
    I do try to delete the build folder, again it does not make sense, sometimes I can and at other times I am not allowed to delete the folder build/zephyr. I can delete its content but not the folder itself

    This sounds like a process is keeping the folder open. Its a generic problem on windows:

    https://superuser.com/questions/1333118/cant-delete-empty-folder-because-it-is-used

     

    Kind regards,

    Håkon 

Related