annotate f103c8/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim.c @ 6:ca42336826bd default tip

working on clock sources
author cin
date Mon, 23 Jan 2017 02:40:17 +0300
parents 0c59e7a7782a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2 ******************************************************************************
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3 * @file stm32f1xx_hal_tim.c
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4 * @author MCD Application Team
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5 * @version V1.0.4
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
6 * @date 29-April-2016
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
7 * @brief TIM HAL module driver
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
8 * This file provides firmware functions to manage the following
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
9 * functionalities of the Timer (TIM) peripheral:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
10 * + Time Base Initialization
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
11 * + Time Base Start
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
12 * + Time Base Start Interruption
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
13 * + Time Base Start DMA
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
14 * + Time Output Compare/PWM Initialization
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
15 * + Time Output Compare/PWM Channel Configuration
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
16 * + Time Output Compare/PWM Start
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
17 * + Time Output Compare/PWM Start Interruption
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
18 * + Time Output Compare/PWM Start DMA
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
19 * + Time Input Capture Initialization
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
20 * + Time Input Capture Channel Configuration
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
21 * + Time Input Capture Start
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
22 * + Time Input Capture Start Interruption
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
23 * + Time Input Capture Start DMA
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
24 * + Time One Pulse Initialization
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
25 * + Time One Pulse Channel Configuration
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
26 * + Time One Pulse Start
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
27 * + Time Encoder Interface Initialization
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
28 * + Time Encoder Interface Start
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
29 * + Time Encoder Interface Start Interruption
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
30 * + Time Encoder Interface Start DMA
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
31 * + Commutation Event configuration with Interruption and DMA
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
32 * + Time OCRef clear configuration
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
33 * + Time External Clock configuration
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
34 @verbatim
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
35 ==============================================================================
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
36 ##### TIMER Generic features #####
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
37 ==============================================================================
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
38 [..] The Timer features include:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
39 (#) 16-bit up, down, up/down auto-reload counter.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
40 (#) 16-bit programmable prescaler allowing dividing (also on the fly) the
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
41 counter clock frequency either by any factor between 1 and 65536.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
42 (#) Up to 4 independent channels for:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
43 (++) Input Capture
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
44 (++) Output Compare
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
45 (++) PWM generation (Edge and Center-aligned Mode)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
46 (++) One-pulse mode output
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
47
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
48 ##### How to use this driver #####
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
49 ==============================================================================
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
50 [..]
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
51 (#) Initialize the TIM low level resources by implementing the following functions
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
52 depending from feature used :
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
53 (++) Time Base : HAL_TIM_Base_MspInit()
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
54 (++) Input Capture : HAL_TIM_IC_MspInit()
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
55 (++) Output Compare : HAL_TIM_OC_MspInit()
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
56 (++) PWM generation : HAL_TIM_PWM_MspInit()
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
57 (++) One-pulse mode output : HAL_TIM_OnePulse_MspInit()
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
58 (++) Encoder mode output : HAL_TIM_Encoder_MspInit()
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
59
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
60 (#) Initialize the TIM low level resources :
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
61 (##) Enable the TIM interface clock using __HAL_RCC_TIMx_CLK_ENABLE();
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
62 (##) TIM pins configuration
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
63 (+++) Enable the clock for the TIM GPIOs using the following function:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
64 __HAL_RCC_GPIOx_CLK_ENABLE();
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
65 (+++) Configure these TIM pins in Alternate function mode using HAL_GPIO_Init();
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
66
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
67 (#) The external Clock can be configured, if needed (the default clock is the
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
68 internal clock from the APBx), using the following function:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
69 HAL_TIM_ConfigClockSource, the clock configuration should be done before
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
70 any start function.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
71
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
72 (#) Configure the TIM in the desired functioning mode using one of the
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
73 Initialization function of this driver:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
74 (++) HAL_TIM_Base_Init: to use the Timer to generate a simple time base
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
75 (++) HAL_TIM_OC_Init and HAL_TIM_OC_ConfigChannel: to use the Timer to generate an
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
76 Output Compare signal.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
77 (++) HAL_TIM_PWM_Init and HAL_TIM_PWM_ConfigChannel: to use the Timer to generate a
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
78 PWM signal.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
79 (++) HAL_TIM_IC_Init and HAL_TIM_IC_ConfigChannel: to use the Timer to measure an
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
80 external signal.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
81 (++) HAL_TIM_OnePulse_Init and HAL_TIM_OnePulse_ConfigChannel: to use the Timer
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
82 in One Pulse Mode.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
83 (++) HAL_TIM_Encoder_Init: to use the Timer Encoder Interface.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
84
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
85 (#) Activate the TIM peripheral using one of the start functions depending from the feature used:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
86 (++) Time Base : HAL_TIM_Base_Start(), HAL_TIM_Base_Start_DMA(), HAL_TIM_Base_Start_IT()
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
87 (++) Input Capture : HAL_TIM_IC_Start(), HAL_TIM_IC_Start_DMA(), HAL_TIM_IC_Start_IT()
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
88 (++) Output Compare : HAL_TIM_OC_Start(), HAL_TIM_OC_Start_DMA(), HAL_TIM_OC_Start_IT()
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
89 (++) PWM generation : HAL_TIM_PWM_Start(), HAL_TIM_PWM_Start_DMA(), HAL_TIM_PWM_Start_IT()
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
90 (++) One-pulse mode output : HAL_TIM_OnePulse_Start(), HAL_TIM_OnePulse_Start_IT()
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
91 (++) Encoder mode output : HAL_TIM_Encoder_Start(), HAL_TIM_Encoder_Start_DMA(), HAL_TIM_Encoder_Start_IT().
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
92
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
93 (#) The DMA Burst is managed with the two following functions:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
94 HAL_TIM_DMABurst_WriteStart()
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
95 HAL_TIM_DMABurst_ReadStart()
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
96
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
97 @endverbatim
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
98 ******************************************************************************
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
99 * @attention
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
100 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
101 * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
102 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
103 * Redistribution and use in source and binary forms, with or without modification,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
104 * are permitted provided that the following conditions are met:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
105 * 1. Redistributions of source code must retain the above copyright notice,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
106 * this list of conditions and the following disclaimer.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
107 * 2. Redistributions in binary form must reproduce the above copyright notice,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
108 * this list of conditions and the following disclaimer in the documentation
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
109 * and/or other materials provided with the distribution.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
110 * 3. Neither the name of STMicroelectronics nor the names of its contributors
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
111 * may be used to endorse or promote products derived from this software
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
112 * without specific prior written permission.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
113 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
114 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
115 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
116 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
117 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
118 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
119 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
120 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
121 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
122 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
123 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
124 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
125 ******************************************************************************
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
126 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
127
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
128 /* Includes ------------------------------------------------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
129 #include "stm32f1xx_hal.h"
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
130
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
131 /** @addtogroup STM32F1xx_HAL_Driver
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
132 * @{
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
133 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
134
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
135 /** @defgroup TIM TIM
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
136 * @brief TIM HAL module driver
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
137 * @{
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
138 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
139
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
140 #ifdef HAL_TIM_MODULE_ENABLED
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
141
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
142 /* Private typedef -----------------------------------------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
143 /* Private define ------------------------------------------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
144 /* Private macro -------------------------------------------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
145 /* Private variables ---------------------------------------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
146 /* Private function prototypes -----------------------------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
147 /** @defgroup TIM_Private_Functions TIM Private Functions
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
148 * @{
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
149 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
150 static void TIM_OC1_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
151 static void TIM_OC3_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
152 static void TIM_OC4_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
153 static void TIM_TI1_ConfigInputStage(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICFilter);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
154 static void TIM_TI2_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
155 uint32_t TIM_ICFilter);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
156 static void TIM_TI2_ConfigInputStage(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICFilter);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
157 static void TIM_TI3_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
158 uint32_t TIM_ICFilter);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
159 static void TIM_TI4_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
160 uint32_t TIM_ICFilter);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
161 static void TIM_ETR_SetConfig(TIM_TypeDef* TIMx, uint32_t TIM_ExtTRGPrescaler,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
162 uint32_t TIM_ExtTRGPolarity, uint32_t ExtTRGFilter);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
163 static void TIM_ITRx_SetConfig(TIM_TypeDef* TIMx, uint16_t InputTriggerSource);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
164 static void TIM_DMAPeriodElapsedCplt(DMA_HandleTypeDef *hdma);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
165 static void TIM_DMATriggerCplt(DMA_HandleTypeDef *hdma);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
166 static void TIM_SlaveTimer_SetConfig(TIM_HandleTypeDef *htim,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
167 TIM_SlaveConfigTypeDef * sSlaveConfig);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
168
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
169 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
170 * @}
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
171 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
172
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
173 /* Exported functions ---------------------------------------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
174
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
175 /** @defgroup TIM_Exported_Functions TIM Exported Functions
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
176 * @{
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
177 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
178
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
179 /** @defgroup TIM_Exported_Functions_Group1 Time Base functions
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
180 * @brief Time Base functions
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
181 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
182 @verbatim
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
183 ==============================================================================
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
184 ##### Time Base functions #####
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
185 ==============================================================================
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
186 [..]
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
187 This section provides functions allowing to:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
188 (+) Initialize and configure the TIM base.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
189 (+) De-initialize the TIM base.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
190 (+) Start the Time Base.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
191 (+) Stop the Time Base.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
192 (+) Start the Time Base and enable interrupt.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
193 (+) Stop the Time Base and disable interrupt.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
194 (+) Start the Time Base and enable DMA transfer.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
195 (+) Stop the Time Base and disable DMA transfer.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
196
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
197 @endverbatim
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
198 * @{
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
199 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
200 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
201 * @brief Initializes the TIM Time base Unit according to the specified
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
202 * parameters in the TIM_HandleTypeDef and create the associated handle.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
203 * @param htim : TIM Base handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
204 * @retval HAL status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
205 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
206 HAL_StatusTypeDef HAL_TIM_Base_Init(TIM_HandleTypeDef *htim)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
207 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
208 /* Check the TIM handle allocation */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
209 if(htim == NULL)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
210 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
211 return HAL_ERROR;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
212 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
213
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
214 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
215 assert_param(IS_TIM_INSTANCE(htim->Instance));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
216 assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
217 assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
218
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
219 if(htim->State == HAL_TIM_STATE_RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
220 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
221 /* Allocate lock resource and initialize it */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
222 htim->Lock = HAL_UNLOCKED;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
223
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
224 /* Init the low level hardware : GPIO, CLOCK, NVIC */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
225 HAL_TIM_Base_MspInit(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
226 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
227
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
228 /* Set the TIM state */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
229 htim->State= HAL_TIM_STATE_BUSY;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
230
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
231 /* Set the Time Base configuration */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
232 TIM_Base_SetConfig(htim->Instance, &htim->Init);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
233
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
234 /* Initialize the TIM state*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
235 htim->State= HAL_TIM_STATE_READY;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
236
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
237 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
238 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
239
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
240 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
241 * @brief DeInitializes the TIM Base peripheral
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
242 * @param htim : TIM Base handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
243 * @retval HAL status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
244 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
245 HAL_StatusTypeDef HAL_TIM_Base_DeInit(TIM_HandleTypeDef *htim)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
246 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
247 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
248 assert_param(IS_TIM_INSTANCE(htim->Instance));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
249
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
250 htim->State = HAL_TIM_STATE_BUSY;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
251
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
252 /* Disable the TIM Peripheral Clock */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
253 __HAL_TIM_DISABLE(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
254
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
255 /* DeInit the low level hardware: GPIO, CLOCK, NVIC */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
256 HAL_TIM_Base_MspDeInit(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
257
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
258 /* Change TIM state */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
259 htim->State = HAL_TIM_STATE_RESET;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
260
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
261 /* Release Lock */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
262 __HAL_UNLOCK(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
263
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
264 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
265 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
266
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
267 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
268 * @brief Initializes the TIM Base MSP.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
269 * @param htim : TIM handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
270 * @retval None
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
271 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
272 __weak void HAL_TIM_Base_MspInit(TIM_HandleTypeDef *htim)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
273 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
274 /* Prevent unused argument(s) compilation warning */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
275 UNUSED(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
276 /* NOTE : This function Should not be modified, when the callback is needed,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
277 the HAL_TIM_Base_MspInit could be implemented in the user file
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
278 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
279 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
280
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
281 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
282 * @brief DeInitializes TIM Base MSP.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
283 * @param htim : TIM handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
284 * @retval None
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
285 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
286 __weak void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef *htim)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
287 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
288 /* Prevent unused argument(s) compilation warning */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
289 UNUSED(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
290 /* NOTE : This function Should not be modified, when the callback is needed,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
291 the HAL_TIM_Base_MspDeInit could be implemented in the user file
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
292 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
293 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
294
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
295
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
296 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
297 * @brief Starts the TIM Base generation.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
298 * @param htim : TIM handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
299 * @retval HAL status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
300 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
301 HAL_StatusTypeDef HAL_TIM_Base_Start(TIM_HandleTypeDef *htim)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
302 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
303 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
304 assert_param(IS_TIM_INSTANCE(htim->Instance));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
305
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
306 /* Set the TIM state */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
307 htim->State= HAL_TIM_STATE_BUSY;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
308
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
309 /* Enable the Peripheral */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
310 __HAL_TIM_ENABLE(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
311
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
312 /* Change the TIM state*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
313 htim->State= HAL_TIM_STATE_READY;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
314
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
315 /* Return function status */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
316 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
317 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
318
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
319 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
320 * @brief Stops the TIM Base generation.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
321 * @param htim : TIM handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
322 * @retval HAL status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
323 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
324 HAL_StatusTypeDef HAL_TIM_Base_Stop(TIM_HandleTypeDef *htim)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
325 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
326 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
327 assert_param(IS_TIM_INSTANCE(htim->Instance));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
328
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
329 /* Set the TIM state */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
330 htim->State= HAL_TIM_STATE_BUSY;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
331
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
332 /* Disable the Peripheral */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
333 __HAL_TIM_DISABLE(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
334
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
335 /* Change the TIM state*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
336 htim->State= HAL_TIM_STATE_READY;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
337
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
338 /* Return function status */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
339 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
340 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
341
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
342 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
343 * @brief Starts the TIM Base generation in interrupt mode.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
344 * @param htim : TIM handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
345 * @retval HAL status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
346 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
347 HAL_StatusTypeDef HAL_TIM_Base_Start_IT(TIM_HandleTypeDef *htim)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
348 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
349 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
350 assert_param(IS_TIM_INSTANCE(htim->Instance));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
351
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
352 /* Enable the TIM Update interrupt */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
353 __HAL_TIM_ENABLE_IT(htim, TIM_IT_UPDATE);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
354
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
355 /* Enable the Peripheral */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
356 __HAL_TIM_ENABLE(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
357
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
358 /* Return function status */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
359 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
360 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
361
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
362 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
363 * @brief Stops the TIM Base generation in interrupt mode.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
364 * @param htim : TIM handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
365 * @retval HAL status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
366 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
367 HAL_StatusTypeDef HAL_TIM_Base_Stop_IT(TIM_HandleTypeDef *htim)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
368 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
369 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
370 assert_param(IS_TIM_INSTANCE(htim->Instance));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
371 /* Disable the TIM Update interrupt */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
372 __HAL_TIM_DISABLE_IT(htim, TIM_IT_UPDATE);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
373
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
374 /* Disable the Peripheral */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
375 __HAL_TIM_DISABLE(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
376
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
377 /* Return function status */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
378 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
379 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
380
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
381 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
382 * @brief Starts the TIM Base generation in DMA mode.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
383 * @param htim : TIM handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
384 * @param pData : The source Buffer address.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
385 * @param Length : The length of data to be transferred from memory to peripheral.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
386 * @retval HAL status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
387 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
388 HAL_StatusTypeDef HAL_TIM_Base_Start_DMA(TIM_HandleTypeDef *htim, uint32_t *pData, uint16_t Length)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
389 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
390 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
391 assert_param(IS_TIM_DMA_INSTANCE(htim->Instance));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
392
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
393 if((htim->State == HAL_TIM_STATE_BUSY))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
394 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
395 return HAL_BUSY;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
396 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
397 else if((htim->State == HAL_TIM_STATE_READY))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
398 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
399 if((pData == 0 ) && (Length > 0))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
400 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
401 return HAL_ERROR;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
402 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
403 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
404 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
405 htim->State = HAL_TIM_STATE_BUSY;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
406 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
407 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
408 /* Set the DMA Period elapsed callback */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
409 htim->hdma[TIM_DMA_ID_UPDATE]->XferCpltCallback = TIM_DMAPeriodElapsedCplt;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
410
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
411 /* Set the DMA error callback */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
412 htim->hdma[TIM_DMA_ID_UPDATE]->XferErrorCallback = TIM_DMAError ;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
413
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
414 /* Enable the DMA channel */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
415 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_UPDATE], (uint32_t)pData, (uint32_t)&htim->Instance->ARR, Length);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
416
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
417 /* Enable the TIM Update DMA request */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
418 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_UPDATE);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
419
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
420 /* Enable the Peripheral */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
421 __HAL_TIM_ENABLE(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
422
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
423 /* Return function status */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
424 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
425 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
426
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
427 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
428 * @brief Stops the TIM Base generation in DMA mode.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
429 * @param htim : TIM handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
430 * @retval HAL status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
431 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
432 HAL_StatusTypeDef HAL_TIM_Base_Stop_DMA(TIM_HandleTypeDef *htim)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
433 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
434 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
435 assert_param(IS_TIM_DMA_INSTANCE(htim->Instance));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
436
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
437 /* Disable the TIM Update DMA request */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
438 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_UPDATE);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
439
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
440 /* Disable the Peripheral */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
441 __HAL_TIM_DISABLE(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
442
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
443 /* Change the htim state */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
444 htim->State = HAL_TIM_STATE_READY;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
445
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
446 /* Return function status */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
447 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
448 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
449
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
450 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
451 * @}
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
452 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
453
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
454 /** @defgroup TIM_Exported_Functions_Group2 Time Output Compare functions
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
455 * @brief Time Output Compare functions
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
456 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
457 @verbatim
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
458 ==============================================================================
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
459 ##### Time Output Compare functions #####
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
460 ==============================================================================
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
461 [..]
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
462 This section provides functions allowing to:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
463 (+) Initialize and configure the TIM Output Compare.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
464 (+) De-initialize the TIM Output Compare.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
465 (+) Start the Time Output Compare.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
466 (+) Stop the Time Output Compare.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
467 (+) Start the Time Output Compare and enable interrupt.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
468 (+) Stop the Time Output Compare and disable interrupt.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
469 (+) Start the Time Output Compare and enable DMA transfer.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
470 (+) Stop the Time Output Compare and disable DMA transfer.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
471
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
472 @endverbatim
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
473 * @{
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
474 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
475 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
476 * @brief Initializes the TIM Output Compare according to the specified
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
477 * parameters in the TIM_HandleTypeDef and create the associated handle.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
478 * @param htim : TIM Output Compare handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
479 * @retval HAL status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
480 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
481 HAL_StatusTypeDef HAL_TIM_OC_Init(TIM_HandleTypeDef* htim)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
482 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
483 /* Check the TIM handle allocation */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
484 if(htim == NULL)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
485 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
486 return HAL_ERROR;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
487 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
488
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
489 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
490 assert_param(IS_TIM_INSTANCE(htim->Instance));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
491 assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
492 assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
493
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
494 if(htim->State == HAL_TIM_STATE_RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
495 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
496 /* Allocate lock resource and initialize it */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
497 htim->Lock = HAL_UNLOCKED;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
498
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
499 /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
500 HAL_TIM_OC_MspInit(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
501 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
502
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
503 /* Set the TIM state */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
504 htim->State= HAL_TIM_STATE_BUSY;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
505
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
506 /* Init the base time for the Output Compare */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
507 TIM_Base_SetConfig(htim->Instance, &htim->Init);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
508
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
509 /* Initialize the TIM state*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
510 htim->State= HAL_TIM_STATE_READY;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
511
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
512 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
513 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
514
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
515 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
516 * @brief DeInitializes the TIM peripheral
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
517 * @param htim : TIM Output Compare handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
518 * @retval HAL status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
519 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
520 HAL_StatusTypeDef HAL_TIM_OC_DeInit(TIM_HandleTypeDef *htim)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
521 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
522 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
523 assert_param(IS_TIM_INSTANCE(htim->Instance));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
524
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
525 htim->State = HAL_TIM_STATE_BUSY;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
526
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
527 /* Disable the TIM Peripheral Clock */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
528 __HAL_TIM_DISABLE(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
529
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
530 /* DeInit the low level hardware: GPIO, CLOCK, NVIC and DMA */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
531 HAL_TIM_OC_MspDeInit(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
532
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
533 /* Change TIM state */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
534 htim->State = HAL_TIM_STATE_RESET;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
535
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
536 /* Release Lock */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
537 __HAL_UNLOCK(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
538
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
539 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
540 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
541
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
542 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
543 * @brief Initializes the TIM Output Compare MSP.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
544 * @param htim : TIM handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
545 * @retval None
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
546 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
547 __weak void HAL_TIM_OC_MspInit(TIM_HandleTypeDef *htim)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
548 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
549 /* Prevent unused argument(s) compilation warning */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
550 UNUSED(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
551 /* NOTE : This function Should not be modified, when the callback is needed,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
552 the HAL_TIM_OC_MspInit could be implemented in the user file
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
553 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
554 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
555
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
556 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
557 * @brief DeInitializes TIM Output Compare MSP.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
558 * @param htim : TIM handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
559 * @retval None
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
560 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
561 __weak void HAL_TIM_OC_MspDeInit(TIM_HandleTypeDef *htim)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
562 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
563 /* Prevent unused argument(s) compilation warning */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
564 UNUSED(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
565 /* NOTE : This function Should not be modified, when the callback is needed,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
566 the HAL_TIM_OC_MspDeInit could be implemented in the user file
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
567 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
568 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
569
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
570 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
571 * @brief Starts the TIM Output Compare signal generation.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
572 * @param htim : TIM Output Compare handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
573 * @param Channel : TIM Channel to be enabled
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
574 * This parameter can be one of the following values:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
575 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
576 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
577 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
578 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
579 * @retval HAL status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
580 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
581 HAL_StatusTypeDef HAL_TIM_OC_Start(TIM_HandleTypeDef *htim, uint32_t Channel)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
582 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
583 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
584 assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
585
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
586 /* Enable the Output compare channel */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
587 TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
588
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
589 if(IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
590 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
591 /* Enable the main output */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
592 __HAL_TIM_MOE_ENABLE(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
593 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
594
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
595 /* Enable the Peripheral */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
596 __HAL_TIM_ENABLE(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
597
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
598 /* Return function status */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
599 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
600 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
601
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
602 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
603 * @brief Stops the TIM Output Compare signal generation.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
604 * @param htim : TIM handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
605 * @param Channel : TIM Channel to be disabled
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
606 * This parameter can be one of the following values:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
607 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
608 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
609 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
610 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
611 * @retval HAL status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
612 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
613 HAL_StatusTypeDef HAL_TIM_OC_Stop(TIM_HandleTypeDef *htim, uint32_t Channel)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
614 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
615 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
616 assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
617
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
618 /* Disable the Output compare channel */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
619 TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
620
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
621 if(IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
622 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
623 /* Disable the Main Ouput */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
624 __HAL_TIM_MOE_DISABLE(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
625 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
626
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
627 /* Disable the Peripheral */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
628 __HAL_TIM_DISABLE(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
629
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
630 /* Return function status */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
631 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
632 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
633
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
634 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
635 * @brief Starts the TIM Output Compare signal generation in interrupt mode.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
636 * @param htim : TIM OC handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
637 * @param Channel : TIM Channel to be enabled
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
638 * This parameter can be one of the following values:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
639 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
640 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
641 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
642 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
643 * @retval HAL status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
644 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
645 HAL_StatusTypeDef HAL_TIM_OC_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
646 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
647 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
648 assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
649
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
650 switch (Channel)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
651 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
652 case TIM_CHANNEL_1:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
653 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
654 /* Enable the TIM Capture/Compare 1 interrupt */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
655 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
656 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
657 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
658
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
659 case TIM_CHANNEL_2:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
660 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
661 /* Enable the TIM Capture/Compare 2 interrupt */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
662 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
663 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
664 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
665
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
666 case TIM_CHANNEL_3:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
667 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
668 /* Enable the TIM Capture/Compare 3 interrupt */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
669 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC3);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
670 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
671 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
672
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
673 case TIM_CHANNEL_4:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
674 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
675 /* Enable the TIM Capture/Compare 4 interrupt */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
676 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC4);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
677 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
678 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
679
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
680 default:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
681 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
682 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
683
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
684 /* Enable the Output compare channel */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
685 TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
686
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
687 if(IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
688 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
689 /* Enable the main output */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
690 __HAL_TIM_MOE_ENABLE(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
691 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
692
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
693 /* Enable the Peripheral */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
694 __HAL_TIM_ENABLE(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
695
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
696 /* Return function status */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
697 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
698 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
699
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
700 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
701 * @brief Stops the TIM Output Compare signal generation in interrupt mode.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
702 * @param htim : TIM Output Compare handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
703 * @param Channel : TIM Channel to be disabled
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
704 * This parameter can be one of the following values:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
705 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
706 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
707 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
708 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
709 * @retval HAL status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
710 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
711 HAL_StatusTypeDef HAL_TIM_OC_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
712 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
713 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
714 assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
715
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
716 switch (Channel)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
717 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
718 case TIM_CHANNEL_1:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
719 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
720 /* Disable the TIM Capture/Compare 1 interrupt */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
721 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
722 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
723 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
724
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
725 case TIM_CHANNEL_2:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
726 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
727 /* Disable the TIM Capture/Compare 2 interrupt */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
728 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
729 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
730 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
731
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
732 case TIM_CHANNEL_3:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
733 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
734 /* Disable the TIM Capture/Compare 3 interrupt */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
735 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC3);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
736 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
737 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
738
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
739 case TIM_CHANNEL_4:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
740 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
741 /* Disable the TIM Capture/Compare 4 interrupt */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
742 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC4);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
743 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
744 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
745
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
746 default:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
747 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
748 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
749
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
750 /* Disable the Output compare channel */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
751 TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
752
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
753 if(IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
754 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
755 /* Disable the Main Ouput */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
756 __HAL_TIM_MOE_DISABLE(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
757 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
758
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
759 /* Disable the Peripheral */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
760 __HAL_TIM_DISABLE(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
761
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
762 /* Return function status */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
763 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
764 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
765
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
766 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
767 * @brief Starts the TIM Output Compare signal generation in DMA mode.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
768 * @param htim : TIM Output Compare handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
769 * @param Channel : TIM Channel to be enabled
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
770 * This parameter can be one of the following values:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
771 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
772 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
773 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
774 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
775 * @param pData : The source Buffer address.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
776 * @param Length : The length of data to be transferred from memory to TIM peripheral
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
777 * @retval HAL status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
778 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
779 HAL_StatusTypeDef HAL_TIM_OC_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
780 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
781 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
782 assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
783
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
784 if((htim->State == HAL_TIM_STATE_BUSY))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
785 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
786 return HAL_BUSY;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
787 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
788 else if((htim->State == HAL_TIM_STATE_READY))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
789 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
790 if(((uint32_t)pData == 0 ) && (Length > 0))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
791 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
792 return HAL_ERROR;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
793 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
794 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
795 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
796 htim->State = HAL_TIM_STATE_BUSY;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
797 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
798 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
799 switch (Channel)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
800 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
801 case TIM_CHANNEL_1:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
802 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
803 /* Set the DMA Period elapsed callback */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
804 htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMADelayPulseCplt;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
805
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
806 /* Set the DMA error callback */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
807 htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
808
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
809 /* Enable the DMA channel */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
810 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)pData, (uint32_t)&htim->Instance->CCR1, Length);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
811
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
812 /* Enable the TIM Capture/Compare 1 DMA request */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
813 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
814 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
815 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
816
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
817 case TIM_CHANNEL_2:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
818 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
819 /* Set the DMA Period elapsed callback */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
820 htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMADelayPulseCplt;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
821
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
822 /* Set the DMA error callback */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
823 htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError ;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
824
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
825 /* Enable the DMA channel */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
826 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)pData, (uint32_t)&htim->Instance->CCR2, Length);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
827
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
828 /* Enable the TIM Capture/Compare 2 DMA request */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
829 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
830 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
831 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
832
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
833 case TIM_CHANNEL_3:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
834 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
835 /* Set the DMA Period elapsed callback */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
836 htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMADelayPulseCplt;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
837
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
838 /* Set the DMA error callback */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
839 htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = TIM_DMAError ;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
840
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
841 /* Enable the DMA channel */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
842 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)pData, (uint32_t)&htim->Instance->CCR3,Length);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
843
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
844 /* Enable the TIM Capture/Compare 3 DMA request */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
845 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC3);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
846 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
847 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
848
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
849 case TIM_CHANNEL_4:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
850 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
851 /* Set the DMA Period elapsed callback */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
852 htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = TIM_DMADelayPulseCplt;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
853
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
854 /* Set the DMA error callback */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
855 htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = TIM_DMAError ;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
856
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
857 /* Enable the DMA channel */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
858 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)pData, (uint32_t)&htim->Instance->CCR4, Length);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
859
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
860 /* Enable the TIM Capture/Compare 4 DMA request */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
861 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC4);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
862 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
863 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
864
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
865 default:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
866 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
867 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
868
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
869 /* Enable the Output compare channel */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
870 TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
871
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
872 if(IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
873 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
874 /* Enable the main output */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
875 __HAL_TIM_MOE_ENABLE(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
876 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
877
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
878 /* Enable the Peripheral */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
879 __HAL_TIM_ENABLE(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
880
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
881 /* Return function status */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
882 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
883 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
884
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
885 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
886 * @brief Stops the TIM Output Compare signal generation in DMA mode.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
887 * @param htim : TIM Output Compare handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
888 * @param Channel : TIM Channel to be disabled
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
889 * This parameter can be one of the following values:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
890 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
891 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
892 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
893 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
894 * @retval HAL status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
895 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
896 HAL_StatusTypeDef HAL_TIM_OC_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
897 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
898 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
899 assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
900
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
901 switch (Channel)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
902 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
903 case TIM_CHANNEL_1:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
904 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
905 /* Disable the TIM Capture/Compare 1 DMA request */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
906 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
907 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
908 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
909
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
910 case TIM_CHANNEL_2:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
911 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
912 /* Disable the TIM Capture/Compare 2 DMA request */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
913 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
914 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
915 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
916
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
917 case TIM_CHANNEL_3:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
918 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
919 /* Disable the TIM Capture/Compare 3 DMA request */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
920 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC3);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
921 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
922 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
923
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
924 case TIM_CHANNEL_4:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
925 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
926 /* Disable the TIM Capture/Compare 4 interrupt */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
927 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC4);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
928 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
929 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
930
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
931 default:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
932 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
933 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
934
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
935 /* Disable the Output compare channel */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
936 TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
937
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
938 if(IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
939 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
940 /* Disable the Main Ouput */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
941 __HAL_TIM_MOE_DISABLE(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
942 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
943
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
944 /* Disable the Peripheral */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
945 __HAL_TIM_DISABLE(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
946
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
947 /* Change the htim state */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
948 htim->State = HAL_TIM_STATE_READY;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
949
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
950 /* Return function status */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
951 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
952 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
953
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
954 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
955 * @}
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
956 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
957
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
958 /** @defgroup TIM_Exported_Functions_Group3 Time PWM functions
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
959 * @brief Time PWM functions
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
960 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
961 @verbatim
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
962 ==============================================================================
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
963 ##### Time PWM functions #####
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
964 ==============================================================================
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
965 [..]
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
966 This section provides functions allowing to:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
967 (+) Initialize and configure the TIM PWM.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
968 (+) De-initialize the TIM PWM.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
969 (+) Start the Time PWM.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
970 (+) Stop the Time PWM.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
971 (+) Start the Time PWM and enable interrupt.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
972 (+) Stop the Time PWM and disable interrupt.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
973 (+) Start the Time PWM and enable DMA transfer.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
974 (+) Stop the Time PWM and disable DMA transfer.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
975
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
976 @endverbatim
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
977 * @{
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
978 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
979 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
980 * @brief Initializes the TIM PWM Time Base according to the specified
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
981 * parameters in the TIM_HandleTypeDef and create the associated handle.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
982 * @param htim : TIM handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
983 * @retval HAL status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
984 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
985 HAL_StatusTypeDef HAL_TIM_PWM_Init(TIM_HandleTypeDef *htim)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
986 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
987 /* Check the TIM handle allocation */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
988 if(htim == NULL)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
989 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
990 return HAL_ERROR;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
991 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
992
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
993 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
994 assert_param(IS_TIM_INSTANCE(htim->Instance));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
995 assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
996 assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
997
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
998 if(htim->State == HAL_TIM_STATE_RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
999 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1000 /* Allocate lock resource and initialize it */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1001 htim->Lock = HAL_UNLOCKED;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1002
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1003 /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1004 HAL_TIM_PWM_MspInit(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1005 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1006
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1007 /* Set the TIM state */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1008 htim->State= HAL_TIM_STATE_BUSY;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1009
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1010 /* Init the base time for the PWM */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1011 TIM_Base_SetConfig(htim->Instance, &htim->Init);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1012
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1013 /* Initialize the TIM state*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1014 htim->State= HAL_TIM_STATE_READY;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1015
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1016 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1017 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1018
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1019 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1020 * @brief DeInitializes the TIM peripheral
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1021 * @param htim : TIM handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1022 * @retval HAL status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1023 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1024 HAL_StatusTypeDef HAL_TIM_PWM_DeInit(TIM_HandleTypeDef *htim)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1025 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1026 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1027 assert_param(IS_TIM_INSTANCE(htim->Instance));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1028
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1029 htim->State = HAL_TIM_STATE_BUSY;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1030
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1031 /* Disable the TIM Peripheral Clock */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1032 __HAL_TIM_DISABLE(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1033
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1034 /* DeInit the low level hardware: GPIO, CLOCK, NVIC and DMA */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1035 HAL_TIM_PWM_MspDeInit(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1036
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1037 /* Change TIM state */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1038 htim->State = HAL_TIM_STATE_RESET;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1039
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1040 /* Release Lock */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1041 __HAL_UNLOCK(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1042
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1043 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1044 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1045
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1046 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1047 * @brief Initializes the TIM PWM MSP.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1048 * @param htim : TIM handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1049 * @retval None
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1050 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1051 __weak void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef *htim)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1052 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1053 /* Prevent unused argument(s) compilation warning */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1054 UNUSED(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1055 /* NOTE : This function Should not be modified, when the callback is needed,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1056 the HAL_TIM_PWM_MspInit could be implemented in the user file
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1057 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1058 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1059
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1060 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1061 * @brief DeInitializes TIM PWM MSP.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1062 * @param htim : TIM handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1063 * @retval None
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1064 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1065 __weak void HAL_TIM_PWM_MspDeInit(TIM_HandleTypeDef *htim)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1066 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1067 /* Prevent unused argument(s) compilation warning */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1068 UNUSED(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1069 /* NOTE : This function Should not be modified, when the callback is needed,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1070 the HAL_TIM_PWM_MspDeInit could be implemented in the user file
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1071 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1072 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1073
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1074 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1075 * @brief Starts the PWM signal generation.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1076 * @param htim : TIM handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1077 * @param Channel : TIM Channels to be enabled
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1078 * This parameter can be one of the following values:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1079 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1080 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1081 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1082 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1083 * @retval HAL status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1084 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1085 HAL_StatusTypeDef HAL_TIM_PWM_Start(TIM_HandleTypeDef *htim, uint32_t Channel)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1086 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1087 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1088 assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1089
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1090 /* Enable the Capture compare channel */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1091 TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1092
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1093 if(IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1094 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1095 /* Enable the main output */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1096 __HAL_TIM_MOE_ENABLE(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1097 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1098
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1099 /* Enable the Peripheral */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1100 __HAL_TIM_ENABLE(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1101
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1102 /* Return function status */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1103 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1104 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1105
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1106 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1107 * @brief Stops the PWM signal generation.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1108 * @param htim : TIM handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1109 * @param Channel : TIM Channels to be disabled
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1110 * This parameter can be one of the following values:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1111 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1112 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1113 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1114 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1115 * @retval HAL status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1116 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1117 HAL_StatusTypeDef HAL_TIM_PWM_Stop(TIM_HandleTypeDef *htim, uint32_t Channel)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1118 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1119 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1120 assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1121
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1122 /* Disable the Capture compare channel */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1123 TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1124
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1125 if(IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1126 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1127 /* Disable the Main Ouput */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1128 __HAL_TIM_MOE_DISABLE(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1129 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1130
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1131 /* Disable the Peripheral */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1132 __HAL_TIM_DISABLE(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1133
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1134 /* Change the htim state */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1135 htim->State = HAL_TIM_STATE_READY;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1136
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1137 /* Return function status */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1138 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1139 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1140
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1141 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1142 * @brief Starts the PWM signal generation in interrupt mode.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1143 * @param htim : TIM handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1144 * @param Channel : TIM Channel to be disabled
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1145 * This parameter can be one of the following values:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1146 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1147 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1148 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1149 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1150 * @retval HAL status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1151 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1152 HAL_StatusTypeDef HAL_TIM_PWM_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1153 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1154 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1155 assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1156
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1157 switch (Channel)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1158 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1159 case TIM_CHANNEL_1:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1160 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1161 /* Enable the TIM Capture/Compare 1 interrupt */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1162 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1163 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1164 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1165
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1166 case TIM_CHANNEL_2:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1167 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1168 /* Enable the TIM Capture/Compare 2 interrupt */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1169 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1170 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1171 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1172
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1173 case TIM_CHANNEL_3:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1174 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1175 /* Enable the TIM Capture/Compare 3 interrupt */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1176 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC3);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1177 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1178 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1179
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1180 case TIM_CHANNEL_4:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1181 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1182 /* Enable the TIM Capture/Compare 4 interrupt */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1183 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC4);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1184 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1185 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1186
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1187 default:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1188 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1189 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1190
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1191 /* Enable the Capture compare channel */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1192 TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1193
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1194 if(IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1195 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1196 /* Enable the main output */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1197 __HAL_TIM_MOE_ENABLE(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1198 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1199
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1200 /* Enable the Peripheral */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1201 __HAL_TIM_ENABLE(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1202
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1203 /* Return function status */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1204 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1205 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1206
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1207 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1208 * @brief Stops the PWM signal generation in interrupt mode.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1209 * @param htim : TIM handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1210 * @param Channel : TIM Channels to be disabled
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1211 * This parameter can be one of the following values:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1212 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1213 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1214 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1215 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1216 * @retval HAL status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1217 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1218 HAL_StatusTypeDef HAL_TIM_PWM_Stop_IT (TIM_HandleTypeDef *htim, uint32_t Channel)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1219 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1220 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1221 assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1222
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1223 switch (Channel)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1224 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1225 case TIM_CHANNEL_1:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1226 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1227 /* Disable the TIM Capture/Compare 1 interrupt */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1228 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1229 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1230 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1231
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1232 case TIM_CHANNEL_2:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1233 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1234 /* Disable the TIM Capture/Compare 2 interrupt */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1235 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1236 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1237 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1238
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1239 case TIM_CHANNEL_3:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1240 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1241 /* Disable the TIM Capture/Compare 3 interrupt */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1242 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC3);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1243 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1244 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1245
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1246 case TIM_CHANNEL_4:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1247 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1248 /* Disable the TIM Capture/Compare 4 interrupt */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1249 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC4);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1250 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1251 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1252
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1253 default:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1254 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1255 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1256
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1257 /* Disable the Capture compare channel */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1258 TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1259
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1260 if(IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1261 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1262 /* Disable the Main Ouput */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1263 __HAL_TIM_MOE_DISABLE(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1264 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1265
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1266 /* Disable the Peripheral */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1267 __HAL_TIM_DISABLE(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1268
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1269 /* Return function status */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1270 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1271 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1272
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1273 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1274 * @brief Starts the TIM PWM signal generation in DMA mode.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1275 * @param htim : TIM handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1276 * @param Channel : TIM Channels to be enabled
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1277 * This parameter can be one of the following values:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1278 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1279 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1280 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1281 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1282 * @param pData : The source Buffer address.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1283 * @param Length : The length of data to be transferred from memory to TIM peripheral
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1284 * @retval HAL status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1285 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1286 HAL_StatusTypeDef HAL_TIM_PWM_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1287 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1288 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1289 assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1290
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1291 if((htim->State == HAL_TIM_STATE_BUSY))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1292 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1293 return HAL_BUSY;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1294 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1295 else if((htim->State == HAL_TIM_STATE_READY))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1296 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1297 if(((uint32_t)pData == 0 ) && (Length > 0))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1298 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1299 return HAL_ERROR;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1300 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1301 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1302 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1303 htim->State = HAL_TIM_STATE_BUSY;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1304 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1305 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1306 switch (Channel)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1307 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1308 case TIM_CHANNEL_1:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1309 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1310 /* Set the DMA Period elapsed callback */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1311 htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMADelayPulseCplt;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1312
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1313 /* Set the DMA error callback */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1314 htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1315
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1316 /* Enable the DMA channel */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1317 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)pData, (uint32_t)&htim->Instance->CCR1, Length);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1318
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1319 /* Enable the TIM Capture/Compare 1 DMA request */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1320 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1321 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1322 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1323
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1324 case TIM_CHANNEL_2:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1325 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1326 /* Set the DMA Period elapsed callback */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1327 htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMADelayPulseCplt;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1328
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1329 /* Set the DMA error callback */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1330 htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError ;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1331
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1332 /* Enable the DMA channel */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1333 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)pData, (uint32_t)&htim->Instance->CCR2, Length);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1334
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1335 /* Enable the TIM Capture/Compare 2 DMA request */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1336 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1337 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1338 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1339
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1340 case TIM_CHANNEL_3:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1341 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1342 /* Set the DMA Period elapsed callback */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1343 htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMADelayPulseCplt;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1344
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1345 /* Set the DMA error callback */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1346 htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = TIM_DMAError ;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1347
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1348 /* Enable the DMA channel */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1349 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)pData, (uint32_t)&htim->Instance->CCR3,Length);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1350
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1351 /* Enable the TIM Output Capture/Compare 3 request */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1352 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC3);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1353 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1354 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1355
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1356 case TIM_CHANNEL_4:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1357 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1358 /* Set the DMA Period elapsed callback */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1359 htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = TIM_DMADelayPulseCplt;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1360
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1361 /* Set the DMA error callback */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1362 htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = TIM_DMAError ;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1363
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1364 /* Enable the DMA channel */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1365 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)pData, (uint32_t)&htim->Instance->CCR4, Length);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1366
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1367 /* Enable the TIM Capture/Compare 4 DMA request */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1368 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC4);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1369 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1370 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1371
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1372 default:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1373 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1374 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1375
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1376 /* Enable the Capture compare channel */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1377 TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1378
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1379 if(IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1380 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1381 /* Enable the main output */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1382 __HAL_TIM_MOE_ENABLE(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1383 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1384
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1385 /* Enable the Peripheral */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1386 __HAL_TIM_ENABLE(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1387
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1388 /* Return function status */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1389 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1390 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1391
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1392 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1393 * @brief Stops the TIM PWM signal generation in DMA mode.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1394 * @param htim : TIM handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1395 * @param Channel : TIM Channels to be disabled
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1396 * This parameter can be one of the following values:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1397 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1398 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1399 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1400 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1401 * @retval HAL status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1402 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1403 HAL_StatusTypeDef HAL_TIM_PWM_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1404 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1405 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1406 assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1407
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1408 switch (Channel)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1409 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1410 case TIM_CHANNEL_1:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1411 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1412 /* Disable the TIM Capture/Compare 1 DMA request */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1413 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1414 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1415 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1416
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1417 case TIM_CHANNEL_2:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1418 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1419 /* Disable the TIM Capture/Compare 2 DMA request */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1420 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1421 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1422 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1423
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1424 case TIM_CHANNEL_3:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1425 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1426 /* Disable the TIM Capture/Compare 3 DMA request */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1427 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC3);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1428 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1429 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1430
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1431 case TIM_CHANNEL_4:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1432 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1433 /* Disable the TIM Capture/Compare 4 interrupt */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1434 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC4);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1435 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1436 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1437
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1438 default:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1439 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1440 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1441
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1442 /* Disable the Capture compare channel */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1443 TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1444
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1445 if(IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1446 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1447 /* Disable the Main Ouput */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1448 __HAL_TIM_MOE_DISABLE(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1449 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1450
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1451 /* Disable the Peripheral */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1452 __HAL_TIM_DISABLE(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1453
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1454 /* Change the htim state */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1455 htim->State = HAL_TIM_STATE_READY;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1456
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1457 /* Return function status */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1458 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1459 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1460
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1461 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1462 * @}
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1463 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1464
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1465 /** @defgroup TIM_Exported_Functions_Group4 Time Input Capture functions
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1466 * @brief Time Input Capture functions
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1467 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1468 @verbatim
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1469 ==============================================================================
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1470 ##### Time Input Capture functions #####
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1471 ==============================================================================
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1472 [..]
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1473 This section provides functions allowing to:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1474 (+) Initialize and configure the TIM Input Capture.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1475 (+) De-initialize the TIM Input Capture.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1476 (+) Start the Time Input Capture.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1477 (+) Stop the Time Input Capture.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1478 (+) Start the Time Input Capture and enable interrupt.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1479 (+) Stop the Time Input Capture and disable interrupt.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1480 (+) Start the Time Input Capture and enable DMA transfer.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1481 (+) Stop the Time Input Capture and disable DMA transfer.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1482
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1483 @endverbatim
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1484 * @{
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1485 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1486 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1487 * @brief Initializes the TIM Input Capture Time base according to the specified
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1488 * parameters in the TIM_HandleTypeDef and create the associated handle.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1489 * @param htim : TIM Input Capture handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1490 * @retval HAL status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1491 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1492 HAL_StatusTypeDef HAL_TIM_IC_Init(TIM_HandleTypeDef *htim)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1493 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1494 /* Check the TIM handle allocation */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1495 if(htim == NULL)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1496 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1497 return HAL_ERROR;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1498 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1499
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1500 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1501 assert_param(IS_TIM_INSTANCE(htim->Instance));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1502 assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1503 assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1504
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1505 if(htim->State == HAL_TIM_STATE_RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1506 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1507 /* Allocate lock resource and initialize it */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1508 htim->Lock = HAL_UNLOCKED;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1509
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1510 /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1511 HAL_TIM_IC_MspInit(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1512 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1513
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1514 /* Set the TIM state */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1515 htim->State= HAL_TIM_STATE_BUSY;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1516
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1517 /* Init the base time for the input capture */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1518 TIM_Base_SetConfig(htim->Instance, &htim->Init);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1519
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1520 /* Initialize the TIM state*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1521 htim->State= HAL_TIM_STATE_READY;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1522
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1523 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1524 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1525
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1526 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1527 * @brief DeInitializes the TIM peripheral
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1528 * @param htim : TIM Input Capture handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1529 * @retval HAL status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1530 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1531 HAL_StatusTypeDef HAL_TIM_IC_DeInit(TIM_HandleTypeDef *htim)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1532 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1533 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1534 assert_param(IS_TIM_INSTANCE(htim->Instance));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1535
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1536 htim->State = HAL_TIM_STATE_BUSY;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1537
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1538 /* Disable the TIM Peripheral Clock */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1539 __HAL_TIM_DISABLE(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1540
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1541 /* DeInit the low level hardware: GPIO, CLOCK, NVIC and DMA */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1542 HAL_TIM_IC_MspDeInit(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1543
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1544 /* Change TIM state */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1545 htim->State = HAL_TIM_STATE_RESET;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1546
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1547 /* Release Lock */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1548 __HAL_UNLOCK(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1549
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1550 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1551 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1552
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1553 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1554 * @brief Initializes the TIM Input Capture MSP.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1555 * @param htim : TIM handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1556 * @retval None
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1557 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1558 __weak void HAL_TIM_IC_MspInit(TIM_HandleTypeDef *htim)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1559 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1560 /* Prevent unused argument(s) compilation warning */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1561 UNUSED(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1562 /* NOTE : This function Should not be modified, when the callback is needed,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1563 the HAL_TIM_IC_MspInit could be implemented in the user file
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1564 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1565 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1566
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1567 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1568 * @brief DeInitializes TIM Input Capture MSP.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1569 * @param htim : TIM handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1570 * @retval None
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1571 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1572 __weak void HAL_TIM_IC_MspDeInit(TIM_HandleTypeDef *htim)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1573 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1574 /* Prevent unused argument(s) compilation warning */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1575 UNUSED(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1576 /* NOTE : This function Should not be modified, when the callback is needed,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1577 the HAL_TIM_IC_MspDeInit could be implemented in the user file
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1578 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1579 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1580
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1581 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1582 * @brief Starts the TIM Input Capture measurement.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1583 * @param htim : TIM Input Capture handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1584 * @param Channel : TIM Channels to be enabled
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1585 * This parameter can be one of the following values:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1586 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1587 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1588 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1589 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1590 * @retval HAL status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1591 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1592 HAL_StatusTypeDef HAL_TIM_IC_Start (TIM_HandleTypeDef *htim, uint32_t Channel)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1593 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1594 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1595 assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1596
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1597 /* Enable the Input Capture channel */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1598 TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1599
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1600 /* Enable the Peripheral */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1601 __HAL_TIM_ENABLE(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1602
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1603 /* Return function status */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1604 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1605 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1606
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1607 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1608 * @brief Stops the TIM Input Capture measurement.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1609 * @param htim : TIM handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1610 * @param Channel : TIM Channels to be disabled
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1611 * This parameter can be one of the following values:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1612 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1613 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1614 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1615 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1616 * @retval HAL status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1617 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1618 HAL_StatusTypeDef HAL_TIM_IC_Stop(TIM_HandleTypeDef *htim, uint32_t Channel)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1619 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1620 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1621 assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1622
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1623 /* Disable the Input Capture channel */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1624 TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1625
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1626 /* Disable the Peripheral */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1627 __HAL_TIM_DISABLE(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1628
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1629 /* Return function status */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1630 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1631 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1632
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1633 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1634 * @brief Starts the TIM Input Capture measurement in interrupt mode.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1635 * @param htim : TIM Input Capture handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1636 * @param Channel : TIM Channels to be enabled
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1637 * This parameter can be one of the following values:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1638 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1639 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1640 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1641 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1642 * @retval HAL status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1643 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1644 HAL_StatusTypeDef HAL_TIM_IC_Start_IT (TIM_HandleTypeDef *htim, uint32_t Channel)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1645 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1646 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1647 assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1648
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1649 switch (Channel)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1650 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1651 case TIM_CHANNEL_1:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1652 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1653 /* Enable the TIM Capture/Compare 1 interrupt */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1654 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1655 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1656 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1657
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1658 case TIM_CHANNEL_2:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1659 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1660 /* Enable the TIM Capture/Compare 2 interrupt */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1661 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1662 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1663 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1664
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1665 case TIM_CHANNEL_3:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1666 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1667 /* Enable the TIM Capture/Compare 3 interrupt */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1668 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC3);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1669 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1670 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1671
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1672 case TIM_CHANNEL_4:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1673 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1674 /* Enable the TIM Capture/Compare 4 interrupt */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1675 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC4);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1676 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1677 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1678
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1679 default:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1680 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1681 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1682 /* Enable the Input Capture channel */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1683 TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1684
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1685 /* Enable the Peripheral */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1686 __HAL_TIM_ENABLE(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1687
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1688 /* Return function status */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1689 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1690 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1691
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1692 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1693 * @brief Stops the TIM Input Capture measurement in interrupt mode.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1694 * @param htim : TIM handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1695 * @param Channel : TIM Channels to be disabled
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1696 * This parameter can be one of the following values:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1697 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1698 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1699 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1700 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1701 * @retval HAL status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1702 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1703 HAL_StatusTypeDef HAL_TIM_IC_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1704 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1705 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1706 assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1707
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1708 switch (Channel)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1709 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1710 case TIM_CHANNEL_1:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1711 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1712 /* Disable the TIM Capture/Compare 1 interrupt */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1713 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1714 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1715 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1716
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1717 case TIM_CHANNEL_2:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1718 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1719 /* Disable the TIM Capture/Compare 2 interrupt */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1720 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1721 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1722 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1723
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1724 case TIM_CHANNEL_3:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1725 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1726 /* Disable the TIM Capture/Compare 3 interrupt */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1727 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC3);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1728 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1729 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1730
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1731 case TIM_CHANNEL_4:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1732 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1733 /* Disable the TIM Capture/Compare 4 interrupt */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1734 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC4);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1735 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1736 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1737
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1738 default:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1739 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1740 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1741
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1742 /* Disable the Input Capture channel */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1743 TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1744
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1745 /* Disable the Peripheral */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1746 __HAL_TIM_DISABLE(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1747
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1748 /* Return function status */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1749 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1750 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1751
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1752 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1753 * @brief Starts the TIM Input Capture measurement in DMA mode.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1754 * @param htim : TIM Input Capture handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1755 * @param Channel : TIM Channels to be enabled
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1756 * This parameter can be one of the following values:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1757 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1758 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1759 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1760 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1761 * @param pData : The destination Buffer address.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1762 * @param Length : The length of data to be transferred from TIM peripheral to memory.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1763 * @retval HAL status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1764 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1765 HAL_StatusTypeDef HAL_TIM_IC_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1766 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1767 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1768 assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1769 assert_param(IS_TIM_DMA_CC_INSTANCE(htim->Instance));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1770
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1771 if((htim->State == HAL_TIM_STATE_BUSY))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1772 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1773 return HAL_BUSY;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1774 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1775 else if((htim->State == HAL_TIM_STATE_READY))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1776 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1777 if((pData == 0 ) && (Length > 0))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1778 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1779 return HAL_ERROR;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1780 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1781 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1782 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1783 htim->State = HAL_TIM_STATE_BUSY;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1784 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1785 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1786
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1787 switch (Channel)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1788 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1789 case TIM_CHANNEL_1:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1790 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1791 /* Set the DMA Period elapsed callback */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1792 htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMACaptureCplt;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1793
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1794 /* Set the DMA error callback */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1795 htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1796
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1797 /* Enable the DMA channel */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1798 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)&htim->Instance->CCR1, (uint32_t)pData, Length);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1799
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1800 /* Enable the TIM Capture/Compare 1 DMA request */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1801 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1802 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1803 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1804
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1805 case TIM_CHANNEL_2:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1806 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1807 /* Set the DMA Period elapsed callback */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1808 htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMACaptureCplt;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1809
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1810 /* Set the DMA error callback */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1811 htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError ;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1812
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1813 /* Enable the DMA channel */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1814 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)&htim->Instance->CCR2, (uint32_t)pData, Length);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1815
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1816 /* Enable the TIM Capture/Compare 2 DMA request */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1817 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1818 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1819 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1820
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1821 case TIM_CHANNEL_3:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1822 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1823 /* Set the DMA Period elapsed callback */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1824 htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMACaptureCplt;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1825
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1826 /* Set the DMA error callback */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1827 htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = TIM_DMAError ;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1828
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1829 /* Enable the DMA channel */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1830 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)&htim->Instance->CCR3, (uint32_t)pData, Length);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1831
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1832 /* Enable the TIM Capture/Compare 3 DMA request */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1833 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC3);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1834 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1835 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1836
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1837 case TIM_CHANNEL_4:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1838 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1839 /* Set the DMA Period elapsed callback */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1840 htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = TIM_DMACaptureCplt;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1841
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1842 /* Set the DMA error callback */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1843 htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = TIM_DMAError ;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1844
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1845 /* Enable the DMA channel */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1846 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)&htim->Instance->CCR4, (uint32_t)pData, Length);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1847
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1848 /* Enable the TIM Capture/Compare 4 DMA request */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1849 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC4);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1850 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1851 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1852
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1853 default:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1854 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1855 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1856
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1857 /* Enable the Input Capture channel */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1858 TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1859
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1860 /* Enable the Peripheral */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1861 __HAL_TIM_ENABLE(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1862
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1863 /* Return function status */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1864 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1865 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1866
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1867 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1868 * @brief Stops the TIM Input Capture measurement in DMA mode.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1869 * @param htim : TIM Input Capture handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1870 * @param Channel : TIM Channels to be disabled
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1871 * This parameter can be one of the following values:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1872 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1873 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1874 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1875 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1876 * @retval HAL status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1877 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1878 HAL_StatusTypeDef HAL_TIM_IC_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1879 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1880 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1881 assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1882 assert_param(IS_TIM_DMA_CC_INSTANCE(htim->Instance));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1883
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1884 switch (Channel)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1885 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1886 case TIM_CHANNEL_1:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1887 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1888 /* Disable the TIM Capture/Compare 1 DMA request */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1889 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1890 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1891 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1892
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1893 case TIM_CHANNEL_2:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1894 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1895 /* Disable the TIM Capture/Compare 2 DMA request */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1896 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1897 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1898 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1899
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1900 case TIM_CHANNEL_3:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1901 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1902 /* Disable the TIM Capture/Compare 3 DMA request */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1903 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC3);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1904 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1905 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1906
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1907 case TIM_CHANNEL_4:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1908 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1909 /* Disable the TIM Capture/Compare 4 DMA request */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1910 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC4);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1911 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1912 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1913
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1914 default:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1915 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1916 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1917
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1918 /* Disable the Input Capture channel */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1919 TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1920
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1921 /* Disable the Peripheral */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1922 __HAL_TIM_DISABLE(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1923
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1924 /* Change the htim state */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1925 htim->State = HAL_TIM_STATE_READY;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1926
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1927 /* Return function status */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1928 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1929 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1930 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1931 * @}
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1932 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1933
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1934 /** @defgroup TIM_Exported_Functions_Group5 Time One Pulse functions
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1935 * @brief Time One Pulse functions
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1936 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1937 @verbatim
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1938 ==============================================================================
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1939 ##### Time One Pulse functions #####
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1940 ==============================================================================
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1941 [..]
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1942 This section provides functions allowing to:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1943 (+) Initialize and configure the TIM One Pulse.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1944 (+) De-initialize the TIM One Pulse.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1945 (+) Start the Time One Pulse.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1946 (+) Stop the Time One Pulse.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1947 (+) Start the Time One Pulse and enable interrupt.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1948 (+) Stop the Time One Pulse and disable interrupt.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1949 (+) Start the Time One Pulse and enable DMA transfer.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1950 (+) Stop the Time One Pulse and disable DMA transfer.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1951
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1952 @endverbatim
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1953 * @{
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1954 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1955 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1956 * @brief Initializes the TIM One Pulse Time Base according to the specified
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1957 * parameters in the TIM_HandleTypeDef and create the associated handle.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1958 * @param htim : TIM OnePulse handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1959 * @param OnePulseMode : Select the One pulse mode.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1960 * This parameter can be one of the following values:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1961 * @arg TIM_OPMODE_SINGLE: Only one pulse will be generated.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1962 * @arg TIM_OPMODE_REPETITIVE: Repetitive pulses wil be generated.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1963 * @retval HAL status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1964 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1965 HAL_StatusTypeDef HAL_TIM_OnePulse_Init(TIM_HandleTypeDef *htim, uint32_t OnePulseMode)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1966 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1967 /* Check the TIM handle allocation */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1968 if(htim == NULL)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1969 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1970 return HAL_ERROR;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1971 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1972
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1973 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1974 assert_param(IS_TIM_INSTANCE(htim->Instance));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1975 assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1976 assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1977 assert_param(IS_TIM_OPM_MODE(OnePulseMode));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1978
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1979 if(htim->State == HAL_TIM_STATE_RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1980 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1981 /* Allocate lock resource and initialize it */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1982 htim->Lock = HAL_UNLOCKED;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1983
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1984 /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1985 HAL_TIM_OnePulse_MspInit(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1986 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1987
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1988 /* Set the TIM state */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1989 htim->State= HAL_TIM_STATE_BUSY;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1990
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1991 /* Configure the Time base in the One Pulse Mode */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1992 TIM_Base_SetConfig(htim->Instance, &htim->Init);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1993
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1994 /* Reset the OPM Bit */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1995 htim->Instance->CR1 &= ~TIM_CR1_OPM;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1996
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1997 /* Configure the OPM Mode */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1998 htim->Instance->CR1 |= OnePulseMode;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
1999
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2000 /* Initialize the TIM state*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2001 htim->State= HAL_TIM_STATE_READY;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2002
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2003 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2004 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2005
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2006 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2007 * @brief DeInitializes the TIM One Pulse
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2008 * @param htim : TIM One Pulse handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2009 * @retval HAL status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2010 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2011 HAL_StatusTypeDef HAL_TIM_OnePulse_DeInit(TIM_HandleTypeDef *htim)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2012 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2013 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2014 assert_param(IS_TIM_INSTANCE(htim->Instance));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2015
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2016 htim->State = HAL_TIM_STATE_BUSY;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2017
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2018 /* Disable the TIM Peripheral Clock */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2019 __HAL_TIM_DISABLE(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2020
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2021 /* DeInit the low level hardware: GPIO, CLOCK, NVIC */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2022 HAL_TIM_OnePulse_MspDeInit(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2023
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2024 /* Change TIM state */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2025 htim->State = HAL_TIM_STATE_RESET;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2026
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2027 /* Release Lock */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2028 __HAL_UNLOCK(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2029
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2030 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2031 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2032
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2033 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2034 * @brief Initializes the TIM One Pulse MSP.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2035 * @param htim : TIM handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2036 * @retval None
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2037 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2038 __weak void HAL_TIM_OnePulse_MspInit(TIM_HandleTypeDef *htim)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2039 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2040 /* Prevent unused argument(s) compilation warning */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2041 UNUSED(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2042 /* NOTE : This function Should not be modified, when the callback is needed,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2043 the HAL_TIM_OnePulse_MspInit could be implemented in the user file
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2044 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2045 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2046
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2047 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2048 * @brief DeInitializes TIM One Pulse MSP.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2049 * @param htim : TIM handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2050 * @retval None
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2051 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2052 __weak void HAL_TIM_OnePulse_MspDeInit(TIM_HandleTypeDef *htim)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2053 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2054 /* Prevent unused argument(s) compilation warning */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2055 UNUSED(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2056 /* NOTE : This function Should not be modified, when the callback is needed,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2057 the HAL_TIM_OnePulse_MspDeInit could be implemented in the user file
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2058 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2059 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2060
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2061 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2062 * @brief Starts the TIM One Pulse signal generation.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2063 * @param htim : TIM One Pulse handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2064 * @param OutputChannel : TIM Channels to be enabled
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2065 * This parameter can be one of the following values:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2066 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2067 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2068 * @retval HAL status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2069 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2070 HAL_StatusTypeDef HAL_TIM_OnePulse_Start(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2071 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2072 /* Enable the Capture compare and the Input Capture channels
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2073 (in the OPM Mode the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2074 if TIM_CHANNEL_1 is used as output, the TIM_CHANNEL_2 will be used as input and
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2075 if TIM_CHANNEL_1 is used as input, the TIM_CHANNEL_2 will be used as output
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2076 in all combinations, the TIM_CHANNEL_1 and TIM_CHANNEL_2 should be enabled together
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2077
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2078 No need to enable the counter, it's enabled automatically by hardware
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2079 (the counter starts in response to a stimulus and generate a pulse */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2080
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2081 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2082 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2083
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2084 if(IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2085 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2086 /* Enable the main output */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2087 __HAL_TIM_MOE_ENABLE(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2088 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2089
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2090 /* Return function status */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2091 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2092 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2093
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2094 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2095 * @brief Stops the TIM One Pulse signal generation.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2096 * @param htim : TIM One Pulse handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2097 * @param OutputChannel : TIM Channels to be disable
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2098 * This parameter can be one of the following values:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2099 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2100 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2101 * @retval HAL status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2102 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2103 HAL_StatusTypeDef HAL_TIM_OnePulse_Stop(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2104 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2105 /* Disable the Capture compare and the Input Capture channels
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2106 (in the OPM Mode the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2107 if TIM_CHANNEL_1 is used as output, the TIM_CHANNEL_2 will be used as input and
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2108 if TIM_CHANNEL_1 is used as input, the TIM_CHANNEL_2 will be used as output
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2109 in all combinations, the TIM_CHANNEL_1 and TIM_CHANNEL_2 should be disabled together */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2110
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2111 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2112 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2113
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2114 if(IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2115 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2116 /* Disable the Main Ouput */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2117 __HAL_TIM_MOE_DISABLE(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2118 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2119
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2120 /* Disable the Peripheral */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2121 __HAL_TIM_DISABLE(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2122
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2123 /* Return function status */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2124 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2125 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2126
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2127 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2128 * @brief Starts the TIM One Pulse signal generation in interrupt mode.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2129 * @param htim : TIM One Pulse handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2130 * @param OutputChannel : TIM Channels to be enabled
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2131 * This parameter can be one of the following values:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2132 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2133 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2134 * @retval HAL status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2135 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2136 HAL_StatusTypeDef HAL_TIM_OnePulse_Start_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2137 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2138 /* Enable the Capture compare and the Input Capture channels
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2139 (in the OPM Mode the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2140 if TIM_CHANNEL_1 is used as output, the TIM_CHANNEL_2 will be used as input and
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2141 if TIM_CHANNEL_1 is used as input, the TIM_CHANNEL_2 will be used as output
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2142 in all combinations, the TIM_CHANNEL_1 and TIM_CHANNEL_2 should be enabled together
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2143
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2144 No need to enable the counter, it's enabled automatically by hardware
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2145 (the counter starts in response to a stimulus and generate a pulse */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2146
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2147 /* Enable the TIM Capture/Compare 1 interrupt */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2148 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2149
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2150 /* Enable the TIM Capture/Compare 2 interrupt */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2151 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2152
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2153 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2154 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2155
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2156 if(IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2157 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2158 /* Enable the main output */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2159 __HAL_TIM_MOE_ENABLE(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2160 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2161
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2162 /* Return function status */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2163 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2164 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2165
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2166 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2167 * @brief Stops the TIM One Pulse signal generation in interrupt mode.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2168 * @param htim : TIM One Pulse handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2169 * @param OutputChannel : TIM Channels to be enabled
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2170 * This parameter can be one of the following values:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2171 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2172 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2173 * @retval HAL status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2174 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2175 HAL_StatusTypeDef HAL_TIM_OnePulse_Stop_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2176 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2177 /* Disable the TIM Capture/Compare 1 interrupt */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2178 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2179
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2180 /* Disable the TIM Capture/Compare 2 interrupt */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2181 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2182
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2183 /* Disable the Capture compare and the Input Capture channels
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2184 (in the OPM Mode the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2185 if TIM_CHANNEL_1 is used as output, the TIM_CHANNEL_2 will be used as input and
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2186 if TIM_CHANNEL_1 is used as input, the TIM_CHANNEL_2 will be used as output
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2187 in all combinations, the TIM_CHANNEL_1 and TIM_CHANNEL_2 should be disabled together */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2188 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2189 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2190
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2191 if(IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2192 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2193 /* Disable the Main Ouput */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2194 __HAL_TIM_MOE_DISABLE(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2195 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2196
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2197 /* Disable the Peripheral */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2198 __HAL_TIM_DISABLE(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2199
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2200 /* Return function status */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2201 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2202 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2203
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2204 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2205 * @}
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2206 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2207
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2208 /** @defgroup TIM_Exported_Functions_Group6 Time Encoder functions
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2209 * @brief Time Encoder functions
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2210 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2211 @verbatim
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2212 ==============================================================================
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2213 ##### Time Encoder functions #####
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2214 ==============================================================================
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2215 [..]
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2216 This section provides functions allowing to:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2217 (+) Initialize and configure the TIM Encoder.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2218 (+) De-initialize the TIM Encoder.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2219 (+) Start the Time Encoder.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2220 (+) Stop the Time Encoder.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2221 (+) Start the Time Encoder and enable interrupt.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2222 (+) Stop the Time Encoder and disable interrupt.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2223 (+) Start the Time Encoder and enable DMA transfer.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2224 (+) Stop the Time Encoder and disable DMA transfer.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2225
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2226 @endverbatim
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2227 * @{
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2228 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2229 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2230 * @brief Initializes the TIM Encoder Interface and create the associated handle.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2231 * @param htim : TIM Encoder Interface handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2232 * @param sConfig : TIM Encoder Interface configuration structure
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2233 * @retval HAL status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2234 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2235 HAL_StatusTypeDef HAL_TIM_Encoder_Init(TIM_HandleTypeDef *htim, TIM_Encoder_InitTypeDef* sConfig)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2236 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2237 uint32_t tmpsmcr = 0;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2238 uint32_t tmpccmr1 = 0;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2239 uint32_t tmpccer = 0;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2240
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2241 /* Check the TIM handle allocation */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2242 if(htim == NULL)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2243 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2244 return HAL_ERROR;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2245 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2246
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2247 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2248 assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2249 assert_param(IS_TIM_ENCODER_MODE(sConfig->EncoderMode));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2250 assert_param(IS_TIM_IC_SELECTION(sConfig->IC1Selection));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2251 assert_param(IS_TIM_IC_SELECTION(sConfig->IC2Selection));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2252 assert_param(IS_TIM_IC_POLARITY(sConfig->IC1Polarity));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2253 assert_param(IS_TIM_IC_POLARITY(sConfig->IC2Polarity));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2254 assert_param(IS_TIM_IC_PRESCALER(sConfig->IC1Prescaler));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2255 assert_param(IS_TIM_IC_PRESCALER(sConfig->IC2Prescaler));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2256 assert_param(IS_TIM_IC_FILTER(sConfig->IC1Filter));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2257 assert_param(IS_TIM_IC_FILTER(sConfig->IC2Filter));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2258
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2259 if(htim->State == HAL_TIM_STATE_RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2260 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2261 /* Allocate lock resource and initialize it */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2262 htim->Lock = HAL_UNLOCKED;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2263
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2264 /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2265 HAL_TIM_Encoder_MspInit(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2266 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2267
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2268 /* Set the TIM state */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2269 htim->State= HAL_TIM_STATE_BUSY;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2270
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2271 /* Reset the SMS bits */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2272 htim->Instance->SMCR &= ~TIM_SMCR_SMS;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2273
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2274 /* Configure the Time base in the Encoder Mode */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2275 TIM_Base_SetConfig(htim->Instance, &htim->Init);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2276
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2277 /* Get the TIMx SMCR register value */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2278 tmpsmcr = htim->Instance->SMCR;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2279
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2280 /* Get the TIMx CCMR1 register value */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2281 tmpccmr1 = htim->Instance->CCMR1;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2282
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2283 /* Get the TIMx CCER register value */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2284 tmpccer = htim->Instance->CCER;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2285
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2286 /* Set the encoder Mode */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2287 tmpsmcr |= sConfig->EncoderMode;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2288
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2289 /* Select the Capture Compare 1 and the Capture Compare 2 as input */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2290 tmpccmr1 &= ~(TIM_CCMR1_CC1S | TIM_CCMR1_CC2S);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2291 tmpccmr1 |= (sConfig->IC1Selection | (sConfig->IC2Selection << 8));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2292
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2293 /* Set the the Capture Compare 1 and the Capture Compare 2 prescalers and filters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2294 tmpccmr1 &= ~(TIM_CCMR1_IC1PSC | TIM_CCMR1_IC2PSC);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2295 tmpccmr1 &= ~(TIM_CCMR1_IC1F | TIM_CCMR1_IC2F);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2296 tmpccmr1 |= sConfig->IC1Prescaler | (sConfig->IC2Prescaler << 8);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2297 tmpccmr1 |= (sConfig->IC1Filter << 4) | (sConfig->IC2Filter << 12);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2298
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2299 /* Set the TI1 and the TI2 Polarities */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2300 tmpccer &= ~(TIM_CCER_CC1P | TIM_CCER_CC2P);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2301 tmpccer &= ~(TIM_CCER_CC1NP | TIM_CCER_CC2NP);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2302 tmpccer |= sConfig->IC1Polarity | (sConfig->IC2Polarity << 4);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2303
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2304 /* Write to TIMx SMCR */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2305 htim->Instance->SMCR = tmpsmcr;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2306
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2307 /* Write to TIMx CCMR1 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2308 htim->Instance->CCMR1 = tmpccmr1;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2309
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2310 /* Write to TIMx CCER */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2311 htim->Instance->CCER = tmpccer;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2312
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2313 /* Initialize the TIM state*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2314 htim->State= HAL_TIM_STATE_READY;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2315
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2316 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2317 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2318
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2319
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2320 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2321 * @brief DeInitializes the TIM Encoder interface
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2322 * @param htim : TIM Encoder handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2323 * @retval HAL status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2324 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2325 HAL_StatusTypeDef HAL_TIM_Encoder_DeInit(TIM_HandleTypeDef *htim)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2326 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2327 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2328 assert_param(IS_TIM_INSTANCE(htim->Instance));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2329
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2330 htim->State = HAL_TIM_STATE_BUSY;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2331
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2332 /* Disable the TIM Peripheral Clock */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2333 __HAL_TIM_DISABLE(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2334
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2335 /* DeInit the low level hardware: GPIO, CLOCK, NVIC */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2336 HAL_TIM_Encoder_MspDeInit(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2337
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2338 /* Change TIM state */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2339 htim->State = HAL_TIM_STATE_RESET;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2340
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2341 /* Release Lock */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2342 __HAL_UNLOCK(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2343
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2344 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2345 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2346
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2347 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2348 * @brief Initializes the TIM Encoder Interface MSP.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2349 * @param htim : TIM handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2350 * @retval None
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2351 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2352 __weak void HAL_TIM_Encoder_MspInit(TIM_HandleTypeDef *htim)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2353 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2354 /* Prevent unused argument(s) compilation warning */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2355 UNUSED(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2356 /* NOTE : This function Should not be modified, when the callback is needed,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2357 the HAL_TIM_Encoder_MspInit could be implemented in the user file
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2358 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2359 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2360
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2361 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2362 * @brief DeInitializes TIM Encoder Interface MSP.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2363 * @param htim : TIM handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2364 * @retval None
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2365 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2366 __weak void HAL_TIM_Encoder_MspDeInit(TIM_HandleTypeDef *htim)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2367 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2368 /* Prevent unused argument(s) compilation warning */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2369 UNUSED(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2370 /* NOTE : This function Should not be modified, when the callback is needed,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2371 the HAL_TIM_Encoder_MspDeInit could be implemented in the user file
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2372 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2373 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2374
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2375 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2376 * @brief Starts the TIM Encoder Interface.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2377 * @param htim : TIM Encoder Interface handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2378 * @param Channel : TIM Channels to be enabled
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2379 * This parameter can be one of the following values:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2380 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2381 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2382 * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2383 * @retval HAL status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2384 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2385 HAL_StatusTypeDef HAL_TIM_Encoder_Start(TIM_HandleTypeDef *htim, uint32_t Channel)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2386 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2387 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2388 assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2389
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2390 /* Enable the encoder interface channels */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2391 switch (Channel)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2392 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2393 case TIM_CHANNEL_1:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2394 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2395 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2396 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2397 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2398 case TIM_CHANNEL_2:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2399 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2400 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2401 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2402 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2403 default :
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2404 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2405 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2406 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2407 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2408 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2409 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2410 /* Enable the Peripheral */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2411 __HAL_TIM_ENABLE(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2412
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2413 /* Return function status */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2414 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2415 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2416
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2417 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2418 * @brief Stops the TIM Encoder Interface.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2419 * @param htim : TIM Encoder Interface handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2420 * @param Channel : TIM Channels to be disabled
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2421 * This parameter can be one of the following values:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2422 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2423 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2424 * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2425 * @retval HAL status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2426 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2427 HAL_StatusTypeDef HAL_TIM_Encoder_Stop(TIM_HandleTypeDef *htim, uint32_t Channel)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2428 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2429 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2430 assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2431
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2432 /* Disable the Input Capture channels 1 and 2
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2433 (in the EncoderInterface the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2) */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2434 switch (Channel)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2435 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2436 case TIM_CHANNEL_1:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2437 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2438 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2439 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2440 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2441 case TIM_CHANNEL_2:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2442 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2443 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2444 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2445 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2446 default :
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2447 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2448 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2449 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2450 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2451 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2452 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2453
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2454 /* Disable the Peripheral */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2455 __HAL_TIM_DISABLE(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2456
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2457 /* Return function status */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2458 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2459 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2460
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2461 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2462 * @brief Starts the TIM Encoder Interface in interrupt mode.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2463 * @param htim : TIM Encoder Interface handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2464 * @param Channel : TIM Channels to be enabled
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2465 * This parameter can be one of the following values:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2466 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2467 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2468 * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2469 * @retval HAL status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2470 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2471 HAL_StatusTypeDef HAL_TIM_Encoder_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2472 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2473 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2474 assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2475
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2476 /* Enable the encoder interface channels */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2477 /* Enable the capture compare Interrupts 1 and/or 2 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2478 switch (Channel)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2479 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2480 case TIM_CHANNEL_1:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2481 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2482 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2483 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2484 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2485 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2486 case TIM_CHANNEL_2:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2487 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2488 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2489 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2490 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2491 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2492 default :
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2493 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2494 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2495 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2496 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2497 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2498 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2499 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2500 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2501
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2502 /* Enable the Peripheral */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2503 __HAL_TIM_ENABLE(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2504
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2505 /* Return function status */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2506 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2507 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2508
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2509 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2510 * @brief Stops the TIM Encoder Interface in interrupt mode.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2511 * @param htim : TIM Encoder Interface handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2512 * @param Channel : TIM Channels to be disabled
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2513 * This parameter can be one of the following values:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2514 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2515 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2516 * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2517 * @retval HAL status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2518 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2519 HAL_StatusTypeDef HAL_TIM_Encoder_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2520 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2521 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2522 assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2523
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2524 /* Disable the Input Capture channels 1 and 2
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2525 (in the EncoderInterface the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2) */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2526 if(Channel == TIM_CHANNEL_1)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2527 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2528 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2529
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2530 /* Disable the capture compare Interrupts 1 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2531 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2532 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2533 else if(Channel == TIM_CHANNEL_2)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2534 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2535 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2536
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2537 /* Disable the capture compare Interrupts 2 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2538 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2539 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2540 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2541 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2542 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2543 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2544
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2545 /* Disable the capture compare Interrupts 1 and 2 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2546 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2547 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2548 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2549
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2550 /* Disable the Peripheral */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2551 __HAL_TIM_DISABLE(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2552
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2553 /* Change the htim state */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2554 htim->State = HAL_TIM_STATE_READY;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2555
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2556 /* Return function status */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2557 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2558 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2559
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2560 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2561 * @brief Starts the TIM Encoder Interface in DMA mode.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2562 * @param htim : TIM Encoder Interface handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2563 * @param Channel : TIM Channels to be enabled
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2564 * This parameter can be one of the following values:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2565 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2566 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2567 * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2568 * @param pData1 : The destination Buffer address for IC1.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2569 * @param pData2 : The destination Buffer address for IC2.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2570 * @param Length : The length of data to be transferred from TIM peripheral to memory.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2571 * @retval HAL status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2572 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2573 HAL_StatusTypeDef HAL_TIM_Encoder_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData1, uint32_t *pData2, uint16_t Length)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2574 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2575 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2576 assert_param(IS_TIM_DMA_CC_INSTANCE(htim->Instance));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2577
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2578 if((htim->State == HAL_TIM_STATE_BUSY))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2579 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2580 return HAL_BUSY;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2581 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2582 else if((htim->State == HAL_TIM_STATE_READY))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2583 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2584 if((((pData1 == 0) || (pData2 == 0) )) && (Length > 0))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2585 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2586 return HAL_ERROR;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2587 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2588 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2589 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2590 htim->State = HAL_TIM_STATE_BUSY;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2591 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2592 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2593
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2594 switch (Channel)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2595 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2596 case TIM_CHANNEL_1:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2597 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2598 /* Set the DMA Period elapsed callback */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2599 htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMACaptureCplt;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2600
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2601 /* Set the DMA error callback */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2602 htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2603
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2604 /* Enable the DMA channel */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2605 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)&htim->Instance->CCR1, (uint32_t )pData1, Length);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2606
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2607 /* Enable the TIM Input Capture DMA request */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2608 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2609
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2610 /* Enable the Peripheral */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2611 __HAL_TIM_ENABLE(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2612
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2613 /* Enable the Capture compare channel */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2614 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2615 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2616 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2617
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2618 case TIM_CHANNEL_2:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2619 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2620 /* Set the DMA Period elapsed callback */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2621 htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMACaptureCplt;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2622
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2623 /* Set the DMA error callback */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2624 htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2625 /* Enable the DMA channel */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2626 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)&htim->Instance->CCR2, (uint32_t)pData2, Length);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2627
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2628 /* Enable the TIM Input Capture DMA request */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2629 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2630
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2631 /* Enable the Peripheral */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2632 __HAL_TIM_ENABLE(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2633
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2634 /* Enable the Capture compare channel */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2635 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2636 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2637 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2638
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2639 case TIM_CHANNEL_ALL:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2640 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2641 /* Set the DMA Period elapsed callback */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2642 htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMACaptureCplt;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2643
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2644 /* Set the DMA error callback */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2645 htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2646
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2647 /* Enable the DMA channel */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2648 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)&htim->Instance->CCR1, (uint32_t)pData1, Length);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2649
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2650 /* Set the DMA Period elapsed callback */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2651 htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMACaptureCplt;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2652
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2653 /* Set the DMA error callback */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2654 htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError ;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2655
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2656 /* Enable the DMA channel */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2657 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)&htim->Instance->CCR2, (uint32_t)pData2, Length);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2658
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2659 /* Enable the Peripheral */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2660 __HAL_TIM_ENABLE(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2661
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2662 /* Enable the Capture compare channel */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2663 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2664 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2665
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2666 /* Enable the TIM Input Capture DMA request */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2667 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2668 /* Enable the TIM Input Capture DMA request */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2669 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2670 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2671 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2672
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2673 default:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2674 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2675 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2676 /* Return function status */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2677 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2678 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2679
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2680 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2681 * @brief Stops the TIM Encoder Interface in DMA mode.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2682 * @param htim : TIM Encoder Interface handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2683 * @param Channel : TIM Channels to be enabled
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2684 * This parameter can be one of the following values:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2685 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2686 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2687 * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2688 * @retval HAL status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2689 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2690 HAL_StatusTypeDef HAL_TIM_Encoder_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2691 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2692 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2693 assert_param(IS_TIM_DMA_CC_INSTANCE(htim->Instance));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2694
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2695 /* Disable the Input Capture channels 1 and 2
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2696 (in the EncoderInterface the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2) */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2697 if(Channel == TIM_CHANNEL_1)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2698 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2699 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2700
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2701 /* Disable the capture compare DMA Request 1 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2702 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2703 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2704 else if(Channel == TIM_CHANNEL_2)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2705 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2706 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2707
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2708 /* Disable the capture compare DMA Request 2 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2709 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2710 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2711 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2712 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2713 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2714 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2715
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2716 /* Disable the capture compare DMA Request 1 and 2 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2717 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2718 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2719 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2720
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2721 /* Disable the Peripheral */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2722 __HAL_TIM_DISABLE(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2723
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2724 /* Change the htim state */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2725 htim->State = HAL_TIM_STATE_READY;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2726
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2727 /* Return function status */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2728 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2729 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2730
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2731 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2732 * @}
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2733 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2734 /** @defgroup TIM_Exported_Functions_Group7 TIM IRQ handler management
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2735 * @brief IRQ handler management
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2736 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2737 @verbatim
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2738 ==============================================================================
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2739 ##### IRQ handler management #####
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2740 ==============================================================================
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2741 [..]
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2742 This section provides Timer IRQ handler function.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2743
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2744 @endverbatim
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2745 * @{
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2746 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2747 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2748 * @brief This function handles TIM interrupts requests.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2749 * @param htim : TIM handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2750 * @retval None
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2751 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2752 void HAL_TIM_IRQHandler(TIM_HandleTypeDef *htim)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2753 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2754 /* Capture compare 1 event */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2755 if(__HAL_TIM_GET_FLAG(htim, TIM_FLAG_CC1) != RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2756 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2757 if(__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_CC1) !=RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2758 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2759 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2760 __HAL_TIM_CLEAR_IT(htim, TIM_IT_CC1);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2761 htim->Channel = HAL_TIM_ACTIVE_CHANNEL_1;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2762
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2763 /* Input capture event */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2764 if((htim->Instance->CCMR1 & TIM_CCMR1_CC1S) != 0x00)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2765 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2766 HAL_TIM_IC_CaptureCallback(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2767 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2768 /* Output compare event */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2769 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2770 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2771 HAL_TIM_OC_DelayElapsedCallback(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2772 HAL_TIM_PWM_PulseFinishedCallback(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2773 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2774 htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2775 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2776 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2777 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2778 /* Capture compare 2 event */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2779 if(__HAL_TIM_GET_FLAG(htim, TIM_FLAG_CC2) != RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2780 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2781 if(__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_CC2) !=RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2782 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2783 __HAL_TIM_CLEAR_IT(htim, TIM_IT_CC2);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2784 htim->Channel = HAL_TIM_ACTIVE_CHANNEL_2;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2785 /* Input capture event */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2786 if((htim->Instance->CCMR1 & TIM_CCMR1_CC2S) != 0x00)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2787 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2788 HAL_TIM_IC_CaptureCallback(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2789 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2790 /* Output compare event */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2791 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2792 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2793 HAL_TIM_OC_DelayElapsedCallback(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2794 HAL_TIM_PWM_PulseFinishedCallback(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2795 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2796 htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2797 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2798 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2799 /* Capture compare 3 event */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2800 if(__HAL_TIM_GET_FLAG(htim, TIM_FLAG_CC3) != RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2801 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2802 if(__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_CC3) !=RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2803 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2804 __HAL_TIM_CLEAR_IT(htim, TIM_IT_CC3);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2805 htim->Channel = HAL_TIM_ACTIVE_CHANNEL_3;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2806 /* Input capture event */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2807 if((htim->Instance->CCMR2 & TIM_CCMR2_CC3S) != 0x00)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2808 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2809 HAL_TIM_IC_CaptureCallback(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2810 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2811 /* Output compare event */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2812 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2813 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2814 HAL_TIM_OC_DelayElapsedCallback(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2815 HAL_TIM_PWM_PulseFinishedCallback(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2816 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2817 htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2818 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2819 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2820 /* Capture compare 4 event */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2821 if(__HAL_TIM_GET_FLAG(htim, TIM_FLAG_CC4) != RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2822 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2823 if(__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_CC4) !=RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2824 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2825 __HAL_TIM_CLEAR_IT(htim, TIM_IT_CC4);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2826 htim->Channel = HAL_TIM_ACTIVE_CHANNEL_4;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2827 /* Input capture event */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2828 if((htim->Instance->CCMR2 & TIM_CCMR2_CC4S) != 0x00)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2829 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2830 HAL_TIM_IC_CaptureCallback(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2831 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2832 /* Output compare event */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2833 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2834 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2835 HAL_TIM_OC_DelayElapsedCallback(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2836 HAL_TIM_PWM_PulseFinishedCallback(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2837 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2838 htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2839 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2840 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2841 /* TIM Update event */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2842 if(__HAL_TIM_GET_FLAG(htim, TIM_FLAG_UPDATE) != RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2843 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2844 if(__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_UPDATE) !=RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2845 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2846 __HAL_TIM_CLEAR_IT(htim, TIM_IT_UPDATE);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2847 HAL_TIM_PeriodElapsedCallback(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2848 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2849 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2850 /* TIM Break input event */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2851 if(__HAL_TIM_GET_FLAG(htim, TIM_FLAG_BREAK) != RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2852 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2853 if(__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_BREAK) !=RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2854 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2855 __HAL_TIM_CLEAR_IT(htim, TIM_IT_BREAK);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2856 HAL_TIMEx_BreakCallback(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2857 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2858 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2859 /* TIM Trigger detection event */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2860 if(__HAL_TIM_GET_FLAG(htim, TIM_FLAG_TRIGGER) != RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2861 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2862 if(__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_TRIGGER) !=RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2863 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2864 __HAL_TIM_CLEAR_IT(htim, TIM_IT_TRIGGER);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2865 HAL_TIM_TriggerCallback(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2866 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2867 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2868 /* TIM commutation event */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2869 if(__HAL_TIM_GET_FLAG(htim, TIM_FLAG_COM) != RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2870 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2871 if(__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_COM) !=RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2872 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2873 __HAL_TIM_CLEAR_IT(htim, TIM_FLAG_COM);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2874 HAL_TIMEx_CommutationCallback(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2875 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2876 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2877 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2878
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2879 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2880 * @}
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2881 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2882
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2883 /** @defgroup TIM_Exported_Functions_Group8 Peripheral Control functions
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2884 * @brief Peripheral Control functions
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2885 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2886 @verbatim
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2887 ==============================================================================
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2888 ##### Peripheral Control functions #####
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2889 ==============================================================================
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2890 [..]
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2891 This section provides functions allowing to:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2892 (+) Configure The Input Output channels for OC, PWM, IC or One Pulse mode.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2893 (+) Configure External Clock source.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2894 (+) Configure Complementary channels, break features and dead time.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2895 (+) Configure Master and the Slave synchronization.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2896 (+) Configure the DMA Burst Mode.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2897
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2898 @endverbatim
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2899 * @{
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2900 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2901
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2902 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2903 * @brief Initializes the TIM Output Compare Channels according to the specified
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2904 * parameters in the TIM_OC_InitTypeDef.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2905 * @param htim : TIM Output Compare handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2906 * @param sConfig : TIM Output Compare configuration structure
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2907 * @param Channel : TIM Channels to be enabled
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2908 * This parameter can be one of the following values:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2909 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2910 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2911 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2912 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2913 * @retval HAL status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2914 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2915 HAL_StatusTypeDef HAL_TIM_OC_ConfigChannel(TIM_HandleTypeDef *htim, TIM_OC_InitTypeDef* sConfig, uint32_t Channel)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2916 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2917 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2918 assert_param(IS_TIM_CHANNELS(Channel));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2919 assert_param(IS_TIM_OC_MODE(sConfig->OCMode));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2920 assert_param(IS_TIM_OC_POLARITY(sConfig->OCPolarity));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2921
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2922 /* Check input state */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2923 __HAL_LOCK(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2924
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2925 htim->State = HAL_TIM_STATE_BUSY;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2926
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2927 switch (Channel)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2928 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2929 case TIM_CHANNEL_1:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2930 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2931 assert_param(IS_TIM_CC1_INSTANCE(htim->Instance));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2932 /* Configure the TIM Channel 1 in Output Compare */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2933 TIM_OC1_SetConfig(htim->Instance, sConfig);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2934 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2935 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2936
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2937 case TIM_CHANNEL_2:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2938 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2939 assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2940 /* Configure the TIM Channel 2 in Output Compare */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2941 TIM_OC2_SetConfig(htim->Instance, sConfig);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2942 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2943 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2944
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2945 case TIM_CHANNEL_3:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2946 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2947 assert_param(IS_TIM_CC3_INSTANCE(htim->Instance));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2948 /* Configure the TIM Channel 3 in Output Compare */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2949 TIM_OC3_SetConfig(htim->Instance, sConfig);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2950 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2951 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2952
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2953 case TIM_CHANNEL_4:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2954 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2955 assert_param(IS_TIM_CC4_INSTANCE(htim->Instance));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2956 /* Configure the TIM Channel 4 in Output Compare */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2957 TIM_OC4_SetConfig(htim->Instance, sConfig);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2958 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2959 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2960
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2961 default:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2962 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2963 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2964 htim->State = HAL_TIM_STATE_READY;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2965
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2966 __HAL_UNLOCK(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2967
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2968 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2969 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2970
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2971 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2972 * @brief Initializes the TIM Input Capture Channels according to the specified
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2973 * parameters in the TIM_IC_InitTypeDef.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2974 * @param htim : TIM IC handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2975 * @param sConfig : TIM Input Capture configuration structure
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2976 * @param Channel : TIM Channels to be enabled
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2977 * This parameter can be one of the following values:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2978 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2979 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2980 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2981 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2982 * @retval HAL status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2983 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2984 HAL_StatusTypeDef HAL_TIM_IC_ConfigChannel(TIM_HandleTypeDef *htim, TIM_IC_InitTypeDef* sConfig, uint32_t Channel)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2985 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2986 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2987 assert_param(IS_TIM_CC1_INSTANCE(htim->Instance));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2988 assert_param(IS_TIM_IC_POLARITY(sConfig->ICPolarity));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2989 assert_param(IS_TIM_IC_SELECTION(sConfig->ICSelection));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2990 assert_param(IS_TIM_IC_PRESCALER(sConfig->ICPrescaler));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2991 assert_param(IS_TIM_IC_FILTER(sConfig->ICFilter));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2992
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2993 __HAL_LOCK(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2994
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2995 htim->State = HAL_TIM_STATE_BUSY;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2996
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2997 if (Channel == TIM_CHANNEL_1)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2998 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
2999 /* TI1 Configuration */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3000 TIM_TI1_SetConfig(htim->Instance,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3001 sConfig->ICPolarity,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3002 sConfig->ICSelection,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3003 sConfig->ICFilter);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3004
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3005 /* Reset the IC1PSC Bits */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3006 htim->Instance->CCMR1 &= ~TIM_CCMR1_IC1PSC;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3007
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3008 /* Set the IC1PSC value */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3009 htim->Instance->CCMR1 |= sConfig->ICPrescaler;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3010 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3011 else if (Channel == TIM_CHANNEL_2)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3012 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3013 /* TI2 Configuration */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3014 assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3015
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3016 TIM_TI2_SetConfig(htim->Instance,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3017 sConfig->ICPolarity,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3018 sConfig->ICSelection,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3019 sConfig->ICFilter);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3020
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3021 /* Reset the IC2PSC Bits */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3022 htim->Instance->CCMR1 &= ~TIM_CCMR1_IC2PSC;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3023
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3024 /* Set the IC2PSC value */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3025 htim->Instance->CCMR1 |= (sConfig->ICPrescaler << 8);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3026 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3027 else if (Channel == TIM_CHANNEL_3)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3028 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3029 /* TI3 Configuration */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3030 assert_param(IS_TIM_CC3_INSTANCE(htim->Instance));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3031
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3032 TIM_TI3_SetConfig(htim->Instance,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3033 sConfig->ICPolarity,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3034 sConfig->ICSelection,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3035 sConfig->ICFilter);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3036
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3037 /* Reset the IC3PSC Bits */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3038 htim->Instance->CCMR2 &= ~TIM_CCMR2_IC3PSC;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3039
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3040 /* Set the IC3PSC value */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3041 htim->Instance->CCMR2 |= sConfig->ICPrescaler;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3042 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3043 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3044 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3045 /* TI4 Configuration */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3046 assert_param(IS_TIM_CC4_INSTANCE(htim->Instance));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3047
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3048 TIM_TI4_SetConfig(htim->Instance,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3049 sConfig->ICPolarity,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3050 sConfig->ICSelection,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3051 sConfig->ICFilter);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3052
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3053 /* Reset the IC4PSC Bits */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3054 htim->Instance->CCMR2 &= ~TIM_CCMR2_IC4PSC;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3055
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3056 /* Set the IC4PSC value */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3057 htim->Instance->CCMR2 |= (sConfig->ICPrescaler << 8);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3058 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3059
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3060 htim->State = HAL_TIM_STATE_READY;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3061
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3062 __HAL_UNLOCK(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3063
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3064 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3065 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3066
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3067 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3068 * @brief Initializes the TIM PWM channels according to the specified
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3069 * parameters in the TIM_OC_InitTypeDef.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3070 * @param htim : TIM handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3071 * @param sConfig : TIM PWM configuration structure
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3072 * @param Channel : TIM Channels to be enabled
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3073 * This parameter can be one of the following values:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3074 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3075 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3076 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3077 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3078 * @retval HAL status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3079 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3080 HAL_StatusTypeDef HAL_TIM_PWM_ConfigChannel(TIM_HandleTypeDef *htim, TIM_OC_InitTypeDef* sConfig, uint32_t Channel)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3081 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3082 __HAL_LOCK(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3083
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3084 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3085 assert_param(IS_TIM_CHANNELS(Channel));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3086 assert_param(IS_TIM_PWM_MODE(sConfig->OCMode));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3087 assert_param(IS_TIM_OC_POLARITY(sConfig->OCPolarity));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3088 assert_param(IS_TIM_FAST_STATE(sConfig->OCFastMode));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3089
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3090 htim->State = HAL_TIM_STATE_BUSY;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3091
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3092 switch (Channel)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3093 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3094 case TIM_CHANNEL_1:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3095 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3096 assert_param(IS_TIM_CC1_INSTANCE(htim->Instance));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3097 /* Configure the Channel 1 in PWM mode */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3098 TIM_OC1_SetConfig(htim->Instance, sConfig);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3099
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3100 /* Set the Preload enable bit for channel1 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3101 htim->Instance->CCMR1 |= TIM_CCMR1_OC1PE;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3102
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3103 /* Configure the Output Fast mode */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3104 htim->Instance->CCMR1 &= ~TIM_CCMR1_OC1FE;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3105 htim->Instance->CCMR1 |= sConfig->OCFastMode;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3106 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3107 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3108
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3109 case TIM_CHANNEL_2:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3110 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3111 assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3112 /* Configure the Channel 2 in PWM mode */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3113 TIM_OC2_SetConfig(htim->Instance, sConfig);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3114
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3115 /* Set the Preload enable bit for channel2 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3116 htim->Instance->CCMR1 |= TIM_CCMR1_OC2PE;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3117
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3118 /* Configure the Output Fast mode */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3119 htim->Instance->CCMR1 &= ~TIM_CCMR1_OC2FE;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3120 htim->Instance->CCMR1 |= sConfig->OCFastMode << 8;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3121 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3122 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3123
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3124 case TIM_CHANNEL_3:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3125 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3126 assert_param(IS_TIM_CC3_INSTANCE(htim->Instance));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3127 /* Configure the Channel 3 in PWM mode */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3128 TIM_OC3_SetConfig(htim->Instance, sConfig);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3129
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3130 /* Set the Preload enable bit for channel3 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3131 htim->Instance->CCMR2 |= TIM_CCMR2_OC3PE;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3132
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3133 /* Configure the Output Fast mode */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3134 htim->Instance->CCMR2 &= ~TIM_CCMR2_OC3FE;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3135 htim->Instance->CCMR2 |= sConfig->OCFastMode;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3136 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3137 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3138
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3139 case TIM_CHANNEL_4:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3140 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3141 assert_param(IS_TIM_CC4_INSTANCE(htim->Instance));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3142 /* Configure the Channel 4 in PWM mode */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3143 TIM_OC4_SetConfig(htim->Instance, sConfig);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3144
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3145 /* Set the Preload enable bit for channel4 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3146 htim->Instance->CCMR2 |= TIM_CCMR2_OC4PE;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3147
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3148 /* Configure the Output Fast mode */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3149 htim->Instance->CCMR2 &= ~TIM_CCMR2_OC4FE;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3150 htim->Instance->CCMR2 |= sConfig->OCFastMode << 8;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3151 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3152 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3153
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3154 default:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3155 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3156 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3157
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3158 htim->State = HAL_TIM_STATE_READY;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3159
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3160 __HAL_UNLOCK(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3161
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3162 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3163 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3164
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3165 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3166 * @brief Initializes the TIM One Pulse Channels according to the specified
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3167 * parameters in the TIM_OnePulse_InitTypeDef.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3168 * @param htim : TIM One Pulse handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3169 * @param sConfig : TIM One Pulse configuration structure
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3170 * @param OutputChannel : TIM Channels to be enabled
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3171 * This parameter can be one of the following values:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3172 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3173 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3174 * @param InputChannel : TIM Channels to be enabled
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3175 * This parameter can be one of the following values:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3176 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3177 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3178 * @retval HAL status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3179 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3180 HAL_StatusTypeDef HAL_TIM_OnePulse_ConfigChannel(TIM_HandleTypeDef *htim, TIM_OnePulse_InitTypeDef* sConfig, uint32_t OutputChannel, uint32_t InputChannel)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3181 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3182 TIM_OC_InitTypeDef temp1;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3183
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3184 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3185 assert_param(IS_TIM_OPM_CHANNELS(OutputChannel));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3186 assert_param(IS_TIM_OPM_CHANNELS(InputChannel));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3187
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3188 if(OutputChannel != InputChannel)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3189 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3190 __HAL_LOCK(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3191
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3192 htim->State = HAL_TIM_STATE_BUSY;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3193
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3194 /* Extract the Ouput compare configuration from sConfig structure */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3195 temp1.OCMode = sConfig->OCMode;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3196 temp1.Pulse = sConfig->Pulse;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3197 temp1.OCPolarity = sConfig->OCPolarity;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3198 temp1.OCNPolarity = sConfig->OCNPolarity;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3199 temp1.OCIdleState = sConfig->OCIdleState;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3200 temp1.OCNIdleState = sConfig->OCNIdleState;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3201
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3202 switch (OutputChannel)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3203 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3204 case TIM_CHANNEL_1:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3205 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3206 assert_param(IS_TIM_CC1_INSTANCE(htim->Instance));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3207
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3208 TIM_OC1_SetConfig(htim->Instance, &temp1);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3209 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3210 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3211 case TIM_CHANNEL_2:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3212 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3213 assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3214
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3215 TIM_OC2_SetConfig(htim->Instance, &temp1);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3216 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3217 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3218 default:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3219 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3220 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3221 switch (InputChannel)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3222 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3223 case TIM_CHANNEL_1:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3224 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3225 assert_param(IS_TIM_CC1_INSTANCE(htim->Instance));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3226
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3227 TIM_TI1_SetConfig(htim->Instance, sConfig->ICPolarity,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3228 sConfig->ICSelection, sConfig->ICFilter);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3229
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3230 /* Reset the IC1PSC Bits */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3231 htim->Instance->CCMR1 &= ~TIM_CCMR1_IC1PSC;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3232
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3233 /* Select the Trigger source */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3234 htim->Instance->SMCR &= ~TIM_SMCR_TS;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3235 htim->Instance->SMCR |= TIM_TS_TI1FP1;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3236
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3237 /* Select the Slave Mode */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3238 htim->Instance->SMCR &= ~TIM_SMCR_SMS;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3239 htim->Instance->SMCR |= TIM_SLAVEMODE_TRIGGER;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3240 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3241 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3242 case TIM_CHANNEL_2:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3243 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3244 assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3245
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3246 TIM_TI2_SetConfig(htim->Instance, sConfig->ICPolarity,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3247 sConfig->ICSelection, sConfig->ICFilter);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3248
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3249 /* Reset the IC2PSC Bits */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3250 htim->Instance->CCMR1 &= ~TIM_CCMR1_IC2PSC;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3251
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3252 /* Select the Trigger source */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3253 htim->Instance->SMCR &= ~TIM_SMCR_TS;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3254 htim->Instance->SMCR |= TIM_TS_TI2FP2;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3255
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3256 /* Select the Slave Mode */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3257 htim->Instance->SMCR &= ~TIM_SMCR_SMS;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3258 htim->Instance->SMCR |= TIM_SLAVEMODE_TRIGGER;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3259 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3260 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3261
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3262 default:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3263 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3264 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3265
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3266 htim->State = HAL_TIM_STATE_READY;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3267
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3268 __HAL_UNLOCK(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3269
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3270 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3271 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3272 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3273 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3274 return HAL_ERROR;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3275 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3276 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3277
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3278 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3279 * @brief Configure the DMA Burst to transfer Data from the memory to the TIM peripheral
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3280 * @param htim : TIM handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3281 * @param BurstBaseAddress : TIM Base address from where the DMA will start the Data write
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3282 * This parameter can be one of the following values:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3283 * @arg TIM_DMABASE_CR1
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3284 * @arg TIM_DMABASE_CR2
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3285 * @arg TIM_DMABASE_SMCR
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3286 * @arg TIM_DMABASE_DIER
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3287 * @arg TIM_DMABASE_SR
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3288 * @arg TIM_DMABASE_EGR
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3289 * @arg TIM_DMABASE_CCMR1
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3290 * @arg TIM_DMABASE_CCMR2
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3291 * @arg TIM_DMABASE_CCER
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3292 * @arg TIM_DMABASE_CNT
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3293 * @arg TIM_DMABASE_PSC
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3294 * @arg TIM_DMABASE_ARR
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3295 * @arg TIM_DMABASE_RCR
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3296 * @arg TIM_DMABASE_CCR1
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3297 * @arg TIM_DMABASE_CCR2
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3298 * @arg TIM_DMABASE_CCR3
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3299 * @arg TIM_DMABASE_CCR4
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3300 * @arg TIM_DMABASE_BDTR
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3301 * @arg TIM_DMABASE_DCR
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3302 * @param BurstRequestSrc : TIM DMA Request sources
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3303 * This parameter can be one of the following values:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3304 * @arg TIM_DMA_UPDATE: TIM update Interrupt source
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3305 * @arg TIM_DMA_CC1: TIM Capture Compare 1 DMA source
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3306 * @arg TIM_DMA_CC2: TIM Capture Compare 2 DMA source
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3307 * @arg TIM_DMA_CC3: TIM Capture Compare 3 DMA source
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3308 * @arg TIM_DMA_CC4: TIM Capture Compare 4 DMA source
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3309 * @arg TIM_DMA_COM: TIM Commutation DMA source
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3310 * @arg TIM_DMA_TRIGGER: TIM Trigger DMA source
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3311 * @param BurstBuffer : The Buffer address.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3312 * @param BurstLength : DMA Burst length. This parameter can be one value
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3313 * between: TIM_DMABURSTLENGTH_1TRANSFER and TIM_DMABURSTLENGTH_18TRANSFERS.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3314 * @retval HAL status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3315 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3316 HAL_StatusTypeDef HAL_TIM_DMABurst_WriteStart(TIM_HandleTypeDef *htim, uint32_t BurstBaseAddress, uint32_t BurstRequestSrc,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3317 uint32_t* BurstBuffer, uint32_t BurstLength)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3318 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3319 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3320 assert_param(IS_TIM_DMABURST_INSTANCE(htim->Instance));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3321 assert_param(IS_TIM_DMA_BASE(BurstBaseAddress));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3322 assert_param(IS_TIM_DMA_SOURCE(BurstRequestSrc));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3323 assert_param(IS_TIM_DMA_LENGTH(BurstLength));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3324
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3325 if((htim->State == HAL_TIM_STATE_BUSY))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3326 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3327 return HAL_BUSY;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3328 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3329 else if((htim->State == HAL_TIM_STATE_READY))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3330 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3331 if((BurstBuffer == 0 ) && (BurstLength > 0))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3332 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3333 return HAL_ERROR;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3334 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3335 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3336 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3337 htim->State = HAL_TIM_STATE_BUSY;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3338 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3339 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3340 switch(BurstRequestSrc)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3341 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3342 case TIM_DMA_UPDATE:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3343 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3344 /* Set the DMA Period elapsed callback */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3345 htim->hdma[TIM_DMA_ID_UPDATE]->XferCpltCallback = TIM_DMAPeriodElapsedCplt;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3346
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3347 /* Set the DMA error callback */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3348 htim->hdma[TIM_DMA_ID_UPDATE]->XferErrorCallback = TIM_DMAError ;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3349
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3350 /* Enable the DMA channel */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3351 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_UPDATE], (uint32_t)BurstBuffer, (uint32_t)&htim->Instance->DMAR, ((BurstLength) >> 8) + 1);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3352 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3353 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3354 case TIM_DMA_CC1:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3355 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3356 /* Set the DMA Period elapsed callback */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3357 htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMADelayPulseCplt;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3358
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3359 /* Set the DMA error callback */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3360 htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3361
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3362 /* Enable the DMA channel */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3363 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)BurstBuffer, (uint32_t)&htim->Instance->DMAR, ((BurstLength) >> 8) + 1);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3364 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3365 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3366 case TIM_DMA_CC2:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3367 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3368 /* Set the DMA Period elapsed callback */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3369 htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMADelayPulseCplt;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3370
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3371 /* Set the DMA error callback */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3372 htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError ;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3373
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3374 /* Enable the DMA channel */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3375 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)BurstBuffer, (uint32_t)&htim->Instance->DMAR, ((BurstLength) >> 8) + 1);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3376 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3377 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3378 case TIM_DMA_CC3:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3379 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3380 /* Set the DMA Period elapsed callback */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3381 htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMADelayPulseCplt;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3382
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3383 /* Set the DMA error callback */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3384 htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = TIM_DMAError ;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3385
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3386 /* Enable the DMA channel */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3387 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)BurstBuffer, (uint32_t)&htim->Instance->DMAR, ((BurstLength) >> 8) + 1);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3388 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3389 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3390 case TIM_DMA_CC4:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3391 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3392 /* Set the DMA Period elapsed callback */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3393 htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = TIM_DMADelayPulseCplt;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3394
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3395 /* Set the DMA error callback */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3396 htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = TIM_DMAError ;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3397
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3398 /* Enable the DMA channel */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3399 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)BurstBuffer, (uint32_t)&htim->Instance->DMAR, ((BurstLength) >> 8) + 1);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3400 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3401 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3402 case TIM_DMA_COM:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3403 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3404 /* Set the DMA Period elapsed callback */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3405 htim->hdma[TIM_DMA_ID_COMMUTATION]->XferCpltCallback = TIMEx_DMACommutationCplt;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3406
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3407 /* Set the DMA error callback */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3408 htim->hdma[TIM_DMA_ID_COMMUTATION]->XferErrorCallback = TIM_DMAError ;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3409
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3410 /* Enable the DMA channel */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3411 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_COMMUTATION], (uint32_t)BurstBuffer, (uint32_t)&htim->Instance->DMAR, ((BurstLength) >> 8) + 1);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3412 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3413 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3414 case TIM_DMA_TRIGGER:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3415 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3416 /* Set the DMA Period elapsed callback */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3417 htim->hdma[TIM_DMA_ID_TRIGGER]->XferCpltCallback = TIM_DMATriggerCplt;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3418
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3419 /* Set the DMA error callback */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3420 htim->hdma[TIM_DMA_ID_TRIGGER]->XferErrorCallback = TIM_DMAError ;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3421
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3422 /* Enable the DMA channel */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3423 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_TRIGGER], (uint32_t)BurstBuffer, (uint32_t)&htim->Instance->DMAR, ((BurstLength) >> 8) + 1);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3424 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3425 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3426 default:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3427 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3428 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3429 /* configure the DMA Burst Mode */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3430 htim->Instance->DCR = BurstBaseAddress | BurstLength;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3431
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3432 /* Enable the TIM DMA Request */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3433 __HAL_TIM_ENABLE_DMA(htim, BurstRequestSrc);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3434
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3435 htim->State = HAL_TIM_STATE_READY;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3436
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3437 /* Return function status */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3438 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3439 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3440
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3441 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3442 * @brief Stops the TIM DMA Burst mode
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3443 * @param htim : TIM handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3444 * @param BurstRequestSrc : TIM DMA Request sources to disable
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3445 * @retval HAL status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3446 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3447 HAL_StatusTypeDef HAL_TIM_DMABurst_WriteStop(TIM_HandleTypeDef *htim, uint32_t BurstRequestSrc)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3448 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3449 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3450 assert_param(IS_TIM_DMA_SOURCE(BurstRequestSrc));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3451
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3452 /* Abort the DMA transfer (at least disable the DMA channel) */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3453 switch(BurstRequestSrc)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3454 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3455 case TIM_DMA_UPDATE:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3456 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3457 HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_UPDATE]);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3458 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3459 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3460 case TIM_DMA_CC1:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3461 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3462 HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_CC1]);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3463 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3464 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3465 case TIM_DMA_CC2:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3466 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3467 HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_CC2]);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3468 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3469 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3470 case TIM_DMA_CC3:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3471 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3472 HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_CC3]);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3473 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3474 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3475 case TIM_DMA_CC4:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3476 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3477 HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_CC4]);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3478 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3479 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3480 case TIM_DMA_COM:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3481 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3482 HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_COMMUTATION]);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3483 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3484 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3485 case TIM_DMA_TRIGGER:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3486 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3487 HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_TRIGGER]);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3488 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3489 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3490 default:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3491 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3492 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3493
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3494 /* Disable the TIM Update DMA request */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3495 __HAL_TIM_DISABLE_DMA(htim, BurstRequestSrc);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3496
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3497 /* Return function status */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3498 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3499 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3500
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3501 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3502 * @brief Configure the DMA Burst to transfer Data from the TIM peripheral to the memory
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3503 * @param htim : TIM handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3504 * @param BurstBaseAddress : TIM Base address from where the DMA will starts the Data read
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3505 * This parameter can be one of the following values:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3506 * @arg TIM_DMABASE_CR1
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3507 * @arg TIM_DMABASE_CR2
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3508 * @arg TIM_DMABASE_SMCR
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3509 * @arg TIM_DMABASE_DIER
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3510 * @arg TIM_DMABASE_SR
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3511 * @arg TIM_DMABASE_EGR
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3512 * @arg TIM_DMABASE_CCMR1
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3513 * @arg TIM_DMABASE_CCMR2
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3514 * @arg TIM_DMABASE_CCER
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3515 * @arg TIM_DMABASE_CNT
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3516 * @arg TIM_DMABASE_PSC
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3517 * @arg TIM_DMABASE_ARR
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3518 * @arg TIM_DMABASE_RCR
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3519 * @arg TIM_DMABASE_CCR1
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3520 * @arg TIM_DMABASE_CCR2
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3521 * @arg TIM_DMABASE_CCR3
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3522 * @arg TIM_DMABASE_CCR4
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3523 * @arg TIM_DMABASE_BDTR
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3524 * @arg TIM_DMABASE_DCR
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3525 * @param BurstRequestSrc : TIM DMA Request sources
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3526 * This parameter can be one of the following values:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3527 * @arg TIM_DMA_UPDATE: TIM update Interrupt source
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3528 * @arg TIM_DMA_CC1: TIM Capture Compare 1 DMA source
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3529 * @arg TIM_DMA_CC2: TIM Capture Compare 2 DMA source
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3530 * @arg TIM_DMA_CC3: TIM Capture Compare 3 DMA source
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3531 * @arg TIM_DMA_CC4: TIM Capture Compare 4 DMA source
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3532 * @arg TIM_DMA_COM: TIM Commutation DMA source
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3533 * @arg TIM_DMA_TRIGGER: TIM Trigger DMA source
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3534 * @param BurstBuffer : The Buffer address.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3535 * @param BurstLength : DMA Burst length. This parameter can be one value
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3536 * between: TIM_DMABURSTLENGTH_1TRANSFER and TIM_DMABURSTLENGTH_18TRANSFERS.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3537 * @retval HAL status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3538 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3539 HAL_StatusTypeDef HAL_TIM_DMABurst_ReadStart(TIM_HandleTypeDef *htim, uint32_t BurstBaseAddress, uint32_t BurstRequestSrc,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3540 uint32_t *BurstBuffer, uint32_t BurstLength)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3541 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3542 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3543 assert_param(IS_TIM_DMABURST_INSTANCE(htim->Instance));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3544 assert_param(IS_TIM_DMA_BASE(BurstBaseAddress));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3545 assert_param(IS_TIM_DMA_SOURCE(BurstRequestSrc));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3546 assert_param(IS_TIM_DMA_LENGTH(BurstLength));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3547
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3548 if((htim->State == HAL_TIM_STATE_BUSY))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3549 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3550 return HAL_BUSY;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3551 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3552 else if((htim->State == HAL_TIM_STATE_READY))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3553 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3554 if((BurstBuffer == 0 ) && (BurstLength > 0))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3555 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3556 return HAL_ERROR;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3557 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3558 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3559 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3560 htim->State = HAL_TIM_STATE_BUSY;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3561 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3562 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3563 switch(BurstRequestSrc)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3564 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3565 case TIM_DMA_UPDATE:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3566 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3567 /* Set the DMA Period elapsed callback */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3568 htim->hdma[TIM_DMA_ID_UPDATE]->XferCpltCallback = TIM_DMAPeriodElapsedCplt;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3569
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3570 /* Set the DMA error callback */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3571 htim->hdma[TIM_DMA_ID_UPDATE]->XferErrorCallback = TIM_DMAError ;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3572
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3573 /* Enable the DMA channel */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3574 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_UPDATE], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, ((BurstLength) >> 8) + 1);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3575 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3576 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3577 case TIM_DMA_CC1:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3578 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3579 /* Set the DMA Period elapsed callback */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3580 htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMACaptureCplt;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3581
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3582 /* Set the DMA error callback */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3583 htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3584
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3585 /* Enable the DMA channel */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3586 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, ((BurstLength) >> 8) + 1);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3587 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3588 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3589 case TIM_DMA_CC2:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3590 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3591 /* Set the DMA Period elapsed callback */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3592 htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMACaptureCplt;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3593
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3594 /* Set the DMA error callback */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3595 htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError ;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3596
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3597 /* Enable the DMA channel */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3598 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, ((BurstLength) >> 8) + 1);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3599 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3600 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3601 case TIM_DMA_CC3:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3602 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3603 /* Set the DMA Period elapsed callback */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3604 htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMACaptureCplt;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3605
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3606 /* Set the DMA error callback */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3607 htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = TIM_DMAError ;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3608
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3609 /* Enable the DMA channel */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3610 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, ((BurstLength) >> 8) + 1);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3611 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3612 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3613 case TIM_DMA_CC4:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3614 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3615 /* Set the DMA Period elapsed callback */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3616 htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = TIM_DMACaptureCplt;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3617
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3618 /* Set the DMA error callback */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3619 htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = TIM_DMAError ;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3620
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3621 /* Enable the DMA channel */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3622 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, ((BurstLength) >> 8) + 1);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3623 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3624 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3625 case TIM_DMA_COM:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3626 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3627 /* Set the DMA Period elapsed callback */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3628 htim->hdma[TIM_DMA_ID_COMMUTATION]->XferCpltCallback = TIMEx_DMACommutationCplt;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3629
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3630 /* Set the DMA error callback */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3631 htim->hdma[TIM_DMA_ID_COMMUTATION]->XferErrorCallback = TIM_DMAError ;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3632
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3633 /* Enable the DMA channel */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3634 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_COMMUTATION], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, ((BurstLength) >> 8) + 1);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3635 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3636 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3637 case TIM_DMA_TRIGGER:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3638 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3639 /* Set the DMA Period elapsed callback */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3640 htim->hdma[TIM_DMA_ID_TRIGGER]->XferCpltCallback = TIM_DMATriggerCplt;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3641
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3642 /* Set the DMA error callback */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3643 htim->hdma[TIM_DMA_ID_TRIGGER]->XferErrorCallback = TIM_DMAError ;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3644
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3645 /* Enable the DMA channel */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3646 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_TRIGGER], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, ((BurstLength) >> 8) + 1);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3647 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3648 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3649 default:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3650 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3651 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3652
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3653 /* configure the DMA Burst Mode */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3654 htim->Instance->DCR = BurstBaseAddress | BurstLength;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3655
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3656 /* Enable the TIM DMA Request */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3657 __HAL_TIM_ENABLE_DMA(htim, BurstRequestSrc);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3658
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3659 htim->State = HAL_TIM_STATE_READY;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3660
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3661 /* Return function status */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3662 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3663 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3664
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3665 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3666 * @brief Stop the DMA burst reading
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3667 * @param htim : TIM handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3668 * @param BurstRequestSrc : TIM DMA Request sources to disable.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3669 * @retval HAL status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3670 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3671 HAL_StatusTypeDef HAL_TIM_DMABurst_ReadStop(TIM_HandleTypeDef *htim, uint32_t BurstRequestSrc)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3672 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3673 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3674 assert_param(IS_TIM_DMA_SOURCE(BurstRequestSrc));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3675
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3676 /* Abort the DMA transfer (at least disable the DMA channel) */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3677 switch(BurstRequestSrc)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3678 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3679 case TIM_DMA_UPDATE:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3680 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3681 HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_UPDATE]);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3682 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3683 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3684 case TIM_DMA_CC1:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3685 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3686 HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_CC1]);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3687 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3688 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3689 case TIM_DMA_CC2:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3690 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3691 HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_CC2]);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3692 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3693 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3694 case TIM_DMA_CC3:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3695 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3696 HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_CC3]);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3697 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3698 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3699 case TIM_DMA_CC4:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3700 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3701 HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_CC4]);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3702 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3703 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3704 case TIM_DMA_COM:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3705 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3706 HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_COMMUTATION]);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3707 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3708 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3709 case TIM_DMA_TRIGGER:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3710 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3711 HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_TRIGGER]);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3712 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3713 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3714 default:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3715 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3716 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3717
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3718 /* Disable the TIM Update DMA request */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3719 __HAL_TIM_DISABLE_DMA(htim, BurstRequestSrc);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3720
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3721 /* Return function status */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3722 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3723 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3724
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3725 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3726 * @brief Generate a software event
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3727 * @param htim : TIM handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3728 * @param EventSource : specifies the event source.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3729 * This parameter can be one of the following values:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3730 * @arg TIM_EVENTSOURCE_UPDATE: Timer update Event source
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3731 * @arg TIM_EVENTSOURCE_CC1: Timer Capture Compare 1 Event source
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3732 * @arg TIM_EVENTSOURCE_CC2: Timer Capture Compare 2 Event source
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3733 * @arg TIM_EVENTSOURCE_CC3: Timer Capture Compare 3 Event source
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3734 * @arg TIM_EVENTSOURCE_CC4: Timer Capture Compare 4 Event source
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3735 * @arg TIM_EVENTSOURCE_COM: Timer COM event source
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3736 * @arg TIM_EVENTSOURCE_TRIGGER: Timer Trigger Event source
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3737 * @arg TIM_EVENTSOURCE_BREAK: Timer Break event source
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3738 * @note TIM6 and TIM7 can only generate an update event.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3739 * @note TIM_EVENTSOURCE_COM and TIM_EVENTSOURCE_BREAK are used only with TIM1, TIM15, TIM16 and TIM17.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3740 * @retval HAL status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3741 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3742
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3743 HAL_StatusTypeDef HAL_TIM_GenerateEvent(TIM_HandleTypeDef *htim, uint32_t EventSource)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3744 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3745 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3746 assert_param(IS_TIM_INSTANCE(htim->Instance));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3747 assert_param(IS_TIM_EVENT_SOURCE(EventSource));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3748
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3749 /* Process Locked */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3750 __HAL_LOCK(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3751
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3752 /* Change the TIM state */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3753 htim->State = HAL_TIM_STATE_BUSY;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3754
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3755 /* Set the event sources */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3756 htim->Instance->EGR = EventSource;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3757
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3758 /* Change the TIM state */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3759 htim->State = HAL_TIM_STATE_READY;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3760
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3761 __HAL_UNLOCK(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3762
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3763 /* Return function status */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3764 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3765 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3766
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3767 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3768 * @brief Configures the OCRef clear feature
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3769 * @param htim : TIM handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3770 * @param sClearInputConfig : pointer to a TIM_ClearInputConfigTypeDef structure that
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3771 * contains the OCREF clear feature and parameters for the TIM peripheral.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3772 * @param Channel : specifies the TIM Channel
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3773 * This parameter can be one of the following values:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3774 * @arg TIM_CHANNEL_1: TIM Channel 1
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3775 * @arg TIM_CHANNEL_2: TIM Channel 2
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3776 * @arg TIM_CHANNEL_3: TIM Channel 3
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3777 * @arg TIM_CHANNEL_4: TIM Channel 4
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3778 * @retval HAL status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3779 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3780 HAL_StatusTypeDef HAL_TIM_ConfigOCrefClear(TIM_HandleTypeDef *htim, TIM_ClearInputConfigTypeDef * sClearInputConfig, uint32_t Channel)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3781 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3782 uint32_t tmpsmcr = 0;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3783
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3784 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3785 assert_param(IS_TIM_OCXREF_CLEAR_INSTANCE(htim->Instance));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3786 assert_param(IS_TIM_CLEARINPUT_SOURCE(sClearInputConfig->ClearInputSource));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3787 assert_param(IS_TIM_CLEARINPUT_POLARITY(sClearInputConfig->ClearInputPolarity));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3788 assert_param(IS_TIM_CLEARINPUT_PRESCALER(sClearInputConfig->ClearInputPrescaler));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3789 assert_param(IS_TIM_CLEARINPUT_FILTER(sClearInputConfig->ClearInputFilter));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3790
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3791 /* Process Locked */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3792 __HAL_LOCK(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3793
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3794 htim->State = HAL_TIM_STATE_BUSY;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3795
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3796 switch (sClearInputConfig->ClearInputSource)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3797 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3798 case TIM_CLEARINPUTSOURCE_NONE:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3799 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3800 /* Clear the OCREF clear selection bit */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3801 tmpsmcr &= ~TIM_SMCR_OCCS;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3802
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3803 /* Clear the ETR Bits */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3804 tmpsmcr &= ~(TIM_SMCR_ETF | TIM_SMCR_ETPS | TIM_SMCR_ECE | TIM_SMCR_ETP);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3805
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3806 /* Set TIMx_SMCR */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3807 htim->Instance->SMCR = tmpsmcr;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3808 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3809 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3810
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3811 case TIM_CLEARINPUTSOURCE_ETR:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3812 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3813 TIM_ETR_SetConfig(htim->Instance,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3814 sClearInputConfig->ClearInputPrescaler,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3815 sClearInputConfig->ClearInputPolarity,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3816 sClearInputConfig->ClearInputFilter);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3817
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3818 /* Set the OCREF clear selection bit */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3819 htim->Instance->SMCR |= TIM_SMCR_OCCS;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3820 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3821 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3822 default:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3823 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3824 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3825
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3826 switch (Channel)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3827 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3828 case TIM_CHANNEL_1:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3829 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3830 if(sClearInputConfig->ClearInputState != RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3831 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3832 /* Enable the Ocref clear feature for Channel 1 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3833 htim->Instance->CCMR1 |= TIM_CCMR1_OC1CE;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3834 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3835 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3836 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3837 /* Disable the Ocref clear feature for Channel 1 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3838 htim->Instance->CCMR1 &= ~TIM_CCMR1_OC1CE;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3839 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3840 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3841 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3842 case TIM_CHANNEL_2:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3843 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3844 assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3845 if(sClearInputConfig->ClearInputState != RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3846 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3847 /* Enable the Ocref clear feature for Channel 2 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3848 htim->Instance->CCMR1 |= TIM_CCMR1_OC2CE;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3849 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3850 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3851 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3852 /* Disable the Ocref clear feature for Channel 2 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3853 htim->Instance->CCMR1 &= ~TIM_CCMR1_OC2CE;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3854 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3855 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3856 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3857 case TIM_CHANNEL_3:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3858 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3859 assert_param(IS_TIM_CC3_INSTANCE(htim->Instance));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3860 if(sClearInputConfig->ClearInputState != RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3861 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3862 /* Enable the Ocref clear feature for Channel 3 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3863 htim->Instance->CCMR2 |= TIM_CCMR2_OC3CE;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3864 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3865 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3866 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3867 /* Disable the Ocref clear feature for Channel 3 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3868 htim->Instance->CCMR2 &= ~TIM_CCMR2_OC3CE;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3869 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3870 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3871 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3872 case TIM_CHANNEL_4:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3873 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3874 assert_param(IS_TIM_CC4_INSTANCE(htim->Instance));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3875 if(sClearInputConfig->ClearInputState != RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3876 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3877 /* Enable the Ocref clear feature for Channel 4 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3878 htim->Instance->CCMR2 |= TIM_CCMR2_OC4CE;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3879 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3880 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3881 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3882 /* Disable the Ocref clear feature for Channel 4 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3883 htim->Instance->CCMR2 &= ~TIM_CCMR2_OC4CE;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3884 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3885 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3886 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3887 default:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3888 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3889 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3890
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3891 htim->State = HAL_TIM_STATE_READY;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3892
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3893 __HAL_UNLOCK(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3894
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3895 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3896 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3897
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3898 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3899 * @brief Configures the clock source to be used
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3900 * @param htim : TIM handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3901 * @param sClockSourceConfig : pointer to a TIM_ClockConfigTypeDef structure that
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3902 * contains the clock source information for the TIM peripheral.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3903 * @retval HAL status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3904 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3905 HAL_StatusTypeDef HAL_TIM_ConfigClockSource(TIM_HandleTypeDef *htim, TIM_ClockConfigTypeDef * sClockSourceConfig)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3906 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3907 uint32_t tmpsmcr = 0;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3908
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3909 /* Process Locked */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3910 __HAL_LOCK(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3911
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3912 htim->State = HAL_TIM_STATE_BUSY;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3913
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3914 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3915 assert_param(IS_TIM_CLOCKSOURCE(sClockSourceConfig->ClockSource));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3916
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3917 /* Reset the SMS, TS, ECE, ETPS and ETRF bits */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3918 tmpsmcr = htim->Instance->SMCR;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3919 tmpsmcr &= ~(TIM_SMCR_SMS | TIM_SMCR_TS);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3920 tmpsmcr &= ~(TIM_SMCR_ETF | TIM_SMCR_ETPS | TIM_SMCR_ECE | TIM_SMCR_ETP);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3921 htim->Instance->SMCR = tmpsmcr;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3922
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3923 switch (sClockSourceConfig->ClockSource)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3924 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3925 case TIM_CLOCKSOURCE_INTERNAL:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3926 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3927 assert_param(IS_TIM_INSTANCE(htim->Instance));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3928 /* Disable slave mode to clock the prescaler directly with the internal clock */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3929 htim->Instance->SMCR &= ~TIM_SMCR_SMS;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3930 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3931 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3932
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3933 case TIM_CLOCKSOURCE_ETRMODE1:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3934 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3935 /* Check whether or not the timer instance supports external trigger input mode 1 (ETRF)*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3936 assert_param(IS_TIM_CLOCKSOURCE_ETRMODE1_INSTANCE(htim->Instance));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3937
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3938 /* Check ETR input conditioning related parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3939 assert_param(IS_TIM_CLOCKPRESCALER(sClockSourceConfig->ClockPrescaler));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3940 assert_param(IS_TIM_CLOCKPOLARITY(sClockSourceConfig->ClockPolarity));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3941 assert_param(IS_TIM_CLOCKFILTER(sClockSourceConfig->ClockFilter));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3942
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3943 /* Configure the ETR Clock source */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3944 TIM_ETR_SetConfig(htim->Instance,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3945 sClockSourceConfig->ClockPrescaler,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3946 sClockSourceConfig->ClockPolarity,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3947 sClockSourceConfig->ClockFilter);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3948 /* Get the TIMx SMCR register value */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3949 tmpsmcr = htim->Instance->SMCR;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3950 /* Reset the SMS and TS Bits */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3951 tmpsmcr &= ~(TIM_SMCR_SMS | TIM_SMCR_TS);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3952 /* Select the External clock mode1 and the ETRF trigger */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3953 tmpsmcr |= (TIM_SLAVEMODE_EXTERNAL1 | TIM_CLOCKSOURCE_ETRMODE1);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3954 /* Write to TIMx SMCR */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3955 htim->Instance->SMCR = tmpsmcr;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3956 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3957 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3958
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3959 case TIM_CLOCKSOURCE_ETRMODE2:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3960 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3961 /* Check whether or not the timer instance supports external trigger input mode 2 (ETRF)*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3962 assert_param(IS_TIM_CLOCKSOURCE_ETRMODE2_INSTANCE(htim->Instance));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3963
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3964 /* Check ETR input conditioning related parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3965 assert_param(IS_TIM_CLOCKPRESCALER(sClockSourceConfig->ClockPrescaler));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3966 assert_param(IS_TIM_CLOCKPOLARITY(sClockSourceConfig->ClockPolarity));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3967 assert_param(IS_TIM_CLOCKFILTER(sClockSourceConfig->ClockFilter));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3968
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3969 /* Configure the ETR Clock source */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3970 TIM_ETR_SetConfig(htim->Instance,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3971 sClockSourceConfig->ClockPrescaler,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3972 sClockSourceConfig->ClockPolarity,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3973 sClockSourceConfig->ClockFilter);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3974 /* Enable the External clock mode2 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3975 htim->Instance->SMCR |= TIM_SMCR_ECE;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3976 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3977 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3978
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3979 case TIM_CLOCKSOURCE_TI1:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3980 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3981 /* Check whether or not the timer instance supports external clock mode 1 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3982 assert_param(IS_TIM_CLOCKSOURCE_TIX_INSTANCE(htim->Instance));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3983
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3984 /* Check TI1 input conditioning related parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3985 assert_param(IS_TIM_CLOCKPOLARITY(sClockSourceConfig->ClockPolarity));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3986 assert_param(IS_TIM_CLOCKFILTER(sClockSourceConfig->ClockFilter));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3987
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3988 TIM_TI1_ConfigInputStage(htim->Instance,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3989 sClockSourceConfig->ClockPolarity,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3990 sClockSourceConfig->ClockFilter);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3991 TIM_ITRx_SetConfig(htim->Instance, TIM_CLOCKSOURCE_TI1);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3992 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3993 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3994 case TIM_CLOCKSOURCE_TI2:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3995 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3996 /* Check whether or not the timer instance supports external clock mode 1 (ETRF)*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3997 assert_param(IS_TIM_CLOCKSOURCE_TIX_INSTANCE(htim->Instance));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3998
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
3999 /* Check TI2 input conditioning related parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4000 assert_param(IS_TIM_CLOCKPOLARITY(sClockSourceConfig->ClockPolarity));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4001 assert_param(IS_TIM_CLOCKFILTER(sClockSourceConfig->ClockFilter));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4002
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4003 TIM_TI2_ConfigInputStage(htim->Instance,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4004 sClockSourceConfig->ClockPolarity,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4005 sClockSourceConfig->ClockFilter);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4006 TIM_ITRx_SetConfig(htim->Instance, TIM_CLOCKSOURCE_TI2);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4007 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4008 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4009 case TIM_CLOCKSOURCE_TI1ED:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4010 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4011 /* Check whether or not the timer instance supports external clock mode 1 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4012 assert_param(IS_TIM_CLOCKSOURCE_TIX_INSTANCE(htim->Instance));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4013
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4014 /* Check TI1 input conditioning related parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4015 assert_param(IS_TIM_CLOCKPOLARITY(sClockSourceConfig->ClockPolarity));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4016 assert_param(IS_TIM_CLOCKFILTER(sClockSourceConfig->ClockFilter));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4017
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4018 TIM_TI1_ConfigInputStage(htim->Instance,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4019 sClockSourceConfig->ClockPolarity,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4020 sClockSourceConfig->ClockFilter);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4021 TIM_ITRx_SetConfig(htim->Instance, TIM_CLOCKSOURCE_TI1ED);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4022 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4023 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4024 case TIM_CLOCKSOURCE_ITR0:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4025 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4026 /* Check whether or not the timer instance supports external clock mode 1 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4027 assert_param(IS_TIM_CLOCKSOURCE_ITRX_INSTANCE(htim->Instance));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4028
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4029 TIM_ITRx_SetConfig(htim->Instance, TIM_CLOCKSOURCE_ITR0);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4030 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4031 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4032 case TIM_CLOCKSOURCE_ITR1:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4033 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4034 /* Check whether or not the timer instance supports external clock mode 1 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4035 assert_param(IS_TIM_CLOCKSOURCE_ITRX_INSTANCE(htim->Instance));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4036
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4037 TIM_ITRx_SetConfig(htim->Instance, TIM_CLOCKSOURCE_ITR1);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4038 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4039 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4040 case TIM_CLOCKSOURCE_ITR2:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4041 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4042 /* Check whether or not the timer instance supports external clock mode 1 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4043 assert_param(IS_TIM_CLOCKSOURCE_ITRX_INSTANCE(htim->Instance));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4044
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4045 TIM_ITRx_SetConfig(htim->Instance, TIM_CLOCKSOURCE_ITR2);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4046 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4047 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4048 case TIM_CLOCKSOURCE_ITR3:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4049 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4050 /* Check whether or not the timer instance supports external clock mode 1 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4051 assert_param(IS_TIM_CLOCKSOURCE_ITRX_INSTANCE(htim->Instance));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4052
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4053 TIM_ITRx_SetConfig(htim->Instance, TIM_CLOCKSOURCE_ITR3);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4054 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4055 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4056
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4057 default:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4058 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4059 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4060 htim->State = HAL_TIM_STATE_READY;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4061
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4062 __HAL_UNLOCK(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4063
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4064 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4065 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4066
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4067 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4068 * @brief Selects the signal connected to the TI1 input: direct from CH1_input
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4069 * or a XOR combination between CH1_input, CH2_input & CH3_input
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4070 * @param htim : TIM handle.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4071 * @param TI1_Selection : Indicate whether or not channel 1 is connected to the
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4072 * output of a XOR gate.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4073 * This parameter can be one of the following values:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4074 * @arg TIM_TI1SELECTION_CH1: The TIMx_CH1 pin is connected to TI1 input
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4075 * @arg TIM_TI1SELECTION_XORCOMBINATION: The TIMx_CH1, CH2 and CH3
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4076 * pins are connected to the TI1 input (XOR combination)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4077 * @retval HAL status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4078 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4079 HAL_StatusTypeDef HAL_TIM_ConfigTI1Input(TIM_HandleTypeDef *htim, uint32_t TI1_Selection)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4080 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4081 uint32_t tmpcr2 = 0;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4082
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4083 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4084 assert_param(IS_TIM_XOR_INSTANCE(htim->Instance));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4085 assert_param(IS_TIM_TI1SELECTION(TI1_Selection));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4086
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4087 /* Get the TIMx CR2 register value */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4088 tmpcr2 = htim->Instance->CR2;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4089
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4090 /* Reset the TI1 selection */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4091 tmpcr2 &= ~TIM_CR2_TI1S;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4092
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4093 /* Set the the TI1 selection */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4094 tmpcr2 |= TI1_Selection;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4095
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4096 /* Write to TIMxCR2 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4097 htim->Instance->CR2 = tmpcr2;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4098
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4099 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4100 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4101
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4102 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4103 * @brief Configures the TIM in Slave mode
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4104 * @param htim : TIM handle.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4105 * @param sSlaveConfig : pointer to a TIM_SlaveConfigTypeDef structure that
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4106 * contains the selected trigger (internal trigger input, filtered
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4107 * timer input or external trigger input) and the ) and the Slave
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4108 * mode (Disable, Reset, Gated, Trigger, External clock mode 1).
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4109 * @retval HAL status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4110 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4111 HAL_StatusTypeDef HAL_TIM_SlaveConfigSynchronization(TIM_HandleTypeDef *htim, TIM_SlaveConfigTypeDef * sSlaveConfig)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4112 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4113 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4114 assert_param(IS_TIM_SLAVE_INSTANCE(htim->Instance));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4115 assert_param(IS_TIM_SLAVE_MODE(sSlaveConfig->SlaveMode));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4116 assert_param(IS_TIM_TRIGGER_SELECTION(sSlaveConfig->InputTrigger));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4117
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4118 __HAL_LOCK(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4119
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4120 htim->State = HAL_TIM_STATE_BUSY;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4121
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4122 TIM_SlaveTimer_SetConfig(htim, sSlaveConfig);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4123
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4124 /* Disable Trigger Interrupt */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4125 __HAL_TIM_DISABLE_IT(htim, TIM_IT_TRIGGER);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4126
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4127 /* Disable Trigger DMA request */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4128 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_TRIGGER);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4129
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4130 htim->State = HAL_TIM_STATE_READY;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4131
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4132 __HAL_UNLOCK(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4133
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4134 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4135 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4136
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4137 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4138 * @brief Configures the TIM in Slave mode in interrupt mode
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4139 * @param htim: TIM handle.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4140 * @param sSlaveConfig: pointer to a TIM_SlaveConfigTypeDef structure that
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4141 * contains the selected trigger (internal trigger input, filtered
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4142 * timer input or external trigger input) and the ) and the Slave
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4143 * mode (Disable, Reset, Gated, Trigger, External clock mode 1).
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4144 * @retval HAL status
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4145 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4146 HAL_StatusTypeDef HAL_TIM_SlaveConfigSynchronization_IT(TIM_HandleTypeDef *htim,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4147 TIM_SlaveConfigTypeDef * sSlaveConfig)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4148 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4149 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4150 assert_param(IS_TIM_SLAVE_INSTANCE(htim->Instance));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4151 assert_param(IS_TIM_SLAVE_MODE(sSlaveConfig->SlaveMode));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4152 assert_param(IS_TIM_TRIGGER_SELECTION(sSlaveConfig->InputTrigger));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4153
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4154 __HAL_LOCK(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4155
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4156 htim->State = HAL_TIM_STATE_BUSY;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4157
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4158 TIM_SlaveTimer_SetConfig(htim, sSlaveConfig);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4159
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4160 /* Enable Trigger Interrupt */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4161 __HAL_TIM_ENABLE_IT(htim, TIM_IT_TRIGGER);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4162
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4163 /* Disable Trigger DMA request */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4164 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_TRIGGER);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4165
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4166 htim->State = HAL_TIM_STATE_READY;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4167
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4168 __HAL_UNLOCK(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4169
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4170 return HAL_OK;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4171 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4172
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4173 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4174 * @brief Read the captured value from Capture Compare unit
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4175 * @param htim : TIM handle.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4176 * @param Channel : TIM Channels to be enabled
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4177 * This parameter can be one of the following values:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4178 * @arg TIM_CHANNEL_1 : TIM Channel 1 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4179 * @arg TIM_CHANNEL_2 : TIM Channel 2 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4180 * @arg TIM_CHANNEL_3 : TIM Channel 3 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4181 * @arg TIM_CHANNEL_4 : TIM Channel 4 selected
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4182 * @retval Captured value
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4183 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4184 uint32_t HAL_TIM_ReadCapturedValue(TIM_HandleTypeDef *htim, uint32_t Channel)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4185 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4186 uint32_t tmpreg = 0;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4187
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4188 __HAL_LOCK(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4189
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4190 switch (Channel)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4191 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4192 case TIM_CHANNEL_1:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4193 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4194 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4195 assert_param(IS_TIM_CC1_INSTANCE(htim->Instance));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4196
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4197 /* Return the capture 1 value */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4198 tmpreg = htim->Instance->CCR1;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4199
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4200 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4201 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4202 case TIM_CHANNEL_2:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4203 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4204 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4205 assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4206
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4207 /* Return the capture 2 value */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4208 tmpreg = htim->Instance->CCR2;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4209
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4210 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4211 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4212
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4213 case TIM_CHANNEL_3:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4214 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4215 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4216 assert_param(IS_TIM_CC3_INSTANCE(htim->Instance));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4217
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4218 /* Return the capture 3 value */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4219 tmpreg = htim->Instance->CCR3;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4220
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4221 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4222 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4223
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4224 case TIM_CHANNEL_4:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4225 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4226 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4227 assert_param(IS_TIM_CC4_INSTANCE(htim->Instance));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4228
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4229 /* Return the capture 4 value */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4230 tmpreg = htim->Instance->CCR4;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4231
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4232 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4233 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4234
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4235 default:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4236 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4237 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4238
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4239 __HAL_UNLOCK(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4240 return tmpreg;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4241 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4242
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4243 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4244 * @}
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4245 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4246
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4247 /** @defgroup TIM_Exported_Functions_Group9 TIM Callbacks functions
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4248 * @brief TIM Callbacks functions
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4249 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4250 @verbatim
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4251 ==============================================================================
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4252 ##### TIM Callbacks functions #####
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4253 ==============================================================================
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4254 [..]
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4255 This section provides TIM callback functions:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4256 (+) Timer Period elapsed callback
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4257 (+) Timer Output Compare callback
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4258 (+) Timer Input capture callback
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4259 (+) Timer Trigger callback
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4260 (+) Timer Error callback
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4261
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4262 @endverbatim
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4263 * @{
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4264 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4265
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4266 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4267 * @brief Period elapsed callback in non blocking mode
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4268 * @param htim : TIM handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4269 * @retval None
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4270 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4271 __weak void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4272 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4273 /* Prevent unused argument(s) compilation warning */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4274 UNUSED(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4275 /* NOTE : This function Should not be modified, when the callback is needed,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4276 the __HAL_TIM_PeriodElapsedCallback could be implemented in the user file
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4277 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4278
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4279 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4280 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4281 * @brief Output Compare callback in non blocking mode
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4282 * @param htim : TIM OC handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4283 * @retval None
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4284 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4285 __weak void HAL_TIM_OC_DelayElapsedCallback(TIM_HandleTypeDef *htim)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4286 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4287 /* Prevent unused argument(s) compilation warning */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4288 UNUSED(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4289 /* NOTE : This function Should not be modified, when the callback is needed,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4290 the __HAL_TIM_OC_DelayElapsedCallback could be implemented in the user file
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4291 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4292 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4293 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4294 * @brief Input Capture callback in non blocking mode
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4295 * @param htim : TIM IC handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4296 * @retval None
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4297 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4298 __weak void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4299 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4300 /* Prevent unused argument(s) compilation warning */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4301 UNUSED(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4302 /* NOTE : This function Should not be modified, when the callback is needed,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4303 the __HAL_TIM_IC_CaptureCallback could be implemented in the user file
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4304 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4305 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4306
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4307 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4308 * @brief PWM Pulse finished callback in non blocking mode
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4309 * @param htim : TIM handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4310 * @retval None
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4311 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4312 __weak void HAL_TIM_PWM_PulseFinishedCallback(TIM_HandleTypeDef *htim)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4313 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4314 /* Prevent unused argument(s) compilation warning */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4315 UNUSED(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4316 /* NOTE : This function Should not be modified, when the callback is needed,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4317 the __HAL_TIM_PWM_PulseFinishedCallback could be implemented in the user file
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4318 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4319 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4320
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4321 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4322 * @brief Hall Trigger detection callback in non blocking mode
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4323 * @param htim : TIM handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4324 * @retval None
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4325 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4326 __weak void HAL_TIM_TriggerCallback(TIM_HandleTypeDef *htim)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4327 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4328 /* Prevent unused argument(s) compilation warning */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4329 UNUSED(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4330 /* NOTE : This function Should not be modified, when the callback is needed,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4331 the HAL_TIM_TriggerCallback could be implemented in the user file
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4332 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4333 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4334
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4335 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4336 * @brief Timer error callback in non blocking mode
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4337 * @param htim : TIM handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4338 * @retval None
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4339 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4340 __weak void HAL_TIM_ErrorCallback(TIM_HandleTypeDef *htim)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4341 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4342 /* Prevent unused argument(s) compilation warning */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4343 UNUSED(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4344 /* NOTE : This function Should not be modified, when the callback is needed,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4345 the HAL_TIM_ErrorCallback could be implemented in the user file
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4346 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4347 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4348
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4349 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4350 * @}
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4351 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4352
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4353 /** @defgroup TIM_Exported_Functions_Group10 Peripheral State functions
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4354 * @brief Peripheral State functions
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4355 *
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4356 @verbatim
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4357 ==============================================================================
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4358 ##### Peripheral State functions #####
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4359 ==============================================================================
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4360 [..]
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4361 This subsection permit to get in run-time the status of the peripheral
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4362 and the data flow.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4363
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4364 @endverbatim
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4365 * @{
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4366 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4367
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4368 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4369 * @brief Return the TIM Base state
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4370 * @param htim : TIM Base handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4371 * @retval HAL state
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4372 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4373 HAL_TIM_StateTypeDef HAL_TIM_Base_GetState(TIM_HandleTypeDef *htim)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4374 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4375 return htim->State;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4376 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4377
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4378 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4379 * @brief Return the TIM OC state
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4380 * @param htim : TIM Ouput Compare handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4381 * @retval HAL state
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4382 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4383 HAL_TIM_StateTypeDef HAL_TIM_OC_GetState(TIM_HandleTypeDef *htim)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4384 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4385 return htim->State;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4386 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4387
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4388 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4389 * @brief Return the TIM PWM state
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4390 * @param htim : TIM handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4391 * @retval HAL state
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4392 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4393 HAL_TIM_StateTypeDef HAL_TIM_PWM_GetState(TIM_HandleTypeDef *htim)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4394 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4395 return htim->State;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4396 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4397
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4398 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4399 * @brief Return the TIM Input Capture state
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4400 * @param htim : TIM IC handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4401 * @retval HAL state
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4402 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4403 HAL_TIM_StateTypeDef HAL_TIM_IC_GetState(TIM_HandleTypeDef *htim)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4404 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4405 return htim->State;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4406 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4407
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4408 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4409 * @brief Return the TIM One Pulse Mode state
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4410 * @param htim : TIM OPM handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4411 * @retval HAL state
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4412 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4413 HAL_TIM_StateTypeDef HAL_TIM_OnePulse_GetState(TIM_HandleTypeDef *htim)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4414 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4415 return htim->State;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4416 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4417
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4418 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4419 * @brief Return the TIM Encoder Mode state
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4420 * @param htim : TIM Encoder handle
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4421 * @retval HAL state
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4422 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4423 HAL_TIM_StateTypeDef HAL_TIM_Encoder_GetState(TIM_HandleTypeDef *htim)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4424 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4425 return htim->State;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4426 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4427
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4428 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4429 * @}
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4430 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4431
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4432 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4433 * @}
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4434 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4435
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4436 /** @addtogroup TIM_Private_Functions
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4437 * @{
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4438 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4439
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4440 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4441 * @brief TIM DMA error callback
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4442 * @param hdma : pointer to DMA handle.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4443 * @retval None
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4444 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4445 void TIM_DMAError(DMA_HandleTypeDef *hdma)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4446 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4447 TIM_HandleTypeDef* htim = ( TIM_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4448
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4449 htim->State= HAL_TIM_STATE_READY;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4450
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4451 HAL_TIM_ErrorCallback(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4452 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4453
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4454 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4455 * @brief TIM DMA Delay Pulse complete callback.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4456 * @param hdma : pointer to DMA handle.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4457 * @retval None
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4458 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4459 void TIM_DMADelayPulseCplt(DMA_HandleTypeDef *hdma)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4460 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4461 TIM_HandleTypeDef* htim = ( TIM_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4462
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4463 htim->State= HAL_TIM_STATE_READY;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4464
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4465 if (hdma == htim->hdma[TIM_DMA_ID_CC1])
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4466 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4467 htim->Channel = HAL_TIM_ACTIVE_CHANNEL_1;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4468 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4469 else if (hdma == htim->hdma[TIM_DMA_ID_CC2])
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4470 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4471 htim->Channel = HAL_TIM_ACTIVE_CHANNEL_2;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4472 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4473 else if (hdma == htim->hdma[TIM_DMA_ID_CC3])
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4474 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4475 htim->Channel = HAL_TIM_ACTIVE_CHANNEL_3;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4476 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4477 else if (hdma == htim->hdma[TIM_DMA_ID_CC4])
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4478 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4479 htim->Channel = HAL_TIM_ACTIVE_CHANNEL_4;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4480 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4481
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4482 HAL_TIM_PWM_PulseFinishedCallback(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4483
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4484 htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4485 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4486 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4487 * @brief TIM DMA Capture complete callback.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4488 * @param hdma : pointer to DMA handle.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4489 * @retval None
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4490 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4491 void TIM_DMACaptureCplt(DMA_HandleTypeDef *hdma)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4492 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4493 TIM_HandleTypeDef* htim = ( TIM_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4494
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4495 htim->State= HAL_TIM_STATE_READY;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4496
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4497 if (hdma == htim->hdma[TIM_DMA_ID_CC1])
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4498 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4499 htim->Channel = HAL_TIM_ACTIVE_CHANNEL_1;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4500 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4501 else if (hdma == htim->hdma[TIM_DMA_ID_CC2])
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4502 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4503 htim->Channel = HAL_TIM_ACTIVE_CHANNEL_2;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4504 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4505 else if (hdma == htim->hdma[TIM_DMA_ID_CC3])
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4506 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4507 htim->Channel = HAL_TIM_ACTIVE_CHANNEL_3;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4508 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4509 else if (hdma == htim->hdma[TIM_DMA_ID_CC4])
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4510 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4511 htim->Channel = HAL_TIM_ACTIVE_CHANNEL_4;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4512 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4513
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4514 HAL_TIM_IC_CaptureCallback(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4515
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4516 htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4517 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4518
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4519 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4520 * @brief TIM DMA Period Elapse complete callback.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4521 * @param hdma : pointer to DMA handle.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4522 * @retval None
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4523 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4524 static void TIM_DMAPeriodElapsedCplt(DMA_HandleTypeDef *hdma)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4525 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4526 TIM_HandleTypeDef* htim = ( TIM_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4527
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4528 htim->State= HAL_TIM_STATE_READY;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4529
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4530 HAL_TIM_PeriodElapsedCallback(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4531 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4532
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4533 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4534 * @brief TIM DMA Trigger callback.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4535 * @param hdma : pointer to DMA handle.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4536 * @retval None
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4537 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4538 static void TIM_DMATriggerCplt(DMA_HandleTypeDef *hdma)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4539 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4540 TIM_HandleTypeDef* htim = ( TIM_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4541
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4542 htim->State= HAL_TIM_STATE_READY;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4543
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4544 HAL_TIM_TriggerCallback(htim);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4545 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4546
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4547 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4548 * @brief Time Base configuration
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4549 * @param TIMx : TIM periheral
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4550 * @param Structure : TIM Base configuration structure
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4551 * @retval None
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4552 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4553 void TIM_Base_SetConfig(TIM_TypeDef *TIMx, TIM_Base_InitTypeDef *Structure)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4554 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4555 uint32_t tmpcr1 = 0;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4556 tmpcr1 = TIMx->CR1;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4557
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4558 /* Set TIM Time Base Unit parameters ---------------------------------------*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4559 if (IS_TIM_COUNTER_MODE_SELECT_INSTANCE(TIMx))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4560 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4561 /* Select the Counter Mode */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4562 tmpcr1 &= ~(TIM_CR1_DIR | TIM_CR1_CMS);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4563 tmpcr1 |= Structure->CounterMode;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4564 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4565
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4566 if(IS_TIM_CLOCK_DIVISION_INSTANCE(TIMx))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4567 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4568 /* Set the clock division */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4569 tmpcr1 &= ~TIM_CR1_CKD;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4570 tmpcr1 |= (uint32_t)Structure->ClockDivision;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4571 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4572
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4573 TIMx->CR1 = tmpcr1;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4574
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4575 /* Set the Autoreload value */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4576 TIMx->ARR = (uint32_t)Structure->Period ;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4577
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4578 /* Set the Prescaler value */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4579 TIMx->PSC = (uint32_t)Structure->Prescaler;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4580
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4581 if (IS_TIM_REPETITION_COUNTER_INSTANCE(TIMx))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4582 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4583 /* Set the Repetition Counter value */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4584 TIMx->RCR = Structure->RepetitionCounter;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4585 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4586
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4587 /* Generate an update event to reload the Prescaler
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4588 and the repetition counter(only for TIM1 and TIM8) value immediatly */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4589 TIMx->EGR = TIM_EGR_UG;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4590 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4591
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4592 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4593 * @brief Time Ouput Compare 1 configuration
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4594 * @param TIMx to select the TIM peripheral
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4595 * @param OC_Config : The ouput configuration structure
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4596 * @retval None
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4597 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4598 static void TIM_OC1_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4599 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4600 uint32_t tmpccmrx = 0;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4601 uint32_t tmpccer = 0;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4602 uint32_t tmpcr2 = 0;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4603
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4604 /* Disable the Channel 1: Reset the CC1E Bit */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4605 TIMx->CCER &= ~TIM_CCER_CC1E;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4606
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4607 /* Get the TIMx CCER register value */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4608 tmpccer = TIMx->CCER;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4609 /* Get the TIMx CR2 register value */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4610 tmpcr2 = TIMx->CR2;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4611
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4612 /* Get the TIMx CCMR1 register value */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4613 tmpccmrx = TIMx->CCMR1;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4614
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4615 /* Reset the Output Compare Mode Bits */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4616 tmpccmrx &= ~TIM_CCMR1_OC1M;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4617 tmpccmrx &= ~TIM_CCMR1_CC1S;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4618 /* Select the Output Compare Mode */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4619 tmpccmrx |= OC_Config->OCMode;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4620
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4621 /* Reset the Output Polarity level */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4622 tmpccer &= ~TIM_CCER_CC1P;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4623 /* Set the Output Compare Polarity */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4624 tmpccer |= OC_Config->OCPolarity;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4625
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4626 if(IS_TIM_CCXN_INSTANCE(TIMx, TIM_CHANNEL_1))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4627 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4628 /* Check parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4629 assert_param(IS_TIM_OCN_POLARITY(OC_Config->OCNPolarity));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4630
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4631 /* Reset the Output N Polarity level */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4632 tmpccer &= ~TIM_CCER_CC1NP;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4633 /* Set the Output N Polarity */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4634 tmpccer |= OC_Config->OCNPolarity;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4635 /* Reset the Output N State */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4636 tmpccer &= ~TIM_CCER_CC1NE;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4637 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4638
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4639 if(IS_TIM_BREAK_INSTANCE(TIMx))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4640 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4641 /* Check parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4642 assert_param(IS_TIM_OCNIDLE_STATE(OC_Config->OCNIdleState));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4643 assert_param(IS_TIM_OCIDLE_STATE(OC_Config->OCIdleState));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4644
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4645 /* Reset the Output Compare and Output Compare N IDLE State */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4646 tmpcr2 &= ~TIM_CR2_OIS1;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4647 tmpcr2 &= ~TIM_CR2_OIS1N;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4648 /* Set the Output Idle state */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4649 tmpcr2 |= OC_Config->OCIdleState;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4650 /* Set the Output N Idle state */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4651 tmpcr2 |= OC_Config->OCNIdleState;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4652 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4653 /* Write to TIMx CR2 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4654 TIMx->CR2 = tmpcr2;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4655
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4656 /* Write to TIMx CCMR1 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4657 TIMx->CCMR1 = tmpccmrx;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4658
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4659 /* Set the Capture Compare Register value */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4660 TIMx->CCR1 = OC_Config->Pulse;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4661
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4662 /* Write to TIMx CCER */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4663 TIMx->CCER = tmpccer;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4664 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4665
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4666 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4667 * @brief Time Ouput Compare 2 configuration
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4668 * @param TIMx to select the TIM peripheral
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4669 * @param OC_Config : The ouput configuration structure
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4670 * @retval None
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4671 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4672 void TIM_OC2_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4673 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4674 uint32_t tmpccmrx = 0;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4675 uint32_t tmpccer = 0;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4676 uint32_t tmpcr2 = 0;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4677
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4678 /* Disable the Channel 2: Reset the CC2E Bit */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4679 TIMx->CCER &= ~TIM_CCER_CC2E;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4680
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4681 /* Get the TIMx CCER register value */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4682 tmpccer = TIMx->CCER;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4683 /* Get the TIMx CR2 register value */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4684 tmpcr2 = TIMx->CR2;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4685
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4686 /* Get the TIMx CCMR1 register value */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4687 tmpccmrx = TIMx->CCMR1;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4688
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4689 /* Reset the Output Compare mode and Capture/Compare selection Bits */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4690 tmpccmrx &= ~TIM_CCMR1_OC2M;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4691 tmpccmrx &= ~TIM_CCMR1_CC2S;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4692
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4693 /* Select the Output Compare Mode */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4694 tmpccmrx |= (OC_Config->OCMode << 8);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4695
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4696 /* Reset the Output Polarity level */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4697 tmpccer &= ~TIM_CCER_CC2P;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4698 /* Set the Output Compare Polarity */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4699 tmpccer |= (OC_Config->OCPolarity << 4);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4700
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4701 if(IS_TIM_CCXN_INSTANCE(TIMx, TIM_CHANNEL_2))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4702 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4703 assert_param(IS_TIM_OCN_POLARITY(OC_Config->OCNPolarity));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4704
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4705 /* Reset the Output N Polarity level */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4706 tmpccer &= ~TIM_CCER_CC2NP;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4707 /* Set the Output N Polarity */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4708 tmpccer |= (OC_Config->OCNPolarity << 4);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4709 /* Reset the Output N State */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4710 tmpccer &= ~TIM_CCER_CC2NE;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4711
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4712 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4713
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4714 if(IS_TIM_BREAK_INSTANCE(TIMx))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4715 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4716 /* Check parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4717 assert_param(IS_TIM_OCNIDLE_STATE(OC_Config->OCNIdleState));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4718 assert_param(IS_TIM_OCIDLE_STATE(OC_Config->OCIdleState));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4719
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4720 /* Reset the Output Compare and Output Compare N IDLE State */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4721 tmpcr2 &= ~TIM_CR2_OIS2;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4722 tmpcr2 &= ~TIM_CR2_OIS2N;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4723 /* Set the Output Idle state */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4724 tmpcr2 |= (OC_Config->OCIdleState << 2);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4725 /* Set the Output N Idle state */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4726 tmpcr2 |= (OC_Config->OCNIdleState << 2);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4727 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4728
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4729 /* Write to TIMx CR2 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4730 TIMx->CR2 = tmpcr2;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4731
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4732 /* Write to TIMx CCMR1 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4733 TIMx->CCMR1 = tmpccmrx;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4734
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4735 /* Set the Capture Compare Register value */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4736 TIMx->CCR2 = OC_Config->Pulse;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4737
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4738 /* Write to TIMx CCER */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4739 TIMx->CCER = tmpccer;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4740 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4741
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4742 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4743 * @brief Time Ouput Compare 3 configuration
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4744 * @param TIMx to select the TIM peripheral
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4745 * @param OC_Config : The ouput configuration structure
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4746 * @retval None
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4747 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4748 static void TIM_OC3_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4749 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4750 uint32_t tmpccmrx = 0;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4751 uint32_t tmpccer = 0;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4752 uint32_t tmpcr2 = 0;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4753
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4754 /* Disable the Channel 3: Reset the CC2E Bit */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4755 TIMx->CCER &= ~TIM_CCER_CC3E;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4756
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4757 /* Get the TIMx CCER register value */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4758 tmpccer = TIMx->CCER;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4759 /* Get the TIMx CR2 register value */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4760 tmpcr2 = TIMx->CR2;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4761
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4762 /* Get the TIMx CCMR2 register value */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4763 tmpccmrx = TIMx->CCMR2;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4764
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4765 /* Reset the Output Compare mode and Capture/Compare selection Bits */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4766 tmpccmrx &= ~TIM_CCMR2_OC3M;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4767 tmpccmrx &= ~TIM_CCMR2_CC3S;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4768 /* Select the Output Compare Mode */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4769 tmpccmrx |= OC_Config->OCMode;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4770
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4771 /* Reset the Output Polarity level */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4772 tmpccer &= ~TIM_CCER_CC3P;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4773 /* Set the Output Compare Polarity */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4774 tmpccer |= (OC_Config->OCPolarity << 8);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4775
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4776 if(IS_TIM_CCXN_INSTANCE(TIMx, TIM_CHANNEL_3))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4777 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4778 assert_param(IS_TIM_OCN_POLARITY(OC_Config->OCNPolarity));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4779
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4780 /* Reset the Output N Polarity level */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4781 tmpccer &= ~TIM_CCER_CC3NP;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4782 /* Set the Output N Polarity */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4783 tmpccer |= (OC_Config->OCNPolarity << 8);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4784 /* Reset the Output N State */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4785 tmpccer &= ~TIM_CCER_CC3NE;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4786 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4787
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4788 if(IS_TIM_BREAK_INSTANCE(TIMx))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4789 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4790 /* Check parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4791 assert_param(IS_TIM_OCNIDLE_STATE(OC_Config->OCNIdleState));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4792 assert_param(IS_TIM_OCIDLE_STATE(OC_Config->OCIdleState));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4793
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4794 /* Reset the Output Compare and Output Compare N IDLE State */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4795 tmpcr2 &= ~TIM_CR2_OIS3;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4796 tmpcr2 &= ~TIM_CR2_OIS3N;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4797 /* Set the Output Idle state */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4798 tmpcr2 |= (OC_Config->OCIdleState << 4);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4799 /* Set the Output N Idle state */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4800 tmpcr2 |= (OC_Config->OCNIdleState << 4);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4801 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4802
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4803 /* Write to TIMx CR2 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4804 TIMx->CR2 = tmpcr2;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4805
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4806 /* Write to TIMx CCMR2 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4807 TIMx->CCMR2 = tmpccmrx;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4808
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4809 /* Set the Capture Compare Register value */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4810 TIMx->CCR3 = OC_Config->Pulse;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4811
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4812 /* Write to TIMx CCER */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4813 TIMx->CCER = tmpccer;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4814 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4815
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4816 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4817 * @brief Time Ouput Compare 4 configuration
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4818 * @param TIMx to select the TIM peripheral
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4819 * @param OC_Config : The ouput configuration structure
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4820 * @retval None
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4821 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4822 static void TIM_OC4_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4823 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4824 uint32_t tmpccmrx = 0;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4825 uint32_t tmpccer = 0;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4826 uint32_t tmpcr2 = 0;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4827
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4828 /* Disable the Channel 4: Reset the CC4E Bit */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4829 TIMx->CCER &= ~TIM_CCER_CC4E;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4830
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4831 /* Get the TIMx CCER register value */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4832 tmpccer = TIMx->CCER;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4833 /* Get the TIMx CR2 register value */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4834 tmpcr2 = TIMx->CR2;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4835
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4836 /* Get the TIMx CCMR2 register value */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4837 tmpccmrx = TIMx->CCMR2;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4838
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4839 /* Reset the Output Compare mode and Capture/Compare selection Bits */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4840 tmpccmrx &= ~TIM_CCMR2_OC4M;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4841 tmpccmrx &= ~TIM_CCMR2_CC4S;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4842
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4843 /* Select the Output Compare Mode */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4844 tmpccmrx |= (OC_Config->OCMode << 8);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4845
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4846 /* Reset the Output Polarity level */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4847 tmpccer &= ~TIM_CCER_CC4P;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4848 /* Set the Output Compare Polarity */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4849 tmpccer |= (OC_Config->OCPolarity << 12);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4850
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4851 if(IS_TIM_BREAK_INSTANCE(TIMx))
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4852 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4853 assert_param(IS_TIM_OCIDLE_STATE(OC_Config->OCIdleState));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4854
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4855 /* Reset the Output Compare IDLE State */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4856 tmpcr2 &= ~TIM_CR2_OIS4;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4857 /* Set the Output Idle state */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4858 tmpcr2 |= (OC_Config->OCIdleState << 6);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4859 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4860
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4861 /* Write to TIMx CR2 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4862 TIMx->CR2 = tmpcr2;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4863
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4864 /* Write to TIMx CCMR2 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4865 TIMx->CCMR2 = tmpccmrx;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4866
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4867 /* Set the Capture Compare Register value */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4868 TIMx->CCR4 = OC_Config->Pulse;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4869
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4870 /* Write to TIMx CCER */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4871 TIMx->CCER = tmpccer;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4872 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4873
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4874
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4875 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4876 * @brief Time Slave configuration
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4877 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4878 * the configuration information for TIM module.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4879 * @param sSlaveConfig: The slave configuration structure
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4880 * @retval None
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4881 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4882 static void TIM_SlaveTimer_SetConfig(TIM_HandleTypeDef *htim,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4883 TIM_SlaveConfigTypeDef * sSlaveConfig)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4884 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4885 uint32_t tmpsmcr = 0;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4886 uint32_t tmpccmr1 = 0;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4887 uint32_t tmpccer = 0;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4888
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4889 /* Get the TIMx SMCR register value */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4890 tmpsmcr = htim->Instance->SMCR;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4891
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4892 /* Reset the Trigger Selection Bits */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4893 tmpsmcr &= ~TIM_SMCR_TS;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4894 /* Set the Input Trigger source */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4895 tmpsmcr |= sSlaveConfig->InputTrigger;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4896
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4897 /* Reset the slave mode Bits */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4898 tmpsmcr &= ~TIM_SMCR_SMS;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4899 /* Set the slave mode */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4900 tmpsmcr |= sSlaveConfig->SlaveMode;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4901
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4902 /* Write to TIMx SMCR */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4903 htim->Instance->SMCR = tmpsmcr;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4904
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4905 /* Configure the trigger prescaler, filter, and polarity */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4906 switch (sSlaveConfig->InputTrigger)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4907 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4908 case TIM_TS_ETRF:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4909 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4910 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4911 assert_param(IS_TIM_CLOCKSOURCE_ETRMODE1_INSTANCE(htim->Instance));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4912 assert_param(IS_TIM_TRIGGERPRESCALER(sSlaveConfig->TriggerPrescaler));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4913 assert_param(IS_TIM_TRIGGERPOLARITY(sSlaveConfig->TriggerPolarity));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4914 assert_param(IS_TIM_TRIGGERFILTER(sSlaveConfig->TriggerFilter));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4915 /* Configure the ETR Trigger source */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4916 TIM_ETR_SetConfig(htim->Instance,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4917 sSlaveConfig->TriggerPrescaler,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4918 sSlaveConfig->TriggerPolarity,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4919 sSlaveConfig->TriggerFilter);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4920 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4921 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4922
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4923 case TIM_TS_TI1F_ED:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4924 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4925 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4926 assert_param(IS_TIM_CC1_INSTANCE(htim->Instance));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4927 assert_param(IS_TIM_TRIGGERFILTER(sSlaveConfig->TriggerFilter));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4928
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4929 /* Disable the Channel 1: Reset the CC1E Bit */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4930 tmpccer = htim->Instance->CCER;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4931 htim->Instance->CCER &= ~TIM_CCER_CC1E;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4932 tmpccmr1 = htim->Instance->CCMR1;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4933
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4934 /* Set the filter */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4935 tmpccmr1 &= ~TIM_CCMR1_IC1F;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4936 tmpccmr1 |= ((sSlaveConfig->TriggerFilter) << 4);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4937
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4938 /* Write to TIMx CCMR1 and CCER registers */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4939 htim->Instance->CCMR1 = tmpccmr1;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4940 htim->Instance->CCER = tmpccer;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4941
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4942 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4943 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4944
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4945 case TIM_TS_TI1FP1:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4946 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4947 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4948 assert_param(IS_TIM_CC1_INSTANCE(htim->Instance));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4949 assert_param(IS_TIM_TRIGGERPOLARITY(sSlaveConfig->TriggerPolarity));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4950 assert_param(IS_TIM_TRIGGERFILTER(sSlaveConfig->TriggerFilter));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4951
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4952 /* Configure TI1 Filter and Polarity */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4953 TIM_TI1_ConfigInputStage(htim->Instance,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4954 sSlaveConfig->TriggerPolarity,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4955 sSlaveConfig->TriggerFilter);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4956 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4957 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4958
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4959 case TIM_TS_TI2FP2:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4960 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4961 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4962 assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4963 assert_param(IS_TIM_TRIGGERPOLARITY(sSlaveConfig->TriggerPolarity));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4964 assert_param(IS_TIM_TRIGGERFILTER(sSlaveConfig->TriggerFilter));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4965
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4966 /* Configure TI2 Filter and Polarity */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4967 TIM_TI2_ConfigInputStage(htim->Instance,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4968 sSlaveConfig->TriggerPolarity,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4969 sSlaveConfig->TriggerFilter);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4970 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4971 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4972
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4973 case TIM_TS_ITR0:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4974 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4975 /* Check the parameter */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4976 assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4977 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4978 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4979
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4980 case TIM_TS_ITR1:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4981 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4982 /* Check the parameter */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4983 assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4984 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4985 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4986
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4987 case TIM_TS_ITR2:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4988 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4989 /* Check the parameter */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4990 assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4991 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4992 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4993
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4994 case TIM_TS_ITR3:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4995 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4996 /* Check the parameter */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4997 assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4998 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
4999 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5000
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5001 default:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5002 break;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5003 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5004 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5005
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5006 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5007 * @brief Configure the TI1 as Input.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5008 * @param TIMx to select the TIM peripheral.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5009 * @param TIM_ICPolarity : The Input Polarity.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5010 * This parameter can be one of the following values:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5011 * @arg TIM_ICPOLARITY_RISING
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5012 * @arg TIM_ICPOLARITY_FALLING
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5013 * @arg TIM_ICPOLARITY_BOTHEDGE
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5014 * @param TIM_ICSelection : specifies the input to be used.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5015 * This parameter can be one of the following values:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5016 * @arg TIM_ICSELECTION_DIRECTTI: TIM Input 1 is selected to be connected to IC1.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5017 * @arg TIM_ICSELECTION_INDIRECTTI: TIM Input 1 is selected to be connected to IC2.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5018 * @arg TIM_ICSELECTION_TRC: TIM Input 1 is selected to be connected to TRC.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5019 * @param TIM_ICFilter : Specifies the Input Capture Filter.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5020 * This parameter must be a value between 0x00 and 0x0F.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5021 * @retval None
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5022 * @note TIM_ICFilter and TIM_ICPolarity are not used in INDIRECT mode as TI2FP1
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5023 * (on channel2 path) is used as the input signal. Therefore CCMR1 must be
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5024 * protected against un-initialized filter and polarity values.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5025 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5026 void TIM_TI1_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5027 uint32_t TIM_ICFilter)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5028 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5029 uint32_t tmpccmr1 = 0;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5030 uint32_t tmpccer = 0;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5031
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5032 /* Disable the Channel 1: Reset the CC1E Bit */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5033 TIMx->CCER &= ~TIM_CCER_CC1E;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5034 tmpccmr1 = TIMx->CCMR1;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5035 tmpccer = TIMx->CCER;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5036
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5037 /* Select the Input */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5038 if(IS_TIM_CC2_INSTANCE(TIMx) != RESET)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5039 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5040 tmpccmr1 &= ~TIM_CCMR1_CC1S;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5041 tmpccmr1 |= TIM_ICSelection;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5042 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5043 else
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5044 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5045 tmpccmr1 |= TIM_CCMR1_CC1S_0;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5046 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5047
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5048 /* Set the filter */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5049 tmpccmr1 &= ~TIM_CCMR1_IC1F;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5050 tmpccmr1 |= ((TIM_ICFilter << 4) & TIM_CCMR1_IC1F);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5051
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5052 /* Select the Polarity and set the CC1E Bit */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5053 tmpccer &= ~(TIM_CCER_CC1P | TIM_CCER_CC1NP);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5054 tmpccer |= (TIM_ICPolarity & (TIM_CCER_CC1P | TIM_CCER_CC1NP));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5055
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5056 /* Write to TIMx CCMR1 and CCER registers */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5057 TIMx->CCMR1 = tmpccmr1;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5058 TIMx->CCER = tmpccer;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5059 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5060
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5061 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5062 * @brief Configure the Polarity and Filter for TI1.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5063 * @param TIMx to select the TIM peripheral.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5064 * @param TIM_ICPolarity : The Input Polarity.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5065 * This parameter can be one of the following values:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5066 * @arg TIM_ICPOLARITY_RISING
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5067 * @arg TIM_ICPOLARITY_FALLING
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5068 * @arg TIM_ICPOLARITY_BOTHEDGE
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5069 * @param TIM_ICFilter : Specifies the Input Capture Filter.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5070 * This parameter must be a value between 0x00 and 0x0F.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5071 * @retval None
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5072 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5073 static void TIM_TI1_ConfigInputStage(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICFilter)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5074 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5075 uint32_t tmpccmr1 = 0;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5076 uint32_t tmpccer = 0;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5077
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5078 /* Disable the Channel 1: Reset the CC1E Bit */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5079 tmpccer = TIMx->CCER;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5080 TIMx->CCER &= ~TIM_CCER_CC1E;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5081 tmpccmr1 = TIMx->CCMR1;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5082
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5083 /* Set the filter */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5084 tmpccmr1 &= ~TIM_CCMR1_IC1F;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5085 tmpccmr1 |= (TIM_ICFilter << 4);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5086
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5087 /* Select the Polarity and set the CC1E Bit */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5088 tmpccer &= ~(TIM_CCER_CC1P | TIM_CCER_CC1NP);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5089 tmpccer |= TIM_ICPolarity;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5090
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5091 /* Write to TIMx CCMR1 and CCER registers */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5092 TIMx->CCMR1 = tmpccmr1;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5093 TIMx->CCER = tmpccer;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5094 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5095
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5096 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5097 * @brief Configure the TI2 as Input.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5098 * @param TIMx to select the TIM peripheral
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5099 * @param TIM_ICPolarity : The Input Polarity.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5100 * This parameter can be one of the following values:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5101 * @arg TIM_ICPOLARITY_RISING
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5102 * @arg TIM_ICPOLARITY_FALLING
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5103 * @arg TIM_ICPOLARITY_BOTHEDGE
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5104 * @param TIM_ICSelection : specifies the input to be used.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5105 * This parameter can be one of the following values:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5106 * @arg TIM_ICSELECTION_DIRECTTI: TIM Input 2 is selected to be connected to IC2.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5107 * @arg TIM_ICSELECTION_INDIRECTTI: TIM Input 2 is selected to be connected to IC1.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5108 * @arg TIM_ICSELECTION_TRC: TIM Input 2 is selected to be connected to TRC.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5109 * @param TIM_ICFilter : Specifies the Input Capture Filter.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5110 * This parameter must be a value between 0x00 and 0x0F.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5111 * @retval None
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5112 * @note TIM_ICFilter and TIM_ICPolarity are not used in INDIRECT mode as TI1FP2
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5113 * (on channel1 path) is used as the input signal. Therefore CCMR1 must be
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5114 * protected against un-initialized filter and polarity values.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5115 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5116 static void TIM_TI2_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5117 uint32_t TIM_ICFilter)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5118 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5119 uint32_t tmpccmr1 = 0;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5120 uint32_t tmpccer = 0;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5121
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5122 /* Disable the Channel 2: Reset the CC2E Bit */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5123 TIMx->CCER &= ~TIM_CCER_CC2E;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5124 tmpccmr1 = TIMx->CCMR1;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5125 tmpccer = TIMx->CCER;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5126
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5127 /* Select the Input */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5128 tmpccmr1 &= ~TIM_CCMR1_CC2S;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5129 tmpccmr1 |= (TIM_ICSelection << 8);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5130
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5131 /* Set the filter */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5132 tmpccmr1 &= ~TIM_CCMR1_IC2F;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5133 tmpccmr1 |= ((TIM_ICFilter << 12) & TIM_CCMR1_IC2F);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5134
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5135 /* Select the Polarity and set the CC2E Bit */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5136 tmpccer &= ~(TIM_CCER_CC2P | TIM_CCER_CC2NP);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5137 tmpccer |= ((TIM_ICPolarity << 4) & (TIM_CCER_CC2P | TIM_CCER_CC2NP));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5138
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5139 /* Write to TIMx CCMR1 and CCER registers */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5140 TIMx->CCMR1 = tmpccmr1 ;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5141 TIMx->CCER = tmpccer;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5142 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5143
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5144 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5145 * @brief Configure the Polarity and Filter for TI2.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5146 * @param TIMx to select the TIM peripheral.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5147 * @param TIM_ICPolarity : The Input Polarity.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5148 * This parameter can be one of the following values:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5149 * @arg TIM_ICPOLARITY_RISING
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5150 * @arg TIM_ICPOLARITY_FALLING
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5151 * @arg TIM_ICPOLARITY_BOTHEDGE
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5152 * @param TIM_ICFilter : Specifies the Input Capture Filter.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5153 * This parameter must be a value between 0x00 and 0x0F.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5154 * @retval None
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5155 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5156 static void TIM_TI2_ConfigInputStage(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICFilter)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5157 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5158 uint32_t tmpccmr1 = 0;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5159 uint32_t tmpccer = 0;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5160
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5161 /* Disable the Channel 2: Reset the CC2E Bit */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5162 TIMx->CCER &= ~TIM_CCER_CC2E;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5163 tmpccmr1 = TIMx->CCMR1;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5164 tmpccer = TIMx->CCER;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5165
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5166 /* Set the filter */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5167 tmpccmr1 &= ~TIM_CCMR1_IC2F;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5168 tmpccmr1 |= (TIM_ICFilter << 12);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5169
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5170 /* Select the Polarity and set the CC2E Bit */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5171 tmpccer &= ~(TIM_CCER_CC2P | TIM_CCER_CC2NP);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5172 tmpccer |= (TIM_ICPolarity << 4);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5173
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5174 /* Write to TIMx CCMR1 and CCER registers */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5175 TIMx->CCMR1 = tmpccmr1 ;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5176 TIMx->CCER = tmpccer;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5177 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5178
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5179 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5180 * @brief Configure the TI3 as Input.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5181 * @param TIMx to select the TIM peripheral
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5182 * @param TIM_ICPolarity : The Input Polarity.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5183 * This parameter can be one of the following values:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5184 * @arg TIM_ICPOLARITY_RISING
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5185 * @arg TIM_ICPOLARITY_FALLING
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5186 * @arg TIM_ICPOLARITY_BOTHEDGE
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5187 * @param TIM_ICSelection : specifies the input to be used.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5188 * This parameter can be one of the following values:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5189 * @arg TIM_ICSELECTION_DIRECTTI: TIM Input 3 is selected to be connected to IC3.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5190 * @arg TIM_ICSELECTION_INDIRECTTI: TIM Input 3 is selected to be connected to IC4.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5191 * @arg TIM_ICSELECTION_TRC: TIM Input 3 is selected to be connected to TRC.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5192 * @param TIM_ICFilter : Specifies the Input Capture Filter.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5193 * This parameter must be a value between 0x00 and 0x0F.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5194 * @retval None
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5195 * @note TIM_ICFilter and TIM_ICPolarity are not used in INDIRECT mode as TI3FP4
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5196 * (on channel1 path) is used as the input signal. Therefore CCMR2 must be
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5197 * protected against un-initialized filter and polarity values.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5198 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5199 static void TIM_TI3_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5200 uint32_t TIM_ICFilter)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5201 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5202 uint32_t tmpccmr2 = 0;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5203 uint32_t tmpccer = 0;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5204
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5205 /* Disable the Channel 3: Reset the CC3E Bit */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5206 TIMx->CCER &= ~TIM_CCER_CC3E;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5207 tmpccmr2 = TIMx->CCMR2;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5208 tmpccer = TIMx->CCER;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5209
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5210 /* Select the Input */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5211 tmpccmr2 &= ~TIM_CCMR2_CC3S;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5212 tmpccmr2 |= TIM_ICSelection;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5213
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5214 /* Set the filter */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5215 tmpccmr2 &= ~TIM_CCMR2_IC3F;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5216 tmpccmr2 |= ((TIM_ICFilter << 4) & TIM_CCMR2_IC3F);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5217
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5218 /* Select the Polarity and set the CC3E Bit */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5219 tmpccer &= ~(TIM_CCER_CC3P | TIM_CCER_CC3NP);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5220 tmpccer |= ((TIM_ICPolarity << 8) & (TIM_CCER_CC3P | TIM_CCER_CC3NP));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5221
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5222 /* Write to TIMx CCMR2 and CCER registers */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5223 TIMx->CCMR2 = tmpccmr2;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5224 TIMx->CCER = tmpccer;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5225 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5226
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5227 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5228 * @brief Configure the TI4 as Input.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5229 * @param TIMx to select the TIM peripheral
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5230 * @param TIM_ICPolarity : The Input Polarity.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5231 * This parameter can be one of the following values:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5232 * @arg TIM_ICPOLARITY_RISING
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5233 * @arg TIM_ICPOLARITY_FALLING
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5234 * @arg TIM_ICPOLARITY_BOTHEDGE
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5235 * @param TIM_ICSelection : specifies the input to be used.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5236 * This parameter can be one of the following values:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5237 * @arg TIM_ICSELECTION_DIRECTTI: TIM Input 4 is selected to be connected to IC4.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5238 * @arg TIM_ICSELECTION_INDIRECTTI: TIM Input 4 is selected to be connected to IC3.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5239 * @arg TIM_ICSELECTION_TRC: TIM Input 4 is selected to be connected to TRC.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5240 * @param TIM_ICFilter : Specifies the Input Capture Filter.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5241 * This parameter must be a value between 0x00 and 0x0F.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5242 * @note TIM_ICFilter and TIM_ICPolarity are not used in INDIRECT mode as TI4FP3
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5243 * (on channel1 path) is used as the input signal. Therefore CCMR2 must be
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5244 * protected against un-initialized filter and polarity values.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5245 * @retval None
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5246 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5247 static void TIM_TI4_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5248 uint32_t TIM_ICFilter)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5249 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5250 uint32_t tmpccmr2 = 0;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5251 uint32_t tmpccer = 0;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5252
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5253 /* Disable the Channel 4: Reset the CC4E Bit */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5254 TIMx->CCER &= ~TIM_CCER_CC4E;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5255 tmpccmr2 = TIMx->CCMR2;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5256 tmpccer = TIMx->CCER;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5257
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5258 /* Select the Input */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5259 tmpccmr2 &= ~TIM_CCMR2_CC4S;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5260 tmpccmr2 |= (TIM_ICSelection << 8);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5261
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5262 /* Set the filter */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5263 tmpccmr2 &= ~TIM_CCMR2_IC4F;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5264 tmpccmr2 |= ((TIM_ICFilter << 12) & TIM_CCMR2_IC4F);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5265
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5266 /* Select the Polarity and set the CC4E Bit */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5267 tmpccer &= ~(TIM_CCER_CC4P | TIM_CCER_CC4NP);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5268 tmpccer |= ((TIM_ICPolarity << 12) & (TIM_CCER_CC4P | TIM_CCER_CC4NP));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5269
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5270 /* Write to TIMx CCMR2 and CCER registers */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5271 TIMx->CCMR2 = tmpccmr2;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5272 TIMx->CCER = tmpccer ;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5273 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5274
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5275 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5276 * @brief Selects the Input Trigger source
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5277 * @param TIMx to select the TIM peripheral
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5278 * @param InputTriggerSource : The Input Trigger source.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5279 * This parameter can be one of the following values:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5280 * @arg TIM_TS_ITR0 : Internal Trigger 0
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5281 * @arg TIM_TS_ITR1 : Internal Trigger 1
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5282 * @arg TIM_TS_ITR2 : Internal Trigger 2
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5283 * @arg TIM_TS_ITR3 : Internal Trigger 3
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5284 * @arg TIM_TS_TI1F_ED : TI1 Edge Detector
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5285 * @arg TIM_TS_TI1FP1 : Filtered Timer Input 1
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5286 * @arg TIM_TS_TI2FP2 : Filtered Timer Input 2
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5287 * @arg TIM_TS_ETRF : External Trigger input
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5288 * @retval None
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5289 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5290 static void TIM_ITRx_SetConfig(TIM_TypeDef *TIMx, uint16_t InputTriggerSource)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5291 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5292 uint32_t tmpsmcr = 0;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5293
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5294 /* Get the TIMx SMCR register value */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5295 tmpsmcr = TIMx->SMCR;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5296 /* Reset the TS Bits */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5297 tmpsmcr &= ~TIM_SMCR_TS;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5298 /* Set the Input Trigger source and the slave mode*/
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5299 tmpsmcr |= InputTriggerSource | TIM_SLAVEMODE_EXTERNAL1;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5300 /* Write to TIMx SMCR */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5301 TIMx->SMCR = tmpsmcr;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5302 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5303 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5304 * @brief Configures the TIMx External Trigger (ETR).
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5305 * @param TIMx to select the TIM peripheral
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5306 * @param TIM_ExtTRGPrescaler : The external Trigger Prescaler.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5307 * This parameter can be one of the following values:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5308 * @arg TIM_ETRPRESCALER_DIV1: ETRP Prescaler OFF.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5309 * @arg TIM_ETRPRESCALER_DIV2: ETRP frequency divided by 2.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5310 * @arg TIM_ETRPRESCALER_DIV4: ETRP frequency divided by 4.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5311 * @arg TIM_ETRPRESCALER_DIV8: ETRP frequency divided by 8.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5312 * @param TIM_ExtTRGPolarity : The external Trigger Polarity.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5313 * This parameter can be one of the following values:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5314 * @arg TIM_ETRPOLARITY_INVERTED: active low or falling edge active.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5315 * @arg TIM_ETRPOLARITY_NONINVERTED: active high or rising edge active.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5316 * @param ExtTRGFilter : External Trigger Filter.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5317 * This parameter must be a value between 0x00 and 0x0F
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5318 * @retval None
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5319 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5320 static void TIM_ETR_SetConfig(TIM_TypeDef* TIMx, uint32_t TIM_ExtTRGPrescaler,
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5321 uint32_t TIM_ExtTRGPolarity, uint32_t ExtTRGFilter)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5322 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5323 uint32_t tmpsmcr = 0;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5324
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5325 tmpsmcr = TIMx->SMCR;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5326
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5327 /* Reset the ETR Bits */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5328 tmpsmcr &= ~(TIM_SMCR_ETF | TIM_SMCR_ETPS | TIM_SMCR_ECE | TIM_SMCR_ETP);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5329
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5330 /* Set the Prescaler, the Filter value and the Polarity */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5331 tmpsmcr |= (uint32_t)(TIM_ExtTRGPrescaler | (TIM_ExtTRGPolarity | (ExtTRGFilter << 8)));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5332
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5333 /* Write to TIMx SMCR */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5334 TIMx->SMCR = tmpsmcr;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5335 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5336
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5337 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5338 * @brief Enables or disables the TIM Capture Compare Channel x.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5339 * @param TIMx to select the TIM peripheral
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5340 * @param Channel : specifies the TIM Channel
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5341 * This parameter can be one of the following values:
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5342 * @arg TIM_CHANNEL_1: TIM Channel 1
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5343 * @arg TIM_CHANNEL_2: TIM Channel 2
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5344 * @arg TIM_CHANNEL_3: TIM Channel 3
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5345 * @arg TIM_CHANNEL_4: TIM Channel 4
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5346 * @param ChannelState : specifies the TIM Channel CCxE bit new state.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5347 * This parameter can be: TIM_CCx_ENABLE or TIM_CCx_Disable.
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5348 * @retval None
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5349 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5350 void TIM_CCxChannelCmd(TIM_TypeDef* TIMx, uint32_t Channel, uint32_t ChannelState)
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5351 {
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5352 uint32_t tmp = 0;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5353
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5354 /* Check the parameters */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5355 assert_param(IS_TIM_CC1_INSTANCE(TIMx));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5356 assert_param(IS_TIM_CHANNELS(Channel));
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5357
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5358 tmp = TIM_CCER_CC1E << Channel;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5359
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5360 /* Reset the CCxE Bit */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5361 TIMx->CCER &= ~tmp;
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5362
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5363 /* Set or reset the CCxE Bit */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5364 TIMx->CCER |= (uint32_t)(ChannelState << Channel);
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5365 }
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5366
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5367 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5368 * @}
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5369 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5370
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5371 #endif /* HAL_TIM_MODULE_ENABLED */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5372 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5373 * @}
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5374 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5375
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5376 /**
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5377 * @}
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5378 */
0c59e7a7782a Working on GPIO and RCC
cin
parents:
diff changeset
5379 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/