(first posting here so bear with!)


I'm a very novice embedded programmer and have hit a wall trying to use an STM32 discovery board as an ST-Link programmer to an external STM32F051K8T. I know that the hardware I have is correct as I have inherited this project from someone who had everything working and was able to program without issue.

The SWD connections are as follows:

Discovery board CN3 -> external STM32F051K8T
NRST -> NRST with NOT, pulled up to VDD with 1K
SWO -> PB3

I have removed the CN2 jumpers from the discovery board, and am powering the external chip via a UART USB lead.

I'm using the Windows ST-Link app to attempt to connect to the board with the following settings: st-link settings

The only other observation I have made that might be of some use is that when I initially connect the SWD lead to the external board, an LED on it remains on (this LED is permanently on when the board is powered with the current firmware loaded onto it). When I attempt to connect to target in the ST-Link app and get the below failure message, the LED turns off and remains off until I cycle power to the board or remove the SWD lead.

14:11:34 : Can not connect to target!
                  If you're trying to connect to an STM32W1xx device, please select Normal or HotPlug mode from Target->Settings menu.
                  If you're trying to connect to a low frequency application , please select a lower SWD Frequency mode from Target->Settings menu.
14:12:55 : Internal command error

I have exhausted all avenues I can think of to try to get this project working so any help would be much appreciated!



2018-12-03 10:43 edit:

I'm not at liberty to share the entire schematic but here are the SWD connections. Also, power comes over USB through a UART -> I2C bridge and then regulated by a TPS61071DDCR.

SWD connector Vdd -> Vcc

enter image description here enter image description here

  • \$\begingroup\$ Tell us about the actual physical implementation of the wiring, not just the logical connections. Trigger the target reset just before attempting connection. Hold the target in reset while attempting connection. Use a real power source rather than stealing current from a USB-UART's wimpy on-chip regulator. Reduce the SWD clock rate as far as it will go. Change the boot mode pin to have it start up in the bootloader, avoiding any firmware or corrupt image which might re-purpose the SWD pins or enter a deep suspend where SWD does not work. Try another target board. \$\endgroup\$ Nov 30, 2018 at 15:45
  • 3
    \$\begingroup\$ Possible duplicate of How to use external ST-Link to debug/program STM32F103 MCU? \$\endgroup\$
    – A.R.C.
    Dec 3, 2018 at 7:08
  • \$\begingroup\$ Hi @ChrisStratton, hopefully my edits have addressed some of your points. I have tried with two identical target boards and had no luck with either. I've also tried various SWD clock rates and none have worked. How do I go about controlling what the boot mode pin is doing? Are there better applications than the ST-Link Windows app for doing so? \$\endgroup\$
    – Batters
    Dec 3, 2018 at 11:00
  • \$\begingroup\$ And @A.R.C. I had seen that question but don't think it answers mine. I've tested my VDD pin and found that it's at 3V3 when the target board is powered externally which I believe is correct? \$\endgroup\$
    – Batters
    Dec 3, 2018 at 11:02
  • 4
    \$\begingroup\$ I'm voting to close this question as off-topic because the asker has abandoned it and failed to ever provide the repeatedly requested details of the physical implementation of the wiring \$\endgroup\$ Aug 5, 2019 at 18:05

3 Answers 3


I've managed to solve my question without 100% knowing why but here's what I did:

  • Set SWD frequency to the lowest setting, 5kHz
  • Use a clamping stand to hold the programming cable (with spring loaded pins) onto the external board
  • Check continuity from discovery board's CN2 to the relevant pins on the external STM32 chip

At some point, things just started to work and the ST-Link app displayed the device's memory contents and was able to program it! So I guess the solution was either ensuring correct connection, or just setting the SWD frequency low and being persistent with trying to connect, cycling power, trying to connect again, etc., etc.


Try changing "Reset Mode" to a setting for software reset. The programmer is perfectly good at sending a software reset command to the chip before uploading code, but it won't try to if you have hardware reset enabled, and since you don't have the NRST pin of the programmer connected to the reset pin on the board, the chip will never get reset.

  • \$\begingroup\$ I've just tried changing the mode to either 'normal' or 'hot plug' and using 'Software System Reset' as the reset mode. In both of these configurations I get a "can not connected to target" error and it suggests I switch mode to 'connect under reset'. When in 'connect under reset' mode the reset mode is forced to 'hardware reset' \$\endgroup\$
    – Batters
    Nov 30, 2018 at 15:05
  • \$\begingroup\$ Are you required to use the ST Link App? \$\endgroup\$ Nov 30, 2018 at 15:09
  • \$\begingroup\$ Nop, no requirements other than to get it working! Also not pegged to Windows either, currently have only been able to get code to build in Keil but Ubuntu tooling would be preferable \$\endgroup\$
    – Batters
    Nov 30, 2018 at 15:11
  • \$\begingroup\$ I would try putting your code into SW4STM32 and uploading with the debug interface there, I've had good experiences with that. I can't speak for Keil as I haven't used it. \$\endgroup\$ Nov 30, 2018 at 15:13
  • \$\begingroup\$ I'll give it a go, I had a go with it yesterday on my linux machine to no avail \$\endgroup\$
    – Batters
    Nov 30, 2018 at 15:26

Make sure that the Idd pin header is jumpered. It is there to allow you to measure the current consumption to the STM32, but won't provide current to the STM32 if not jumpered (obviously).

  • 2
    \$\begingroup\$ This is not applicable in the situation of the question actually asked as the board is being used only as a programmer for an external target. The current monitor jumper could be a reason for failure of the on board target but that is not what the question is about. \$\endgroup\$ Aug 5, 2019 at 18:03

Not the answer you're looking for? Browse other questions tagged or ask your own question.