1. 程式人生 > >STM32中重定位printf到串列埠輸出

STM32中重定位printf到串列埠輸出

#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 */
 /* e.g. write a character to the USART */
 USART_SendData(USART1, (unsigned char) ch);
 /* Loop until the end of transmission */
 while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET);
 return ch;
}