【STM32-代码】
STM32-代码
- ■ printf() 输出到uart1
- ■
- ■
- ■
■ printf() 输出到uart1
static UART_HandleTypeDef * g_HDebugUART = &huart1;int fputc(int c, FILE *f)
{(void)f;HAL_UART_Transmit(g_HDebugUART, (const uint8_t *)&c, 1, DEBUG_UART_TIMEOUT);return c;
}int fgetc(FILE *f)
{uint8_t ch = 0;(void)f;/* Clear the Overrun flag just before receiving the first character */__HAL_UART_CLEAR_OREFLAG(g_HDebugUART);/* Wait for reception of a character on the USART RX line and echo this* character on console */HAL_UART_Receive(g_HDebugUART, (uint8_t *)&ch, 1, HAL_MAX_DELAY);HAL_UART_Transmit(g_HDebugUART, (uint8_t *)&ch, 1, HAL_MAX_DELAY);return ch;
}