方法借鉴于博主Z小璇的串口调试文章本文链接:【STM32】HAL库 STM32CubeMX教程四---UART串口通信详解_Z小旋的博客-CSDN博客_hal_uart_transmit详解
使用STM32F103ZET6亲测有效,,在此做一个笔记:
1.在stm32f1xx_hal.c文件中添加以下定义
#include <stdio.h>
extern UART_HandleTypeDef huart1;
2.继续在该文件中添加以下函数:
3.在main.c中添加,就可以使用printf 、Scanf,getchar函数
主函数中再次添加一次#include<stdio.h> 再使用printf后编译就不会出现警告 亲测有效