8 years, 5 months ago.

NUCLEO-L053R8 EEPROM

According to the microcontroller datasheet, there is a 2KB EEPROM but there is no implemented library. How can I read or write that EEPROM?

Question relating to:

ST
A world leader in providing the semiconductor solutions that make a positive contribution to people’s lives, both today and in the future.

1 Answer

8 years, 5 months ago.

You can find the driver for accessing the EEProm in the cmsis part of the mbed-dev code. Exchange the mbed lib with the mbed-dev lib. Browse to : targets/cmsis/TARGET_STM/TARGET_STM32L0/stm32l0xx_hal_flash_ex.c. There you find code to write and erase the EEPROM.

Accepted Answer

Hi Peter! Thank you so much for answering, I found some functions to erase and program flash where you said.

You can write the EEPROM like this:

void Eeprom::writeWord(uint32_t word, uint32_t address){
    HAL_FLASHEx_DATAEEPROM_Unlock();
    HAL_FLASHEx_DATAEEPROM_Program(FLASH_TYPEPROGRAMDATA_WORD, address, word);
    HAL_FLASHEx_DATAEEPROM_Lock();
}
posted by Viviana Marcela Quirama Cañaveral 23 Jun 2016

Thanks, It was usefull on the NUCLEO L152RE.

posted by Felícito Manzano 18 Sep 2017

Someone asked me to update this post. Here is a more comprehensive example of the functions to interact with the EEPROM:

uint8_t readByte(uint32_t address)
{
    uint8_t *data = (uint8_t *)address;
    return *data;
}

uint16_t readHalfWord(uint32_t address)
{
    uint16_t *data = (uint16_t *)address;
    return *data;
}

uint32_t readWord(uint32_t address)
{
    uint32_t *data = (uint32_t *)address;
    return *data;
}

void writeByte(uint8_t byte, uint32_t address)
{
    HAL_FLASHEx_DATAEEPROM_Unlock();
    HAL_FLASHEx_DATAEEPROM_Program(FLASH_TYPEPROGRAMDATA_BYTE, address, byte);
    HAL_FLASHEx_DATAEEPROM_Lock();
}

void writeHalfWord(uint16_t halfWord, uint32_t address)
{
    HAL_FLASHEx_DATAEEPROM_Unlock();
    HAL_FLASHEx_DATAEEPROM_Program(FLASH_TYPEPROGRAMDATA_HALFWORD, address, halfWord);
    HAL_FLASHEx_DATAEEPROM_Lock();
}

void writeWord(uint32_t word, uint32_t address)
{
    HAL_FLASHEx_DATAEEPROM_Unlock();
    HAL_FLASHEx_DATAEEPROM_Program(FLASH_TYPEPROGRAMDATA_WORD, address, word);
    HAL_FLASHEx_DATAEEPROM_Lock();
}
posted by Viviana Marcela Quirama Cañaveral 17 Nov 2017