[其他ST产品] SW4STM32下使用printf发送消息,将消息用串口助手接收

[复制链接]
340|0
 楼主| 麻花油条 发表于 2023-1-12 10:46 | 显示全部楼层 |阅读模式
问题描述:
在keil环境下正常使用printf功能,但是在SW4STM32下使用不了,下面是添加到uart.c里面的重定向语句
#ifdef __GNUC__
  /* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf
     set to 'Yes') calls __io_putchar() */
  #define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
  #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif /* __GNUC__ */
/**
  * @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 EVAL_COM1 and Loop until the end of transmission */
  HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, 0xFFFF);

  return ch;
}
如何才能正常使用printf呢?

您需要登录后才可以回帖 登录 | 注册

本版积分规则

308

主题

1743

帖子

3

粉丝
快速回复 在线客服 返回列表 返回顶部