2 ******************************************************************************
4 * Description : This file provides code for the configuration
5 * of the USART instances.
6 ******************************************************************************
8 * COPYRIGHT(c) 2016 STMicroelectronics
10 * Redistribution and use in source and binary forms, with or without modification,
11 * are permitted provided that the following conditions are met:
12 * 1. Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright notice,
15 * this list of conditions and the following disclaimer in the documentation
16 * and/or other materials provided with the distribution.
17 * 3. Neither the name of STMicroelectronics nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 ******************************************************************************
35 /* Includes ------------------------------------------------------------------*/
41 /* USER CODE BEGIN 0 */
45 UART_HandleTypeDef huart3
;
46 DMA_HandleTypeDef hdma_usart3_tx
;
48 /* USART3 init function */
50 void MX_USART3_UART_Init(void)
53 huart3
.Instance
= USART3
;
54 huart3
.Init
.BaudRate
= 115200;
55 huart3
.Init
.WordLength
= UART_WORDLENGTH_8B
;
56 huart3
.Init
.StopBits
= UART_STOPBITS_1
;
57 huart3
.Init
.Parity
= UART_PARITY_NONE
;
58 huart3
.Init
.Mode
= UART_MODE_TX_RX
;
59 huart3
.Init
.HwFlowCtl
= UART_HWCONTROL_NONE
;
60 huart3
.Init
.OverSampling
= UART_OVERSAMPLING_16
;
61 huart3
.Init
.OneBitSampling
= UART_ONE_BIT_SAMPLE_DISABLE
;
62 huart3
.AdvancedInit
.AdvFeatureInit
= UART_ADVFEATURE_NO_INIT
;
63 if (HAL_UART_Init(&huart3
) != HAL_OK
)
70 void HAL_UART_MspInit(UART_HandleTypeDef
* uartHandle
)
73 GPIO_InitTypeDef GPIO_InitStruct
;
74 if(uartHandle
->Instance
==USART3
)
76 /* USER CODE BEGIN USART3_MspInit 0 */
78 /* USER CODE END USART3_MspInit 0 */
79 /* Peripheral clock enable */
80 __HAL_RCC_USART3_CLK_ENABLE();
82 /**USART3 GPIO Configuration
86 GPIO_InitStruct
.Pin
= STLK_RX_Pin
|STLK_TX_Pin
;
87 GPIO_InitStruct
.Mode
= GPIO_MODE_AF_PP
;
88 GPIO_InitStruct
.Pull
= GPIO_PULLUP
;
89 GPIO_InitStruct
.Speed
= GPIO_SPEED_FREQ_VERY_HIGH
;
90 GPIO_InitStruct
.Alternate
= GPIO_AF7_USART3
;
91 HAL_GPIO_Init(GPIOD
, &GPIO_InitStruct
);
93 /* Peripheral DMA init*/
95 hdma_usart3_tx
.Instance
= DMA1_Stream3
;
96 hdma_usart3_tx
.Init
.Channel
= DMA_CHANNEL_4
;
97 hdma_usart3_tx
.Init
.Direction
= DMA_MEMORY_TO_PERIPH
;
98 hdma_usart3_tx
.Init
.PeriphInc
= DMA_PINC_DISABLE
;
99 hdma_usart3_tx
.Init
.MemInc
= DMA_MINC_ENABLE
;
100 hdma_usart3_tx
.Init
.PeriphDataAlignment
= DMA_PDATAALIGN_BYTE
;
101 hdma_usart3_tx
.Init
.MemDataAlignment
= DMA_MDATAALIGN_BYTE
;
102 hdma_usart3_tx
.Init
.Mode
= DMA_NORMAL
;
103 hdma_usart3_tx
.Init
.Priority
= DMA_PRIORITY_LOW
;
104 hdma_usart3_tx
.Init
.FIFOMode
= DMA_FIFOMODE_DISABLE
;
105 if (HAL_DMA_Init(&hdma_usart3_tx
) != HAL_OK
)
110 __HAL_LINKDMA(uartHandle
,hdmatx
,hdma_usart3_tx
);
112 /* Peripheral interrupt init */
113 HAL_NVIC_SetPriority(USART3_IRQn
, 2, 0);
114 HAL_NVIC_EnableIRQ(USART3_IRQn
);
115 /* USER CODE BEGIN USART3_MspInit 1 */
117 /* USER CODE END USART3_MspInit 1 */
121 void HAL_UART_MspDeInit(UART_HandleTypeDef
* uartHandle
)
124 if(uartHandle
->Instance
==USART3
)
126 /* USER CODE BEGIN USART3_MspDeInit 0 */
128 /* USER CODE END USART3_MspDeInit 0 */
129 /* Peripheral clock disable */
130 __HAL_RCC_USART3_CLK_DISABLE();
132 /**USART3 GPIO Configuration
133 PD8 ------> USART3_TX
134 PD9 ------> USART3_RX
136 HAL_GPIO_DeInit(GPIOD
, STLK_RX_Pin
|STLK_TX_Pin
);
138 /* Peripheral DMA DeInit*/
139 HAL_DMA_DeInit(uartHandle
->hdmatx
);
141 /* Peripheral interrupt Deinit*/
142 HAL_NVIC_DisableIRQ(USART3_IRQn
);
145 /* USER CODE BEGIN USART3_MspDeInit 1 */
147 /* USER CODE END USART3_MspDeInit 1 */
150 /* USER CODE BEGIN 1 */
152 /* USER CODE END 1 */
162 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/