Skip to content

Upload fails if no serial port is set #688

@fjansson

Description

@fjansson

This is related to #4 and #20. I posted a comment on #20 but could not reopen the issue, so I open this one. At the end is some new analysis of why the problem occurs.

From #20:
I'm meeting what seems to be the same issue on Windows 10: a fresh install of the Arduino editor and arduino-pico cannot program a blank Pico or a Pico connected in BOOTSEL mode.

This can be somewhat difficult to reproduce, because if you had it working once or Arduino at some point connected to a serial port, the com port setting is remembered in the Arduino preferences file and this makes subsequent Pico programming work. Crucially, this issue will hit new users who install the Arduino editor to program a new Pico.

Steps

  • Fresh install of Arduino 1.8.19 on Windows 10. Using the Windows .exe installer. Allow all drivers the installer proposes.
  • Install arduino-pico according to instructions in this repo. I have version 2.3.0
  • Select Tools -> Board -> Raspberry Pi RP2040 Boards(2.3.0) -> Raspberry Pi Pico
  • Open Blink example
  • Connect a Pico with USB in BOOTSEL mode (holding down BOOTSEL while plugging in the USB cable)
  • observe Tools > Port menu is gray (at least for me it is, the computer has no other serial ports and Pico in BOOTSEL mode doesn't have a serial port)
  • press Upload
    for me compilation works, upload fails with "Serial port not selected". I cannot select a serial port, because the Port menu is gray.

If you connect a Pico already programmed from Arduino in non-BOOTSEL mode, upload works. After this the Arduino editor remembers the serial port in the preferences file. Subsequent uploads also in BOOTSEL mode will work. One way I found to reproduce the problem is to delete Arduino's preferences file (when Arduino is not running).
This PC > Windows (C:) > Users > > AppData > Local > Arduino15 > preferences
Then start Arduino, and fill in the arduino-pico Board Manager URL in File>preferences again. Now the port setting is forgotten, as you can verify in the status bar at the bottom of the window. Just reinstalling Arduino seems insufficient, as that doesn't delete the preferences file.

Workaround

Program the Pico once by drag-and-drop a .uf2 file:

  • Open a new, empty sketch (doesn't work with a read-only example sketch).
  • Compile it by pressing the "Verify" checkmark button.
  • Sketch > Export compiled Binary. Select a location e.g. the desktop. A folder is created there, containing a file ending in .uf2
  • Copy this file to the Pico's drive, by drag and drop in the Explorer.

The Pico restarts and now now has a serial port. Now the Port menu in Arduino is not gray anymore, select the port there. After this, normal uploading from the Arduino editor should work.

Analysis

The actual uploading to the Pico happens with uf2conv.py which is part of this repository. The Arduino IDE runs this command on upload. The problem is not in uf2conv but in the Arduino IDE constructing the command to launch it.

Looking at the source code of Arduino 1.8:

  • The message "Serial port not selected." is printed from app/src/processing/app/Editor.java, function run(), if SerialNotFoundException is caught.

  • SerialNotFoundException is thrown by runCommand() in arduino-core/src/cc/arduino/packages/uploaders/SerialUploader.java, if serial.port is part of the command string but is not present in the preferences.

This makes it look like SerialUploader won't work if there is no serial port, as in the case when uploading to a blank Pico or a Pico in BOOTSEL mode (on a computer with no other serial ports). If serial.port wasn't part of the command string, programming without a serial port would probably work, but then the auto-reset feature wouldn't work.

From my testing, it seems the serial port in the preferences doesn't need to exist, it just has to be defined so that the string substitution in the run command can finish. So if Arduino remembers a serial port setting from a previous board, uploading to the Pico will work if the Pico is already in BOOTSEL mode.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions