Close

detect_GPIO_BASE.sh is broken again...

A project log for C GPIO library for Raspberry Pi

Lightweight GPL'd #include for your C programs

yann-guidon-ygdesYann Guidon / YGDES 01/07/2021 at 02:380 Comments

On a Pi 3 with the 2016 script, the failure is even more burning

Why can't the RPi guys keep a consistent system or at least preserve backwards compatibility ?

A new script is required, considering the list I recently found:

#define PI_01_REG_BASE  0x20000000  // Pi Zero or 1
#define PI_23_REG_BASE  0x3F000000  // Pi 2 or 3
#define PI_4_REG_BASE   0xFE000000  // Pi 4

And don't forget that this is the base of the peripherals block, not the start address of the GPIO block. In these cases, it's:

#define PI_01_REG_BASE  0x20200000  // Pi Zero or 1
#define PI_23_REG_BASE  0x3F200000  // Pi 2 or 3
#define PI_4_REG_BASE   0xFE200000  // Pi 4

thus:

$ grep gpio /proc/iomem | grep -i -E '20200000|3F200000|FE200000' 
00000000-00000000 : 3f200000.gpio gpio@7e200000

It's getting tiring to have to rewrite stuff all the time...




The latest script is :
#!/bin/bash
# version 20210107

export GPIO_BASE=""
GPIO_LINE=$(grep gpio /proc/iomem) && {
  echo "$GPIO_LINE" | grep -i 20200000 && export GPIO_BASE=0x20200000  # Pi Z or 1
  echo "$GPIO_LINE" | grep -i 3F200000 && export GPIO_BASE=0x3F200000  # Pi 2, 3
  echo "$GPIO_LINE" | grep -i FE200000 && export GPIO_BASE=0xFE200000  # Pi4
}
echo GPIO_BASE=$GPIO_BASE

Now how long is it going to work ?

Discussions