Skip to content

Commit c2d5712

Browse files
committed
Merge branch 'bugfix/openthread_uart_vfs_register_v5_3' into 'release/v5.3'
fix(openthread): register uart vfs devices when they are not registered(v5.3) See merge request espressif/esp-idf!31795
2 parents e3e5b34 + 9d60b90 commit c2d5712

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

components/openthread/src/port/esp_openthread_uart.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -17,6 +17,7 @@
1717
#include "esp_openthread_common_macro.h"
1818
#include "esp_openthread_platform.h"
1919
#include "esp_openthread_types.h"
20+
#include "esp_vfs.h"
2021
#include "esp_vfs_dev.h"
2122
#include "common/logging.hpp"
2223
#include "driver/uart.h"
@@ -62,6 +63,17 @@ otError otPlatUartSend(const uint8_t *buf, uint16_t buf_length)
6263

6364
esp_err_t esp_openthread_uart_init_port(const esp_openthread_uart_config_t *config)
6465
{
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
6577
ESP_RETURN_ON_ERROR(uart_param_config(config->port, &config->uart_config), OT_PLAT_LOG_TAG,
6678
"uart_param_config failed");
6779
ESP_RETURN_ON_ERROR(
@@ -91,7 +103,6 @@ esp_err_t esp_openthread_host_cli_usb_init(const esp_openthread_platform_config_
91103

92104
ret = usb_serial_jtag_driver_install((usb_serial_jtag_driver_config_t *)&config->host_config.host_usb_config);
93105
usb_serial_jtag_vfs_use_driver();
94-
uart_vfs_dev_register();
95106
return ret;
96107
}
97108
#endif

0 commit comments

Comments
 (0)