在 main.c 中增加
/* USER CODE BEGIN Includes */
#include <stdio.h>
/* USER CODE END Includes */
/* 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(&huart5, (uint8_t *)&ch, 1, HAL_MAX_DELAY);
return ch;
}
/* USER CODE END 0 */
...main...
/* USER CODE BEGIN 2 */
printf("abc\n");
printf("a = %d\n", 100);
printf("b = %f\n", 1.23);
/* USER CODE END 2 */
注意后面需要加 "\n",不然有可能不顯示出來,或者可以用 fflush(stdout)。
浮點數需要開啟 浮點數支持,project --> properties --> c/c++ build --> setting --> tools setting --> mcu setting --> use float xxx
參考: https://www.cnblogs.com/tianxxl/p/11970459.html
http://ibotx.com/?p=198
當使用 secureCRT 進行調試的時候,"\n" 下一行不會從最左邊開始顯示。如果想要 "\n" 實現 "\r\n" 的效果,只要設置 會話選項 --> 終端 --> 仿真 --> 模式 --> 新行模式。
參考:http://www.mamicode.com/info-detail-204918.html
如果想要每個外設的配置文件放在單獨的文件里面,可以在 mx 的 project manager --> code generator --> generate periheral initialization as apair of “.c/.h” files per periheral;