Jump to: navigation, search

PyPRUSS on BeagleBone

PyPRUSS is a Python library for programming the PRUs on BeagleBone (Black). The library is open source (of course) and the source code is available from this bitbucket repository: https://bitbucket.org/intelligentagent/pypruss


PyPRUSS is available as a an OPKG from the thing-printer feed. This is the preferred way to install the software for Angstrom.

I'm assuming you are starting with Angstrom v2013.06:

 root@thing2:~# lsb_release -a
 Distributor ID: Angstrom
 Description:    Angstrom GNU/Linux v2013.06 (Core edition)
 Release:        v2013.06
 Codename:       Core edition

If you do not have this distro, have a look at this page: http://wiki.thing-printer.com/index.php?title=Installing_angstrom

Add the thing-printer feeds:

 echo 'src/gz replicape-base http://feeds.thing-printer.com/feeds/v2013.06/ipk/eglibc/armv7ahf-vfp-neon/machine/beaglebone' > /etc/opkg/replicape-base.conf

Update the feed:

 opkg update

Install the PyPRUSS packages. All necessary dependencies should be installed as well:

 opkg install pypruss

In order to compile PSU assembler files, you also need pasm:

 opkg install pasm

The PyPRUSS package has a dependency on libprussdrv which is then also installed. There is a bug in the libprussdrv package, so you need to manually make a soft link from /usr/lib/libprussdrv.so.1 to /usr/lib/libprussdrv.so:

 cd /usr/lib
 ln -s libprussdrv.so.1 libprussdrv.so


After you have installed the package, try running this example on your BBB:

 nano blinkled.py

Paste this Python code:

''' blinkled.py - test script for the PyPRUSS library
It blinks the user leds ten times'''

import pypruss

pypruss.modprobe()                              # This only has to be called once pr boot
pypruss.init()                                  # Init the PRU
pypruss.open(0)                                 # Open PRU event 0 which is PRU0_ARM_INTERRUPT
pypruss.pruintc_init()                          # Init the interrupt controller
pypruss.exec_program(0, "./blinkled.bin")	# Load firmware "blinkled.bin" on PRU 0
pypruss.wait_for_event(0)                       # Wait for event 0 which is connected to PRU0_ARM_INTERRUPT
pypruss.clear_event(0)                          # Clear the event
pypruss.pru_disable(0)                          # Disable PRU 0, this is already done by the firmware
pypruss.exit()                                  # Exit, don't know what this does.

Then start nano again:

 nano blinkled.p

and copy-paste this PRU Assembler code:

.origin 0
.entrypoint START


#define GPIO1 				0x4804c000		// The adress of the GPIO1 
#define GPIO_CLEARDATAOUT 	0x190
#define GPIO_SETDATAOUT 	0x194

    LBCO r0, C4, 4, 4					// Load Bytes Constant Offset (?)
    CLR  r0, r0, 4						// Clear bit 4 in reg 0
    SBCO r0, C4, 4, 4					// Store Bytes Constant Offset

    MOV r1, 10
    MOV r2, 7<<22
    SBBO r2, r3, 0, 4

    MOV r0, 0x00a00000
    SUB r0, r0, 1
    QBNE DELAY, r0, 0

    MOV r2, 7<<22
    SBBO r2, r3, 0, 4

    MOV r0, 0x00a00000
    SUB r0, r0, 1
    QBNE DELAY2, r0, 0
    SUB r1, r1, 1
    QBNE BLINK, r1, 0

    MOV R31.b0, PRU0_ARM_INTERRUPT+16   // Send notification to Host for program completion

You need to compile the assembler code:

 pasm -b blinkled.p 

Then you can run the Python script:

 python blinkled.py

You should see the four user LEDs on the BeagleBone flash 10 times with about a second interval.