Skip to main content
Visitor II
April 15, 2020
Question

EEPROM on STM8L001

  • April 15, 2020
  • 1 reply
  • 645 views

Hello

I wonder if there is some example code available on how to use the Data EEPROM in the 8pin STM8L001J3.

I did successfully work with the internal Data EEPROM on the STM8L051, but no success on the SO8. The address I used is 0x9BFB (in contrast to 0x1000 on the STM8L051). There is no error when debugging the code in ST Visual Develop/Cosmic, but the content of the bytes I want to alter does not change.

Best regards

Thomas

    This topic has been closed for replies.

    1 reply

    AmampondoAuthor
    Visitor II
    April 20, 2020

    TO WHOM IT MAY CONCERN:

    Unlike all official examples show and all documentation implies, it is needed to address the Data EEPROM as if it was Program EEPROM. Hence the following code works:

    // Do this once, e.g. after power-up:

    FLASH_DeInit();

    FLASH_SetProgrammingTime(FLASH_ProgramTime_Standard);

    // Do this for each write access

    // Unlock the Flash

    FLASH_Unlock(FLASH_MemType_Program);

    // copied from FLASH_ProgramWord: "Enable Word Write Once"

    FLASH->CR2 |= FLASH_CR2_WPRG;

    // Do what you need, e.g.

    FLASH_ProgramByte(EEPROMSTARTADDR,  "yourDataByte");

    // ...

    // Finalize

    FLASH_Lock(FLASH_MemType_Program);

    "EEPROMSTARTADDR" in my case is #defined as 0x9FC0

    Best regards

    Thomas