Writing to EEPROM of STM32L051K8?
I am trying to flash a data to `EEPROM` of `STM32L051K8` with HAL library. This functions keeps returning `HAL_ERROR`. With debug i found the problem.
In HAL Flash library before writing data to `EEPROM` it checks for error flags with `FLASH_WaitForLastOperation` and `FLASH_FLAG_WRPERR`(write protection error flag) is set. So it returns `HAL_ERROR` but `HAL_FLASHEx_DATAEEPROM_Unlock` returns `HAL_OK`.
HAL_StatusTypeDef setCommAddressState(void){
HAL_StatusTypeDef status;
status = HAL_FLASHEx_DATAEEPROM_Unlock();
if (status != HAL_ERROR)
{
status = HAL_FLASHEx_DATAEEPROM_Program(FLASH_TYPEPROGRAMDATA_BYTE, COM_ADDRESS_STATE_ADDRESS, comAddressStateData);
if (status == HAL_OK){
comAddressState = comAddressStateData;
}
}
HAL_FLASHEx_DATAEEPROM_Lock();
return status;
}