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 Programming with multiple ST-Link programmers (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
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!
I’m running into this as well. Trying to set up a Raspberry Pi 3B+ as build farm, with eight STM Nucleo boards, for testing across the different ARM Cortex families.
I can identify unique serial IDs and disk labels for each ST-Link (most are v2.1, one is v3). I have a simple blink+uart test which compiles for each board, but this won’t work until OpenOCD can address the matching board when uploading to each of them.
As I understand it, this will require a custom .cfg
file for each board, passed to openocd as a custom upload?
Update - The following command (with the added hla_serial
option) works:
~/.platformio/packages/tool-openocd/bin/openocd -d2 -s /home/jcw/.platformio/packages/tool-openocd/scripts -f interface/stlink.cfg -c "transport select hla_swd" -c "hla_serial 0669FF555052836687022922" -f target/stm32l4x.cfg -c "program {.pio/build/l432/firmware.elf} verify reset; shutdown;"
Update # 2 - see Add support for multiple ST-Link adapters · Issue #564 · platformio/platform-ststm32 · GitHub on GitHub
See a solution with extra scripting at