Definition
JTAG is the common name for IEEE 1149.1 [398], a standard that gives a chip a serial test port. Through four or five wires, a host shifts bits into and out of registers inside the chip. The standard defines boundary scan: reading and driving the chip’s pins through test cells, to check the connections on a circuit board. Chip makers also attach their own registers to the port, most often a processor’s debug logic, the circuitry that stops and inspects the processor, so JTAG is also a common debug connection.
The idea
Boundary scan answers a manufacturing problem. Chips have hundreds of fine pins, and some packages, such as the ball grid array (BGA), place their connections underneath the chip. A bed-of-nails tester, which presses one spring-loaded pin onto each connection of a board, cannot touch such joints. Yet a factory must still find every board that has a broken solder joint.
The idea of boundary scan is to build the test equipment into every chip. A small cell sits between each pin and the chip’s internal logic. All cells of a chip are linked into one long shift register: a row of one-bit storage cells in which every bit moves one place along at each clock tick. A host shifts a pattern in, makes the cells of one chip drive the pattern onto its output pins, makes the cells of another chip record the levels arriving at its input pins, and shifts the recorded bits out. Each chip thus acts as a test probe on its own pins. The chip’s processor, if it has one, plays no part.
Once chips had this port, chip makers used it for a second, unrelated job. They added instructions that connect the shift path to a processor’s debug logic, which can stop the processor, run it one instruction at a time, and read its registers and memory. That is instruction-level debugging. One connector now carries two services that act on different things: boundary scan acts on the pins, and debugging acts on the running program.
How it works
The standard calls the port the test access port (TAP). It has these signals:
TCK (test clock): the host supplies every clock tick, and nothing happens between ticks.
TMS (test mode select): its value at each rising edge of TCK moves the port’s controller from one state to the next.
TDI (test data in): the bits the host shifts into the chip.
TDO (test data out): the bits that leave the chip.
TRST (test reset): an optional wire that resets the test logic.
Behind the port sit a controller and several registers.
The TAP controller is a finite-state machine §8.33, a circuit that is always in one of a fixed set of states, here 16, and moves between them according to the value of TMS at each tick of TCK.
The instruction register holds the current test instruction. The instruction decides which data register is connected between TDI and TDO, and what the test logic does with it.
The data registers include the boundary-scan register, with one or more cells per pin; the 1-bit bypass register; and, optionally, a 32-bit identification register that reports the maker, the part number and the version.
Each access, called a scan, reads and writes either the instruction register or the selected data register, in three steps.
Capture: the register loads all its bits at once. In the boundary-scan register, each input cell records the level on its pin.
Shift: at each tick of TCK, every bit moves one cell toward TDO. A new bit enters from TDI and the last bit leaves through TDO, so reading the old content and writing new content happen together.
Update: the shifted bits are copied into a second one-bit store in each cell, the update latch. The update latches hold steady while the shift stage is busy, so the pins do not flicker during shifting. In the instruction register, Update makes the new instruction take effect.
The standard defines a few instructions. BYPASS, the instruction whose bits are all 1, puts the 1-bit bypass register in the path, so a chip that is not being tested adds only one bit to each scan. SAMPLE/PRELOAD captures the pins while the chip works normally, and loads values into the update latches without driving the pins. EXTEST (external test) makes the update latches drive the output pins and the cells capture the input pins; while it is active, the chip’s own logic no longer controls its pins. IDCODE (identification code) selects the identification register.
Several chips on one board form a chain. TCK and TMS go to all of them. The host’s TDI line enters the first chip, the TDO of each chip feeds the TDI of the next, and the TDO of the last chip returns to the host. One scan therefore shifts through the selected registers of every chip in the chain, one after another.
Debugging uses the same port in a different way. On an Arm processor, instructions that Arm defines, outside IEEE 1149.1, connect the shift path to the Arm debug interface [397]. That interface turns the shifted bits into read and write requests on the processor’s debug registers and on memory. The register writes, not the TAP, stop and start the processor. SWD §6.25 (Serial Wire Debug), Arm’s two-wire debug port, reaches the same debug interface without a TAP, and so offers debugging without boundary scan.
Worked example
A board carries chip A, a microcontroller §6.1 (a small computer on one chip), and chip B, a memory chip. One copper track, net N, runs from an output pin of A to an input pin of B. The chain runs from the host’s TDI through A, then through B, and back to the host’s TDO. To keep the numbers small, A has a 4-bit instruction register and 8 boundary cells, and B has a 5-bit instruction register and 4 boundary cells. Real chips have hundreds of cells.
Shift SAMPLE/PRELOAD into both instruction registers: bits.
Shift a pattern through both boundary-scan registers, bits, in which the cell for A’s pin holds 1 and every other cell holds a safe value. Update copies the pattern into the update latches. The pins do not change yet, because both chips still work normally.
Shift EXTEST into both instruction registers: 9 bits. At Update, A’s pin starts to drive 1 onto net N.
Scan the data registers. At Capture, B’s input cell records the level on net N. During Shift, the 12 captured bits come out while a new pattern, with A’s cell set to 0, goes in. At Update, A’s pin drives 0.
Scan again: Capture records the new level on net N, and 12 more bits come out.
The shifting took clock ticks, plus a few ticks per scan to move the TAP controller between states. With TCK at 1 MHz (megahertz, one million ticks per second), one tick lasts 1 microsecond, so the shifting took 54 microseconds.
If B’s cell reads 1 after the first pattern and 0 after the second, net N carries both levels from A to B. Reading 0 both times would mean that net N is stuck at 0, for example because it is shorted to ground. An input that is not connected at all can float and read either value, which is why both levels are tested. The processor in chip A executed no instruction during this test, and the test works on a board whose flash memory §6.6, which holds the program, is still empty.
Instruction-level debugging of chip A asks a different kind of question. On an Arm Cortex-M processor, a debugger halts the processor by writing the value 0xA05F0003 to the Debug Halting Control and Status Register (DHCSR) at address 0xE000EDF0. The upper 16 bits, 0xA05F, are a key that the register requires on every write; bit 0 enables halting debug, and bit 1 requests the halt. The debugger then reads the processor’s registers, such as the program counter §2.9, which holds the address of the next instruction. These requests reach the debug logic through the Arm debug interface. Whether they travel over the JTAG port or over SWD makes no difference to the result.
Stated precisely
IEEE 1149.1 fixes the protocol of the TAP. TMS and TDI are sampled at the rising edge of TCK, and TDO changes at the falling edge. Holding TMS at 1 for five ticks of TCK brings the TAP controller to its reset state from any state, which is why TRST is optional. After that reset, the instruction register selects the identification register if the chip has one, and the bypass register otherwise.
Let the chain hold chips , and let be the length in bits of the register that chip currently connects between its TDI and TDO, with for a chip in BYPASS. One full scan through the chain shifts bits, and a bit that enters at the host’s TDI leaves at the host’s TDO ticks later.
Boundary scan promises this and nothing more: while EXTEST is active, each output pin drives the value in its cell’s update latch, and at Capture each input cell records the logic level at its pin. Instruction-level debugging is not part of IEEE 1149.1. Its contract, meaning which debug registers exist, what a halt does and which memory a debugger may reach, comes from the processor’s debug architecture; for Arm processors, from the Arm debug interface and the processor’s architecture manual. IEEE 1149.1 contributes only a port that can carry those requests.
Limits and common mistakes
A JTAG port does not imply boundary scan. Many microcontrollers connect their JTAG port only to the processor’s debug logic, and some place a separate boundary-scan TAP next to the debug TAP in the same chain. A chip with only an SWD port has neither boundary scan nor a TAP.
EXTEST takes the pins away from the running firmware. If two chips drive one net with opposite levels, the drivers fight and can be damaged; loading safe values with SAMPLE/PRELOAD before switching to EXTEST avoids this. Whatever the pins control, such as a motor driver or a radio, also follows the test pattern instead of the firmware.
A passing boundary-scan test shows that logic levels arrive. It does not measure the resistance of a connection, and it does not show that the connection works at full operating speed.
Debug access through the port can read and change all of memory, so production devices often lock it; see the entry on debug access protection §16.4. An unlocked port on a deployed device gives an attacker with physical access full control.
The word JTAG is used loosely for the connector, for the probe and for debugging in general. When it appears in a question, establish which service is meant: the standard’s boundary scan, or a maker’s debug logic reached through the port.
Questions answered
How does boundary scan differ from instruction-level debugging?
Boundary scan acts on a chip’s pins, while instruction-level debugging acts on the program that the chip’s processor executes; the two share only the JTAG port. Boundary scan is defined by IEEE 1149.1 itself. It places a test cell between each pin and the chip’s internal logic. Using the instructions EXTEST (external test) and SAMPLE/PRELOAD, a host shifts values into these cells to drive output pins, and shifts the levels captured at input pins back out. Its purpose is to test the connections between chips on a circuit board, and it needs neither a processor nor firmware.
Instruction-level debugging uses the processor’s own debug logic to halt the processor, execute one instruction at a time, set breakpoints §14.29, and read or write registers and memory. IEEE 1149.1 does not define it. The processor’s architecture does, for Arm processors through the Arm debug interface, and the same functions are often reachable through a different port, SWD (Serial Wire Debug), which has no boundary scan. The effects differ as well: EXTEST takes the pins away from the chip’s own logic, while a debug halt stops the program and leaves the pins as the program last set them.
Related entries: SWD (§6.25), J-Link (§6.27), GDB (§6.28), APPROTECT and debug access protection (§16.4). Further reading: [34, 397, 398].