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

Dependencies:   mbed

Description in AN4061 from STM.

Changed (compared with the original code AN4061):

  • possibility of a larger size of emulated EEPROM (using multiple Flash pages)
  • dummy variables prevent overwrite code in Flash by algorithm of EEPROM emulation




Macro PAGE_NB_PVP (in eeprom.h) defines the size of the virtual page.
Eg. For F091 where Flash page are 2kB value 4 gives 8kB.

Size 8kB virtual page gives you the ability to use max. approx. 2k of 16-bit variables.

Files at this revision

API Documentation at this revision

Comitter:
mega64
Date:
Fri Sep 23 23:58:25 2016 +0000
Parent:
5:aa44afa6ca35
Commit message:
Added possibility to increase size of virtual pages of emulation

Changed in this revision

eeprom/eeprom.cpp Show annotated file Show diff for this revision Revisions of this file
eeprom/eeprom.h Show annotated file Show diff for this revision Revisions of this file
diff -r aa44afa6ca35 -r 669ff12928f9 eeprom/eeprom.cpp
--- a/eeprom/eeprom.cpp	Fri Sep 23 17:44:45 2016 +0000
+++ b/eeprom/eeprom.cpp	Fri Sep 23 23:58:25 2016 +0000
@@ -92,7 +92,7 @@
   /* Fill EraseInit structure*/
   s_eraseinit.TypeErase   = FLASH_TYPEERASE_PAGES;
   s_eraseinit.PageAddress = PAGE0_BASE_ADDRESS;
-  s_eraseinit.NbPages     = 1;
+  s_eraseinit.NbPages     = PAGE_NB_PVP;
   
   /* Check for invalid header states and repair if necessary */
   switch (pagestatus0)
@@ -179,7 +179,7 @@
         }
         s_eraseinit.TypeErase   = FLASH_TYPEERASE_PAGES;
         s_eraseinit.PageAddress = PAGE1_BASE_ADDRESS;
-        s_eraseinit.NbPages     = 1;
+        s_eraseinit.NbPages     = PAGE_NB_PVP;
         /* Erase Page1 */
         if(!EE_VerifyPageFullyErased(PAGE1_BASE_ADDRESS))
         { 
@@ -195,7 +195,7 @@
       {
         s_eraseinit.TypeErase   = FLASH_TYPEERASE_PAGES;
         s_eraseinit.PageAddress = PAGE1_BASE_ADDRESS;
-        s_eraseinit.NbPages     = 1;
+        s_eraseinit.NbPages     = PAGE_NB_PVP;
         /* Erase Page1 */
         if(!EE_VerifyPageFullyErased(PAGE1_BASE_ADDRESS))
         { 
@@ -241,7 +241,7 @@
       {
         s_eraseinit.TypeErase   = FLASH_TYPEERASE_PAGES;
         s_eraseinit.PageAddress = PAGE1_BASE_ADDRESS;
-        s_eraseinit.NbPages     = 1;
+        s_eraseinit.NbPages     = PAGE_NB_PVP;
         /* Erase Page1 */
         if(!EE_VerifyPageFullyErased(PAGE1_BASE_ADDRESS))
         { 
@@ -288,7 +288,7 @@
         }
         s_eraseinit.TypeErase   = FLASH_TYPEERASE_PAGES;
         s_eraseinit.PageAddress = PAGE0_BASE_ADDRESS;
-        s_eraseinit.NbPages     = 1;
+        s_eraseinit.NbPages     = PAGE_NB_PVP;
         /* Erase Page0 */
         if(!EE_VerifyPageFullyErased(PAGE0_BASE_ADDRESS))
         { 
@@ -466,7 +466,7 @@
 
   s_eraseinit.TypeErase   = FLASH_TYPEERASE_PAGES;
   s_eraseinit.PageAddress = PAGE0_BASE_ADDRESS;
-  s_eraseinit.NbPages     = 1;
+  s_eraseinit.NbPages     = PAGE_NB_PVP;
   /* Erase Page0 */
   if(!EE_VerifyPageFullyErased(PAGE0_BASE_ADDRESS))
   {
@@ -715,7 +715,7 @@
 
   s_eraseinit.TypeErase   = FLASH_TYPEERASE_PAGES;
   s_eraseinit.PageAddress = oldpageid;
-  s_eraseinit.NbPages     = 1;
+  s_eraseinit.NbPages     = PAGE_NB_PVP;
   
   /* Erase the old Page: Set old Page status to ERASED status */
   flashstatus = HAL_FLASHEx_Erase(&s_eraseinit, &page_error);  
diff -r aa44afa6ca35 -r 669ff12928f9 eeprom/eeprom.h
--- a/eeprom/eeprom.h	Fri Sep 23 17:44:45 2016 +0000
+++ b/eeprom/eeprom.h	Fri Sep 23 23:58:25 2016 +0000
@@ -175,8 +175,11 @@
 #define ADDR_FLASH_PAGE_126   ((uint32_t)0x0803F000) /* Base @ of Page 126, 2 Kbytes */
 #define ADDR_FLASH_PAGE_127   ((uint32_t)0x0803F800) /* Base @ of Page 127, 2 Kbytes */
 
+/* Define the number of physical pages per virtual page of algorithm*/
+#define PAGE_NB_PVP ((uint32_t) 4)
+
 /* Define the size of the sectors to be used */
-#define PAGE_SIZE               (uint32_t)FLASH_PAGE_SIZE  /* Page size */
+#define PAGE_SIZE               ((uint32_t)FLASH_PAGE_SIZE * PAGE_NB_PVP)  /* Page size */
 
 /* EEPROM start address in Flash */
 #define EEPROM_START_ADDRESS  ((uint32_t)ADDR_FLASH_PAGE_16) /* EEPROM emulation start address */
@@ -190,10 +193,10 @@
 
 /* Used Flash pages for EEPROM emulation */
 #define PAGE0                 ((uint16_t)0x0000)
-#define PAGE1                 ((uint16_t)32) /* Page nb between PAGE0_BASE_ADDRESS & PAGE1_BASE_ADDRESS*/
+#define PAGE1                 ((uint16_t)((PAGE1_BASE_ADDRESS-PAGE0_BASE_ADDRESS)/PAGE_SIZE)) /* Page nb between PAGE0_BASE_ADDRESS & PAGE1_BASE_ADDRESS*/
 
 /* No valid page define */
-#define NO_VALID_PAGE         ((uint16_t)0x00AB)
+#define NO_VALID_PAGE         ((uint16_t)0xFFFF)
 
 /* Page status definitions */
 #define ERASED                ((uint16_t)0xFFFF)     /* Page is empty */