页擦除与全片擦除,一般在烧录前会对芯片进行部分擦除或者全片擦除,这个根据需求来调取函数,具体分析大家可以参考FLASH相关的寄存器。 FLASH_Status FLASH_ErasePage(uint32_t Page_Address)
{
FLASH_Status status = FLASH_COMPLETE;
status = FLASH_WaitForLastOperation(EraseTimeout);
if(status == FLASH_COMPLETE)
{
FLASH->CTLR|= CR_PER_Set;
FLASH->ADDR = Page_Address;
FLASH->CTLR|= CR_STRT_Set;
status = FLASH_WaitForLastOperation(EraseTimeout);
FLASH->CTLR &= CR_PER_Reset;
}
*(__IO uint32_t*)0x40022034 = *(__IO uint32_t*)((Page_Address & 0xFFFFFFFC) ^ 0x00001000);
return status;
}
FLASH_Status FLASH_EraseAllPages(void)
{
FLASH_Status status = FLASH_COMPLETE;
status = FLASH_WaitForLastOperation(EraseTimeout);
if(status == FLASH_COMPLETE)
{
FLASH->CTLR |= CR_MER_Set;
FLASH->CTLR |= CR_STRT_Set;
status = FLASH_WaitForLastOperation(EraseTimeout);
FLASH->CTLR &= CR_MER_Reset;
}
return status;
}
|