Jump to content
43oh

BeagleBone Black - Using Devicetrees to expose GPIO pin functions


Recommended Posts

I figured it out.  Had my gpio # wrong; since it's 1_16, it needs to be 32+16, likewise 1_19 = 32+19.

 

Found my hint here: http://www.armhf.com/index.php/using-beaglebone-black-gpios/

That guy used the same pins plus 2 others and his gpio #'s were way off from what I was using, then I realized my mistake.

 

Looks like even with the default pinmux setting of 0x27, these pins can be used for GPIO output.  The 0x20 just enables the input buffer I guess (like Renesas RX PORTx.ICR.BIT.Bx to enable the input schmitt trigger), but it can be used in output mode too.  So pinmux is really needed only for changing the pin functions to one of the alternate settings, ala PxSEL/PxSEL2 on the MSP430 value line.  And perhaps some of the pins don't start out in GPIO mode automatically (mode 7 seems to be the GPIO function universally for all of them) so they would need pinmuxing to get started.

 

Process of enabling it:

1. What's our GPIO#

root@beaglebone:~# echo $(expr 32 + 16) $(expr 32 + 19)
48 51

 

so 1_16 = gpio #48, 1_19 = gpio #51.

 

2. Export 48 & 51 to the sysfs gpio interface:

root@beaglebone:/sys/class/gpio# ls -l
total 0
--w------- 1 root root 4096 Jan  1 00:29 export
lrwxrwxrwx 1 root root    0 Jan  1 00:00 gpiochip0 -> ../../devices/virtual/gpio/gpiochip0
lrwxrwxrwx 1 root root    0 Jan  1 00:00 gpiochip32 -> ../../devices/virtual/gpio/gpiochip32
lrwxrwxrwx 1 root root    0 Jan  1 00:00 gpiochip64 -> ../../devices/virtual/gpio/gpiochip64
lrwxrwxrwx 1 root root    0 Jan  1 00:00 gpiochip96 -> ../../devices/virtual/gpio/gpiochip96
--w------- 1 root root 4096 Jan  1 00:34 unexport
root@beaglebone:/sys/class/gpio# echo 48 > export
root@beaglebone:/sys/class/gpio# echo 51 > export
root@beaglebone:/sys/class/gpio# ls -l
total 0
--w------- 1 root root 4096 Jan  1 00:35 export
lrwxrwxrwx 1 root root    0 Jan  1 00:35 gpio48 -> ../../devices/virtual/gpio/gpio48
lrwxrwxrwx 1 root root    0 Jan  1 00:35 gpio51 -> ../../devices/virtual/gpio/gpio51
lrwxrwxrwx 1 root root    0 Jan  1 00:00 gpiochip0 -> ../../devices/virtual/gpio/gpiochip0
lrwxrwxrwx 1 root root    0 Jan  1 00:00 gpiochip32 -> ../../devices/virtual/gpio/gpiochip32
lrwxrwxrwx 1 root root    0 Jan  1 00:00 gpiochip64 -> ../../devices/virtual/gpio/gpiochip64
lrwxrwxrwx 1 root root    0 Jan  1 00:00 gpiochip96 -> ../../devices/virtual/gpio/gpiochip96
--w------- 1 root root 4096 Jan  1 00:34 unexport

Booyah, gpio48 & gpio51 in the house.

 

What's in those directories though:

root@beaglebone:/sys/class/gpio# ls -l gpio48/
total 0
-rw-r--r-- 1 root root 4096 Jan  1 00:36 active_low
-rw-r--r-- 1 root root 4096 Jan  1 00:35 direction
-rw-r--r-- 1 root root 4096 Jan  1 00:36 edge
drwxr-xr-x 2 root root    0 Jan  1 00:36 power
lrwxrwxrwx 1 root root    0 Jan  1 00:36 subsystem -> ../../../../class/gpio
-rw-r--r-- 1 root root 4096 Jan  1 00:35 uevent
-rw-r--r-- 1 root root 4096 Jan  1 00:36 value

"direction" and "value" is all we care about here.

root@beaglebone:/sys/class/gpio# cat gpio48/direction
in
root@beaglebone:/sys/class/gpio# cat gpio51/direction
in

They're set to Input mode by default.

 

Set them to output mode:

root@beaglebone:/sys/class/gpio# echo out > gpio48/direction
root@beaglebone:/sys/class/gpio# echo out > gpio51/direction
root@beaglebone:/sys/class/gpio# cat gpio48/value
0
root@beaglebone:/sys/class/gpio# cat gpio51/value
0

Value set to 0, so the pins should be driving to GND right now.

 

Let's set gpio51 high:

root@beaglebone:/sys/class/gpio# echo 1 > gpio51/value
root@beaglebone:/sys/class/gpio# cat gpio48/value
0
root@beaglebone:/sys/class/gpio# cat gpio51/value
1

And now we have 1 lit LED and one not lit:

post-4-14264691110951_thumb.jpg

 

Light the other one:

root@beaglebone:/sys/class/gpio# echo 1 > gpio48/value
root@beaglebone:/sys/class/gpio# cat gpio48/value
1
root@beaglebone:/sys/class/gpio# cat gpio51/value
1

post-4-14264691111248_thumb.jpg

 

 

Ok, now all this crap is starting to come together for me :)

Time to play with UART4... Going to test my BBB LaunchPad Cape with the GPS boosterpack to see if I can get the data flowing over UART4 @ 9600.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...