Menu

#191 64bit This module can only be run on a Raspberry Pi!

Done
None
Critical
Patch
2022-02-06
2020-11-27
No

Hi Ben,
I went to a lot of tickets to find a solution for this re-occurring problem but it seems it is here again on latest hard- and software:

import RPi.GPIO as GPIO
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.8/site-packages/RPi/GPIO/init.py", line 23, in <module>
from RPi._GPIO import *
RuntimeError: This module can only be run on a Raspberry Pi!</module></module></stdin>

 RPi4B 4Gbyte

 OS: Archlinux ARM aarch64

 Python version 3.8.6 and GCC 10.2.0

 Rpi.GPIO version: 0.7.0

More precisely: installed AUR package python-raspberry-gpio 0.7.0-2 via
git clone https://aur.archlinux.org/python-raspberry-gpio.git and running makepkg -si
In the PKGBUILD file CFLAGS=”-fcommon” is specified by default.
Installation is not the problem.

 cat /proc/cpuinfo

Identical info for processor : 0/1/2/3
BogoMIPS : 108.00
Features : fp asimd evtstrm crc32 cpuid
CPU implementer : 0x41
CPU architecture: 8
CPU variant : 0x0
CPU part : 0xd08
CPU revision : 3

 cat: /proc/device-tree/system/linux,revision: No such file or directory

I do not run a container and there is no difference in using it with sudo or not.

In /dev I see /dev/gpiochip0 and /dev/gpiochip1, not /dev/gpiomem

Any clue?
Thanks in advance.

Discussion

  • Lucas Nussbaum

    Lucas Nussbaum - 2020-11-29

    Hi,

    I can confirm this problem on Debian.

    On the vanilla linux kernel (not the rpi one), there is no /dev/gpiomem. So this library tries to detect PERI_BASE using various heuristics.

    I tried forcing the value with this patch, which works fine:

    --- rpi.gpio-0.7.0.orig/source/c_gpio.c
    +++ rpi.gpio-0.7.0/source/c_gpio.c
    @@ -30,6 +30,7 @@ SOFTWARE.
    
     #define BCM2708_PERI_BASE_DEFAULT   0x20000000
     #define BCM2709_PERI_BASE_DEFAULT   0x3f000000
    +#define BCM2711_PERI_BASE_DEFAULT   0xFE000000
     #define GPIO_BASE_OFFSET            0x200000
     #define FSEL_OFFSET                 0   // 0x0000
     #define SET_OFFSET                  7   // 0x001c / 4
    @@ -92,8 +93,10 @@ int setup(void)
             fseek(fp, 4, SEEK_SET);
             if (fread(buf, 1, sizeof buf, fp) == sizeof buf) {
                 peri_base = buf[0] << 24 | buf[1] << 16 | buf[2] << 8 | buf[3] << 0;
    +            printf("peri_base from /proc/device-tree/soc/ranges: %x\n", peri_base);
             }
             fclose(fp);
    +        peri_base = BCM2711_PERI_BASE_DEFAULT;
         } else {
             // guess peri base based on /proc/cpuinfo hardware field
             if ((fp = fopen("/proc/cpuinfo", "r")) == NULL)
    

    But I don't know to fit in the current detection logic.

    Here is the content of /proc/device-tree/soc/ranges:

    # cat /proc/device-tree/soc/ranges  | hexdump
    0000000 007e 0000 0000 0000 00fe 0000 8001 0000
    0000010 007c 0000 0000 0000 00fc 0000 0002 0000
    0000020 0040 0000 0000 0000 80ff 0000 8000 0000
    0000030
    

    Apparently, on the RPI 4, you need to look at the 3rd 32-b word, not at the second (I don't understand the format of that file). See https://gist.github.com/jperkin/c37a574379ef71e339361954be96be12 for values on various models.

     
  • Grant Spence

    Grant Spence - 2021-02-27

    Having issues in a non-privileged (no /sys from host) docker environment (Homeassistant.io). I just updated my kernel, and was getting:

    RuntimeError: This module can only be run on a Raspberry Pi!
    

    It seems the logic block regarding /proc/cpuinfo is missing BCM2711. I'm probably over simplifying, but why is BCM2711 missing? I'm patching with this:

       else if ((fp = fopen("/proc/cpuinfo", "r"))) {                                         
          printf("here2");                                                
          while(!feof(fp) && fgets(buffer, sizeof(buffer), fp)) {         
             sscanf(buffer, "Hardware       : %s", hardware);             
             if (strcmp(hardware, "BCM2708") == 0 ||                      
                 strcmp(hardware, "BCM2709") == 0 ||                      
                 strcmp(hardware, "BCM2711") == 0 ||                      
                 strcmp(hardware, "BCM2835") == 0 ||                      
                 strcmp(hardware, "BCM2836") == 0 ||                      
                 strcmp(hardware, "BCM2837") == 0 ) {                     
                found = 1;                                                
                printf("Revision       : %s", revision);                  
             }                                                            
             sscanf(buffer, "Revision       : %s", revision);             
          }                                                               
       }     
    
     
  • Ben Croston

    Ben Croston - 2021-03-01
    • status: New --> Accepted
     
  • Ben Croston

    Ben Croston - 2021-03-01

    Fixed i n 0.7.1a4

     
  • Ben Croston

    Ben Croston - 2022-02-06
    • status: Accepted --> Done
     
  • Ben Croston

    Ben Croston - 2022-02-06

    Fixed in 0.7.1

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.