Project

General

Profile

How to add aditional HPS GPIO's

Added by Alexander Block over 9 years ago

Posting on behalf of a customer:

On the MitySom .dts file, you specify some GPIOS like this:

                /* GPIO 56 */
                button@1 {
                        label = "Switch 1";
                        linux,code = <0x101>;
                        gpios = <&gpio1 8 1>;
                        debounce-interval = <100>;
                };
                /* GPIO 55 */
                button@2 {
                        label = "Switch 2";
                        linux,code = <0x102>;
                        gpios = <&gpio1 11 1>;
                        debounce-interval = <100>;
                };
                /* GPIO 54 */
                button@3 {
                        label = "Switch 3";
                        linux,code = <0x103>;
                        gpios = <&gpio1 12 1>;
                        debounce-interval = <100>;

In my new design I want to use GPIO 53, 48, 49, and 50 to drive some LEDs.
How do I add these?


Replies (5)

RE: How to add aditional HPS GPIO's - Added by Alexander Block over 9 years ago

In the case described of wanting to add GPIO's to drive/control an LED (output from the HPS) you do not need to alter the DTS file. The DTS additions were for Switch based GPIO's which are a special case in which their is a Linux driver that handles additional things like switch debouncing. So the process for adding and accessing the additional 4 GPIO's mentioned would be as follows:

1) In your QSys project open the "HPS" peripheral settings from the "System Contents" tab.
2) Go to the "Peripheral Pin Multiplexing" Tab and scroll down to the bottom of the window in Qsys and from there select the *GPIO mode for each 53, 48, 29 and 50. Note that by doing this you may change/disable another HPS feature (i.e. GPIO53 could have been defined as CAN1).
3) "Finish" making your changes and then export the changes to your top level entity.
4) Rebuild your FPGA project
5) Rebuild your pre-loader
6) Replace your pre-loader on your MitySOM-5CSX system and boot into Linux
7) From within Linux you can now work on accessing the new GPIO pins. To do this you need to first determine the pin number in Linux for each GPIO you enabled in QSys. The table below has the Linux GPIO number on the left and the HPS GPIO number on the right.

So in this specific case:
GPIO 53 is #222
GPIO 50 is #219
GPIO 49 is #218
GPIO 48 is #217

Virtual gpio base Linux GPIO Numbers <---> Hardware (HPS) gpio
gpiochip227 227 to 255 <---> GPIO0 to GPIO28
gpiochip198 198 to 226 <---> GPIO29 to GPIO57
gpiochip171 171 to 179 <---> GPIO58 to GPIO66

8) Example using GPIO 49 (#217)

8a) First confirm that your Linux Kernel has the GPIO drivers configured. To do this "cd" to the /sys/class/gpio/ directory. Do a file listing in the directory as shown below nad you should see gpiochip listings 227, 198 and 171:

root@mitysom-5csx:/sys/class/gpio# ls
export  gpiochip171  gpiochip198  gpiochip227  unexport

8b) In Linux you first need to export the GPIO:

root@mitysom-5csx:/sys/class/gpio# echo "217" > /sys/class/gpio/export

Confirm that the GPIO has been exported by doing an 'ls' in the GPIO directory. You should see an entry for "gpio217" added.

root@mitysom-5csx:/sys/class/gpio# ls
export  gpio217  gpiochip171  gpiochip198  gpiochip227  unexport

8c) Now we need to set the direction to be an output (controlling an LED)

echo "out" > /sys/class/gpio/gpio217/direction 

You can confirm the direction by running the 'cat' command and see that it show "out"

root@mitysom-5csx:/sys/class/gpio# cat /sys/class/gpio/gpio217/direction
out

For an "input" change the "out" to "in" when setting the direction

8d) Now we can set the state of the GPIO High/Low

High

echo "1" > /sys/class/gpio/gpio217/value 

Low

echo "0" > /sys/class/gpio/gpio217/value 

RE: How to add aditional HPS GPIO's - Added by Matthew Schubert almost 8 years ago

I'm having some issues setting GPIO37, 40 and 41 from within Linux.

Firstly, in the instructions above, you mention that GPIO29 to GPIO57 are mapped to gpio198 to gpio226, but then go on to say that GPIO49 corresponds to gpio217. Shouldn't that be gpio218?

Secondly, I've followed the instructions, but none of the 3 GPIOs are changing. They seem to be high-Z. I've verified the settings are sticking:

root@mitysom-5csx:/boot# cd /sys/class/gpio/
root@mitysom-5csx:/sys/class/gpio# ls
export       gpio209      gpiochip128  gpiochip160  gpiochip224  gpiochip99
gpio206      gpio210      gpiochip157  gpiochip192  gpiochip72   unexport
root@mitysom-5csx:/sys/class/gpio# cat gpio209/value
1
root@mitysom-5csx:/sys/class/gpio# cat gpio210/value
1
root@mitysom-5csx:/sys/class/gpio# cat gpio206/value
0
root@mitysom-5csx:/sys/class/gpio# cat gpio206/direction
out
root@mitysom-5csx:/sys/class/gpio# cat gpio209/direction
out
root@mitysom-5csx:/sys/class/gpio# cat gpio210/direction
out

I can correctly set the GPIOs in uBoot, so it isn't an FPGA routing issue.

Any ideas?

RE: How to add aditional HPS GPIO's - Added by Matthew Schubert almost 8 years ago

I have noticed that in the DTS the switches are now on the GPIOs that I want to use:
http://support.criticallink.com/gitweb/?p=linux-socfpga.git;a=blob;f=arch/arm/boot/dts/socfpga_mitysom5csx_devkit.dts;hb=refs/heads/socfpga-3.16

I suspect that has something to do with it, so I'm building a device tree without the switches.

RE: How to add aditional HPS GPIO's - Added by Alexander Block almost 8 years ago

Maetthew,

Good catch. Apparently when I did the mapping I started off by one. We have updated the post above to have the correct mapping and also the associated wiki page (https://support.criticallink.com/redmine/projects/mityarm-5cs/wiki/Linux_GPIO_Chip_Mapping).

You are correct that you need to remove the switches from the device tree to use them as GPIO's.

Thanks,
Alex

RE: How to add aditional HPS GPIO's - Added by Matthew Schubert almost 8 years ago

Hi Alex,

Still a few misnumbered things in the above post.

Anyway, removing the switches from the DTS means that the GPIOs don't go to high impedance any more, and whatever I set them to in uBoot persists, but I still can't control things under Linux. Is there anything else in the device tree that needs changing to use those IOs?

    (1-5/5)
    Go to top
    Add picture from clipboard (Maximum size: 1 GB)