From c99dfc3147ef08ef62e729dc2860e06ad90380d3 Mon Sep 17 00:00:00 2001 From: liukangcc Date: Wed, 13 Oct 2021 18:04:46 +0800 Subject: [PATCH] =?UTF-8?q?[update]=20fix=20finsh=5Fgetchar()=20=E6=9C=AA?= =?UTF-8?q?=E5=AF=B9=20shell->device=20=E4=B8=BA=E7=A9=BA=E5=A4=84?= =?UTF-8?q?=E7=90=86=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/finsh/shell.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/components/finsh/shell.c b/components/finsh/shell.c index 48651d2c4f..7b577db6b6 100644 --- a/components/finsh/shell.c +++ b/components/finsh/shell.c @@ -151,15 +151,19 @@ char finsh_getchar(void) char ch = 0; RT_ASSERT(shell != RT_NULL); + if (shell->device == RT_NULL) + { + return -RT_ERROR; + } while (rt_device_read(shell->device, -1, &ch, 1) != 1) rt_sem_take(&shell->rx_sem, RT_WAITING_FOREVER); return ch; -#endif +#endif /* RT_USING_POSIX */ #else extern char rt_hw_console_getchar(void); return rt_hw_console_getchar(); -#endif +#endif /* RT_USING_DEVICE */ } #if !defined(RT_USING_POSIX) && defined(RT_USING_DEVICE)