2 * This file is part of Cleanflight.
4 * Cleanflight is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * Cleanflight is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
20 #define UART_AF(uart, af) CONCAT3(GPIO_AF, af, _ ## uart)
22 // Since serial ports can be used for any function these buffer sizes should be equal
23 // The two largest things that need to be sent are: 1, MSP responses, 2, UBLOX SVINFO packet.
25 // Size must be a power of two due to various optimizations which use 'and' instead of 'mod'
26 // Various serial routines return the buffer occupied size as uint8_t which would need to be extended in order to
27 // increase size further.
28 #define UART1_RX_BUFFER_SIZE 256
29 #define UART1_TX_BUFFER_SIZE 256
30 #define UART2_RX_BUFFER_SIZE 256
31 #define UART2_TX_BUFFER_SIZE 256
32 #define UART3_RX_BUFFER_SIZE 256
33 #define UART3_TX_BUFFER_SIZE 256
34 #define UART4_RX_BUFFER_SIZE 256
35 #define UART4_TX_BUFFER_SIZE 256
36 #define UART5_RX_BUFFER_SIZE 256
37 #define UART5_TX_BUFFER_SIZE 256
38 #define UART6_RX_BUFFER_SIZE 256
39 #define UART6_TX_BUFFER_SIZE 256
40 #define UART7_RX_BUFFER_SIZE 256
41 #define UART7_TX_BUFFER_SIZE 256
42 #define UART8_RX_BUFFER_SIZE 256
43 #define UART8_TX_BUFFER_SIZE 256
64 UART_HandleTypeDef Handle
;
66 USART_TypeDef
*USARTx
;
71 void uartGetPortPins(UARTDevice_e device
, serialPortPins_t
* pins
);
72 void uartClearIdleFlag(uartPort_t
*s
);
73 void uartConfigurePinSwap(uartPort_t
*uartPort
);
75 serialPort_t
*uartOpen(usart_type
*USARTx
, serialReceiveCallbackPtr rxCallback
, void *rxCallbackData
, uint32_t baudRate
, portMode_t mode
, portOptions_t options
);
77 serialPort_t
*uartOpen(USART_TypeDef
*USARTx
, serialReceiveCallbackPtr rxCallback
, void *rxCallbackData
, uint32_t baudRate
, portMode_t mode
, portOptions_t options
);
80 void uartWrite(serialPort_t
*instance
, uint8_t ch
);
81 uint32_t uartTotalRxBytesWaiting(const serialPort_t
*instance
);
82 uint32_t uartTotalTxBytesFree(const serialPort_t
*instance
);
83 uint8_t uartRead(serialPort_t
*instance
);
84 void uartSetBaudRate(serialPort_t
*s
, uint32_t baudRate
);
85 bool isUartTransmitBufferEmpty(const serialPort_t
*s
);