• 首先,在main.h中加上
#include <stdio.h>
  • 然后在usart.c中加上以下程序即可
#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;
}
  • 测试,在main.c的while函数中加上如下代码测试
printf("测试串口打印/r/n");