查看: 982|回复: 0
打印 上一主题 下一主题

STM32在MDK工程中使用printf函数

[复制链接]
跳转到指定楼层
沙发
发表于 2015-9-28 00:17:22 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
STM32在MDK工程中使用printf,STM32如何在MDK工程中使用printf函数?
首先,要包含头文件"stdio.h"
第二:printf()函数使用了int fputc(int ch,FILE *f)完成其功能。
要使用printf,就需要重写这个函数。
第三,在工程选项的Target里边勾选USE MicroLIB项。
fputc示例如下:
  • int fputc(int ch,FILE *f)
  • {
  • /* Place your implementation of fputc here */
  • /* e.g. write a character to the USART */
  • USART_SendData(USART1, (uint8_t) ch);
  • /* Loop until the end of transmission */
  • while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET)
  • {}
  • return ch;
  • }


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 加入因仑

本版积分规则

快速回复 返回顶部 返回列表