Subversion Repositories EngineBay2

Rev

Rev 28 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
28 mjames 1
/* USER CODE BEGIN Header */
2 mjames 2
/**
3
  ******************************************************************************
4
  * File Name          : stm32l1xx_hal_msp.c
28 mjames 5
  * Description        : This file provides code for the MSP Initialization
2 mjames 6
  *                      and de-Initialization codes.
7
  ******************************************************************************
28 mjames 8
  * @attention
2 mjames 9
  *
28 mjames 10
  * <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
11
  * All rights reserved.</center></h2>
2 mjames 12
  *
28 mjames 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
2 mjames 17
  *
18
  ******************************************************************************
19
  */
28 mjames 20
/* USER CODE END Header */
21
 
2 mjames 22
/* Includes ------------------------------------------------------------------*/
28 mjames 23
#include "main.h"
24
/* USER CODE BEGIN Includes */
2 mjames 25
 
28 mjames 26
/* USER CODE END Includes */
6 mjames 27
extern DMA_HandleTypeDef hdma_adc;
28
 
28 mjames 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
 
2 mjames 59
/* USER CODE BEGIN 0 */
60
 
61
/* USER CODE END 0 */
29 mjames 62
 
63
void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim);
64
                    /**
2 mjames 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_COMP_CLK_ENABLE();
74
  __HAL_RCC_SYSCFG_CLK_ENABLE();
28 mjames 75
  __HAL_RCC_PWR_CLK_ENABLE();
2 mjames 76
 
77
  /* System interrupt init*/
78
 
79
  /* USER CODE BEGIN MspInit 1 */
80
 
81
  /* USER CODE END MspInit 1 */
82
}
83
 
28 mjames 84
/**
85
* @brief ADC MSP Initialization
86
* This function configures the hardware resources used in this example
87
* @param hadc: ADC handle pointer
88
* @retval None
89
*/
2 mjames 90
void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc)
91
{
28 mjames 92
  GPIO_InitTypeDef GPIO_InitStruct = {0};
2 mjames 93
  if(hadc->Instance==ADC1)
94
  {
95
  /* USER CODE BEGIN ADC1_MspInit 0 */
96
 
97
  /* USER CODE END ADC1_MspInit 0 */
98
    /* Peripheral clock enable */
99
    __HAL_RCC_ADC1_CLK_ENABLE();
28 mjames 100
 
101
    __HAL_RCC_GPIOC_CLK_ENABLE();
102
    /**ADC GPIO Configuration
6 mjames 103
    PC0     ------> ADC_IN10
104
    PC1     ------> ADC_IN11
105
    PC2     ------> ADC_IN12
28 mjames 106
    PC3     ------> ADC_IN13
2 mjames 107
    */
6 mjames 108
    GPIO_InitStruct.Pin = V_Batt1_Pin|V_Batt2_Pin|V_Oil_Pin|V_MAP_Pin;
2 mjames 109
    GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
110
    GPIO_InitStruct.Pull = GPIO_NOPULL;
6 mjames 111
    HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
2 mjames 112
 
28 mjames 113
    /* ADC1 DMA Init */
114
    /* ADC Init */
6 mjames 115
    hdma_adc.Instance = DMA1_Channel1;
116
    hdma_adc.Init.Direction = DMA_PERIPH_TO_MEMORY;
117
    hdma_adc.Init.PeriphInc = DMA_PINC_DISABLE;
118
    hdma_adc.Init.MemInc = DMA_MINC_ENABLE;
119
    hdma_adc.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;
120
    hdma_adc.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD;
13 mjames 121
    hdma_adc.Init.Mode = DMA_CIRCULAR;
6 mjames 122
    hdma_adc.Init.Priority = DMA_PRIORITY_LOW;
123
    if (HAL_DMA_Init(&hdma_adc) != HAL_OK)
124
    {
125
      Error_Handler();
126
    }
127
 
128
    __HAL_LINKDMA(hadc,DMA_Handle,hdma_adc);
129
 
2 mjames 130
  /* USER CODE BEGIN ADC1_MspInit 1 */
131
 
132
  /* USER CODE END ADC1_MspInit 1 */
133
  }
134
 
135
}
136
 
28 mjames 137
/**
138
* @brief ADC MSP De-Initialization
139
* This function freeze the hardware resources used in this example
140
* @param hadc: ADC handle pointer
141
* @retval None
142
*/
2 mjames 143
void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc)
144
{
145
  if(hadc->Instance==ADC1)
146
  {
147
  /* USER CODE BEGIN ADC1_MspDeInit 0 */
148
 
149
  /* USER CODE END ADC1_MspDeInit 0 */
150
    /* Peripheral clock disable */
151
    __HAL_RCC_ADC1_CLK_DISABLE();
28 mjames 152
 
153
    /**ADC GPIO Configuration
6 mjames 154
    PC0     ------> ADC_IN10
155
    PC1     ------> ADC_IN11
156
    PC2     ------> ADC_IN12
28 mjames 157
    PC3     ------> ADC_IN13
2 mjames 158
    */
6 mjames 159
    HAL_GPIO_DeInit(GPIOC, V_Batt1_Pin|V_Batt2_Pin|V_Oil_Pin|V_MAP_Pin);
2 mjames 160
 
28 mjames 161
    /* ADC1 DMA DeInit */
6 mjames 162
    HAL_DMA_DeInit(hadc->DMA_Handle);
2 mjames 163
  /* USER CODE BEGIN ADC1_MspDeInit 1 */
164
 
165
  /* USER CODE END ADC1_MspDeInit 1 */
28 mjames 166
  }
2 mjames 167
 
168
}
169
 
28 mjames 170
/**
171
* @brief SPI MSP Initialization
172
* This function configures the hardware resources used in this example
173
* @param hspi: SPI handle pointer
174
* @retval None
175
*/
2 mjames 176
void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
177
{
28 mjames 178
  GPIO_InitTypeDef GPIO_InitStruct = {0};
2 mjames 179
  if(hspi->Instance==SPI1)
180
  {
181
  /* USER CODE BEGIN SPI1_MspInit 0 */
182
 
183
  /* USER CODE END SPI1_MspInit 0 */
184
    /* Peripheral clock enable */
185
    __HAL_RCC_SPI1_CLK_ENABLE();
28 mjames 186
 
187
    __HAL_RCC_GPIOA_CLK_ENABLE();
188
    /**SPI1 GPIO Configuration
2 mjames 189
    PA5     ------> SPI1_SCK
3 mjames 190
    PA6     ------> SPI1_MISO
28 mjames 191
    PA7     ------> SPI1_MOSI
2 mjames 192
    */
28 mjames 193
    GPIO_InitStruct.Pin = SPI1_SCK_Pin|SPI1_MISO_Pin|SPI1_MOSI_Pin;
2 mjames 194
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
195
    GPIO_InitStruct.Pull = GPIO_NOPULL;
196
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
197
    GPIO_InitStruct.Alternate = GPIO_AF5_SPI1;
198
    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
199
 
200
  /* USER CODE BEGIN SPI1_MspInit 1 */
201
 
202
  /* USER CODE END SPI1_MspInit 1 */
203
  }
204
 
205
}
206
 
28 mjames 207
/**
208
* @brief SPI MSP De-Initialization
209
* This function freeze the hardware resources used in this example
210
* @param hspi: SPI handle pointer
211
* @retval None
212
*/
2 mjames 213
void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi)
214
{
215
  if(hspi->Instance==SPI1)
216
  {
217
  /* USER CODE BEGIN SPI1_MspDeInit 0 */
218
 
219
  /* USER CODE END SPI1_MspDeInit 0 */
220
    /* Peripheral clock disable */
221
    __HAL_RCC_SPI1_CLK_DISABLE();
28 mjames 222
 
223
    /**SPI1 GPIO Configuration
2 mjames 224
    PA5     ------> SPI1_SCK
3 mjames 225
    PA6     ------> SPI1_MISO
28 mjames 226
    PA7     ------> SPI1_MOSI
2 mjames 227
    */
28 mjames 228
    HAL_GPIO_DeInit(GPIOA, SPI1_SCK_Pin|SPI1_MISO_Pin|SPI1_MOSI_Pin);
2 mjames 229
 
230
  /* USER CODE BEGIN SPI1_MspDeInit 1 */
231
 
232
  /* USER CODE END SPI1_MspDeInit 1 */
28 mjames 233
  }
2 mjames 234
 
235
}
236
 
