1 /* USER CODE BEGIN Header */ 2 /** 3 ****************************************************************************** 4 * @file stm32wlxx_hal_msp.c 5 * @brief This file provides code for the MSP Initialization 6 * and de-Initialization codes. 7 ****************************************************************************** 8 * @attention 9 * 10 * <h2><center>© Copyright (c) 2021 STMicroelectronics. 11 * All rights reserved.</center></h2> 12 * 13 * This software component is licensed by ST under BSD 3-Clause license, 14 * the "License"; You may not use this file except in compliance with the 15 * License. You may obtain a copy of the License at: 16 * opensource.org/licenses/BSD-3-Clause 17 * 18 ****************************************************************************** 19 */ 20 /* USER CODE END Header */ 21 22 /* Includes ------------------------------------------------------------------*/ 23 #include "main.h" 24 /* USER CODE BEGIN Includes */ 25 #include <drv_common.h> 26 /* USER CODE END Includes */ 27 28 /* Private typedef -----------------------------------------------------------*/ 29 /* USER CODE BEGIN TD */ 30 /* USER CODE END TD */ 31 32 /* Private define ------------------------------------------------------------*/ 33 /* USER CODE BEGIN Define */ 34 /* USER CODE END Define */ 35 36 /* Private macro -------------------------------------------------------------*/ 37 /* USER CODE BEGIN Macro */ 38 /* USER CODE END Macro */ 39 40 /* Private variables ---------------------------------------------------------*/ 41 /* USER CODE BEGIN PV */ 42 /* USER CODE END PV */ 43 44 /* Private function prototypes -----------------------------------------------*/ 45 /* USER CODE BEGIN PFP */ 46 47 /* USER CODE END PFP */ 48 49 /* External functions --------------------------------------------------------*/ 50 /* USER CODE BEGIN ExternalFunctions */ 51 52 /* USER CODE END ExternalFunctions */ 53 54 /* USER CODE BEGIN 0 */ 55 56 /* USER CODE END 0 */ 57 /** 58 * Initializes the Global MSP. 59 */ HAL_MspInit(void)60void HAL_MspInit(void) 61 { 62 /* USER CODE BEGIN MspInit 0 */ 63 64 /* USER CODE END MspInit 0 */ 65 66 /* System interrupt init*/ 67 68 /* USER CODE BEGIN MspInit 1 */ 69 70 /* USER CODE END MspInit 1 */ 71 } 72 73 /** 74 * @brief UART MSP Initialization 75 * This function configures the hardware resources used in this example 76 * @param huart: UART handle pointer 77 * @retval None 78 */ HAL_UART_MspInit(UART_HandleTypeDef * huart)79void HAL_UART_MspInit(UART_HandleTypeDef* huart) 80 { 81 GPIO_InitTypeDef GPIO_InitStruct = {0}; 82 RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0}; 83 if(huart->Instance==LPUART1) 84 { 85 /* USER CODE BEGIN LPUART1_MspInit 0 */ 86 87 /* USER CODE END LPUART1_MspInit 0 */ 88 /** Initializes the peripherals clocks 89 */ 90 PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LPUART1; 91 PeriphClkInitStruct.Lpuart1ClockSelection = RCC_LPUART1CLKSOURCE_PCLK1; 92 if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK) 93 { 94 Error_Handler(); 95 } 96 97 /* Peripheral clock enable */ 98 __HAL_RCC_LPUART1_CLK_ENABLE(); 99 100 __HAL_RCC_GPIOA_CLK_ENABLE(); 101 /**LPUART1 GPIO Configuration 102 PA2 ------> LPUART1_TX 103 PA3 ------> LPUART1_RX 104 */ 105 GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_3; 106 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; 107 GPIO_InitStruct.Pull = GPIO_PULLUP; 108 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; 109 GPIO_InitStruct.Alternate = GPIO_AF8_LPUART1; 110 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); 111 112 /* USER CODE BEGIN LPUART1_MspInit 1 */ 113 114 /* USER CODE END LPUART1_MspInit 1 */ 115 } 116 else if(huart->Instance==USART1) 117 { 118 /* USER CODE BEGIN USART1_MspInit 0 */ 119 120 /* USER CODE END USART1_MspInit 0 */ 121 122 /** Initializes the peripherals clocks 123 */ 124 PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USART1; 125 PeriphClkInitStruct.Usart1ClockSelection = RCC_USART1CLKSOURCE_SYSCLK; 126 if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK) 127 { 128 Error_Handler(); 129 } 130 131 /* Peripheral clock enable */ 132 __HAL_RCC_USART1_CLK_ENABLE(); 133 134 __HAL_RCC_GPIOA_CLK_ENABLE(); 135 /**USART1 GPIO Configuration 136 PA9 ------> USART1_TX 137 PA10 ------> USART1_RX 138 */ 139 GPIO_InitStruct.Pin = GPIO_PIN_9|GPIO_PIN_10; 140 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; 141 GPIO_InitStruct.Pull = GPIO_NOPULL; 142 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; 143 GPIO_InitStruct.Alternate = GPIO_AF7_USART1; 144 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); 145 146 /* USER CODE BEGIN USART1_MspInit 1 */ 147 148 /* USER CODE END USART1_MspInit 1 */ 149 } 150 151 } 152 153 /** 154 * @brief UART MSP De-Initialization 155 * This function freeze the hardware resources used in this example 156 * @param huart: UART handle pointer 157 * @retval None 158 */ HAL_UART_MspDeInit(UART_HandleTypeDef * huart)159void HAL_UART_MspDeInit(UART_HandleTypeDef* huart) 160 { 161 if(huart->Instance==LPUART1) 162 { 163 /* USER CODE BEGIN LPUART1_MspDeInit 0 */ 164 165 /* USER CODE END LPUART1_MspDeInit 0 */ 166 /* Peripheral clock disable */ 167 __HAL_RCC_LPUART1_CLK_DISABLE(); 168 169 /**LPUART1 GPIO Configuration 170 PA2 ------> LPUART1_TX 171 PA3 ------> LPUART1_RX 172 */ 173 HAL_GPIO_DeInit(GPIOA, GPIO_PIN_2|GPIO_PIN_3); 174 175 /* USER CODE BEGIN LPUART1_MspDeInit 1 */ 176 177 /* USER CODE END LPUART1_MspDeInit 1 */ 178 } 179 else if(huart->Instance==USART1) 180 { 181 /* USER CODE BEGIN USART1_MspDeInit 0 */ 182 183 /* USER CODE END USART1_MspDeInit 0 */ 184 /* Peripheral clock disable */ 185 __HAL_RCC_USART1_CLK_DISABLE(); 186 187 /**USART1 GPIO Configuration 188 PA9 ------> USART1_TX 189 PA10 ------> USART1_RX 190 */ 191 HAL_GPIO_DeInit(GPIOA, GPIO_PIN_9|GPIO_PIN_10); 192 193 /* USER CODE BEGIN USART1_MspDeInit 1 */ 194 195 /* USER CODE END USART1_MspDeInit 1 */ 196 } 197 198 } 199 200 /* USER CODE BEGIN 1 */ 201 202 /* USER CODE END 1 */ 203 204 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 205