# How to use external ST-Link to debug/program STM32F103 MCU?

I'm using STM32F103 MCU for my own project and want to use the ST-Link of STM32F411 Nucleo board for external debugging / programming purposes.

I've set the CN2 jumpers OFF and my actual question is in the pinouts of SWO (CN2). How I proceed on this is as follows:

• PIN 1 (of SWO) is VDD_Target
• PIN 2 is SWCLK
• PIN 3 is GND
• PIN 4 is SWDIO
• PIN 5 is NRST
• PIN 6 is SWO

To the best of my knowledge, I shouldn't use all these pins above. As in, I've connected

• PIN 2 to PIN 37 (or PA14) in MCU
• PIN 3 to GND
• PIN 4 to PIN 34 (or PA13)
• PIN 5 to PIN 7 or (RESET) in target MCU.

Not sure if I should connect SWO pin as it's set as "reserved" (Why?). Also I'm giving 3.3 V to VIN pin of MCU, means that I don't need to connect VDD (PIN 1 of stlink).

Please refer to this table I've taken from the official datasheet:

Here's the general pinout configuration of the MCU here:

I've tested "almost" everything with oscilloscope and tester and everything seems okay. What else I'm missing here? Should I do anything with BOOT0 or BOOT1 pins?

First of all, you are right, if your board has already got a supply voltage source you do not have to connect ST-Link's VDD pin.

The second thing I would recommend you is to open the STM32F411 Nucleo board's reference manual and look at the schematics. Especially the part where the ST-Link is connected to the controller on the board.

By ST Microelectronics, SWCLK, SWDIO, NRST and SWO (and GND of course) are connected to the target MCU. The additional SWO pin is used for debug purposes, you can access printed data with the printf function through this pin with ST-Link Utility.

The Printf via SWO Viewer displays the printf data sent from the target through SWO.

So I can recommend you to connect SWO as well, can be useful later. Connect your MCU to ST-Link just like they have connected the Nucleo's MCU to it.

As for boot configurations, there are three selectable options, easiest it to stick with the Main Flash and tie Boot0 to GND, but I do not know your requirements so it is up to you to choose.

• While you can "get away with" not connecting the VDD pin, it isn't there to be a supply, but rather there to detect the target's supply voltage (see how it is connected to an analog input). A more sophisticated debug interface could keep its lines low without that, and only raise them to the corresponding supply level, supporting multiple target voltages. The reset line is not normally needed (unlike with many other SWD implementations). It is key to recovering from bad loads and firmwares which disable the SWD pins, but can be manually manipulated as well. – Chris Stratton Dec 17 '15 at 13:52
• On an STM32F1xx board the main reason for making BOOT0 externally select-able would be if there's a desire to use the factory ROM UART (etc) bootloader. On the '103 this does not support USB as it does on many of ST's later parts. If one desired a USB bootloader on the '103 it has to be in the main flash memory, so the BOOT0 pin isn't useful for that. – Chris Stratton Dec 17 '15 at 13:56
• My boot0 and boot0 is set to zero to make sure the the program will be written to Flash memory. Apart from that, I'll try using st-link utility in Windows machine. I'm currently using Mac OS, but not sure if it my problem is OS related. – baqx0r Dec 17 '15 at 14:43
• I have used an STM32F407 Discovery Kit's ST-Link to program an STM32F303. I have simply connected the (2-5 pins) Kit's SWD connector to my board SWCLK, GND, SWDIO, NRST, SWO (just like it is done on the Discovery and Nucleo) and it worked with ST-Link Utility. The boot0 pin is tied to GND through a 10k resistor, based on the STM32F303 hardware reference manual. – Bence Kaulics Dec 17 '15 at 15:26

First of all thanks to everyone for their contribution.

After two sleepless nights and struggle, I could find out the issue. The problem was in pin connections in my custom board: I thought that, in my MCU, Pin 9 (VDDA) is short-circuited with PINs 24-36-48, and Pin 8 (VSSA) with PINs 23-35-47, but it's not so.

I needed to give another 3.3V and GND to VDDA and VSSA and st-link started working.

Solution Method: I used Maple Mini schematics to understand the connections of STM32F103. It turned out that, they've short-circuited VDDA with VDD1, VDD2 & VDD3, and VSSA with VSS1, VSS2 and VSS3. I think, I should've understood this from the naming VSSA, as it's not VSS0 or VSS4.