LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer
User Name
Password
Linux - Embedded & Single-board computer This forum is for the discussion of Linux on both embedded devices and single-board computers (such as the Raspberry Pi, BeagleBoard and PandaBoard). Discussions involving Arduino, plug computers and other micro-controller like devices are also welcome.

Notices


Reply
  Search this Thread
Old 02-09-2012, 03:00 AM   #1
sharan013
LQ Newbie
 
Registered: Feb 2012
Posts: 8

Rep: Reputation: Disabled
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
 
Old 02-09-2012, 10:18 PM   #2
jhwilliams
Senior Member
 
Registered: Apr 2007
Location: Portland, OR
Distribution: Debian, Android, LFS
Posts: 1,168

Rep: Reputation: 211Reputation: 211Reputation: 211
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.

Best,
HTH,
Jameson
 
Old 02-09-2012, 11:27 PM   #3
sharan013
LQ Newbie
 
Registered: Feb 2012
Posts: 8

Original Poster
Rep: Reputation: Disabled
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

Thanks,
Sharan
 
Old 02-10-2012, 02:06 AM   #4
jhwilliams
Senior Member
 
Registered: Apr 2007
Location: Portland, OR
Distribution: Debian, Android, LFS
Posts: 1,168

Rep: Reputation: 211Reputation: 211Reputation: 211
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:

Code:
#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;
    }
    
    gpio_free(GPIO_VAL);
    return 0;
}
module_init(gpiotest_init);

MODULE_LICENSE("GPL");
with this Makefile:
Code:
obj-m := gpio_test.o
KDIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
default:
	$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
Code:
make
sudo insmod gpio_test.ko
dmesg
 
Old 02-13-2012, 11:25 PM   #5
sharan013
LQ Newbie
 
Registered: Feb 2012
Posts: 8

Original Poster
Rep: Reputation: Disabled
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,
Sharan
 
Old 02-22-2012, 11:08 AM   #6
sharan013
LQ Newbie
 
Registered: Feb 2012
Posts: 8

Original Poster
Rep: Reputation: Disabled
Sir,
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
sys/class/net/ethx/type What is it? tank junior Linux - Newbie 1 05-03-2011 08:23 PM
how to export a class in a shared library DEF. Programming 7 10-04-2009 02:13 PM
/sys/class/hwmon Question Aztral Linux - General 1 08-11-2009 02:00 PM
Problem with reading/writing GPIO on video card with bttv compatible chip boky Linux - Hardware 0 10-13-2005 05:08 AM
how to export a class(g++) onnyloh Programming 4 07-07-2004 06:30 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration