STM32-串口输出

使用 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");
发布了124 篇原创文章 · 获赞 21 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/tyustli/article/details/103881366