Yet another Zephyr DeviceTree problem; this time with SPI spi-max-frequency (amongst others)

My question is:  why are XX_frame_format, XX_duplex, and XX_spi_max_frequency #defines not being generated in devicetree_generated.h??

Here's the .dts snippet for &spi3:

&spi3 {
    compatible = "nordic,nrf-spim";
    status = "okay";
    cs-gpios = <&gpio0 19 GPIO_ACTIVE_LOW>;  // Memory CS
    pinctrl-0 = <&spi3_default>;
    pinctrl-1 = <&spi3_sleep>;
    pinctrl-names = "default", "sleep";

    spiflash: spiflash@0 {
        status = "okay";
        compatible = "spi-device";
        reg = <0>;
        label = "spiFlash";
        frame-format = <0>;
        spi-max-frequency = <40000000>;
    };
};

Note that both frame-format and spi-max-frequency are specified.

But when I build I get errors for the following line:

#define SPI_OP  (SPI_OP_MODE_MASTER | SPI_MODE_GET(0) | SPI_WORD_SET(8) | SPI_LINES_SINGLE)
const struct spi_dt_spec spiFlashDt = SPI_DT_SPEC_GET(DT_NODELABEL(spiflash), SPI_OP, 0);

Specifically, complaints about XX_spi_max_frequency and XX_frame_format and XX_duplex not being defined in devicetree_generated.h

Here's the error:

In file included from C:/Projects/GuidoRail/workspace/zephyr/include/zephyr/arch/arm/aarch32/arch.h:20,
                 from C:/Projects/GuidoRail/workspace/zephyr/include/zephyr/arch/cpu.h:19,
                 from C:/Projects/GuidoRail/workspace/zephyr/include/zephyr/kernel_includes.h:33,
                 from C:/Projects/GuidoRail/workspace/zephyr/include/zephyr/kernel.h:17,
                 from ../src/spiFlashRaw.c:7:
zephyr/include/generated/devicetree_generated.h:11437:33: error: 'DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_P_spi_max_frequency' undeclared here (not in a function); did you mean 'DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_P_status_LEN'?
11437 | #define DT_N_NODELABEL_spiflash DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0
      |                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:/Projects/GuidoRail/workspace/zephyr/include/zephyr/devicetree.h:4231:29: note: in definition of macro 'DT_CAT3'
 4231 | #define DT_CAT3(a1, a2, a3) a1 ## a2 ## a3
      |                             ^~
C:/Projects/GuidoRail/workspace/zephyr/include/zephyr/drivers/spi.h:332:30: note: in expansion of macro 'DT_PROP'
  332 |                 .frequency = DT_PROP(node_id, spi_max_frequency),       \
      |                              ^~~~~~~
C:/Projects/GuidoRail/workspace/zephyr/include/zephyr/drivers/spi.h:386:27: note: in expansion of macro 'SPI_CONFIG_DT'
  386 |                 .config = SPI_CONFIG_DT(node_id, operation_, delay_) \
      |                           ^~~~~~~~~~~~~
../src/spiFlashRaw.c:20:39: note: in expansion of macro 'SPI_DT_SPEC_GET'
   20 | const struct spi_dt_spec spiFlashDt = SPI_DT_SPEC_GET(DT_NODELABEL(spiflash), SPI_OP, 0);
      |                                       ^~~~~~~~~~~~~~~
C:/Projects/GuidoRail/workspace/zephyr/include/zephyr/devicetree.h:4229:24: note: in expansion of macro 'DT_N_NODELABEL_spiflash'
 4229 | #define DT_CAT(a1, a2) a1 ## a2
      |                        ^~
C:/Projects/GuidoRail/workspace/zephyr/include/zephyr/devicetree.h:197:29: note: in expansion of macro 'DT_CAT'
  197 | #define DT_NODELABEL(label) DT_CAT(DT_N_NODELABEL_, label)
      |                             ^~~~~~
../src/spiFlashRaw.c:20:55: note: in expansion of macro 'DT_NODELABEL'
   20 | const struct spi_dt_spec spiFlashDt = SPI_DT_SPEC_GET(DT_NODELABEL(spiflash), SPI_OP, 0);
      |                                                       ^~~~~~~~~~~~
