STM32CubeIDE 添加printf打印输出

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/qq_36075612/article/details/96851644

1、在使用STM32Cubde 生成好代码中usart.c中添加,如下的代码即可:

/* USER CODE BEGIN 0 */
#include "stdio.h"

#ifdef __GNUC__

#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)

PUTCHAR_PROTOTYPE
{

  // 注意下面第一个参数是&huart1,因为cubemx配置了串口1自动生成的
  HAL_UART_Transmit(&huart1, (uint8_t*)&ch, 1, HAL_MAX_DELAY);

  return ch;
}
#endif

/* USER CODE END 0 */

猜你喜欢

转载自blog.csdn.net/qq_36075612/article/details/96851644