cancel
Showing results for 
Search instead for 
Did you mean: 

EEPROM Read/Write STM32L15x

JAN R
Associate III

Hi,

I am having a problem with using internal EEPROM memory for saving data. I can read data only from BASE adress of EEPROM. I can not write to EEPROM or read form any other place in EEPROM.

MY simple code:

#define FLASH_EEPROM_BASE     ((uint32_t)(FLASH_BASE + 0x80000U))  /*!< FLASH EEPROM base address in the alias region */
uint8_t eeprom;
/*************************************/
/* unlock EEPROM*/ 
HAL_FLASHEx_DATAEEPROM_Unlock();
/* Clear flags*/
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP|FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | FLASH_FLAG_SIZERR | FLASH_FLAG_OPTVERR );
 
/* 1)  I read from Base - it works fine*/
eeprom=*(volatile uint8_t *) FLASH_EEPROM_BASE;   //now I can read the value from eeprom correctly
 
/* 2) want to write to eeprom - fails*/
HAL_FLASHEx_DATAEEPROM_Program(FLASH_TYPEPROGRAMDATA_BYTE,FLASH_EEPROM_BASE,0x11); // now the writing values to eeprom fails
 
/* 3 ) read form another place - fails*/
eeprom=*(volatile uint8_t *) FLASH_EEPROM_BASE+7;   // I read absolutely differnet values than it should be

I use this procedure on STM32L071 and it works fine, Do not know what I make wrong here.

Thank you for help. Jan.

2 REPLIES 2

Didn't you mean

eeprom=*(volatile uint8_t *)(FLASH_EEPROM_BASE+7);

which is different from yours given operators precedence.

JW

JAN R
Associate III

you are Genius😊 !

Thanks, Jan.