In file included from ../src/spiFlashRaw.c:11:
../src/spiFlashRaw.c:18:39: warning: implicit declaration of function 'SPI_MODE_SET'; did you mean 'SPI_MODE_GET'? [-Wimplicit-function-declaration]
   18 | #define SPI_OP  (SPI_OP_MODE_MASTER | SPI_MODE_SET(0) | SPI_WORD_SET(8) | SPI_LINES_SINGLE)
      |                                       ^~~~~~~~~~~~
C:/Projects/GuidoRail/workspace/zephyr/include/zephyr/drivers/spi.h:333:31: note: in definition of macro 'SPI_CONFIG_DT'
  333 |                 .operation = (operation_) |                             \
      |                               ^~~~~~~~~~
../src/spiFlashRaw.c:20:39: note: in expansion of macro 'SPI_DT_SPEC_GET'
   20 | const struct spi_dt_spec spiFlashDt = SPI_DT_SPEC_GET(DT_NODELABEL(spiflash), SPI_OP, 0);
      |                                       ^~~~~~~~~~~~~~~
../src/spiFlashRaw.c:20:79: note: in expansion of macro 'SPI_OP'
   20 | const struct spi_dt_spec spiFlashDt = SPI_DT_SPEC_GET(DT_NODELABEL(spiflash), SPI_OP, 0);
      |                                                                               ^~~~~~
zephyr/include/generated/devicetree_generated.h:11437:33: error: 'DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_P_duplex' undeclared here (not in a function); did you mean 'DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_P_label'?
11437 | #define DT_N_NODELABEL_spiflash DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0
      |                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:/Projects/GuidoRail/workspace/zephyr/include/zephyr/devicetree.h:4231:29: note: in definition of macro 'DT_CAT3'
 4231 | #define DT_CAT3(a1, a2, a3) a1 ## a2 ## a3
      |                             ^~
C:/Projects/GuidoRail/workspace/zephyr/include/zephyr/drivers/spi.h:334:25: note: in expansion of macro 'DT_PROP'
  334 |                         DT_PROP(node_id, duplex) |                      \
      |                         ^~~~~~~
C:/Projects/GuidoRail/workspace/zephyr/include/zephyr/drivers/spi.h:386:27: note: in expansion of macro 'SPI_CONFIG_DT'
  386 |                 .config = SPI_CONFIG_DT(node_id, operation_, delay_) \
      |                           ^~~~~~~~~~~~~
../src/spiFlashRaw.c:20:39: note: in expansion of macro 'SPI_DT_SPEC_GET'
   20 | const struct spi_dt_spec spiFlashDt = SPI_DT_SPEC_GET(DT_NODELABEL(spiflash), SPI_OP, 0);
      |                                       ^~~~~~~~~~~~~~~
C:/Projects/GuidoRail/workspace/zephyr/include/zephyr/devicetree.h:4229:24: note: in expansion of macro 'DT_N_NODELABEL_spiflash'
 4229 | #define DT_CAT(a1, a2) a1 ## a2
      |                        ^~
C:/Projects/GuidoRail/workspace/zephyr/include/zephyr/devicetree.h:197:29: note: in expansion of macro 'DT_CAT'
  197 | #define DT_NODELABEL(label) DT_CAT(DT_N_NODELABEL_, label)
      |                             ^~~~~~
../src/spiFlashRaw.c:20:55: note: in expansion of macro 'DT_NODELABEL'
   20 | const struct spi_dt_spec spiFlashDt = SPI_DT_SPEC_GET(DT_NODELABEL(spiflash), SPI_OP, 0);
      |                                                       ^~~~~~~~~~~~
zephyr/include/generated/devicetree_generated.h:11437:33: error: 'DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_P_frame_format' undeclared here (not in a function); did you mean 'DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_P_label_EXISTS'?
11437 | #define DT_N_NODELABEL_spiflash DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0
      |                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:/Projects/GuidoRail/workspace/zephyr/include/zephyr/devicetree.h:4231:29: note: in definition of macro 'DT_CAT3'
 4231 | #define DT_CAT3(a1, a2, a3) a1 ## a2 ## a3
      |                             ^~
C:/Projects/GuidoRail/workspace/zephyr/include/zephyr/drivers/spi.h:335:25: note: in expansion of macro 'DT_PROP'
  335 |                         DT_PROP(node_id, frame_format),                 \
      |                         ^~~~~~~
C:/Projects/GuidoRail/workspace/zephyr/include/zephyr/drivers/spi.h:386:27: note: in expansion of macro 'SPI_CONFIG_DT'
  386 |                 .config = SPI_CONFIG_DT(node_id, operation_, delay_) \
      |                           ^~~~~~~~~~~~~
../src/spiFlashRaw.c:20:39: note: in expansion of macro 'SPI_DT_SPEC_GET'
   20 | const struct spi_dt_spec spiFlashDt = SPI_DT_SPEC_GET(DT_NODELABEL(spiflash), SPI_OP, 0);
      |                                       ^~~~~~~~~~~~~~~
C:/Projects/GuidoRail/workspace/zephyr/include/zephyr/devicetree.h:4229:24: note: in expansion of macro 'DT_N_NODELABEL_spiflash'
 4229 | #define DT_CAT(a1, a2) a1 ## a2
      |                        ^~
C:/Projects/GuidoRail/workspace/zephyr/include/zephyr/devicetree.h:197:29: note: in expansion of macro 'DT_CAT'
  197 | #define DT_NODELABEL(label) DT_CAT(DT_N_NODELABEL_, label)
      |                             ^~~~~~
../src/spiFlashRaw.c:20:55: note: in expansion of macro 'DT_NODELABEL'
   20 | const struct spi_dt_spec spiFlashDt = SPI_DT_SPEC_GET(DT_NODELABEL(spiflash), SPI_OP, 0);
      |                                                       ^~~~~~~~~~~~


And I agree with the error - XX_spi_max_frequency and XX_frame_format and XX_duplex are not in devicetree_generated.h.  My question is why?


Here's the applicable devicetree_generated.h snippet.

/*
 * Devicetree node: /soc/peripheral@40000000/spi@b000/spiflash@0
 *
 * Node identifier: DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0
 */

/* Node's full path: */
#define DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_PATH "/soc/peripheral@40000000/spi@b000/spiflash@0"

/* Node's name with unit-address: */
#define DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_FULL_NAME "spiflash@0"

/* Node parent (/soc/peripheral@40000000/spi@b000) identifier: */
#define DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_PARENT DT_N_S_soc_S_peripheral_40000000_S_spi_b000

/* Node's index in its parent's list of children: */
#define DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_CHILD_IDX 0

/* Helper macros for child nodes of this node. */
#define DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_FOREACH_CHILD(fn)
#define DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_FOREACH_CHILD_SEP(fn, sep)
#define DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_FOREACH_CHILD_VARGS(fn, ...)
#define DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_FOREACH_CHILD_SEP_VARGS(fn, sep, ...)
#define DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_FOREACH_CHILD_STATUS_OKAY(fn)
#define DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_FOREACH_CHILD_STATUS_OKAY_SEP(fn, sep)
#define DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_FOREACH_CHILD_STATUS_OKAY_VARGS(fn, ...)
#define DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_FOREACH_CHILD_STATUS_OKAY_SEP_VARGS(fn, sep, ...)

/* Node's dependency ordinal: */
#define DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_ORD 111
#define DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_ORD_STR_SORTABLE 00111

/* Ordinals for what this node depends on directly: */
#define DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_REQUIRES_ORDS \
    110, /* /soc/peripheral@40000000/spi@b000 */

/* Ordinals for what depends directly on this node: */
#define DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_SUPPORTS_ORDS /* nothing */

/* Existence and alternate IDs: */
#define DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_EXISTS 1
#define DT_N_INST_0_spi_device  DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0
#define DT_N_NODELABEL_spiflash DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0

/* Bus info (controller: '/soc/peripheral@40000000/spi@b000', type: '['spi']') */
#define DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_BUS_spi 1
#define DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_BUS DT_N_S_soc_S_peripheral_40000000_S_spi_b000

