🛠 Journaliser dans la flash QSPI 16 Mo (pas de slot TF)

Arduino Nicla Vision · avance · Schéma : IMG-nicla-vision-avance-1-niclavision-logs-flash-qspi.svg — architecture mémoire du Nicla Vision : STM32H747, bus QSPI vers la puce NOR 16 Mo découpée en zones romfs, firmware radio et journal circulaire

Objectives

Set up a non-volatile measurement log on the Nicla Vision. Warning: the board has NO micro-SD card reader; the embedded mass storage is the 16 MB (128 Mbit) QSPI NOR flash, of which MicroPython exposes ~88 Mbit as a filesystem after 4 MB of romfs and 1 MB of Wi-Fi/BT firmware.

Hardware

Complete code

// Journal circulaire brut dans la flash QSPI (mbed QSPI)
// > 
#include "QSPI.h"

QSPI qspi(PD_11, PF_9, PE_2, PD_13, PF_10, PG_6); // bus QSPI x4
const uint32_t LOG_BASE = 0x600000;  // zone journal apres romfs+fw (hyp.)
const uint16_t SECT = 4096;          // effacement par secteur
uint32_t offset = 0;

void flashCmd(uint8_t cmd, uint32_t addr, const uint8_t* buf, size_t n, bool write) {
  qspi.format(8, 0);
  qspi.frequency(1000000);
  QSPI_TransferConfig_t t = {};
  t.instruction = cmd; t.address = addr;
  t.alternateBytes = 0; t.dataMode = QSPI_1;
  t.dataLength = n; t.dataBufferSize = n;
  t.txBuffer = write ? (uint8_t*)buf : nullptr;
  t.rxBuffer = write ? nullptr : (uint8_t*)buf;
  qspi.transfer(&t);
}

void logLine(const char* line) {
  uint32_t a = LOG_BASE + (offset % (256 * SECT));
  uint8_t we = 0x06; flashCmd(we, 0, nullptr, 0, true);      // write enable
  uint8_t er = 0x20; flashCmd(er, a & ~(SECT - 1), nullptr, 0, true); // erase
  uint8_t pp[64]; memset(pp, 0xFF, 64); size_t L = strlen(line);
  memcpy(pp, line, L > 63 ? 63 : L);
  we = 0x06; flashCmd(we, 0, nullptr, 0, true);
  flashCmd(0x32, a, pp, 64, true);                            // page program
  offset += 64;
}

void setup {
  Serial.begin(115200);
  char buf[48]; uint32_t n = 0;
  snprintf(buf, sizeof buf, "%lu,tof=%u\n", (unsigned long)millis, n++);
  logLine(buf);
  Serial.println(F("ligne journalisee en QSPI"));
}
void loop {}

Expected verification

Replay the 0x03 read on LOG_BASE after reset: the line is still present (non-volatile). In MicroPython, the same area is accessible via os.listdir on the QSPI filesystem — path confirmed by the official port.

Common errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials