一、打开系统生成usart.c
二、移到usart.c最下面,在/* USER CODE BEGIN 1 */下面添加如下代码
#include<stdio.h>
#ifdef __GNUC__
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif
PUTCHAR_PROTOTYPE
{
HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, 0xFFFF);
return ch;
}
三、添加效果如下
![](https://img-blog.csdnimg.cn/img_convert/32fb5eb31e35c9ef15d79786e3697a54.png)