OpenWrt Forum Archive

Topic: GPIO kernel access

The content of this topic has been archived on 3 May 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Hi

I am quite new to Linux and Openwrt but I managed to compile a C program and make it work on my WRT54G (v3.1).
Well.. almost work. I wanted to port a program that send binary signal to RTS line of serial port and send this signal through DMZ led (GPIO 7 on my router).

I took inspiration from the SD/MMC source codes and came up with something like

--8<--snip----

static unsigned char mask = 1 << 7;
static volatile unsigned char *gpio_output = ( unsigned char * ) 0xb8000064;

if (atoi(argv[1])==1){
    *gpio_output |= mask;
} else {
    *gpio_output &= ~mask;
}

--8<--snip----

The program compiles but I get a "Bus error" when executed

I tried to fwrite to /proc/diag/led/dmz but I think that the file writing is buffered and my signal gets all messed up.

What am I missing ? I suspect that the gpio_output address is different from a chip to another, may this be the cause of my problem ?

Thanks for your reply. I saw this post [s]but can't get sorted on the definition of the GPIO_DIR_OUT, GPIO_SET and GPIO_CLEAR[/s].

Tried to run only the

open("/dev/gpio/", O_RDWR)

part but it came up with a "Is a directory" error.

edit :
sorted out the constant definitions from this document : http://www.mjmwired.net/kernel/Document … number.txt and the source code of gpioctl.

However, I still can't open /dev/gpio as it is a directory.

I tried opening as well /dev/gpio/out, no error when opening the file anymore but no result when using ioctl(fd, GPIO_SET, gpio_pin);

(Last edited by remy_g on 24 Feb 2012, 09:42)

Maybe your kernel has no gpio support? That is the way I currently use the gpios and it works very well. You also might have to include gpio-dev etc.

I think that you are right. There is probably limited GPIO support for WRT54G as I don't find gpioctl in the list of available packages for my platform (http://downloads.openwrt.org/backfire/1 … /packages/).

I'll try again by compiling an image for brcm47xx.

solved. That was indeed a gpio support issue. Once the image compiled with brcm47xx profile, the open("/dev/gpio/", O_RDWR) solution works. Thanks for your help.

The discussion might have continued from here.