zoukankan      html  css  js  c++  java
  • STM32 串口 重定向

    转载于:

    https://www.bilibili.com/video/av64690830?p=12

    https://tangxing.blog.csdn.net/article/details/104369364?utm_medium=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromBaidu-1.control&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromBaidu-1.control

    1. 引入头文件 stdio.h

    #include "stdio.h"

    2.添加重定向代码 此处我是将printf函数重定向到串口1 // 重定向printf函数

    // 重定向printf函数
    int fputc(int ch,FILE *f)
    {
      uint8_t temp[1]={ch};
      HAL_UART_Transmit(&huart1,temp,1,2);
      return 0;
    }

    3.添加DEBUG宏定义 使用以下宏定义,debug结果会按照格式化输出,非常方便

    #define USER_MAIN_DEBUG

    #ifdef USER_MAIN_DEBUG
    #define user_main_printf(format, ...) printf( format " ",##__VA_ARGS__)
    #define user_main_info(format, ...) printf("【main】info:" format " ",##__VA_ARGS__)
    #define user_main_debug(format, ...) printf("【main】debug:" format " ",##__VA_ARGS__)
    #define user_main_error(format, ...) printf("【main】error:" format " ",##__VA_ARGS__)
    #else
    #define user_main_printf(format, ...)
    #define user_main_info(format, ...)
    #define user_main_debug(format, ...)
    #define user_main_error(format, ...)
    #endif

  • 相关阅读:
    ◆ C++中通过溢出覆盖虚函数指针列表执行代码
    关于在OnTimer中连续弹出对话框的讨论
    SetTimer
    Windows内核对象
    日志收缩
    暴力求值
    低级问题
    函数限制
    字符串找字段和表
    android错误提示说明汇总
  • 原文地址:https://www.cnblogs.com/zjvskn/p/14161906.html
Copyright © 2011-2022 走看看