Simplicity Studio v4 Watchpoints

by <a href="http://community.silabs.com/t5/Welcome-and-Announcements/Community-Ranking-System-and-Recognition-Program/m-p/140490#U140490"><font color="#000000"><font size="2">Hero Employee</font></font> </a> ChrisM on ‎02-13-2017 10:58 AM

Question

How do I setup a breakpoint to suspend program execution when a specific variable is read or written?

Answer

What are Watchpoints?

 

Simplicity Studio v4 supports a feature called watchpoints.  Watchpoints are similar to breakpoints in that program execution is suspended when certain conditions occurs.  Breakpoints halt once the program counter (PC) matches a specified value.  Watchpoints can be configured to halt once an expression is read or written or a specified condition is true.

 

Configuring Watchpoints

 

To configure a watchpoint for EFM32 products, perform the following steps:

1. Develop a firmware project or use an existing code example.

2. Download the firmware and start a debug session.

3. Once the debug session has connected, select the Breakpoints view.

4. To add a new watchpoint, click the down arrow on the top right side of the Breakpoints view.

add_watchpoint.png

5. In the Properties for C/C++ Watchpoint dialog, enter a valid expression, such as the name of a variable you wish to watch.

watchpoint_expression_to_watch.png

6. Check Read if you want to break when the expression is read by the CPU. Check Write if you want to break when the expression is written by the CPU.

7. Check Enabled to enable the watchpoint.

8. Condition can be used in addition to Read/Write to halt the CPU only when all specified conditions are true.  A condition can be an expression such as "msTicks > 1000".

9. Click OK to apply the watchpoint settings.

 

Watchpoint Examples

 

The following examples describe how to enable simple watchpoints using the SLSTK3401A_blink example for the Pearl Gecko STK.

 

Break When Expression is Read

 

To halt the CPU when the msTicks variable is read by the CPU, choose the following settings:

Expression to watch: msTicks

Read: Checked

Enabled: Checked

watchpoint_expression_read.png

 

After enabling the watchpoint and running, the CPU will halt at the first instruction after the expression is read.  In this case, msTicks is read when it is assigned to curTicks and again each time in the while loop while waiting for the delay to complete. 

 

watchpoint_expression_read_line.png

 

Break When Expression is Written

 

To halt the CPU when the msTicks variable is written by the CPU, choose the following settings:

Expression to watch: msTicks

Write: Checked

Enabled: Checked

watchpoint_expression_write.png

 

After enabling the watchpoint and running, the CPU will halt at the first instruction after the expression is written.  In this case, msTicks is written when it is incremented by SysTick_Handler(). 

 

watchpoint_expression_write_line.png

 

Break When Expression is Read/Written and a Condition is True

 

Adding a condition to the watchpoint will only break when the read/write condition is true as well as the expression in the Condition text box also evaluates to true.

 

Note that adding an expression to Condition will greatly reduce the running speed of the firmware as the debugger must constantly run/halt the CPU to evaluate the expression.

 

To break when msTicks is written to a value greater than 1000, choose the following settings:

Expression to watch: msTicks

Write: Checked

Enabled: Checked

Condition: msTicks > 1000

watchpoint_expression_condition.png

 

Note that since the debugger will run/halt the CPU rapidly, it may be difficult to manually suspend the CPU.  To do so, uncheck the watchpoint enable checkbox on the Breakpoints view and then click the suspend button as normal.