From nobody Thu Jul 14 00:36:03 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 872311D21B35 for ; Thu, 14 Jul 2022 00:36:14 +0000 (UTC) (envelope-from freebsd-rj@cyclaero.com) Received: from mo4-p00-ob.smtp.rzone.de (mo4-p00-ob.smtp.rzone.de [85.215.255.25]) (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 (2048 bits) client-digest SHA256) (Client CN "*.smtp.rzone.de", Issuer "TeleSec ServerPass Class 2 CA" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4LjwXF0Dz4z3kB4 for ; Thu, 14 Jul 2022 00:36:12 +0000 (UTC) (envelope-from freebsd-rj@cyclaero.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1657758970; s=strato-dkim-0002; d=cyclaero.com; h=Message-Id:In-Reply-To:To:References:Date:Subject:From:Cc:Date:From: Subject:Sender; bh=okWYdgaGu6r18em66uDjnfbEcD1HsWk9AfSnZdMF9fo=; b=UTXtoYfv5domrlQ7Sm/5qxoUr7YY9A0/p6ut8r4XlBqnhW+P5IvGKzD9gJeuzvxjUY Rsuzo5HwRzrKPVOYaRofOOJ5b7MEDTouTxyWEu4UWwvHL3lgd1n1XOPREHcsV1DKVWMt RkbCVPtjppoeE4HzZjlQzLRjvslqY3DzH4J0zTfS2xU4P0Q+RpHLjYVKZOWzCYBpCt9Q Bt8tbGBTEaosYNG2z4Hh6HVOfY0eEvH2xwYTLsB+x2LkOLAAvFuU4IE0FfSZBhM2UhZ9 n01L76yQS6HLvgqGwq6knzCZe9sFmTgpLTvWRsSQpEwmo7W8KDAxLvPx7HGFpdKDT/L0 FKvQ== X-RZG-AUTH: ":O2kGeEG7b/pS1F2rRHW2isrKl4DV03XBEi+I6ZuztdvN9wS3wFGySS4Lw+ldTBio08NTPnK5bNCibgxfnBg=" X-RZG-CLASS-ID: mo00 Received: from mail.obsigna.com by smtp.strato.de (RZmta 47.47.0 AUTH) with ESMTPSA id 5bc9a3y6E0aA4e8 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate) for ; Thu, 14 Jul 2022 02:36:10 +0200 (CEST) Received: from rolf-mini.obsigna.com (unknown [177.95.254.116]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.obsigna.com (Postfix) with ESMTPSA id A64BE63931 for ; Thu, 14 Jul 2022 02:36:08 +0200 (CEST) From: "Dr. Rolf Jansen" Content-Type: multipart/alternative; boundary="Apple-Mail=_936E5512-84CF-4CAE-BADE-F9D8BE751C0F" 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 Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.15\)) Subject: Re: Startup-/Shutdown Button for the Raspberry Pi 4 Date: Wed, 13 Jul 2022 21:36:03 -0300 References: <165775440275.8.4265153478134935826.51718197@qoruscant.com> To: freebsd-arm In-Reply-To: <165775440275.8.4265153478134935826.51718197@qoruscant.com> Message-Id: X-Mailer: Apple Mail (2.3445.104.15) X-Rspamd-Queue-Id: 4LjwXF0Dz4z3kB4 X-Spamd-Bar: - Authentication-Results: mx1.freebsd.org; dkim=pass header.d=cyclaero.com header.s=strato-dkim-0002 header.b=UTXtoYfv; dmarc=none; spf=pass (mx1.freebsd.org: domain of freebsd-rj@cyclaero.com designates 85.215.255.25 as permitted sender) smtp.mailfrom=freebsd-rj@cyclaero.com X-Spamd-Result: default: False [-2.00 / 15.00]; FROM_NAME_HAS_TITLE(1.00)[dr]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; NEURAL_HAM_SHORT(-1.00)[-1.000]; NEURAL_HAM_LONG(-1.00)[-1.000]; MV_CASE(0.50)[]; R_SPF_ALLOW(-0.20)[+ip4:85.215.255.0/24]; R_DKIM_ALLOW(-0.20)[cyclaero.com:s=strato-dkim-0002]; MIME_GOOD(-0.10)[multipart/alternative,text/plain]; RCVD_IN_DNSWL_NONE(0.00)[85.215.255.25:from]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; MLMMJ_DEST(0.00)[freebsd-arm]; ASN(0.00)[asn:6724, ipnet:85.215.255.0/24, country:DE]; MIME_TRACE(0.00)[0:+,1:+,2:~]; DKIM_TRACE(0.00)[cyclaero.com:+]; RCVD_COUNT_THREE(0.00)[3]; RCVD_TLS_ALL(0.00)[]; FROM_HAS_DN(0.00)[]; ARC_NA(0.00)[]; TO_DN_ALL(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DMARC_NA(0.00)[cyclaero.com]; PREVIOUSLY_DELIVERED(0.00)[freebsd-arm@freebsd.org]; RCPT_COUNT_ONE(0.00)[1]; MID_RHS_MATCH_FROM(0.00)[] X-ThisMailContainsUnwantedMimeParts: N --Apple-Mail=_936E5512-84CF-4CAE-BADE-F9D8BE751C0F Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > 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.com = = wrote: >>=20 >> =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. >>=20 >> 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. >>=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. Well, this is not becoming an elaborated question, but here I am = going to elaborate 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 = can 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 = 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 The power management of the RPis is quite non-sophisticated, and pin 5 = (GPIO 3) of the Pis (3 or 4) happen to be the start-up-only 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 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 = shutdd configures the given GPIO pin for exactly this purpose, and = therefore I2C1 could not be used anymore. In the Linux world it is common sense to simply assume, that you can't = have your cake and eat it, and either I2C1 is either 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 is internally pulled-up, pin 13 is = internally 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 resistor. 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 configured GPIO's. 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 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, and without the 100 =CE=A9 resistor, starting up does work but = shutting down does not. I do know nothing about the Rock64, except that it exists. In case the = power management is comparable to the one of RPis, this might work as = well. In case it 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 does working = normally, and once somebody pushes the button, it is not that important = anymore, since the RPi goes down anyway. BTW, right now I am working on implementing a double-push facility into = shutdd. This would then restart the RPi instead of shutting it down. --Apple-Mail=_936E5512-84CF-4CAE-BADE-F9D8BE751C0F Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8

Am 13.07.2022 um 20:19 schrieb 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 <nxtzmchnyjrirskcrisaafakxcekosgmhdcricnnjyxomsvwpn@simplelogin.= co> wrote:

=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 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 elaborate = my solution for FreeBSD.

1. I Prepared a = momentary push button for connecting it to the RPi:
  =         ___ 
      =      | /
          =  |/
           /
          /
  =      +-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 any 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

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

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

The power management of the RPis is quite = non-sophisticated, and pin 5 (GPIO 3) of the Pis (3 or 4) happen to be = the start-up-only 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 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 shutdd configures the given GPIO = pin for exactly this purpose, and therefore I2C1 could not be used = anymore.

In the Linux world it is common sense to simply assume, that = you can't have your cake and eat it, and either I2C1 is either 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 is internally pulled-up, pin 13 is internally 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 = resistor. 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 configured GPIO's.

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 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, and without the 100 =CE=A9 resistor, starting up does work but = shutting down does not.

I do know nothing about the Rock64, except that it exists. In = case the power management is comparable to the one of RPis, this might = work as well. In case it 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 does working = normally, and once somebody pushes the button, it is not that important = anymore, since the RPi goes down anyway.

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

= --Apple-Mail=_936E5512-84CF-4CAE-BADE-F9D8BE751C0F--