Issues Configuring nRF52820 as SPI Slave on Custom Board with Zephyr – Missing Definitions

Hello,

I am experiencing difficulties configuring an nRF52820 to function as an SPI slave on a custom-designed board. I followed Lesson 5 of the NCS Intermediate Tutorial on DevAcademy to set up the nRF52820. However, I continuously encounter compilation errors related to missing definitions.

FAILED: CMakeFiles/app.dir/src/main.c.obj 
C:\ncs\toolchains\ce3b5ff664\opt\zephyr-sdk\arm-zephyr-eabi\bin\arm-zephyr-eabi-gcc.exe -DKERNEL -DK_HEAP_MEM_POOL_SIZE=0 -DNRF52820_XXAA -DPICOLIBC_LONG_LONG_PRINTF_SCANF -D__LINUX_ERRNO_EXTENSIONS__ -D__PROGRAM_START -D__ZEPHYR__=1 -IC:/ncs/v2.7.0/zephyr/include -IC:/dev/bh_node_80_820/build/zephyr/include/generated -IC:/ncs/v2.7.0/modules/soc-hwmv1/soc/arm/nordic_nrf/nrf52 -IC:/ncs/v2.7.0/modules/soc-hwmv1/soc/arm/nordic_nrf/common/. -IC:/ncs/v2.7.0/nrf/include -IC:/ncs/v2.7.0/nrf/tests/include -IC:/ncs/v2.7.0/modules/hal/cmsis/CMSIS/Core/Include -IC:/ncs/v2.7.0/zephyr/modules/cmsis/. -IC:/ncs/v2.7.0/modules/hal/nordic/nrfx -IC:/ncs/v2.7.0/modules/hal/nordic/nrfx/drivers/include -IC:/ncs/v2.7.0/modules/hal/nordic/nrfx/mdk -IC:/ncs/v2.7.0/zephyr/modules/hal_nordic/nrfx/. -IC:/ncs/v2.7.0/modules/debug/segger/SEGGER -IC:/ncs/v2.7.0/modules/debug/segger/Config -isystem C:/ncs/v2.7.0/zephyr/lib/libc/common/include -fno-strict-aliasing -Os -imacros C:/dev/bh_node_80_820/build/zephyr/include/generated/autoconf.h -fno-printf-return-value -fno-common -g -gdwarf-4 -fdiagnostics-color=always -mcpu=cortex-m4 -mthumb -mabi=aapcs -mfp16-format=ieee -mtp=soft --sysroot=C:/ncs/toolchains/ce3b5ff664/opt/zephyr-sdk/arm-zephyr-eabi/arm-zephyr-eabi -imacros C:/ncs/v2.7.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:/dev/bh_node_80_820=CMAKE_SOURCE_DIR -fmacro-prefix-map=C:/ncs/v2.7.0/zephyr=ZEPHYR_BASE -fmacro-prefix-map=C:/ncs/v2.7.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:/dev/bh_node_80_820/src/main.c
In file included from C:/ncs/v2.7.0/zephyr/include/zephyr/toolchain/gcc.h:98,
                 from C:/ncs/v2.7.0/zephyr/include/zephyr/toolchain.h:50,
                 from C:/ncs/v2.7.0/zephyr/include/zephyr/kernel_includes.h:23,
                 from C:/ncs/v2.7.0/zephyr/include/zephyr/kernel.h:17,
                 from C:/dev/bh_node_80_820/src/main.c:1:
C:/ncs/v2.7.0/zephyr/include/zephyr/device.h:91:41: error: '__device_dts_ord_DT_N_S_soc_S_spi_40003000_BUS_ORD' undeclared here (not in a function)
   91 | #define DEVICE_NAME_GET(dev_id) _CONCAT(__device_, dev_id)
      |                                         ^~~~~~~~~
