AT32F421
Series Reference Manual
2022.11.11
Page 66
Rev 2.02
5.4 User system data area
5.4.1
Unlock/lock
After reset, user system data area is protected, by default. Write and erase operations can be performed
only after the Flash memory is unlocked and then the user system data area is unlocked.
Unlock procedure:
Flash memory block can be unlocked by writing KEY1 (0x45670123) and KEY2 (0xCDEF89AB) to the
FLASH_UNLOCK register;
Writing KEY1 (0x45670123) and KEY2 (0xCDEF89AB) to the FLASH_USD_UNLOCK register, the
USDULKS bit in the FLASH_CTRL register will be automatically set by hardware, indicating that the user
system data area can be programmed (write/erase).
Note: Writing an incorrect key sequence leads to bus error and locks up the Flash memory until the next
reset.
Lock procedure:
User system data area is locked again by clearing the USDULKS bit in the FLASH_CTRL register by
software.
5.4.2
Erase operation
Erase operation must be done before programming. User system data area can be erased independently.
To perform erase, following the procedures below:
Check that no Flash memory operation is ongoing by checking the OBF bit in the FLASH_STS
register
Set the USDERS and ERSTR bits in the FLASH_CTRL register to enable erase operation;
Wait until the OBF bit becomes “0” in the FLASH_STS register. Read the ODF bit in the
FLASH_STSx register to verify.
Note: Read operation to the Flash memory during programming halts CPU until the completion of
erase. The internal HICK must be enabled prior to erase operation.