📄 erase.txt
字号:
#define FLASH_START_ADDR 0x0000
#define FLASH _ADDR_UNLOCK1 0x555
#define FLASH _ADDR_UNLOCK2 0x2aa
#define FLASH _DATA_UNLOCK1 0xaaaa
#define FLASH _DATA_UNLOCK2 0x5555
#define FLASH _SETUP_ERASE 0x8080
#define FLASH _CHIP_ERASE 0x1010
#define UINT16 unsigned short
int FlashStatusDetect(UINT16 *ptr,UINT16 Data, int TimeCounter);
int Main()
{
int i;
volatile UINT16 *flashptr=(UINT16 *) FLASH _START_ADDR;
*((volatile UINT16 *) FLASH_START_ADDR+ FLASH _ADDR_UNLOCK1) =FLASH _DATA_UNLOCK1;
*((volatile UINT16 *) FLASH _START_ADDR+ FLASH _ADDR_UNLOCK2) =FLASH _DATA_UNLOCK2;
*((volatile UINT16 *) FLASH _START_ADDR+ FLASH _ADDR_UNLOCK1) =FLASH _SETUP_ERASE;
*((volatile UINT16 *) FLASH_START_ADDR+ FLASH_ADDR_UNLOCK1) =FLASH _DATA_UNLOCK1;
*((volatile UINT16 *) FLASH_START_ADDR+ FLASH_ADDR_UNLOCK2) =FLASH _DATA_UNLOCK2;
*((volatile UINT16 *) FLASH_START_ADDR+ FLASH_ADDR_UNLOCK1) =FLASH _CHIP_ERASE;
if(FlashStatusDetect((UINT16 *)flashPtr, 0xffff, 0x1000000)!=1)
printf("ERROR!");
return(0);
}
int FlashStatusDetect(UINT16 *ptr, UINT16 Data, int TimeCounter)
{
int tmp=TimeCounter;
volatile UINT16 *P=ptr;
UINT16 data1, data2,current_data;
current_data=Data & 0x8080;
while((*p& 0x8080) !=current_data)
{
if(tmp-- <=0)
return 0;
}
return 1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -