debug: 确保 rt_console_set_device 可以将 _console_device 置为 NULL

Signed-off-by: a1012112796 <1012112796@qq.com>
This commit is contained in:
2023-04-17 14:02:00 +08:00
parent 823dd2e41e
commit b48f2d044c

View File

@@ -746,19 +746,17 @@ rt_device_t rt_console_set_device(const char *name)
/* check whether it's a same device */
if (new_device == old_device) return RT_NULL;
if (new_device != RT_NULL)
if (_console_device != RT_NULL)
{
if (_console_device != RT_NULL)
{
/* close old console device */
rt_device_close(_console_device);
}
/* set new console device */
rt_device_open(new_device, RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_STREAM);
_console_device = new_device;
/* close old console device */
rt_device_close(_console_device);
}
/* set new console device */
if (new_device != RT_NULL)
rt_device_open(new_device, RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_STREAM);
_console_device = new_device;
return old_device;
}
RTM_EXPORT(rt_console_set_device);