#ifdef __GNUC__ //另外GNU还有一些公用的扩展出来的宏 比如__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__ */
/**
* @brief Retargets the C library printf function to the USART.
* @param None
* @retval None
*/
PUTCHAR_PROTOTYPE
{
/* Place your implementation of fputc here */
/* e.g. write a character to the EVAL_COM1 and Loop until the end of transmission */
HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, 0xFFFF);
return ch;
}
把代码加在一个.c文件中。就可以使用printf来进行数据重定向。上面代码适合32,其它的要进行相应替换即可。
printf("123456rn");一定要加rn.
『本文转载自网络,版权归原作者所有,如有侵权请联系删除』