下面的程序用来擦除一FLASH页, 但是一执行就死机, 不知原因何在, 求高手指点(芯片为STM32F103ZET)
void TestEraseFlashPage(void)
{//仅供测试
uint32_t j,flashAddr;
char *pc;
uint16_t *pu16;
flashAddr=FLASH_MY_DATA_BEG; //ERASE THIS PAGE: =0x803F000
FLASH_ClearFlag(FLASH_FLAG_BSY | FLASH_FLAG_EOP | FLASH_FLAG_PGERR | FLASH_FLAG_WRPRTERR); //Clear all pending flags
FLASH_Unlock(); //解锁以允许写FLASH
j=FLASH_ErasePage(flashAddr);
FLASH_Lock(); //重新锁定
switch(j)
{
case FLASH_BUSY:
pc="FLASH_BUSY";
break;
case FLASH_ERROR_PG:
pc="FLASH_ERROR_PG";
break;
case FLASH_ERROR_WRP:
pc="FLASH_ERROR_WRP";
break;
case FLASH_TIMEOUT:
pc="FLASH_TIMEOUT";
break;
case FLASH_COMPLETE:
pc="FLASH_COMPLETE: 成功!";
break;
default:
pc="ERASE PAGE BUG!";
}
LCD_ShowText(CMD_HZK16ASC, 0,180, pc);
//检查是否成功擦除
pu16=(uint16_t*)flashAddr;
for (j=0;j<FLASH_PAGE_SIZE/2;j++)
{
if (*pu16++!=0xFFFF) break;
}
if (j==FLASH_PAGE_SIZE/2) pc="擦除彻底成功!";
else pc="没擦干净";
LCD_ShowText(CMD_HZK16ASC, 0,200, pc);
} |