28 mjames 237
/**
238
* @brief TIM_Base MSP Initialization
239
* This function configures the hardware resources used in this example
240
* @param htim_base: TIM_Base handle pointer
241
* @retval None
242
*/
12 mjames 243
void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base)
2 mjames 244
{
28 mjames 245
  GPIO_InitTypeDef GPIO_InitStruct = {0};
12 mjames 246
  if(htim_base->Instance==TIM2)
2 mjames 247
  {
248
  /* USER CODE BEGIN TIM2_MspInit 0 */
249
 
250
  /* USER CODE END TIM2_MspInit 0 */
251
    /* Peripheral clock enable */
252
    __HAL_RCC_TIM2_CLK_ENABLE();
28 mjames 253
 
254
    __HAL_RCC_GPIOA_CLK_ENABLE();
255
    /**TIM2 GPIO Configuration
256
    PA15     ------> TIM2_CH1
2 mjames 257
    */
258
    GPIO_InitStruct.Pin = CB_Pulse_Pin;
259
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
260
    GPIO_InitStruct.Pull = GPIO_NOPULL;
261
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
262
    GPIO_InitStruct.Alternate = GPIO_AF1_TIM2;
263
    HAL_GPIO_Init(CB_Pulse_GPIO_Port, &GPIO_InitStruct);
264
 
28 mjames 265
    /* TIM2 interrupt Init */
6 mjames 266
    HAL_NVIC_SetPriority(TIM2_IRQn, 0, 0);
267
    HAL_NVIC_EnableIRQ(TIM2_IRQn);
2 mjames 268
  /* USER CODE BEGIN TIM2_MspInit 1 */
269
 
270
  /* USER CODE END TIM2_MspInit 1 */
271
  }
28 mjames 272
  else if(htim_base->Instance==TIM3)
273
  {
274
  /* USER CODE BEGIN TIM3_MspInit 0 */
275
 
276
  /* USER CODE END TIM3_MspInit 0 */
277
    /* Peripheral clock enable */
278
    __HAL_RCC_TIM3_CLK_ENABLE();
29 mjames 279
    /* TIM3 interrupt Init */
280
    HAL_NVIC_SetPriority(TIM3_IRQn, 0, 0);
281
    HAL_NVIC_EnableIRQ(TIM3_IRQn);
28 mjames 282
  /* USER CODE BEGIN TIM3_MspInit 1 */
283
 
284
  /* USER CODE END TIM3_MspInit 1 */
285
  }
12 mjames 286
  else if(htim_base->Instance==TIM6)
2 mjames 287
  {
288
  /* USER CODE BEGIN TIM6_MspInit 0 */
289
 
290
  /* USER CODE END TIM6_MspInit 0 */
291
    /* Peripheral clock enable */
292
    __HAL_RCC_TIM6_CLK_ENABLE();
28 mjames 293
    /* TIM6 interrupt Init */
7 mjames 294
    HAL_NVIC_SetPriority(TIM6_IRQn, 0, 0);
295
    HAL_NVIC_EnableIRQ(TIM6_IRQn);
2 mjames 296
  /* USER CODE BEGIN TIM6_MspInit 1 */
297
 
298
  /* USER CODE END TIM6_MspInit 1 */
299
  }
300
 
301
}
302
 
