ARM Architecture

# Utilizing the Beaglebone PRU to realize realtime at low price

I work as an engineer in a synchrotron facility. A number of weeks in the past, I helped the individuals in command of the facility provide developments to combine a realtime management algorithm on a prototype platform: a BeagleBone Black (BBB) operating Linux. I had already labored with this board previously, and I discovered it very fascinating given its wonderful assets versus value ratio (round 40 euros). This time, I used to be impressed by its realtime capabilities. I assumed it could be a good suggestion to share my expertise right here.

On this software, the management loop core algorithm seems as follows:

whereas (1)
{timer_wait();
d = update_pid(pid_state, u);
pwm_set_duty(d);
}

The usual Linux working system cannot be used because the management loop has realtime constraints too exhausting to be met. Thus, typical designs run the loop an on a devoted unit, both a FPGA or perhaps a specialised microcontroller. This unit communicates with the principle CPU over a PCIe serial level to level hyperlink. A consumer software can work together with the facility provide interface over the community utilizing a TCP channel. This structure is depicted within the diagram under:

Whereas this structure works nicely, the facility provide unit (PSU) management board might price a number of hundred euros, or much more if a selected design is made in low portions. This is the reason the BBB was investigated: it’s shipped with an am335x CPU that integrates 2 independant realtime items. Through the use of these items to run the management loop, the FPGA and associated communication hyperlinks are eliminated and the general prices is essentially lowered. Additionally, the extent of integration eases iteration throughout the improvement course of.

The BBB board is commonly in contrast with the raspberry PI (RPI):

http://beagleboard.org/Merchandise/BeagleBone+Black

http://www.raspberrypi.org

Each are low-cost boards utilizing ARM CPUs. Nonetheless, I discover the BBB a way more fascinating platform than the RPI, each from a peripheral and {hardware} documentation perspective. The BBB depends across the Texas Devices am335x CPU:

http://www.ti.com/product/am3359

This CPU integrates 2 realtime items, often known as the PRUs:

http://processors.wiki.ti.com/index.php/Programmable_Realtime_Unit_Subsystem

Surprisingly sufficient, Texas Devices doesn’t help the PRU. As an alternative, there’s a group pushed effort that gives a full improvement equipment which incorporates documentation and code:

https://github.com/beagleboard/am335x_pru_package

A PRU has its personal execution core (clocked at 200MHz) and reminiscence. As I perceive, its foremost goal was to implement the equal of software program bitbanging (ie. SPI …) in devoted {hardware} items as a substitute of busying the principle CPU. Nonetheless, the PRU is way more highly effective than that: it has a wealthy instruction set, and even a multiply accumulate unit. It might probably set off or obtain interrupts, entry the principle reminiscence for sharing with the CPU. In our software, it additionally accesses the PWMs and browse ADCs values. It additionally has a restricted set of built-in peripherals. The next part particulars easy methods to setup the PRU.

First, it’s important to configure linux in order that it helps the PRU module. I personnally use LFS, a instrument to generate minimal linux based mostly system disk pictures:

https://github.com/texane/lfs

A documentation is accessible in:

doc/tex/foremost.pdf

There are nonetheless some hardcoded values right here and there that forestall LFS for use as is, however chances are you’ll discover it helpful.

Then, the PRU software program improvement equipment might be retrieved from right here:

https://github.com/beagleboard/am335x_pru_package

It accommodates all of the documentation, instruments and examples to get began with the PRU. The assembler is in:

pru_sw/utils/pasm_source

It generates binary information from meeting supply code. The generated information are then uploaded to the PRU utilizing a library often known as the appliance loader, obtainable in:

A python model is even obtainable in:

The next part exhibits an exemple on easy methods to use the PRU.

For example, I’ll use the next repository:

https://github.com/texane/pru_sdk

Right here once more, some variables are hardcoded however it’s fairly usable. The documentation listing accommodates the 4 pdf information that I used throughout this mission. The instance listing accommodates unit exams exhibiting easy methods to use the totally different {hardware} modules required by the mission (shared reminiscence, ADCs, PWMs, MAC and timers). We are going to invesigate the timer instance.

First, the Makefile is right here:

instance/pruss_iep/Makefile

It compiles 3 totally different information:

• a tool tree script,
• the principle program,
• the PRU program.

The machine script is right here:

instance/pruss_iep/pru_enable-00A0.dts

It’s compiled as an object file:

pru_enable-00A0.dtbo

dtbo information should be copied within the firmware listing, on this case:

/lib/firmware/pru_enable-00A0.dtbo

This object file is required by the linux kernel to allow the PRU. Extra typically, machine tree information are used to explain machine assets, as it may be seen in different examples from this repository. These to know extra can discover a good introduction in regards to the kernel machine tree right here:

http://free-electrons.com/pub/conferences/2013/elce/petazzoni-device-tree-dummies/

The principle program file is right here:

instance/pruss_iep/foremost.c

It’s a typical C program in command of loading the PRU program within the PRU unit. It periodically reads values from a reminiscence shared between the CPU and the PRU, and ultimately terminates the PRU program upon consumer sign reception.

Then comes the precise PRU program code. It may be discovered right here:

instance/pruss_iep/iep.p

As you may see, the assembler comes with a preprocessor, dealing with feedback and directives. Additionally, these of you acquainted with the GNU assembler syntax ought to really feel at house. I wont element the code right here, however be at liberty to ask questions. Word nonetheless that the PRU reference information accommodates all of the supplies associated to the instruction set.

Lastly, operating the appliance is completed utilizing the script:

instance/pruss_iep/run.sh

It assumes that you simply copied the machine tree object into:

/lib/firmware/pru_enable-00A0.dtbo

I hope this put up sparked the curiosity to analyze the BBB as a platform for software with realtime necessities. The PRU might not be supported by TI, however there are many communauty supported supplies obtainable on the internet. Listed below are a few of them I discovered fascinating:

http://analogdigitallab.org/articles/beaglebone-black-introduction-pru-icss

http://elinux.org/BeagleBone_PRU

https://github.com/modmaker/BeBoPr

TI lately launched a model of their Code Composer Studio for each Linux and Home windows which permits to compile C code for the PRU. It ships with an ordinary library, and has float kind help. I examined it solely briefly, so any suggestions is welcome. You could find extra data right here:

http://www.element14.com/group/group/knode/single-board_computers/next-gen_beaglebone/weblog/2014/04/30/bbb–pru-c-compiler