PlatformIO Community

Official PlatformIO + Arduino IDE support for the Raspberry Pi Pico is now available!

We now have the official Arduino Mbed OS RP2040 IDE support for the Raspberry Pi Pico.

A quick search for Pico in the Arduino Boards Manager will show the Raspberry Pi Pico boards as Arduino Mbed OS RP2040. Connect the Pico and select the Raspberry Pi Pico board from the Tools->Board:"Raspberry Pi Pico"->Arduino Mbed OS RP2040 Boards.

I installed the package under both Arduino 1.8.13 IDE and Arduino 1.8.9 IDE. All seems to work well.

The Raspberry Pi Pico installation should also work under the Arduino 2.0 IDE Beta, though I haven’t tried it out as the Beta is quite flaky at the moment.

Hopefully the Arduino Mbed OS RP2040 support will mean that the PlatformIO support is not too far behind.

3 Likes

Hope we will get support soon.

We added official support for Raspberry Pi Pico. Please check this post:

2 Likes

Ivan,

Excellent! Thank you. It’s very much appreciated.

If anyone is having issues with the RaspberryPi Pico builds using PlatformIO, use the following platformio.ini.

The upload_port is the path to the mounted Pico USB UF2, below is for macOS.

[env:pico]
platform = https://github.com/platformio/platform-raspberrypi.git
framework = arduino
board = pico
upload_port = /Volumes/RPI-RP2

The debug support under PlatformIO doesn’t work at the moment (see Raspberry Pi RP2040 microcontroller - PIO support when? :) - #42 by sstaub ).

I have tested out a couple of my Pico sketches on RaspberryPi Pico board and the Pimoroni Tiny2040 board (Tiny 2040 – Pimoroni). All work fine with PlatformIO.

I tried the arduino-blink sketch with Raspberry Pi Pico. I tried to upload over USB
(press BOOTSEL, connect USB, release BOOTSEL).

Compilation succeeded but when trying to upload the sketch (from within IDE) to the Pico (on Windows) the upload seems to fail and the LED lits in a certain pattern (possibly the ‘blink of death’ but not the 1s on/off blink pattern from the sketch).

; platformio.ini

[env:pico]
platform = https://github.com/platformio/platform-raspberrypi.git
framework = arduino
board = pico
upload_port = E:

The E: drive is the RPI-RP2 volume.

Upload Task output:

CONFIGURATION: https://docs.platformio.org/page/boards/raspberrypi/pico.html
PLATFORM: Raspberry Pi RP2040 (0.0.0+sha.aa251bf) > Raspberry Pi Pico
HARDWARE: RP2040 133MHz, 264KB RAM, 2MB Flash
DEBUG: Current (cmsis-dap) External (cmsis-dap, raspberrypi-swd, stlink)
PACKAGES:
 - framework-arduino-mbed 2.0.0
 - tool-openocd-raspberrypi 2.1100.0 (11.0)
 - tool-rp2040tools 1.0.2
 - toolchain-gccarmnoneeabi 1.90201.191206 (9.2.1)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 27 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Checking size .pio\build\pico\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [==        ]  18.7% (used 50500 bytes from 270336 bytes)
Flash: [          ]   3.5% (used 73056 bytes from 2097152 bytes)
Configuring upload protocol...
AVAILABLE: cmsis-dap, raspberrypi-swd, stlink
Looking for upload port...
Use manually specified: E:
Forcing reset using 1200bps open/close on port E:
Uploading .pio\build\pico\firmware.elf
rp2040load 1.0.1 - compiled with go1.15.8

There’s little documentation currently.
What is needed to get this working?

Set additionally

upload_protocol = mbed

in the platformio.ini. (This way you may also not need to specify E:.)

Thanks.

The upload appears to work now.

Building in release mode
Compiling .pio\build\pico\src\main.cpp.o
Linking .pio\build\pico\firmware.elf
Checking size .pio\build\pico\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [==        ]  18.7% (used 50500 bytes from 270336 bytes)      
Flash: [          ]   3.5% (used 73056 bytes from 2097152 bytes)     
Building .pio\build\pico\firmware.bin
Configuring upload protocol...
AVAILABLE: cmsis-dap, mbed, raspberrypi-swd, stlink
CURRENT: upload_protocol = mbed
Looking for upload disk...
Use manually specified: E:
Uploading .pio\build\pico\firmware.bin
Firmware has been successfully uploaded.
(Some boards may require manual hard reset)

I see that firmware.bin is uploaded to the Pico (E: drive).

But it does not work as expected.

  1. Pico #1, was running some MicroPython or CircuitPython before.
    firmware.bin is uloaded tot the E: drive. If I press the reset (custom added) button, then the LED starts some blink pattern which is totally unrelated to the blink sketch.
    This may be from a previous xPython experiment, I just cant remember.

    If I disconnect USB and reconnect (power cycle) then the same thing happens.

  2. Pico #2, freshly removed from package, not used before.
    This one has no reset button so to reset I have to power cycle it.

    Here comes the strange thing:
    Press BOOTSEL, connect to USB, release BOOTSEL.
    Then upload the blink sketch.
    I see firmware.bin being copied to the E: drive.
    I then disconnect and reconnect USB to powercycle.
    And then the E: drive pops up again (without firmware.bin present). It looks as if I had pressed BOOTSEL, then connected USB and released BOOTSEL again but I have NOT. I have only connected to USB again to power it. This is strange.

