Playing with Pandaboard GPIO

Pandaboard GPIO detailAfter playing for a while with the Beagleboard (http://beagleboard.org) Expansion Header now is time to explore the PandaBoard one (http://pandaboard.org). I soldered a couple header sometime ago and finally I found half an hour to play with them.

For this brief experiment I used GPIO138 that corresponds to pin 10 on J3 (the header closer to the edge of the board). The "official" name of the pin is MCSPI1_CS1. For details check Table 10 on page 43 of the reference manual (http://pandaboard.org/node/223/#versions). Note that I have a PandaBoard Revision-A. Page and table references may differ from the PandaBoard ES manual.

First let's check the default configuration for this pin:

root@discola:/sys/class/gpio/gpio138# cat /sys/kernel/debug/omap_mux/mcspi1_cs1
name: mcspi1_cs1.gpio_138 (0x4a10013a/0x13a = 0x010b), b af23, t NA
mode: OMAP_PIN_INPUT_PULLDOWN | OMAP_MUX_MODE3
signals: mcspi1_cs1 | uart1_rx | NA | gpio_138 | NA | NA | NA | safe_mode

So, /sys/kernel/debug/omap_mux/ contain information regarding the configuration of all the signals we can interact with. In our case, the pin 10 on J3 is configured by default a a GPIO with number 138 (we already knew that :) and it is using a pulldown resistor. That means that we need to connect our button to PIN 10 and to 1.8V (PIN 1) and then, every time we press the button we will read a 1. Otherwise we will read a 0.

So far so good. But what is interesting is that we can configure pins on the expansion headers using the kernel debug pseudo file system. For a very detailed explanation check this article http://www.blaess.fr/christophe/2012/06/04/gpio-pandaboard-et-temps-reel.... It is really good with a lot of very interesting information. Google translation may be handy.

To check how to use this file system I just changed PIN 10 to use a Pull-up resistor, instead of the default Pull-down (actually I find out later that this is also done in the blog entry we had just mention but it was a good exercise anyway). Basically that means that I will get inverted logic and I have to connect my switch to ground instead of 1.8V. According to the blog entry referenced above the pins can be configured sending a hexadecimal word to the appropriate file . Let's see

First the word to build. It is a 16 bits word with the following coding:

  • Bits 0, 1 and 2: Multiplexing mode
  • Bit 3: Enable pull-up resistor input
  • Bit 4: Select Pull-up or Pull-down.
  • Bit 5-7: unused
  • Bit 8: Input pin
  • Bit 9-15: Used to control the off mode for the signal pads

For those of you wondering about where this information come from you need to check that huge OMAP4 TRM (look for yours in this page http://www.ti.com/general/docs/wtbu/wtbudocumentcenter.tsp?templateId=61...) , actually you need to look into section 18.4.8 and suddenly everything will make sense.

So, let's check again what the debug pseudo-filesystem reports with regards to our signal of interest


root@discola:/sys/class/gpio/gpio138# cat /sys/kernel/debug/omap_mux/mcspi1_cs1
name: mcspi1_cs1.gpio_138 (0x4a10013a/0x13a = 0x010b), b af23, t NA
mode: OMAP_PIN_INPUT_PULLDOWN | OMAP_MUX_MODE3
signals: mcspi1_cs1 | uart1_rx | NA | gpio_138 | NA | NA | NA | safe_mode

We need to look to the flags... that is the value 0x010b in the first line. If you want to know why we have to look at this one check the mux.c file for the omap architecture in the linux kernel.... It is interesting... really.

OK, back to business. First nibble (the first 4 bits) is an hexadecimal B (0xB) which translated to binary corresponds to 1011. In other words, we are setting mode 3 and enabling the pull resistor. Bit 4 is in the next nibble and its value is 0 in this case. That means we are selecting a pull-down resistor. So, in order to use a pull-up resistor for our input pin we should activate pin 4 which leads to a configuration value of 0x11b. Same value but with bit 4 set to 1 or, in other words, with a value of 1 on the second nibble. This is what will happen:


root@discola:/sys/class/gpio/gpio138# echo 0x11b > /sys/kernel/debug/omap_mux/mcspi1_cs1
root@discola:/sys/class/gpio/gpio138# cat /sys/kernel/debug/omap_mux/mcspi1_cs1
name: mcspi1_cs1.gpio_138 (0x4a10013a/0x13a = 0x011b), b af23, t NA
mode: OMAP_PIN_INPUT_PULLUP | OMAP_MUX_MODE3
signals: mcspi1_cs1 | uart1_rx | NA | gpio_138 | NA | NA | NA | safe_mode

Now we can just connect our button to ground (PIN 28) and to our GPIO (PIN10) and we will read a 1 unless the button is pressed. This simple bash line helped to test this:


root@discola:/sys/class/gpio/gpio138# while true; do cat value; sleep 0.05; done

PandaBoard GPIO GeneralPandaBoard GPIO General

maybe you wonder what is that big button for...

cheers
The picoFlamingo Team