🛠 Bootloader DFU, flash double banque et sauvegarde sur SRAM de sauvegarde
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
- 1 Arduino GIGA R1 WiFi board
- A PC with dfu-util (or the Arduino core that calls it automatically)
- Optional: a 3 V coin cell battery on VRTC to test RTC/SRAM persistence after power loss
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
- Writing to the backup SRAM without powering VRTC: data disappears upon power loss, which is not a code bug.
- Overwriting the Zephyr loader area (0x08040000) during manual DFU: reflash the loader or perform an initial Arduino upload (core ≥ 0.90.0 installs it automatically).
- Confusing the PIDs: 0x0666 = application, 0x0366 = bootloader; incorrect dfu-util targeting fails cleanly.
- Assuming flash is erasable byte by byte: flash is managed in pages/sectors; for frequent logging, prefer backup SRAM or external storage.
- Using the OFF pin without understanding it: connecting OFF to ground forces a complete board shutdown, requiring a reset press or replugging to restart.
Other tutorials for this board
Code examples for this board
clignotante.inoArduinobouton.inoArduinorespiration.inoArduinoanalogique.inoArduinodac-onde.inoArduinooled-i2c.inoArduino