VAR-SOM-AM43 GPIO: Difference between revisions
No edit summary |
|||
(11 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
{{PageHeader|VAR-SOM-AM43 - GPIO}} {{DocImage|category1=VAR-SOM- | {{PageHeader|VAR-SOM-AM43 - GPIO}} {{DocImage|category1=VAR-SOM-AM43|category2=Yocto}} __toc__ | ||
Line 8: | Line 8: | ||
The above command on Variscite's VAR-DVK-AM43 will show the following: | The above command on Variscite's VAR-DVK-AM43 will show the following: | ||
<pre> | <pre> | ||
root@varsomam43:~# cat /sys/kernel/debug/gpio | root@varsomam43:~# cat /sys/kernel/debug/gpio | ||
GPIOs 0-31, platform/44e07000.gpio, gpio: | GPIOs 0-31, platform/44e07000.gpio, gpio: | ||
Line 35: | Line 34: | ||
</pre> | </pre> | ||
Each GPIO is defined as in or out and the state is shown as lo or hi. | Each GPIO is defined as in or out and the state is shown as lo or hi. | ||
<br/>For example , | <br/>For example , SW4 the Menu Button:<br> | ||
When | When SW4 is pressed the state will be: | ||
<pre> | <pre> | ||
gpio- | gpio-166 (sw4 ) in lo IRQ | ||
</pre> | </pre> | ||
When | When SW4 is released the state will be: | ||
<pre> | <pre> | ||
gpio- | gpio-166 (sw4 ) in hi IRQ | ||
</pre> | </pre> | ||
= Manipulating a single GPIO via /sys/class/gpio = | = Manipulating a single GPIO via /sys/class/gpio = | ||
GPIOs in | GPIOs in the AM437X are grouped in 6 groups of 32 pins from GPIO0-GPIO5.<br/> | ||
<br/> | For example GPIO0_3 belongs to the first group pin 3. Its absolute number will be 3. | ||
<br/>GPIO5_8 will be (5)*32+8=168. | |||
<br/>Lets assume that you defined this GPIO in the device tree. We will show in the following sections how to define it. | <br/>Lets assume that you defined this GPIO in the device tree. We will show in the following sections how to define it. | ||
<br/>To configure as output: | <br/>To configure as output: | ||
<pre>$ echo | <pre>$ echo 168 > /sys/class/gpio/export | ||
$ echo out > /sys/class/gpio/ | $ echo out > /sys/class/gpio/gpio168/direction | ||
</pre> | </pre> | ||
Set GPIO low: | Set GPIO low: | ||
<pre> | <pre> | ||
$ echo 0 > /sys/class/gpio/ | $ echo 0 > /sys/class/gpio/gpio168/value | ||
</pre> | |||
Set GPIO high: | |||
<pre>$ echo 1 > /sys/class/gpio/gpio168/value | |||
</pre> | </pre> | ||
To configure as input: | To configure as input: | ||
<pre>$ echo | <pre>$ echo 168 > /sys/class/gpio/export | ||
$ echo in > /sys/class/gpio/ | $ echo in > /sys/class/gpio/gpio168/direction | ||
</pre> | </pre> | ||
<pre>$ cat /sys/class/gpio/ | <pre>$ cat /sys/class/gpio/gpio168/value | ||
</pre> | </pre> | ||
Will read the current value. | Will read the current value. | ||
= Reference reading = | = Reference reading = | ||
http://processors.wiki.ti.com/index.php/Linux_PSP_GPIO_Driver_Guide | http://processors.wiki.ti.com/index.php/Linux_PSP_GPIO_Driver_Guide |
Latest revision as of 13:16, 24 December 2015
GPIO state
The current state of the systems' GPIOs can be obtained in user-mode, as shown in the following example:
$ cat /sys/kernel/debug/gpio
The above command on Variscite's VAR-DVK-AM43 will show the following:
root@varsomam43:~# cat /sys/kernel/debug/gpio GPIOs 0-31, platform/44e07000.gpio, gpio: gpio-6 (cd ) in lo IRQ GPIOs 32-63, platform/4804c000.gpio, gpio: gpio-48 (kim ) out lo gpio-52 (vmmcwl_fixed ) out lo GPIOs 64-95, platform/481ac000.gpio, gpio: GPIOs 96-127, platform/481ae000.gpio, gpio: GPIOs 128-159, platform/48320000.gpio, gpio: gpio-136 (? ) out lo gpio-154 (? ) out lo gpio-157 (ft5x06_irq_gpio ) in hi IRQ GPIOs 160-191, platform/48322000.gpio, gpio: gpio-164 (sw6 ) in hi IRQ gpio-165 (sw5 ) in hi IRQ gpio-166 (sw4 ) in hi IRQ gpio-167 (vtt_fixed ) out hi GPIOs 510-511, platform/50000000.gpmc, omap-gpmc:
Each GPIO is defined as in or out and the state is shown as lo or hi.
For example , SW4 the Menu Button:
When SW4 is pressed the state will be:
gpio-166 (sw4 ) in lo IRQ
When SW4 is released the state will be:
gpio-166 (sw4 ) in hi IRQ
Manipulating a single GPIO via /sys/class/gpio
GPIOs in the AM437X are grouped in 6 groups of 32 pins from GPIO0-GPIO5.
For example GPIO0_3 belongs to the first group pin 3. Its absolute number will be 3.
GPIO5_8 will be (5)*32+8=168.
Lets assume that you defined this GPIO in the device tree. We will show in the following sections how to define it.
To configure as output:
$ echo 168 > /sys/class/gpio/export $ echo out > /sys/class/gpio/gpio168/direction
Set GPIO low:
$ echo 0 > /sys/class/gpio/gpio168/value
Set GPIO high:
$ echo 1 > /sys/class/gpio/gpio168/value
To configure as input:
$ echo 168 > /sys/class/gpio/export $ echo in > /sys/class/gpio/gpio168/direction
$ cat /sys/class/gpio/gpio168/value
Will read the current value.
Reference reading
http://processors.wiki.ti.com/index.php/Linux_PSP_GPIO_Driver_Guide