From 66374edd6deb93e51266e952b33ce5906ba4a624 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 8 Mar 2026 01:20:47 -1000 Subject: [PATCH] Fix comments: ESP8266 logging uses Serial, not ets_printf --- esphome/components/esp8266/__init__.py | 4 +++- esphome/components/esp8266/printf_stubs.cpp | 10 +++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/esphome/components/esp8266/__init__.py b/esphome/components/esp8266/__init__.py index 4892293738..1ef4f5e037 100644 --- a/esphome/components/esp8266/__init__.py +++ b/esphome/components/esp8266/__init__.py @@ -264,7 +264,9 @@ async def to_code(config): # Wrap FILE*-based printf functions to eliminate newlib's _vfiprintf_r # (~1.6 KB). See printf_stubs.cpp for implementation. - if not config.get(CONF_ENABLE_FULL_PRINTF): + if config.get(CONF_ENABLE_FULL_PRINTF): + cg.add_define("USE_FULL_PRINTF") + else: for symbol in ("vprintf", "printf", "fprintf"): cg.add_build_flag(f"-Wl,--wrap={symbol}") diff --git a/esphome/components/esp8266/printf_stubs.cpp b/esphome/components/esp8266/printf_stubs.cpp index 374c001523..4eb316d6ec 100644 --- a/esphome/components/esp8266/printf_stubs.cpp +++ b/esphome/components/esp8266/printf_stubs.cpp @@ -3,14 +3,14 @@ * * The ESP8266 Arduino framework and libraries may reference printf(), * vprintf(), and fprintf() which pull in newlib's _vfprintf_r (~900 bytes). - * ESPHome never uses these — all logging goes through ets_printf/ets_vsnprintf - * directly, so the libc FILE*-based printf path is dead code. + * ESPHome never uses these — all logging writes directly to the UART via + * Arduino's Serial, so the libc FILE*-based printf path is dead code. * * These stubs redirect through vsnprintf() (which is already in the binary * for ESPHome's logging) and fwrite(), allowing the linker to dead-code * eliminate _vfprintf_r. * - * Saves ~900 bytes of flash. + * Saves ~1.6 KB of flash. */ #if defined(USE_ESP8266) && !defined(USE_FULL_PRINTF) @@ -22,8 +22,8 @@ namespace esphome::esp8266 {} static constexpr size_t PRINTF_BUFFER_SIZE = 256; -// These stubs are essentially dead code at runtime — ESPHome uses ets_printf -// for logging, and the Arduino core's Serial.printf() has its own implementation. +// These stubs are essentially dead code at runtime — ESPHome writes directly +// to the UART via Arduino's Serial, and Serial.printf() has its own implementation. // The buffer overflow check is purely defensive and should never trigger. static int write_printf_buffer(FILE *stream, char *buf, int len) { if (len < 0) {