AT32F421 Series Reference Manual
2022.11.11 Page 70 Rev 2.02
5.5.2 Erase/program protection
For 64 K Flash memory and less, erase/program protection is performed on the basis of 4 sectors.
This is used to protect the contents in the Flash memory against inadvertent operation when the program
crash occurs.
Erase/program operation is not permitted under one of the following events, and the EPPERR bit is set
accordingly:
Attempting to erase/program sectors (in Flash memory and its extended area) which are already
protected (erase/program protection enabled)
Attempting to mass erase Flash memory and its extended area) in which one of the sectors is
already protected (erase/program protection enabled)
When the Flash access protection is enabled, the sector 0~3 in the main Flash memory will
be protected against erase/program automatically. In this case, no sector erase/program is
allowed.
When the Flash access protection is enabled, the main Flash memory and its extended area are
protected when they are in debug mode or when booting from non-main Flash memory. In this
case, no sector erase/program is allowed.
5.6 Read access
To increase system clock frequency, it is necessary to program the number of wait states to access to
Flash memory through the WTCYC bit in the FLASH_PSR register.
The Flash read times can be decreased through the PFT_EN, PFT_EN and PFT_LAT_DIS bits in the
FLASH_PSR register.
The HFCYC_EN bit (when it is enabled) is used to save half-cycle system clock for Flash memory access,
which is useful for continually reading large amount of constants. But there are some restrictions in
system clock frequency. Please refer to the AT32F421 data sheet for more details.
5.7 Special functions
5.7.1 Security library settings
Security library is a defined area protected by a password in the main memory. This area is only
executable but cannot be read (Except for I-Code and D-code buses), written, or deleted, unless a
correct code is keyed in. Security library contains instruction security library and data security library.
Advantages of security library:
Security library is protected by a password so that solution providers can program core algorithm into
this area;
Security library is executable, but cannot be read or deleted (including ISP/IAP/SWD) unless a correct
password defined by the solution provider is keyed in;
The remaining blank area can be used for secondary development by solution providers;
Solution providers can sell core algorithm with security library function and do not have to develop a
complete set of solutions for every customer.
Security library helps prevent from deliberate damage or changing terminal application codes.
Note:
Security library code must be programmed on the sector level, with its start address being aligned with
the main memory address;
Only I-Code bus is allowed to read instruction security library;
Only I-Code and D-Code bus are allowed to read the read-only area;
In an attempt of writing or deleting security library code, a warning message will be issued by setting
WRPRTFLR =1 in the FLASH_STS register;
Executing mass erase in the main memory will not erase the security library.
By default, security library setting register is unreadable and write protected. To enable write access to