1、在文件中加入如下代码,GCC环境需要重写_write函数或者__io_putchar函数,hlpuart1为STM32配置的串口,根据不同的配置修改
2、ANSI C中定义换行符'\n'可以认为是行刷新标志。所以,printf函数没有带'\n'是不会自动刷新输出流,直至缓存被填满
3、编译环境勾选 use MicroLIB

4、添加代码:
#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__ */
/**
* @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 USART */</
492




被折叠的 条评论
为什么被折叠?



