I want to write a variable, for example an integer with the number 5 to the FLASH and then after the power goes away and the device is turned on again read it.
I already know that in order to write something I first need to erase the page and then write.
In the manual it says:
- Write OPTKEY1 = 0x0819 2A3B in the Flash option key register (FLASH_OPTKEYR)
- Write OPTKEY2 = 0x4C5D 6E7F in the Flash option key register (FLASH_OPTKEYR)
How do I perform this tasks?
Sector 0 has a Block adress from 0x0800 0000 to 0x0800 3FFF, this is where I want to write.
Here the link to the manual, page 71: STM32 Manual
OPTKEY1
andOPTKEY2
are values, not addresses. Adding them to the address of FLASH_OPTKEYR will result in a crash or unexpected behavior. – Karlise