Skip to content

Commit e81e04d

Browse files
committed
Write README documenting the current LED code
1 parent 4f87d35 commit e81e04d

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,40 @@
11
# Pybricks EV3 PRU firmware source code
22

33
This is the source code for the firmware which runs on the Programmable Real-Time Unit Subsystem (PRUSS) of the EV3.
4+
5+
## Quick Start
6+
7+
1. Obtain the GCC `pru-elf` toolchain. Prebuilt Linux binaries are available [here](https://github.com/dinuxbg/gnupru/releases). Ensure that the tools are in your `PATH` (for example, by running `pru-gcc -v`)
8+
2. Run `make` in this directory
9+
3. The binary file which will be embedded into Pybricks is `pru_ledpwm.bin`
10+
3. If you want to examine the resulting assembly code, run `pru-objdump -dS pru_ledpwm.elf`
11+
12+
## What is the purpose of this code?
13+
14+
The PRU is a small custom microcontroller core embedded inside the larger AM1808 System-on-Chip which powers the Mindstorms EV3. Although it has access to most of the system, the intended use-case for the PRU is to offload tasks which require "real-time" performance. Moving tasks from the main ARM CPU to the PRU frees up the main CPU from having to handle these events.
15+
16+
The PRUs have their own instruction and data memory separate from the ARM CPU, and they are relatively small, so a common developer workflow is to embed precompiled PRU firmware blobs into the (much larger) ARM code. The GitHub Actions workflows in this repository help automate this.
17+
18+
The AM1808 contains two PRU cores, called PRU0 and PRU1. PRU0 is used to provide two additional UART serial ports for sensor ports 3 and 4, and this is done using a TI-provided software UART library. PRU1 runs the code in this repository.
19+
20+
Currently, PRU1 is used to implement brightness control for the front LEDs on the EV3 brick.
21+
22+
## Functionality and resources used
23+
24+
This firmware runs on PRU1.
25+
26+
Data is exchanged between the ARM CPU and the PRU firmware using shared memory located in the second 64 KiB of the on-chip RAM (i.e starting at address `0x8001_0000`).
27+
28+
This firmware requires `CONTABPROPTR1.C30` to be set such that the constant table entry points to the shared memory (i.e. the field should have the value `0x0100`).
29+
30+
### LED PWM functionality
31+
32+
This code allows varying the brightness of the front LEDs on the EV3 brick (the red/green LEDs in the directional button pad). This is done by turning them on and off for a specified percentage of the time (pulse-width modulation). PWM is being implemented entirely in software and not via a dedicated PWM peripheral.
33+
34+
There are four LEDs, and their brightnesses can be controlled independently. Each LED's brightness can be a value from 0 to 255 inclusive.
35+
36+
The timing for the LED PWM is derived from a hardware timer, Timer0.TIM34. Timer0.TIM34 is expected to count continuously with a period of $256\times256$ (i.e. counting from 0 to 0xffff inclusive).
37+
38+
The LEDs are turned on and off through the PRU's special register R30. This requires the GPIO alternate function to be programmed to select the PRU1 function.
39+
40+
The PRU firmware expects these resources to be set up ahead of time by the ARM firmware.

0 commit comments

Comments
 (0)