Help with HAL_FLASHEx_DATAEEPROM_Program() function on STM32L0
Hello all,
I have a problem with the HAL_FLASHEx_DATAEEPROM_Program() function and maybe someone can help me. I am using an stm32L073. The address range oft he EEprom ist from 0x0808 0000 to 0x0808 17FF. I tried a simple test for writing to the EEprom like the following:
HAL_FLASHEx_DATAEEPROM_Unlock();
HAL_FLASHEx_DATAEEPROM_Program(FLASH_TYPEPROGRAMDATA_WORD, 0x08080100, 0x12345678);
HAL_FLASHEx_DATAEEPROM_Lock();
This didnt work. So I start to debug. In the function HAL_FLASHEx_DATAEEPROM_Program() there is the following call:
status = FLASH_WaitForLastOperation(FLASH_TIMEOUT_VALUE);
In the function FLASH_WaitForLastOperation the program goes without timeout into the if statement if (__HAL_FLASH_GET_FLAG(FLASH_FLAG_EOP)) but the program runs also into the last if-statement and returns HAL_ERROR. I found out that the __HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR) flag is set. So I looked into the reference manuel for the stm32L073 and read the folowing:
Write protection error flag (WRPERR)
If an erase/program operation to a write-protected page of the Flash program memory and
data EEPROM is launched, the Write Protection Error flag (WRPERR) is set in the
FLASH_SR register. Consequently, the WRPERR flag is set when the software tries to:
• Write to a WRP page.
• Write to a System memory page or to factory option bytes.
• Write to the Flash program memory, data EEPROM or Option bytes if they are not
unlocked by PEKEY, PRGKEY or OPTKEY.
• Write to the Flash program memory, data EEPROM or Option bytes when the RDP
Option byte is set and the device is in debug mode or is booting from the RAM or from
the System memory.
When I out command the __HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR) everything is fine and the 0x12345678 value is written the to address 0x08080100. Do someone know why the WRPERR-Bit is set? I thought with the HAL_FLASHEx_DATAEEPROM_Unlock() call the EEprom is free for write access.
Regards
Tobias