Difference between revisions of "EBC Exercise 11a Device Trees"

From eLinux.org
Jump to: navigation, search
m (Seeing What Pins are in Use)
m (Changing the Pin Mux)
Line 104: Line 104:
 
  beagle$ '''gedit MAY-gpio-SET.dts'''
 
  beagle$ '''gedit MAY-gpio-SET.dts'''
  
 +
To set P9_15 you need to look up it's address offset. This is the hex value (0x134) reported by the '''findGPIO.js''' command. The following table shows what bits to set.
 +
{|
 +
| Bit || Description
 +
|-
 +
| 6 || Slew Control. Slew Rate: Fast is 0, Slow is 1
 +
|-
 +
| 5 || Receiver Active. Input Enable: Receiver Disable 0, Receiver Enable 1
 +
|-
 +
| 4 || Pad Pullup/Pulldown Type. Pullup is 1, Pulldown is 0
 +
|-
 +
| 3 || Pad Pullup/Pulldown enable. Enabled is 0, Disabled is 1
 +
|-
 +
| 2-0 || Mode. Pad functional mux select. A number between 0 and 7 i.e. 000 and 111. This depends on which mode we require.
 +
|}
 +
Since we want mode 7, with pullup enabled and receiver active enabled use 0b11 0111 or 0x37.
 
Here's the part of the file we'll edit
 
Here's the part of the file we'll edit
 
 
  /{
 
  /{
 
     compatible = "ti,beaglebone", "ti,beaglebone-black";
 
     compatible = "ti,beaglebone", "ti,beaglebone-black";
Line 118: Line 132:
 
         pinctrl-single,pins = <
 
         pinctrl-single,pins = <
 
   
 
   
             0x078 0x07 /* P9_12 60 OUTPUT MODE7 - The LED Output */
+
             '''0x134 0x37 // P9_15 48 INPUT  MODE7 pullup'''
            0x184 0x2f /* P9_24 15 INPUT  MODE7 none    - The Button Input */
+
             '''0x04c 0x37  // P9_16  51 INPUT  MODE7 pullup'''
             0x034 0x37  /* P8_11 45 INPUT  MODE7 pullup   - Yellow Wire */
+
             '''0x15c 0x37 // P9_17  5 INPUT  MODE7 pullup'''
             0x030 0x27 /* P8_12 44 INPUT  MODE7 pulldown - Green Wire */
+
             '''0x158 0x37 // P9_18  4 INPUT  MODE7 pullup'''
             0x024 0x2f /* P8_13 23 INPUT  MODE7 none    - White Wire */
+
 
                          
 
                          
 
             /* OUTPUT  GPIO(mode7) 0x07 pulldown, 0x17 pullup, 0x?f no pullup/down */
 
             /* OUTPUT  GPIO(mode7) 0x07 pulldown, 0x17 pullup, 0x?f no pullup/down */
Line 131: Line 144:
 
       };
 
       };
 
     };
 
     };
 +
Notice the register/value pairs for each of the pins.  P9_15 is at address 0x134 and gets a value 0x37. Use findGPIO.js and check to be sure the other pin addresses are correct.
  
 
== Compile ==
 
== Compile ==

Revision as of 16:15, 18 September 2013

thumb‎ Embedded Linux Class by Mark A. Yoder


The Device Tree (DT), and Device Tree Overlay are a way to describe hardware in a system. This introduction is heavily based on Adafruit's Introduction to the BeagleBone Black Device Tree using Derek Molloy's gpio example.

The purpose of this exercise is to learn how to set the pin mux and enable the pullup or pulldown resistors.

Pin Muxing

The am335x processor on the BeagleBone has more internal 'pins' than external pins. The solution is to have each external pin attached to a multiplexer that can be 'muxed' to one of eight internal pins. A nice chart that shows what can connect to where can be found by

beagle$ git clone git://github.com/derekmolloy/boneDeviceTree.git 
beagle$ cd boneDeviceTree/docs
beagle$ ls
BeagleboneBlackP8HeaderTable.pdf  BeagleboneBlackP9HeaderTable.pdf

These two pdf files show where each of the pins on the P8 and P9 headers can be muxed. The initial muxing is set at boot time using the Device Tree (DT).

Seeing What Pins are in Use

The HeaderTable pdfs give a nice overview of what the various pins can do, but they don't show what's currently in use. The BeagleBone has many gpio pins to choose from, but many are already in use and can't be changed. Here's how to see what's currently in use. First, do this once

