
AT32F413
Series Reference Manual
2022.06.27
Page 75
Rev 2.00
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; users can select
part of or the whole security library for instruction storage, but using the whole security library for storing
data is not supported.
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 can only be located in the main Flash memory;
Security library code must be programmed by page, with its start address aligned with the main memory
address;
Interrupt vector table will be placed on the first page of Flash memory (page 0), which should not be
configured as security library;
Program codes to be protected by the security library should not be placed on the first page of Flash
memory;
Only I-Code bus is allowed to read instruction security library;
Only D-Code bus is allowed to read data security library;
When writing or deleting security library code, a warning message will be issued 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 should be unlocked first, write 0xA35F6D24 to the SLIB_UNLOCK register,
and check the SLIB_ULKF bit in the SLIB_MISC_STS register to verify if it is unlocked successfully.
Then write a value into the security library setting register.
Optional CRC check for security library code is based on a page level.
The steps to enable security library are as follows:
Check the OBF bit in the FLASH_STS register to ensure that there is no other ongoing programming
operation;
Write 0xA35F6D24 to the SLIB_UNLOCK register to unlock security library.
Check the SLIB_ULKF bit of SLIB_MISC_STS register to verify that it is unlocked successfully.
Set the pages to be protected in the SLIB_SET_RANGE register, including the address of instruction
and data area;
Wait until the OBF bit becomes “0”
Set a security libaray 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 words
Read the SLIB_STS0/STS1 register to verify the security library settings
Steps to unlock security library: