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 v126.96.36.199 (driver v188.8.131.52, st-link_cli.exe v184.108.40.206, 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.
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?
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.