STM32
直播中

肖耳朵

12年用户 557经验值
私信 关注
[问答]

如何实现STM32对printf打印输出信息的支持呢

如何实现STM32对printf打印输出信息的支持呢?

回帖(1)

望艳妮

2021-12-2 15:19:07
在软件高度过程中,使用printf打印输出信息非常方便,可通过添加以下内容实现STM32对printf的支持。




  • #include


  • #ifdef __GNUC__
  • #define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
  • #else
  • #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)

  • #endif


  • /**
  •   * @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;  
  • }


举报

更多回帖

发帖
×
20
完善资料,
赚取积分