devicetree_unfixed issue with SPI device node lookup

I am getting compilation errors when using the DT_ macros to access SPI bus child entries.

Overlay file:

&spi1 {
compatible = "nordic,nrf-spim";
status = "okay";
sck-pin = <12>;
mosi-pin = <10>;
miso-pin = <11>;

cs-gpios = <&gpio0 22 GPIO_ACTIVE_LOW>,
<&gpio0 23 GPIO_ACTIVE_LOW>;
ltc3300: spi-dev-ltc3300@0 {
reg = <0>;
spi-max-frequency = <250000>;
};
ltc6804: spi-dev-ltc6804@1 {
reg = <1>;
spi-max-frequency = <250000>;
};
};

Code
const struct device* LTC3300SpiDev = DT_BUS(DT_NODELABEL(ltc3300));

Error Messages

/Users/allencurtis/MyProjects/EJR-BMS/EJR-RTOS-BMS/build/zephyr/include/generated/devicetree_unfixed.h:5955:59: error: 'DT_N_S_soc_S_spi_40004000' undeclared here (not in a function); did you mean 'DT_N_S_soc_S_spi_40004000_ORD'?
 5955 | #define DT_N_S_soc_S_spi_40004000_S_spi_dev_ltc3300_0_BUS DT_N_S_soc_S_spi_40004000
      |                                                           ^~~~~~~~~~~~~~~~~~~~~~~~~
/opt/nordic/ncs/v1.7.1/zephyr/include/devicetree.h:2542:24: note: in expansion of macro 'DT_N_S_soc_S_spi_40004000_S_spi_dev_ltc3300_0_BUS'
 2542 | #define DT_CAT(a1, a2) a1 ## a2
      |                        ^~
/opt/nordic/ncs/v1.7.1/zephyr/include/devicetree.h:1923:25: note: in expansion of macro 'DT_CAT'
 1923 | #define DT_BUS(node_id) DT_CAT(node_id, _BUS)
      |                         ^~~~~~
/Users/allencurtis/MyProjects/EJR-BMS/EJR-RTOS-BMS/src/main.c:54:38: note: in expansion of macro 'DT_BUS'
   54 | const struct device* LTC3300SpiDev = DT_BUS(DT_NODELABEL(ltc3300));
      |                                      ^~~~~~
/opt/nordic/ncs/v1.7.1/zephyr/include/devicetree.h:2542:24: note: in expansion of macro 'DT_N_NODELABEL_ltc3300'
 2542 | #define DT_CAT(a1, a2) a1 ## a2
      |                        ^~
/opt/nordic/ncs/v1.7.1/zephyr/include/devicetree.h:177:29: note: in expansion of macro 'DT_CAT'
  177 | #define DT_NODELABEL(label) DT_CAT(DT_N_NODELABEL_, label)
      |                             ^~~~~~
/Users/allencurtis/MyProjects/EJR-BMS/EJR-RTOS-BMS/src/main.c:54:45: note: in expansion of macro 'DT_NODELABEL'
   54 | const struct device* LTC3300SpiDev = DT_BUS(DT_NODELABEL(ltc3300));
    
Parents Reply Children
  • Hello Elfving, I was able to resolve this issue via Discord. Essentially the code above is missing another macro. DT_BUS() gives you a node pointer, not a struct device*.

    To do that:

    const struct device* LTC3300SpiDev = DEVICE_DT_GET((DT_BUS(DT_NODELABEL(ltc3300)));

    Another issue I have is that the devicetree macros are not compatible with the C++ compiler. Obviously that is a different issue but thought I would mention it.
Related