逆向学习物联网-感知层设计-07Usart打印重定向程序设计
1.包含头文件
#include "stdio.h"
2.添加重定向函数
/* USER CODE BEGIN 0 */
int fputc ( int ch, FILE *f )
{
/* Place your implementation of fputc here */
/* e.g. write a character to the EVAL_COM1 and Loop until the end of transmission */
HAL_UART_Transmit ( &huart1, ( uint8_t * ) &ch, 1, 0xFFFF );
return ch;
}
/* USER CODE END 0 */
3.使用实例
printf使用函数:
https://www.runoob.com/cprogramming/c-standard-library-stdio-h.html
发送函数不要用DMA,DMA只能发送一个字节,
4.添加DEBUG宏定义
#define USER_MAIN_DEBUG
#ifdef USER_MAIN_DEBUG
#define user_main_printf(format,...) printf( format"\r\n",##_VA_ARGS__)
#define user_main_info(format,...) printf("【main】 info:" format“\r\n",##_VA_ARGS_)
#define user_main_debug(format,...) printf("【main】debug:" fonrmat"\r\n",##_VA_ARGS_)
#define user_main_error(format,...) printf( "【main】error:”format“\r\n",##_VA_ARGs_)
#else
#define user_main_printf(format,...)
#define user_main_info(format,...)
#define user_main_debug(format,...)
#define user_main_error(format,...)
#endif