I was able to put together a custom driver for a device that already had a binding with a little help, and it works great! Now I have another device that I would like to add, but this one doesn’t have an existing device binding, so I am trying to add my own.
The device is a SPI SRAM IC that contains two dies of 0×40000 bytes each. I figured the following binding made sense, and I put it in my_app/dts/bindings/sram/sram,my_sram.yaml
:
include: base.yaml
on-bus: spi
properties:
reg:
required: true
label:
required: true
spi_max_frequency:
type: int
required: true
description: Maximum clock frequency of device's SPI interface in Hz
dies:
type: int
required: true
description: Number of SRAM dies in the IC
die_size:
type: int
required: true
description: Size of each die on the device
Then I add the device to my overlay:
...
sram@0 {
compatible = "sram,my_sram";
label = "SRAM";
status = "okay";
reg = <0>;
spi_max_frequency = <16000000>;
dies = <2>;
die_size = <0x40000>;
};
...
When I add the device to my application and build, I get errors that spi_max_frequency
, dies
, and die_size
cannot be found when using DT_INST_PROP(inst, spi_max_frequency)
and similar. When I check in the generated devicetree_unfixed.h
I indeed do not find these entries, although all of the other ones (reg
, label
, the device path, bus, etc.) appear and are correct. I might be wrong, but this seems very much like the build system isn’t finding my binding yaml and is just applying the base props to the device. I tried adding the yaml file instead to my_app/dts/bindings
(i.e., no sram
subdirectory), to my_app/src
, and to my_app
, but to no success. Am I missing something about pointing the build system to a custom, local binding? Should it be added, e.g., to CMakeLists.txt
somewhere?
Here’s one of the error messages where it can’t find spi_max_frequency
error: 'DT_N_S_soc_S_peripheral_40000000_S_spi_a000_S_sram_0_P_spi_max_frequency' undeclared here (not in a function); did you mean 'DT_N_S_soc_S_peripheral_40000000_S_spi_a000_S_sram_0_P_reg'?
...
note: in expansion of macro 'DT_INST_PROP'
.frequency = DT_INST_PROP(inst, spi_max_frequency), \
^~~~~~~~~~~~