PIO device monitor trick

Looking into the PySerial package which is also used by pio device monitor, I noticed that you can do a few more things with it in PIO than currently documented:

    pio device monitor -b115200 -p'hwgrep://SWLINK&n=2'

This will open the second serial port which has the text “SWLINK” in its USB description (this happens to be the correct one when using a Blue Pill as Black Magic Probe).

There are a few more “URL handlers” built in, as documented here.

This works on at least MacOS and Linux. All the current serial ports and their descriptions at the PySerial level can be listed with:

    python3 -m serial.tools.list_ports -v

None of this is documented in PIO, perhaps because it won’t be supported at some point, but for now it works. One use case for this, is to reliably select the proper serial port when multiple JTAG programmers are connected at the same time (by specifying its unique serial number).