Understand ChengYeXing · Start from every drop
Electronic component suppliers of global famous brands

STM32 protection measures for internal Flash

STM32 protection measures for internal Flash

STM32 protection measures for internal Flash

1. STM32 protection measures for internal Flash


All STM32 chips provide Flash protection to prevent illegal access to Flash - write protection and read protection.


1) Read protection, commonly known as "encryption", is applied to the entire Flash storage area. Once the read protection of Flash is set, the built-in Flash storage area can only be read through the normal execution of the program, but not through any of the following methods:


Through the debugger (JTAG or SWD);


Program started and executed from RAM;






2) . Write protection is to provide write protection based on a four-page (1KB/page) Flash storage area. Programming or erasing the protected page will not be performed, and an operation error flag will be generated at the same time.





The effect of read and write settings is shown in the following table:


Read protection Write protection Flash operation function


Effective and effective CPU can only read, debugging and illegal access are prohibited.


Effective and invalid CPUs can read and write, debugging and illegal access are prohibited, and pages 0~3 are write protected.


Invalid valid CPU readable, debugging and illegal access allowed.


Invalid CPU can be read and written, and debugging and illegal access are allowed.





2. When Flash read protection takes effect, the CPU execution program can read the protected Flash area, but there are two exceptions:


1) When debugging the execution program;


2) When starting and executing programs from RAM





STM32 also provides a special protection, that is, after the read protection is applied to the Flash storage area, even if the write protection is not enabled, pages 0 to 3 of the Flash will also be in the write protection state. This is to prevent changing the reset or interrupt vector and jumping to the RAM area to execute illegal program code.





3. Flash protection related functions


FLASH_ Unlock(); // Flash unlock


FLASH_ ReadOutProtection(DISABLE); // Flash read protection prohibited


FLASH_ ReadOutProtection(ENABLE); // Flash read protection allowed

粤ICP备2022135715号