The standard JTAG connector for ARM processors is the huge 20 pin IDC header. It has a whole bunch of unused pins and takes up a lot of board space. There are a several alternatives that reduce the pin count but, for a bare minimum, you can use Serial Wire Debug (SWD)…

It is often stated that SWD needs only two wires to connect to the processor but that overlooks the need for a common ground. Actual implementations are also likely to want a power connection to drive level converters or to tell the programming/debug hardware that the device is present and powered up. Then there is the reset line. While not strictly needed, your debug hardware and software may need to be able to reset the processor to overcome issues caused by reassigning the SWD pins in your target code. If you don’t need the reset though, you can easily manage just 4 pins to the target.

My current development tools are the Rowley Crossworks for ARM suite. I run that on a mac so all the following is predicated upon use of a OSX and I have no idea how it all behaves under Windows. Just lately, Rowley added support for the STLINK/V2 programmer. You can buy these quite readily but don’t get the earlier STLINK. It will work fine with other tools but not Crossworks on a mac. The STLINK/V2 is probably one of the cheapest debugger/programmers available – it can be had from Farnell for about £34. It is small and neat and connects to the PC using a common mini-USB lead. Best of all, for the Mac, it needs no drivers. Crossworks sees it automatically. All you need to remember is to set it up to use SWD rather than JTAG. As an extra benefit, the new STM32F4Discovery has an STLINK/V2 built in which can aso be used as a slightly less elegant stand-alone debugger/programmer for other targets.

The connector provided on the STLINK/V2 for STM32 targets is the standard 20-pin header so you will need to make an adaptor to bring out just the SWD signals to your target. The minimum requirement is four wires and it is quite easy to use four separate wires into a standard IDC connector directly. Be sure to use suitable wires for this – they need an outside diameter of no more than 1mm if you are to avoid accidentally connecting to the pins either side. On the target board side, use whatever is convenient.

STLINK/V2 four wire SWD connection for STM32

For my breadboarded test rig, I used a four pin Harwin M20 connector. Even on a half size micromouse, this will not take up much room and I may use it as the only debug/programming connector.

The pins on the 20-pin standard JTAG connector to use are:

Pin 1 – VCC:
This is the traget board Vcc. It is used by the STLINK/V2
Pin 7 – TMS/SWDIO:
The SWD Data signal
Pin 8 – GND:
Be sure there is a common ground
Pin 9 – TCK/SWCLK
The SWD Clock Signal
Pin 15 – nSRST/RESET
System reset – probably optional

 You can find out more about JTAG/SWD connectors here:

