mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-21 23:35:34 +03:00
UART DMA refactor
- Add UART DMA configurability - Consolidation of DMA settings code DMA setting code for all MCUs is now in serial_uart.c - Consolidation of UART buffer UART buffers are not embedded in uartDevice[] array anymore for all MCUs. - Consolidation of HAL DMA IRQ handler - Add missing defs for DMA on UART4 for F3
This commit is contained in:
parent
9aa1a75fe0
commit
d9d878d88e
9 changed files with 421 additions and 435 deletions
|
@ -39,42 +39,13 @@
|
|||
#include "drivers/serial_uart.h"
|
||||
#include "drivers/serial_uart_impl.h"
|
||||
|
||||
#define UART_BUFFERS(n) \
|
||||
volatile uint8_t uart ## n ## RxBuffer[UART_RX_BUFFER_SIZE]; \
|
||||
volatile uint8_t uart ## n ## TxBuffer[UART_TX_BUFFER_SIZE]; struct dummy_s
|
||||
|
||||
#ifdef USE_UART1
|
||||
UART_BUFFERS(1);
|
||||
#endif
|
||||
|
||||
#ifdef USE_UART2
|
||||
UART_BUFFERS(2);
|
||||
#endif
|
||||
|
||||
#ifdef USE_UART3
|
||||
UART_BUFFERS(3);
|
||||
#endif
|
||||
|
||||
#ifdef USE_UART4
|
||||
UART_BUFFERS(4);
|
||||
#endif
|
||||
|
||||
#ifdef USE_UART5
|
||||
UART_BUFFERS(5);
|
||||
#endif
|
||||
|
||||
#ifdef USE_UART6
|
||||
UART_BUFFERS(6);
|
||||
#endif
|
||||
|
||||
#undef UART_BUFFERS
|
||||
|
||||
const uartHardware_t uartHardware[UARTDEV_COUNT] = {
|
||||
#ifdef USE_UART1
|
||||
{
|
||||
.device = UARTDEV_1,
|
||||
.reg = USART1,
|
||||
.DMAChannel = DMA_Channel_4,
|
||||
.rxDMAChannel = DMA_Channel_4,
|
||||
.txDMAChannel = DMA_Channel_4,
|
||||
#ifdef USE_UART1_RX_DMA
|
||||
.rxDMAResource = (dmaResource_t *)DMA2_Stream5,
|
||||
#endif
|
||||
|
@ -107,7 +78,8 @@ const uartHardware_t uartHardware[UARTDEV_COUNT] = {
|
|||
{
|
||||
.device = UARTDEV_2,
|
||||
.reg = USART2,
|
||||
.DMAChannel = DMA_Channel_4,
|
||||
.rxDMAChannel = DMA_Channel_4,
|
||||
.txDMAChannel = DMA_Channel_4,
|
||||
#ifdef USE_UART2_RX_DMA
|
||||
.rxDMAResource = (dmaResource_t *)DMA1_Stream5,
|
||||
#endif
|
||||
|
@ -132,7 +104,8 @@ const uartHardware_t uartHardware[UARTDEV_COUNT] = {
|
|||
{
|
||||
.device = UARTDEV_3,
|
||||
.reg = USART3,
|
||||
.DMAChannel = DMA_Channel_4,
|
||||
.rxDMAChannel = DMA_Channel_4,
|
||||
.txDMAChannel = DMA_Channel_4,
|
||||
#ifdef USE_UART3_RX_DMA
|
||||
.rxDMAResource = (dmaResource_t *)DMA1_Stream1,
|
||||
#endif
|
||||
|
@ -157,7 +130,8 @@ const uartHardware_t uartHardware[UARTDEV_COUNT] = {
|
|||
{
|
||||
.device = UARTDEV_4,
|
||||
.reg = UART4,
|
||||
.DMAChannel = DMA_Channel_4,
|
||||
.rxDMAChannel = DMA_Channel_4,
|
||||
.txDMAChannel = DMA_Channel_4,
|
||||
#ifdef USE_UART4_RX_DMA
|
||||
.rxDMAResource = (dmaResource_t *)DMA1_Stream2,
|
||||
#endif
|
||||
|
@ -182,7 +156,8 @@ const uartHardware_t uartHardware[UARTDEV_COUNT] = {
|
|||
{
|
||||
.device = UARTDEV_5,
|
||||
.reg = UART5,
|
||||
.DMAChannel = DMA_Channel_4,
|
||||
.rxDMAChannel = DMA_Channel_4,
|
||||
.txDMAChannel = DMA_Channel_4,
|
||||
#ifdef USE_UART5_RX_DMA
|
||||
.rxDMAResource = (dmaResource_t *)DMA1_Stream0,
|
||||
#endif
|
||||
|
@ -207,7 +182,8 @@ const uartHardware_t uartHardware[UARTDEV_COUNT] = {
|
|||
{
|
||||
.device = UARTDEV_6,
|
||||
.reg = USART6,
|
||||
.DMAChannel = DMA_Channel_5,
|
||||
.rxDMAChannel = DMA_Channel_5,
|
||||
.txDMAChannel = DMA_Channel_5,
|
||||
#ifdef USE_UART6_RX_DMA
|
||||
.rxDMAResource = (dmaResource_t *)DMA2_Stream1,
|
||||
#endif
|
||||
|
@ -246,7 +222,7 @@ static void handleUsartTxDma(uartPort_t *s)
|
|||
uartTryStartTxDMA(s);
|
||||
}
|
||||
|
||||
void dmaIRQHandler(dmaChannelDescriptor_t* descriptor)
|
||||
void uartDmaIrqHandler(dmaChannelDescriptor_t* descriptor)
|
||||
{
|
||||
uartPort_t *s = &(((uartDevice_t*)(descriptor->userParam))->port);
|
||||
if (DMA_GET_FLAG_STATUS(descriptor, DMA_IT_TCIF))
|
||||
|
@ -292,21 +268,9 @@ uartPort_t *serialUART(UARTDevice_e device, uint32_t baudRate, portMode_e mode,
|
|||
|
||||
s->USARTx = hardware->reg;
|
||||
|
||||
if (hardware->rxDMAResource) {
|
||||
dmaInit(dmaGetIdentifier(hardware->rxDMAResource), OWNER_SERIAL_RX, RESOURCE_INDEX(device));
|
||||
s->rxDMAChannel = hardware->DMAChannel;
|
||||
s->rxDMAResource = hardware->rxDMAResource;
|
||||
s->rxDMAPeripheralBaseAddr = (uint32_t)&s->USARTx->DR;
|
||||
}
|
||||
|
||||
if (hardware->txDMAResource) {
|
||||
const dmaIdentifier_e identifier = dmaGetIdentifier(hardware->txDMAResource);
|
||||
dmaInit(identifier, OWNER_SERIAL_TX, RESOURCE_INDEX(device));
|
||||
dmaSetHandler(identifier, dmaIRQHandler, hardware->txPriority, (uint32_t)uart);
|
||||
s->txDMAChannel = hardware->DMAChannel;
|
||||
s->txDMAResource = hardware->txDMAResource;
|
||||
s->txDMAPeripheralBaseAddr = (uint32_t)&s->USARTx->DR;
|
||||
}
|
||||
#ifdef USE_DMA
|
||||
uartConfigureDma(uart);
|
||||
#endif
|
||||
|
||||
IO_t txIO = IOGetByTag(uart->tx.pin);
|
||||
IO_t rxIO = IOGetByTag(uart->rx.pin);
|
||||
|
@ -330,7 +294,8 @@ uartPort_t *serialUART(UARTDevice_e device, uint32_t baudRate, portMode_e mode,
|
|||
}
|
||||
}
|
||||
|
||||
if (!(s->rxDMAChannel)) {
|
||||
#ifdef USE_DMA
|
||||
if (!(s->rxDMAResource)) {
|
||||
NVIC_InitTypeDef NVIC_InitStructure;
|
||||
|
||||
NVIC_InitStructure.NVIC_IRQChannel = hardware->irqn;
|
||||
|
@ -339,6 +304,7 @@ uartPort_t *serialUART(UARTDevice_e device, uint32_t baudRate, portMode_e mode,
|
|||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||
NVIC_Init(&NVIC_InitStructure);
|
||||
}
|
||||
#endif
|
||||
|
||||
return s;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue