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