2019-11-20 01:12 AM
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;
}
2019-11-21 12:25 PM
I haven't had any issues writing to flash with the HAL library on the STM32L072. Have you tried erasing your address range before attempting to write?
2019-11-21 11:24 PM
Yes i did and it didnt work. I tried a do while loop and it is ok now. after trying several time error flag did not set but i feel like there is an other problem and i am not sure.