Issues with Selecting Correct COM Port for Upload in Multi-Environment Setup

Hello PlatformIO Community,

I am encountering an issue with my PlatformIO project where it does not seem to respect the selected environment’s COM port settings during the upload process. I have a project configured with multiple environments (master and slave) for a Nucleo G070RB board. Despite specifying different COM ports for each environment, PlatformIO consistently uploads using the COM port associated with the master environment, ignoring the slave setting.

Here is the relevant section of my platformio.ini file:

platform = ststm32
board = nucleo_g070rb
framework = stm32cube
upload_protocol = stlink
debug_tool = stlink

build_flags = -D MASTER=1
debug_port = COM9
upload_port = COM9

build_flags = -D SLAVE=1
debug_port = COM8
upload_port = COM8

When I attempt to upload to the slave environment using the following command:

pio run -e slave -t upload

The upload process seems to ignore the upload_port = COM8 setting. I do not observe any specific log messages indicating the use of COM9, but I notice the STLink LED on the master Nucleo board blinking (indicative of activity) during the upload process, while the slave board shows no such activity.

Additional Details:

  • I am using a USB hub to connect both boards to my Windows machine.
  • I have verified that COM8 is active and correctly configured on my system.
  • The STLink drivers are up-to-date.
  • I have tried specifying the upload port and protocol directly in the command line without any success.

Could anyone provide insights on why this might be happening, or if there’s a known issue or workaround for this behavior? Any help or suggestions would be greatly appreciated!

Thank you!