IAR for STM8 printf redirected to the serial port

Article Directory


Add the following code in the main.c

#include <stdio.h>			// 包含头文件

int fputc(int ch, FILE *f)	//STM8 printf函数重定向 
{ 
	while ( (USART2->SR&0x80) == 0 );
	
	USART2->DR = (uint8_t)ch;
	
	return ch; 
} 
Published 57 original articles · won praise 64 · views 30000 +

Guess you like

Origin blog.csdn.net/qq_36310253/article/details/103107505