nixy82
Posts: 42
Joined: Sat Sep 12, 2015 9:19 am

Device Tree Overlay to adjust GPIO Outputs

Sat Sep 12, 2015 5:46 pm

Hi

I'd like to add an overlay to alter the standard compute module GPIO settings without resorting to a custom device tree blob or adding in a load of raspi-gpio commands during startup

If I've understood the device tree overlay system correctly I should be able to apply an overlay file to alter these settings and add the overlay as an add-on at the bottom of config.txt

So far looking at basic device tree file I've determined what lines I would need to edit out of the main dts file if I were to go for a custom blob as a starting point, however I'm a bit lost as to what I need to wrap the below into turn this into a valid overlay file

Code: Select all

  pin@p34  { function = "output"; termination = "no_pulling"; startup_state = "inactive"; polarity = "active_high"; };
  pin@p35  { function = "output"; termination = "no_pulling"; startup_state = "inactive"; polarity = "active_low"; }; 
  pin@p36  { function = "output"; termination = "no_pulling"; startup_state = "inactive"; polarity = "active_low"; }; 
  pin@p39  { function = "output"; termination = "no_pulling"; startup_state = "inactive"; polarity = "active_low"; }; 
  pin@p44  { function = "output"; termination = "no_pulling"; startup_state = "inactive"; polarity = "active_low"; }; 
I've tried this (see below) it's compiled and not given any errors and so added the overlay to the config.txt file, but it's not done anything either...

Code: Select all

/dts-v1/;

/ {
  videocore {

    pins_cm {

      pin_config {
                pin@p34  { function = "output"; termination = "no_pulling"; startup_state = "inactive"; polarity = "active_high"; };
                pin@p35  { function = "output"; termination = "no_pulling"; startup_state = "inactive"; polarity = "active_low"; }; 
                pin@p36  { function = "output"; termination = "no_pulling"; startup_state = "inactive"; polarity = "active_low"; }; 
                pin@p39  { function = "output"; termination = "no_pulling"; startup_state = "inactive"; polarity = "active_low"; }; 
                pin@p44  { function = "output"; termination = "no_pulling"; startup_state = "inactive"; polarity = "active_low"; };  
      }; // pin_defines

    }; // pins_cm

  }; // videocore
};

Code: Select all

vcdbg log msg
<snip>
002045.785: Loaded overlay 'systemgpio'
<snip>

Code: Select all

raspi-gpio get
<snip>
  GPIO 34: level=1 fsel=0 alt=  func=INPUT
  GPIO 35: level=1 fsel=0 alt=  func=INPUT
  GPIO 36: level=1 fsel=0 alt=  func=INPUT
  GPIO 37: level=0 fsel=0 alt=  func=INPUT
  GPIO 38: level=0 fsel=0 alt=  func=INPUT
  GPIO 39: level=0 fsel=0 alt=  func=INPUT
  GPIO 40: level=0 fsel=0 alt=  func=INPUT
  GPIO 41: level=0 fsel=0 alt=  func=INPUT
  GPIO 42: level=0 fsel=0 alt=  func=INPUT
  GPIO 43: level=0 fsel=0 alt=  func=INPUT
  GPIO 44: level=0 fsel=0 alt=  func=INPUT
<snip>
Is there an example I can crib from, or can someone point out where I'm going wrong?

Thanks in advance

nixy82
Posts: 42
Joined: Sat Sep 12, 2015 9:19 am

Re: Device Tree Overlay to adjust GPIO Outputs

Mon Sep 14, 2015 5:57 pm

Got a bit further with this

Found a page here :

https://github.com/fivdi/onoff/wiki/Ena ... spberry-Pi

Which I've modified as below :

Code: Select all

/dts-v1/;
/plugin/;

/ {
    compatible = "brcm,bcm2708";

    fragment@0 {
        target = <&gpio>;
        __overlay__ {
            pinctrl-names = "default";
            pinctrl-0 = <&my_pins>;

            my_pins: my_pins {
                brcm,pins     = <34 35 36 39 44>;    /* gpio no. */
                brcm,function = <1  1  1  1  1> ;    /* 0:in, 1:out */
                brcm,pull     = <0  0  0  0  0>;     /* 2:up 1:down 0:none */
               // How to set active state?
               // How to set initial state?
            };
        };
    };
};
So I now get this :

Code: Select all

