-
Notifications
You must be signed in to change notification settings - Fork 587
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
Access to GPIO fails with all versions of RaspiOS starting from 2024-10-28 on Raspberry Pi 5 #2366
Comments
One of the attempts I've tried is return new LibGpiodDriver(0, LibGpiodDriverVersion.V2); without succes. Diggin into LibGpiodDriver contructor I've found into LibGpiodDriverFactory
that deals with _installedLibraries. Since in my working solution I've forced V1 version, may be that latest RaspiOS now install by the V2 version, the library find it but has some incompatibility with your code? One more thingh: what about the gpioChip parameter of LibGpiodDriver contructor? Your default is 4, mine is 0 and is working! |
[Triage] Can you confirm we understand this correctly? V1 works but with |
Yes @krwq. Same error with V2 and gpioChip = 0. This is my final working lazy GpioController initialization. private readonly Lazy<GpioController> gpioController;
private GpioController _gpioController { get => gpioController.Value; }
public LedManager(ILogger<LedManager> logger)
{
_logger = logger;
gpioController = new(() => GpioControllerFactory());
}
/// <summary>
/// Create GpioController
/// </summary>
/// <returns></returns>
private GpioController GpioControllerFactory()
{
try
{
//old working way on pre 2024-10-28 RaspiOS devices
return new GpioController();
}
catch (Exception ex)
{
_logger.LogWarning($"Error creating GpioController standard, trying new way with experimental features....{Environment.NewLine}{ex.ToString()}");
#pragma warning disable SDGPIO0001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
//new working way on after 2024-10-28 RaspiOS devices
return new GpioController(PinNumberingScheme.Logical, new LibGpiodDriver(0, LibGpiodDriverVersion.V1));
#pragma warning restore SDGPIO0001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
}
} I honestly didn't search what gpioChip stand for, but I can try different combination if you need more test on my side. |
[Triage] @ciacco85 can you run here is example output:
the 54 lines chip is likely the one which needs to be passed to LibGpiodDriver |
@krwq here it's the result! it seems the same $ gpiodetect
gpiochip0 [pinctrl-rp1] (54 lines)
gpiochip10 [gpio-brcmstb@107d508500] (32 lines)
gpiochip11 [gpio-brcmstb@107d508520] (4 lines)
gpiochip12 [gpio-brcmstb@107d517c00] (17 lines)
gpiochip13 [gpio-brcmstb@107d517c20] (6 lines)
gpiochip0 [pinctrl-rp1] (54 lines) |
I just had access to a RPi5 and the result is very different: $ gpiodetect
gpiochip0 [gpio-brcmstb@107d508500] (32 lines)
gpiochip1 [gpio-brcmstb@107d508520] (4 lines)
gpiochip2 [gpio-brcmstb@107d517c00] (17 lines)
gpiochip3 [gpio-brcmstb@107d517c20] (6 lines)
gpiochip4 [pinctrl-rp1] (54 lines) $ cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"
NAME="Debian GNU/Linux"
VERSION_ID="12"
VERSION="12 (bookworm)"
VERSION_CODENAME=bookworm
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/" $ cat /proc/cpuinfo
processor : 0
BogoMIPS : 108.00
Features : fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm lrcpc dcpop asimddp
CPU implementer : 0x41
CPU architecture: 8
CPU variant : 0x4
CPU part : 0xd0b
CPU revision : 1
processor : 1
BogoMIPS : 108.00
Features : fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm lrcpc dcpop asimddp
CPU implementer : 0x41
CPU architecture: 8
CPU variant : 0x4
CPU part : 0xd0b
CPU revision : 1
processor : 2
BogoMIPS : 108.00
Features : fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm lrcpc dcpop asimddp
CPU implementer : 0x41
CPU architecture: 8
CPU variant : 0x4
CPU part : 0xd0b
CPU revision : 1
processor : 3
BogoMIPS : 108.00
Features : fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm lrcpc dcpop asimddp
CPU implementer : 0x41
CPU architecture: 8
CPU variant : 0x4
CPU part : 0xd0b
CPU revision : 1
Revision : d04170
Serial : 00f314ef4983fb91
Model : Raspberry Pi 5 Model B Rev 1.0 @ciacco85 I invite you to do the same and compare the results. Thanks |
BTW I just see a lot of posts saying that the recent kernel update changed the mappings of the chip id. |
here it is my results @raffaeler cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"
NAME="Debian GNU/Linux"
VERSION_ID="12"
VERSION="12 (bookworm)"
VERSION_CODENAME=bookworm
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/" cat /proc/cpuinfo
processor : 0
BogoMIPS : 108.00
Features : fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm lrcpc dcpop asimddp
CPU implementer : 0x41
CPU architecture: 8
CPU variant : 0x4
CPU part : 0xd0b
CPU revision : 1
processor : 1
BogoMIPS : 108.00
Features : fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm lrcpc dcpop asimddp
CPU implementer : 0x41
CPU architecture: 8
CPU variant : 0x4
CPU part : 0xd0b
CPU revision : 1
processor : 2
BogoMIPS : 108.00
Features : fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm lrcpc dcpop asimddp
CPU implementer : 0x41
CPU architecture: 8
CPU variant : 0x4
CPU part : 0xd0b
CPU revision : 1
processor : 3
BogoMIPS : 108.00
Features : fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm lrcpc dcpop asimddp
CPU implementer : 0x41
CPU architecture: 8
CPU variant : 0x4
CPU part : 0xd0b
CPU revision : 1
Revision : c04170
Serial : e4545656b96ccf93
Model : Raspberry Pi 5 Model B Rev 1.0 |
@raffaeler |
@ciacco85 Apparently this is "just" a kernel update unrelated to the hardware revision board. With regards to the OS kernel issues, I think we can't do much about it from our library.
HTH |
After further investigation, I found that the In fact it has the following private field: private readonly Chip _chip; The public string GetName()
public string GetLabel() These methods return the same info provided by gpiodetect. There is some work to do:
Unfortunately, the libgpiod v1 driver does not provide the same info, but they are available and could be added to the driver similarly to what the v2 does. Once added support for the Chip and ChipInfo in v1, the above steps should be repeated for the v1 as well. Anyone willing to contribute with a PR on this is welcome. |
Thank you! I think I'll do both! |
Now I'll do a short vacation, but a PR could be a really nicr christmas activity. I'll think about it. |
@ciacco85 I've just had a look: The SysFs driver also includes logic to read out the chip name and identification. It seems that we just need to make this logic public in some fashion. |
@pgrawehr Interestingly, we should find a way that allows to do that without loading the entire driver first. Otherwise, this could incur in a performance hit every time we initialize the I would suggest to extract the minimum possible logic from the |
@raffaeler I agree to that. I was thinking of a static method in |
You are right but I never had any Windows board exposing GPIOs, so I can't imagine an equivalent implementation on Windows. It could make sense to throw an Exception when no Gpio underlying device is found (on any OS). |
[Triage] @ciacco85 thank you for offering help to implement API here. We suggest to add API in following shape: // we already have similar internal version of this for LibGpiod but it should be edited to be more generic:
// https://github.com/dotnet/iot/blob/main/src/System.Device.Gpio/Interop/Unix/libgpiod/V2/Proxies/ChipInfo.cs
[Experimental(DiagnosticIds.SDGPIO0001, UrlFormat = DiagnosticIds.UrlFormat)]
public sealed record ChipInfo(int Id, string Name, string Label, int NumberOfLines)
{
}
public partial class SysFsDriver // partial because it already exists
{
[Experimental(DiagnosticIds.SDGPIO0001, UrlFormat = DiagnosticIds.UrlFormat)]
public static IEnumerable<ChipInfo> GetAllChipsInfo();
} |
Describe the bug
It was ok with previous versions of RaspiOS until 2024-07-04.
The code runs in a container under IotHub module.
Steps to reproduce
First of all, I've solved with a workaround using this code that isn't production ready
and with the following Dockerfile (I'm sure I can remove some packages)
RUN apt-get update \ && apt-get install -y sudo libgpiod2 gpiod libgpiod-dev libpigpiod-if-dev libpigpiod-if1 libpigpiod-if2-1
Full very simple code at my repo gpio-tester
Previous attempts as suggested in #2361
and with the following Dockerfile
RUN apt-get update \ && apt install -y sudo libgpiod-dev
Made a lot of attempt trying different package without success until I've found the working solution described above
Expected behavior
All should work with
or at least this code inside your library should be modified from this
to this
I can make a PR, but I think this part is so crucial and you're already working on the implementation for RP1
Actual behavior
This exception is thown
Versions used
Latest version 3.2.0 of System.Device.Gpio and net9
The text was updated successfully, but these errors were encountered: