I'm pretty new to embedded systems, and I keep seeing this term used all the time, but I can't quite understand what is it. A quick search online yields this Wikipedia page: https://en.wikipedia.org/wiki/Joint_Test_Action_Group which describe it as some-kind of protocol for debugging. But in other contexts it used like it's able to program a chip's memory like a programmer. What is it?
- Anybody can ask a question
- Anybody can answer
- The best answers are voted up and rise to the top
It is like USB, SPI, I2C, and other "busses", and it has a number of popular uses, not limited to:
It is a generic-ish way to allow you to isolate things on the chain you want to send a series of bits to or get a series of bits from, in a way that each thing you want to talk to can be designed for various numbers of bits from a small number to a large number. For a debugger you would naturally have it write to or read from a register-sized thing in your chip - maybe a 16 bit register or 32 bit. But for silicon or board testing your scan chain might be dozens of bits. Each individual thing you address can vary in size, if you want, from any other thing, making this a very versatile bus with a relatively small number of pins that is attractive for these types of use cases.
Perhaps because of the popularity for software debugging they now have some two pin solutions to save on pin count for microcontrollers and perhaps others will adopt that, perhaps not.
JTAG was originally an interface used for testing PCBs after assembly. The IO lines on the chips could be controlled and read via the JTAG ports allowing a board test sequence to be performed. Later on it also started to be used as a programming and debug interface. What functionality is available over JTAG will depend on the particular IC you are dealing with.
One advantage of JTAG over most other programming interfaces is that devices can be daisy chained. So one JTAG port can serve to program/debug/test multiple devices (though I would advise designing your systems so that different brands of chip can be split on to different chains, while the low level JTAG protocol is pretty standardised unfortunately the tools you need to program/debug the chips are not).
JTAG is somewhat an odd term. To begin, the term can specify a specific connector and protocol, composed of a clock signal (TCK), mode-select (TMS), and data in/out (TDI/TDO). This comprises a network of devices, where each device's TDO is connected to the next device's TDI in a so-called scan chain. TMS is used to put all devices simultaneously into various modes.
The devices on the scan chain are typically connected as one large shift register comprised of registers in each individual device. When devices are in the SHIFT_IR or SHIFT_DR state, they connect to the scan chain one of two temporary registers: An instruction register, and a data register.
Once a value is shifted in, the UPDATE_IR or UPDATE_DR mode can be activated by setting TMS appropriately while toggling TCK. At this point, the value shifted into the register "takes effect". For example, shifting various sequences into the IR of an FPGA and transitioning into UPDATE_IR will cause the FPGA to enter various modes such as configuration, readback, normal runtime, or access specific user registers and JTAG-specific primitives instantiated in the design.
Likewise, capture states can be used to "read" a value from the device and put it into the IR or DR, to be shifted out through TDO and ultimately read by the JTAG programmer.
JTAG defines a serial protocol, and some commands, to allow access to internal registers within complex ICs. This allows a tester to get observability and controllability in a standard way using few pins.
The original use was for 'boundary scan', where all the I/O pins could be read and driven by a large shift register that circles the chip. However, it was quickly augmented to add further shift registers to access the internals of the chip, including memories.
You rarely bit-bang JTAG, access is usually through libraries, aka drivers, supplied by the IC manufacturer, and used by the test system and test access adapter.
There is what JTAG 'means' and there is what JTAG 'is'. As others have pointed out JTAG 'is' a industry standard bus interface for manufacturing testing, as in Joint Test Action Group.
What JTAG 'means' to an embedded software developer is the debug interface on the SoC/microprocessor for external debug of embedded software running on the chip. Nearly every CPU/SoC on the market uses the JTAG interface not only for manufacturing tests, but for software debug support. You will find a JTAG interface on everything from server class x86 CPUs to under $50 home WiFi routers. With the right interface hardware, and the right software, these interfaces will grant you the ability to read/write memory, set breakpoints, and single-step code.
The key of course is getting the right hardware and software. Even though the basic JTAG interface is standardized, the specific software debug facilities available in a device may not be. JTAG is like TCP/IP. It exists in the middle of the application stack. You need the right physical layer to communicate with the equipment (i.e. what do you mean this thing uses 10-Base-2?!?!?), and you need the right application software above it (what do you mean I need a Gopher client?!?!?!). However the strength of the ARM ecosystem has lead some degree of standardization there (see OpenOCD).
You also asked about using JTAG to program flash. Yes, some software uses it for that purpose as well. The SoC may provide JTAG facilities to read/write from CPU memory address spaces, it may provide direct access to flash controllers, and at a minimum JTAG provides raw low-level access to I/O pins on the edge of the chip (this was the original purpose of JTAG, to enable continuity testing of chip to chip interconnections during manufacturing test, i.e. 'JTAG boundary scan'). Any of these facilities could be use by clever programmers to drive the signals necessary to reprogram a flash chip in case a device is accidentally 'bricked'.