2 shujianhongye feng shujianhongye_feng 于 2016.05.04 11:42 提问

stm32的flash擦除不正常

先贴代码:
U32 Flashadd;
U8 FLASH_Sector;
FLASH_Status status = FLASH_COMPLETE;
Flashadd=addr-0x8000000;

if(Flashadd<0x10000) FLASH_Sector=(U8)(Flashadd>>14);
else if(Flashadd<=0x1ffff) FLASH_Sector=4;
else if(Flashadd<=0x1fffff) FLASH_Sector=(U8) (5+((Flashadd-0x20000)>>17));
FLASH_Unlock();
FLASH_ClearFlag(FLASH_FLAG_PGSERR | FLASH_FLAG_PGPERR |   FLASH_FLAG_PGAERR | FLASH_FLAG_WRPERR |    FLASH_FLAG_OPERR | FLASH_FLAG_EOP); 
    FLASH_OB_WRPConfig(FLASH_Sector, DISABLE);
FLASH_OB_Unlock();

/* Check the parameters /
assert_param(IS_FLASH_SECTOR(FLASH_Sector));
/
Wait for last operation to be completed /
status = FLASH_WaitForLastOperation(ERASE_TIMEOUT);
FLASH_Sector=FLASH_Sector<<3;
if(status == FLASH_COMPLETE)
{
/
if the previous operation is completed, proceed to erase the sector */
FLASH->CR &= SECTOR_MASK;
FLASH->CR |= FLASH_CR_SER | FLASH_Sector;
FLASH->CR |= FLASH_CR_STRT;

/* Wait for last operation to be completed */
status = FLASH_WaitForLastOperation(ERASE_TIMEOUT);

/* if the erase operation is completed, disable the SER Bit */
FLASH->CR &= (~FLASH_CR_SER);
FLASH->CR &= SECTOR_MASK; 

}
FLASH_Lock();
/* Return the Erase Status */
return status;
运行这个函数的,我在线调试时会出现Could not stop Cortex-M device.
将改程序中的FLASH->CR |= FLASH_CR_STRT;语句屏蔽,就能进入调试,但是擦除flash不正常,不知道为什么,有哪位大虾指点迷津,小弟在此道谢。

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!