simple test EEPROM emulation (STM algorithm described in the application notes: AN4061, AN3969, AN2594, AN3390, AN4056) for STM32F091
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.
Diff: eeprom/eeprom.h
- Revision:
- 6:669ff12928f9
- Parent:
- 3:a51a1737b55d
--- 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 */