From fcb21998f81ddb7db6970ed5db51e3c358038057 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 28 Feb 2026 15:35:48 -1000 Subject: [PATCH] Guard portYIELD_FROM_ISR with USE_ESP32 LibreTiny's FreeRTOS port does not provide portYIELD_FROM_ISR. On ARM Cortex-M, FreeRTOS internally sets the PendSV bit when vTaskNotifyGiveFromISR wakes a higher-priority task, so the context switch happens automatically when the ISR returns. --- esphome/core/lwip_fast_select.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/esphome/core/lwip_fast_select.c b/esphome/core/lwip_fast_select.c index a3cc6ab8fe1..07228420316 100644 --- a/esphome/core/lwip_fast_select.c +++ b/esphome/core/lwip_fast_select.c @@ -261,7 +261,13 @@ void IRAM_ATTR esphome_lwip_wake_main_loop_any_context(void) { #endif int px_higher_priority_task_woken = 0; esphome_lwip_wake_main_loop_from_isr(&px_higher_priority_task_woken); +#ifdef USE_ESP32 + // On ESP32, explicitly request context switch if a higher-priority task was woken. + // On LibreTiny (ARM Cortex-M), portYIELD_FROM_ISR is not available — FreeRTOS + // sets the PendSV bit internally when needed, so the switch happens automatically + // when the ISR returns. portYIELD_FROM_ISR(px_higher_priority_task_woken); +#endif } else { esphome_lwip_wake_main_loop(); }