adafruit / Adafruit_Blinka

Add CircuitPython hardware API and libraries to MicroPython & CPython devices
https://learn.adafruit.com/circuitpython-on-raspberrypi-linux
MIT License
457 stars 349 forks source link

Cannot determine SOC peripheral base address #907

Open caternuson opened 2 weeks ago

caternuson commented 2 weeks ago

Board Name

Pi 5

Steps

Follow the guide for initial setup: https://learn.adafruit.com/circuitpython-on-raspberrypi-linux/installing-circuitpython-on-raspberry-pi and then run the blinkatest.py script.

Description

The installation runs without issue. But when the blinkatest.py script is run, get the following error:

(env) pi@raspberrypi:~ $ python3 blinkatest.py
Hello, blinka!
Traceback (most recent call last):
  File "/home/pi/blinkatest.py", line 8, in <module>
    pin = digitalio.DigitalInOut(board.D4)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/pi/env/lib/python3.11/site-packages/digitalio.py", line 197, in __init__
    self.direction = Direction.INPUT
    ^^^^^^^^^^^^^^
  File "/home/pi/env/lib/python3.11/site-packages/digitalio.py", line 227, in direction
    self._pin.init(mode=Pin.IN)
  File "/home/pi/env/lib/python3.11/site-packages/adafruit_blinka/microcontroller/bcm283x/pin.py", line 40, in init
    GPIO.setup(self.id, GPIO.IN)
RuntimeError: Cannot determine SOC peripheral base address
(env) pi@raspberrypi:~ $

Additional information

Related forum post: https://forums.adafruit.com/viewtopic.php?t=214687

Bichidian commented 2 weeks ago

I had the same problem. I figured out that this was caused by using the RPi.GPIO package, which does not support Raspberry Pi 5. The strange thing is that I found this bug was already fixed by pull request #856. Reinstalling directly from github by pip install git+https://github.com/adafruit/Adafruit_Blinka.git fixed the problem for me. Somehow pip install Adafruit_Blinka got the wrong dependency.

caternuson commented 2 weeks ago

Since it's pulling the pin from bcm283x, it seems like the detector is not correctly IDing the board as a Pi5. https://github.com/adafruit/Adafruit_Blinka/blob/b91d3fc70bd1599ea50517a390d18a3fc455fc85/src/digitalio.py#L17-L27

caternuson commented 2 weeks ago

Or something else?

(env) pi@raspberrypi:~ $ python3
Python 3.11.2 (main, Aug 26 2024, 07:20:54) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import digitalio
>>> digitalio.detector.chip.BCM2XXX
True
>>> digitalio.board_id
'RASPBERRY_PI_5'
>>> digitalio.Pin
<class 'adafruit_blinka.microcontroller.bcm283x.pin.Pin'>
>>> 
caternuson commented 2 weeks ago

Oh, that's just what it does: https://github.com/adafruit/Adafruit_Blinka/blob/b91d3fc70bd1599ea50517a390d18a3fc455fc85/src/adafruit_blinka/microcontroller/bcm2711/pin.py#L4-L6

MGPhil commented 2 weeks ago

I had the same problem. I figured out that this was caused by using the RPi.GPIO package, which does not support Raspberry Pi 5. The strange thing is that I found this bug was already fixed by pull request #856. Reinstalling directly from github by pip install git+https://github.com/adafruit/Adafruit_Blinka.git fixed the problem for me. Somehow pip install Adafruit_Blinka got the wrong dependency.

For me RPi.GPIO works out of the box on PI 5, install Blinka or rpi-lgpio breaks the GPIO function

caternuson commented 2 weeks ago

There's a hardwired pip install of RPi.GPIO in the installer script: https://github.com/adafruit/Raspberry-Pi-Installer-Scripts/blob/ad19b39863503ce5edf76cfff1334ccad388c03d/raspi-blinka.py#L95 which may be interfering with the rpi-lgpio install?

https://pypi.org/project/rpi-lgpio/

You cannot install rpi-lgpio and rpi-gpio (aka RPi.GPIO, the library it emulates) at the same time, in the same Python environment. Both packages attempt to install a module named RPi.GPIO and obviously this will not work.

MGPhil commented 2 weeks ago

There's a hardwired pip install of RPi.GPIO in the installer script: https://github.com/adafruit/Raspberry-Pi-Installer-Scripts/blob/ad19b39863503ce5edf76cfff1334ccad388c03d/raspi-blinka.py#L95 which may be interfering with the rpi-lgpio install?

https://pypi.org/project/rpi-lgpio/

You cannot install rpi-lgpio and rpi-gpio (aka RPi.GPIO, the library it emulates) at the same time, in the same Python environment. Both packages attempt to install a module named RPi.GPIO and obviously this will not work.

So how to install blinka without rpi-lgpio as RPI.GPIO works out of the box now on PI 5?

caternuson commented 2 weeks ago

Tested above by manually uninstalling RPi.GPIO:

(env) pi@raspberrypi:~ $ pip3 uninstall RPi.GPIO
Found existing installation: RPi.GPIO 0.7.1
Uninstalling RPi.GPIO-0.7.1:
  Would remove:
    /home/pi/env/lib/python3.11/site-packages/RPi.GPIO-0.7.1.dist-info/*
    /home/pi/env/lib/python3.11/site-packages/RPi/*
Proceed (Y/n)? y
  Successfully uninstalled RPi.GPIO-0.7.1

And then it works:

(env) pi@raspberrypi:~ $ python3
Python 3.11.2 (main, Aug 26 2024, 07:20:54) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import board
>>> import digitalio
>>> pin = digitalio.DigitalInOut(board.D4)
>>> 
caternuson commented 2 weeks ago

So how to install blinka without rpi-lgpio as RPI.GPIO works out of the box now on PI 5?

@MGPhil You don't. There's an installation issue (and maybe more) that needs to be fixed. Currently investigating and documenting here. This is not a user issue. It needs to be fixed by Adafruit.

MGPhil commented 2 weeks ago

@caternuson OK then I wait for the fix, just saying I postet that issue in the adafruit forum and debugged a lot before that post. As I found out RPi.GPIO works out of the box on PI 5 for me and thats why rpi.lgpio which is installed with blinka breaks both.

however happy waiting for you devs to fix that issue, thanks a lot for that great work and great library