C:/ncs/v2.7.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.7.0/zephyr/include/zephyr/device.h:91:33: note: in expansion of macro '_CONCAT'
   91 | #define DEVICE_NAME_GET(dev_id) _CONCAT(__device_, dev_id)
      |                                 ^~~~~~~
C:/ncs/v2.7.0/zephyr/include/zephyr/device.h:228:37: note: in expansion of macro 'DEVICE_NAME_GET'
  228 | #define DEVICE_DT_NAME_GET(node_id) DEVICE_NAME_GET(Z_DEVICE_DT_DEV_ID(node_id))
      |                                     ^~~~~~~~~~~~~~~
C:/ncs/v2.7.0/zephyr/include/zephyr/device.h:245:34: note: in expansion of macro 'DEVICE_DT_NAME_GET'
  245 | #define DEVICE_DT_GET(node_id) (&DEVICE_DT_NAME_GET(node_id))
      |                                  ^~~~~~~~~~~~~~~~~~
C:/ncs/v2.7.0/zephyr/include/zephyr/drivers/spi.h:403:24: note: in expansion of macro 'DEVICE_DT_GET'
  403 |                 .bus = DEVICE_DT_GET(DT_BUS(node_id)),               \
      |                        ^~~~~~~~~~~~~
C:/dev/bh_node_80_820/src/main.c:12:30: note: in expansion of macro 'SPI_DT_SPEC_GET'
   12 | struct spi_dt_spec spispec = SPI_DT_SPEC_GET(DT_NODELABEL(spitest), SPIOP, 0);
      |                              ^~~~~~~~~~~~~~~
In file included from C:/ncs/v2.7.0/zephyr/include/zephyr/arch/arm/arch.h:20,
                 from C:/ncs/v2.7.0/zephyr/include/zephyr/arch/cpu.h:19,
                 from C:/ncs/v2.7.0/zephyr/include/zephyr/kernel_includes.h:36:
C:/dev/bh_node_80_820/build/zephyr/include/generated/devicetree_generated.h:4806:37: error: 'DT_N_S_soc_S_spi_40003000_P_spi_max_frequency' undeclared here (not in a function); did you mean 'DT_N_S_soc_S_spi_40003000_P_max_frequency'?
 4806 | #define DT_N_NODELABEL_spitest      DT_N_S_soc_S_spi_40003000
      |                                     ^~~~~~~~~~~~~~~~~~~~~~~~~
C:/ncs/v2.7.0/zephyr/include/zephyr/devicetree.h:4534:29: note: in definition of macro 'DT_CAT3'
 4534 | #define DT_CAT3(a1, a2, a3) a1 ## a2 ## a3
      |                             ^~
C:/ncs/v2.7.0/zephyr/include/zephyr/drivers/spi.h:349:30: note: in expansion of macro 'DT_PROP'
  349 |                 .frequency = DT_PROP(node_id, spi_max_frequency),       \
      |                              ^~~~~~~
C:/ncs/v2.7.0/zephyr/include/zephyr/drivers/spi.h:404:27: note: in expansion of macro 'SPI_CONFIG_DT'
  404 |                 .config = SPI_CONFIG_DT(node_id, operation_, delay_) \
      |                           ^~~~~~~~~~~~~
C:/dev/bh_node_80_820/src/main.c:12:30: note: in expansion of macro 'SPI_DT_SPEC_GET'
   12 | struct spi_dt_spec spispec = SPI_DT_SPEC_GET(DT_NODELABEL(spitest), SPIOP, 0);
      |                              ^~~~~~~~~~~~~~~
C:/ncs/v2.7.0/zephyr/include/zephyr/devicetree.h:4532:24: note: in expansion of macro 'DT_N_NODELABEL_spitest'
 4532 | #define DT_CAT(a1, a2) a1 ## a2
      |                        ^~
C:/ncs/v2.7.0/zephyr/include/zephyr/devicetree.h:200:29: note: in expansion of macro 'DT_CAT'
  200 | #define DT_NODELABEL(label) DT_CAT(DT_N_NODELABEL_, label)
      |                             ^~~~~~
