AT32F425
Series Reference Manual
2022.03.30
Page 75
Ver 2.01
5.6
Special functions
5.6.1
Security library settings
Security library is a defined area protected by a code 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 includes instruction security library and data security library.
Advantages of security library:
Security library is protected by codes so that solution providers can program core algorithm into this
area;
Security library cannot be read or deleted (including ISP/IAP/SWD) but only executed unless code
defined by the solution provider is keyed in;
The rest of the 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 full
solutions for every customer.
Security library helps prevent from deliberate damage or changing terminal application codes.
Note: Security library code must be programmed based on page level, and the start address must be
aligned with Flash memory address;
Only I-Code bus is permitted to read instruction security library;
I-Code and D-Code bus are able to read read-only area;
In an attempt of writing or erasing security library code, a warning will be given by 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
this register, security library must be unlocked first by writing 0xA35F6D24 to the SLIB_UNLOCK register,
and checking the SLIB_ULKF bit in the SLIB_MISC_STS register to verify if it is unlocked successfully
and then writing the programmed value into the security library setting register.
Follow the steps below to enable security library:
Check the OBF bit in the FLASH_STS register to ensure that there is no other ongoing programming
operation;
Write 0xA35F6D24 to the SLIB_KEYR register to unlock security library;
Check the SLIB_ULKF bit of SLIB_MISC_STS register to verify that it is unlocked successfully;
If the security library is located in main Flash memory, it is necessary to set the pages to be protected
(including instruction and read-only area) in the SLIB_SET_RANG register; if the security library is
in the main Flash memory extention area, it is required to set the EM_SLIB_SET register;
Wait until the OBF bit becomes “0”;
Set a password in the SLIB_SET_PWD register
Wait until the OBF bit becomes “0”
Program the code to be saved in security library
Perform system reset, and then reload security library setting word
Read the SLIB_STS0/STS1 register to verify the security library settings
Note:
It is not permitted to configure the main Flash memory and its extension area as security library
simultaneously;
Security library should enabled when the Flash access protection is disabled.
Follow the steps below to unlock security library:
Write the previously set security library password to the SLIB_PWD_CLR register
Wait until the OBF bit becomes “0”
Perform system reset, and then reload security library setting word
Read the SLIB_STS0 register to check the security library settings