stm32l053 eeprom

Files at this revision

API Documentation at this revision

Comitter:
lzbpli
Date:
Fri Sep 30 01:01:27 2016 +0000
Commit message:
stm32l053 eeprom read wirte erse

Changed in this revision

eeprom.cpp Show annotated file Show diff for this revision Revisions of this file
eeprom.h Show annotated file Show diff for this revision Revisions of this file
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);
+    }
+}
+
diff -r 000000000000 -r 143c9dcabcf0 eeprom.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/eeprom.h	Fri Sep 30 01:01:27 2016 +0000
@@ -0,0 +1,9 @@
+#ifndef __EEPROM_H_
+#define __EEPROM_H_
+#include "mbed.h"
+//#include "stm32l0xx_hal.h"
+
+void EEPROM_ErasePages(uint16_t startPage,uint16_t endPage);
+void EEPROM_Read(uint16_t ReadAddr,uint8_t *pBuffer,uint16_t NumToRead);
+void EEPROM_Write(uint16_t WriteAddr,uint8_t *pBuffer,uint16_t NumToWrite);
+#endif