加入头文件
#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(&huart2 , (uint8_t *)&ch, 1, 0xFFFF);
return ch;
}
打印浮点数时
参考文章
STM32CUBEIDE(6)----printf打印配置_记帖的博客-CSDN博客



