Skip to main content
okals.1492
Associate
November 20, 2019
Question

Writing to EEPROM of STM32L051K8?

  • November 20, 2019
  • 2 replies
  • 838 views

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;
 }

This topic has been closed for replies.

2 replies

ty.locke
Associate II
November 21, 2019

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?

okals.1492
Associate
November 22, 2019

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.