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;
}

你可能感兴趣的:(stm32 HAL 实现printf)