From 8b606e1fbe8e196651d9197f2da3a2634e398b06 Mon Sep 17 00:00:00 2001 From: Paul Kendall Date: Thu, 13 Jun 2024 09:26:29 +1200 Subject: [PATCH] Use empty sector before the FS partition for 8266 power-on-counter (#2755) --- src/lib/CONFIG/config.cpp | 47 +++++++++++++++++++++++++++++++++++++++ src/lib/CONFIG/config.h | 4 ++++ src/src/rx_main.cpp | 2 +- 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/src/lib/CONFIG/config.cpp b/src/lib/CONFIG/config.cpp index fd12505f77..db50319249 100644 --- a/src/lib/CONFIG/config.cpp +++ b/src/lib/CONFIG/config.cpp @@ -689,6 +689,10 @@ TxConfig::SetModelId(uint8_t modelId) #if defined(TARGET_RX) +#if defined(PLATFORM_ESP8266) +#include "flash_hal.h" +#endif + RxConfig::RxConfig() { } @@ -918,9 +922,38 @@ bool RxConfig::GetIsBound() const return !m_config.volatileBind && UID_IS_BOUND(m_config.uid); } +#if defined(PLATFORM_ESP8266) +#define EMPTY_SECTOR ((FS_start - 0x1000 - 0x40200000) / SPI_FLASH_SEC_SIZE) // empty sector before FS area start +static bool erase_power_on_count = false; +static int realPowerOnCounter = -1; +uint8_t +RxConfig::GetPowerOnCounter() const +{ + if (realPowerOnCounter == -1) { + byte zeros[16]; + ESP.flashRead(EMPTY_SECTOR * SPI_FLASH_SEC_SIZE, zeros, sizeof(zeros)); + realPowerOnCounter = sizeof(zeros); + for (int i=0 ; i=3, enter binding, the counter will be reset after 2s - else if (config.GetPowerOnCounter() >= 3) + else if (!InBindingMode && config.GetPowerOnCounter() >= 3) { #if defined(PLATFORM_ESP32) || defined(PLATFORM_ESP8266) // Never enter wifi if forced to binding mode