使用 STM32CubeMx 工具配置好串口外设。
1、uart.c 中定义 buf
char debug_buf[128];
2、uart.h 中实现串口输出函数
#include<stdio.h>
extern char debug_buf[128];
#define debug(...){ \
int len = 0; \
len = snprintf(debug_buf, 128, __VA_ARGS__); \
if (len > 0) \
{ \
HAL_UART_Transmit_DMA(&huart1, (uint8_t *)debug_buf, len);\
} \
}
3、其他函数调用串口输出函数
debug("hello tyustli\r\n");