simple test EEPROM emulation for STM32F401 (STM algorithm described in the application notes: AN4061, AN3969, AN2594, AN3390, AN4056).

Dependencies:   mbed

https://developer.mbed.org/questions/69101/Is-there-a-way-to-store-variables-in-a-n/#answer10369?compage=1#c24579



Versions for microcontrollers with smaller flash pages (using several flash pages for each virtual page):

Import program00_eeprom_emulation_f030

EEPROM emulation (STM algorithm described in the application notes: AN4061, AN3969, AN2594, AN3390, AN4056) with added multipage possibility. For Nucleo-F030 and others boards with similar microcontrolers.



Import program00_eeprom_emulation_f091

simple test EEPROM emulation (STM algorithm described in the application notes: AN4061, AN3969, AN2594, AN3390, AN4056) for STM32F091

Files at this revision

API Documentation at this revision

Comitter:
mega64
Date:
Tue Sep 27 20:36:44 2016 +0000
Parent:
0:1756c3542c95
Commit message:
bug fix in EE_VerifyPageFullyErased

Changed in this revision

eeprom/eeprom.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 1756c3542c95 -r bc0ee9ad46aa eeprom/eeprom.cpp
--- a/eeprom/eeprom.cpp	Thu Sep 22 03:54:18 2016 +0000
+++ b/eeprom/eeprom.cpp	Tue Sep 27 20:36:44 2016 +0000
@@ -47,9 +47,10 @@
 /* Private macro -------------------------------------------------------------*/
 /* Private variables ---------------------------------------------------------*/
 
-/* Dummy variable to protect eeprom pages if code size is bigger than 32kb (F401) 
+/* Dummy variables to protect eeprom pages if code size is bigger than 32kb (F401) 
 needed in Mbed online compiler to avoid conflict with linker (N.S.) */
-const uint8_t Eeprom_area[2 * PAGE_SIZE] __attribute__((at(EEPROM_START_ADDRESS),used))={ [0 ... (2 * PAGE_SIZE-1)] = 0xFF };
+const uint8_t Eeprom_area0[PAGE_SIZE] __attribute__((at(PAGE0_BASE_ADDRESS),used))={ [0 ... (PAGE_SIZE-1)] = 0xFF };
+const uint8_t Eeprom_area1[PAGE_SIZE] __attribute__((at(PAGE1_BASE_ADDRESS),used))={ [0 ... (PAGE_SIZE-1)] = 0xFF };
 
 
 /* Global variable used to store variable value in read sequence */
@@ -328,21 +329,32 @@
   */
 uint16_t EE_VerifyPageFullyErased(uint32_t Address)
 {
-  uint32_t ReadStatus = 1;
-  uint16_t AddressValue = 0x5555;
+  uint32_t readstatus = 1;
+  uint16_t addressvalue = 0x5555;
+  uint32_t end_address;
+  
+  if (PAGE0_BASE_ADDRESS==Address)
+  {
+    end_address = PAGE0_END_ADDRESS;
+  }
+  else
+  {
+    end_address = PAGE1_END_ADDRESS;
+  };
+  
     
   /* Check each active page address starting from end */
-  while (Address <= PAGE0_END_ADDRESS)
+  while (Address <= end_address)
   {
     /* Get the current location content to be compared with virtual address */
-    AddressValue = (*(__IO uint16_t*)Address);
+    addressvalue = (*(__IO uint16_t*)Address);
 
     /* Compare the read address with the virtual address */
-    if (AddressValue != ERASED)
+    if (addressvalue != ERASED)
     {
       
-      /* In case variable value is read, reset ReadStatus flag */
-      ReadStatus = 0;
+      /* In case variable value is read, reset readstatus flag */
+      readstatus = 0;
 
       break;
     }
@@ -350,8 +362,8 @@
     Address = Address + 4;
   }
   
-  /* Return ReadStatus value: (0: Page not erased, 1: Sector erased) */
-  return ReadStatus;
+  /* Return readstatus value: (0: Page not erased, 1: Page erased) */
+  return readstatus;
 }
 
 /**