-
Notifications
You must be signed in to change notification settings - Fork 223
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
EdgeDetection crashes Raspberry Pi 3 #35
Comments
Edit, it is done using this - https://golang.org/pkg/syscall/#EpollCreate1 |
Hi, Could you provide me more info about your environment? The approach using epoll seems interesting, I'll take the closer look into it sometime. |
I will provide more information tomorrow when I am back at the University :)
…On Tue, 27 Nov 2018, 15.16 Drahoslav Bednář ***@***.*** wrote:
Hi,
this seems to be the same issue as in #33
<#33>, (which I am not
able to reproduce, unfortunately). Does it freeze every time as soon as
Detect method is called, or only when you connect it to RF receiver and
generate some edges?
Could you provide me more info about your environment?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#35 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AYwLSv62Bej1Bi2QLuTSwpR9ZqxxhGwHks5uzUkggaJpZM4YzpxP>
.
|
Greate, also:
|
But I will check number 1 tomorrow to make sure! :) |
Setup
Running the latest version of Raspbian (2018-11-13-raspbian-stretch-lite), having the latests updates using
Code executionRunning the code below WITHOUT the RF receiver attached, prints "works" and then exists the program and everything works fine. Currently I am just using the polling method, and checking the state each time.
Output from hexdump
Final notesIf you lived nearby, I would be able to give you a module for testing (if the university agrees), but doesn't look like it. Please say if you need anymore information from me ! Or need me to test some more ;) |
Thanks for the info!
And, I'm from Brno in the Czech Republic. I Guess you are from Germany? 🗺️ 🤔 |
Me neither.. It seems quite weird..
Denmark but close! Seems like quite a stretch. |
That is really some kind of magic. Maybe pi just can't handle faster changes. Also we can try to use "asynchronous" GPAREN/GPAFEN registers for detection instead of "synchronous" GPREN/GPFEN registers. The difference is the synchronous looking for 011/100 patterns, and the other dont - so they should be able to detect even shorter pulses. Just change lines 351/352 in renReg := p/32 + 31
fenReg := p/32 + 34 See chapter 6.1 in https://www.raspberrypi.org/app/uploads/2012/02/BCM2835-ARM-Peripherals.pdf if you are interested in details. |
package main
import (
"fmt"
"github.com/stianeikeland/go-rpio"
"os"
"os/signal"
"sync"
"time"
)
func pour(pin rpio.Pin, sleep time.Duration) {
fmt.Printf("Pouring: %f\n", sleep.Seconds())
pin.High()
time.Sleep(sleep)
pin.Low()
return
}
func main() {
defer rpio.Close()
if err := rpio.Open(); err != nil {
fmt.Println(err)
os.Exit(1)
}
Relay1 := rpio.Pin(18)
Relay2 := rpio.Pin(22)
Relay3 := rpio.Pin(26)
Input1 := rpio.Pin(6)
Input1.PullUp()
Relay1.Output()
Relay2.Output()
Relay3.Output()
Relay1.Low()
Relay2.Low()
Relay3.Low()
Input1.Detect(rpio.FallEdge)
fmt.Println("press button")
for i := 0; i < 2; {
if Input1.EdgeDetected() { // check if event occured
fmt.Println("button pressed")
pour(Relay1, 2*time.Second)
pour(Relay2, 3*time.Second)
i++
}
time.Sleep(5 * time.Second)
}
Input1.Detect(rpio.NoEdge) // disable edge event detection
} this code crashes my Rpi3 as well after a button press is detected, it runs the first pour() then pi hardlocks and i have to pull power cable Pin6 is connected to GND via a push button |
Solved! Explanation: Every edge event generates interruption as the side effect, but these are not handled by the system and after some number of unhandled interruptions it freezes. In some update of Linux kernel (to which I switched after implementing the event detection functionality) the way the interruptions are handled changed. It worked before "by accident". The solution above will disable all gpio interruption requests. But it is just workaround since it might break some other programs. Therefore I'll try to figure out a better solution. Either by disabling irq from within go-rpio, or better by reimplementing the detection functionality and actually handle the interruptions. But disabling irq using dtoverlay in config should be good enough for now. |
@Drahoslav7 awesome, i'll have results in a few minutes after testing |
@Drahoslav7 my code works like a charm with the dtoverlay setting no more freeze, thank you! |
I'm happy we figured it out. |
@Drahoslav7 haven't had time to test it, currently in the mid of getting all the code to work together before the deadline. |
I had this issue on my Pi 4B running the program as root. Adding |
Using
Detect
and running a very basic program on the Raspberry Pi 3, will result in the whole Raspberry Pi locking up (and needing a forced restart).This only happens on a pin with very many rises/falls, currently I am using this for a RF receiver, so there are quite a lot of rises/falls.
The code I am using is this ...
Not even doing anything with it. I don't know what the solution would be, but I think that we could get the interrupt etc. if we used such a system as epoll (http://man7.org/linux/man-pages/man7/epoll.7.html), I know it is uses for another Go system for GPIO interaction here - https://godoc.org/github.com/kidoman/embd
The text was updated successfully, but these errors were encountered: