stm32cubeide 串口輸出


在 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;


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM