1、在主函數中添加
#include “stdio.h”
2、主程式中添加函數
// 重定向函數1
int fputc(int c,FILE *stream)
{
HAL_UART_Transmit(&huart1,(unsigned char *)&c,1,100); //huart1是序列槽的句柄
return 1;
}
3、在keil中勾選使用C庫
使用printf()函數,像C語言一樣輸出列印資訊,
比如列印字元串printf(“hello word”);
列印數字格式輸出printf(“the counter is %d”,cnt);