ST-Link

From Stm32World Wiki
Revision as of 05:19, 6 July 2021 by Lth (talk | contribs)
Jump to navigation Jump to search

Template:Metadesc:ST-Link

There's a number of different ways to flash STM32 devices. One of these is to use ST's own ST-Link devices.

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).

The most common option are these:

STLink-v2 (Chinese knock off).jpg

ST-Link Bunch.jpg

They are Chinese knock offs and they run the official ST-Link firmware.

Hardware Analysis

ST does not make schematics or source code available for the official ST-Link devices, which is a pity (and a someone 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.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.