This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/PRU-SWPKG: Loading PRU code from Linux

Part Number: PRU-SWPKG

Tool/software: Code Composer Studio

Hi,

I am trying to run a simple PRU code to bit-bang P9.27 on the Beaglebone black. I have already achieved this using assembly code, however now I want to move on to doing so using C.

I have both Linux SDK and the CCS installed. There are two approaches that I have tried but none of them worked.

1. My beaglebone is running the linux kernel compiled and loaded with the 'create-sdcard.sh' script provided with linux sdk. I compiled my program by modifying the Makefile given in the example-application and am using AM335X_PRU.cmd file. Copied the *.out file to /lib/firmware/pru and updated the symbolic link (am335x-pru0-fw) to point to the out file. I reboot the board but the program doesn't seem to run.
What am I doing wrong?

2. Using CCSv7, I compile my code and generate the out file. I copy this file to the board (it is running the debian image) and try to generate the bin file using hexpru. I am using the AM335X_PRU.cmd file in this case as well. Here hexpru fails at the onset stating 'invalid option: cr'. I have echo-ed the compiled dts file into the capemgr file which enables P9.27 for output.
How do I use the out file without the TI debugger?

Attaching the C file for reference:

/*
 * main.c
 */

#include <stdint.h>
#include <pru_cfg.h>

// Declare r30 register
volatile register uint32_t __R30;

int main(void) {

    /* GPI Mode 0, GPO Mode 0 */
    CT_CFG.GPCFG0 = 0;

    /* Clear GPO pins */
    __R30 = 0x0000;

    while(1)
    {
        __R30 ^= (1 << 5);
        __delay_cycles(100000000); // half-second delay
    }

}
/*end*/

Thanks in advance,

Puneeth

  • The PRU experts have been notified. They will respond here.
  • Puneeth,

    Your C code looks correct. This feels like a pin muxing issue that will be resolved by making a device tree change. This step in the hands-on labs describes how to modify the device tree (and in turn the pin muxing) for the PRU cape: processors.wiki.ti.com/.../PRU_Training:_Hands-on_Labs. You can use that sample dtsi file as an example of how to set up your pin muxing to configure the P9-27 pin in PRU GPO mode.

    Support for the Debian distribution (and the cape manager) will come from the Beagleboard community here: http://beagleboard.org/discuss.
  • Thank you, Jason.

    This is the dts file I am using:

    /dts-v1/;
    /plugin/;
    
    / {
    	compatible = "ti,beaglebone", "ti,beaglebone-black";
    
    	/* identification */
    	part-number = "BB-BONE-PRU-01";
    	version = "00A0";
    
    	/* state the resources this cape uses */
    	exclusive-use =
    		/* the pin header uses */
    		"P9.27",	/* pru0: pr1_pru0_pru_r30_5 */
    		/* the hardware IP uses */
    		"pru0";
    
    	fragment@0 {
    		target = <&am33xx_pinmux>;
    		__overlay__ {
    
    			pru_gpio_pins: pinmux_pru_gpio_pins {
    				pinctrl-single,pins = <
    					0x1a4 0x0f 	/* P9 27 GPIO3_19: mcasp0_fsr.gpio3[19] | MODE7 | OUTPUT */
    				>;
    			};
    
    			pru_pru_pins: pinmux_pru_pru_pins {
    				pinctrl-single,pins = <
    					0x1a4 0x25	/* mcasp0_fsr.pr1_pru0_pru_r30_5, MODE5 | OUTPUT | PRU */
    				>;
    			};
    		};
    	};
    
    	fragment@2 {
    		target = <&pruss>;
    		__overlay__ {
    			status = "okay";
    
    			pinctrl-names = "default";
    			pinctrl-0 = <&pru_pru_pins>;
    		};
    	};
    };

    I think it enables P9.27 for output, if I am not wrong.

    Is it sufficient to copy the out file to /lib/firmware/pru, point the symbolic links and restart the kernel? Is there a more "programmatic" way to do this?

  • Puneeth,

    Device tree overlays are not supported by TI's Linux Processor SDK distribution. If you are using the Debian distribution along with the cape manager, then you will need to post your question to the BeagleBoard forums as mentioned before.

    Please see the example in the hands-on labs for the PRU cape device tree modification as an example for TI's Linux Processor SDK pin muxing.

    You do not need to restart the kernel to reload the PRUs, you can reload them with your new firmware by unbinding and then binding the PRUs to the pru-rproc bus. E.g:

    echo 4a334000.pru0 > /sys/bus/platform/drivers/pru-rproc/unbind

    echo 4a334000.pru0 > /sys/bus/platform/drivers/pru-rproc/bind


    Jason Reeder

  • Thanks Jason,
    I managed to find resources from the beagleboard forums. For future reference these are the links that helped me get my code running on BBB.
    www.embeddedrelated.com/.../603.php
    github.com/.../pru_sdk
    The newer beaglebones come with the clpru, hexpru etc. commands from ti toolchain pre-installed. All one needs to do is point to the correct include directories and link the libraries from software-dl.ti.com/.../beta.htm.
    Although CCS makes things easier, it is not strictly required and code can be compiled and run on BBB without it.

    Puneeth
  • Puneeth,

    The latest versions of the TI Provided C compiler for the PRU can be found here: http://software-dl.ti.com/codegen/non-esd/downloads/download.htm#PRU. There is no need to download CCS to get it or use the old beta link that you've posted above. On this page you can find an ARM version of the TI C compiler if you'd like to install it on your BeagleBone while running TI's Linux Processor SDK.

    The TI provided examples (while running TI's Linux Processor SDK) can be found here: https://git.ti.com/pru-software-support-package/pru-software-support-package/. The provided Makefiles in every example project show how to setup your environment to rebuild the examples (on a host PC or on the BeagleBone itself) at the top of the Makefile. These examples can also be used with the community's Debian distribution if you are using the remoteproc and rpmsg Linux drivers.

    When you say that the clpru and hexpru is included on the BeagleBone you are referring to the BeagleBoard community distribution of Linux that is supported here: http://beagleboard.org/discuss

    Jason Reeder