/* Macros for properties that are special in the specification: */
#define DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_REG_NUM 1
#define DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_REG_IDX_0_EXISTS 1
#define DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_REG_IDX_0_VAL_ADDRESS 0 /* 0x0 */
#define DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_RANGES_NUM 0
#define DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_FOREACH_RANGE(fn)
#define DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_IRQ_NUM 0
#define DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_COMPAT_MATCHES_spi_device 1
#define DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_STATUS_okay 1

/* Pin control (pinctrl-<i>, pinctrl-names) properties: */
#define DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_PINCTRL_NUM 0

/* Generic property macros: */
#define DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_P_status "okay"
#define DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_P_status_STRING_UNQUOTED okay
#define DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_P_status_STRING_TOKEN okay
#define DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_P_status_STRING_UPPER_TOKEN OKAY
#define DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_P_status_IDX_0 "okay"
#define DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_P_status_IDX_0_EXISTS 1
#define DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_P_status_ENUM_IDX 1
#define DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_P_status_ENUM_VAL_okay_EXISTS 1
#define DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_P_status_ENUM_TOKEN okay
#define DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_P_status_ENUM_UPPER_TOKEN OKAY
#define DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_P_status_FOREACH_PROP_ELEM(fn) fn(DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0, status, 0)
#define DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_P_status_FOREACH_PROP_ELEM_SEP(fn, sep) fn(DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0, status, 0)
#define DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_P_status_FOREACH_PROP_ELEM_VARGS(fn, ...) fn(DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0, status, 0, __VA_ARGS__)
#define DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_P_status_FOREACH_PROP_ELEM_SEP_VARGS(fn, sep, ...) fn(DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0, status, 0, __VA_ARGS__)
#define DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_P_status_LEN 1
#define DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_P_status_EXISTS 1
#define DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_P_compatible {"spi-device"}
#define DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_P_compatible_IDX_0 "spi-device"
#define DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_P_compatible_IDX_0_STRING_UNQUOTED spi-device
#define DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_P_compatible_IDX_0_STRING_TOKEN spi_device
#define DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_P_compatible_IDX_0_STRING_UPPER_TOKEN SPI_DEVICE
#define DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_P_compatible_IDX_0_EXISTS 1
#define DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_P_compatible_FOREACH_PROP_ELEM(fn) fn(DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0, compatible, 0)
#define DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_P_compatible_FOREACH_PROP_ELEM_SEP(fn, sep) fn(DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0, compatible, 0)
#define DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_P_compatible_FOREACH_PROP_ELEM_VARGS(fn, ...) fn(DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0, compatible, 0, __VA_ARGS__)
#define DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_P_compatible_FOREACH_PROP_ELEM_SEP_VARGS(fn, sep, ...) fn(DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0, compatible, 0, __VA_ARGS__)
#define DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_P_compatible_LEN 1
#define DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_P_compatible_EXISTS 1
#define DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_P_reg {0 /* 0x0 */}
#define DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_P_reg_IDX_0 0
#define DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_P_reg_IDX_0_EXISTS 1
#define DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_P_reg_EXISTS 1
#define DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_P_label "spiFlash"
#define DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_P_label_STRING_UNQUOTED spiFlash
#define DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_P_label_STRING_TOKEN spiFlash
#define DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_P_label_STRING_UPPER_TOKEN SPIFLASH
#define DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_P_label_IDX_0 "spiFlash"
#define DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_P_label_IDX_0_EXISTS 1
#define DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_P_label_FOREACH_PROP_ELEM(fn) fn(DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0, label, 0)
#define DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_P_label_FOREACH_PROP_ELEM_SEP(fn, sep) fn(DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0, label, 0)
#define DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_P_label_FOREACH_PROP_ELEM_VARGS(fn, ...) fn(DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0, label, 0, __VA_ARGS__)
#define DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_P_label_FOREACH_PROP_ELEM_SEP_VARGS(fn, sep, ...) fn(DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0, label, 0, __VA_ARGS__)
#define DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_P_label_LEN 1
#define DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_P_label_EXISTS 1

Edit:

!!! Workaround.

I hard-coded the following and the compiler seems happy. Can somebody confirm it's equivalent to what I have in my board .dts file? Thanks

#define SPI_OP  (SPI_OP_MODE_MASTER | SPI_MODE_GET(0) | SPI_WORD_SET(8) | SPI_LINES_SINGLE)

