Using GPIO ?


I know that there are many topics on this forum, but no one give a real

On internet, there are many topics but also few answers.

So I don't wait the answer that everyone wait.

But I wouldlike to know what pins can we use as GPIO on the GPIO connector
- Are all the pin free ? 
- What pins do what function (TOR, ADC ...) ?

The second thing is : 
Is it possible to adapt the mini2440_leds driver to use TOR output ?
And what are the risks if i try to modify this driver ?

The last thing is :
Is it possible to compile a new driver and add it to my Mini2440 without
recompile the whole Kernel ?
I think yes, it would be very stupid if not, but how ?

Thanks you very much.

Well if you look at the schematic:

CON5 consists mainly of Data and Address bus which you cant use due to the
processor using those line to access the program form external memory. It
also has a few EXTINT lines which is shared by other connector too. The
only pins I was able to use on CON5 was the nXDxxxx and nGCSx pins unless
you want to hook some memory mapped device onto the Address and Data bus.

For CON4 and CAMERA I managed to use almost all the pins. On CON4 there was
about 5 pins which I didn't use. That does not mean you can't use them,
maybe they were just not suited for my application. You will have to trace
all the pins to the CPU and then check in the CPU datasheet for the IO
capabilities of that pin. On the CAMERA connector there was about 4 pins
which I didn't use.

What is TOR?

It is possible to load modules at run-time. Whether the kernel needs to
know that at compile time and how you go about doing that I'm not sure. I
always compile my drivers into the kernel. Kernel compilation is quick :).
Less than 30minutes.

Ok for the pin.

For the driver, if I want to debug my codean I have to compile the Kernel
each time I modify  the code, it will be very long !!

Juergen Beisert
You do not have to recompile the whole kernel if you modify only one file.
Just run "make" again and Kbuild will find the modified file and only
re-compiles this one.

It seems like I misunderstood you. The kernel creates an abstract layer, a
software layer which is a driver that at most times encapsulates all the
possible functionality of defined hardware. May that be GPIO pins or a
peripheral such as a uart. Once the driver for a piece of hardware has been
included into the kernel there is no need to further edit the driver. The
driver now provides a driver API that supports all the possible
functionality of that hardware. For instance if it was an IO, that driver
provides an interface to set the IO direction (in/out) and it provides an
interface to either read the state of the IO or set the state of the IO. It
is now up to you to write a piece of software that interacts with the
driver to control or manipulate the hardware. No need to re-compile the
kernel, only compile your software that interacts with the kernel driver.
Your code could compile within a few milli seconds depending on its size
and complexity. You can use any common/supported programming langauge and
tools to develop software to interact with the drivers. I use gcc, g++ and
Qt to develop software on top of the kernel.

@bluscape Ok I agree with you but the original system send by Friendlyarm
doesn't have a gpio driver ??? Or I didn't see it. If you have info on how
use the driver you speak about ? What is his name? Where is it ...

After that I think that you cannot do what you want with this kind of
driver. You cannot control the time accurately for example.

@Juergen Beisert Ok but so I need to compile it one time and then I just
recompile the driver.

Lets take the LEDs as an example.

If you use a Mini2440 kernel is should be part of it by default. For
example if you use this kernel it will be part of the kernel:

You can enable or disable the LED driver in the menuconfig (make menuconfig
- Read here for more info: OR, and it will be enabled by default. Or if you
don't want to re-compile the kernel you can download a pre-compiled kernel
image which will also have the driver enabled (you might have to convert
the image to a uimage, depending on the bootloader you are using):

You can now access the driver as s file/register using standard file read
and write operations. See the example programs:

When the kernel initializes the driver it will create a set of
files/registers that provides access to the different functionality of the
respective hardware. All you have to do is read and write to these
files/registers to control or manipulate the respective hardware.

This is how you can control a GPIO pin:

FILE *StatusLED;  
// GPIO Initialization
// Get a handle to the export file/register
StatusLED = fopen("/sys/class/gpio/export", "w");  
// Export gpio204, GPG12
fputs("204", StatusLED);
// Get a handle to the direction file/register
StatusLED = fopen("/sys/class/gpio/gpio204/direction", "w");  
// Set the GPIO direction
fputs("out", StatusLED);

// GPIO Control
// Get a handle to the value file/register
StatusLED = fopen("/sys/class/gpio/gpio204/value", "w");
// Swith the LED on
fputs("1", StatusLED);
// Swith the LED off
fputs("0", StatusLED);

First thanks for your help.

Ok for the kernel and thanks for the link.

I will try to do anything with the code you gave me.

But the Friendlyarm's exmaple don't use this way, there is a driver for
each example (dev/buttons, dev/leds...).

I try your code and I give you a feed back.

So, I tried your code, but I get that :

[root@FriendlyARM /]# echo 32 > /sys/class/gpio/export
-/bin/sh: can't create /sys/class/gpio/export: nonexistent directory

[root@FriendlyARM /]# ls /sys/class
bdi           input         mtd           scsi_generic  video4linux
block         leds          net           scsi_host     vtconsole
firmware      mem           rtc           sound
graphics      misc          scsi_device   tty
i2c-dev       mmc_host      scsi_disk     vc

So I think that the GPIO is not enable on my Kernel ?

Yet a question,

Is the GPIO driver enabled by default in this binaries :


The friendlyarm kernel needs to have sysfs enabled in the kernel.By default
it does not. You will need to download the friendly arm kernel source,
enable the sysfs and build the kernel.


Ok, the only thing I have to enable is sysfs. Nothing else about gpio ? 

When I build the Kernel, do I need to configure it or can I use the default
configuration because I have a W35 screen and I red any issues about that.


i need to interface ping sensor and mini2440 using gpio pins.can anyone
help me with the c code?