From nobody Thu Jul 14 13:26:38 2022 X-Original-To: freebsd-arm@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4LkFdb6XkDz1J1kM for ; Thu, 14 Jul 2022 13:26:59 +0000 (UTC) (envelope-from sl.lmysyibvge3tsnzzgazcyibshaydcnrwlu.zgzhagnq27dm2@qoruscant.com) Received: from mail-200163.simplelogin.co (mail-200163.simplelogin.co [176.119.200.163]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "protonmail.com", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4LkFdZ6SLPz3wgD for ; Thu, 14 Jul 2022 13:26:58 +0000 (UTC) (envelope-from sl.lmysyibvge3tsnzzgazcyibshaydcnrwlu.zgzhagnq27dm2@qoruscant.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qoruscant.com; s=dkim; t=1657805211; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ft6tEPw750tfZGVKRCRCxR1PV0FIeer6jn7x/Xlf2nM=; b=hWUwuc0ryoJC5v2DzlSJjCDlUCcqeIUX3ySBfesUTFzVMeXxyKRf9S2nZInCm4dTfB2eUc YrRLiWEZVBRT7PVR/UL7EsZIBijh6pZhnDjj4QI+WvOBp7dLxYm5Vdwbl0J/TWItWQBhAr OGebii5EC8HSeMcXNidzHO1n1vVxHdk= Content-Type: multipart/alternative; boundary=Apple-Mail-A247728D-319B-4FEE-B8DD-9328EB68D6BC Content-Transfer-Encoding: 7bit Subject: Re: Startup-/Shutdown Button for the Raspberry Pi 4 Date: Thu, 14 Jul 2022 08:26:38 -0500 In-Reply-To: From: Jedi Tek'Unum To: freebsd-arm Message-ID: <165780521135.7.10590681011079085662.51797902@qoruscant.com> References: X-SimpleLogin-Type: Reply X-SimpleLogin-EmailLog-ID: 51797902 X-SimpleLogin-Want-Signing: yes X-Rspamd-Queue-Id: 4LkFdZ6SLPz3wgD X-Spamd-Bar: / Authentication-Results: mx1.freebsd.org; dkim=pass header.d=qoruscant.com header.s=dkim header.b=hWUwuc0r; dmarc=pass (policy=quarantine) header.from=qoruscant.com; spf=pass (mx1.freebsd.org: domain of sl.lmysyibvge3tsnzzgazcyibshaydcnrwlu.zgzhagnq27dm2@qoruscant.com designates 176.119.200.163 as permitted sender) smtp.mailfrom=sl.lmysyibvge3tsnzzgazcyibshaydcnrwlu.zgzhagnq27dm2@qoruscant.com X-Spamd-Result: default: False [-0.50 / 15.00]; MISSING_MIME_VERSION(2.00)[]; NEURAL_HAM_SHORT(-0.99)[-0.991]; NEURAL_HAM_MEDIUM(-0.60)[-0.604]; DMARC_POLICY_ALLOW(-0.50)[qoruscant.com,quarantine]; FORGED_SENDER(0.30)[freebsd-arm-list-2022-fea3@qoruscant.com,sl.lmysyibvge3tsnzzgazcyibshaydcnrwlu.zgzhagnq27dm2@qoruscant.com]; NEURAL_HAM_LONG(-0.21)[-0.206]; R_DKIM_ALLOW(-0.20)[qoruscant.com:s=dkim]; R_SPF_ALLOW(-0.20)[+ip4:176.119.200.160/29]; MIME_GOOD(-0.10)[multipart/alternative,text/plain]; RCVD_COUNT_ZERO(0.00)[0]; MIME_TRACE(0.00)[0:+,1:+,2:~]; MLMMJ_DEST(0.00)[freebsd-arm]; ASN(0.00)[asn:62371, ipnet:176.119.200.0/24, country:CH]; ARC_NA(0.00)[]; TO_DN_ALL(0.00)[]; FROM_NEQ_ENVFROM(0.00)[freebsd-arm-list-2022-fea3@qoruscant.com,sl.lmysyibvge3tsnzzgazcyibshaydcnrwlu.zgzhagnq27dm2@qoruscant.com]; FROM_HAS_DN(0.00)[]; DKIM_TRACE(0.00)[qoruscant.com:+]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; MID_RHS_MATCH_FROM(0.00)[] X-ThisMailContainsUnwantedMimeParts: N List-Id: Porting FreeBSD to ARM processors List-Archive: https://lists.freebsd.org/archives/freebsd-arm List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-arm@freebsd.org --Apple-Mail-A247728D-319B-4FEE-B8DD-9328EB68D6BC Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Jul 13, 2022, at 7:36 PM, Dr. Rolf Jansen - freebsd-rj at cyclaero.com <= nxtzmchnyjrirskcrisaafakxcekosgmhdcricnnjyxomsvwpn@simplelogin.co> wrote: >=20 > =EF=BB=BF >=20 >>> Am 13.07.2022 um 20:19 schrieb Jedi Tek'Unum : >>>=20 >>> On Jul 12, 2022, at 8:17 PM, Dr. Rolf Jansen - freebsd-rj at cyclaero.c= om wrot= e: >>>=20 >>> =EF=BB=BFOne week ago I started with exploring the Raspberry Pi 4 B, wh= ich might be a substitute for the aging BeagleBone Blacks for my future pro= jects. >>>=20 >>> I very much like the built-in power button facility of the BBB, and unf= ortunately 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 wa= s really worth to give it even a try, compared to live without the button. = Well, this is not becoming an elaborated question, but here I am going to e= laborate 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) >>=20 >> Ok, I=E2=80=99ll bite. I=E2=80=99m not understanding this. >>=20 >> I imagine that the resistor is a current limit for the gpio pin and not = the pullup. >>=20 >> Regardless of how it is wired, why use SCL1 which is pulsing? And how ca= n any of this cause a boot? >>=20 >> Is this =E2=80=9Cmagic=E2=80=9D dependent on some quirk(s) of RPi? Will = it work with others, like Rock64? >>=20 >>> 2. I created a shutdown daemon in C for FreeBSD, lurking for push butto= n >>> 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 > The power management of the RPis is quite non-sophisticated, and pin 5 (G= PIO 3) of the Pis (3 or 4) happen to be the start-up-only pin when pulled d= own to ground. Now, the SCL line of the default I2C bus 1 is also routed to= pin 5, and that cannot be changed. In case we don't need I2C1 otherwise, t= hen we are done with connecting a simple momentary push button without resi= stor, and we would start shutdd with the flag -g 3. In this case pushing th= e button would start up the Pi when it is down, and it would stop the Pi by= the way of the daemon when it is up. Only shutdd configures the given GPIO= pin for exactly this purpose, and therefore I2C1 could not be used anymore= . >=20 > In the Linux world it is common sense to simply assume, that you can't ha= ve your cake and eat it, and either I2C1 is either abandoned or double-swit= ches or even more complex button assemblies with a n-channel analog multipl= exer like the CMOS4053 are used. >=20 > The 100 =CE=A9 resistor together with the auxiliary GPIO line lets us do = this in a more simple way. Pin 5 is internally pulled-up, pin 13 is interna= lly pulled down. Now pushing the button would do a fractional pull-down of = pin 3 and a fractional pull up of pin 13. The fraction is determined by the= values of the internal pull up/down resisters compared to the 100 =CE=A9 r= esistor. The point is, that shutdd does not depend on accurate logic levels= are reached, but instead reacts on rising and/or falling edges on the conf= igured GPIO's. >=20 > Now by experiment, for my RPi 4B, the 100 =CE=A9 resistor is sufficiently= large for the pulled up fraction of the level on GPIO 27 (pin 13) produces= edges which can be recognized and yet it is sufficiently low, so that star= ting up the RPi by pulling down GPIO 3 (=3D SCL 1, pin 5) does work as well= . For example a resistor of 1 k=CE=A9 (and above) does not work for startin= g up, while shutting down does work, and without the 100 =CE=A9 resistor, s= tarting up does work but shutting down does not. >=20 > I do know nothing about the Rock64, except that it exists. In case the po= wer management is comparable to the one of RPis, this might work as well. I= n case it is comparable to the sophisticated one of the BeagleBone Black, a= ll this is not needed, you even don't need the shutdown daemon shutdd for t= hat. In case Rock64's power management is completely different, then you wo= uld start with reading the specs. >=20 > As long as nobody pushes the button, SCL 1 and with it I2C1 does working = normally, and once somebody pushes the button, it is not that important any= more, since the RPi goes down anyway. >=20 > BTW, right now I am working on implementing a double-push facility into s= hutdd. This would then restart the RPi instead of shutting it down. Clever solution. Thanks for the explanation. I should have looked before I typed. The Rock64 has a button. Your solution= is likely very specific to the Rpi chip. --Apple-Mail-A247728D-319B-4FEE-B8DD-9328EB68D6BC Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable
On Jul 13, 2022, at 7:36 PM, Dr. Rolf Jansen - freebsd-rj at cyclaero.com = <nxtzmchnyjrirskcrisaafakxcekosgmhdcricnnjyxomsvwpn@simplelogin.co> w= rote:

=EF=BB=BF

Am 13.07.2022 um 20:19 schrie= b Jedi Tek'Unum <freebsd-arm-list-2022-fea3@qoruscant.com>:

On Jul 12, 2022, = at 8:17 PM, Dr. Rolf Jansen - freebsd-rj at cyclaero.com <nxtzmchnyjrirskcrisaa= fakxcekosgmhdcricnnjyxomsvwpn@simplelogin.co> wrote:
<= br class=3D"">=EF=BB=BFOne week ago I started with exploring the Raspberry = Pi 4 B, which might be a substitute for the aging BeagleBone Blacks for my = future projects.

I very much like the built-in= power button facility of the BBB, and unfortunately the RPi 4 has nothing = comparable - the one button to rule it all.

I = read a lot of howtos and blog posts (mostly for Linux) and nothing was real= ly worth to give it even a try, compared to live without the button. Well, = this is not becoming an elaborated question, but here I am going to el= aborate my solution for FreeBSD.

1. I Prepared= a momentary push button for connecting it to the RPi:
 =         ___ 
      &= nbsp;    | /
          &nb= sp;|/
           /
          /
      &= nbsp;+-o      o--------+
      =  |        |        |
       |       [R] 100 =CE=A9 |       |        |  = ;      |
       o   &= nbsp;    o        o
  &nbs= p;  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 o= f how it is wired, why use SCL1 which is pulsing? And how can any of this c= ause a boot?

Is this =E2=80=9Cmagic=E2=80=9D d= ependent on some quirk(s) of RPi? Will it work with others, like Rock64?
2. I create= d a shutdown daemon in C for FreeBSD, lurking for push button
 events on a GPIO port: https://github.com/cyclaero/shutdd

 clang -g0 -O3 -fsigned-char -Wno-empty-body -Wno-parentheses sh= utdd.c -lgpio -s -o /usr/local/bin/shutdd

&nbs= p;shutdd [-p file] [-f] [-n] [-b] [-g] [-h]  
  -p = file    the path to the pid file [default: /var/run/shutdd.pid] &= nbsp;
  -f         foreground mode, = don't fork off as a daemon.  
  -n     &n= bsp;   no console, don't fork off as a daemon.  
&n= bsp; -b         GPIO bank id [default: 0].  
  -g         GPIO line id [default: 27]. =  
  -h         shows these usag= e instructions.  

The power management of the RPis is quite non-sophisti= cated, and pin 5 (GPIO 3) of the Pis (3 or 4) happen to be the start-up-onl= y pin when pulled down to ground. Now, the SCL line of the default I2C= bus 1 is also routed to pin 5, and that cannot be changed. In case we don'= t need I2C1 otherwise, then we are done with connecting a simple momentary&= nbsp;push button without resistor, and we would start shutdd with the flag = -g 3. In this case pushing the button would start up the Pi when it is down= , and it would stop the Pi by the way of the daemon when it is up. Only shu= tdd configures the given GPIO pin for exactly this purpose, and therefore I= 2C1 could not be used anymore.

In the Linux world it is common sense to simpl= y assume, that you can't have your cake and eat it, and either I2C1 is eith= er abandoned or double-switches or even more complex button assemblies with= a n-channel analog multiplexer like the CMOS4053 are used.

The 100 =CE=A9 resistor together= with the auxiliary GPIO line lets us do this in a more simple way. Pin 5 i= s internally pulled-up, pin 13 is internally pulled down. Now pushing the b= utton would do a fractional pull-down of pin 3 and a fractional pull up of = pin 13. The fraction is determined by the values of the internal pull up/do= wn resisters compared to the 100 =CE=A9 resistor. The point is, that shutdd= does not depend on accurate logic levels are reached, but instead reacts o= n rising and/or falling edges on the configured GPIO's.

Now by experiment, for my RPi 4B, th= e 100 =CE=A9 resistor is sufficiently large for the pulled up fraction of t= he level on GPIO 27 (pin 13) produces edges which can be recognized and yet= it is sufficiently low, so that starting up the RPi by pulling down GPIO 3= (=3D SCL 1, pin 5) does work as well. For example a resistor of 1 k=CE=A9 = (and above) does not work for starting up, while shutting down does work, a= nd without the 100 =CE=A9 resistor, starting up does work but shutting down= does not.

I do k= now nothing about the Rock64, except that it exists. In case the power mana= gement is comparable to the one of RPis, this might work as well. In case i= t is comparable to the sophisticated one of the BeagleBone Black, all this = is not needed, you even don't need the shutdown daemon shutdd for that. In = case Rock64's power management is completely different, then you would= start with reading the specs.

As long as nobody pushes the button, SCL 1 and with it I2C1 d= oes working normally, and once somebody pushes the button, it is not that i= mportant anymore, since the RPi goes down anyway.

BTW, right now I am working on implementin= g a double-push facility into shutdd. This would then restart the RPi inste= ad of shutting it down.

Clever solution. T= hanks for the explanation.

I should have looked be= fore I typed. The Rock64 has a button. Your solution is likely very specifi= c to the Rpi chip.

--Apple-Mail-A247728D-319B-4FEE-B8DD-9328EB68D6BC--