stm32 HAL 实现printf

vcp 方式:

int fputc(int ch, FILE *f) 
{ 
	 while(CDC_Transmit_FS((uint8_t*)(&ch),1)!=USBD_OK){}
        return ch; 
} 

uart 方式:

#include "stdio.h"

#ifdef __GNUC__
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif 
PUTCHAR_PROTOTYPE
{
HAL_UART_Transmit(&huart2 , (uint8_t *)&ch, 1, 0xFFFF);
return ch;
}

猜你喜欢

转载自blog.csdn.net/shawn_shao/article/details/86491885