fix(esp_log): add Kconfig to optionally bypass esp_rom_vprintf

In Log V2, ESP_LOG macros are using the runtime
constrained-environment path in esp_log_vprintf() reference
esp_rom_vprintf as the fallback formatter. On chips where ets_vprintf
is not in ROM (all targets except ESP32-S2 and ESP32-C2), this pulls
~1.2 KB of printf implementation into IRAM.

Add a new Kconfig option LOG_API_CONSTRAINED_ENV_SAFE (default y) that
controls whether this IRAM-resident fallback is used:

Also update the logging and RAM-usage documentation accordingly.

Closes https://github.com/espressif/esp-idf/issues/18346
This commit is contained in:
Guillaume Souchere
2026-04-07 12:00:51 +02:00
parent 23298ce2df
commit 0cba1db0ed
6 changed files with 72 additions and 6 deletions
+21 -1
View File
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2024-2026 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -13,6 +13,7 @@
#include "esp_log_level.h"
#include "esp_assert.h"
#include "sdkconfig.h"
#include "esp_rom_caps.h"
#ifdef __cplusplus
extern "C" {
@@ -111,6 +112,25 @@ extern "C" {
#ifndef ESP_LOG_FORMATTING_DISABLED
#define ESP_LOG_FORMATTING_DISABLED (0)
#endif
/**
* This define controls whether esp_rom_vprintf is used as the fallback print function in constrained
* environments (ISR, cache disabled, early startup). When set to 0, esp_rom_vprintf is never referenced,
* saving ~1.2 KB of IRAM on chips where it is not a true ROM function.
* ESP_DRAM_LOGx and ESP_EARLY_LOGx will use esp_rom_printf directly instead.
*
* On chips where ets_vprintf is in ROM (ESP32-S2, ESP32-C2), this is always enabled
* since there is no IRAM cost.
*/
#if BOOTLOADER_BUILD || ESP_ROM_HAS_VPRINTF_FUNC
#define ESP_LOG_API_CONSTRAINED_ENV_SAFE (1)
#else
#ifdef CONFIG_LOG_API_CONSTRAINED_ENV_SAFE
#define ESP_LOG_API_CONSTRAINED_ENV_SAFE (1)
#else
#define ESP_LOG_API_CONSTRAINED_ENV_SAFE (0)
#endif
#endif
/** @endcond */
/**