raspi-gpio get

  GPIO 34: level=0 fsel=1 alt=  func=OUTPUT
  GPIO 35: level=0 fsel=1 alt=  func=OUTPUT
  GPIO 36: level=0 fsel=1 alt=  func=OUTPUT
  GPIO 37: level=0 fsel=0 alt=  func=INPUT
  GPIO 38: level=0 fsel=0 alt=  func=INPUT
  GPIO 39: level=0 fsel=1 alt=  func=OUTPUT
  GPIO 40: level=0 fsel=0 alt=  func=INPUT
  GPIO 41: level=0 fsel=0 alt=  func=INPUT
  GPIO 42: level=0 fsel=0 alt=  func=INPUT
  GPIO 43: level=0 fsel=0 alt=  func=INPUT
  GPIO 44: level=0 fsel=1 alt=  func=OUTPUT
  GPIO 45: level=0 fsel=0 alt=  func=INPUT
But I'm still missing the params to setup active high/low and startup state as you would using the syntax below :

Code: Select all

pin@p34  { function = "output"; termination = "no_pulling"; startup_state = "inactive"; polarity = "active_high"; };
Can anyone shed any light on how you do that part ?

notro
Posts: 695
Joined: Tue Oct 16, 2012 6:21 pm
Location: Drammen, Norway

Re: Device Tree Overlay to adjust GPIO Outputs

Tue Sep 15, 2015 9:28 am

Maybe GPIO hogging can help you: https://www.kernel.org/doc/Documentatio ... o/gpio.txt
I haven't tried it myself.

brdirais
Posts: 1
Joined: Mon Mar 30, 2015 3:08 pm

Re: Device Tree Overlay to adjust GPIO Outputs

Mon Jun 20, 2016 12:33 pm

Hi,
Did you get the answer to your question? (how to set initial GPIO level using device tree)
I'm facing the same problematic
Thank you
BR

nixy82
Posts: 42
Joined: Sat Sep 12, 2015 9:19 am

Re: Device Tree Overlay to adjust GPIO Outputs

Mon Jun 20, 2016 3:38 pm

Hi

No I kind of gave up with that in the end!

I've only managed to set initial levels via the main DT file (as per first post), which was good enough for what I wanted

I did see one of the RPi engineers (James?) showing someone else a trick that allowed you to achieve something similar using overlays, this was some method that involved of by hooking commands like "set this IO" into an existing DT stub for another function (LEDs possibly?) so it gets executed after something that's /always/ going to happen.

I can't really remember now unfortunately but I did think at the time it was a bit cunning...

dloranger
Posts: 34
Joined: Wed Nov 02, 2016 1:56 am

Re: Device Tree Overlay to adjust GPIO Outputs

Wed Mar 15, 2017 5:33 am

It seems like this is a fairly common request, I too am facing this problem but I must have my pins configured during the device tree sequencing as one of the pins is the reset for my device, and being stuck in reset, the blob that loads the device fails to locate the device and moves on.

Has a solution come up for this that does not involve modifying default files <dtblob.dts or others> or other hackery? I don't want to end up in a custom model other that having a overlay to load.

nixy82
Posts: 42
Joined: Sat Sep 12, 2015 9:19 am

Re: Device Tree Overlay to adjust GPIO Outputs

Wed Mar 15, 2017 8:24 am

Have a look at this :

viewtopic.php?f=107&t=168145

There's a dt-overlay suggestion there

I /think/ the best I've seen was creating an input with the pulls in the right direction as a pseudo output, which you can then redefine as an output once you've booted via raspi-gpio

Alternatively you can bite the bullet and compile a new dt-blob.bin file, it's not as scary as you'd think

Use the compatible device tree file for your platform as a starting point and add in any custom lines. Compile and insert in /boot as dt-blob.bin and all being well it'll get loaded in preference to the default ones.

The other angle here is to revisit which GPIO pins you are using and select ones that "go with" the design off the bat so you would only need to interact with the GPIO when you want to toggle a reset.

Just my 2c here, not a definitive answer.

dloranger
Posts: 34
Joined: Wed Nov 02, 2016 1:56 am

Re: Device Tree Overlay to adjust GPIO Outputs

Wed Mar 15, 2017 5:47 pm

so for now, I haven't been able to get the overlays to do what I want, specifically targetting GPIO26

in any case, I have modified the dt-blob to update this pin for output high. It works for me, but not sure if it will be accepted into the project I am working on just yet.

added the following to the dt-blob at line 1167 if anyone else comes along and this might help them (using pi 3 v1.2)
pin@p26 { function = "output"; termination = "no_pulling"; startup_state = "active"; };

Return to “Device Tree”