根据官方文档在串口内绑定char rt_hw_console_getchar(void)
char rt_hw_console_getchar(void)
{
int ch = -1;
if (__HAL_UART_GET_FLAG(&huart1, UART_FLAG_RXNE) != RESET)
{
ch = huart1.Instance->DR & 0xff;
}
else
{
if(__HAL_UART_GET_FLAG(&huart1, UART_FLAG_ORE) != RESET)
{
__HAL_UART_CLEAR_OREFLAG(&huart1);
}
rt_thread_mdelay(50);
}
return ch;
}
然后在主main函数内添加主动调动函数(例如rt_thread_mdelay()),否则系统如果没有比该线程优先级更高,则该线程一直占用CPU,造成控制台无法使用的现象
此命令需要rt_hw_console_output()配合使用
https://blog.csdn.net/zhangsxa/article/details/105459050