原文出处:https://www.cnblogs.com/shangdawei/p/3970489.html
 
一、对工程属性进行配置,详细步骤如下
 
1、首先要在你的main 文件中 包含“stdio.h” (标准输入输出头文件)。
 
2、在main文件中重定义<fputc>函数    如下:
stm32使用printf重定向到usart1
// 发送数据
   int fputc(int ch, FILE *f)
   {
      USART_SendData(USART1, (unsigned char) ch);// USART1 可以换成 USART2 等
      while (!(USART1->SR & USART_FLAG_TXE));
      return (ch);
   }
   // 接收数据
   int GetKey (void)  
{ while (!(USART1->SR & USART_FLAG_RXNE)); return ((int)(USART1->DR & 0x1FF)); }
stm32使用printf重定向到usart1
这样在使用printf时就会调用自定义的fputc函数,来发送字符。
 
3、在工程属性的 “Target" -> "Code Generation" 选项中勾选 "Use MicroLIB"
   MicroLIB 是缺省C的备份库,关于它可以到网上查找详细资料。

相关文章:

  • 2021-08-16
  • 2021-12-06
  • 2021-11-10
  • 2021-08-07
  • 2021-09-24
  • 2021-08-28
  • 2021-05-08
  • 2021-10-31
猜你喜欢
  • 2021-08-25
  • 2021-12-18
  • 2022-12-23
  • 2021-07-07
  • 2022-12-23
  • 2021-10-26
相关资源
相似解决方案