diff options
author | Paul Selkirk <paul@psgd.org> | 2016-06-06 12:03:24 -0400 |
---|---|---|
committer | Paul Selkirk <paul@psgd.org> | 2016-06-06 12:03:24 -0400 |
commit | b37cbe6a58367c9ecaf732e05f445230c64a6b08 (patch) | |
tree | 5a1f845733e9d557a1f72efe595384bdfeeb4d7e | |
parent | 77fc19698b46cfb33b6cc60bc26413a1c0f93ab5 (diff) |
Refactor HAL_UART_MspInit, link DMA in MX_USART*_UART_Init so HAL_UART_MspInit doesn't have to.
-rw-r--r-- | libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F4/TARGET_CRYPTECH_ALPHA/stm32f4xx_hal_msp.c | 95 | ||||
-rw-r--r-- | stm-init.c | 8 |
2 files changed, 50 insertions, 53 deletions
diff --git a/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F4/TARGET_CRYPTECH_ALPHA/stm32f4xx_hal_msp.c b/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F4/TARGET_CRYPTECH_ALPHA/stm32f4xx_hal_msp.c index 4f3b68d..b46b158 100644 --- a/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F4/TARGET_CRYPTECH_ALPHA/stm32f4xx_hal_msp.c +++ b/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F4/TARGET_CRYPTECH_ALPHA/stm32f4xx_hal_msp.c @@ -33,7 +33,6 @@ */ /* Includes ------------------------------------------------------------------*/ #include "stm32f4xx_hal.h" -#include "stm-uart.h" /** @@ -113,10 +112,11 @@ void HAL_SDRAM_MspDeInit(SDRAM_HandleTypeDef* hsdram) { } - void HAL_UART_MspInit(UART_HandleTypeDef* huart) { GPIO_InitTypeDef GPIO_InitStruct; + IRQn_Type IRQn; + DMA_Stream_TypeDef *hdma_instance; if (huart->Instance == USART1) { /* This is huart_mgmt (USER_MGMT) */ @@ -130,38 +130,15 @@ void HAL_UART_MspInit(UART_HandleTypeDef* huart) PA10 ------> USART1_RX */ GPIO_InitStruct.Pin = GPIO_PIN_9 | GPIO_PIN_10; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_PULLUP; - GPIO_InitStruct.Speed = GPIO_SPEED_LOW; GPIO_InitStruct.Alternate = GPIO_AF7_USART1; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - HAL_NVIC_SetPriority(USART1_IRQn, 0, 1); - HAL_NVIC_EnableIRQ(USART1_IRQn); + IRQn = USART1_IRQn; /* Peripheral DMA init*/ - hdma_usart_mgmt_rx.Instance = DMA2_Stream2; - hdma_usart_mgmt_rx.Init.Channel = DMA_CHANNEL_4; - hdma_usart_mgmt_rx.Init.Direction = DMA_PERIPH_TO_MEMORY; - hdma_usart_mgmt_rx.Init.PeriphInc = DMA_PINC_DISABLE; - hdma_usart_mgmt_rx.Init.MemInc = DMA_MINC_ENABLE; - hdma_usart_mgmt_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE; - hdma_usart_mgmt_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; - hdma_usart_mgmt_rx.Init.Mode = DMA_CIRCULAR; - hdma_usart_mgmt_rx.Init.Priority = DMA_PRIORITY_LOW; - hdma_usart_mgmt_rx.Init.FIFOMode = DMA_FIFOMODE_DISABLE; - /* - hdma_usart_mgmt_rx.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_HALFFULL; - hdma_usart_mgmt_rx.Init.MemBurst = DMA_MBURST_SINGLE; - hdma_usart_mgmt_rx.Init.PeriphBurst = DMA_PBURST_SINGLE; - */ - if (HAL_DMA_Init(&hdma_usart_mgmt_rx) != HAL_OK) { - Error_Handler(); - } - - __HAL_LINKDMA(huart, hdmarx, hdma_usart_mgmt_rx); - - } else if (huart->Instance == USART2) { + hdma_instance = DMA2_Stream2; + } + + else if (huart->Instance == USART2) { /* This is huart_user (USER UART) */ /* Peripheral clock enable */ @@ -173,36 +150,48 @@ void HAL_UART_MspInit(UART_HandleTypeDef* huart) PA3 ------> USART2_RX */ GPIO_InitStruct.Pin = GPIO_PIN_2 | GPIO_PIN_3; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_PULLUP; - GPIO_InitStruct.Speed = GPIO_SPEED_LOW; GPIO_InitStruct.Alternate = GPIO_AF7_USART2; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - HAL_NVIC_SetPriority(USART2_IRQn, 0, 1); - HAL_NVIC_EnableIRQ(USART2_IRQn); + IRQn = USART2_IRQn; /* Peripheral DMA init*/ - hdma_usart_user_rx.Instance = DMA1_Stream5; - hdma_usart_user_rx.Init.Channel = DMA_CHANNEL_4; - hdma_usart_user_rx.Init.Direction = DMA_PERIPH_TO_MEMORY; - hdma_usart_user_rx.Init.PeriphInc = DMA_PINC_DISABLE; - hdma_usart_user_rx.Init.MemInc = DMA_MINC_ENABLE; - hdma_usart_user_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE; - hdma_usart_user_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; - hdma_usart_user_rx.Init.Mode = DMA_CIRCULAR; - hdma_usart_user_rx.Init.Priority = DMA_PRIORITY_LOW; - hdma_usart_user_rx.Init.FIFOMode = DMA_FIFOMODE_DISABLE; + hdma_instance = DMA1_Stream5; + } + + else { + return; + } + + /* common setup */ + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_PULLUP; + GPIO_InitStruct.Speed = GPIO_SPEED_LOW; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + HAL_NVIC_SetPriority(IRQn, 0, 1); + HAL_NVIC_EnableIRQ(IRQn); + + /* Peripheral DMA init*/ + DMA_HandleTypeDef *hdma = huart->hdmarx; + if (hdma != NULL) { + hdma->Instance = hdma_instance; + hdma->Init.Channel = DMA_CHANNEL_4; + hdma->Init.Direction = DMA_PERIPH_TO_MEMORY; + hdma->Init.PeriphInc = DMA_PINC_DISABLE; + hdma->Init.MemInc = DMA_MINC_ENABLE; + hdma->Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE; + hdma->Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; + hdma->Init.Mode = DMA_CIRCULAR; + hdma->Init.Priority = DMA_PRIORITY_LOW; + hdma->Init.FIFOMode = DMA_FIFOMODE_DISABLE; /* - hdma_usart_user_rx.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_HALFFULL; - hdma_usart_user_rx.Init.MemBurst = DMA_MBURST_SINGLE; - hdma_usart_user_rx.Init.PeriphBurst = DMA_PBURST_SINGLE; + hdma->Init.FIFOThreshold = DMA_FIFO_THRESHOLD_HALFFULL; + hdma->Init.MemBurst = DMA_MBURST_SINGLE; + hdma->Init.PeriphBurst = DMA_PBURST_SINGLE; */ - if (HAL_DMA_Init(&hdma_usart_user_rx) != HAL_OK) { - Error_Handler(); + if (HAL_DMA_Init(hdma) != HAL_OK) { + mbed_die(); } - - __HAL_LINKDMA(huart, hdmarx, hdma_usart_user_rx); } } @@ -120,6 +120,10 @@ static void MX_USART1_UART_Init(void) huart_mgmt.Init.HwFlowCtl = UART_HWCONTROL_RTS_CTS; huart_mgmt.Init.OverSampling = UART_OVERSAMPLING_16; +#ifdef HAL_DMA_MODULE_ENABLED + __HAL_LINKDMA(&huart_mgmt, hdmarx, hdma_usart_mgmt_rx); +#endif + if (HAL_UART_Init(&huart_mgmt) != HAL_OK) { /* Initialization Error */ Error_Handler(); @@ -137,6 +141,10 @@ static void MX_USART2_UART_Init(void) huart_user.Init.HwFlowCtl = UART_HWCONTROL_RTS_CTS; huart_user.Init.OverSampling = UART_OVERSAMPLING_16; +#ifdef HAL_DMA_MODULE_ENABLED + __HAL_LINKDMA(&huart_user, hdmarx, hdma_usart_user_rx); +#endif + if (HAL_UART_Init(&huart_user) != HAL_OK) { /* Initialization Error */ Error_Handler(); |