🛠 Dual-core et mise à jour OTA sur la flash 4 Mo

Raspberry Pi Pico 2 W · avance · Schéma : IMG-pico-2-w-avance-9-pico2w-ota-double-coeur.svg — deux cœurs RP2350 séparés, flash 4 Mo découpée en zones A/B, téléchargement Wi-Fi écrivant la zone inactive et bascule du boot-info.

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

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

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials