KugleFirmware/Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_flash.c
/**
  * @brief This function handles FLASH interrupt request.
  * @retval None
  */
@brief This function handles FLASH interrupt request.
@retval None
@brief This function handles FLASH interrupt request . @retval None
void HAL_FLASH_IRQHandler(void)
{
  uint32_t temp;
  if(__HAL_FLASH_GET_FLAG_BANK1(FLASH_SR_EOP) != RESET)
  {
    if(pFlash.ProcedureOnGoing == FLASH_PROC_SECTERASE_BANK1)
    {
      pFlash.NbSectorsToErase--;
      if(pFlash.NbSectorsToErase != 0)
      {
        temp = pFlash.Sector;
        HAL_FLASH_EndOfOperationCallback(temp);
        __HAL_FLASH_CLEAR_FLAG_BANK1(FLASH_FLAG_EOP_BANK1 | FLASH_FLAG_ALL_ERRORS_BANK1);  
        temp = ++pFlash.Sector;
        FLASH_Erase_Sector(temp, FLASH_BANK_1, pFlash.VoltageForErase);
      }
      else
      {
        pFlash.Sector = temp = 0xFFFFFFFF;
        pFlash.ProcedureOnGoing = FLASH_PROC_NONE;
        HAL_FLASH_EndOfOperationCallback(temp);
        __HAL_FLASH_CLEAR_FLAG_BANK1(FLASH_FLAG_EOP_BANK1);
      }
    }
    else 
    {
      if((pFlash.ProcedureOnGoing == FLASH_PROC_MASSERASE_BANK1) || (pFlash.ProcedureOnGoing == FLASH_PROC_ALLBANK_MASSERASE))
      {
        HAL_FLASH_EndOfOperationCallback(FLASH_BANK_1);
      }
      else if(pFlash.ProcedureOnGoing == FLASH_PROC_PROGRAM_BANK1)
      {
        HAL_FLASH_EndOfOperationCallback(pFlash.Address);
      }
      if((pFlash.ProcedureOnGoing != FLASH_PROC_SECTERASE_BANK2) && \
         (pFlash.ProcedureOnGoing != FLASH_PROC_MASSERASE_BANK2)&& \
         (pFlash.ProcedureOnGoing != FLASH_PROC_PROGRAM_BANK2))
      {
        pFlash.ProcedureOnGoing = FLASH_PROC_NONE;
        __HAL_FLASH_CLEAR_FLAG_BANK1(FLASH_FLAG_EOP_BANK1);
      }
    }
  }
  if(__HAL_FLASH_GET_FLAG_BANK2(FLASH_SR_EOP) != RESET)
  {
    if(pFlash.ProcedureOnGoing == FLASH_PROC_SECTERASE_BANK2)
    {
      pFlash.NbSectorsToErase--;
      if(pFlash.NbSectorsToErase != 0)
      {
        temp = pFlash.Sector;
        HAL_FLASH_EndOfOperationCallback(temp);
        __HAL_FLASH_CLEAR_FLAG_BANK2(FLASH_FLAG_EOP_BANK2 | FLASH_FLAG_ALL_ERRORS_BANK2);  
        temp = ++pFlash.Sector;
        FLASH_Erase_Sector(temp, FLASH_BANK_2 , pFlash.VoltageForErase);
      }
      else
      {
        pFlash.Sector = temp = 0xFFFFFFFF;
        pFlash.ProcedureOnGoing = FLASH_PROC_NONE;
        HAL_FLASH_EndOfOperationCallback(temp);
        __HAL_FLASH_CLEAR_FLAG_BANK2(FLASH_FLAG_EOP_BANK2);
      }
    }
    else 
    {
      if((pFlash.ProcedureOnGoing == FLASH_PROC_MASSERASE_BANK2) || (pFlash.ProcedureOnGoing == FLASH_PROC_ALLBANK_MASSERASE))
      {
        HAL_FLASH_EndOfOperationCallback(FLASH_BANK_2);
      }
      else
      {
        HAL_FLASH_EndOfOperationCallback(pFlash.Address);
      }
      if((pFlash.ProcedureOnGoing != FLASH_PROC_SECTERASE_BANK1) && \
          (pFlash.ProcedureOnGoing != FLASH_PROC_MASSERASE_BANK1)&& \
          (pFlash.ProcedureOnGoing != FLASH_PROC_PROGRAM_BANK1))
      {
        pFlash.ProcedureOnGoing = FLASH_PROC_NONE;
        __HAL_FLASH_CLEAR_FLAG_BANK2(FLASH_FLAG_EOP_BANK2);
      }
    }
  }
  if(__HAL_FLASH_GET_FLAG_BANK1((FLASH_FLAG_EOP_BANK1    | FLASH_FLAG_WRPERR_BANK1 | FLASH_FLAG_PGSERR_BANK1 | \
                                 FLASH_FLAG_STRBER_BANK1R | FLASH_FLAG_INCERR_BANK1 | FLASH_FLAG_OPERR_BANK1)) != RESET)
  {
    if(pFlash.ProcedureOnGoing == FLASH_PROC_SECTERASE_BANK1)
    {
      temp = pFlash.Sector;
      pFlash.Sector = 0xFFFFFFFF;
    }
    else if((pFlash.ProcedureOnGoing == FLASH_PROC_MASSERASE_BANK1) || (pFlash.ProcedureOnGoing == FLASH_PROC_ALLBANK_MASSERASE))
    {
      temp = FLASH_BANK_1;
    }
    else
    {
      temp = pFlash.Address;
    }
    FLASH_SetErrorCode(FLASH_BANK_1);
    HAL_FLASH_OperationErrorCallback(temp);
    __HAL_FLASH_CLEAR_FLAG_BANK1((FLASH_FLAG_EOP_BANK1    | FLASH_FLAG_WRPERR_BANK1 | FLASH_FLAG_PGSERR_BANK1 | \
                                  FLASH_FLAG_STRBER_BANK1R | FLASH_FLAG_INCERR_BANK1 | FLASH_FLAG_OPERR_BANK1));
    pFlash.ProcedureOnGoing = FLASH_PROC_NONE;
  }
  if(__HAL_FLASH_GET_FLAG_BANK2((FLASH_FLAG_EOP_BANK2    | FLASH_FLAG_WRPERR_BANK2 | FLASH_FLAG_PGSERR_BANK2 | \
                                 FLASH_FLAG_STRBER_BANK2R | FLASH_FLAG_INCERR_BANK2 | FLASH_FLAG_OPERR_BANK2)) != RESET)
  {
    if(pFlash.ProcedureOnGoing == FLASH_PROC_SECTERASE_BANK2)
    {
      temp = pFlash.Sector;
      pFlash.Sector = 0xFFFFFFFF;
    }
    else if((pFlash.ProcedureOnGoing == FLASH_PROC_MASSERASE_BANK2) || (pFlash.ProcedureOnGoing == FLASH_PROC_ALLBANK_MASSERASE))
    {
      temp = FLASH_BANK_2;
    }
    else
    {
      temp = pFlash.Address;
    }
    FLASH_SetErrorCode(FLASH_BANK_2);
    HAL_FLASH_OperationErrorCallback(temp);
    __HAL_FLASH_CLEAR_FLAG_BANK2((FLASH_FLAG_EOP_BANK2    | FLASH_FLAG_WRPERR_BANK2 | FLASH_FLAG_PGSERR_BANK2 | \
                                  FLASH_FLAG_STRBER_BANK2R | FLASH_FLAG_INCERR_BANK2 |   FLASH_FLAG_OPERR_BANK2));
    pFlash.ProcedureOnGoing = FLASH_PROC_NONE;
  }  
  if(pFlash.ProcedureOnGoing == FLASH_PROC_NONE)
  {
    __HAL_FLASH_DISABLE_IT_BANK1(FLASH_IT_EOP_BANK1    | FLASH_IT_WRPERR_BANK1 | FLASH_IT_PGSERR_BANK1 | \
                                 FLASH_IT_STRBERR_BANK1 | FLASH_IT_INCERR_BANK1 | FLASH_IT_OPERR_BANK1);
    __HAL_FLASH_DISABLE_IT_BANK2(FLASH_IT_EOP_BANK2    | FLASH_IT_WRPERR_BANK2 | FLASH_IT_PGSERR_BANK2 | \
                                 FLASH_IT_STRBERR_BANK2 | FLASH_IT_INCERR_BANK2 | FLASH_IT_OPERR_BANK2); 
    __HAL_UNLOCK(&pFlash);
  }
}
void HAL_FLASH_IRQHandler ( void ) { uint32_t temp ; if ( __HAL_FLASH_GET_FLAG_BANK1 ( FLASH_SR_EOP ) != RESET ) { if ( pFlash . ProcedureOnGoing == FLASH_PROC_SECTERASE_BANK1 ) { pFlash . NbSectorsToErase -- ; if ( pFlash . NbSectorsToErase != 0 ) { temp = pFlash . Sector ; HAL_FLASH_EndOfOperationCallback ( temp ) ; __HAL_FLASH_CLEAR_FLAG_BANK1 ( FLASH_FLAG_EOP_BANK1 | FLASH_FLAG_ALL_ERRORS_BANK1 ) ; temp = ++ pFlash . Sector ; FLASH_Erase_Sector ( temp , FLASH_BANK_1 , pFlash . VoltageForErase ) ; } else { pFlash . Sector = temp = 0xFFFFFFFF ; pFlash . ProcedureOnGoing = FLASH_PROC_NONE ; HAL_FLASH_EndOfOperationCallback ( temp ) ; __HAL_FLASH_CLEAR_FLAG_BANK1 ( FLASH_FLAG_EOP_BANK1 ) ; } } else { if ( ( pFlash . ProcedureOnGoing == FLASH_PROC_MASSERASE_BANK1 ) || ( pFlash . ProcedureOnGoing == FLASH_PROC_ALLBANK_MASSERASE ) ) { HAL_FLASH_EndOfOperationCallback ( FLASH_BANK_1 ) ; } else if ( pFlash . ProcedureOnGoing == FLASH_PROC_PROGRAM_BANK1 ) { HAL_FLASH_EndOfOperationCallback ( pFlash . Address ) ; } if ( ( pFlash . ProcedureOnGoing != FLASH_PROC_SECTERASE_BANK2 ) && ( pFlash . ProcedureOnGoing != FLASH_PROC_MASSERASE_BANK2 ) && ( pFlash . ProcedureOnGoing != FLASH_PROC_PROGRAM_BANK2 ) ) { pFlash . ProcedureOnGoing = FLASH_PROC_NONE ; __HAL_FLASH_CLEAR_FLAG_BANK1 ( FLASH_FLAG_EOP_BANK1 ) ; } } } if ( __HAL_FLASH_GET_FLAG_BANK2 ( FLASH_SR_EOP ) != RESET ) { if ( pFlash . ProcedureOnGoing == FLASH_PROC_SECTERASE_BANK2 ) { pFlash . NbSectorsToErase -- ; if ( pFlash . NbSectorsToErase != 0 ) { temp = pFlash . Sector ; HAL_FLASH_EndOfOperationCallback ( temp ) ; __HAL_FLASH_CLEAR_FLAG_BANK2 ( FLASH_FLAG_EOP_BANK2 | FLASH_FLAG_ALL_ERRORS_BANK2 ) ; temp = ++ pFlash . Sector ; FLASH_Erase_Sector ( temp , FLASH_BANK_2 , pFlash . VoltageForErase ) ; } else { pFlash . Sector = temp = 0xFFFFFFFF ; pFlash . ProcedureOnGoing = FLASH_PROC_NONE ; HAL_FLASH_EndOfOperationCallback ( temp ) ; __HAL_FLASH_CLEAR_FLAG_BANK2 ( FLASH_FLAG_EOP_BANK2 ) ; } } else { if ( ( pFlash . ProcedureOnGoing == FLASH_PROC_MASSERASE_BANK2 ) || ( pFlash . ProcedureOnGoing == FLASH_PROC_ALLBANK_MASSERASE ) ) { HAL_FLASH_EndOfOperationCallback ( FLASH_BANK_2 ) ; } else { HAL_FLASH_EndOfOperationCallback ( pFlash . Address ) ; } if ( ( pFlash . ProcedureOnGoing != FLASH_PROC_SECTERASE_BANK1 ) && ( pFlash . ProcedureOnGoing != FLASH_PROC_MASSERASE_BANK1 ) && ( pFlash . ProcedureOnGoing != FLASH_PROC_PROGRAM_BANK1 ) ) { pFlash . ProcedureOnGoing = FLASH_PROC_NONE ; __HAL_FLASH_CLEAR_FLAG_BANK2 ( FLASH_FLAG_EOP_BANK2 ) ; } } } if ( __HAL_FLASH_GET_FLAG_BANK1 ( ( FLASH_FLAG_EOP_BANK1 | FLASH_FLAG_WRPERR_BANK1 | FLASH_FLAG_PGSERR_BANK1 | FLASH_FLAG_STRBER_BANK1R | FLASH_FLAG_INCERR_BANK1 | FLASH_FLAG_OPERR_BANK1 ) ) != RESET ) { if ( pFlash . ProcedureOnGoing == FLASH_PROC_SECTERASE_BANK1 ) { temp = pFlash . Sector ; pFlash . Sector = 0xFFFFFFFF ; } else if ( ( pFlash . ProcedureOnGoing == FLASH_PROC_MASSERASE_BANK1 ) || ( pFlash . ProcedureOnGoing == FLASH_PROC_ALLBANK_MASSERASE ) ) { temp = FLASH_BANK_1 ; } else { temp = pFlash . Address ; } FLASH_SetErrorCode ( FLASH_BANK_1 ) ; HAL_FLASH_OperationErrorCallback ( temp ) ; __HAL_FLASH_CLEAR_FLAG_BANK1 ( ( FLASH_FLAG_EOP_BANK1 | FLASH_FLAG_WRPERR_BANK1 | FLASH_FLAG_PGSERR_BANK1 | FLASH_FLAG_STRBER_BANK1R | FLASH_FLAG_INCERR_BANK1 | FLASH_FLAG_OPERR_BANK1 ) ) ; pFlash . ProcedureOnGoing = FLASH_PROC_NONE ; } if ( __HAL_FLASH_GET_FLAG_BANK2 ( ( FLASH_FLAG_EOP_BANK2 | FLASH_FLAG_WRPERR_BANK2 | FLASH_FLAG_PGSERR_BANK2 | FLASH_FLAG_STRBER_BANK2R | FLASH_FLAG_INCERR_BANK2 | FLASH_FLAG_OPERR_BANK2 ) ) != RESET ) { if ( pFlash . ProcedureOnGoing == FLASH_PROC_SECTERASE_BANK2 ) { temp = pFlash . Sector ; pFlash . Sector = 0xFFFFFFFF ; } else if ( ( pFlash . ProcedureOnGoing == FLASH_PROC_MASSERASE_BANK2 ) || ( pFlash . ProcedureOnGoing == FLASH_PROC_ALLBANK_MASSERASE ) ) { temp = FLASH_BANK_2 ; } else { temp = pFlash . Address ; } FLASH_SetErrorCode ( FLASH_BANK_2 ) ; HAL_FLASH_OperationErrorCallback ( temp ) ; __HAL_FLASH_CLEAR_FLAG_BANK2 ( ( FLASH_FLAG_EOP_BANK2 | FLASH_FLAG_WRPERR_BANK2 | FLASH_FLAG_PGSERR_BANK2 | FLASH_FLAG_STRBER_BANK2R | FLASH_FLAG_INCERR_BANK2 | FLASH_FLAG_OPERR_BANK2 ) ) ; pFlash . ProcedureOnGoing = FLASH_PROC_NONE ; } if ( pFlash . ProcedureOnGoing == FLASH_PROC_NONE ) { __HAL_FLASH_DISABLE_IT_BANK1 ( FLASH_IT_EOP_BANK1 | FLASH_IT_WRPERR_BANK1 | FLASH_IT_PGSERR_BANK1 | FLASH_IT_STRBERR_BANK1 | FLASH_IT_INCERR_BANK1 | FLASH_IT_OPERR_BANK1 ) ; __HAL_FLASH_DISABLE_IT_BANK2 ( FLASH_IT_EOP_BANK2 | FLASH_IT_WRPERR_BANK2 | FLASH_IT_PGSERR_BANK2 | FLASH_IT_STRBERR_BANK2 | FLASH_IT_INCERR_BANK2 | FLASH_IT_OPERR_BANK2 ) ; __HAL_UNLOCK ( & pFlash ) ; } }
@brief This function handles FLASH interrupt request.
@brief This function handles FLASH interrupt request .
/* Check FLASH Bank1 End of Operation flag  */ /*Nb of sector to erased can be decreased*/ /* Check if there are still sectors to erase*/ /*Indicate user which sector has been erased*/ /* Clear pending flags (if any) */ /* Clear bank 1 pending flags (if any) */ /*Increment sector number*/ /*pFlash.Bank*/ /*No more sectors to Erase, user callback can be called.*/ /*Reset Sector and stop Erase sectors procedure*/ /* FLASH EOP interrupt user callback */ /* Clear FLASH End of Operation pending bit */ /*MassErase ended. Return the selected bank*/ /* FLASH EOP interrupt user callback */ /*Program ended. Return the selected address*/ /* FLASH EOP interrupt user callback */ /* Clear FLASH End of Operation pending bit */ /* Check FLASH Bank2 End of Operation flag  */ /*Nb of sector to erased can be decreased*/ /* Check if there are still sectors to erase*/ /*Indicate user which sector has been erased*/ /* Clear pending flags (if any) */ /* Clear bank 2 pending flags (if any) */ /*Increment sector number*/ /*pFlash.Bank*/ /*No more sectors to Erase, user callback can be called.*/ /*Reset Sector and stop Erase sectors procedure*/ /* FLASH EOP interrupt user callback */ /* Clear FLASH End of Operation pending bit */ /*MassErase ended. Return the selected bank*/ /* FLASH EOP interrupt user callback */ /*Program ended. Return the selected address*/ /* FLASH EOP interrupt user callback */ /* Clear FLASH End of Operation pending bit */ /* Check FLASH Bank1 operation error flags */ /*return the faulty sector*/ /*return the faulty bank*/ /*return the faulty address*/ /*Save the Error code*/ /* FLASH error interrupt user callback */ /* Clear FLASH error pending bits */ /*Stop the procedure ongoing*/ /* Check FLASH Bank2 operation error flags */ /*return the faulty sector*/ /*return the faulty bank*/ /*return the faulty address*/ /*Save the Error code*/ /* FLASH error interrupt user callback */ /* Clear FLASH error pending bits */ /*Stop the procedure ongoing*/ /* Disable Bank1 Operation and Error source interrupt */ /* Disable Bank2 Operation and Error source interrupt */ /* Process Unlocked */