From 6cb627953f8cf8645e6b84aac071e745c7eade86 Mon Sep 17 00:00:00 2001 From: Pavel Fedin Date: Sat, 24 Jun 2023 16:19:38 +0300 Subject: [PATCH] main/Faikin: Fix comm pollution Make sure all the output is sent out before proceeding. Shut off also boot console, which is for some strange reason used by wi-fi blob Signed-off-by: Pavel Fedin --- main/Faikin.c | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/main/Faikin.c b/main/Faikin.c index 00505ab6..b6067b8a 100644 --- a/main/Faikin.c +++ b/main/Faikin.c @@ -1757,21 +1757,37 @@ int faikin_log_putc(int c) { return c; } +// !!! GROSS HACK !!! +// For some strange reason wifi code, which is only available in a prebuilt .a form, +// uses ets_printf() for its logging. This causes wifi logs to bypass regular +// filtering and be sent directly to the UART no matter what. From ets_printf.c +// source code the only legitimate way to stop it is to define +// CONFIG_ESP_CONSOLE_UART_NONE, which would kill all the logs completely. +// Fortunately Espressif guys have come accross this problem themselves in a +// different scenario, so they implemented this internal flag as a stopgap. +// It's normally manipulated by code in spi_flash. +// This solution also equires CONFIG_ETS_PRINTF_EXIT_WHEN_FLASH_RW to work. +#ifndef CONFIG_ETS_PRINTF_EXIT_WHEN_FLASH_RW +#warning CONFIG_ETS_PRINTF_EXIT_WHEN_FLASH_RW is not set, UART clash is possible! +#endif +extern uint8_t FlashIsOnGoing; + void uart_setup (void) { esp_err_t err = 0; if (!protocol_set) s21 = 1 - s21; // Flip ESP_LOGI (TAG, "Starting UART%s", s21 ? " S21" : ""); -// Shut off console log if it is using our UART -#if defined(CONFIG_ESP_CONSOLE_UART_DEFAULT) || defined(CONFIG_ESP_CONSOLE_UART_CUSTOM_NUM_0) - if (uart == UART_NUM_0) - esp_log_set_putchar(faikin_log_putc); -#endif -#if defined(CONFIG_ESP_CONSOLE_UART_CUSTOM_NUM_1) - if (uart == UART_NUM_1) + // Shut off console log if it is using our UART + if (uart == CONFIG_ESP_CONSOLE_UART_NUM) { + FlashIsOnGoing = 1; + // Wait for previously emitted log text to reach its destination + // fflush(stdout) doesn't do the job + uart_wait_tx_done(uart, 1000 / portTICK_PERIOD_MS); + // Only after this we switch the output, otherwise we lose the final line. + // Apparently stdout does tons of buffering together with the UART driver esp_log_set_putchar(faikin_log_putc); -#endif + } uart_config_t uart_config = { .baud_rate = s21 ? 2400 : 9600, .data_bits = UART_DATA_8_BITS,