Debugging the PRU from CCS#

CCS is TI’s primary debug tool for PRU firmware.

This section assumes that the PRU core was already initialized in Lab 4: How to Initialize the PRU. We will debug either the c_code version of pru_add, or the assembly_code version.

Load debug symbols for the PRU core#

The debug symbols allow CCS to associate the project source code with the generated assembly code running on the PRU cores.

If the PRU project was initialized by CCS

No additional steps are needed. The debug symbols were loaded into CCS when CCS loaded the program into the PRU core. Continue to section Get familiar with the CCS environment.

If the PRU project was initialized by an MCU+ core

or

If the PRU project was initialized by a Linux core

Connect the JTAG cable to the PC, and follow the steps in Initializing the PRU from CCS to connect CCS to the EVM. However, in section Load the PRU firmware, STOP after Launch Selected Configuration and return to this page.

Right click on the appropriate PRU core and select Connect Target. Do NOT reset the CPU! Instead, load the debug symbols by selecting Run > Load > Load Symbols. Select the PRU binary that is currently running on the remote core.

Get familiar with the CCS environment#

Set up the debugging windows#

We will be using these debugging windows during this lab:

  • View > Registers

  • View > Memory. View > Memory Allocation may also be helpful

  • View > Disassembly

  • View > Variables

Take note of where the windows have appeared. Some Views may be on the Left-hand menu, the Right-hand menu, or along the bottom of the screen.

In the Debug view, select the PRU core that has the firmware loaded. The core should say Halted.

Inspect the debug interface#

Get familiar with important buttons in the Debug interface. Hover the mouse over a button to see the button’s name.

  • Continue places the PRU firmware into a “running” state

  • Pause pauses the PRU core. The PRU core must be paused in order to view memory values, edit variables, etc.

  • Stop closes the debug session

  • Restart moves the Program Counter (PC) back to the program entry point. It does NOT actually reset the core under debug.

C code:

  • Step Into takes one step through C code, and then pauses the PRU core. Note that a single step in C code may translate to several steps in the generated assembly code running on the PRU core. If there is a function, “Step Into” will jump into the function and pause at the first C instruction within the function

  • Step Over takes one step through the C code, and then pauses the PRU core. Note that a single step in C code may translate to several steps in the generated assembly code running on the PRU core. If there is a function, “Step Over” will step over the function and pause at the first C instruction after the function

Assembly code:

  • Step Into takes one step to the next assembly instruction and pauses. If there is a subroutine or function, “Step Into” will jump into the subroutine or function and pause at the first assembly instruction within the subroutine or function.

  • Step Over takes one step to the next assembly instruction and pauses. If there is a subroutine or function, “Step Into” will jump over the subroutine or function and pause at the first assembly instruction after the subroutine or function.

To continue debugging the assembly_code project, jump down to section Debugging Assembly Code.

Debugging C Code#

This section uses the c_code example.

If you clicked on any of the buttons in the previous step, right click on the core and select Reset > Core reset or Restart to get back to the program entry point. Note that resetting the core does NOT cause the PRU’s local memory to get zeroed out.

Use the “Step Over” or “Step Into” buttons to step through the PRU function to the beginning of the while loop.

Reading and modifying values in memory#

Navigate to the Memory window.

  1. Select Data_Memory. In the location box, enter 0x0 to see the stack and addresses for a, b, and c

  2. Begin stepping through the program. If this is the first time the program is running since the processor booted up, you should see the values for a and b populated into 0x110 and 0x114. After stepping through the loop once, the value of c at 0x118 should now equal a + b

  3. Double click the block of memory at 0x110 in the memory browser. Change the value to a new number (for example, assign a new value to a). Press the enter key on the keyboard to save the new value of a.

  4. Step through the loop again. The value of c at 0x118 should change.

Reading and modifying variable values#

Navigate to the Variables window. Variables x, y, and z are defined here.

Note

CCS20 and all earlier versions of CCS have a bug in the Variables window as of OpenPRU 2026.01.00. The variables are stored in one location on the stack, but the CCS debugger thinks that the variables are stored in a different location. This bug does not affect PRU functionality, but it does mean that the Variables window is not useful for debugging.

The Variables window shows the value of a variable, as well as the variable’s location in memory.

Variables x, y, and z should be saved to the stack.

Check the linker command file to see where the stack is located:

  1. In the Left-hand menu, Explorer and navigate back to the PRU firmware project in the CCS workspace

  2. In the PRU build outputs, open the .map file

  3. Scroll down to the SECTION ALLOCATION MAP and look for .stack. In my case, .stack is in page 1, offset 0x0000, with a length of 0x100:

SECTION ALLOCATION MAP

 output                                  attributes/
section   page    origin      length       input sections
--------  ----  ----------  ----------   ----------------
...
.stack     1    00000000    00000100     UNINITIALIZED
                  00000000    00000004     rtspruv3_le.lib : boot.c.obj (.stack)
                  00000004    000000fc     --HOLE--
  1. Check the linker command file. The MEMORY section tells us which memory regions are at what address offsets in PAGE 1. The SECTIONS section tells us which memory region we place .stack into. In my case, .stack is placed into PRU0_DMEM_0, which is Data RAM 0:

