Welcome to new site for BeagleBoard.org docs!

Getting Started#

We assume you have some experience with the Beagle and are here to learn about the PRU. This chapter discusses what Beagles are out there, how to load the latest software image on your Beagle, how to run the Visual Studio Code IDE and how to blink an LED. ======= latest software image on your Beagle, how to run the Visual Studio Code (VS Code) IDE and how to blink an LED.

If you already have your Beagle and know your way around it, you can find the code at https://git.beagleboard.org/beagleboard/pru-cookbook-code and book contents at https://git.beagleboard.org/docs/docs.beagleboard.io under the books/pru-cookbook directory.

Selecting a Beagle#

Problem#

Which Beagle should you use?

Solution#

http://beagleboard.org/boards lists the many Beagles from which to choose. Here we’ll give examples for the venerable BeagleBone Black, the robotics BeagleBone Blue, tiny PockeBeagle and the powerful AI. All the examples should also run on the other Beagles too.

Discussion#

BeagleBone Black#

If you aren’t sure which Beagle to use, it’s hard to go wrong with the BeagleBone Black. It’s the most popular member of the open hardware Beagle family.

BeableBone Black

Fig. 541 BeagleBone Black#

The Black has:

  • AM335x 1GHz ARM® Cortex-A8 processor

  • 512MB DDR3 RAM

  • 4GB 8-bit eMMC on-board flash storage

  • 3D graphics accelerator

  • NEON floating-point accelerator

  • 2x PRU 32-bit microcontrollers

  • USB client for power & communications

  • USB host

  • Ethernet

  • HDMI

  • 2x 46 pin headers

See http://beagleboard.org/black for more details.

BeagleBone Blue#

The Blue is a good choice if you are doing robotics.

BeagleBone Blue

Fig. 542 BeagleBone Blue#

The Blue has everything the Black has except it has no Ethernet and no HDMI. But it also has:

  • Wireless: 802.11bgn, Bluetooth 4.1 and BLE

  • Battery support: 2-cell LiPo with balancing, LED state-of-charge monitor

  • Charger input: 9-18V

  • Motor control: 8 6V @ 4A servo out, 4 bidirectional DC motor out, 4 quadrature encoder in

  • Sensors: 9 axis IMU (accels, gyros, magnetometer), barometer, thermometer

  • User interface: 11 user programmable LEDs, 2 user programmable buttons

In addition you can mount the Blue on the EduMIP kit as shown in BeagleBone Blue EduMIP Kit to get a balancing robot.

BeagleBone Blue EduMIP Kit

Fig. 543 BeagleBone Blue EduMIP Kit#

https://www.hackster.io/53815/controlling-edumip-with-ni-labview-2005f8 shows how to assemble the robot and control it from LabVIEW.

PocketBeagle#

The PocketBeagle is the smallest member of the Beagle family. It is an ultra-tiny-yet-complete Beagle that is software compatible with the other Beagles.

PocketBeagle

Fig. 544 PocketBeagle#

The Pocket is based on the same processor as the Black and Blue and has:

  • 8 analog inputs

  • 44 digital I/Os and

  • numerous digital interface peripherals

See http://beagleboard.org/pocket for more details.

BeagleBone AI#

If you want to do deep learning, try the BeagleBone AI.

BeableBone AI

Fig. 545 BeagleBone AI#

The AI has:

  • Dual Arm® Cortex®-A15 microprocessor subsystem

  • 2 C66x floating-point VLIW DSPs

  • 2.5MB of on-chip L3 RAM

  • 2x dual Arm® Cortex®-M4 co-processors

  • 4x Embedded Vision Engines (EVEs)

  • 2x dual-core Programmable Real-Time Unit and Industrial Communication SubSystem (PRU-ICSS)

  • 2D-graphics accelerator (BB2D) subsystem

  • Dual-core PowerVR® SGX544™ 3D GPU

  • IVA-HD subsystem (4K @ 15fps encode and decode support for H.264, 1080p60 for others)

  • BeagleBone Black mechanical and header compatibility

  • 1GB RAM and 16GB on-board eMMC flash with high-speed interface

  • USB type-C for power and superspeed dual-role controller; and USB type-A host

  • Gigabit Ethernet, 2.4/5GHz WiFi, and Bluetooth

  • microHDMI

  • Zero-download out-of-box software experience with Debian GNU/Linux

