🛠 Journaliser dans la flash QSPI 16 Mo (pas de slot TF)
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
- Arduino Nicla Vision (QSPI flash on pins PD11/PF9/PE2/PD13/PF10/PG6 according to pins_arduino.h)
- ArduinoCore-mbed core
- >
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
- Looking for a TF slot: the Nicla Vision has no card reader; any reference to SD.h/SdFat is off-topic — use the QSPI (or the 2 MB MCU flash for very short logs).
- Erasing the radio firmware area: never write to the first 5 MB (romfs + Wi-Fi/BT firmware); erasing breaks connectivity (full DFU reflash required).
- Forgetting the erase: a NOR page can only be programmed from 1 to 0; without a prior 0x20, bytes are ANDed with the old content.
- Frequent writes: sector erase wears out the chip; log in bursts (RAM buffer, write every N lines).
- QSPI frequency too high: start at 1 MHz before increasing, depending on the actual chip.
Other tutorials for this board
Code examples for this board
led_rgb.inoArduinoimu_lsm6dsox.inoArduinotof_distance.inoArduinomicro_pdm.inoArduinocamera_capture.inoArduinowifi_scan.inoArduino