uart_debug.c 源文件
#include "stm32f4xx.h"
#include "stdio.h"
int fputc(int ch, FILE *f)
{
while((USART6->SR & USART_SR_TXE) == 0){}
USART6->DR = ch;
return ch;
}
uart_debug.h 头文件
#ifndef __UART_DEBUG_H__
#define __UART_DEBUG_H__
#include "stdio.h"
#include "stdint.h"
#define USER_MAIN_DEBUG
#ifdef USER_MAIN_DEBUG
#define user_printf(format, ...) printf( format "\r\n", ##__VA_ARGS__)
#define user_info(format, ...) printf("【info】" format "\r\n", ##__VA_ARGS__)
#define user_debug(format, ...) printf("【debug】" format "\r\n", ##__VA_ARGS__)
#define user_error(format, ...) printf("【error】" format "\r\n", ##__VA_ARGS__)
#else
#define user_printf(format, ...)
#define user_info(format, ...)
#define user_debug(format, ...)
#define user_error(format, ...)
#endif
#endif //__UART_DEBUG_H__