[BeagleBone Black] How to set gpio pin when booting

Robert,
Thank you for keeping me informed. My colleague and I like the idea of the ‘line’ class. I work with digital inputs(s) and output(s) every day. From my embedded controller perspective most of my outputs are to relays, coils, solenoids, control signals to other digital devices… with a few connected to indicators (LEDs, bulbs). Most inputs are toggle-switches, push-buttons, control signals from other digital devices… none are from keypads. I now understand better that using the gpio-led class is used as ‘output’ and gpio-keypad is used as ‘input’. However ‘gpio-line’ is a much better description.

I see that Rodolfo has gotten feedback from Linus Walleij. I am keeping an eye on their conversation.

Robert,

Can you show me an example on how to setup the gpio as pull up input on mode 7? I need to configure pins P8-7 through P8-19. I’ve managed to get the output gpio working fine, but i’ve tried many times with the input and I just can’t figure it out.

Thanks for your help!

Alain

Hi

I think I have followed this whole discussion quite thoroughly and everything seems clear, but I have to go back to the basic question posed by taek8461: “How to set gpio pin when booting” but, I would like to use the pin bindings created in /sys/class/gpio/ (I wouldn’t want to use the script and systemd for this). I saw that is possible write a device-tree overlay to create such a structure in /sys/class/gpio/ at boot time. Could you please give some hints on how to write .dts or give an example. Below is my sample:

/dts-v1/;
/plugin/;

/ {
  compatible = "ti,beaglebone", "ti,beaglebone-black";
  part-number = "cape-gpio";
  version = "00A0";

  exclusive-use =
    "P9.42";

  fragment@0 {
    target = <&am33xx_pinmux>;
    __overlay__ {
      P9_42_default_pin: pinmux_P9_42_default_pin {
        pinctrl-single,pins = <
          0x164 0x17
        >;
      };
      P9_42_pin: pinmux_P9_42_pin {
        pinctrl-single,pins = <
          0x164 0x2f
        >;
      };
      P9_42_pu_pin: pinmux_P9_42_pu_pin {
        pinctrl-single,pins = <
          0x164 0x37
        >;
      };
      P9_42_pd_pin: pinmux_P9_42_pd_pin {
        pinctrl-single,pins = <
          0x164 0x27
        >;
      };
    };
  };

  fragment@1 {
    target = <&ocp>;
    __overlay__ {
      P9_42_pinmux {
        compatible = "bone-pinmux-helper";
        status = "okay";
        pinctrl-names = "default", "gpio", "gpio_pu", "gpio_pd";
        pinctrl-0 = <&P9_42_default_pin>;
        pinctrl-1 = <&P9_42_pin>;
        pinctrl-2 = <&P9_42_pu_pin>;
        pinctrl-3 = <&P9_42_pd_pin>;
      };
    };
  };
};`

Regards
Daniel

pins muxed in /sys/class/gpio only occur after you export then manually after booting up…

Do you want these pin’s to be input or output?’

For output:

Do you want the output state set as early as possible, without the ability to change it? → gpio-hog

Do you want the output state to be set just a little later then gpio-hog, but want the ablity to change it? → gpio-led

Input:

Best is still export once booted, but gpio-keyboard can make it an input sooner and have and reponse tied to keyboard subsystem…

Regards,

Hi Robert. Thank you for your response :slight_smile:

Actually, I just want the pins to be exported after booting in /sys/class/gpio/. Nothing more.
I am using version

Linux beaglebone 4.14.49-ti-r54 #1 SMP PREEMPT Fri Jun 15 22:14:13 UTC 2018 armv7l GNU/Linux

Right now, after booting, I have only ~gpio12 and ~gpio13 ready (as I heard, these pins reserved for use by other capes and shouldn’t be modified). So now, I have to manually (or script) export the rest of the pins I need - ok, its work, but…
If I have a choice :), then let’s say that I would like to have selected pins available after the system start (let it be 8 pullup inputs and 9 outputs in the off state) - but let’s not exaggerate - the rule of how to do it in the overlay will be enough.
Pins shouldn’t be a hog-pins. It should be possible to change the direction of the pin and modify or read the value file.
As already mentioned, I have seen a similar overlay that worked this way, but I have no way of finding out from the author how it achieved it.

Regards
Daniel