uart
This commit is contained in:
parent
919203c467
commit
f63b6c2462
1 changed files with 19 additions and 0 deletions
19
uart.c
Normal file
19
uart.c
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
#include <libopencm3/stm32/usart.h>
|
||||||
|
#include <libopencm3/stm32/rcc.h>
|
||||||
|
#include <libopencm3/stm32/gpio.h>
|
||||||
|
|
||||||
|
static void usart_setup(void) {
|
||||||
|
rcc_periph_clock_enable(RCC_GPIOA);
|
||||||
|
rcc_periph_clock_enable(RCC_USART1);
|
||||||
|
|
||||||
|
// Set PA9 (TX) to alternate function, push-pull
|
||||||
|
gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_USART1_TX);
|
||||||
|
|
||||||
|
usart_set_baudrate(USART1, 115200);
|
||||||
|
usart_set_databits(USART1, 8);
|
||||||
|
usart_set_stopbits(USART1, USART_STOPBITS_1);
|
||||||
|
usart_set_mode(USART1, USART_MODE_TX);
|
||||||
|
usart_set_parity(USART1, USART_PARITY_NONE);
|
||||||
|
usart_set_flow_control(USART1, USART_FLOWCONTROL_NONE);
|
||||||
|
usart_enable(USART1);
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue