GeorgeIoak
Posts: 43
Joined: Thu Aug 30, 2012 1:50 am

Confirmation of gpio-poweroff Behavior

Wed Jan 03, 2018 8:27 pm

I've been running some experiments and wanted to confirm the behavior I'm seeing. I'm running the latest Stretch and firmware has been updated.

In /boot/config.txt I have:

Code: Select all

dtoverlay=gpio-poweroff,gpiopin=21,active_low="y"
dtoverlay=gpio-shutdown,gpio_pin=20
This seems to work properly but the delay before GPIO21 changes is over 4 seconds (yellow line is Pi's 3.3V, blue is GPIO21):
GPIO21_Not_inDTS_PowerUp.PNG
GPIO21 Power Up
GPIO21_Not_inDTS_PowerUp.PNG (5.54 KiB) Viewed 5484 times
Here is what it looks like on power down:
GPIO21_Not_inDTS_PowerUp.PNG
GPIO21 Power Up
GPIO21_Not_inDTS_PowerUp.PNG (5.54 KiB) Viewed 5484 times
I wanted to reduce the time that it takes for GPIO21 to go up/down so I created a "blob" with:

Code: Select all

            //[email protected] { function = "input"; termination = "pull_up"; polarity = "active_low"; }; // Pi_GPIO20
            [email protected] { function = "output"; termination = "pull_up"; startup_state = "active"; }; // Pi_GPIO21
I found that I don't need to define GPIO20 in my situation but it's in there from a prior test. When this is added I see the following changes:

Power Up now looks like this:
GPIO21_inDTS_PowerUp.PNG
GPIO21 Power Up (DTS)
GPIO21_inDTS_PowerUp.PNG (5.93 KiB) Viewed 5484 times
Power Down will be shown in the next thread since I can't add 4 files
Attachments
GPIO21_Not_inDTS_PowerDwn.PNG
GPIO21 Power Down
GPIO21_Not_inDTS_PowerDwn.PNG (6.31 KiB) Viewed 5484 times

GeorgeIoak
Posts: 43
Joined: Thu Aug 30, 2012 1:50 am

Re: Confirmation of gpio-poweroff Behavior

Wed Jan 03, 2018 8:28 pm

GPIO21 Power Down when using "blob"
GPIO21_inDTS_PowerDwn.PNG
GPIO21 Power Down (DTS)
GPIO21_inDTS_PowerDwn.PNG (6.09 KiB) Viewed 5482 times
So why does GPIO21 not stay low?

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1884
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Confirmation of gpio-poweroff Behavior

Fri Jan 05, 2018 10:14 am

Running the same tests I get different results - it works as expected.

First without the dt-blob:
without_dtblob.png
without_dtblob.png (53.38 KiB) Viewed 5434 times
Then with:
with_dtblob.png
with_dtblob.png (53.55 KiB) Viewed 5434 times
Apart from a decrease in the time before GPIO21 goes high, the two traces are essentially the same.

My advice is to work with the natural pull of the GPIO (0-8 pull high, 9-27 pull low), if possible, then there is no need for the dt-blob:
gpio4_noblob.png
gpio4_noblob.png (53.88 KiB) Viewed 5434 times

GeorgeIoak
Posts: 43
Joined: Thu Aug 30, 2012 1:50 am

Re: Confirmation of gpio-poweroff Behavior

Sun Jan 07, 2018 12:11 am

Hi Phil,

Well I've got a custom board designed, built, and attached to the Pi so I need to work with these 2 GPIO pins (20 and 21). It looks like in your first capture without the dt-blob GPIO 21 doesn't go low until about 10 seconds after you toggle GPIO 20 low, is that correct? There are seems to be a bit of a bounce before GPIO 21 goes low. Perhaps I'm zoomed in on this bounce and not seeing the complete picture that you're showing with the logic analyzer captures. Would you mind zooming in and showing me what your GPIO 21 looks like when it first goes low please.

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1884
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Confirmation of gpio-poweroff Behavior

Sun Jan 07, 2018 9:50 pm

My boot sequence is particularly slow because kernel UART output is enabled and it is running from an NFS-mounted root FS, but that should not alter the final shutdown sequence.

At the end of the power-down the gpio-poweroff driver sets the pin active (low) for 100ms, then inactive (high) for 100ms, then active (low) again.

Killertechno
Posts: 141
Joined: Wed Jan 02, 2013 8:28 am

Re: Confirmation of gpio-poweroff Behavior

Tue Feb 20, 2018 11:54 am

Hi to all!
Are these pins working on which version of Pi/Debian?
This looks perfect to use LTC2951 (1 or 2 version depending from enable state of DC/DC controller) through GPIO21 pin, is this right?
Image





But GPIO20 stands for.. what?

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1884
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Confirmation of gpio-poweroff Behavior

Tue Feb 20, 2018 11:58 am

Read the first post in this topic, run "dtoverlay -h gpio-poweroff" and "dtoverlay -h gpio-shutdown", then post again if you still have questions.

Killertechno
Posts: 141
Joined: Wed Jan 02, 2013 8:28 am

Re: Confirmation of gpio-poweroff Behavior

Tue Feb 20, 2018 2:09 pm

Mmh, ok, thanks for help.
Now I've just downloaded latest image (2017-11-29-raspbian-stretch-lite) and it correctly works, image I was previously using had missing dtoverlay entries.

Simple
Posts: 12
Joined: Tue Aug 01, 2017 6:51 am

Re: Confirmation of gpio-poweroff Behavior

Sun Apr 15, 2018 6:58 pm

So if I am reading this correctly..
Setting both overlays

GPIO21 is just an indicator of the PI status, coming up as soon as it can, and dropping low after all systems flushed?
GPIO20 is the input from a button or other method, pulling low, initiating the shutdown process?

I ask because for the while, I have been using one of the UART pins as a PI power status pin, and lately I noticed with the newer PI3B+, the UART pin does not go low at powerdown anymore. It only worked on the previous model. I need a newer and more robust method. My UPS doesn't work with the newer PI3B+. What would be the best GPIO to use for these functions? I use GPIO 2,3,18,19,21 for my DAC.

Thank You

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1884
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Confirmation of gpio-poweroff Behavior

Sun Apr 15, 2018 7:19 pm

Using the gpio-poweroff overlay you can choose the GPIO, and provided the pin is not needed for another purpose which one you choose doesn't matter except in one respect: the natural pull direction.

It is a good idea to use pins that naturally pull in the "on" direction, i.e. use a GPIO that by default pulls high (0-8} if you want low to indicate that shutdown is complete (active-low mode), and one that pulls low (9-27) for active-high mode.

Simple
Posts: 12
Joined: Tue Aug 01, 2017 6:51 am

Re: Confirmation of gpio-poweroff Behavior

Sun Apr 15, 2018 9:18 pm

Thanks Phil

Been playing around a little with it and now have the "dtoverlay=gpio-poweroff,gpiopin=5,active_low="y"" working like a charm. It runs high upon power connection and falls low at shutdown (halt), however, "dtoverlay=gpio-shutdown,gpio_pin=6" yields no results when shorting to ground, neither does leaving the "gpio_pin" part blank, and shorting gpio3 to pin 6. I've searched a bit and seems there are at least one other person having the same issue. I hope these pins aren't outputs that I am shorting. Also, as I am intending on cutting power to the pi using these methods, is it OK to actually have the power cut off to the pi at the exact time that the poweroff gpio falls low, or is there some amount of delay that would be beneficial?

https://raspberrypi.stackexchange.com/q ... pi-distros

Much appreciated
S

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1884
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Confirmation of gpio-poweroff Behavior

Sun Apr 15, 2018 9:34 pm

You will also need to add ",active_low=1" to the gpio-shutdown line if you want to activate it by shorting to ground (via a resistor would be best - 10kOhm or less should be fine). gpio-shutdown does not have the same timing issues as gpio-poweroff - it is safe to let the driver configure the GPIO with the appropriate pull, so you have more pins to choose from.

The gpio-poweroff driver does go through a sequence at shutdown time - inactive->active, pause 100ms, active->inactive, pause 100ms, inactive->active. This is to support both level triggered and edge-triggered power off, but I don't see any reason why you should pull the power immediately the signal goes active (low, in your case), provided it will never trigger during power-on.

Simple
Posts: 12
Joined: Tue Aug 01, 2017 6:51 am

Re: Confirmation of gpio-poweroff Behavior

Sun Apr 15, 2018 11:17 pm

Thanks again Phil

Interestingly, my old school spinny hard drive doesn't shutdown using these overlays. My old method would flush and shutdown the drive on powerdown. I would hear a "click" and the light would turn off. Using the poweroff overlay, it appears to do some action, but then it just keeps spinning with the light on?

Still not getting any action using the following "dtoverlay=gpio-shutdown" on the gpio specified, or the default gpio3. I tried using ",active_low=1" as well.

Code: Select all

initramfs volumio.initrd
gpu_mem=16
max_usb_current=1
dtparam=audio=on
audio_pwm_mode=2
dtparam=i2c_arm=on
disable_splash=1
hdmi_force_hotplug=1

works
dtoverlay=gpio-poweroff,gpiopin=5,active_low=1

either does not work
dtoverlay=gpio-shutdown,active_low=1
or
dtoverlay=gpio-shutdown,gpio_pin=26,active_low=1

Simple
Posts: 12
Joined: Tue Aug 01, 2017 6:51 am

Re: Confirmation of gpio-poweroff Behavior

Mon Apr 16, 2018 2:53 pm

Message to the original poster GeorgeIoak

I've been running my tests with a DMM and wasn't getting the actual logic signals from the pin using the gpio-poweroff overlay until I attached a LED to the pin to notice the same delay that you have. I have been reading the voltage from the internal pull-up resistor before the pin is actually set HIGH. This pull-up is activated on power application of the PI.

If I am correct, you are seeking a more quick signal from the pin indicating power up as well as I am.

What I have done on a test board is place a BS170 MOSFET with it's gate attached to the gpio-poweroff pin and its source to ground, using it as a grounding switch. This way, the BS170 switches ON using the raspberry pi's pull-up resistor, and will remain on until the gpio-poweroff pin is pulled LOW after shutdown.

Hope this helps
S

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1884
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Confirmation of gpio-poweroff Behavior

Mon Apr 16, 2018 3:53 pm

@Simple - I had a go myself (with a 3B+) and

Code: Select all

dtoverlay=gpio-shutdown,gpio_pin=26
is sufficient. Although what I said about the default pull of GPIO26 is correct, the overlay forces the pull to high and the sense to be active low by default.

If it's not working for you, try a few tests:

Code: Select all

$ raspi-gpio get 26
$ sudo grep 26 /sys/kernel/debug/pinctrl/3f200000.gpio/{pinmux-,}pins
$ raspi-gpio set 26 op dh
# Check that 26 is high
$ raspi-gpio set 26 op dl
# Check that 26 is low

Simple
Posts: 12
Joined: Tue Aug 01, 2017 6:51 am

Re: Confirmation of gpio-poweroff Behavior

Tue Apr 17, 2018 2:29 am

Thanks again Phil

1K resistor and button between pin 37 and 39 and still no action
Using the plugin through the Volumio interface and I am able to shutdown using the pin, however, I would prefer using the overlay
This could be an issue in using Volumio and some missing packages.

Code: Select all

[email protected]:~$ raspi-gpio get 26
-bash: raspi-gpio: command not found
This command apparently shows at least some indication of action

Code: Select all

[email protected]:~$ sudo grep 26 /sys/kernel/debug/pinctrl/3f200000.gpio/{pinmux-,}pins
/sys/kernel/debug/pinctrl/3f200000.gpio/pinmux-pins:pin 26 (gpio26): soc:shutdown_button pinctrl-bcm2835:26 function gpio_in group gpio26
/sys/kernel/debug/pinctrl/3f200000.gpio/pins:pin 26 (gpio26) function gpio_in in hi; irq 170 (edge-both)

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1884
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Confirmation of gpio-poweroff Behavior

Tue Apr 17, 2018 7:52 am

Those results are as I would expect, so the problem must be elsewhere. The overlay works by creating an instance of gpio-keys that sends Linux keycode 116 (POWER). If Volumio doesn't respond to that keycode then that would explain the problem.

At this point you will probably get more help in a Volumio-specific forum.

Simple
Posts: 12
Joined: Tue Aug 01, 2017 6:51 am

Re: Confirmation of gpio-poweroff Behavior

Tue Apr 17, 2018 10:47 pm

Thanks Phil

I hoped that the overlays would take care of business by themselves. Wasn't aware that there would be other dependencies.
At least i've got a workaround at the moment. It;l most likely be incorporated better in the not distant future.

S

Simple
Posts: 12
Joined: Tue Aug 01, 2017 6:51 am

Re: Confirmation of gpio-poweroff Behavior

Sun Apr 22, 2018 1:34 am

I would also like to confirm to the original poster that the action using a P-CH MOSFET results in the same type of preferable action for me, and potentially them. Using "one that pulls low (9-27) for active-high mode." mine I used GPIO17 and a P-CH MOSFET powering a LED connected to the drain and the MOSFET source connected to the power rail. The LED lights on powerup using the GPIO internal pull-down resistor, and remains on until the system is powered down, and the GPIO set HIGH. This I believe is what you are looking for, opposite of the N-CH MOSFET.

dtoverlay=gpio-poweroff,gpiopin=17,active_low=0

S

Return to “Device Tree”