STM32 添加printf()
1.在main.c中添加 #include “stdio.h”
2.在usart.c中增加如下代码:
#include “stdio.h”
#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
{
USART_Transmit(USART3, ch);
while (USART_GetFlagStatus(USART3, USART_FLAG_TC) == RESET);
return ch;
}
3.在main.c中,添加 printf("\n\r USART3 Printf Exzmple:\n\r");
复位后串口发生字符串: USART3 Printf Exzmple
备注:
在 Options for Target -> C/C++ 下:GNU extensions 不能打钩。打钩的话,编译器不能输出Printf()。