GPIO XS not loaded

58 views
Skip to first unread message

Pilgrim Dust

unread,
Feb 24, 2024, 11:34:35 PM2/24/24
to HiPi Perl
Hi, folks!

I'm trying to control GPIO using HiPi module.
Here's my code :

  use strict;
  use warnings;
  use HiPi::GPIO;

  my $gpio = HiPi::GPIO->new();
  my $level = $gpio->get_pin_level( 2 );
  print "level = $level";


And here's the output :

Undefined subroutine &HiPi::GPIO::xs_gpio_read called at /usr/local/lib/aarch64-linux-gnu/perl/5.36.0/HiPi/GPIO.pm line 71.

Here's the board info :

--------------------------------------------------
Raspberry Pi Board Info
--------------------------------------------------
Model Name       : Raspberry Pi 4 Model B Rev 1.5
Released         : Q1 2022
Manufacturer     : Sony UK
Memory           : 8192
Processor        : BCM2711
Hardware         : BCM2709
Description      : Type 3 40 pin GPIO header
Revision         : d03115
Serial Number    : 10000000bc1d47af
Short Serial No  : bc1d47af
GPIO Header Type : 3
Revision Number  : 5
Device Tree      : Yes
Is Raspberry     : No
Is Raspberry 2   : No
Is Raspberry 3   : No
Is Raspberry 4   : Yes
Is Raspberry 5   : No
Alt Function Map : Version 2
ARM Core         : Cortex-A72
Number of Cores  : 4
Architecture     : Width 64 bit
OS arch support  : armhf, arm64

Since it says " Is Raspberry : No " (despite " Is Raspberry 4 : Yes "), the GPIO library don't get loaded (HiPi/GPIO.pm, lines 26-32) :

if ( HiPi::is_raspberry_pi() ) {
    if ( HiPi::RaspberryPi::has_rp1() ) {
        XSLoader::load('HiPi::GPIO::RP1', $VERSION);
    } else {
        XSLoader::load('HiPi::GPIO', $VERSION);
    }
}

The variable $HiPi::RaspberryPi::israspberry gets undefined here (line 519 or HiPi/RaspberryPi.pm) :

    $israspberry = $_cpuinfostash{Hardware} && $_cpuinfostash{Hardware} =~ /^BCM(27|28)/;

because $_cpuinfostash{Hardware} is undefined :

$ cat /proc/cpuinfo
processor       : 0
BogoMIPS        : 108.00
Features        : fp asimd evtstrm crc32 cpuid
CPU implementer : 0x41
CPU architecture: 8
CPU variant     : 0x0
CPU part        : 0xd08
CPU revision    : 3

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

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

processor       : 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

Revision        : d03115
Serial          : 10000000bc1d47af
Model           : Raspberry Pi 4 Model B Rev 1.5

I'm not quite sure what exactly is_raspberry means - does it mean the device type is Raspberry Pi, or it means that device is the first generation Rapsberry Pi.

If I edit the module code to forcefully set $israspberry to true, then the error about undefined subroutine disappears. (Though, I didn't test yet if GPIO actually starts working). 

So I wonder what's the best way to correct the module code?

Here's my system data :

$ uname -a
Linux ts 6.1.0-rpi8-rpi-v8 #1 SMP PREEMPT Debian 1:6.1.73-1+rpt1 (2024-01-25) aarch64 GNU/Linux

$ perl -v
This is perl 5, version 36, subversion 0 (v5.36.0) built for aarch64-linux-gnu-thread-multi
(with 53 registered patches, see perl -V for more detail)

$ perl -mHiPi -e 'print $HiPi::VERSION . "\n";'
0.90

$ perl -mHiPi::GPIO -e 'print $HiPi::GPIO::VERSION . "\n";'
0.90

The module was installed with apt :

$ sudo apt install libhipi-perl

Thanks in advance.

Mark Dootson

unread,
Feb 24, 2024, 11:45:34 PM2/24/24
to HiPi Perl
Hi,

There's a change to /proc/cpuinfo in the latest Raspberry Pi OS that required a fix to HiPi.

You can install the fixed 64 bit package with:

sudo apt update
wget https://hipi.znix.com/download/libhipi-perl_0.91-2.bookworm_arm64.deb
sudo dpkg --install libhipi-perl_0.91-2.bookworm_arm64.deb
sudo apt -y -f install


Regards

Mark

Aendrew

unread,
Mar 25, 2024, 3:33:47 PM3/25/24
to HiPi Perl
Hey there,

I installed the newest version but still receive an error that looks much like similar to that error above.

sudo apt update
wget https://hipi.znix.com/download/libhipi-perl_0.91-2.bookworm_armhf.deb
sudo dpkg --install
libhipi-perl_0.91-2.bookworm_armhf.deb

sudo apt -y -f install

After that i downloaded the source (https://hipi.znix.com/download/HiPi-0.91.tar.gz)
From the source i executed the sample "mfrc522/module_info.pl" and receive "Undefined subroutine &HiPi::GPIO::xs_gpio_get_mode called".

In my case the pi is an Raspberry Pi Zero W Rev 1.1.

Any ideas?


Mark Dootson

unread,
Mar 28, 2024, 4:18:59 PM3/28/24
to HiPi Perl
Apologies. There are issues in Version 0.91 recognising Raspberry Pi models A, B, A Plus, B Plus, Zero and Zero W.
Fixed in version 0.92.

wget https://hipi.znix.com/download/libhipi-perl_0.92-1.bookworm_armhf.deb
Reply all
Reply to author
Forward
0 new messages