1 #include "elrs_eeprom.h"
5 #if defined(PLATFORM_STM32)
6 #if defined(TARGET_USE_EEPROM) && \
7 defined(GPIO_PIN_SDA) && (GPIO_PIN_SDA != UNDEF_PIN) && \
8 defined(GPIO_PIN_SCL) && (GPIO_PIN_SCL != UNDEF_PIN)
9 #if !defined(TARGET_EEPROM_ADDR)
10 #define TARGET_EEPROM_ADDR 0x51
11 #warning "!! Using default EEPROM address (0x51) !!"
15 #include <extEEPROM.h>
16 extEEPROM
EEPROM(kbits_2
, 1, 1, TARGET_EEPROM_ADDR
);
18 #define STM32_USE_FLASH
19 #include <utility/stm32_eeprom.h>
28 #if defined(PLATFORM_STM32)
29 #if defined(STM32_USE_FLASH)
31 #else // !STM32_USE_FLASH
33 Wire
.setSDA(GPIO_PIN_SDA
);
34 Wire
.setSCL(GPIO_PIN_SCL
);
36 /* Initialize EEPROM */
37 #if defined(TARGET_EEPROM_400K)
38 EEPROM
.begin(extEEPROM::twiClock400kHz
, &Wire
);
40 EEPROM
.begin(extEEPROM::twiClock100kHz
, &Wire
);
42 #endif // STM32_USE_FLASH
43 #else /* !PLATFORM_STM32 */
44 EEPROM
.begin(RESERVED_EEPROM_SIZE
);
45 #endif /* PLATFORM_STM32 */
49 ELRS_EEPROM::ReadByte(const uint32_t address
)
51 if (address
>= RESERVED_EEPROM_SIZE
)
53 // address is out of bounds
54 ERRLN("EEPROM address is out of bounds");
57 #if defined(STM32_USE_FLASH)
58 return eeprom_buffered_read_byte(address
);
60 return EEPROM
.read(address
);
65 ELRS_EEPROM::WriteByte(const uint32_t address
, const uint8_t value
)
67 if (address
>= RESERVED_EEPROM_SIZE
)
69 // address is out of bounds
70 ERRLN("EEPROM address is out of bounds");
73 #if defined(STM32_USE_FLASH)
74 eeprom_buffered_write_byte(address
, value
);
75 #elif defined(PLATFORM_STM32)
76 EEPROM
.update(address
, value
);
78 EEPROM
.write(address
, value
);
85 #if defined(PLATFORM_ESP32) || defined(PLATFORM_ESP8266)
88 ERRLN("EEPROM commit failed");
90 #elif defined(STM32_USE_FLASH)
91 eeprom_buffer_flush();