beagle$ export SLOTS=/sys/devices/bone_capemgr.*/slots
beagle$ export PINS=/sys/kernel/debug/pinctrl/44e10800.pinmux/pins
beagle$ export PINMUX=/sys/kernel/debug/pinctrl/44e10800.pinmux/pinmux-pins
beagle$ export PINGROUPS=/sys/kernel/debug/pinctrl/44e10800.pinmux/pingroups

Now

beagle$ cat $PINGROUPS
registered pin groups:
group: pinmux_userled_pins
pin 21 (44e10854)
pin 22 (44e10858)
pin 23 (44e1085c)
pin 24 (44e10860)

group: pinmux_rstctl_pins
pin 20 (44e10850)

group: pinmux_i2c0_pins
pin 98 (44e10988)
pin 99 (44e1098c)
...

What you see are the pins that are in use, listed by functional group. You can see what all the pins are doing with

beagle$ cat $PINMUX
Pinmux settings per pin
Format: pin (name): mux_owner gpio_owner hog?
pin 0 (44e10800): mmc.10 (GPIO UNCLAIMED) function pinmux_emmc2_pins group pinmux_emmc2_pins
pin 1 (44e10804): mmc.10 (GPIO UNCLAIMED) function pinmux_emmc2_pins group pinmux_emmc2_pins
pin 2 (44e10808): mmc.10 (GPIO UNCLAIMED) function pinmux_emmc2_pins group pinmux_emmc2_pins
pin 3 (44e1080c): mmc.10 (GPIO UNCLAIMED) function pinmux_emmc2_pins group pinmux_emmc2_pins
pin 4 (44e10810): mmc.10 (GPIO UNCLAIMED) function pinmux_emmc2_pins group pinmux_emmc2_pins
pin 5 (44e10814): mmc.10 (GPIO UNCLAIMED) function pinmux_emmc2_pins group pinmux_emmc2_pins
pin 6 (44e10818): mmc.10 (GPIO UNCLAIMED) function pinmux_emmc2_pins group pinmux_emmc2_pins
pin 7 (44e1081c): mmc.10 (GPIO UNCLAIMED) function pinmux_emmc2_pins group pinmux_emmc2_pins
pin 8 (44e10820): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 9 (44e10824): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 10 (44e10828): (MUX UNCLAIMED) (GPIO UNCLAIMED)
...

Notice the first 8 are using my the emmc. The next few are unused. You can see all the unused pins with

beagle$ grep "(MUX UNCLAIMED) (GPIO UNCLAIMED)" $PINMUX
pin 8 (44e10820): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 9 (44e10824): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 10 (44e10828): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 11 (44e1082c): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 12 (44e10830): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 13 (44e10834): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 14 (44e10838): (MUX UNCLAIMED) (GPIO UNCLAIMED)
...

The problem is the pins are listed by an internal pin number and the hardware address (44e10820). The class repo has a couple of simple scripts that help with this.

beagle$ cd exercises/gpio
beagle$ ./freeGPIO
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_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

These are pins your are free to use. You can get information about a given pin using

beagle$ './findGPIO.js P9_16
{ name: 'EHRPWM1B',
  gpio: 51,
  mux: 'gpmc_a3',
  eeprom: 35,
  pwm: { muxmode: 6, path: 'ehrpwm.1:1', name: 'EHRPWM1B' },
  key: 'P9_16',
  muxRegOffset: '0x04c',
  options: 
   [ 'gpmc_a3',
     'gmii2_txd2',
     'rgmii2_td2',
     'mmc2_dat2',
     'gpmc_a19',
     'pr1_mii1_txd1',
     'ehrpwm1B',
     'gpio1_19' ] }
P9_16 (gpio 51) mode: 7 (gpio1_19) 0x04c pulldown Receiver Active
pin 19 (44e1084c): (MUX UNCLAIMED) (GPIO UNCLAIMED)

This tells you how the mux and pullup/pulldown resistors are currently set, and how they could be set. You can get a quick summary for several pins using beagle$ ./findGPIO.js P9_15 P9_16 P9_17 P9_18

P9_16 (gpio 51) mode: 7 (gpio1_19) 0x04c pulldown Receiver Active
P9_15 (gpio 48) mode: 0 (mii1_rxd3) 0x134 pulldown Receiver Active
P9_17 (gpio 5) mode: 2 (i2c1_scl) 0x15c pulldown Receiver Active Slew Control Slow
P9_18 (gpio 4) mode: 2 (i2c1_sda) 0x158 pulldown Receiver Active Slew Control Slow

Changing the Pin Mux

