天天看點

STM32f030 HAL層調用printf函數進行列印

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庫

STM32f030 HAL層調用printf函數進行列印

使用printf()函數,像C語言一樣輸出列印資訊,

比如列印字元串printf(“hello word”);

列印數字格式輸出printf(“the counter is %d”,cnt);

繼續閱讀