SWD vs JTAG: Similarities & Differences Explained..!!

Everyone at their embedded journey will meet these 2 major protocols. When they do a few questions inevitably come up in their mind!

  • Is one better than the other?
  • If so how?
  • If we are designing our own board and we got to choose one then which option should we choose?

This article is all about answering the above questions! If you are in a hurry here is the short version of the answer for you!

The Short Version of the Answer: SWD vs JTAG

The table below shows the main differences between SWD and JTAG standards.

SWDJTAG
Pin count24
FunctionalitiesOnly programming and debuggingProgramming, debugging and Boundary scanning for production tests
Supported CPU architecturesOnly ARMJTAG is an independent group and hence is supported by many architectures not just limited to ARM
TopologyStarDaisy chained
Special featuresPrinting debug info via debug portnot supported

Now that we have seen the short version, let’s go ahead and look at the longer and more informative version and learn the key differences between SWD and JTAG starting from the fundamentals!

Okay let’s begin!

What Are Debuggers?

Debuggers, in simple words, are devices that translate the commands send from the PC (eg. via USB protocol) to the language ( eg. SWD or JTAG protocol) that is understood by the microcontrollers (the peripheral inside the microcontroller that is responsible for loading code and controlling execution to be exact).

Need for Debugging Standards

Before looking at the need for debugging standards let’s start with answering a simple question.

What is a Standard? A Standard, in simple terms, is a set of rules and protocols that every player in a particular industry agreed to follow and implement.

Earlier before the advent of protocols like SWD and JTAG the debugging world was just full of chaos. Each major manufacturer came up with their own proprietary way of loading the code onto their microcontrollers and as a result the only ones who had to suffer were people like us the embedded engineers. Each time a big manufacturer releases a microcontroller, we, the embedded engineers, need to learn about their proprietary protocols for loading code into our microcontrollers.

Also, the debug adapters were expensive since the manufacturers don’t really have any competition who makes debug adapters to match with their protocols as the protocols were proprietary. Another reason why they were expensive is because of a lack of volume since they can sell their debug adapters to only those people who use the microcontrollers manufactured by them!

The third issue that gave rise to these standards is the issue of production testing of electronic devices. Consider this scenario, you have 4 chips from 4 different manufacturers on the board you designed and you wish to implement some automated testing on them to make the production process more efficient. But since all the boards have their own protocol now you need to make a super complicated production code that accommodates for the complexity and you need 4 different debuggers mounted to the test points of your board leading to the added cost, production time and programming time.

In their essence all of these proprietary protocols perform the same activities like loading the code and giving the ability to debug and test these issues. They just do it in a slightly different manner.

To combat these 3 issues of

  • reducing the time invest in learning,
  • reducing the expenses, and
  • making production testing more efficient,

engineers from all major microcontroller manufacturers and product manufacturers got together discussed and made some specifications for how a debugging protocol should work. The result of such get-togethers are standards like JTAG.

This way all of the microcontroller manufacturers can all implement the same debugging protocol so that the same debug adapter can be used with all of the microcontrollers that implement the given standard!

There are 2 such major standards available for loading and debugging code on microcontrollers and FPGAs. Let’s start with learning about the JTAG standard!

The JTAG Standard

JTAG stands for Joint Test Action Group, just a fancy name for the team of engineers from major manufacturers who sat together and came up with the standard that we now refer to as JTAG.

This group started their discussions in the late 1980s and in 1990 they officially released a document explaining the standard in the IEEE. (IEEE stands for Institute of Electrical and Electronics Engineers, is an international organization where all standards like WiFi, Bluetooth, etc are published). The protocol they came up with was documented into IEEE 1149.1 in 1990. Later this document was revised and made better and at the time of this writing the latest standard was IEEE 1149.7.

The interesting story about JTAG is that the main reason this group was formed was to help with the production and testing of electronic devices and not actually to make a standard for software debugging! But as time went on JTAG became very popular in its usage on software debugging also!

JTAG Pins and Architecture

JTAG basically comes with 5 pins namely

  • TDI (Test Data In, serial input line)
  • TDO (Test Data Out, serial output line)
  • TCK (Test Clock, clock input for the protocol)
  • TMS (Test Mode Select, control input) and
  • TRST (Test Reset)

These 5 pins are collectively known as Test Access Port or TAP for short. Among these the TRST is optional and we can make our boards compatible with JTAG with just the other 4!

JTAG uses daisy chaining topology for making connections between chips and hence the speed is determined by the slowest chip on the chain.

Boundary Scanning Capability

What is Boundary Scanning? Boundary Scanning is a feature that gives us the ability to test the assembled PCBs after production for short circuits and open circuits. This is achieved using some special hardware inside each chip known as boundary scanning cells. These cells can be used to control each individual pin of the chips we have on our PCB to turn them on/off. This way soldering errors can be caught very easily without the need for a test points/bed-of-nails system!

