Published: Sep 15, 2022

ST-Link/V2 Setup

Build stlink tools

Clone the stlink tools repository

git clone https://github.com/stlink-org/stlink

Install required libraries and tools to build the source

sudo apt install git make cmake libusb-1.0-0-dev gcc build-essential

Start the build and install stlink tools.

cd stlink
mkdir build
cd build
cmake ..
make
sudo make install

Now you can find following executables in the bin/ directory:

st-flash  st-info  st-trace  st-util  test-flash  test-sg  test-usb

Test the ST-Link

Connect the ST-Link to your PC, run lsusb and look for ST-LINK/V2 in the output:

lsusb | grep --color -i ST-LINK
Bus 002 Device 007: ID 0483:3748 STMicroelectronics ST-LINK/V2

Running st-info --probe should detect the ST-Link and return some details about it.

st-info --probe
Found 1 stlink programmers
  version:    V2J29S7
  serial:     2F0A03003212364D434B4E00
  flash:      0 (pagesize: 0)
  sram:       0
  chipid:     0x444

Now connect the ST-Link to your target device.

ST-LinkTarget
3.3V3.3V
GNDGND
SWDIODIO
SWDCLKCLK

Let’s try to read some data from the target. If the command was successful you should see the name of your target device and information about it’s memory in the output.

st-flash read dummy.bin 0 0xFFFF
st-flash 1.7.0-214-gc2db68e
Failed to parse flash type or unrecognized flash type
2022-09-15T04:30:22 INFO common.c: STM32F03x: 4 KiB SRAM, 16 KiB flash in at least 1 KiB pages.
2022-09-15T04:30:22 INFO common.c: read from address 0000000000 size 65535

Your ST-Link is now ready to be used for flashing and debugging.

Troubleshooting

ERROR usb.c: Could not open USB device 0x0483:0x3748, access error.

The udev rules should have been copied during make install, check if they actually exist in /etc/udev/rules.d/. You can also manually copy the rules:

sudo cp config/udev/rules.d/49-stlinkv2.rules /etc/udev/rules.d/

Also try reloading the udev rules:

sudo udevadm control --reload-rules
sudo udevadm trigger