A discussion on the PRU Data In Out example page describes how to launch a PRU PASM Assembler binary which will access certain pins on the Beaglebone Black P8 and P9 header for the purposes of input and output. The associated PASM Assembly Language source can be found in the file BBBCSIOHelp_PRUPinInOutExamplePASMCode.html and it will manipulate bits in the R31 and R30 registers of PRU0 to read and set the state of pins in the Beaglebone Black P8 header. In that example, the register bits which are used correspond to Header 8 pin 16 (as an input) and Header 8 pin 11 (as an output).
It is important to note that, while the PASM code running in the PRU can always manipulate the content of its R31 and R30 registers, if I/O channels which the bits in these registers represent have not been correctly configured then no action in the PRU (either read or write) will have any meaningful effect. The proper mapping is set by adjusting the PinMux mode for that pin and also other associated attributes such as setting it as an input or output and the pullup resistors etc.
A useful discussion of the Beaglebone Black PinMux, and how it operates, can be found on this page. Information on the configuration and usage of the PRU I/O lines can be found on this page. If you are not familiar with the PinMux and the way in which the PRU's access the I/O lines available to them, then it is strongly recommended that you read both pages. The information on this page and in the PRU Pin In/Out Example PASM Code will make a lot more sense.
In order to ensure that the specified pins on theP8 or P9 header are properly configured so the PRU can access them you will need to set the PinMux mode and configuration for that pin. On the Beaglebone Black, the PinMux mode for the pins can be set by adjusting the Device Tree source, recompiling and rebooting or, rather more simply, by building and executing a Device Tree Overlay which does the job without the necessity of a reboot. The About the Device Tree document on this site discusses in detail the process of de-compiling, editing, re-compiling and installing a new Device Tree and such methods will not be discussed further here.
The information below details the two Device Tree Overlays required to support the PRU Pin In/Out Example PASM Code and intentionally does not provide much in the way of background. A comprehensive discussion of the motivation and content of these files can be found on the Using Device Trees To Configure PRU I/O Pins page.
Creating an overlay for any one PinMux pin is not very difficult - there are lots of samples on the Internet. However, one simple method is to go to the excellent Device Tree Overlay Generator at KiloBaser.com and generate the basic structure of the Device Tree Overlay there. The instructions for compiling and installing the Device Tree Overlay are also helpfully contained on that page.
Below is a summary of the Device Tree Overlay and actions required to enable the P8_16 pin (pr1_pru0_pru_r31_14
) as an input.
First set up the form with the following information (Pin=P8_16, Slew=Fast, Direction=Input, Pullup/Pulldown=Pulldown, MuxMode=Mode6:pr1_pru0_pru_r31_14). Once that is done, if you look below on the form, you will see that the Device Tree Overlay is dynamically generated every time you make a change. Here is the code it generated for P8_16 Mode6
/* * This is a template-generated file from BoneScript */ /dts-v1/; /plugin/; /{ compatible = "ti,beaglebone", "ti,beaglebone-black"; part_number = "BS_PINMODE_P8_16_0x26"; exclusive-use = "P8.16", "pr1_pru0_pru_r31_14"; fragment@0 { target = <&am33xx_pinmux>; __overlay__ { bs_pinmode_P8_16_0x26: pinmux_bs_pinmode_P8_16_0x26 { pinctrl-single,pins = <0x038 0x26>; }; }; }; fragment@1 { target = <&ocp>; __overlay__ { bs_pinmode_P8_16_0x26_pinmux { compatible = "bone-pinmux-helper"; status = "okay"; pinctrl-names = "default"; pinctrl-0 = <&bs_pinmode_P8_16_0x26>; }; }; }; };
A bit of copy and paste later and the file is saved . Note the line which performs the copy to the
/lib/firmware
location is important
otherwise the code which later loads the compiled .dtbo
binary at boot time will not be able to find it. The .dts
is compiled with command...
dtc -O dtb -o bspm_P8_16_26-00A0.dtbo -b 0 -@ bspm_P8_16_26-00A0.dts cp bspm_P8_16_26-00A0 /lib/firmware/
... and the .dtbo
binary is installed by editing the uEnv.txt
file. For more information on this see the Beaglebone Black and Device Tree Overlays
Technical Note.
Below is a summary of the Device Tree Overlay and actions required to enable the P8_11 pin (pr1_pru0_pru_r30_15
) as an output.
First set up the form with the following information (Pin=P8_11, Slew=Fast, Direction=Input, Pullup/Pulldown=Pulldown, MuxMode=Mode6:pr1_pru0_pru_r30_15). Once that is done, if you look below on the form, you will see that the Device Tree Overlay is dynamically generated every time you make a change. Here is the code it generated for P8_11 Mode6.
/* * This is a template-generated file from BoneScript */ /dts-v1/; /plugin/; /{ compatible = "ti,beaglebone", "ti,beaglebone-black"; part_number = "BS_PINMODE_P8_11_0x6"; exclusive-use = "P8.11", "pr1_pru0_pru_r30_15"; fragment@0 { target = <&am33xx_pinmux>; __overlay__ { bs_pinmode_P8_11_0x6: pinmux_bs_pinmode_P8_11_0x6 { pinctrl-single,pins = <0x034 0x6>; }; }; }; fragment@1 { target = <&ocp>; __overlay__ { bs_pinmode_P8_11_0x6_pinmux { compatible = "bone-pinmux-helper"; status = "okay"; pinctrl-names = "default"; pinctrl-0 = <&bs_pinmode_P8_11_0x6>; }; }; }; };
A bit of copy and paste later and the file is saved . Note the line which performs the copy to the
/lib/firmware
location is important
otherwise the code which later loads the compiled .dtbo
binary at boot time will not be able to find it. The .dts
is compiled with command...
dtc -O dtb -o bspm_P8_11_6-00A0.dtbo -b 0 -@ bspm_P8_11_6-00A0.dts cp bspm_P8_11_6-00A0.dtbo /lib/firmware/
... and the .dtbo
binary is installed by editing the uEnv.txt
file. For more information on this see the Beaglebone Black and Device Tree Overlays
Technical Note.