SAMD21 non volatile setup storage

Looking to store a small amount fo config data < 4k bytes but have it survive an update of code, seen some indications that we can set the max linker memory size to stop overwrites, is there anything that wraps this up as a library that works on samd21 (Seeed Xiao for example) ?


The Seeed Xiao core has the FlashStroage library which is able to store basic variables in structs into flash and read them back. See e.g. example. Does that work for you?

Other cores might have different libraries.

I think the reason why that did not work for me was this:

// Note: the area of flash memory reserved lost every time
// the sketch is uploaded on the board.

Need to track something over firmware updates… it’s not leaping out to me how I could modify this to use a reserved block at end of space, sure I can create something ff the back of it but I’m lazy and hoped someone had done it better :slight_smile:


The reason it gets lost when the sketch is reflashed is because the persistent memory managed by that FlashStorage library is within the sketch itself (think of it as a static const variable in Flash, which it is – of course it’s still modified with the flash controller). Depending on the way you firmware updates (from within the code?) you are able to temporarily load the data into RAM and write it back, or skip over this part in the firmware update process. But yes if you’d just reflash the sketch normally via USB, it would get lost, and you’d need to prevent that with a custom linker script so that a few pages of flash are never touched.

Have you looked into the resources linked at how to get an EEPROM like functionality ? - #3 by Dirk67 - Arduino Zero - Arduino Forum? The Atmel Start Framework has a more sophisticated EEPROM emulation. Though something simpler such as modifying the linker script would also do, you need to look into the datasheet for details though. Per doc and code you can inform PlatformIO about modified available space through board_upload.maximum_size = xyz in the platformio.ini, and the linker script with board_build.ldscript = abc (code).