How do I make a device tree overlay which turns GPIO 7 on my Raspberry Pi Rev 2 Model B to a HIGH OUTPUT pin?

EDIT: I require the pin to be this way as early as possible. That is why I am thinking of DT overlays. Setting the pin when the operating system is running is too late.

  • 1
    I know it's not the software solution you're looking for, but couldn't you just use a pull up resistor? – jDo Mar 13 '16 at 4:36
  • 1
    Would I be able to control the pin afterwards if I did this? – mcsilvio Mar 13 '16 at 20:51
  • I would think so, yeah. Provided, of course, that the value of the resistor between the GPIO pin and whatever it's connected to is considerably smaller than the value of the pull-up. Say, 500-1000 ohm from GPIO to the thing you're controlling and 10 times that from GPIO to 3v3. What are you controlling with the GPIO pin? – jDo Mar 13 '16 at 21:00

See: https://www.kernel.org/doc/Documentation/devicetree/bindings/pinctrl/brcm,bcm2835-gpio.txt

This is how I did inputs with pull up resisters:


/ {
    compatible = "brcm,bcm2835", "brcm,bcm2708", "brcm,bcm2709";

    fragment@0 {
        target-path = "/soc/gpio";
        __overlay__ {
            keypad_pins: keypad_pins {
                brcm,pins = <5 6 17 19 22 26>;
                brcm,function = <0>;
                brcm,pull = <2>;

The name can be anything. BTW it took weeks of on and off searching to find this.

  • I tried this but it didn't work. Note that I do not require pulling up. I require no pulling (I think) and ACTIVE HIGH on an OUTPUT pin. This overlay is very close I believe. It looks like several of the documented examples look. I tried a few variations on it but nothing worked. – mcsilvio Mar 13 '16 at 20:36

Either I'm blind, or the whole concept of device tree overlays is very badly documented. Here is what I've found:

Install prerequisites:

sudo apt-get update
sudo apt-get install raspi-gpio device-tree-compiler

Make a text file and call it something.dts (adapted from this).


/ {
    compatible = "brcm,bcm2708";

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

            my_pins: my_pins {
                brcm,pins = <7>;     /* GPIO7 */
                brcm,function = <1>; /* Output */

This will make the GPIO pin to an output, but doesn't specify the output level (LOW or HIGH). According to this thread, there is no way to specify this, here. It seems like the default is LOW, at least for GPIO7.

If you are OK with a weak pull-up (i.e. when you don't have to supply a lot of current, then you can make the pin an input, by replacing the my_pins section with the following:

my_pins: my_pins {
    brcm,pins = <7>;     /* GPIO7 */
    brcm,function = <0>; /* Input */
    brcm,pull = <2>;     /* Pull up */

Some pins have altenative functions, which allow you to cheat...

my_pins: my_pins {
    brcm,pins = <7>;     /* GPIO7 */
    brcm,function = <4>; /* Alternative function 0 = SPI0 CE1 */

To test the pull-up strength, connect a resistor between GPIO7 and GND, and measure the voltage drop on the pin. With alt0, the voltage drops to 2.3V when I connect a 100 ohm resistor between GPIO7 and GND, which equates to a pull-up of about 43 ohms on that pin. A normal input with pull-up drops to 0.16V with a 2.6kOhm resistor, which means the pull-up is equivalent to about 51kOhm.

If you need even more drive strength, build an external logic buffer (a crude but effective one can be implemented with a single NPN BJT and one or two resistors).

Another options is to accept the low output on GPIO7, and use a logic inverter (can be done with a PNP BJT and one or two resistors).

Compile the dts file using dtc:

dtc -@ -I dts -O dtb -o something.dtb something.dts

Put it in /boot/overlays:

sudo cp something.dts /boot/overlays/something.dts

Add a line to /boot/config.txt:



Check if it works using a multimeter on the relevant GPIO pin, and raspi-gpio:

raspi-gpio get 7

Example output:

GPIO 7: level=1 fsel=4 alt=0 func=SPI0_CE1_N

You don't need overlay for this. Simply run at the command prompt

echo 7 > /sys/class/gpio/export

after that

echo high > /sys/class/gpio/gpio7/direction 

Update: It will work only when OS is running.
If you want to make a changes as early as possible I suggest to use hardware solution: inverter (NOT gate)

  • I edited a key piece of info OUT of my question. My mistake. I will put it back. Does your answer still apply? – mcsilvio Mar 11 '16 at 2:28
  • How early must it be? raspberry bootstrap process is complicated and some time passes before kernel executing. – edo1 Mar 12 '16 at 23:52
  • I believe the correct solution is with device-tree overlays, but not many (none) examples exist for my problem. – mcsilvio Mar 13 '16 at 20:35
  • Maybe, but some steps need to be done before kernel will be executed. So it is impossible to set output value with kernel immediately after poweron. – edo1 Mar 13 '16 at 20:40
  • Don't need immediately. Need "as early as possible". – mcsilvio Mar 13 '16 at 20:50

You could "misuse" the gpio-poweroff overlay for this. Just tested it on GPIO7. Add this line to /boot/config.txt, and reboot:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.