Debugging firmware is nothing like debugging a web app. You cannot just open the console. JTAG and SWD give you direct access to the processor — here is how to use them.
What these protocols do
JTAG and SWD are debug interfaces that let an external debugger (your PC running OpenOCD or a hardware debugger like a J-Link) communicate directly with the microcontroller's debug subsystem. Through this connection you can:
- Set breakpoints and step through code
- Read and write CPU registers
- Read and write memory
- Flash new firmware
- Reset the processor
JTAG vs SWD
JTAG is the original standard and uses 4 signal pins. SWD (Serial Wire Debug) is a two-pin interface developed by ARM — it uses SWDIO (data) and SWDCLK (clock). SWD has become the standard for ARM Cortex-M devices because it uses fewer pins while providing the same debugging capability.
Hardware setup
You need a debug probe. Options range from a $15 ST-Link to a $600 Segger J-Link Ultra+. For most development, an ST-Link V3 is excellent. Connect it to the SWD header on your target board (usually SWDIO, SWDCLK, GND, and optionally VTREF).
Using GDB with OpenOCD
# Start OpenOCD with your board config
openocd -f interface/stlink.cfg -f target/stm32f4x.cfg
# In another terminal, connect GDB
arm-none-eabi-gdb firmware.elf
(gdb) target extended-remote :3333
(gdb) monitor reset halt
(gdb) break main
(gdb) continue
Semihosting
Semihosting lets your firmware output debug messages through the SWD interface to your host computer — no UART needed. Just call printf() and the output appears in your OpenOCD console. Invaluable for debugging when UART is not available.
Watchpoints
Set watchpoints on memory addresses or variables. The processor halts whenever that memory is read or written. This is how you track down the mysterious variable corruption that is ruining your state machine.



