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,

     

    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

  • 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

Reply Children
  • 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 

  • 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

Related