C:/dev/bh_node_80_820/src/main.c:12:46: note: in expansion of macro 'DT_NODELABEL'
   12 | struct spi_dt_spec spispec = SPI_DT_SPEC_GET(DT_NODELABEL(spitest), SPIOP, 0);
      |                                              ^~~~~~~~~~~~
C:/dev/bh_node_80_820/build/zephyr/include/generated/devicetree_generated.h:4806:37: error: 'DT_N_S_soc_S_spi_40003000_P_duplex' undeclared here (not in a function); did you mean 'DT_N_S_soc_S_spi_40003000_P_label'?
 4806 | #define DT_N_NODELABEL_spitest      DT_N_S_soc_S_spi_40003000
      |                                     ^~~~~~~~~~~~~~~~~~~~~~~~~
C:/ncs/v2.7.0/zephyr/include/zephyr/devicetree.h:4534:29: note: in definition of macro 'DT_CAT3'
 4534 | #define DT_CAT3(a1, a2, a3) a1 ## a2 ## a3
      |                             ^~
C:/ncs/v2.7.0/zephyr/include/zephyr/drivers/spi.h:351:25: note: in expansion of macro 'DT_PROP'
  351 |                         DT_PROP(node_id, duplex) |                      \
      |                         ^~~~~~~
C:/ncs/v2.7.0/zephyr/include/zephyr/drivers/spi.h:404:27: note: in expansion of macro 'SPI_CONFIG_DT'
  404 |                 .config = SPI_CONFIG_DT(node_id, operation_, delay_) \
      |                           ^~~~~~~~~~~~~
C:/dev/bh_node_80_820/src/main.c:12:30: note: in expansion of macro 'SPI_DT_SPEC_GET'
   12 | struct spi_dt_spec spispec = SPI_DT_SPEC_GET(DT_NODELABEL(spitest), SPIOP, 0);
      |                              ^~~~~~~~~~~~~~~
C:/ncs/v2.7.0/zephyr/include/zephyr/devicetree.h:4532:24: note: in expansion of macro 'DT_N_NODELABEL_spitest'
 4532 | #define DT_CAT(a1, a2) a1 ## a2
      |                        ^~
C:/ncs/v2.7.0/zephyr/include/zephyr/devicetree.h:200:29: note: in expansion of macro 'DT_CAT'
  200 | #define DT_NODELABEL(label) DT_CAT(DT_N_NODELABEL_, label)
      |                             ^~~~~~
C:/dev/bh_node_80_820/src/main.c:12:46: note: in expansion of macro 'DT_NODELABEL'
   12 | struct spi_dt_spec spispec = SPI_DT_SPEC_GET(DT_NODELABEL(spitest), SPIOP, 0);
      |                                              ^~~~~~~~~~~~
C:/dev/bh_node_80_820/build/zephyr/include/generated/devicetree_generated.h:4806:37: error: 'DT_N_S_soc_S_spi_40003000_P_frame_format' undeclared here (not in a function); did you mean 'DT_N_S_soc_S_spi_40003000_P_def_char'?
 4806 | #define DT_N_NODELABEL_spitest      DT_N_S_soc_S_spi_40003000
      |                                     ^~~~~~~~~~~~~~~~~~~~~~~~~
C:/ncs/v2.7.0/zephyr/include/zephyr/devicetree.h:4534:29: note: in definition of macro 'DT_CAT3'
 4534 | #define DT_CAT3(a1, a2, a3) a1 ## a2 ## a3
      |                             ^~
C:/ncs/v2.7.0/zephyr/include/zephyr/drivers/spi.h:352:25: note: in expansion of macro 'DT_PROP'
  352 |                         DT_PROP(node_id, frame_format) |                        \
      |                         ^~~~~~~
C:/ncs/v2.7.0/zephyr/include/zephyr/drivers/spi.h:404:27: note: in expansion of macro 'SPI_CONFIG_DT'
  404 |                 .config = SPI_CONFIG_DT(node_id, operation_, delay_) \
      |                           ^~~~~~~~~~~~~
C:/dev/bh_node_80_820/src/main.c:12:30: note: in expansion of macro 'SPI_DT_SPEC_GET'
   12 | struct spi_dt_spec spispec = SPI_DT_SPEC_GET(DT_NODELABEL(spitest), SPIOP, 0);
      |                              ^~~~~~~~~~~~~~~
C:/ncs/v2.7.0/zephyr/include/zephyr/devicetree.h:4532:24: note: in expansion of macro 'DT_N_NODELABEL_spitest'
 4532 | #define DT_CAT(a1, a2) a1 ## a2
      |                        ^~
C:/ncs/v2.7.0/zephyr/include/zephyr/devicetree.h:200:29: note: in expansion of macro 'DT_CAT'
  200 | #define DT_NODELABEL(label) DT_CAT(DT_N_NODELABEL_, label)
      |                             ^~~~~~
C:/dev/bh_node_80_820/src/main.c:12:46: note: in expansion of macro 'DT_NODELABEL'
   12 | struct spi_dt_spec spispec = SPI_DT_SPEC_GET(DT_NODELABEL(spitest), SPIOP, 0);
      |                                              ^~~~~~~~~~~~
In file included from C:/ncs/v2.7.0/zephyr/include/zephyr/devicetree.h:19:
C:/dev/bh_node_80_820/build/zephyr/include/generated/devicetree_generated.h:4811:57: warning: unsigned conversion from 'int' to 'short unsigned int' changes value from '1073754112' to '12288' [-Woverflow]
 4811 | #define DT_N_S_soc_S_spi_40003000_REG_IDX_0_VAL_ADDRESS 1073754112 /* 0x40003000 */
      |                                                         ^~~~~~~~~~
C:/ncs/v2.7.0/zephyr/include/zephyr/devicetree.h:4536:33: note: in expansion of macro 'DT_N_S_soc_S_spi_40003000_REG_IDX_0_VAL_ADDRESS'
 4536 | #define DT_CAT4(a1, a2, a3, a4) a1 ## a2 ## a3 ## a4
      |                                 ^~
C:/ncs/v2.7.0/zephyr/include/zephyr/devicetree.h:2212:9: note: in expansion of macro 'DT_CAT4'
 2212 |         DT_CAT4(node_id, _REG_IDX_, idx, _VAL_ADDRESS)
      |         ^~~~~~~
C:/ncs/v2.7.0/zephyr/include/zephyr/devicetree.h:2235:30: note: in expansion of macro 'DT_REG_ADDR_BY_IDX'
 2235 | #define DT_REG_ADDR(node_id) DT_REG_ADDR_BY_IDX(node_id, 0)
      |                              ^~~~~~~~~~~~~~~~~~
C:/ncs/v2.7.0/zephyr/include/zephyr/drivers/spi.h:356:26: note: in expansion of macro 'DT_REG_ADDR'
  356 |                 .slave = DT_REG_ADDR(node_id),                          \
      |                          ^~~~~~~~~~~
C:/ncs/v2.7.0/zephyr/include/zephyr/drivers/spi.h:404:27: note: in expansion of macro 'SPI_CONFIG_DT'
  404 |                 .config = SPI_CONFIG_DT(node_id, operation_, delay_) \
      |                           ^~~~~~~~~~~~~
C:/dev/bh_node_80_820/src/main.c:12:30: note: in expansion of macro 'SPI_DT_SPEC_GET'
   12 | struct spi_dt_spec spispec = SPI_DT_SPEC_GET(DT_NODELABEL(spitest), SPIOP, 0);
      |                              ^~~~~~~~~~~~~~~
