Enabling uarts on the beaglebone white and black with ubuntu 13.10

This is fairly welly documented around the internet but usually for angstrom distribution and there is a complication when using ubuntu 13.04/10. The beaglebones have up to 5 uarts, although some use the same pins as the hdmi, or lack an rx. In order to be able to use them you have to enable them through the device tree. If you look in /lib/firmware you will see a list of device tree overlays that can be applied to the board to enable certain pin configurations. I assume that the following process can be applied to enable pins for spi, pwm etc.. but have not tried it.

Firstly how do you make an overlay that will set up my io pins? Using a couple of good sources, hipster circuits and ada fruit, you can find the structure of a device overlay which should be saved as a .dts file. The example from ladyada worked great for me;

 
/*
* Copyright (C) 2013 CircuitCo
*
* Virtual cape for UART1 on connector pins P9.24 P9.26
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
/dts-v1/;
/plugin/;
 
/ {
    compatible = "ti,beaglebone", "ti,beaglebone-black";
 
        /* identification */
        part-number = "BB-UART1";
        version = "00A0";
 
        /* state the resources this cape uses */
        exclusive-use =
            /* the pin header uses */
            "P9.24",    /* uart1_txd */
            "P9.26",    /* uart1_rxd */
            /* the hardware ip uses */
            "uart1";
 
        fragment@0 {
            target = <&am33xx_pinmux>;
            __overlay__ {
                bb_uart1_pins: pinmux_bb_uart1_pins {
                    pinctrl-single,pins = <
                        0x184 0x20 /* P9.24 uart1_txd.uart1_txd MODE0 OUTPUT (TX) */
                        0x180 0x20 /* P9.26 uart1_rxd.uart1_rxd MODE0 INPUT (RX) */
                    >;
                };
            };
        };
 
    fragment@1 {
        target = <&uart2>;  /* really uart1 */
        __overlay__ {
            status = "okay";
            pinctrl-names = "default";
            pinctrl-0 = <&bb_uart1_pins>;
        };
    };
};

In ubuntu I hit a snag when compiling the overlay where the compiler doesnt recognise the ‘@’ syntax. Looking here I found a solution to update the compiler.

wget -c https://raw.github.com/RobertCNelson/tools/master/pkgs/dtc.sh
chmod +x dtc.sh
./dtc.sh

This solved the compilation issue for me and generated a .dtbo. With regards to understanding the overlay, both ladyada and here provide good information. The main thing to worry about is how you references the pins you want to enable. In the following snippet two numbers are passed for each pin, one defines the pin and the second defines the mode.

       fragment@0 {
            target = <&am33xx_pinmux>;
            __overlay__ {
                bb_uart1_pins: pinmux_bb_uart1_pins {
                    pinctrl-single,pins = <
                        0x184 0x20 /* P9.24 uart1_txd.uart1_txd MODE0 OUTPUT (TX) */
                        0x180 0x20 /* P9.26 uart1_rxd.uart1_rxd MODE0 INPUT (RX) */
                    >;
                };
            };
        };

From here I found a great table that provides the uart pin numbers which should correlate with the beaglebone srm;

 RX: 0x170 0x20 (j1-p4)  (ZCZ-E15 UART0_RXD mode:0 [datasheet]) = (conf_uart0_rxd 970h [TRM p1126] = 0x0170)
 
UART1: 0x4802_2000 (/dev/ttyO1)
   TX: 0x184 0x00  (p9-24) (ZCZ-D15 UART1_TXD mode:0 [datasheet]) = (conf_uart1_txd 984h [TRM p1126] = 0x0184)
   RX: 0x180 0x20  (p9-26) (ZCZ-D16 UART1_RXD mode:0 [datasheet]) = (conf_uart1_rxd 980h [TRM p1126] = 0x0180)
 
UART2: 0x4802_4000 (/dev/ttyO2)
   TX: 0x154 0x01  (p9-21) (ZCZ-B17 SPI0_D0   mode:1 [datasheet]) = (conf_spi0_d0   954h [TRM p1126] = 0x0154)
   RX: 0x150 0x21  (p9-22) (ZCZ-A17 SPI0_SCLK mode:1 [datasheet]) = (conf_spi0_sclk 950h [TRM p1126] = 0x0150)
 
UART3: 0x481A_6000 (/dev/ttyO3)
   TX: 0x164 0x01  (p9-42)       (ZCZ-C18 ECAP0_IN_PWM0_OUT mode:1 [datasheet]) = (conf_ecap0_in_pwm0_out 964h [TRM p1126] = 0x0164)
   RX: 0x188 0x21  (no breakout) (ZCZ-C17 I2C0_SDA          mode:1 [datasheet]) = (conf_i2c0_sda          988h [TRM p1126] = 0x0188) I2C0_SDA is tied to TDA19988
 
UART4: 0x481A_8000 (/dev/ttyO4)
   TX: 0x074 0x06  (p9-13) (ZCZ-U17 GPMC_WPn   mode:6 [datasheet]) = (conf_gpmc_wpn   874h [TRM p1124] = 0x0074)
   RX: 0x070 0x26  (p9-11) (ZCZ-T17 GPMC_WAIT0 mode:6 [datasheet]) = (conf_gpmc_wait0 870h [TRM p1124] = 0x0070)
 
UART5: 0x481A_A000 (/dev/ttyO5)
   TX: 0x0C0 0x04  (p8-37) (ZCZ-U1 LCD_DATA8 mode:4 [datasheet]) = (conf_lcd_data8 8C0h [TRM p1125] = 0x00C0)
   RX: 0x0C4 0x24  (p8-38) (ZCZ-U2 LCD_DATA9 mode:4 [datasheet]) = (conf_lcd_data9 8C4h [TRM p1125] = 0x00C4)

The second number being passed defines the pin mode, and from I know that this relates to the defined modes in the beaglebone srm. If you note down the numbers used you can compare them with the pin mode options in the srm to see whats being enabled and set.

From this you should be able to work out how to create an overlay for any of the uarts available on the beaglebone. So once you have a compiled on the beaglebone you need to copy or move it to the /lib/firmware/ directory. In order to enable this overlay you need to call the command;

echo enable-uart1 > /sys/devices/bone_capemgr.8/slots

Note that the bone_capemgr.# varies between boards. My beaglebone black is 9, whilst white is 8. This command also doesnt quite work in ubuntu. Instead I use the following command in order to achieve the correct user rights to set the overlay.

sudo sh -c "echo enable-uart1 > /sys/devices/bone_capemgr.8/slots”

You can check that the overlay is set by viewing the /sys/devices/bone_capemgr.8/slots file, which should show the overlay you just added.

Leave a Reply