Page 1 of 1

STM32 Programming. Part 13: ST-Link Programmer

Posted: 17 Oct 2023, 04:49
by Oleg
By all means, this topic should have been touched upon in the 2nd or 3rd part of this article series. But better late than never, so let's go! In this part we will get acquainted with ST-Link programmer, which can be used to load firmware into STM32 microcontroller and debug the software.

Varieties of ST-Link programmers
To load firmware into STM32 microcontrollers ST-Link programmer is used, which can be connected to the programmable microcontroller via SWD interface. In addition, using the same ST-Link and SWD you can perform step-by-step debugging of the firmware from the development environment with support for breakpoints (breakpoints). The number of simultaneously installed breakpoints is limited to several pieces (I don't remember exactly how many, like 5 pieces), but it is more than enough for debugging the firmware.

In branded debugging boards from ST on board there is the target microcontroller itself, and ST-Link programmer, which is also made on the microcontroller STM32. By the way a very convenient solution. In addition, the programmer, which is built into the debug board, can be used to flash any external microcontroller STM32. For this purpose there is a special comb on the board and jumpers with which you can disconnect the SWD interface from the microcontroller soldered on the board. At my disposal I have a board stm32f4discovery, on which the microcontroller STM32F407VG is installed, and this board I just use as a programmer ST-Link:
image.png
image.png (689.63 KiB)
Viewed 3516 times
Of course, you can purchase a separate ST-Link programmer. There are several options here. The first is a branded ST-Link, which comes with and without galvanic isolation. These programmers look like this:
image.png
image.png (137.71 KiB)
Viewed 3516 times
Another option is a Chinese ST-Link in a flash drive form factor:
image.png
image.png (245.56 KiB)
Viewed 3516 times
In principle, this option is not bad either, but you should keep in mind that inside it there are no protections for USB interface and target board, so in case of unaligned earths of the circuit and PC, short circuit in the debugging circuit, and so on, there is a big chance to burn the programmer together with USB port in the computer. So you should be extremely careful when working with this programmer!

Connecting ST-Link programmer to STM32 microcontroller

SWD interface, through which the programmer is connected to the microcontroller, has 2 lines:
  • SWDIO
  • SWCLK
This is a necessary minimum for successful loading of firmware into a new microcontroller or debugging and development environment (from IAR, for example). In all STM32 microcontrollers the programming pins are combined with the following I/O ports:
  • SWDIO - PA13
  • SWCLK - PA14
Pins PA13 and PA14 can be used as the most common I / O ports, however, in this case, you lose the ability to debug the firmware from the development environment. Besides, if the default settings of pins PA13 and PA14 are changed from the firmware loaded into the MC, the process of loading the new firmware becomes difficult, you will have to use one more wire connecting the programmer and the MC: the RESET line. In this case, before loading the firmware, ST-Link will reset the microcontroller, thereby switching pins PA13 and PA14 to the default state, and after that it will load the new firmware into the MC. To use the microcontroller reset function before loading the firmware in IAR in the ST-Link configuration section, select the "Reset Pin" option:
image.png
image.png (24.35 KiB)
Viewed 3516 times
That's all for now, thanks for listening!