调试信息输出配置

转载:http://blog.163.com/y_chengwan@126/blog/static/166026328201233072644134/
作者:小枣年糕

  #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)

 // @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 USART 
  USART_SendData(USART1, (uint8_t) ch);
  // Loop until the end of transmission
  while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET)
  {}
  return ch;
}
这一段函数就是把printf函数输出到串口,需要将fputc输出给串口,也就是重新定义。


下面就说一下使用printf需要做哪些配置。



有两种配置方法:


一、对工程属性进行配置,详细步骤如下


1、首先要在你的main 文件中 包含“stdio.h” (标准输入输出头文件)。


2、在main文件中重定义<fputc>函数 如下:


/**
  * @brief  Retargets the C library printf function to the USART.
  * @param  None
  * @retval None  printf 重定向到串口
  */
PUTCHAR_PROTOTYPE
{
  /* Place your implementation of fputc here */
  /* e.g. write a character to the USART */
  USART_SendData(EVAL_COM1, (uint8_t) ch);


  /* Loop until the end of transmission */
  while (USART_GetFlagStatus(EVAL_COM1, USART_FLAG_TC) == RESET)
  {}


  return ch;
}

3、在工程属性的 “Target" -> "Code Generation" 选项中勾选 "Use MicroLIB"”


MicroLIB 是缺省C的备份库,关于它可以到网上查找详细资料。


至此完成配置,在工程中可以随意使用printf向串口发送数据了。


  retarget.c  一般工程都会带有的重定向函数文件。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值