Read and Write to the flash memory

dev board RobotDyn M0 Mini
firmware Arduino
chip SAMD21
features flash read write

Before starting

Dependancies

Ensure the following requirements are available:

Pre-requisites

Try these simpler examples:

Buy the components

Description

Read and write a single number to the flash memory of a SAMD21 board (E.g. Arduino M0 or RobotDyn SAMD21 M0-Mini).

Code

Download code
#include <FlashStorage.h>

FlashStorage(my_flash_store, int);
String readString = "54";  // Change this number to store in flash

void setup() {
  SerialUSB.begin(9600);
  while (!SerialUSB) { }
  delay(100);

  int number;

  SerialUSB.print("Number read from flash before storing: ");
  number = my_flash_store.read();
  SerialUSB.println(number);

  SerialUSB.print("Number from user: ");
  SerialUSB.println(readString);

  SerialUSB.println("Number has been stored in flash!");
  my_flash_store.write(readString.toInt());

  SerialUSB.print("Number read from flash: ");
  number = my_flash_store.read();
  SerialUSB.println(number);
}

void loop() {}

Makefile

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

Serial console

Serial output from the firmware.

Read and Write to the flash memory serial console

References

Watch