June 14, 2020

Mapping PRU pins on Header with R30,r31


On Pocket beagle, Beaglbone black , beagle Wireless etc there are 2 Programable real time units which can operate at 200MHz and are suitable for applications where a real time performence is required. The picture below shows the PRU pins coloured in cyan colour.

There are 2 variants of compilers namely clpru and pru-gcc available which allows developer to write a c, c++ code to interface peripherals with PRU. There are 2 32 bit registers namely R30 and R31 which control the PRU pins. The R30 register controls the PRU pins output and R31 controls the input. So the the first hurdle is to translate the pin number on the header to the bit number on the register which controls the pin. For example on pocketbeagle the pin P2.34 is controlled by 5th bit of the R30 and R31.There is no easy way to figureout this relation. If you are stuck in your programing task like i was here is a table below to get you going. In the first column the last digit is the bit number the second column explains if this register is output or input. 3rd column gives you the alphanumeric pysical pin on the Processor IC. The 4th and 5th columns represent the pins on the header of pocket beagle and beaglebone Black respectively.So when you switching from one board to another you can make a edit in the code accordingly.
Bit Number Description ZCZ Ball PocketBeagle Beaglebone Black
pr1_pru0_pru_r30_6 output D13 P2.28 P9.41
pr1_pru0_pru_r30_3 output C12 P2.30 P9.28
pr1_pru0_pru_r30_10 Output D12 P2.32 P9.30
pr1_pru0_pru_r30_5 Output C13 P2.34 P9.27
pr1_pru0_pru_r30_7 Output A14 P1.29 P9.25
pr1_pru0_pru_r30_4 Output B12 P1.31 P9.42
pr1_pru0_pru_r30_1 Output B13 P1.33 P9.29
pr1_pru0_pru_r30_10 Output V5 P1.35 P8.28
Similarly if you need to read the bits you should read it from R31 register. The bit number and relation remains the same.

How i figured out the Relation

Yeah!!! you are looking here. You want to know more. Dont you
I first looked at the page no 86 of TRM availabe at AM335X TRM
. In one of the column zczball i found the Pad numbers and from the first column i found the corresponding bit. After this I ran a perl script as following
cd /opt/script/device/bone
sudo perl show-pins.pl | grep P2.32 /
The output it gave is as following:
P9.27 105 C13 fast rx 6 pru 0 in 5 ocp/P2_34_pinmux (pinmux_P2_34_default_pin)
Here you can see it displays C13 as the Physical pin number on the Processor chip the bit number is 5 and the header pins are P2.34 and P9.27. I hope now you can figure out the relationship for any pin