Finding free gpio poins

I wrote a little script, freeGPIO.js, to help locate which gpio pins are free[1]. It uses the information in pinmux-pins[2] and then uses bone.js[3] to map the internal pin numbers to header pins. The output is a list of header pins:

beagle$ ./freeGPIO.js
P8_10 P8_11 P8_12 P8_13 P8_14 P8_15 P8_16 P8_17 P8_18 P8_19 P8_26 P8_7 P8_8 P8_9 P9_11 P9_12 P9_13 P9_14 P9_15 P9_16 P9_17 P9_18 P9_21 P9_22 P9_23 P9_24 P9_26 P9_27 P9_30 P9_41 P9_42 USR0 USR1 USR2 USR3

You can then use findGPIO.js[4] to find information about the pin.

beagle$ ./findGPIO.js P9_11

{ name: ‘UART4_RXD’,
gpio: 30,
mux: ‘gpmc_wait0’,
eeprom: 18,
key: ‘P9_11’,
muxRegOffset: ‘0x070’,
options:
[ ‘gpmc_wait0’,
‘mii2_crs’,
‘NA’,
‘rmii2_crs_dv’,
‘mmc1_sdcd’,
‘NA’,
‘NA’,
‘gpio0_30’ ] }
P9_11 (gpio 30) mode: 7 (gpio0_30) 0x070 pullup Receiver Active
pin 28 (44e10870): (MUX UNCLAIMED) (GPIO UNCLAIMED)

If you give move than one argument you will get a summary for each pin.

beagle$ ./findGPIO.js P9_11 P9_12 P9_13 P9_14
P9_12 (gpio 60) mode: 7 (gpio1_28) 0x078 pullup Receiver Active
P9_11 (gpio 30) mode: 7 (gpio0_30) 0x070 pullup Receiver Active
P9_13 (gpio 31) mode: 7 (gpio0_31) 0x074 pullup Receiver Active
P9_14 (gpio 50) mode: 7 (gpio1_18) 0x048 pulldown Receiver Active

I have my students use these when they are learning about Device Tree Overlays[5]. It’s a quick way to see if your overlay worked.

I hope this is helpful to others…

–Mark

[1] https://github.com/MarkAYoder/BeagleBoard-exercises/blob/master/gpio/freeGPIO.js
[2] /sys/kernel/debug/pinctrl/44e10800.pinmux/pinmux-pins
[3] /usr/lib/node_modules/bonescript/bone.js
[4] https://github.com/MarkAYoder/BeagleBoard-exercises/blob/master/gpio/findGPIO.js
[5] http://elinux.org/EBC_Exercise_11a_Device_Trees

Mark A. Yoder <mark.a.yoder@gmail.com> [13-09-21 20:56]:

I wrote a little script, *freeGPIO.js*, to help locate which gpio pins are
free[1]. It uses the information in pinmux-pins[2] and then uses bone.js[3]
to map the internal pin numbers to header pins. The output is a list of
header pins:

beagle$ *./freeGPIO.js *
P8_10 P8_11 P8_12 P8_13 P8_14 P8_15 P8_16 P8_17 P8_18 P8_19 P8_26 P8_7 P8_8
P8_9 P9_11 P9_12 P9_13 P9_14 P9_15 P9_16 P9_17 P9_18 P9_21 P9_22 P9_23
P9_24 P9_26 P9_27 P9_30 P9_41 P9_42 USR0 USR1 USR2 USR3

You can then use *findGPIO.js*[4] to find information about the pin.
beagle$ *./findGPIO.js P9_11*
{ name: 'UART4_RXD',
  gpio: 30,
  mux: 'gpmc_wait0',
  eeprom: 18,
  key: 'P9_11',
  muxRegOffset: '0x070',
  options:
   [ 'gpmc_wait0',
     'mii2_crs',
     'NA',
     'rmii2_crs_dv',
     'mmc1_sdcd',
     'NA',
     'NA',
     'gpio0_30' ] }
P9_11 (gpio 30) mode: 7 (gpio0_30) 0x070 pullup Receiver Active
pin 28 (44e10870): (MUX UNCLAIMED) (GPIO UNCLAIMED)

If you give move than one argument you will get a summary for each pin.
beagle$ *./findGPIO.js P9_11 P9_12 P9_13 P9_14*
P9_12 (gpio 60) mode: 7 (gpio1_28) 0x078 pullup Receiver Active
P9_11 (gpio 30) mode: 7 (gpio0_30) 0x070 pullup Receiver Active
P9_13 (gpio 31) mode: 7 (gpio0_31) 0x074 pullup Receiver Active
P9_14 (gpio 50) mode: 7 (gpio1_18) 0x048 pulldown Receiver Active

I have my students use these when they are learning about Device Tree
Overlays[5]. It's a quick way to see if your overlay worked.

I hope this is helpful to others...

--Mark

Hi Mark,

thanks for the script and the material/exercises! :slight_smile:

One thing:
Under /sys/kernel/debug/pinctrl there are files which reflects
the usage of the pins.
These show all pins even those, which are not routed to the
headers P8/P9 on the beaglebone black.
Is there any way to filter out those, which are not accessible
via P8/P9 other than doing it by hand or by a script, which "knows"
which pins can be found on P8/P9?

Best regards,
mcc