From 2cda31ab7433b2b2c77f5d15c551e412ea6786f6 Mon Sep 17 00:00:00 2001 From: zhangwenxu Date: Tue, 26 Sep 2023 17:25:13 +0800 Subject: [PATCH] feat(BR): USB console init refactor --- docs/en/dev-guide/build_and_run.rst | 2 +- .../main/esp_ot_config.h | 8 ++++ .../sdkconfig.defaults | 3 +- .../common/border_router_board/CMakeLists.txt | 4 -- .../include/border_router_board.h | 18 ------- .../src/border_router_board.c | 47 ------------------- .../thread_border_router/CMakeLists.txt | 2 +- .../src/border_router_launch.c | 2 - 8 files changed, 12 insertions(+), 74 deletions(-) delete mode 100644 examples/common/border_router_board/CMakeLists.txt delete mode 100644 examples/common/border_router_board/include/border_router_board.h delete mode 100644 examples/common/border_router_board/src/border_router_board.c diff --git a/docs/en/dev-guide/build_and_run.rst b/docs/en/dev-guide/build_and_run.rst index 3229628..1b5b36f 100644 --- a/docs/en/dev-guide/build_and_run.rst +++ b/docs/en/dev-guide/build_and_run.rst @@ -11,7 +11,7 @@ Clone the `esp-idf `_ and the `esp-thread- .. code-block:: bash - git clone -b v5.1.1 --recursive https://github.com/espressif/esp-idf.git + git clone -b v5.1.2 --recursive https://github.com/espressif/esp-idf.git .. code-block:: bash diff --git a/examples/basic_thread_border_router/main/esp_ot_config.h b/examples/basic_thread_border_router/main/esp_ot_config.h index b37f217..856b94f 100644 --- a/examples/basic_thread_border_router/main/esp_ot_config.h +++ b/examples/basic_thread_border_router/main/esp_ot_config.h @@ -77,6 +77,7 @@ .target_chip = ESP32H2_CHIP, \ } +#if CONFIG_OPENTHREAD_CONSOLE_TYPE_UART #define ESP_OPENTHREAD_DEFAULT_HOST_CONFIG() \ { \ .host_connection_mode = HOST_CONNECTION_MODE_CLI_UART, \ @@ -96,6 +97,13 @@ .tx_pin = UART_PIN_NO_CHANGE, \ }, \ } +#elif CONFIG_OPENTHREAD_CONSOLE_TYPE_USB_SERIAL_JTAG +#define ESP_OPENTHREAD_DEFAULT_HOST_CONFIG() \ + { \ + .host_connection_mode = HOST_CONNECTION_MODE_CLI_USB, \ + .host_usb_config = USB_SERIAL_JTAG_DRIVER_CONFIG_DEFAULT(), \ + } +#endif #define ESP_OPENTHREAD_DEFAULT_PORT_CONFIG() \ { \ diff --git a/examples/basic_thread_border_router/sdkconfig.defaults b/examples/basic_thread_border_router/sdkconfig.defaults index f5e623c..3c2dadb 100644 --- a/examples/basic_thread_border_router/sdkconfig.defaults +++ b/examples/basic_thread_border_router/sdkconfig.defaults @@ -52,6 +52,7 @@ CONFIG_OPENTHREAD_ENABLED=y CONFIG_OPENTHREAD_BORDER_ROUTER=y CONFIG_OPENTHREAD_TREL=y CONFIG_OPENTHREAD_CLI_OTA=y +CONFIG_OPENTHREAD_CONSOLE_TYPE_USB_SERIAL_JTAG=y # end of OpenThread # @@ -107,4 +108,4 @@ CONFIG_EXAMPLE_ETH_SPI_CLOCK_MHZ=36 CONFIG_EXAMPLE_ETH_SPI_INT_GPIO=39 CONFIG_EXAMPLE_ETH_PHY_RST_GPIO=40 CONFIG_EXAMPLE_ETH_PHY_ADDR=1 -# end of Etherenet \ No newline at end of file +# end of Etherenet diff --git a/examples/common/border_router_board/CMakeLists.txt b/examples/common/border_router_board/CMakeLists.txt deleted file mode 100644 index 2223c83..0000000 --- a/examples/common/border_router_board/CMakeLists.txt +++ /dev/null @@ -1,4 +0,0 @@ -idf_component_register(SRC_DIRS "src" - INCLUDE_DIRS "include" - REQUIRES driver vfs -) diff --git a/examples/common/border_router_board/include/border_router_board.h b/examples/common/border_router_board/include/border_router_board.h deleted file mode 100644 index b85e89b..0000000 --- a/examples/common/border_router_board/include/border_router_board.h +++ /dev/null @@ -1,18 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#pragma once - -#include "esp_err.h" -#ifdef __cplusplus -extern "C" { -#endif - -esp_err_t border_router_board_init(void); - -#ifdef __cplusplus -} -#endif diff --git a/examples/common/border_router_board/src/border_router_board.c b/examples/common/border_router_board/src/border_router_board.c deleted file mode 100644 index 3022f34..0000000 --- a/examples/common/border_router_board/src/border_router_board.c +++ /dev/null @@ -1,47 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "border_router_board.h" -#include "esp_err.h" -#include "sdkconfig.h" - -#if CONFIG_ESP_BR_BOARD_DEV_KIT && CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG - -#include "esp_vfs_dev.h" -#include "esp_vfs_usb_serial_jtag.h" -#include "driver/usb_serial_jtag.h" - -#include - -esp_err_t border_router_board_init(void) -{ - esp_err_t ret = ESP_OK; - /* Disable buffering on stdin */ - setvbuf(stdin, NULL, _IONBF, 0); - - /* Minicom, screen, idf_monitor send CR when ENTER key is pressed */ - esp_vfs_dev_usb_serial_jtag_set_rx_line_endings(ESP_LINE_ENDINGS_CR); - /* Move the caret to the beginning of the next line on '\n' */ - esp_vfs_dev_usb_serial_jtag_set_tx_line_endings(ESP_LINE_ENDINGS_CRLF); - - /* Enable non-blocking mode on stdin and stdout */ - fcntl(fileno(stdout), F_SETFL, O_NONBLOCK); - fcntl(fileno(stdin), F_SETFL, O_NONBLOCK); - - usb_serial_jtag_driver_config_t usb_serial_jtag_config = USB_SERIAL_JTAG_DRIVER_CONFIG_DEFAULT(); - ret = usb_serial_jtag_driver_install(&usb_serial_jtag_config); - esp_vfs_usb_serial_jtag_use_driver(); - esp_vfs_dev_uart_register(); - return ret; -} - -#else // CONFIG_BR_BOARD_DEV_KIT && CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG - -esp_err_t border_router_board_init(void) -{ - return ESP_OK; -} -#endif // CONFIG_BR_BOARD_DEV_KIT && CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG diff --git a/examples/common/thread_border_router/CMakeLists.txt b/examples/common/thread_border_router/CMakeLists.txt index 915a60f..43f2bdc 100644 --- a/examples/common/thread_border_router/CMakeLists.txt +++ b/examples/common/thread_border_router/CMakeLists.txt @@ -1,4 +1,4 @@ -set(requires esp_ot_cli_extension openthread vfs border_router_board) +set(requires esp_ot_cli_extension openthread vfs) if(CONFIG_OPENTHREAD_CLI_OTA) list(APPEND requires esp_http_client esp_br_http_ota) diff --git a/examples/common/thread_border_router/src/border_router_launch.c b/examples/common/thread_border_router/src/border_router_launch.c index 7b4c108..9d5f135 100644 --- a/examples/common/thread_border_router/src/border_router_launch.c +++ b/examples/common/thread_border_router/src/border_router_launch.c @@ -6,7 +6,6 @@ */ #include "border_router_launch.h" -#include "border_router_board.h" #include #include @@ -94,7 +93,6 @@ static void ot_task_worker(void *ctx) assert(openthread_netif != NULL); // Initialize the OpenThread stack - ESP_ERROR_CHECK(border_router_board_init()); esp_openthread_register_rcp_failure_handler(rcp_failure_handler); ESP_ERROR_CHECK(esp_openthread_init(&s_openthread_platform_config));