PlatformIO Community

Raspberry Pi Pico upload problem

I’m trying to test RasPi Pico board, build went ok but uploading giving me these error:

Generating UF2 image
C:\Users\Adam Alfath\.platformio\packages\tool-rp2040tools\elf2uf2 ".pio\build\pico\firmware.elf" ".pio\build\pico\firmware.uf2"
'C:\Users\Adam' is not recognized as an internal or external command,
operable program or batch file.
*** Error 1
Checking size .pio\build\pico\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [==        ]  18.6% (used 50240 bytes from 270336 bytes)
Flash: [          ]   3.5% (used 72392 bytes from 2097152 bytes)
Configuring upload protocol...
AVAILABLE: cmsis-dap, jlink, picotool, raspberrypi-swd
CURRENT: upload_protocol = picotool
Looking for upload port...
Use manually specified: E:
Forcing reset using 1200bps open/close on port E:
Uploading .pio\build\pico\firmware.elf
'C:\Users\Adam' is not recognized as an internal or external command,
operable program or batch file.
*** [upload] Error 1
============================================================================ [FAILED] Took 63.45 seconds ============================================================================
The terminal process "C:\Users\Adam Alfath\.platformio\penv\Scripts\platformio.exe 'run', '--target', 'upload', '--environment', 'pico'" terminated with exit code: 1.

Some kind of path handling problem? the command is terminated on space character at my username folder.

RP2040 platform: 1.2.0

See Official PlatformIO + Arduino IDE support for the Raspberry Pi Pico is now available! and Upload port required · Issue #2 · platformio/platform-raspberrypi · GitHub.

For the first firmware upload, you need to plug in the Pi with the BOOTSEL button pressed so that it shows up as UF2 drive. Then, use Zadig to change the driver of the RP2040 to WinUSB. Then, use the normal picotool upload – do not use upload_port = E: or a upload_protocol = .. directive in the platformio.ini.

That is indeed a bug (somebody did not escape paths) but not relevant in your case since it’s the wrong upload method altogether.

Ok thanks for pointing it out. I’ve change the USB using zadig, it’s already picking-up the correct port.
Now for the escape character bug, I think it’s on the main.py files related to the environment variable. I’m not really familiar with python so I will happily waiting for the bug fix :slight_smile:

It’s works normally on Arduino IDE though.

Generating UF2 image
C:\Users\Adam Alfath\.platformio\packages\tool-rp2040tools\elf2uf2 ".pio\build\pico\firmware.elf" ".pio\build\pico\firmware.uf2"
'C:\Users\Adam' is not recognized as an internal or external command,
operable program or batch file.
*** Error 1
Checking size .pio\build\pico\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [==        ]  18.6% (used 50240 bytes from 270336 bytes)
Flash: [          ]   3.5% (used 72392 bytes from 2097152 bytes)
Configuring upload protocol...
AVAILABLE: cmsis-dap, jlink, picotool, raspberrypi-swd
CURRENT: upload_protocol = picotool
Looking for upload port...
Auto-detected: COM56
Forcing reset using 1200bps open/close on port COM56
Uploading .pio\build\pico\firmware.elf
'C:\Users\Adam' is not recognized as an internal or external command,
operable program or batch file.
*** [upload] Error 1

I see you’ve opened Escape character handling problem · Issue #16 · platformio/platform-raspberrypi · GitHub, which is the correct place. The developers should take core of that.

I created a script in python to perform the upload action to pi pico. At the moment I did tests with the linux platform.

import os, sys
from platform import system


if system() == 'Linux':
  current_path = str(os.path.abspath(os.getcwd())) + '/scripts'
  pico_dir = "/media/" + os.popen('whoami').read().replace('\n', '') + "/RPI-RP2"
  if os.path.exists(pico_dir):
    os.system("cp " + current_path +  "/../.pio/build/pico/firmware.uf2 " + pico_dir)
  else:
    sys.exit()

elif system() == 'Windows':
  current_path = str(os.path.abspath(os.getcwd())) + '\\scripts'

  device_ids = os.popen('wmic logicaldisk get deviceid').read().replace(' ', '').strip().split('\n')
  volume_names = os.popen('wmic logicaldisk get volumename').read().replace(' ', '').strip().split('\n')
  for volume_name, device_id in zip(volume_names, device_ids):
    if volume_name == 'RPI-RP2':
      pico_dir = "\\" + device_id
      break
    else:
      sys.exit()
    
  os.system("copy " + current_path +  "\\..\\.pio\\build\\pico\\firmware.uf2 " + pico_dir)
    
else:
  sys.exit()

I created a folder called scripts and my platformio.ini looked like this:

[env:pico]
platform = https://github.com/maxgerhardt/platform-raspberrypi.git
board = pico
framework = arduino
board_build.core = earlephilhower

upload_command = python3 scripts/upload_fw.py 

Hey,
I tried your script. I adjusted the path.
os.system("copy " + current_path + "\…\.pio\build\rpipico\firmware.uf2 " + pico_dir)
upload_command = python scripts/upload_fw.py

following message in the IO terminal
CURRENT: upload_protocol = picotool
Looking for upload port…
Auto-detected: COM5
Forcing reset using 1200bps open/close on port COM5
Uploading .pio\build\rpipico\firmware.elf

What am I doing wrong. Thanks for your support
Willi

Are you sure regular upload does not work if you copy the .uf2 file (pio\build\rpipico\firmware.uf2 ) once on the Pico’s boot drive?

Did you install libusb drivers via Zadig for the Boot interface? https://github.com/platformio/platform-raspberrypi/issues/2#issuecomment-828586398

Thanks for the quick response.
The regular upload into the Pico boot drive is ok. Move the .uf2 file to the boot directory with the mouse.
From time to time the Pico is not recognized as a device. It is currently like this :nauseated_face:. I will try again tomorrow.
I using Windows 10
Willi

Sorry
I’m currently struggling with this problem.

USB-Error

And happens when you disconnect the Pico, hold down the BOOTSEL button and plug the Pico back in while the button is still being pressed? Are after firmware upload?

Dear maxgerhardt,
lease excuse my late reply. I tried a lot and then installed a fresh Windows10. I installed “usbser (v10.0.19041.2130)”. Now I can upload via COM port. Occasionally I still have to press the BootSel button. I’ll try your script when I get a chance.
But " never change a running system"😊!
Thanks for your help and your patience.
By the way, I am 66 years old and have only had this beautiful Hoppy for 5 years. I have some experience with Arduino.