STM32 printf 重定向

Options 選項里面Target選項頁 將Use MicroLIB 勾上。
為了實現重定向 printf()函數,我們需要重寫 fputc() 這個 c 標準庫函數,
因為 printf()在 c 標準庫函數中實質是一個宏,最終是調用了 fputc()這個函數
的。
int fputc(int ch, FILE *f)
{
/* 將 Printf 內容發往串口 */
USART_SendData(USART1, (unsigned char) ch);
while( USART_GetFlagStatus(USART1,USART_FLAG_TC)!= SET);
return (ch);
}
評論