STM32 Printf函数利用标准库实现方法



/****************************************************分割线*******************************************/

// 加入以下代码。支持printf函数,则不需要选择use MicroLIB

//添加头文件

#include <stdio.h>

//添加代码

#if 1

#pragma import(__use_no_semihosting)             
//标准库需要支持函数              
struct __FILE 

int handle; 
}; 

FILE __stdout;       
//定义_sys_exit()以避免使用半主机模式
_sys_exit(int x) 

x = x; 


//重定义fput()函数。UART5:根据需求更改串口(USART1-USART3、UART4-UART5)
int fputc(int ch, FILE *f)
{
/*将printf内容发往串口*/
USART_SendData(UART5,(uint8_t)ch);
  while(USART_GetFlagStatus(UART5, USART_FLAG_TC) == RESET);
return ch;
}

#endif 


/****************************************************分割线*******************************************/

_sys_exit()函数可能出现以下警告,不用理会。编译时不会出现警告




猜你喜欢

转载自blog.csdn.net/qq_33557833/article/details/76417263