Rev 3 | Go to most recent revision | Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 2 | mjames | 1 | /* USER CODE BEGIN Header */ |
| 2 | /** |
||
| 3 | ****************************************************************************** |
||
| 4 | * File Name : stm32f0xx_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_adc; |
||
| 28 | |||
| 29 | /* Private typedef -----------------------------------------------------------*/ |
||
| 30 | /* USER CODE BEGIN TD */ |
||
| 31 | |||
| 32 | /* USER CODE END TD */ |
||
| 33 | |||
| 34 | /* Private define ------------------------------------------------------------*/ |
||
| 35 | /* USER CODE BEGIN Define */ |
||
| 36 | |||
| 37 | /* USER CODE END Define */ |
||
| 38 | |||
| 39 | /* Private macro -------------------------------------------------------------*/ |
||
| 40 | /* USER CODE BEGIN Macro */ |
||
| 41 | |||
| 42 | /* USER CODE END Macro */ |
||
| 43 | |||
| 44 | /* Private variables ---------------------------------------------------------*/ |
||
| 45 | /* USER CODE BEGIN PV */ |
||
| 46 | |||
| 47 | /* USER CODE END PV */ |
||
| 48 | |||
| 49 | /* Private function prototypes -----------------------------------------------*/ |
||
| 50 | /* USER CODE BEGIN PFP */ |
||
| 51 | |||
| 52 | /* USER CODE END PFP */ |
||
| 53 | |||
| 54 | /* External functions --------------------------------------------------------*/ |
||
| 55 | /* USER CODE BEGIN ExternalFunctions */ |
||
| 56 | |||
| 57 | /* USER CODE END ExternalFunctions */ |
||
| 58 | |||
| 59 | /* USER CODE BEGIN 0 */ |
||
| 60 | |||
| 61 | /* USER CODE END 0 */ |
||
| 62 | /** |
||
| 63 | * Initializes the Global MSP. |
||
| 64 | */ |
||
| 65 | void HAL_MspInit(void) |
||
| 66 | { |
||
| 67 | /* USER CODE BEGIN MspInit 0 */ |
||
| 68 | |||
| 69 | /* USER CODE END MspInit 0 */ |
||
| 70 | |||
| 71 | __HAL_RCC_SYSCFG_CLK_ENABLE(); |
||
| 72 | __HAL_RCC_PWR_CLK_ENABLE(); |
||
| 73 | |||
| 74 | /* System interrupt init*/ |
||
| 75 | |||
| 76 | /* USER CODE BEGIN MspInit 1 */ |
||
| 77 | |||
| 78 | /* USER CODE END MspInit 1 */ |
||
| 79 | } |
||
| 80 | |||
| 81 | /** |
||
| 82 | * @brief ADC MSP Initialization |
||
| 83 | * This function configures the hardware resources used in this example |
||
| 84 | * @param hadc: ADC handle pointer |
||
| 85 | * @retval None |
||
| 86 | */ |
||
| 87 | void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc) |
||
| 88 | { |
||
| 89 | GPIO_InitTypeDef GPIO_InitStruct = {0}; |
||
| 90 | if(hadc->Instance==ADC1) |
||
| 91 | { |
||
| 92 | /* USER CODE BEGIN ADC1_MspInit 0 */ |
||
| 93 | |||
| 94 | /* USER CODE END ADC1_MspInit 0 */ |
||
| 95 | /* Peripheral clock enable */ |
||
| 96 | __HAL_RCC_ADC1_CLK_ENABLE(); |
||
| 97 | |||
| 98 | __HAL_RCC_GPIOA_CLK_ENABLE(); |
||
| 99 | /**ADC GPIO Configuration |
||
| 100 | PA0 ------> ADC_IN0 |
||
| 101 | */ |
||
| 102 | GPIO_InitStruct.Pin = GPIO_PIN_0; |
||
| 103 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
||
| 104 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
||
| 105 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
||
| 106 | |||
| 107 | /* ADC1 DMA Init */ |
||
| 108 | /* ADC Init */ |
||
| 109 | hdma_adc.Instance = DMA1_Channel1; |
||
| 110 | hdma_adc.Init.Direction = DMA_PERIPH_TO_MEMORY; |
||
| 111 | hdma_adc.Init.PeriphInc = DMA_PINC_DISABLE; |
||
| 112 | hdma_adc.Init.MemInc = DMA_MINC_ENABLE; |
||
| 113 | hdma_adc.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD; |
||
| 114 | hdma_adc.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD; |
||
| 115 | hdma_adc.Init.Mode = DMA_CIRCULAR; |
||
| 116 | hdma_adc.Init.Priority = DMA_PRIORITY_LOW; |
||
| 117 | if (HAL_DMA_Init(&hdma_adc) != HAL_OK) |
||
| 118 | { |
||
| 119 | Error_Handler(); |
||
| 120 | } |
||
| 121 | |||
| 122 | __HAL_LINKDMA(hadc,DMA_Handle,hdma_adc); |
||
| 123 | |||
| 124 | /* USER CODE BEGIN ADC1_MspInit 1 */ |
||
| 125 | |||
| 126 | /* USER CODE END ADC1_MspInit 1 */ |
||
| 127 | } |
||
| 128 | |||
| 129 | } |
||
| 130 | |||
| 131 | /** |
||
| 132 | * @brief ADC MSP De-Initialization |
||
| 133 | * This function freeze the hardware resources used in this example |
||
| 134 | * @param hadc: ADC handle pointer |
||
| 135 | * @retval None |
||
| 136 | */ |
||
| 137 | void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc) |
||
| 138 | { |
||
| 139 | if(hadc->Instance==ADC1) |
||
| 140 | { |
||
| 141 | /* USER CODE BEGIN ADC1_MspDeInit 0 */ |
||
| 142 | |||
| 143 | /* USER CODE END ADC1_MspDeInit 0 */ |
||
| 144 | /* Peripheral clock disable */ |
||
| 145 | __HAL_RCC_ADC1_CLK_DISABLE(); |
||
| 146 | |||
| 147 | /**ADC GPIO Configuration |
||
| 148 | PA0 ------> ADC_IN0 |
||
| 149 | */ |
||
| 150 | HAL_GPIO_DeInit(GPIOA, GPIO_PIN_0); |
||
| 151 | |||
| 152 | /* ADC1 DMA DeInit */ |
||
| 153 | HAL_DMA_DeInit(hadc->DMA_Handle); |
||
| 154 | /* USER CODE BEGIN ADC1_MspDeInit 1 */ |
||
| 155 | |||
| 156 | /* USER CODE END ADC1_MspDeInit 1 */ |
||
| 157 | } |
||
| 158 | |||
| 159 | } |
||
| 160 | |||
| 161 | /** |
||
| 162 | * @brief TIM_Base MSP Initialization |
||
| 163 | * This function configures the hardware resources used in this example |
||
| 164 | * @param htim_base: TIM_Base handle pointer |
||
| 165 | * @retval None |
||
| 166 | */ |
||
| 167 | void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base) |
||
| 168 | { |
||
| 169 | if(htim_base->Instance==TIM1) |
||
| 170 | { |
||
| 171 | /* USER CODE BEGIN TIM1_MspInit 0 */ |
||
| 172 | |||
| 173 | /* USER CODE END TIM1_MspInit 0 */ |
||
| 174 | /* Peripheral clock enable */ |
||
| 175 | __HAL_RCC_TIM1_CLK_ENABLE(); |
||
| 176 | /* USER CODE BEGIN TIM1_MspInit 1 */ |
||
| 177 | |||
| 178 | /* USER CODE END TIM1_MspInit 1 */ |
||
| 179 | } |
||
| 180 | else if(htim_base->Instance==TIM3) |
||
| 181 | { |
||
| 182 | /* USER CODE BEGIN TIM3_MspInit 0 */ |
||
| 183 | |||
| 184 | /* USER CODE END TIM3_MspInit 0 */ |
||
| 185 | /* Peripheral clock enable */ |
||
| 186 | __HAL_RCC_TIM3_CLK_ENABLE(); |
||
| 187 | /* USER CODE BEGIN TIM3_MspInit 1 */ |
||
| 188 | |||
| 189 | /* USER CODE END TIM3_MspInit 1 */ |
||
| 190 | } |
||
| 191 | |||
| 192 | } |
||
| 193 | |||
| 194 | /** |
||
| 195 | * @brief TIM_Base MSP De-Initialization |
||
| 196 | * This function freeze the hardware resources used in this example |
||
| 197 | * @param htim_base: TIM_Base handle pointer |
||
| 198 | * @retval None |
||
| 199 | */ |
||
| 200 | void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* htim_base) |
||
| 201 | { |
||
| 202 | if(htim_base->Instance==TIM1) |
||
| 203 | { |
||
| 204 | /* USER CODE BEGIN TIM1_MspDeInit 0 */ |
||
| 205 | |||
| 206 | /* USER CODE END TIM1_MspDeInit 0 */ |
||
| 207 | /* Peripheral clock disable */ |
||
| 208 | __HAL_RCC_TIM1_CLK_DISABLE(); |
||
| 209 | /* USER CODE BEGIN TIM1_MspDeInit 1 */ |
||
| 210 | |||
| 211 | /* USER CODE END TIM1_MspDeInit 1 */ |
||
| 212 | } |
||
| 213 | else if(htim_base->Instance==TIM3) |
||
| 214 | { |
||
| 215 | /* USER CODE BEGIN TIM3_MspDeInit 0 */ |
||
| 216 | |||
| 217 | /* USER CODE END TIM3_MspDeInit 0 */ |
||
| 218 | /* Peripheral clock disable */ |
||
| 219 | __HAL_RCC_TIM3_CLK_DISABLE(); |
||
| 220 | /* USER CODE BEGIN TIM3_MspDeInit 1 */ |
||
| 221 | |||
| 222 | /* USER CODE END TIM3_MspDeInit 1 */ |
||
| 223 | } |
||
| 224 | |||
| 225 | } |
||
| 226 | |||
| 227 | /** |
||
| 228 | * @brief UART MSP Initialization |
||
| 229 | * This function configures the hardware resources used in this example |
||
| 230 | * @param huart: UART handle pointer |
||
| 231 | * @retval None |
||
| 232 | */ |
||
| 233 | void HAL_UART_MspInit(UART_HandleTypeDef* huart) |
||
| 234 | { |
||
| 235 | GPIO_InitTypeDef GPIO_InitStruct = {0}; |
||
| 236 | if(huart->Instance==USART1) |
||
| 237 | { |
||
| 238 | /* USER CODE BEGIN USART1_MspInit 0 */ |
||
| 239 | |||
| 240 | /* USER CODE END USART1_MspInit 0 */ |
||
| 241 | /* Peripheral clock enable */ |
||
| 242 | __HAL_RCC_USART1_CLK_ENABLE(); |
||
| 243 | |||
| 244 | __HAL_RCC_GPIOA_CLK_ENABLE(); |
||
| 245 | /**USART1 GPIO Configuration |
||
| 246 | PA2 ------> USART1_TX |
||
| 247 | PA3 ------> USART1_RX |
||
| 248 | */ |
||
| 249 | GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_3; |
||
| 250 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; |
||
| 251 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
||
| 252 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; |
||
| 253 | GPIO_InitStruct.Alternate = GPIO_AF1_USART1; |
||
| 254 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
||
| 255 | |||
| 256 | /* USER CODE BEGIN USART1_MspInit 1 */ |
||
| 257 | |||
| 258 | /* USER CODE END USART1_MspInit 1 */ |
||
| 259 | } |
||
| 260 | |||
| 261 | } |
||
| 262 | |||
| 263 | /** |
||
| 264 | * @brief UART MSP De-Initialization |
||
| 265 | * This function freeze the hardware resources used in this example |
||
| 266 | * @param huart: UART handle pointer |
||
| 267 | * @retval None |
||
| 268 | */ |
||
| 269 | void HAL_UART_MspDeInit(UART_HandleTypeDef* huart) |
||
| 270 | { |
||
| 271 | if(huart->Instance==USART1) |
||
| 272 | { |
||
| 273 | /* USER CODE BEGIN USART1_MspDeInit 0 */ |
||
| 274 | |||
| 275 | /* USER CODE END USART1_MspDeInit 0 */ |
||
| 276 | /* Peripheral clock disable */ |
||
| 277 | __HAL_RCC_USART1_CLK_DISABLE(); |
||
| 278 | |||
| 279 | /**USART1 GPIO Configuration |
||
| 280 | PA2 ------> USART1_TX |
||
| 281 | PA3 ------> USART1_RX |
||
| 282 | */ |
||
| 283 | HAL_GPIO_DeInit(GPIOA, GPIO_PIN_2|GPIO_PIN_3); |
||
| 284 | |||
| 285 | /* USER CODE BEGIN USART1_MspDeInit 1 */ |
||
| 286 | |||
| 287 | /* USER CODE END USART1_MspDeInit 1 */ |
||
| 288 | } |
||
| 289 | |||
| 290 | } |
||
| 291 | |||
| 292 | /* USER CODE BEGIN 1 */ |
||
| 293 | |||
| 294 | /* USER CODE END 1 */ |
||
| 295 | |||
| 296 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |