RM0366
Option byte programming
The option bytes are programmed differently from normal user addresses. The number of
option bytes is limited to 6 (2 for write protection, 1 for readout protection, 1 for hardware
configuration, and 2 for data storage). After unlocking the FPEC, the user has to authorize
the programming of the option bytes by writing the same set of KEYS (KEY1 and KEY2) to
the FLASH_OPTKEYR register (refer to
the OPTWRE bit in the FLASH_CR register is set by hardware and the user has to set the
OPTPG bit in the FLASH_CR register and perform a half-word write operation at the desired
flash memory address.
The value of the addressed option byte is first read to check it is really erased. If not, the
program operation is skipped and a warning is issued by the PGERR bit in the FLASH_SR
register. The end of the program operation is indicated by the EOP bit in the FLASH_SR
register.
The LSB value is automatically complemented into the MSB before the programming
operation starts. This guarantees that the option byte and its complement are always
correct.
Figure 4. Flash memory Mass Erase procedure
Read FLASH_CR_LOCK
FLASH_CR_LOCK
= 1
Write into FLASH_CR_MER
to 1
Write FLASH_CR_STRT to 1
FLASH_SR_BSY
= 0
Check EOP flag in FLASH_SR,
and then clear it by software.
Unlocking the flash memory
RM0366 Rev 5
Yes
Perform unlock sequency
No
No
Yes
Embedded flash memory
for key values). Then,
53/874
67
Need help?
Do you have a question about the STM32F301 6 Series and is the answer not in the manual?