Home / Learn Embedded C / JTAG and SWD Explained

JTAG and SWD Explained

The two most common hardware debug interfaces used to control and inspect a running microcontroller.

The gistThe two most common hardware debug interfaces used to control and inspect a running microcontroller.

The idea, explained simply

JTAG vs SWDJTAG4-5 wiresSupports chaining multipledevicesWidely supported across manyarchitecturesSWDJust 2 wiresVery common on ARM Cortex-MchipsSimpler, fewer dedicated pinsneeded
JTAG vs SWD

What it is

JTAG and SWD (Serial Wire Debug) are hardware debug interfaces letting an external debugger probe control the chip directly: halting execution, single-stepping, reading/writing memory and registers, and setting breakpoints — all without any special debug code built into the application itself.

Why it matters

This is fundamentally different from printf-style debugging (covered next): the debugger can inspect and control the chip's actual internal state directly, even stopping execution completely, which is essential for diagnosing certain classes of bugs printf alone cannot reveal.

Mechanically speaking

SWD uses just 2 wires (compared to JTAG's 4-5), making it popular on many modern ARM Cortex-M chips specifically because it needs fewer dedicated debug pins, while JTAG remains common on many other architectures and for chaining multiple devices together.

Shows up in

  • Hardware-level debugging
  • Breakpoint-based bug diagnosis
  • Register/memory inspection

Try it

Simulating a debugger halting the CPU and reading a registerC: edit and run

A real debugger does this over the JTAG/SWD wires, directly, without the firmware itself needing any special debug code.

Try it: single-stepping through instructions

Advancing the program counter one instruction at a timeC: edit and run

A debugger single-step advances exactly one machine instruction, whose size can vary, before halting again and letting you inspect state.

Check yourself

1. What capability do JTAG/SWD hardware debug interfaces provide that printf debugging cannot?