diff --git a/components/console/esp_console.h b/components/console/esp_console.h index cd7bf8155e7f..0590551abfa9 100644 --- a/components/console/esp_console.h +++ b/components/console/esp_console.h @@ -108,7 +108,7 @@ typedef struct { { \ } -#if CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG +#if CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG || CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG /** * @brief Parameters for console device: USB-SERIAL-JTAG * @@ -348,7 +348,7 @@ esp_err_t esp_console_new_repl_uart(const esp_console_dev_uart_config_t *dev_con */ esp_err_t esp_console_new_repl_usb_cdc(const esp_console_dev_usb_cdc_config_t *dev_config, const esp_console_repl_config_t *repl_config, esp_console_repl_t **ret_repl); -#if CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG +#if CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG || CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG /** * @brief Establish a console REPL (Read-eval-print loop) environment over USB-SERIAL-JTAG * diff --git a/components/console/esp_console_repl.c b/components/console/esp_console_repl.c index cb60df5452d9..29c1e0574d16 100644 --- a/components/console/esp_console_repl.c +++ b/components/console/esp_console_repl.c @@ -49,7 +49,7 @@ typedef struct { static void esp_console_repl_task(void *args); static esp_err_t esp_console_repl_uart_delete(esp_console_repl_t *repl); static esp_err_t esp_console_repl_usb_cdc_delete(esp_console_repl_t *repl); -#if CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG +#if CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG || CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG static esp_err_t esp_console_repl_usb_serial_jtag_delete(esp_console_repl_t *repl); #endif //CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG static esp_err_t esp_console_common_init(size_t max_cmdline_length, esp_console_repl_com_t *repl_com); @@ -120,7 +120,7 @@ esp_err_t esp_console_new_repl_usb_cdc(const esp_console_dev_usb_cdc_config_t *d return ret; } -#if CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG +#if CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG || CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG esp_err_t esp_console_new_repl_usb_serial_jtag(const esp_console_dev_usb_serial_jtag_config_t *dev_config, const esp_console_repl_config_t *repl_config, esp_console_repl_t **ret_repl) { esp_console_repl_universal_t *usb_serial_jtag_repl = NULL; @@ -442,7 +442,7 @@ static esp_err_t esp_console_repl_usb_cdc_delete(esp_console_repl_t *repl) return ret; } -#if CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG +#if CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG || CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG static esp_err_t esp_console_repl_usb_serial_jtag_delete(esp_console_repl_t *repl) { esp_err_t ret = ESP_OK; diff --git a/components/esp_system/Kconfig b/components/esp_system/Kconfig index 1fbb378ad2cf..4b5de33044b3 100644 --- a/components/esp_system/Kconfig +++ b/components/esp_system/Kconfig @@ -220,18 +220,23 @@ menu "ESP System Settings" - On chips with an USB serial/JTAG debug controller, selecting the option for that redirects output to the CDC/ACM (serial port emulation) component of that device. + config ESP_CONSOLE_UART_DEFAULT bool "Default: UART0" + config ESP_CONSOLE_USB_CDC bool "USB CDC" # && !TINY_USB is because the ROM CDC driver is currently incompatible with TinyUSB. depends on (IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3) && !TINY_USB + config ESP_CONSOLE_USB_SERIAL_JTAG bool "USB Serial/JTAG Controller" select ESPTOOLPY_NO_STUB if IDF_TARGET_ESP32C3 #ESPTOOL-252 depends on IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32S3 + config ESP_CONSOLE_UART_CUSTOM bool "Custom UART" + config ESP_CONSOLE_NONE bool "None" endchoice @@ -246,16 +251,26 @@ menu "ESP System Settings" non-blocking mode without using REPL. If you want to output in blocking mode with REPL or input through this secondary port, please change the primary config to this port in `Channel for console output` menu. + config ESP_CONSOLE_SECONDARY_NONE bool "No secondary console" + config ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG - bool "USB_SERIAL_JTAG PORT" + bool "USB Serial/JTAG Controller" depends on !ESP_CONSOLE_USB_SERIAL_JTAG help This option supports output through USB_SERIAL_JTAG port when the UART0 port is not connected. The output currently only supports non-blocking mode without using the console. If you want to output in blocking mode with REPL or input through USB_SERIAL_JTAG port, please change the primary config to ESP_CONSOLE_USB_SERIAL_JTAG above. + + config ESP_CONSOLE_SECONDARY_UART_DEFAULT + bool "UART0 Default" + depends on ! ESP_CONSOLE_UART_DEFAULT && ! ESP_CONSOLE_UART_CUSTOM + + config ESP_CONSOLE_SECONDARY_USB_CDC + bool "USB CDC" + depends on ! ESP_CONSOLE_USB_CDC endchoice diff --git a/components/esp_system/panic.c b/components/esp_system/panic.c index 8622a640ce71..f2582678ddd6 100644 --- a/components/esp_system/panic.c +++ b/components/esp_system/panic.c @@ -81,14 +81,25 @@ static void panic_print_char_uart(const char c) } #endif // CONFIG_ESP_CONSOLE_UART +#if CONFIG_ESP_CONSOLE_SECONDARY_UART_DEFAULT +static uart_hal_context_t s_panic_uart_secondary_default = { .dev = &UART0 }; -#if CONFIG_ESP_CONSOLE_USB_CDC -static void panic_print_char_usb_cdc(const char c) +static void panic_print_char_uart_secondary_default(const char c) +{ + uint32_t sz = 0; + while (!uart_hal_get_txfifo_len(&s_panic_uart_secondary_default)); + uart_hal_write_txfifo(&s_panic_uart_secondary_default, (uint8_t *) &c, 1, &sz); +} +#endif // CONFIG_ESP_CONSOLE_SECONDARY_UART_DEFAULT + + +#if CONFIG_ESP_CONSOLE_USB_CDC || CONFIG_ESP_CONSOLE_SECONDARY_USB_CDC +void panic_print_char_usb_cdc(const char c) { esp_usb_console_write_buf(&c, 1); /* result ignored */ } -#endif // CONFIG_ESP_CONSOLE_USB_CDC +#endif // CONFIG_ESP_CONSOLE_USB_CDC || CONFIG_ESP_CONSOLE_SECONDARY_USB_CDC #if CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG || CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG //Timeout; if there's no host listening, the txfifo won't ever @@ -110,13 +121,15 @@ static void panic_print_char_usb_serial_jtag(const char c) } #endif //CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG || CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG - void panic_print_char(const char c) { #if CONFIG_ESP_CONSOLE_UART panic_print_char_uart(c); #endif -#if CONFIG_ESP_CONSOLE_USB_CDC +#if CONFIG_ESP_CONSOLE_SECONDARY_UART_DEFAULT + panic_print_char_uart_secondary_default(c); +#endif +#if CONFIG_ESP_CONSOLE_USB_CDC || CONFIG_ESP_CONSOLE_SECONDARY_USB_CDC panic_print_char_usb_cdc(c); #endif #if CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG || CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG @@ -177,7 +190,7 @@ void esp_panic_handler_reconfigure_wdts(void) { wdt_hal_context_t wdt0_context = {.inst = WDT_MWDT0, .mwdt_dev = &TIMERG0}; #if SOC_TIMER_GROUPS >= 2 - // IDF-3825 + // IDF-3825 wdt_hal_context_t wdt1_context = {.inst = WDT_MWDT1, .mwdt_dev = &TIMERG1}; #endif diff --git a/components/vfs/vfs_console.c b/components/vfs/vfs_console.c index be10600b879a..8f9d8e59d0d0 100644 --- a/components/vfs/vfs_console.c +++ b/components/vfs/vfs_console.c @@ -40,7 +40,9 @@ const static char *primary_path = "/dev/cdcacm"; #endif // Secondary register part. -#if CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG +#if (CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG || \ + CONFIG_ESP_CONSOLE_SECONDARY_UART_DEFAULT || \ + CONFIG_ESP_CONSOLE_SECONDARY_USB_CDC) const static char *secondary_path = "/dev/secondary"; static int secondary_vfs_index; #endif // Secondary part @@ -63,6 +65,10 @@ int console_open(const char * path, int flags, int mode) // Secondary port open #if CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG vfs_console.fd_secondary = get_vfs_for_path(secondary_path)->vfs.open("/", flags, mode); +#elif CONFIG_ESP_CONSOLE_SECONDARY_UART_DEFAULT + vfs_console.fd_secondary = get_vfs_for_path(secondary_path)->vfs.open("/0", flags, mode); +#elif CONFIG_ESP_CONSOLE_SECONDARY_USB_CDC + vfs_console.fd_secondary = get_vfs_for_path(secondary_path)->vfs.open("/", flags, mode); #endif return 0; } @@ -71,7 +77,9 @@ ssize_t console_write(int fd, const void *data, size_t size) { // All function calls are to primary, except from write and close, which will be forwarded to both primary and secondary. get_vfs_for_index(primary_vfs_index)->vfs.write(vfs_console.fd_primary, data, size); -#if CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG +#if (CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG || \ + CONFIG_ESP_CONSOLE_SECONDARY_UART_DEFAULT || \ + CONFIG_ESP_CONSOLE_SECONDARY_USB_CDC) get_vfs_for_index(secondary_vfs_index)->vfs.write(vfs_console.fd_secondary, data, size); #endif return size; @@ -210,6 +218,18 @@ esp_err_t esp_vfs_console_register(void) if(err != ESP_OK) { return err; } +#elif CONFIG_ESP_CONSOLE_SECONDARY_UART_DEFAULT + const esp_vfs_t *uart_vfs = esp_vfs_uart_get_vfs(); + err = esp_vfs_register_common(secondary_path, strlen(secondary_path), uart_vfs, NULL, &secondary_vfs_index); + if(err != ESP_OK) { + return err; + } +#elif CONFIG_ESP_CONSOLE_SECONDARY_USB_CDC + const esp_vfs_t *cdcacm_vfs = esp_vfs_cdcacm_get_vfs(); + err = esp_vfs_register_common(secondary_path, strlen(secondary_path), cdcacm_vfs, NULL, &secondary_vfs_index); + if(err != ESP_OK) { + return err; + } #endif err = esp_vfs_dev_console_register(); return err;