🛠 Bootloader DFU, flash double banque et sauvegarde sur SRAM de sauvegarde

Arduino GIGA R1 · avance · Schéma : IMG-giga-r1-a3-1-boot-flash-basse-consommation.svg — Les modes de démarrage du GIGA R1 : application USB DFU (PID 0x0666), bootloader de récupération (PID 0x0366), flash 2 Mo double banque et SRAM de sauvegarde 4 Ko maintenue par la broche VRTC.

Objectives

Understand the GIGA R1 boot chain and secure your programs: USB DFU recovery when a sketch bricks the board, organization of the 2 MB dual-bank flash of the STM32H747XI, and saving counters or calibrations in the 4 KB backup SRAM maintained by the VRTC pin. You will also learn about the OFF pin for clean power shutdown.

Hardware

Complete Code

// GIGA R1 WiFi — compteur persistant dans la SRAM de sauvegarde (4 Ko, maintenue par VRTC)
#include <Arduino.h>

// SRAM de sauvegarde STM32H7 : base 0x38800000 (4 Ko). Accès direct, noyau Mbed.
// En cas de reinitialisation complete (backup domain), la valeur devient 0xFFFFFFFF.
volatile uint32_t* const BKPSRAM = (volatile uint32_t*)0x38800000;
const uint32_t MAGIE = 0x47523158;   // "GR1X"

void setup {
  Serial.begin(115200);
  delay(1500);                        // laisse le temps d'ouvrir le moniteur

  if (BKPSRAM[0] == 0xFFFFFFFF) {     // zone vierge : premiere utilisation
    BKPSRAM[0] = MAGIE;
    BKPSRAM[1] = 0;
    Serial.println("SRAM de sauvegarde initialisee");
  }
  if (BKPSRAM[0] != MAGIE) {
    Serial.println("Sauvegarde invalide (backup domain reinitialise)");
    return;
  }
  BKPSRAM[1]++;                       // incrementation a chaque demarrage
  Serial.print("Nombre de demarrages : ");
  Serial.println(BKPSRAM[1]);
  Serial.println("Couperez l'alimentation : la valeur doit survivre (VRTC/pile)");
}

void loop { }

DFU Recovery: if a sketch prevents uploading, perform a "touch" at 1200 baud on the serial port (or hold the BOOT button depending on the host board) to enter the bootloader — it then appears with PID 0x0366 instead of 0x0666 (VID 0x2341) — then run dfu-util -a 0 -s 0x08040000:leave -D sketch.bin. On the Zephyr core, the loader resides at 0x08040000 and sketches are loaded on top via LLEXT.

Expected Verification

After several resets, the counter increases at each startup. After completely unplugging the USB (with a battery on VRTC), the value is preserved; without a battery, the backup SRAM may be lost and the message "invalid backup" appears. In recovery mode, the USB explorer shows a 2341:0366 device and dfu-util lists the board.

Common Errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials