各位大侠,stm32f031g4 最后一页起始是0x08003c00,页大小1024字节;
试了4块板子,2块稳定ok,2块老是跑飞,2块跑飞的就在执行擦除指令的时候跑飞,有时候单步直线ok,全速跑飞;代码完全一样,已经关闭全局中断,执行擦除操作;
求大侠帮忙呀!
bool FlashErase(FLASH_TypeDef *pTemp, uint32_t PageAddr)
{
bool status = false;
int16_t temp = (PageAddr - FLASH_START_ADDRESS) / FLASH_PAGE_BYTES;
if((temp > 0) && (temp < FLASH_PAGES))
{
/* Unlock Flash.
*/
FlashUnlock(pTemp);
/* Enable Erase Operation.
*/
pTemp->CR |= FLASH_CR_PER;
pTemp->AR = PageAddr;
pTemp->CR |= FLASH_CR_STRT; //这个代码开始跑飞;那2个正常的,一直不跑飞;芯片代码一样
/* Waiting for Erase finish.
*/
while ((pTemp->SR & FLASH_SR_BSY) != 0);
if((pTemp->SR & FLASH_SR_EOP) != 0)
{
pTemp->SR = FLASH_SR_EOP;
status = true;
}
/* Clear Erase Operation.
*/
pTemp->CR &= ~FLASH_CR_PER;
/* Lock Flash.
*/
FlashLock(pTemp);
}
return status;
} |