您现在的位置: 主页 > 嵌入式开发入门到精通 > 单片机技术进阶 > STM32F4(Flash读保护) -
本文所属标签:
为本文创立个标签吧:

STM32F4(Flash读保护) -

来源: 网络用户发布,如有版权联系网管删除 2018-09-08 

[导读]
1,目的 在实际的产品发布中,如果不对储存在单片机Flash中的程序做一些保护的话,就有可能被一些不法公司,通过仿真器(J-Link,ST-Link等)把Flash中的程序读取回来,得到bin文件或hex文件,然后去山

1,目的

本文引用地址: http://www.21ic.com/app/mcu/201806/764644.htm

在实际的产品发布中,如果不对储存在单片机Flash中的程序做一些保护的话,就有可能被一些不法公司,通过仿真器(J-Link,ST-Link等)把Flash中的程序读取回来,得到bin文件或hex文件,然后去山寨产品。所以我们需要对程序进行保护,一种比较简单可靠的方法就是把Flash设置成读保护。


2,开发环境

1,适用芯片:STM32F4全部芯片

2,固件库:STM32F4xx_DSP_StdPeriph_Lib_V1.8.0

3,IDE:MDK517


3,程序源码


/****************************************************************

* Function: Flash_EnableReadProtection

* Description: Enable the read protection of user flash area.

* Input:

* Output:

* Return: 1: Read Protection successfully enable

* 2: Error: Flash read unprotection failed

*****************************************************************/

uint32_t Flash_EnableReadProtection(void)

{

/* Returns the FLASH Read Protection level. */

if( FLASH_OB_GetRDP() == RESET )

{

/* Unlock the Option Bytes */

FLASH_OB_Unlock();

/* Sets the read protection level. */

FLASH_OB_RDPConfig(OB_RDP_Level_1);

/* Start the Option Bytes programming process. */

if (FLASH_OB_Launch() != FLASH_COMPLETE)

{

/* Disable the Flash option control register access (recommended to protect

the option Bytes against possible unwanted operations) */

FLASH_OB_Lock();

/* Error: Flash read unprotection failed */

return (2);

}

/* Disable the Flash option control register access (recommended to protect

the option Bytes against possible unwanted operations) */

FLASH_OB_Lock();

/* Read Protection successfully enable */

return (1);

}

/* Read Protection successfully enable */

return (1);

}

/****************************************************************

* Function: Flash_DisableReadProtection

* Description: Disable the read protection of user flash area.

* Input:

* Output:

* Return: 1: Read Protection successfully disable

* 2: Error: Flash read unprotection failed

*****************************************************************/

uint32_t Flash_DisableReadProtection(void)

{

/* Returns the FLASH Read Protection level. */

if( FLASH_OB_GetRDP() != RESET )

{

/* Unlock the Option Bytes */

FLASH_OB_Unlock();

/* Sets the read protection level. */

FLASH_OB_RDPConfig(OB_RDP_Level_0);

/* Start the Option Bytes programming process. */

if (FLASH_OB_Launch() != FLASH_COMPLETE)

{

/* Disable the Flash option control register access (recommended to protect

the option Bytes against possible unwanted operations) */

FLASH_OB_Lock();

/* Error: Flash read unprotection failed */

return (2);

}

/* Disable the Flash option control register access (recommended to protect

the option Bytes against possible unwanted operations) */

FLASH_OB_Lock();

/* Read Protection successfully disable */

return (1);

}

/* Read Protection successfully disable */

return (1);

}




              查看评论 回复



 

"STM32F4(Flash读保护) -"的相关文章

网站地图

围观()