DocID024597 Rev 5 113/1830
RM0351 Embedded Flash memory (FLASH)
136
3.4.2 Option bytes programming
After reset, the options related bits in the Flash control register (FLASH_CR) are write-
protected. To run any operation on the option bytes page, the option lock bit OPTLOCK in
the Flash control register (FLASH_CR) must be cleared. The following sequence is used to
unlock this register:
1. Unlock the FLASH_CR with the LOCK clearing sequence (refer to Unlocking the Flash
memory).
2. Write OPTKEY1 = 0x08192A3B in the Flash option key register (FLASH_OPTKEYR).
3. Write OPTKEY2 = 0x4C5D6E7F in the FLASH_OPTKEYR register.
The user options can be protected against unwanted erase/program operations by setting
the OPTLOCK bit by software.
Note: If LOCK is set by software, OPTLOCK is automatically set too.
Modifying user options
The option bytes are programmed differently from a main memory user address. It is not
possible to modify independently user options of bank 1 or bank 2. The users Options of the
bank 1 are modified first.
To modify the user options value, follow the procedure below:
1. Check that no Flash memory operation is on going by checking the BSY bit in the Flash
status register (FLASH_SR).
2. Clear OPTLOCK option lock bit with the clearing sequence described above.
3. Write the desired options value in the options registers: Flash option register
(FLASH_OPTR), Flash Bank 1 PCROP Start address register (FLASH_PCROP1SR),
Flash Bank 1 PCROP End address register (FLASH_PCROP1ER), Flash Bank 1 WRP
area A address register (FLASH_WRP1AR), Flash Bank 1 WRP area B address
register (FLASH_WRP1BR), Flash Bank 2 PCROP Start address register
(FLASH_PCROP2SR), Flash Bank 2 PCROP End address register
(FLASH_PCROP2ER), Flash Bank 2 WRP area A address register
(FLASH_WRP2AR), Flash Bank 2 WRP area B address register (FLASH_WRP2BR).
4. Set the Options Start bit OPTSTRT in the Flash control register (FLASH_CR).
5. Wait for the BSY bit to be cleared.
Note: Any modification of the value of one option is automatically performed by erasing both user
option bytes pages first (bank 1 and bank 2) and then programming all the option bytes with
the values contained in the flash option registers.
Bits 23:16 WRP2B_END: Bank 2 WRP first area “B” end offset
WRP2B_END contains the last page of the Bank 2 WRP second area.
Bits 15:8 Not used
Bits 7:0 WRP2B_STRT: Bank 2 WRP first area “B” start offset
WRP2B_STRT contains the first page of the Bank 2 WRP second area.