Disable UART logging within the config.
Write your own log function with esp_log_set_vprintf.
Disable UART0 bootloader and log output
Run “idf.py menuconfig”, as explained on this page.
Bootloader config > Bootloader log verbosity
Default is “Info”, change it to “No output” to disable bootloader output
Component config > Log output > Default log verbosity
Default is “Info”, change it to “No output” to disable application output
Now when you build you’ll see all the build messages in the TERMINAL window, but none of the messages as the application runs.
Disable UART0 ROM bootloader output
Using the above config will disable everything your application sends to UART0, but it won’t stop the ROM bootloader outputting something like this on reset:
ESP-ROM:esp32s2-rc4-20191025
Build:Oct 25 2019
rst:0x1 (POWERON),boot:0x9 (SPI_FAST_FLASH_BOOT)
SPIWP:0xee
mode:DIO, clock div:1
load:0x3ffe6108,len:0x430
load:0x4004c000,len:0x860
load:0x40050000,len:0x299c
entry 0x4004c120
This is sent by the ROM bootloader to the U0TXD pin.
There is some discussion about it here.
It seems if can be suppressed on some devices by tying one of the IO pins low on reset, or by burning an eFuse (possibly UART_PRINT_CONTROL – we’ve not tried it?)
Disabling UART0 use at runtime
For a ESP32 C3:
//Release GPIO02 and 21 from console and UART0 use
esp_log_level_set("*", ESP_LOG_NONE); //DISABLE ESP32 LOGGING ON UART0
gpio_reset_pin(GPIO_NUM_20);
gpio_reset_pin(GPIO_NUM_21);
Switching between Console Log use of UART0 and something else using it
We used this code on an ESP32S2 with an Iridium modem UART connected to pins GPIO 6 & 7. We only needed to use the Iridium UART occasionally, so we switched between it and the Console Log using UART0 via the default TXD0 and RXD0 pins.
static int EnableIridiumUart = 0;
static int EnableIridiumUart_last = -1;
//WE NEED TO SWITCH UART0 BETWEN CONSOLE AND IRIDIUM
if (IridiumCurrentMode >= SM_IRIDIUM_RESET)
EnableIridiumUart = 1;
else
EnableIridiumUart = 0;
if (EnableIridiumUart_last != EnableIridiumUart)
{
EnableIridiumUart_last = EnableIridiumUart;
if (EnableIridiumUart)
{
//-------------------------------------
//----- SET UART 0 TO IRIDIUM USE -----
//-------------------------------------
//DISABLE ESP32 LOGGING ON UART0
esp_log_level_set("*", ESP_LOG_NONE);
if (uart_is_driver_installed(IRIDIUM_UART_NUM))
uart_driver_delete(IRIDIUM_UART_NUM);
//SETUP UART
//Set for Iridium Log use:
uart_config_t UartConfig0 = {
.baud_rate = 19200,
.data_bits = UART_DATA_8_BITS,
.parity = UART_PARITY_DISABLE,
.stop_bits = UART_STOP_BITS_1,
.flow_ctrl = UART_HW_FLOWCTRL_DISABLE, //UART_HW_FLOWCTRL_CTS
.source_clk = UART_SCLK_APB,
.rx_flow_ctrl_thresh = 100
};
uart_driver_install(IRIDIUM_UART_NUM, IRIDIUM_UART_RX_BUF_SIZE, 0, 0, NULL, 0);
uart_param_config(IRIDIUM_UART_NUM, &UartConfig0);
uart_set_pin(IRIDIUM_UART_NUM, 6, 7, 0, 0); //UART, TX, RX, RTS, CTS
IridiumUartEnabled = 1;
}
else
{
//----------------------------------------------
//----- SET UART 0 BACK TO CONSOLE LOG USE -----
//----------------------------------------------
IridiumUartEnabled = 0;
uart_driver_delete(UART_NUM_0);
//Set UART for Console Log use:
uart_config_t UartConfig0a = {
.baud_rate = 115200,
.data_bits = UART_DATA_8_BITS,
.parity = UART_PARITY_DISABLE,
.stop_bits = UART_STOP_BITS_1,
.flow_ctrl = UART_HW_FLOWCTRL_DISABLE, //UART_HW_FLOWCTRL_CTS
.source_clk = UART_SCLK_APB,
.rx_flow_ctrl_thresh = 100
};
uart_driver_install(UART_NUM_0, IRIDIUM_UART_RX_BUF_SIZE, 0, 0, NULL, 0);
uart_param_config(UART_NUM_0, &UartConfig0a);
uart_set_pin(UART_NUM_0, 0, 0, 0, 0); //UART, TX, RX, RTS, CTS //<<<<IS THIS RIGHT????? GPIO SET TO 0 FOR DEFAULT PINS ????? Can't find any official doc, but this seems to work fine on ESP32S2
//SET ESP32 LOGGING LEVEL
#ifdef __DEBUG
//WE ARE IN DEBUG MODE
esp_log_level_set("*", ESP_LOG_WARN); //<<<Default logging level for all tags
esp_log_level_set("ApMain", ESP_LOG_INFO);
esp_log_level_set("Messaging", ESP_LOG_INFO);
#else
//WE ARE IN RELEASE MODE
esp_log_level_set("*", ESP_LOG_ERROR); //<<<Default logging level for all tags
#endif
ESP_LOGI(TAG, "Uart0 back to console use");
}
}