From 4bcb544bebb670a732b59f49bdbb8ed82e52620e Mon Sep 17 00:00:00 2001 From: Tomasz Duda Date: Sun, 8 Feb 2026 14:41:16 +0100 Subject: [PATCH] fix --- esphome/components/logger/logger.h | 1 + esphome/components/logger/task_log_buffer_zephyr.cpp | 4 ++-- esphome/components/logger/task_log_buffer_zephyr.h | 2 +- esphome/core/defines.h | 1 + 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/esphome/components/logger/logger.h b/esphome/components/logger/logger.h index 6e04438521e..b20f1c23b4e 100644 --- a/esphome/components/logger/logger.h +++ b/esphome/components/logger/logger.h @@ -623,6 +623,7 @@ class Logger : public Component { // - Recursion from logging within logging is the main concern // - Cross-task "recursion" is prevented by the buffer mutex anyway // - Missing a recursive call from another task is acceptable (falls back to direct output) + // // Zephyr use __thread as TLS // Check if non-main task is already in recursion diff --git a/esphome/components/logger/task_log_buffer_zephyr.cpp b/esphome/components/logger/task_log_buffer_zephyr.cpp index 77d5511f58a..8c9c5a20b09 100644 --- a/esphome/components/logger/task_log_buffer_zephyr.cpp +++ b/esphome/components/logger/task_log_buffer_zephyr.cpp @@ -6,7 +6,7 @@ namespace esphome::logger { -__thread bool non_main_task_recursion_guard_; +__thread bool non_main_task_recursion_guard_; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) static inline uint32_t get_wlen(const mpsc_pbuf_generic *item) { auto *msg = reinterpret_cast(item); @@ -68,7 +68,7 @@ bool TaskLogBufferZephyr::send_message_thread_safe(uint8_t level, const char *ta // this shall not happened vsnprintf was called already once // fill with '\n' to not call mpsc_pbuf_free from producer // it will be trimmed anyway - for (uint16_t i = 0; i < text_length; ++i) { + for (size_t i = 0; i < text_length; ++i) { text_area[i] = '\n'; } text_area[text_length] = 0; diff --git a/esphome/components/logger/task_log_buffer_zephyr.h b/esphome/components/logger/task_log_buffer_zephyr.h index 9d0993f2a0a..4a7d6ff781d 100644 --- a/esphome/components/logger/task_log_buffer_zephyr.h +++ b/esphome/components/logger/task_log_buffer_zephyr.h @@ -13,7 +13,7 @@ static constexpr size_t MAX_POINTER_REPRESENTATION = 2 + sizeof(void *) * 2 + 1; #ifdef USE_ESPHOME_TASK_LOG_BUFFER -extern __thread bool non_main_task_recursion_guard_; +extern __thread bool non_main_task_recursion_guard_; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables) class TaskLogBufferZephyr { public: diff --git a/esphome/core/defines.h b/esphome/core/defines.h index ee865a7e65a..0c888933bf0 100644 --- a/esphome/core/defines.h +++ b/esphome/core/defines.h @@ -320,6 +320,7 @@ #endif #ifdef USE_NRF52 +#define USE_ESPHOME_TASK_LOG_BUFFER #define USE_NRF52_DFU #define USE_NRF52_REG0_VOUT 5 #define USE_NRF52_UICR_ERASE