More than one ST-Link for upload (several devices are connected to PC_

Hello everyone,

Is there a way how to work with two or more ST-Link connected boards at once? Ideally IDE should ask me what device to use for upload if sees more than one board connected.

Can you override upload command Redirecting... ?

openocd is inherently unable to distinguish STLinks by default, but a modification can be done to check the serial. See Programming with multiple ST-Link programmers. This is different for every single upload tool, some might not even support it.

2 Likes

I am successfully able to flash 2 different china clone bluepill (STM32F103C8T6) with 2 different ST link_v2.

First you have to identify the stlink_v2 device Serial Number.
For this the easiest was to download/install STM32 ST-LINK Utility, connect to ST-Link and check it.
Here you can find the official tool: https://www.st.com/en/development-tools/stsw-link004.html
When you connected the device the toll will show you the SN. While its connected the ST-Link will blink rapidly. (I recommend to check ST-link SN separately)

Within platformio.ini extend with the following code:

upload_protocol = custom
upload_command = openocd -s $PROJECT_PACKAGES_DIR/tool-openocd/scripts -f interface/stlink.cfg -c "transport select hla_swd" $UPLOAD_FLAGS -c "program {$SOURCE} 0x08000000 verify reset; shutdown;"
build_flags = -Wno-format -DSTM32F1
upload_flags = 
    -c
    hla_serial **274E0C0011145157544D4E00**
    -f
    target/stm32f1x.cfg
monitor_port = /dev/serial/by-id/usb-STMicroelectronics_STM32_STLink_**274E0C0011145157544D4E00**-if02

In my case the ST-Link SN is : “274E0C0011145157544D4E00”.
Replace with your SN in the above code. (you have the replace 2 times. 1 in upload_flags, and 1 in monitor_port)

I am also insert my full paltfromio.ini code if needed. This is valid for china clone bluepill (STM32F103C8T6).

[env:bluepill_f103c8]
platform = ststm32
board = bluepill_f103c8
framework = arduino
lib_deps = 
	olikraus/U8g2@^2.28.8
	lowpowerlab/RFM69@^1.4.3
	mikem/RadioHead@^1.113

upload_protocol = custom
upload_command = openocd -s $PROJECT_PACKAGES_DIR/tool-openocd/scripts -f interface/stlink.cfg -c "transport select hla_swd" $UPLOAD_FLAGS -c "program {$SOURCE} 0x08000000 verify reset; shutdown;"
build_flags = -Wno-format -DSTM32F1
upload_flags = 
	-c ;<--This is only need if you are using the china clone of bluepill
	set CPUTAPID 0x2ba01477 ; <--This is only need if you are using the china clone of bluepill
	-c
	hla_serial **274E0C0011145157544D4E00** ;<-- Replace with your ST-link SN
	-f
	target/stm32f1x.cfg
monitor_port = /dev/serial/by-id/usb-STMicroelectronics_STM32_STLink_**274E0C0011145157544D4E00**-if02 ;<-- Replace with your ST-link SN