29 mjames 303
void HAL_TIM_MspPostInit(TIM_HandleTypeDef* htim)
304
{
305
  GPIO_InitTypeDef GPIO_InitStruct = {0};
306
  if(htim->Instance==TIM3)
307
  {
308
  /* USER CODE BEGIN TIM3_MspPostInit 0 */
309
 
310
  /* USER CODE END TIM3_MspPostInit 0 */
311
 
312
    __HAL_RCC_GPIOC_CLK_ENABLE();
313
    /**TIM3 GPIO Configuration
314
    PC6     ------> TIM3_CH1
315
    */
316
    GPIO_InitStruct.Pin = GPIO_PIN_6;
317
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
318
    GPIO_InitStruct.Pull = GPIO_NOPULL;
319
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
320
    GPIO_InitStruct.Alternate = GPIO_AF2_TIM3;
321
    HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
322
 
323
  /* USER CODE BEGIN TIM3_MspPostInit 1 */
324
 
325
  /* USER CODE END TIM3_MspPostInit 1 */
326
  }
327
 
328
}
28 mjames 329
/**
330
* @brief TIM_Base MSP De-Initialization
331
* This function freeze the hardware resources used in this example
332
* @param htim_base: TIM_Base handle pointer
333
* @retval None
334
*/
12 mjames 335
void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* htim_base)
2 mjames 336
{
12 mjames 337
  if(htim_base->Instance==TIM2)
2 mjames 338
  {
339
  /* USER CODE BEGIN TIM2_MspDeInit 0 */
340
 
341
  /* USER CODE END TIM2_MspDeInit 0 */
342
    /* Peripheral clock disable */
343
    __HAL_RCC_TIM2_CLK_DISABLE();
28 mjames 344
 
345
    /**TIM2 GPIO Configuration
346
    PA15     ------> TIM2_CH1
2 mjames 347
    */
348
    HAL_GPIO_DeInit(CB_Pulse_GPIO_Port, CB_Pulse_Pin);
349
 
28 mjames 350
    /* TIM2 interrupt DeInit */
6 mjames 351
    HAL_NVIC_DisableIRQ(TIM2_IRQn);
2 mjames 352
  /* USER CODE BEGIN TIM2_MspDeInit 1 */
353
 
354
  /* USER CODE END TIM2_MspDeInit 1 */
12 mjames 355
  }
28 mjames 356
  else if(htim_base->Instance==TIM3)
357
  {
358
  /* USER CODE BEGIN TIM3_MspDeInit 0 */
359
 
360
  /* USER CODE END TIM3_MspDeInit 0 */
361
    /* Peripheral clock disable */
362
    __HAL_RCC_TIM3_CLK_DISABLE();
29 mjames 363
 
364
    /* TIM3 interrupt DeInit */
365
    HAL_NVIC_DisableIRQ(TIM3_IRQn);
28 mjames 366
  /* USER CODE BEGIN TIM3_MspDeInit 1 */
367
 
368
  /* USER CODE END TIM3_MspDeInit 1 */
369
  }
12 mjames 370
  else if(htim_base->Instance==TIM6)
2 mjames 371
  {
372
  /* USER CODE BEGIN TIM6_MspDeInit 0 */
373
 
374
  /* USER CODE END TIM6_MspDeInit 0 */
375
    /* Peripheral clock disable */
376
    __HAL_RCC_TIM6_CLK_DISABLE();
7 mjames 377
 
28 mjames 378
    /* TIM6 interrupt DeInit */
7 mjames 379
    HAL_NVIC_DisableIRQ(TIM6_IRQn);
2 mjames 380
  /* USER CODE BEGIN TIM6_MspDeInit 1 */
381
 
382
  /* USER CODE END TIM6_MspDeInit 1 */
12 mjames 383
  }
2 mjames 384
 
385
}
386
 
