0
|
1 /**
|
|
2 ******************************************************************************
|
|
3 * File Name : TIM.c
|
|
4 * Description : This file provides code for the configuration
|
|
5 * of the TIM instances.
|
|
6 ******************************************************************************
|
|
7 *
|
|
8 * COPYRIGHT(c) 2017 STMicroelectronics
|
|
9 *
|
|
10 * Redistribution and use in source and binary forms, with or without modification,
|
|
11 * are permitted provided that the following conditions are met:
|
|
12 * 1. Redistributions of source code must retain the above copyright notice,
|
|
13 * this list of conditions and the following disclaimer.
|
|
14 * 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
15 * this list of conditions and the following disclaimer in the documentation
|
|
16 * and/or other materials provided with the distribution.
|
|
17 * 3. Neither the name of STMicroelectronics nor the names of its contributors
|
|
18 * may be used to endorse or promote products derived from this software
|
|
19 * without specific prior written permission.
|
|
20 *
|
|
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
24 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
27 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
28 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
29 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
31 *
|
|
32 ******************************************************************************
|
|
33 */
|
|
34
|
|
35 /* Includes ------------------------------------------------------------------*/
|
|
36 #include "tim.h"
|
|
37
|
|
38 /* USER CODE BEGIN 0 */
|
|
39
|
|
40 /* USER CODE END 0 */
|
|
41
|
|
42 TIM_HandleTypeDef htim2;
|
|
43
|
|
44 /* TIM2 init function */
|
|
45 void MX_TIM2_Init(void)
|
|
46 {
|
|
47 TIM_MasterConfigTypeDef sMasterConfig;
|
|
48 TIM_OC_InitTypeDef sConfigOC;
|
|
49
|
|
50 htim2.Instance = TIM2;
|
|
51 htim2.Init.Prescaler = 799;
|
|
52 htim2.Init.CounterMode = TIM_COUNTERMODE_UP;
|
|
53 htim2.Init.Period = 99;
|
|
54 htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
|
55 if (HAL_TIM_PWM_Init(&htim2) != HAL_OK)
|
|
56 {
|
|
57 Error_Handler();
|
|
58 }
|
|
59
|
|
60 sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
|
|
61 sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
|
|
62 if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != HAL_OK)
|
|
63 {
|
|
64 Error_Handler();
|
|
65 }
|
|
66
|
|
67 sConfigOC.OCMode = TIM_OCMODE_PWM1;
|
|
68 sConfigOC.Pulse = 29;
|
|
69 sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
|
|
70 sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
|
|
71 if (HAL_TIM_PWM_ConfigChannel(&htim2, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)
|
|
72 {
|
|
73 Error_Handler();
|
|
74 }
|
|
75
|
|
76 HAL_TIM_MspPostInit(&htim2);
|
|
77
|
|
78 }
|
|
79
|
|
80 void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef* tim_pwmHandle)
|
|
81 {
|
|
82
|
|
83 if(tim_pwmHandle->Instance==TIM2)
|
|
84 {
|
|
85 /* USER CODE BEGIN TIM2_MspInit 0 */
|
|
86
|
|
87 /* USER CODE END TIM2_MspInit 0 */
|
|
88 /* Peripheral clock enable */
|
|
89 __HAL_RCC_TIM2_CLK_ENABLE();
|
|
90 /* USER CODE BEGIN TIM2_MspInit 1 */
|
|
91
|
|
92 /* USER CODE END TIM2_MspInit 1 */
|
|
93 }
|
|
94 }
|
|
95 void HAL_TIM_MspPostInit(TIM_HandleTypeDef* timHandle)
|
|
96 {
|
|
97
|
|
98 GPIO_InitTypeDef GPIO_InitStruct;
|
|
99 if(timHandle->Instance==TIM2)
|
|
100 {
|
|
101 /* USER CODE BEGIN TIM2_MspPostInit 0 */
|
|
102
|
|
103 /* USER CODE END TIM2_MspPostInit 0 */
|
|
104
|
|
105 /**TIM2 GPIO Configuration
|
|
106 PA5 ------> TIM2_CH1
|
|
107 */
|
|
108 GPIO_InitStruct.Pin = GPIO_PIN_5;
|
|
109 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
|
110 GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
111 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
112 GPIO_InitStruct.Alternate = GPIO_AF1_TIM2;
|
|
113 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
|
114
|
|
115 /* USER CODE BEGIN TIM2_MspPostInit 1 */
|
|
116
|
|
117 /* USER CODE END TIM2_MspPostInit 1 */
|
|
118 }
|
|
119
|
|
120 }
|
|
121
|
|
122 void HAL_TIM_PWM_MspDeInit(TIM_HandleTypeDef* tim_pwmHandle)
|
|
123 {
|
|
124
|
|
125 if(tim_pwmHandle->Instance==TIM2)
|
|
126 {
|
|
127 /* USER CODE BEGIN TIM2_MspDeInit 0 */
|
|
128
|
|
129 /* USER CODE END TIM2_MspDeInit 0 */
|
|
130 /* Peripheral clock disable */
|
|
131 __HAL_RCC_TIM2_CLK_DISABLE();
|
|
132 }
|
|
133 /* USER CODE BEGIN TIM2_MspDeInit 1 */
|
|
134
|
|
135 /* USER CODE END TIM2_MspDeInit 1 */
|
|
136 }
|
|
137
|
|
138 /* USER CODE BEGIN 1 */
|
|
139
|
|
140 /* USER CODE END 1 */
|
|
141
|
|
142 /**
|
|
143 * @}
|
|
144 */
|
|
145
|
|
146 /**
|
|
147 * @}
|
|
148 */
|
|
149
|
|
150 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|