Dangku / RPi.GPIO-Amlogic

RPi.GPIO for Bananapi M5/M2pro, M2S, CM4
MIT License
3 stars 6 forks source link

Getting "This module can only be run on a Raspberry Pi!" in Banana Pi M5 running Armbian 23 with kernel 6.1.30-meson64 #4

Open aalku opened 1 year ago

aalku commented 1 year ago

Hi! It seems the detection of the board is not working in my board running Armbian 23 with kernel 6.1.30-meson64

I get this error:

pi@bananapim5:~$ sudo python3 auto-fan.py 
Traceback (most recent call last):
  File "/home/pi/auto-fan.py", line 2, in <module>
    import RPi.GPIO as GPIO
  File "/usr/local/lib/python3.10/dist-packages/RPi.GPIO-0.7.1-py3.10-linux-aarch64.egg/RPi/GPIO/__init__.py", line 23, in <module>
    from RPi._GPIO import *
RuntimeError: This module can only be run on a Raspberry Pi!

Looking at the code I think the problem is that I get no "Hardware" section in /proc/cpuinfo:

cat /proc/cpuinfo
processor       : 0
model name      : ARMv8 Processor rev 0 (v8l)
BogoMIPS        : 48.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     : 0x1
CPU part        : 0xd05
CPU revision    : 0

processor       : 1
model name      : ARMv8 Processor rev 0 (v8l)
BogoMIPS        : 48.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     : 0x1
CPU part        : 0xd05
CPU revision    : 0

processor       : 2
model name      : ARMv8 Processor rev 0 (v8l)
BogoMIPS        : 48.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     : 0x1
CPU part        : 0xd05
CPU revision    : 0

processor       : 3
model name      : ARMv8 Processor rev 0 (v8l)
BogoMIPS        : 48.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     : 0x1
CPU part        : 0xd05
CPU revision    : 0

I think we could use this, but I don't think if you know a better way:

grep BOARD_NAME /etc/armbian-image-release
BOARD_NAME="Banana Pi M5"

I might code it myself but I wish to get at least your advice.

aalku commented 1 year ago

I added this so I think the board gets detected but there's a new error. I guess the module is not compatible with the kernel or something, right?

image

I get this:

Traceback (most recent call last):
  File "/home/pi/auto-fan.py", line 2, in <module>
    import RPi.GPIO as GPIO
  File "/usr/local/lib/python3.10/dist-packages/RPi.GPIO-0.7.1-py3.10-linux-aarch64.egg/RPi/GPIO/__init__.py", line 23, in <module>
    from RPi._GPIO import *
SystemError: initialization of _GPIO raised unreported exception

I'll try to find out where does that unreported error come from.

EDIT:

Ok... sometimes... it works!

It seems the error is thrown randomly like 9 of every 10 tries and the other time it works perfectly.

But if I add a fprint here it works always. 🤷🏻‍♂️

image

I don't undersand why.

aalku commented 1 year ago

Ok. I needed to initialize "revision" variable. It needs to have a length, a \0, I guess, It makes sense.

image

I don't know why prints here or there totally changed the probability of crash but once I fixed that variable then it works as expected.

So the pending thing is if we detect the board this way or how.

Here it is the code if you can make use of it: https://github.com/aalku/RPi.GPIO-Amlogic-BPiM5/commit/beff42442ffb9c4a6780b5bf0f8b4c1570716045

Dangku commented 1 year ago

it's only for bananapi amlogic 4.9 kernel ubuntu/debian image, no support third part images like armbian.

aalku commented 1 year ago

Ok. Thanks. I'll leave my fork online then. It works for me and maybe it will help someone else.

https://github.com/aalku/RPi.GPIO-Amlogic-BPiM5

Thanks again. Great job.