在stm32 单片机程序中使用printf()进行串口调试

来源:互联网 发布:8787端口是干嘛的 编辑:程序博客网 时间:2024/05/07 18:28

在单片机使用printf()函数进行程序调试很方便,官方给的串口输出函数功能比较单一,又满足不了要求。

修改方法如下:

1、在.c文件中包含如下代码:

#ifdef __GNUC__/* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf   set to 'Yes') calls __io_putchar() */#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)#else#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)#endif /* __GNUC__ */PUTCHAR_PROTOTYPE{  /* Place your implementation of fputc here */  USART_SendData(USART1, (uint8_t) ch);  /* Loop until the end of transmission */  while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET)  {}  return ch;}
2、然后包含头文件。

#include "stdio.h"

如此,便可使用其进行格式化输出。
0 0
原创粉丝点击