-
Notifications
You must be signed in to change notification settings - Fork 5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use gpiochip0 for the user-facing GPIOs on Pi 5 #6144
Conversation
Are we not risking breaking existing users who have hard coded gpiochip4 into their library? @waveform80 would probably have a better knowledge of the current assumptions made. |
Heads up, @waveform80. I see that rpi-lgpio selects |
Yes, I'm afraid gpiozero and rpi-lgpio both assume gpiochip4 at the moment (which is almost certainly terrible laziness on my part, but the latter in particular has been a bit of a rush-job). I did something slightly more respectable for our GPIO udev rules, filtering on the driver, and ideally I think something similar should work for the two libraries, by querying sysfs (e.g. /sys/bus/gpio/devices/gpiochip4/of_node/compatible). Something like:
I'll see what I can do about pushing a fix out to the libraries in the next few days. |
There are moves afoot [1] to change the gpiochip device on the Pi 5 from gpiochip4 to gpiochip0. The current gpiochip discovery in rpi-lgpio is crude, to say the least. This commit refines the method to discovering the chip based on the GPIO driver in use (which should work on all Pi boards with all kernels). Closes: #10 [1]: raspberrypi/linux#6144
The issue of discovering the user-facing GPIOs, the subject of this PR, came up again today. How are people feeling about the possibility of this being merged in the near future? |
In the same way that other subsystems support the setting of device id numbers from Device Tree aliases, allow gpiochip numbers to be derived from "gpiochip<n>" aliases. Signed-off-by: Phil Elwell <phil@raspberrypi.com>
Add a gpiochip0 aliase pointing to the rp1 GPIO node, making it appear as gpiochip0. Signed-off-by: Phil Elwell <phil@raspberrypi.com>
Make the BCM2712's onboard GPIOs start at gpiochip10, marking them out as system resources and preventing accidental use by existing Pi 5 code. Signed-off-by: Phil Elwell <phil@raspberrypi.com>
Let me double-check I've got things in place. I definitely have in rpi-lgpio but I think I forgot to release a version of gpiozero with this in place. I'll have a look this evening! |
If there are no objections, this will be merged next week. |
Sorry if I ask in the wrong place, when will these changes uploaded to APT repository? I hope it will soon. Thanks. |
We don't have a specific date planned. In "some" weeks time is my guess. |
quick heads up: gpiozero using the lgpio pin factory (recommended default on RPiOS) is currently broken due to this change, I've created a gpiozero issue gpiozero/gpiozero#1166 |
Yesternights RPi kernel bump from 6.6.31 to 6.6.47 effectively broke gpiozero. Python PWM-control is currently dead-in-the-water |
So 4 months' notice was not enough? |
Sadly |
I'm glad they did! |
can’t an alias be created from gpiochip4 to gpiochip0? That would solve all the problems, making both gpiochip0 and gpiochip4 functional, |
Not without adding some potentially large hack to the kernel code. The client-side fix is much easier. |
I understand that it is a large hack, but I would like to point out that a client-side fix means that:
need to implement these changes. Furthermore, there is the problem that if the client is changed, one cannot assume that Kernel 6.6.47 is installed. The current Pi OS image (July 4th, 2024) still contains the old kernel. With older kernel versions, gpiochip0 can be opened, but this is the wrong chip. To be sure, a check of the chip label must be performed. For me, however, this topic is now closed. |
I suspect that most internet blogs / YouTube tutorials / etc. are simply using a 3rd-party library (e.g. GpioZero) rather than making low-level libgpiod calls directly; so once GpioZero is fixed to work with this kernel change, all that tutorial content will be totally fine again!
Yes, that's exactly what waveform80/rpi-lgpio@bb7ff0e does, and I assume the eventual GpioZero fix will be similar. |
It turns out that we may be able to put a workaround into RPiOS - watch this space. |
|
Meteo-pi on a Raspberry Pi 5 still does not work with the above changes! pi@cumulusmxkitchen:~ $ gpiodetect |
That looks like a commercial product - have you reported the problem to the manufacturer? |
I have reported the problem to both the developer of cumulusmx https://cumulus.hosiene.co.uk/viewtopic.php?t=22529 and have sent an email to the manufacturer of the meteo-pi. |
After upgrading, gpiozero's PWM is back in working order. Well Done! |
I use the below dtparam and dtoverlay in my config.txt Is it possible whoever created the below dtparam for uart0 and uart0_console hard coded a reference to gpiochip4? Can the dtparam and dtoverlay reference the udev rule that was created? Here is what i have in my config.txt /boot/firmware/config.txt dtparam=uart0=on Thanks, |
I have contacted the manufacturer of the meteo-pi Here is the response from the manufacturer: MeteoPi is just connectivity tool. It provides wires from Console's UART TX and RX, to RP UART RX and TX on PIN 8(GPIO14), and 10(GPIO15). I enable uart on Pins 8(GPIO14) and 10(GPIO15) with the following lines in the config.txt as mentioned above. dtparam=uart0=on I contacted the developer of Cumulusmx and asked if there where any hard coded references to gpiochip4 in the cumulusmx software and he said no. Thanks, |
It doesn't sound as though MeteoPi is using GPIOs - just a UART. To enable UART0 on GPIOs 14 & 15 (pins 8 & 10) on a Pi 5, all you need is:
Enabling the console on that UART may interfere with however MeteoPi is using it, but if you do want to be able to log in over that UART then you should use:
You don't need to keep |
the meteopi uses the gpio on the Raspberry PI 5. It uses the Uart0 on GPIO 14(pins 8) and GPIO 15(pin 10). uart0_console is a dtparam that enables uart0, maps it to GPIOs 14 & 15, and makes it the "console" UART (i.e. serial0 points to it). please see this topic for details. Unfortunately, this is a major breaking change for me! Thanks, |
Using two pins for UART does not amount to using GPIO in the strictest sense. GPIO standards for General Purpose Input/Output, and it allows software to set or read the level on a pin.
I know - I created
Here, and you have done, but arguing with the people trying to help is not a good way to go about it. |
I am very grateful for the help you have been giving me. Would there be any log files I could generate and send to you that may help to diagnose the reason the meteopi no longer works? Thanks, |
Let's first establish whether it might have been this change that caused your problem:
|
when i ran pi@cumulusmxkitchen:~ $ sudo rpi-update bfaaf1b |
Sorry - there are two parallel repos, and those hashes must be from the wrong one. This should give a non-working system: And this should work: |
I ran pi@cumulusmxkitchen:~ $ uname -a I then ran pi@cumulusmxkitchen:~ $ uname -a I then ran pi@CumulusMX:~ $ uname -a what would the command be to update the kernel to 6.6.42? I would like to see if the meteopi works with kernel 6.6.42 |
On this page you will find a list of kernels that you can install. The 7/8-digit hexadecimal number on each line is the value to pass to rpi-update. (Each build is actually represented by a much longer hex number, but any unique prefix should work). |
I ran pi@cumulusmxkitchen:~ $ uname -a The issue with the meteopi not working occurs with kernel 6.6.44! How can I see what changes were made with this kernel version? Thank You. |
Clicking on any of the releases on that page takes you to another page that shows the contents (strictly, the changes introduced by that release). The file Because GitHub recognises those hashes it has transformed them into links to the source code commits. There are over 600 commits between those two points (
Further ignoring the Merge commits (the first because it is a placeholder for the upstream changes from that period, and the second because it is the known good state). Looking at that list, a few things stand out - the various RP1 DMA changes, and a UART-driver change: f3cb675 Step one will be to create a PR with all of those downstream changes reverted (I hope that doesn't get messy), to give you another build to try. And this deserves a separate issue since we've established that it broke before the gpiochip0 change. |
This reverts commit f3cb675. Data loss has been observed on the Pi's PL011 UARTs since f3cb675 was merged. The loss appears to be on reception, not transmission. Revert the commit as a workaroud and potential fix. Link: raspberrypi#6365 Link: raspberrypi#6144 (comment) Link: https://forums.raspberrypi.com/viewtopic.php?t=376532 Signed-off-by: Phil Elwell <phil@raspberrypi.com>
Pi 5 contains multiple GPIO controllers; running
gpiodetect
shows that there are five. Prior to this patch set, they appear like this:Notice how
pinctrl-rp1
- the driver for the GPIOs that appear on the 40-pin header - is shown asgpiochip4
. This is not user-friendly, requiring careful handling when trying to locate a particular GPIO via libgpiod.This patch set adds the ability to override the gpiochip numbers using DT aliases, just as is done for I2C, SPI etc. It also adds a
gpiochip0
alias topinctrl-rp1
. changing the gpiochip numbering to this:P.S. There's now an additional commit that sets the base of the SoC gpiochips to 10, for two reasons:
With this commit, the final picture is: