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

  • 相关阅读:
    游标定位:Cursor类
    拨号操作——android.intent.action.CALL
    按键——Button事件监听器
    文本框——EditText
    配置文件:mainfest.xml
    win7如何设置以管理员身份运行
    随机数:rand()
    std::string 和 CString问题
    文件操作:rewind()
    文件操作:fread()和fwrite()
  • 原文地址:https://www.cnblogs.com/zjvskn/p/14161906.html
Copyright © 2011-2022 走看看