如果打开文件usart3.c,就可以看到下面新增的代码,它就是使能printf的关键:
#if defined(__GNUC__)
int USART3_printCHAR(char character, FILE *stream)
{
USART3_Write(character);
return 0;
}
FILE USART3_stream = FDEV_SETUP_STREAM(USART3_printCHAR, NULL, _FDEV_SETUP_WRITE);
#elif defined(__ICCAVR__)
int putchar(int outChar)
{
USART0_Write(outChar);
return outChar;
}
#endif
#if defined(__GNUC__)
stdout = &USART3_stream;
#endif