🛠 Programmer les cores PRU : le clignotement temps réel déterministe
Objectives
The real power of the AM335x: two 32-bit PRU-ICSS cores running at 200 MHz, wired directly to the I/O pins, capable of bit-banging and deterministic control loops while Linux runs alongside. You will assemble a PRU blink program in assembly, load it via the mainline remoteproc driver, and measure period stability. As the SRM reminds us: TI never supported this chain on this platform — it is the community ecosystem (am335x_pru_package) that carries the subject.
Hardware
- 1 BeagleBone Black
- Oscilloscope or logic analyzer on the output pin (or a simple LED + resistor for visual inspection)
- Packages: build-essential, device-tree-compiler; community toolchain am335x_pru_package
Complete Code
; blink.pasm — bascule la broche PRU0 R30.7 (à muxer vers une broche
; de nappe via un overlay gpmux)
.origin 0
.cinit
INIT SET R30, 0 ; efface le registre de sortie
LOOP SET R30.t7 ; bit 7 haut -> broche haute
CALL DELAY
CLR R30.t7 ; bit 7 bas -> broche basse
CALL DELAY
JMP LOOP
DELAY MOV R0, 200000000 ; ~1 s à l'horloge 200 MHz du PRU
WAIT SUB R0, R0, 1
QBEQ DONE, R0, 0
JMP WAIT
DONE HALT
# Assemblage avec la toolchain communautaire
git clone https://github.com/beagleboard/am335x_pru_package
cd am335x_pru_package && make -C pru_sw/app_loader && cd ..
export PATH=$PWD/pru_sw/utils:$PATH
clpr blink.pasm && link_pru blink.obj blink_out
sudo cp blink_out /lib/firmware/am335x-pru0-fw
# Chargement via remoteproc mainline (les noms exacts varient selon le noyau)
ls /sys/class/remoteproc/
echo start | sudo tee /sys/class/remoteproc/remoteproc0/state
cat /sys/class/remoteproc/remoteproc0/state # attendu : running
Expected Verification
The remoteproc state transitions to running, and the oscilloscope shows a perfectly regular square wave: the period does NOT depend on the Linux load (test with stress-ng --cpu 1 running alongside: the square wave does not shift by a single cycle). This demonstrates the real-time coprocessor.
Common Errors
- Forgetting pin muxing: R30.7 only becomes a header signal if an overlay (gpmux) routes it; otherwise, the PRU runs into a void.
- The firmware name must be exactly
am335x-pru0-fw(oram335x-pru1-fw) for the remoteproc driver to find it. - The remoteproc0/1 indices change depending on the kernel: script by core name, not by number.
- Confusing toolchains: TI SDK, community package, and mainline interfere with each other; pin down a single toolchain source.
- The SRM is explicit: "This feature is not supported by Texas Instruments" — in case of a bug, it is the community (and fragmented documentation) that responds, not TI support.
Other tutorials for this board
- Premier boot de la BeagleBone Black avec un seul câble mini-USB
- Comprendre les triggers en pilotant les 4 LED utilisateur
- Bouton et LED avec Adafruit_BBIO, la bibliothèque historique
- Lire l'ADC 12 bits sans griller le SoC : la règle des 1,8 V
- Ajouter une horloge temps réel sur le bus I2C des capes
- Micro-HDMI : exploiter les limites d'affichage de la BBB
Code examples for this board
clignotante.pyPythonbouton-gpio.pyPythoncapteur-i2c.shBashsurveillance-temperature.shBashcapteur-dht11.pyPythonservo-pwm-sysfs.shBash