HAL庫使用printf


用stm32cubemx配置好串口功能之后,想要使用printf函數進行打印輸出的話,還需要自己添加一個重定向函數。

 1 #ifdef __GNUC__  
 2 /* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf 
 3 set to 'Yes') calls __io_putchar() */  
 4 #define PUTCHAR_PROTOTYPE int __io_putchar(int ch)  
 5 #else  
 6 #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)   
 7 #endif /* __GNUC__ */ 
 8 
 9 PUTCHAR_PROTOTYPE
10 {
11     /* Place your implementation of fputc here */
12     /* e.g. write a character to the EVAL_COM1 and Loop until the end of transmission */
13     HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, 0xFFFF); 
14 
15     return ch;
16 }

隨便找個位置定義了就可以正常使用printf函數了。


免責聲明!

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



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