Stlink is ignoring upload_port setting

I am currently working on a project involving sub-GHz RF comms between two nucleo boards (L053R8 and F401RE).

I have created separate platformio environments for my transmitter and receiver, which differ by the option -DTRANSMITTER that conditionally compiles different code for the transmitter and receiver.

In the platformio environments, I have specified the upload_port option to the serial port of my transmitter and receiver boards (and I checked that Windows always gives them the same COM port number). Unfortunately, it seems that the stlink tool is ignoring this option, and always uploading to the first board that it finds.

I have specified the upload_protocol=stlink option, because I seem to have even more problems getting reliable uploading through disk based upload. (the board often cannot be reset after upload)

It should be upload_protocol = stlink.

Sorry, that was just a typo in my mesage, my platformio.ini file has the correct upload_protocol = stlink, so this is not the cause

Are you sure that stlink supports uploading port argument?

Here is the output of st-flash.exe with no arguments, suggesting that it does support specifying the serial port with the --serial option.

stlinkv1 command line: ./st-flash [--debug] [--reset] [--format <format>] {read|write} /dev/sgX <path> <addr> <size>
stlinkv1 command line: ./st-flash [--debug] /dev/sgX erase
stlinkv2 command line: ./st-flash [--debug] [--reset] [--serial <serial>] [--format <format>] {read|write} <path> <addr> <size>
stlinkv2 command line: ./st-flash [--debug] [--serial <serial>] erase
                       Use hex format for addr, <serial> and <size>.
                       Format may be 'binary' (default) or 'ihex', although <addr> must be specified for binary format only.

Run uploading with -v option, you will see a full command. Try to append --serial /path. Does this work?

I checked further, and it seems that --serial is actually the serial number of the board. For my purposes, this would also do the job, as the board’s serial number is available via st-info --serial. However the option --serial always causes st-flash options parser code to return an error. Here is an example of what I tried (I also tried many other variations, including remove the = sign)

C:\Users\dap124\.platformio\packages\tool-stlink\st-flash --serial=303637304646343935303536383035 write .pioenvs\transmitter\firmware.bin 0x08000000

Reading the code for the options parser, I can’t see what I am doing wrong. I’m tempted to raise an issue with the stlink project, but I can’t figure out which version of the utility is packaged with platformio, as the versioning seems different and I can’t find the build/download scripts.

As an aside, stlink has an option for passing the device name of the board, but that is linux specific, and only applicable to stlinkv1 (I think nucleo boards are v2).

edit: If I can get this working with platformio’s upload_flags, then that would be a good solution. The confusing part is that platformio acknowledges the upload_port flag, but does not (and apparently cannot) pass this to the stlink upload tool.

@xor-gate , do you have any ideas? Can users use st-link to program multiple connected boards?