Skip to main content

Subsection 7.1.7 Part 3d: Breakpoints

Single-stepping is precise but slow, and you must not step your way into Blinky’s delay loop. Instead of walking the program line by line, you can mark a line of interest with a breakpoint and let the program run at full speed until it reaches it. The statements in between execute normally, but the program pauses when it gets to a breakpoint so that you can look at the registers and the variables. Setting two breakpoints (Figure 7.1.12) and watching GPIOA_ODR at each stop (Figure 7.1.13) is the exercise below.

Activity 7.1.7. Run Between Two Breakpoints.

(a)

Place a breakpoint beside the line that turns the LED on (GPIOA->ODR |= LED_PIN;) and another one beside the line that turns the LED off (right-click the thin margin strip at the left edge of the code window beside the row where you wish to add the breakpoint). A small marker appears beside each.

(b)

Click Resume. The delay loop executes at full speed and the program suspends at the next breakpoint. Click Resume a few more times, watching two things at each stop: the on-board LED, and OD5 inside GPIOA_ODR in the SFRs view.

(c)

At each stop, check: does the LED’s state agree with OD5? You are hopping the program between its two visible states, with the register view and the hardware in lockstep.
Figure 7.1.12. Two breakpoints set in the left margin, on the LED-on and LED-off lines of Blinky’s loop. Each Resume runs the delay loop at full speed and suspends at the next marked line.
Figure 7.1.13. GPIOA_ODR at the two breakpoints. Left: 0x0 with OD5 = 0, the LED is off. Right: 0x20 with OD5 = 1, the LED is on. The register view and the physical LED change together.
If you do find yourself stuck partway through a delay loop (it happens), do not click your way out. Use Terminate and Relaunch to start the session fresh, or Reset the chip and restart execution; both are on the toolbar (Subsection 7.2.5 has the full icon reference).