Why error = FLASH->SR is set and block erasing flash memory?
In my code i try to delete a flash mem page using
if(HAL_FLASHEx_Erase(&FlashErase,&PageError) != HAL_OK)but always got an HAL_ERROR because in this function (which is called in HAL_FLASHEx_Erase...)
HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout)
{
uint32_t error;
uint32_t tickstart = HAL_GetTick();
/* Wait for the FLASH operation to complete by polling on BUSY flag to be reset.
Even if the FLASH operation fails, the BUSY flag will be reset and an error
flag will be set */
while (__HAL_FLASH_GET_FLAG(FLASH_FLAG_BSY))
{
if ((HAL_GetTick() - tickstart) >= Timeout)
{
return HAL_TIMEOUT;
}
}
/* check flash errors. Only ECC correction can be checeked here as ECCD
generates NMI */
error = FLASH->SR;
/* Check FLASH End of Operation flag */
if ((error & FLASH_FLAG_EOP) != 0U)
{
/* Clear FLASH End of Operation pending bit */
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP);
}
/* Now update error variable to only error value */
error &= FLASH_FLAG_SR_ERROR;
/* Update error with ECC error value */
error |= (FLASH->ECCR & FLASH_FLAG_ECCC);
/* clear error flags */
__HAL_FLASH_CLEAR_FLAG(error);
if (error != 0U)
{
/*Save the error code*/
pFlash.ErrorCode = error;
return HAL_ERROR;
}
/* Wait for control register to be written */
while (__HAL_FLASH_GET_FLAG(FLASH_FLAG_CFGBSY))
{
if ((HAL_GetTick() - tickstart) >= Timeout)
{
return HAL_TIMEOUT;
}
}error = FLASH->SR sets error to 0x8000.
In the datasheet this part is marked as reserved so why FLASH-SR sets this error bit and blocks the erase process?
Thank you all for your comments!