Description
Describe the bug
Some Arduino boards have native USB capability which allows the primary microcontroller to produce a CDC serial port over which sketches are uploaded. The upload process for these boards goes like so:
- Arduino IDE signals the board to run the bootloader.
- Sketch program stops, which kills the CDC serial port it produces.
- Bootloader program starts, which produces another CDC serial port.
- Upload happens.
- Bootloader program stops, which kills the CDC serial port it produces.
- Sketch program starts, which produces another CDC serial port.
During this process, the port disappears and reappears. This causes the IDE to select the wrong port if any other ports have been associated with the currently selected board name .
The obvious way that multiple ports might be associated with the same board name is having multiple boards of the same model connected to your computer. However, it occurs even with a single board simply by selecting the wrong port once.
To Reproduce
You will need:
- Arduino board with native USB capability (e.g., Leonardo, MKR, Nano 33 BLE)
- An additional serial port on your computer. This could be an internal built-in port (i.e., COM1), a spare Arduino board connected to your computer, or any other device that produces a port (e.g., FTDI adapter).
- Select the additional serial port from the Tools > Port menu in the Arduino IDE.
- Select your native USB board from the Tools > Board menu in the Arduino IDE.
You have now associated the selected port with this board name. - Select the real port of your native USB board from the Tools > Port menu in the Arduino IDE.
- Select Sketch > Upload from the Arduino IDE menus.
🐛 The port selection will now switch to the port that was selected in step (1).
Note: The above instructions use Tools > ... menu paths for the sake of clarity. The issue also occurs when using the board/port selection dropdown menu and the "Select other board and port..." dialog.
Expected behavior
Retain the port I selected.
Desktop
- OS: Windows 10
- Version: 2.0.0-rc2-snapshot.c064673
Date: 2021-12-15T09:32:43.552Z
CLI Version: 0.20.2 [13783819]
Additional context
The tried and true established approach used by the classic Arduino IDE handles this just fine. So its behavior can serve as a reference for the solution.
There are several other issues related to the IDE not correctly handling the port selection:
- Port selection of Portenta H7 (M4 Core) is lost on every upload #43
- Adafruit Trinket M0 won't persist port #82
- Port defaults to first available com port with lowest number not the last used #180
- Serial port re-enumerates after upload with SAMD boards (probably other USB native) #287
The issue also occurs on pressing the reset button instead of doing a full upload.
Originally reported at https://forum.arduino.cc/t/each-day-a-new-problem/937997
Also reported at: