PlatformIO Community

Choosing STLink V2 programmer

I have two STM32 BluePill boards connected to my Windows 10 PC using two separate ST-Link V2 programmers. However, I can’t find a way how to tell platformio uploader which of the two programmers it should use. Tried playing with uploader_port, but I don’t have any idea what values I should put there. I tried “platformio device list”, but it doesn’t show the ST-Link V2 devices (they are not serial port devices).
Any ideas? Thanks

Not possible out of the box.

You’ll have to modify the OpenOCD script to e.g. check for the existence of an environment variable like “SERIAL”, and then the script can use that serial to identify the correct STLinkv2. That’s how I’ve implemented a “flash firmware to a specific STLink” some time ago.

The code for the modified stlink.cfg can be found at https://www.bergzand.net/programming-with-multiple-st-link-programmers.html (the new scripts all redirect to stlink.cfg).

#
# STMicroelectronics ST-LINK/V2-1 in-circuit debugger/programmer
#

interface hla
hla_layout stlink
if { [info exists ::env(SERIAL) ] } {
        hla_serial  $::env(SERIAL)
}
hla_device_desc "ST-LINK/V2-1"
hla_vid_pid 0x0483 0x374b

This file is at <home folder>\.platformio\packages\tool-openocd\scripts\interface\stlink.cfg.

You can then find out the serial number of your STLinks with e.g. the ST-Link utility, but it’s also printed by OpenOCD

grafik

Once you have that you can write a python script for PIO (see docs) to invoke OpenOCD in a special environment (or modify the global environment vars) which has this SERIAL variable set correctly according to the name of the environment or some other configuration paramter in the platformio.ini. Normal python functions can be used for that.

I see. Many thanks for your reply!