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 裁剪缩小内存。

  • 相关阅读:
    sss
    sss
    maven tomcat jstl 异常
    第1章 预备知识
    第2章 存储管理
    第8章 虚拟机字节码执行引擎
    第23章 Spring MVC初体验
    第1章 预备知识
    第5章 Java中的锁
    第13章 线程安全与锁优化
  • 原文地址:https://www.cnblogs.com/siyun/p/14335120.html
Copyright © 2011-2022 走看看