让MDK支持printf(基于stm32)

来源:互联网 发布:游戏编程软件下载 编辑:程序博客网 时间:2024/05/16 13:44

作者:number007cool

转自:http://blog.chinaunix.net/uid-21658993-id-3025200.html


1、在Option->Target选项框里选Use MicroLib 选项 
2、在将要调用printf的函数的c文件中包含头文件#include "stdio.h"
3、在该c文件中添加如下函数:

int fputc(int ch, FILE *f)  

{  

//USART_SendData(USART1, (u8) ch);  

USART1->DR = (u8) ch;  

/* Loop until the end of transmission */  

while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET)  

{  

}  

return ch;  

}
4、然后就可以正常使用printf了。
原创粉丝点击