28 mjames 387
/**
388
* @brief UART MSP Initialization
389
* This function configures the hardware resources used in this example
390
* @param huart: UART handle pointer
391
* @retval None
392
*/
2 mjames 393
void HAL_UART_MspInit(UART_HandleTypeDef* huart)
394
{
28 mjames 395
  GPIO_InitTypeDef GPIO_InitStruct = {0};
2 mjames 396
  if(huart->Instance==USART1)
397
  {
398
  /* USER CODE BEGIN USART1_MspInit 0 */
399
 
400
  /* USER CODE END USART1_MspInit 0 */
401
    /* Peripheral clock enable */
402
    __HAL_RCC_USART1_CLK_ENABLE();
28 mjames 403
 
404
    __HAL_RCC_GPIOA_CLK_ENABLE();
405
    /**USART1 GPIO Configuration
2 mjames 406
    PA9     ------> USART1_TX
28 mjames 407
    PA10     ------> USART1_RX
2 mjames 408
    */
409
    GPIO_InitStruct.Pin = GPIO_PIN_9|GPIO_PIN_10;
410
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
28 mjames 411
    GPIO_InitStruct.Pull = GPIO_NOPULL;
2 mjames 412
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
413
    GPIO_InitStruct.Alternate = GPIO_AF7_USART1;
414
    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
415
 
28 mjames 416
    /* USART1 interrupt Init */
6 mjames 417
    HAL_NVIC_SetPriority(USART1_IRQn, 0, 0);
418
    HAL_NVIC_EnableIRQ(USART1_IRQn);
2 mjames 419
  /* USER CODE BEGIN USART1_MspInit 1 */
420
 
421
  /* USER CODE END USART1_MspInit 1 */
422
  }
6 mjames 423
  else if(huart->Instance==USART2)
424
  {
425
  /* USER CODE BEGIN USART2_MspInit 0 */
2 mjames 426
 
6 mjames 427
  /* USER CODE END USART2_MspInit 0 */
428
    /* Peripheral clock enable */
429
    __HAL_RCC_USART2_CLK_ENABLE();
28 mjames 430
 
431
    __HAL_RCC_GPIOA_CLK_ENABLE();
432
    /**USART2 GPIO Configuration
6 mjames 433
    PA2     ------> USART2_TX
28 mjames 434
    PA3     ------> USART2_RX
6 mjames 435
    */
436
    GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_3;
437
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
28 mjames 438
    GPIO_InitStruct.Pull = GPIO_NOPULL;
6 mjames 439
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
440
    GPIO_InitStruct.Alternate = GPIO_AF7_USART2;
441
    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
442
 
28 mjames 443
    /* USART2 interrupt Init */
6 mjames 444
    HAL_NVIC_SetPriority(USART2_IRQn, 0, 0);
445
    HAL_NVIC_EnableIRQ(USART2_IRQn);
446
  /* USER CODE BEGIN USART2_MspInit 1 */
447
 
448
  /* USER CODE END USART2_MspInit 1 */
449
  }
450
 
2 mjames 451
}
452
 
28 mjames 453
/**
454
* @brief UART MSP De-Initialization
455
* This function freeze the hardware resources used in this example
456
* @param huart: UART handle pointer
457
* @retval None
458
*/
2 mjames 459
void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
460
{
461
  if(huart->Instance==USART1)
462
  {
463
  /* USER CODE BEGIN USART1_MspDeInit 0 */
464
 
465
  /* USER CODE END USART1_MspDeInit 0 */
466
    /* Peripheral clock disable */
467
    __HAL_RCC_USART1_CLK_DISABLE();
28 mjames 468
 
469
    /**USART1 GPIO Configuration
2 mjames 470
    PA9     ------> USART1_TX
28 mjames 471
    PA10     ------> USART1_RX
2 mjames 472
    */
473
    HAL_GPIO_DeInit(GPIOA, GPIO_PIN_9|GPIO_PIN_10);
474
 
28 mjames 475
    /* USART1 interrupt DeInit */
6 mjames 476
    HAL_NVIC_DisableIRQ(USART1_IRQn);
2 mjames 477
  /* USER CODE BEGIN USART1_MspDeInit 1 */
478
 
479
  /* USER CODE END USART1_MspDeInit 1 */
6 mjames 480
  }
481
  else if(huart->Instance==USART2)
482
  {
483
  /* USER CODE BEGIN USART2_MspDeInit 0 */
2 mjames 484
 
6 mjames 485
  /* USER CODE END USART2_MspDeInit 0 */
486
    /* Peripheral clock disable */
487
    __HAL_RCC_USART2_CLK_DISABLE();
28 mjames 488
 
489
    /**USART2 GPIO Configuration
6 mjames 490
    PA2     ------> USART2_TX
28 mjames 491
    PA3     ------> USART2_RX
6 mjames 492
    */
493
    HAL_GPIO_DeInit(GPIOA, GPIO_PIN_2|GPIO_PIN_3);
494
 
28 mjames 495
    /* USART2 interrupt DeInit */
6 mjames 496
    HAL_NVIC_DisableIRQ(USART2_IRQn);
497
  /* USER CODE BEGIN USART2_MspDeInit 1 */
498
 
499
  /* USER CODE END USART2_MspDeInit 1 */
500
  }
501
 
2 mjames 502
}
503
 
504
/* USER CODE BEGIN 1 */
505
 
506
/* USER CODE END 1 */
507
 
508
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/