From 8c7fcacab48e8c1ad76d7ca034fc1a369160d899 Mon Sep 17 00:00:00 2001 From: Mathieu Carbou Date: Fri, 21 Mar 2025 15:40:26 +0100 Subject: [PATCH 1/5] feat(logging): Arduino log redirection --- cores/esp32/esp32-hal-uart.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cores/esp32/esp32-hal-uart.c b/cores/esp32/esp32-hal-uart.c index 75e2da013ea..ef033388067 100644 --- a/cores/esp32/esp32-hal-uart.c +++ b/cores/esp32/esp32-hal-uart.c @@ -1120,7 +1120,7 @@ int log_printfv(const char *format, va_list arg) { } #endif */ -#if (ARDUINO_USB_CDC_ON_BOOT == 1 && ARDUINO_USB_MODE == 0) || CONFIG_IDF_TARGET_ESP32C3 \ +#if ARDUINO_LOG_FORCE_ETS_PRINTF == 1 || (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); ets_printf("%s", temp); From 1744fba7a50a181706a73ce7294efc4057a1b9f5 Mon Sep 17 00:00:00 2001 From: Sugar Glider Date: Sat, 5 Apr 2025 12:15:24 -0300 Subject: [PATCH 2/5] fix(uart): log will only use ets_printf() for uart and cdc --- cores/esp32/esp32-hal-uart.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/cores/esp32/esp32-hal-uart.c b/cores/esp32/esp32-hal-uart.c index ef033388067..144cd5f11c5 100644 --- a/cores/esp32/esp32-hal-uart.c +++ b/cores/esp32/esp32-hal-uart.c @@ -1120,17 +1120,9 @@ int log_printfv(const char *format, va_list arg) { } #endif */ -#if ARDUINO_LOG_FORCE_ETS_PRINTF == 1 || (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); 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 #if !CONFIG_DISABLE_HAL_LOCKS if(s_uart_debug_nr != -1 && _uart_bus_array[s_uart_debug_nr].lock){ From aae4d76cb1869c21cf927c244475b498f45f988a Mon Sep 17 00:00:00 2001 From: Sugar Glider Date: Sat, 5 Apr 2025 12:21:59 -0300 Subject: [PATCH 3/5] feat(uart_cdc): when CDC is logging, UART is silent --- cores/esp32/HWCDC.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/cores/esp32/HWCDC.cpp b/cores/esp32/HWCDC.cpp index 170e323a035..062317d9f53 100644 --- a/cores/esp32/HWCDC.cpp +++ b/cores/esp32/HWCDC.cpp @@ -603,6 +603,7 @@ void HWCDC::setDebugOutput(bool en) { } else { 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 From f4c21ddc59c18277a09a188fcd6209d78940a1e5 Mon Sep 17 00:00:00 2001 From: Sugar Glider Date: Sat, 5 Apr 2025 12:23:15 -0300 Subject: [PATCH 4/5] feat(uart_cdc): when CDC is logging, UART is silent --- cores/esp32/USBCDC.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/cores/esp32/USBCDC.cpp b/cores/esp32/USBCDC.cpp index 945021a79e2..c7bb4582d4f 100644 --- a/cores/esp32/USBCDC.cpp +++ b/cores/esp32/USBCDC.cpp @@ -455,6 +455,7 @@ void USBCDC::setDebugOutput(bool en) { } else { ets_install_putc2(NULL); } + ets_install_putc1(NULL); // closes UART log output } USBCDC::operator bool() const { From 7360076a74e11781910a6a5023739569ed2929c7 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci-lite[bot]" <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Date: Wed, 9 Apr 2025 09:03:30 +0000 Subject: [PATCH 5/5] ci(pre-commit): Apply automatic fixes --- cores/esp32/esp32-hal-uart.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cores/esp32/esp32-hal-uart.c b/cores/esp32/esp32-hal-uart.c index 144cd5f11c5..5b48b2d868c 100644 --- a/cores/esp32/esp32-hal-uart.c +++ b/cores/esp32/esp32-hal-uart.c @@ -1112,7 +1112,7 @@ int log_printfv(const char *format, va_list arg) { return 0; } } -/* + /* // This causes dead locks with logging in specific cases and also with C++ constructors that may send logs #if !CONFIG_DISABLE_HAL_LOCKS if(s_uart_debug_nr != -1 && _uart_bus_array[s_uart_debug_nr].lock){ @@ -1122,7 +1122,7 @@ int log_printfv(const char *format, va_list arg) { */ vsnprintf(temp, len + 1, format, arg); ets_printf("%s", temp); -/* + /* // This causes dead locks with logging and also with constructors that may send logs #if !CONFIG_DISABLE_HAL_LOCKS if(s_uart_debug_nr != -1 && _uart_bus_array[s_uart_debug_nr].lock){