From nobody Wed Jul 13 01:17:00 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 524FC1CFCB0A for ; Wed, 13 Jul 2022 01:17:09 +0000 (UTC) (envelope-from freebsd-rj@cyclaero.com) Received: from mo4-p00-ob.smtp.rzone.de (mo4-p00-ob.smtp.rzone.de [81.169.146.217]) (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 4LjKTw0sTTz3lrN for ; Wed, 13 Jul 2022 01:17:07 +0000 (UTC) (envelope-from freebsd-rj@cyclaero.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1657675025; s=strato-dkim-0002; d=cyclaero.com; h=To:Date:Message-Id:Subject:From:Cc:Date:From:Subject:Sender; bh=dk+iBNDhJ/GND58CuGPsJnTRT3kZJX2lfSzfbQEQteE=; b=K3EwnZYPJiyOkgVHmLQ44tbT6ptMCEC0Y66BsaAjSB2YAnDNRpLJglJpgF1mUkp0rh o0oUZq05A1rGWQuF0+Bchjm2G4voD+VnnrvBK4p0WICgiRtPC/jC4hU1HCXI2Rexaxuq 1lNPDjc4FmZmZaz7sk+EwfURjP5pgtJcKT4AjmCDkh7foIfXxsOsVqt4g4RAQJJGyDM6 WDTQ5n15ranPZrKzAaPDi1/COmMexcJR/gRSkCS+SbZ+xVq1DwBwms0SJFf4uXg+VtRJ 4vPsM9m0VvNmXPdAz2NdSVWJ1sHlpYydWFTcAZYUMMw/yXFjS5Ypv5W+texg2Ez3uYeL XimQ== 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 5bc9a3y6D1H40dh (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate) for ; Wed, 13 Jul 2022 03:17:04 +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 3D845631C3 for ; Wed, 13 Jul 2022 03:17:03 +0200 (CEST) From: "Dr. Rolf Jansen" Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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: Startup-/Shutdown Button for the Raspberry Pi 4 Message-Id: Date: Tue, 12 Jul 2022 22:17:00 -0300 To: freebsd-arm X-Mailer: Apple Mail (2.3445.104.15) X-Rspamd-Queue-Id: 4LjKTw0sTTz3lrN X-Spamd-Bar: - Authentication-Results: mx1.freebsd.org; dkim=pass header.d=cyclaero.com header.s=strato-dkim-0002 header.b=K3EwnZYP; dmarc=none; spf=pass (mx1.freebsd.org: domain of freebsd-rj@cyclaero.com designates 81.169.146.217 as permitted sender) smtp.mailfrom=freebsd-rj@cyclaero.com X-Spamd-Result: default: False [-2.00 / 15.00]; NEURAL_HAM_LONG(-1.00)[-1.000]; FROM_NAME_HAS_TITLE(1.00)[dr]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; NEURAL_HAM_SHORT(-1.00)[-0.999]; MV_CASE(0.50)[]; R_SPF_ALLOW(-0.20)[+ip4:81.169.146.128/25]; R_DKIM_ALLOW(-0.20)[cyclaero.com:s=strato-dkim-0002]; MIME_GOOD(-0.10)[text/plain]; RCVD_IN_DNSWL_NONE(0.00)[81.169.146.217:from]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; MLMMJ_DEST(0.00)[freebsd-arm]; ASN(0.00)[asn:6724, ipnet:81.169.144.0/22, country:DE]; MIME_TRACE(0.00)[0:+]; 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 One 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: ___=20 | / |/ / / +-o o--------+ | | | | [R] 100 =CE=A9 | | | | o o o Pin 5 Pin 6 Pin 13 (SCL 1) (GND) (GPIO 27) 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] =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 echo "/usr/local/bin/shutdd" >> /etc/rc.local=20 Restart and ready for testing the RPi's Power Button. shutdd does not poll the state of the GPIO port, but instead utilizes = FreeBSD's user space interface for GPIO interrupts for lurking on state = changes of the GPIO line - default GPIO.0.27. Therefore, no significant = load is imposed on the CPU's. After 2 hs of operation, in output of ps -ax: ... 550 - Is 0:00.03 /usr/local/bin/shutdd ... - No CPU load !!! - Pressing the power button does the same as shutdown -p now - Pressing the power button when the RPi is down but still connected to = the 5 V power supply lets it starting up. BTW, I left the RTC DS3231 on I2C 1. That means, the RTC and the power = button share the same pins for SCL 1 and GND.