Project

General

Profile

GPIO Usage Overview

In Critical Link kernels we enable GPIO support by default and almost every design will make use of a GPIO for some function (Ethernet reset, status LED, etc.). Please note that the TI Linux GPIO Wiki concerning the GPIO driver is a great resource to reference.

GPIO Pin Muxing

As for all AM335x pins the pin-mux must be configured in the kernel for every processor pin. For any pin that can be configured as a GPIO the mode is always the last mode, 7 (base of 0), as each pin can support up to 8 different pin-mux modes. This wiki page Creating a custom baseboard provides further details about this process.

  • GPIO1_13 as an output
    {"gpmc_ad13.gpio1_13", AM33XX_PULL_ENBL | AM33XX_PIN_OUTPUT},
    
  • GPIO1_12 as an input
    {"gpmc_ad12.gpio1_12", AM33XX_PIN_INPUT_PULLUP},
    

GPIO Mapping

The AM335x processor features 4 banks of GPIO's, with up to 32 GPIO's each.

For example Module Pin 114 when pin-muxed as a GPIO is GPIO2[20]. That means that to access that GPIO at the Userspace level it is referenced as GPIO# 84. This is based on the 2[20] portion of the GPIO mode name.

2 (GPIO Bank #) * 32 (# of GPIO's per bank) = 64

64 (Base number for bank 2) + 20 (index of this specific GPIO in the bank) = 84.

#define GPIO_TO_PIN(bank, bank_gpio)    (32 * (bank) + (bank_gpio))

Example Userspace Usage (for development kit and development kit Kernel)

J506 (10-pin shrouded header) - Pin 1 (Module pin 114 - GPIO2[20])

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

  1. Login to Linux through the console serial port using the user name of "root" with no password
  2. This will export the GPIO and allow you to use it
    echo "84" > /sys/class/gpio/export
    
  3. Set the direction as an output
    echo "out" > /sys/class/gpio/gpio84/direction
    
  4. Enable the GPIO - 3.3V driven on this bus
    echo "1" > /sys/class/gpio/gpio84/value
    
  5. Disable the GPIO - 0V
     echo "0" > /sys/class/gpio/gpio84/value
    

Example userspace c++ command and library

Building libdaq example applications libraries

The gpio and gpiosingle binaries allow testing/controlling gpios from the command line by handling the above sysfs steps. These classes can also be used as libraries in your c++ application to make it easier to control gpio.

Example, assume we have a blue led connected to GPIO1_13:

#include "gpiosingle.h" 

#define GPIO_TO_PIN(bank, bank_gpio)    (32 * (bank) + (bank_gpio))
const int GPIO_LED_BLUE = GPIO_TO_PIN(1, 13);

void main() {
  tcGpioSingle ledBlue(GPIO_LED_BLUE);

  int ledOn = 0;
  ledBlue.setDirection(1, ledOn); // Output Low

  while (true) {
    ledOn = !ledOn;
    ledBlue.setValue(ledOn);
  }
}

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