# How to enable the PRU's on the Beaglebone black?



## JWB (Jun 16, 2017)

I want to use the PRU's with FreeBSD on the BeagleBone black

version:

```
# uname -a
FreeBSD beaglebone 12.0-CURRENT FreeBSD 12.0-CURRENT #0 r319859: Tue Jun 13 00:26:37 UTC 2017     root@releng3.nyi.freebsd.org:/usr/obj/arm.armv6/usr/src/sys/BEAGLEBONE  arm
```
I installed pructl with pkg.  

```
# pructl -t ti
pructl: unable to allocate PRU structure: No such file or directory
```
 I do not see a device node in /dev and no PRU device in dmesg.

How can the PRU's on the beaglebone black be enabled?


----------



## SirDice (Jun 19, 2017)

I don't know how many incarnations the BBB has but I can image not all variants are supported at the moment.

https://bitbucket.org/rpaulo/libpru/overview


----------



## JWB (Jun 19, 2017)

Thank you for the answer. 
The BBB has 2 PRU's. With FreeBSD 10 I saw a device node for the PRU. FreeBSD 12-current does not show it. Maybe this is a bug in FreeBSD 12-current but it could also be my ignorance.


----------



## tingo (Jun 20, 2017)

Perhaps one ore more missing device tree files? Have you compared the  files in FreeBSD 10 with those ins FreeBSD -CURRENT?


----------



## JWB (Jun 20, 2017)

https://svnweb.freebsd.org/base/release/10.3.0/sys/boot/fdt/dts/arm/ contains some files for the BBB but https://svnweb.freebsd.org/base/head/sys/boot/fdt/dts/arm/ does not.
Could this be the cause of a missing device node?

I installed FreeBSD 10.3 and it gives me:


```
freebsd@beaglebone:~ % uname -a
FreeBSD beaglebone 10.3-RELEASE FreeBSD 10.3-RELEASE #0 r297264: Fri Mar 25 06:52:50 UTC 2016     root@releng1.nyi.freebsd.org:/usr/obj/arm.armv6/usr/src/sys/BEAGLEBONE  arm
freebsd@beaglebone:~ % dmesg | grep pruss
ti_pruss0: <TI Programmable Realtime Unit Subsystem> mem 0x4a300000-0x4a37ffff irq 20,21,22,23,24,25,26,27 on simplebus0
ti_pruss0: AM33xx PRU-ICSS
freebsd@beaglebone:~ %
```


----------



## SirDice (Jun 21, 2017)

JWB said:


> https://svnweb.freebsd.org/base/release/10.3.0/sys/boot/fdt/dts/arm/ contains some files for the BBB but https://svnweb.freebsd.org/base/head/sys/boot/fdt/dts/arm/ does not.
> Could this be the cause of a missing device node?


That's certainly possible. Keep in mind that HEAD (aka -CURRENT) is an unsupported development branch.


----------



## aragats (Jun 21, 2017)

JWB , you can simply copy .dts files over, also, most likely, you can re-use the compiled ones (.dtbs) since they are just descriptions, they do not provide any functionality, just letting the kernel know what exists and how the pins have to be configured.


----------



## obsigna (Jun 22, 2017)

Since 10.3-RELEASE (or was it 11), FreeBSD adopted the so-called vendor distribution of the device tree description files, however, I cannot find anymore the notice when exactly this happened. Anyway, the result was that some devices on the Beaglebone Black disappeared in 12-CURRENT. For example, in order to activate the ADC on my Beaglebone Black, I needed to create a DT overlay (s. Enable the ADC device of the Beaglebone Black on FreeBSD 12.0-CURRENT).

I just tried the overlay approach for activating the PRU as well, but unfortunately this didn't work out -- perhaps because I don't know all the DT overlay magics, and so I ended up hacking the PRUSS code directly into the main DTB as follows:


```
# uname -a
FreeBSD CyStat-BBB 12.0-CURRENT FreeBSD 12.0-CURRENT #0 r320095: Mon Jun 19 19:07:02 UTC 2017
```

decompile the current device tree blob:
`cd /boot/dtb`
`dtc -I dtb -O dts -o am335x-boneblack.dts am335x-boneblack.dtb`


save the original .dtb file:
`mv am335x-boneblack.dtb am335x-boneblack.dtb.orig`


edit the device tree source, adding the pruss@4A300000 entries below the rng records:
`nano am335x-boneblack.dts`

```
interrupts = <0x6f>;
            linux,phandle = <0xca>;
            phandle = <0xca>;
        };

        pruss@4A300000 {
            compatible = "ti,pruss-v2";
            reg = <0x4a300000 0x80000>;
            interrupt-parent = <0x1>;
            interrupts = <0x14 0x15 0x16 0x17 0x18 0x19 0x1a 0x1b>;
        };
```


```
sham = "/ocp/sham@53100000";
        aes = "/ocp/aes@53500000";
        mcasp0 = "/ocp/mcasp@48038000";
        mcasp1 = "/ocp/mcasp@4803C000";
        rng = "/ocp/rng@48310000";
        pruss = "/ocp/pruss@4A300000";
        vmmcsd_fixed = "/fixedregulator0";
        clk_mcasp0_fixed = "/clk_mcasp0_fixed";
        clk_mcasp0 = "/clk_mcasp0";
        dailink0_master = "/sound/simple-audio-card,cpu";
    };
```

compile the edited device tree source file into the new device tree binary:
`dtc -I dts -O dtb -o am335x-boneblack.dtb am335x-boneblack.dts`


restart the Beaglebone Black:


```
# dmesg | grep pruss
ti_pruss0: <TI Programmable Realtime Unit Subsystem> mem 0x4a300000-0x4a37ffff irq 53,54,55,56,57,58,59,60 on simplebus0
ti_pruss0: AM33xx PRU-ICSS
```


```
# ls -l /dev/pruss*
crw-------  1 root  wheel  0x2e Jun 21 19:34 /dev/pruss0
```

EDIT: Corrected the commands for (de)compiling the device tree (steps 1 & 4), s. message of JWB below.


----------



## Phishfry (Jun 22, 2017)

The Vendor DTS switchover happened in April 2015
https://lists.freebsd.org/pipermail/freebsd-arm/2015-April/010889.html


----------



## JWB (Jun 22, 2017)

Obsigna, I followed your instructions and it worked great:

```
# uname -a
FreeBSD beaglebone 12.0-CURRENT FreeBSD 12.0-CURRENT #0 r319859: Tue Jun 13 00:26:37 UTC 2017     root@releng3.nyi.freebsd.org:/usr/obj/arm.armv6/usr/src/sys/BEAGLEBONE  arm
root@beaglebone:~ # dmesg | grep pruss
ti_pruss0: <TI Programmable Realtime Unit Subsystem> mem 0x4a300000-0x4a37ffff irq 53,54,55,56,57,58,59,60 on simplebus0
ti_pruss0: AM33xx PRU-ICSS
root@beaglebone:~ #
```
I had to correct a typo for the command to compile the edited dts file to dtb:

```
# dtc -I dts -O dtb -o am335x-boneblack.dtb am335x-boneblack.dts
```


----------



## aragats (Jun 29, 2017)

Those things become much easier now with the latest u-boot I've build yesterday.
Now u-boot takes care of device tree descriptions and overlays, see http://elinux.org/Beagleboard:BeagleBoneBlack_Debian#U-Boot_Overlays .
I haven't tried it FreeBSD yet, but it perfectly works with Linux.


----------

