SPI for nrf5340dk in ncsv2.8

nrfConnectSDK V2.8

Toolchain

Board: nrf5340dk

Hi, while compiling ncs-spi-master-slave-example , I am getting below errors

In function 'spi_init':
C:/Users/hello/spi/src/main.c:34:8: error: macro "GPIO_DT_SPEC_GET_BY_IDX_OR" requires 4 arguments, but only 3 given
34 | struct gpio_dt_spec spim_cs_gpio = MY_SPI_MASTER_CS_DT_SPEC;


In file included from C:/Users/hello/spi/src/main.c:11:
C:/ncs/v2.8.0/zephyr/include/zephyr/drivers/spi.h:213:9: error: 'GPIO_DT_SPEC_GET_BY_IDX_OR' undeclared (first use in this function)
213 | GPIO_DT_SPEC_GET_BY_IDX_OR(DT_BUS(spi_dev), cs_gpios, \

C:/Users/hello/spi/src/main.c:44:8: error: macro "GPIO_DT_SPEC_GET_BY_IDX_OR" requires 4 arguments, but only 3 given
44 | .cs = {.gpio = MY_SPI_MASTER_CS_DT_SPEC, .delay = 0},

C:/ncs/v2.8.0/zephyr/include/zephyr/drivers/spi.h:213:9: error: 'GPIO_DT_SPEC_GET_BY_IDX_OR' undeclared here (not in a function)
213 | GPIO_DT_SPEC_GET_BY_IDX_OR(DT_BUS(spi_dev), cs_gpios, \

Is it related to sdk version? Can anyone help to resolve ?

Parents
  • Hi,

    I recommend you go through the SPI lesson on our academy pages https://academy.nordicsemi.com/courses/nrf-connect-sdk-intermediate/lessons/lesson-5-serial-peripheral-interface-spi/ as well as the sysbuild exercise https://academy.nordicsemi.com/courses/nrf-connect-sdk-intermediate/lessons/lesson-8-sysbuild/topic/sysbuild-explained/.

    The unofficial sample that you're using will unfortunately not be maintained and upgraded to support any newer release and the latest version this sample was supported for is NCS older than v2.7.0 as far as I can see.

    The only resolution for you is to go through the two supplied links, understand the topics and apply the required changes to the sample you've based the application on.

    Kind regards,
    Andreas

  • Hi, We want a design where we want use 2 spi buses for 4 slaves.

    &pinctrl {
    	spi_master1_default: spi_master1_default {
    		group1 {
    			psels = <NRF_PSEL(SPIM_SCK, 1, 15)>,
    					<NRF_PSEL(SPIM_MOSI, 1, 13)>,
    					<NRF_PSEL(SPIM_MISO, 1, 14)>;
    		};
    	};
    
    	spi_master1_sleep: spi_master1_sleep {
    		group1 {
    			psels = <NRF_PSEL(SPIM_SCK, 1, 15)>,
    					<NRF_PSEL(SPIM_MOSI, 1, 13)>,
    					<NRF_PSEL(SPIM_MISO, 1, 14)>;
    			low-power-enable;
    		};
    	};
    	
    	spi_master0_default: spi_master0_default {
    		group1 {
    			psels = <NRF_PSEL(SPIM_SCK, 0, 8)>,
    					<NRF_PSEL(SPIM_MOSI, 0, 9)>,
    					<NRF_PSEL(SPIM_MISO, 0, 10)>;
    		};
    	};
    
    	spi_master0_sleep: spi_master0_sleep {
    		group1 {
    			psels = <NRF_PSEL(SPIM_SCK, 0, 8)>,
    					<NRF_PSEL(SPIM_MOSI, 0, 9)>,
    					<NRF_PSEL(SPIM_MISO, 0, 10)>;
    			low-power-enable;
    		};
    	};
    	
    };
    
    &gpio0 {
    	status = "okay";
    };
    
    &gpio1 {
    	status = "okay";
    };
    
    &spi4 {
    	compatible = "nordic,nrf-spim";
    	status = "okay";
    	pinctrl-0 = <&spi_master1_default>;
    	pinctrl-1 = <&spi_master1_sleep>;
    	pinctrl-names = "default", "sleep";
    	/*cs-gpios = <&gpio1 12 GPIO_ACTIVE_LOW>, 	
    			   <&gpio1 10 GPIO_ACTIVE_LOW>;	
    			   
    	reg_spi_master1: spi-dev-a@0 {
    		reg = <0>;
    		compatible = "spi-device";
    	};
    	
    	reg_spi_master2: spi-dev-a@1 {
    		reg = <1>;
    		compatible = "spi-device";
    	};*/
    };
    
    
    &spi0{
    	compatible = "nordic,nrf-spim";
    	status = "okay";
    	pinctrl-0 = <&spi0_default>;
    	pinctrl-1 = <&spi0_sleep>;
    	pinctrl-names = "default", "sleep";
    	
    	/*cs-gpios = <&gpio0 11 GPIO_ACTIVE_LOW>, 	
    			   <&gpio0 19 GPIO_ACTIVE_LOW>;		
    			   
    	reg_spi0_master1: spi-dev-a@0 {
    		reg = <0>;
    	};
    	
    	reg_spi0_master2: spi-dev-b@1 {
    		reg = <1>;
    	};*/
    
    };
    
    When configuring like above in overlay
    In main 
    
    #define SPI1_MASTER                         DT_NODELABEL(spi4)
    #define SPI0_MASTER                         DT_NODELABEL(spi0)
    #define SPI0_MASTER_CS_GPIO                 DT_NODELABEL(gpio0)
    #define SPI1_MASTER_CS_GPIO                 DT_NODELABEL(gpio1)
    
    
    const struct device *spi_dev;
    const struct device *gpio_dev;
    
    
    struct spi_config spi_cfg={
    .operation = SPI_WORD_SET(8) | SPI_TRANSFER_MSB | SPI_MODE_CPOL | SPI_MODE_CPHA,
    .frequency = 4000000,
    .slave = 0,
    };
    
    
    void Init(uint8_t slave)
    {
            spi_dev = DEVICE_DT_GET(SPI0_MASTER);
            gpio_dev = DEVICE_DT_GET(SPI0_MASTER_CS_GPIO);
    
            spi_cfg.cs.gpio.port=gpio_dev;
            spi_cfg.cs.gpio.pin = 11;
            spi_cfg.cs.gpio.dt_flags = GPIO_ACTIVE_HIGH;
    
    }
    
    Giving error only for SPI0_MASTER. when all are SPI1_MASTER, it is building
    
    error: '__device_dts_ord_105' undeclared (first use in this function); did you mean '__device_dts_ord_15'?
       92 | #define DEVICE_NAME_GET(dev_id) _CONCAT(__device_, dev_id)
          |                                         ^~~~~~~~~
    C:/ncs/v2.8.0/zephyr/include/zephyr/toolchain/common.h:137:26: note: in definition of macro '_DO_CONCAT'
      137 | #define _DO_CONCAT(x, y) x ## y
          |                          ^
    C:/ncs/v2.8.0/zephyr/include/zephyr/device.h:92:33: note: in expansion of macro '_CONCAT'
       92 | #define DEVICE_NAME_GET(dev_id) _CONCAT(__device_, dev_id)
          |                                 ^~~~~~~
    C:/ncs/v2.8.0/zephyr/include/zephyr/device.h:229:37: note: in expansion of macro 'DEVICE_NAME_GET'
      229 | #define DEVICE_DT_NAME_GET(node_id) DEVICE_NAME_GET(Z_DEVICE_DT_DEV_ID(node_id))
          |                                     ^~~~~~~~~~~~~~~
    C:/ncs/v2.8.0/zephyr/include/zephyr/device.h:246:34: note: in expansion of macro 'DEVICE_DT_NAME_GET'
      246 | #define DEVICE_DT_GET(node_id) (&DEVICE_DT_NAME_GET(node_id))
          |                                  ^~~~~~~~~~~~~~~~~~
    C:/Users/nrf_Projects/ad_spi/src/main.c:40:19: note: in expansion of macro 'DEVICE_DT_GET'
       40 |         spi_dev = DEVICE_DT_GET(SPI0_MASTER);
          |                   ^~~~~~~~~~~~~
    C:/ncs/v2.8.0/zephyr/include/zephyr/device.h:92:41: note: each undeclared identifier is reported only once for each function it appears in
       92 | #define DEVICE_NAME_GET(dev_id) _CONCAT(__device_, dev_id)
          |                                         ^~~~~~~~~
    C:/ncs/v2.8.0/zephyr/include/zephyr/toolchain/common.h:137:26: note: in definition of macro '_DO_CONCAT'
      137 | #define _DO_CONCAT(x, y) x ## y
          |                          ^
    C:/ncs/v2.8.0/zephyr/include/zephyr/device.h:92:33: note: in expansion of macro '_CONCAT'
       92 | #define DEVICE_NAME_GET(dev_id) _CONCAT(__device_, dev_id)
          |                                 ^~~~~~~
    C:/ncs/v2.8.0/zephyr/include/zephyr/device.h:229:37: note: in expansion of macro 'DEVICE_NAME_GET'
      229 | #define DEVICE_DT_NAME_GET(node_id) DEVICE_NAME_GET(Z_DEVICE_DT_DEV_ID(node_id))
          |                                     ^~~~~~~~~~~~~~~
    C:/ncs/v2.8.0/zephyr/include/zephyr/device.h:246:34: note: in expansion of macro 'DEVICE_DT_NAME_GET'
      246 | #define DEVICE_DT_GET(node_id) (&DEVICE_DT_NAME_GET(node_id))
          |                                  ^~~~~~~~~~~~~~~~~~
    C:/Users/nrf_Projects/ad_spi/src/main.c:40:19: note: in expansion of macro 'DEVICE_DT_GET'
       40 |         spi_dev = DEVICE_DT_GET(SPI0_MASTER);
    
    
    /*
    In overlay file
    spi1_master:&spi4 {
    	compatible = "nordic,nrf-spim";
    	status = "okay";
    	pinctrl-0 = <&spi_master1_default>;
    	pinctrl-1 = <&spi_master1_sleep>;
    	pinctrl-names = "default", "sleep";
    	cs-gpios = <&gpio1 12 GPIO_ACTIVE_LOW>, 	
    			   <&gpio1 10 GPIO_ACTIVE_LOW>;	
    			   
    	reg_spi_master1: spi-dev-a@0 {
    		reg = <0>;
    		compatible = "spi-device";
    	};
    	
    	reg_spi_master2: spi-dev-a@1 {
    		reg = <1>;
    		compatible = "spi-device";
    	};
    };
    In main 
    #define SPI1_MASTER                         DT_NODELABEL(spi1_master)
    spi_dev = DEVICE_DT_GET(SPI1_MASTER);
    
    
    Giving below error
    error: '__device_dts_ord_DT_N_NODELABEL_spi1_master_ORD' undeclared (first use in this function)
       92 | #define DEVICE_NAME_GET(dev_id) _CONCAT(__device_, dev_id)
          |                                         ^~~~~~~~~
    C:/ncs/v2.8.0/zephyr/include/zephyr/toolchain/common.h:137:26: note: in definition of macro '_DO_CONCAT'
      137 | #define _DO_CONCAT(x, y) x ## y
          |                          ^
    C:/ncs/v2.8.0/zephyr/include/zephyr/device.h:92:33: note: in expansion of macro '_CONCAT'
       92 | #define DEVICE_NAME_GET(dev_id) _CONCAT(__device_, dev_id)
          |                                 ^~~~~~~
    C:/ncs/v2.8.0/zephyr/include/zephyr/device.h:229:37: note: in expansion of macro 'DEVICE_NAME_GET'
      229 | #define DEVICE_DT_NAME_GET(node_id) DEVICE_NAME_GET(Z_DEVICE_DT_DEV_ID(node_id))
          |                                     ^~~~~~~~~~~~~~~
    C:/ncs/v2.8.0/zephyr/include/zephyr/device.h:246:34: note: in expansion of macro 'DEVICE_DT_NAME_GET'
      246 | #define DEVICE_DT_GET(node_id) (&DEVICE_DT_NAME_GET(node_id))
          |                                  ^~~~~~~~~~~~~~~~~~
    C:/Users/nrf_Projects/spi/src/main.c:40:19: note: in expansion of macro 'DEVICE_DT_GET'
       40 |         spi_dev = DEVICE_DT_GET(SPI1_MASTER);
          |                   ^~~~~~~~~~~~~
    C:/ncs/v2.8.0/zephyr/include/zephyr/device.h:92:41: note: each undeclared identifier is reported only once for each function it appears in
       92 | #define DEVICE_NAME_GET(dev_id) _CONCAT(__device_, dev_id)
          |                                         ^~~~~~~~~
    C:/ncs/v2.8.0/zephyr/include/zephyr/toolchain/common.h:137:26: note: in definition of macro '_DO_CONCAT'
      137 | #define _DO_CONCAT(x, y) x ## y
          |                          ^
    C:/ncs/v2.8.0/zephyr/include/zephyr/device.h:92:33: note: in expansion of macro '_CONCAT'
       92 | #define DEVICE_NAME_GET(dev_id) _CONCAT(__device_, dev_id)
          |                                 ^~~~~~~
    C:/ncs/v2.8.0/zephyr/include/zephyr/device.h:229:37: note: in expansion of macro 'DEVICE_NAME_GET'
      229 | #define DEVICE_DT_NAME_GET(node_id) DEVICE_NAME_GET(Z_DEVICE_DT_DEV_ID(node_id))
          |                                     ^~~~~~~~~~~~~~~
    C:/ncs/v2.8.0/zephyr/include/zephyr/device.h:246:34: note: in expansion of macro 'DEVICE_DT_NAME_GET'
      246 | #define DEVICE_DT_GET(node_id) (&DEVICE_DT_NAME_GET(node_id))
          |                                  ^~~~~~~~~~~~~~~~~~
    C:/Users/nrf_Projects/spi/src/main.c:40:19: note: in expansion of macro 'DEVICE_DT_GET'
       40 |         spi_dev = DEVICE_DT_GET(SPI1_MASTER);
          |                   ^~~~~~~~~~~~~
    */
    
    

    Can you once check above attached file??

    Is there any zephyr spi sample example for nrf5340 for multiple slaves?

    Thankyou

  • Hi,

    I tried again to build the same example by selecting nrf5340dk/nrf5340/cpuapp in Board target when adding build configuration. still getting the below errors.

    Executing task: nRF Connect: Generate config nrf5340dk/nrf5340/cpuapp for c:\Users\hello\Music\ncs-spi-master-slave-example-master
    
    Building ncs-spi-master-slave-example-master
    C:\Windows\system32\cmd.exe /d /s /c "west build --build-dir c:/Users/hello/ncs-spi-master-slave-example-master/build c:/Users/hello/ncs-spi-master-slave-example-master --pristine --board nrf5340dk/nrf5340/cpuapp -- -DNCS_TOOLCHAIN_VERSION=NONE -DBOARD_ROOT=c:/users/hello/ncs-spi-master-slave-example-master"
    
    -- west build: generating a build system
    Loading Zephyr module(s) (Zephyr base): sysbuild_default
    -- Found Python3: C:/ncs/toolchains/2d382dcd92/opt/bin/python.exe (found suitable version "3.12.4", minimum required is "3.8") found components: Interpreter
    -- Cache files will be written to: C:/ncs/v2.8.0/zephyr/.cache
    -- Found west (found suitable version "1.2.0", minimum required is "0.14.0")
    -- Board: nrf5340dk, qualifiers: nrf5340/cpuapp
    Parsing C:/ncs/v2.8.0/zephyr/share/sysbuild/Kconfig
    Loaded configuration 'C:/Users/hello/ncs-spi-master-slave-example-master/build/_sysbuild/empty.conf'
    Merged configuration 'C:/Users/hello/ncs-spi-master-slave-example-master/build/_sysbuild/empty.conf'
    Configuration saved to 'C:/Users/hello/ncs-spi-master-slave-example-master/build/zephyr/.config'
    Kconfig header saved to 'C:/Users/hello/ncs-spi-master-slave-example-master/build/_sysbuild/autoconf.h'
    --
    *********************************************************
    * Running CMake for ncs-spi-master-slave-example-master *
    *********************************************************
    
    Loading Zephyr default modules (Zephyr base).
    -- Application: C:/Users/hello/ncs-spi-master-slave-example-master
    -- CMake version: 3.21.0
    -- Found Python3: C:/ncs/toolchains/2d382dcd92/opt/bin/python.exe (found suitable version "3.12.4", minimum required is "3.8") found components: Interpreter
    -- Cache files will be written to: C:/ncs/v2.8.0/zephyr/.cache
    -- Zephyr version: 3.7.99 (C:/ncs/v2.8.0/zephyr)
    -- Found west (found suitable version "1.2.0", minimum required is "0.14.0")
    -- Board: nrf5340dk, qualifiers: nrf5340/cpuapp
    -- Found host-tools: zephyr 0.16.8 (C:/ncs/toolchains/2d382dcd92/opt/zephyr-sdk)
    -- Found toolchain: zephyr 0.16.8 (C:/ncs/toolchains/2d382dcd92/opt/zephyr-sdk)
    -- Found Dtc: C:/ncs/toolchains/2d382dcd92/opt/bin/dtc.exe (found suitable version "1.4.7", minimum required is "1.4.6")
    -- Found BOARD.dts: C:/ncs/v2.8.0/zephyr/boards/nordic/nrf5340dk/nrf5340dk_nrf5340_cpuapp.dts
    -- Found devicetree overlay: C:/Users/hello/ncs-spi-master-slave-example-master/boards/nrf5340dk_nrf5340_cpuapp.overlay
    -- Generated zephyr.dts: C:/Users/hello/ncs-spi-master-slave-example-master/build/ncs-spi-master-slave-example-master/zephyr/zephyr.dts
    -- Generated devicetree_generated.h: C:/Users/hello/ncs-spi-master-slave-example-master/build/ncs-spi-master-slave-example-master/zephyr/include/generated/zephyr/devicetree_generated.h
    -- Including generated dts.cmake file: C:/Users/hello/ncs-spi-master-slave-example-master/build/ncs-spi-master-slave-example-master/zephyr/dts.cmake
    
    warning: Experimental symbol SPI_SLAVE is enabled.
    
    Parsing C:/ncs/v2.8.0/zephyr/Kconfig
    Loaded configuration 'C:/ncs/v2.8.0/zephyr/boards/nordic/nrf5340dk/nrf5340dk_nrf5340_cpuapp_defconfig'
    Merged configuration 'C:/Users/hello/ncs-spi-master-slave-example-master/prj.conf'
    Merged configuration 'C:/Users/hello/ncs-spi-master-slave-example-master/build/ncs-spi-master-slave-example-master/zephyr/.config.sysbuild'
    Configuration saved to 'C:/Users/hello/ncs-spi-master-slave-example-master/build/ncs-spi-master-slave-example-master/zephyr/.config'
    Kconfig header saved to 'C:/Users/hello/ncs-spi-master-slave-example-master/build/ncs-spi-master-slave-example-master/zephyr/include/generated/zephyr/autoconf.h'
    -- Found GnuLd: c:/ncs/toolchains/2d382dcd92/opt/zephyr-sdk/arm-zephyr-eabi/arm-zephyr-eabi/bin/ld.bfd.exe (found version "2.38")
    -- The C compiler identification is GNU 12.2.0
    -- The CXX compiler identification is GNU 12.2.0
    -- The ASM compiler identification is GNU
    -- Found assembler: C:/ncs/toolchains/2d382dcd92/opt/zephyr-sdk/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc.exe
    -- Setting build type to 'MinSizeRel' as none was specified.
    -- Configuring done
    -- Generating done
    -- Build files have been written to: C:/Users/hello/ncs-spi-master-slave-example-master/build/ncs-spi-master-slave-example-master
    -- Configuring done
    -- Generating done
    -- Build files have been written to: C:/Users/hello/ncs-spi-master-slave-example-master/build
    -- west build: building application
    [4/150] Generating include/generated/zephyr/version.h
    -- Zephyr version: 3.7.99 (C:/ncs/v2.8.0/zephyr), build: v3.7.99-ncs1
    [17/150] Building C object CMakeFiles/app.dir/src/main.c.obj
    FAILED: CMakeFiles/app.dir/src/main.c.obj
    C:\ncs\toolchains\2d382dcd92\opt\zephyr-sdk\arm-zephyr-eabi\bin\arm-zephyr-eabi-gcc.exe -DKERNEL -DK_HEAP_MEM_POOL_SIZE=0 -DNRF5340_XXAA_APPLICATION -DNRF_SKIP_FICR_NS_COPY_TO_RAM -DPICOLIBC_LONG_LONG_PRINTF_SCANF -DUSE_PARTITION_MANAGER=1 -D__LINUX_ERRNO_EXTENSIONS__ -D__PROGRAM_START -D__ZEPHYR__=1 -IC:/Users/hello/ncs-spi-master-slave-example-master/build/ncs-spi-master-slave-example-master/zephyr/include/generated/zephyr -IC:/ncs/v2.8.0/zephyr/include -IC:/Users/hello/ncs-spi-master-slave-example-master/build/ncs-spi-master-slave-example-master/zephyr/include/generated -IC:/ncs/v2.8.0/zephyr/soc/nordic -IC:/ncs/v2.8.0/zephyr/soc/nordic/nrf53/. -IC:/ncs/v2.8.0/zephyr/soc/nordic/common/. -IC:/ncs/v2.8.0/nrf/include -IC:/ncs/v2.8.0/nrf/tests/include -IC:/ncs/v2.8.0/modules/hal/cmsis/CMSIS/Core/Include -IC:/ncs/v2.8.0/zephyr/modules/cmsis/. -IC:/ncs/v2.8.0/modules/hal/nordic/nrfx -IC:/ncs/v2.8.0/modules/hal/nordic/nrfx/drivers/include -IC:/ncs/v2.8.0/modules/hal/nordic/nrfx/mdk -IC:/ncs/v2.8.0/zephyr/modules/hal_nordic/nrfx/. -isystem C:/ncs/v2.8.0/zephyr/lib/libc/common/include -isystem C:/ncs/v2.8.0/nrfxlib/crypto/nrf_cc312_platform/include -Os -DNDEBUG -fno-strict-aliasing -Os -imacros C:/Users/hello/ncs-spi-master-slave-example-master/build/ncs-spi-master-slave-example-master/zephyr/include/generated/zephyr/autoconf.h -fno-printf-return-value -fno-common -g -gdwarf-4 -fdiagnostics-color=always -mcpu=cortex-m33 -mthumb -mabi=aapcs -mfp16-format=ieee -mtp=soft --sysroot=C:/ncs/toolchains/2d382dcd92/opt/zephyr-sdk/arm-zephyr-eabi/arm-zephyr-eabi -imacros C:/ncs/v2.8.0/zephyr/include/zephyr/toolchain/zephyr_stdint.h -Wall -Wformat -Wformat-security -Wno-format-zero-length -Wdouble-promotion -Wno-pointer-sign -Wpointer-arith -Wexpansion-to-defined -Wno-unused-but-set-variable -Werror=implicit-int -fno-pic -fno-pie -fno-asynchronous-unwind-tables -ftls-model=local-exec -fno-reorder-functions --param=min-pagesize=0 -fno-defer-pop -fmacro-prefix-map=C:/Users/hello/ncs-spi-master-slave-example-master=CMAKE_SOURCE_DIR -fmacro-prefix-map=C:/ncs/v2.8.0/zephyr=ZEPHYR_BASE -fmacro-prefix-map=C:/ncs/v2.8.0=WEST_TOPDIR -ffunction-sections -fdata-sections --specs=picolibc.specs -std=c99 -MD -MT CMakeFiles/app.dir/src/main.c.obj -MF CMakeFiles\app.dir\src\main.c.obj.d -o CMakeFiles/app.dir/src/main.c.obj -c C:/Users/hello/ncs-spi-master-slave-example-master/src/main.c
    C:/Users/hello/ncs-spi-master-slave-example-master/src/main.c: In function 'spi_init':
    C:/Users/hello/ncs-spi-master-slave-example-master/src/main.c:34:8: error: macro "GPIO_DT_SPEC_GET_BY_IDX_OR" requires 4 arguments, but only 3 given
    34 | struct gpio_dt_spec spim_cs_gpio = MY_SPI_MASTER_CS_DT_SPEC;
    | ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    In file included from C:/Users/hello/ncs-spi-master-slave-example-master/src/main.c:10:
    C:/ncs/v2.8.0/zephyr/include/zephyr/drivers/gpio.h:355: note: macro "GPIO_DT_SPEC_GET_BY_IDX_OR" defined here
    355 | #define GPIO_DT_SPEC_GET_BY_IDX_OR(node_id, prop, idx, default_value) \
    |
    In file included from C:/Users/hello/ncs-spi-master-slave-example-master/src/main.c:11:
    C:/ncs/v2.8.0/zephyr/include/zephyr/drivers/spi.h:213:9: error: 'GPIO_DT_SPEC_GET_BY_IDX_OR' undeclared (first use in this function)
    213 | GPIO_DT_SPEC_GET_BY_IDX_OR(DT_BUS(spi_dev), cs_gpios, \
    | ^~~~~~~~~~~~~~~~~~~~~~~~~~
    C:/Users/hello/ncs-spi-master-slave-example-master/src/main.c:20:34: note: in expansion of macro 'SPI_CS_GPIOS_DT_SPEC_GET'
    20 | #define MY_SPI_MASTER_CS_DT_SPEC SPI_CS_GPIOS_DT_SPEC_GET(DT_NODELABEL(reg_my_spi_master))
    | ^~~~~~~~~~~~~~~~~~~~~~~~
    C:/Users/hello/ncs-spi-master-slave-example-master/src/main.c:34:44: note: in expansion of macro 'MY_SPI_MASTER_CS_DT_SPEC'
    34 | struct gpio_dt_spec spim_cs_gpio = MY_SPI_MASTER_CS_DT_SPEC;
    | ^~~~~~~~~~~~~~~~~~~~~~~~
    C:/ncs/v2.8.0/zephyr/include/zephyr/drivers/spi.h:213:9: note: each undeclared identifier is reported only once for each function it appears in
    213 | GPIO_DT_SPEC_GET_BY_IDX_OR(DT_BUS(spi_dev), cs_gpios, \
    | ^~~~~~~~~~~~~~~~~~~~~~~~~~
    C:/Users/hello/ncs-spi-master-slave-example-master/src/main.c:20:34: note: in expansion of macro 'SPI_CS_GPIOS_DT_SPEC_GET'
    20 | #define MY_SPI_MASTER_CS_DT_SPEC SPI_CS_GPIOS_DT_SPEC_GET(DT_NODELABEL(reg_my_spi_master))
    | ^~~~~~~~~~~~~~~~~~~~~~~~
    C:/Users/hello/ncs-spi-master-slave-example-master/src/main.c:34:44: note: in expansion of macro 'MY_SPI_MASTER_CS_DT_SPEC'
    34 | struct gpio_dt_spec spim_cs_gpio = MY_SPI_MASTER_CS_DT_SPEC;
    | ^~~~~~~~~~~~~~~~~~~~~~~~
    C:/Users/hello/ncs-spi-master-slave-example-master/src/main.c: At top level:
    C:/Users/hello/ncs-spi-master-slave-example-master/src/main.c:44:8: error: macro "GPIO_DT_SPEC_GET_BY_IDX_OR" requires 4 arguments, but only 3 given
    44 | .cs = {.gpio = MY_SPI_MASTER_CS_DT_SPEC, .delay = 0},
    | ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    C:/ncs/v2.8.0/zephyr/include/zephyr/drivers/gpio.h:355: note: macro "GPIO_DT_SPEC_GET_BY_IDX_OR" defined here
    355 | #define GPIO_DT_SPEC_GET_BY_IDX_OR(node_id, prop, idx, default_value) \
    |
    C:/ncs/v2.8.0/zephyr/include/zephyr/drivers/spi.h:213:9: error: 'GPIO_DT_SPEC_GET_BY_IDX_OR' undeclared here (not in a function)
    213 | GPIO_DT_SPEC_GET_BY_IDX_OR(DT_BUS(spi_dev), cs_gpios, \
    | ^~~~~~~~~~~~~~~~~~~~~~~~~~
    C:/Users/hello/ncs-spi-master-slave-example-master/src/main.c:20:34: note: in expansion of macro 'SPI_CS_GPIOS_DT_SPEC_GET'
    20 | #define MY_SPI_MASTER_CS_DT_SPEC SPI_CS_GPIOS_DT_SPEC_GET(DT_NODELABEL(reg_my_spi_master))
    | ^~~~~~~~~~~~~~~~~~~~~~~~
    C:/Users/hello/ncs-spi-master-slave-example-master/src/main.c:44:24: note: in expansion of macro 'MY_SPI_MASTER_CS_DT_SPEC'
    44 | .cs = {.gpio = MY_SPI_MASTER_CS_DT_SPEC, .delay = 0},
    | ^~~~~~~~~~~~~~~~~~~~~~~~
    [21/150] Building C object zephyr/CMakeFiles/zephyr.dir/lib/os/cbprintf_packaged.c.obj
    ninja: build stopped: subcommand failed.
    FAILED: _sysbuild/sysbuild/images/ncs-spi-master-slave-example-master-prefix/src/ncs-spi-master-slave-example-master-stamp/ncs-spi-master-slave-example-master-build C:/Users/hello/ncs-spi-master-slave-example-master/build/_sysbuild/sysbuild/images/ncs-spi-master-slave-example-master-prefix/src/ncs-spi-master-slave-example-master-stamp/ncs-spi-master-slave-example-master-build
    cmd.exe /C "cd /D C:\Users\hello\Music\ncs-spi-master-slave-example-master\build\ncs-spi-master-slave-example-master && C:\ncs\toolchains\2d382dcd92\opt\bin\cmake.exe --build ."
    ninja: build stopped: subcommand failed.
    FATAL ERROR: command exited with status 1: 'C:\ncs\toolchains\2d382dcd92\opt\bin\cmake.EXE' --build C:/Users/hello/ncs-spi-master-slave-example-master/build...

    Didn't make any changes to the example.

    Also can you once check the configurations in my before post ?

  • KTH said:
    I tried again to build the same example by selecting nrf5340dk/nrf5340/cpuapp in Board target when adding build configuration. still getting the below errors.

    You're referring to an unmodified version this sample, right? https://github.com/too1/ncs-spi-master-slave-example/tree/master/src 

    If so, please try again but first delete the build folder before building again. I'm not getting any faulty builds for any versions of NCS from NCS 2.5.0 to NCS 2.9.0 

    Kind regards,
    Andreas

  • Tried to build again like you mentioned by deleting the build folder before building again, still same.

    Previously also, downloaded the example again and tried to build it.

  • Strange.. And the errors you're getting is the same as the initial comment in this post?

    Please describe in detail every step you do to build the sample. Images are also welcome.

    Kind regards,
    Andreas

  • Hi,Here are the images of the building the sample

Reply Children
  • Ah, thank you for providing this. You're building for the /ns target of the nRF5340DK. Currently there are no board files for this within the board folder meaning that the SPI configuration is not set up for the build target you're trying to target

    Please try again with this target and let me know if this compiles

    Kind regards,
    Andreas

  • Hi, tried building with target nrf5340dk/nrf5340/cpuapp selected, still giving errors.

    Not able to build zephyr ADC examples also

  • Hi

    Lets start with the ADC sample first. This sample work for at least the supported boards. Lets focus on the adc_sequence sample within zephyr/samples/drivers/adc.

    KTH said:
    Not able to build zephyr ADC examples also

    There are also no nRF5340 board support in the board folder of this sample. It works with any of the boards found within adc_sequence/boards, for instance with nrf52840dk/nrf52840 (below is a result with build from terminal and list of the boards found in the boards folder of this sample. The same can be stated for the VS Code extension).

    If you remove and build for the nrf52840dk, do you see the error as you previously did? If you do, then I believe there is something wrong with your installation. Could you 1: generate support information from vs code by opening command pallette in VS Code, i.e

    1. Open VS Code
    2. Open command pallet by pressing ctrl+***+p
    3. search for "generate support information" 
    4. Select it and press enter and upload the information here

    If we get this working, then we can go back to the spi master sample from too1's git repo

    Kind regards,
    Andreas

  • Hi,

    adc_sequene sample is building with target nrf52840dk

    nrf connect generate support information is as below

    // IMPORTANT: The following data can contain sensitive or confidential information about your environment.
    // If you do not want others to see this information, make sure to remove it before sharing the data.
    
    // For help and support, visit Nordic Semiconductor's DevZone at https://devzone.nordicsemi.com/.
    
    {
      "platform": {
        "os": "win32",
        "osVersion": "Windows 11 Home Single Language",
        "osKernel": "10.0.26100",
        "vscode": "1.97.2",
        "electron": "32.2.7",
        "node": "v20.18.1"
      },
      "system": {
        "date": "2025-02-28T08:51:25.141Z",
        "vscodeRoot": "c:\\Users\\hello\\AppData\\Local\\Programs\\Microsoft VS Code\\resources\\app",
        "nrfConnectForDesktopInstalled": false,
        "vscodeUptime": "00:00:15",
        "osUptime": "98:35:17",
        "cpu": "11th Gen Intel(R) Core(TM) i3-1115G4 @ 3.00GHz"
      },
      "workspace": {
        "name": null,
        "workspaceFile": null,
        "folders": []
      },
      "sdks": [
        {
          "version": "v2.8.0",
          "path": "c:\\ncs\\v2.8.0"
        }
      ],
      "apps": [],
      "toolchains": [
        {
          "version": "2.8.0",
          "path": "c:\\ncs\\toolchains\\2d382dcd92"
        }
      ],
      "connectedDevices": [],
      "tools": {
        "C:\\ncs\\toolchains\\2d382dcd92\\opt\\zephyr-sdk\\arm-zephyr-eabi\\bin\\arm-zephyr-eabi-gcc.exe": "0.16.8",
        "C:\\Program Files\\SEGGER\\JLink_V794e\\JLink.exe": "7.94e",
        "C:\\Program Files\\Nordic Semiconductor\\nrf-command-line-tools\\bin\\nrfjprog.exe": "10.24.2",
        "C:\\ncs\\toolchains\\2d382dcd92\\cmake": "3.21.0",
        "C:\\ncs\\toolchains\\2d382dcd92\\opt\\bin\\Scripts\\west.exe": "1.2.0",
        "C:\\ncs\\toolchains\\2d382dcd92\\opt\\bin\\python.exe": "3.12.4",
        "C:\\ncs\\toolchains\\2d382dcd92\\opt\\bin\\ninja.exe": "1.10.2",
        "C:\\ncs\\toolchains\\2d382dcd92\\opt\\bin\\gperf.exe": "3.1",
        "C:\\ncs\\toolchains\\2d382dcd92\\opt\\bin\\dtc.exe": "1.4.7",
        "C:\\ncs\\toolchains\\2d382dcd92\\opt\\bin\\gn.exe": "2201",
        "C:\\ncs\\toolchains\\2d382dcd92\\mingw64\\bin\\git.exe": "2.37.3.windows.1",
        "arm-gdbPath": "c:\\ncs\\toolchains\\2d382dcd92\\opt\\zephyr-sdk\\arm-zephyr-eabi\\bin\\arm-zephyr-eabi-gdb.exe",
        "riscv-gdbPath": "C:\\ncs\\toolchains\\2d382dcd92\\opt\\zephyr-sdk\\riscv64-zephyr-elf\\bin\\riscv64-zephyr-elf-gdb.exe"
      },
      "nrfutil": {
        "nrfutil-device": {
          "version": "2.7.9",
          "binPath": "c:\\Users\\hello\\.vscode\\extensions\\nordic-semiconductor.nrf-connect-2025.1.127-win32-x64\\platform\\nrfutil\\bin\\nrfutil-device",
          "jlinkInfo": {
            "description": "This version of SEGGER J-Link is different from the J-Link version that was used to test nrfutil device commands",
            "expectedVersion": {
              "version": "JLink_V7.94i",
              "versionFormat": "string"
            },
            "name": "JlinkARM",
            "version": "JLink_V7.94e",
            "versionFormat": "string"
          }
        },
        "nrfutil-toolchain-manager": {
          "version": "0.14.4",
          "binPath": "c:\\Users\\hello\\.vscode\\extensions\\nordic-semiconductor.nrf-connect-2025.1.127-win32-x64\\platform\\nrfutil\\bin\\nrfutil-toolchain-manager"
        }
      },
      "environment": {
        "westEnv": {
          "HOME": "C:\\Users\\hello",
          "HOMEDRIVE": "C:",
          "HOMEPATH": "\\Users\\hello",
          "PATH": "C:\\ncs\\toolchains\\2d382dcd92;C:\\ncs\\toolchains\\2d382dcd92\\mingw64\\bin;C:\\ncs\\toolchains\\2d382dcd92\\bin;C:\\ncs\\toolchains\\2d382dcd92\\opt\\bin;C:\\ncs\\toolchains\\2d382dcd92\\opt\\bin\\Scripts;C:\\ncs\\toolchains\\2d382dcd92\\opt\\nanopb\\generator-bin;C:\\ncs\\toolchains\\2d382dcd92\\opt\\zephyr-sdk\\arm-zephyr-eabi\\bin;C:\\ncs\\toolchains\\2d382dcd92\\opt\\zephyr-sdk\\riscv64-zephyr-elf\\bin;c:\\Users\\hello\\.vscode\\extensions\\nordic-semiconductor.nrf-connect-2025.1.127-win32-x64\\platform\\nrfutil\\lib\\nrfutil-toolchain-manager;C:\\TwinCAT\\Common64;C:\\TwinCAT\\Common32;C:\\Program Files (x86)\\Common Files\\Oracle\\Java\\javapath;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\;C:\\WINDOWS\\System32\\OpenSSH\\;C:\\Program Files\\dotnet\\;C:\\Program Files\\Microsoft SQL Server\\150\\Tools\\Binn\\;C:\\Program Files\\Git\\cmd;C:\\Program Files\\usbipd-win\\;C:\\Program Files\\Microchip\\xc32\\v4.30\\bin;C:\\Program Files (x86)\\dotnet\\;C:\\Program Files\\Microsoft SQL Server\\130\\Tools\\Binn\\;C:\\Program Files\\Microsoft SQL Server\\Client SDK\\ODBC\\170\\Tools\\Binn\\;C:\\Program Files (x86)\\GnuWin32\\bin;C:\\Program Files\\PowerShell\\7\\;C:\\Program Files\\PuTTY\\;C:\\Program Files\\Nordic Semiconductor\\nrf-command-line-tools\\bin\\;C:\\Users\\hello\\AppData\\Local\\Programs\\Python\\Python312\\Scripts\\;C:\\Users\\hello\\AppData\\Local\\Programs\\Python\\Python312\\;C:\\Users\\hello\\AppData\\Local\\Programs\\Python\\Python311\\Scripts\\;C:\\Users\\hello\\AppData\\Local\\Programs\\Python\\Python311\\;C:\\Users\\hello\\AppData\\Local\\Programs\\Python\\Launcher\\;C:\\Users\\hello\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Users\\hello\\AppData\\Local\\GitHubDesktop\\bin;C:\\Users\\hello\\AppData\\Local\\JetBrains\\PyCharm Community Edition 2023.1.2\\bin;;C:\\Users\\hello\\AppData\\Local\\Programs\\Microsoft VS Code\\bin",
          "ZEPHYR_BASE": "c:\\ncs\\v2.8.0\\zephyr",
          "ZEPHYR_TOOLCHAIN_VARIANT": "zephyr",
          "ZEPHYR_SDK_INSTALL_DIR": "C:\\ncs\\toolchains\\2d382dcd92\\opt\\zephyr-sdk",
          "PYTHONPATH": "C:\\ncs\\toolchains\\2d382dcd92\\opt\\bin;C:\\ncs\\toolchains\\2d382dcd92\\opt\\bin\\Lib;C:\\ncs\\toolchains\\2d382dcd92\\opt\\bin\\Lib\\site-packages"
        },
        "inherited": {
          "HOME": "C:\\Users\\hello",
          "HOMEDRIVE": "C:",
          "HOMEPATH": "\\Users\\hello",
          "Path": "C:\\TwinCAT\\Common64;C:\\TwinCAT\\Common32;C:\\Program Files (x86)\\Common Files\\Oracle\\Java\\javapath;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\;C:\\WINDOWS\\System32\\OpenSSH\\;C:\\Program Files\\dotnet\\;C:\\Program Files\\Microsoft SQL Server\\150\\Tools\\Binn\\;C:\\Program Files\\Git\\cmd;C:\\Program Files\\usbipd-win\\;C:\\Program Files\\Microchip\\xc32\\v4.30\\bin;C:\\Program Files (x86)\\dotnet\\;C:\\Program Files\\Microsoft SQL Server\\130\\Tools\\Binn\\;C:\\Program Files\\Microsoft SQL Server\\Client SDK\\ODBC\\170\\Tools\\Binn\\;C:\\Program Files (x86)\\GnuWin32\\bin;C:\\Program Files\\PowerShell\\7\\;C:\\Program Files\\PuTTY\\;C:\\Program Files\\Nordic Semiconductor\\nrf-command-line-tools\\bin\\;C:\\Users\\hello\\AppData\\Local\\Programs\\Python\\Python312\\Scripts\\;C:\\Users\\hello\\AppData\\Local\\Programs\\Python\\Python312\\;C:\\Users\\hello\\AppData\\Local\\Programs\\Python\\Python311\\Scripts\\;C:\\Users\\hello\\AppData\\Local\\Programs\\Python\\Python311\\;C:\\Users\\hello\\AppData\\Local\\Programs\\Python\\Launcher\\;C:\\Users\\hello\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Users\\hello\\AppData\\Local\\GitHubDesktop\\bin;C:\\Users\\hello\\AppData\\Local\\JetBrains\\PyCharm Community Edition 2023.1.2\\bin;;C:\\Users\\hello\\AppData\\Local\\Programs\\Microsoft VS Code\\bin;",
          "PATH": "C:\\TwinCAT\\Common64;C:\\TwinCAT\\Common32;C:\\Program Files (x86)\\Common Files\\Oracle\\Java\\javapath;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\;C:\\WINDOWS\\System32\\OpenSSH\\;C:\\Program Files\\dotnet\\;C:\\Program Files\\Microsoft SQL Server\\150\\Tools\\Binn\\;C:\\Program Files\\Git\\cmd;C:\\Program Files\\usbipd-win\\;C:\\Program Files\\Microchip\\xc32\\v4.30\\bin;C:\\Program Files (x86)\\dotnet\\;C:\\Program Files\\Microsoft SQL Server\\130\\Tools\\Binn\\;C:\\Program Files\\Microsoft SQL Server\\Client SDK\\ODBC\\170\\Tools\\Binn\\;C:\\Program Files (x86)\\GnuWin32\\bin;C:\\Program Files\\PowerShell\\7\\;C:\\Program Files\\PuTTY\\;C:\\Program Files\\Nordic Semiconductor\\nrf-command-line-tools\\bin\\;C:\\Users\\hello\\AppData\\Local\\Programs\\Python\\Python312\\Scripts\\;C:\\Users\\hello\\AppData\\Local\\Programs\\Python\\Python312\\;C:\\Users\\hello\\AppData\\Local\\Programs\\Python\\Python311\\Scripts\\;C:\\Users\\hello\\AppData\\Local\\Programs\\Python\\Python311\\;C:\\Users\\hello\\AppData\\Local\\Programs\\Python\\Launcher\\;C:\\Users\\hello\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Users\\hello\\AppData\\Local\\GitHubDesktop\\bin;C:\\Users\\hello\\AppData\\Local\\JetBrains\\PyCharm Community Edition 2023.1.2\\bin;;C:\\Users\\hello\\AppData\\Local\\Programs\\Microsoft VS Code\\bin;"
        }
      },
      "terminal": {
        "defaultProfile": null
      },
      "config": {
        "nordic-semiconductor.nrf-connect": {
          "topdir": "",
          "toolchain": {
            "path": ""
          },
          "ozonePath": "",
          "applications": [],
          "applicationOptions": {},
          "kconfig": {
            "interface": "kconfig"
          },
          "west": {
            "env": {
              "$base": "terminal"
            }
          },
          "boardRoots": [],
          "taskBindings": {},
          "buildTerminal": {
            "condensedProgress": true
          },
          "debugging": {
            "flash": true,
            "bindings": {},
            "justMyCode": false
          },
          "activeAppFollowActiveEditor": true,
          "flash": {
            "softreset": false,
            "erase": false,
            "recover": false
          },
          "enableTelemetry": null,
          "thirdpartyIntegration": {},
          "toolchainManager": {
            "indexURL": null,
            "installDirectory": null
          },
          "nrfutil": {
            "home": null
          },
          "defaultOpenAction": "ask",
          "terminalProfile": {
            "shell": null
          }
        },
        "nordic-semiconductor.nrf-terminal": {
          "terminalMode": "character"
        }
      },
      "extensions": {
        "internal": {
          "nordic-semiconductor.nrf-connect": {
            "version": "2025.1.127",
            "path": "c:\\Users\\hello\\.vscode\\extensions\\nordic-semiconductor.nrf-connect-2025.1.127-win32-x64",
            "isActive": true
          },
          "nordic-semiconductor.nrf-terminal": {
            "version": "2024.9.14",
            "path": "c:\\Users\\hello\\.vscode\\extensions\\nordic-semiconductor.nrf-terminal-2024.9.14",
            "isActive": true
          },
          "nordic-semiconductor.nrf-devicetree": {
            "version": "2024.12.15",
            "path": "c:\\Users\\hello\\.vscode\\extensions\\nordic-semiconductor.nrf-devicetree-2024.12.15",
            "isActive": true
          },
          "nordic-semiconductor.nrf-kconfig": {
            "version": "2024.12.13",
            "path": "c:\\Users\\hello\\.vscode\\extensions\\nordic-semiconductor.nrf-kconfig-2024.12.13",
            "isActive": true
          }
        },
        "external": {
          "marus25.cortex-debug": null,
          "ms-vscode.cpptools": "1.23.6",
          "ms-vscode.js-debug": "1.97.1",
          "ms-vscode.js-debug-companion": "1.1.3",
          "ms-vscode.vscode-js-profile-table": "1.0.10",
          "trond-snekvik.gnu-mapfiles": "1.1.0",
          "twxs.cmake": "0.0.17"
        }
      }
    }
    
    

  • KTH said:
    adc_sequene sample is building with target nrf52840dk

    Thats good to hear. This indicates that the SDK is properly set up and that building an in-tree application works.

    KTH said:
    nrf connect generate support information is as below

    Everything here looks fine and your setup is as good as identical to mine.

    W.r.t the spi sample. 

    Here's a new, unmodified version of the same sample from here https://github.com/too1/ncs-spi-master-slave-example/tree/master 

     spi_m_s.zip

    I've verified with multiple colleagues that this sample builds out of the box for the following configuration

    • NCS 2.8.0
    • nrf5340dk/nrf5340/cpuapp
    • with and without sysbuild

    I see that you've previously built the SPI sample from c:\Users\hello\Music\ncs-spi-master-slave-example-master. Could you shorten the name of the sample and preferably place it closer to C:\? Windows has an issue with path length when building any project.

    Place the sample for instance within ncs/my_projects

    and build for the configuration I mentioned.

    Kind regards,
    Andreas

Related