STM32添加printf支持

来源:互联网 发布:淘宝直通车在哪开通 编辑:程序博客网 时间:2024/05/20 09:24
在软件高度过程中,使用printf打印输出信息非常方便,可通过添加以下内容实现STM32对printf的支持。



  1. #include <stdio.h>

  2. #ifdef __GNUC__
  3. #define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
  4. #else
  5. #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
  6. #endif




  7. /** 
  8.   * @brief  Retargets the C library printf function to the USART. 
  9.   * @param  None 
  10.   * @retval None 
  11.   */  
  12. PUTCHAR_PROTOTYPE  
  13. {  
  14.   /* Place your implementation of fputc here */  
  15.   /* e.g. write a character to the USART */  
  16.   USART_SendData(USART1, (uint8_t) ch);  
  17.   
  18.   /* Loop until the end of transmission */  
  19.   while(USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET)  
  20.   {  
  21.   }  
  22.   
  23.   return ch;  


http://blog.csdn.net/dldw8816/article/details/44563749
原创粉丝点击