How can Flash memory replace EEPROM?

We used to work with EEPROM on the 328p to dynamically save data and read it while the program runs.

I could see that with some Arduino chips, like the SAMD21 ARM, there is EEPROM by emulation, where you save stuff to the flash using a protected area RWW .

What I know is that Flash is a program memory that is written once the chip is programmed, so how can you emulate a dynamic EEPROM with Flash? ( saving data in runtime?)

Thanks.

I don't see why it would be a problem. Flash is read/write. I doubt there is any difference between saving data to it in programming mode or when your actual program is running.

As far as I understand, in programming mode there is a piece of code running (bootloader), saving incoming data to user programming space. Why would it be a problem to reserve a piece of that space for eeprom emulation and let your program code read and write to it?

There is a bootloader addition, which unfortunately I don’t have bookmarked on this computer, that will let your sketch write to flash memory. This code can only be executed from the bootloader area of memory.

I don’t know if it’s any faster than the 3.3mS it takes for an EEPROM write.