stm32l053 eeprom
Diff: eeprom.cpp
- Revision:
- 0:143c9dcabcf0
diff -r 000000000000 -r 143c9dcabcf0 eeprom.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/eeprom.cpp Fri Sep 30 01:01:27 2016 +0000 @@ -0,0 +1,32 @@ +#include "eeprom.h" + +void EEPROM_Write(uint16_t WriteAddr,uint8_t *pBuffer,uint16_t NumToWrite) +{ + uint16_t t; + HAL_FLASHEx_DATAEEPROM_Unlock(); + for(t = 0;t < NumToWrite;t++) + { + HAL_FLASHEx_DATAEEPROM_Program(FLASH_TYPEPROGRAMDATA_BYTE,DATA_EEPROM_BASE + WriteAddr + t,*(pBuffer + t)); + } + HAL_FLASHEx_DATAEEPROM_Unlock(); +} + +//PageRange 0-511 +void EEPROM_ErasePages(uint16_t startPage,uint16_t endPage) +{ + uint16_t t; + for(t = startPage ;t <= endPage;t++) + { + HAL_FLASHEx_DATAEEPROM_Erase(DATA_EEPROM_BASE + t*4); + } +} + +void EEPROM_Read(uint16_t ReadAddr,uint8_t *pBuffer,uint16_t NumToRead) +{ + uint16_t t; + for(t = ReadAddr;t < NumToRead ;t++) + { + *(pBuffer + t) = *(uint8_t*)(DATA_EEPROM_BASE + ReadAddr + t); + } +} +