Using multiple ST-Link boards at the same time

To develop code for an RF board, I want to develop and run the same code on two different µC boards. The idea is to have three terminal windows open: one to build and upload to both boards, and one each to show the terminal output from the respective boards (called “n32” and “n64”). Here’s how to make this work very nicely in Platformio:

platformio.ini

[platformio]
default_envs = ${sysenv.ENV}

[env]
platform = ststm32
framework = cmsis
build_flags = ...
monitor_speed = 2000000

[env:n32]
board = nucleo_l412kb
upload_flags = -c, adapter serial 0668FF575051717867043125
monitor_port =           hwgrep://0668FF575051717867043125

[env:n64]
board = nucleo_l412rb_p
upload_flags = -c, adapter serial 0670FF495649657867193622
monitor_port =           hwgrep://0670FF495649657867193622

Terminal #1

Build and upload to both boards in one step:

pio run -t upload

Terminal #2

Connect to the first board and show its output:

export ENV=n32
pio device monitor

Terminal #3

Connect to the second board and show its output:

export ENV=n64
pio device monitor

Notes

  • the ${sysenv.ENV} expansion will choose the right build based on the ENV variable, but does nothing when it’s not set
  • terminal windows #2 and #3 will only use the settings for the corresponding board (for serial comms, but also for builds and for uploads)
  • the upload_flags and monitor_port settings tie each board to a specific on-board ST-Link’s serial number, as obtained via pio device list

-jcw