rudiratlos
Posts: 160
Joined: Tue May 01, 2012 8:47 am

GPIO 1sec High at Boot and Poweroff How to?

Sun Nov 17, 2019 5:21 pm

Hi,
I have a Beeper connected to GPIO4 (default PullUp) via a transistor. Driving the GPIO 1sec High, the Beeper is active. Everything works out of an application.

Due to the fact that GPIO4 has PullUp, the Beeper beeps until EEprom from HAT sets GPIO4 to Output LOW. This takes about 5secs. On ShutdownHalt, the Beeper is also activ until I remove the powersupply.

It's not so bad that the Beeper is activ at startup and on ShutdownHalt. But 1-2sec activation of the beeper whould be not so nagging.

Inspired by the gpio-poweroff overlay, it can drive the gpio to a high level at exactly at startup and ShutdownHalt. But the level ist static. Is there a way to modify the gpio-poweroff overlay to issue a 1-2sec pulse at these states?

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

Re: GPIO 1sec High at Boot and Poweroff How to?

Mon Nov 18, 2019 9:47 am

Can I confirm that you want a beep at startup and shutdown, but only a short one?

Unfortunately I think it isn't possible to limit the length of the beep without external circuitry. The state of the pins gets reset at every poweroff/shutdown and reboot, at which point they return to inputs with the default pull-up. An external R/C circuit or simple timer could be used to gate the GPIO output after a fixed interval, but I suspect this isn't an option with the HAT you are using.

You don't say what model of Pi you have, but if it's a Pi 4 you have some options. The bootloader EEPROM reads the config.txt file very early during boot, so if include "gpio=4=op,dl" then the beep at reboot will be less than a second. In fact, even a Pi 3 will switch it off in under a second, so that will reduce the initial start-up beep. The Pi 4 EEPROM also has some configuration options including POWER_OFF_ON_HALT. If set, the Pi will completely power down at a shutdown. You can learn about the bootloader options here: https://www.raspberrypi.org/documentati ... _config.md

rudiratlos
Posts: 160
Joined: Tue May 01, 2012 8:47 am

Re: GPIO 1sec High at Boot and Poweroff How to?

Mon Nov 18, 2019 2:13 pm

tried on my rpi4. works with following entries in /boot/config.txt
dtoverlay=gpio-poweroff,gpiopin=4,active_low=0
gpio=4=op,dl

rpi4 running, then OS command tested reboot:
beeper beeps 1-2sec at startup only

rpi4 running, then OS command tested shutdown -h now :
beeper beeps always until power was removed!!

rpi4 powered off, power on:
beeper beeps 1-2sec

with dtoverlay=gpio-poweroff I tried to suppress the unlimited beeping at shutdown, but didn't work WHY?

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

Re: GPIO 1sec High at Boot and Poweroff How to?

Mon Nov 18, 2019 2:27 pm

rpi4 running, then OS command tested shutdown -h now :
beeper beeps always until power was removed!!
The gpio_poweroff code is designed to signal to an external device that power can be removed. With active_low=0, the normal state of the GPIO is low. At the point where the Pi can be safely powered off, the pin goes high for a 100 ms, then low for 100ms, then high for 3 seconds. If the power hasn't been switched off after this point the driver generates a WARN message and ploughs on. After that, all bets are off because enabling gpio_poweroff disables the normal reset mechanism.

You are using the gpio_poweroff driver in a way it wasn't intended to work, then being surprised when it doesn't do exactly what you expect - perhaps another mechanism would work better. How about removing the gpio-poweroff overlay and relying on the default pin pull to drive the line high until the EEPROM takes over?

rudiratlos
Posts: 160
Joined: Tue May 01, 2012 8:47 am

Re: GPIO 1sec High at Boot and Poweroff How to?

Wed Nov 20, 2019 12:40 pm

Thanks that helps for the beep at startup.

How is the chronology?
You wrote that config.txt gpio command will be loaded very early.
When is the eeprom (HAT) loaded and executed?

Is there a documentation how the GPIO pins will be initialized, facing the chronology.

Let's assume that I set in config.txt gpio4 to high and in eeprom to low. which will win?

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

Re: GPIO 1sec High at Boot and Poweroff How to?

Wed Nov 20, 2019 1:47 pm

The load order is (from power on):

Code: Select all

* Boot ROM
* SPI EEPROM (Pi 4) or bootcode.bin (any Pi)
  + config.txt
* start.elf
  + config.txt (main settings)
  + initramfs
  + HAT EEPROM
  + .dtb
  + config.txt (DT settings)
  + cmdline.txt
  + armstub
  + kernel
You'll notice that config.txt gets loaded three times, but it's the first two that interest you. The delays between them should be quite small, but will depend on SD card (or network /USB) speed.

User avatar
jbeale
Posts: 3578
Joined: Tue Nov 22, 2011 11:51 pm
Contact: Website

Re: GPIO 1sec High at Boot and Poweroff How to?

Wed Nov 20, 2019 3:18 pm

^ this post on loading order feels like important information that should be documented somewhere easier to find than here, if it isn't already.

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

Re: GPIO 1sec High at Boot and Poweroff How to?

Wed Nov 20, 2019 3:23 pm

The internal load order of start.elf is subject to change - it wasn't the same a few months ago. The rest is public knowledge.

Return to “Device Tree”