Chapter 6: Programming GPIO using Sysfs - tshakthipradeep/BBB GitHub Wiki

GPIO (General Purpose Input Output) is a general purpose pin on the SOC which can either be used in input mode or output mode.

When used in input mode, it can sense the pin state as either HIGH (1) or LOW (0). Most of the SOCs nowadays, support interrupt mode where GPIO controller can detect and generate an interrupt on change in edge (Rising or Falling or Both) or change is level (High or Low).

When used in output mode, pin's state can be changed to HIGH (1) or LOW (0).

To know more about GPIO please refer to the link below.

https://www.kernel.org/doc/Documentation/gpio/gpio.txt

In this chapter I will show you how you can program GPIO from user space using Sysfs and Debugfs.

To know more about Sysfs and Debugfs please refer to the links below.

https://www.kernel.org/doc/Documentation/filesystems/sysfs.txt
https://www.kernel.org/doc/Documentation/filesystems/debugfs.txt

First run cat /sys/kernel/debug/gpio to view information on the GPIO's which are currently acquired by various driver in Kernel, direction they are set in and their current state.

root@beaglebone:~# cat /sys/kernel/debug/gpio 
GPIOs 0-31, gpio:
 gpio-6   (mmc_cd              ) in  hi

GPIOs 32-63, gpio:
 gpio-52  (eMMC_RSTn           ) out lo
 gpio-53  (beaglebone:green:usr) out lo
 gpio-54  (beaglebone:green:usr) out lo
 gpio-55  (beaglebone:green:usr) out hi
 gpio-56  (beaglebone:green:usr) out lo
 gpio-59  (McASP Clock Enable P) out hi

GPIOs 64-95, gpio:

GPIOs 96-127, gpio: