PRU Pin Toggle

This is a followup to a past post on the PRU’s. I’m looking to provide a clock pulse in the 100kHz range plus send additional pulses out of the PRU and receive a couple other pulses back from a sensor.

I’ve been able to load the device tree overlays for pins P8.11, P8.12, P8.15, P8.16 and P9.24 with no problems. For output, the overlay sets the mode for pins P8.11 and P8.12 to 0x06. Plus, I’ve been able to generate the clock pulse on P8.11 and the other needed outgoing pulse on P8.12 using assembly language but I get the general impression that going forward the preferred method for programming the PRU’s is with C. So for testing I’ve tried to get PRU_gpioToggle.c to work but for some reason I can’t get pins P8.11 or P8.12 to toggle. Instead, they just read a constant 0 volts. In the code, gpio is set to 0x000F thinking this should be pin 15, as in pr1_pru0_pru_r30_15. Not being certain for the format of this number I’ve also tried 0x1111 but with the same results.

PRU_gpioToggle compiles OK and the .out file is copied to /lib/firmware/am335x-pru0-fw The PRU’s are stopped and restarted with rmmod -f pru_rproc and modprobe pru_rproc. dmesg shows they stop and start as expected. However, still no luck with the toggling.

uname -a reads 4.4.54-ti-r93 #1 SMP.

Does anybody have any idea what I’m doing wrong?


Mike Pitman

R30 is a bit field of GPIO outputs. Try “__R30 ^= 0xffff” to toglle all 16 PRU outputs.


Good news. The issue appears to be resolved by using a bit shift as in:

gpio = 1 << 15; // to toggle P8.11
gpio = 1 << 14; // to toggle P8.12