Skip to main content
JAN R
Associate III
October 8, 2018
Question

EEPROM Read/Write STM32L15x

  • October 8, 2018
  • 2 replies
  • 607 views

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.

    This topic has been closed for replies.

    2 replies

    waclawek.jan
    Super User
    October 8, 2018

    Didn't you mean

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

    which is different from yours given operators precedence.

    JW

    JAN R
    JAN RAuthor
    Associate III
    October 8, 2018

    you are Genius:smiling_face_with_smiling_eyes: !

    Thanks, Jan.