Firefly Open Source Community

   Login   |   Register   |
New_Topic
Print Previous Topic Next Topic

how to use GPIO ?

17

Credits

0

Prestige

0

Contribution

new registration

Rank: 1

Credits
17

how to use GPIO ?

Posted at 1/14/2016 19:19:04      View:9635 | Replies:3        Print      Only Author   [Copy Link] 1#
Hello,

I'm new on this forum so I hope I don't ask a question which has been answered yet.

I have a fireflyRK3288 and I want to send a signal with one free GPIO (not the ones used by the system, like leds which I perfectly control now). The problem is I don't have a clue on how to do this. I'm a programmer and don't really understand the electronic documentation given in the wiki.

From what I've understood, I assume that I can use A7 and A6 GPIO on J6 and B5, A3, A7 and B1 on J10. These names are the ones written on the card itself, how can I discover the ones used by the kernel I must use in my program (in C++) and then how do I use them ?

If anyone has an answer, at least on how to start using these GPIO, it would be great.

Thanks.
Reply

Use props Report

403

Credits

10

Prestige

12

Contribution

intermediate

Rank: 3Rank: 3

Credits
403
Posted at 1/20/2016 11:15:49        Only Author  2#
Last edited by busybee In 1/20/2016 11:34 Editor

Maybe the link below is useful for you:
https://developer.ridgerun.com/wiki/index.php/Gpio-int-test.c
GPIO sysfs interace document:
kernel/Documentation/gpio.txt

Reply

Use props Report

17

Credits

0

Prestige

0

Contribution

new registration

Rank: 1

Credits
17
Posted at 1/21/2016 22:28:31        Only Author  3#
Thanks for your reply busybee. This page seems helpful to create code fore GPIO. I will try a few thing from what I understand and I'll post the results here.
Reply

Use props Report

17

Credits

0

Prestige

0

Contribution

new registration

Rank: 1

Credits
17
Posted at 2/8/2016 19:22:36        Only Author  4#
Hello everybody,

I've tried to understand how to use a free GPIO with the firefly and I've finally succeded. It took me quite a long time because it was not my only work and because documentation is very scarce on the subject.

Here is how I did it. First, I must say it is certainly not the best way to do it. I guess the official documentation is the better way to handle things, the only problem is I've never found the files they indicate. For instance, files like pinctrl-rockchip.c do not exist on my ubuntu for firefly and can't be changed. I haven't found  firefly-rk3288.dts either.  So, the way to use GPIO in the official documentation simply doesn't work (or it is very badly explained).

I found another solution. GPIO ports in linux are all in the /sys/class/gpio/ directory. Here you can find gpiochipX directories. X is a number and goes from 0 to 288. gpiochip directories are controllers for all the gpio firefly uses. What does it mean ? If you go in a gpiochip directory, you will see label. If you do cat label, it will give you the name of the bank of gpio for the firefly. For instance gpiochip0 has a label gpio0, gpiochip32 has a label gpio1, gpiochip64 has a label gpio2, etc. You can see that gpiochip directories jump from a number to the next number + 32. That is why we have 0, 32, 64, 96, 128, 160, 192, 224, 256 and 288 after gpiochip. There is a second file named in each of these directories called ngpio which gives the number of gpio controlled by this particular gpiochip and each time you have 32. so the first number of gpiochip correspond to the 9 banks of gpio described in the documentation (from gpio0 to gpio8) and the last one (gpiochip288) correspond to a gpio15 (?).

Now, how to use a particular gpio. Simple, in the gpio directory, just type echo X > export and then a directory gpioX will appear. In this, you will have all the method needed to use this particular gpio. How to set the right number ? You need to know on which bank is this gpio port and to understand the position of it in this bank.

I you read the page about gpio for firefly, they tell you some gpio ports are free to use. They give you an image of the pins you can find on the board. For example, for the j10 you have P7_A3 which is free  (you can take P0_B5 or another one, just look). On the physical board you can spot them easily (P7_A3 is written A3, P0_B5 is written B5). So P7_A3 means it the A3 position of the gpio7. If we take gpiochip, gpio7 is controlled by gpiochip224 and A3 is the 4th position (it starts at A0). It means you must type echo 227 > export in the gpio directory to gain access to controls of this particular gpio.

In the gpio227 directory, you must first set the direction to out (echo out > direction) and then change the value to 1 (echo 1 > value) and then the electricity flows ! If you want to stop it, type echo 0 > value (of course).

To test it, I used a small led with a 100 ohm resistor and it worked fine but be careful with the led and resistor characteristics. I know that this gpio port of the firefly has a 3.3 volts current but I just guessed the intensity was 0.02 ampere (like the raspberry) but I am not sure at all. Be careful on this point. You can find many tutorials on internet about making a simple electronic circuit with one led, they can be useful.

For the moment, in my program (C++) I use a command like system("echo 227 > gpio") because I use linux and it works just fine (my program is not sophisticated for the gpio, I just need to give one pulse of electricity for a few ms). So I won't go further but it would be nice if someone knows how to do it more properly and give a clear explanation.
Reply

Use props Report

You need to log in before you can reply Login | Register

This forum Credits Rules

Quick Reply Back to top Back to list