JoachimSchurig / CppGPIO

C++14 GPIO library for embedded systems on Linux
99 stars 27 forks source link

Raspberry Pi 4 freezes on Ubuntu when controlling digital output #17

Open farshidtz opened 1 year ago

farshidtz commented 1 year ago

I used the example provided here to try out the library. I can see the LED turning on for the requested time but the Pi mostly freezes afterwards. Sometimes the LED stays on longer. An SSH session wouldn't survive but I could get more output using a serial UART consule:

$ g++ onoff.cpp -o onoff -lcppgpio
$ ./onoff
[  161.254299] mmc1: Timeout waiting for hardware interrupt.
[  161.259919] brcmfmac: brcmf_sdio_htclk: HT Avail request error: -110
[  169.098267] rcu: INFO: rcu_preempt detected stalls on CPUs/tasks:
[  169.104480] rcu:     0-...!: (1 ticks this GP) idle=1a7/0/0x7 softirq=8657/8657 fqs=0
[  169.112361] rcu: rcu_preempt kthread timer wakeup didn't happen for 5251 jiffies! g9873 f0x0 RCU_GP_WAIT_FQS(5) ->state=0x402
[  169.123844] rcu:     Possible timer handling issue on cpu=0 timer-softirq=2351
[  169.130910] rcu: rcu_preempt kthread starved for 5252 jiffies! g9873 f0x0 RCU_GP_WAIT_FQS(5) ->state=0x402 ->cpu=0
[  169.141421] rcu:     Unless rcu_preempt kthread gets sufficient CPU time, OOM is now expected behavior.
[  169.150691] rcu: RCU grace-period kthread stack dump:
[  169.155936] rcu: Stack dump where RCU GP kthread last ran:
[  171.494266] mmc1: Timeout waiting for hardware interrupt.
[  171.499872] brcmfmac: brcmf_sdio_htclk: HT Avail request error: -110
[  176.006255] watchdog: BUG: soft lockup - CPU#0 stuck for 26s! [swapper/0:0]
[  181.730253] mmc1: Timeout waiting for hardware interrupt.
[  181.735866] brcmfmac: brcmf_sdio_htclk: HT Avail request error: -110
[  191.970244] mmc1: Timeout waiting for hardware interrupt.
[  191.975847] brcmfmac: brcmf_sdio_htclk: HT Avail request error: -110
[  202.210242] mmc1: Timeout waiting for hardware interrupt.
[  202.215841] brcmfmac: brcmf_sdio_htclk: HT Avail request error: -110
[  204.006227] watchdog: BUG: soft lockup - CPU#0 stuck for 52s! [swapper/0:0]
[  212.450238] mmc1: Timeout waiting for hardware interrupt.
[  212.455859] brcmfmac: brcmf_sdio_htclk: HT Avail request error: -110
[  222.690236] mmc1: Timeout waiting for hardware interrupt.
[  222.695849] brcmfmac: brcmf_sdio_htclk: HT Avail request error: -110
[  232.006223] watchdog: BUG: soft lockup - CPU#0 stuck for 79s! [swapper/0:0]
[  232.118228] rcu: INFO: rcu_preempt detected stalls on CPUs/tasks:
[  232.124436] rcu:     0-....: (1 ticks this GP) idle=1a7/0/0x5 softirq=8657/8657 fqs=5681
[  232.930242] mmc1: Timeout waiting for hardware interrupt.
[  232.935832] brcmfmac: brcmf_sdio_htclk: HT Avail request error: -110

System info:

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 22.04.1 LTS
Release:        22.04
Codename:       jammy

$ g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/aarch64-linux-gnu/11/lto-wrapper
Target: aarch64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 11.3.0-1ubuntu1~22.04' --with-bugurl=file:///usr/share/doc/gcc-11/README.Bugs --enable-languages=c,ada,c++
,go,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-11 --program-prefix=aarch64-linux-gnu- --enable-shared --enable-linker-build-
id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debu
g --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-libquadmath --disable-libquadmath-support --enable-plugin --enable-de
fault-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --enable-fix-cortex-a53-843419 -
-disable-werror --enable-checking=release --build=aarch64-linux-gnu --host=aarch64-linux-gnu --target=aarch64-linux-gnu --with-build-config=bootstrap-lto-lean --enable-l
ink-serialization=2
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.3.0 (Ubuntu 11.3.0-1ubuntu1~22.04) 
icamaster commented 10 months ago

Not sure if helpful or not, but running the provided demo on a Raspberry Pi 4 with a 64-bit OS crashes the network and requires a reboot.

JoachimSchurig commented 10 months ago

This library has only been tested with raspbian as OS - please debug and submit a PR for Ubuntu.

SamueleFacenda commented 1 week ago

This also happens on Raspberry Pi OS 64bit. One of the problems is that pins on /sys/class/gpio/export have a different base number (for me the first one is pin 512). One other problem is that the loop for waiting for a exported gpio is too fast, I have increased it by 5 times in order to be able to open the direction, also because the permissions are set asynchronously and takes some time. The system freezes anyway. Note also that gpio sysfs was deprecated almost 10 years ago