cancel
Showing results for 
Search instead for 
Did you mean: 

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

elKarro
Associate III
Posted on May 04, 2016 at 11:36

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;

}

#stm32l1xx-eeprom-unlock
MCU speaks VHDL and CPU speaks assembly. Neither of them speaks HAL.
2 REPLIES 2
slimen
Senior
Posted on May 04, 2016 at 19:55

Hi,

The description of the issue is not clear enough .

Could you please provide more details about your problem ?

Regards

roger2
Associate

I just stumbled across this same error in the stm32l0xx_hal_flash_ex module, and it's related to behavior in the stm32l0xx_hal_flash module:

HAL_FLASH_Unlock() clears the PECR_PELOCK bit, as it must before it can clear the PECR_PRGLOCK bit. However, HAL_FLASH_LOCK() does not set the PECR_PELOCK bit, only the PECR_PRGLOCK bit. As a result, after writing to program flash memory any subsequent call to HAL_FLASHEx_DATAEEPROM_Unlock() will fail.

I believe the correct solution is for HAL_FLASH_Lock() to set the PECR_PELOCK bit. I'm making this change in my own code, but ST please fix this!