zoukankan      html  css  js  c++  java
  • STM32F1 串口输出Printf 输出重定向

    注意下列代码huart1串号对齐。

    增加以下代码:(增加输出重定向会消耗大概7K左右内存。)

    #include "stdio.h"
    #ifdef __GNUC__
    /* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf
       set to 'Yes') calls __io_putchar() */
    #define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
    #else
    #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
    #endif /* __GNUC__ */
    /**
      * @brief  Retargets the C library printf function to the USART.
      * @param  None
      * @retval None
      */
    PUTCHAR_PROTOTYPE
    {
        /* Place your implementation of fputc here */
        /* e.g. write a character to the EVAL_COM1 and Loop until the end of transmission */
        HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, 0xFFFF);//使用串口发送出去
    
        return ch;
    }
    

    如果输出中文乱码

    把代码UTF-8转换为GBK格式

    如果需要支持浮点数输出

    把 #add_compile_options(-mfloat-abi=soft)  前面的#取消掉,增加后会消耗11.3K内存。

     如果是老版本CubeMX 在CMakeLists.txt 增加 -u _printf_float 让该函数例外不要被前面的-specs 裁剪缩小内存。

  • 相关阅读:
    第三章 系统总线
    人工神经网络及其应用
    专家系统
    遗传算法
    搜索算法策略
    js判断有无属性及新添属性
    vue 文件插件 Vetur 设置说明官网
    vue 获得当前无素并做相应处理
    VUE style 绑定
    vue入门基础知识点测试
  • 原文地址:https://www.cnblogs.com/siyun/p/14335120.html
Copyright © 2011-2022 走看看