What is JTAG, and how is it used for debugging?

 

What is JTAG?

JTAG (Joint Test Action Group, standardized as IEEE 1149.1) is a hardware interface used for:



  • Programming FPGAs, CPLDs, and microcontrollers.

  • Debugging embedded systems (ARM Cortex, RISC-V, etc.).

  • Boundary-scan testing (PCB manufacturing verification).

How JTAG Works

1. Physical Connection

  • 4-5 mandatory signals (plus optional ones):

    • TDI (Test Data In) → Serial data input

    • TDO (Test Data Out) → Serial data output

    • TCK (Test Clock) → Synchronization clock

    • TMS (Test Mode Select) → State machine control

    • TRST (Test Reset, optional) → Reset the JTAG interface

plaintext
Host (PC) 
  │
  ├── TCK → FPGA/CPU
  ├── TMS → FPGA/CPU
  ├── TDI → FPGA/CPU
  └── TDO ← FPGA/CPU

2. JTAG State Machine

JTAG operates via a 16-state TAP (Test Access Port) controller:

  • Key states:

    • Shift-DR/IR (Data/Instruction Register)

    • Capture-DR/IR

    • Update-DR/IR

JTAG State Machine

3. Boundary Scan (Manufacturing Test)

  • Tests PCB connections by toggling I/O pins without physical probes.

  • Uses BSDL files (Boundary Scan Description Language) to define pin mappings.


How JTAG is Used for Debugging

1. FPGA/CPLD Programming

  • Xilinx Vivado/ISEIntel Quartus use JTAG to:

    • Flash bitstreams (.bit/.sof files).

    • Read/write registers during debugging.

bash
# Example: Programming Xilinx FPGA via JTAG
vivado -mode batch -source program_fpga.tcl

2. Embedded CPU Debugging (ARM, RISC-V)

  • OpenOCDSegger J-LinkLauterbach debuggers use JTAG to:

    • Halt/resume CPU execution.

    • Set breakpoints, inspect registers/memory.

    • Flash firmware (via SWD, a JTAG-derived protocol).

bash
# OpenOCD example for ARM Cortex-M
openocd -f interface/jlink.cfg -f target/stm32f1x.cfg

3. Real-Time Monitoring

  • ChipScope (Xilinx)SignalTap (Intel) use JTAG to:

    • Capture FPGA internal signals without extra pins.

    • Debug timing issues (e.g., metastability).


JTAG Debugging Tools

ToolUse CaseSupported Devices
Xilinx Platform Cable USBXilinx FPGAsArtix/Kintex/Virtex
Segger J-LinkARM/RISC-V MCUsSTM32, NXP, GD32
Intel USB-BlasterIntel FPGAsCyclone/Arria/Max
OpenOCD (Open-Source)Multi-vendorSTM32, ESP32, RISC-V
Lauterbach Trace32High-end debugARM Cortex, PowerPC

JTAG vs. Alternatives

ProtocolSpeedPinsPrimary Use
JTAGMedium (10-30 MHz)4-5FPGA/MCU debug, boundary scan
SWD (ARM)Fast (up to 50 MHz)2ARM Cortex debugging
cJTAG (Reduced JTAG)Low-speed2Power-sensitive devices
UARTSlow2Basic serial console

Key Takeaways

  1. JTAG is the industry standard for hardware debugging and programming.

  2. Critical for FPGA workflows (bitstream loading, SignalTap debugging).

  3. ARM/RISC-V debugging often uses SWD (a JTAG derivative).

  4. Boundary scan helps validate PCB assemblies without physical probes.

评论

此博客中的热门博文

How To Connect Stm32 To PC?

What are the common HDL languages used in FPGA design?

How do you set up ADC (Analog-to-Digital Converter) in STM32?