GPIO configuration

From liteSOM Wiki
Jump to: navigation, search

GPIO configuration

Each i.MX6UL GPIO can be exported to the userspace and later on controlled via /sys/class/gpio* subsystem.

Pinout configuration

Presented below device tree file snippet will configure pads:

  • JTAG_TRSTn/GPT2_COMPARE3/SAI2_TX_DATA/PWM8_OUT/GPIO1_IO15/ANATOP_24M_OUT/CAAM_RNG_OSC_OBS (pad 25 on liteSOM) as GPIO1[15],
  • JTAG_TDO/GPT2_CAPTURE2/SAI2_TX_SYNC/CCM_CLKO2/CCM_STOP/GPIO1_IO12/MQS_RIGHT/EPIT2_OUT (pad 24 on liteSOM) as GPIO1[12],
  • JTAG_TMS/GPT2_CAPTURE1/SAI2_MCLK/CCM_CLKO1/CCM_WAIT/GPIO1_IO11/SDMA_EXT_EVENT01/EPIT1_OUT (pad 22 on liteSOM) as GPIO1[11].
&iomuxc {
	pinctrl-names = "default";
	pinctrl-0 = <&pinctrl_hog>;
 
	pinctrl_hog: hoggrp {
		fsl,pins = <
			MX6UL_PAD_JTAG_TRST_B__GPIO1_IO15  0x0b0b0
			MX6UL_PAD_JTAG_TDO__GPIO1_IO12     0x0b0b0
			MX6UL_PAD_JTAG_TMS__GPIO1_IO11     0x0b0b0
		>;
	};
};

Controlling GPIO from userspace

Exporting GPIO

Each requested GPIO before any usage must exported to the userspace, for example

echo 15 > /sys/class/gpio/export

where 15 is index calculated as presented below

index  = (gpio_bank - 1) * 32 + gpio_port

For example for GPIO1[15] index should be equal

(1 - 1) * 32 + 15 = 15

GPIO direction

Exported GPIO can work as input or output. To check current mode you can read /sys/class/gpio/gpio*/direction like presented below

GPIO configured as input

# cat /sys/class/gpio/gpio15/direction 
in

GPIO configured as output

# cat /sys/class/gpio/gpio15/direction 
out

To change GPIO direction you can use following commands:

To set GPIO as output

echo out > /sys/class/gpio/gpio15/direction

To set GPIO as input

echo in > /sys/class/gpio/gpio15/direction

GPIO configured as input

Current GPIO state can be tested via /sys/class/gpio/gpio*/value like presented below

# cat /sys/class/gpio/gpio15/value 
1

GPIO configured as output

GPIO state can be requested via /sys/class/gpio/gpio*/value like presented below

To set GPIO in high state

# echo 1 > /sys/class/gpio/gpio15/value 

To set GPIO in low state

# echo 0 > /sys/class/gpio/gpio15/value