ST-Link

From Stm32World Wiki
(Redirected from STLink)
Jump to navigation Jump to search


There's a number of different ways to flash STM32 devices. One of these is to use ST's own ST-Link devices using the Serial Wire Debug (aka SWD) protocol.

STLink.jpg

There are multiple benefits of using one of these ST-Link devices rather than a plain serial dongle:

  1. The device need not be restarted in flash mode (Boot0)
  2. Programs can be debugged on the device

The official ST-Link as seen above are relatively cheap (< $20) and there are Chinese copies available (haven't tried those).


We are also running on a DIY ST-Link V2.1 device.

ST-Link/V2

ST-Link V2 Photo.png

While there must have been a V1 at some point, the ST-Link/V2 displayed in the photo to the left was for years the one to use. The original can still be purchased from places like Mouser, but there are also plenty of exact Chinese clones around (exact as in they look exactly the same).

These ST-Link devices are enclosed in a quite large white plastic casing but for some truly bizarre reason, ST could not be arsed to put a legend on the device, so one either have to have a very good memory or Google the pin out constantly.

Another very common clone are these:

STLink-v2 (Chinese knock off).jpg

ST-Link Bunch.jpg

They are Chinese knock offs but they run the official ST-Link firmware and contrary to the official one they actually have the pin out legend printed on the box. Generally these devices work just fine but with certain limitations.

The V2 devices does not have any UART/Serial functionality. The original does have SWO (Serial Wire Output) which can be used to print debug information. The small Chinese knock-offs can be modified to include a SWO pin (see link here).

ST-Link/V2-1 (Nucleo)

St-Link Nucleo.png

For beginners, the Nucleo boards are absolutely brilliant. First of all, being official ST boards they obviously include an original STM32 MCU, but they do in fact include two MCUs and the second one acts like a ST-Link/V2-1 device. Contrary to the ST-Link/V2, this one does include a SWO pin AND a USB/UART interface.

ST-Link/V2-1 devices does not exist as a stand-alone product, but they can be broken off the Nucleo and used as a stand-alone device. The complete schematics is available in the manual of the Nucleo boards, so it is in fact possible to use this to build your own. An example of that is shown here: DIY STM32 Programmer (ST-Link/V2-1).

Home made ST-Link/V2-1 devices

ST-Link/V3MINIE

ST-Link V3MINIE Photo.png

To be added

ST-Link/V3SET

ST-Link V3SET.png

To be added

Hardware Analysis

ST does not make schematics or source code available for the official ST-Link devices, which is a pity (and a somewhat odd business decision). However, they do publish a partial schematics since a built-in ST-Link device is included in all their development boards, a partial schematics is available.

ST-Link V2.1 Original Schematics.png

From the schematics we can see that the ST-Link device is build around a STM32F103CBT6 which is the 128 kB Flash version.

PC13 and PC14 (and possibly PC15 in the future) appears to be working as a means for the firmware to identify the "version" of the hardware. On above schematics, PC13 is pulled low with a resistor while PC14 (and PC15) are left floating.

A voltage divider splitting +3.3 V in half is connected to PA0 and labelled AIN_1. The ST-Link devices are capable of measuring the target processor supply voltage and this is probably a workaround of the development boards (which know their supply voltage already).

The "output" pins of the ST-Link V2 are as follows:

Pin Label Remarks
PA0 AIN_1 Probably meant as an analog input, measuring the supply voltage on the target device. On the development boards, the supply voltage is well known, so this pin is connected to a voltage divider splitting the supply voltage in half (1.65V or thereabouts).
PA5 T_JTCK Target Clock
PA6 T_JTDO
PA7 T_JTDI
PA10 T_SWO Target trace debugging. This pin is unconnected on the Chinese clone ST-Links, which is annoying.
PA12 T_SWDIO_IN On development boards connected via a 100 Ohm resistor to PA14
PA13 T_JTCK
PA14 T_JTMS
PB0 T_NRST
PB1 T_JRST Labelled but not connected to anything

More Reading

Github user lujji have done a number of interesting writeups on ST-Link devices, reverse engineering the ST-Link firmware and adding trace (SWO) support to the cheap Chinese ST-Link devices.