怎么实现
STM32f030 HAL层调用printf函数进行打印?
回帖(1)
2021-12-1 10:11:28
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);
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);
举报
更多回帖