Rev 4 | Details | Compare with Previous | 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 | |||
| 3 | mjames | 29 | extern DMA_HandleTypeDef hdma_spi1_tx; |
| 30 | |||
| 2 | mjames | 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 */ |
||
| 6 | mjames | 64 | |
| 65 | void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim); |
||
| 66 | /** |
||
| 2 | mjames | 67 | * Initializes the Global MSP. |
| 68 | */ |
||
| 69 | void HAL_MspInit(void) |
||
| 70 | { |
||
| 71 | /* USER CODE BEGIN MspInit 0 */ |
||
| 72 | |||
| 73 | /* USER CODE END MspInit 0 */ |
||
| 74 | |||
| 75 | __HAL_RCC_SYSCFG_CLK_ENABLE(); |
||
| 76 | __HAL_RCC_PWR_CLK_ENABLE(); |
||
| 77 | |||
| 78 | /* System interrupt init*/ |
||
| 79 | |||
| 80 | /* USER CODE BEGIN MspInit 1 */ |
||
| 81 | |||
| 82 | /* USER CODE END MspInit 1 */ |
||
| 83 | } |
||
| 84 | |||
| 85 | /** |
||
| 86 | * @brief ADC MSP Initialization |
||
| 87 | * This function configures the hardware resources used in this example |
||
| 88 | * @param hadc: ADC handle pointer |
||
| 89 | * @retval None |
||
| 90 | */ |
||
| 91 | void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc) |
||
| 92 | { |
||
| 93 | GPIO_InitTypeDef GPIO_InitStruct = {0}; |
||
| 94 | if(hadc->Instance==ADC1) |
||
| 95 | { |
||
| 96 | /* USER CODE BEGIN ADC1_MspInit 0 */ |
||
| 97 | |||
| 98 | /* USER CODE END ADC1_MspInit 0 */ |
||
| 99 | /* Peripheral clock enable */ |
||
| 100 | __HAL_RCC_ADC1_CLK_ENABLE(); |
||
| 3 | mjames | 101 | |
| 2 | mjames | 102 | __HAL_RCC_GPIOA_CLK_ENABLE(); |
| 3 | mjames | 103 | /**ADC GPIO Configuration |
| 104 | PA0 ------> ADC_IN0 |
||
| 6 | mjames | 105 | PA1 ------> ADC_IN1 |
| 2 | mjames | 106 | */ |
| 6 | mjames | 107 | GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1; |
| 2 | mjames | 108 | GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; |
| 109 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
||
| 110 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
||
| 111 | |||
| 112 | /* ADC1 DMA Init */ |
||
| 113 | /* ADC Init */ |
||
| 114 | hdma_adc.Instance = DMA1_Channel1; |
||
| 115 | hdma_adc.Init.Direction = DMA_PERIPH_TO_MEMORY; |
||
| 116 | hdma_adc.Init.PeriphInc = DMA_PINC_DISABLE; |
||
| 117 | hdma_adc.Init.MemInc = DMA_MINC_ENABLE; |
||
| 118 | hdma_adc.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD; |
||
| 119 | hdma_adc.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD; |
||
| 120 | hdma_adc.Init.Mode = DMA_CIRCULAR; |
||
| 121 | hdma_adc.Init.Priority = DMA_PRIORITY_LOW; |
||
| 122 | if (HAL_DMA_Init(&hdma_adc) != HAL_OK) |
||
| 123 | { |
||
| 124 | Error_Handler(); |
||
| 125 | } |
||
| 126 | |||
| 127 | __HAL_LINKDMA(hadc,DMA_Handle,hdma_adc); |
||
| 128 | |||
| 129 | /* USER CODE BEGIN ADC1_MspInit 1 */ |
||
| 130 | |||
| 131 | /* USER CODE END ADC1_MspInit 1 */ |
||
| 132 | } |
||
| 133 | |||
| 134 | } |
||
| 135 | |||
| 136 | /** |
||
| 137 | * @brief ADC MSP De-Initialization |
||
| 138 | * This function freeze the hardware resources used in this example |
||
| 139 | * @param hadc: ADC handle pointer |
||
| 140 | * @retval None |
||
| 141 | */ |
||
| 142 | void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc) |
||
| 143 | { |
||
| 144 | if(hadc->Instance==ADC1) |
||
| 145 | { |
||
| 146 | /* USER CODE BEGIN ADC1_MspDeInit 0 */ |
||
| 147 | |||
| 148 | /* USER CODE END ADC1_MspDeInit 0 */ |
||
| 149 | /* Peripheral clock disable */ |
||
| 150 | __HAL_RCC_ADC1_CLK_DISABLE(); |
||
| 3 | mjames | 151 | |
| 152 | /**ADC GPIO Configuration |
||
| 153 | PA0 ------> ADC_IN0 |
||
| 6 | mjames | 154 | PA1 ------> ADC_IN1 |
| 2 | mjames | 155 | */ |
| 6 | mjames | 156 | HAL_GPIO_DeInit(GPIOA, GPIO_PIN_0|GPIO_PIN_1); |
| 2 | mjames | 157 | |
| 158 | /* ADC1 DMA DeInit */ |
||
| 159 | HAL_DMA_DeInit(hadc->DMA_Handle); |
||
| 160 | /* USER CODE BEGIN ADC1_MspDeInit 1 */ |
||
| 161 | |||
| 162 | /* USER CODE END ADC1_MspDeInit 1 */ |
||
| 163 | } |
||
| 164 | |||
| 165 | } |
||
| 166 | |||
| 167 | /** |
||
| 3 | mjames | 168 | * @brief SPI MSP Initialization |
| 169 | * This function configures the hardware resources used in this example |
||
| 170 | * @param hspi: SPI handle pointer |
||
| 171 | * @retval None |
||
| 172 | */ |
||
| 173 | void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi) |
||
| 174 | { |
||
| 175 | GPIO_InitTypeDef GPIO_InitStruct = {0}; |
||
| 176 | if(hspi->Instance==SPI1) |
||
| 177 | { |
||
| 178 | /* USER CODE BEGIN SPI1_MspInit 0 */ |
||
| 179 | |||
| 180 | /* USER CODE END SPI1_MspInit 0 */ |
||
| 181 | /* Peripheral clock enable */ |
||
| 182 | __HAL_RCC_SPI1_CLK_ENABLE(); |
||
| 183 | |||
| 184 | __HAL_RCC_GPIOA_CLK_ENABLE(); |
||
| 185 | /**SPI1 GPIO Configuration |
||
| 186 | PA5 ------> SPI1_SCK |
||
| 187 | PA7 ------> SPI1_MOSI |
||
| 188 | */ |
||
| 189 | GPIO_InitStruct.Pin = GPIO_PIN_5|GPIO_PIN_7; |
||
| 190 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; |
||
| 191 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
||
| 192 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; |
||
| 193 | GPIO_InitStruct.Alternate = GPIO_AF0_SPI1; |
||
| 194 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
||
| 195 | |||
| 196 | /* SPI1 DMA Init */ |
||
| 197 | /* SPI1_TX Init */ |
||
| 198 | hdma_spi1_tx.Instance = DMA1_Channel3; |
||
| 199 | hdma_spi1_tx.Init.Direction = DMA_MEMORY_TO_PERIPH; |
||
| 200 | hdma_spi1_tx.Init.PeriphInc = DMA_PINC_DISABLE; |
||
| 201 | hdma_spi1_tx.Init.MemInc = DMA_MINC_ENABLE; |
||
| 202 | hdma_spi1_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE; |
||
| 4 | mjames | 203 | hdma_spi1_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; |
| 3 | mjames | 204 | hdma_spi1_tx.Init.Mode = DMA_NORMAL; |
| 4 | mjames | 205 | hdma_spi1_tx.Init.Priority = DMA_PRIORITY_HIGH; |
| 3 | mjames | 206 | if (HAL_DMA_Init(&hdma_spi1_tx) != HAL_OK) |
| 207 | { |
||
| 208 | Error_Handler(); |
||
| 209 | } |
||
| 210 | |||
| 211 | __HAL_LINKDMA(hspi,hdmatx,hdma_spi1_tx); |
||
| 212 | |||
| 213 | /* USER CODE BEGIN SPI1_MspInit 1 */ |
||
| 214 | |||
| 215 | /* USER CODE END SPI1_MspInit 1 */ |
||
| 216 | } |
||
| 217 | |||
| 218 | } |
||
| 219 | |||
| 220 | /** |
||
| 221 | * @brief SPI MSP De-Initialization |
||
| 222 | * This function freeze the hardware resources used in this example |
||
| 223 | * @param hspi: SPI handle pointer |
||
| 224 | * @retval None |
||
| 225 | */ |
||
| 226 | void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi) |
||
| 227 | { |
||
| 228 | if(hspi->Instance==SPI1) |
||
| 229 | { |
||
| 230 | /* USER CODE BEGIN SPI1_MspDeInit 0 */ |
||
| 231 | |||
| 232 | /* USER CODE END SPI1_MspDeInit 0 */ |
||
| 233 | /* Peripheral clock disable */ |
||
| 234 | __HAL_RCC_SPI1_CLK_DISABLE(); |
||
| 235 | |||
| 236 | /**SPI1 GPIO Configuration |
||
| 237 | PA5 ------> SPI1_SCK |
||
| 238 | PA7 ------> SPI1_MOSI |
||
| 239 | */ |
||
| 240 | HAL_GPIO_DeInit(GPIOA, GPIO_PIN_5|GPIO_PIN_7); |
||
| 241 | |||
| 242 | /* SPI1 DMA DeInit */ |
||
| 243 | HAL_DMA_DeInit(hspi->hdmatx); |
||
| 244 | /* USER CODE BEGIN SPI1_MspDeInit 1 */ |
||
| 245 | |||
| 246 | /* USER CODE END SPI1_MspDeInit 1 */ |
||
| 247 | } |
||
| 248 | |||
| 249 | } |
||
| 250 | |||
| 251 | /** |
||
| 2 | mjames | 252 | * @brief TIM_Base MSP Initialization |
| 253 | * This function configures the hardware resources used in this example |
||
| 254 | * @param htim_base: TIM_Base handle pointer |
||
| 255 | * @retval None |
||
| 256 | */ |
||
| 257 | void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base) |
||
| 258 | { |
||
| 259 | if(htim_base->Instance==TIM1) |
||
| 260 | { |
||
| 261 | /* USER CODE BEGIN TIM1_MspInit 0 */ |
||
| 262 | |||
| 263 | /* USER CODE END TIM1_MspInit 0 */ |
||
| 264 | /* Peripheral clock enable */ |
||
| 265 | __HAL_RCC_TIM1_CLK_ENABLE(); |
||
| 266 | /* USER CODE BEGIN TIM1_MspInit 1 */ |
||
| 267 | |||
| 268 | /* USER CODE END TIM1_MspInit 1 */ |
||
| 269 | } |
||
| 270 | else if(htim_base->Instance==TIM3) |
||
| 271 | { |
||
| 272 | /* USER CODE BEGIN TIM3_MspInit 0 */ |
||
| 273 | |||
| 274 | /* USER CODE END TIM3_MspInit 0 */ |
||
| 275 | /* Peripheral clock enable */ |
||
| 276 | __HAL_RCC_TIM3_CLK_ENABLE(); |
||
| 277 | /* USER CODE BEGIN TIM3_MspInit 1 */ |
||
| 278 | |||
| 279 | /* USER CODE END TIM3_MspInit 1 */ |
||
| 280 | } |
||
| 6 | mjames | 281 | else if(htim_base->Instance==TIM14) |
| 282 | { |
||
| 283 | /* USER CODE BEGIN TIM14_MspInit 0 */ |
||
| 2 | mjames | 284 | |
| 6 | mjames | 285 | /* USER CODE END TIM14_MspInit 0 */ |
| 286 | /* Peripheral clock enable */ |
||
| 287 | __HAL_RCC_TIM14_CLK_ENABLE(); |
||
| 288 | /* USER CODE BEGIN TIM14_MspInit 1 */ |
||
| 289 | |||
| 290 | /* USER CODE END TIM14_MspInit 1 */ |
||
| 291 | } |
||
| 292 | |||
| 2 | mjames | 293 | } |
| 294 | |||
| 6 | mjames | 295 | void HAL_TIM_MspPostInit(TIM_HandleTypeDef* htim) |
| 296 | { |
||
| 297 | GPIO_InitTypeDef GPIO_InitStruct = {0}; |
||
| 298 | if(htim->Instance==TIM14) |
||
| 299 | { |
||
| 300 | /* USER CODE BEGIN TIM14_MspPostInit 0 */ |
||
| 301 | |||
| 302 | /* USER CODE END TIM14_MspPostInit 0 */ |
||
| 303 | |||
| 304 | __HAL_RCC_GPIOA_CLK_ENABLE(); |
||
| 305 | /**TIM14 GPIO Configuration |
||
| 306 | PA4 ------> TIM14_CH1 |
||
| 307 | */ |
||
| 308 | GPIO_InitStruct.Pin = Gauge_Pulse_Pin; |
||
| 309 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; |
||
| 310 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
||
| 311 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
||
| 312 | GPIO_InitStruct.Alternate = GPIO_AF4_TIM14; |
||
| 313 | HAL_GPIO_Init(Gauge_Pulse_GPIO_Port, &GPIO_InitStruct); |
||
| 314 | |||
| 315 | /* USER CODE BEGIN TIM14_MspPostInit 1 */ |
||
| 316 | |||
| 317 | /* USER CODE END TIM14_MspPostInit 1 */ |
||
| 318 | } |
||
| 319 | |||
| 320 | } |
||
| 2 | mjames | 321 | /** |
| 322 | * @brief TIM_Base MSP De-Initialization |
||
| 323 | * This function freeze the hardware resources used in this example |
||
| 324 | * @param htim_base: TIM_Base handle pointer |
||
| 325 | * @retval None |
||
| 326 | */ |
||
| 327 | void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* htim_base) |
||
| 328 | { |
||
| 329 | if(htim_base->Instance==TIM1) |
||
| 330 | { |
||
| 331 | /* USER CODE BEGIN TIM1_MspDeInit 0 */ |
||
| 332 | |||
| 333 | /* USER CODE END TIM1_MspDeInit 0 */ |
||
| 334 | /* Peripheral clock disable */ |
||
| 335 | __HAL_RCC_TIM1_CLK_DISABLE(); |
||
| 336 | /* USER CODE BEGIN TIM1_MspDeInit 1 */ |
||
| 337 | |||
| 338 | /* USER CODE END TIM1_MspDeInit 1 */ |
||
| 339 | } |
||
| 340 | else if(htim_base->Instance==TIM3) |
||
| 341 | { |
||
| 342 | /* USER CODE BEGIN TIM3_MspDeInit 0 */ |
||
| 343 | |||
| 344 | /* USER CODE END TIM3_MspDeInit 0 */ |
||
| 345 | /* Peripheral clock disable */ |
||
| 346 | __HAL_RCC_TIM3_CLK_DISABLE(); |
||
| 347 | /* USER CODE BEGIN TIM3_MspDeInit 1 */ |
||
| 348 | |||
| 349 | /* USER CODE END TIM3_MspDeInit 1 */ |
||
| 350 | } |
||
| 6 | mjames | 351 | else if(htim_base->Instance==TIM14) |
| 352 | { |
||
| 353 | /* USER CODE BEGIN TIM14_MspDeInit 0 */ |
||
| 2 | mjames | 354 | |
| 6 | mjames | 355 | /* USER CODE END TIM14_MspDeInit 0 */ |
| 356 | /* Peripheral clock disable */ |
||
| 357 | __HAL_RCC_TIM14_CLK_DISABLE(); |
||
| 358 | /* USER CODE BEGIN TIM14_MspDeInit 1 */ |
||
| 359 | |||
| 360 | /* USER CODE END TIM14_MspDeInit 1 */ |
||
| 361 | } |
||
| 362 | |||
| 2 | mjames | 363 | } |
| 364 | |||
| 365 | /** |
||
| 366 | * @brief UART MSP Initialization |
||
| 367 | * This function configures the hardware resources used in this example |
||
| 368 | * @param huart: UART handle pointer |
||
| 369 | * @retval None |
||
| 370 | */ |
||
| 371 | void HAL_UART_MspInit(UART_HandleTypeDef* huart) |
||
| 372 | { |
||
| 373 | GPIO_InitTypeDef GPIO_InitStruct = {0}; |
||
| 374 | if(huart->Instance==USART1) |
||
| 375 | { |
||
| 376 | /* USER CODE BEGIN USART1_MspInit 0 */ |
||
| 377 | |||
| 378 | /* USER CODE END USART1_MspInit 0 */ |
||
| 379 | /* Peripheral clock enable */ |
||
| 380 | __HAL_RCC_USART1_CLK_ENABLE(); |
||
| 3 | mjames | 381 | |
| 2 | mjames | 382 | __HAL_RCC_GPIOA_CLK_ENABLE(); |
| 3 | mjames | 383 | /**USART1 GPIO Configuration |
| 2 | mjames | 384 | PA2 ------> USART1_TX |
| 3 | mjames | 385 | PA3 ------> USART1_RX |
| 2 | mjames | 386 | */ |
| 387 | GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_3; |
||
| 388 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; |
||
| 389 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
||
| 390 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; |
||
| 391 | GPIO_InitStruct.Alternate = GPIO_AF1_USART1; |
||
| 392 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
||
| 393 | |||
| 394 | /* USER CODE BEGIN USART1_MspInit 1 */ |
||
| 395 | |||
| 396 | /* USER CODE END USART1_MspInit 1 */ |
||
| 397 | } |
||
| 398 | |||
| 399 | } |
||
| 400 | |||
| 401 | /** |
||
| 402 | * @brief UART MSP De-Initialization |
||
| 403 | * This function freeze the hardware resources used in this example |
||
| 404 | * @param huart: UART handle pointer |
||
| 405 | * @retval None |
||
| 406 | */ |
||
| 407 | void HAL_UART_MspDeInit(UART_HandleTypeDef* huart) |
||
| 408 | { |
||
| 409 | if(huart->Instance==USART1) |
||
| 410 | { |
||
| 411 | /* USER CODE BEGIN USART1_MspDeInit 0 */ |
||
| 412 | |||
| 413 | /* USER CODE END USART1_MspDeInit 0 */ |
||
| 414 | /* Peripheral clock disable */ |
||
| 415 | __HAL_RCC_USART1_CLK_DISABLE(); |
||
| 3 | mjames | 416 | |
| 417 | /**USART1 GPIO Configuration |
||
| 2 | mjames | 418 | PA2 ------> USART1_TX |
| 3 | mjames | 419 | PA3 ------> USART1_RX |
| 2 | mjames | 420 | */ |
| 421 | HAL_GPIO_DeInit(GPIOA, GPIO_PIN_2|GPIO_PIN_3); |
||
| 422 | |||
| 423 | /* USER CODE BEGIN USART1_MspDeInit 1 */ |
||
| 424 | |||
| 425 | /* USER CODE END USART1_MspDeInit 1 */ |
||
| 426 | } |
||
| 427 | |||
| 428 | } |
||
| 429 | |||
| 430 | /* USER CODE BEGIN 1 */ |
||
| 431 | |||
| 432 | /* USER CODE END 1 */ |