diff --git a/components/vfs/vfs_uart.c b/components/vfs/vfs_uart.c index d53de7597..17ef81bb6 100644 --- a/components/vfs/vfs_uart.c +++ b/components/vfs/vfs_uart.c @@ -382,6 +382,17 @@ static esp_err_t uart_start_select(int nfds, fd_set *readfds, fd_set *writefds, FD_ZERO(writefds); FD_ZERO(exceptfds); + for (int i = 0; i < max_fds; ++i) { + if (FD_ISSET(i, _readfds_orig)) { + size_t buffered_size; + if (uart_get_buffered_data_len(i, &buffered_size) == ESP_OK && buffered_size > 0) { + // signalize immediately when data is buffered + FD_SET(i, _readfds); + esp_vfs_select_triggered(_signal_sem); + } + } + } + portEXIT_CRITICAL(uart_get_selectlock()); // s_one_select_lock is not released on successfull exit - will be // released in uart_end_select() diff --git a/examples/peripherals/uart_select/main/uart_select_example_main.c b/examples/peripherals/uart_select/main/uart_select_example_main.c index 62bca5698..717042f27 100644 --- a/examples/peripherals/uart_select/main/uart_select_example_main.c +++ b/examples/peripherals/uart_select/main/uart_select_example_main.c @@ -66,7 +66,10 @@ static void uart_select_task() if (FD_ISSET(fd, &rfds)) { char buf; if (read(fd, &buf, 1) > 0) { - ESP_LOGI(TAG, "Received: %c", buf); + ESP_LOGI(TAG, "Received: %c", buf); + // Note: Only one character was read even the buffer contains more. The other characters will + // be read one-by-one by subsequent calls to select() which will then return immediately + // without timeout. } else { ESP_LOGE(TAG, "UART read error"); break;