Skip to main content

Subsection 7.1.4 Part 3a: Launching the Debugger

The third tool is the interactive debugger built into the STM32CubeIDE, and it does something the other two cannot: it halts the processor wherever you ask, and then lets you look at any variable and any peripheral register on the chip, and step the program forward one line at a time. A printf only reports from the places you decided in advance to put one; the debugger needs no such decision beforehand. It talks to the STM32C031C6 over the same USB cable you already program with (the Nucleo’s ST-LINK circuitry is the go-between), and it works even before the UART does. The debugger finds errors that appear while the program runs, not compile errors, so the project has to compile and build without errors first.
The launch itself is one click: the bug icon in the toolbar, immediately left of the green Run button (Figure 7.1.4).
Figure 7.1.4. The bug icon (boxed) is beside the green Run button in the toolbar. Clicking it builds, flashes, and launches the program under the debugger.

Activity 7.1.5. Launch a Debug Session.

(a)

Your Blinky project should be open and built from the start of class. Run it normally once to confirm the on-board LED still blinks.

(b)

Click the bug icon in the toolbar (next to the green Run button, the boxed icon in the figure) to build, flash, and launch under the debugger. When the “Confirm perspective switch” window appears, accept it.

(c)

Check your screen against the debug-perspective screenshot. The layout has changed (this is the debug perspective) and execution is halted at the first statement of main(), highlighted in blue. The program is loaded but has not run a single line of your code yet.
Figure 7.1.5. The debug perspective, immediately after launch. The editor holds the Blinky source, blinky.c in this capture, with the first statement of main() highlighted in blue, loaded, but not yet executed. The tabbed pane on the right is the one we’ll work in: the SFRs tab first, and the Variables tab later in the hour (the tab labels truncate on screen to “Variabl” and “Breakp”).

Insight 7.1.6. If the Debugger Will Not Launch.

Four failure modes cover nearly every stuck launch. Find your symptom below and apply the fix. A launch that does not come up on the first try is normal.
  • The project will not build. You are likely trying to debug some other code than the known and already working Blinky. Download the known-good blinky.c, replace the contents of the blinky.c in your Blinky project’s Src folder with it, and build again. If the project still will not build, raise your hand and watch with a neighbor: nothing later today requires your own launch, and you can redo this walkthrough from this chapter, step by step, before the next class.
  • Board not found, or a connection error at launch. Reseat the USB cable at both ends, and close any other program that might be holding the board (a CoolTerm window on the same port, or an ST-LINK utility).
  • Clicked the wrong button on the perspective popup. Window \(\to\) Perspective \(\to\) Open Perspective \(\to\) Debug brings the debug layout up by hand.
  • The session behaves strangely, or a second launch fails. A previous debug session is probably still running. Terminate it with the red square first: one debug session at a time.