Remote code upload is not targetting the correct port

Hi Guys,

I am using a raspberry pi as a remote agent. I have two Teensy 4.1 devices connected to the raspberry pi. When I do “pio remote device list” I can see both the devices and their associated ports.

The problem I am having is when I am uploading to a targetted port with the following command:
“pio remote --agent AGENT_NAME run --target upload --upload-port /dev/ttyACM1”
The code is getting remotely deployed to BOTH devices when I only want to upload the code to my device in port /dev/ttyACM1.

Has anyone experienced anything similar ? I have also tried setting the upload_port explicitly in the platformio config file for the project to no avail.

Anyone able to help ? Upload port does not work ?

Duplicate of --upload-port flag has no effect · Issue #44 · platformio/platform-teensy · GitHub. There are also tested workarounds available.

The general problem here that the standard uploader program (which I assume you use), teensy_loader_cli, cannot be given a target device. The uplaod port is ignored and not even given to the program because it doesn’t process it anyways.

See PlatformIO invocation line here and available program options here.

There’s no option to specify a target USB device.

So fundamentally this is a problem of the uploader, and it was already reported as issue in

There are also multiple PRs open that address this, all in different styles and with different options. As linked above e.g.

But not one got merged yet because… well read the author’s comment.

What you can do is e.g. just

  • try out the workaround I first linked to which uses tycmd or,
  • try out one of the PRs by compiling that fork, replacing then using that as a replacement for ~/.platformio/packages/tool-teensy/teensy_loader_cli and add extra configuration options in the environment of the platformio.ini to give the program the new flag.

This first one e.g. adds the option of

“\t–serial-number=SERIAL_NUMBER : Serial number to use in conjunction with soft reboot (UNIX only).\n”

to the program which should solve your problem.

On the Rasberry Pi, you can e.g. try

sudo apt-get install libusb-dev gcc
git clone
cd teensy_loader_cli
git checkout serial_number
cp teensy_loader_cli ~/.platformio/packages/tool-teensy/.

to compile and replace the loader executable. Then read out the USB serial number of both teensies (e.g. per here and using the /dev/ttyACMx device), then add upload_flags = -t <serial number> in the environment of the platformio.ini. You might want to duplicate the environments.

Thank you maxgerhardt for the detailed response, much appreciated. All working now.