1 /* USER CODE BEGIN Header */ 2 /** 3 ****************************************************************************** 4 * File Name : stm32l4xx_hal_msp.c 5 * Description : This file provides code for the MSP Initialization 6 * and de-Initialization codes. 7 ****************************************************************************** 8 * @attention 9 * 10 * <h2><center>© Copyright (c) 2020 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 26 /* USER CODE END Includes */ 27 extern DMA_HandleTypeDef hdma_spi2_rx; 28 29 extern DMA_HandleTypeDef hdma_spi2_tx; 30 31 /* Private typedef -----------------------------------------------------------*/ 32 /* USER CODE BEGIN TD */ 33 34 /* USER CODE END TD */ 35 36 /* Private define ------------------------------------------------------------*/ 37 /* USER CODE BEGIN Define */ 38 39 /* USER CODE END Define */ 40 41 /* Private macro -------------------------------------------------------------*/ 42 /* USER CODE BEGIN Macro */ 43 44 /* USER CODE END Macro */ 45 46 /* Private variables ---------------------------------------------------------*/ 47 /* USER CODE BEGIN PV */ 48 49 /* USER CODE END PV */ 50 51 /* Private function prototypes -----------------------------------------------*/ 52 /* USER CODE BEGIN PFP */ 53 54 /* USER CODE END PFP */ 55 56 /* External functions --------------------------------------------------------*/ 57 /* USER CODE BEGIN ExternalFunctions */ 58 59 /* USER CODE END ExternalFunctions */ 60 61 /* USER CODE BEGIN 0 */ 62 63 /* USER CODE END 0 */ 64 /** 65 * Initializes the Global MSP. 66 */ 67 void HAL_MspInit(void) 68 { 69 /* USER CODE BEGIN MspInit 0 */ 70 71 /* USER CODE END MspInit 0 */ 72 73 __HAL_RCC_SYSCFG_CLK_ENABLE(); 74 __HAL_RCC_PWR_CLK_ENABLE(); 75 76 /* System interrupt init*/ 77 78 /* USER CODE BEGIN MspInit 1 */ 79 80 /* USER CODE END MspInit 1 */ 81 } 82 83 /** 84 * @brief LPTIM MSP Initialization 85 * This function configures the hardware resources used in this example 86 * @param hlptim: LPTIM handle pointer 87 * @retval None 88 */ 89 void HAL_LPTIM_MspInit(LPTIM_HandleTypeDef* hlptim) 90 { 91 if(hlptim->Instance==LPTIM1) 92 { 93 /* USER CODE BEGIN LPTIM1_MspInit 0 */ 94 95 /* USER CODE END LPTIM1_MspInit 0 */ 96 /* Peripheral clock enable */ 97 __HAL_RCC_LPTIM1_CLK_ENABLE(); 98 /* LPTIM1 interrupt Init */ 99 HAL_NVIC_SetPriority(LPTIM1_IRQn, 0, 0); 100 HAL_NVIC_EnableIRQ(LPTIM1_IRQn); 101 /* USER CODE BEGIN LPTIM1_MspInit 1 */ 102 103 /* USER CODE END LPTIM1_MspInit 1 */ 104 } 105 106 } 107 108 /** 109 * @brief LPTIM MSP De-Initialization 110 * This function freeze the hardware resources used in this example 111 * @param hlptim: LPTIM handle pointer 112 * @retval None 113 */ 114 void HAL_LPTIM_MspDeInit(LPTIM_HandleTypeDef* hlptim) 115 { 116 if(hlptim->Instance==LPTIM1) 117 { 118 /* USER CODE BEGIN LPTIM1_MspDeInit 0 */ 119 120 /* USER CODE END LPTIM1_MspDeInit 0 */ 121 /* Peripheral clock disable */ 122 __HAL_RCC_LPTIM1_CLK_DISABLE(); 123 124 /* LPTIM1 interrupt DeInit */ 125 HAL_NVIC_DisableIRQ(LPTIM1_IRQn); 126 /* USER CODE BEGIN LPTIM1_MspDeInit 1 */ 127 128 /* USER CODE END LPTIM1_MspDeInit 1 */ 129 } 130 131 } 132 133 /** 134 * @brief SPI MSP Initialization 135 * This function configures the hardware resources used in this example 136 * @param hspi: SPI handle pointer 137 * @retval None 138 */ 139 void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi) 140 { 141 GPIO_InitTypeDef GPIO_InitStruct = {0}; 142 if(hspi->Instance==SPI2) 143 { 144 /* USER CODE BEGIN SPI2_MspInit 0 */ 145 146 /* USER CODE END SPI2_MspInit 0 */ 147 /* Peripheral clock enable */ 148 __HAL_RCC_SPI2_CLK_ENABLE(); 149 150 __HAL_RCC_GPIOB_CLK_ENABLE(); 151 /**SPI2 GPIO Configuration 152 PB15 ------> SPI2_MOSI 153 PB14 ------> SPI2_MISO 154 PB10 ------> SPI2_SCK 155 */ 156 GPIO_InitStruct.Pin = RF_MOSI_Pin|RF_MISO_Pin|RF_SCK_Pin; 157 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; 158 GPIO_InitStruct.Pull = GPIO_NOPULL; 159 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; 160 GPIO_InitStruct.Alternate = GPIO_AF5_SPI2; 161 HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); 162 163 /* SPI2 DMA Init */ 164 /* SPI2_RX Init */ 165 hdma_spi2_rx.Instance = DMA1_Channel4; 166 hdma_spi2_rx.Init.Request = DMA_REQUEST_1; 167 hdma_spi2_rx.Init.Direction = DMA_PERIPH_TO_MEMORY; 168 hdma_spi2_rx.Init.PeriphInc = DMA_PINC_DISABLE; 169 hdma_spi2_rx.Init.MemInc = DMA_MINC_ENABLE; 170 hdma_spi2_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE; 171 hdma_spi2_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; 172 hdma_spi2_rx.Init.Mode = DMA_NORMAL; 173 hdma_spi2_rx.Init.Priority = DMA_PRIORITY_LOW; 174 if (HAL_DMA_Init(&hdma_spi2_rx) != HAL_OK) 175 { 176 Error_Handler(); 177 } 178 179 __HAL_LINKDMA(hspi,hdmarx,hdma_spi2_rx); 180 181 /* SPI2_TX Init */ 182 hdma_spi2_tx.Instance = DMA1_Channel5; 183 hdma_spi2_tx.Init.Request = DMA_REQUEST_1; 184 hdma_spi2_tx.Init.Direction = DMA_MEMORY_TO_PERIPH; 185 hdma_spi2_tx.Init.PeriphInc = DMA_PINC_DISABLE; 186 hdma_spi2_tx.Init.MemInc = DMA_MINC_ENABLE; 187 hdma_spi2_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE; 188 hdma_spi2_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; 189 hdma_spi2_tx.Init.Mode = DMA_NORMAL; 190 hdma_spi2_tx.Init.Priority = DMA_PRIORITY_LOW; 191 if (HAL_DMA_Init(&hdma_spi2_tx) != HAL_OK) 192 { 193 Error_Handler(); 194 } 195 196 __HAL_LINKDMA(hspi,hdmatx,hdma_spi2_tx); 197 198 /* SPI2 interrupt Init */ 199 HAL_NVIC_SetPriority(SPI2_IRQn, 0, 0); 200 HAL_NVIC_EnableIRQ(SPI2_IRQn); 201 /* USER CODE BEGIN SPI2_MspInit 1 */ 202 203 /* USER CODE END SPI2_MspInit 1 */ 204 } 205 206 } 207 208 /** 209 * @brief SPI MSP De-Initialization 210 * This function freeze the hardware resources used in this example 211 * @param hspi: SPI handle pointer 212 * @retval None 213 */ 214 void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi) 215 { 216 if(hspi->Instance==SPI2) 217 { 218 /* USER CODE BEGIN SPI2_MspDeInit 0 */ 219 220 /* USER CODE END SPI2_MspDeInit 0 */ 221 /* Peripheral clock disable */ 222 __HAL_RCC_SPI2_CLK_DISABLE(); 223 224 /**SPI2 GPIO Configuration 225 PB15 ------> SPI2_MOSI 226 PB14 ------> SPI2_MISO 227 PB10 ------> SPI2_SCK 228 */ 229 HAL_GPIO_DeInit(GPIOB, RF_MOSI_Pin|RF_MISO_Pin|RF_SCK_Pin); 230 231 /* SPI2 DMA DeInit */ 232 HAL_DMA_DeInit(hspi->hdmarx); 233 HAL_DMA_DeInit(hspi->hdmatx); 234 235 /* SPI2 interrupt DeInit */ 236 HAL_NVIC_DisableIRQ(SPI2_IRQn); 237 /* USER CODE BEGIN SPI2_MspDeInit 1 */ 238 239 /* USER CODE END SPI2_MspDeInit 1 */ 240 } 241 242 } 243 244 /** 245 * @brief TIM_Base MSP Initialization 246 * This function configures the hardware resources used in this example 247 * @param htim_base: TIM_Base handle pointer 248 * @retval None 249 */ 250 void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base) 251 { 252 if(htim_base->Instance==TIM2) 253 { 254 /* USER CODE BEGIN TIM2_MspInit 0 */ 255 256 /* USER CODE END TIM2_MspInit 0 */ 257 /* Peripheral clock enable */ 258 __HAL_RCC_TIM2_CLK_ENABLE(); 259 /* TIM2 interrupt Init */ 260 HAL_NVIC_SetPriority(TIM2_IRQn, 0, 0); 261 HAL_NVIC_EnableIRQ(TIM2_IRQn); 262 /* USER CODE BEGIN TIM2_MspInit 1 */ 263 264 /* USER CODE END TIM2_MspInit 1 */ 265 } 266 267 } 268 269 /** 270 * @brief TIM_Base MSP De-Initialization 271 * This function freeze the hardware resources used in this example 272 * @param htim_base: TIM_Base handle pointer 273 * @retval None 274 */ 275 void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* htim_base) 276 { 277 if(htim_base->Instance==TIM2) 278 { 279 /* USER CODE BEGIN TIM2_MspDeInit 0 */ 280 281 /* USER CODE END TIM2_MspDeInit 0 */ 282 /* Peripheral clock disable */ 283 __HAL_RCC_TIM2_CLK_DISABLE(); 284 285 /* TIM2 interrupt DeInit */ 286 HAL_NVIC_DisableIRQ(TIM2_IRQn); 287 /* USER CODE BEGIN TIM2_MspDeInit 1 */ 288 289 /* USER CODE END TIM2_MspDeInit 1 */ 290 } 291 292 } 293 294 /* USER CODE BEGIN 1 */ 295 296 /* USER CODE END 1 */ 297 298 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 299