diff options
author | Fredrik Thulin <fredrik@thulin.net> | 2016-06-02 14:56:56 +0200 |
---|---|---|
committer | Fredrik Thulin <fredrik@thulin.net> | 2016-06-02 14:56:56 +0200 |
commit | ae1ecf87f6b8d7c34b32af0547f118ff7697c2ef (patch) | |
tree | ad7923423ba64b3a40f2646b210617340d96eaf2 /stm-init.c | |
parent | 1b3870dd4e0429e1809ce40b70a8f558ffb5df3a (diff) |
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.
Diffstat (limited to 'stm-init.c')
-rw-r--r-- | stm-init.c | 29 |
1 files changed, 29 insertions, 0 deletions
@@ -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) |