Introduction

This part covers the device tree overlay for our little Hello-World Example. I will not cover Linux device trees here or why they are useful because there are already a lot of good sources out there that do so.

The overlay source-code

This part will be pretty short. I will just throw some code at you and explain what it does. Once you have read at least one of the articles linked at the end of this page, you should understand what it does, even without comments (Yes it’s that simple).

/dts-v1/;
/plugin/;

/ {
  /* This overlay is compatible with the following devices */
  compatible = "ti,beaglebone", "ti,beaglebone-black";

  /* overlay identification */
  part-number = "BB-WAVE-GEN";
  version = "00A0";

  /* Define the resources used by this overlay */
  exclusive-use = "P9.27", "pru0";

  fragment@0{
    /* target in the device tree */  
    target = <&am33xx_pinmux>;

    /* The overlay we define */
    __overlay__{
      /* Change the GPIO-Pin mode according to the pinmuxing table */
      pru_pru_pins: pinmux_pru_pru_pins{
        /* The first value (0x1a4) is the offset of the pin's address */
        /* Value two is the pin-multiplexing (pinmux) mode, we want */
        /* 25 represents mode 5, output, pull-up enabled */
        /* See the pinmux table (see below) */
        pinctrl-single,pins = < 0x1a4 0x25 >;
      };
    };
  };

  fragment@2{
    target = <&pruss>;
    __overlay__{
      status = "okay";
      pinctrl-names = "default";
      pinctrl-0 = <&pru_pru_pins>;
    };
  };
};

The Pinmuxing (Pin-Multiplexing) tables are available for download here.

Compiling the code

After you have copied the above code to your beaglebone black (save it as BB-WAVE-GEN-00A0.dts), you’ll have to compile it. To do so, use the following bash command:

dtc -I dts -O dtb -o BB-WAVE-GEN-00A0.dtbo -@ BB-WAVE-GEN-00A0.dts

After the compilation finished (with no errors), you’ll see a newly generated dtbo file. Copy it to /lib/firmware and change into the firmware directory.

Loading the overlay

Now you have to load the overlay so that the system can configure your hardware accordingly. To load the overlay, echo it into the slots file, which is located at:

/sys/devices/bone_capemgr.*/

The “*” is a wildcard. It is there because the number it represents changes from system to system. If you leave the “*” where it is, the system will extend the correct number for you. So to load your overlay, you have to enter the following command:

echo ./BB-WAVE-GEN:00A0.dtbo > /sys/devices/bone_capemgr.*/slots

If there is no output after you entered the above command, the overlay was loaded successfully. If there is, check the error message with dmesg and solve eventual problems. If you catenate the contents of the slots-file you can verify whether or not the overlay was loaded correctly:

Bildschirmfoto 2016-05-23 um 20.39.32

As you can see, the last line (overlay #6) shows the overlay from above. You can unload it by echoing “-6” to the slots file.

Further readings

A very nice guide about device tree overlays (Adafruit)About the theory behind device trees and the syntaxOfficial devicetree.org webpageVery well written article about gpios and device trees on the bbb with discussionsAbout the PRU Sub System

Table of contents

Part 0 - Introduction

comment-banner