|
1 | 1 | /* |
2 | | - * SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD |
| 2 | + * SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD |
3 | 3 | * |
4 | 4 | * SPDX-License-Identifier: Apache-2.0 |
5 | 5 | */ |
|
17 | 17 | #include "esp_openthread_common_macro.h" |
18 | 18 | #include "esp_openthread_platform.h" |
19 | 19 | #include "esp_openthread_types.h" |
| 20 | +#include "esp_vfs.h" |
20 | 21 | #include "esp_vfs_dev.h" |
21 | 22 | #include "common/logging.hpp" |
22 | 23 | #include "driver/uart.h" |
@@ -62,6 +63,17 @@ otError otPlatUartSend(const uint8_t *buf, uint16_t buf_length) |
62 | 63 |
|
63 | 64 | esp_err_t esp_openthread_uart_init_port(const esp_openthread_uart_config_t *config) |
64 | 65 | { |
| 66 | +#ifndef CONFIG_ESP_CONSOLE_UART |
| 67 | + // If UART console is used, UART vfs devices should be registered during startup. |
| 68 | + // Otherwise we need to register them here. |
| 69 | + DIR *uart_dir = opendir("/dev/uart"); |
| 70 | + if (!uart_dir) { |
| 71 | + // If UART vfs devices are registered, we will failed to open the directory |
| 72 | + uart_vfs_dev_register(); |
| 73 | + } else { |
| 74 | + closedir(uart_dir); |
| 75 | + } |
| 76 | +#endif |
65 | 77 | ESP_RETURN_ON_ERROR(uart_param_config(config->port, &config->uart_config), OT_PLAT_LOG_TAG, |
66 | 78 | "uart_param_config failed"); |
67 | 79 | ESP_RETURN_ON_ERROR( |
@@ -91,7 +103,6 @@ esp_err_t esp_openthread_host_cli_usb_init(const esp_openthread_platform_config_ |
91 | 103 |
|
92 | 104 | ret = usb_serial_jtag_driver_install((usb_serial_jtag_driver_config_t *)&config->host_config.host_usb_config); |
93 | 105 | usb_serial_jtag_vfs_use_driver(); |
94 | | - uart_vfs_dev_register(); |
95 | 106 | return ret; |
96 | 107 | } |
97 | 108 | #endif |
|
0 commit comments