2 * This file is part of Cleanflight and Betaflight.
4 * Cleanflight and Betaflight are free software. You can redistribute
5 * this software and/or modify this software under the terms of the
6 * GNU General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option)
10 * Cleanflight and Betaflight are distributed in the hope that they
11 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this software.
18 * If not, see <http://www.gnu.org/licenses/>.
23 // Configuration constants
26 #define UARTDEV_COUNT_MAX 3
27 #define UARTHARDWARE_MAX_PINS 3
28 #ifndef UART_RX_BUFFER_SIZE
29 #define UART_RX_BUFFER_SIZE 128
31 #ifndef UART_TX_BUFFER_SIZE
32 #define UART_TX_BUFFER_SIZE 128
34 #elif defined(STM32F3)
35 #define UARTDEV_COUNT_MAX 5
36 #define UARTHARDWARE_MAX_PINS 4
37 #ifndef UART_RX_BUFFER_SIZE
38 #define UART_RX_BUFFER_SIZE 128
40 #ifndef UART_TX_BUFFER_SIZE
41 #define UART_TX_BUFFER_SIZE 128
43 #elif defined(STM32F4)
44 #define UARTDEV_COUNT_MAX 6
45 #define UARTHARDWARE_MAX_PINS 4
46 #ifndef UART_RX_BUFFER_SIZE
47 #define UART_RX_BUFFER_SIZE 128
49 #ifndef UART_TX_BUFFER_SIZE
50 #define UART_TX_BUFFER_SIZE 128
52 #elif defined(STM32F7)
53 #define UARTDEV_COUNT_MAX 8
54 #define UARTHARDWARE_MAX_PINS 3
55 #ifndef UART_RX_BUFFER_SIZE
56 #define UART_RX_BUFFER_SIZE 128
58 #ifndef UART_TX_BUFFER_SIZE
59 #define UART_TX_BUFFER_SIZE 128
62 #error unknown MCU family
65 // Count number of configured UARTs
68 #define UARTDEV_COUNT_1 1
70 #define UARTDEV_COUNT_1 0
74 #define UARTDEV_COUNT_2 1
76 #define UARTDEV_COUNT_2 0
80 #define UARTDEV_COUNT_3 1
82 #define UARTDEV_COUNT_3 0
86 #define UARTDEV_COUNT_4 1
88 #define UARTDEV_COUNT_4 0
92 #define UARTDEV_COUNT_5 1
94 #define UARTDEV_COUNT_5 0
98 #define UARTDEV_COUNT_6 1
100 #define UARTDEV_COUNT_6 0
104 #define UARTDEV_COUNT_7 1
106 #define UARTDEV_COUNT_7 0
110 #define UARTDEV_COUNT_8 1
112 #define UARTDEV_COUNT_8 0
115 #define UARTDEV_COUNT (UARTDEV_COUNT_1 + UARTDEV_COUNT_2 + UARTDEV_COUNT_3 + UARTDEV_COUNT_4 + UARTDEV_COUNT_5 + UARTDEV_COUNT_6 + UARTDEV_COUNT_7 + UARTDEV_COUNT_8)
117 typedef struct uartHardware_s
{
118 UARTDevice_e device
; // XXX Not required for full allocation
120 #if defined(STM32F1) || defined(STM32F3)
121 DMA_Channel_TypeDef
*txDMAChannel
;
122 DMA_Channel_TypeDef
*rxDMAChannel
;
123 #elif defined(STM32F4) || defined(STM32F7)
125 DMA_Stream_TypeDef
*txDMAStream
;
126 DMA_Stream_TypeDef
*rxDMAStream
;
128 ioTag_t rxPins
[UARTHARDWARE_MAX_PINS
];
129 ioTag_t txPins
[UARTHARDWARE_MAX_PINS
];
132 rccPeriphTag_t rcc_apb2
;
133 rccPeriphTag_t rcc_apb1
;
148 extern const uartHardware_t uartHardware
[];
150 // uartDevice_t is an actual device instance.
151 // XXX Instances are allocated for uarts defined by USE_UARTx atm.
153 typedef struct uartDevice_s
{
155 const uartHardware_t
*hardware
;
158 volatile uint8_t rxBuffer
[UART_RX_BUFFER_SIZE
];
159 volatile uint8_t txBuffer
[UART_TX_BUFFER_SIZE
];
162 extern uartDevice_t
*uartDevmap
[];
164 extern const struct serialPortVTable uartVTable
[];
166 #ifdef USE_HAL_DRIVER
167 void uartStartTxDMA(uartPort_t
*s
);
169 void uartTryStartTxDMA(uartPort_t
*s
);
172 uartPort_t
*serialUART(UARTDevice_e device
, uint32_t baudRate
, portMode_e mode
, portOptions_e options
);
174 void uartIrqHandler(uartPort_t
*s
);
176 void uartReconfigure(uartPort_t
*uartPort
);