Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
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:
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.
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(); }
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(); }