- Table of contents
 - PRU Hello world - ARM/remoteproc load, CCS attach
 
PRU Hello world - ARM/remoteproc load, CCS attach¶
Objective¶
The objective of this example is to demonstrate the technique of starting a PRU program from the ARM/Linux using remoteproc and then using Code Composer to "attach" to this program through the JTAG.
This example will demonstrate the use of a wait loop at the start of the program so you have time to attach the debugger. The wait loop will wait for a specified amount of time (60 seconds in this example) and then run the program as usual.
Prerequisites¶
- See first example which loaded a program through the JTAG. Hello World - Toggling GPIO with PRU GPO. This example uses the first example as a starting point.
 - Assumes "am62x" is configured as a target name as described in Ssh_target_naming_and_port_forwarding
 
Steps¶
Modify Source Code¶
- Start with program from previous demo. Hello World - Toggling GPIO with PRU GPO
 - Add a wait for debugger loop
This allows time for connecting to the debugger so you can place a break point and step through the code. In this simple example it is not strictly necessary, but useful to know for more complex projects.int ii; ... // wait for 60 seconds for (ii = 0; ii < 60; ++ii) { __delay_cycles(CYCLES_PER_SECOND); } - main.c should look like the following:
#include <stdint.h> #include <pru_cfg.h> #include <stdio.h> #include <stdlib.h> volatile register uint32_t __R30; /* * main.c */ #define CYCLES_PER_SECOND (250000000) #define CYCLES_PER_MS (CYCLES_PER_SECOND/1000) int main(void) { volatile uint32_t gpo; int counter = 0; int ii; /* GPI Mode 0, GPO Mode 0 */ CT_CFG.gpcfg0_reg = 0; /* Clear GPO pins */ gpo = 0x0000; // wait for 60 seconds for (ii = 0; ii < 60; ++ii) { __delay_cycles(CYCLES_PER_SECOND); } fputs ("Hello World from a PRU\r\n", stdout); while (1) { counter++; if ((counter % 10) == 0) { char buff[20]; ltoa (counter/10, buff, 10); fputs(buff, stdout); fputs(": another hello from the PRU\r\n", stdout); } gpo = __R30; gpo ^= 0xF; __R30 = gpo; __delay_cycles(500*CYCLES_PER_MS); // half-second delay } } 
- Build program (Project->Build Program)
 
Copy program to target¶
- Copy to target
	
- Open a Terminal View (Windows->Show View->Other...->Terminal)
	
- Start a terminal (shift-ctrl-alt-T), Choose terminal of type "Local Terminal", hit OK
cd <workspace_directory>/toggle_led/Debug ssh am62x mkdir -p /lib/firmware/pru_demos scp toggle_led.out am62x:/lib/firmware/pru_demos
 
 - Start a terminal (shift-ctrl-alt-T), Choose terminal of type "Local Terminal", hit OK
 
 - Open a Terminal View (Windows->Show View->Other...->Terminal)
	
 - Fix up PRU_0 link in /lib/firmware 
ssh am62x ln -sf /lib/firmware/pru_demos/toggle_led.out /lib/firmware/am62x-pru0-fw
- Verify link
ssh am62x ls -l /lib/firmware/am62x-pru0* lrwxrwxrwx 1 root root 37 Apr 20 19:37 /lib/firmware/am62x-pru0-fw -> /lib/firmware/pru_demos/pru_hello.out
 
 - Verify link
 
Use remoteproc to start program on PRU_0¶
- Use remoteproc, see which processor is which
ssh am62x tail /sys/class/remoteproc/*/name ssh am62x tail /sys/class/remoteproc/*/state
- remoteproc2 corresponds to PRU_0
 - Output of the name files should be something like:
==> /sys/class/remoteproc/remoteproc0/name <== 5000000.m4fss ==> /sys/class/remoteproc/remoteproc1/name <== 78000000.r5f ==> /sys/class/remoteproc/remoteproc2/name <== 30074000.pru ==> /sys/class/remoteproc/remoteproc3/name <== 30078000.pru
 - Output of the state files should be something like:
==> /sys/class/remoteproc/remoteproc0/state <== running ==> /sys/class/remoteproc/remoteproc1/state <== attached ==> /sys/class/remoteproc/remoteproc2/state <== offline ==> /sys/class/remoteproc/remoteproc3/state <== offline
 
 - Start PRU_0. This will load the software and start it running.
ssh am62x "echo start >/sys/class/remoteproc/remoteproc2/state" ssh am62x tail /sys/class/remoteproc/remoteproc2/state
- The output from the first command will generate on the target console, messages like:
[12750.919679] remoteproc remoteproc2: powering up 30074000.pru [12750.930343] remoteproc remoteproc2: Booting fw image am62x-pru0-fw, size 175168 [12750.937829] remoteproc remoteproc2: remote processor 30074000.pru is now up
 
 - The output from the first command will generate on the target console, messages like:
 
Start the Debugger¶
- CCS - launch target config
	
- In the Target Configurations view, select am62x.ccxml->right-mouse->Launch Selected Configuration
 
 - In Debug view, select PRU_0-> Connect Target
 - Load the symbols
	
- Run->Load->Load symbols
 - Note that CPU Reset and Load Program have been replaced by the Load Symbols.
 
 - Target probably stopped in the wait loop
 - Breaking out of the loop
	
- Alternative 1: Change the value of the variable
	
- Variables view
 - Select the "value" for the loop variable (i.e. ii), change to 60, hit enter
 
 - Alternative 2: Use "Move to line" 
	
- Select the line after the loop. Right-mouse->Move to Line
 
 
 - Alternative 1: Change the value of the variable
	
 - Set breakpoint for line after fputs output
 - run
 - see initial message and periodic output
 
Summary¶
- Demonstrated starting the program using remoteproc
	
- Note that the PRU is different from the M4 MCU in that a resource table is not required when starting from remoteproc
 
 - Added a wait loop to wait up to 60 seconds.
 - Demonstrated attaching to the program from Code Composer
 - Demonstrated two ways to get out of the wait loop
 
Go to top