fix(ota): bypass 64KB flash block erase, increase WDT timeouts, and place encoder table in DRAM
All checks were successful
ESP32 Build & Release / build (push) Successful in 1m11s

This commit is contained in:
2026-09-12 15:52:12 +02:00
parent c3bc42fe94
commit 6b8e8f3e8d
5 changed files with 40 additions and 2 deletions

View File

@@ -11,6 +11,7 @@
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_log.h"
#include "esp_attr.h"
#include "driver/gpio.h"
#include "hw_pins.h"
#include "encoder.h"
@@ -41,8 +42,11 @@ static volatile int8_t s_steps_per_detent = 4; /* 4 = full-step, 2 = half-step *
*
* All bounces (e.g. 11 <-> 01) cancel out: +1 + (-1) = 0.
* Invalid diagonal skips (00 <-> 11, 01 <-> 10): 0.
*
* Placed in DRAM_ATTR so reading it during flash erase (when cache is disabled)
* does not trigger a Cache Disabled DoubleException.
*/
static const int8_t s_quad_table[16] = {
static const DRAM_ATTR int8_t s_quad_table[16] = {
[0] = 0,
[1] = -1, // 00 -> 01 (CCW)
[2] = 1, // 00 -> 10 (CW)

View File

@@ -23,6 +23,7 @@
#include "nvs.h"
#include "cJSON.h"
#include "wifi_manager.h"
#include "rfid_manager.h"
#include "ota_manager.h"
static const char *TAG = "ota";
@@ -488,6 +489,7 @@ static void ota_download_task(void *arg)
set_state(OTA_STATUS_DOWNLOADING, "Starting download...");
ESP_LOGI(TAG, "Starting HTTPS OTA from: %s", s_release.download_url);
rfid_manager_pause(true);
esp_http_client_config_t http_cfg = {
.url = s_release.download_url,
@@ -506,6 +508,7 @@ static void ota_download_task(void *arg)
esp_https_ota_handle_t ota_handle = NULL;
esp_err_t err = esp_https_ota_begin(&ota_cfg, &ota_handle);
if (err != ESP_OK || ota_handle == NULL) {
rfid_manager_pause(false);
wifi_manager_release_net_lock();
ESP_LOGE(TAG, "esp_https_ota_begin failed: %s", esp_err_to_name(err));
set_state(OTA_STATUS_FAILED, "Failed to connect to image");
@@ -521,6 +524,7 @@ static void ota_download_task(void *arg)
if (memcmp(new_app_info.app_elf_sha256, running->app_elf_sha256, sizeof(new_app_info.app_elf_sha256)) == 0) {
ESP_LOGW(TAG, "Incoming image has identical ELF SHA-256 as running app - aborting flash write");
esp_https_ota_abort(ota_handle);
rfid_manager_pause(false);
wifi_manager_release_net_lock();
set_state(OTA_STATUS_UP_TO_DATE, "Firmware is already up to date");
s_ota_task_handle = NULL;
@@ -533,6 +537,7 @@ static void ota_download_task(void *arg)
if (s_cancel_requested) {
ESP_LOGW(TAG, "OTA canceled by user");
esp_https_ota_abort(ota_handle);
rfid_manager_pause(false);
wifi_manager_release_net_lock();
set_state(OTA_STATUS_IDLE, "Update canceled");
s_ota_task_handle = NULL;
@@ -553,6 +558,8 @@ static void ota_download_task(void *arg)
vTaskDelay(pdMS_TO_TICKS(10));
}
rfid_manager_pause(false);
if (err == ESP_OK) {
if (esp_https_ota_is_complete_data_received(ota_handle)) {
esp_err_t finish_err = esp_https_ota_finish(ota_handle);

View File

@@ -196,3 +196,17 @@ void rfid_manager_consume_card(void)
{
s_pending_card = false;
}
void rfid_manager_pause(bool pause)
{
TaskHandle_t task = xTaskGetHandle(RC522_TASK_NAME);
if (task != NULL) {
if (pause) {
vTaskSuspend(task);
ESP_LOGI(TAG, "RFID polling suspended");
} else {
vTaskResume(task);
ESP_LOGI(TAG, "RFID polling resumed");
}
}
}

View File

@@ -44,6 +44,11 @@ bool rfid_manager_has_pending_card(void);
*/
void rfid_manager_consume_card(void);
/**
* @brief Pause or resume RFID polling task (e.g. during OTA flash write).
*/
void rfid_manager_pause(bool pause);
#ifdef __cplusplus
}
#endif

View File

@@ -27,8 +27,16 @@ CONFIG_JD_SZBUF=512
CONFIG_JD_FORMAT_RGB565=y
CONFIG_JD_FASTDECODE_32BIT=y
# Flash Chip Driver Optimization
# Flash Chip Driver Optimization (Boya & Winbond)
CONFIG_SPI_FLASH_SUPPORT_BOYA_CHIP=y
CONFIG_SPI_FLASH_BYPASS_BLOCK_ERASE=y
CONFIG_SPI_FLASH_YIELD_DURING_ERASE=y
CONFIG_SPI_FLASH_ERASE_YIELD_DURATION_MS=20
CONFIG_SPI_FLASH_ERASE_YIELD_TICKS=2
# Watchdog Timeouts for Flash Erase & OTA Operations
CONFIG_ESP_INT_WDT_TIMEOUT_MS=1000
CONFIG_ESP_TASK_WDT_TIMEOUT_S=15
# mbedTLS Dynamic Buffers & Memory Optimization (Vital for ESP32 without PSRAM)
CONFIG_MBEDTLS_DYNAMIC_BUFFER=y