Inline ASM - Advanced AVR 3.0 Core - LMP read from flash Load Program Memory
lmp instruction allows the MCU to read from its CPU flash memory location or program space. It seems like a super complicated process, but only 2 lines of code are needed in inline asm and total 4 lines of asm code compiled, so it's super simple. The MCU can write to the program space as well, bootloader-less, and that is more complicated, implementing as a read-and-write flash memory used in application. Flash memory can be read instantly, for a good reason, since the MCU is required to read 2 bytes in one clock cycle. On the other hand, writing to flash by itself without a bootloader is slightly complicated.
1, only 1 page can be written at a time. Where as reading can be done randomly.
2, during writing a page, the MCU is freezing.
3, spm instruction only works in the RWW section. Dumb name for a section indeed. It simply means the memory address within the bootloader section.
4, read can be done so as many time as desired. Write cycle wears down the memory cell and is limited to 10k write/erase cycles or 5k actual cycles since to write a page, it is required to be erased first.
5, done, that is all.
======================================
Strategy for solving number 4:
a, for battery powered logging application, sram can be used as a buffer, and combined with power down mode, minimal amount of energy is needed to keep the content of sram alive. Flash memory is updated at a fixed interval or with external event such as a push of a button.
b, eeprom has a true random access 100k write cycle, so it should be used as a secondary buffer.