From c18c10f51dce7e7582eb19cbb053822c68596850 Mon Sep 17 00:00:00 2001 From: Guillaume Souchere Date: Wed, 1 Jul 2026 14:39:02 +0200 Subject: [PATCH] feat(console): Add linux support for console examples --- examples/system/console/.build-test-rules.yml | 4 +- .../advanced/components/cmd_nvs/cmd_nvs.c | 4 +- .../components/cmd_system/cmd_system_common.c | 10 ++- .../console/advanced/main/CMakeLists.txt | 3 +- .../console/advanced/main/console_settings.c | 72 ++----------------- 5 files changed, 18 insertions(+), 75 deletions(-) diff --git a/examples/system/console/.build-test-rules.yml b/examples/system/console/.build-test-rules.yml index fea468f6f4e..f87c89880c7 100644 --- a/examples/system/console/.build-test-rules.yml +++ b/examples/system/console/.build-test-rules.yml @@ -1,6 +1,6 @@ examples/system/console/advanced: disable_test: - - if: IDF_TARGET not in ["esp32", "esp32c3"] # IDF-9120 and IDF-9133 + - if: IDF_TARGET not in ["esp32", "esp32c3", "linux"] # IDF-9120 and IDF-9133 reason: Sufficient to run this app on one chip with each architecture depends_components: - *common_components @@ -13,7 +13,7 @@ examples/system/console/advanced: examples/system/console/basic: disable_test: - - if: IDF_TARGET not in ["esp32", "esp32c3"] + - if: IDF_TARGET not in ["esp32", "esp32c3", "linux"] reason: Sufficient to run this app on one chip with each architecture depends_components: - *common_components diff --git a/examples/system/console/advanced/components/cmd_nvs/cmd_nvs.c b/examples/system/console/advanced/components/cmd_nvs/cmd_nvs.c index 5451008b18d..815f83e0fd2 100644 --- a/examples/system/console/advanced/components/cmd_nvs/cmd_nvs.c +++ b/examples/system/console/advanced/components/cmd_nvs/cmd_nvs.c @@ -302,12 +302,12 @@ static esp_err_t get_value_from_nvs(const char *key, const char *str_type) } else if (type == NVS_TYPE_I64) { int64_t value; if ((err = nvs_get_i64(nvs, key, &value)) == ESP_OK) { - printf("%lld\n", value); + printf("%"PRId64"\n", value); } } else if (type == NVS_TYPE_U64) { uint64_t value; if ( (err = nvs_get_u64(nvs, key, &value)) == ESP_OK) { - printf("%llu\n", value); + printf("%"PRIu64"\n", value); } } else if (type == NVS_TYPE_STR) { size_t len; diff --git a/examples/system/console/advanced/components/cmd_system/cmd_system_common.c b/examples/system/console/advanced/components/cmd_system/cmd_system_common.c index ca1fb17a728..e97d7f8808a 100644 --- a/examples/system/console/advanced/components/cmd_system/cmd_system_common.c +++ b/examples/system/console/advanced/components/cmd_system/cmd_system_common.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2023-2026 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -20,6 +20,8 @@ #include "esp_console.h" #include "esp_chip_info.h" #include "esp_flash.h" +#include "esp_idf_version.h" +#include "esp_system.h" #include "argtable3/argtable3.h" #include "freertos/FreeRTOS.h" #include "freertos/task.h" @@ -35,7 +37,9 @@ static const char *TAG = "cmd_system_common"; static void register_free(void); static void register_heap(void); static void register_version(void); +#ifndef CONFIG_IDF_TARGET_LINUX static void register_restart(void); +#endif #if WITH_TASKS_INFO static void register_tasks(void); #endif @@ -46,7 +50,9 @@ void register_system_common(void) register_free(); register_heap(); register_version(); +#ifndef CONFIG_IDF_TARGET_LINUX register_restart(); +#endif #if WITH_TASKS_INFO register_tasks(); #endif @@ -121,6 +127,7 @@ static void register_version(void) ESP_ERROR_CHECK( esp_console_cmd_register(&cmd) ); } +#ifndef CONFIG_IDF_TARGET_LINUX /** 'restart' command restarts the program */ static int restart(int argc, char **argv) @@ -139,6 +146,7 @@ static void register_restart(void) }; ESP_ERROR_CHECK( esp_console_cmd_register(&cmd) ); } +#endif // !CONFIG_IDF_TARGET_LINUX /** 'free' command prints available heap memory */ diff --git a/examples/system/console/advanced/main/CMakeLists.txt b/examples/system/console/advanced/main/CMakeLists.txt index 925ae435e9f..23325f38322 100644 --- a/examples/system/console/advanced/main/CMakeLists.txt +++ b/examples/system/console/advanced/main/CMakeLists.txt @@ -1,4 +1,3 @@ idf_component_register(SRCS "console_example_main.c" "console_settings.c" - PRIV_REQUIRES console esp_driver_uart fatfs esp_driver_usb_serial_jtag - esp_usb_cdc_rom_console nvs_flash cmd_system cmd_wifi cmd_nvs + PRIV_REQUIRES console fatfs nvs_flash cmd_system cmd_wifi cmd_nvs esp_stdio INCLUDE_DIRS ".") diff --git a/examples/system/console/advanced/main/console_settings.c b/examples/system/console/advanced/main/console_settings.c index 29c3beeba31..70e47217203 100644 --- a/examples/system/console/advanced/main/console_settings.c +++ b/examples/system/console/advanced/main/console_settings.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2024-2026 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -12,12 +12,7 @@ #include "esp_log.h" #include "esp_console.h" #include "sdkconfig.h" -#include "soc/soc_caps.h" -#include "driver/uart_vfs.h" -#include "driver/uart.h" -#include "driver/usb_serial_jtag.h" -#include "driver/usb_serial_jtag_vfs.h" -#include "esp_vfs_cdcacm.h" +#include "esp_stdio.h" #include "linenoise/linenoise.h" #include "argtable3/argtable3.h" @@ -33,67 +28,8 @@ void initialize_console_peripheral(void) fflush(stdout); fsync(fileno(stdout)); -#if defined(CONFIG_ESP_CONSOLE_UART_DEFAULT) || defined(CONFIG_ESP_CONSOLE_UART_CUSTOM) - /* Minicom, screen, idf_monitor send CR when ENTER key is pressed */ - uart_vfs_dev_port_set_rx_line_endings(CONFIG_ESP_CONSOLE_UART_NUM, ESP_LINE_ENDINGS_CR); - /* Move the caret to the beginning of the next line on '\n' */ - uart_vfs_dev_port_set_tx_line_endings(CONFIG_ESP_CONSOLE_UART_NUM, ESP_LINE_ENDINGS_CRLF); - - /* Configure UART. Note that REF_TICK is used so that the baud rate remains - * correct while APB frequency is changing in light sleep mode. - */ - const uart_config_t uart_config = { - .baud_rate = CONFIG_ESP_CONSOLE_UART_BAUDRATE, - .data_bits = UART_DATA_8_BITS, - .parity = UART_PARITY_DISABLE, - .stop_bits = UART_STOP_BITS_1, -#if SOC_UART_SUPPORT_REF_TICK - .source_clk = UART_SCLK_REF_TICK, -#elif SOC_UART_SUPPORT_XTAL_CLK - .source_clk = UART_SCLK_XTAL, -#endif - }; - /* Install UART driver for interrupt-driven reads and writes */ - ESP_ERROR_CHECK( uart_driver_install(CONFIG_ESP_CONSOLE_UART_NUM, 256, 0, 0, NULL, 0) ); - ESP_ERROR_CHECK( uart_param_config(CONFIG_ESP_CONSOLE_UART_NUM, &uart_config) ); - - /* Tell VFS to use UART driver */ - uart_vfs_dev_use_driver(CONFIG_ESP_CONSOLE_UART_NUM); - -#elif defined(CONFIG_ESP_CONSOLE_USB_CDC) - /* Minicom, screen, idf_monitor send CR when ENTER key is pressed */ - esp_vfs_dev_cdcacm_set_rx_line_endings(ESP_LINE_ENDINGS_CR); - /* Move the caret to the beginning of the next line on '\n' */ - esp_vfs_dev_cdcacm_set_tx_line_endings(ESP_LINE_ENDINGS_CRLF); - - /* Enable blocking mode on stdin and stdout */ - fcntl(fileno(stdout), F_SETFL, 0); - fcntl(fileno(stdin), F_SETFL, 0); - -#elif defined(CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG) - /* Minicom, screen, idf_monitor send CR when ENTER key is pressed */ - usb_serial_jtag_vfs_set_rx_line_endings(ESP_LINE_ENDINGS_CR); - /* Move the caret to the beginning of the next line on '\n' */ - usb_serial_jtag_vfs_set_tx_line_endings(ESP_LINE_ENDINGS_CRLF); - - /* Enable blocking mode on stdin and stdout */ - fcntl(fileno(stdout), F_SETFL, 0); - fcntl(fileno(stdin), F_SETFL, 0); - - usb_serial_jtag_driver_config_t jtag_config = { - .tx_buffer_size = 256, - .rx_buffer_size = 256, - }; - - /* Install USB-SERIAL-JTAG driver for interrupt-driven reads and writes */ - ESP_ERROR_CHECK( usb_serial_jtag_driver_install(&jtag_config)); - - /* Tell vfs to use usb-serial-jtag driver */ - usb_serial_jtag_vfs_use_driver(); - -#else -#error Unsupported console type -#endif + /* Configure the proper driver selected in the menuconfig*/ + esp_stdio_install_io_driver(); /* Disable buffering on stdin */ setvbuf(stdin, NULL, _IONBF, 0);