Dependancies
Pre-requisites
Buy the components
eeprom-emulation-samd21.ino
#include <FlashAsEEPROM.h>
void setup() {
SerialUSB.begin(115200);
delay(100);
}
void loop() {
if (!EEPROM.isValid()) {
SerialUSB.println("EEPROM is empty, writing some example data:");
storeInFlash();
SerialUSB.print("");
} else {
SerialUSB.println("EEPROM has been written.");
SerialUSB.print("Total length of EEPROM is ");
SerialUSB.println(EEPROM.length());
SerialUSB.println("Here is the content of the first 20 bytes:");
SerialUSB.print("->");
readFromFlash();
SerialUSB.println("");
}
delay(5000);
}
void storeInFlash() {
for (int i = 0; i < 20; i++) {
EEPROM.write(i, 100+i);
SerialUSB.print(" ");
SerialUSB.print(100+i);
}
EEPROM.commit();
}
void readFromFlash() {
for (int i = 0; i < 20; i++) {
SerialUSB.print(" ");
SerialUSB.print(EEPROM.read(i));
}
SerialUSB.println();
}
BOARD?=arduino:samd:mzero_bl
PORT := $(shell ls /dev/cu.usbmodem*)
.PHONY: default lint all flash clean
default: lint all flash clean
lint:
cpplint --extensions=ino --filter=-legal/copyright *.ino
all:
arduino-cli compile --fqbn $(BOARD) ./
flash:
arduino-cli upload -p $(PORT) --fqbn $(BOARD) ./
clean:
rm -f .*.bin
rm -f .*.elf
rm -f .*.hex
Read and write to the flash memory of a SAMD21 board (E.g. Arduino M0 or RobotDyn SAMD21 M0-Mini) with the EEPROM Arduino API.
The following APIs are used in the example:
EEPROM.isValid()
EEPROM.length()
EEPROM.commit()
EEPROM.write
EEPROM.read