/* * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * * Change Logs: * Date Author Notes */ #include #include #ifndef RT_USING_FINSH #error Please uncomment the line <#include "finsh_config.h"> in the rtconfig.h #endif #ifdef RT_USING_FINSH //RT_WEAK char rt_hw_console_getchar(void) //{ // /* Note: the initial value of ch must < 0 */ // int ch = -1; // //#error "TODO 4: Read a char from the uart and assign it to 'ch'." // // return ch; //} #include "main.h" #include "usart.h" void rt_hw_console_output(const char *str) { rt_size_t i = 0, size = 0; char a = '\r'; rt_enter_critical(); size = rt_strlen(str); for (i = 0; i < size; i++) { if (*(str + i) == '\n') HAL_UART_Transmit(&huart1, (uint8_t *)&a, 1, 1); HAL_UART_Transmit(&huart1, (uint8_t *)(str + i), 1, 1); } rt_exit_critical(); } char rt_hw_console_getchar(void) { if (__HAL_UART_GET_FLAG(&huart1, UART_FLAG_RXNE) != RESET) { return huart1.Instance->DR & 0xff; } if(__HAL_UART_GET_FLAG(&huart1, UART_FLAG_ORE) != RESET) { __HAL_UART_CLEAR_OREFLAG(&huart1); } rt_thread_mdelay(10); return -1; } #endif /* RT_USING_FINSH */