This Post Has 25 Comments

  1. digital_dreamer

    Thanks for all this great info on the STM32F4! Just got my Discovery board and, like you, am on a Mac, so this info is very helpful.

    Given that there is a embedded STLINK/V2 on the STM32F4Discovery card, I’m a bit disappointed that there is no way to use it with via USB port connected to a Mac, but must use a debugger/programmer adapter.

    I’m new at this stuff and find the STLINK/V2 issue a little confusing. When some use this term, I immediately think of the external adapter. But, this board has the STLINK/V2 tool embedded, so I’m left with wondering a bit.

    Looking at your previous article (…taste of speed), when you said Crossworks will support the STLINK/V2, I’m assuming you mean via external STLINK/V2 debugger/programmer, as mentioned here in this article. Crossworks will not support the embedded STLINK/V2 tool via USB on the Mac (like it does in WIN), correct? Or, am I a bit confused with how this interface is being used?

    I’m a newbie just venturing into MCUs, but used to program in assembly on 8-bit micros (Z-80, 6502, 6809, etc.) some 25 years ago.

    best of wishes,
    MAJ

  2. Peter Harrison

    Perhaps I was not clear. the STM32F4 Discovery board has a built-in STLINK/V2. Crossworks on the mac can use that either to program the processor on the discovery board or as a programmer for external target boards. I also purchased a stand-alone STLINK/V2 and can use that as a general- programmer, both for the discovery board and other SRM32 targets. And, I presume, other ARM targets but I don’t have any.

    Does that help?

  3. digital_dreamer

    Yes, that’s perfectly clear now and certainly helps! The confusion was on my part. 🙂

    Best of wishes and thanks for your contributions.
    MAJ

  4. Rodrigo

    Hi, great site, you help a lot with STM32 informations. I bought a ST-LINK/V2 and use CrossWorks (2.1.2.2011120900.13079) on Mac OS Lion. How you set it up to working with this programmer?

    Thanks

  5. Peter Harrison

    To use the SWD and ST-LINK/V2 with Crossworks, you need only select it in the target device list and then, in the target properties window, change the Target Interface Type to SWD.

    On a Mac, this just works. It may need additional work on Windows or Linux though. I run neither here I am afraid.

  6. Sumankumar

    Hi all,

    Could you pls any one help me on this.

    I am using one STM32217xx in one of the product. i am making one fixture for the flashing the firmware to the PCBA. Can this STLINK SWD for STM32 can be used as unviersal flash programmer for flashing the firmware to the controller

    Rgds,
    Suman

  7. Alvaro Torres Di Zeo

    Hi,

    really useful info!

    Do you know the connectors part numbers or references?

    Thank you.

  8. fabrice

    Hi,

    I have some difficulties with the STLINK V2. I used a J-Link to program/debug my STM32F205 and it works well. I just bought a ST LINK V2. First I used my cable from J-LINK to program, so it seems to program (I got the progress bar) but in fact, it still be the old program in my µc. So I just made your cable, and the same, it programs well, but in fact it still be the old program.
    Have you some ideas or settings to do ?

    Thank you

  9. Peter Harrison

    Have you made sure that the programmer is set into SWD mode?

  10. fabrice

    Hi,

    Thank you for your reply. Yes, the programmer is set in SWD mode, I have checked.

  11. dave

    Hi, thanks for all the info, it is truly invaluable to us just starting.

    Have you ever dealt with any noise issues on the SWD interface?

    I have a STM32F1 discovery that I use solely as a programmer for my own creations. I connect GND, SWDIO and SWCLK (the target has it’s own 3.3 regulator so I currently do not connect the power, but the results are the same if I power my handrolled board from the 3.3v output of the Discovery board).

    I notice that if the SWDIO and SWCLK lines are nearby each other, then I cannot enumerate the target device (I use texane stlink to program with, but it shouldn’t matter). If I hold the SWDIO and SWCLK lines physically apart with my hand, then stlink recognizes the target and programs no problem. I am just using dupont female/female jumper wires I had lying around. They are only about 6 inches long.

    I don’t see any other passives in the STM32 discovery kits on the SWD bus. Any suggestions?

  12. Peter Harrison

    I am afraid that I have never had any trouble with any of my programmer arrangements.

  13. Eldad Wasserman

    Hi,

    I need some help…

    I would like to communicate with the discovery board only via the MINI USB and also communicate via this MINI USB in a regular way, not for debugging – for regular RS232 communication…

    anybody know if this Is possible ?

    Or, if’ it’s not possible, how I can send 5V power via the MICRO USB ?

    I hope someone can help me here …

    Eldad

  14. Paul D.

    It appears that you have the clock and data positions swapped in your diagram. The second pin after the power should be the clock, yes? Every diagram I can find has it that way.

  15. Paul D.

    …sorry, maybe I should clarify: if you put the connections inline as they are on a 4 or 6 pin SWD port of a Discovery or Nucleo board, the Clock comes right after the Power, pins 2 and 1 respectively. You don’t enumerate but your listing them in the order that you do might be misleading to someone like me who is utilizing a board such as this (Nucleo).

  16. Peter Harrison

    The pin numbers shown refer specifically to the ‘standard’ 20 pin JTAG connector as found on the STLINK/V2. I did not bother to look at any of the other configurations for this.

    You are probably correct for other debug interfaces. Can you link to some of the other references that you have found so that I can compare?

  17. Mosi

    Peter where did you get that cable with VCC GND SWDIO SWCLK labels on it? What kind of cable is that? It’s really cute!

  18. Peter Harrison

    I made it up using Harwin M20 crimp connectors and housing. The label was just printed out and stuck on.

  19. Mosi

    I see. Cause I though there is something like that in the package but apparently it’s not! Yeah, you know it’s very funny that ST only includes the old 20 pin JTAG connector in the package and nothing more. I don’t know why they are bragging about their SWD interface!

  20. stephen parkinson

    swd connections on the target vary especially if brought out as on red and blue generic stm32f103c8t6 system boards advertised on aliexpress.
    could play safe and look them in the manual for the chip in use

  21. Brian Cavanagh

    Hi, I’m using the ST-Link/V2 to program an STM32-F427… If I understand correctly, the board that I have the STM32 on powers the ST-Link programmer? If I’m correct, does anyone know how much current is required to power the ST-Link? Thanks

  22. Peter Harrison

    The programmer is powered from the host. If there is a requirement for power on the target to be connected to power on the programmer, it is only for level-shifters. No other power from the target is used for any part of the programmer.

  23. Amir

    Hello
    I got a question, If my target board feeds with its own Vcc, do I need still use Vcc wire (connected to the debugger- here, the red wire)? Generally what the purpose of using this Vcc is?

    Thank you.

  24. Peter Harrison

    I do not use the debugger Vcc. So long as the debugger and target voltages are the same (3V3 I think) you should not need it. I believe it is there for level shifters whenthe voltages are different.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.