Skip to content

Commit

Permalink
main/Faikin: Fix comm pollution
Browse files Browse the repository at this point in the history
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 <pavel_fedin@mail.ru>
  • Loading branch information
Sonic-Amiga committed Jun 24, 2023
1 parent 1f09a82 commit 6cb6279
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions main/Faikin.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 6cb6279

Please sign in to comment.