4 #if defined(USE_ESP32_FRAMEWORK_ARDUINO) || defined(USE_ESP_IDF) 6 #endif // USE_ESP32_FRAMEWORK_ARDUINO || USE_ESP_IDF 9 #include <driver/uart.h> 11 #ifdef USE_LOGGER_USB_SERIAL_JTAG 12 #include <driver/usb_serial_jtag.h> 13 #if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 3, 0) 14 #include <esp_vfs_dev.h> 15 #include <esp_vfs_usb_serial_jtag.h> 17 #include <driver/usb_serial_jtag_vfs.h> 21 #include "freertos/FreeRTOS.h" 22 #include "esp_idf_version.h" 35 static const char *
const TAG =
"logger";
39 #ifdef USE_LOGGER_USB_SERIAL_JTAG 40 static void init_usb_serial_jtag_() {
41 setvbuf(stdin, NULL, _IONBF, 0);
43 #if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 3, 0) 45 esp_vfs_dev_usb_serial_jtag_set_rx_line_endings(ESP_LINE_ENDINGS_CR);
47 esp_vfs_dev_usb_serial_jtag_set_tx_line_endings(ESP_LINE_ENDINGS_CRLF);
50 usb_serial_jtag_vfs_set_rx_line_endings(ESP_LINE_ENDINGS_CR);
52 usb_serial_jtag_vfs_set_tx_line_endings(ESP_LINE_ENDINGS_CRLF);
56 fcntl(fileno(stdout), F_SETFL, 0);
57 fcntl(fileno(stdin), F_SETFL, 0);
59 usb_serial_jtag_driver_config_t usb_serial_jtag_config{};
60 usb_serial_jtag_config.rx_buffer_size = 512;
61 usb_serial_jtag_config.tx_buffer_size = 512;
63 esp_err_t ret = ESP_OK;
65 ret = usb_serial_jtag_driver_install(&usb_serial_jtag_config);
71 #if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 3, 0) 72 esp_vfs_usb_serial_jtag_use_driver();
74 usb_serial_jtag_vfs_use_driver();
79 void init_uart(uart_port_t uart_num, uint32_t baud_rate,
int tx_buffer_size) {
80 uart_config_t uart_config{};
81 uart_config.baud_rate = (int) baud_rate;
82 uart_config.data_bits = UART_DATA_8_BITS;
83 uart_config.parity = UART_PARITY_DISABLE;
84 uart_config.stop_bits = UART_STOP_BITS_1;
85 uart_config.flow_ctrl = UART_HW_FLOWCTRL_DISABLE;
86 #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0) 87 uart_config.source_clk = UART_SCLK_DEFAULT;
89 uart_param_config(uart_num, &uart_config);
90 const int uart_buffer_size = tx_buffer_size;
92 uart_driver_install(uart_num, uart_buffer_size, uart_buffer_size, 10,
nullptr, 0);
100 switch (this->
uart_) {
102 #if ARDUINO_USB_CDC_ON_BOOT 114 #ifdef USE_ESP32_VARIANT_ESP32 121 #ifdef USE_LOGGER_USB_CDC 124 #if ARDUINO_USB_CDC_ON_BOOT 125 Serial.setTxTimeoutMs(0);
131 #endif // USE_ARDUINO 135 switch (this->
uart_) {
144 #ifdef USE_ESP32_VARIANT_ESP32 150 #ifdef USE_LOGGER_USB_CDC 154 #ifdef USE_LOGGER_USB_SERIAL_JTAG 156 init_usb_serial_jtag_();
160 #endif // USE_ESP_IDF 164 #if defined(USE_ESP_IDF) || defined(USE_ESP32_FRAMEWORK_ARDUINO) 166 if (ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_VERBOSE) {
167 esp_log_level_set(
"*", ESP_LOG_VERBOSE);
169 #endif // USE_ESP_IDF || USE_ESP32_FRAMEWORK_ARDUINO 171 ESP_LOGI(TAG,
"Log initialized");
177 #
if defined(USE_ESP32_VARIANT_ESP32S2)
179 #elif defined(USE_ESP32_VARIANT_ESP32C3) || defined(USE_ESP32_VARIANT_ESP32C6) || defined(USE_ESP32_VARIANT_ESP32H2)
181 #elif defined(USE_ESP32_VARIANT_ESP32S3)
189 uart_write_bytes(this->
uart_num_, msg, strlen(msg));
190 uart_write_bytes(this->
uart_num_,
"\n", 1);
199 #ifdef USE_ESP32_VARIANT_ESP32 202 #ifdef USE_LOGGER_USB_CDC 205 #ifdef USE_LOGGER_USB_SERIAL_JTAG
const char * get_uart_selection_()
void init_uart(uart_port_t uart_num, uint32_t baud_rate, int tx_buffer_size)
void pre_setup()
Set up this component.
const char *const UART_SELECTIONS[]
Implementation of SPI Controller mode.
void write_msg_(const char *msg)
int HOT esp_idf_log_vprintf_(const char *format, va_list args)