Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Following an upload, port selection lost when reset causes port address cycle #1648

Open
3 tasks done
per1234 opened this issue Nov 7, 2022 · 0 comments
Open
3 tasks done
Labels
topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project

Comments

@per1234
Copy link
Contributor

per1234 commented Nov 7, 2022

Describe the problem

On the native USB boards, the primary microcontroller communicates directly to the PC running the IDE via a USB CDC serial port generated by the program running on the microcontroller.

The microcontroller contains two separate programs:

  • The user's sketch application
  • The bootloader that writes the received sketch application to memory during an upload

Each of these produces a CDC serial port when it starts. On Windows, the port of each enumerates to a separate address.

In addition to being automatically activated during the upload process, the bootloader on these boards can also be activated by the user manually resetting the board. This causes the port address of the board to cycle on Windows. For example:

  1. Sketch program is running, it produces a CDC serial port that is enumerated to COM42.
  2. User activates the bootloader by resetting the board.
  3. CDC serial port that was produced by the sketch program disappears.
  4. Bootloader program produces a CDC serial port.
  5. Operating system enumerates port to COM43.
  6. Bootloader either times out or is exited by the user resetting the board again (depending on which style of bootloader is running on the board).
  7. CDC serial port that was produced by the bootloader program disappears.
  8. Sketch program produces a CDC serial port.
  9. Operating system enumerates port to COM42.

The user expects that if they select COM42 at step (1) of the above sequence, that port will still be selected at step (9) in the sequence.

If an upload was performed at any time the user selecting the port and when the a manual reset caused a port cycle, the port selection is lost.

🐛 If the user does not notice the unexpected loss of the port selection, they will be confused by the resulting failure to upload or use Serial Monitor/Plotter. Even after discovering the port selection loss, they will find it inconvenient to reselect the port.

To reproduce

Equipment

Any native USB Arduino board with bootloader that activates when the reset button is pressed:

Steps

  1. Select File > New from the Arduino IDE menus.
  2. Connect the board to your computer.
  3. Select the board and port from the Arduino IDE menus.
  4. Press and release the reset button on the board.
    This step is not required to reproduce the bug. It only demonstrates that an upload prior to the manual reset is a required condition.
  5. You will now see the LED on the board marked "L" pulsing to indicate the bootloader program is running. Wait for the LED to stop pulsing, which indicates the bootloader timed out and the sketch application is running again.
  6. Open the Tools > Port menu in the Arduino IDE.
    🙂 The board's port is still selected.
  7. Select Sketch > Upload from the Arduino IDE menus.
  8. Wait for the upload to finish successfully.
  9. Open the Tools > Port menu in the Arduino IDE.
    🙂 The board's port is still selected.
  10. Press and release the reset button on the board.
  11. You will now see the LED on the board marked "L" pulsing to indicate the bootloader program is running. Wait for the LED to stop pulsing, which indicates the bootloader timed out and the sketch application is running again.
  12. Open the Tools > Port menu in the Arduino IDE.

🐛 The board's port is no longer selected.

To reproduce (alternate version)

An advancement was made at some time after the development of the "caterina" bootloader used for the Leonardo and Micro boards:

  • Bootloader is only triggered after two resets in quick succession.
  • Bootloader runs indefinitely instead of timing out after several seconds.

Since this allows the sketch application to be reset without activating the bootloader and thus triggering the port cycle, users of these boards are less likely to be impacted by the bug. However, it is still possible to reproduce the bug via a slightly modified procedure with any of the boards with this type of bootloader.

Equipment

Any board that can be put in bootloader mode via a double reset:

Steps

  1. Select File > New from the Arduino IDE menus.
  2. Connect the board to your computer.
  3. Select the board and port from the Arduino IDE menus.
  4. Press and release the reset button on the board twice quickly.
    This step is not required to reproduce the bug. It only demonstrates that an upload prior to the manual reset is a required condition.
  5. You will now see the LED on the board marked "L" pulsing to indicate the bootloader program is running. Press and release the reset button once more to exit the bootloader and cause the sketch application to run again.
    The "L" LED will stop pulsing.
  6. Open the Tools > Port menu in the Arduino IDE.
    🙂 The board's port is still selected.
  7. Select Sketch > Upload from the Arduino IDE menus.
  8. Wait for the upload to finish successfully.
  9. Open the Tools > Port menu in the Arduino IDE.
    🙂 The board's port is still selected.
  10. Press and release the reset button on the board twice quickly.
  11. You will now see the LED on the board marked "L" pulsing to indicate the bootloader program is running. Press and release the reset button once more to exit the bootloader and cause the sketch application to run again.
    The "L" LED will stop pulsing.
  12. Open the Tools > Port menu in the Arduino IDE.

🐛 The board's port is no longer selected.

Expected behavior

Always use the port the user selected. *

* There is one exception to this rule: when uploading to a board that has native USB capabilities, the CDC serial port of the board enumerates at the start and end of the upload. Most often, the port will have the same address at the end of the upload as at the start, but it is possible that the operating system will assign it a different address, and that final port should be selected in the IDE after the completion of the upload. This exception is not relevant to this bug because this port selection loss is not directly caused by an upload.

Arduino IDE version

2.0.1

Operating system

Windows

Operating system version

10

Additional context

I bisected the regression to cc5cf3b / #1328 (does not occur when using the build for the previous commit 125bd64)


The issue does not occur on Linux because the board's application and bootloader use the same port address on that operating system.


The issue does not occur when using Arduino IDE 1.x


Originally reported by @sterretjeToo at https://forum.arduino.cc/t/the-disappearing-serial-connection-on-boards-with-native-usb/1050457

Issue checklist

  • I searched for previous reports in the issue tracker
  • I verified the problem still occurs when using the latest nightly build
  • My report contains all necessary details
@per1234 per1234 added topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project labels Nov 7, 2022
@per1234 per1234 changed the title Following an upload, port selection lost when reset causes port number cycle Following an upload, port selection lost when reset causes port address cycle Nov 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project
Projects
None yet
Development

No branches or pull requests

1 participant