GPIO APIs

Hi everybody. I am hoping somebody else has had this problem and has since corrected it. I flashed the Dragonboard with the latest release of Debian (#110 image) and then proceeded to install the GPIO access libraries. I had first installed the Libsoc, MRAA, and UPM from the latest git sources, but there have been some changes in the libraries that have caused some inconsistencies with the examples. To simplify things, I reflashed the board with the #110 image and then installed Libsoc, MRAA, and UPM from the repos (i…e using apt-get). Since there is no 96BoardsGPIO library in the debian repo, I installed that from the GitHub master branch. After following the install guide, I get the following output when performing a logon to the DragonBoard:

-bash: export:
[board]’: not a valid identifier
-bash: export: [GPIO]': not a valid identifier -bash: export: GPIO-A=36’: not a valid identifier
-bash: export: GPIO-B=12': not a valid identifier -bash: export: GPIO-C=13’: not a valid identifier
-bash: export: GPIO-D=69': not a valid identifier -bash: export: GPIO-E=115’: not a valid identifier
-bash: export: GPIO-F=4': not a valid identifier -bash: export: GPIO-G=24’: not a valid identifier
-bash: export: GPIO-H=25': not a valid identifier -bash: export: GPIO-I=35’: not a valid identifier
-bash: export: GPIO-J=34': not a valid identifier -bash: export: GPIO-K=28’: not a valid identifier
-bash: export: GPIO-L=33': not a valid identifier -bash: export: GPIO-23=36’: not a valid identifier
-bash: export: GPIO-24=12': not a valid identifier -bash: export: GPIO-25=13’: not a valid identifier
-bash: export: GPIO-26=69': not a valid identifier -bash: export: GPIO-27=115’: not a valid identifier
-bash: export: GPIO-28=4': not a valid identifier -bash: export: GPIO-29=24’: not a valid identifier
-bash: export: GPIO-30=25': not a valid identifier -bash: export: GPIO-31=35’: not a valid identifier
-bash: export: GPIO-32=34': not a valid identifier -bash: export: GPIO-33=28’: not a valid identifier
-bash: export: `GPIO-34=33’: not a valid identifier

As a result, the GPIO shell commands do not work when following the “through the shell” example. When performing a command line … echo $GPIO_A > export … the system responds with “bash: echo: write error: Invalid argument”. This happens when using $GPIO_A or $GPIO-A. It also happens when using the number rather than the letter.

However, the programmatic examples work just fine. I created a small demo similar Blink.c using a switch and LED and was able to access GPIO-A and GPIO-C using the letter designations… so it works. I am just not sure how to get rid if the above error messages. Any advice?

Hi @cryptik,

The Debian release already include the libsoc, libmraa and libupm package so you do not have to download
the latest git sources which might have some changes.

Would you try bellow to install the libraries?


$ sudo apt-get install libsoc-dev
$ sudo apt-get install libmraa-dev libupm-dev

Hi @Akira, thanks for the reply. That’s what I did… I refreshed the board and then installed libsoc-dev, libmraa-dev, and libupm-dev from the Debian release. The problem appears to be caused by 96BoardGPIO. This is not available in the Debian release and has to be installed via source. There appears to be some mismatch in the way 96BoardGPIO expects that libsoc labels the pins (i.e. GPIO-A=36 appears to not be valid).

Hi @cryptik,

The error message looks like it is from libsoc by reading the source.

I am in the middle of downloading the Debian (#110 image) to try installing libsoc and build the 96BoardGPIO.
The download indicator shows I need to wait about an hour.

I will get back to you when I am able to try it at my place.

Hi @cryptik,

I tried to reproduce your error message and the following was the procedure I tried.


$ ntpdate pool.ntp.org
(this is to confirm network connection and set the correct time for building the source later)
$ sudo apt-get update
$ sudo apt-get dist-upgrade -u
$ sudo apt-get install git build-essential autoconf automake libtool swig3.0 python-dev nodejs-dev cmake pkg-config libpcre3-dev
$ sudo apt-get install libmraa-dev libupm-dev
(I do not think this was necessary to reproduce the error)
$ sudo apt-get install libsoc-dev
$ sudo apt-get clean
$ git clone https://github.com/96boards/96BoardsGPIO.git
$ cd 96BoardsGPIO/
$ ./autogen.sh
$ ./configure
$ make && sudo make install
$ sudo ldconfig /usr/local/lib
$ sudo reboot

And this is the only error message I had on next reboot.

ERROR: Unable to find libsoc_gpio.conf

So it seem to be your error is different.

Let me investigate next week.

Hi @Akira. Thanks for the detailed reply. This is the same error message I got after performing the steps you outline. I forgot to mention I did one other step, I copied the libsoc.conf file to libsoc_gpio.conf and thats when the errors started happening. The GPIO library will work… but not the shell script variables using either method. See the following for more information.

Cheers,
Ken

Hi @cryptik,

I read your comment at "Pin X is Y or libsoc patches ".
Thank you for pointing out the correct way to use 96BoardsGPIO with libsoc on new version.

I managed to make it work.
I added the file


sudo vi /etc/libsoc_gpio.conf

with the contents bellow.


#[board]
model = Qualcomm Technologies, Inc. APQ 8016 SBC

#[GPIO]
# dragonboard 410c pin layout
#<Pin Name> <SoC Num>
GPIO_A = 36
GPIO_B = 12
GPIO_C = 13
GPIO_D = 69
GPIO_E = 115
GPIO_F = 4
GPIO_G = 24
GPIO_H = 25
GPIO_I = 35
GPIO_J = 34
GPIO_K = 28
GPIO_L = 33

# include mappings by pin number on board
GPIO_23 = 36
GPIO_24 = 12
GPIO_25 = 13
GPIO_26 = 69
GPIO_27 = 115
GPIO_28 = 4
GPIO_29 = 24
GPIO_30 = 25
GPIO_31 = 35
GPIO_32 = 34
GPIO_33 = 28
GPIO_34 = 33

and rebooted.

And tried both C program and bash for using 96BoardsGPIO.

C:


#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#include <gpio.h>

#define LED "GPIO_E"

int main()
{
    int led_state = HIGH;

    if(gpio_open(gpio_id(LED), "out")){
        goto fail;
    }

    while(1){
        digitalWrite(gpio_id(LED), led_state);
        led_state=(led_state==HIGH)?LOW:HIGH;
        usleep(500000);
    }

fail:
    digitalWrite(gpio_id(LED), LOW);
    return EXIT_SUCCESS;
}

Build:


gcc E-ledGPIO.c -o E-ledGPIO -Wall -lsoc -l96BoardsGPIO

Run:


sudo ./E-ledGPIO

bash:


#!/bin/bash -u

GPIO_PORT=$GPIO_E

GPIO_DIR=/sys/class/gpio
INT_SHORT=0.1
INT_LONG=1

# initialization
cd $GPIO_DIR
echo $GPIO_PORT > export
cd gpio$GPIO_PORT
echo out > direction

# flash LED
while true; do
   echo 0 > value
   sleep $INT_SHORT
   echo 1 > value
   sleep $INT_SHORT
   echo 0 > value
   sleep $INT_SHORT
   echo 1 > value
   sleep $INT_SHORT
   echo 0 > value
   sleep $INT_LONG
done

The sample codes I referred are uploaded here.
https://github.com/dmandala/library_test.git

For the dragonboard 410c, the values that we see in examples should be changed by adding an offet of 390.
To get the correct value, you can check with midnight commander (sudo apt install mc).
Midnight commander is a very convenient file manager on the console. It works fine on the Dragonboard.
On the command line:
cd /sys/class/gpio
ls
cd gpiochip390
ls
cat ngpio
It gives 122, the other 2 chips give 4.
cat base
It gives 390

So all the old docs should be converted:
user led 1 | 21 | 411
user led 2 | 120 | 510
user led 3 | 1 | 1 + 382 OR 386 (UNTESTED)
user led 4 | 2 | 2 + 382 OR 386 (UNTESTED)

D410c | Mezz | GPIO | OLD | NEW
------±-----±-------±----±----
J8.23 | G1.1 | GPIO A | 36 | 426
J8.24 | G1.2 | GPIO B | 12 | 402
J8.25 | (NA) | GPIO C | 13 | 403
J8.26 | (NA) | GPIO D | 69 | 459
J8.27 | G2.1 | GPIO E | 115 | 505
J8.28 | G2.2 | GPIO F | 4 | 4 + 382 OR 386 (UNTESTED)
J8.29 | G3.1 | GPIO G | 24 | 414
J8.30 | G3.2 | GPIO H | 25 | 415
J8.31 | G4.1 | GPIO I | 35 | 425
J8.32 | G4.2 | GPIO J | 34 | 424
J8.33 | G5.1 | GPIO K | 28 | 418
J8.34 | G5.2 | GPIO L | 33 | 423