PlatformIO Community

Pio run not obeying upload_port parameter on linux

I am deploying via CLI on Ubuntu 20. I have multiple devices hooked up to the system for testing and I would like to specify which one I will deploy to. All research points to using upload-port as the parameter, but it seems to have no effect, and verbose output does not indicate that it even takes note of this parameter, nor does it indicate how it decided on which device to flash, nor even does it identify which device it decided to flash, however it does that… The only way I know which one it gets the update is by seeing the actuators do their startup jitters. I have confirmed that each device works if I plug/unplug them selectively.

I have 3 devices, each on:
/dev/ttyACM0
/dev/ttyACM1
/dev/ttyACM2

Here is my commad and verbose output:

pio run --environment int-test-idle --target upload --upload-port /dev/ttyACM1 -v
Processing int-test-idle (platform: ststm32; board: custom_stm32; build_flags: -Icommon/include/, -std=gnu++17, -fno-exceptions, -Wall, -Werror, -Wconversion, -Wno-sign-conversion, -Wno-sign-compare, -fstrict-volatile-bitfields, -mfpu=fpv4-sp-d16, -mfloat-abi=hard, -Wl,-Map,stm32.map, -Wl,-u,vectors, -Wl,-u,_init, -DBARE_STM32, -DIDLE_TEST; board_build.ldscript: boards/stm32_ldscript.ld; extra_scripts: pre:boards/stm32_scripts.py; src_filter: +<*> -<.git/> -<.svn/> -<test/> -<src/> -<src_test/> +<integration_tests/>; lib_ldf_mode: deep+; lib_extra_dirs: common/libs, common/generated_libs, common/third_party; build_unflags: -std=gnu++11, -std=gnu++14, -fpermissive; platform_packages: toolchain-gccarmnoneeabi@>1.80301.190214)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
CONFIGURATION: https://docs.platformio.org/page/boards/ststm32/custom_stm32.html
PLATFORM: ST STM32 6.1.1 > ST Nucleo L452RE
HARDWARE: STM32L452RET6 80MHz, 160KB RAM, 512KB Flash
DEBUG: Current (stlink) On-board (stlink) External (blackmagic, jlink)
PACKAGES: 
 - tool-dfuutil 1.9.200310 
 - tool-openocd 2.1000.190707 (10.0) 
 - tool-stm32duino 1.0.1 
 - toolchain-gccarmnoneeabi 1.90201.191206 (9.2.1)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ deep+, Compatibility ~ soft
