|
HAL 笔记1----printf 串口重定向 # v: E( t5 v) ?( t) T7 [, Q2 p #ifdef __GNUC__2 s4 m. b7 x/ c# d- u6 u' { /* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf set to 'Yes') calls __io_putchar() */ #define PUTCHAR_PROTOTYPE int __io_putchar(int ch) #else! {3 }4 k3 T& f( \( |& h1 b% f #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f) #endif /* __GNUC__ */# Q8 s0 l3 z6 V* { /** * @brief Retargets the C library printf function to the USART.( B/ s" j+ l* F1 U- i0 L* @. o+ i* p * @param None8 {7 {: V3 Z6 ~5 Y3 b, T * @retval None */' f4 k3 _6 q6 x# d PUTCHAR_PROTOTYPE- K5 [# C5 R- N! T5 [ {+ s; J: {% C7 j1 w( B /* Place your implementation of fputc here */ /* e.g. write a character to the EVAL_COM1 and Loop until the end of transmission */ HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, 0xFFFF); return ch; } 这里面是putchar, getchar 类似., HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, 0xFFFF); 参数huart1 替换为所需要的串口号即可 ' Y& L% ^2 u9 l" W& Z0 j |
微信公众号
手机版
你需要什么然后?
为什么我粘贴进去没反应啊,huart1改成huart2了已经,也没有报错
那是默认时钟,如果希望灵活更改时钟,个人觉得还是自己在代码里进行配置的好