Installing the Latest OS on Your Bone#

Problem#

You want to find the latest version of Debian that is available for your Bone.

Solution#

On your host computer open a browser and go to http://www.beagleboard.org/distros.

Todo

Update links

This shows you two current choices of recent Debian images, one for the BeagleBone AI (AM5729 Debian 10.3 2020-04-06 8GB SD IoT TIDL) and one for all the other Beagles ( AM3358 Debian 10.3 2020-04-06 4GB SD IoT). Download the one for your Beagle.

Latest Debian images

Fig. 546 Latest Debian images#

It contains all the packages we’ll need.

Flashing a Micro SD Card#

Problem#

I’ve downloaded the image and need to flash my micro SD card.

Solution#

Get a micro SD card that has at least 4GB and preferably 8GB.

There are many ways to flash the card, but the best seems to be Etcher by https://www.balena.io/. Go to https://www.balena.io/etcher/ and download the version for your host computer. Fire up Etcher, select the image you just downloaded (no need to uncompress it, Etcher does it for you), select the SD card and hit the Flash button and wait for it to finish.

Ether

Fig. 547 Etcher#

Once the SD is flashed, insert it in the Beagle and power it up.

Visual Studio Code IDE#

Problem#

How do I manage and edit my files?

Solution#

The image you downloaded includes Visual Studio Code, a web-based integrated development environment (IDE) as shown in Visual Studio Code IDE.

The Visual Studio Code IDE

Fig. 548 Visual Studio Code IDE#

Just point the browser on your host computer to http://192.168.7.2:3000 and start exploring. You may also want to upgrade bb-code-server to pull in the latest updates. Another route to take is to apply this command to boot the service called bb-code-server.

sudo systemctl start bb-code-server.service

If you want the files in your home directory to appear in the tree structure click the settings gear and select Show Home in Favorites as shown in Visual Studio Code Showing Home files.

Vidual Studio Code showing home files

Fig. 549 Visual Studio Code Showing Home files#

Just point the browser on your host computer to http://192.168.7.2:3000 and start exploring.

If you want to edit files beyond your home directory you can link to the root file system by:

bone:~$ cd
bone:~$ ln -s / root
bone:~$ cd root
bone:~$ ls
bbb-uEnv.txt  boot  etc   ID.txt  lost+found  mnt           opt   root  sbin  sys  usr
bin           dev   home  lib     media       nfs-uEnv.txt  proc  run   srv   tmp  var

Now you can reach all the files from VS Code.

Getting Example Code#

Problem#

You are ready to start playing with the examples and need to find the code.

Solution#

You can find the code on the PRU Cookbook Code project on git.beagleboard.org: https://git.beagleboard.org/beagleboard/pru-cookbook-code. Just clone it on your Beagle.

bone:~$ cd /opt/source
bone:~$ git clone https://git.beagleboard.org/beagleboard/pru-cookbook-code
bone:~$ cd pru-cookbook-code
bone:~$ sudo ./install.sh
bone:~$ ls -F
01case/   03details/  05blocks/  07more/  README.md
02start/  04details/  06io/      08ai/

Each chapter has its own directory that has all of the code.

bone:~$ cd 02start/
bone:~$ ls
hello.pru0.c  hello.pru1_1.c  Makefile  setup.sh
ai.notes         hello2.pru1_1.c  hello2.pru2_1.c  Makefile
hello2.pru0.c    hello2.pru1.c    hello.pru0.c     setup2.sh*
hello2.pru1_0.c  hello2.pru2_0.c  hello.pru1_1.c   setup.sh*

Go and explore.

Blinking an LED#

Problem#

You want to make sure everything is set up by blinking an LED.

Solution#

The ‘hello, world’ of the embedded world is to flash an LED. hello.pru0.c is some code that blinks the USR3 LED ten times using the PRU.

