mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-17 05:15:25 +03:00
Configurable UART
This commit is contained in:
parent
4ee7a330d6
commit
fdfe9e8af3
15 changed files with 1617 additions and 1604 deletions
|
@ -17,10 +17,158 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
// device specific uart implementation is defined here
|
||||
// Configuration constants
|
||||
|
||||
#if defined(STM32F1)
|
||||
#define UARTDEV_COUNT_MAX 3
|
||||
#define UARTHARDWARE_PINPAIR_COUNT 3
|
||||
#ifndef UART_RX_BUFFER_SIZE
|
||||
#define UART_RX_BUFFER_SIZE 256
|
||||
#endif
|
||||
#ifndef UART_TX_BUFFER_SIZE
|
||||
#define UART_TX_BUFFER_SIZE 256
|
||||
#endif
|
||||
#elif defined(STM32F3)
|
||||
#define UARTDEV_COUNT_MAX 5
|
||||
#define UARTHARDWARE_PINPAIR_COUNT 4
|
||||
#ifndef UART_RX_BUFFER_SIZE
|
||||
#define UART_RX_BUFFER_SIZE 256
|
||||
#endif
|
||||
#ifndef UART_TX_BUFFER_SIZE
|
||||
#define UART_TX_BUFFER_SIZE 256
|
||||
#endif
|
||||
#elif defined(STM32F4)
|
||||
#define UARTDEV_COUNT_MAX 6
|
||||
#define UARTHARDWARE_PINPAIR_COUNT 4
|
||||
#ifndef UART_RX_BUFFER_SIZE
|
||||
#define UART_RX_BUFFER_SIZE 512
|
||||
#endif
|
||||
#ifndef UART_TX_BUFFER_SIZE
|
||||
#define UART_TX_BUFFER_SIZE 512
|
||||
#endif
|
||||
#elif defined(STM32F7)
|
||||
#define UARTDEV_COUNT_MAX 8
|
||||
#define UARTHARDWARE_PINPAIR_COUNT 3
|
||||
#ifndef UART_RX_BUFFER_SIZE
|
||||
#define UART_RX_BUFFER_SIZE 512
|
||||
#endif
|
||||
#ifndef UART_TX_BUFFER_SIZE
|
||||
#define UART_TX_BUFFER_SIZE 512
|
||||
#endif
|
||||
#else
|
||||
#error unknown MCU family
|
||||
#endif
|
||||
|
||||
// Count number of configured UARTs
|
||||
|
||||
#ifdef USE_UART1
|
||||
#define UARTDEV_COUNT_1 1
|
||||
#else
|
||||
#define UARTDEV_COUNT_1 0
|
||||
#endif
|
||||
|
||||
#ifdef USE_UART2
|
||||
#define UARTDEV_COUNT_2 1
|
||||
#else
|
||||
#define UARTDEV_COUNT_2 0
|
||||
#endif
|
||||
|
||||
#ifdef USE_UART3
|
||||
#define UARTDEV_COUNT_3 1
|
||||
#else
|
||||
#define UARTDEV_COUNT_3 0
|
||||
#endif
|
||||
|
||||
#ifdef USE_UART4
|
||||
#define UARTDEV_COUNT_4 1
|
||||
#else
|
||||
#define UARTDEV_COUNT_4 0
|
||||
#endif
|
||||
|
||||
#ifdef USE_UART5
|
||||
#define UARTDEV_COUNT_5 1
|
||||
#else
|
||||
#define UARTDEV_COUNT_5 0
|
||||
#endif
|
||||
|
||||
#ifdef USE_UART6
|
||||
#define UARTDEV_COUNT_6 1
|
||||
#else
|
||||
#define UARTDEV_COUNT_6 0
|
||||
#endif
|
||||
|
||||
#ifdef USE_UART7
|
||||
#define UARTDEV_COUNT_7 1
|
||||
#else
|
||||
#define UARTDEV_COUNT_7 0
|
||||
#endif
|
||||
|
||||
#ifdef USE_UART8
|
||||
#define UARTDEV_COUNT_8 1
|
||||
#else
|
||||
#define UARTDEV_COUNT_8 0
|
||||
#endif
|
||||
|
||||
#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)
|
||||
|
||||
typedef struct uartPinPair_s {
|
||||
ioTag_t rx;
|
||||
ioTag_t tx;
|
||||
} uartPinPair_t;
|
||||
|
||||
typedef struct uartHardware_s {
|
||||
UARTDevice device; // XXX Not required for full allocation
|
||||
USART_TypeDef* reg;
|
||||
#if defined(STM32F1) || defined(STM32F3)
|
||||
DMA_Channel_TypeDef *txDMAChannel;
|
||||
DMA_Channel_TypeDef *rxDMAChannel;
|
||||
#elif defined(STM32F4) || defined(STM32F7)
|
||||
uint32_t DMAChannel;
|
||||
DMA_Stream_TypeDef *txDMAStream;
|
||||
DMA_Stream_TypeDef *rxDMAStream;
|
||||
#endif
|
||||
uartPinPair_t pinPair[UARTHARDWARE_PINPAIR_COUNT];
|
||||
#if defined(STM32F7)
|
||||
uint32_t rcc_ahb1;
|
||||
rccPeriphTag_t rcc_apb2;
|
||||
rccPeriphTag_t rcc_apb1;
|
||||
#else
|
||||
rccPeriphTag_t rcc;
|
||||
#endif
|
||||
uint8_t af;
|
||||
#if defined(STM32F7)
|
||||
uint8_t txIrq;
|
||||
uint8_t rxIrq;
|
||||
#else
|
||||
uint8_t irqn;
|
||||
#endif
|
||||
uint8_t txPriority;
|
||||
uint8_t rxPriority;
|
||||
} uartHardware_t;
|
||||
|
||||
extern const uartHardware_t uartHardware[];
|
||||
|
||||
// uartDevice_t is an actual device instance.
|
||||
// XXX Instances are allocated for uarts defined by USE_UARTx atm.
|
||||
|
||||
typedef struct uartDevice_s {
|
||||
uartPort_t port;
|
||||
const uartHardware_t *hardware;
|
||||
ioTag_t rx;
|
||||
ioTag_t tx;
|
||||
volatile uint8_t rxBuffer[UART_RX_BUFFER_SIZE];
|
||||
volatile uint8_t txBuffer[UART_TX_BUFFER_SIZE];
|
||||
} uartDevice_t;
|
||||
|
||||
extern uartDevice_t uartDevice[];
|
||||
extern uartDevice_t *uartDevmap[];
|
||||
|
||||
extern const struct serialPortVTable uartVTable[];
|
||||
|
||||
void uartStartTxDMA(uartPort_t *s);
|
||||
|
||||
uartPort_t *serialUART(UARTDevice device, uint32_t baudRate, portMode_t mode, portOptions_t options);
|
||||
|
||||
void uartIrqHandler(uartPort_t *s);
|
||||
|
||||
void uartReconfigure(uartPort_t *uartPort);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue