日本黄色一级经典视频|伊人久久精品视频|亚洲黄色色周成人视频九九九|av免费网址黄色小短片|黄色Av无码亚洲成年人|亚洲1区2区3区无码|真人黄片免费观看|无码一级小说欧美日免费三级|日韩中文字幕91在线看|精品久久久无码中文字幕边打电话

當前位置:首頁 > 單片機 > 單片機
[導讀] 1,目的 在實際的產品發(fā)布中,如果不對儲存在單片機Flash中的程序做一些保護的話,就有可能被一些不法公司,通過仿真器(J-Link,ST-Link等)把Flash中的程序讀取回來,得到bin文件或hex文件,然后去山

1,目的

在實際的產品發(fā)布中,如果不對儲存在單片機Flash中的程序做一些保護的話,就有可能被一些不法公司,通過仿真器(J-Link,ST-Link等)把Flash中的程序讀取回來,得到bin文件或hex文件,然后去山寨產品。所以我們需要對程序進行保護,一種比較簡單可靠的方法就是把Flash設置成讀保護。


2,開發(fā)環(huán)境

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);

}


本站聲明: 本文章由作者或相關機構授權發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點,本站亦不保證或承諾內容真實性等。需要轉載請聯系該專欄作者,如若文章內容侵犯您的權益,請及時聯系本站刪除( 郵箱:macysun@21ic.com )。
換一批
延伸閱讀
關閉