Hardware Breakpoints and Watchpoints for C28x in CCS

From Texas Instruments Wiki
Jump to: navigation, search

Introduction

This page describes how to setup and use Hardware breakpoints, Watchpoints, Count Events and Data Access Counts in CCS v5 and v6 for the C2000 devices.

Hardware breakpoints stop execution of the program. Hardware watchpoints allow you to halt when a read or write access is made to a data variable address. Count Event can be used to measure clock cycles between two points in the code. Data Access Count can be used to determine the number of times a data variable address has been accessed. Since these are all implemented internally by the hardware and require on-chip analysis resources, there is usually a limit to the maximum number of events that can be enabled at one time.

Configure a Hardware Breakpoint

The steps below describe how to configure a hardware breakpoint in CCS.

  1. Configure CCS for a C28x target and launch a debug session.
  2. In the Debug Perspective, open the breakpoint dialog: View->Breakpoints.
  3. Use the pull-down menu to select Hardware Breakpoint.

    C28x hw breakpoint.png

  4. In the Location field, specify the address where the breakpoint should be set.
    Alternately, if the code is programmed to Flash, double-clicking on a line of code in the editor will automatically set a hardware breakpoint.

Note: C28x devices have two analysis resources available at a time. One resource can be used as a hardware breakpoint, watchpoint, or counter. The other one can be used as a hardware breakpoint or watchpoint. So when working with hardware breakpoints, you are limited to 2 hardware breakpoints. If you try to set more than the allowed limit, the following message will appear

C28x no aet resource.png

Also, by default the debugger may set a breakpoint to halt at CIO functions, so a breakpoint will be used for this, allowing only one breakpoint to be available to the user. This breakpoint can be disabled by going into menu Run->Debug Configurations…, Target tab, and unchecking the box for “Enable CIO function use”. Also ensure that the box for “Halt at program termination” is also unchecked if you want access to both available breakpoints

C28x cio endprogram bp.png

Configure a Hardware Watchpoint

  1. Configure CCS for a C28x target and launch a debug session.
  2. In the Debug Perspective, open the breakpoint dialog: View->Breakpoints.
  3. Use the pull-down menu to select Hardware Watchpoint.

    C28x hw watchpoint.png

  4. In the Location field, specify the address that you want to watch and if it should stop on a read or write access. For eg, if you want to watch when a global variable named interruptCount is written to, you can specify interruptCount for the Location and Write for the memory access.

    C28x hw watchpoint1.png

  5. The watchpoint can be further customized, if needed, by right-clicking on the watchpoint and selecting Breakpoint Properties. From this dialog box you can:
    • Configure a data read/write of a particular value
    • Configure the size of the data
    • Configure a mask value (bits that will be ignored)

      C28x hw watchpoint2.png

Configure a Count Event

The Count Event can be used to count different events, one of them being clock cycles. Using Count Event for measuring clock cycles could be an alternate method of profiling, in addition to the methods described in this page.

  1. Configure CCS for a C28x target and launch a debug session.
  2. In the Debug Perspective, open the breakpoint dialog: View->Breakpoints.
  3. Use the pulldown to select Count Event.

    C28x count event.png

  4. Select the Event to Count as Clock Cycles.

    C28x clock cycles.png

  5. Enable a breakpoint in your code by double-clicking on the line in the source file. Select the Run icon. When the breakpoint is reached the Count Event will display the number of Clock Cycles.

    C28x count event1.png

  6. You can also set two breakpoints to count the number of cycles between two places in your code (useful to profile functions):
    Enable the count event as shown above, then right-click on its entry in the Breakpoints view, select Properties and check the box marked Reset Count on Run. This will make the Event counter reset every time the processor is put to run, therefore allowing counting events within breakpoint boundaries.

    C28x count event2.png

  7. Set two breakpoints in your code
  8. Run to the first breakpoint. The Event counter will count the number of cycles up to this point in your code. You can disregard this number.
  9. Run to the second breakpoint. This time the Event count will show the number of cycles between the first and the second breakpoint.

Note: If you are setting software breakpoints (ie code is in RAM) then you can set any number of breakpoints. If they are hardware breakpoints or code is in Flash, then you will only be able to set 1 breakpoint if Count Event is enabled. So you would need to run to the first breakpoint, then disable the first breakpoint and enable the second, and run to the second breakpoint.

Note: The number of CPU cycles can vary greatly depending on the type of memory the code is running from (Flash, RAM, external).

Configure Data Access Count

Data Access Count can be used to count the number of times a data variable has been accessed.

  1. Configure CCS for a C28x target and launch a debug session.
  2. In the Debug Perspective, open the breakpoint dialog: View->Breakpoints.
  3. Use the pulldown to select Data Access Count.

    C28x data access.png

  4. In the Location field, specify the data variable that you want to count accesses for and in the Memory field, choose if you want to count Read or Write access.

    C28x data access1.png

  5. Select the Run icon. Halt the code when desired.
  6. The Count column will display the number of times that variable was accessed up to that point in the code.

    C28x data access2.png

  7. To reset the count between runs, right-click on its entry in the Breakpoints view, select Breakpoint Properties and check the box marked Reset Count on Run. This will make the counter reset every time the processor is put to run.

    C28x data access3.png

Profiler

Please see the page Profiling on C28x Targets for information on how to profile code on C28x devices. The same concepts apply to CCSv5 and v6. An alternate method is to use the Count Event as described above.

Checking for stack overflow

A common issue causing software instability is stack overflow. When building a project the stack size is specified in the project linker options (or in the configuration file for DSP/BIOS projects). That corresponding size will be allocated for the stack by the linker. The linker will generate a symbol called __STACK_END (two preceding underscores) that corresponds to the end of stack.

A hardware watchpoint can be set to monitor when __STACK_END - 2 is written to which will indicate that a stack overflow has occurred.

  1. Configure CCS for a C28x target and launch a debug session.
  2. In the Debug Perspective, open the breakpoint dialog: View->Breakpoints.
  3. Use the pull-down menu to select Hardware Watchpoint.
  4. For the Location, enter the symbol __STACK_END - 2. For the Access Type, select Memory Write. Now every time the CPU writes to that address it will halt.

    C28x stack overflow.png

References

Checking for Stack Overflow
Profiling on C28x Targets

How Do Breakpoints Work