This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

using linux gpio functions for AM335x beaglebone



Just getting started with the BeagleBone and trying to do a simple GPIO example without using the user space methods. Perhaps I am missing something obvious but when I compile the following on the beaglebone:

#include <stdio.h>
#include <linux/gpio.h>

int main()
{
        int err = 0;
        err = gpio_request(113, "testGPIO"); 
        printf("Hello C world!\n");
        return 0;
}

I get this:


xuser@beaglebone:~/testCprog$ gcc -o gpiotest hello.c hello.c:2:24: fatal error: linux/gpio.h: No such file or directory compilation terminated.

I realize that the program is incomplete. I am just calling a function described in the gpio.txt file from the linux documentation but, in order to do that, I need to know where the correct include files are.

Is there something that I am missing? Where is the file located?

Sorry for the newbiness of my question...

  • The file "linux/gpio.h" is included by kernel code or drivers. You will probably have to build the kernel. Your code will have to either be part of the kernel code, eg in the board file. Or it can be in a driver.

  • AFAIK GPIO functionality in user space is exposed only via sysfs. Correct me, if I'm wrong. Take a look at this library, that would simplify GPIO programming from user space.

  • rfc2217 said:

    AFAIK GPIO functionality in user space is exposed only via sysfs. Correct me, if I'm wrong. Take a look at this library, that would simplify GPIO programming from user space.

    I took a look at the library you suggested. I understand this method using the user space (/sys/class/gpio) but I am interested in alternate methods that can provide higher speed toggling.

    Do you have any references or examples using methods other than user space?

  • Norman Wong said:

    The file "linux/gpio.h" is included by kernel code or drivers. You will probably have to build the kernel. Your code will have to either be part of the kernel code, eg in the board file. Or it can be in a driver.

    Can you refer me to an example perhaps pointing me to the location of the files that I would have to modify/add?

    Thanks.

  • My background is with the OMAP-L chips. Not familiar with the AM335x BeagleBone. You need to first need find the kernel source. You should be able find the missing header files. You might be able get single files at the TI GIT, www.arago-project.org. Unfortunately, the files are not sufficient to build a kernel code. You will need to build the kernel itself. Even if you use a Loadable Kernel Module (LKM), you will need a directory with a built kernel to link against. Building a LKM is the same as writing a linux driver. There are a lot references on the web for driver code.

    All this is not a trivial task. Maybe try the TI Wiki for info on how to start, processors.wiki.ti.com

    Unless speed is an issue, I'd suggest sticking with the user space sysfs interface.