Now that we've manually enabled an overlay, let's take an overlay created and used in the Adafruit BBIO Python library for enabling the SPI0 device and bus. You can find the latest copy of this overlay at the Adafruit Github repository for Adafruit_BBIO.

Below is a copy of the overlay for SPI0 that we'll use to compile, and enable:

/ {
    compatible = "ti,beaglebone", "ti,beaglebone-black";

    /* identification */
    part-number = "ADAFRUIT-SPI0";

    /* version */
    version = "00A0";

    fragment@0 {
        target = <&am33xx_pinmux>;
        __overlay__ {
            spi0_pins_s0: spi0_pins_s0 {
                pinctrl-single,pins = <
                  0x150 0x30 /* spi0_sclk, INPUT_PULLUP | MODE0 */
                  0x154 0x30 /* spi0_d0, INPUT_PULLUP | MODE0 */
                  0x158 0x10 /* spi0_d1, OUTPUT_PULLUP | MODE0 */
                  0x15c 0x10 /* spi0_cs0, OUTPUT_PULLUP | MODE0 */

    fragment@1 {
        target = <&spi0>;
        __overlay__ {
             #address-cells = <1>;
             #size-cells = <0>;

             status = "okay";
             pinctrl-names = "default";
             pinctrl-0 = <&spi0_pins_s0>;

             spidev@0 {
                 spi-max-frequency = <24000000>;
                 reg = <0>;
                 compatible = "spidev";
             spidev@1 {
                 spi-max-frequency = <24000000>;
                 reg = <1>;
                 compatible = "spidev";
Quickly looking at the above overlay, we can see it follows the same pattern as the overlay for UART1. there are two fragments, with the first one utilizing the pinctrl-single driver to mux the pins. We're using 4 of the SPI0 pins, setting everything to Mode 0. Then, fragment@1 is targeting the spi0 device with the proper pins, and setting various parameters specific to using the spi device, such as the 'spi-max-frequency'. You can see the available options in the spi-bus documentation.

Navigate to your home directory, and open nano to copy and paste the new file. You'll need to save it exactly as named below as well:
root@beaglebone:/tmp# cd ~
root@beaglebone:~# nano ADAFRUIT-SPI0-00A0.dts
Next, we'll execute the command to compile this file into the device tree overlay compiled format (.dtbo):
dtc -O dtb -o ADAFRUIT-SPI0-00A0.dtbo -b 0 -@ ADAFRUIT-SPI0-00A0.dts
The compilation should be nearly instant, and you should end up with the newly compiled file:
root@beaglebone:~# ls -ltr
-rw-r--r-- 1 root root 1255 Jul 29 14:33 ADAFRUIT-SPI0-00A0.dts
-rw-r--r-- 1 root root 1042 Jul 29 14:35 ADAFRUIT-SPI0-00A0.dtbo
Let's break down the options used to compile the overlay.

To start with we're using the device tree compiler (dtc). Everything required to compile DT overlays are included with the latest Angstrom distribution.

-O dtb is the output format. We're outputting device tree binaries.
-o is the output filename.
-b 0 is setting the physical boot CPU. (a zero)
-@ generates a symbols node as part of the dynamic DT loading of the overlay

You'll know if you don't have a new enough version of dtc if the compiler complains about the missing -@ flag. You can attempt an upgrade of dtc by executing the following (this may need to be done on Ubuntu for now):
wget -c
chmod +x

This guide was first published on Jul 29, 2013. It was last updated on Aug 16, 2013.

This page (Compiling an Overlay) was last updated on Jul 28, 2013.

Text editor powered by tinymce.