Dear:
Below is the flash erase program I wrote.
void BlFlash_EraseDone( tFlashParam* flashParam, uint32 eraseValue )
{
BlFlash_RegType * FlashReg;
FlashReg = (BlFlash_RegType *)BLFLASH_REG_BASE_ADDR;
int i = 0;
/* check if flash is operating */
if (((FlashReg->C55FMC_MCR & BLFLASH_MCR_PGM_SET) == 0x00uL) &&
((FlashReg->C55FMC_MCR & BLFLASH_MCR_ERS_SET) == 0x00uL) &&
((FlashReg->C55FMC_MCR & BLFLASH_MCR_EHV_SET) == 0x00uL) )
{
/* set flash erase flag */
FlashReg->C55FMC_MCR |= BLFLASH_MCR_ERS_SET; //置起ERS位
/* unlock blocks */
BlFlash_BlockLock(~eraseValue);
/* select erased blocks */
BlFlash_BlockSelect(eraseValue); //选择FLASH块
/*interlock write*/
*((volatile uint32 *)flashParam->address) = 0xFFFFFFFFuL; //擦除操作写锁定
/* set flash voltage to high */
FlashReg->C55FMC_MCR |= BLFLASH_MCR_EHV_SET;
/* wait flash erase finish */
do{
/* watch dog task */
if (flashParam->wdTriggerFct != NULLPTR)
{
flashParam->wdTriggerFct(); //定时喂狗
}
}
while ((FlashReg->C55FMC_MCR) & (BLFLASH_MCR_DONE) == 0x0000uL);
/* check if flash operating successful */
if ((FlashReg->C55FMC_MCR & (BLFLASH_MCR_PEG)) == 0x0000uL)
{
flashParam->errorCode = kFlashFailed;
}
/*for(i = 0;i < 5000000; i++)
{
}*/
FlashReg->C55FMC_MCR &= BLFLASH_MCR_EHV_CLEAR;
/* lock all blocks */
BlFlash_BlockLock(0xFFFFFFFFuL);
}
else
{
flashParam->errorCode = kFlashFailed;
}
/*for(i = 0;i < 5000000; i++)
{
}*/
FlashReg->C55FMC_MCR &= BLFLASH_MCR_ERS_CLEAR;
return;
}
If there is no added for loop, the flash eraser program cannot complete the operation. If the for loop is added, the flash eraser program can complete the erase task.Can you tell me how to solve this problem?
Thank you very much.
Hi,
it's caused by missing parentheses. Use this:
while (((FlashReg->C55FMC_MCR) & (BLFLASH_MCR_DONE)) == 0x0000uL);
instead of this
while ((FlashReg->C55FMC_MCR) & (BLFLASH_MCR_DONE) == 0x0000uL);
I guess that you are getting also compiler warning about this.
Regards,
Lukas
hahahaha,My technical level is too low, thank you very much!!!Thank you for your help very much.