Ground Embedded KO Subscribe

Notes / Test & Debug Instruments

Debugger: stopping firmware line by line

Load firmware with an ST-LINK or J-Link and find problems with breakpoints, variable watches and register views. Faster than debugging with printf.

GROUND EMBEDDED · NOTETest & Debug Instruments 05DebuggerAvg 30%D1 period

Connection

PCIDEDebuggerST-Link · J-LinkSWDIO · SWCLK · GNDMCU
Debugger connection. SWD needs only two signal wires and GND.

A Cortex-M connects to the debugger through the SWD interface (SWDIO, SWCLK, GND, and NRST and VTref if needed). When designing a board, always bring the SWD pins out to a connector.

What you can do

Breakpointstop at a chosen lineStep line by lineView variables · registersChange values
What you do with a debugger.
  • Breakpoint: stop at a particular line
  • Stepping: one line at a time, stepping into or over functions
  • Variable watch: check values while stopped; some tools update live while running
  • Register / peripheral view: see whether GPIO and timer registers hold the settings you intended, decoded through the SVD file
  • Memory view: buffer contents, the stack area
  • Data watchpoint: stop the instant a particular variable changes. Powerful for finding who is corrupting a value

Cautions

  • Stopping during real-time operation such as motor control can be dangerous, because the PWM stays as it was. Use the timer's debug-stop feature (DBGMCU) so the outputs turn off when execution stops.
  • With optimisation (-O2) on, variables disappear or the line order looks scrambled. Use -Og for debugging.
  • The debug connection can drop when the MCU enters a low-power mode.
FREE PDFGet the 3 free ebooksIf you want to keep reading this topic as one book: BLDC motor control, serial communication and sensors at book length. PDFs are in Korean.Get them free →