[Pkg-raspi-maintainers] GPIO support / Ubuntu images
lucas at debian.org
Thu Mar 21 20:52:26 GMT 2019
On 21/03/19 at 10:41 +0100, Lucas Nussbaum wrote:
> I noticed that Ubuntu ships a patch for rpi.gpio that is supposed
> (according to the patch description -- I haven't tested) to add GPIO
> I'm wondering if somebody looked at Ubuntu images (provided on
> https://wiki.ubuntu.com/ARM/RaspberryPi)? There might be other things to
> import back into Debian.
So I dug a bit deeper.
The Ubuntu image uses a custom kernel:
I suppose it's the stock Ubuntu kernel + rpi-specific patches.
GPIO work on it with RPi.GPIO (which AFAIK is the lower-level library).
It does not work with gpiozero.
To get GPIO to work on the Debian image:
I applied the patch from Ubuntu that fixes auto-detection. There's
also a different patch upstream which does more things.
Then what RPi.GPIO does is that it mmaps the memory at the address where
GPIOs are mapped by the broadcom chip. On Ubuntu, /dev/gpiomem is
available, so that's easy.
On Debian, there's no /dev/gpiomem because it's not in the vanilla
kernel. RPi.GPIO needs to open /dev/mem at the correct address. This
fails with a segmentation because of
Because of that bug, the error handling fails and it segfaults.
So, it fails to open /dev/mem. That's because the Debian kernel is
built with CONFIG_DEVMEM_STRICT=y. To work around that, we need to add
iomem=relaxed to the kernel command line in /boot/firmware/cmdline.txt
After that, RPi.GPIO just works.
To debug this, it's also useful to use
https://github.com/RPi-Distro/raspi-gpio which doesn't have the cast
bug described above. Maybe it's worth packaging in Debian.
For reference, I'm testing with:
import RPi.GPIO as gpio
and a circuit like this one:
More information about the Pkg-raspi-maintainers