-
Notifications
You must be signed in to change notification settings - Fork 5.1k
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
4.14 freezes when GPIO is pulled high #2550
Comments
Which utility are you using - raspi-gpio? With which GPIOs have you seen this freeze? |
I'm using rpio which uses the |
If you have any external hardware attached to the 40-pin header, please disconnect it and retest. |
I don't have anything connected other than a couple of outputs connected to relays and an input. The input's source is 16V and has a current-limiting 33kΩ resistor attached in series (so maximum current is under 0.5mV, well with-in the the pi's capabilities). |
Really? GPIOs are only 3.3V capable.
Yes, you did say that. I want to narrow down where the fault might be, so please disconnect your hardware from the 40-pin header and retest. If that shows no problems, try reconnecting the pins one at a time to determine which make a difference. |
Alright, I'll de-solder everything when I have the time and report back. |
I think I am having the same issue on our Raspberry Pi's Model 3. They freeze/crash occasionally when trying to read an input pin that has been initialised with a pull up. I've tried different pins (physical pins 29 and 31), with the same result. This can be reproduced with or without any physical connections to the input, e.g. also crashes when you simply try to read the pin without it being connected to anything. Using standard Raspberry Pi power source, no external hardware connected. This has only started happening after I started using the latest Raspbian image. @pelwell any thoughts on what I could do to help you debug this? Otherwise we see no option but to downgrade all devices back to 4.9. |
Here's a simple Node script that reproduces the issue const rpio = require('rpio');
const {INPUT, OUTPUT, HIGH, LOW, PULL_UP} = rpio;
const pin = 29;
console.log('Opening pin');
rpio.open(pin, INPUT, PULL_UP);
console.log('Pin opened');
console.log('Reading state');
const state = rpio.read(pin) || LOW
console.log(`Pin state is ${state}`);
console.log('Setting up polling');
rpio.poll(pin, pin => {
console.log('In poll cycle');
console.log('Reading state');
const state = rpio.read(pin) || LOW
console.log(`Pin state is ${state}`);
});
console.log('End of script'); Removing the Note that this does not happen 100% consistently, but about 95% of the time if you run this shortly after a reboot. For some reason, after some time passes and I make some changes to the script etc. and run it again, it runs fine. But then when I run it after a reboot, it crashes again. |
I'm seeing the same behavior. The problem appears to exist with /dev/mem* as well as dev/gpiomem. Andrew. |
Are you using the correct numbering scheme? I don't know the node 'rpio' library beyond a cursory scan of the source, but I think it uses the official "Broadcom" GPIO numbering scheme. This labels 54 of the SoC pins as GPIO0 to GPIO53. GPIO2 to GPIO27 are brought out onto the 40 pin header - the rest are used to control other features of the Pi. Note that the GPIO number to pin number map is not a simple linear map: GPIO 4 is on header pin 7, while GPIO 5 is on header pin 29. Why does this matter for your use case? Pin 31, which you mention, carries GPIO6, while GPIO31 can control anything from the RTS line of the Bluetooth modem to the reset line for the USB Hubs/Ethernet controller. If you are in doubt, use the raspi-gpio utility (https://github.com/RPi-Distro/raspi-gpio) to examine the pin functions and control the pull settings - I choose it because it only uses the BRCM scheme (which is a close match for the SoC hardware). |
Yes, we're using the physical numbering scheme (1-40) as supported by rpio. As mentioned, this works flawlessly on kernel 4.9, but breaks on 4.14. Rpio also supports the GPIO numbering scheme, but we aren't using that. So whenever I mention a pin number, I'm referring to the physical pin number. However, I don't think which pin it is matters much, as we've experienced the issue with pins 29 and 31 (the only ones I tested), and @kimjongskill has reported issues with physical pins 12, 16, 22, 26. So it seems a wide range of different pins are affected. |
I see the same behavior on various pins. I'm using GPIO numbering. |
Are any of you not using the Node rpio library? (I'm not saying it is at fault, but it might be different in a significant way). |
I did a test using the Node 'onoff' library and was unable to replicate the problem. I've not tested other libraries. |
@pelwell One of the first things I tried was rolling back to older versions of rpio, but when I investigated further, I noticed there hadn't been any significant code changes done at all in the past few months that would suddenly cause it stop working. I didn't test any other libraries as this one seems to be the best maintained one. Some of the other libraries haven't been updated in 2 years. I also tried on different versions of Node, but same result. The only thing that fixes it for me at the moment is rolling back to the 4.9 kernel. Could any clues be found in the |
I really don't think so - all /dev/gpiomem does is map the GPIO registers for user space - a restricted version of /dev/mem which doesn't need root privileges to access. |
Would you have any recommended place to look for clues as to why it's causing the crash? I've examined Any chance you could have a chat with the maintainer of rpio (@jperkin) to try and figure out what could be happening? He'll probably know more about what the library is doing and how any kernel update changes could be affecting the package. |
The backend of rpio uses Mike McCauley's bcm2835 library to handle I can't see how nodejs would be affecting the behaviour here, but you could always just use the bcm2835 library directly and write a simple C program to perform the same functions to rule it out. I don't have any hardware running newer kernels to verify this at the moment unfortunately. |
It doesn't make much sense to me - kernel changes should have no effect on how rpio works because rpio is essentially a driver that runs in userspace, and it hasn't changed. The only hypothesis so far is that the kernel is manipulating the GPIO hardware at the same time as rpio, and without any kind of synchronisation it ends up changing a critical pull in the wrong direction. |
Any ideas how I can install the rpio library on 4.17? I get the following output from
|
Looks like you are using a very old version of node (finally something I can help with lol) |
Direct user-space access to hardware may be fast, but it is non-portable and runs the risk of atomicity issues (as this may be). Linux has a new character device interface - libgpiod - which should be much more efficient than the sysfs interface whilst still remaining portable. |
The device doesn't freeze when this happens. Access to I/O devices (USB, network) stops but the machine keeps running - if you run top with a fast refresh (for instance top -id 0.125) you'll see activity. I noticed the problem with a kernel updated around the March '18 timeframe. Previously the same nodejs code had been stable. It didn't seem as though rpio had been updated around that time so I feel that a change in the kernel caused this to start happening. It seems as though it's some kind of i/o initialization issue that's causing the problem - if I can get the thing to run, it will continue to run without failing until the next boot. Stopping/starting node.js seems to have no impact on the problem. It also doesn't matter how long the system has been running - it happens on the first run after reboot (but not every time). Andrew. |
Thanks, @kimjongskill, I've got node updated now, and rpio is installed. I'll have a play for a bit and report back. |
FWIW rpio should build fine on any nodejs version since 0.8 (travis confirms this, each push is tested on every version and all are currently green), unfortunately npm and gyp are a pile of crap and will often fail for spurious reasons with no useful information, as in this case. Sorry for the terrible user experience :( |
I can recreate the issue, or at least I'm getting lockups running the GPIO test script, but I won't get much time until next week. |
Great, thanks for looking into it @jperkin and @pelwell. @ASwingler thanks for correcting me. I assumed the devices freezes, but you're right it does still stay on, but loses all network connectivity and USB, so from the outside it appears dead. I also noticed that once it's running, it will work fine. While debugging, I found that it worked one time after reboot after I had downgraded Node, so I thought I found the problem, but then after the next reboot it failed again. Seemed pretty random in the end. |
Getting further: I can get a lock-up reliably in two simple steps:
Breaking out of the script leaves the event bits for rising and falling edges on GPIO5 (pin 29) enabled. Subsequently setting the pull in the opposite direction seems to be the fatal step, presumably because it causes the input level to change. In fact, replacing the raspi-gpio invocation with pull the pin down using a patch cable is enough to kill the system. Clearing the event bits before changing the pin level avoids the problem. |
An overlay to disable all GPIO interrupts. See: raspberrypi/linux#2550 Signed-off-by: Phil Elwell <[email protected]>
An overlay to disable all GPIO interrupts. See: #2550 Signed-off-by: Phil Elwell <[email protected]>
An overlay to disable all GPIO interrupts. See: raspberrypi/linux#2550 Signed-off-by: Phil Elwell <[email protected]> (cherry picked from commit ed8ae65c08be8559612bb3c234ec8d9ac52956c4) Signed-off-by: Paolo Pisati <[email protected]>
commit 0d947b12856e6cf9f1e46ad861eaa86282ae86d8 from https://github.com/raspberrypi/linux.git An overlay to disable all GPIO interrupts. See: raspberrypi/linux#2550 Signed-off-by: Phil Elwell <[email protected]> Signed-off-by: Xulin Sun <[email protected]>
commit 0d947b12856e6cf9f1e46ad861eaa86282ae86d8 from https://github.com/raspberrypi/linux.git An overlay to disable all GPIO interrupts. See: raspberrypi/linux#2550 Signed-off-by: Phil Elwell <[email protected]> Signed-off-by: Xulin Sun <[email protected]>
Hi @pelwell I am just following up on this issue. Is there anyway to use |
No, but there is a gpio-key-polled (or gpio-polled-key) driver which could be used instead for shutdown detection with a modified overlay, provided the driver is enabled. |
@adamreisnz onoff and pigpio are also very well maintained (even if I may say so myself 😄)
@jperkin onoff uses the sysfs interface and can detect approximately 20,000 state changes per second with this test program on a Raspberry Pi 4. An equivalent rpio test program can detect approximately 923 state changes per second. |
The ioctl-based libgpiod API should easily outperform the sysfs API. |
While this is likely to be the case in many scenarios, I'm not sure if it will be the case with Node.js. In Node.js applications there is normally only one JavaScript thread and blocking calls in this thread are regarded as being a bad practice. Under the covers, onoff uses epoll to detect state changes. It looks like libgpiod uses ppoll to detect state changes. To avoid blocking the JavaScript thread, it's necessary to start a C/C++ thread in the background. This background thread can then make blocking epoll/ppoll calls. When the background thread detects a state change, it needs to inform the JavaScript thread about the state change. This results in context switching between the threads which comes with a cost. I'm not sure if using libgpiod in combination with ppoll will be any faster than sysfs in combination with epoll. @pelwell why do you think the libgpiod API should easily outperform the sysfs API for state change notifications? |
libgpiod cuts out several layers of software compared to sysfs - it allows multiple GPIOs (or a single GPIO repeatedly) to be queried and controlled from a single open file descriptor. There may be some use cases where the extra overheads of sysfs matter less, and your edge event case may be one of them, but that doesn't mean that libgpiod isn't superior. You should also consider what the kernel documentation says:
|
As google points here, I'm hesitant to start another topic on the same issue. Problem:
This is a clean system with little else installed, please see below:
Home Directory Permissions:
I have tried with Archlinux and Raspberry Pi OS for a few days, all with the same "freezing" result:
The 8 Channel Relay I'm using is active low so I need the pins high on reboot.
Here is the tree of my home folder:
|
Can you explain this section of your config.txt:
At best it's a bit strange. |
I added that section to set the state of the pins when the rPi is powered on as detailed here: The relay board linked to above is active low. So I want to prevent the relays from activating when there is a power disconnection. |
Each instance of gpio-poweroff overwrites the previous one so only one of them has any effect - the last one. The only sure way to avoid glitches on GPIOs is to make use of the default pulls, rather than trying to change them. |
Thank you, yes it did feel strange pasting each line. I found this: Here: Is there anything you would like me to try? |
I updated the /boot/config.txt and the good news is I can see the pull up resistors are working. |
Make sure you didn't accidentally remove the "dtoverlay=gpio-no-irq" line -
that would cause a lockup.
…On Tue, Sep 22, 2020 at 1:16 PM Nahshon Williams ***@***.***> wrote:
I updated the /boot/config.txt and the good news is I can see the pull up
resistors are working.
Unfortunately the freezing/crashing persists.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#2550 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AD7O7WJNLGV4PN75JBSDBI3SHEA3HANCNFSM4E7HAE5A>
.
|
@nahshonw A different suggestion – instead of changing the way the Raspi IOs work with The relay module is active low, but you have normally closed and normally open. Why not connect the thing you want to control to the other connector (normally open) so the lights are off when there is no input? |
Thank you, yes I did check and the file is fine. Here is the updated /boot/config.txt file:
|
The relays are for powering up some Vacuum Fluorescent Displays which need a lot of current when powered on, so I switch all seven on in sequence to protect the power supply. |
As mentioned in a Raspberry Pi Forums post (which I won't link to because it just duplicates effort) I am looking at GPIO edge detection for another reason, so I may have something to add in a few days. |
My RPI4 suffered from the same symptoms and, |
Is this issue really fixed? I have the same problem reading GPIO pins externally controlled and have tried the pigpio library and the BCM2835 library. Having applied the 'dtoverlay=gpio-no-irq' line to the /boot/config.txt file it only takes slightly longer for the crash to occur. I am working on a PI Zero W, kernel version 5.4.83 Running gpio tests reveals all working ok, swapping out the pi for another produces the same results. |
In my case I had to assume the Pi was faulty as I was given another Raspberry Pi 3 which has worked flawlessly since. |
@Sarain-Richard That's not nearly enough information to work with. If you think there is a problem with the GPIO handling, please create a new issue giving all the relevant information - config.txt settings, devices attached to GPIOs, what software is reading each GPIO etc. |
Understood |
Since upgrading my Raspberry Pi Zero to the 4.14 kernel from 4.9, every time a GPIO pin is read and it is high, the device freezes and has to be reset. I couldn't find anything in the logs related to this.
The GPIO pins are accessed through
/dev/gpiomem/
.The text was updated successfully, but these errors were encountered: