Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

finsh_port.c 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. */
  9. #include <rthw.h>
  10. #include <rtconfig.h>
  11. #ifndef RT_USING_FINSH
  12. #error Please uncomment the line <#include "finsh_config.h"> in the rtconfig.h
  13. #endif
  14. #ifdef RT_USING_FINSH
  15. //RT_WEAK char rt_hw_console_getchar(void)
  16. //{
  17. // /* Note: the initial value of ch must < 0 */
  18. // int ch = -1;
  19. //
  20. //#error "TODO 4: Read a char from the uart and assign it to 'ch'."
  21. //
  22. // return ch;
  23. //}
  24. #include "main.h"
  25. #include "usart.h"
  26. void rt_hw_console_output(const char *str)
  27. {
  28. rt_size_t i = 0, size = 0;
  29. char a = '\r';
  30. rt_enter_critical();
  31. size = rt_strlen(str);
  32. for (i = 0; i < size; i++)
  33. {
  34. if (*(str + i) == '\n')
  35. HAL_UART_Transmit(&huart1, (uint8_t *)&a, 1, 1);
  36. HAL_UART_Transmit(&huart1, (uint8_t *)(str + i), 1, 1);
  37. }
  38. rt_exit_critical();
  39. }
  40. char rt_hw_console_getchar(void)
  41. {
  42. if (__HAL_UART_GET_FLAG(&huart1, UART_FLAG_RXNE) != RESET)
  43. {
  44. return huart1.Instance->DR & 0xff;
  45. }
  46. if(__HAL_UART_GET_FLAG(&huart1, UART_FLAG_ORE) != RESET)
  47. {
  48. __HAL_UART_CLEAR_OREFLAG(&huart1);
  49. }
  50. rt_thread_mdelay(10);
  51. return -1;
  52. }
  53. #endif /* RT_USING_FINSH */