arduinoarduino-idefirmwarearduino-c++rp2040

RP2040-Zero (using Arduino C++) does not persist loaded program


I've got the RP2040-Zero from Waveshare and am using the Arduino IDE with C++ to program it. The firmware upload happens using the UF2 system where the device looks to the host computer like a file system and a UF2 file is stored there, but in reality the UF2 file is converted to firmware and loaded into the RP2040 memory. This works great when writing the program using the Arduino IDE and and then letting it download the code to see if the program works.

This is the code:

#include <Arduino.h>
#include <FastLEDh>
#include NUM_LEDS 1
#include DATA_PIN 16
CRGB leds[NUM_LEDS];
bool led_is_on;

void setup() {
    Serial.begin(115200);
    while (!Serial);
    delay(1000);
    Serial.println("Initializing the system");
    FastLED.addLeds<WS2812B, DATA_PIN>(leds, NUM_LEDS);
    led_is_on = false;
}

void loop() {
    leds[0] = (led_is_on = !led_is_on) ? CRGB::Red : CRGB::Green;
    FastLED.show();
    delay(500);
}

However, when I just press the RESET button (or cycle power to the device) the program does not load anymore and the device is not active until I download again with the Arduino IDE.

How can I convince the RP2040 to remember the downloaded C++ firmware?


Solution

  • Here's the reason: Turns out that while Arduino UNO boards and ESP32 boards seem to always start the Serial interface, regardless of whether there's anything there to listen to it, the RP2040-Zero does not. And the while (!Serial); statement effectively made it look like the board is dead (which it is, as it is an endless loop after all).

    Removing the Serial port parts made the board work just fine.