cmaglie / FlashStorage

A convenient way to store data into Flash memory on the ATSAMD21 and ATSAMD51 processor family
202 stars 69 forks source link

What's the point of using this library vs. simply defining variables? #1

Closed q2dg closed 9 years ago

q2dg commented 9 years ago

I mean...if Flash memory will be erased when a new sketch is uploaded...I can't see the usefulness of this library. Thanks.

q2dg commented 9 years ago

Ooh, I see...PROGMEM is only valid in AVR, so this library would be like a "replacement" of this feature, isn t? Sorry for bothering you

cmaglie commented 9 years ago

Ooh, I see...PROGMEM is only valid in AVR, so this library would be like a "replacement" of this feature, isn t?

Well not exactly.

The equivalent of PROGMEM for ARM is to just declare data as static const, since ARM Cortex-M has a flat addressing space and you can access flash memory directly, you don't need to pass through all the pgmspace.h mess like on AVR.

const char flash_string[] = "Hello!";   // <-- On 32-bit ARM Cortex this is stored in Flash

void loop() {
     Serial.println(flash_string);
}

This is far easier compared to AVRs!

On the other hand most Cortex-M based CPU doesn't provide an EEPROM (well, some chip-maker may have some CPU models with it, but from my experience it's not so common) so this library is aimed to be an alternative to EEPROM (in fact allows you to change the content of the data stored in flash).

Of course this library shows also the limits of a Flash memory compared to an EEPROM:

q2dg commented 9 years ago

Oooh, I see! Thanks a lot for your explanation! Maybe it should be placed in README.md, as it clears several doubts other people could also have. Thanks!