uart: improve setup, blocking transmission, and flushing
This commit is contained in:
parent
e238b9ee6a
commit
67f161adf9
|
@ -39,6 +39,7 @@ void uart_setup(void)
|
|||
/* enable UART I/O peripheral */
|
||||
rcc_periph_clock_enable(RCC_USART_PORT(UART_ID)); // enable clock for UART port peripheral
|
||||
rcc_periph_clock_enable(RCC_USART(UART_ID)); // enable clock for UART peripheral
|
||||
rcc_periph_reset_pulse(RST_USART(UART_ID)); // reset peripheral
|
||||
rcc_periph_clock_enable(RCC_AFIO); // enable pin alternate function (UART)
|
||||
gpio_set_mode(USART_TX_PORT(UART_ID), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, USART_TX_PIN(UART_ID)); // setup GPIO pin UART transmit
|
||||
gpio_set_mode(USART_RX_PORT(UART_ID), GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, USART_RX_PIN(UART_ID)); // setup GPIO pin UART receive
|
||||
|
@ -63,8 +64,7 @@ void uart_setup(void)
|
|||
|
||||
void uart_putchar_blocking(char c)
|
||||
{
|
||||
uart_flush(); // empty buffer first
|
||||
usart_send_blocking(USART(UART_ID), c); // send character
|
||||
usart_send_blocking(USART(UART_ID), c); // send character (this already wait for the buffer to be empty)
|
||||
}
|
||||
|
||||
void uart_flush(void)
|
||||
|
@ -73,6 +73,7 @@ void uart_flush(void)
|
|||
__WFI(); // sleep until interrupt
|
||||
}
|
||||
usart_wait_send_ready(USART(UART_ID)); // wait until transmit register is empty (transmission might not be complete)
|
||||
while(!usart_get_flag(USART(UART_ID), USART_SR_TC)); // wait for transmission to be complete
|
||||
}
|
||||
|
||||
void uart_putchar_nonblocking(char c)
|
||||
|
|
Loading…
Reference in New Issue