From ae1ecf87f6b8d7c34b32af0547f118ff7697c2ef Mon Sep 17 00:00:00 2001 From: Fredrik Thulin Date: Thu, 2 Jun 2016 14:56:56 +0200 Subject: Use DMA for UART RX instead of interrupts. DMA is more efficient and less prone to miss characters than interrupts. An open question is if circular mode is really the best. If someone copy-pastes more than the RX buffer size of configuration into the CLI, we risk the DMA controller catching up with the reader and overwriting data not yet read. Since we don't have flow control back to the users terminal, we will always fail if too much data is entered before we can process it. The question is if failing to stuff new data at the end of a buffer might be better than data being overwritten - thus messing up the commands in unpredictable ways. --- stm-init.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'stm-init.c') diff --git a/stm-init.c b/stm-init.c index c8228d8..4fd9dd4 100644 --- a/stm-init.c +++ b/stm-init.c @@ -59,6 +59,9 @@ static void MX_GPIO_Init(void); static void MX_USART1_UART_Init(void); static void MX_USART2_UART_Init(void); #endif +#ifdef HAL_DMA_MODULE_ENABLED +static void MX_DMA_Init(void); +#endif #ifdef HAL_I2C_MODULE_ENABLED static void MX_I2C2_Init(void); #endif @@ -87,6 +90,9 @@ void stm_init(void) fpgacfg_access_control(ALLOW_FPGA); #endif #endif +#ifdef HAL_DMA_MODULE_ENABLED + MX_DMA_Init(); +#endif #ifdef HAL_UART_MODULE_ENABLED MX_USART1_UART_Init(); MX_USART2_UART_Init(); @@ -165,6 +171,29 @@ static void MX_GPIO_Init(void) #undef gpio_output #endif + +#ifdef HAL_DMA_MODULE_ENABLED +/** + * Enable DMA controller clock + */ +static void MX_DMA_Init(void) +{ + /* DMA controller clock enable */ + __HAL_RCC_DMA2_CLK_ENABLE(); + __HAL_RCC_DMA1_CLK_ENABLE(); + + /* DMA interrupt init */ + + /* USER UART RX */ + HAL_NVIC_SetPriority(DMA1_Stream5_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(DMA1_Stream5_IRQn); + /* MGMT UART RX */ + HAL_NVIC_SetPriority(DMA2_Stream2_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(DMA2_Stream2_IRQn); +} +#endif /* HAL_DMA_MODULE_ENABLED */ + + #ifdef HAL_I2C_MODULE_ENABLED /* I2C2 init function (external RTC chip) */ void MX_I2C2_Init(void) -- cgit v1.2.3