Let's set pins P9_15 P9_16 P9_17 P9_18 to all be mode 7 with a pullup resistor. To change the pin mux we'll get an overlay that works and edit it.

beagle$ cd ../overlay
beagle$ cp DM-gpio-Test.dts ~/MAY-gpio-set.dts  // Copy to a place of your choice
                                                // Use your initials instead of MAY
beagle$ gedit MAY-gpio-SET.dts

To set P9_15 you need to look up it's address offset. This is the hex value (0x134) reported by the findGPIO.js command. The following table shows what bits to set.

Bit Description
6 Slew Control. Slew Rate: Fast is 0, Slow is 1
5 Receiver Active. Input Enable: Receiver Disable 0, Receiver Enable 1
4 Pad Pullup/Pulldown Type. Pullup is 1, Pulldown is 0
3 Pad Pullup/Pulldown enable. Enabled is 0, Disabled is 1
2-0 Mode. Pad functional mux select. A number between 0 and 7 i.e. 000 and 111. This depends on which mode we require.

Since we want mode 7, with pullup enabled and receiver active enabled use 0b11 0111 or 0x37. Here's the part of the file we'll edit

/{
   compatible = "ti,beaglebone", "ti,beaglebone-black";
   part-number = "MAY-gpio-set";
   version = "00A0";

   fragment@0 {
       target = <&am33xx_pinmux>;
            
       __overlay__ {
           pinctrl_test: MAY-gpio-set {
       pinctrl-single,pins = <

           0x134 0x37  // P9_15  48 INPUT  MODE7 pullup
           0x04c 0x37  // P9_16  51 INPUT  MODE7 pullup
           0x15c 0x37  // P9_17   5 INPUT  MODE7 pullup
           0x158 0x37  // P9_18   4 INPUT  MODE7 pullup
                       
           /* OUTPUT  GPIO(mode7) 0x07 pulldown, 0x17 pullup, 0x?f no pullup/down */
           /* INPUT   GPIO(mode7) 0x27 pulldown, 0x37 pullup, 0x?f no pullup/down */

       >;
      };
     };
   };

Notice the register/value pairs for each of the pins. P9_15 is at address 0x134 and gets a value 0x37. Use findGPIO.js and check to be sure the other pin addresses are correct.

Compile

beagle$ dtc -O dtb -o MAY-gpio-set-00A0.dtbo -b 0 -@ MAY-gpio-set.dts

Compiling the overlay from .dts to .dtbo

Install

beagle$ cp MAY-gpio-set-00A0.dtbo /lib/firmware
beagle$ echo MAY-gpio-set > $SLOTS

Verify

Check to be sure it worked. First check for errors.

beagle$ dmesg | tail
[   83.795688] pinctrl-single 44e10800.pinmux: pin 44e10990 already requested by 48038000.mcasp; cannot claim for helper.14
[   83.807174] pinctrl-single 44e10800.pinmux: pin-100 (helper.14) status -22
[   83.814392] pinctrl-single 44e10800.pinmux: could not request pin 100 on device pinctrl-single
[   83.823421] bone-pinmux-helper helper.14: Failed to select default state

Looks like I can't use that pin.

Then check the slots.

beagle$ cat $SLOTS 
0: 54:PF--- 
1: 55:PF--- 
2: 56:PF--- 
3: 57:PF--- 
4: ff:P-O-L Bone-LT-eMMC-2G,00A0,Texas Instrument,BB-BONE-EMMC-2G
5: ff:P-O-L Bone-Black-HDMI,00A0,Texas Instrument,BB-BONELT-HDMI
7: ff:P-O-L Override Board Name,00A0,Override Manuf,MAY-gpio-set

Now check with

beagle$ cd exercises/gpio
beagle$ ./findGPIO.js P8_12
{ name: 'GPIO1_12',
  gpio: 44,
  mux: 'gpmc_ad12',
  eeprom: 28,
  key: 'P8_12',
  muxRegOffset: '0x030',
 options: 
  [ 'gpmc_ad12',
    'lcd_data19',
    'mmc1_dat4',
    'mmc2_dat0',
    'eqep2a_in',
    'pr1_mii0_txd2',
    'pr1_pru0_pru_r30_14',
    'gpio1_12' ] }
pin 12 (44e10830) 00000027 pinctrl-single 

Mode: 7 (gpio1_12) pulldown Receiver Active

Looks like it worked, now check the others.

Removing

It's appeared in slot 7. You can remove it with

beagle$ echo -7 > $SLOTS

Be careful though, the current versions appear unstable when removing this way.




thumb‎ Embedded Linux Class by Mark A. Yoder