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