-   Linux - Embedded & Single-board computer (
-   -   writing to /sys/class/gpio/export (

sharan013 02-09-2012 04:00 AM

writing to /sys/class/gpio/export
I am working on a project which needs me to configure the gpio pins and add sensors to atom board. The kernel has configured the gpio ... CONFIG_GPIO_SYSFS=y is one of the kernel options.

I am using fedora version 2.6.29-10
But i am not able to write to export file in gpio folder using

GPIO=22 // to add pin 22 to userspace
echo $GPIO > /sys/class/gpio/export

I get the error
bash: echo: write error: Invalid argument

I also tried the same with sudo and sh -c but no use ,unless i can expose these pins to userspace i cant write any code.What am i doing wrong?
Is the problem with the kernel version or some other kernel options needs to set??

Thanks in advance

jhwilliams 02-09-2012 11:18 PM

Hi Sharan,

This error is not present in the Android x86 BSP for Atom. The command populates the gpio entry as documented.

My guess is that something is amiss with that particular Fedora kernel. Have you tried any other traditional Linux distros? What's your platform, specifically?

My suggestion would be to just develop the GPIO code as a kernel module. May I ask why you're wanting to do it in user space, currently? I mean for one, GPIOs are good for interrupts, and you won't have those in user space.


sharan013 02-10-2012 12:27 AM

I am working on intel atom Processor E6 series .And I cant boot other os into it other than what was provided by our sponsorer(i am in a college). We are still working on how to load other os, that's because its not like other system with a bios and boot loader(like grub), efi is hard coded into eeprom and I am trying to modify it .

I also tried it on ubuntu 2.6.32-38 , its the same problem .

I have to add sensors(for a portable medical kit) to the board provided.I want to use GPIO as other way to add sensors ex: through USB is power consuming,I cant build a portable device which is power hungry ... :) . Hence I am also constrained to using interrupts and making the processor use efficient. But I can as of now i can ignore using interrupts and stick to traditional ways of polling if it can solve my problem.

Are you suggesting that I can still write code to access these pins provided it's run as a kernel module?Because all that I have read till now wanted me to expose these pins first in userspace and then start to code.I do have root privilege so I can develop the GPIO code as a kernel module.

Can you please suggest a place where I can find relevant stuff(write kernel module for devices). New to embedded develpoment please bear with me if I have written something silly :)


jhwilliams 02-10-2012 03:06 AM

Hi Sharan,

I wonder if the it's just the userspace interface that's not working, or the gpio stack itself.

Try to build a simple module with this gpio_test.c:


#include <linux/gpio.h>
#include <linux/kernel.h>
#include <linux/module.h>

#define GPIO_VAL 100
#define GPIO_LABEL "gpiotest"

static int __init gpiotest_init(void)
    if (!gpio_is_valid(GPIO_VAL)) {
        printk(KERN_CRIT "gpio_is_valid(%d) is false.\n", GPIO_VAL);
        return -EINVAL;

    if (gpio_request(GPIO_VAL, GPIO_LABEL)) {
        printk(KERN_CRIT "gpio_request(%d, %s) failed.\n",
                        GPIO_VAL, GPIO_LABEL);
        return -EINVAL;
    return 0;


with this Makefile:

obj-m := gpio_test.o
KDIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
        $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules


sudo insmod gpio_test.ko

sharan013 02-14-2012 12:25 AM

Hi sir,

Tried inserting the module using insmod and modprobe but getting errors
[root@localhost inforce]# sudo insmod gpio_test.ko
insmod: error inserting 'gpio_test.ko': -1 Invalid parameters

[root@localhost inforce]# modprobe gpio_test.ko
WARNING: Deprecated config file /etc/modprobe.conf, all config files
belong into /etc/modprobe.d/.
FATAL: Module gpio_test.ko not found.

dmesg had the following as last few lines.
fuse init (API version 7.11)
gpio_request(100, gpiotest) failed.

What am i doing wrong?

Thank you,

sharan013 02-22-2012 12:08 PM

I contacted the people who supplied us the boards,they gave a kernel module which had to complied , now that issue is sorted , thanks for your help.

All times are GMT -5. The time now is 05:18 PM.