🛠 Dual-core et mise à jour OTA sur la flash 4 Mo
Objectives
Leverage the RP2350's two cores and 4 MB flash: core 0 handles Wi-Fi (CYW43), core 1 handles the application logic, synchronized via mutexes; the OTA update downloads firmware into the inactive flash region and then switches the boot-info to start from it, similar to the official pico_w/wifi/ota_update example.
Hardware
- Pico 2 W connected to Wi-Fi
- pico-sdk (pico_multicore, pico_bootrom, flash API)
- HTTP server hosting the new firmware .bin
Full code
// main.c - dual-core + squelette OTA (inspiré pico_w/wifi/ota_update)
#include "pico/stdlib.h"
#include "pico/multicore.h"
#include "pico/cyw43_arch.h"
#include "pico/bootrom.h"
static volatile bool firmware_pret = false;
void coeur_metier(void) { // coeur 1 : logique, jamais de lwIP ici
while (true) {
if (firmware_pret) {
rom_data_call(ROM_TABLE_ENTRY_RESET_TO_BOOTLOADER, 0);
}
sleep_ms(100);
}
}
int main(void) {
stdio_init_all;
if (cyw43_arch_init) { return 1; } // Wi-Fi sur coeur 0
cyw43_arch_enable_sta_mode;
cyw43_arch_wifi_connect_timeout_ms(
"mon_ssid", "mon_mot_de_passe", CYW43_AUTH_WPA2_AES_PSK, 30000);
multicore_launch_core1(coeur_metier);
// 1) telecharger firmware.bin en HTTP vers la zone B (flash_range_erase
// puis flash_range_program, hors zone XIP du programme courant)
// 2) verifier taille + checksum
// 3) ecrire un boot-info pointant vers la zone B, puis reinitialiser
firmware_pret = true;
while (true) { sleep_ms(500); }
}
Expected verification
After a complete download and valid checksum, the board resets, starts from region B, and the version displayed over serial has changed. Core 1 continues running during the download without corrupting lwIP.
Common errors
- Writing to the flash region containing the XIP code of the currently running firmware: the program crashes; identify addresses using the .map file and picotool.
- Calling lwIP APIs from core 1: all networking must remain on the core running cyw43_arch (bug in MicroPython < 1.25: Wi-Fi events were lost when core 1 was running).
- Forgetting the checksum before switching: a truncated firmware bricks the boot process, keep the fallback to region A.
- Not disabling interrupts around flash_range_program: the written data gets corrupted.
Other tutorials for this board
Code examples for this board
clignotante.pyPythonbouton-interruption.pyPythonpwm-servo.pyPythonlecture-adc.pyPythonneopixel.pyPythonoled-i2c.pyPython