Devicetree overlay for simple GPIO

It seems like there are lots of questions regarding simple GPIOs and devicetree, but I can't quite find something that describes my problem:

I am using the nrf52840dk, and I successfully created an overlay file to read/write to an I2C device, but I am having trouble adding a simple GPIO pin to my overlay file.

First, I tried adding the following to my overlay file:

columnswitchint: column_switch_input
    {
             compatible = "gpio-keys";
            gpios = <&gpio0 2 GPIO_ACTIVE_LOW>;
            label = "Column Switch Input Signal";
    };

When I try to build, I get the error "Property not mentioned in "/" ".  

Next, I tried declaring the pin like the 'buttons' definition in the .dts file for the blinky example:

sample_gpio_signals
{

    compatible = "gpio-keys";
    columnswitchint: column_switch_input
    {
           
            gpios = <&gpio0 2 GPIO_ACTIVE_LOW>;
            label = "Column Switch Interrupt Signal";
    };
};

This results in the error "Node column_switch_input should have "compatible" property".

Finally, I tried moving the compatible property down into the node:

sample_gpio_signals
{

    columnswitchint: column_switch_input
    {
   
            compatible = "gpio-keys";
            gpios = <&gpio0 2 GPIO_ACTIVE_LOW>;
            label = "Column Switch Interrupt Signal";
    };
};

And this results in the error "Property not mentioned in "gpio-keys".  Obviously 'gpios' is one of the only two properties declared in gpio-keys, so I'm stuck.

What am I missing here?  

  • ..and I apologize in advance for the terrible formatting!

  • Hello,

     I think the issue is with the compatible section here. AFAIK, the system always looks for the matching binding file and for this compatible properties are used. Take a look at this page which explains more on this. I think you need to create a binding file inside ncs\v2.x.x\nrf\dts\bindings and then add this to your dts node.
    Creating binding file is explained here. Something like below need to be created. Each section inside the yaml file is described here.

    .

    description: GPIO test
    
    compatible: "xyz,test"
    
    include: base.yaml
    
    properties:
      status:
        required: true
    
      gpios:
        type: phandle-array
        required: true
        description: |
          GPIO to use as testpin.

    Try adding this to your dts node. Something like below

    xyz: test {
    	compatible = "xyz,test";
    	gpios = <&gpio0 29 GPIO_ACTIVE_HIGH>;
    };

    I am not completely sure on this as I haven't tried this before. Give it a shot and let me know.

    Kind Regards,

    Abhijith

  • Hi Abhijith,

    I understand what you're saying, but the "gpio-keys" binding I am trying to use is already present at

    ncs\v2.1.2\zephyr\dts\bindings\gpio

    The file nrf52840dk_nrf52840.dts generated by the blinky example uses the 'gpio-keys' binding with no issues, so why can't I use it as well on my .overlay file?

    Also, if I am going to create my own binding files (which I've tried and not been successful yet), I would like to create them in my own application directory (and not in the ncs\xx\xx structure) so that I can commit them to my repository with the rest of my project files, but this is a separate topic. For now, I just want to be able to use the 'gpio-keys' binding in my overlay file (or any other binding in the ncs\v2.1.2\zephyr\dts\bindings for that matter).

    Thanks

  • Actually, if you can just point me to an example that toggles a GPIO pin on the nrf52840dk that is NOT one of the on-board LEDs, that will probably be enough to get me pointed in the right direction.

    Ideally the example should use a .overlay file (and not modify the original .dts file).


  • Also, just to be clear, if I add

    sample_gpio_signals

    {
        compatible = "gpio-keys";
        columnswitchint: column_switch_input

        {   
                gpios = <&gpio0 2 GPIO_ACTIVE_LOW>;
                label = "Column Switch Interrupt Signal";
        };
    };

    To the .dts file (and not the overlay file), the project builds and works just fine.  My concern with this is that now I've modified a file that is not in my project directory and I can't easily commit it to my repository.

Related