×
单片机 > 单片机程序设计 > 详情

STM32串口通信printf重定向方法

发布时间:2020-08-31 发布时间:
|

在源程序中加入如下代码,包含“stdio.h”。

默认使用USART1,确认串口已经初始化成功、


  1. #pragma import(__use_no_semihosting)   

  2. _sys_exit(int x)   

  3. {   

  4. x = x;   

  5. }   

  6. struct __FILE   

  7. {   

  8. int handle;   

  9. /* Whatever you require here. If the only file you are using is */   

  10. /* standard output using printf() for debugging, no file handling */   

  11. /* is required. */   

  12. };   

  13. /* FILE is typedef’ d in stdio.h. */   

  14. FILE __stdout;  

  15. int fputc(int ch, FILE *f)  

  16. {  

  17.         while(USART_GetFlagStatus(USART1,USART_FLAG_TC) == RESET);  

  18.         USART_SendData(USART1,ch);  

  19.         return ch;  

  20. }  


关键字:STM32  串口通信  printf  重定向 

『本文转载自网络,版权归原作者所有,如有侵权请联系删除』

热门文章 更多
ARM 汇编的必知必会