From d99193e77159f9ed8a311670ad8d65aafa346ada Mon Sep 17 00:00:00 2001 From: liukangcc Date: Tue, 15 Mar 2022 10:14:51 +0800 Subject: [PATCH 1/2] [update] fix finsh bug --- components/finsh/shell.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/components/finsh/shell.c b/components/finsh/shell.c index 824c60392d9..ef227286734 100644 --- a/components/finsh/shell.c +++ b/components/finsh/shell.c @@ -162,14 +162,19 @@ int finsh_getchar(void) RT_ASSERT(shell != RT_NULL); device = shell->device; - if (device == RT_NULL) - { - return -1; /* EOF */ - } while (rt_device_read(device, -1, &ch, 1) != 1) + { rt_sem_take(&shell->rx_sem, RT_WAITING_FOREVER); - + if (shell->device != device) + { + device = shell->device; + if (device == RT_NULL) + { + return -1; + } + } + } return ch; #endif /* RT_USING_POSIX_STDIO */ #else From 0b992c4d06ebf80ad7c64f346f38c31b26a32811 Mon Sep 17 00:00:00 2001 From: liukangcc Date: Tue, 15 Mar 2022 11:08:47 +0800 Subject: [PATCH 2/2] [update] format code --- components/finsh/shell.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/components/finsh/shell.c b/components/finsh/shell.c index ef227286734..3304733496b 100644 --- a/components/finsh/shell.c +++ b/components/finsh/shell.c @@ -162,9 +162,13 @@ int finsh_getchar(void) RT_ASSERT(shell != RT_NULL); device = shell->device; + if (device == RT_NULL) + { + return -1; /* EOF */ + } while (rt_device_read(device, -1, &ch, 1) != 1) - { + { rt_sem_take(&shell->rx_sem, RT_WAITING_FOREVER); if (shell->device != device) {