feat(logging): Arduino log redirection (#11159)

* feat(logging): Arduino log redirection

* fix(uart): log will only use ets_printf() for uart and cdc

* feat(uart_cdc): when CDC is logging, UART is silent

* feat(uart_cdc): when CDC is logging, UART is silent

* ci(pre-commit): Apply automatic fixes

---------

Co-authored-by: Sugar Glider <rodrigo.garcia@espressif.com>
Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
This commit is contained in:
Mathieu Carbou 2025-04-14 11:08:33 +02:00 committed by GitHub
parent 3fcc316d3c
commit 60c8206ee6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 3 additions and 9 deletions

View file

@ -603,6 +603,7 @@ void HWCDC::setDebugOutput(bool en) {
} else { } else {
ets_install_putc2(NULL); ets_install_putc2(NULL);
} }
ets_install_putc1(NULL); // closes UART log output
} }
#if ARDUINO_USB_MODE && ARDUINO_USB_CDC_ON_BOOT // Hardware JTAG CDC selected #if ARDUINO_USB_MODE && ARDUINO_USB_CDC_ON_BOOT // Hardware JTAG CDC selected

View file

@ -455,6 +455,7 @@ void USBCDC::setDebugOutput(bool en) {
} else { } else {
ets_install_putc2(NULL); ets_install_putc2(NULL);
} }
ets_install_putc1(NULL); // closes UART log output
} }
USBCDC::operator bool() const { USBCDC::operator bool() const {

View file

@ -1194,16 +1194,8 @@ int log_printfv(const char *format, va_list arg) {
} }
#endif #endif
*/ */
#if (ARDUINO_USB_CDC_ON_BOOT == 1 && ARDUINO_USB_MODE == 0) || CONFIG_IDF_TARGET_ESP32C3 \
|| ((CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32P4) && ARDUINO_USB_CDC_ON_BOOT == 1)
vsnprintf(temp, len + 1, format, arg); vsnprintf(temp, len + 1, format, arg);
ets_printf("%s", temp); ets_printf("%s", temp);
#else
int wlen = vsnprintf(temp, len + 1, format, arg);
for (int i = 0; i < wlen; i++) {
ets_write_char_uart(temp[i]);
}
#endif
/* /*
// This causes dead locks with logging and also with constructors that may send logs // This causes dead locks with logging and also with constructors that may send logs
#if !CONFIG_DISABLE_HAL_LOCKS #if !CONFIG_DISABLE_HAL_LOCKS