From 16eeaa87af604ef8ffe12a434a4e969a49071313 Mon Sep 17 00:00:00 2001 From: Simon Billemont Date: Tue, 12 Apr 2022 20:29:46 +0200 Subject: [PATCH] Fix issue with Esp8266/Esp32 platform reinitializing EEPROM multiple times causing it to forget staged EEPROM changes --- src/esp32_platform.cpp | 8 ++++++-- src/esp_platform.cpp | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/esp32_platform.cpp b/src/esp32_platform.cpp index 6f499340..46ebd204 100644 --- a/src/esp32_platform.cpp +++ b/src/esp32_platform.cpp @@ -106,8 +106,12 @@ bool Esp32Platform::sendBytesUniCast(uint32_t addr, uint16_t port, uint8_t* buff uint8_t * Esp32Platform::getEepromBuffer(uint16_t size) { - EEPROM.begin(size); - return EEPROM.getDataPtr(); + uint8_t * eepromptr = EEPROM.getDataPtr(); + if(eepromptr == nullptr) { + EEPROM.begin(KNX_FLASH_SIZE); + eepromptr = EEPROM.getDataPtr(); + } + return eepromptr; } void Esp32Platform::commitToEeprom() diff --git a/src/esp_platform.cpp b/src/esp_platform.cpp index 14a7c586..0a9e9cc8 100644 --- a/src/esp_platform.cpp +++ b/src/esp_platform.cpp @@ -106,8 +106,12 @@ bool EspPlatform::sendBytesUniCast(uint32_t addr, uint16_t port, uint8_t* buffer uint8_t * EspPlatform::getEepromBuffer(uint16_t size) { - EEPROM.begin(size); - return EEPROM.getDataPtr(); + uint8_t * eepromptr = EEPROM.getDataPtr(); + if(eepromptr == nullptr) { + EEPROM.begin(KNX_FLASH_SIZE); + eepromptr = EEPROM.getDataPtr(); + } + return eepromptr; } void EspPlatform::commitToEeprom()