JTAG is the standard that introduced this boundary scanning technology and is especially irreplaceable when it comes to production testing of Ball Grid Array (BGA) chips, as in the case of BGAs “bed of nails” testing is simply not possible!

If you are interested in learning more about Boundary scanning, I suggest you read this excellent article over at xjtag

The SWD Standard

SWD stands for Serial Wire Debug is the protocol designed by ARM for programming and debugging their microcontrollers. Since SWD specializes in programming and debugging, it comes with many special features that is usually not available anywhere else like sending debug info to the computer via the IO line. Also since it is specially made by ARM for use in their devices, SWD’s performance is usually the best in class!

Since ARM’s business model is just licensing its designs a lot of manufacturers make debug adapters based on SWD designs and this makes SWD as ubiquitous as ARM-based chips themselves!

SWD Pins and Architecture

SWD protocol has only 2 pins namely

  • SWDIO (Serial Wire Data Input Output: the data line) and
  • SWCLK (Serial Wire Clock: the clock line)

SWD supports star topology in terms of architecture.

SWD/JTAG Intercompatibility

You can find many microcontrollers and debug adapters that can support both SWD and JTAG protocols. They usually achieve this by having a single set of external pins that are internally multiplexed to both an SWD peripheral and a JTAG peripheral. Usually one of these protocols is selected as default and you can switch between the 2 of them using some special set of instructions as given by the manufacturer.

Maybe you are in the middle of choosing a chip for your next project and you got 2 similar chips with the major difference between them is that one only supports SWD, while the other only supports JTAG, now how do you decide?

Let’s look at the answer to the above questions in the next section!

SWD Protocol’s Strengths

Let’s have a look at the pros SWD have against JTAG

  • only requires 2 lines instead of 4 on JTAG and this makes the schematic design part easier
  • SWD has special features like printing out debug info over its I/O line
  • SWD has better overall performance in terms of speed as compared to JTAG

JTAG Protocol’s Strengths

Next, let’s have a look at the pros JTAGs have against SWD.

  • JTAG is not limited to ARM chips and is supported outside the ARM ecosystem
  • JTAG is multipurpose as it can be used for programming, debugging and production testing
  • JTAG is an independent group and is expected to evolve as a protocol

In other factors like price, both JTAG and SWD adapters are equally inexpensive and hence is not important for us to make our decision.

When to choose SWD over JTAG

Let’s look at a few scenarios where you can choose SWD

  • If your schematics/board design is simple enough to test without the boundary scanning capability of JTAG (BGA’s make it harder!)
  • Debugging performance is more important than production testing as your device is focussed to serve research rather than on mass production!
  • Your product has constraints regarding dimensions, then the space saved by the presence 2 extra pins in JTAG as opposed to SWD can be an advantage
  • Your hardware design is too complex and you can’t route the extra 2 signals to the microcontroller

When to choose JTAG over SWD

Let’s look at a few scenarios where you can choose JTAG

  • Your hardware design is very complex and you need the boundary scanning capability for running production tests
  • Your device is going to be mass-produced
  • You feel that debugging performance of JTAG is enough for your use case
  • The size increase due to extra pins and routes on your PCB design is not a big deal for your device.

But then, if both options are available for you in your microcontroller how can you make a decision? The answer for this one is simple, just keep the microcontroller in SWD mode during programming and switch over to JTAG during production testing!

Summary

Let’s end this article by looking at a table of differences between these 2 debugging standards

SWDJTAG
Pin count24
FunctionalitiesOnly programming and debuggingProgramming, debugging and Boundary scanning for production tests
Supported CPU architecturesOnly ARMJTAG is an independent group and hence is supported by many architectures not just limited to ARM
TopologyStarDaisy chained
Special featuresPrinting debug info via debug portnot supported

And with that, I will conclude this article!

I hope you guys enjoyed this article and learned something useful.

If you liked the post, feel free to share this post with your friends and colleagues!

Related Articles

Here are some of my other articles that might interest you!

Hardware, Software, Firmware, Middleware, Drivers, OS & Applications, The Difference?

Top 14 Alternatives to Raspberry Pi 4B

Video: Embedded Software Engineer Interview Questions

Embedded Engineers Salaries In Europe

Photo of author
Editor
Balaji Gunasekaran
Balaji Gunasekaran is a Senior Software Engineer with a Master of Science degree in Mechatronics and a bachelor’s degree in Electrical and Electronics Engineering. He loves to write about tech and has written more than 300 articles. He has also published the book “Cracking the Embedded Software Engineering Interview”. You can follow him on LinkedIn