2016-05-04 02:36 AM
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-unlock2016-05-04 10:55 AM
Hi,
The description of the issue is not clear enough .Could you please provide more details about your problem ?
Regards2018-07-26 07:58 AM
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!