It looks like firmware.bin is uploaded to the Pico’s but the firmware does not do what it should do.
Size of the firmware.bin file on the E: drive is 72KB.

Hm no that’s still wrong, the USB drive doesn’t accept .bin files but .uf2 files. I re-read the code again and you shouldn’t use mbed but

upload_protocol = picotool
upload_port = E:

instead.

I’m actually trying this on Windows 10 too but the tool fails to connect

C:\Users\Max\.platformio\packages\tool-rp2040tools>picotool.exe info
No accessible RP2040 devices in BOOTSEL mode were found.

but:

Device at bus 2, address 9 appears to be a RP2040 device in BOOTSEL mode, but picotool was unable to connect

AHA. The device manager showed an unknown device. I used https://zadig.akeo.ie/ to load libusb-win32 drivers…

grafik

and now it says…

>picotool.exe info
Program Information
 none

so no error anymore.

And uploading works now too and it blinks! Yay!

Uploading .pio\build\pico\firmware.elf
rp2040load 1.0.1 - compiled with go1.15.8
.Loading into Flash: [                              ]  0%
Loading into Flash: [=                             ]  5%
Loading into Flash: [===                           ]  11%
Loading into Flash: [====                          ]  16%
Loading into Flash: [======                        ]  22%
Loading into Flash: [========                      ]  27%
Loading into Flash: [=========                     ]  33%
Loading into Flash: [===========                   ]  39%
Loading into Flash: [=============                 ]  44%
Loading into Flash: [===============               ]  50%
Loading into Flash: [================              ]  55%
Loading into Flash: [==================            ]  61%
Loading into Flash: [===================           ]  66%
Loading into Flash: [=====================         ]  72%
Loading into Flash: [=======================       ]  78%
Loading into Flash: [========================      ]  83%
Loading into Flash: [==========================    ]  89%
Loading into Flash: [============================  ]  94%
Loading into Flash: [==============================]  100%


========================= [SUCCESS] Took 3.47 seconds =========================
1 Like

It seems also once that is done once, the loaded Arduino firmware opens a COM port and that makes it work too, without specifying E:.

CURRENT: upload_protocol = picotool
Looking for upload port...
Auto-detected: COM9
Forcing reset using 1200bps open/close on port COM9
Uploading .pio\build\pico\firmware.elf
rp2040load 1.0.1 - compiled with go1.15.8
...Loading into Flash: [                              ]  0%
Loading into Flash: [=                             ]  5%
Loading into Flash: [===                           ]  11%
Loading into Flash: [====                          ]  16%
Loading into Flash: [======                        ]  22%
Loading into Flash: [========                      ]  27%
Loading into Flash: [=========                     ]  33%
Loading into Flash: [===========                   ]  39%
Loading into Flash: [=============                 ]  44%
Loading into Flash: [===============               ]  50%
Loading into Flash: [================              ]  55%
Loading into Flash: [==================            ]  61%
Loading into Flash: [===================           ]  66%
Loading into Flash: [=====================         ]  72%
Loading into Flash: [=======================       ]  78%
Loading into Flash: [========================      ]  83%
Loading into Flash: [==========================    ]  89%
Loading into Flash: [============================  ]  94%
Loading into Flash: [==============================]  100%

======================== [SUCCESS] Took 12.80 seconds ========================

Not entirely sure if this is the intended way, but it got me up and running.

Edit: There’s also discussion in Upload port required · Issue #2 · platformio/platform-raspberrypi · GitHub about this.

1 Like

It’s interesting regarding:

CURRENT: upload_protocol = picotool

I haven’t been specifying the above upload_protocol setting, just using upload_port.

