how can i build sam9l9260 +led blinking

hello friends,

i will have to build led blinking program on sam9 board through 40 pin connector .I have done simple helloworld program on the board using arm-unknown-linux-gnu-gcc compiler.for creating led program how i can configure header files in compiler and what is the pattern to write input output ports program.

I found this post looking for an answer to pretty much the same question, and I don’t mean to hijack your thread but I think I can help ask the question we both want answered.

I am assuming you want to compile a program that will run on the Linux OS.

I am also searching for methods of using the IO pins on this board, so far I have found that Linux has device drivers for the IO of this board built-in, and you can find them at /sys/class/gpio/…

I have been able to control the STAT led on the board by injecting a brightness level into the file /sys/class/leds/led_stat/brightness.

I dug through the test_butt archive that comes with this board to see how IO was implemented but this test project is to run on the board without an underlying OS.

I find header and include files, for example AT91SAM9260.h, so I assume that I could compile a program using these header files and directly access the IO pins even if my program is to run under the Linux OS(?) or use the Linux device drivers for GPIO.

Either way I cannot seem to find any reference material telling what variables and methods are declared in the header files, and how to use or interface with them, nor can I find a reference to what Linux device driver goes with each GPIO pin.

In the /sys/class/gpio directory there are three other directories gpiochip32, gpiochip64, and gpiochip96.

In these directories are files base, label, ngpio, uevent and directory subsystem, cat label tells me that gpiochip32 is for A, but which set of IO pins on the board does it go to?

Hopefully my more lengthy question is in line with the OP’s question and both of us can benefit from answers received.

Thanks in advance.

I have spent many hours researching this topic and am finding that it is much harder than I expected to get help with micro-controller questions if you are a newbie like myself.

I have found some reference to mmap() functions but that seems like a function best left alone unless you know what you are doing.

I have come to the conclusion that for rookies like myself, and I am guessing the OP, that using the /sys/class/gpio drivers are the safe way to go, although I am not sure if timing will be a problem, I want to use the pins to communicate with sensors via 1-wire or 2-wire protocol.

Anyway to the OP, if you are using the Linux OS on this board you should have /sys/class/gpio/ directory with:

  • export (file)

  • unexport (file)

  • gpiochip32 (directory)

  • gpiochip64 (directory)

  • gpiochip96 (directory)

In each respective directory will be a few files, the “label” file should give a description of the port, on mine for example they are:

/gpiochip32/label = A

/gpiochip64/label = B

/gpiochip96/label = C

I look at the data sheet for the board and find that the 40-pin header (EXT) is labeled with mostly PB#'s, so I choose a “B” port pin to work with.

The base for “B” is 64, ie. gpiochip64, this will also see this via

cat /sys/class/gpio/gpiochip64/base

I want to manipulate PB0 and PB1, pins 5 and 7 on the 40-pin header so I “export” them from the command line like so:

– PB0: 64 + 0 = 64

echo 64 > /sys/class/gpio/export

– PB1: 64 + 1 = 65

echo 65 > /sys/class/gpio/export

These commands will create directories “gpio64” and “gpio65” under /sys/class/gpio.

In each of these new folders will be four files, the files we are interested in are “direction” and “value”. You can see the current values via the cat command from the command line, you can set them via echo commands.

cd /sys/class/gpio/gpio64   (make sure you are in the correct directory)
cat direction      (output will be "in" or "out")
cat value          (output will be "1" or "0")
echo "out" > direction   (set the direction of the pin to out)
echo 1 > value      (set the value to "1" or high)
echo 0 > value      (set the value to "0" or low)

To use this in a C program you write yourself and compile to run on Linux OS of this board there is some example code at the following link that I used and seemed to work when I tested it on my board:

http://xilinx.wikidot.com/gpio-user-space-app

Just make sure you change the “240” in the code to match your gpio, for my board I changed the “240” to “64” for PB0(pin 5 of 40-pin header).

Hope this helps.