Skip to main content
Visitor II
July 25, 2024
Solved

STM32f0. No FLASH_CR_PER clear after erasing flash in HAL_FLASH_IRQHandler ?

  • July 25, 2024
  • 2 replies
  • 1073 views

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.

    This topic has been closed for replies.

    2 replies

    TDKAnswer
    Super User
    July 26, 2024
    July 26, 2024

    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.