DocID025202 Rev 7
66/1080
RM0365
Embedded Flash memory
80
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 WRPRTERR 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.
The sequence is as follows:
•
Check that no Flash memory operation is ongoing by checking the BSY bit in the
FLASH_SR register.
•
Unlock the OPTWRE bit in the FLASH_CR register.
•
Set the OPTPG bit in the FLASH_CR register
•
Write the data (half-word) to the desired address
•
Wait for the BSY bit to be reset.
•
Read the programmed value and verify.
When the Flash memory read protection option is changed from protected to unprotected, a
Mass Erase of the main Flash memory is performed before reprogramming the read
protection option. If the user wants to change an option other than the read protection
option, then the mass erase is not performed. The erased state of the read protection option
byte protects the Flash memory.
Erase procedure
The option byte erase sequence (OPTERASE) is as follows:
•
Check that no Flash memory operation is ongoing by reading the BSY bit in the
FLASH_SR register
•
Unlock the OPTWRE bit in the FLASH_CR register
•
Set the OPTER bit in the FLASH_CR register
•
Set the STRT bit in the FLASH_CR register
•
Wait for BSY to reset
•
Read the erased option bytes and verify