BeagleBone Black programmable realtime unit (PRU) Hello World – Part 1


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).


/ {
  /* 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";

    /* target in the device tree */  
    target = <&am33xx_pinmux>;

    /* The overlay we define */
      /* 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 >;

    target = <&pruss>;
      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:


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 syntax
Official webpage
Very well written article about gpios and device trees on the bbb with discussions
About the PRU Sub System

Table of contents

Part 0 – Introduction
Part 1 – About device trees and overlays (You are here)
Part 2 – Programming


27 thoughts on “BeagleBone Black programmable realtime unit (PRU) Hello World – Part 1

  1. Hi, it was a great tutotrial to start with but I’m stuck with the final proceedure where you run the binaries generated by pasm assembler code for the code you have written. I’m expereincing the follwing issue when I run this-

    ./pwm or sudo ./pwm
    Segmentation fault

    Im really struggling to cope up with other tutorials with one or the other dead ends. Can you please help me with this?

    Thank you.


    1. Hello!
      Unfortunately the segmentation fault error can mean a lot of things in this context and it’s usually the only error that I get when programming the PRU, regardless of what goes wrong.

      But usually it either means that you try to access an invalid address, which we don’t in this example, or that the overlay was not loaded properly or the PRU program did not end the last time and the system is now unable to halt it, or the PRU code wrong.

      So when I get this error, I usually check, if I already loaded the necessary overlay:

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

      and if it shows up, I restart the system and then I reload the overlay right after the reboot.

      Just one quick thing to note: If you change the PRU code, so that it uses different GPIO pins or devices, you will also have to change the device-tree overlay.

      Hope this helps so far, feel free to let me know or to write me an email if you need further help (see the contact page for the address)!


      1. HI, Thanks for making time to reply. I did figure a way out thanks for your help. Turns out that the proceedure quoted above worked for me when i downgraded to kernel version 3.8 (from 4.9). To add to this –

        1.does the device tree binary or .dtbs varies for different kernel versions ?

        It may be insesitive of me to ask this but DTC version is all that metters right ?(for generation of .dtbs from .dts) Having asked this since the syntax of some .dts file changed in lower version of kerneal compared to that of one I used I’m bit confuded about the working nature of DTC(DEVICE TREE COMPILER).

        Loads of thanks.

        Liked by 1 person

      2. Good to hear that it’s working now! You have an interesting point here. I personally never thought that it makes a difference, what Kernel version one uses. I’d also say, that the compiler version is the only thing that matters, but I have to admit that I don’t know exactly, but I will look into this at some point, because this is something I haven’t thought about so far. But from what I’ve read so far, the newer kernel versions seem to occupy some other GPIOs that then can not be used which then leads to a segmentation fault. But huge thanks for pointing this issue out, I’ll have to further investigate this and I might update the articles according to what I find out!


  2. I really like what you guys tend to be up too. This type of clever work and coverage! Keep up the terrific works guys I’ve added you guys to our blogroll.

    Liked by 1 person

  3. Your style is very unique in comparison to other folks I have read stuff from.
    Many thanks for posting when you’ve got the opportunity, Guess I’ll just
    bookmark this page.


  4. Pretty nice post. I simply stumbled upon your
    weblog and wished to mention that I have really enjoyed surfing around your
    weblog posts. In any case I will be subscribing for your feed and I hope you write once
    more soon!

    Liked by 1 person

  5. I don’t know whether it’s just me or if everybody else encountering problems
    with your site. It appears as though some of the written text within your content are running off the screen. Can somebody else
    please comment and let me know if this is happening to them as well?
    This may be a issue with my internet browser because I’ve had this happen before.


Leave your two cents, comment here!

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.