Found 10 compatible libraries
Scanning dependencies...
Warning! Circular dependencies detected between `/home/martin/VentilatorSoftware/controller/lib/core` and `/home/martin/VentilatorSoftware/controller/lib/hal`
Warning! Circular dependencies detected between `/home/martin/VentilatorSoftware/controller/lib/debug` and `/home/martin/VentilatorSoftware/controller/lib/core`
Warning! Circular dependencies detected between `/home/martin/VentilatorSoftware/controller/lib/debug` and `/home/martin/VentilatorSoftware/controller/lib/hal`
Dependency Graph
|-- <hal> (/home/martin/VentilatorSoftware/controller/lib/hal)
|   |-- <stl> (/home/martin/VentilatorSoftware/controller/lib/stl)
|   |-- <units> (/home/martin/VentilatorSoftware/common/libs/units)
|   |-- <checksum> (/home/martin/VentilatorSoftware/common/libs/checksum)
|   |-- <core> (/home/martin/VentilatorSoftware/controller/lib/core)
|   |   |-- <network_protocol> (/home/martin/VentilatorSoftware/common/generated_libs/network_protocol)
|   |   |   |-- <nanopb> (/home/martin/VentilatorSoftware/common/third_party/nanopb)
|   |   |-- <nanopb> (/home/martin/VentilatorSoftware/common/third_party/nanopb)
|   |   |-- <stl> (/home/martin/VentilatorSoftware/controller/lib/stl)
|   |   |-- <units> (/home/martin/VentilatorSoftware/common/libs/units)
|   |   |-- <pid> (/home/martin/VentilatorSoftware/controller/lib/pid)
|   |   |   |-- <units> (/home/martin/VentilatorSoftware/common/libs/units)
|   |   |   |-- <stl> (/home/martin/VentilatorSoftware/controller/lib/stl)
|   |   |-- <debug> (/home/martin/VentilatorSoftware/controller/lib/debug)
|   |   |   |-- <stl> (/home/martin/VentilatorSoftware/controller/lib/stl)
|   |   |   |-- <units> (/home/martin/VentilatorSoftware/common/libs/units)
|   |-- <debug> (/home/martin/VentilatorSoftware/controller/lib/debug)
|   |   |-- <stl> (/home/martin/VentilatorSoftware/controller/lib/stl)
|   |   |-- <units> (/home/martin/VentilatorSoftware/common/libs/units)
|-- <stl> (/home/martin/VentilatorSoftware/controller/lib/stl)
|-- <units> (/home/martin/VentilatorSoftware/common/libs/units)
|-- <core> (/home/martin/VentilatorSoftware/controller/lib/core)
|   |-- <network_protocol> (/home/martin/VentilatorSoftware/common/generated_libs/network_protocol)
|   |   |-- <nanopb> (/home/martin/VentilatorSoftware/common/third_party/nanopb)
|   |-- <nanopb> (/home/martin/VentilatorSoftware/common/third_party/nanopb)
|   |-- <stl> (/home/martin/VentilatorSoftware/controller/lib/stl)
|   |-- <units> (/home/martin/VentilatorSoftware/common/libs/units)
|   |-- <pid> (/home/martin/VentilatorSoftware/controller/lib/pid)
|   |   |-- <units> (/home/martin/VentilatorSoftware/common/libs/units)
|   |   |-- <stl> (/home/martin/VentilatorSoftware/controller/lib/stl)
|   |-- <debug> (/home/martin/VentilatorSoftware/controller/lib/debug)
|   |   |-- <stl> (/home/martin/VentilatorSoftware/controller/lib/stl)
|   |   |-- <units> (/home/martin/VentilatorSoftware/common/libs/units)
|-- <network_protocol> (/home/martin/VentilatorSoftware/common/generated_libs/network_protocol)
|   |-- <nanopb> (/home/martin/VentilatorSoftware/common/third_party/nanopb)
|-- <nanopb> (/home/martin/VentilatorSoftware/common/third_party/nanopb)
|-- <pid> (/home/martin/VentilatorSoftware/controller/lib/pid)
|   |-- <units> (/home/martin/VentilatorSoftware/common/libs/units)
|   |-- <stl> (/home/martin/VentilatorSoftware/controller/lib/stl)
|-- <debug> (/home/martin/VentilatorSoftware/controller/lib/debug)
|   |-- <stl> (/home/martin/VentilatorSoftware/controller/lib/stl)
|   |-- <units> (/home/martin/VentilatorSoftware/common/libs/units)
|-- <checksum> (/home/martin/VentilatorSoftware/common/libs/checksum)
Building in release mode
MethodWrapper(["checkprogsize"], [".pio/build/int-test-idle/firmware.elf"])
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [=====     ]  50.4% (used 82532 bytes from 163840 bytes)
Flash: [          ]   2.3% (used 11972 bytes from 524288 bytes)
.pio/build/int-test-idle/firmware.elf  :
section            size        addr
.isr_vector         404   134217728
.text              9012   134218176
.rodata            2712   134227188
.ARM.extab            0   134229900
.ARM                  0   134229900
.preinit_array        0   134229900
.init_array          60   134229900
.fini_array           0   134229960
.data               248   536870912
.bss              82284   536871160
.ARM.attributes      50           0
.comment            102           0
.debug_frame        176           0
.stabstr            118           0
Total             95166
<lambda>(["upload"], [".pio/build/int-test-idle/firmware.elf"])
AVAILABLE: blackmagic, jlink, mbed, stlink
CURRENT: upload_protocol = stlink
openocd -d2 -s /home/martin/.platformio/packages/tool-openocd/scripts -f board/st_nucleo_l4.cfg -c "program {.pio/build/int-test-idle/firmware.elf}  verify reset; shutdown;"
xPack OpenOCD, 64-bit Open On-Chip Debugger 0.10.0+dev (2019-07-17-11:25)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
debug_level: 2

Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
srst_only separate srst_nogate srst_open_drain connect_deassert_srst

Info : clock speed 500 kHz
Info : STLINK V2J30M19 (API v2) VID:PID 0483:374B
Info : Target voltage: 3.252425
Info : stm32l4x.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : Listening on port 3333 for gdb connections
Info : Unable to match requested speed 500 kHz, using 480 kHz
Info : Unable to match requested speed 500 kHz, using 480 kHz
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x08001da0 msp: 0x20014108
** Programming Started **
Info : device id = 0x20016462
Info : flash size = 512kbytes
Warn : block write succeeded
** Programming Finished **
** Verify Started **
** Verified OK **
** Resetting Target **
Info : Unable to match requested speed 500 kHz, using 480 kHz
Info : Unable to match requested speed 500 kHz, using 480 kHz
shutdown command invoked
================================================================================================================================================================================================================================ [SUCCESS] Took 1.36 seconds ================================================================================================================================================================================================================================

Environment           Status    Duration
--------------------  --------  ------------
stm32                 IGNORED
stm32-test            IGNORED
int-test-idle         SUCCESS   00:00:01.357
int-test-buzzer       IGNORED
int-test-blower       IGNORED
int-test-solenoid     IGNORED
int-test-stepper      IGNORED
int-test-pinch-valve  IGNORED
native                IGNORED
================================================================================================================================================================================================================================ 1 succeeded in 00:00:01.357 ================================================================================================================================================================================================================================

pio device list gives the following:

/dev/ttyACM1
------------
Hardware ID: USB VID:PID=0483:374B SER=0668FF303435554157105440 LOCATION=3-2:1.2
Description: STM32 STLink - ST-Link VCP Ctrl

/dev/ttyACM0
------------
Hardware ID: USB VID:PID=0483:374B SER=066FFF303435554157105014 LOCATION=1-4:1.2
Description: STM32 STLink - ST-Link VCP Ctrl

/dev/ttyACM2
------------
Hardware ID: USB VID:PID=0483:374B SER=066BFF303435554157104916 LOCATION=1-10:1.2
Description: STM32 STLink - ST-Link VCP Ctrl

Once you choose upload_protocol = stlink (which is also the default for Nucleo boards), upload_port has no effect. You are not uploading via /dev/ttyACM0 devices (that would take effect when you do a serial bootloader upload), but via the ST-Link USB device.

Choosing stlink will simply invoke openocd saying “use the ST-Link adapter”, but not which.

openocd -d2 -s /home/martin/.platformio/packages/tool-openocd/scripts -f board/st_nucleo_l4.cfg -c "program {.pio/build/int-test-idle/firmware.elf}  verify reset; shutdown;"

For that, special logic must be injected into openocd (board scripts) and into PlatformIO to figure out the ST-Link UID.

This was discussed in Choosing STLink V2 programmer.

If you want an easy solution: If you work with Nucleos, they will expose themselves as a USB flashdrive device.

Choose the upload protocol mbed and point upload_port to the directory where the device is mounted.

I made a similar - may be related - observation. I connected two devices (a d1_mini and an esp32dev) to my PC. They got the devices /dev/ttyUSB0 respectively /dev/ttyUSB1. Altered plattformio.ini appropriate to

[env:esp32]
platform = espressif32
board = esp32dev
test_port = /dev/ttyUSB1
test_speed = 921600
monitor_port = /dev/ttyUSB1
monitor_speed = 921600

[env:d1_mini]
platform = espressif8266
board = d1_mini
test_port = /dev/ttyUSB0
test_speed = 460800
monitor_port = /dev/ttyUSB0
monitor_speed = 460800

Then I ran pio test -e d1_mini -e esp32 and that happened:

Verbose mode can be enabled via `-v, --verbose` option
Collected 1 items

Processing * in esp32 environment
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Building...
Flash: [=====     ]  54.7% (used 717253 bytes from 1310720 bytes)
Uploading...
Flash: [=====     ]  54.7% (used 717253 bytes from 1310720 bytes)
Connecting....
*** [upload] Error 2
================================================================================ [FAILED] Took 6.70 seconds ================================================================================

Processing * in d1_mini environment
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Building...
RAM:   [=====     ]  54.7% (used 44804 bytes from 81920 bytes)
Flash: [======    ]  59.8% (used 624880 bytes from 1044464 bytes)
Uploading...
RAM:   [=====     ]  54.7% (used 44804 bytes from 81920 bytes)
Flash: [======    ]  59.8% (used 624880 bytes from 1044464 bytes)
Connecting....
Writing at 0x00000000... (5 %)
Writing at 0x00004000... (10 %)
Writing at 0x00008000... (15 %)
Writing at 0x0000c000... (21 %)
Writing at 0x00010000... (26 %)
Writing at 0x00020000... (47 %)
Writing at 0x00030000... (68 %)
Writing at 0x00040000... (89 %)
Wrote 629040 bytes (305637 compressed) at 0x00000000 in 26.9 seconds (effective 186.8 kbit/s)...
Testing...
If you don't see any output for the first 10 secs, please reset board (press reset button)

[==========] Running 1 test from 1 test suite.
Global test environment set-up.
[----------]
[----------] 1 test from test_getBitmap
[ RUN      ] test_getBitmap.CheckPointer[       OK ] test_getBitmap.CheckPointer (6 ms)
[----------] 1 test from test_getBitmap (9 ms total)
Global test environment tear-down
[----------]
[==========] 1 test from 1 test suite ran. (17 ms total)[  PASSED  ] 1 test.
=============================================================================== [PASSED] Took 32.76 seconds ===============================================================================

Test    Environment    Status    Duration
------  -------------  --------  ------------
*       esp32          FAILED    00:00:06.695
*       d1_mini        PASSED    00:00:32.757
*       native         IGNORED
========================================================================== 1 failed, 1 succeeded in 00:00:39.452 ==========================================================================

During run I could see that only d1_mini was accessed.

Then I shortly unplugged d1_mini and reconnected it immediately (it got /dev/ttyUSB0 again) and ran again pio test -e d1_mini -e esp32. This time that happened :open_mouth:

Verbose mode can be enabled via `-v, --verbose` option
Collected 1 items

Processing * in esp32 environment
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Building...
Flash: [=====     ]  54.7% (used 717253 bytes from 1310720 bytes)
Uploading...
Flash: [=====     ]  54.7% (used 717253 bytes from 1310720 bytes)
Connecting....
Writing at 0x00001000... (100 %)
Wrote 15872 bytes (10319 compressed) at 0x00001000 in 0.2 seconds (effective 538.1 kbit/s)...
Writing at 0x00008000... (100 %)
Wrote 3072 bytes (128 compressed) at 0x00008000 in 0.0 seconds (effective 4921.9 kbit/s)...
Writing at 0x0000e000... (100 %)
Wrote 8192 bytes (47 compressed) at 0x0000e000 in 0.0 seconds (effective 20802.0 kbit/s)...
Writing at 0x00010000... (6 %)
Writing at 0x00020000... (31 %)
Writing at 0x00030000... (56 %)
Writing at 0x00040000... (81 %)
Wrote 717376 bytes (260644 compressed) at 0x00010000 in 7.1 seconds (effective 809.2 kbit/s)...
Testing...
If you don't see any output for the first 10 secs, please reset board (press reset button)

[==========] Running 1 test from 1 test suite.
[----------] Global test environment set-up.
[----------] 1 test from test_getBitmap
[ RUN      ] test_getBitmap.CheckPointer
[       OK ] test_getBitmap.CheckPointer (3 ms)
[----------] 1 test from test_getBitmap (5 ms total)
[----------] Global test environment tear-down
[==========] 1 test from 1 test suite ran. (7 ms total)
[  PASSED  ] 1 test.
=============================================================================== [PASSED] Took 14.53 seconds ===============================================================================

Processing * in d1_mini environment
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Building...
RAM:   [=====     ]  54.7% (used 44804 bytes from 81920 bytes)
Flash: [======    ]  59.8% (used 624880 bytes from 1044464 bytes)
Uploading...
RAM:   [=====     ]  54.7% (used 44804 bytes from 81920 bytes)
Flash: [======    ]  59.8% (used 624880 bytes from 1044464 bytes)
Connecting......
*** [upload] Error 2
================================================================================ [FAILED] Took 3.88 seconds ================================================================================

Test    Environment    Status    Duration
------  -------------  --------  ------------
*       esp32          PASSED    00:00:14.532
*       d1_mini        FAILED    00:00:03.875
*       native         IGNORED
========================================================================== 1 failed, 1 succeeded in 00:00:18.407 ==========================================================================

and I could see, that only esp32dev was accessed, i.e. just the opposite result. Funny - isn’t it :wink:?