重定義fputc()函數,在STM32序列槽中實作printf():
在usart.c檔案的末尾添加如下代碼
#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(&huart1 , (uint8_t *)&ch, 1, 0xFFFF);
return ch;
}
在程式中添加printf(),就可以在PC端序列槽助手中看到列印資訊
(注:。。。換行使用\r\n。)