【HAL库】printf()函数未定义问题调试

问题描述:
一般C语言中使用printf()函数时,包含#include "stdio.h"即可使用,但在Keil(HAL库)开发环境中使用不了。
问题分析:
未定义printf()使用的串口
解决方案:
在HAL库stm32xxxx_hal.c函数中,对输出串口进行定义与配置。
示例代码:

extern UART_HandleTypeDef huart2;   

int fputc(int ch, FILE *f)
{
  HAL_UART_Transmit(&huart2, (uint8_t *)&ch, 1, 0xffff);
  return ch;
}
 

int fgetc(FILE *f)
{
  uint8_t ch = 0;
  HAL_UART_Receive(&huart2, &ch, 1, 0xffff);
  return ch;
}

猜你喜欢

转载自blog.csdn.net/weixin_44064233/article/details/108522957
今日推荐