cancel
Showing results for 
Search instead for 
Did you mean: 

ST-LINK, SWD, JTAG <- Which To Use Where?

tonofsteel
Associate II
Posted on May 09, 2014 at 08:32

Using the disco boards for the STM32 they come with a built in ST-LINK/V2 on them and so when programming / debugging I have not had to give much thought to the details on this connection.

Can someone clarify what each of these do?  I ended up going down the rabbit hole and now I have 30 pages open from google searching and there is nothing that clearly outlines the programming/debugging questions that I can see.

This is what I think I know:

- There is Jtag 10 pin and 20 pin.  The 10 pin is newer and uses less pins.

- There is SWD which is equivalent from a protocol standpoint but uses 2 (or 3 including GND?) pins instead.  This is the ST-LINK/V2

So if after using the disco boards I have a prototype I want to create and I start drafting up the schematic what do I do about the programming/debugging of this?  From what I read there is a third option of using a serial port and a bootloader?  The ST-LINK/V2 comes shipped on the disco boards so if you buy an external hardware ST-LINK/V2 is there a header from the STM32 for the SWD/STLINK interface and another header for the JTAG interface?

I thought in the past I read a page that outlined nicely what each of these were and how/where you would use each one.  As well there were links to different programmers and what they were compatible with.  I cannot find this page again after searching through my bookmarks and scouring google.

I would just like to understand the different options, how they connect / when you would use them and any extra hardware needed for any of them.

One thing that seems confusing is that in the VisualGDB tutorial they show using STLINK for programming AND OpenOCD for debugging.  Does this mean that you would need both a STLINK /V2 connected to the SWD and a JTAG device to the JTAG 10 pin port?

Then I find JTAG devices but for example they will be from IAR, so does that mean it will not work when trying to use VisualGDB?

I thought JTAG was a standard and if I got a JTAG programmer, no matter who makes it, that I would be able to use it with anything that has a JTAG port.  So if I got a JTAG programmer and it worked with IAR/VisualGDB/Cosmic etc compilers and then I wanted to program a Xilinx FPGA would I be able to use the same JTAG hardware?

Also there was a JTAG device that was popular and in-expensive but I cannot find this link again either.  I thought there was a table on the page where you could get a cheaper version that was somewhat limited and it compared it to more featured more expensive versions.  Anyone know which one this might be?

I read in one forum that the person no longer uses anything other than SWD for the past few years and it has been working fine.  There was no mention on what was used to connect (would it be the stand-alone hardware version of the STLINK/V2?) 

Can someone please offer some clarification on this whole mess of protocols/devices/manufacturers/ports?  I am pretty sure from what I read that I can either hang the SWD or JTAG connector off of my board and I will be able to program using an external piece of hardware or have a bootloader and use a serial port to allow this as well.  (BTW what software would you use in each case, or is it the same?)

#confused #stm32
7 REPLIES 7
chen
Associate II
Posted on May 09, 2014 at 10:24

Hi

I think that the STM32 range does not support JTAG. The full signals required to support JTAG are not listed in the pin outs (at least for the STM32F405 device that I work on).

The STM32 only support SWD.

The ST-Link, Seggar J-Link and IAR I-Jet are 'debuggers'. They 'talk' the SWD protocol (the j-link and I-Jet also talk JTAG). The 'debugging/programming application' must support one of these devices.

The debugger can be used to download the binary AND do debugging.

''Then I find JTAG devices but for example they will be from IAR, so does that mean it will not work when trying to use VisualGDB?''

You need to pick a debugging application to work with. IAR produce their own. Seggar I think do not. ST do have one but I do not think may people use it.

Most people use one of these (in no particular order and there may be others) :

IAR workbench

Keil uVision

Atollic TrueStudio (Eclipse based)

CooCox (Eclipse based)

emBlocks

''I thought JTAG was a standard and if I got a JTAG programmer, no matter who makes it, that I would be able to use it with anything that has a JTAG port.''

Yes, this is mostly true. Depends on the device and the application.

For instance the Segar J-Link is a JTAG programmer and can be used for a number of different ARM based processors and with most of the programs I mentioned.

''Also there was a JTAG device that was popular and in-expensive but I cannot find this link again either.  I thought there was a table on the page where you could get a cheaper version that was somewhat limited and it compared it to more featured more expensive versions.  Anyone know which one this might be?''

The ST-Link is very cheap

The Segar J-Link is cheap for personal use but around £600 for commercial use.

No idea how much the IAR I-Jet is - they do not publish prices - you have to get a quote.

''From what I read there is a third option of using a serial port and a bootloader? ''

Yes, this is for programming ONLY. You cannot debug. (not unless you invent your own serial debug protocol).

There has been a few people querrying the circuit needed to support ST's SWD. Search the forum for them. A number of schematics have been posted

Mark Edwards
Associate II
Posted on May 09, 2014 at 21:23

''I think that the STM32 range does not support JTAG. The full signals required to support JTAG are not listed in the pin outs (at least for the STM32F405 device that I work on).

The STM32 only support SWD.''

If this is correct how can the STM32F429 support boundary scan tests? Which doesn't work with SWD.

I haven't tried to use it myself yet, but hope to in the future.

From the STM32F42x Reference Manual:

38.5 STM32F4xx JTAG TAP connection

The STM32F4xx MCUs integrate two serially connected JTAG TAPs, the boundary scan

TAP (IR is 5-bit wide) and the Cortexâ„¢-M4 with FPU TAP (IR is 4-bit wide).

To access the TAP of the Cortexâ„¢-M4 with FPU for debug purposes:

1. First, it is necessary to shift the BYPASS instruction of the boundary scan TAP.

2. Then, for each IR shift, the scan chain contains 9 bits (=5+4) and the unused TAP

instruction must be shifted in using the BYPASS instruction.

3. For each data shift, the unused TAP, which is in BYPASS mode, adds 1 extra data bit in

the data scan chain.

Note: Important: Once Serial-Wire is selected using the dedicated ARM JTAG sequence, the

boundary scan TAP is automatically disabled (JTMS forced high).

Posted on May 09, 2014 at 21:29

Everything except the STM32F0 support JTAG and SWD

You don't get an RTCK (Return Clock), but this shouldn't be a problem.

JTAG is a standard, what individual vendors do with the scan chains inside their devices is obviously completely up to them.

If you want to know what VisualGDB does/supports, you'll need to talk to them about that.

Generally speaking I'd recommend using the old 20 pin 0.1'' header, as practically everything will connect to it without magic cables. The 10 pin 0.05'' header is what we use for all our boards these days because it's significantly more compact, and new pods will support directly, or with a simple off the shelf adapter.

Try to avoid using custom headers, or the 5-6 in-line connector used by ST on the DISCO boards.

0690X0000060MmPQAU.gif

http://www.keil.com/support/man/docs/ulink2/ulink2_hw_connectors.htm

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on May 09, 2014 at 22:04

0690X00000602v9QAA.jpg
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
tonofsteel
Associate II
Posted on May 11, 2014 at 09:26

I think this makes more sense to me now.  (please correct me if I am wrong) There is the JTAG connectors that are on the boards and it is just that there are different versions of them, not that one is JTAG and another is something else because of the pin count.  The most common when dealing with dev boards (from what I see anyways) is the 20 pin, 10 pin and the ones that are found on the disco board (5-6 pin inline connector)

The JTAG vs SWD is just a setting/support option but the STLINK/V2 can do both.  The SWD uses a subset of the JTAG pins.  Now that I write this though I am wondering if the 5-6 pin disco connector is SWD and the other boards with the 10 pin are JTAG, or can the 5-6 pin be JTAG or SWD?

I didn't get too far into the exact specifics yet but it looks like the Segger JLink can do more advanced debugging than what the STLINK/V2 can.  All of the toolchain options that I am considering though seem to support both so any consequences of choosing one over the other should be able to be resolved if needed.

Any other bootloaders are programmed into the STM32 and once you do this then you can use other methods to program the STM32, but this is dependant on what the bootloader implements (serial, Ethernet, CAN etc)  Custom software is used to connect and upload to the board using a custom bootloader.

The onboard built in JTAG bootloader is always there in ROM though and can be accessed by holding down reset while power cycling the board.

All of this seems fairly basic, but just the SWD vs JTAG specifics are still a little vague to me.
tonofsteel
Associate II
Posted on May 11, 2014 at 09:45

SWD is a 2-pin electrical alternative JTAG interface with the same JTAG protocol on top. To benefit from that you need SWD support from the target chip and you need a dongle that goes between the chip and you development PC.

I think this explains it, SWD and JTAG are the same thing except for the pin counts.  Also the chip and STLINK, JLINK etc needs to support it.  It achieves the same thing but just is a different way of doing it using a different protocol and pins. (The pins are common between SWD and JTAG, just SWD uses less of them)

Also:

Switching between JTAG and SWD modes of debug

Some Cortex-M based MCUs support both SWD and JTAG, others support only SWD (such as NXP LPC11xx and LPC13xx). Where both are supported, there are special sequences defined to switch from JTAG mode (default) to SWD mode (and vice versa) that can sent to the core. This switch sequence uses TMS (SWDIO), and this line is connected for any SWD/JTAG connection

chen
Associate II
Posted on May 12, 2014 at 10:18

Hi

''Any other bootloaders are programmed into the STM32 and once you do this then you can use other methods to program the STM32, but this is dependant on what the bootloader implements (serial, Ethernet, CAN etc)  Custom software is used to connect and upload to the board using a custom bootloader.''

''The onboard built in JTAG bootloader is always there in ROM though and can be accessed by holding down reset while power cycling the board.''

The STM32 series has built in bootloader that supports USB, RS232, I2C (maysbe SPI amd CAN but not sure about these 2).

The built in bootloader can be started by :

Pulling BOOT0 pin high and booting the STM32.

You can choose to write your own custom bootloader. (That is what we have chosen to do here in my company).

'' SWD vs JTAG specifics are still a little vague to me.''

Both are hardware pins and a communication protocol to communicate with the processor for programming and debugging the processor application code.

''Some Cortex-M based MCUs support both SWD and JTAG, others support only SWD''

Yes.

I personally have never managed to get any Cortex M range to work with JTAG (used STM, NXP and Freescale, looked at TI bu never debugged on them), I have always had to use SWD. It does not seem to make any difference in downloading or debugging.