source: ecs_cellMon/firmware/Core/Src/tim.c

Last change on this file was 3, checked in by f.jahn, 20 months ago

fw hinzugfügt-->zed

File size: 4.6 KB
Line 
1/**
2  ******************************************************************************
3  * @file    tim.c
4  * @brief   This file provides code for the configuration
5  *          of the TIM instances.
6  ******************************************************************************
7  * @attention
8  *
9  * <h2><center>&copy; Copyright (c) 2021 STMicroelectronics.
10  * All rights reserved.</center></h2>
11  *
12  * This software component is licensed by ST under BSD 3-Clause license,
13  * the "License"; You may not use this file except in compliance with the
14  * License. You may obtain a copy of the License at:
15  *                        opensource.org/licenses/BSD-3-Clause
16  *
17  ******************************************************************************
18  */
19
20/* Includes ------------------------------------------------------------------*/
21#include "tim.h"
22
23/* USER CODE BEGIN 0 */
24
25/* USER CODE END 0 */
26
27TIM_HandleTypeDef htim1;
28
29/* TIM1 init function */
30void MX_TIM1_Init(void)
31{
32
33  /* USER CODE BEGIN TIM1_Init 0 */
34
35  /* USER CODE END TIM1_Init 0 */
36
37  TIM_ClockConfigTypeDef sClockSourceConfig = {0};
38  TIM_SlaveConfigTypeDef sSlaveConfig = {0};
39  TIM_MasterConfigTypeDef sMasterConfig = {0};
40  TIM_IC_InitTypeDef sConfigIC = {0};
41
42  /* USER CODE BEGIN TIM1_Init 1 */
43
44  /* USER CODE END TIM1_Init 1 */
45  htim1.Instance = TIM1;
46  htim1.Init.Prescaler = 0;
47  htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
48  htim1.Init.Period = 65535;
49  htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
50  htim1.Init.RepetitionCounter = 0;
51  htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
52  if (HAL_TIM_Base_Init(&htim1) != HAL_OK)
53  {
54    Error_Handler();
55  }
56  sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
57  if (HAL_TIM_ConfigClockSource(&htim1, &sClockSourceConfig) != HAL_OK)
58  {
59    Error_Handler();
60  }
61  if (HAL_TIM_IC_Init(&htim1) != HAL_OK)
62  {
63    Error_Handler();
64  }
65  sSlaveConfig.SlaveMode = TIM_SLAVEMODE_RESET;
66  sSlaveConfig.InputTrigger = TIM_TS_TI1FP1;
67  sSlaveConfig.TriggerPolarity = TIM_INPUTCHANNELPOLARITY_FALLING;
68  sSlaveConfig.TriggerFilter = 0;
69  if (HAL_TIM_SlaveConfigSynchro(&htim1, &sSlaveConfig) != HAL_OK)
70  {
71    Error_Handler();
72  }
73  sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
74  sMasterConfig.MasterOutputTrigger2 = TIM_TRGO2_RESET;
75  sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
76  if (HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig) != HAL_OK)
77  {
78    Error_Handler();
79  }
80  sConfigIC.ICPolarity = TIM_INPUTCHANNELPOLARITY_FALLING;
81  sConfigIC.ICSelection = TIM_ICSELECTION_DIRECTTI;
82  sConfigIC.ICPrescaler = TIM_ICPSC_DIV1;
83  sConfigIC.ICFilter = 0;
84  if (HAL_TIM_IC_ConfigChannel(&htim1, &sConfigIC, TIM_CHANNEL_1) != HAL_OK)
85  {
86    Error_Handler();
87  }
88  if (HAL_TIMEx_TISelection(&htim1, TIM_TIM1_TI1_COMP1, TIM_CHANNEL_1) != HAL_OK)
89  {
90    Error_Handler();
91  }
92  sConfigIC.ICPolarity = TIM_INPUTCHANNELPOLARITY_RISING;
93  if (HAL_TIM_IC_ConfigChannel(&htim1, &sConfigIC, TIM_CHANNEL_2) != HAL_OK)
94  {
95    Error_Handler();
96  }
97  if (HAL_TIMEx_TISelection(&htim1, TIM_TIM1_TI2_COMP2, TIM_CHANNEL_2) != HAL_OK)
98  {
99    Error_Handler();
100  }
101  /* USER CODE BEGIN TIM1_Init 2 */
102
103  /* USER CODE END TIM1_Init 2 */
104
105}
106
107void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* tim_baseHandle)
108{
109
110  GPIO_InitTypeDef GPIO_InitStruct = {0};
111  if(tim_baseHandle->Instance==TIM1)
112  {
113  /* USER CODE BEGIN TIM1_MspInit 0 */
114
115  /* USER CODE END TIM1_MspInit 0 */
116    /* TIM1 clock enable */
117    __HAL_RCC_TIM1_CLK_ENABLE();
118
119    __HAL_RCC_GPIOA_CLK_ENABLE();
120    /**TIM1 GPIO Configuration
121    PA8     ------> TIM1_CH1
122    */
123    GPIO_InitStruct.Pin = GPIO_PIN_8;
124    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
125    GPIO_InitStruct.Pull = GPIO_NOPULL;
126    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
127    GPIO_InitStruct.Alternate = GPIO_AF2_TIM1;
128    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
129
130  /* USER CODE BEGIN TIM1_MspInit 1 */
131
132  /* USER CODE END TIM1_MspInit 1 */
133  }
134}
135
136void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* tim_baseHandle)
137{
138
139  if(tim_baseHandle->Instance==TIM1)
140  {
141  /* USER CODE BEGIN TIM1_MspDeInit 0 */
142
143  /* USER CODE END TIM1_MspDeInit 0 */
144    /* Peripheral clock disable */
145    __HAL_RCC_TIM1_CLK_DISABLE();
146
147    /**TIM1 GPIO Configuration
148    PA8     ------> TIM1_CH1
149    */
150    HAL_GPIO_DeInit(GPIOA, GPIO_PIN_8);
151
152  /* USER CODE BEGIN TIM1_MspDeInit 1 */
153
154  /* USER CODE END TIM1_MspDeInit 1 */
155  }
156}
157
158/* USER CODE BEGIN 1 */
159
160/* USER CODE END 1 */
161
162/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Note: See TracBrowser for help on using the repository browser.