zoukankan      html  css  js  c++  java
  • STM32 CUBEIDE 串口的使用与printf重定向

    1.配置IOC文件

     保存后生成代码,没有使用DMA模式

    2.在main.c或者.h中添加以下代码进行重定向

    #ifdef __GNUC__
    /* With GCC, 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 USART3 and Loop until the end of transmission */
      HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, 0xFFFF);
    
      return ch;
    }

    3.设置可以输出float型变量的printf函数

    项目管理器中右键项目选择properties选项(快捷键为alt+enter)

    按照以下步骤将两个选项打对号

     4.测试结果

  • 相关阅读:
    day 17
    day 16
    信息系统项目管理师 教程学习 第一章
    服务器安全防护
    少有人走的路
    Python文件学习
    测试新文章
    测试
    python基础 一、 数值类型、序列类型和散列类型
    apache No input filespecified
  • 原文地址:https://www.cnblogs.com/Lxk0825/p/15358822.html
Copyright © 2011-2022 走看看