C:/ncs/v2.7.0/zephyr/include/zephyr/devicetree.h:4532:24: note: in expansion of macro 'DT_N_NODELABEL_spitest'
 4532 | #define DT_CAT(a1, a2) a1 ## a2
      |                        ^~
C:/ncs/v2.7.0/zephyr/include/zephyr/devicetree.h:200:29: note: in expansion of macro 'DT_CAT'
  200 | #define DT_NODELABEL(label) DT_CAT(DT_N_NODELABEL_, label)
      |                             ^~~~~~
C:/dev/bh_node_80_820/src/main.c:12:46: note: in expansion of macro 'DT_NODELABEL'
   12 | struct spi_dt_spec spispec = SPI_DT_SPEC_GET(DT_NODELABEL(spitest), SPIOP, 0);
      |                                              ^~~~~~~~~~~~
[55/147] Building C object zephyr/CMakeFiles/zephyr.dir/lib/utils/bitarray.c.obj
ninja: build stopped: subcommand failed.
FATAL ERROR: command exited with status 1: 'C:\ncs\toolchains\ce3b5ff664\opt\bin\cmake.EXE' --build 'c:\dev\bh_node_80_820\build'

Here detail configuration about the SPI module for my custom board:

  • In the board configuration files .dts and pinctrl.dtsi:

&spi0 {
	compatible = "nordic,nrf-spis";
	status = "okay";
	cs-gpios = <&gpio0 0 0>;
	pinctrl-0 = <&spi0_default>;
	pinctrl-names = "default", "sleep";
	pinctrl-1 = <&spi0_sleep>;
	wake-gpios = <&gpio0 6 0>;
	def-char = <0xFF>;
};

&pinctrl {

	spi0_default: spi0_default {
		group1 {
			psels = <NRF_PSEL(SPIM_MISO, 0, 1)>,
					<NRF_PSEL(SPIM_MOSI, 0, 4)>,
					<NRF_PSEL(SPIM_SCK, 0, 5)>;
		};
	};

	spi0_sleep: spi0_sleep {
		group1 {
			psels = <NRF_PSEL(SPIM_MISO, 0, 1)>,
					<NRF_PSEL(SPIM_MOSI, 0, 4)>,
					<NRF_PSEL(SPIM_SCK, 0, 5)>;
			low-power-enable;
		};
	};
};

  • .overlay file in the project base:

spitest: &spi0 {
    status = "okay";
    label = "spis0";
    compatible = "nordic,nrf-spis";
    def-char = <0xFF>;
    wake-gpios = <&gpio0 6 GPIO_ACTIVE_LOW>;
    cs-gpios = <&gpio0 0 GPIO_ACTIVE_LOW>;

    reg = <0x40003000 0x1000>;        
    interrupts = <30 0>;              
    pinctrl-0 = <&spi0_default>;
    pinctrl-1 = <&spi0_sleep>;
    pinctrl-names = "default", "sleep";
    max-frequency = <8000000>;        
    easydma-maxcnt-bits = <16>;       
    #address-cells = <1>;
    #size-cells = <0>;
    status = "okay";
};

  • prj.conf:

CONFIG_SPI=y
CONFIG_GPIO=y
CONFIG_PINCTRL=y
CONFIG_PINCTRL_NRF=y
CONFIG_LOG=y

  • The errors are from these lines in src file:

#define SPIOP	SPI_WORD_SET(8) | SPI_TRANSFER_MSB | SPI_OP_MODE_SLAVE | SPI_MODE_CPOL 
struct spi_dt_spec spispec = SPI_DT_SPEC_GET(DT_NODELABEL(spitest), SPIOP, 0);

  • I am using the ncs SDK 2.7.0 with the toolchain 2.7.0.

Could you please help me identify what configurations are missing and provide guidance on how to correctly configure the nRF52820 as an SPI slave on my custom board? Any insights into the device tree configuration or necessary code adjustments would be greatly appreciated.

Thank you for your assistance!

Best regards,

Lezhi

Related