STM32 Printf
如何实现
STM32对printf打印输出信息的支持呢?
回帖(1)
2021-12-2 15:19:07
在软件高度过程中,使用printf打印输出信息非常方便,可通过添加以下内容实现STM32对printf的支持。
- #include
- #ifdef __GNUC__
- #define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
- #else
- #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
- #endif
- /**
- * @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 USART */
- USART_SendData(USART1, (uint8_t) ch);
-
- /* Loop until the end of transmission */
- while(USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET)
- {
- }
-
- return ch;
- }
在软件高度过程中,使用printf打印输出信息非常方便,可通过添加以下内容实现STM32对printf的支持。
- #include
- #ifdef __GNUC__
- #define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
- #else
- #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
- #endif
- /**
- * @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 USART */
- USART_SendData(USART1, (uint8_t) ch);
-
- /* Loop until the end of transmission */
- while(USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET)
- {
- }
-
- return ch;
- }
举报
更多回帖