GPIO APIs


#1

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?


#2

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


#3

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).


#4

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.


#5

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.


#6

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


#7

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.