【STM32】HAL库串口使用printf
1、HAL库配置
1、选择芯片
2、系统配置
2、在Keil中增加代码
生成代码后:
1、首先在图示位置加入头文件#include “stdio.h”
/* USER CODE BEGIN Includes */
#include "stdio.h"
/* USER CODE END Includes */
2、然后在main.c文件中加入下面的这个函数,注意串口号根据自己的实际使用的串口进行更改
int fputc(int ch, FILE *f)
{
uint8_t temp[1] = {
ch};
HAL_UART_Transmit(&huart1, temp, 1, 2);
return ch;
}
3、然后就可以使用printf()函数了