STM32 read and write protection features and settings

:: function
will read the protection settings can not read the contents of the flash; when released when read protection stm32 will automatically wipe out
entire flash;
set:
read protection settings: In the beginning of the program by adding "Read Protection" code that is achieved read protection; (each program

Run first
open protection)
release the read protection: read protection release button may be provided on the inside, to facilitate unlocking, nor may not be provided;
(1) read protection provided:
IF (FLASH_GetReadOutProtectionStatus () = the SET)!
{
// FLASH_Unlock (); unlock FALSH not read can also be set to protect? ? ?
FLASH_ReadOutProtection (the ENABLE);
}
(2) read protection release
IF (FLASH_GetReadOutProtectionStatus () = the RESET!)
{
FLASH_Unlock ();
FLASH_ReadOutProtection (the DISABLE);
}
These functions stm32f10x_flash inside;
Note: The above call time required in the library #include "stm32f10x_flash.h" before adding #define

_FLASH_PROG;
otherwise, newspaper (not defined) wrong;

************************************************************************

/* Flash读保护使能 */ 
if (FLASH_GetReadOutProtectionStatus() == RESET) 
{
FLASH_Unlock();
FLASH_ReadOutProtection(ENABLE); 
}


/ * Clear Flash read protection * / 
IF (FLASH_GetReadOutProtectionStatus () == the SET) 

/ * * erases Flash /
FLASH_Unlock ();
FLASH_ReadOutProtection (the DISABLE); 
}

After the CPU Flash read protection is enabled, the emulator debug fail. J-LINK has a menu to unlock, need to unlock the programming process to function properly again. Of course, unlocking cause Flash content is all clashes.
Start "J-Flash ARM" tool, Target-> unsercure chip on the lifting of the read protected chip.
Target-> After unsercure chip must be power-on reset, system reset is not acceptable.

Be sure to power-on reset, reset the system does not work!

STM32 measures to protect the internal Flash

1, STM32 measures to protect the internal Flash of 
all the chips are STM32 Flash provides protection to prevent unauthorized access to the Flash - write protection and read protection. 
1), read protection in what is often said that the "encryption" is applied to the entire Flash memory area. Flash read protection once set, the built-in Flash memory area can be read out only by normal program execution, but can not be read out in any of the following: the debugger (JTAG or SWD);
boot from the RAM and program execution; 
2), write protection is four (1KB / page) Flash memory write-protects the area as a unit, on page protected implementation program or erase operation will not be executed, while generating operating error flag. 
The effect of reading and writing settings in the table below: 
read protection write protect operating functions of Flash 
Enabled Enabled CPU can only read, debug, and prohibit unauthorized access. 
Valid Invalid CPU can read and write, debug, and prohibit illegal access, p. 0-3 is write-protected. 
Disabled Enabled CPU readable, allows debugging and unauthorized access. 
Invalid Invalid CPU can read and write, debug, and allow unauthorized access.


2, when the Flash read protection into effect, http: //tiyubisai.com/video_news/news_135620.html CPU executes the program can be read by the Flash area protected, but there are two exceptions: 
1), when the debug executive; 
2) when RAM to start and execute the program from the 
STM32 also provides a special protection, ie after applying read protection of Flash storage area, even if no write-protected, Flash of 0 to 3 will be write-protected, which is to to prevent or modify the interrupt vector is reset to jump to the RAM area performed an illegal code.
3, Flash protection correlation function 
FLASH_Unlock (); // Flash unlock 
FLASH_ReadOutProtection (DISABLE); // Flash read protection prohibited 
FLASH_ReadOutProtection (ENABLE); // Flash read protection permit

To summarize FLASH reading step of reading protection and de-protection:
(1) Set read protected
int main (void)
{
....
IF (FLASH_GetReadOutProtectionStatus () = the SET!)
{
// FLASH_Unlock ();
FLASH_ReadOutProtection (ENABLE); 
}
......
the while (. 1)
{
.....
}
}
(2) release the read protection: an operation in the program (such as key presses, etc.) add the following code after the execution of
the code he killed own, ha ha! ! !
IF (FLASH_GetReadOutProtectionStatus () = the RESET!)
{
FLASH_Unlock ();
FLASH_ReadOutProtection (the DISABLE); 

If you do not enter disarmament read protection code in the program, it does not matter, you can write in block RAM running
for canceling the read protection, after execution, FLASH will automatically erase all. The following code:
int main (void)
{
Chinp_Init ();
FLASH_Unlock ();
FLASH_ReadOutProtection (the DISABLE); 
}

※ to run the program in RAM, as follows:
(1) I use IAR + J-Link, and without the Boot0 arranged boot1 foot can debug (I arranged to boot from FLASH) from the boot RAM in RAM.
(2) Set Link file in IAR environment for lnkarm_ram.xcl
(3) Debuger options Download tab in the hook all removed.
When finished, press disposed above Debug button press, performing the above procedure may be read protection release.

http://blog.csdn.net/chengfeng135/article/details/49638181

http://blog.csdn.net/chengfeng135/
--------------------- 

Original: https: //blog.csdn.net/chengfeng135/article/details / 49638245 
 

Guess you like

Origin blog.csdn.net/oshan2012/article/details/90314788