2024-07-25 03:25 PM - last edited on 2024-07-26 04:16 AM by Andrew Neil
In stm32f0xx_hal_flash.c line 319:
/* Check if there are still pages to erase */
if(pFlash.DataRemaining != 0U)
{
addresstmp = pFlash.Address;
/*Indicate user which sector has been erased */
HAL_FLASH_EndOfOperationCallback(addresstmp);
/*Increment sector number*/
addresstmp = pFlash.Address + FLASH_PAGE_SIZE;
pFlash.Address = addresstmp;
/* If the erase operation is completed, disable the PER Bit */
CLEAR_BIT(FLASH->CR, FLASH_CR_PER);
FLASH_PageErase(addresstmp);
}
else
{
/* No more pages to Erase, user callback can be called. */
/* Reset Sector and stop Erase pages procedure */
pFlash.Address = addresstmp = 0xFFFFFFFFU;
pFlash.ProcedureOnGoing = FLASH_PROC_NONE;
/* FLASH EOP interrupt user callback */
HAL_FLASH_EndOfOperationCallback(addresstmp);
CLEAR_BIT(FLASH->CR, FLASH_CR_PER); // ?????????For example here???????????
}
After interrupt I expect PER bit to be cleared but it is not, because of this I can't program flash. Currently I clear this bit myself before programming flash, but is there any reason not to do it in HAL_FLASH_IRQHandler?
P.S. I spent a lot of time figuring this out. Maybe I'm not the only one.
Solved! Go to Solution.
2024-07-25 06:15 PM
It's done later on in HAL_FLASH_IRQHandler on line 407.
2024-07-25 06:15 PM
It's done later on in HAL_FLASH_IRQHandler on line 407.
2024-07-26 12:00 AM
This is indeed true. It turned out that I was locking the flash memory in the interrupt handler, and after that these bits cannot be set. That's why these lines did not work for me. Thank you.