Koduino
eeprom_stm32.h
1 
19 #ifndef eeprom_stm32_h
20 #define eeprom_stm32_h
21 
22 #include <stdint.h>
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
33 #if defined(SERIES_STM32F37x)
34  #define PAGE_SIZE (uint16_t)0x800 // 2K
35  #define EEPROM_START_ADDRESS ((uint32_t)0x08010000) // total = 256K, eeprom after 64K
36 #elif defined(SERIES_STM32F30x)
37  #define PAGE_SIZE (uint16_t)0x800 // 2K
38  #define EEPROM_START_ADDRESS ((uint32_t)(0x08000000 + MAX_PROGRAM_SIZE)) // specified in boards.txt (end of flash - 2*page size)
39 #elif defined(STM32F40_41xxx) || defined(STM32F411xE)
40 
41  // EEPROM moved to first two 128k sectors (slowest place for it)
42  // #define PAGE_SIZE (uint32_t) 0x20000 // 128K
43  // #define EEPROM_START_ADDRESS ((uint32_t)0x08020000)
44  // #define PAGE0_ID FLASH_Sector_5
45  // #define PAGE1_ID FLASH_Sector_6
46 
47  // Original EEPROM location (good sectors, but can interfere if program is big)
48  // #define PAGE_SIZE (uint16_t)0x4000 // 16K
49  // #define EEPROM_START_ADDRESS ((uint32_t)0x08008000) // total = 1M, eeprom after 16K
50  // #define PAGE0_ID FLASH_Sector_2
51  // #define PAGE1_ID FLASH_Sector_3
52 
53  // EEPROM in 'flash hole' that the linker skips, best solution
54  #define PAGE_SIZE (uint16_t)0x4000 // 16K
55  #define EEPROM_START_ADDRESS ((uint32_t)0x08004000) // total = 1M, eeprom after 16K
56  #define PAGE0_ID FLASH_Sector_1
57  #define PAGE1_ID FLASH_Sector_2
58  // Device voltage range supposed to be [2.7V to 3.6V], the operation will be done by word
59  #define VOLTAGE_RANGE (uint8_t)VoltageRange_3
60 #endif
61 
62 
63 // From ST =======================================================================
64 
65 /* Pages 0 and 1 base and end addresses */
66 #define PAGE0_BASE_ADDRESS ((uint32_t)(EEPROM_START_ADDRESS + 0x000))
67 #define PAGE0_END_ADDRESS ((uint32_t)(EEPROM_START_ADDRESS + (PAGE_SIZE - 1)))
68 
69 #define PAGE1_BASE_ADDRESS ((uint32_t)(EEPROM_START_ADDRESS + PAGE_SIZE))
70 #define PAGE1_END_ADDRESS ((uint32_t)(EEPROM_START_ADDRESS + (2 * PAGE_SIZE - 1)))
71 
72 /* Used Flash pages for EEPROM emulation */
73 #define PAGE0 ((uint16_t)0x0000)
74 #define PAGE1 ((uint16_t)0x0001)
75 
76 /* No valid page define */
77 #define NO_VALID_PAGE ((uint16_t)0x00AB)
78 
79 /* Page status definitions */
80 #define ERASED ((uint16_t)0xFFFF) /* PAGE is empty */
81 #define RECEIVE_DATA ((uint16_t)0xEEEE) /* PAGE is marked to receive data */
82 #define VALID_PAGE ((uint16_t)0x0000) /* PAGE containing valid data */
83 
84 /* Valid pages in read and write defines */
85 #define READ_FROM_VALID_PAGE ((uint8_t)0x00)
86 #define WRITE_IN_VALID_PAGE ((uint8_t)0x01)
87 
88 /* Page full define */
89 #define PAGE_FULL ((uint8_t)0x80)
90 
91 uint16_t EE_Init(void);
92 uint16_t EE_ReadVariable(uint16_t VirtAddress, uint16_t* Data);
93 uint16_t EE_WriteVariable(uint16_t VirtAddress, uint16_t Data);
94 
95 #ifdef __cplusplus
96 }
97 #endif
98 
99 #endif
100