Electronic – STM32 & ST-LINK – SWD connector not working

st-linkstm32stm32f4swd

I am using an ST-LINK/V2 debugger (Firmware version V2.J27.S6, up-to-date) to program my STM32F407G discovery board. So far, I have been using USB to flash the MCU, using the STM32 ST-LINK Utility v4.0.0.0 (driver v4.4.0.0, st-link_cli.exe v3.0.0.0, should all be up-to-date). Now we are getting rid of the discovery board and we need to flash the MCU using the SWD interface. However, I found some behaviour which is inconsistent with the ST-LINK/V2 debugger manual (UM1075).

The connection of pins as per manual is

JTAG (on ST-LINK debugger) – SWD (CN2 on STM32 board)

  • 1 – 1 (MCU VDD)
  • 5 – 2 (GND)
  • 7 – 3 (SWDIO)
  • 9 – 4 (SWDCLK)

However, in this configuration I get the error

Can not connect to target!

The logfile reads

ST-Link/V2 device detected
Target voltage detected: 0.722835
Error getting target IDCODE: if SWD, check SWD connection
Error (4) while initializing ST-Link in SWD mode

This error I found also in this question but no satisfying answer. I think it essentially means that it does not detect the VDD voltage on the STM32 board (although it is powered with 3V).

I managed to solve the issue by directly connecting the pins in the following way:

  • JTAG 1 – P1 VDD
  • JTAG 5 – P1 GND
  • JTAG 7 – P2 PA13
  • JTAG 9 – P2 PA15

And now everything works fine, I can flash the board as I used to with USB.

I found similar questions here and here but none of them helped.

Interestingly, both types of behaviour do not depend on the ST-LINK CN3 jumper positions on the STM32 board. (Why not?)

Why can't I use the SWD connector? Why does the ST-LINK/V2 do not detect the VDD voltage?

Edit

Found that R2 is not fitted (see SWD schematic p. 27 of STM32F407G discovery board manual). I had suspected fitting this with a 100R resistor would solve the problem but it made no difference.

Best Answer

The SWD connector on a Discovery board (CN2) is not for programming the on-board Target MCU.

Rather, it is to allow the on-board ST-LINK to be used to program an external target.

If you want to program the on-board target with a different programmer, you will need to study the schematics, find all the relevant signals, and make sure the on-board programmer is not loading the lines - which sounds to be about what you did in picking up the SWD pins from their GPIO breakout positions.

From looking at the schematics, it looks like as if with the CN3 jumpers removed, the Target SWCLK should be available on CN3-2 and its SWDIO on CN3-4. But pins 1 and 3 of that connector are not power and ground - rather, they are the on-board programmer's versions of these signals arriving at the jumper positions.