ECE497 BeagleBone PRU
Embedded Linux Class by Mark A. Yoder
- 1 Executive Summary
- 2 Installation Instructions
- 3 User Instructions
- 4 Finding Where to Access Things
- 5 Building and Running the GPIO_PWM_PRU Example
- 6 How the Assembly Code Works
- 7 How the C Code Works
- 8 Sending an array to the PRU
- 9 Highlights
- 10 Theory of Operation
- 11 Work Breakdown
- 12 Future Work
- 13 Conclusions
For this project, the objective is to explore the PRU of the BeagleBone, looking at both the limitations of implementation and how to implement tasks such as handling pulse width modulation. The project is more research intensive, as opposed to implementation intensive, and serves to bring together all of the sources found on the BeagleBone's PRU into one abbreviated document with examples of how to use it and the potential for extra projects. The ultimate goal here is to walk through step by step leading to the representation of a sinusoidal wave using pulse width modulation accessed from PRU and play the produced wave through a speaker.
As of now we have gathered information about the PRU, found memory locations that can be edited on the PRU and in C so that we can interact with functions outside of the PRU's capabilities, and implemented code on the PRU that simulates a pulse width modulation on a GPIO pin.
Give two sentences telling what isn't working.
- Actual PWM implementation
End with a two sentence conclusion.
The Git Hub is on the following link:
- Hardware: A push button for input and, though not necessarily required, some LEDs for messing with the GPIO pins and a speaker for listening to PWM approximated sine wave.
Note: When implementing the pulse width modulation, you may want to bias the wave around 0V instead of 1.65V. If this is the case, you may want to use a summer circui which will require an Op-Amp, a 2kohm and 1kohm resistor, and 3 resistors of the same value (Higher values preferable for lower power consumption), which will need to be connected as shown:
Unless you desire a louder output than capable with simple I/O pins, there is no additional hardware needed.
Always run the following before doing anything with the PRU:
beagle$ modprobe uio_pruss
Finding Where to Access Things
There are many locations in memory that are needed to access specific I/O pins on the BeagleBone. Some of these I/O pins can be found here:
The following are not found in the file, but are good addresses to know when accessing MUXs:
memory location: gpmc_a2.gpio1_18 (0x44e10848/0x848 = 0x0027), b NA, t NA mode: OMAP_PIN_INPUT_PULLDOWN | OMAP_MUX_MODE7 signals: gpmc_a2 | gmii2_txd3 | rgmii2_td3 | mmc2_dat1 | gpmc_a18 | pr1_mii1_txd2 | ehrpwm1A | gpio1_18
memory location: gpmc_a3.gpio1_19 (0x44e1084c/0x84c = 0x0027), b NA, t NA mode: OMAP_PIN_INPUT_PULLDOWN | OMAP_MUX_MODE7 signals: gpmc_a3 | gmii2_txd2 | rgmii2_td2 | mmc2_dat2 | gpmc_a19 | pr1_mii1_txd1 | ehrpwm1B | gpio1_19
memory location: gpmc_ad8.gpio0_22 (0x44e10820/0x820 = 0x0027), b NA, t NA mode: OMAP_PIN_INPUT_PULLDOWN | OMAP_MUX_MODE7 signals: gpmc_ad8 | lcd_data23 | mmc1_dat0 | mmc2_dat4 | ehrpwm2A | pr1_mii_mt0_clk | NA | gpio0_22
memory location: gpmc_ad9.gpio0_23 (0x44e10824/0x824 = 0x0027), b NA, t NA mode: OMAP_PIN_INPUT_PULLDOWN | OMAP_MUX_MODE7 signals: gpmc_ad9 | lcd_data22 | mmc1_dat1 | mmc2_dat5 | ehrpwm2B | pr1_mii0_col | NA | gpio0_23
Building and Running the GPIO_PWM_PRU Example
This example is located in the GPIO_PWM_PRU directory in the AM335x_PRU_BeagleBone git repository, and can be pulled with the following:
This example uses the gpio and delay loops to approximate a PWM using the user LEDs on the BeagleBone. It is based on an example provided by Lyren Brown and documented by boxysean at
In GPIO_PWM_PRU all of the complicated Makefiles and directories used to make a multitude of examples at once have been stripped away to allow the user to compile one individual program that will run on the PRU.
The readme.txt file in the GPIO_PWM_PRU directory provides a walkthrough for compiling and running blinker on the BeagleBone.
The first step to compiling a program for the PRU is to make sure prussdrv.c is made and up to date. This is the file provided by TI that contains all of the C functions that allow for communication with the PRU. To do this, do the following:
cd <directory>/AM335x_PRU_BeagleBone/GPIO_PWM_PRU/interface make CROSS_COMPILE=""
CROSS_COMPILE is specified as "" because this is running on the BeagleBone itself and the Makefile is setup to defaultly cross compile the code from another linux machine.
Once this is completed, the pasm_source must be set for the BeagleBone's linux operating system:
cd ../utils/pasm_source ./linuxbuild
Note: The above instructions need to be done for every time the BeagleBone boots up and these directories should be included with any code that you write for the PRU
Now, the BeagleBone is ready to compile the example code. Navigate to the example's root directory again:
cd ../../ make CROSS_COMPILE=""
This will compile the blinker.c file and output it to the bin folder. After this point, the assembly file needs to be compiled into a .bin file. This is done in the bin folder.
cd bin make
Now, there should be a blinker.bin file in the folder. running the blinker executabile will put the blinker.bin file on the PRU and start it running. Use the following:
How the Assembly Code Works
//in the overview talk about the period being 5ns
Registers r5 and r6 are the duty_cycle and period respectively. The duty_cycle is a number smaller than the period that the accumulator r4 counts up to before setting the output to zero. When the r4 = period, r4 resets and the output is set to 1. This gives the following for for OnTime and OffTime.
SecondsPerCycle = 5*10^-9 OnCycles = 2 + (duty_cycle)*3 + 2 OffCycles = 2 + (period - duty_cycle)*3 - 1 + 2 TotalCycles = 7 + (period)*3
These equations can be used to create a very exact PWM output by setting duty_cycle and period to the values you wish to use. The code that was compiled and run above has a period of about a second and a duty cycle of about 50%.
There are a few macros defined at the beginning of the program. These macros are the location of GPIO1's memory space, the location of its set registers and the location of its clear registers. The BeagleBone's GPIO pins must be turned off and on using these two different memory locations. Setting the set register to 0 does not turn off its respective GPIO pin.
r2 stores the value that is going to be written to either set or clear gpio. r3 sores the address that r2 will be written to. within the first 3 lines of PWM_ON these values are set such that r2 will turn on the user LEDs. The instruction that actually turns it on is SBBO. This takes the value of r2 and writes it to memory location r3 with an offset of 0.
Here is a complete guide to the PRU's Assembly Instructions from TI
How the C Code Works
FILL THIS IN LATER
Sending an array to the PRU
The initialization code provided by TI has a handy function for passing an array to the PRU. Each of the PRU cores have an 8kb data ram associated with them, and that data space can be populated from an external C program. The next example will make use of this function to pass different PWM duty cycles to the PRU. This will be largely based around the following function:
Here is where you brag about what your project can do.
Include a YouTube demo.
Theory of Operation
Give a high level overview of the structure of your software. Are you using GStreamer? Show a diagram of the pipeline. Are you running multiple tasks? Show what they do and how they interact.
10/22: We should have all research done. Update documentation with every Milestone.
10/26: We should be able to show something, an example or simple implementation.
10/29: Ability to send different lengths to turn on an LEDs.
10/31: Ability to send different lengths to multiple LEDs.
11/2: We should be able to demo our overall work, possibly have some things to fix before presentation.
11/4: Finalize presentation
Most of our research has come from internet resources listed below:
- TI PRU Resources
- Example for Running Code on the PRU
- PRU Assembly Instructions
- Initializing PRU in C
- AM335X Datasheet
Suggest addition things that could be done with this project.
Give some concluding thoughts about the project. Suggest some future additions that could make it even more interesting.
Embedded Linux Class by Mark A. Yoder