Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 13 Jul 2022 18:19:57 -0500
From:      Jedi Tek'Unum <freebsd-arm-list-2022-fea3@qoruscant.com>
To:        "Dr. Rolf Jansen" <freebsd-rj@cyclaero.com>
Cc:        freebsd-arm@freebsd.org
Subject:   Re: Startup-/Shutdown Button for the Raspberry Pi 4
Message-ID:  <165775440275.8.4265153478134935826.51718197@qoruscant.com>
In-Reply-To: <E1F8EA20-D709-45FD-941F-DB28921601D1@cyclaero.com>
References:  <E1F8EA20-D709-45FD-941F-DB28921601D1@cyclaero.com>

next in thread | previous in thread | raw e-mail | index | archive | help
> On Jul 12, 2022, at 8:17 PM, Dr. Rolf Jansen - freebsd-rj at cyclaero.com=
 <nxtzmchnyjrirskcrisaafakxcekosgmhdcricnnjyxomsvwpn@simplelogin.co> wrote:
>=20
> =EF=BB=BFOne week ago I started with exploring the Raspberry Pi 4 B, whic=
h might be a substitute for the aging BeagleBone Blacks for my future proje=
cts.
>=20
> I very much like the built-in power button facility of the BBB, and unfor=
tunately the RPi 4 has nothing comparable - the one button to rule it all.
>=20
> I read a lot of howtos and blog posts (mostly for Linux) and nothing was =
really worth to give it even a try, compared to live without the button. We=
ll, this is not becoming an elaborated question, but here I am going to ela=
borate my solution for FreeBSD.
>=20
> 1. I Prepared a momentary push button for connecting it to the RPi:
>            ___=20
>             | /
>             |/
>             /
>            /
>         +-o      o--------+
>         |        |        |
>         |       [R] 100 =CE=A9 |
>         |        |        |
>         o        o        o
>       Pin 5    Pin 6    Pin 13
>      (SCL 1)   (GND)   (GPIO 27)

Ok, I=E2=80=99ll bite. I=E2=80=99m not understanding this.

I imagine that the resistor is a current limit for the gpio pin and not the=
 pullup.

Regardless of how it is wired, why use SCL1 which is pulsing? And how can a=
ny of this cause a boot?

Is this =E2=80=9Cmagic=E2=80=9D dependent on some quirk(s) of RPi? Will it =
work with others, like Rock64?

> 2. I created a shutdown daemon in C for FreeBSD, lurking for push button
>   events on a GPIO port: https://github.com/cyclaero/shutdd
>=20
>   clang -g0 -O3 -fsigned-char -Wno-empty-body -Wno-parentheses shutdd.c -=
lgpio -s -o /usr/local/bin/shutdd
>=20
>   shutdd [-p file] [-f] [-n] [-b] [-g] [-h] =20
>    -p file    the path to the pid file [default: /var/run/shutdd.pid] =20
>    -f         foreground mode, don't fork off as a daemon. =20
>    -n         no console, don't fork off as a daemon. =20
>    -b         GPIO bank id [default: 0]. =20
>    -g         GPIO line id [default: 27]. =20
>    -h         shows these usage instructions. =20
>=20
>   echo "/usr/local/bin/shutdd" >> /etc/rc.local=20
>=20
> Restart and ready for testing the RPi's Power Button.
>=20
> shutdd does not poll the state of the GPIO port, but instead utilizes Fre=
eBSD's user space interface for GPIO interrupts for lurking on state change=
s of the GPIO line - default GPIO.0.27. Therefore, no significant load is i=
mposed on the CPU's.
>=20
> After 2 hs of operation, in output of ps -ax:
> ...
> 550  -  Is     0:00.03 /usr/local/bin/shutdd
> ...
>=20
> - No CPU load !!!
>=20
> - Pressing the power button does the same as shutdown -p now
>=20
> - Pressing the power button when the RPi is down but still connected to t=
he 5 V power supply lets it starting up.
>=20
> BTW, I left the RTC DS3231 on I2C 1. That means, the RTC and the power bu=
tton share the same pins for SCL 1 and GND.
>=20
>=20
>=20




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?165775440275.8.4265153478134935826.51718197>