comparison l476rg/Src/usart.c @ 0:32a3b1785697

a rough draft of Hardware Abstraction Layer for C++ STM32L476RG drivers
author cin
date Thu, 12 Jan 2017 02:45:43 +0300
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:32a3b1785697
1 /**
2 ******************************************************************************
3 * File Name : USART.c
4 * Description : This file provides code for the configuration
5 * of the USART instances.
6 ******************************************************************************
7 *
8 * COPYRIGHT(c) 2017 STMicroelectronics
9 *
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.
20 *
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.
31 *
32 ******************************************************************************
33 */
34
35 /* Includes ------------------------------------------------------------------*/
36 #include "usart.h"
37
38 #include "gpio.h"
39
40 /* USER CODE BEGIN 0 */
41
42 /* USER CODE END 0 */
43
44 UART_HandleTypeDef huart2;
45
46 /* USART2 init function */
47
48 void MX_USART2_UART_Init(void)
49 {
50
51 huart2.Instance = USART2;
52 huart2.Init.BaudRate = 115200;
53 huart2.Init.WordLength = UART_WORDLENGTH_8B;
54 huart2.Init.StopBits = UART_STOPBITS_1;
55 huart2.Init.Parity = UART_PARITY_NONE;
56 huart2.Init.Mode = UART_MODE_TX_RX;
57 huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
58 huart2.Init.OverSampling = UART_OVERSAMPLING_16;
59 huart2.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
60 huart2.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
61 if (HAL_UART_Init(&huart2) != HAL_OK)
62 {
63 Error_Handler();
64 }
65
66 }
67
68 void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle)
69 {
70
71 GPIO_InitTypeDef GPIO_InitStruct;
72 if(uartHandle->Instance==USART2)
73 {
74 /* USER CODE BEGIN USART2_MspInit 0 */
75
76 /* USER CODE END USART2_MspInit 0 */
77 /* Peripheral clock enable */
78 __HAL_RCC_USART2_CLK_ENABLE();
79
80 /**USART2 GPIO Configuration
81 PA2 ------> USART2_TX
82 PA3 ------> USART2_RX
83 */
84 GPIO_InitStruct.Pin = USART_TX_Pin|USART_RX_Pin;
85 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
86 GPIO_InitStruct.Pull = GPIO_NOPULL;
87 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
88 GPIO_InitStruct.Alternate = GPIO_AF7_USART2;
89 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
90
91 /* USER CODE BEGIN USART2_MspInit 1 */
92
93 /* USER CODE END USART2_MspInit 1 */
94 }
95 }
96
97 void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle)
98 {
99
100 if(uartHandle->Instance==USART2)
101 {
102 /* USER CODE BEGIN USART2_MspDeInit 0 */
103
104 /* USER CODE END USART2_MspDeInit 0 */
105 /* Peripheral clock disable */
106 __HAL_RCC_USART2_CLK_DISABLE();
107
108 /**USART2 GPIO Configuration
109 PA2 ------> USART2_TX
110 PA3 ------> USART2_RX
111 */
112 HAL_GPIO_DeInit(GPIOA, USART_TX_Pin|USART_RX_Pin);
113
114 }
115 /* USER CODE BEGIN USART2_MspDeInit 1 */
116
117 /* USER CODE END USART2_MspDeInit 1 */
118 }
119
120 /* USER CODE BEGIN 1 */
121
122 /* USER CODE END 1 */
123
124 /**
125 * @}
126 */
127
128 /**
129 * @}
130 */
131
132 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/