33 #include <libopencm3/stm32/gpio.h>
34 #include <libopencm3/stm32/rcc.h>
35 #include <libopencm3/stm32/usart.h>
36 #include <libopencm3/cm3/nvic.h>
96 mode |= USART_MODE_TX;
99 mode |= USART_MODE_RX;
105 if (hw_flow_control) {
190 nvic_enable_irq(IRQn);
198 #define USE_UART1_TX TRUE
201 #define USE_UART1_RX TRUE
204 #ifndef UART1_HW_FLOW_CONTROL
205 #define UART1_HW_FLOW_CONTROL FALSE
209 #define UART1_BITS UBITS_8
213 #define UART1_STOP USTOP_1
217 #define UART1_PARITY UPARITY_NO
220 void uart1_init(
void)
224 uart1.reg_addr = (
void *)USART1;
227 rcc_periph_clock_enable(RCC_USART1);
239 #if UART1_HW_FLOW_CONTROL
240 #warning "USING UART1 FLOW CONTROL. Make sure to pull down CTS if you are not connecting any flow-control-capable hardware."
254 void usart1_isr(
void) {
usart_isr(&uart1); }
263 #define USE_UART2_TX TRUE
266 #define USE_UART2_RX TRUE
269 #ifndef UART2_HW_FLOW_CONTROL
270 #define UART2_HW_FLOW_CONTROL FALSE
274 #define UART2_BITS UBITS_8
278 #define UART2_STOP USTOP_1
282 #define UART2_PARITY UPARITY_NO
285 void uart2_init(
void)
289 uart2.reg_addr = (
void *)USART2;
292 rcc_periph_clock_enable(RCC_USART2);
304 #if UART2_HW_FLOW_CONTROL && defined(STM32F4)
305 #warning "USING UART2 FLOW CONTROL. Make sure to pull down CTS if you are not connecting any flow-control-capable hardware."
319 void usart2_isr(
void) {
usart_isr(&uart2); }
328 #define USE_UART3_TX TRUE
331 #define USE_UART3_RX TRUE
334 #ifndef UART3_HW_FLOW_CONTROL
335 #define UART3_HW_FLOW_CONTROL FALSE
339 #define UART3_BITS UBITS_8
343 #define UART3_STOP USTOP_1
347 #define UART3_PARITY UPARITY_NO
350 void uart3_init(
void)
354 uart3.reg_addr = (
void *)USART3;
357 rcc_periph_clock_enable(RCC_USART3);
369 #if UART3_HW_FLOW_CONTROL && defined(STM32F4)
370 #warning "USING UART3 FLOW CONTROL. Make sure to pull down CTS if you are not connecting any flow-control-capable hardware."
384 void usart3_isr(
void) {
usart_isr(&uart3); }
393 #define USE_UART4_TX TRUE
396 #define USE_UART4_RX TRUE
400 #define UART4_BITS UBITS_8
404 #define UART4_STOP USTOP_1
408 #define UART4_PARITY UPARITY_NO
411 void uart4_init(
void)
415 uart4.reg_addr = (
void *)UART4;
418 rcc_periph_clock_enable(RCC_UART4);
436 void uart4_isr(
void) {
usart_isr(&uart4); }
445 #define USE_UART5_TX TRUE
448 #define USE_UART5_RX TRUE
452 #define UART5_BITS UBITS_8
456 #define UART5_STOP USTOP_1
460 #define UART5_PARITY UPARITY_NO
463 void uart5_init(
void)
467 uart5.reg_addr = (
void *)UART5;
470 rcc_periph_clock_enable(RCC_UART5);
488 void uart5_isr(
void) {
usart_isr(&uart5); }
493 #if USE_UART6 && defined STM32F4
497 #define USE_UART6_TX TRUE
500 #define USE_UART6_RX TRUE
503 #ifndef UART6_HW_FLOW_CONTROL
504 #define UART6_HW_FLOW_CONTROL FALSE
508 #define UART6_BITS UBITS_8
512 #define UART6_STOP USTOP_1
516 #define UART6_PARITY UPARITY_NO
519 void uart6_init(
void)
523 uart6.reg_addr = (
void *)USART6;
526 rcc_periph_clock_enable(RCC_USART6);
539 #if UART6_HW_FLOW_CONTROL
540 #warning "USING UART6 FLOW CONTROL. Make sure to pull down CTS if you are not connecting any flow-control-capable hardware."
552 void usart6_isr(
void) {
usart_isr(&uart6); }
561 #define USE_UART7_TX TRUE
564 #define USE_UART7_RX TRUE
568 #define UART7_BITS UBITS_8
572 #define UART7_STOP USTOP_1
576 #define UART7_PARITY UPARITY_NO
579 void uart7_init(
void)
583 uart7.reg_addr = (
void *)UART7;
586 rcc_periph_clock_enable(RCC_UART7);
604 void uart7_isr(
void) {
usart_isr(&uart7); }
613 #define USE_UART8_TX TRUE
616 #define USE_UART8_RX TRUE
620 #define UART8_BITS UBITS_8
624 #define UART8_STOP USTOP_1
628 #define UART8_PARITY UPARITY_NO
631 void uart8_init(
void)
635 uart8.reg_addr = (
void *)UART8;
638 rcc_periph_clock_enable(RCC_UART8);
656 void uart8_isr(
void) {
usart_isr(&uart8); }
uint8_t tx_buf[UART_TX_BUFFER_SIZE]
Transmit buffer.
uint8_t rx_buf[UART_RX_BUFFER_SIZE]
Receive buffer.
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
void uart_periph_set_baudrate(struct uart_periph *p, uint32_t baud)
Set baudrate.
volatile uint8_t tx_running
Some architecture independent helper functions for GPIOs.
#define UART_RX_BUFFER_SIZE
static void usart_isr(struct uart_periph *p)
#define UART7_GPIO_PORT_RX
void uart_periph_set_mode(struct uart_periph *p, bool tx_enabled, bool rx_enabled, bool hw_flow_control)
Set mode (not necessary, or can be set by SerialConfig)
void * reg_addr
UART Register.
#define UART3_GPIO_PORT_RX
#define UART5_GPIO_PORT_TX
#define UART6_GPIO_PORT_TX
void uart_periph_init(struct uart_periph *p)
#define UART4_GPIO_PORT_RX
#define UART6_GPIO_PORT_RX
volatile uint16_t ne_err
noise error counter
volatile uint16_t fe_err
framing error counter
void uart_put_byte(struct uart_periph *p, long fd, uint8_t data)
Uart transmit implementation.
#define UART1_GPIO_PORT_RX
void gpio_setup_pin_af(ioportid_t port, uint16_t pin, uint8_t af)
Setup a gpio for input or output with alternate function.
#define UART5_GPIO_PORT_RX
void uart_periph_set_bits_stop_parity(struct uart_periph *p, uint8_t bits, uint8_t stop, uint8_t parity)
Set parity and stop bits.
#define UART2_GPIO_PORT_RX
#define UART4_GPIO_PORT_TX
#define UART8_GPIO_PORT_RX
#define UART3_GPIO_PORT_TX
int baudrate
UART Baudrate.
#define UART_TX_BUFFER_SIZE
#define UART8_GPIO_PORT_TX
#define UART1_GPIO_PORT_TX
volatile uint16_t ore
overrun error counter
#define UART2_GPIO_PORT_TX
#define UART7_GPIO_PORT_TX
static void usart_enable_irq(uint8_t IRQn)