1 #include "elrs_eeprom.h"
5 #if !defined(TARGET_NATIVE)
6 #if defined(PLATFORM_STM32)
7 #if defined(TARGET_USE_EEPROM) && defined(USE_I2C)
8 #if !defined(TARGET_EEPROM_ADDR)
9 #define TARGET_EEPROM_ADDR 0x51
10 #warning "!! Using default EEPROM address (0x51) !!"
14 #include <extEEPROM.h>
15 extEEPROM
EEPROM(kbits_2
, 1, 1, TARGET_EEPROM_ADDR
);
17 #define STM32_USE_FLASH
18 #include <utility/stm32_eeprom.h>
27 #if defined(PLATFORM_STM32)
28 #if defined(STM32_USE_FLASH)
30 #else // !STM32_USE_FLASH
31 // I2C initialization is the responsibility of the caller
32 // e.g. Wire.begin(GPIO_PIN_SDA, GPIO_PIN_SCL);
34 /* Initialize EEPROM */
35 #if defined(TARGET_EEPROM_400K)
36 EEPROM
.begin(extEEPROM::twiClock400kHz
, &Wire
);
38 EEPROM
.begin(extEEPROM::twiClock100kHz
, &Wire
);
40 #endif // STM32_USE_FLASH
41 #else /* !PLATFORM_STM32 */
42 EEPROM
.begin(RESERVED_EEPROM_SIZE
);
43 #endif /* PLATFORM_STM32 */
47 ELRS_EEPROM::ReadByte(const uint32_t address
)
49 if (address
>= RESERVED_EEPROM_SIZE
)
51 // address is out of bounds
52 ERRLN("EEPROM address is out of bounds");
55 #if defined(STM32_USE_FLASH)
56 return eeprom_buffered_read_byte(address
);
58 return EEPROM
.read(address
);
63 ELRS_EEPROM::WriteByte(const uint32_t address
, const uint8_t value
)
65 if (address
>= RESERVED_EEPROM_SIZE
)
67 // address is out of bounds
68 ERRLN("EEPROM address is out of bounds");
71 #if defined(STM32_USE_FLASH)
72 eeprom_buffered_write_byte(address
, value
);
73 #elif defined(PLATFORM_STM32)
74 EEPROM
.update(address
, value
);
76 EEPROM
.write(address
, value
);
83 #if defined(PLATFORM_ESP32) || defined(PLATFORM_ESP8266)
86 ERRLN("EEPROM commit failed");
88 #elif defined(STM32_USE_FLASH)
89 eeprom_buffer_flush();
91 // PLATFORM_STM32 with external flash every byte is committed as it is written
94 #endif /* !TARGET_NATIVE */