Hi everyone,
I'm working on a project with Zephyr (v2.9.1) and I'm facing a compilation issue related to managing two SPI devices on different buses (spi0 and spi2).
In my .dts file, I’ve defined two SPI devices.
/dts-v1/;
#include <nordic/nrf52840_qiaa.dtsi>
#include "device-pinctrl.dtsi"
#include <zephyr/dt-bindings/input/input-event-codes.h>
/ {
model = "device";
compatible = "company,device";
chosen {
zephyr,sram = &sram0;
zephyr,flash = &flash0;
zephyr,code-partition = &slot0_partition;
zephyr,uart-mcumgr = &cdc_acm_uart0;
};
leds {
compatible = "gpio-leds";
led_red: led_0 {
gpios = < &gpio1 2 GPIO_ACTIVE_HIGH >;
label = "Led Red";
};
led_green: led_1 {
gpios = < &gpio1 6 GPIO_ACTIVE_HIGH >;
label = "Led Green";
};
led_blue: led_2 {
gpios = < &gpio1 4 GPIO_ACTIVE_HIGH >;
label = "Led Blue";
};
};
pwmleds {
compatible = "pwm-leds";
pwm_led_red: pwm_led_red {
pwms = <&pwm0 0 PWM_MSEC(20) PWM_POLARITY_NORMAL>;
label = "Pwm Led Red";
};
pwm_led_green: pwm_led_green {
pwms = <&pwm1 1 PWM_MSEC(20) PWM_POLARITY_NORMAL>;
label = "Pwm Led Green";
};
pwm_led_blue: pwm_led_blue {
pwms = <&pwm2 2 PWM_MSEC(20) PWM_POLARITY_NORMAL>;
label = "Pwm Led Blue";
};
};
gpiocustom {
compatible = "gpio-keys";
pwr_en_mcu: gpiocustom_0 {
gpios = < &gpio1 8 GPIO_ACTIVE_HIGH >;
label = "PWR_EN_MCU";
};
button_mcu: gpiocustom_1 {
gpios = < &gpio0 12 GPIO_ACTIVE_HIGH >;
label = "BUTTON_MCU";
};
chg_wrd_mcu: gpiocustom_2 {
gpios = < &gpio0 8 GPIO_ACTIVE_HIGH >;
label = "CHG_WRD_MCU";
};
pg_wrd_mcu: gpiocustom_3 {
gpios = < &gpio1 9 GPIO_ACTIVE_HIGH >;
label = "PG_WRD_MCU";
};
imu_int1: gpiocustom_4 {
gpios = < &gpio0 2 GPIO_ACTIVE_HIGH >;
label = "IMU_INT1";
};
imu_int2: gpiocustom_5 {
gpios = < &gpio0 6 GPIO_ACTIVE_HIGH >;
label = "IMU_INT2";
};
bio_reset: gpiocustom_6 {
gpios = < &gpio1 11 GPIO_ACTIVE_HIGH >;
label = "BIO_RESET";
};
bio_start: gpiocustom_7 {
gpios = < &gpio1 12 GPIO_ACTIVE_HIGH >;
label = "BIO_START";
};
bio_drdy: gpiocustom_8 {
gpios = < &gpio1 10 GPIO_ACTIVE_HIGH >;
label = "BIO_DRDY";
};
bio_dout0: gpiocustom_9 {
gpios = < &gpio1 14 GPIO_ACTIVE_HIGH >;
label = "BIO_DOUT0";
};
bio_dout1: gpiocustom_10 {
gpios = < &gpio0 3 GPIO_ACTIVE_HIGH >;
label = "BIO_DOUT1";
};
bio_dout2: gpiocustom_11 {
gpios = < &gpio1 13 GPIO_ACTIVE_HIGH >;
label = "BIO_DOUT2";
};
bio_dout3: gpiocustom_12 {
gpios = < &gpio1 15 GPIO_ACTIVE_HIGH >;
label = "BIO_DOUT3";
};
bio_mode0: gpiocustom_13 {
gpios = < &gpio1 7 GPIO_ACTIVE_HIGH >;
label = "BIO_MODE0";
};
bio_mode1: gpiocustom_14 {
gpios = < &gpio0 5 GPIO_ACTIVE_HIGH >;
label = "BIO_MODE1";
};
bio_mode2: gpiocustom_15 {
gpios = < &gpio1 1 GPIO_ACTIVE_HIGH >;
label = "BIO_MODE2";
};
bio_mode3: gpiocustom_16 {
gpios = < &gpio1 3 GPIO_ACTIVE_HIGH >;
label = "BIO_MODE3";
};
bio_mclk: gpiocustom_17 {
gpios = < &gpio0 15 GPIO_ACTIVE_HIGH >;
label = "BIO_MCLK";
};
bio_dclk: gpiocustom_18 {
gpios = < &gpio0 13 GPIO_ACTIVE_HIGH >;
label = "BIO_DCLK";
};
bio_pwen: gpiocustom_19 {
gpios = < &gpio0 14 GPIO_ACTIVE_HIGH >;
label = "BIO_PWEN";
};
};
buttons {
compatible = "gpio-keys";
button0: button_0 {
gpios = <&gpio0 12 ( GPIO_PULL_UP | GPIO_ACTIVE_LOW )>;
label = "Push button switch 0";
zephyr,code = <INPUT_KEY_0>;
};
};
msc_disk0 {
compatible = "zephyr,flash-disk";
partition = <&flash_storage_partition>;
disk-name = "NAND";
cache-size = <4096>;
};
aliases {
mcuboot-button0 = &button0;
mcuboot-led0 = &led_blue;
};
};
&gpio1 {
status = "okay";
};
&gpio0 {
status = "okay";
};
&gpiote {
status = "okay";
};
&pwm0 {
status = "okay";
pinctrl-0 = <&pwm0_default>;
pinctrl-1 = <&pwm0_sleep>;
pinctrl-names = "default", "sleep";
};
&pwm1 {
status = "okay";
pinctrl-0 = <&pwm1_default>;
pinctrl-1 = <&pwm1_sleep>;
pinctrl-names = "default", "sleep";
};
&pwm2 {
status = "okay";
pinctrl-0 = <&pwm2_default>;
pinctrl-1 = <&pwm2_sleep>;
pinctrl-names = "default", "sleep";
};
&i2c1 {
status = "okay";
clock-frequency = <400000>;
pinctrl-0 = <&i2c1_default>;
pinctrl-1 = <&i2c1_sleep>;
pinctrl-names = "default", "sleep";
bq27421_g1: bq27421_g1@55 {
compatible = "i2c-device";
reg = <0x55>;
};
lis2mdl: lis2mdl@1E {
compatible = "i2c-device";
reg = <0x1E>;
};
};
&spi0 {
compatible = "nordic,nrf-spim";
status = "okay";
pinctrl-0 = <&spi0_default>;
pinctrl-1 = <&spi0_sleep>;
pinctrl-names = "default", "sleep";
cs-gpios = <&gpio0 7 GPIO_ACTIVE_LOW>;
lsm6dsv16x: lsm6dsv16x@0 {
compatible = "st,lsm6dsv16x";
reg = <0>;
spi-max-frequency = <8000000>;
};
};
&spi2 {
compatible = "nordic,nrf-spim";
status = "okay";
pinctrl-0 = <&spi2_default>;
pinctrl-1 = <&spi2_sleep>;
pinctrl-names = "default", "sleep";
cs-gpios = <&gpio0 24 GPIO_ACTIVE_LOW>;
ad7779: ad7779@0 {
compatible = "spi-device";
reg = <0>;
spi-max-frequency = <8000000>;
};
};
&qspi {
status = "disabled";
pinctrl-0 = <&qspi_default>;
pinctrl-1 = <&qspi_sleep>;
pinctrl-names = "default", "sleep";
mt25qu512: mt25qu512@0 {
compatible = "nordic,qspi-nor";
reg = <0>;
writeoc = "pp4io";
readoc = "read4o";
sck-frequency = <8000000>;
jedec-id = [20 bb 20];
sfdp-bfp = [
e5 20 fb ff ff ff ff 1f 29 eb 27 6b 27 3b 27 bb
ff ff ff ff ff ff 27 bb ff ff 29 eb 0c 20 10 d8
0f 52 00 00 24 4a 99 00 8b 8e 03 e1 ac 01 27 38
7a 75 7a 75 fb bd d5 5c 4a 0f 82 ff 81 bd 3d 36
];
size = <536870912>;
has-dpd;
t-enter-dpd = <10000>;
t-exit-dpd = <35000>;
partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;
flash_storage_partition: partition@0 {
label = "flash-storage";
reg = <0x00000000 0x04000000>;
};
};
};
};
&flash0 {
partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;
boot_partition: partition@0 {
label = "mcuboot";
reg = <0x00000000 0x0000C000>;
};
slot0_partition: partition@c000 {
label = "image-0";
reg = <0x0000C000 0x00067000>;
};
slot1_partition: partition@73000 {
label = "image-1";
reg = <0x00073000 0x00067000>;
};
scratch_partition: partition@da000 {
label = "image-scratch";
reg = <0x000da000 0x0001e000>;
};
storage_partition: partition@f8000 {
label = "storage";
reg = <0x000f8000 0x00008000>;
};
};
};
zephyr_udc0: &usbd {
compatible = "nordic,nrf-usbd";
status = "okay";
};
&zephyr_udc0 {
cdc_acm_uart0: cdc_acm_uart0 {
compatible = "zephyr,cdc-acm-uart";
};
};
One of them is an AD7779 ADC connected to spi2. I'm using the macro
static struct spi_dt_spec bioSensorSpiSpec = SPI_DT_SPEC_GET( DT_NODELABEL( ad7779 ), SPI_WORD_SET( 8 ) | SPI_TRANSFER_MSB | SPI_MODE_CPOL | SPI_MODE_CPHA, 0 );
in my C code to initialize the SPI communication, but during compilation I get the following error:
error: 'DT_N_S_soc_S_spi_40023000_S_ad7779_0_P_spi_max_frequency' undeclared here
It seems like the ad7779 node is not being recognized properly. Note that there is also another SPI device on spi0, with a different name and label, which doesn't cause any issues during compilation.
Has anyone experienced something similar? What am I missing?
Thanks in advance for your help!
EDIT:
I noticed that if I use
compatible = "st,lsm6dsv16x";
instead of
compatible = "spi-device";
everything compiles correctly. So the issue is with "spi-device". Of course, I can't leave "st,lsm6dsv16x" there, so what do you suggest I do?