Use MicroLIB 一定要勾选上
print.c
/* Includes ------------------------------------------------------------------*/
#include "print.h"
#include "usart.h"
#include "stdio.h"
/* USER CODE BEGIN 0 */
#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(&huart1 , (uint8_t *)&ch, 1, 0xFFFF);
return ch;
}
/* USER CODE END 0 */
/*----------------------------------------------------------------------------*/
/* Configure GPIO */
/*----------------------------------------------------------------------------*/
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/** Configure pins as
* Analog
* Input
* Output
* EVENT_OUT
* EXTI
*/
print.h
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __print_H
#define __print_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "main.h"
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* USER CODE BEGIN Private defines */
/* USER CODE END Private defines */
/* USER CODE BEGIN Prototypes */
/* USER CODE END Prototypes */
#ifdef __cplusplus
}
#endif
#endif /*__ pinoutConfig_H */
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
主函数调用print.h
但是使用printf 函数会被警告 但是可以使用
cubemx配置的时候不需要开中断
或者直接在主函数上添加
int fputc(int c,FILE* s)
{
HAL_UART_Transmit(&huart1,(const uint8_t*)&c,1,0xFFFF );
return c;
}
一定要记得打开
头文件
#include “stdio.h”