cpu_uart.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016 Freie Universität Berlin
3  * 2017 OTA keys S.A.
4  *
5  * This file is subject to the terms and conditions of the GNU Lesser
6  * General Public License v2.1. See the file LICENSE in the top level
7  * directory for more details.
8  */
9 
10 #pragma once
11 
23 #include <stdint.h>
24 
25 #include "cpu.h"
26 #include "periph/cpu_dma.h"
27 #include "periph/cpu_gpio.h"
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
36 typedef enum {
39 } uart_type_t;
40 
44 #ifndef UART_TXBUF_SIZE
45 #define UART_TXBUF_SIZE (64)
46 #endif
47 
48 #ifndef DOXYGEN
55 #define UART_INVALID_MODE (0x8000000)
56 
61 #define HAVE_UART_PARITY_T
62 typedef enum {
63  UART_PARITY_NONE = 0,
64  UART_PARITY_EVEN = USART_CR1_PCE,
65  UART_PARITY_ODD = (USART_CR1_PCE | USART_CR1_PS),
75 #define HAVE_UART_DATA_BITS_T
76 typedef enum {
79 #if defined(USART_CR1_M1)
80  UART_DATA_BITS_7 = USART_CR1_M1,
81 #else
83 #endif
84  UART_DATA_BITS_8 = 0,
92 #define HAVE_UART_STOP_BITS_T
93 typedef enum {
94  UART_STOP_BITS_1 = 0,
95  UART_STOP_BITS_2 = USART_CR2_STOP_1,
98 #endif /* ndef DOXYGEN */
99 
103 typedef struct {
104  USART_TypeDef *dev;
105  uint32_t rcc_mask;
106  gpio_t rx_pin;
107  gpio_t tx_pin;
108 #ifndef CPU_FAM_STM32F1
111 #endif
112  uint8_t bus;
113  uint8_t irqn;
114 #ifdef MODULE_PERIPH_UART_HW_FC
115  gpio_t cts_pin;
116  gpio_t rts_pin;
117 #ifndef CPU_FAM_STM32F1
118  gpio_af_t cts_af;
119  gpio_af_t rts_af;
120 #endif
121 #endif
122 #if defined(CPU_FAM_STM32L0) || defined(CPU_FAM_STM32L4) || \
123  defined(CPU_FAM_STM32WB) || defined(CPU_FAM_STM32G4) || \
124  defined(CPU_FAM_STM32L5) || defined(CPU_FAM_STM32U5) || \
125  defined(CPU_FAM_STM32MP1) || defined(CPU_FAM_STM32WL)
126  uart_type_t type;
127  uint32_t clk_src;
128 #endif
129 #ifdef MODULE_PERIPH_DMA
130  dma_t dma;
131  uint8_t dma_chan;
132 #endif
133 } uart_conf_t;
134 
135 #ifdef __cplusplus
136 }
137 #endif
138 
DMA CPU specific definitions for the STM32 family.
GPIO CPU definitions for the STM32 family.
uart_type_t
UART hardware module types.
Definition: cpu_uart.h:36
@ STM32_LPUART
STM32 Low-power UART (LPUART) module type.
Definition: cpu_uart.h:38
@ STM32_USART
STM32 USART module type.
Definition: cpu_uart.h:37
gpio_af_t
Override alternative GPIO mode options.
Definition: periph_cpu.h:165
@ UART_PARITY_SPACE
space parity
Definition: periph_cpu.h:506
@ UART_PARITY_NONE
no parity
Definition: periph_cpu.h:502
@ UART_PARITY_EVEN
even parity
Definition: periph_cpu.h:503
@ UART_PARITY_ODD
odd parity
Definition: periph_cpu.h:504
@ UART_PARITY_MARK
mark parity
Definition: periph_cpu.h:505
@ UART_STOP_BITS_2
2 stop bits
Definition: periph_cpu.h:535
@ UART_STOP_BITS_1
1 stop bit
Definition: periph_cpu.h:534
@ UART_DATA_BITS_6
6 data bits
Definition: periph_cpu.h:519
@ UART_DATA_BITS_5
5 data bits
Definition: periph_cpu.h:518
@ UART_DATA_BITS_7
7 data bits
Definition: periph_cpu.h:520
@ UART_DATA_BITS_8
8 data bits
Definition: periph_cpu.h:521
uart_type_t
UART hardware module types.
Definition: periph_cpu.h:536
uart_parity_t
Definition of possible parity modes.
Definition: periph_cpu.h:501
uart_stop_bits_t
Definition of possible stop bits lengths.
Definition: periph_cpu.h:533
#define UART_INVALID_MODE
Invalid UART mode mask.
Definition: periph_cpu.h:492
uart_data_bits_t
Definition of possible data bits lengths in a UART frame.
Definition: periph_cpu.h:517
unsigned dma_t
DMA channel type.
UART device configuration.
Definition: periph_cpu.h:217
gpio_af_t rx_af
alternate function for RX pin
Definition: cpu_uart.h:109
uint32_t rcc_mask
bit in clock enable register
Definition: cpu_uart.h:105
USART_TypeDef * dev
UART device base register address.
Definition: cpu_uart.h:104
gpio_af_t tx_af
alternate function for TX pin
Definition: cpu_uart.h:110