AnsweredAssumed Answered

Bug in HAL_FLASHEx_DATAEEPROM_Unlock() - file stm32l1xx_hal_flash_ex.c v1.1.3

Question asked by Carretti_Mambrini.An on May 4, 2016
Latest reply on May 4, 2016 by ForumSTM32.ForumSTM3
Function returns HAL_ERR if PELOCK bit in PECR is already unlocked, so in my code I changed it into this:

HAL_StatusTypeDef HAL_FLASHEx_DATAEEPROM_Unlock(void)
{
    if (READ_BIT((*FLASH).PECR, FLASH_PECR_PELOCK))
    {
    //  Unlocking the Data memory and FLASH_PECR register access
        (*FLASH).PEKEYR = FLASH_PEKEY1;
        (*FLASH).PEKEYR = FLASH_PEKEY2;

        if (READ_BIT((*FLASH).PECR, FLASH_PECR_PELOCK))
            return HAL_ERROR;
    }

    return HAL_OK;
}

Outcomes