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.
Figure7.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.
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.
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.
Figure7.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”).
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.
Project won’t build → you are likely debugging other code than the known-good Blinky: download blinky.c (the link in this chapter), paste it over the blinky.c in your Blinky project’s Src folder, build again. Still stuck? We’re here to help!
Board not found / connection error → reseat the USB cable at both ends, and close anything else holding the board (a CoolTerm window on the same port, or an ST-LINK utility).