According to Appendix B: Using Picotool (https://datasheets.raspberrypi.org/pico/getting-started-with-pico.pdf), picotool utility can be used to extract embedded information (e.g. Basic info related to program currently on a Pico; Pins - pin assignments used by the program; build attributes) from a Raspberry Pi Pico.

This can be quite useful if you want to check what is currently running on a Pico or in a target file (uf2, elf, or bin) .

1 Like

Thanks!
That solved the upload issue.

It’s a pitty that PlatformIO cannot detect the proper drive/volume automatically (similar for upload_protol embed).

I tried. This worked a few times but then again it needed upload_port to be specified again.

When using SerialUSB for printing output to the serial monitor, auto upload unfortunately does not work anymore and the Pico needs to be in BOOTSEL mode to be able to upload anything to it.

It would be useful if that could be fixed but this may be related to the design of the Pico(?).

Putting the Pico in BOOTSEL mode every time is a bit of a PITB because it has to be power cycled to reset it (due to lack of a reset button) which normally means disconnecting and reconnecting the USB connector every time.
For this reason I soldered a reset button on top of one of my Pico’s.

Luckily I’m now able to upload, but the next step is getting an existing program to run on the Pico. I currently get several compilation errors that appear not easy to fix and may possibly be related to incompatibilities in the Arduino Embed core(?).

E.g. while doing some tests I noticed that the standard SDA and SCL pin definitions are not present. Instead I2C_SDA and I2C_SCL are defined. This is a fundamental incompatibility when compared with most other Arduino cores (SPI pins are defined though).

The issues I’m currently running into seem more complex than just lacking SDA and SCL pin definitions, but latter indicates that there may be more compatibility issues with the ‘Arduino Embed’ Arduino core.

Possibly the issue is related to use of namespaces.
For instance I noticed that instead of UART one needs to specify arduino::UART.

I needed this to get a reference to SerialUSB:

arduino::UART& serial = SerialUSB;

so I can do something like

serial.println("Code does not need to know if SerialUSB or Serial");

Having to explicitly add the namespace may possibly also cause issues elsewhere, in external libraries. I’m not yet sure what is causing the problems.

The program I’m trying to run on the Pico, runs without problems on many other Arduino cores (e.g. STM32, SAMD21, ESP21, ATmega328) but for the Pico I currently get many errors when compiling.

In attempts to transfer some of the Pico sketches (e.g. Bodmer's ILI9341 tft_espi driver, GitHub - Bodmer/TFT_eSPI: Arduino and PlatformIO IDE compatible TFT library optimised for the Raspberry Pi Pico (RP2040), STM32, ESP8266 and ESP32 that supports different driver chips) to PlatformIO that work fine under Arduino IDE, I’m finding a significant number of warnings that crop up under PlatformIO that do not occur under the Arduino IDE, plus some that then fail in PlatformIO but succeed under the Arduino IDE.

For example, using Arduino IDE with Arduino-mbed core, I can successfully build most of Bodmer’s tft_espi examples for a Pico hooked up to a ILI9341 display using SPI and they run fine. With the Arduino IDE set to capture all compiler warnings, only a handle of warnings show up.

However, if the same source gets re-compiled under PlatformIO, I observe a significant number of warnings to do with the expansion of SPI macros (SPI0_BASE, spit_hw, spi0). Some of these warnings may well be due to potential incompatibilities in the Arduino-mbed core and other Arduino libraries.

Despite the large number of compilation warnings, I’m able to run most of Bodmer’s tft_espi examples on the Pico-ILI9341TFT using PlatformIO.

Bottom line? On the Pico, we can expect both the Arduino-mbed core and PlatformIO support to be a work in-progress for sometime to come. Hopefully over the next several months more of these issues will get resolved.

On another note, I hope the PlatformIO developers can add J-Link & ST-Link support for Pico debugging. Segger already provides Pico support for J-Link and some of us can debug Pico using VSCODE + Pico SDK/cmake with J-Link.

I have tried to use U8g2 with SSD1306 OLED display.
Even this already gives errors.

The advantage of Arduino is that (nowadays) it is cross platform.
It should be possible to run many popular examples and libraries (that are not architecture specific) on any Arduino core.
If this is not possible than the port of the Arduino framework to that architecture is not (yet) successful i.m.o. and possibly still a long way to go.

Adafruit SSD1306 + GFX works with Pico & Arduino IDE. However, the same code under PlatformIO generates tons of warnings.

Bodmer’s optimised tft_eSPI driver works with Pico and ILI9341 displays. Again mostly under Arduino IDE.

Next, I’ll test out a Pico with a ST7789 display, and then ADC, PWM, etc.

Yes, agree that we’re still at the early stages of Arduino-mbed core for RP2040 and its integration with PlatformIO.

After update to Release the automatic upload doesn’t work anymore.
I’m working on macOS and this behavior is new because the port was automatic detected before.
Bildschirmfoto 2021-05-01 um 16.38.39

What version of macOS are you using?

What update to Release are you referring to?

I’ve been specifying the USB UF2 explicitly via

upload_port = /Volumes/RPI-RP2

Auto port detection hasn’t worked for me on macOS 10.14.6 or macOS 11.3.

I hope we get a release of PlatformIO that supports jlink and stlink soon and be able to debug.

Your upload method works only once after then get following error
Bildschirmfoto 2021-05-01 um 22.56.49

After deleting upload_port = /Volumes/RPI-RP2 from .ini it works know as expected.

I’m a little confused. Your automatic upload wasn’t working, then after adding
upload_port = /Volumes/RPI-RP2 the upload worked only once. After reverting, the auto upload started to work again. Correct?

Which version of macOS are you using?

For me, on both macOS 11.3 and macOS 10.14.6 (VSCode 1.55.2), I’m using the below platform.ini. Uploads work consistently in all of my Pico projects. Don’t forget to put the Pico into upload mode via BOOTSEL/RESET sequence before uploading.

If I omit the upload_port from the platform.ini then uploads fail.

[platformio]
default_envs = pico

[env:pico]
platform = https://github.com/platformio/platform-raspberrypi.git
framework = arduino
board = pico
upload_protocol= picotool
upload_port = /Volumes/RPI-RP2

Screen Shot 2021-05-01 at 5.35.02 PM