MEMORY
{
...
      PAGE 1:
        /* Data RAMs */
        /* 8 KB PRU Data RAM 0; */
        PRU0_DMEM_0     : org = 0x00000000 len = 0x00001000
...
SECTIONS {
...
        .stack          >  PRU0_DMEM_0, PAGE 1

In my case, the stack will begin at address 0x0 in the PRU core’s DMEM0.

From the .map file, we saw that the stack was 0x100. If we wanted to change the stack size, we would modify the stack size as per Writing C Code in CCS or Writing C Code in OpenPRU.

Now I know that the stack has a size of 0x100 and begins at address 0x0 in the PRU’s DMEM0. Navigate back to the Debug perspective in the Left-hand menu.

In the Memory window, find the stack location. The variable values listed in the Variables view should be visible in the Memory window at the location listed in the Variables table.

Click on the Value cell of a variable in the Variables view. type a new number, and press the enter key on the keyboard. The value in the Memory view will change

Reading and modifying register values#

Navigate to the Registers window. Click on Restart to return to the program entry point.

  1. Expand the core registers dropdown.

  2. Step through the C code. The register values will change. PRU programs written in assembly code specify exactly which core register is doing what. However, for C code, the PRU compiler determines which values go in which registers.

  3. Register values can be changed by clicking on the Value cell and typing in a new hexadecimal value.

Viewing and navigating assembly code#

  1. Navigate to the Disassembly window. This window shows what assembly code was generated from the C code.

  2. Click the Step Into button several times. Note that the yellow arrow representing the Program Counter (PC) in the main.c view matches the yellow arrow representing the PC in the Disassembly view.

CCS Disassembly View

  1. Return to the Register window. Under Core Registers, select PC and change it to a different memory location. The PC arrows in main.c and the Disassembly view should jump to the new program counter location.

Warning

Be careful when manually changing the Program Counter. The PRU firmware does not know when the PC value is manually changed, so register values, memory values, etc may be different from what the PRU firmware expects.

  1. Click on Restart to return to the program entry point.

  2. In the Disassembly view, notice how there can be multiple assembly instructions under a single line of C code. In the Debug view, click the Step Into button. The PC will jump forward to the next line of C code, instead of the next assembly instruction.

  3. Note that the Disassembly view has different buttons, labeled Assembly Step Into and Assembly Step Over. These buttons allow us to step from one assembly instruction to the next.

Assembly Step Into

Note

The disassembly instructions in the Getting Started Guide directly align with the C code because the PRU compiler is not performing any code optimization. If the PRU compiler performs software optimization for speed or memory size, the generated assembly may be organized differently from the original C code. If the PRU use case requires exact timing, we suggest writing the time sensitive code in assembly rather than C in order to give the developer complete control over the PRU instructions.

Breakpoints#

View all breakpoints in the code under Debug > Breakpoints.

To toggle a breakpoint, either click on the left side of either the line number in the source code view or the address in the disassembly view, or select the line, and go Run > Toggle Breakpoint.

Add a breakpoint.

Select Run > Resume. The code will run until it reaches the breakpoint, and then the software execution will pause. Utilize the step into/step over commands to see what is happening in the PRU code. To set new breakpoints in the PRU code and see them catch in runtime, select Run > Restart, set your breakpoints in the PRU code, then select Run > Resume.

Debugging Assembly Code#

This section uses the assembly_code example.

Reading and modifying values in memory#

The assembly_code project does not read or modify values in memory. Refer to Debugging C Code for steps on how to read and modify memory values in the Memory window.

Reading and modifying variable values#

The assembly_code project does not read or modify variables. Refer to Debugging C Code for steps on how to read and modify variable values in the Variables window.

Reading and modifying register values#

Navigate to the Registers window. Click on Restart to return to the program entry point.

  1. Expand the core registers drop down.

  2. Step through the assembly code. The register values will change.

  3. Register values can be changed by clicking on the Value cell and typing in a new hexadecimal value.

Before changing any register values, let’s take a closer look at exactly what the assembly code is doing.

Viewing and navigating assembly code#

  1. Navigate to the Disassembly window. This window shows what processor instructions were generated from the assembly code.

  2. Click the Assembly Step Into button several times. Note that the yellow arrow representing the Program Counter (PC) in the main.asm view matches the yellow arrow representing the PC in the Disassembly view. One assembly instruction in main.asm will be related to one assembly instruction in the Disassembly window.

  3. Return to the Register window. Under Core Registers, select PC and change it to a different memory location. The PC arrows in main.asm and the Disassembly view should jump to the new program counter location.

Warning

Be careful when manually changing the Program Counter. The PRU firmware does not know when the PC value is manually changed, so register values, memory values, etc may be different from what the PRU firmware expects.

  1. Click on Restart to return to the program entry point.

  2. Click the Assembly Step Into button until the PC reaches the while_true function.

  3. Notice how the command ldi x_register, x was interpreted in the Disassembly view. x was converted into a static value of 1 instead of a variable that can be changed.

  4. Step all the way through the while_true loop. The value of R22 should update to equal R20 + R21.

  5. What if we want to change the values getting passed to the assembly instruction add z_register, x_register, y_register? The LDI commands will overwrite any value in R20 and R21 every while loop.

  6. Step until the PC is pointing to add z_register, x_register, y_register. At this point, the two LDI commands just executed. The very next PRU clock cycle, the ADD command will execute.

  7. Go to the Registers view and enter new values in for R20 and R21.

  8. Step one more time. R22 should update with the sum of the new values that were entered in. Stepping through the loop again should replace all register values with the values that were hardcoded in instruction memory.

Breakpoints#

View all breakpoints in the code under Debug > Breakpoints.

To toggle a breakpoint, either click on the left side of either the line number in the source code view or the address in the disassembly view, or select the line, and go Run > Toggle Breakpoint.

Add a breakpoint.

Select Run > Resume. The code will run until it reaches the breakpoint, and then the software execution will pause. Utilize the step into/step over commands to see what is happening in the PRU code. To set new breakpoints in the PRU code and see them catch in runtime, select Run > Restart, set your breakpoints in the PRU code, then select Run > Resume.