Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pios_usart on F4: DMA send/receive implementation (WIP) #2032

Open
wants to merge 6 commits into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions flight/PiOS/Common/pios_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,7 @@ void PIOS_HAL_ConfigurePort(HwSharedPortTypesOptions port_type,

case HWSHARED_PORTTYPES_OPENLOG:
#if defined(PIOS_INCLUDE_OPENLOG)
usart_port_params.flags = PIOS_USART_ALLOW_TRANSMIT_DMA;
PIOS_HAL_ConfigureCom(usart_port_cfg, &usart_port_params, 0, PIOS_COM_OPENLOG_TX_BUF_LEN, com_driver, &port_driver_id);
target = &pios_com_openlog_logging_id;
#endif /* PIOS_INCLUDE_OPENLOG */
Expand Down Expand Up @@ -874,6 +875,7 @@ void PIOS_HAL_ConfigurePort(HwSharedPortTypesOptions port_type,
usart_port_params.init.USART_StopBits = USART_StopBits_2;
usart_port_params.init.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
usart_port_params.init.USART_Mode = USART_Mode_Rx;
usart_port_params.flags = PIOS_USART_ALLOW_RECEIVE_DMA;

if (port_type == HWSHARED_PORTTYPES_SBUS)
usart_port_params.rx_invert = true;
Expand Down Expand Up @@ -919,6 +921,7 @@ void PIOS_HAL_ConfigurePort(HwSharedPortTypesOptions port_type,
usart_port_params.init.USART_StopBits = USART_StopBits_1;
usart_port_params.init.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
usart_port_params.init.USART_Mode = USART_Mode_Rx;
usart_port_params.flags = PIOS_USART_ALLOW_RECEIVE_DMA;

PIOS_HAL_ConfigureSRXL(usart_port_cfg, &usart_port_params, com_driver);
}
Expand All @@ -934,6 +937,7 @@ void PIOS_HAL_ConfigurePort(HwSharedPortTypesOptions port_type,
usart_port_params.init.USART_StopBits = USART_StopBits_1;
usart_port_params.init.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
usart_port_params.init.USART_Mode = USART_Mode_Rx;
usart_port_params.flags = PIOS_USART_ALLOW_RECEIVE_DMA;

PIOS_HAL_ConfigureIBus(usart_port_cfg, &usart_port_params, com_driver);
}
Expand All @@ -949,6 +953,7 @@ void PIOS_HAL_ConfigurePort(HwSharedPortTypesOptions port_type,
usart_port_params.init.USART_StopBits = USART_StopBits_1;
usart_port_params.init.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
usart_port_params.init.USART_Mode = USART_Mode_Rx|USART_Mode_Tx;
usart_port_params.flags = PIOS_USART_ALLOW_RECEIVE_DMA | PIOS_USART_ALLOW_TRANSMIT_DMA;

PIOS_HAL_ConfigureTbsCrossfire(usart_port_cfg, &usart_port_params, com_driver);
PIOS_Modules_Enable(PIOS_MODULE_UAVOCROSSFIRETELEMETRY);
Expand Down
39 changes: 39 additions & 0 deletions flight/PiOS/STM32/inc/pios_usart_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,30 @@
#include <pios_stm32.h>
#include "pios_usart.h"

#define PIOS_USART_ALLOW_RECEIVE_DMA 0x1
#define PIOS_USART_ALLOW_TRANSMIT_DMA 0x2

extern const struct pios_com_driver pios_usart_com_driver;

#if defined(STM32F4XX)
struct pios_usart_dma_cfg {
DMA_Stream_TypeDef *stream;
DMA_InitTypeDef init;
uint32_t tcif;
NVIC_InitTypeDef irq;
};
#endif

struct pios_usart_cfg {
USART_TypeDef *regs;
uint32_t remap; /* GPIO_Remap_* */
struct stm32_gpio rx;
struct stm32_gpio tx;
struct stm32_irq irq;
#if defined(STM32F4XX)
struct pios_usart_dma_cfg *dma_send;
struct pios_usart_dma_cfg *dma_recv;
#endif
};

struct pios_usart_params {
Expand All @@ -50,11 +66,34 @@ struct pios_usart_params {
bool tx_invert;
bool rxtx_swap;
bool single_wire;
uint8_t flags;
};

extern int32_t PIOS_USART_Init(uintptr_t * usart_id, const struct pios_usart_cfg * cfg, struct pios_usart_params * params);
extern const struct pios_usart_cfg * PIOS_USART_GetConfig(uintptr_t usart_id);

#if defined(STM32F4XX)

extern void PIOS_USART_1_dmarx_irq_handler(void);
extern void PIOS_USART_1_dmatx_irq_handler(void);

extern void PIOS_USART_2_dmarx_irq_handler(void);
extern void PIOS_USART_2_dmatx_irq_handler(void);

extern void PIOS_USART_3_dmarx_irq_handler(void);
extern void PIOS_USART_3_dmatx_irq_handler(void);

extern void PIOS_USART_4_dmarx_irq_handler(void);
extern void PIOS_USART_4_dmatx_irq_handler(void);

extern void PIOS_USART_5_dmarx_irq_handler(void);
extern void PIOS_USART_5_dmatx_irq_handler(void);

extern void PIOS_USART_6_dmarx_irq_handler(void);
extern void PIOS_USART_6_dmatx_irq_handler(void);

#endif

#endif /* PIOS_USART_PRIV_H */

/**
Expand Down
Loading