
HAL 笔记1----printf 串口重定向 #ifdef __GNUC__ /* 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 #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f) #endif /* __GNUC__ */ /** * @brief Retargets the C library printf function to the USART. * @param None * @retval None */ PUTCHAR_PROTOTYPE { /* 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 替换为所需要的串口号即可 |
你需要什么然后?
为什么我粘贴进去没反应啊,huart1改成huart2了已经,也没有报错
那是默认时钟,如果希望灵活更改时钟,个人觉得还是自己在代码里进行配置的好