UART
Dependencies: BSP_DISCO_L476VG LCD_DISCO_L476VG mbed
stm32l4xx_hal_msp.c@0:7b78e040f288, 2016-10-05 (annotated)
- Committer:
- codebreaker7
- Date:
- Wed Oct 05 10:24:06 2016 +0000
- Revision:
- 0:7b78e040f288
UART
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
codebreaker7 | 0:7b78e040f288 | 1 | /** |
codebreaker7 | 0:7b78e040f288 | 2 | ****************************************************************************** |
codebreaker7 | 0:7b78e040f288 | 3 | * @file stm32l4xx_hal_msp_template.c |
codebreaker7 | 0:7b78e040f288 | 4 | * @author MCD Application Team |
codebreaker7 | 0:7b78e040f288 | 5 | * @version V1.0.0 |
codebreaker7 | 0:7b78e040f288 | 6 | * @date 26-June-2015 |
codebreaker7 | 0:7b78e040f288 | 7 | * @brief HAL MSP module. |
codebreaker7 | 0:7b78e040f288 | 8 | * This file template is located in the HAL folder and should be copied |
codebreaker7 | 0:7b78e040f288 | 9 | * to the user folder. |
codebreaker7 | 0:7b78e040f288 | 10 | * |
codebreaker7 | 0:7b78e040f288 | 11 | @verbatim |
codebreaker7 | 0:7b78e040f288 | 12 | =============================================================================== |
codebreaker7 | 0:7b78e040f288 | 13 | ##### How to use this driver ##### |
codebreaker7 | 0:7b78e040f288 | 14 | =============================================================================== |
codebreaker7 | 0:7b78e040f288 | 15 | [..] |
codebreaker7 | 0:7b78e040f288 | 16 | This file is generated automatically by MicroXplorer and eventually modified |
codebreaker7 | 0:7b78e040f288 | 17 | by the user |
codebreaker7 | 0:7b78e040f288 | 18 | |
codebreaker7 | 0:7b78e040f288 | 19 | @endverbatim |
codebreaker7 | 0:7b78e040f288 | 20 | ****************************************************************************** |
codebreaker7 | 0:7b78e040f288 | 21 | * @attention |
codebreaker7 | 0:7b78e040f288 | 22 | * |
codebreaker7 | 0:7b78e040f288 | 23 | * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> |
codebreaker7 | 0:7b78e040f288 | 24 | * |
codebreaker7 | 0:7b78e040f288 | 25 | * Redistribution and use in source and binary forms, with or without modification, |
codebreaker7 | 0:7b78e040f288 | 26 | * are permitted provided that the following conditions are met: |
codebreaker7 | 0:7b78e040f288 | 27 | * 1. Redistributions of source code must retain the above copyright notice, |
codebreaker7 | 0:7b78e040f288 | 28 | * this list of conditions and the following disclaimer. |
codebreaker7 | 0:7b78e040f288 | 29 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
codebreaker7 | 0:7b78e040f288 | 30 | * this list of conditions and the following disclaimer in the documentation |
codebreaker7 | 0:7b78e040f288 | 31 | * and/or other materials provided with the distribution. |
codebreaker7 | 0:7b78e040f288 | 32 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
codebreaker7 | 0:7b78e040f288 | 33 | * may be used to endorse or promote products derived from this software |
codebreaker7 | 0:7b78e040f288 | 34 | * without specific prior written permission. |
codebreaker7 | 0:7b78e040f288 | 35 | * |
codebreaker7 | 0:7b78e040f288 | 36 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
codebreaker7 | 0:7b78e040f288 | 37 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
codebreaker7 | 0:7b78e040f288 | 38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
codebreaker7 | 0:7b78e040f288 | 39 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
codebreaker7 | 0:7b78e040f288 | 40 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
codebreaker7 | 0:7b78e040f288 | 41 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
codebreaker7 | 0:7b78e040f288 | 42 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
codebreaker7 | 0:7b78e040f288 | 43 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
codebreaker7 | 0:7b78e040f288 | 44 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
codebreaker7 | 0:7b78e040f288 | 45 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
codebreaker7 | 0:7b78e040f288 | 46 | * |
codebreaker7 | 0:7b78e040f288 | 47 | ****************************************************************************** |
codebreaker7 | 0:7b78e040f288 | 48 | */ |
codebreaker7 | 0:7b78e040f288 | 49 | |
codebreaker7 | 0:7b78e040f288 | 50 | /* Includes ------------------------------------------------------------------*/ |
codebreaker7 | 0:7b78e040f288 | 51 | #include "stm32l4xx_hal.h" |
codebreaker7 | 0:7b78e040f288 | 52 | #include "main.h" |
codebreaker7 | 0:7b78e040f288 | 53 | |
codebreaker7 | 0:7b78e040f288 | 54 | /** @addtogroup STM32L4xx_HAL_Driver |
codebreaker7 | 0:7b78e040f288 | 55 | * @{ |
codebreaker7 | 0:7b78e040f288 | 56 | */ |
codebreaker7 | 0:7b78e040f288 | 57 | |
codebreaker7 | 0:7b78e040f288 | 58 | /** @defgroup HAL_MSP HAL MSP module driver |
codebreaker7 | 0:7b78e040f288 | 59 | * @brief HAL MSP module. |
codebreaker7 | 0:7b78e040f288 | 60 | * @{ |
codebreaker7 | 0:7b78e040f288 | 61 | */ |
codebreaker7 | 0:7b78e040f288 | 62 | |
codebreaker7 | 0:7b78e040f288 | 63 | /* Private typedef -----------------------------------------------------------*/ |
codebreaker7 | 0:7b78e040f288 | 64 | /* Private define ------------------------------------------------------------*/ |
codebreaker7 | 0:7b78e040f288 | 65 | /* Private macro -------------------------------------------------------------*/ |
codebreaker7 | 0:7b78e040f288 | 66 | /* Private variables ---------------------------------------------------------*/ |
codebreaker7 | 0:7b78e040f288 | 67 | /* Private function prototypes -----------------------------------------------*/ |
codebreaker7 | 0:7b78e040f288 | 68 | /* Private functions ---------------------------------------------------------*/ |
codebreaker7 | 0:7b78e040f288 | 69 | |
codebreaker7 | 0:7b78e040f288 | 70 | /** @defgroup HAL_MSP_Private_Functions |
codebreaker7 | 0:7b78e040f288 | 71 | * @{ |
codebreaker7 | 0:7b78e040f288 | 72 | */ |
codebreaker7 | 0:7b78e040f288 | 73 | |
codebreaker7 | 0:7b78e040f288 | 74 | /** |
codebreaker7 | 0:7b78e040f288 | 75 | * @brief Initialize the Global MSP. |
codebreaker7 | 0:7b78e040f288 | 76 | * @param None |
codebreaker7 | 0:7b78e040f288 | 77 | * @retval None |
codebreaker7 | 0:7b78e040f288 | 78 | */ |
codebreaker7 | 0:7b78e040f288 | 79 | //void HAL_MspInit(void) |
codebreaker7 | 0:7b78e040f288 | 80 | //{ |
codebreaker7 | 0:7b78e040f288 | 81 | /* NOTE : This function is generated automatically by STM32CubeMX and eventually |
codebreaker7 | 0:7b78e040f288 | 82 | modified by the user |
codebreaker7 | 0:7b78e040f288 | 83 | */ |
codebreaker7 | 0:7b78e040f288 | 84 | //} |
codebreaker7 | 0:7b78e040f288 | 85 | |
codebreaker7 | 0:7b78e040f288 | 86 | /** |
codebreaker7 | 0:7b78e040f288 | 87 | * @brief DeInitialize the Global MSP. |
codebreaker7 | 0:7b78e040f288 | 88 | * @param None |
codebreaker7 | 0:7b78e040f288 | 89 | * @retval None |
codebreaker7 | 0:7b78e040f288 | 90 | */ |
codebreaker7 | 0:7b78e040f288 | 91 | //void HAL_MspDeInit(void) |
codebreaker7 | 0:7b78e040f288 | 92 | //{ |
codebreaker7 | 0:7b78e040f288 | 93 | /* NOTE : This function is generated automatically by STM32CubeMX and eventually |
codebreaker7 | 0:7b78e040f288 | 94 | modified by the user |
codebreaker7 | 0:7b78e040f288 | 95 | */ |
codebreaker7 | 0:7b78e040f288 | 96 | //} |
codebreaker7 | 0:7b78e040f288 | 97 | |
codebreaker7 | 0:7b78e040f288 | 98 | /** |
codebreaker7 | 0:7b78e040f288 | 99 | * @brief Initialize the PPP MSP. |
codebreaker7 | 0:7b78e040f288 | 100 | * @param None |
codebreaker7 | 0:7b78e040f288 | 101 | * @retval None |
codebreaker7 | 0:7b78e040f288 | 102 | */ |
codebreaker7 | 0:7b78e040f288 | 103 | void HAL_UART_MspInit(UART_HandleTypeDef * usart) |
codebreaker7 | 0:7b78e040f288 | 104 | { |
codebreaker7 | 0:7b78e040f288 | 105 | static DMA_HandleTypeDef hdma_tx; |
codebreaker7 | 0:7b78e040f288 | 106 | static DMA_HandleTypeDef hdma_rx; |
codebreaker7 | 0:7b78e040f288 | 107 | |
codebreaker7 | 0:7b78e040f288 | 108 | GPIO_InitTypeDef GPIO_InitStruct; |
codebreaker7 | 0:7b78e040f288 | 109 | |
codebreaker7 | 0:7b78e040f288 | 110 | /*##-1- Enable peripherals and GPIO Clocks #################################*/ |
codebreaker7 | 0:7b78e040f288 | 111 | /* Enable GPIO TX/RX clock */ |
codebreaker7 | 0:7b78e040f288 | 112 | USARTx_TX_GPIO_CLK_ENABLE(); |
codebreaker7 | 0:7b78e040f288 | 113 | USARTx_RX_GPIO_CLK_ENABLE(); |
codebreaker7 | 0:7b78e040f288 | 114 | |
codebreaker7 | 0:7b78e040f288 | 115 | |
codebreaker7 | 0:7b78e040f288 | 116 | /* Enable USARTx clock */ |
codebreaker7 | 0:7b78e040f288 | 117 | USARTx_CLK_ENABLE(); |
codebreaker7 | 0:7b78e040f288 | 118 | |
codebreaker7 | 0:7b78e040f288 | 119 | __HAL_RCC_DMA1_CLK_ENABLE(); |
codebreaker7 | 0:7b78e040f288 | 120 | |
codebreaker7 | 0:7b78e040f288 | 121 | /*##-2- Configure peripheral GPIO ##########################################*/ |
codebreaker7 | 0:7b78e040f288 | 122 | /* UART TX GPIO pin configuration */ |
codebreaker7 | 0:7b78e040f288 | 123 | GPIO_InitStruct.Pin = USARTx_TX_PIN; |
codebreaker7 | 0:7b78e040f288 | 124 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; |
codebreaker7 | 0:7b78e040f288 | 125 | GPIO_InitStruct.Pull = GPIO_PULLUP; |
codebreaker7 | 0:7b78e040f288 | 126 | GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; |
codebreaker7 | 0:7b78e040f288 | 127 | GPIO_InitStruct.Alternate = USARTx_TX_AF; |
codebreaker7 | 0:7b78e040f288 | 128 | |
codebreaker7 | 0:7b78e040f288 | 129 | HAL_GPIO_Init(USARTx_TX_GPIO_PORT, &GPIO_InitStruct); |
codebreaker7 | 0:7b78e040f288 | 130 | |
codebreaker7 | 0:7b78e040f288 | 131 | /* UART RX GPIO pin configuration */ |
codebreaker7 | 0:7b78e040f288 | 132 | GPIO_InitStruct.Pin = USARTx_RX_PIN; |
codebreaker7 | 0:7b78e040f288 | 133 | GPIO_InitStruct.Alternate = USARTx_RX_AF; |
codebreaker7 | 0:7b78e040f288 | 134 | |
codebreaker7 | 0:7b78e040f288 | 135 | HAL_GPIO_Init(USARTx_RX_GPIO_PORT, &GPIO_InitStruct); |
codebreaker7 | 0:7b78e040f288 | 136 | |
codebreaker7 | 0:7b78e040f288 | 137 | hdma_tx.Instance = DMA1_Channel4; |
codebreaker7 | 0:7b78e040f288 | 138 | hdma_tx.Init.Direction = DMA_MEMORY_TO_PERIPH; |
codebreaker7 | 0:7b78e040f288 | 139 | hdma_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; |
codebreaker7 | 0:7b78e040f288 | 140 | hdma_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE; |
codebreaker7 | 0:7b78e040f288 | 141 | hdma_tx.Init.MemInc = DMA_MINC_ENABLE; |
codebreaker7 | 0:7b78e040f288 | 142 | hdma_tx.Init.PeriphInc = DMA_PINC_DISABLE; |
codebreaker7 | 0:7b78e040f288 | 143 | hdma_tx.Init.Mode = DMA_NORMAL; |
codebreaker7 | 0:7b78e040f288 | 144 | hdma_tx.Init.Priority = DMA_PRIORITY_LOW; |
codebreaker7 | 0:7b78e040f288 | 145 | hdma_tx.Init.Request = DMA_REQUEST_2; |
codebreaker7 | 0:7b78e040f288 | 146 | |
codebreaker7 | 0:7b78e040f288 | 147 | HAL_DMA_Init(&hdma_tx); |
codebreaker7 | 0:7b78e040f288 | 148 | |
codebreaker7 | 0:7b78e040f288 | 149 | hdma_rx.Instance = DMA1_Channel5; |
codebreaker7 | 0:7b78e040f288 | 150 | hdma_rx.Init.Direction = DMA_PERIPH_TO_MEMORY; |
codebreaker7 | 0:7b78e040f288 | 151 | hdma_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; |
codebreaker7 | 0:7b78e040f288 | 152 | hdma_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE; |
codebreaker7 | 0:7b78e040f288 | 153 | hdma_rx.Init.MemInc = DMA_MINC_ENABLE; |
codebreaker7 | 0:7b78e040f288 | 154 | hdma_rx.Init.PeriphInc = DMA_PINC_DISABLE; |
codebreaker7 | 0:7b78e040f288 | 155 | hdma_rx.Init.Mode = DMA_NORMAL; |
codebreaker7 | 0:7b78e040f288 | 156 | hdma_rx.Init.Priority = DMA_PRIORITY_LOW; |
codebreaker7 | 0:7b78e040f288 | 157 | hdma_rx.Init.Request = DMA_REQUEST_2; |
codebreaker7 | 0:7b78e040f288 | 158 | |
codebreaker7 | 0:7b78e040f288 | 159 | HAL_DMA_Init(&hdma_rx); |
codebreaker7 | 0:7b78e040f288 | 160 | |
codebreaker7 | 0:7b78e040f288 | 161 | __HAL_LINKDMA(usart, hdmatx, hdma_tx); |
codebreaker7 | 0:7b78e040f288 | 162 | //__HAL_LINKDMA(usart, hdmarx, hdma_rx); |
codebreaker7 | 0:7b78e040f288 | 163 | |
codebreaker7 | 0:7b78e040f288 | 164 | HAL_NVIC_SetPriority(USART1_IRQn, 1, 1); |
codebreaker7 | 0:7b78e040f288 | 165 | HAL_NVIC_EnableIRQ(USART1_IRQn); |
codebreaker7 | 0:7b78e040f288 | 166 | |
codebreaker7 | 0:7b78e040f288 | 167 | HAL_NVIC_SetPriority(DMA1_Channel4_IRQn, 2, 2); |
codebreaker7 | 0:7b78e040f288 | 168 | HAL_NVIC_EnableIRQ(DMA1_Channel4_IRQn); |
codebreaker7 | 0:7b78e040f288 | 169 | |
codebreaker7 | 0:7b78e040f288 | 170 | //HAL_NVIC_SetPriority(DMA1_Channel5_IRQn, 1, 1); |
codebreaker7 | 0:7b78e040f288 | 171 | //HAL_NVIC_EnableIRQ(DMA1_Channel5_IRQn); |
codebreaker7 | 0:7b78e040f288 | 172 | } |
codebreaker7 | 0:7b78e040f288 | 173 | |
codebreaker7 | 0:7b78e040f288 | 174 | /** |
codebreaker7 | 0:7b78e040f288 | 175 | * @brief DeInitialize the PPP MSP. |
codebreaker7 | 0:7b78e040f288 | 176 | * @param None |
codebreaker7 | 0:7b78e040f288 | 177 | * @retval None |
codebreaker7 | 0:7b78e040f288 | 178 | */ |
codebreaker7 | 0:7b78e040f288 | 179 | void HAL_UART_MspDeInit(UART_HandleTypeDef *husart) |
codebreaker7 | 0:7b78e040f288 | 180 | { |
codebreaker7 | 0:7b78e040f288 | 181 | HAL_GPIO_DeInit(GPIOA, GPIO_PIN_2); |
codebreaker7 | 0:7b78e040f288 | 182 | HAL_GPIO_DeInit(GPIOA, GPIO_PIN_3); |
codebreaker7 | 0:7b78e040f288 | 183 | } |
codebreaker7 | 0:7b78e040f288 | 184 | |
codebreaker7 | 0:7b78e040f288 | 185 | /** |
codebreaker7 | 0:7b78e040f288 | 186 | * @} |
codebreaker7 | 0:7b78e040f288 | 187 | */ |
codebreaker7 | 0:7b78e040f288 | 188 | |
codebreaker7 | 0:7b78e040f288 | 189 | /** |
codebreaker7 | 0:7b78e040f288 | 190 | * @} |
codebreaker7 | 0:7b78e040f288 | 191 | */ |
codebreaker7 | 0:7b78e040f288 | 192 | |
codebreaker7 | 0:7b78e040f288 | 193 | /** |
codebreaker7 | 0:7b78e040f288 | 194 | * @} |
codebreaker7 | 0:7b78e040f288 | 195 | */ |
codebreaker7 | 0:7b78e040f288 | 196 | |
codebreaker7 | 0:7b78e040f288 | 197 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
codebreaker7 | 0:7b78e040f288 | 198 |