Skip to main content
marcogrossi89
Associate III
November 18, 2014
Question

STM32 internal EEPROM

  • November 18, 2014
  • 5 replies
  • 4496 views
Posted on November 18, 2014 at 10:02

I am using the STM32l Discovery board (http://uk.farnell.com/stmicroelectronics/stm32l152c-disco/stm32l-discovery-eval-board/dp/2317987). The ucontroller on the board (STM32L152RB) features 4kB of EEPROM at the address 0x08080000 that can be used for non-volatile data storage.

I was trying to read/write/erase such memory using the pheripheral library stm32l1xx_flash.c

My questions are:

1) In the header file stm32l1xx_flash.h all the supported functions are listed. There are functions to unlock/lock the memory, write byte/word, erase byte/word. However there are no functions to read a byte/word. What is the code to read a byte/word at a particular address in the range 0x08080000 - 0x08080FFF?

2) Before making a write operation on a byte/word, is it necessary to erase that byte/word before?

Thanks.
    This topic has been closed for replies.

    5 replies

    chen
    Associate II
    November 18, 2014
    Posted on November 18, 2014 at 10:15

    Hi

    ''The ucontroller on the board (STM32L152RB) features 4kB of EEPROM at the address 0x08080000''

    No it does not.

    It is probably a EEPROM emulation in Flash.

    '' However there are no functions to read a byte/word. What is the code to read a byte/word at a particular address in the range 0x08080000 - 0x08080FFF?''

    It is probably EEPROM emulation in Flash.

    You can just read the memory locations.

    ''2) Before making a write operation on a byte/word, is it necessary to erase that byte/word before?''

    It is probably EEPROM emulation in Flash.

    Either the EEPROM emulation takes care of this for you OR

    You must erase the whole Flash sector before writing to it.

    ivani
    Visitor II
    November 18, 2014
    Posted on November 18, 2014 at 10:47

    1) The EEPROM of L1xx devices resides in the address space of the chip, so the reading operation is straight-forward - you either map some const values in this address range and read them directly, or use something like:

    unsigned int var;

    var = *(unsigned int *)0x08080000;

    2) For L1 EEPROM there is automatic erase operation for the word, which is written to. You could write word, half-word, or byte directly without worrying if the word was erased before it. However, there is a limitation that you can't write 0x00000000 on some Cat. devices. If you need to write zero the only way to do it is to erase the word (0x00000000 is the erase state of the memory in this family).

    chen
    Associate II
    November 18, 2014
    Posted on November 18, 2014 at 11:42

    Hi

    I take it back. The STM32L152RB does have built in EEPROM.

    Only just noticed it in the key features list.

    I did not think ST did any ARMs with EEPROM.

    Sorry, my mistake.

    kevinliao
    Associate II
    June 26, 2015
    Posted on June 26, 2015 at 04:36

    Would you please tell me how to write data into the internal EEPROM of stm32L152?

    Thank you for answer.

    Tesla DeLorean
    Guru
    June 26, 2015
    Posted on June 26, 2015 at 05:39

    Review the example code

    STM32L1xx_StdPeriph_Lib_V1.3.0\Project\STM32L1xx_StdPeriph_Examples\FLASH\Data_Program\main.c

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..