question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

GpioController is not correctly identifying Raspberry Pi after latest Raspbian kernel updates

See original GitHub issue

Describe the bug

After running apt-get upgrade on a Raspberry Pi 4B, I couldn’t set pinmodes to pullup or pulldown anymore. Instead, I was getting an error: Unhandled exception. System.InvalidOperationException: The pin does not support the selected mode.

After checking the System.Device.Gpio project I found that GpioController is trying to know if it’s running on a Raspberry Pi via /proc/cpuinfo. There’s a field in there called Hardware and it returns the processor type. Apparently in older Raspbian kernels it was returning the wrong value, since even on a Raspberry Pi 4 it would return “BCM2835”. This is the value that GpioController is comparing against.

Since the kernel update however it seems to be returning the correct value, which for a Raspberry Pi 4 is “BCM2711”.

In fact, BCM2835 is only correct for the first Raspberry Pi, the other models are listed here: https://www.raspberrypi.org/documentation/hardware/raspberrypi/bcm2711/README.md

Current workaround is to manually specify a GpioDriver and pass it to the GpioController constructor:

GpioDriver driver = new RaspberryPi3Driver();
Controller = new GpioController(PinNumberingScheme.Logical, driver);

Steps to reproduce

Update Raspbian on Raspberry Pi 4b to latest kernel via:

sudo apt-get update sudo apt-get upgrade

and reboot the Pi. Then the following code will fail:

Controller = new GpioController();
Controller.OpenPin(26, PinMode.InputPullUp);

Expected behavior

The pin would be opened and the internal pullup resistor turned on.

Actual behavior

Exception is raised: System.InvalidOperationException: The pin does not support the selected mode.

Versions used Target framework: netcoreapp3.1 System.Device.Gpio version: 1.1.0-prerelease.20276.1

Running self-contained on Raspberry Pi 4b, with kernel version 5.4.51-v7l+ (before the update it was 4.19.118-v7l+)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:19 (17 by maintainers)

github_iconTop GitHub Comments

1reaction
krwqcommented, Sep 18, 2020

@pgrawehr I’m fine with that PR but I do not want any new APIs in SDG as part of it, I’d prefer we’ve split SDG into abstraction and implementation. We’re currently brainstorming about how to align board abstraction with other repos and we already have some idea what we could possibly do

1reaction
pgrawehrcommented, Aug 15, 2020

Two observations from my side:

  • The RaspberryPi3Driver works fine on the Pi4. I’ve always used that one and it has never had any problems (except for the pull up/pull down stuff, but that’s fixed since long). So the register address detection works.
  • When (due to the bug in our detection routine) the LibgpiodDriver is used instead of the Raspi driver, everything should be fine as well, since with the current build, that one also supports the pulls.
Read more comments on GitHub >

github_iconTop Results From Across the Web

GpioController is not correctly identifying Raspberry Pi with ...
I would like to use Dht11 module on Raspberry PI 4 Revision 1.2 (Model C03112). Steps to reproduce using (Dht11 dht = new...
Read more >
kernel update problem - Raspberry Pi Forums
Hi all, I'm facing to a strange problem since the lasttest two raspbian update on my Raspberry pi 3. When I'm doing a...
Read more >
Configuration - Raspberry Pi Documentation
In this submenu there are the following options to enable/disable: Camera, SSH, VNC, SPI, I2C, Serial, 1-wire, and Remote GPIO. Camera. Enable/disable the...
Read more >
Raspberry Pi OS - Raspberry Pi Documentation
rpi-update is a command line application that will update your Raspberry Pi OS kernel and VideoCore firmware to the latest pre-release versions. Warning....
Read more >
Do I still need rpi-update if I am using the latest version of ...
The answer marked as correct is in fact outdated, and in a problematic way: rpi-update will update the firmware to the latest published...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found