1. 程式人生 > >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;
}