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

1,目的

在实际的产品发布中,如果不对储存在单片机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);

}


本站声明: 本文章由作者或相关机构授权发布,目的在于传递更多信息,并不代表本站赞同其观点,本站亦不保证或承诺内容真实性等。需要转载请联系该专栏作者,如若文章内容侵犯您的权益,请及时联系本站删除。
换一批
延伸阅读

西班牙塞维利亚,2024年3月12日 — Teledyne Technologies旗下公司、全球成像解决方案创新者Teledyne e2v宣布扩展其Flash™ CMOS图像传感器系列,推出Flash 2K LSA,该...

关键字: 图像传感器 Flash 摄像机

在这篇文章中,小编将为大家带来JTAG接口与Flash的相关报道。如果你对本文即将要讲解的内容存在一定兴趣,不妨继续往下阅读哦。

关键字: JTAG Flash

近日,第11届EEVIA年度中国硬科技媒体论坛暨产业链研创趋势展望研讨会在深圳召开,兆易创新Flash事业部产品市场经理张静在会上发布了主题为“持续开拓,兆易新一代存储产品助力行业创新”的演讲。

关键字: 兆易创新 Flash 闪存

随着信息技术的快速发展,存储器的需求日益增长。Flash存储器作为一种非易失性存储器,具有重要的应用价值和广泛的应用领域。本文将详细介绍Flash存储器的基本原理、工作方式和作用,帮助读者更好地了解这一重要的存储器技术。

关键字: Flash 汽车 电子设备

随着信息时代的到来,数据存储成为了一项基本需求。Flash存储器成为了一种常见的存储设备,用于存储各种类型的数据,如文档、图片、视频等。本文将详细介绍如何使用Flash存储器以及如何写入数据,帮助读者了解Flash存储器...

关键字: Flash 存储器 数据

随着科技的不断发展,Flash存储器已经成为存储设备中最常用的一种类型。它具有非易失性、高密度、低功耗和快速读写等特点,广泛应用于各种领域,如移动设备、嵌入式系统和存储芯片等。本文将介绍Flash存储器的编程设计以及一些...

关键字: 存储器 Flash 嵌入式

(全球TMT2023年7月28日讯)2023年7月28日,江波龙上海总部项目封顶仪式在中国(上海)自由贸易试验区临港新片区举行。江波龙上海总部位于临港新片区滴水湖科创总部湾核心区,项目于2021年启动建设,占地面积约1...

关键字: 存储芯片 数据中心 芯片设计 Flash

昨天下午,中国市场监管总局附加限制性条件批准了美国半导体公司迈凌(MaxLinear)对全球最大 NAND Flash 控制芯片供应商慧荣科技(SMI)的收购。

关键字: 迈凌 慧荣 芯片 NAND Flash

Flash存储器,也称为闪存存储器,是一种非易失性存储器(Non-Volatile Memory,NVM),用于在设备断电后仍然能够保持存储的数据。它的名称来源于一种称为“闪存技术”的特殊电子存储技术。Flash存储器的...

关键字: Flash 存储器 电荷贮存器

据业内信息统计数据,2023 年第一季度 NAND-Flash 存储市场的营收或将持续下滑,除了传统的淡季影响之外,还和过去两年的市场影响以及双边制裁等因素有关。据悉,NAND-Flash 存储市场去年不断下跌,最后一个...

关键字: NAND Flash 闪存 三星 美光 SK 海力士 铠侠
关闭
关闭