增加以下配置到工程里即可。
注意fputc里重定向的对象。
还有使用微库的方法,见 http://blog.sina.com.cn/s/blog_b4ce638e0102w9fw.html
//printf reconf
#pragma import(__use_no_semihosting)
struct __FILE
{
int handle;
};
FILE __stdout;
/// <summary>
/// 定义_sys_exit()以避免使用半主机模式
/// </summary>
/// <param name="x"></param>
/// <returns></returns>
_sys_exit(int x)
{
x = x;
}
int fputc(int ch, FILE *f)
{
USART_SendData(USART2, (unsigned char) ch);
while (!(USART2->SR & USART_FLAG_TXE));
return (ch);
}