STM32
直播中

李玉鑫

7年用户 1237经验值
私信 关注
[问答]

怎么去解决STM32串口重定向printf出现FILE未定义的问题呢

怎么去解决STM32串口重定向printf出现FILE未定义的问题呢?

回帖(1)

李婧

2021-12-2 14:12:16
在usart.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;
}


报错:


../Src/usart.c(118): error:  #20: identifier "FILE" is undefined


在usart.c文件中添加头文件包含


#include


再次编译无报错
举报

更多回帖

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