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), \
             ^~~~~~~~~~~~

Answering my own question here. Not entirely sure which piece of this did the trick, but it was something about underscores and dashes. I noticed for similarly names devices (ones with a logical space), that most of the file structure, the overlays, and the properties listed in the binding yaml use a dash (-), but then an underscore (_) is used throughout the actual code to refer to these objects. So I went back and changed my_sram to my-sram in the yaml, the overlay, and in the file structure (except my actual driver code, which I left as my_sram.c and my_sram.h) and I changed spi_max_frequency to spi-max-frequency and die_size to die-size. Afterwards, my binding was picked up properly from my_app/dts/bindings/sram/sram,my-sram.yaml and I can see the properties correctly.

If ever I find the time, I think some sort of validation tool that looks for things like this might be handy… Does anyone know off-hand if this type of thing is documented somewhere? I’m having difficulty finding it.

    I’ve had the same pain of dealing with the differentiation between dashes an underscores. It was trial by fire for me. 😵

    Glad you got it working though TrivialSolution !

    Terms and Conditions | Privacy Policy