Todo

The ‘s and _’s in the code are messing with the formatting.

Listing 86 hello.pru0.c#
 1#include <stdint.h>
 2#include <pru_cfg.h>
 3#include "resource_table_empty.h"
 4#include "prugpio.h"
 5
 6volatile register unsigned int __R30;
 7volatile register unsigned int __R31;
 8
 9void main(void) {
10	int i;
11
12	uint32_t *gpio1 = (uint32_t *)GPIO1;
13	
14	/* Clear SYSCFG[STANDBY_INIT] to enable OCP master port */
15	CT_CFG.SYSCFG_bit.STANDBY_INIT = 0;
16
17	for(i=0; i<10; i++) {
18		gpio1[GPIO_SETDATAOUT]   = USR3;	// The the USR3 LED on
19
20		__delay_cycles(500000000/5);    	// Wait 1/2 second
21
22		gpio1[GPIO_CLEARDATAOUT] = USR3;
23
24		__delay_cycles(500000000/5); 
25
26	}
27	__halt();
28}
29
30// Turns off triggers
31#pragma DATA_SECTION(init_pins, ".init_pins")
32#pragma RETAIN(init_pins)
33const char init_pins[] =  
34	"/sys/class/leds/beaglebone:green:usr3/trigger\0none\0" \
35	"\0\0";

hello.pru0.c

Later chapters will go into details of how this code works, but if you want to run it right now do the following.

bone:~$ cd /opt/source
bone:~$ git clone https://git.beagleboard.org/beagleboard/pru-cookbook-code
bone:~$ cd pru-cookbook-code/02start
bone:~$ sudo ../install.sh

Tip

If the following doesn’t work see Compiling with clpru and lnkpru for installation instructions.

Running Code on the Black or Pocket#

bone:~$ make TARGET=hello.pru0
/opt/source/pru-cookbook-code/common/Makefile:27: MODEL=TI_AM335x_BeagleBone_Green_Wireless,TARGET=hello.pru0,COMMON=/opt/source/pru-cookbook-code/common
-    Stopping PRU 0
CC  hello.pru0.c
"/opt/source/pru-cookbook-code/common/prugpio.h", line 53: warning #1181-D: #warning directive: "Found else"
LD  /tmp/vsx-examples/hello.pru0.o
-   copying firmware file /tmp/vsx-examples/hello.pru0.out to /lib/firmware/am335x-pru0-fw
-    Starting PRU 0
write_init_pins.sh
writing "none" to "/sys/class/leds/beaglebone:green:usr3/trigger"
MODEL   = TI_AM335x_BeagleBone_Green_Wireless
PROC    = pru
PRUN    = 0
PRU_DIR = /sys/class/remoteproc/remoteproc1

Tip

If you get the following error:

cp: cannot create regular file '/lib/firmware/am335x-pru0-fw': Permission denied

Run the following command to set the permissions.

bone:~$ sudo chown debian:debian /lib/firmware/am335x-pru*

Running Code on the AI#

bone$ make TARGET=hello.pru1_1
/var/lib/code-server/common/Makefile:28: MODEL=BeagleBoard.org_BeagleBone_AI,TARGET=hello.pru1_1
-    Stopping PRU 1_1
CC  hello.pru1_1.c
"/var/lib/code-server/common/prugpio.h", line 4: warning #1181-D: #warning directive: "Found AI"
LD  /tmp/code-server-examples/hello.pru1_1.o
-   copying firmware file /tmp/code-server-examples/hello.pru1_1.out to /lib/firmware/am57xx-pru1_1-fw
write_init_pins.sh
writing "none" to "/sys/class/leds/beaglebone:green:usr3/trigger"
-    Starting PRU 1_1
MODEL   = BeagleBoard.org_BeagleBone_AI
PROC    = pru
PRUN    = 1_1
PRU_DIR = /dev/remoteproc/pruss1-core1
rm /tmp/code-server-examples/hello.pru1_1.o

Look quickly and you will see the USR3 LED blinking.

Later sections give more details on how all this works.