在工程的usart.c文件中加入如下代码:
#include <stdio.h>
#ifndef __MICROLIB
#pragma import(__use_no_semihosting)
void _sys_exit(int x)
{
x = x;
}
struct __FILE
{
int handle;
};
FILE __stdout;
#endif
#ifdef __GNUC__
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif
PUTCHAR_PROTOTYPE
{
while((USART2->ISR & 0X40) == 0);
USART2->TDR = (uint8_t)ch;
return ch;
}