#if 0
const struct spi_dt_spec spiFlashDt = SPI_DT_SPEC_GET(DT_NODELABEL(spiflash), SPI_OP, 0);
#else


const struct spi_dt_spec spiFlashDt =
{
    .bus = DEVICE_DT_GET(DT_NODELABEL(spi3)),
    .config.cs.gpio.dt_flags = GPIO_ACTIVE_LOW,
    .config.cs.gpio.pin = 19,
    .config.cs.delay = 0,
    .config.frequency = 40000000,
    .config.operation = SPI_OP,
    .config.slave = 0,
};

  • Hi,

    Could you edit your ticket and put the error message inside Insert->Code?
    This will help us keep DevZone tidy.

    This almost looks like an XY Problem to me: Is your SPI flash NOR flash?
    What do you intend to use the external flash for?

    Regards,
    Sigurd Hellesvik

  • I'm not familiar with XY Problems. Based on the link you sent it would imply that my attempt to use device-tree MACROs isn't necessary for me to be able to read/write data from external SPI flash.  And I guess that's true because I perhaps found a work-around that doesn't use device-tree.  Having said that, all the lessons in the online introductory classes suggest using .dts files and device-tree MACROs, so I assumed that was the preferred way of configuring drivers.  I see examples online that do exactly what I was trying to do, yet when I do the same thing, required configuration #defines (e.g. XXXX_spi_max_frequency) are missing from devicetree_generated.h.  I'd like to understand why that is.

    As for our intended use of the SPI flash, we'd like to store run-time data and status that we can subsequently retrieve at a later time.

    Here's the error message in an Insert->Code

    In file included from C:/Projects/GuidoRail/workspace/zephyr/include/zephyr/arch/arm/aarch32/arch.h:20,
                     from C:/Projects/GuidoRail/workspace/zephyr/include/zephyr/arch/cpu.h:19,
                     from C:/Projects/GuidoRail/workspace/zephyr/include/zephyr/kernel_includes.h:33,
                     from C:/Projects/GuidoRail/workspace/zephyr/include/zephyr/kernel.h:17,
                     from ../src/spiFlashRaw.c:7:
    zephyr/include/generated/devicetree_generated.h:11437:33: error: 'DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_P_spi_max_frequency' undeclared here (not in a function); did you mean 'DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_P_status_LEN'?
    11437 | #define DT_N_NODELABEL_spiflash DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0
          |                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    C:/Projects/GuidoRail/workspace/zephyr/include/zephyr/devicetree.h:4231:29: note: in definition of macro 'DT_CAT3'
     4231 | #define DT_CAT3(a1, a2, a3) a1 ## a2 ## a3
          |                             ^~
    C:/Projects/GuidoRail/workspace/zephyr/include/zephyr/drivers/spi.h:332:30: note: in expansion of macro 'DT_PROP'
      332 |                 .frequency = DT_PROP(node_id, spi_max_frequency),       \
          |                              ^~~~~~~
    C:/Projects/GuidoRail/workspace/zephyr/include/zephyr/drivers/spi.h:386:27: note: in expansion of macro 'SPI_CONFIG_DT'
      386 |                 .config = SPI_CONFIG_DT(node_id, operation_, delay_) \
          |                           ^~~~~~~~~~~~~
    ../src/spiFlashRaw.c:20:39: note: in expansion of macro 'SPI_DT_SPEC_GET'
       20 | const struct spi_dt_spec spiFlashDt = SPI_DT_SPEC_GET(DT_NODELABEL(spiflash), SPI_OP, 0);
          |                                       ^~~~~~~~~~~~~~~
    C:/Projects/GuidoRail/workspace/zephyr/include/zephyr/devicetree.h:4229:24: note: in expansion of macro 'DT_N_NODELABEL_spiflash'
     4229 | #define DT_CAT(a1, a2) a1 ## a2
          |                        ^~
    C:/Projects/GuidoRail/workspace/zephyr/include/zephyr/devicetree.h:197:29: note: in expansion of macro 'DT_CAT'
      197 | #define DT_NODELABEL(label) DT_CAT(DT_N_NODELABEL_, label)
          |                             ^~~~~~
    ../src/spiFlashRaw.c:20:55: note: in expansion of macro 'DT_NODELABEL'
       20 | const struct spi_dt_spec spiFlashDt = SPI_DT_SPEC_GET(DT_NODELABEL(spiflash), SPI_OP, 0);
          |                                                       ^~~~~~~~~~~~
    In file included from ../src/spiFlashRaw.c:11:
    ../src/spiFlashRaw.c:18:39: warning: implicit declaration of function 'SPI_MODE_SET'; did you mean 'SPI_MODE_GET'? [-Wimplicit-function-declaration]
       18 | #define SPI_OP  (SPI_OP_MODE_MASTER | SPI_MODE_SET(0) | SPI_WORD_SET(8) | SPI_LINES_SINGLE)
          |                                       ^~~~~~~~~~~~
    C:/Projects/GuidoRail/workspace/zephyr/include/zephyr/drivers/spi.h:333:31: note: in definition of macro 'SPI_CONFIG_DT'
      333 |                 .operation = (operation_) |                             \
          |                               ^~~~~~~~~~
    ../src/spiFlashRaw.c:20:39: note: in expansion of macro 'SPI_DT_SPEC_GET'
       20 | const struct spi_dt_spec spiFlashDt = SPI_DT_SPEC_GET(DT_NODELABEL(spiflash), SPI_OP, 0);
          |                                       ^~~~~~~~~~~~~~~
    ../src/spiFlashRaw.c:20:79: note: in expansion of macro 'SPI_OP'
       20 | const struct spi_dt_spec spiFlashDt = SPI_DT_SPEC_GET(DT_NODELABEL(spiflash), SPI_OP, 0);
          |                                                                               ^~~~~~
    zephyr/include/generated/devicetree_generated.h:11437:33: error: 'DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_P_duplex' undeclared here (not in a function); did you mean 'DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_P_label'?
    11437 | #define DT_N_NODELABEL_spiflash DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0
          |                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    C:/Projects/GuidoRail/workspace/zephyr/include/zephyr/devicetree.h:4231:29: note: in definition of macro 'DT_CAT3'
     4231 | #define DT_CAT3(a1, a2, a3) a1 ## a2 ## a3
          |                             ^~
    C:/Projects/GuidoRail/workspace/zephyr/include/zephyr/drivers/spi.h:334:25: note: in expansion of macro 'DT_PROP'
      334 |                         DT_PROP(node_id, duplex) |                      \
          |                         ^~~~~~~
    C:/Projects/GuidoRail/workspace/zephyr/include/zephyr/drivers/spi.h:386:27: note: in expansion of macro 'SPI_CONFIG_DT'
      386 |                 .config = SPI_CONFIG_DT(node_id, operation_, delay_) \
          |                           ^~~~~~~~~~~~~
    ../src/spiFlashRaw.c:20:39: note: in expansion of macro 'SPI_DT_SPEC_GET'
       20 | const struct spi_dt_spec spiFlashDt = SPI_DT_SPEC_GET(DT_NODELABEL(spiflash), SPI_OP, 0);
          |                                       ^~~~~~~~~~~~~~~
    C:/Projects/GuidoRail/workspace/zephyr/include/zephyr/devicetree.h:4229:24: note: in expansion of macro 'DT_N_NODELABEL_spiflash'
     4229 | #define DT_CAT(a1, a2) a1 ## a2
          |                        ^~
    C:/Projects/GuidoRail/workspace/zephyr/include/zephyr/devicetree.h:197:29: note: in expansion of macro 'DT_CAT'
      197 | #define DT_NODELABEL(label) DT_CAT(DT_N_NODELABEL_, label)
          |                             ^~~~~~
    ../src/spiFlashRaw.c:20:55: note: in expansion of macro 'DT_NODELABEL'
       20 | const struct spi_dt_spec spiFlashDt = SPI_DT_SPEC_GET(DT_NODELABEL(spiflash), SPI_OP, 0);
          |                                                       ^~~~~~~~~~~~
    zephyr/include/generated/devicetree_generated.h:11437:33: error: 'DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_P_frame_format' undeclared here (not in a function); did you mean 'DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0_P_label_EXISTS'?
    11437 | #define DT_N_NODELABEL_spiflash DT_N_S_soc_S_peripheral_40000000_S_spi_b000_S_spiflash_0
          |                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    C:/Projects/GuidoRail/workspace/zephyr/include/zephyr/devicetree.h:4231:29: note: in definition of macro 'DT_CAT3'
     4231 | #define DT_CAT3(a1, a2, a3) a1 ## a2 ## a3
          |                             ^~
    C:/Projects/GuidoRail/workspace/zephyr/include/zephyr/drivers/spi.h:335:25: note: in expansion of macro 'DT_PROP'
      335 |                         DT_PROP(node_id, frame_format),                 \
          |                         ^~~~~~~
    C:/Projects/GuidoRail/workspace/zephyr/include/zephyr/drivers/spi.h:386:27: note: in expansion of macro 'SPI_CONFIG_DT'
      386 |                 .config = SPI_CONFIG_DT(node_id, operation_, delay_) \
          |                           ^~~~~~~~~~~~~
    ../src/spiFlashRaw.c:20:39: note: in expansion of macro 'SPI_DT_SPEC_GET'
       20 | const struct spi_dt_spec spiFlashDt = SPI_DT_SPEC_GET(DT_NODELABEL(spiflash), SPI_OP, 0);
          |                                       ^~~~~~~~~~~~~~~
    C:/Projects/GuidoRail/workspace/zephyr/include/zephyr/devicetree.h:4229:24: note: in expansion of macro 'DT_N_NODELABEL_spiflash'
     4229 | #define DT_CAT(a1, a2) a1 ## a2
          |                        ^~
    C:/Projects/GuidoRail/workspace/zephyr/include/zephyr/devicetree.h:197:29: note: in expansion of macro 'DT_CAT'
      197 | #define DT_NODELABEL(label) DT_CAT(DT_N_NODELABEL_, label)
          |                             ^~~~~~
    ../src/spiFlashRaw.c:20:55: note: in expansion of macro 'DT_NODELABEL'
       20 | const struct spi_dt_spec spiFlashDt = SPI_DT_SPEC_GET(DT_NODELABEL(spiflash), SPI_OP, 0);

    Thank you.

  • Spi said:
    I'm not familiar with XY Problems.

    It is basically that you ask for one thing but need another. I do not know that this is the case, but I find it useful to ask for it in som cases.
    The best way to figure this out is to ask what you need to use it for.

    Spi said:
    As for our intended use of the SPI flash, we'd like to store run-time data and status that we can subsequently retrieve at a later time.

    So that is your "Problem X"

    In this case, the standard Zephyr way to add an external flash is as such:

    1. Add flash information to the devicetree.

    2. Enable Kconfig options for drivers related to the flash.

    3. Define partitions for external storage.

    4. Run any library for storage. These should now automatically know to use external flash from partitioning. (

    So let us start looking at 1:

    Which SPI flash chip do you use? Is it NOR flash? Does it support JEDEC?

  • Thank you. The flash is probably  NOR, and it's JEDEC compliant.. I know there off-the-shelf drivers for this but for a few reasons I prefer to access the SPI flash using

    compatible="spi-device";

    So I configure spi3 as per

    :

    &spi3 {
    	compatible = "nordic,nrf-spim";
    	status = "okay";
    	cs-gpios = <&gpio0 19 GPIO_ACTIVE_LOW>;  // Memory CS
    	pinctrl-0 = <&spi3_default>;
    	pinctrl-1 = <&spi3_sleep>;
    	pinctrl-names = "default", "sleep";
    
    	spiflash: spiflash@0 {
    		status = "okay";
    		compatible = "spi-device";
    //		compatible="jedec,spi-nor";
    		reg = <0>; 
    		label = "spiFlash";
    		frame-format = <0>;
    		spi-max-frequency = <40000000>;
    	};

    I think that's okay. But unfortunately the xxxx_spi_max_frequency parameter does not appear in the resultant devicetree_generated.h file, even though from my limited yaml knowledge, "spi_max_frequency" is a required attribute for "spi-device" compatible.

  • I think maybe you may need to define a vendor. Does it work if you do "vnd,spi-device"?

Related