Rev 2 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2 | Rev 9 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | /** |
1 | /** |
2 | ****************************************************************************** |
2 | ****************************************************************************** |
3 | * @file stm32f1xx_hal_tim.c |
3 | * @file stm32f1xx_hal_tim.c |
4 | * @author MCD Application Team |
4 | * @author MCD Application Team |
5 | * @brief TIM HAL module driver |
5 | * @brief TIM HAL module driver. |
6 | * This file provides firmware functions to manage the following |
6 | * This file provides firmware functions to manage the following |
7 | * functionalities of the Timer (TIM) peripheral: |
7 | * functionalities of the Timer (TIM) peripheral: |
8 | * + Time Base Initialization |
8 | * + TIM Time Base Initialization |
9 | * + Time Base Start |
9 | * + TIM Time Base Start |
10 | * + Time Base Start Interruption |
10 | * + TIM Time Base Start Interruption |
11 | * + Time Base Start DMA |
11 | * + TIM Time Base Start DMA |
12 | * + Time Output Compare/PWM Initialization |
12 | * + TIM Output Compare/PWM Initialization |
13 | * + Time Output Compare/PWM Channel Configuration |
13 | * + TIM Output Compare/PWM Channel Configuration |
14 | * + Time Output Compare/PWM Start |
14 | * + TIM Output Compare/PWM Start |
15 | * + Time Output Compare/PWM Start Interruption |
15 | * + TIM Output Compare/PWM Start Interruption |
16 | * + Time Output Compare/PWM Start DMA |
16 | * + TIM Output Compare/PWM Start DMA |
17 | * + Time Input Capture Initialization |
17 | * + TIM Input Capture Initialization |
18 | * + Time Input Capture Channel Configuration |
18 | * + TIM Input Capture Channel Configuration |
19 | * + Time Input Capture Start |
19 | * + TIM Input Capture Start |
20 | * + Time Input Capture Start Interruption |
20 | * + TIM Input Capture Start Interruption |
21 | * + Time Input Capture Start DMA |
21 | * + TIM Input Capture Start DMA |
22 | * + Time One Pulse Initialization |
22 | * + TIM One Pulse Initialization |
23 | * + Time One Pulse Channel Configuration |
23 | * + TIM One Pulse Channel Configuration |
24 | * + Time One Pulse Start |
24 | * + TIM One Pulse Start |
25 | * + Time Encoder Interface Initialization |
25 | * + TIM Encoder Interface Initialization |
26 | * + Time Encoder Interface Start |
26 | * + TIM Encoder Interface Start |
27 | * + Time Encoder Interface Start Interruption |
27 | * + TIM Encoder Interface Start Interruption |
28 | * + Time Encoder Interface Start DMA |
28 | * + TIM Encoder Interface Start DMA |
29 | * + Commutation Event configuration with Interruption and DMA |
29 | * + Commutation Event configuration with Interruption and DMA |
30 | * + Time OCRef clear configuration |
30 | * + TIM OCRef clear configuration |
31 | * + Time External Clock configuration |
31 | * + TIM External Clock configuration |
32 | @verbatim |
32 | @verbatim |
33 | ============================================================================== |
33 | ============================================================================== |
34 | ##### TIMER Generic features ##### |
34 | ##### TIMER Generic features ##### |
35 | ============================================================================== |
35 | ============================================================================== |
36 | [..] The Timer features include: |
36 | [..] The Timer features include: |
37 | (#) 16-bit up, down, up/down auto-reload counter. |
37 | (#) 16-bit up, down, up/down auto-reload counter. |
38 | (#) 16-bit programmable prescaler allowing dividing (also on the fly) the |
38 | (#) 16-bit programmable prescaler allowing dividing (also on the fly) the |
39 | counter clock frequency either by any factor between 1 and 65536. |
39 | counter clock frequency either by any factor between 1 and 65536. |
40 | (#) Up to 4 independent channels for: |
40 | (#) Up to 4 independent channels for: |
41 | (++) Input Capture |
41 | (++) Input Capture |
42 | (++) Output Compare |
42 | (++) Output Compare |
43 | (++) PWM generation (Edge and Center-aligned Mode) |
43 | (++) PWM generation (Edge and Center-aligned Mode) |
44 | (++) One-pulse mode output |
44 | (++) One-pulse mode output |
- | 45 | (#) Synchronization circuit to control the timer with external signals and to interconnect |
|
- | 46 | several timers together. |
|
- | 47 | (#) Supports incremental encoder for positioning purposes |
|
45 | 48 | ||
46 | ##### How to use this driver ##### |
49 | ##### How to use this driver ##### |
47 | ============================================================================== |
50 | ============================================================================== |
48 | [..] |
51 | [..] |
49 | (#) Initialize the TIM low level resources by implementing the following functions |
52 | (#) Initialize the TIM low level resources by implementing the following functions |
50 | depending from feature used : |
53 | depending on the selected feature: |
51 | (++) Time Base : HAL_TIM_Base_MspInit() |
54 | (++) Time Base : HAL_TIM_Base_MspInit() |
52 | (++) Input Capture : HAL_TIM_IC_MspInit() |
55 | (++) Input Capture : HAL_TIM_IC_MspInit() |
53 | (++) Output Compare : HAL_TIM_OC_MspInit() |
56 | (++) Output Compare : HAL_TIM_OC_MspInit() |
54 | (++) PWM generation : HAL_TIM_PWM_MspInit() |
57 | (++) PWM generation : HAL_TIM_PWM_MspInit() |
55 | (++) One-pulse mode output : HAL_TIM_OnePulse_MspInit() |
58 | (++) One-pulse mode output : HAL_TIM_OnePulse_MspInit() |
Line 60... | Line 63... | ||
60 | (##) TIM pins configuration |
63 | (##) TIM pins configuration |
61 | (+++) Enable the clock for the TIM GPIOs using the following function: |
64 | (+++) Enable the clock for the TIM GPIOs using the following function: |
62 | __HAL_RCC_GPIOx_CLK_ENABLE(); |
65 | __HAL_RCC_GPIOx_CLK_ENABLE(); |
63 | (+++) Configure these TIM pins in Alternate function mode using HAL_GPIO_Init(); |
66 | (+++) Configure these TIM pins in Alternate function mode using HAL_GPIO_Init(); |
64 | 67 | ||
65 | (#) The external Clock can be configured, if needed (the default clock is the |
68 | (#) The external Clock can be configured, if needed (the default clock is the |
66 | internal clock from the APBx), using the following function: |
69 | internal clock from the APBx), using the following function: |
67 | HAL_TIM_ConfigClockSource, the clock configuration should be done before |
70 | HAL_TIM_ConfigClockSource, the clock configuration should be done before |
68 | any start function. |
71 | any start function. |
69 | 72 | ||
70 | (#) Configure the TIM in the desired functioning mode using one of the |
73 | (#) Configure the TIM in the desired functioning mode using one of the |
71 | Initialization function of this driver: |
74 | Initialization function of this driver: |
72 | (++) HAL_TIM_Base_Init: to use the Timer to generate a simple time base |
75 | (++) HAL_TIM_Base_Init: to use the Timer to generate a simple time base |
73 | (++) HAL_TIM_OC_Init and HAL_TIM_OC_ConfigChannel: to use the Timer to generate an |
76 | (++) HAL_TIM_OC_Init and HAL_TIM_OC_ConfigChannel: to use the Timer to generate an |
74 | Output Compare signal. |
77 | Output Compare signal. |
75 | (++) HAL_TIM_PWM_Init and HAL_TIM_PWM_ConfigChannel: to use the Timer to generate a |
78 | (++) HAL_TIM_PWM_Init and HAL_TIM_PWM_ConfigChannel: to use the Timer to generate a |
76 | PWM signal. |
79 | PWM signal. |
77 | (++) HAL_TIM_IC_Init and HAL_TIM_IC_ConfigChannel: to use the Timer to measure an |
80 | (++) HAL_TIM_IC_Init and HAL_TIM_IC_ConfigChannel: to use the Timer to measure an |
78 | external signal. |
81 | external signal. |
79 | (++) HAL_TIM_OnePulse_Init and HAL_TIM_OnePulse_ConfigChannel: to use the Timer |
82 | (++) HAL_TIM_OnePulse_Init and HAL_TIM_OnePulse_ConfigChannel: to use the Timer |
80 | in One Pulse Mode. |
83 | in One Pulse Mode. |
81 | (++) HAL_TIM_Encoder_Init: to use the Timer Encoder Interface. |
84 | (++) HAL_TIM_Encoder_Init: to use the Timer Encoder Interface. |
82 | 85 | ||
83 | (#) Activate the TIM peripheral using one of the start functions depending from the feature used: |
86 | (#) Activate the TIM peripheral using one of the start functions depending from the feature used: |
84 | (++) Time Base : HAL_TIM_Base_Start(), HAL_TIM_Base_Start_DMA(), HAL_TIM_Base_Start_IT() |
87 | (++) Time Base : HAL_TIM_Base_Start(), HAL_TIM_Base_Start_DMA(), HAL_TIM_Base_Start_IT() |
85 | (++) Input Capture : HAL_TIM_IC_Start(), HAL_TIM_IC_Start_DMA(), HAL_TIM_IC_Start_IT() |
88 | (++) Input Capture : HAL_TIM_IC_Start(), HAL_TIM_IC_Start_DMA(), HAL_TIM_IC_Start_IT() |
Line 90... | Line 93... | ||
90 | 93 | ||
91 | (#) The DMA Burst is managed with the two following functions: |
94 | (#) The DMA Burst is managed with the two following functions: |
92 | HAL_TIM_DMABurst_WriteStart() |
95 | HAL_TIM_DMABurst_WriteStart() |
93 | HAL_TIM_DMABurst_ReadStart() |
96 | HAL_TIM_DMABurst_ReadStart() |
94 | 97 | ||
- | 98 | *** Callback registration *** |
|
- | 99 | ============================================= |
|
- | 100 | ||
- | 101 | [..] |
|
- | 102 | The compilation define USE_HAL_TIM_REGISTER_CALLBACKS when set to 1 |
|
- | 103 | allows the user to configure dynamically the driver callbacks. |
|
- | 104 | ||
- | 105 | [..] |
|
- | 106 | Use Function @ref HAL_TIM_RegisterCallback() to register a callback. |
|
- | 107 | @ref HAL_TIM_RegisterCallback() takes as parameters the HAL peripheral handle, |
|
- | 108 | the Callback ID and a pointer to the user callback function. |
|
- | 109 | ||
- | 110 | [..] |
|
- | 111 | Use function @ref HAL_TIM_UnRegisterCallback() to reset a callback to the default |
|
- | 112 | weak function. |
|
- | 113 | @ref HAL_TIM_UnRegisterCallback takes as parameters the HAL peripheral handle, |
|
- | 114 | and the Callback ID. |
|
- | 115 | ||
- | 116 | [..] |
|
- | 117 | These functions allow to register/unregister following callbacks: |
|
- | 118 | (+) Base_MspInitCallback : TIM Base Msp Init Callback. |
|
- | 119 | (+) Base_MspDeInitCallback : TIM Base Msp DeInit Callback. |
|
- | 120 | (+) IC_MspInitCallback : TIM IC Msp Init Callback. |
|
- | 121 | (+) IC_MspDeInitCallback : TIM IC Msp DeInit Callback. |
|
- | 122 | (+) OC_MspInitCallback : TIM OC Msp Init Callback. |
|
- | 123 | (+) OC_MspDeInitCallback : TIM OC Msp DeInit Callback. |
|
- | 124 | (+) PWM_MspInitCallback : TIM PWM Msp Init Callback. |
|
- | 125 | (+) PWM_MspDeInitCallback : TIM PWM Msp DeInit Callback. |
|
- | 126 | (+) OnePulse_MspInitCallback : TIM One Pulse Msp Init Callback. |
|
- | 127 | (+) OnePulse_MspDeInitCallback : TIM One Pulse Msp DeInit Callback. |
|
- | 128 | (+) Encoder_MspInitCallback : TIM Encoder Msp Init Callback. |
|
- | 129 | (+) Encoder_MspDeInitCallback : TIM Encoder Msp DeInit Callback. |
|
- | 130 | (+) HallSensor_MspInitCallback : TIM Hall Sensor Msp Init Callback. |
|
- | 131 | (+) HallSensor_MspDeInitCallback : TIM Hall Sensor Msp DeInit Callback. |
|
- | 132 | (+) PeriodElapsedCallback : TIM Period Elapsed Callback. |
|
- | 133 | (+) PeriodElapsedHalfCpltCallback : TIM Period Elapsed half complete Callback. |
|
- | 134 | (+) TriggerCallback : TIM Trigger Callback. |
|
- | 135 | (+) TriggerHalfCpltCallback : TIM Trigger half complete Callback. |
|
- | 136 | (+) IC_CaptureCallback : TIM Input Capture Callback. |
|
- | 137 | (+) IC_CaptureHalfCpltCallback : TIM Input Capture half complete Callback. |
|
- | 138 | (+) OC_DelayElapsedCallback : TIM Output Compare Delay Elapsed Callback. |
|
- | 139 | (+) PWM_PulseFinishedCallback : TIM PWM Pulse Finished Callback. |
|
- | 140 | (+) PWM_PulseFinishedHalfCpltCallback : TIM PWM Pulse Finished half complete Callback. |
|
- | 141 | (+) ErrorCallback : TIM Error Callback. |
|
- | 142 | (+) CommutationCallback : TIM Commutation Callback. |
|
- | 143 | (+) CommutationHalfCpltCallback : TIM Commutation half complete Callback. |
|
- | 144 | (+) BreakCallback : TIM Break Callback. |
|
- | 145 | ||
- | 146 | [..] |
|
- | 147 | By default, after the Init and when the state is HAL_TIM_STATE_RESET |
|
- | 148 | all interrupt callbacks are set to the corresponding weak functions: |
|
- | 149 | examples @ref HAL_TIM_TriggerCallback(), @ref HAL_TIM_ErrorCallback(). |
|
- | 150 | ||
- | 151 | [..] |
|
- | 152 | Exception done for MspInit and MspDeInit functions that are reset to the legacy weak |
|
- | 153 | functionalities in the Init / DeInit only when these callbacks are null |
|
- | 154 | (not registered beforehand). If not, MspInit or MspDeInit are not null, the Init / DeInit |
|
- | 155 | keep and use the user MspInit / MspDeInit callbacks(registered beforehand) |
|
- | 156 | ||
- | 157 | [..] |
|
- | 158 | Callbacks can be registered / unregistered in HAL_TIM_STATE_READY state only. |
|
- | 159 | Exception done MspInit / MspDeInit that can be registered / unregistered |
|
- | 160 | in HAL_TIM_STATE_READY or HAL_TIM_STATE_RESET state, |
|
- | 161 | thus registered(user) MspInit / DeInit callbacks can be used during the Init / DeInit. |
|
- | 162 | In that case first register the MspInit/MspDeInit user callbacks |
|
- | 163 | using @ref HAL_TIM_RegisterCallback() before calling DeInit or Init function. |
|
- | 164 | ||
- | 165 | [..] |
|
- | 166 | When The compilation define USE_HAL_TIM_REGISTER_CALLBACKS is set to 0 or |
|
- | 167 | not defined, the callback registration feature is not available and all callbacks |
|
- | 168 | are set to the corresponding weak functions. |
|
- | 169 | ||
95 | @endverbatim |
170 | @endverbatim |
96 | ****************************************************************************** |
171 | ****************************************************************************** |
97 | * @attention |
172 | * @attention |
98 | * |
173 | * |
99 | * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> |
174 | * <h2><center>© Copyright (c) 2016 STMicroelectronics. |
100 | * |
- | |
101 | * Redistribution and use in source and binary forms, with or without modification, |
- | |
102 | * are permitted provided that the following conditions are met: |
- | |
103 | * 1. Redistributions of source code must retain the above copyright notice, |
- | |
104 | * this list of conditions and the following disclaimer. |
- | |
105 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
- | |
106 | * this list of conditions and the following disclaimer in the documentation |
- | |
107 | * and/or other materials provided with the distribution. |
- | |
108 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
- | |
109 | * may be used to endorse or promote products derived from this software |
- | |
110 | * without specific prior written permission. |
175 | * All rights reserved.</center></h2> |
111 | * |
176 | * |
112 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
177 | * This software component is licensed by ST under BSD 3-Clause license, |
113 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
- | |
114 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
- | |
115 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
- | |
116 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
- | |
117 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
178 | * the "License"; You may not use this file except in compliance with the |
118 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
179 | * License. You may obtain a copy of the License at: |
119 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
- | |
120 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
- | |
121 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
180 | * opensource.org/licenses/BSD-3-Clause |
122 | * |
181 | * |
123 | ****************************************************************************** |
182 | ****************************************************************************** |
124 | */ |
183 | */ |
125 | 184 | ||
126 | /* Includes ------------------------------------------------------------------*/ |
185 | /* Includes ------------------------------------------------------------------*/ |
Line 137... | Line 196... | ||
137 | 196 | ||
138 | #ifdef HAL_TIM_MODULE_ENABLED |
197 | #ifdef HAL_TIM_MODULE_ENABLED |
139 | 198 | ||
140 | /* Private typedef -----------------------------------------------------------*/ |
199 | /* Private typedef -----------------------------------------------------------*/ |
141 | /* Private define ------------------------------------------------------------*/ |
200 | /* Private define ------------------------------------------------------------*/ |
142 | /* Private macro -------------------------------------------------------------*/ |
201 | /* Private macros ------------------------------------------------------------*/ |
143 | /* Private variables ---------------------------------------------------------*/ |
202 | /* Private variables ---------------------------------------------------------*/ |
144 | /* Private function prototypes -----------------------------------------------*/ |
203 | /* Private function prototypes -----------------------------------------------*/ |
145 | /** @defgroup TIM_Private_Functions TIM Private Functions |
204 | /** @addtogroup TIM_Private_Functions |
146 | * @{ |
205 | * @{ |
147 | */ |
206 | */ |
148 | static void TIM_OC1_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config); |
207 | static void TIM_OC1_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config); |
149 | static void TIM_OC3_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config); |
208 | static void TIM_OC3_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config); |
150 | static void TIM_OC4_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config); |
209 | static void TIM_OC4_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config); |
151 | static void TIM_TI1_ConfigInputStage(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICFilter); |
210 | static void TIM_TI1_ConfigInputStage(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICFilter); |
152 | static void TIM_TI2_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection, |
211 | static void TIM_TI2_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection, |
153 | uint32_t TIM_ICFilter); |
212 | uint32_t TIM_ICFilter); |
154 | static void TIM_TI2_ConfigInputStage(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICFilter); |
213 | static void TIM_TI2_ConfigInputStage(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICFilter); |
155 | static void TIM_TI3_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection, |
214 | static void TIM_TI3_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection, |
156 | uint32_t TIM_ICFilter); |
215 | uint32_t TIM_ICFilter); |
157 | static void TIM_TI4_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection, |
216 | static void TIM_TI4_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection, |
158 | uint32_t TIM_ICFilter); |
217 | uint32_t TIM_ICFilter); |
159 | static void TIM_ETR_SetConfig(TIM_TypeDef* TIMx, uint32_t TIM_ExtTRGPrescaler, |
- | |
160 | uint32_t TIM_ExtTRGPolarity, uint32_t ExtTRGFilter); |
- | |
161 | static void TIM_ITRx_SetConfig(TIM_TypeDef* TIMx, uint16_t InputTriggerSource); |
218 | static void TIM_ITRx_SetConfig(TIM_TypeDef *TIMx, uint32_t InputTriggerSource); |
162 | static void TIM_DMAPeriodElapsedCplt(DMA_HandleTypeDef *hdma); |
219 | static void TIM_DMAPeriodElapsedCplt(DMA_HandleTypeDef *hdma); |
- | 220 | static void TIM_DMAPeriodElapsedHalfCplt(DMA_HandleTypeDef *hdma); |
|
- | 221 | static void TIM_DMADelayPulseCplt(DMA_HandleTypeDef *hdma); |
|
163 | static void TIM_DMATriggerCplt(DMA_HandleTypeDef *hdma); |
222 | static void TIM_DMATriggerCplt(DMA_HandleTypeDef *hdma); |
- | 223 | static void TIM_DMATriggerHalfCplt(DMA_HandleTypeDef *hdma); |
|
164 | static void TIM_SlaveTimer_SetConfig(TIM_HandleTypeDef *htim, |
224 | static HAL_StatusTypeDef TIM_SlaveTimer_SetConfig(TIM_HandleTypeDef *htim, |
165 | TIM_SlaveConfigTypeDef * sSlaveConfig); |
225 | TIM_SlaveConfigTypeDef *sSlaveConfig); |
166 | - | ||
167 | /** |
226 | /** |
168 | * @} |
227 | * @} |
169 | */ |
228 | */ |
170 | - | ||
171 | /* Exported functions ---------------------------------------------------------*/ |
229 | /* Exported functions --------------------------------------------------------*/ |
172 | 230 | ||
173 | /** @defgroup TIM_Exported_Functions TIM Exported Functions |
231 | /** @defgroup TIM_Exported_Functions TIM Exported Functions |
174 | * @{ |
232 | * @{ |
175 | */ |
233 | */ |
176 | 234 | ||
177 | /** @defgroup TIM_Exported_Functions_Group1 Time Base functions |
235 | /** @defgroup TIM_Exported_Functions_Group1 TIM Time Base functions |
178 | * @brief Time Base functions |
236 | * @brief Time Base functions |
179 | * |
237 | * |
180 | @verbatim |
238 | @verbatim |
181 | ============================================================================== |
239 | ============================================================================== |
182 | ##### Time Base functions ##### |
240 | ##### Time Base functions ##### |
183 | ============================================================================== |
241 | ============================================================================== |
184 | [..] |
242 | [..] |
185 | This section provides functions allowing to: |
243 | This section provides functions allowing to: |
Line 195... | Line 253... | ||
195 | @endverbatim |
253 | @endverbatim |
196 | * @{ |
254 | * @{ |
197 | */ |
255 | */ |
198 | /** |
256 | /** |
199 | * @brief Initializes the TIM Time base Unit according to the specified |
257 | * @brief Initializes the TIM Time base Unit according to the specified |
200 | * parameters in the TIM_HandleTypeDef and create the associated handle. |
258 | * parameters in the TIM_HandleTypeDef and initialize the associated handle. |
201 | * @note Switching from Center Aligned counter mode to Edge counter mode (or reverse) |
259 | * @note Switching from Center Aligned counter mode to Edge counter mode (or reverse) |
202 | * requires a timer reset to avoid unexpected direction |
260 | * requires a timer reset to avoid unexpected direction |
203 | * due to DIR bit readonly in center aligned mode. |
261 | * due to DIR bit readonly in center aligned mode. |
204 | * Ex: call @ref HAL_TIM_Base_DeInit() before HAL_TIM_Base_Init() |
262 | * Ex: call @ref HAL_TIM_Base_DeInit() before HAL_TIM_Base_Init() |
205 | * @param htim : TIM Base handle |
263 | * @param htim TIM Base handle |
206 | * @retval HAL status |
264 | * @retval HAL status |
207 | */ |
265 | */ |
208 | HAL_StatusTypeDef HAL_TIM_Base_Init(TIM_HandleTypeDef *htim) |
266 | HAL_StatusTypeDef HAL_TIM_Base_Init(TIM_HandleTypeDef *htim) |
209 | { |
267 | { |
210 | /* Check the TIM handle allocation */ |
268 | /* Check the TIM handle allocation */ |
211 | if(htim == NULL) |
269 | if (htim == NULL) |
212 | { |
270 | { |
213 | return HAL_ERROR; |
271 | return HAL_ERROR; |
214 | } |
272 | } |
215 | 273 | ||
216 | /* Check the parameters */ |
274 | /* Check the parameters */ |
217 | assert_param(IS_TIM_INSTANCE(htim->Instance)); |
275 | assert_param(IS_TIM_INSTANCE(htim->Instance)); |
218 | assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode)); |
276 | assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode)); |
219 | assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision)); |
277 | assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision)); |
220 | assert_param(IS_TIM_AUTORELOAD_PRELOAD(htim->Init.AutoReloadPreload)); |
278 | assert_param(IS_TIM_AUTORELOAD_PRELOAD(htim->Init.AutoReloadPreload)); |
221 | 279 | ||
222 | if(htim->State == HAL_TIM_STATE_RESET) |
280 | if (htim->State == HAL_TIM_STATE_RESET) |
223 | { |
281 | { |
224 | /* Allocate lock resource and initialize it */ |
282 | /* Allocate lock resource and initialize it */ |
225 | htim->Lock = HAL_UNLOCKED; |
283 | htim->Lock = HAL_UNLOCKED; |
- | 284 | ||
- | 285 | #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) |
|
- | 286 | /* Reset interrupt callbacks to legacy weak callbacks */ |
|
- | 287 | TIM_ResetCallback(htim); |
|
- | 288 | ||
- | 289 | if (htim->Base_MspInitCallback == NULL) |
|
226 | 290 | { |
|
- | 291 | htim->Base_MspInitCallback = HAL_TIM_Base_MspInit; |
|
- | 292 | } |
|
- | 293 | /* Init the low level hardware : GPIO, CLOCK, NVIC */ |
|
- | 294 | htim->Base_MspInitCallback(htim); |
|
- | 295 | #else |
|
227 | /* Init the low level hardware : GPIO, CLOCK, NVIC */ |
296 | /* Init the low level hardware : GPIO, CLOCK, NVIC */ |
228 | HAL_TIM_Base_MspInit(htim); |
297 | HAL_TIM_Base_MspInit(htim); |
- | 298 | #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */ |
|
229 | } |
299 | } |
230 | 300 | ||
231 | /* Set the TIM state */ |
301 | /* Set the TIM state */ |
232 | htim->State= HAL_TIM_STATE_BUSY; |
302 | htim->State = HAL_TIM_STATE_BUSY; |
233 | 303 | ||
234 | /* Set the Time Base configuration */ |
304 | /* Set the Time Base configuration */ |
235 | TIM_Base_SetConfig(htim->Instance, &htim->Init); |
305 | TIM_Base_SetConfig(htim->Instance, &htim->Init); |
236 | 306 | ||
- | 307 | /* Initialize the DMA burst operation state */ |
|
- | 308 | htim->DMABurstState = HAL_DMA_BURST_STATE_READY; |
|
- | 309 | ||
- | 310 | /* Initialize the TIM channels state */ |
|
- | 311 | TIM_CHANNEL_STATE_SET_ALL(htim, HAL_TIM_CHANNEL_STATE_READY); |
|
- | 312 | TIM_CHANNEL_N_STATE_SET_ALL(htim, HAL_TIM_CHANNEL_STATE_READY); |
|
- | 313 | ||
237 | /* Initialize the TIM state*/ |
314 | /* Initialize the TIM state*/ |
238 | htim->State= HAL_TIM_STATE_READY; |
315 | htim->State = HAL_TIM_STATE_READY; |
239 | 316 | ||
240 | return HAL_OK; |
317 | return HAL_OK; |
241 | } |
318 | } |
242 | 319 | ||
243 | /** |
320 | /** |
244 | * @brief DeInitializes the TIM Base peripheral |
321 | * @brief DeInitializes the TIM Base peripheral |
245 | * @param htim : TIM Base handle |
322 | * @param htim TIM Base handle |
246 | * @retval HAL status |
323 | * @retval HAL status |
247 | */ |
324 | */ |
248 | HAL_StatusTypeDef HAL_TIM_Base_DeInit(TIM_HandleTypeDef *htim) |
325 | HAL_StatusTypeDef HAL_TIM_Base_DeInit(TIM_HandleTypeDef *htim) |
249 | { |
326 | { |
250 | /* Check the parameters */ |
327 | /* Check the parameters */ |
Line 253... | Line 330... | ||
253 | htim->State = HAL_TIM_STATE_BUSY; |
330 | htim->State = HAL_TIM_STATE_BUSY; |
254 | 331 | ||
255 | /* Disable the TIM Peripheral Clock */ |
332 | /* Disable the TIM Peripheral Clock */ |
256 | __HAL_TIM_DISABLE(htim); |
333 | __HAL_TIM_DISABLE(htim); |
257 | 334 | ||
- | 335 | #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) |
|
- | 336 | if (htim->Base_MspDeInitCallback == NULL) |
|
- | 337 | { |
|
- | 338 | htim->Base_MspDeInitCallback = HAL_TIM_Base_MspDeInit; |
|
- | 339 | } |
|
- | 340 | /* DeInit the low level hardware */ |
|
- | 341 | htim->Base_MspDeInitCallback(htim); |
|
- | 342 | #else |
|
258 | /* DeInit the low level hardware: GPIO, CLOCK, NVIC */ |
343 | /* DeInit the low level hardware: GPIO, CLOCK, NVIC */ |
259 | HAL_TIM_Base_MspDeInit(htim); |
344 | HAL_TIM_Base_MspDeInit(htim); |
- | 345 | #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */ |
|
- | 346 | ||
- | 347 | /* Change the DMA burst operation state */ |
|
- | 348 | htim->DMABurstState = HAL_DMA_BURST_STATE_RESET; |
|
- | 349 | ||
- | 350 | /* Change the TIM channels state */ |
|
- | 351 | TIM_CHANNEL_STATE_SET_ALL(htim, HAL_TIM_CHANNEL_STATE_RESET); |
|
- | 352 | TIM_CHANNEL_N_STATE_SET_ALL(htim, HAL_TIM_CHANNEL_STATE_RESET); |
|
260 | 353 | ||
261 | /* Change TIM state */ |
354 | /* Change TIM state */ |
262 | htim->State = HAL_TIM_STATE_RESET; |
355 | htim->State = HAL_TIM_STATE_RESET; |
263 | 356 | ||
264 | /* Release Lock */ |
357 | /* Release Lock */ |
Line 267... | Line 360... | ||
267 | return HAL_OK; |
360 | return HAL_OK; |
268 | } |
361 | } |
269 | 362 | ||
270 | /** |
363 | /** |
271 | * @brief Initializes the TIM Base MSP. |
364 | * @brief Initializes the TIM Base MSP. |
272 | * @param htim : TIM handle |
365 | * @param htim TIM Base handle |
273 | * @retval None |
366 | * @retval None |
274 | */ |
367 | */ |
275 | __weak void HAL_TIM_Base_MspInit(TIM_HandleTypeDef *htim) |
368 | __weak void HAL_TIM_Base_MspInit(TIM_HandleTypeDef *htim) |
276 | { |
369 | { |
277 | /* Prevent unused argument(s) compilation warning */ |
370 | /* Prevent unused argument(s) compilation warning */ |
278 | UNUSED(htim); |
371 | UNUSED(htim); |
- | 372 | ||
279 | /* NOTE : This function Should not be modified, when the callback is needed, |
373 | /* NOTE : This function should not be modified, when the callback is needed, |
280 | the HAL_TIM_Base_MspInit could be implemented in the user file |
374 | the HAL_TIM_Base_MspInit could be implemented in the user file |
281 | */ |
375 | */ |
282 | } |
376 | } |
283 | 377 | ||
284 | /** |
378 | /** |
285 | * @brief DeInitializes TIM Base MSP. |
379 | * @brief DeInitializes TIM Base MSP. |
286 | * @param htim : TIM handle |
380 | * @param htim TIM Base handle |
287 | * @retval None |
381 | * @retval None |
288 | */ |
382 | */ |
289 | __weak void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef *htim) |
383 | __weak void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef *htim) |
290 | { |
384 | { |
291 | /* Prevent unused argument(s) compilation warning */ |
385 | /* Prevent unused argument(s) compilation warning */ |
292 | UNUSED(htim); |
386 | UNUSED(htim); |
- | 387 | ||
293 | /* NOTE : This function Should not be modified, when the callback is needed, |
388 | /* NOTE : This function should not be modified, when the callback is needed, |
294 | the HAL_TIM_Base_MspDeInit could be implemented in the user file |
389 | the HAL_TIM_Base_MspDeInit could be implemented in the user file |
295 | */ |
390 | */ |
296 | } |
391 | } |
297 | 392 | ||
298 | 393 | ||
299 | /** |
394 | /** |
300 | * @brief Starts the TIM Base generation. |
395 | * @brief Starts the TIM Base generation. |
301 | * @param htim : TIM handle |
396 | * @param htim TIM Base handle |
302 | * @retval HAL status |
397 | * @retval HAL status |
303 | */ |
398 | */ |
304 | HAL_StatusTypeDef HAL_TIM_Base_Start(TIM_HandleTypeDef *htim) |
399 | HAL_StatusTypeDef HAL_TIM_Base_Start(TIM_HandleTypeDef *htim) |
305 | { |
400 | { |
- | 401 | uint32_t tmpsmcr; |
|
- | 402 | ||
306 | /* Check the parameters */ |
403 | /* Check the parameters */ |
307 | assert_param(IS_TIM_INSTANCE(htim->Instance)); |
404 | assert_param(IS_TIM_INSTANCE(htim->Instance)); |
308 | 405 | ||
309 | /* Set the TIM state */ |
406 | /* Check the TIM state */ |
310 | htim->State= HAL_TIM_STATE_BUSY; |
407 | if (htim->State != HAL_TIM_STATE_READY) |
- | 408 | { |
|
- | 409 | return HAL_ERROR; |
|
- | 410 | } |
|
311 | 411 | ||
312 | /* Enable the Peripheral */ |
412 | /* Set the TIM state */ |
313 | __HAL_TIM_ENABLE(htim); |
413 | htim->State = HAL_TIM_STATE_BUSY; |
314 | 414 | ||
- | 415 | /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */ |
|
- | 416 | if (IS_TIM_SLAVE_INSTANCE(htim->Instance)) |
|
- | 417 | { |
|
- | 418 | tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS; |
|
- | 419 | if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr)) |
|
- | 420 | { |
|
315 | /* Change the TIM state*/ |
421 | __HAL_TIM_ENABLE(htim); |
- | 422 | } |
|
- | 423 | } |
|
- | 424 | else |
|
- | 425 | { |
|
316 | htim->State= HAL_TIM_STATE_READY; |
426 | __HAL_TIM_ENABLE(htim); |
- | 427 | } |
|
317 | 428 | ||
318 | /* Return function status */ |
429 | /* Return function status */ |
319 | return HAL_OK; |
430 | return HAL_OK; |
320 | } |
431 | } |
321 | 432 | ||
322 | /** |
433 | /** |
323 | * @brief Stops the TIM Base generation. |
434 | * @brief Stops the TIM Base generation. |
324 | * @param htim : TIM handle |
435 | * @param htim TIM Base handle |
325 | * @retval HAL status |
436 | * @retval HAL status |
326 | */ |
437 | */ |
327 | HAL_StatusTypeDef HAL_TIM_Base_Stop(TIM_HandleTypeDef *htim) |
438 | HAL_StatusTypeDef HAL_TIM_Base_Stop(TIM_HandleTypeDef *htim) |
328 | { |
439 | { |
329 | /* Check the parameters */ |
440 | /* Check the parameters */ |
330 | assert_param(IS_TIM_INSTANCE(htim->Instance)); |
441 | assert_param(IS_TIM_INSTANCE(htim->Instance)); |
331 | 442 | ||
332 | /* Set the TIM state */ |
- | |
333 | htim->State= HAL_TIM_STATE_BUSY; |
- | |
334 | - | ||
335 | /* Disable the Peripheral */ |
443 | /* Disable the Peripheral */ |
336 | __HAL_TIM_DISABLE(htim); |
444 | __HAL_TIM_DISABLE(htim); |
337 | 445 | ||
338 | /* Change the TIM state*/ |
446 | /* Set the TIM state */ |
339 | htim->State= HAL_TIM_STATE_READY; |
447 | htim->State = HAL_TIM_STATE_READY; |
340 | 448 | ||
341 | /* Return function status */ |
449 | /* Return function status */ |
342 | return HAL_OK; |
450 | return HAL_OK; |
343 | } |
451 | } |
344 | 452 | ||
345 | /** |
453 | /** |
346 | * @brief Starts the TIM Base generation in interrupt mode. |
454 | * @brief Starts the TIM Base generation in interrupt mode. |
347 | * @param htim : TIM handle |
455 | * @param htim TIM Base handle |
348 | * @retval HAL status |
456 | * @retval HAL status |
349 | */ |
457 | */ |
350 | HAL_StatusTypeDef HAL_TIM_Base_Start_IT(TIM_HandleTypeDef *htim) |
458 | HAL_StatusTypeDef HAL_TIM_Base_Start_IT(TIM_HandleTypeDef *htim) |
351 | { |
459 | { |
- | 460 | uint32_t tmpsmcr; |
|
- | 461 | ||
352 | /* Check the parameters */ |
462 | /* Check the parameters */ |
353 | assert_param(IS_TIM_INSTANCE(htim->Instance)); |
463 | assert_param(IS_TIM_INSTANCE(htim->Instance)); |
354 | 464 | ||
355 | /* Enable the TIM Update interrupt */ |
465 | /* Check the TIM state */ |
356 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_UPDATE); |
466 | if (htim->State != HAL_TIM_STATE_READY) |
- | 467 | { |
|
- | 468 | return HAL_ERROR; |
|
- | 469 | } |
|
357 | 470 | ||
- | 471 | /* Set the TIM state */ |
|
- | 472 | htim->State = HAL_TIM_STATE_BUSY; |
|
- | 473 | ||
358 | /* Enable the Peripheral */ |
474 | /* Enable the TIM Update interrupt */ |
- | 475 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_UPDATE); |
|
- | 476 | ||
- | 477 | /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */ |
|
- | 478 | if (IS_TIM_SLAVE_INSTANCE(htim->Instance)) |
|
- | 479 | { |
|
- | 480 | tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS; |
|
- | 481 | if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr)) |
|
- | 482 | { |
|
- | 483 | __HAL_TIM_ENABLE(htim); |
|
- | 484 | } |
|
- | 485 | } |
|
- | 486 | else |
|
- | 487 | { |
|
359 | __HAL_TIM_ENABLE(htim); |
488 | __HAL_TIM_ENABLE(htim); |
- | 489 | } |
|
360 | 490 | ||
361 | /* Return function status */ |
491 | /* Return function status */ |
362 | return HAL_OK; |
492 | return HAL_OK; |
363 | } |
493 | } |
364 | 494 | ||
365 | /** |
495 | /** |
366 | * @brief Stops the TIM Base generation in interrupt mode. |
496 | * @brief Stops the TIM Base generation in interrupt mode. |
367 | * @param htim : TIM handle |
497 | * @param htim TIM Base handle |
368 | * @retval HAL status |
498 | * @retval HAL status |
369 | */ |
499 | */ |
370 | HAL_StatusTypeDef HAL_TIM_Base_Stop_IT(TIM_HandleTypeDef *htim) |
500 | HAL_StatusTypeDef HAL_TIM_Base_Stop_IT(TIM_HandleTypeDef *htim) |
371 | { |
501 | { |
372 | /* Check the parameters */ |
502 | /* Check the parameters */ |
373 | assert_param(IS_TIM_INSTANCE(htim->Instance)); |
503 | assert_param(IS_TIM_INSTANCE(htim->Instance)); |
- | 504 | ||
374 | /* Disable the TIM Update interrupt */ |
505 | /* Disable the TIM Update interrupt */ |
375 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_UPDATE); |
506 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_UPDATE); |
376 | 507 | ||
377 | /* Disable the Peripheral */ |
508 | /* Disable the Peripheral */ |
378 | __HAL_TIM_DISABLE(htim); |
509 | __HAL_TIM_DISABLE(htim); |
379 | 510 | ||
- | 511 | /* Set the TIM state */ |
|
- | 512 | htim->State = HAL_TIM_STATE_READY; |
|
- | 513 | ||
380 | /* Return function status */ |
514 | /* Return function status */ |
381 | return HAL_OK; |
515 | return HAL_OK; |
382 | } |
516 | } |
383 | 517 | ||
384 | /** |
518 | /** |
385 | * @brief Starts the TIM Base generation in DMA mode. |
519 | * @brief Starts the TIM Base generation in DMA mode. |
386 | * @param htim : TIM handle |
520 | * @param htim TIM Base handle |
387 | * @param pData : The source Buffer address. |
521 | * @param pData The source Buffer address. |
388 | * @param Length : The length of data to be transferred from memory to peripheral. |
522 | * @param Length The length of data to be transferred from memory to peripheral. |
389 | * @retval HAL status |
523 | * @retval HAL status |
390 | */ |
524 | */ |
391 | HAL_StatusTypeDef HAL_TIM_Base_Start_DMA(TIM_HandleTypeDef *htim, uint32_t *pData, uint16_t Length) |
525 | HAL_StatusTypeDef HAL_TIM_Base_Start_DMA(TIM_HandleTypeDef *htim, uint32_t *pData, uint16_t Length) |
392 | { |
526 | { |
- | 527 | uint32_t tmpsmcr; |
|
- | 528 | ||
393 | /* Check the parameters */ |
529 | /* Check the parameters */ |
394 | assert_param(IS_TIM_DMA_INSTANCE(htim->Instance)); |
530 | assert_param(IS_TIM_DMA_INSTANCE(htim->Instance)); |
395 | 531 | ||
- | 532 | /* Set the TIM state */ |
|
396 | if((htim->State == HAL_TIM_STATE_BUSY)) |
533 | if (htim->State == HAL_TIM_STATE_BUSY) |
397 | { |
534 | { |
398 | return HAL_BUSY; |
535 | return HAL_BUSY; |
399 | } |
536 | } |
400 | else if((htim->State == HAL_TIM_STATE_READY)) |
537 | else if (htim->State == HAL_TIM_STATE_READY) |
401 | { |
538 | { |
402 | if((pData == 0U) && (Length > 0U)) |
539 | if ((pData == NULL) && (Length > 0U)) |
403 | { |
540 | { |
404 | return HAL_ERROR; |
541 | return HAL_ERROR; |
405 | } |
542 | } |
406 | else |
543 | else |
407 | { |
544 | { |
408 | htim->State = HAL_TIM_STATE_BUSY; |
545 | htim->State = HAL_TIM_STATE_BUSY; |
409 | } |
546 | } |
410 | } |
547 | } |
- | 548 | else |
|
- | 549 | { |
|
- | 550 | return HAL_ERROR; |
|
- | 551 | } |
|
- | 552 | ||
411 | /* Set the DMA Period elapsed callback */ |
553 | /* Set the DMA Period elapsed callbacks */ |
412 | htim->hdma[TIM_DMA_ID_UPDATE]->XferCpltCallback = TIM_DMAPeriodElapsedCplt; |
554 | htim->hdma[TIM_DMA_ID_UPDATE]->XferCpltCallback = TIM_DMAPeriodElapsedCplt; |
- | 555 | htim->hdma[TIM_DMA_ID_UPDATE]->XferHalfCpltCallback = TIM_DMAPeriodElapsedHalfCplt; |
|
413 | 556 | ||
414 | /* Set the DMA error callback */ |
557 | /* Set the DMA error callback */ |
415 | htim->hdma[TIM_DMA_ID_UPDATE]->XferErrorCallback = TIM_DMAError ; |
558 | htim->hdma[TIM_DMA_ID_UPDATE]->XferErrorCallback = TIM_DMAError ; |
416 | 559 | ||
417 | /* Enable the DMA channel */ |
560 | /* Enable the DMA channel */ |
418 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_UPDATE], (uint32_t)pData, (uint32_t)&htim->Instance->ARR, Length); |
561 | if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_UPDATE], (uint32_t)pData, (uint32_t)&htim->Instance->ARR, Length) != HAL_OK) |
- | 562 | { |
|
- | 563 | /* Return error status */ |
|
- | 564 | return HAL_ERROR; |
|
- | 565 | } |
|
419 | 566 | ||
420 | /* Enable the TIM Update DMA request */ |
567 | /* Enable the TIM Update DMA request */ |
421 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_UPDATE); |
568 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_UPDATE); |
422 | 569 | ||
- | 570 | /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */ |
|
- | 571 | if (IS_TIM_SLAVE_INSTANCE(htim->Instance)) |
|
- | 572 | { |
|
- | 573 | tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS; |
|
- | 574 | if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr)) |
|
- | 575 | { |
|
423 | /* Enable the Peripheral */ |
576 | __HAL_TIM_ENABLE(htim); |
- | 577 | } |
|
- | 578 | } |
|
- | 579 | else |
|
- | 580 | { |
|
424 | __HAL_TIM_ENABLE(htim); |
581 | __HAL_TIM_ENABLE(htim); |
- | 582 | } |
|
425 | 583 | ||
426 | /* Return function status */ |
584 | /* Return function status */ |
427 | return HAL_OK; |
585 | return HAL_OK; |
428 | } |
586 | } |
429 | 587 | ||
430 | /** |
588 | /** |
431 | * @brief Stops the TIM Base generation in DMA mode. |
589 | * @brief Stops the TIM Base generation in DMA mode. |
432 | * @param htim : TIM handle |
590 | * @param htim TIM Base handle |
433 | * @retval HAL status |
591 | * @retval HAL status |
434 | */ |
592 | */ |
435 | HAL_StatusTypeDef HAL_TIM_Base_Stop_DMA(TIM_HandleTypeDef *htim) |
593 | HAL_StatusTypeDef HAL_TIM_Base_Stop_DMA(TIM_HandleTypeDef *htim) |
436 | { |
594 | { |
437 | /* Check the parameters */ |
595 | /* Check the parameters */ |
438 | assert_param(IS_TIM_DMA_INSTANCE(htim->Instance)); |
596 | assert_param(IS_TIM_DMA_INSTANCE(htim->Instance)); |
439 | 597 | ||
440 | /* Disable the TIM Update DMA request */ |
598 | /* Disable the TIM Update DMA request */ |
441 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_UPDATE); |
599 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_UPDATE); |
442 | 600 | ||
- | 601 | (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_UPDATE]); |
|
- | 602 | ||
443 | /* Disable the Peripheral */ |
603 | /* Disable the Peripheral */ |
444 | __HAL_TIM_DISABLE(htim); |
604 | __HAL_TIM_DISABLE(htim); |
445 | 605 | ||
446 | /* Change the htim state */ |
606 | /* Set the TIM state */ |
447 | htim->State = HAL_TIM_STATE_READY; |
607 | htim->State = HAL_TIM_STATE_READY; |
448 | 608 | ||
449 | /* Return function status */ |
609 | /* Return function status */ |
450 | return HAL_OK; |
610 | return HAL_OK; |
451 | } |
611 | } |
452 | 612 | ||
453 | /** |
613 | /** |
454 | * @} |
614 | * @} |
455 | */ |
615 | */ |
456 | 616 | ||
457 | /** @defgroup TIM_Exported_Functions_Group2 Time Output Compare functions |
617 | /** @defgroup TIM_Exported_Functions_Group2 TIM Output Compare functions |
458 | * @brief Time Output Compare functions |
618 | * @brief TIM Output Compare functions |
459 | * |
619 | * |
460 | @verbatim |
620 | @verbatim |
461 | ============================================================================== |
621 | ============================================================================== |
462 | ##### Time Output Compare functions ##### |
622 | ##### TIM Output Compare functions ##### |
463 | ============================================================================== |
623 | ============================================================================== |
464 | [..] |
624 | [..] |
465 | This section provides functions allowing to: |
625 | This section provides functions allowing to: |
466 | (+) Initialize and configure the TIM Output Compare. |
626 | (+) Initialize and configure the TIM Output Compare. |
467 | (+) De-initialize the TIM Output Compare. |
627 | (+) De-initialize the TIM Output Compare. |
468 | (+) Start the Time Output Compare. |
628 | (+) Start the TIM Output Compare. |
469 | (+) Stop the Time Output Compare. |
629 | (+) Stop the TIM Output Compare. |
470 | (+) Start the Time Output Compare and enable interrupt. |
630 | (+) Start the TIM Output Compare and enable interrupt. |
471 | (+) Stop the Time Output Compare and disable interrupt. |
631 | (+) Stop the TIM Output Compare and disable interrupt. |
472 | (+) Start the Time Output Compare and enable DMA transfer. |
632 | (+) Start the TIM Output Compare and enable DMA transfer. |
473 | (+) Stop the Time Output Compare and disable DMA transfer. |
633 | (+) Stop the TIM Output Compare and disable DMA transfer. |
474 | 634 | ||
475 | @endverbatim |
635 | @endverbatim |
476 | * @{ |
636 | * @{ |
477 | */ |
637 | */ |
478 | /** |
638 | /** |
479 | * @brief Initializes the TIM Output Compare according to the specified |
639 | * @brief Initializes the TIM Output Compare according to the specified |
480 | * parameters in the TIM_HandleTypeDef and create the associated handle. |
640 | * parameters in the TIM_HandleTypeDef and initializes the associated handle. |
481 | * @note Switching from Center Aligned counter mode to Edge counter mode (or reverse) |
641 | * @note Switching from Center Aligned counter mode to Edge counter mode (or reverse) |
482 | * requires a timer reset to avoid unexpected direction |
642 | * requires a timer reset to avoid unexpected direction |
483 | * due to DIR bit readonly in center aligned mode. |
643 | * due to DIR bit readonly in center aligned mode. |
484 | * Ex: call @ref HAL_TIM_OC_DeInit() before HAL_TIM_OC_Init() |
644 | * Ex: call @ref HAL_TIM_OC_DeInit() before HAL_TIM_OC_Init() |
485 | * @param htim : TIM Output Compare handle |
645 | * @param htim TIM Output Compare handle |
486 | * @retval HAL status |
646 | * @retval HAL status |
487 | */ |
647 | */ |
488 | HAL_StatusTypeDef HAL_TIM_OC_Init(TIM_HandleTypeDef* htim) |
648 | HAL_StatusTypeDef HAL_TIM_OC_Init(TIM_HandleTypeDef *htim) |
489 | { |
649 | { |
490 | /* Check the TIM handle allocation */ |
650 | /* Check the TIM handle allocation */ |
491 | if(htim == NULL) |
651 | if (htim == NULL) |
492 | { |
652 | { |
493 | return HAL_ERROR; |
653 | return HAL_ERROR; |
494 | } |
654 | } |
495 | 655 | ||
496 | /* Check the parameters */ |
656 | /* Check the parameters */ |
497 | assert_param(IS_TIM_INSTANCE(htim->Instance)); |
657 | assert_param(IS_TIM_INSTANCE(htim->Instance)); |
498 | assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode)); |
658 | assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode)); |
499 | assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision)); |
659 | assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision)); |
500 | assert_param(IS_TIM_AUTORELOAD_PRELOAD(htim->Init.AutoReloadPreload)); |
660 | assert_param(IS_TIM_AUTORELOAD_PRELOAD(htim->Init.AutoReloadPreload)); |
501 | 661 | ||
502 | if(htim->State == HAL_TIM_STATE_RESET) |
662 | if (htim->State == HAL_TIM_STATE_RESET) |
503 | { |
663 | { |
504 | /* Allocate lock resource and initialize it */ |
664 | /* Allocate lock resource and initialize it */ |
505 | htim->Lock = HAL_UNLOCKED; |
665 | htim->Lock = HAL_UNLOCKED; |
- | 666 | ||
- | 667 | #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) |
|
- | 668 | /* Reset interrupt callbacks to legacy weak callbacks */ |
|
- | 669 | TIM_ResetCallback(htim); |
|
- | 670 | ||
- | 671 | if (htim->OC_MspInitCallback == NULL) |
|
506 | 672 | { |
|
- | 673 | htim->OC_MspInitCallback = HAL_TIM_OC_MspInit; |
|
- | 674 | } |
|
- | 675 | /* Init the low level hardware : GPIO, CLOCK, NVIC */ |
|
- | 676 | htim->OC_MspInitCallback(htim); |
|
- | 677 | #else |
|
507 | /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */ |
678 | /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */ |
508 | HAL_TIM_OC_MspInit(htim); |
679 | HAL_TIM_OC_MspInit(htim); |
- | 680 | #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */ |
|
509 | } |
681 | } |
510 | 682 | ||
511 | /* Set the TIM state */ |
683 | /* Set the TIM state */ |
512 | htim->State= HAL_TIM_STATE_BUSY; |
684 | htim->State = HAL_TIM_STATE_BUSY; |
513 | 685 | ||
514 | /* Init the base time for the Output Compare */ |
686 | /* Init the base time for the Output Compare */ |
515 | TIM_Base_SetConfig(htim->Instance, &htim->Init); |
687 | TIM_Base_SetConfig(htim->Instance, &htim->Init); |
516 | 688 | ||
- | 689 | /* Initialize the DMA burst operation state */ |
|
- | 690 | htim->DMABurstState = HAL_DMA_BURST_STATE_READY; |
|
- | 691 | ||
- | 692 | /* Initialize the TIM channels state */ |
|
- | 693 | TIM_CHANNEL_STATE_SET_ALL(htim, HAL_TIM_CHANNEL_STATE_READY); |
|
- | 694 | TIM_CHANNEL_N_STATE_SET_ALL(htim, HAL_TIM_CHANNEL_STATE_READY); |
|
- | 695 | ||
517 | /* Initialize the TIM state*/ |
696 | /* Initialize the TIM state*/ |
518 | htim->State= HAL_TIM_STATE_READY; |
697 | htim->State = HAL_TIM_STATE_READY; |
519 | 698 | ||
520 | return HAL_OK; |
699 | return HAL_OK; |
521 | } |
700 | } |
522 | 701 | ||
523 | /** |
702 | /** |
524 | * @brief DeInitializes the TIM peripheral |
703 | * @brief DeInitializes the TIM peripheral |
525 | * @param htim : TIM Output Compare handle |
704 | * @param htim TIM Output Compare handle |
526 | * @retval HAL status |
705 | * @retval HAL status |
527 | */ |
706 | */ |
528 | HAL_StatusTypeDef HAL_TIM_OC_DeInit(TIM_HandleTypeDef *htim) |
707 | HAL_StatusTypeDef HAL_TIM_OC_DeInit(TIM_HandleTypeDef *htim) |
529 | { |
708 | { |
530 | /* Check the parameters */ |
709 | /* Check the parameters */ |
531 | assert_param(IS_TIM_INSTANCE(htim->Instance)); |
710 | assert_param(IS_TIM_INSTANCE(htim->Instance)); |
532 | 711 | ||
533 | htim->State = HAL_TIM_STATE_BUSY; |
712 | htim->State = HAL_TIM_STATE_BUSY; |
534 | 713 | ||
535 | /* Disable the TIM Peripheral Clock */ |
714 | /* Disable the TIM Peripheral Clock */ |
536 | __HAL_TIM_DISABLE(htim); |
715 | __HAL_TIM_DISABLE(htim); |
537 | 716 | ||
- | 717 | #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) |
|
- | 718 | if (htim->OC_MspDeInitCallback == NULL) |
|
- | 719 | { |
|
- | 720 | htim->OC_MspDeInitCallback = HAL_TIM_OC_MspDeInit; |
|
- | 721 | } |
|
- | 722 | /* DeInit the low level hardware */ |
|
- | 723 | htim->OC_MspDeInitCallback(htim); |
|
- | 724 | #else |
|
538 | /* DeInit the low level hardware: GPIO, CLOCK, NVIC and DMA */ |
725 | /* DeInit the low level hardware: GPIO, CLOCK, NVIC and DMA */ |
539 | HAL_TIM_OC_MspDeInit(htim); |
726 | HAL_TIM_OC_MspDeInit(htim); |
- | 727 | #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */ |
|
- | 728 | ||
- | 729 | /* Change the DMA burst operation state */ |
|
- | 730 | htim->DMABurstState = HAL_DMA_BURST_STATE_RESET; |
|
- | 731 | ||
- | 732 | /* Change the TIM channels state */ |
|
- | 733 | TIM_CHANNEL_STATE_SET_ALL(htim, HAL_TIM_CHANNEL_STATE_RESET); |
|
- | 734 | TIM_CHANNEL_N_STATE_SET_ALL(htim, HAL_TIM_CHANNEL_STATE_RESET); |
|
540 | 735 | ||
541 | /* Change TIM state */ |
736 | /* Change TIM state */ |
542 | htim->State = HAL_TIM_STATE_RESET; |
737 | htim->State = HAL_TIM_STATE_RESET; |
543 | 738 | ||
544 | /* Release Lock */ |
739 | /* Release Lock */ |
Line 547... | Line 742... | ||
547 | return HAL_OK; |
742 | return HAL_OK; |
548 | } |
743 | } |
549 | 744 | ||
550 | /** |
745 | /** |
551 | * @brief Initializes the TIM Output Compare MSP. |
746 | * @brief Initializes the TIM Output Compare MSP. |
552 | * @param htim : TIM handle |
747 | * @param htim TIM Output Compare handle |
553 | * @retval None |
748 | * @retval None |
554 | */ |
749 | */ |
555 | __weak void HAL_TIM_OC_MspInit(TIM_HandleTypeDef *htim) |
750 | __weak void HAL_TIM_OC_MspInit(TIM_HandleTypeDef *htim) |
556 | { |
751 | { |
557 | /* Prevent unused argument(s) compilation warning */ |
752 | /* Prevent unused argument(s) compilation warning */ |
558 | UNUSED(htim); |
753 | UNUSED(htim); |
- | 754 | ||
559 | /* NOTE : This function Should not be modified, when the callback is needed, |
755 | /* NOTE : This function should not be modified, when the callback is needed, |
560 | the HAL_TIM_OC_MspInit could be implemented in the user file |
756 | the HAL_TIM_OC_MspInit could be implemented in the user file |
561 | */ |
757 | */ |
562 | } |
758 | } |
563 | 759 | ||
564 | /** |
760 | /** |
565 | * @brief DeInitializes TIM Output Compare MSP. |
761 | * @brief DeInitializes TIM Output Compare MSP. |
566 | * @param htim : TIM handle |
762 | * @param htim TIM Output Compare handle |
567 | * @retval None |
763 | * @retval None |
568 | */ |
764 | */ |
569 | __weak void HAL_TIM_OC_MspDeInit(TIM_HandleTypeDef *htim) |
765 | __weak void HAL_TIM_OC_MspDeInit(TIM_HandleTypeDef *htim) |
570 | { |
766 | { |
571 | /* Prevent unused argument(s) compilation warning */ |
767 | /* Prevent unused argument(s) compilation warning */ |
572 | UNUSED(htim); |
768 | UNUSED(htim); |
- | 769 | ||
573 | /* NOTE : This function Should not be modified, when the callback is needed, |
770 | /* NOTE : This function should not be modified, when the callback is needed, |
574 | the HAL_TIM_OC_MspDeInit could be implemented in the user file |
771 | the HAL_TIM_OC_MspDeInit could be implemented in the user file |
575 | */ |
772 | */ |
576 | } |
773 | } |
577 | 774 | ||
578 | /** |
775 | /** |
579 | * @brief Starts the TIM Output Compare signal generation. |
776 | * @brief Starts the TIM Output Compare signal generation. |
580 | * @param htim : TIM Output Compare handle |
777 | * @param htim TIM Output Compare handle |
581 | * @param Channel : TIM Channel to be enabled |
778 | * @param Channel TIM Channel to be enabled |
582 | * This parameter can be one of the following values: |
779 | * This parameter can be one of the following values: |
583 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
780 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
584 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
781 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
585 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
782 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
586 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
783 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
587 | * @retval HAL status |
784 | * @retval HAL status |
588 | */ |
785 | */ |
589 | HAL_StatusTypeDef HAL_TIM_OC_Start(TIM_HandleTypeDef *htim, uint32_t Channel) |
786 | HAL_StatusTypeDef HAL_TIM_OC_Start(TIM_HandleTypeDef *htim, uint32_t Channel) |
590 | { |
787 | { |
- | 788 | uint32_t tmpsmcr; |
|
- | 789 | ||
591 | /* Check the parameters */ |
790 | /* Check the parameters */ |
592 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
791 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
593 | 792 | ||
- | 793 | /* Check the TIM channel state */ |
|
- | 794 | if (TIM_CHANNEL_STATE_GET(htim, Channel) != HAL_TIM_CHANNEL_STATE_READY) |
|
- | 795 | { |
|
- | 796 | return HAL_ERROR; |
|
- | 797 | } |
|
- | 798 | ||
- | 799 | /* Set the TIM channel state */ |
|
- | 800 | TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_BUSY); |
|
- | 801 | ||
594 | /* Enable the Output compare channel */ |
802 | /* Enable the Output compare channel */ |
595 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE); |
803 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE); |
596 | 804 | ||
597 | if(IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET) |
805 | if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET) |
598 | { |
806 | { |
599 | /* Enable the main output */ |
807 | /* Enable the main output */ |
600 | __HAL_TIM_MOE_ENABLE(htim); |
808 | __HAL_TIM_MOE_ENABLE(htim); |
601 | } |
809 | } |
602 | 810 | ||
- | 811 | /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */ |
|
- | 812 | if (IS_TIM_SLAVE_INSTANCE(htim->Instance)) |
|
- | 813 | { |
|
- | 814 | tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS; |
|
- | 815 | if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr)) |
|
- | 816 | { |
|
603 | /* Enable the Peripheral */ |
817 | __HAL_TIM_ENABLE(htim); |
- | 818 | } |
|
- | 819 | } |
|
- | 820 | else |
|
- | 821 | { |
|
604 | __HAL_TIM_ENABLE(htim); |
822 | __HAL_TIM_ENABLE(htim); |
- | 823 | } |
|
605 | 824 | ||
606 | /* Return function status */ |
825 | /* Return function status */ |
607 | return HAL_OK; |
826 | return HAL_OK; |
608 | } |
827 | } |
609 | 828 | ||
610 | /** |
829 | /** |
611 | * @brief Stops the TIM Output Compare signal generation. |
830 | * @brief Stops the TIM Output Compare signal generation. |
612 | * @param htim : TIM handle |
831 | * @param htim TIM Output Compare handle |
613 | * @param Channel : TIM Channel to be disabled |
832 | * @param Channel TIM Channel to be disabled |
614 | * This parameter can be one of the following values: |
833 | * This parameter can be one of the following values: |
615 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
834 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
616 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
835 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
617 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
836 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
618 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
837 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
619 | * @retval HAL status |
838 | * @retval HAL status |
620 | */ |
839 | */ |
621 | HAL_StatusTypeDef HAL_TIM_OC_Stop(TIM_HandleTypeDef *htim, uint32_t Channel) |
840 | HAL_StatusTypeDef HAL_TIM_OC_Stop(TIM_HandleTypeDef *htim, uint32_t Channel) |
622 | { |
841 | { |
623 | /* Check the parameters */ |
842 | /* Check the parameters */ |
624 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
843 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
625 | 844 | ||
626 | /* Disable the Output compare channel */ |
845 | /* Disable the Output compare channel */ |
627 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE); |
846 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE); |
628 | 847 | ||
629 | if(IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET) |
848 | if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET) |
630 | { |
849 | { |
631 | /* Disable the Main Ouput */ |
850 | /* Disable the Main Output */ |
632 | __HAL_TIM_MOE_DISABLE(htim); |
851 | __HAL_TIM_MOE_DISABLE(htim); |
633 | } |
852 | } |
634 | 853 | ||
635 | /* Disable the Peripheral */ |
854 | /* Disable the Peripheral */ |
636 | __HAL_TIM_DISABLE(htim); |
855 | __HAL_TIM_DISABLE(htim); |
637 | 856 | ||
- | 857 | /* Set the TIM channel state */ |
|
- | 858 | TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY); |
|
- | 859 | ||
638 | /* Return function status */ |
860 | /* Return function status */ |
639 | return HAL_OK; |
861 | return HAL_OK; |
640 | } |
862 | } |
641 | 863 | ||
642 | /** |
864 | /** |
643 | * @brief Starts the TIM Output Compare signal generation in interrupt mode. |
865 | * @brief Starts the TIM Output Compare signal generation in interrupt mode. |
644 | * @param htim : TIM OC handle |
866 | * @param htim TIM Output Compare handle |
645 | * @param Channel : TIM Channel to be enabled |
867 | * @param Channel TIM Channel to be enabled |
646 | * This parameter can be one of the following values: |
868 | * This parameter can be one of the following values: |
647 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
869 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
648 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
870 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
649 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
871 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
650 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
872 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
651 | * @retval HAL status |
873 | * @retval HAL status |
652 | */ |
874 | */ |
653 | HAL_StatusTypeDef HAL_TIM_OC_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel) |
875 | HAL_StatusTypeDef HAL_TIM_OC_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel) |
654 | { |
876 | { |
- | 877 | uint32_t tmpsmcr; |
|
- | 878 | ||
655 | /* Check the parameters */ |
879 | /* Check the parameters */ |
656 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
880 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
657 | 881 | ||
- | 882 | /* Check the TIM channel state */ |
|
- | 883 | if (TIM_CHANNEL_STATE_GET(htim, Channel) != HAL_TIM_CHANNEL_STATE_READY) |
|
- | 884 | { |
|
- | 885 | return HAL_ERROR; |
|
- | 886 | } |
|
- | 887 | ||
- | 888 | /* Set the TIM channel state */ |
|
- | 889 | TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_BUSY); |
|
- | 890 | ||
658 | switch (Channel) |
891 | switch (Channel) |
659 | { |
892 | { |
660 | case TIM_CHANNEL_1: |
893 | case TIM_CHANNEL_1: |
661 | { |
894 | { |
662 | /* Enable the TIM Capture/Compare 1 interrupt */ |
895 | /* Enable the TIM Capture/Compare 1 interrupt */ |
663 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1); |
896 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1); |
- | 897 | break; |
|
664 | } |
898 | } |
665 | break; |
- | |
666 | 899 | ||
667 | case TIM_CHANNEL_2: |
900 | case TIM_CHANNEL_2: |
668 | { |
901 | { |
669 | /* Enable the TIM Capture/Compare 2 interrupt */ |
902 | /* Enable the TIM Capture/Compare 2 interrupt */ |
670 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2); |
903 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2); |
- | 904 | break; |
|
671 | } |
905 | } |
672 | break; |
- | |
673 | 906 | ||
674 | case TIM_CHANNEL_3: |
907 | case TIM_CHANNEL_3: |
675 | { |
908 | { |
676 | /* Enable the TIM Capture/Compare 3 interrupt */ |
909 | /* Enable the TIM Capture/Compare 3 interrupt */ |
677 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC3); |
910 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC3); |
- | 911 | break; |
|
678 | } |
912 | } |
679 | break; |
- | |
680 | 913 | ||
681 | case TIM_CHANNEL_4: |
914 | case TIM_CHANNEL_4: |
682 | { |
915 | { |
683 | /* Enable the TIM Capture/Compare 4 interrupt */ |
916 | /* Enable the TIM Capture/Compare 4 interrupt */ |
684 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC4); |
917 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC4); |
- | 918 | break; |
|
685 | } |
919 | } |
686 | break; |
- | |
687 | 920 | ||
688 | default: |
921 | default: |
689 | break; |
922 | break; |
690 | } |
923 | } |
691 | 924 | ||
692 | /* Enable the Output compare channel */ |
925 | /* Enable the Output compare channel */ |
693 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE); |
926 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE); |
694 | 927 | ||
695 | if(IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET) |
928 | if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET) |
696 | { |
929 | { |
697 | /* Enable the main output */ |
930 | /* Enable the main output */ |
698 | __HAL_TIM_MOE_ENABLE(htim); |
931 | __HAL_TIM_MOE_ENABLE(htim); |
699 | } |
932 | } |
700 | 933 | ||
- | 934 | /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */ |
|
- | 935 | if (IS_TIM_SLAVE_INSTANCE(htim->Instance)) |
|
- | 936 | { |
|
- | 937 | tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS; |
|
- | 938 | if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr)) |
|
- | 939 | { |
|
701 | /* Enable the Peripheral */ |
940 | __HAL_TIM_ENABLE(htim); |
- | 941 | } |
|
- | 942 | } |
|
- | 943 | else |
|
- | 944 | { |
|
702 | __HAL_TIM_ENABLE(htim); |
945 | __HAL_TIM_ENABLE(htim); |
- | 946 | } |
|
703 | 947 | ||
704 | /* Return function status */ |
948 | /* Return function status */ |
705 | return HAL_OK; |
949 | return HAL_OK; |
706 | } |
950 | } |
707 | 951 | ||
708 | /** |
952 | /** |
709 | * @brief Stops the TIM Output Compare signal generation in interrupt mode. |
953 | * @brief Stops the TIM Output Compare signal generation in interrupt mode. |
710 | * @param htim : TIM Output Compare handle |
954 | * @param htim TIM Output Compare handle |
711 | * @param Channel : TIM Channel to be disabled |
955 | * @param Channel TIM Channel to be disabled |
712 | * This parameter can be one of the following values: |
956 | * This parameter can be one of the following values: |
713 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
957 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
714 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
958 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
715 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
959 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
716 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
960 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
717 | * @retval HAL status |
961 | * @retval HAL status |
718 | */ |
962 | */ |
719 | HAL_StatusTypeDef HAL_TIM_OC_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel) |
963 | HAL_StatusTypeDef HAL_TIM_OC_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel) |
720 | { |
964 | { |
721 | /* Check the parameters */ |
965 | /* Check the parameters */ |
722 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
966 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
723 | 967 | ||
Line 725... | Line 969... | ||
725 | { |
969 | { |
726 | case TIM_CHANNEL_1: |
970 | case TIM_CHANNEL_1: |
727 | { |
971 | { |
728 | /* Disable the TIM Capture/Compare 1 interrupt */ |
972 | /* Disable the TIM Capture/Compare 1 interrupt */ |
729 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1); |
973 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1); |
- | 974 | break; |
|
730 | } |
975 | } |
731 | break; |
- | |
732 | 976 | ||
733 | case TIM_CHANNEL_2: |
977 | case TIM_CHANNEL_2: |
734 | { |
978 | { |
735 | /* Disable the TIM Capture/Compare 2 interrupt */ |
979 | /* Disable the TIM Capture/Compare 2 interrupt */ |
736 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2); |
980 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2); |
- | 981 | break; |
|
737 | } |
982 | } |
738 | break; |
- | |
739 | 983 | ||
740 | case TIM_CHANNEL_3: |
984 | case TIM_CHANNEL_3: |
741 | { |
985 | { |
742 | /* Disable the TIM Capture/Compare 3 interrupt */ |
986 | /* Disable the TIM Capture/Compare 3 interrupt */ |
743 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC3); |
987 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC3); |
- | 988 | break; |
|
744 | } |
989 | } |
745 | break; |
- | |
746 | 990 | ||
747 | case TIM_CHANNEL_4: |
991 | case TIM_CHANNEL_4: |
748 | { |
992 | { |
749 | /* Disable the TIM Capture/Compare 4 interrupt */ |
993 | /* Disable the TIM Capture/Compare 4 interrupt */ |
750 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC4); |
994 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC4); |
- | 995 | break; |
|
751 | } |
996 | } |
752 | break; |
- | |
753 | 997 | ||
754 | default: |
998 | default: |
755 | break; |
999 | break; |
756 | } |
1000 | } |
757 | 1001 | ||
758 | /* Disable the Output compare channel */ |
1002 | /* Disable the Output compare channel */ |
759 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE); |
1003 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE); |
760 | 1004 | ||
761 | if(IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET) |
1005 | if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET) |
762 | { |
1006 | { |
763 | /* Disable the Main Ouput */ |
1007 | /* Disable the Main Output */ |
764 | __HAL_TIM_MOE_DISABLE(htim); |
1008 | __HAL_TIM_MOE_DISABLE(htim); |
765 | } |
1009 | } |
766 | 1010 | ||
767 | /* Disable the Peripheral */ |
1011 | /* Disable the Peripheral */ |
768 | __HAL_TIM_DISABLE(htim); |
1012 | __HAL_TIM_DISABLE(htim); |
769 | 1013 | ||
- | 1014 | /* Set the TIM channel state */ |
|
- | 1015 | TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY); |
|
- | 1016 | ||
770 | /* Return function status */ |
1017 | /* Return function status */ |
771 | return HAL_OK; |
1018 | return HAL_OK; |
772 | } |
1019 | } |
773 | 1020 | ||
774 | /** |
1021 | /** |
775 | * @brief Starts the TIM Output Compare signal generation in DMA mode. |
1022 | * @brief Starts the TIM Output Compare signal generation in DMA mode. |
776 | * @param htim : TIM Output Compare handle |
1023 | * @param htim TIM Output Compare handle |
777 | * @param Channel : TIM Channel to be enabled |
1024 | * @param Channel TIM Channel to be enabled |
778 | * This parameter can be one of the following values: |
1025 | * This parameter can be one of the following values: |
779 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
1026 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
780 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
1027 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
781 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
1028 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
782 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
1029 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
783 | * @param pData : The source Buffer address. |
1030 | * @param pData The source Buffer address. |
784 | * @param Length : The length of data to be transferred from memory to TIM peripheral |
1031 | * @param Length The length of data to be transferred from memory to TIM peripheral |
785 | * @retval HAL status |
1032 | * @retval HAL status |
786 | */ |
1033 | */ |
787 | HAL_StatusTypeDef HAL_TIM_OC_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length) |
1034 | HAL_StatusTypeDef HAL_TIM_OC_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length) |
788 | { |
1035 | { |
- | 1036 | uint32_t tmpsmcr; |
|
- | 1037 | ||
789 | /* Check the parameters */ |
1038 | /* Check the parameters */ |
790 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
1039 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
791 | 1040 | ||
- | 1041 | /* Set the TIM channel state */ |
|
792 | if((htim->State == HAL_TIM_STATE_BUSY)) |
1042 | if (TIM_CHANNEL_STATE_GET(htim, Channel) == HAL_TIM_CHANNEL_STATE_BUSY) |
793 | { |
1043 | { |
794 | return HAL_BUSY; |
1044 | return HAL_BUSY; |
795 | } |
1045 | } |
796 | else if((htim->State == HAL_TIM_STATE_READY)) |
1046 | else if (TIM_CHANNEL_STATE_GET(htim, Channel) == HAL_TIM_CHANNEL_STATE_READY) |
797 | { |
1047 | { |
798 | if(((uint32_t)pData == 0U) && (Length > 0U)) |
1048 | if ((pData == NULL) && (Length > 0U)) |
799 | { |
1049 | { |
800 | return HAL_ERROR; |
1050 | return HAL_ERROR; |
801 | } |
1051 | } |
802 | else |
1052 | else |
803 | { |
1053 | { |
804 | htim->State = HAL_TIM_STATE_BUSY; |
1054 | TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_BUSY); |
805 | } |
1055 | } |
806 | } |
1056 | } |
- | 1057 | else |
|
- | 1058 | { |
|
- | 1059 | return HAL_ERROR; |
|
- | 1060 | } |
|
- | 1061 | ||
807 | switch (Channel) |
1062 | switch (Channel) |
808 | { |
1063 | { |
809 | case TIM_CHANNEL_1: |
1064 | case TIM_CHANNEL_1: |
810 | { |
1065 | { |
811 | /* Set the DMA Period elapsed callback */ |
1066 | /* Set the DMA compare callbacks */ |
812 | htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMADelayPulseCplt; |
1067 | htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMADelayPulseCplt; |
- | 1068 | htim->hdma[TIM_DMA_ID_CC1]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt; |
|
813 | 1069 | ||
814 | /* Set the DMA error callback */ |
1070 | /* Set the DMA error callback */ |
815 | htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ; |
1071 | htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ; |
816 | 1072 | ||
817 | /* Enable the DMA channel */ |
1073 | /* Enable the DMA channel */ |
818 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)pData, (uint32_t)&htim->Instance->CCR1, Length); |
1074 | if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)pData, (uint32_t)&htim->Instance->CCR1, Length) != HAL_OK) |
- | 1075 | { |
|
- | 1076 | /* Return error status */ |
|
- | 1077 | return HAL_ERROR; |
|
- | 1078 | } |
|
819 | 1079 | ||
820 | /* Enable the TIM Capture/Compare 1 DMA request */ |
1080 | /* Enable the TIM Capture/Compare 1 DMA request */ |
821 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1); |
1081 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1); |
- | 1082 | break; |
|
822 | } |
1083 | } |
823 | break; |
- | |
824 | 1084 | ||
825 | case TIM_CHANNEL_2: |
1085 | case TIM_CHANNEL_2: |
826 | { |
1086 | { |
827 | /* Set the DMA Period elapsed callback */ |
1087 | /* Set the DMA compare callbacks */ |
828 | htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMADelayPulseCplt; |
1088 | htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMADelayPulseCplt; |
- | 1089 | htim->hdma[TIM_DMA_ID_CC2]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt; |
|
829 | 1090 | ||
830 | /* Set the DMA error callback */ |
1091 | /* Set the DMA error callback */ |
831 | htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError ; |
1092 | htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError ; |
832 | 1093 | ||
833 | /* Enable the DMA channel */ |
1094 | /* Enable the DMA channel */ |
834 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)pData, (uint32_t)&htim->Instance->CCR2, Length); |
1095 | if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)pData, (uint32_t)&htim->Instance->CCR2, Length) != HAL_OK) |
- | 1096 | { |
|
- | 1097 | /* Return error status */ |
|
- | 1098 | return HAL_ERROR; |
|
- | 1099 | } |
|
835 | 1100 | ||
836 | /* Enable the TIM Capture/Compare 2 DMA request */ |
1101 | /* Enable the TIM Capture/Compare 2 DMA request */ |
837 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2); |
1102 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2); |
- | 1103 | break; |
|
838 | } |
1104 | } |
839 | break; |
- | |
840 | 1105 | ||
841 | case TIM_CHANNEL_3: |
1106 | case TIM_CHANNEL_3: |
842 | { |
1107 | { |
843 | /* Set the DMA Period elapsed callback */ |
1108 | /* Set the DMA compare callbacks */ |
844 | htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMADelayPulseCplt; |
1109 | htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMADelayPulseCplt; |
- | 1110 | htim->hdma[TIM_DMA_ID_CC3]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt; |
|
845 | 1111 | ||
846 | /* Set the DMA error callback */ |
1112 | /* Set the DMA error callback */ |
847 | htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = TIM_DMAError ; |
1113 | htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = TIM_DMAError ; |
848 | 1114 | ||
849 | /* Enable the DMA channel */ |
1115 | /* Enable the DMA channel */ |
850 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)pData, (uint32_t)&htim->Instance->CCR3,Length); |
1116 | if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)pData, (uint32_t)&htim->Instance->CCR3, Length) != HAL_OK) |
- | 1117 | { |
|
- | 1118 | /* Return error status */ |
|
- | 1119 | return HAL_ERROR; |
|
851 | 1120 | } |
|
852 | /* Enable the TIM Capture/Compare 3 DMA request */ |
1121 | /* Enable the TIM Capture/Compare 3 DMA request */ |
853 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC3); |
1122 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC3); |
- | 1123 | break; |
|
854 | } |
1124 | } |
855 | break; |
- | |
856 | 1125 | ||
857 | case TIM_CHANNEL_4: |
1126 | case TIM_CHANNEL_4: |
858 | { |
1127 | { |
859 | /* Set the DMA Period elapsed callback */ |
1128 | /* Set the DMA compare callbacks */ |
860 | htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = TIM_DMADelayPulseCplt; |
1129 | htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = TIM_DMADelayPulseCplt; |
- | 1130 | htim->hdma[TIM_DMA_ID_CC4]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt; |
|
861 | 1131 | ||
862 | /* Set the DMA error callback */ |
1132 | /* Set the DMA error callback */ |
863 | htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = TIM_DMAError ; |
1133 | htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = TIM_DMAError ; |
864 | 1134 | ||
865 | /* Enable the DMA channel */ |
1135 | /* Enable the DMA channel */ |
866 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)pData, (uint32_t)&htim->Instance->CCR4, Length); |
1136 | if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)pData, (uint32_t)&htim->Instance->CCR4, Length) != HAL_OK) |
- | 1137 | { |
|
- | 1138 | /* Return error status */ |
|
- | 1139 | return HAL_ERROR; |
|
867 | 1140 | } |
|
868 | /* Enable the TIM Capture/Compare 4 DMA request */ |
1141 | /* Enable the TIM Capture/Compare 4 DMA request */ |
869 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC4); |
1142 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC4); |
- | 1143 | break; |
|
870 | } |
1144 | } |
871 | break; |
- | |
872 | 1145 | ||
873 | default: |
1146 | default: |
874 | break; |
1147 | break; |
875 | } |
1148 | } |
876 | 1149 | ||
877 | /* Enable the Output compare channel */ |
1150 | /* Enable the Output compare channel */ |
878 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE); |
1151 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE); |
879 | 1152 | ||
880 | if(IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET) |
1153 | if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET) |
881 | { |
1154 | { |
882 | /* Enable the main output */ |
1155 | /* Enable the main output */ |
883 | __HAL_TIM_MOE_ENABLE(htim); |
1156 | __HAL_TIM_MOE_ENABLE(htim); |
884 | } |
1157 | } |
885 | 1158 | ||
- | 1159 | /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */ |
|
- | 1160 | if (IS_TIM_SLAVE_INSTANCE(htim->Instance)) |
|
- | 1161 | { |
|
- | 1162 | tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS; |
|
- | 1163 | if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr)) |
|
- | 1164 | { |
|
886 | /* Enable the Peripheral */ |
1165 | __HAL_TIM_ENABLE(htim); |
- | 1166 | } |
|
- | 1167 | } |
|
- | 1168 | else |
|
- | 1169 | { |
|
887 | __HAL_TIM_ENABLE(htim); |
1170 | __HAL_TIM_ENABLE(htim); |
- | 1171 | } |
|
888 | 1172 | ||
889 | /* Return function status */ |
1173 | /* Return function status */ |
890 | return HAL_OK; |
1174 | return HAL_OK; |
891 | } |
1175 | } |
892 | 1176 | ||
893 | /** |
1177 | /** |
894 | * @brief Stops the TIM Output Compare signal generation in DMA mode. |
1178 | * @brief Stops the TIM Output Compare signal generation in DMA mode. |
895 | * @param htim : TIM Output Compare handle |
1179 | * @param htim TIM Output Compare handle |
896 | * @param Channel : TIM Channel to be disabled |
1180 | * @param Channel TIM Channel to be disabled |
897 | * This parameter can be one of the following values: |
1181 | * This parameter can be one of the following values: |
898 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
1182 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
899 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
1183 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
900 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
1184 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
901 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
1185 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
902 | * @retval HAL status |
1186 | * @retval HAL status |
903 | */ |
1187 | */ |
904 | HAL_StatusTypeDef HAL_TIM_OC_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel) |
1188 | HAL_StatusTypeDef HAL_TIM_OC_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel) |
905 | { |
1189 | { |
906 | /* Check the parameters */ |
1190 | /* Check the parameters */ |
907 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
1191 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
908 | 1192 | ||
Line 910... | Line 1194... | ||
910 | { |
1194 | { |
911 | case TIM_CHANNEL_1: |
1195 | case TIM_CHANNEL_1: |
912 | { |
1196 | { |
913 | /* Disable the TIM Capture/Compare 1 DMA request */ |
1197 | /* Disable the TIM Capture/Compare 1 DMA request */ |
914 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1); |
1198 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1); |
- | 1199 | (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC1]); |
|
- | 1200 | break; |
|
915 | } |
1201 | } |
916 | break; |
- | |
917 | 1202 | ||
918 | case TIM_CHANNEL_2: |
1203 | case TIM_CHANNEL_2: |
919 | { |
1204 | { |
920 | /* Disable the TIM Capture/Compare 2 DMA request */ |
1205 | /* Disable the TIM Capture/Compare 2 DMA request */ |
921 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2); |
1206 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2); |
- | 1207 | (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC2]); |
|
- | 1208 | break; |
|
922 | } |
1209 | } |
923 | break; |
- | |
924 | 1210 | ||
925 | case TIM_CHANNEL_3: |
1211 | case TIM_CHANNEL_3: |
926 | { |
1212 | { |
927 | /* Disable the TIM Capture/Compare 3 DMA request */ |
1213 | /* Disable the TIM Capture/Compare 3 DMA request */ |
928 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC3); |
1214 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC3); |
- | 1215 | (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC3]); |
|
- | 1216 | break; |
|
929 | } |
1217 | } |
930 | break; |
- | |
931 | 1218 | ||
932 | case TIM_CHANNEL_4: |
1219 | case TIM_CHANNEL_4: |
933 | { |
1220 | { |
934 | /* Disable the TIM Capture/Compare 4 interrupt */ |
1221 | /* Disable the TIM Capture/Compare 4 interrupt */ |
935 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC4); |
1222 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC4); |
- | 1223 | (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC4]); |
|
- | 1224 | break; |
|
936 | } |
1225 | } |
937 | break; |
- | |
938 | 1226 | ||
939 | default: |
1227 | default: |
940 | break; |
1228 | break; |
941 | } |
1229 | } |
942 | 1230 | ||
943 | /* Disable the Output compare channel */ |
1231 | /* Disable the Output compare channel */ |
944 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE); |
1232 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE); |
945 | 1233 | ||
946 | if(IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET) |
1234 | if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET) |
947 | { |
1235 | { |
948 | /* Disable the Main Ouput */ |
1236 | /* Disable the Main Output */ |
949 | __HAL_TIM_MOE_DISABLE(htim); |
1237 | __HAL_TIM_MOE_DISABLE(htim); |
950 | } |
1238 | } |
951 | 1239 | ||
952 | /* Disable the Peripheral */ |
1240 | /* Disable the Peripheral */ |
953 | __HAL_TIM_DISABLE(htim); |
1241 | __HAL_TIM_DISABLE(htim); |
954 | 1242 | ||
955 | /* Change the htim state */ |
1243 | /* Set the TIM channel state */ |
956 | htim->State = HAL_TIM_STATE_READY; |
1244 | TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY); |
957 | 1245 | ||
958 | /* Return function status */ |
1246 | /* Return function status */ |
959 | return HAL_OK; |
1247 | return HAL_OK; |
960 | } |
1248 | } |
961 | 1249 | ||
962 | /** |
1250 | /** |
963 | * @} |
1251 | * @} |
964 | */ |
1252 | */ |
965 | 1253 | ||
966 | /** @defgroup TIM_Exported_Functions_Group3 Time PWM functions |
1254 | /** @defgroup TIM_Exported_Functions_Group3 TIM PWM functions |
967 | * @brief Time PWM functions |
1255 | * @brief TIM PWM functions |
968 | * |
1256 | * |
969 | @verbatim |
1257 | @verbatim |
970 | ============================================================================== |
1258 | ============================================================================== |
971 | ##### Time PWM functions ##### |
1259 | ##### TIM PWM functions ##### |
972 | ============================================================================== |
1260 | ============================================================================== |
973 | [..] |
1261 | [..] |
974 | This section provides functions allowing to: |
1262 | This section provides functions allowing to: |
975 | (+) Initialize and configure the TIM PWM. |
1263 | (+) Initialize and configure the TIM PWM. |
976 | (+) De-initialize the TIM PWM. |
1264 | (+) De-initialize the TIM PWM. |
977 | (+) Start the Time PWM. |
1265 | (+) Start the TIM PWM. |
978 | (+) Stop the Time PWM. |
1266 | (+) Stop the TIM PWM. |
979 | (+) Start the Time PWM and enable interrupt. |
1267 | (+) Start the TIM PWM and enable interrupt. |
980 | (+) Stop the Time PWM and disable interrupt. |
1268 | (+) Stop the TIM PWM and disable interrupt. |
981 | (+) Start the Time PWM and enable DMA transfer. |
1269 | (+) Start the TIM PWM and enable DMA transfer. |
982 | (+) Stop the Time PWM and disable DMA transfer. |
1270 | (+) Stop the TIM PWM and disable DMA transfer. |
983 | 1271 | ||
984 | @endverbatim |
1272 | @endverbatim |
985 | * @{ |
1273 | * @{ |
986 | */ |
1274 | */ |
987 | /** |
1275 | /** |
988 | * @brief Initializes the TIM PWM Time Base according to the specified |
1276 | * @brief Initializes the TIM PWM Time Base according to the specified |
989 | * parameters in the TIM_HandleTypeDef and create the associated handle. |
1277 | * parameters in the TIM_HandleTypeDef and initializes the associated handle. |
990 | * @note Switching from Center Aligned counter mode to Edge counter mode (or reverse) |
1278 | * @note Switching from Center Aligned counter mode to Edge counter mode (or reverse) |
991 | * requires a timer reset to avoid unexpected direction |
1279 | * requires a timer reset to avoid unexpected direction |
992 | * due to DIR bit readonly in center aligned mode. |
1280 | * due to DIR bit readonly in center aligned mode. |
993 | * Ex: call @ref HAL_TIM_PWM_DeInit() before HAL_TIM_PWM_Init() |
1281 | * Ex: call @ref HAL_TIM_PWM_DeInit() before HAL_TIM_PWM_Init() |
994 | * @param htim : TIM handle |
1282 | * @param htim TIM PWM handle |
995 | * @retval HAL status |
1283 | * @retval HAL status |
996 | */ |
1284 | */ |
997 | HAL_StatusTypeDef HAL_TIM_PWM_Init(TIM_HandleTypeDef *htim) |
1285 | HAL_StatusTypeDef HAL_TIM_PWM_Init(TIM_HandleTypeDef *htim) |
998 | { |
1286 | { |
999 | /* Check the TIM handle allocation */ |
1287 | /* Check the TIM handle allocation */ |
1000 | if(htim == NULL) |
1288 | if (htim == NULL) |
1001 | { |
1289 | { |
1002 | return HAL_ERROR; |
1290 | return HAL_ERROR; |
1003 | } |
1291 | } |
1004 | 1292 | ||
1005 | /* Check the parameters */ |
1293 | /* Check the parameters */ |
1006 | assert_param(IS_TIM_INSTANCE(htim->Instance)); |
1294 | assert_param(IS_TIM_INSTANCE(htim->Instance)); |
1007 | assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode)); |
1295 | assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode)); |
1008 | assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision)); |
1296 | assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision)); |
1009 | assert_param(IS_TIM_AUTORELOAD_PRELOAD(htim->Init.AutoReloadPreload)); |
1297 | assert_param(IS_TIM_AUTORELOAD_PRELOAD(htim->Init.AutoReloadPreload)); |
1010 | 1298 | ||
1011 | if(htim->State == HAL_TIM_STATE_RESET) |
1299 | if (htim->State == HAL_TIM_STATE_RESET) |
1012 | { |
1300 | { |
1013 | /* Allocate lock resource and initialize it */ |
1301 | /* Allocate lock resource and initialize it */ |
1014 | htim->Lock = HAL_UNLOCKED; |
1302 | htim->Lock = HAL_UNLOCKED; |
- | 1303 | ||
- | 1304 | #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) |
|
- | 1305 | /* Reset interrupt callbacks to legacy weak callbacks */ |
|
- | 1306 | TIM_ResetCallback(htim); |
|
- | 1307 | ||
- | 1308 | if (htim->PWM_MspInitCallback == NULL) |
|
1015 | 1309 | { |
|
- | 1310 | htim->PWM_MspInitCallback = HAL_TIM_PWM_MspInit; |
|
- | 1311 | } |
|
- | 1312 | /* Init the low level hardware : GPIO, CLOCK, NVIC */ |
|
- | 1313 | htim->PWM_MspInitCallback(htim); |
|
- | 1314 | #else |
|
1016 | /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */ |
1315 | /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */ |
1017 | HAL_TIM_PWM_MspInit(htim); |
1316 | HAL_TIM_PWM_MspInit(htim); |
- | 1317 | #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */ |
|
1018 | } |
1318 | } |
1019 | 1319 | ||
1020 | /* Set the TIM state */ |
1320 | /* Set the TIM state */ |
1021 | htim->State= HAL_TIM_STATE_BUSY; |
1321 | htim->State = HAL_TIM_STATE_BUSY; |
1022 | 1322 | ||
1023 | /* Init the base time for the PWM */ |
1323 | /* Init the base time for the PWM */ |
1024 | TIM_Base_SetConfig(htim->Instance, &htim->Init); |
1324 | TIM_Base_SetConfig(htim->Instance, &htim->Init); |
1025 | 1325 | ||
- | 1326 | /* Initialize the DMA burst operation state */ |
|
- | 1327 | htim->DMABurstState = HAL_DMA_BURST_STATE_READY; |
|
- | 1328 | ||
- | 1329 | /* Initialize the TIM channels state */ |
|
- | 1330 | TIM_CHANNEL_STATE_SET_ALL(htim, HAL_TIM_CHANNEL_STATE_READY); |
|
- | 1331 | TIM_CHANNEL_N_STATE_SET_ALL(htim, HAL_TIM_CHANNEL_STATE_READY); |
|
- | 1332 | ||
1026 | /* Initialize the TIM state*/ |
1333 | /* Initialize the TIM state*/ |
1027 | htim->State= HAL_TIM_STATE_READY; |
1334 | htim->State = HAL_TIM_STATE_READY; |
1028 | 1335 | ||
1029 | return HAL_OK; |
1336 | return HAL_OK; |
1030 | } |
1337 | } |
1031 | 1338 | ||
1032 | /** |
1339 | /** |
1033 | * @brief DeInitializes the TIM peripheral |
1340 | * @brief DeInitializes the TIM peripheral |
1034 | * @param htim : TIM handle |
1341 | * @param htim TIM PWM handle |
1035 | * @retval HAL status |
1342 | * @retval HAL status |
1036 | */ |
1343 | */ |
1037 | HAL_StatusTypeDef HAL_TIM_PWM_DeInit(TIM_HandleTypeDef *htim) |
1344 | HAL_StatusTypeDef HAL_TIM_PWM_DeInit(TIM_HandleTypeDef *htim) |
1038 | { |
1345 | { |
1039 | /* Check the parameters */ |
1346 | /* Check the parameters */ |
Line 1042... | Line 1349... | ||
1042 | htim->State = HAL_TIM_STATE_BUSY; |
1349 | htim->State = HAL_TIM_STATE_BUSY; |
1043 | 1350 | ||
1044 | /* Disable the TIM Peripheral Clock */ |
1351 | /* Disable the TIM Peripheral Clock */ |
1045 | __HAL_TIM_DISABLE(htim); |
1352 | __HAL_TIM_DISABLE(htim); |
1046 | 1353 | ||
- | 1354 | #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) |
|
- | 1355 | if (htim->PWM_MspDeInitCallback == NULL) |
|
- | 1356 | { |
|
- | 1357 | htim->PWM_MspDeInitCallback = HAL_TIM_PWM_MspDeInit; |
|
- | 1358 | } |
|
- | 1359 | /* DeInit the low level hardware */ |
|
- | 1360 | htim->PWM_MspDeInitCallback(htim); |
|
- | 1361 | #else |
|
1047 | /* DeInit the low level hardware: GPIO, CLOCK, NVIC and DMA */ |
1362 | /* DeInit the low level hardware: GPIO, CLOCK, NVIC and DMA */ |
1048 | HAL_TIM_PWM_MspDeInit(htim); |
1363 | HAL_TIM_PWM_MspDeInit(htim); |
- | 1364 | #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */ |
|
- | 1365 | ||
- | 1366 | /* Change the DMA burst operation state */ |
|
- | 1367 | htim->DMABurstState = HAL_DMA_BURST_STATE_RESET; |
|
- | 1368 | ||
- | 1369 | /* Change the TIM channels state */ |
|
- | 1370 | TIM_CHANNEL_STATE_SET_ALL(htim, HAL_TIM_CHANNEL_STATE_RESET); |
|
- | 1371 | TIM_CHANNEL_N_STATE_SET_ALL(htim, HAL_TIM_CHANNEL_STATE_RESET); |
|
1049 | 1372 | ||
1050 | /* Change TIM state */ |
1373 | /* Change TIM state */ |
1051 | htim->State = HAL_TIM_STATE_RESET; |
1374 | htim->State = HAL_TIM_STATE_RESET; |
1052 | 1375 | ||
1053 | /* Release Lock */ |
1376 | /* Release Lock */ |
Line 1056... | Line 1379... | ||
1056 | return HAL_OK; |
1379 | return HAL_OK; |
1057 | } |
1380 | } |
1058 | 1381 | ||
1059 | /** |
1382 | /** |
1060 | * @brief Initializes the TIM PWM MSP. |
1383 | * @brief Initializes the TIM PWM MSP. |
1061 | * @param htim : TIM handle |
1384 | * @param htim TIM PWM handle |
1062 | * @retval None |
1385 | * @retval None |
1063 | */ |
1386 | */ |
1064 | __weak void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef *htim) |
1387 | __weak void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef *htim) |
1065 | { |
1388 | { |
1066 | /* Prevent unused argument(s) compilation warning */ |
1389 | /* Prevent unused argument(s) compilation warning */ |
1067 | UNUSED(htim); |
1390 | UNUSED(htim); |
- | 1391 | ||
1068 | /* NOTE : This function Should not be modified, when the callback is needed, |
1392 | /* NOTE : This function should not be modified, when the callback is needed, |
1069 | the HAL_TIM_PWM_MspInit could be implemented in the user file |
1393 | the HAL_TIM_PWM_MspInit could be implemented in the user file |
1070 | */ |
1394 | */ |
1071 | } |
1395 | } |
1072 | 1396 | ||
1073 | /** |
1397 | /** |
1074 | * @brief DeInitializes TIM PWM MSP. |
1398 | * @brief DeInitializes TIM PWM MSP. |
1075 | * @param htim : TIM handle |
1399 | * @param htim TIM PWM handle |
1076 | * @retval None |
1400 | * @retval None |
1077 | */ |
1401 | */ |
1078 | __weak void HAL_TIM_PWM_MspDeInit(TIM_HandleTypeDef *htim) |
1402 | __weak void HAL_TIM_PWM_MspDeInit(TIM_HandleTypeDef *htim) |
1079 | { |
1403 | { |
1080 | /* Prevent unused argument(s) compilation warning */ |
1404 | /* Prevent unused argument(s) compilation warning */ |
1081 | UNUSED(htim); |
1405 | UNUSED(htim); |
- | 1406 | ||
1082 | /* NOTE : This function Should not be modified, when the callback is needed, |
1407 | /* NOTE : This function should not be modified, when the callback is needed, |
1083 | the HAL_TIM_PWM_MspDeInit could be implemented in the user file |
1408 | the HAL_TIM_PWM_MspDeInit could be implemented in the user file |
1084 | */ |
1409 | */ |
1085 | } |
1410 | } |
1086 | 1411 | ||
1087 | /** |
1412 | /** |
1088 | * @brief Starts the PWM signal generation. |
1413 | * @brief Starts the PWM signal generation. |
1089 | * @param htim : TIM handle |
1414 | * @param htim TIM handle |
1090 | * @param Channel : TIM Channels to be enabled |
1415 | * @param Channel TIM Channels to be enabled |
1091 | * This parameter can be one of the following values: |
1416 | * This parameter can be one of the following values: |
1092 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
1417 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
1093 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
1418 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
1094 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
1419 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
1095 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
1420 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
1096 | * @retval HAL status |
1421 | * @retval HAL status |
1097 | */ |
1422 | */ |
1098 | HAL_StatusTypeDef HAL_TIM_PWM_Start(TIM_HandleTypeDef *htim, uint32_t Channel) |
1423 | HAL_StatusTypeDef HAL_TIM_PWM_Start(TIM_HandleTypeDef *htim, uint32_t Channel) |
1099 | { |
1424 | { |
- | 1425 | uint32_t tmpsmcr; |
|
- | 1426 | ||
1100 | /* Check the parameters */ |
1427 | /* Check the parameters */ |
1101 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
1428 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
1102 | 1429 | ||
- | 1430 | /* Check the TIM channel state */ |
|
- | 1431 | if (TIM_CHANNEL_STATE_GET(htim, Channel) != HAL_TIM_CHANNEL_STATE_READY) |
|
- | 1432 | { |
|
- | 1433 | return HAL_ERROR; |
|
- | 1434 | } |
|
- | 1435 | ||
- | 1436 | /* Set the TIM channel state */ |
|
- | 1437 | TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_BUSY); |
|
- | 1438 | ||
1103 | /* Enable the Capture compare channel */ |
1439 | /* Enable the Capture compare channel */ |
1104 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE); |
1440 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE); |
1105 | 1441 | ||
1106 | if(IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET) |
1442 | if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET) |
1107 | { |
1443 | { |
1108 | /* Enable the main output */ |
1444 | /* Enable the main output */ |
1109 | __HAL_TIM_MOE_ENABLE(htim); |
1445 | __HAL_TIM_MOE_ENABLE(htim); |
1110 | } |
1446 | } |
1111 | 1447 | ||
- | 1448 | /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */ |
|
- | 1449 | if (IS_TIM_SLAVE_INSTANCE(htim->Instance)) |
|
- | 1450 | { |
|
- | 1451 | tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS; |
|
- | 1452 | if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr)) |
|
- | 1453 | { |
|
1112 | /* Enable the Peripheral */ |
1454 | __HAL_TIM_ENABLE(htim); |
- | 1455 | } |
|
- | 1456 | } |
|
- | 1457 | else |
|
- | 1458 | { |
|
1113 | __HAL_TIM_ENABLE(htim); |
1459 | __HAL_TIM_ENABLE(htim); |
- | 1460 | } |
|
1114 | 1461 | ||
1115 | /* Return function status */ |
1462 | /* Return function status */ |
1116 | return HAL_OK; |
1463 | return HAL_OK; |
1117 | } |
1464 | } |
1118 | 1465 | ||
1119 | /** |
1466 | /** |
1120 | * @brief Stops the PWM signal generation. |
1467 | * @brief Stops the PWM signal generation. |
1121 | * @param htim : TIM handle |
1468 | * @param htim TIM PWM handle |
1122 | * @param Channel : TIM Channels to be disabled |
1469 | * @param Channel TIM Channels to be disabled |
1123 | * This parameter can be one of the following values: |
1470 | * This parameter can be one of the following values: |
1124 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
1471 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
1125 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
1472 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
1126 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
1473 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
1127 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
1474 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
1128 | * @retval HAL status |
1475 | * @retval HAL status |
1129 | */ |
1476 | */ |
1130 | HAL_StatusTypeDef HAL_TIM_PWM_Stop(TIM_HandleTypeDef *htim, uint32_t Channel) |
1477 | HAL_StatusTypeDef HAL_TIM_PWM_Stop(TIM_HandleTypeDef *htim, uint32_t Channel) |
1131 | { |
1478 | { |
1132 | /* Check the parameters */ |
1479 | /* Check the parameters */ |
1133 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
1480 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
1134 | 1481 | ||
1135 | /* Disable the Capture compare channel */ |
1482 | /* Disable the Capture compare channel */ |
1136 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE); |
1483 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE); |
1137 | 1484 | ||
1138 | if(IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET) |
1485 | if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET) |
1139 | { |
1486 | { |
1140 | /* Disable the Main Ouput */ |
1487 | /* Disable the Main Output */ |
1141 | __HAL_TIM_MOE_DISABLE(htim); |
1488 | __HAL_TIM_MOE_DISABLE(htim); |
1142 | } |
1489 | } |
1143 | 1490 | ||
1144 | /* Disable the Peripheral */ |
1491 | /* Disable the Peripheral */ |
1145 | __HAL_TIM_DISABLE(htim); |
1492 | __HAL_TIM_DISABLE(htim); |
1146 | 1493 | ||
1147 | /* Change the htim state */ |
1494 | /* Set the TIM channel state */ |
1148 | htim->State = HAL_TIM_STATE_READY; |
1495 | TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY); |
1149 | 1496 | ||
1150 | /* Return function status */ |
1497 | /* Return function status */ |
1151 | return HAL_OK; |
1498 | return HAL_OK; |
1152 | } |
1499 | } |
1153 | 1500 | ||
1154 | /** |
1501 | /** |
1155 | * @brief Starts the PWM signal generation in interrupt mode. |
1502 | * @brief Starts the PWM signal generation in interrupt mode. |
1156 | * @param htim : TIM handle |
1503 | * @param htim TIM PWM handle |
1157 | * @param Channel : TIM Channel to be enabled |
1504 | * @param Channel TIM Channel to be enabled |
1158 | * This parameter can be one of the following values: |
1505 | * This parameter can be one of the following values: |
1159 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
1506 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
1160 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
1507 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
1161 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
1508 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
1162 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
1509 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
1163 | * @retval HAL status |
1510 | * @retval HAL status |
1164 | */ |
1511 | */ |
1165 | HAL_StatusTypeDef HAL_TIM_PWM_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel) |
1512 | HAL_StatusTypeDef HAL_TIM_PWM_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel) |
1166 | { |
1513 | { |
- | 1514 | uint32_t tmpsmcr; |
|
1167 | /* Check the parameters */ |
1515 | /* Check the parameters */ |
1168 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
1516 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
1169 | 1517 | ||
- | 1518 | /* Check the TIM channel state */ |
|
- | 1519 | if (TIM_CHANNEL_STATE_GET(htim, Channel) != HAL_TIM_CHANNEL_STATE_READY) |
|
- | 1520 | { |
|
- | 1521 | return HAL_ERROR; |
|
- | 1522 | } |
|
- | 1523 | ||
- | 1524 | /* Set the TIM channel state */ |
|
- | 1525 | TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_BUSY); |
|
- | 1526 | ||
1170 | switch (Channel) |
1527 | switch (Channel) |
1171 | { |
1528 | { |
1172 | case TIM_CHANNEL_1: |
1529 | case TIM_CHANNEL_1: |
1173 | { |
1530 | { |
1174 | /* Enable the TIM Capture/Compare 1 interrupt */ |
1531 | /* Enable the TIM Capture/Compare 1 interrupt */ |
1175 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1); |
1532 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1); |
- | 1533 | break; |
|
1176 | } |
1534 | } |
1177 | break; |
- | |
1178 | 1535 | ||
1179 | case TIM_CHANNEL_2: |
1536 | case TIM_CHANNEL_2: |
1180 | { |
1537 | { |
1181 | /* Enable the TIM Capture/Compare 2 interrupt */ |
1538 | /* Enable the TIM Capture/Compare 2 interrupt */ |
1182 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2); |
1539 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2); |
- | 1540 | break; |
|
1183 | } |
1541 | } |
1184 | break; |
- | |
1185 | 1542 | ||
1186 | case TIM_CHANNEL_3: |
1543 | case TIM_CHANNEL_3: |
1187 | { |
1544 | { |
1188 | /* Enable the TIM Capture/Compare 3 interrupt */ |
1545 | /* Enable the TIM Capture/Compare 3 interrupt */ |
1189 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC3); |
1546 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC3); |
- | 1547 | break; |
|
1190 | } |
1548 | } |
1191 | break; |
- | |
1192 | 1549 | ||
1193 | case TIM_CHANNEL_4: |
1550 | case TIM_CHANNEL_4: |
1194 | { |
1551 | { |
1195 | /* Enable the TIM Capture/Compare 4 interrupt */ |
1552 | /* Enable the TIM Capture/Compare 4 interrupt */ |
1196 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC4); |
1553 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC4); |
- | 1554 | break; |
|
1197 | } |
1555 | } |
1198 | break; |
- | |
1199 | 1556 | ||
1200 | default: |
1557 | default: |
1201 | break; |
1558 | break; |
1202 | } |
1559 | } |
1203 | 1560 | ||
1204 | /* Enable the Capture compare channel */ |
1561 | /* Enable the Capture compare channel */ |
1205 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE); |
1562 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE); |
1206 | 1563 | ||
1207 | if(IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET) |
1564 | if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET) |
1208 | { |
1565 | { |
1209 | /* Enable the main output */ |
1566 | /* Enable the main output */ |
1210 | __HAL_TIM_MOE_ENABLE(htim); |
1567 | __HAL_TIM_MOE_ENABLE(htim); |
1211 | } |
1568 | } |
1212 | 1569 | ||
- | 1570 | /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */ |
|
- | 1571 | if (IS_TIM_SLAVE_INSTANCE(htim->Instance)) |
|
- | 1572 | { |
|
- | 1573 | tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS; |
|
- | 1574 | if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr)) |
|
- | 1575 | { |
|
1213 | /* Enable the Peripheral */ |
1576 | __HAL_TIM_ENABLE(htim); |
- | 1577 | } |
|
- | 1578 | } |
|
- | 1579 | else |
|
- | 1580 | { |
|
1214 | __HAL_TIM_ENABLE(htim); |
1581 | __HAL_TIM_ENABLE(htim); |
- | 1582 | } |
|
1215 | 1583 | ||
1216 | /* Return function status */ |
1584 | /* Return function status */ |
1217 | return HAL_OK; |
1585 | return HAL_OK; |
1218 | } |
1586 | } |
1219 | 1587 | ||
1220 | /** |
1588 | /** |
1221 | * @brief Stops the PWM signal generation in interrupt mode. |
1589 | * @brief Stops the PWM signal generation in interrupt mode. |
1222 | * @param htim : TIM handle |
1590 | * @param htim TIM PWM handle |
1223 | * @param Channel : TIM Channels to be disabled |
1591 | * @param Channel TIM Channels to be disabled |
1224 | * This parameter can be one of the following values: |
1592 | * This parameter can be one of the following values: |
1225 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
1593 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
1226 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
1594 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
1227 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
1595 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
1228 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
1596 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
1229 | * @retval HAL status |
1597 | * @retval HAL status |
1230 | */ |
1598 | */ |
1231 | HAL_StatusTypeDef HAL_TIM_PWM_Stop_IT (TIM_HandleTypeDef *htim, uint32_t Channel) |
1599 | HAL_StatusTypeDef HAL_TIM_PWM_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel) |
1232 | { |
1600 | { |
1233 | /* Check the parameters */ |
1601 | /* Check the parameters */ |
1234 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
1602 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
1235 | 1603 | ||
1236 | switch (Channel) |
1604 | switch (Channel) |
1237 | { |
1605 | { |
1238 | case TIM_CHANNEL_1: |
1606 | case TIM_CHANNEL_1: |
1239 | { |
1607 | { |
1240 | /* Disable the TIM Capture/Compare 1 interrupt */ |
1608 | /* Disable the TIM Capture/Compare 1 interrupt */ |
1241 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1); |
1609 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1); |
- | 1610 | break; |
|
1242 | } |
1611 | } |
1243 | break; |
- | |
1244 | 1612 | ||
1245 | case TIM_CHANNEL_2: |
1613 | case TIM_CHANNEL_2: |
1246 | { |
1614 | { |
1247 | /* Disable the TIM Capture/Compare 2 interrupt */ |
1615 | /* Disable the TIM Capture/Compare 2 interrupt */ |
1248 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2); |
1616 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2); |
- | 1617 | break; |
|
1249 | } |
1618 | } |
1250 | break; |
- | |
1251 | 1619 | ||
1252 | case TIM_CHANNEL_3: |
1620 | case TIM_CHANNEL_3: |
1253 | { |
1621 | { |
1254 | /* Disable the TIM Capture/Compare 3 interrupt */ |
1622 | /* Disable the TIM Capture/Compare 3 interrupt */ |
1255 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC3); |
1623 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC3); |
- | 1624 | break; |
|
1256 | } |
1625 | } |
1257 | break; |
- | |
1258 | 1626 | ||
1259 | case TIM_CHANNEL_4: |
1627 | case TIM_CHANNEL_4: |
1260 | { |
1628 | { |
1261 | /* Disable the TIM Capture/Compare 4 interrupt */ |
1629 | /* Disable the TIM Capture/Compare 4 interrupt */ |
1262 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC4); |
1630 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC4); |
- | 1631 | break; |
|
1263 | } |
1632 | } |
1264 | break; |
- | |
1265 | 1633 | ||
1266 | default: |
1634 | default: |
1267 | break; |
1635 | break; |
1268 | } |
1636 | } |
1269 | 1637 | ||
1270 | /* Disable the Capture compare channel */ |
1638 | /* Disable the Capture compare channel */ |
1271 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE); |
1639 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE); |
1272 | 1640 | ||
1273 | if(IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET) |
1641 | if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET) |
1274 | { |
1642 | { |
1275 | /* Disable the Main Ouput */ |
1643 | /* Disable the Main Output */ |
1276 | __HAL_TIM_MOE_DISABLE(htim); |
1644 | __HAL_TIM_MOE_DISABLE(htim); |
1277 | } |
1645 | } |
1278 | 1646 | ||
1279 | /* Disable the Peripheral */ |
1647 | /* Disable the Peripheral */ |
1280 | __HAL_TIM_DISABLE(htim); |
1648 | __HAL_TIM_DISABLE(htim); |
1281 | 1649 | ||
- | 1650 | /* Set the TIM channel state */ |
|
- | 1651 | TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY); |
|
- | 1652 | ||
1282 | /* Return function status */ |
1653 | /* Return function status */ |
1283 | return HAL_OK; |
1654 | return HAL_OK; |
1284 | } |
1655 | } |
1285 | 1656 | ||
1286 | /** |
1657 | /** |
1287 | * @brief Starts the TIM PWM signal generation in DMA mode. |
1658 | * @brief Starts the TIM PWM signal generation in DMA mode. |
1288 | * @param htim : TIM handle |
1659 | * @param htim TIM PWM handle |
1289 | * @param Channel : TIM Channels to be enabled |
1660 | * @param Channel TIM Channels to be enabled |
1290 | * This parameter can be one of the following values: |
1661 | * This parameter can be one of the following values: |
1291 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
1662 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
1292 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
1663 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
1293 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
1664 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
1294 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
1665 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
1295 | * @param pData : The source Buffer address. |
1666 | * @param pData The source Buffer address. |
1296 | * @param Length : The length of data to be transferred from memory to TIM peripheral |
1667 | * @param Length The length of data to be transferred from memory to TIM peripheral |
1297 | * @retval HAL status |
1668 | * @retval HAL status |
1298 | */ |
1669 | */ |
1299 | HAL_StatusTypeDef HAL_TIM_PWM_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length) |
1670 | HAL_StatusTypeDef HAL_TIM_PWM_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length) |
1300 | { |
1671 | { |
- | 1672 | uint32_t tmpsmcr; |
|
- | 1673 | ||
1301 | /* Check the parameters */ |
1674 | /* Check the parameters */ |
1302 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
1675 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
1303 | 1676 | ||
- | 1677 | /* Set the TIM channel state */ |
|
1304 | if((htim->State == HAL_TIM_STATE_BUSY)) |
1678 | if (TIM_CHANNEL_STATE_GET(htim, Channel) == HAL_TIM_CHANNEL_STATE_BUSY) |
1305 | { |
1679 | { |
1306 | return HAL_BUSY; |
1680 | return HAL_BUSY; |
1307 | } |
1681 | } |
1308 | else if((htim->State == HAL_TIM_STATE_READY)) |
1682 | else if (TIM_CHANNEL_STATE_GET(htim, Channel) == HAL_TIM_CHANNEL_STATE_READY) |
1309 | { |
1683 | { |
1310 | if(((uint32_t)pData == 0U) && (Length > 0U)) |
1684 | if ((pData == NULL) && (Length > 0U)) |
1311 | { |
1685 | { |
1312 | return HAL_ERROR; |
1686 | return HAL_ERROR; |
1313 | } |
1687 | } |
1314 | else |
1688 | else |
1315 | { |
1689 | { |
1316 | htim->State = HAL_TIM_STATE_BUSY; |
1690 | TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_BUSY); |
1317 | } |
1691 | } |
1318 | } |
1692 | } |
- | 1693 | else |
|
- | 1694 | { |
|
- | 1695 | return HAL_ERROR; |
|
- | 1696 | } |
|
- | 1697 | ||
1319 | switch (Channel) |
1698 | switch (Channel) |
1320 | { |
1699 | { |
1321 | case TIM_CHANNEL_1: |
1700 | case TIM_CHANNEL_1: |
1322 | { |
1701 | { |
1323 | /* Set the DMA Period elapsed callback */ |
1702 | /* Set the DMA compare callbacks */ |
1324 | htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMADelayPulseCplt; |
1703 | htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMADelayPulseCplt; |
- | 1704 | htim->hdma[TIM_DMA_ID_CC1]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt; |
|
1325 | 1705 | ||
1326 | /* Set the DMA error callback */ |
1706 | /* Set the DMA error callback */ |
1327 | htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ; |
1707 | htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ; |
1328 | 1708 | ||
1329 | /* Enable the DMA channel */ |
1709 | /* Enable the DMA channel */ |
1330 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)pData, (uint32_t)&htim->Instance->CCR1, Length); |
1710 | if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)pData, (uint32_t)&htim->Instance->CCR1, Length) != HAL_OK) |
- | 1711 | { |
|
- | 1712 | /* Return error status */ |
|
- | 1713 | return HAL_ERROR; |
|
- | 1714 | } |
|
1331 | 1715 | ||
1332 | /* Enable the TIM Capture/Compare 1 DMA request */ |
1716 | /* Enable the TIM Capture/Compare 1 DMA request */ |
1333 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1); |
1717 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1); |
- | 1718 | break; |
|
1334 | } |
1719 | } |
1335 | break; |
- | |
1336 | 1720 | ||
1337 | case TIM_CHANNEL_2: |
1721 | case TIM_CHANNEL_2: |
1338 | { |
1722 | { |
1339 | /* Set the DMA Period elapsed callback */ |
1723 | /* Set the DMA compare callbacks */ |
1340 | htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMADelayPulseCplt; |
1724 | htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMADelayPulseCplt; |
- | 1725 | htim->hdma[TIM_DMA_ID_CC2]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt; |
|
1341 | 1726 | ||
1342 | /* Set the DMA error callback */ |
1727 | /* Set the DMA error callback */ |
1343 | htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError ; |
1728 | htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError ; |
1344 | 1729 | ||
1345 | /* Enable the DMA channel */ |
1730 | /* Enable the DMA channel */ |
1346 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)pData, (uint32_t)&htim->Instance->CCR2, Length); |
1731 | if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)pData, (uint32_t)&htim->Instance->CCR2, Length) != HAL_OK) |
- | 1732 | { |
|
- | 1733 | /* Return error status */ |
|
- | 1734 | return HAL_ERROR; |
|
1347 | 1735 | } |
|
1348 | /* Enable the TIM Capture/Compare 2 DMA request */ |
1736 | /* Enable the TIM Capture/Compare 2 DMA request */ |
1349 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2); |
1737 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2); |
- | 1738 | break; |
|
1350 | } |
1739 | } |
1351 | break; |
- | |
1352 | 1740 | ||
1353 | case TIM_CHANNEL_3: |
1741 | case TIM_CHANNEL_3: |
1354 | { |
1742 | { |
1355 | /* Set the DMA Period elapsed callback */ |
1743 | /* Set the DMA compare callbacks */ |
1356 | htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMADelayPulseCplt; |
1744 | htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMADelayPulseCplt; |
- | 1745 | htim->hdma[TIM_DMA_ID_CC3]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt; |
|
1357 | 1746 | ||
1358 | /* Set the DMA error callback */ |
1747 | /* Set the DMA error callback */ |
1359 | htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = TIM_DMAError ; |
1748 | htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = TIM_DMAError ; |
1360 | 1749 | ||
1361 | /* Enable the DMA channel */ |
1750 | /* Enable the DMA channel */ |
1362 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)pData, (uint32_t)&htim->Instance->CCR3,Length); |
1751 | if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)pData, (uint32_t)&htim->Instance->CCR3, Length) != HAL_OK) |
- | 1752 | { |
|
- | 1753 | /* Return error status */ |
|
- | 1754 | return HAL_ERROR; |
|
1363 | 1755 | } |
|
1364 | /* Enable the TIM Output Capture/Compare 3 request */ |
1756 | /* Enable the TIM Output Capture/Compare 3 request */ |
1365 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC3); |
1757 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC3); |
- | 1758 | break; |
|
1366 | } |
1759 | } |
1367 | break; |
- | |
1368 | 1760 | ||
1369 | case TIM_CHANNEL_4: |
1761 | case TIM_CHANNEL_4: |
1370 | { |
1762 | { |
1371 | /* Set the DMA Period elapsed callback */ |
1763 | /* Set the DMA compare callbacks */ |
1372 | htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = TIM_DMADelayPulseCplt; |
1764 | htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = TIM_DMADelayPulseCplt; |
- | 1765 | htim->hdma[TIM_DMA_ID_CC4]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt; |
|
1373 | 1766 | ||
1374 | /* Set the DMA error callback */ |
1767 | /* Set the DMA error callback */ |
1375 | htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = TIM_DMAError ; |
1768 | htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = TIM_DMAError ; |
1376 | 1769 | ||
1377 | /* Enable the DMA channel */ |
1770 | /* Enable the DMA channel */ |
1378 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)pData, (uint32_t)&htim->Instance->CCR4, Length); |
1771 | if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)pData, (uint32_t)&htim->Instance->CCR4, Length) != HAL_OK) |
- | 1772 | { |
|
- | 1773 | /* Return error status */ |
|
- | 1774 | return HAL_ERROR; |
|
1379 | 1775 | } |
|
1380 | /* Enable the TIM Capture/Compare 4 DMA request */ |
1776 | /* Enable the TIM Capture/Compare 4 DMA request */ |
1381 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC4); |
1777 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC4); |
- | 1778 | break; |
|
1382 | } |
1779 | } |
1383 | break; |
- | |
1384 | 1780 | ||
1385 | default: |
1781 | default: |
1386 | break; |
1782 | break; |
1387 | } |
1783 | } |
1388 | 1784 | ||
1389 | /* Enable the Capture compare channel */ |
1785 | /* Enable the Capture compare channel */ |
1390 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE); |
1786 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE); |
1391 | 1787 | ||
1392 | if(IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET) |
1788 | if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET) |
1393 | { |
1789 | { |
1394 | /* Enable the main output */ |
1790 | /* Enable the main output */ |
1395 | __HAL_TIM_MOE_ENABLE(htim); |
1791 | __HAL_TIM_MOE_ENABLE(htim); |
1396 | } |
1792 | } |
1397 | 1793 | ||
- | 1794 | /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */ |
|
- | 1795 | if (IS_TIM_SLAVE_INSTANCE(htim->Instance)) |
|
- | 1796 | { |
|
- | 1797 | tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS; |
|
- | 1798 | if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr)) |
|
- | 1799 | { |
|
1398 | /* Enable the Peripheral */ |
1800 | __HAL_TIM_ENABLE(htim); |
- | 1801 | } |
|
- | 1802 | } |
|
- | 1803 | else |
|
- | 1804 | { |
|
1399 | __HAL_TIM_ENABLE(htim); |
1805 | __HAL_TIM_ENABLE(htim); |
- | 1806 | } |
|
1400 | 1807 | ||
1401 | /* Return function status */ |
1808 | /* Return function status */ |
1402 | return HAL_OK; |
1809 | return HAL_OK; |
1403 | } |
1810 | } |
1404 | 1811 | ||
1405 | /** |
1812 | /** |
1406 | * @brief Stops the TIM PWM signal generation in DMA mode. |
1813 | * @brief Stops the TIM PWM signal generation in DMA mode. |
1407 | * @param htim : TIM handle |
1814 | * @param htim TIM PWM handle |
1408 | * @param Channel : TIM Channels to be disabled |
1815 | * @param Channel TIM Channels to be disabled |
1409 | * This parameter can be one of the following values: |
1816 | * This parameter can be one of the following values: |
1410 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
1817 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
1411 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
1818 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
1412 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
1819 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
1413 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
1820 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
1414 | * @retval HAL status |
1821 | * @retval HAL status |
1415 | */ |
1822 | */ |
1416 | HAL_StatusTypeDef HAL_TIM_PWM_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel) |
1823 | HAL_StatusTypeDef HAL_TIM_PWM_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel) |
1417 | { |
1824 | { |
1418 | /* Check the parameters */ |
1825 | /* Check the parameters */ |
1419 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
1826 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
1420 | 1827 | ||
Line 1422... | Line 1829... | ||
1422 | { |
1829 | { |
1423 | case TIM_CHANNEL_1: |
1830 | case TIM_CHANNEL_1: |
1424 | { |
1831 | { |
1425 | /* Disable the TIM Capture/Compare 1 DMA request */ |
1832 | /* Disable the TIM Capture/Compare 1 DMA request */ |
1426 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1); |
1833 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1); |
- | 1834 | (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC1]); |
|
- | 1835 | break; |
|
1427 | } |
1836 | } |
1428 | break; |
- | |
1429 | 1837 | ||
1430 | case TIM_CHANNEL_2: |
1838 | case TIM_CHANNEL_2: |
1431 | { |
1839 | { |
1432 | /* Disable the TIM Capture/Compare 2 DMA request */ |
1840 | /* Disable the TIM Capture/Compare 2 DMA request */ |
1433 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2); |
1841 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2); |
- | 1842 | (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC2]); |
|
- | 1843 | break; |
|
1434 | } |
1844 | } |
1435 | break; |
- | |
1436 | 1845 | ||
1437 | case TIM_CHANNEL_3: |
1846 | case TIM_CHANNEL_3: |
1438 | { |
1847 | { |
1439 | /* Disable the TIM Capture/Compare 3 DMA request */ |
1848 | /* Disable the TIM Capture/Compare 3 DMA request */ |
1440 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC3); |
1849 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC3); |
- | 1850 | (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC3]); |
|
- | 1851 | break; |
|
1441 | } |
1852 | } |
1442 | break; |
- | |
1443 | 1853 | ||
1444 | case TIM_CHANNEL_4: |
1854 | case TIM_CHANNEL_4: |
1445 | { |
1855 | { |
1446 | /* Disable the TIM Capture/Compare 4 interrupt */ |
1856 | /* Disable the TIM Capture/Compare 4 interrupt */ |
1447 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC4); |
1857 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC4); |
- | 1858 | (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC4]); |
|
- | 1859 | break; |
|
1448 | } |
1860 | } |
1449 | break; |
- | |
1450 | 1861 | ||
1451 | default: |
1862 | default: |
1452 | break; |
1863 | break; |
1453 | } |
1864 | } |
1454 | 1865 | ||
1455 | /* Disable the Capture compare channel */ |
1866 | /* Disable the Capture compare channel */ |
1456 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE); |
1867 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE); |
1457 | 1868 | ||
1458 | if(IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET) |
1869 | if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET) |
1459 | { |
1870 | { |
1460 | /* Disable the Main Ouput */ |
1871 | /* Disable the Main Output */ |
1461 | __HAL_TIM_MOE_DISABLE(htim); |
1872 | __HAL_TIM_MOE_DISABLE(htim); |
1462 | } |
1873 | } |
1463 | 1874 | ||
1464 | /* Disable the Peripheral */ |
1875 | /* Disable the Peripheral */ |
1465 | __HAL_TIM_DISABLE(htim); |
1876 | __HAL_TIM_DISABLE(htim); |
1466 | 1877 | ||
1467 | /* Change the htim state */ |
1878 | /* Set the TIM channel state */ |
1468 | htim->State = HAL_TIM_STATE_READY; |
1879 | TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY); |
1469 | 1880 | ||
1470 | /* Return function status */ |
1881 | /* Return function status */ |
1471 | return HAL_OK; |
1882 | return HAL_OK; |
1472 | } |
1883 | } |
1473 | 1884 | ||
1474 | /** |
1885 | /** |
1475 | * @} |
1886 | * @} |
1476 | */ |
1887 | */ |
1477 | 1888 | ||
1478 | /** @defgroup TIM_Exported_Functions_Group4 Time Input Capture functions |
1889 | /** @defgroup TIM_Exported_Functions_Group4 TIM Input Capture functions |
1479 | * @brief Time Input Capture functions |
1890 | * @brief TIM Input Capture functions |
1480 | * |
1891 | * |
1481 | @verbatim |
1892 | @verbatim |
1482 | ============================================================================== |
1893 | ============================================================================== |
1483 | ##### Time Input Capture functions ##### |
1894 | ##### TIM Input Capture functions ##### |
1484 | ============================================================================== |
1895 | ============================================================================== |
1485 | [..] |
1896 | [..] |
1486 | This section provides functions allowing to: |
1897 | This section provides functions allowing to: |
1487 | (+) Initialize and configure the TIM Input Capture. |
1898 | (+) Initialize and configure the TIM Input Capture. |
1488 | (+) De-initialize the TIM Input Capture. |
1899 | (+) De-initialize the TIM Input Capture. |
1489 | (+) Start the Time Input Capture. |
1900 | (+) Start the TIM Input Capture. |
1490 | (+) Stop the Time Input Capture. |
1901 | (+) Stop the TIM Input Capture. |
1491 | (+) Start the Time Input Capture and enable interrupt. |
1902 | (+) Start the TIM Input Capture and enable interrupt. |
1492 | (+) Stop the Time Input Capture and disable interrupt. |
1903 | (+) Stop the TIM Input Capture and disable interrupt. |
1493 | (+) Start the Time Input Capture and enable DMA transfer. |
1904 | (+) Start the TIM Input Capture and enable DMA transfer. |
1494 | (+) Stop the Time Input Capture and disable DMA transfer. |
1905 | (+) Stop the TIM Input Capture and disable DMA transfer. |
1495 | 1906 | ||
1496 | @endverbatim |
1907 | @endverbatim |
1497 | * @{ |
1908 | * @{ |
1498 | */ |
1909 | */ |
1499 | /** |
1910 | /** |
1500 | * @brief Initializes the TIM Input Capture Time base according to the specified |
1911 | * @brief Initializes the TIM Input Capture Time base according to the specified |
1501 | * parameters in the TIM_HandleTypeDef and create the associated handle. |
1912 | * parameters in the TIM_HandleTypeDef and initializes the associated handle. |
1502 | * @note Switching from Center Aligned counter mode to Edge counter mode (or reverse) |
1913 | * @note Switching from Center Aligned counter mode to Edge counter mode (or reverse) |
1503 | * requires a timer reset to avoid unexpected direction |
1914 | * requires a timer reset to avoid unexpected direction |
1504 | * due to DIR bit readonly in center aligned mode. |
1915 | * due to DIR bit readonly in center aligned mode. |
1505 | * Ex: call @ref HAL_TIM_IC_DeInit() before HAL_TIM_IC_Init() |
1916 | * Ex: call @ref HAL_TIM_IC_DeInit() before HAL_TIM_IC_Init() |
1506 | * @param htim : TIM Input Capture handle |
1917 | * @param htim TIM Input Capture handle |
1507 | * @retval HAL status |
1918 | * @retval HAL status |
1508 | */ |
1919 | */ |
1509 | HAL_StatusTypeDef HAL_TIM_IC_Init(TIM_HandleTypeDef *htim) |
1920 | HAL_StatusTypeDef HAL_TIM_IC_Init(TIM_HandleTypeDef *htim) |
1510 | { |
1921 | { |
1511 | /* Check the TIM handle allocation */ |
1922 | /* Check the TIM handle allocation */ |
1512 | if(htim == NULL) |
1923 | if (htim == NULL) |
1513 | { |
1924 | { |
1514 | return HAL_ERROR; |
1925 | return HAL_ERROR; |
1515 | } |
1926 | } |
1516 | 1927 | ||
1517 | /* Check the parameters */ |
1928 | /* Check the parameters */ |
1518 | assert_param(IS_TIM_INSTANCE(htim->Instance)); |
1929 | assert_param(IS_TIM_INSTANCE(htim->Instance)); |
1519 | assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode)); |
1930 | assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode)); |
1520 | assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision)); |
1931 | assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision)); |
1521 | assert_param(IS_TIM_AUTORELOAD_PRELOAD(htim->Init.AutoReloadPreload)); |
1932 | assert_param(IS_TIM_AUTORELOAD_PRELOAD(htim->Init.AutoReloadPreload)); |
1522 | 1933 | ||
1523 | if(htim->State == HAL_TIM_STATE_RESET) |
1934 | if (htim->State == HAL_TIM_STATE_RESET) |
1524 | { |
1935 | { |
1525 | /* Allocate lock resource and initialize it */ |
1936 | /* Allocate lock resource and initialize it */ |
1526 | htim->Lock = HAL_UNLOCKED; |
1937 | htim->Lock = HAL_UNLOCKED; |
- | 1938 | ||
- | 1939 | #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) |
|
- | 1940 | /* Reset interrupt callbacks to legacy weak callbacks */ |
|
- | 1941 | TIM_ResetCallback(htim); |
|
- | 1942 | ||
- | 1943 | if (htim->IC_MspInitCallback == NULL) |
|
1527 | 1944 | { |
|
- | 1945 | htim->IC_MspInitCallback = HAL_TIM_IC_MspInit; |
|
- | 1946 | } |
|
- | 1947 | /* Init the low level hardware : GPIO, CLOCK, NVIC */ |
|
- | 1948 | htim->IC_MspInitCallback(htim); |
|
- | 1949 | #else |
|
1528 | /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */ |
1950 | /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */ |
1529 | HAL_TIM_IC_MspInit(htim); |
1951 | HAL_TIM_IC_MspInit(htim); |
- | 1952 | #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */ |
|
1530 | } |
1953 | } |
1531 | 1954 | ||
1532 | /* Set the TIM state */ |
1955 | /* Set the TIM state */ |
1533 | htim->State= HAL_TIM_STATE_BUSY; |
1956 | htim->State = HAL_TIM_STATE_BUSY; |
1534 | 1957 | ||
1535 | /* Init the base time for the input capture */ |
1958 | /* Init the base time for the input capture */ |
1536 | TIM_Base_SetConfig(htim->Instance, &htim->Init); |
1959 | TIM_Base_SetConfig(htim->Instance, &htim->Init); |
1537 | 1960 | ||
- | 1961 | /* Initialize the DMA burst operation state */ |
|
- | 1962 | htim->DMABurstState = HAL_DMA_BURST_STATE_READY; |
|
- | 1963 | ||
- | 1964 | /* Initialize the TIM channels state */ |
|
- | 1965 | TIM_CHANNEL_STATE_SET_ALL(htim, HAL_TIM_CHANNEL_STATE_READY); |
|
- | 1966 | TIM_CHANNEL_N_STATE_SET_ALL(htim, HAL_TIM_CHANNEL_STATE_READY); |
|
- | 1967 | ||
1538 | /* Initialize the TIM state*/ |
1968 | /* Initialize the TIM state*/ |
1539 | htim->State= HAL_TIM_STATE_READY; |
1969 | htim->State = HAL_TIM_STATE_READY; |
1540 | 1970 | ||
1541 | return HAL_OK; |
1971 | return HAL_OK; |
1542 | } |
1972 | } |
1543 | 1973 | ||
1544 | /** |
1974 | /** |
1545 | * @brief DeInitializes the TIM peripheral |
1975 | * @brief DeInitializes the TIM peripheral |
1546 | * @param htim : TIM Input Capture handle |
1976 | * @param htim TIM Input Capture handle |
1547 | * @retval HAL status |
1977 | * @retval HAL status |
1548 | */ |
1978 | */ |
1549 | HAL_StatusTypeDef HAL_TIM_IC_DeInit(TIM_HandleTypeDef *htim) |
1979 | HAL_StatusTypeDef HAL_TIM_IC_DeInit(TIM_HandleTypeDef *htim) |
1550 | { |
1980 | { |
1551 | /* Check the parameters */ |
1981 | /* Check the parameters */ |
Line 1554... | Line 1984... | ||
1554 | htim->State = HAL_TIM_STATE_BUSY; |
1984 | htim->State = HAL_TIM_STATE_BUSY; |
1555 | 1985 | ||
1556 | /* Disable the TIM Peripheral Clock */ |
1986 | /* Disable the TIM Peripheral Clock */ |
1557 | __HAL_TIM_DISABLE(htim); |
1987 | __HAL_TIM_DISABLE(htim); |
1558 | 1988 | ||
- | 1989 | #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) |
|
- | 1990 | if (htim->IC_MspDeInitCallback == NULL) |
|
- | 1991 | { |
|
- | 1992 | htim->IC_MspDeInitCallback = HAL_TIM_IC_MspDeInit; |
|
- | 1993 | } |
|
- | 1994 | /* DeInit the low level hardware */ |
|
- | 1995 | htim->IC_MspDeInitCallback(htim); |
|
- | 1996 | #else |
|
1559 | /* DeInit the low level hardware: GPIO, CLOCK, NVIC and DMA */ |
1997 | /* DeInit the low level hardware: GPIO, CLOCK, NVIC and DMA */ |
1560 | HAL_TIM_IC_MspDeInit(htim); |
1998 | HAL_TIM_IC_MspDeInit(htim); |
- | 1999 | #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */ |
|
- | 2000 | ||
- | 2001 | /* Change the DMA burst operation state */ |
|
- | 2002 | htim->DMABurstState = HAL_DMA_BURST_STATE_RESET; |
|
- | 2003 | ||
- | 2004 | /* Change the TIM channels state */ |
|
- | 2005 | TIM_CHANNEL_STATE_SET_ALL(htim, HAL_TIM_CHANNEL_STATE_RESET); |
|
- | 2006 | TIM_CHANNEL_N_STATE_SET_ALL(htim, HAL_TIM_CHANNEL_STATE_RESET); |
|
1561 | 2007 | ||
1562 | /* Change TIM state */ |
2008 | /* Change TIM state */ |
1563 | htim->State = HAL_TIM_STATE_RESET; |
2009 | htim->State = HAL_TIM_STATE_RESET; |
1564 | 2010 | ||
1565 | /* Release Lock */ |
2011 | /* Release Lock */ |
Line 1568... | Line 2014... | ||
1568 | return HAL_OK; |
2014 | return HAL_OK; |
1569 | } |
2015 | } |
1570 | 2016 | ||
1571 | /** |
2017 | /** |
1572 | * @brief Initializes the TIM Input Capture MSP. |
2018 | * @brief Initializes the TIM Input Capture MSP. |
1573 | * @param htim : TIM handle |
2019 | * @param htim TIM Input Capture handle |
1574 | * @retval None |
2020 | * @retval None |
1575 | */ |
2021 | */ |
1576 | __weak void HAL_TIM_IC_MspInit(TIM_HandleTypeDef *htim) |
2022 | __weak void HAL_TIM_IC_MspInit(TIM_HandleTypeDef *htim) |
1577 | { |
2023 | { |
1578 | /* Prevent unused argument(s) compilation warning */ |
2024 | /* Prevent unused argument(s) compilation warning */ |
1579 | UNUSED(htim); |
2025 | UNUSED(htim); |
- | 2026 | ||
1580 | /* NOTE : This function Should not be modified, when the callback is needed, |
2027 | /* NOTE : This function should not be modified, when the callback is needed, |
1581 | the HAL_TIM_IC_MspInit could be implemented in the user file |
2028 | the HAL_TIM_IC_MspInit could be implemented in the user file |
1582 | */ |
2029 | */ |
1583 | } |
2030 | } |
1584 | 2031 | ||
1585 | /** |
2032 | /** |
1586 | * @brief DeInitializes TIM Input Capture MSP. |
2033 | * @brief DeInitializes TIM Input Capture MSP. |
1587 | * @param htim : TIM handle |
2034 | * @param htim TIM handle |
1588 | * @retval None |
2035 | * @retval None |
1589 | */ |
2036 | */ |
1590 | __weak void HAL_TIM_IC_MspDeInit(TIM_HandleTypeDef *htim) |
2037 | __weak void HAL_TIM_IC_MspDeInit(TIM_HandleTypeDef *htim) |
1591 | { |
2038 | { |
1592 | /* Prevent unused argument(s) compilation warning */ |
2039 | /* Prevent unused argument(s) compilation warning */ |
1593 | UNUSED(htim); |
2040 | UNUSED(htim); |
- | 2041 | ||
1594 | /* NOTE : This function Should not be modified, when the callback is needed, |
2042 | /* NOTE : This function should not be modified, when the callback is needed, |
1595 | the HAL_TIM_IC_MspDeInit could be implemented in the user file |
2043 | the HAL_TIM_IC_MspDeInit could be implemented in the user file |
1596 | */ |
2044 | */ |
1597 | } |
2045 | } |
1598 | 2046 | ||
1599 | /** |
2047 | /** |
1600 | * @brief Starts the TIM Input Capture measurement. |
2048 | * @brief Starts the TIM Input Capture measurement. |
1601 | * @param htim : TIM Input Capture handle |
2049 | * @param htim TIM Input Capture handle |
1602 | * @param Channel : TIM Channels to be enabled |
2050 | * @param Channel TIM Channels to be enabled |
1603 | * This parameter can be one of the following values: |
2051 | * This parameter can be one of the following values: |
1604 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
2052 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
1605 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
2053 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
1606 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
2054 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
1607 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
2055 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
1608 | * @retval HAL status |
2056 | * @retval HAL status |
1609 | */ |
2057 | */ |
1610 | HAL_StatusTypeDef HAL_TIM_IC_Start (TIM_HandleTypeDef *htim, uint32_t Channel) |
2058 | HAL_StatusTypeDef HAL_TIM_IC_Start(TIM_HandleTypeDef *htim, uint32_t Channel) |
1611 | { |
2059 | { |
- | 2060 | uint32_t tmpsmcr; |
|
- | 2061 | HAL_TIM_ChannelStateTypeDef channel_state = TIM_CHANNEL_STATE_GET(htim, Channel); |
|
- | 2062 | HAL_TIM_ChannelStateTypeDef complementary_channel_state = TIM_CHANNEL_N_STATE_GET(htim, Channel); |
|
- | 2063 | ||
1612 | /* Check the parameters */ |
2064 | /* Check the parameters */ |
1613 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
2065 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
1614 | 2066 | ||
- | 2067 | /* Check the TIM channel state */ |
|
- | 2068 | if ((channel_state != HAL_TIM_CHANNEL_STATE_READY) |
|
- | 2069 | || (complementary_channel_state != HAL_TIM_CHANNEL_STATE_READY)) |
|
- | 2070 | { |
|
- | 2071 | return HAL_ERROR; |
|
- | 2072 | } |
|
- | 2073 | ||
- | 2074 | /* Set the TIM channel state */ |
|
- | 2075 | TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_BUSY); |
|
- | 2076 | TIM_CHANNEL_N_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_BUSY); |
|
- | 2077 | ||
1615 | /* Enable the Input Capture channel */ |
2078 | /* Enable the Input Capture channel */ |
1616 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE); |
2079 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE); |
1617 | 2080 | ||
- | 2081 | /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */ |
|
- | 2082 | if (IS_TIM_SLAVE_INSTANCE(htim->Instance)) |
|
- | 2083 | { |
|
- | 2084 | tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS; |
|
- | 2085 | if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr)) |
|
- | 2086 | { |
|
1618 | /* Enable the Peripheral */ |
2087 | __HAL_TIM_ENABLE(htim); |
- | 2088 | } |
|
- | 2089 | } |
|
- | 2090 | else |
|
- | 2091 | { |
|
1619 | __HAL_TIM_ENABLE(htim); |
2092 | __HAL_TIM_ENABLE(htim); |
- | 2093 | } |
|
1620 | 2094 | ||
1621 | /* Return function status */ |
2095 | /* Return function status */ |
1622 | return HAL_OK; |
2096 | return HAL_OK; |
1623 | } |
2097 | } |
1624 | 2098 | ||
1625 | /** |
2099 | /** |
1626 | * @brief Stops the TIM Input Capture measurement. |
2100 | * @brief Stops the TIM Input Capture measurement. |
1627 | * @param htim : TIM handle |
2101 | * @param htim TIM Input Capture handle |
1628 | * @param Channel : TIM Channels to be disabled |
2102 | * @param Channel TIM Channels to be disabled |
1629 | * This parameter can be one of the following values: |
2103 | * This parameter can be one of the following values: |
1630 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
2104 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
1631 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
2105 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
1632 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
2106 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
1633 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
2107 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
1634 | * @retval HAL status |
2108 | * @retval HAL status |
1635 | */ |
2109 | */ |
1636 | HAL_StatusTypeDef HAL_TIM_IC_Stop(TIM_HandleTypeDef *htim, uint32_t Channel) |
2110 | HAL_StatusTypeDef HAL_TIM_IC_Stop(TIM_HandleTypeDef *htim, uint32_t Channel) |
1637 | { |
2111 | { |
1638 | /* Check the parameters */ |
2112 | /* Check the parameters */ |
1639 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
2113 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
1640 | 2114 | ||
Line 1642... | Line 2116... | ||
1642 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE); |
2116 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE); |
1643 | 2117 | ||
1644 | /* Disable the Peripheral */ |
2118 | /* Disable the Peripheral */ |
1645 | __HAL_TIM_DISABLE(htim); |
2119 | __HAL_TIM_DISABLE(htim); |
1646 | 2120 | ||
- | 2121 | /* Set the TIM channel state */ |
|
- | 2122 | TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY); |
|
- | 2123 | TIM_CHANNEL_N_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY); |
|
- | 2124 | ||
1647 | /* Return function status */ |
2125 | /* Return function status */ |
1648 | return HAL_OK; |
2126 | return HAL_OK; |
1649 | } |
2127 | } |
1650 | 2128 | ||
1651 | /** |
2129 | /** |
1652 | * @brief Starts the TIM Input Capture measurement in interrupt mode. |
2130 | * @brief Starts the TIM Input Capture measurement in interrupt mode. |
1653 | * @param htim : TIM Input Capture handle |
2131 | * @param htim TIM Input Capture handle |
1654 | * @param Channel : TIM Channels to be enabled |
2132 | * @param Channel TIM Channels to be enabled |
1655 | * This parameter can be one of the following values: |
2133 | * This parameter can be one of the following values: |
1656 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
2134 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
1657 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
2135 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
1658 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
2136 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
1659 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
2137 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
1660 | * @retval HAL status |
2138 | * @retval HAL status |
1661 | */ |
2139 | */ |
1662 | HAL_StatusTypeDef HAL_TIM_IC_Start_IT (TIM_HandleTypeDef *htim, uint32_t Channel) |
2140 | HAL_StatusTypeDef HAL_TIM_IC_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel) |
1663 | { |
2141 | { |
- | 2142 | uint32_t tmpsmcr; |
|
- | 2143 | HAL_TIM_ChannelStateTypeDef channel_state = TIM_CHANNEL_STATE_GET(htim, Channel); |
|
- | 2144 | HAL_TIM_ChannelStateTypeDef complementary_channel_state = TIM_CHANNEL_N_STATE_GET(htim, Channel); |
|
- | 2145 | ||
1664 | /* Check the parameters */ |
2146 | /* Check the parameters */ |
1665 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
2147 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
1666 | 2148 | ||
- | 2149 | /* Check the TIM channel state */ |
|
- | 2150 | if ((channel_state != HAL_TIM_CHANNEL_STATE_READY) |
|
- | 2151 | || (complementary_channel_state != HAL_TIM_CHANNEL_STATE_READY)) |
|
- | 2152 | { |
|
- | 2153 | return HAL_ERROR; |
|
- | 2154 | } |
|
- | 2155 | ||
- | 2156 | /* Set the TIM channel state */ |
|
- | 2157 | TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_BUSY); |
|
- | 2158 | TIM_CHANNEL_N_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_BUSY); |
|
- | 2159 | ||
1667 | switch (Channel) |
2160 | switch (Channel) |
1668 | { |
2161 | { |
1669 | case TIM_CHANNEL_1: |
2162 | case TIM_CHANNEL_1: |
1670 | { |
2163 | { |
1671 | /* Enable the TIM Capture/Compare 1 interrupt */ |
2164 | /* Enable the TIM Capture/Compare 1 interrupt */ |
1672 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1); |
2165 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1); |
- | 2166 | break; |
|
1673 | } |
2167 | } |
1674 | break; |
- | |
1675 | 2168 | ||
1676 | case TIM_CHANNEL_2: |
2169 | case TIM_CHANNEL_2: |
1677 | { |
2170 | { |
1678 | /* Enable the TIM Capture/Compare 2 interrupt */ |
2171 | /* Enable the TIM Capture/Compare 2 interrupt */ |
1679 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2); |
2172 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2); |
- | 2173 | break; |
|
1680 | } |
2174 | } |
1681 | break; |
- | |
1682 | 2175 | ||
1683 | case TIM_CHANNEL_3: |
2176 | case TIM_CHANNEL_3: |
1684 | { |
2177 | { |
1685 | /* Enable the TIM Capture/Compare 3 interrupt */ |
2178 | /* Enable the TIM Capture/Compare 3 interrupt */ |
1686 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC3); |
2179 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC3); |
- | 2180 | break; |
|
1687 | } |
2181 | } |
1688 | break; |
- | |
1689 | 2182 | ||
1690 | case TIM_CHANNEL_4: |
2183 | case TIM_CHANNEL_4: |
1691 | { |
2184 | { |
1692 | /* Enable the TIM Capture/Compare 4 interrupt */ |
2185 | /* Enable the TIM Capture/Compare 4 interrupt */ |
1693 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC4); |
2186 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC4); |
- | 2187 | break; |
|
1694 | } |
2188 | } |
1695 | break; |
- | |
1696 | 2189 | ||
1697 | default: |
2190 | default: |
1698 | break; |
2191 | break; |
1699 | } |
2192 | } |
1700 | /* Enable the Input Capture channel */ |
2193 | /* Enable the Input Capture channel */ |
1701 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE); |
2194 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE); |
1702 | 2195 | ||
- | 2196 | /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */ |
|
- | 2197 | if (IS_TIM_SLAVE_INSTANCE(htim->Instance)) |
|
- | 2198 | { |
|
- | 2199 | tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS; |
|
- | 2200 | if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr)) |
|
- | 2201 | { |
|
1703 | /* Enable the Peripheral */ |
2202 | __HAL_TIM_ENABLE(htim); |
- | 2203 | } |
|
- | 2204 | } |
|
- | 2205 | else |
|
- | 2206 | { |
|
1704 | __HAL_TIM_ENABLE(htim); |
2207 | __HAL_TIM_ENABLE(htim); |
- | 2208 | } |
|
1705 | 2209 | ||
1706 | /* Return function status */ |
2210 | /* Return function status */ |
1707 | return HAL_OK; |
2211 | return HAL_OK; |
1708 | } |
2212 | } |
1709 | 2213 | ||
1710 | /** |
2214 | /** |
1711 | * @brief Stops the TIM Input Capture measurement in interrupt mode. |
2215 | * @brief Stops the TIM Input Capture measurement in interrupt mode. |
1712 | * @param htim : TIM handle |
2216 | * @param htim TIM Input Capture handle |
1713 | * @param Channel : TIM Channels to be disabled |
2217 | * @param Channel TIM Channels to be disabled |
1714 | * This parameter can be one of the following values: |
2218 | * This parameter can be one of the following values: |
1715 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
2219 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
1716 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
2220 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
1717 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
2221 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
1718 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
2222 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
1719 | * @retval HAL status |
2223 | * @retval HAL status |
1720 | */ |
2224 | */ |
1721 | HAL_StatusTypeDef HAL_TIM_IC_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel) |
2225 | HAL_StatusTypeDef HAL_TIM_IC_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel) |
1722 | { |
2226 | { |
1723 | /* Check the parameters */ |
2227 | /* Check the parameters */ |
1724 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
2228 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
1725 | 2229 | ||
Line 1727... | Line 2231... | ||
1727 | { |
2231 | { |
1728 | case TIM_CHANNEL_1: |
2232 | case TIM_CHANNEL_1: |
1729 | { |
2233 | { |
1730 | /* Disable the TIM Capture/Compare 1 interrupt */ |
2234 | /* Disable the TIM Capture/Compare 1 interrupt */ |
1731 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1); |
2235 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1); |
- | 2236 | break; |
|
1732 | } |
2237 | } |
1733 | break; |
- | |
1734 | 2238 | ||
1735 | case TIM_CHANNEL_2: |
2239 | case TIM_CHANNEL_2: |
1736 | { |
2240 | { |
1737 | /* Disable the TIM Capture/Compare 2 interrupt */ |
2241 | /* Disable the TIM Capture/Compare 2 interrupt */ |
1738 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2); |
2242 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2); |
- | 2243 | break; |
|
1739 | } |
2244 | } |
1740 | break; |
- | |
1741 | 2245 | ||
1742 | case TIM_CHANNEL_3: |
2246 | case TIM_CHANNEL_3: |
1743 | { |
2247 | { |
1744 | /* Disable the TIM Capture/Compare 3 interrupt */ |
2248 | /* Disable the TIM Capture/Compare 3 interrupt */ |
1745 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC3); |
2249 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC3); |
- | 2250 | break; |
|
1746 | } |
2251 | } |
1747 | break; |
- | |
1748 | 2252 | ||
1749 | case TIM_CHANNEL_4: |
2253 | case TIM_CHANNEL_4: |
1750 | { |
2254 | { |
1751 | /* Disable the TIM Capture/Compare 4 interrupt */ |
2255 | /* Disable the TIM Capture/Compare 4 interrupt */ |
1752 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC4); |
2256 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC4); |
- | 2257 | break; |
|
1753 | } |
2258 | } |
1754 | break; |
- | |
1755 | 2259 | ||
1756 | default: |
2260 | default: |
1757 | break; |
2261 | break; |
1758 | } |
2262 | } |
1759 | 2263 | ||
1760 | /* Disable the Input Capture channel */ |
2264 | /* Disable the Input Capture channel */ |
1761 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE); |
2265 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE); |
1762 | 2266 | ||
1763 | /* Disable the Peripheral */ |
2267 | /* Disable the Peripheral */ |
1764 | __HAL_TIM_DISABLE(htim); |
2268 | __HAL_TIM_DISABLE(htim); |
1765 | 2269 | ||
- | 2270 | /* Set the TIM channel state */ |
|
- | 2271 | TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY); |
|
- | 2272 | TIM_CHANNEL_N_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY); |
|
- | 2273 | ||
1766 | /* Return function status */ |
2274 | /* Return function status */ |
1767 | return HAL_OK; |
2275 | return HAL_OK; |
1768 | } |
2276 | } |
1769 | 2277 | ||
1770 | /** |
2278 | /** |
1771 | * @brief Starts the TIM Input Capture measurement in DMA mode. |
2279 | * @brief Starts the TIM Input Capture measurement in DMA mode. |
1772 | * @param htim : TIM Input Capture handle |
2280 | * @param htim TIM Input Capture handle |
1773 | * @param Channel : TIM Channels to be enabled |
2281 | * @param Channel TIM Channels to be enabled |
1774 | * This parameter can be one of the following values: |
2282 | * This parameter can be one of the following values: |
1775 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
2283 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
1776 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
2284 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
1777 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
2285 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
1778 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
2286 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
1779 | * @param pData : The destination Buffer address. |
2287 | * @param pData The destination Buffer address. |
1780 | * @param Length : The length of data to be transferred from TIM peripheral to memory. |
2288 | * @param Length The length of data to be transferred from TIM peripheral to memory. |
1781 | * @retval HAL status |
2289 | * @retval HAL status |
1782 | */ |
2290 | */ |
1783 | HAL_StatusTypeDef HAL_TIM_IC_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length) |
2291 | HAL_StatusTypeDef HAL_TIM_IC_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length) |
1784 | { |
2292 | { |
- | 2293 | uint32_t tmpsmcr; |
|
- | 2294 | HAL_TIM_ChannelStateTypeDef channel_state = TIM_CHANNEL_STATE_GET(htim, Channel); |
|
- | 2295 | HAL_TIM_ChannelStateTypeDef complementary_channel_state = TIM_CHANNEL_N_STATE_GET(htim, Channel); |
|
- | 2296 | ||
1785 | /* Check the parameters */ |
2297 | /* Check the parameters */ |
1786 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
2298 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
1787 | assert_param(IS_TIM_DMA_CC_INSTANCE(htim->Instance)); |
2299 | assert_param(IS_TIM_DMA_CC_INSTANCE(htim->Instance)); |
1788 | 2300 | ||
- | 2301 | /* Set the TIM channel state */ |
|
1789 | if((htim->State == HAL_TIM_STATE_BUSY)) |
2302 | if ((channel_state == HAL_TIM_CHANNEL_STATE_BUSY) |
- | 2303 | || (complementary_channel_state == HAL_TIM_CHANNEL_STATE_BUSY)) |
|
1790 | { |
2304 | { |
1791 | return HAL_BUSY; |
2305 | return HAL_BUSY; |
1792 | } |
2306 | } |
1793 | else if((htim->State == HAL_TIM_STATE_READY)) |
2307 | else if ((channel_state == HAL_TIM_CHANNEL_STATE_READY) |
- | 2308 | && (complementary_channel_state == HAL_TIM_CHANNEL_STATE_READY)) |
|
1794 | { |
2309 | { |
1795 | if((pData == 0U) && (Length > 0U)) |
2310 | if ((pData == NULL) && (Length > 0U)) |
1796 | { |
2311 | { |
1797 | return HAL_ERROR; |
2312 | return HAL_ERROR; |
1798 | } |
2313 | } |
1799 | else |
2314 | else |
1800 | { |
2315 | { |
1801 | htim->State = HAL_TIM_STATE_BUSY; |
2316 | TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_BUSY); |
- | 2317 | TIM_CHANNEL_N_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_BUSY); |
|
1802 | } |
2318 | } |
1803 | } |
2319 | } |
- | 2320 | else |
|
- | 2321 | { |
|
- | 2322 | return HAL_ERROR; |
|
- | 2323 | } |
|
1804 | 2324 | ||
1805 | switch (Channel) |
2325 | switch (Channel) |
1806 | { |
2326 | { |
1807 | case TIM_CHANNEL_1: |
2327 | case TIM_CHANNEL_1: |
1808 | { |
2328 | { |
1809 | /* Set the DMA Period elapsed callback */ |
2329 | /* Set the DMA capture callbacks */ |
1810 | htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMACaptureCplt; |
2330 | htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMACaptureCplt; |
- | 2331 | htim->hdma[TIM_DMA_ID_CC1]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt; |
|
1811 | 2332 | ||
1812 | /* Set the DMA error callback */ |
2333 | /* Set the DMA error callback */ |
1813 | htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ; |
2334 | htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ; |
1814 | 2335 | ||
1815 | /* Enable the DMA channel */ |
2336 | /* Enable the DMA channel */ |
1816 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)&htim->Instance->CCR1, (uint32_t)pData, Length); |
2337 | if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)&htim->Instance->CCR1, (uint32_t)pData, Length) != HAL_OK) |
- | 2338 | { |
|
- | 2339 | /* Return error status */ |
|
- | 2340 | return HAL_ERROR; |
|
1817 | 2341 | } |
|
1818 | /* Enable the TIM Capture/Compare 1 DMA request */ |
2342 | /* Enable the TIM Capture/Compare 1 DMA request */ |
1819 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1); |
2343 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1); |
- | 2344 | break; |
|
1820 | } |
2345 | } |
1821 | break; |
- | |
1822 | 2346 | ||
1823 | case TIM_CHANNEL_2: |
2347 | case TIM_CHANNEL_2: |
1824 | { |
2348 | { |
1825 | /* Set the DMA Period elapsed callback */ |
2349 | /* Set the DMA capture callbacks */ |
1826 | htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMACaptureCplt; |
2350 | htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMACaptureCplt; |
- | 2351 | htim->hdma[TIM_DMA_ID_CC2]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt; |
|
1827 | 2352 | ||
1828 | /* Set the DMA error callback */ |
2353 | /* Set the DMA error callback */ |
1829 | htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError ; |
2354 | htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError ; |
1830 | 2355 | ||
1831 | /* Enable the DMA channel */ |
2356 | /* Enable the DMA channel */ |
1832 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)&htim->Instance->CCR2, (uint32_t)pData, Length); |
2357 | if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)&htim->Instance->CCR2, (uint32_t)pData, Length) != HAL_OK) |
- | 2358 | { |
|
- | 2359 | /* Return error status */ |
|
- | 2360 | return HAL_ERROR; |
|
1833 | 2361 | } |
|
1834 | /* Enable the TIM Capture/Compare 2 DMA request */ |
2362 | /* Enable the TIM Capture/Compare 2 DMA request */ |
1835 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2); |
2363 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2); |
- | 2364 | break; |
|
1836 | } |
2365 | } |
1837 | break; |
- | |
1838 | 2366 | ||
1839 | case TIM_CHANNEL_3: |
2367 | case TIM_CHANNEL_3: |
1840 | { |
2368 | { |
1841 | /* Set the DMA Period elapsed callback */ |
2369 | /* Set the DMA capture callbacks */ |
1842 | htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMACaptureCplt; |
2370 | htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMACaptureCplt; |
- | 2371 | htim->hdma[TIM_DMA_ID_CC3]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt; |
|
1843 | 2372 | ||
1844 | /* Set the DMA error callback */ |
2373 | /* Set the DMA error callback */ |
1845 | htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = TIM_DMAError ; |
2374 | htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = TIM_DMAError ; |
1846 | 2375 | ||
1847 | /* Enable the DMA channel */ |
2376 | /* Enable the DMA channel */ |
1848 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)&htim->Instance->CCR3, (uint32_t)pData, Length); |
2377 | if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)&htim->Instance->CCR3, (uint32_t)pData, Length) != HAL_OK) |
- | 2378 | { |
|
- | 2379 | /* Return error status */ |
|
- | 2380 | return HAL_ERROR; |
|
1849 | 2381 | } |
|
1850 | /* Enable the TIM Capture/Compare 3 DMA request */ |
2382 | /* Enable the TIM Capture/Compare 3 DMA request */ |
1851 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC3); |
2383 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC3); |
- | 2384 | break; |
|
1852 | } |
2385 | } |
1853 | break; |
- | |
1854 | 2386 | ||
1855 | case TIM_CHANNEL_4: |
2387 | case TIM_CHANNEL_4: |
1856 | { |
2388 | { |
1857 | /* Set the DMA Period elapsed callback */ |
2389 | /* Set the DMA capture callbacks */ |
1858 | htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = TIM_DMACaptureCplt; |
2390 | htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = TIM_DMACaptureCplt; |
- | 2391 | htim->hdma[TIM_DMA_ID_CC4]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt; |
|
1859 | 2392 | ||
1860 | /* Set the DMA error callback */ |
2393 | /* Set the DMA error callback */ |
1861 | htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = TIM_DMAError ; |
2394 | htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = TIM_DMAError ; |
1862 | 2395 | ||
1863 | /* Enable the DMA channel */ |
2396 | /* Enable the DMA channel */ |
1864 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)&htim->Instance->CCR4, (uint32_t)pData, Length); |
2397 | if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)&htim->Instance->CCR4, (uint32_t)pData, Length) != HAL_OK) |
- | 2398 | { |
|
- | 2399 | /* Return error status */ |
|
- | 2400 | return HAL_ERROR; |
|
1865 | 2401 | } |
|
1866 | /* Enable the TIM Capture/Compare 4 DMA request */ |
2402 | /* Enable the TIM Capture/Compare 4 DMA request */ |
1867 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC4); |
2403 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC4); |
- | 2404 | break; |
|
1868 | } |
2405 | } |
1869 | break; |
- | |
1870 | 2406 | ||
1871 | default: |
2407 | default: |
1872 | break; |
2408 | break; |
1873 | } |
2409 | } |
1874 | 2410 | ||
1875 | /* Enable the Input Capture channel */ |
2411 | /* Enable the Input Capture channel */ |
1876 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE); |
2412 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE); |
1877 | 2413 | ||
- | 2414 | /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */ |
|
- | 2415 | if (IS_TIM_SLAVE_INSTANCE(htim->Instance)) |
|
- | 2416 | { |
|
- | 2417 | tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS; |
|
- | 2418 | if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr)) |
|
- | 2419 | { |
|
1878 | /* Enable the Peripheral */ |
2420 | __HAL_TIM_ENABLE(htim); |
- | 2421 | } |
|
- | 2422 | } |
|
- | 2423 | else |
|
- | 2424 | { |
|
1879 | __HAL_TIM_ENABLE(htim); |
2425 | __HAL_TIM_ENABLE(htim); |
- | 2426 | } |
|
1880 | 2427 | ||
1881 | /* Return function status */ |
2428 | /* Return function status */ |
1882 | return HAL_OK; |
2429 | return HAL_OK; |
1883 | } |
2430 | } |
1884 | 2431 | ||
1885 | /** |
2432 | /** |
1886 | * @brief Stops the TIM Input Capture measurement in DMA mode. |
2433 | * @brief Stops the TIM Input Capture measurement in DMA mode. |
1887 | * @param htim : TIM Input Capture handle |
2434 | * @param htim TIM Input Capture handle |
1888 | * @param Channel : TIM Channels to be disabled |
2435 | * @param Channel TIM Channels to be disabled |
1889 | * This parameter can be one of the following values: |
2436 | * This parameter can be one of the following values: |
1890 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
2437 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
1891 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
2438 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
1892 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
2439 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
1893 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
2440 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
1894 | * @retval HAL status |
2441 | * @retval HAL status |
1895 | */ |
2442 | */ |
1896 | HAL_StatusTypeDef HAL_TIM_IC_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel) |
2443 | HAL_StatusTypeDef HAL_TIM_IC_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel) |
1897 | { |
2444 | { |
1898 | /* Check the parameters */ |
2445 | /* Check the parameters */ |
1899 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
2446 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
1900 | assert_param(IS_TIM_DMA_CC_INSTANCE(htim->Instance)); |
2447 | assert_param(IS_TIM_DMA_CC_INSTANCE(htim->Instance)); |
1901 | 2448 | ||
- | 2449 | /* Disable the Input Capture channel */ |
|
- | 2450 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE); |
|
- | 2451 | ||
1902 | switch (Channel) |
2452 | switch (Channel) |
1903 | { |
2453 | { |
1904 | case TIM_CHANNEL_1: |
2454 | case TIM_CHANNEL_1: |
1905 | { |
2455 | { |
1906 | /* Disable the TIM Capture/Compare 1 DMA request */ |
2456 | /* Disable the TIM Capture/Compare 1 DMA request */ |
1907 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1); |
2457 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1); |
- | 2458 | (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC1]); |
|
- | 2459 | break; |
|
1908 | } |
2460 | } |
1909 | break; |
- | |
1910 | 2461 | ||
1911 | case TIM_CHANNEL_2: |
2462 | case TIM_CHANNEL_2: |
1912 | { |
2463 | { |
1913 | /* Disable the TIM Capture/Compare 2 DMA request */ |
2464 | /* Disable the TIM Capture/Compare 2 DMA request */ |
1914 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2); |
2465 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2); |
- | 2466 | (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC2]); |
|
- | 2467 | break; |
|
1915 | } |
2468 | } |
1916 | break; |
- | |
1917 | 2469 | ||
1918 | case TIM_CHANNEL_3: |
2470 | case TIM_CHANNEL_3: |
1919 | { |
2471 | { |
1920 | /* Disable the TIM Capture/Compare 3 DMA request */ |
2472 | /* Disable the TIM Capture/Compare 3 DMA request */ |
1921 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC3); |
2473 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC3); |
- | 2474 | (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC3]); |
|
- | 2475 | break; |
|
1922 | } |
2476 | } |
1923 | break; |
- | |
1924 | 2477 | ||
1925 | case TIM_CHANNEL_4: |
2478 | case TIM_CHANNEL_4: |
1926 | { |
2479 | { |
1927 | /* Disable the TIM Capture/Compare 4 DMA request */ |
2480 | /* Disable the TIM Capture/Compare 4 DMA request */ |
1928 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC4); |
2481 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC4); |
- | 2482 | (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC4]); |
|
- | 2483 | break; |
|
1929 | } |
2484 | } |
1930 | break; |
- | |
1931 | 2485 | ||
1932 | default: |
2486 | default: |
1933 | break; |
2487 | break; |
1934 | } |
2488 | } |
1935 | 2489 | ||
1936 | /* Disable the Input Capture channel */ |
- | |
1937 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE); |
- | |
1938 | - | ||
1939 | /* Disable the Peripheral */ |
2490 | /* Disable the Peripheral */ |
1940 | __HAL_TIM_DISABLE(htim); |
2491 | __HAL_TIM_DISABLE(htim); |
1941 | 2492 | ||
1942 | /* Change the htim state */ |
2493 | /* Set the TIM channel state */ |
1943 | htim->State = HAL_TIM_STATE_READY; |
2494 | TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY); |
- | 2495 | TIM_CHANNEL_N_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY); |
|
1944 | 2496 | ||
1945 | /* Return function status */ |
2497 | /* Return function status */ |
1946 | return HAL_OK; |
2498 | return HAL_OK; |
1947 | } |
2499 | } |
1948 | /** |
2500 | /** |
1949 | * @} |
2501 | * @} |
1950 | */ |
2502 | */ |
1951 | 2503 | ||
1952 | /** @defgroup TIM_Exported_Functions_Group5 Time One Pulse functions |
2504 | /** @defgroup TIM_Exported_Functions_Group5 TIM One Pulse functions |
1953 | * @brief Time One Pulse functions |
2505 | * @brief TIM One Pulse functions |
1954 | * |
2506 | * |
1955 | @verbatim |
2507 | @verbatim |
1956 | ============================================================================== |
2508 | ============================================================================== |
1957 | ##### Time One Pulse functions ##### |
2509 | ##### TIM One Pulse functions ##### |
1958 | ============================================================================== |
2510 | ============================================================================== |
1959 | [..] |
2511 | [..] |
1960 | This section provides functions allowing to: |
2512 | This section provides functions allowing to: |
1961 | (+) Initialize and configure the TIM One Pulse. |
2513 | (+) Initialize and configure the TIM One Pulse. |
1962 | (+) De-initialize the TIM One Pulse. |
2514 | (+) De-initialize the TIM One Pulse. |
1963 | (+) Start the Time One Pulse. |
2515 | (+) Start the TIM One Pulse. |
1964 | (+) Stop the Time One Pulse. |
2516 | (+) Stop the TIM One Pulse. |
1965 | (+) Start the Time One Pulse and enable interrupt. |
2517 | (+) Start the TIM One Pulse and enable interrupt. |
1966 | (+) Stop the Time One Pulse and disable interrupt. |
2518 | (+) Stop the TIM One Pulse and disable interrupt. |
1967 | (+) Start the Time One Pulse and enable DMA transfer. |
2519 | (+) Start the TIM One Pulse and enable DMA transfer. |
1968 | (+) Stop the Time One Pulse and disable DMA transfer. |
2520 | (+) Stop the TIM One Pulse and disable DMA transfer. |
1969 | 2521 | ||
1970 | @endverbatim |
2522 | @endverbatim |
1971 | * @{ |
2523 | * @{ |
1972 | */ |
2524 | */ |
1973 | /** |
2525 | /** |
1974 | * @brief Initializes the TIM One Pulse Time Base according to the specified |
2526 | * @brief Initializes the TIM One Pulse Time Base according to the specified |
1975 | * parameters in the TIM_HandleTypeDef and create the associated handle. |
2527 | * parameters in the TIM_HandleTypeDef and initializes the associated handle. |
1976 | * @note Switching from Center Aligned counter mode to Edge counter mode (or reverse) |
2528 | * @note Switching from Center Aligned counter mode to Edge counter mode (or reverse) |
1977 | * requires a timer reset to avoid unexpected direction |
2529 | * requires a timer reset to avoid unexpected direction |
1978 | * due to DIR bit readonly in center aligned mode. |
2530 | * due to DIR bit readonly in center aligned mode. |
1979 | * Ex: call @ref HAL_TIM_OnePulse_DeInit() before HAL_TIM_OnePulse_Init() |
2531 | * Ex: call @ref HAL_TIM_OnePulse_DeInit() before HAL_TIM_OnePulse_Init() |
- | 2532 | * @note When the timer instance is initialized in One Pulse mode, timer |
|
- | 2533 | * channels 1 and channel 2 are reserved and cannot be used for other |
|
- | 2534 | * purpose. |
|
1980 | * @param htim : TIM OnePulse handle |
2535 | * @param htim TIM One Pulse handle |
1981 | * @param OnePulseMode : Select the One pulse mode. |
2536 | * @param OnePulseMode Select the One pulse mode. |
1982 | * This parameter can be one of the following values: |
2537 | * This parameter can be one of the following values: |
1983 | * @arg TIM_OPMODE_SINGLE: Only one pulse will be generated. |
2538 | * @arg TIM_OPMODE_SINGLE: Only one pulse will be generated. |
1984 | * @arg TIM_OPMODE_REPETITIVE: Repetitive pulses wil be generated. |
2539 | * @arg TIM_OPMODE_REPETITIVE: Repetitive pulses will be generated. |
1985 | * @retval HAL status |
2540 | * @retval HAL status |
1986 | */ |
2541 | */ |
1987 | HAL_StatusTypeDef HAL_TIM_OnePulse_Init(TIM_HandleTypeDef *htim, uint32_t OnePulseMode) |
2542 | HAL_StatusTypeDef HAL_TIM_OnePulse_Init(TIM_HandleTypeDef *htim, uint32_t OnePulseMode) |
1988 | { |
2543 | { |
1989 | /* Check the TIM handle allocation */ |
2544 | /* Check the TIM handle allocation */ |
1990 | if(htim == NULL) |
2545 | if (htim == NULL) |
1991 | { |
2546 | { |
1992 | return HAL_ERROR; |
2547 | return HAL_ERROR; |
1993 | } |
2548 | } |
1994 | 2549 | ||
1995 | /* Check the parameters */ |
2550 | /* Check the parameters */ |
1996 | assert_param(IS_TIM_INSTANCE(htim->Instance)); |
2551 | assert_param(IS_TIM_INSTANCE(htim->Instance)); |
1997 | assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode)); |
2552 | assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode)); |
1998 | assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision)); |
2553 | assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision)); |
1999 | assert_param(IS_TIM_AUTORELOAD_PRELOAD(htim->Init.AutoReloadPreload)); |
- | |
2000 | assert_param(IS_TIM_OPM_MODE(OnePulseMode)); |
2554 | assert_param(IS_TIM_OPM_MODE(OnePulseMode)); |
- | 2555 | assert_param(IS_TIM_AUTORELOAD_PRELOAD(htim->Init.AutoReloadPreload)); |
|
2001 | 2556 | ||
2002 | if(htim->State == HAL_TIM_STATE_RESET) |
2557 | if (htim->State == HAL_TIM_STATE_RESET) |
2003 | { |
2558 | { |
2004 | /* Allocate lock resource and initialize it */ |
2559 | /* Allocate lock resource and initialize it */ |
2005 | htim->Lock = HAL_UNLOCKED; |
2560 | htim->Lock = HAL_UNLOCKED; |
- | 2561 | ||
- | 2562 | #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) |
|
- | 2563 | /* Reset interrupt callbacks to legacy weak callbacks */ |
|
- | 2564 | TIM_ResetCallback(htim); |
|
- | 2565 | ||
- | 2566 | if (htim->OnePulse_MspInitCallback == NULL) |
|
2006 | 2567 | { |
|
- | 2568 | htim->OnePulse_MspInitCallback = HAL_TIM_OnePulse_MspInit; |
|
- | 2569 | } |
|
- | 2570 | /* Init the low level hardware : GPIO, CLOCK, NVIC */ |
|
- | 2571 | htim->OnePulse_MspInitCallback(htim); |
|
- | 2572 | #else |
|
2007 | /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */ |
2573 | /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */ |
2008 | HAL_TIM_OnePulse_MspInit(htim); |
2574 | HAL_TIM_OnePulse_MspInit(htim); |
- | 2575 | #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */ |
|
2009 | } |
2576 | } |
2010 | 2577 | ||
2011 | /* Set the TIM state */ |
2578 | /* Set the TIM state */ |
2012 | htim->State= HAL_TIM_STATE_BUSY; |
2579 | htim->State = HAL_TIM_STATE_BUSY; |
2013 | 2580 | ||
2014 | /* Configure the Time base in the One Pulse Mode */ |
2581 | /* Configure the Time base in the One Pulse Mode */ |
2015 | TIM_Base_SetConfig(htim->Instance, &htim->Init); |
2582 | TIM_Base_SetConfig(htim->Instance, &htim->Init); |
2016 | 2583 | ||
2017 | /* Reset the OPM Bit */ |
2584 | /* Reset the OPM Bit */ |
2018 | htim->Instance->CR1 &= ~TIM_CR1_OPM; |
2585 | htim->Instance->CR1 &= ~TIM_CR1_OPM; |
2019 | 2586 | ||
2020 | /* Configure the OPM Mode */ |
2587 | /* Configure the OPM Mode */ |
2021 | htim->Instance->CR1 |= OnePulseMode; |
2588 | htim->Instance->CR1 |= OnePulseMode; |
2022 | 2589 | ||
- | 2590 | /* Initialize the DMA burst operation state */ |
|
- | 2591 | htim->DMABurstState = HAL_DMA_BURST_STATE_READY; |
|
- | 2592 | ||
- | 2593 | /* Initialize the TIM channels state */ |
|
- | 2594 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY); |
|
- | 2595 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY); |
|
- | 2596 | TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY); |
|
- | 2597 | TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY); |
|
- | 2598 | ||
2023 | /* Initialize the TIM state*/ |
2599 | /* Initialize the TIM state*/ |
2024 | htim->State= HAL_TIM_STATE_READY; |
2600 | htim->State = HAL_TIM_STATE_READY; |
2025 | 2601 | ||
2026 | return HAL_OK; |
2602 | return HAL_OK; |
2027 | } |
2603 | } |
2028 | 2604 | ||
2029 | /** |
2605 | /** |
2030 | * @brief DeInitializes the TIM One Pulse |
2606 | * @brief DeInitializes the TIM One Pulse |
2031 | * @param htim : TIM One Pulse handle |
2607 | * @param htim TIM One Pulse handle |
2032 | * @retval HAL status |
2608 | * @retval HAL status |
2033 | */ |
2609 | */ |
2034 | HAL_StatusTypeDef HAL_TIM_OnePulse_DeInit(TIM_HandleTypeDef *htim) |
2610 | HAL_StatusTypeDef HAL_TIM_OnePulse_DeInit(TIM_HandleTypeDef *htim) |
2035 | { |
2611 | { |
2036 | /* Check the parameters */ |
2612 | /* Check the parameters */ |
Line 2039... | Line 2615... | ||
2039 | htim->State = HAL_TIM_STATE_BUSY; |
2615 | htim->State = HAL_TIM_STATE_BUSY; |
2040 | 2616 | ||
2041 | /* Disable the TIM Peripheral Clock */ |
2617 | /* Disable the TIM Peripheral Clock */ |
2042 | __HAL_TIM_DISABLE(htim); |
2618 | __HAL_TIM_DISABLE(htim); |
2043 | 2619 | ||
- | 2620 | #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) |
|
- | 2621 | if (htim->OnePulse_MspDeInitCallback == NULL) |
|
- | 2622 | { |
|
- | 2623 | htim->OnePulse_MspDeInitCallback = HAL_TIM_OnePulse_MspDeInit; |
|
- | 2624 | } |
|
- | 2625 | /* DeInit the low level hardware */ |
|
- | 2626 | htim->OnePulse_MspDeInitCallback(htim); |
|
- | 2627 | #else |
|
2044 | /* DeInit the low level hardware: GPIO, CLOCK, NVIC */ |
2628 | /* DeInit the low level hardware: GPIO, CLOCK, NVIC */ |
2045 | HAL_TIM_OnePulse_MspDeInit(htim); |
2629 | HAL_TIM_OnePulse_MspDeInit(htim); |
- | 2630 | #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */ |
|
- | 2631 | ||
- | 2632 | /* Change the DMA burst operation state */ |
|
- | 2633 | htim->DMABurstState = HAL_DMA_BURST_STATE_RESET; |
|
- | 2634 | ||
- | 2635 | /* Set the TIM channel state */ |
|
- | 2636 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_RESET); |
|
- | 2637 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_RESET); |
|
- | 2638 | TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_RESET); |
|
- | 2639 | TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_RESET); |
|
2046 | 2640 | ||
2047 | /* Change TIM state */ |
2641 | /* Change TIM state */ |
2048 | htim->State = HAL_TIM_STATE_RESET; |
2642 | htim->State = HAL_TIM_STATE_RESET; |
2049 | 2643 | ||
2050 | /* Release Lock */ |
2644 | /* Release Lock */ |
Line 2053... | Line 2647... | ||
2053 | return HAL_OK; |
2647 | return HAL_OK; |
2054 | } |
2648 | } |
2055 | 2649 | ||
2056 | /** |
2650 | /** |
2057 | * @brief Initializes the TIM One Pulse MSP. |
2651 | * @brief Initializes the TIM One Pulse MSP. |
2058 | * @param htim : TIM handle |
2652 | * @param htim TIM One Pulse handle |
2059 | * @retval None |
2653 | * @retval None |
2060 | */ |
2654 | */ |
2061 | __weak void HAL_TIM_OnePulse_MspInit(TIM_HandleTypeDef *htim) |
2655 | __weak void HAL_TIM_OnePulse_MspInit(TIM_HandleTypeDef *htim) |
2062 | { |
2656 | { |
2063 | /* Prevent unused argument(s) compilation warning */ |
2657 | /* Prevent unused argument(s) compilation warning */ |
2064 | UNUSED(htim); |
2658 | UNUSED(htim); |
- | 2659 | ||
2065 | /* NOTE : This function Should not be modified, when the callback is needed, |
2660 | /* NOTE : This function should not be modified, when the callback is needed, |
2066 | the HAL_TIM_OnePulse_MspInit could be implemented in the user file |
2661 | the HAL_TIM_OnePulse_MspInit could be implemented in the user file |
2067 | */ |
2662 | */ |
2068 | } |
2663 | } |
2069 | 2664 | ||
2070 | /** |
2665 | /** |
2071 | * @brief DeInitializes TIM One Pulse MSP. |
2666 | * @brief DeInitializes TIM One Pulse MSP. |
2072 | * @param htim : TIM handle |
2667 | * @param htim TIM One Pulse handle |
2073 | * @retval None |
2668 | * @retval None |
2074 | */ |
2669 | */ |
2075 | __weak void HAL_TIM_OnePulse_MspDeInit(TIM_HandleTypeDef *htim) |
2670 | __weak void HAL_TIM_OnePulse_MspDeInit(TIM_HandleTypeDef *htim) |
2076 | { |
2671 | { |
2077 | /* Prevent unused argument(s) compilation warning */ |
2672 | /* Prevent unused argument(s) compilation warning */ |
2078 | UNUSED(htim); |
2673 | UNUSED(htim); |
- | 2674 | ||
2079 | /* NOTE : This function Should not be modified, when the callback is needed, |
2675 | /* NOTE : This function should not be modified, when the callback is needed, |
2080 | the HAL_TIM_OnePulse_MspDeInit could be implemented in the user file |
2676 | the HAL_TIM_OnePulse_MspDeInit could be implemented in the user file |
2081 | */ |
2677 | */ |
2082 | } |
2678 | } |
2083 | 2679 | ||
2084 | /** |
2680 | /** |
2085 | * @brief Starts the TIM One Pulse signal generation. |
2681 | * @brief Starts the TIM One Pulse signal generation. |
2086 | * @param htim : TIM One Pulse handle |
2682 | * @param htim TIM One Pulse handle |
2087 | * @param OutputChannel : TIM Channels to be enabled |
2683 | * @param OutputChannel TIM Channels to be enabled |
2088 | * This parameter can be one of the following values: |
2684 | * This parameter can be one of the following values: |
2089 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
2685 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
2090 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
2686 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
2091 | * @retval HAL status |
2687 | * @retval HAL status |
2092 | */ |
2688 | */ |
2093 | HAL_StatusTypeDef HAL_TIM_OnePulse_Start(TIM_HandleTypeDef *htim, uint32_t OutputChannel) |
2689 | HAL_StatusTypeDef HAL_TIM_OnePulse_Start(TIM_HandleTypeDef *htim, uint32_t OutputChannel) |
2094 | { |
2690 | { |
- | 2691 | HAL_TIM_ChannelStateTypeDef channel_1_state = TIM_CHANNEL_STATE_GET(htim, TIM_CHANNEL_1); |
|
- | 2692 | HAL_TIM_ChannelStateTypeDef channel_2_state = TIM_CHANNEL_STATE_GET(htim, TIM_CHANNEL_2); |
|
- | 2693 | HAL_TIM_ChannelStateTypeDef complementary_channel_1_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_1); |
|
- | 2694 | HAL_TIM_ChannelStateTypeDef complementary_channel_2_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_2); |
|
- | 2695 | ||
2095 | /* Prevent unused argument(s) compilation warning */ |
2696 | /* Prevent unused argument(s) compilation warning */ |
2096 | UNUSED(OutputChannel); |
2697 | UNUSED(OutputChannel); |
2097 | 2698 | ||
- | 2699 | /* Check the TIM channels state */ |
|
- | 2700 | if ((channel_1_state != HAL_TIM_CHANNEL_STATE_READY) |
|
- | 2701 | || (channel_2_state != HAL_TIM_CHANNEL_STATE_READY) |
|
- | 2702 | || (complementary_channel_1_state != HAL_TIM_CHANNEL_STATE_READY) |
|
- | 2703 | || (complementary_channel_2_state != HAL_TIM_CHANNEL_STATE_READY)) |
|
- | 2704 | { |
|
- | 2705 | return HAL_ERROR; |
|
- | 2706 | } |
|
- | 2707 | ||
- | 2708 | /* Set the TIM channels state */ |
|
- | 2709 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_BUSY); |
|
- | 2710 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_BUSY); |
|
- | 2711 | TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_BUSY); |
|
- | 2712 | TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_BUSY); |
|
- | 2713 | ||
2098 | /* Enable the Capture compare and the Input Capture channels |
2714 | /* Enable the Capture compare and the Input Capture channels |
2099 | (in the OPM Mode the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2) |
2715 | (in the OPM Mode the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2) |
2100 | if TIM_CHANNEL_1 is used as output, the TIM_CHANNEL_2 will be used as input and |
2716 | if TIM_CHANNEL_1 is used as output, the TIM_CHANNEL_2 will be used as input and |
2101 | if TIM_CHANNEL_1 is used as input, the TIM_CHANNEL_2 will be used as output |
2717 | if TIM_CHANNEL_1 is used as input, the TIM_CHANNEL_2 will be used as output |
2102 | in all combinations, the TIM_CHANNEL_1 and TIM_CHANNEL_2 should be enabled together |
2718 | in all combinations, the TIM_CHANNEL_1 and TIM_CHANNEL_2 should be enabled together |
2103 | 2719 | ||
2104 | No need to enable the counter, it's enabled automatically by hardware |
2720 | No need to enable the counter, it's enabled automatically by hardware |
2105 | (the counter starts in response to a stimulus and generate a pulse */ |
2721 | (the counter starts in response to a stimulus and generate a pulse */ |
2106 | 2722 | ||
2107 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE); |
2723 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE); |
2108 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE); |
2724 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE); |
2109 | 2725 | ||
2110 | if(IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET) |
2726 | if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET) |
2111 | { |
2727 | { |
2112 | /* Enable the main output */ |
2728 | /* Enable the main output */ |
2113 | __HAL_TIM_MOE_ENABLE(htim); |
2729 | __HAL_TIM_MOE_ENABLE(htim); |
2114 | } |
2730 | } |
2115 | 2731 | ||
Line 2117... | Line 2733... | ||
2117 | return HAL_OK; |
2733 | return HAL_OK; |
2118 | } |
2734 | } |
2119 | 2735 | ||
2120 | /** |
2736 | /** |
2121 | * @brief Stops the TIM One Pulse signal generation. |
2737 | * @brief Stops the TIM One Pulse signal generation. |
2122 | * @param htim : TIM One Pulse handle |
2738 | * @param htim TIM One Pulse handle |
2123 | * @param OutputChannel : TIM Channels to be disable |
2739 | * @param OutputChannel TIM Channels to be disable |
2124 | * This parameter can be one of the following values: |
2740 | * This parameter can be one of the following values: |
2125 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
2741 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
2126 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
2742 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
2127 | * @retval HAL status |
2743 | * @retval HAL status |
2128 | */ |
2744 | */ |
2129 | HAL_StatusTypeDef HAL_TIM_OnePulse_Stop(TIM_HandleTypeDef *htim, uint32_t OutputChannel) |
2745 | HAL_StatusTypeDef HAL_TIM_OnePulse_Stop(TIM_HandleTypeDef *htim, uint32_t OutputChannel) |
2130 | { |
2746 | { |
2131 | /* Prevent unused argument(s) compilation warning */ |
2747 | /* Prevent unused argument(s) compilation warning */ |
2132 | UNUSED(OutputChannel); |
2748 | UNUSED(OutputChannel); |
2133 | 2749 | ||
2134 | /* Disable the Capture compare and the Input Capture channels |
2750 | /* Disable the Capture compare and the Input Capture channels |
2135 | (in the OPM Mode the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2) |
2751 | (in the OPM Mode the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2) |
2136 | if TIM_CHANNEL_1 is used as output, the TIM_CHANNEL_2 will be used as input and |
2752 | if TIM_CHANNEL_1 is used as output, the TIM_CHANNEL_2 will be used as input and |
2137 | if TIM_CHANNEL_1 is used as input, the TIM_CHANNEL_2 will be used as output |
2753 | if TIM_CHANNEL_1 is used as input, the TIM_CHANNEL_2 will be used as output |
2138 | in all combinations, the TIM_CHANNEL_1 and TIM_CHANNEL_2 should be disabled together */ |
2754 | in all combinations, the TIM_CHANNEL_1 and TIM_CHANNEL_2 should be disabled together */ |
2139 | 2755 | ||
2140 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE); |
2756 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE); |
2141 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE); |
2757 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE); |
2142 | 2758 | ||
2143 | if(IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET) |
2759 | if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET) |
2144 | { |
2760 | { |
2145 | /* Disable the Main Ouput */ |
2761 | /* Disable the Main Output */ |
2146 | __HAL_TIM_MOE_DISABLE(htim); |
2762 | __HAL_TIM_MOE_DISABLE(htim); |
2147 | } |
2763 | } |
2148 | 2764 | ||
2149 | /* Disable the Peripheral */ |
2765 | /* Disable the Peripheral */ |
2150 | __HAL_TIM_DISABLE(htim); |
2766 | __HAL_TIM_DISABLE(htim); |
2151 | 2767 | ||
- | 2768 | /* Set the TIM channels state */ |
|
- | 2769 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY); |
|
- | 2770 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY); |
|
- | 2771 | TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY); |
|
- | 2772 | TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY); |
|
- | 2773 | ||
2152 | /* Return function status */ |
2774 | /* Return function status */ |
2153 | return HAL_OK; |
2775 | return HAL_OK; |
2154 | } |
2776 | } |
2155 | 2777 | ||
2156 | /** |
2778 | /** |
2157 | * @brief Starts the TIM One Pulse signal generation in interrupt mode. |
2779 | * @brief Starts the TIM One Pulse signal generation in interrupt mode. |
2158 | * @param htim : TIM One Pulse handle |
2780 | * @param htim TIM One Pulse handle |
2159 | * @param OutputChannel : TIM Channels to be enabled |
2781 | * @param OutputChannel TIM Channels to be enabled |
2160 | * This parameter can be one of the following values: |
2782 | * This parameter can be one of the following values: |
2161 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
2783 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
2162 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
2784 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
2163 | * @retval HAL status |
2785 | * @retval HAL status |
2164 | */ |
2786 | */ |
2165 | HAL_StatusTypeDef HAL_TIM_OnePulse_Start_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel) |
2787 | HAL_StatusTypeDef HAL_TIM_OnePulse_Start_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel) |
2166 | { |
2788 | { |
- | 2789 | HAL_TIM_ChannelStateTypeDef channel_1_state = TIM_CHANNEL_STATE_GET(htim, TIM_CHANNEL_1); |
|
- | 2790 | HAL_TIM_ChannelStateTypeDef channel_2_state = TIM_CHANNEL_STATE_GET(htim, TIM_CHANNEL_2); |
|
- | 2791 | HAL_TIM_ChannelStateTypeDef complementary_channel_1_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_1); |
|
- | 2792 | HAL_TIM_ChannelStateTypeDef complementary_channel_2_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_2); |
|
- | 2793 | ||
2167 | /* Prevent unused argument(s) compilation warning */ |
2794 | /* Prevent unused argument(s) compilation warning */ |
2168 | UNUSED(OutputChannel); |
2795 | UNUSED(OutputChannel); |
2169 | 2796 | ||
- | 2797 | /* Check the TIM channels state */ |
|
- | 2798 | if ((channel_1_state != HAL_TIM_CHANNEL_STATE_READY) |
|
- | 2799 | || (channel_2_state != HAL_TIM_CHANNEL_STATE_READY) |
|
- | 2800 | || (complementary_channel_1_state != HAL_TIM_CHANNEL_STATE_READY) |
|
- | 2801 | || (complementary_channel_2_state != HAL_TIM_CHANNEL_STATE_READY)) |
|
- | 2802 | { |
|
- | 2803 | return HAL_ERROR; |
|
- | 2804 | } |
|
- | 2805 | ||
- | 2806 | /* Set the TIM channels state */ |
|
- | 2807 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_BUSY); |
|
- | 2808 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_BUSY); |
|
- | 2809 | TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_BUSY); |
|
- | 2810 | TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_BUSY); |
|
- | 2811 | ||
2170 | /* Enable the Capture compare and the Input Capture channels |
2812 | /* Enable the Capture compare and the Input Capture channels |
2171 | (in the OPM Mode the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2) |
2813 | (in the OPM Mode the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2) |
2172 | if TIM_CHANNEL_1 is used as output, the TIM_CHANNEL_2 will be used as input and |
2814 | if TIM_CHANNEL_1 is used as output, the TIM_CHANNEL_2 will be used as input and |
2173 | if TIM_CHANNEL_1 is used as input, the TIM_CHANNEL_2 will be used as output |
2815 | if TIM_CHANNEL_1 is used as input, the TIM_CHANNEL_2 will be used as output |
2174 | in all combinations, the TIM_CHANNEL_1 and TIM_CHANNEL_2 should be enabled together |
2816 | in all combinations, the TIM_CHANNEL_1 and TIM_CHANNEL_2 should be enabled together |
2175 | 2817 | ||
2176 | No need to enable the counter, it's enabled automatically by hardware |
2818 | No need to enable the counter, it's enabled automatically by hardware |
2177 | (the counter starts in response to a stimulus and generate a pulse */ |
2819 | (the counter starts in response to a stimulus and generate a pulse */ |
2178 | 2820 | ||
2179 | /* Enable the TIM Capture/Compare 1 interrupt */ |
2821 | /* Enable the TIM Capture/Compare 1 interrupt */ |
2180 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1); |
2822 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1); |
2181 | 2823 | ||
Line 2183... | Line 2825... | ||
2183 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2); |
2825 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2); |
2184 | 2826 | ||
2185 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE); |
2827 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE); |
2186 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE); |
2828 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE); |
2187 | 2829 | ||
2188 | if(IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET) |
2830 | if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET) |
2189 | { |
2831 | { |
2190 | /* Enable the main output */ |
2832 | /* Enable the main output */ |
2191 | __HAL_TIM_MOE_ENABLE(htim); |
2833 | __HAL_TIM_MOE_ENABLE(htim); |
2192 | } |
2834 | } |
2193 | 2835 | ||
Line 2195... | Line 2837... | ||
2195 | return HAL_OK; |
2837 | return HAL_OK; |
2196 | } |
2838 | } |
2197 | 2839 | ||
2198 | /** |
2840 | /** |
2199 | * @brief Stops the TIM One Pulse signal generation in interrupt mode. |
2841 | * @brief Stops the TIM One Pulse signal generation in interrupt mode. |
2200 | * @param htim : TIM One Pulse handle |
2842 | * @param htim TIM One Pulse handle |
2201 | * @param OutputChannel : TIM Channels to be enabled |
2843 | * @param OutputChannel TIM Channels to be enabled |
2202 | * This parameter can be one of the following values: |
2844 | * This parameter can be one of the following values: |
2203 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
2845 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
2204 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
2846 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
2205 | * @retval HAL status |
2847 | * @retval HAL status |
2206 | */ |
2848 | */ |
2207 | HAL_StatusTypeDef HAL_TIM_OnePulse_Stop_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel) |
2849 | HAL_StatusTypeDef HAL_TIM_OnePulse_Stop_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel) |
2208 | { |
2850 | { |
2209 | /* Prevent unused argument(s) compilation warning */ |
2851 | /* Prevent unused argument(s) compilation warning */ |
2210 | UNUSED(OutputChannel); |
2852 | UNUSED(OutputChannel); |
2211 | 2853 | ||
Line 2213... | Line 2855... | ||
2213 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1); |
2855 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1); |
2214 | 2856 | ||
2215 | /* Disable the TIM Capture/Compare 2 interrupt */ |
2857 | /* Disable the TIM Capture/Compare 2 interrupt */ |
2216 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2); |
2858 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2); |
2217 | 2859 | ||
2218 | /* Disable the Capture compare and the Input Capture channels |
2860 | /* Disable the Capture compare and the Input Capture channels |
2219 | (in the OPM Mode the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2) |
2861 | (in the OPM Mode the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2) |
2220 | if TIM_CHANNEL_1 is used as output, the TIM_CHANNEL_2 will be used as input and |
2862 | if TIM_CHANNEL_1 is used as output, the TIM_CHANNEL_2 will be used as input and |
2221 | if TIM_CHANNEL_1 is used as input, the TIM_CHANNEL_2 will be used as output |
2863 | if TIM_CHANNEL_1 is used as input, the TIM_CHANNEL_2 will be used as output |
2222 | in all combinations, the TIM_CHANNEL_1 and TIM_CHANNEL_2 should be disabled together */ |
2864 | in all combinations, the TIM_CHANNEL_1 and TIM_CHANNEL_2 should be disabled together */ |
2223 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE); |
2865 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE); |
2224 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE); |
2866 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE); |
2225 | 2867 | ||
2226 | if(IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET) |
2868 | if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET) |
2227 | { |
2869 | { |
2228 | /* Disable the Main Ouput */ |
2870 | /* Disable the Main Output */ |
2229 | __HAL_TIM_MOE_DISABLE(htim); |
2871 | __HAL_TIM_MOE_DISABLE(htim); |
2230 | } |
2872 | } |
2231 | 2873 | ||
2232 | /* Disable the Peripheral */ |
2874 | /* Disable the Peripheral */ |
2233 | __HAL_TIM_DISABLE(htim); |
2875 | __HAL_TIM_DISABLE(htim); |
- | 2876 | ||
- | 2877 | /* Set the TIM channels state */ |
|
- | 2878 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY); |
|
- | 2879 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY); |
|
- | 2880 | TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY); |
|
- | 2881 | TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY); |
|
2234 | 2882 | ||
2235 | /* Return function status */ |
2883 | /* Return function status */ |
2236 | return HAL_OK; |
2884 | return HAL_OK; |
2237 | } |
2885 | } |
2238 | 2886 | ||
2239 | /** |
2887 | /** |
2240 | * @} |
2888 | * @} |
2241 | */ |
2889 | */ |
2242 | 2890 | ||
2243 | /** @defgroup TIM_Exported_Functions_Group6 Time Encoder functions |
2891 | /** @defgroup TIM_Exported_Functions_Group6 TIM Encoder functions |
2244 | * @brief Time Encoder functions |
2892 | * @brief TIM Encoder functions |
2245 | * |
2893 | * |
2246 | @verbatim |
2894 | @verbatim |
2247 | ============================================================================== |
2895 | ============================================================================== |
2248 | ##### Time Encoder functions ##### |
2896 | ##### TIM Encoder functions ##### |
2249 | ============================================================================== |
2897 | ============================================================================== |
2250 | [..] |
2898 | [..] |
2251 | This section provides functions allowing to: |
2899 | This section provides functions allowing to: |
2252 | (+) Initialize and configure the TIM Encoder. |
2900 | (+) Initialize and configure the TIM Encoder. |
2253 | (+) De-initialize the TIM Encoder. |
2901 | (+) De-initialize the TIM Encoder. |
2254 | (+) Start the Time Encoder. |
2902 | (+) Start the TIM Encoder. |
2255 | (+) Stop the Time Encoder. |
2903 | (+) Stop the TIM Encoder. |
2256 | (+) Start the Time Encoder and enable interrupt. |
2904 | (+) Start the TIM Encoder and enable interrupt. |
2257 | (+) Stop the Time Encoder and disable interrupt. |
2905 | (+) Stop the TIM Encoder and disable interrupt. |
2258 | (+) Start the Time Encoder and enable DMA transfer. |
2906 | (+) Start the TIM Encoder and enable DMA transfer. |
2259 | (+) Stop the Time Encoder and disable DMA transfer. |
2907 | (+) Stop the TIM Encoder and disable DMA transfer. |
2260 | 2908 | ||
2261 | @endverbatim |
2909 | @endverbatim |
2262 | * @{ |
2910 | * @{ |
2263 | */ |
2911 | */ |
2264 | /** |
2912 | /** |
2265 | * @brief Initializes the TIM Encoder Interface and create the associated handle. |
2913 | * @brief Initializes the TIM Encoder Interface and initialize the associated handle. |
2266 | * @note Switching from Center Aligned counter mode to Edge counter mode (or reverse) |
2914 | * @note Switching from Center Aligned counter mode to Edge counter mode (or reverse) |
2267 | * requires a timer reset to avoid unexpected direction |
2915 | * requires a timer reset to avoid unexpected direction |
2268 | * due to DIR bit readonly in center aligned mode. |
2916 | * due to DIR bit readonly in center aligned mode. |
2269 | * Ex: call @ref HAL_TIM_Encoder_DeInit() before HAL_TIM_Encoder_Init() |
2917 | * Ex: call @ref HAL_TIM_Encoder_DeInit() before HAL_TIM_Encoder_Init() |
- | 2918 | * @note Encoder mode and External clock mode 2 are not compatible and must not be selected together |
|
- | 2919 | * Ex: A call for @ref HAL_TIM_Encoder_Init will erase the settings of @ref HAL_TIM_ConfigClockSource |
|
- | 2920 | * using TIM_CLOCKSOURCE_ETRMODE2 and vice versa |
|
- | 2921 | * @note When the timer instance is initialized in Encoder mode, timer |
|
- | 2922 | * channels 1 and channel 2 are reserved and cannot be used for other |
|
- | 2923 | * purpose. |
|
2270 | * @param htim : TIM Encoder Interface handle |
2924 | * @param htim TIM Encoder Interface handle |
2271 | * @param sConfig : TIM Encoder Interface configuration structure |
2925 | * @param sConfig TIM Encoder Interface configuration structure |
2272 | * @retval HAL status |
2926 | * @retval HAL status |
2273 | */ |
2927 | */ |
2274 | HAL_StatusTypeDef HAL_TIM_Encoder_Init(TIM_HandleTypeDef *htim, TIM_Encoder_InitTypeDef* sConfig) |
2928 | HAL_StatusTypeDef HAL_TIM_Encoder_Init(TIM_HandleTypeDef *htim, TIM_Encoder_InitTypeDef *sConfig) |
2275 | { |
2929 | { |
2276 | uint32_t tmpsmcr = 0U; |
2930 | uint32_t tmpsmcr; |
2277 | uint32_t tmpccmr1 = 0U; |
2931 | uint32_t tmpccmr1; |
2278 | uint32_t tmpccer = 0U; |
2932 | uint32_t tmpccer; |
2279 | 2933 | ||
2280 | /* Check the TIM handle allocation */ |
2934 | /* Check the TIM handle allocation */ |
2281 | if(htim == NULL) |
2935 | if (htim == NULL) |
2282 | { |
2936 | { |
2283 | return HAL_ERROR; |
2937 | return HAL_ERROR; |
2284 | } |
2938 | } |
2285 | 2939 | ||
2286 | /* Check the parameters */ |
2940 | /* Check the parameters */ |
2287 | assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); |
2941 | assert_param(IS_TIM_ENCODER_INTERFACE_INSTANCE(htim->Instance)); |
2288 | assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode)); |
2942 | assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode)); |
2289 | assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision)); |
2943 | assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision)); |
2290 | assert_param(IS_TIM_AUTORELOAD_PRELOAD(htim->Init.AutoReloadPreload)); |
2944 | assert_param(IS_TIM_AUTORELOAD_PRELOAD(htim->Init.AutoReloadPreload)); |
2291 | assert_param(IS_TIM_ENCODER_MODE(sConfig->EncoderMode)); |
2945 | assert_param(IS_TIM_ENCODER_MODE(sConfig->EncoderMode)); |
2292 | assert_param(IS_TIM_IC_SELECTION(sConfig->IC1Selection)); |
2946 | assert_param(IS_TIM_IC_SELECTION(sConfig->IC1Selection)); |
2293 | assert_param(IS_TIM_IC_SELECTION(sConfig->IC2Selection)); |
2947 | assert_param(IS_TIM_IC_SELECTION(sConfig->IC2Selection)); |
2294 | assert_param(IS_TIM_IC_POLARITY(sConfig->IC1Polarity)); |
2948 | assert_param(IS_TIM_ENCODERINPUT_POLARITY(sConfig->IC1Polarity)); |
2295 | assert_param(IS_TIM_IC_POLARITY(sConfig->IC2Polarity)); |
2949 | assert_param(IS_TIM_ENCODERINPUT_POLARITY(sConfig->IC2Polarity)); |
2296 | assert_param(IS_TIM_IC_PRESCALER(sConfig->IC1Prescaler)); |
2950 | assert_param(IS_TIM_IC_PRESCALER(sConfig->IC1Prescaler)); |
2297 | assert_param(IS_TIM_IC_PRESCALER(sConfig->IC2Prescaler)); |
2951 | assert_param(IS_TIM_IC_PRESCALER(sConfig->IC2Prescaler)); |
2298 | assert_param(IS_TIM_IC_FILTER(sConfig->IC1Filter)); |
2952 | assert_param(IS_TIM_IC_FILTER(sConfig->IC1Filter)); |
2299 | assert_param(IS_TIM_IC_FILTER(sConfig->IC2Filter)); |
2953 | assert_param(IS_TIM_IC_FILTER(sConfig->IC2Filter)); |
2300 | 2954 | ||
2301 | if(htim->State == HAL_TIM_STATE_RESET) |
2955 | if (htim->State == HAL_TIM_STATE_RESET) |
2302 | { |
2956 | { |
2303 | /* Allocate lock resource and initialize it */ |
2957 | /* Allocate lock resource and initialize it */ |
2304 | htim->Lock = HAL_UNLOCKED; |
2958 | htim->Lock = HAL_UNLOCKED; |
- | 2959 | ||
- | 2960 | #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) |
|
- | 2961 | /* Reset interrupt callbacks to legacy weak callbacks */ |
|
- | 2962 | TIM_ResetCallback(htim); |
|
- | 2963 | ||
- | 2964 | if (htim->Encoder_MspInitCallback == NULL) |
|
2305 | 2965 | { |
|
- | 2966 | htim->Encoder_MspInitCallback = HAL_TIM_Encoder_MspInit; |
|
- | 2967 | } |
|
- | 2968 | /* Init the low level hardware : GPIO, CLOCK, NVIC */ |
|
- | 2969 | htim->Encoder_MspInitCallback(htim); |
|
- | 2970 | #else |
|
2306 | /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */ |
2971 | /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */ |
2307 | HAL_TIM_Encoder_MspInit(htim); |
2972 | HAL_TIM_Encoder_MspInit(htim); |
- | 2973 | #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */ |
|
2308 | } |
2974 | } |
2309 | 2975 | ||
2310 | /* Set the TIM state */ |
2976 | /* Set the TIM state */ |
2311 | htim->State= HAL_TIM_STATE_BUSY; |
2977 | htim->State = HAL_TIM_STATE_BUSY; |
2312 | 2978 | ||
2313 | /* Reset the SMS bits */ |
2979 | /* Reset the SMS and ECE bits */ |
2314 | htim->Instance->SMCR &= ~TIM_SMCR_SMS; |
2980 | htim->Instance->SMCR &= ~(TIM_SMCR_SMS | TIM_SMCR_ECE); |
2315 | 2981 | ||
2316 | /* Configure the Time base in the Encoder Mode */ |
2982 | /* Configure the Time base in the Encoder Mode */ |
2317 | TIM_Base_SetConfig(htim->Instance, &htim->Init); |
2983 | TIM_Base_SetConfig(htim->Instance, &htim->Init); |
2318 | 2984 | ||
2319 | /* Get the TIMx SMCR register value */ |
2985 | /* Get the TIMx SMCR register value */ |
Line 2330... | Line 2996... | ||
2330 | 2996 | ||
2331 | /* Select the Capture Compare 1 and the Capture Compare 2 as input */ |
2997 | /* Select the Capture Compare 1 and the Capture Compare 2 as input */ |
2332 | tmpccmr1 &= ~(TIM_CCMR1_CC1S | TIM_CCMR1_CC2S); |
2998 | tmpccmr1 &= ~(TIM_CCMR1_CC1S | TIM_CCMR1_CC2S); |
2333 | tmpccmr1 |= (sConfig->IC1Selection | (sConfig->IC2Selection << 8U)); |
2999 | tmpccmr1 |= (sConfig->IC1Selection | (sConfig->IC2Selection << 8U)); |
2334 | 3000 | ||
2335 | /* Set the the Capture Compare 1 and the Capture Compare 2 prescalers and filters */ |
3001 | /* Set the Capture Compare 1 and the Capture Compare 2 prescalers and filters */ |
2336 | tmpccmr1 &= ~(TIM_CCMR1_IC1PSC | TIM_CCMR1_IC2PSC); |
3002 | tmpccmr1 &= ~(TIM_CCMR1_IC1PSC | TIM_CCMR1_IC2PSC); |
2337 | tmpccmr1 &= ~(TIM_CCMR1_IC1F | TIM_CCMR1_IC2F); |
3003 | tmpccmr1 &= ~(TIM_CCMR1_IC1F | TIM_CCMR1_IC2F); |
2338 | tmpccmr1 |= sConfig->IC1Prescaler | (sConfig->IC2Prescaler << 8U); |
3004 | tmpccmr1 |= sConfig->IC1Prescaler | (sConfig->IC2Prescaler << 8U); |
2339 | tmpccmr1 |= (sConfig->IC1Filter << 4U) | (sConfig->IC2Filter << 12U); |
3005 | tmpccmr1 |= (sConfig->IC1Filter << 4U) | (sConfig->IC2Filter << 12U); |
2340 | 3006 | ||
2341 | /* Set the TI1 and the TI2 Polarities */ |
3007 | /* Set the TI1 and the TI2 Polarities */ |
2342 | tmpccer &= ~(TIM_CCER_CC1P | TIM_CCER_CC2P); |
3008 | tmpccer &= ~(TIM_CCER_CC1P | TIM_CCER_CC2P); |
2343 | tmpccer &= ~(TIM_CCER_CC1NP | TIM_CCER_CC2NP); |
- | |
2344 | tmpccer |= sConfig->IC1Polarity | (sConfig->IC2Polarity << 4U); |
3009 | tmpccer |= sConfig->IC1Polarity | (sConfig->IC2Polarity << 4U); |
2345 | 3010 | ||
2346 | /* Write to TIMx SMCR */ |
3011 | /* Write to TIMx SMCR */ |
2347 | htim->Instance->SMCR = tmpsmcr; |
3012 | htim->Instance->SMCR = tmpsmcr; |
2348 | 3013 | ||
Line 2350... | Line 3015... | ||
2350 | htim->Instance->CCMR1 = tmpccmr1; |
3015 | htim->Instance->CCMR1 = tmpccmr1; |
2351 | 3016 | ||
2352 | /* Write to TIMx CCER */ |
3017 | /* Write to TIMx CCER */ |
2353 | htim->Instance->CCER = tmpccer; |
3018 | htim->Instance->CCER = tmpccer; |
2354 | 3019 | ||
- | 3020 | /* Initialize the DMA burst operation state */ |
|
- | 3021 | htim->DMABurstState = HAL_DMA_BURST_STATE_READY; |
|
- | 3022 | ||
- | 3023 | /* Set the TIM channels state */ |
|
- | 3024 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY); |
|
- | 3025 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY); |
|
- | 3026 | TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY); |
|
- | 3027 | TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY); |
|
- | 3028 | ||
2355 | /* Initialize the TIM state*/ |
3029 | /* Initialize the TIM state*/ |
2356 | htim->State= HAL_TIM_STATE_READY; |
3030 | htim->State = HAL_TIM_STATE_READY; |
2357 | 3031 | ||
2358 | return HAL_OK; |
3032 | return HAL_OK; |
2359 | } |
3033 | } |
2360 | 3034 | ||
2361 | 3035 | ||
2362 | /** |
3036 | /** |
2363 | * @brief DeInitializes the TIM Encoder interface |
3037 | * @brief DeInitializes the TIM Encoder interface |
2364 | * @param htim : TIM Encoder handle |
3038 | * @param htim TIM Encoder Interface handle |
2365 | * @retval HAL status |
3039 | * @retval HAL status |
2366 | */ |
3040 | */ |
2367 | HAL_StatusTypeDef HAL_TIM_Encoder_DeInit(TIM_HandleTypeDef *htim) |
3041 | HAL_StatusTypeDef HAL_TIM_Encoder_DeInit(TIM_HandleTypeDef *htim) |
2368 | { |
3042 | { |
2369 | /* Check the parameters */ |
3043 | /* Check the parameters */ |
Line 2372... | Line 3046... | ||
2372 | htim->State = HAL_TIM_STATE_BUSY; |
3046 | htim->State = HAL_TIM_STATE_BUSY; |
2373 | 3047 | ||
2374 | /* Disable the TIM Peripheral Clock */ |
3048 | /* Disable the TIM Peripheral Clock */ |
2375 | __HAL_TIM_DISABLE(htim); |
3049 | __HAL_TIM_DISABLE(htim); |
2376 | 3050 | ||
- | 3051 | #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) |
|
- | 3052 | if (htim->Encoder_MspDeInitCallback == NULL) |
|
- | 3053 | { |
|
- | 3054 | htim->Encoder_MspDeInitCallback = HAL_TIM_Encoder_MspDeInit; |
|
- | 3055 | } |
|
- | 3056 | /* DeInit the low level hardware */ |
|
- | 3057 | htim->Encoder_MspDeInitCallback(htim); |
|
- | 3058 | #else |
|
2377 | /* DeInit the low level hardware: GPIO, CLOCK, NVIC */ |
3059 | /* DeInit the low level hardware: GPIO, CLOCK, NVIC */ |
2378 | HAL_TIM_Encoder_MspDeInit(htim); |
3060 | HAL_TIM_Encoder_MspDeInit(htim); |
- | 3061 | #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */ |
|
- | 3062 | ||
- | 3063 | /* Change the DMA burst operation state */ |
|
- | 3064 | htim->DMABurstState = HAL_DMA_BURST_STATE_RESET; |
|
- | 3065 | ||
- | 3066 | /* Set the TIM channels state */ |
|
- | 3067 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_RESET); |
|
- | 3068 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_RESET); |
|
- | 3069 | TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_RESET); |
|
- | 3070 | TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_RESET); |
|
2379 | 3071 | ||
2380 | /* Change TIM state */ |
3072 | /* Change TIM state */ |
2381 | htim->State = HAL_TIM_STATE_RESET; |
3073 | htim->State = HAL_TIM_STATE_RESET; |
2382 | 3074 | ||
2383 | /* Release Lock */ |
3075 | /* Release Lock */ |
Line 2386... | Line 3078... | ||
2386 | return HAL_OK; |
3078 | return HAL_OK; |
2387 | } |
3079 | } |
2388 | 3080 | ||
2389 | /** |
3081 | /** |
2390 | * @brief Initializes the TIM Encoder Interface MSP. |
3082 | * @brief Initializes the TIM Encoder Interface MSP. |
2391 | * @param htim : TIM handle |
3083 | * @param htim TIM Encoder Interface handle |
2392 | * @retval None |
3084 | * @retval None |
2393 | */ |
3085 | */ |
2394 | __weak void HAL_TIM_Encoder_MspInit(TIM_HandleTypeDef *htim) |
3086 | __weak void HAL_TIM_Encoder_MspInit(TIM_HandleTypeDef *htim) |
2395 | { |
3087 | { |
2396 | /* Prevent unused argument(s) compilation warning */ |
3088 | /* Prevent unused argument(s) compilation warning */ |
2397 | UNUSED(htim); |
3089 | UNUSED(htim); |
- | 3090 | ||
2398 | /* NOTE : This function Should not be modified, when the callback is needed, |
3091 | /* NOTE : This function should not be modified, when the callback is needed, |
2399 | the HAL_TIM_Encoder_MspInit could be implemented in the user file |
3092 | the HAL_TIM_Encoder_MspInit could be implemented in the user file |
2400 | */ |
3093 | */ |
2401 | } |
3094 | } |
2402 | 3095 | ||
2403 | /** |
3096 | /** |
2404 | * @brief DeInitializes TIM Encoder Interface MSP. |
3097 | * @brief DeInitializes TIM Encoder Interface MSP. |
2405 | * @param htim : TIM handle |
3098 | * @param htim TIM Encoder Interface handle |
2406 | * @retval None |
3099 | * @retval None |
2407 | */ |
3100 | */ |
2408 | __weak void HAL_TIM_Encoder_MspDeInit(TIM_HandleTypeDef *htim) |
3101 | __weak void HAL_TIM_Encoder_MspDeInit(TIM_HandleTypeDef *htim) |
2409 | { |
3102 | { |
2410 | /* Prevent unused argument(s) compilation warning */ |
3103 | /* Prevent unused argument(s) compilation warning */ |
2411 | UNUSED(htim); |
3104 | UNUSED(htim); |
- | 3105 | ||
2412 | /* NOTE : This function Should not be modified, when the callback is needed, |
3106 | /* NOTE : This function should not be modified, when the callback is needed, |
2413 | the HAL_TIM_Encoder_MspDeInit could be implemented in the user file |
3107 | the HAL_TIM_Encoder_MspDeInit could be implemented in the user file |
2414 | */ |
3108 | */ |
2415 | } |
3109 | } |
2416 | 3110 | ||
2417 | /** |
3111 | /** |
2418 | * @brief Starts the TIM Encoder Interface. |
3112 | * @brief Starts the TIM Encoder Interface. |
2419 | * @param htim : TIM Encoder Interface handle |
3113 | * @param htim TIM Encoder Interface handle |
2420 | * @param Channel : TIM Channels to be enabled |
3114 | * @param Channel TIM Channels to be enabled |
2421 | * This parameter can be one of the following values: |
3115 | * This parameter can be one of the following values: |
2422 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
3116 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
2423 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
3117 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
2424 | * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected |
3118 | * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected |
2425 | * @retval HAL status |
3119 | * @retval HAL status |
2426 | */ |
3120 | */ |
2427 | HAL_StatusTypeDef HAL_TIM_Encoder_Start(TIM_HandleTypeDef *htim, uint32_t Channel) |
3121 | HAL_StatusTypeDef HAL_TIM_Encoder_Start(TIM_HandleTypeDef *htim, uint32_t Channel) |
2428 | { |
3122 | { |
- | 3123 | HAL_TIM_ChannelStateTypeDef channel_1_state = TIM_CHANNEL_STATE_GET(htim, TIM_CHANNEL_1); |
|
- | 3124 | HAL_TIM_ChannelStateTypeDef channel_2_state = TIM_CHANNEL_STATE_GET(htim, TIM_CHANNEL_2); |
|
- | 3125 | HAL_TIM_ChannelStateTypeDef complementary_channel_1_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_1); |
|
- | 3126 | HAL_TIM_ChannelStateTypeDef complementary_channel_2_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_2); |
|
- | 3127 | ||
2429 | /* Check the parameters */ |
3128 | /* Check the parameters */ |
2430 | assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); |
3129 | assert_param(IS_TIM_ENCODER_INTERFACE_INSTANCE(htim->Instance)); |
- | 3130 | ||
- | 3131 | /* Set the TIM channel(s) state */ |
|
- | 3132 | if (Channel == TIM_CHANNEL_1) |
|
- | 3133 | { |
|
- | 3134 | if ((channel_1_state != HAL_TIM_CHANNEL_STATE_READY) |
|
- | 3135 | || (complementary_channel_1_state != HAL_TIM_CHANNEL_STATE_READY)) |
|
- | 3136 | { |
|
- | 3137 | return HAL_ERROR; |
|
- | 3138 | } |
|
- | 3139 | else |
|
- | 3140 | { |
|
- | 3141 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_BUSY); |
|
- | 3142 | TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_BUSY); |
|
- | 3143 | } |
|
- | 3144 | } |
|
- | 3145 | else if (Channel == TIM_CHANNEL_2) |
|
- | 3146 | { |
|
- | 3147 | if ((channel_2_state != HAL_TIM_CHANNEL_STATE_READY) |
|
- | 3148 | || (complementary_channel_2_state != HAL_TIM_CHANNEL_STATE_READY)) |
|
- | 3149 | { |
|
- | 3150 | return HAL_ERROR; |
|
- | 3151 | } |
|
- | 3152 | else |
|
- | 3153 | { |
|
- | 3154 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_BUSY); |
|
- | 3155 | TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_BUSY); |
|
- | 3156 | } |
|
- | 3157 | } |
|
- | 3158 | else |
|
- | 3159 | { |
|
- | 3160 | if ((channel_1_state != HAL_TIM_CHANNEL_STATE_READY) |
|
- | 3161 | || (channel_2_state != HAL_TIM_CHANNEL_STATE_READY) |
|
- | 3162 | || (complementary_channel_1_state != HAL_TIM_CHANNEL_STATE_READY) |
|
- | 3163 | || (complementary_channel_2_state != HAL_TIM_CHANNEL_STATE_READY)) |
|
- | 3164 | { |
|
- | 3165 | return HAL_ERROR; |
|
- | 3166 | } |
|
- | 3167 | else |
|
- | 3168 | { |
|
- | 3169 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_BUSY); |
|
- | 3170 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_BUSY); |
|
- | 3171 | TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_BUSY); |
|
- | 3172 | TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_BUSY); |
|
- | 3173 | } |
|
- | 3174 | } |
|
2431 | 3175 | ||
2432 | /* Enable the encoder interface channels */ |
3176 | /* Enable the encoder interface channels */ |
2433 | switch (Channel) |
3177 | switch (Channel) |
2434 | { |
3178 | { |
2435 | case TIM_CHANNEL_1: |
3179 | case TIM_CHANNEL_1: |
2436 | { |
3180 | { |
2437 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE); |
3181 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE); |
2438 | break; |
3182 | break; |
2439 | } |
3183 | } |
- | 3184 | ||
2440 | case TIM_CHANNEL_2: |
3185 | case TIM_CHANNEL_2: |
2441 | { |
3186 | { |
2442 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE); |
3187 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE); |
2443 | break; |
3188 | break; |
2444 | } |
3189 | } |
- | 3190 | ||
2445 | default : |
3191 | default : |
2446 | { |
3192 | { |
2447 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE); |
3193 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE); |
2448 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE); |
3194 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE); |
2449 | break; |
3195 | break; |
2450 | } |
3196 | } |
2451 | } |
3197 | } |
2452 | /* Enable the Peripheral */ |
3198 | /* Enable the Peripheral */ |
2453 | __HAL_TIM_ENABLE(htim); |
3199 | __HAL_TIM_ENABLE(htim); |
2454 | 3200 | ||
Line 2456... | Line 3202... | ||
2456 | return HAL_OK; |
3202 | return HAL_OK; |
2457 | } |
3203 | } |
2458 | 3204 | ||
2459 | /** |
3205 | /** |
2460 | * @brief Stops the TIM Encoder Interface. |
3206 | * @brief Stops the TIM Encoder Interface. |
2461 | * @param htim : TIM Encoder Interface handle |
3207 | * @param htim TIM Encoder Interface handle |
2462 | * @param Channel : TIM Channels to be disabled |
3208 | * @param Channel TIM Channels to be disabled |
2463 | * This parameter can be one of the following values: |
3209 | * This parameter can be one of the following values: |
2464 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
3210 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
2465 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
3211 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
2466 | * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected |
3212 | * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected |
2467 | * @retval HAL status |
3213 | * @retval HAL status |
2468 | */ |
3214 | */ |
2469 | HAL_StatusTypeDef HAL_TIM_Encoder_Stop(TIM_HandleTypeDef *htim, uint32_t Channel) |
3215 | HAL_StatusTypeDef HAL_TIM_Encoder_Stop(TIM_HandleTypeDef *htim, uint32_t Channel) |
2470 | { |
3216 | { |
2471 | /* Check the parameters */ |
3217 | /* Check the parameters */ |
2472 | assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); |
3218 | assert_param(IS_TIM_ENCODER_INTERFACE_INSTANCE(htim->Instance)); |
2473 | 3219 | ||
2474 | /* Disable the Input Capture channels 1 and 2 |
3220 | /* Disable the Input Capture channels 1 and 2 |
2475 | (in the EncoderInterface the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2) */ |
3221 | (in the EncoderInterface the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2) */ |
2476 | switch (Channel) |
3222 | switch (Channel) |
2477 | { |
3223 | { |
2478 | case TIM_CHANNEL_1: |
3224 | case TIM_CHANNEL_1: |
2479 | { |
3225 | { |
2480 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE); |
3226 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE); |
2481 | break; |
3227 | break; |
2482 | } |
3228 | } |
- | 3229 | ||
2483 | case TIM_CHANNEL_2: |
3230 | case TIM_CHANNEL_2: |
2484 | { |
3231 | { |
2485 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE); |
3232 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE); |
2486 | break; |
3233 | break; |
2487 | } |
3234 | } |
- | 3235 | ||
2488 | default : |
3236 | default : |
2489 | { |
3237 | { |
2490 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE); |
3238 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE); |
2491 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE); |
3239 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE); |
2492 | break; |
3240 | break; |
2493 | } |
3241 | } |
2494 | } |
3242 | } |
2495 | 3243 | ||
2496 | /* Disable the Peripheral */ |
3244 | /* Disable the Peripheral */ |
2497 | __HAL_TIM_DISABLE(htim); |
3245 | __HAL_TIM_DISABLE(htim); |
2498 | 3246 | ||
- | 3247 | /* Set the TIM channel(s) state */ |
|
- | 3248 | if ((Channel == TIM_CHANNEL_1) || (Channel == TIM_CHANNEL_2)) |
|
- | 3249 | { |
|
- | 3250 | TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY); |
|
- | 3251 | TIM_CHANNEL_N_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY); |
|
- | 3252 | } |
|
- | 3253 | else |
|
- | 3254 | { |
|
- | 3255 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY); |
|
- | 3256 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY); |
|
- | 3257 | TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY); |
|
- | 3258 | TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY); |
|
- | 3259 | } |
|
- | 3260 | ||
2499 | /* Return function status */ |
3261 | /* Return function status */ |
2500 | return HAL_OK; |
3262 | return HAL_OK; |
2501 | } |
3263 | } |
2502 | 3264 | ||
2503 | /** |
3265 | /** |
2504 | * @brief Starts the TIM Encoder Interface in interrupt mode. |
3266 | * @brief Starts the TIM Encoder Interface in interrupt mode. |
2505 | * @param htim : TIM Encoder Interface handle |
3267 | * @param htim TIM Encoder Interface handle |
2506 | * @param Channel : TIM Channels to be enabled |
3268 | * @param Channel TIM Channels to be enabled |
2507 | * This parameter can be one of the following values: |
3269 | * This parameter can be one of the following values: |
2508 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
3270 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
2509 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
3271 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
2510 | * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected |
3272 | * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected |
2511 | * @retval HAL status |
3273 | * @retval HAL status |
2512 | */ |
3274 | */ |
2513 | HAL_StatusTypeDef HAL_TIM_Encoder_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel) |
3275 | HAL_StatusTypeDef HAL_TIM_Encoder_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel) |
2514 | { |
3276 | { |
- | 3277 | HAL_TIM_ChannelStateTypeDef channel_1_state = TIM_CHANNEL_STATE_GET(htim, TIM_CHANNEL_1); |
|
- | 3278 | HAL_TIM_ChannelStateTypeDef channel_2_state = TIM_CHANNEL_STATE_GET(htim, TIM_CHANNEL_2); |
|
- | 3279 | HAL_TIM_ChannelStateTypeDef complementary_channel_1_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_1); |
|
- | 3280 | HAL_TIM_ChannelStateTypeDef complementary_channel_2_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_2); |
|
- | 3281 | ||
2515 | /* Check the parameters */ |
3282 | /* Check the parameters */ |
2516 | assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); |
3283 | assert_param(IS_TIM_ENCODER_INTERFACE_INSTANCE(htim->Instance)); |
- | 3284 | ||
- | 3285 | /* Set the TIM channel(s) state */ |
|
- | 3286 | if (Channel == TIM_CHANNEL_1) |
|
- | 3287 | { |
|
- | 3288 | if ((channel_1_state != HAL_TIM_CHANNEL_STATE_READY) |
|
- | 3289 | || (complementary_channel_1_state != HAL_TIM_CHANNEL_STATE_READY)) |
|
- | 3290 | { |
|
- | 3291 | return HAL_ERROR; |
|
- | 3292 | } |
|
- | 3293 | else |
|
- | 3294 | { |
|
- | 3295 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_BUSY); |
|
- | 3296 | TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_BUSY); |
|
- | 3297 | } |
|
- | 3298 | } |
|
- | 3299 | else if (Channel == TIM_CHANNEL_2) |
|
- | 3300 | { |
|
- | 3301 | if ((channel_2_state != HAL_TIM_CHANNEL_STATE_READY) |
|
- | 3302 | || (complementary_channel_2_state != HAL_TIM_CHANNEL_STATE_READY)) |
|
- | 3303 | { |
|
- | 3304 | return HAL_ERROR; |
|
- | 3305 | } |
|
- | 3306 | else |
|
- | 3307 | { |
|
- | 3308 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_BUSY); |
|
- | 3309 | TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_BUSY); |
|
- | 3310 | } |
|
- | 3311 | } |
|
- | 3312 | else |
|
- | 3313 | { |
|
- | 3314 | if ((channel_1_state != HAL_TIM_CHANNEL_STATE_READY) |
|
- | 3315 | || (channel_2_state != HAL_TIM_CHANNEL_STATE_READY) |
|
- | 3316 | || (complementary_channel_1_state != HAL_TIM_CHANNEL_STATE_READY) |
|
- | 3317 | || (complementary_channel_2_state != HAL_TIM_CHANNEL_STATE_READY)) |
|
- | 3318 | { |
|
- | 3319 | return HAL_ERROR; |
|
- | 3320 | } |
|
- | 3321 | else |
|
- | 3322 | { |
|
- | 3323 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_BUSY); |
|
- | 3324 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_BUSY); |
|
- | 3325 | TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_BUSY); |
|
- | 3326 | TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_BUSY); |
|
- | 3327 | } |
|
- | 3328 | } |
|
2517 | 3329 | ||
2518 | /* Enable the encoder interface channels */ |
3330 | /* Enable the encoder interface channels */ |
2519 | /* Enable the capture compare Interrupts 1 and/or 2 */ |
3331 | /* Enable the capture compare Interrupts 1 and/or 2 */ |
2520 | switch (Channel) |
3332 | switch (Channel) |
2521 | { |
3333 | { |
2522 | case TIM_CHANNEL_1: |
3334 | case TIM_CHANNEL_1: |
2523 | { |
3335 | { |
2524 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE); |
3336 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE); |
2525 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1); |
3337 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1); |
2526 | break; |
3338 | break; |
2527 | } |
3339 | } |
- | 3340 | ||
2528 | case TIM_CHANNEL_2: |
3341 | case TIM_CHANNEL_2: |
2529 | { |
3342 | { |
2530 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE); |
3343 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE); |
2531 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2); |
3344 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2); |
2532 | break; |
3345 | break; |
2533 | } |
3346 | } |
- | 3347 | ||
2534 | default : |
3348 | default : |
2535 | { |
3349 | { |
2536 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE); |
3350 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE); |
2537 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE); |
3351 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE); |
2538 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1); |
3352 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1); |
2539 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2); |
3353 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2); |
2540 | break; |
3354 | break; |
2541 | } |
3355 | } |
2542 | } |
3356 | } |
2543 | 3357 | ||
2544 | /* Enable the Peripheral */ |
3358 | /* Enable the Peripheral */ |
2545 | __HAL_TIM_ENABLE(htim); |
3359 | __HAL_TIM_ENABLE(htim); |
Line 2548... | Line 3362... | ||
2548 | return HAL_OK; |
3362 | return HAL_OK; |
2549 | } |
3363 | } |
2550 | 3364 | ||
2551 | /** |
3365 | /** |
2552 | * @brief Stops the TIM Encoder Interface in interrupt mode. |
3366 | * @brief Stops the TIM Encoder Interface in interrupt mode. |
2553 | * @param htim : TIM Encoder Interface handle |
3367 | * @param htim TIM Encoder Interface handle |
2554 | * @param Channel : TIM Channels to be disabled |
3368 | * @param Channel TIM Channels to be disabled |
2555 | * This parameter can be one of the following values: |
3369 | * This parameter can be one of the following values: |
2556 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
3370 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
2557 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
3371 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
2558 | * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected |
3372 | * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected |
2559 | * @retval HAL status |
3373 | * @retval HAL status |
2560 | */ |
3374 | */ |
2561 | HAL_StatusTypeDef HAL_TIM_Encoder_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel) |
3375 | HAL_StatusTypeDef HAL_TIM_Encoder_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel) |
2562 | { |
3376 | { |
2563 | /* Check the parameters */ |
3377 | /* Check the parameters */ |
2564 | assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); |
3378 | assert_param(IS_TIM_ENCODER_INTERFACE_INSTANCE(htim->Instance)); |
2565 | 3379 | ||
2566 | /* Disable the Input Capture channels 1 and 2 |
3380 | /* Disable the Input Capture channels 1 and 2 |
2567 | (in the EncoderInterface the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2) */ |
3381 | (in the EncoderInterface the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2) */ |
2568 | if(Channel == TIM_CHANNEL_1) |
3382 | if (Channel == TIM_CHANNEL_1) |
2569 | { |
3383 | { |
2570 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE); |
3384 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE); |
2571 | 3385 | ||
2572 | /* Disable the capture compare Interrupts 1 */ |
3386 | /* Disable the capture compare Interrupts 1 */ |
2573 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1); |
3387 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1); |
2574 | } |
3388 | } |
2575 | else if(Channel == TIM_CHANNEL_2) |
3389 | else if (Channel == TIM_CHANNEL_2) |
2576 | { |
3390 | { |
2577 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE); |
3391 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE); |
2578 | 3392 | ||
2579 | /* Disable the capture compare Interrupts 2 */ |
3393 | /* Disable the capture compare Interrupts 2 */ |
2580 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2); |
3394 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2); |
2581 | } |
3395 | } |
2582 | else |
3396 | else |
2583 | { |
3397 | { |
2584 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE); |
3398 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE); |
2585 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE); |
3399 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE); |
Line 2590... | Line 3404... | ||
2590 | } |
3404 | } |
2591 | 3405 | ||
2592 | /* Disable the Peripheral */ |
3406 | /* Disable the Peripheral */ |
2593 | __HAL_TIM_DISABLE(htim); |
3407 | __HAL_TIM_DISABLE(htim); |
2594 | 3408 | ||
2595 | /* Change the htim state */ |
3409 | /* Set the TIM channel(s) state */ |
- | 3410 | if ((Channel == TIM_CHANNEL_1) || (Channel == TIM_CHANNEL_2)) |
|
- | 3411 | { |
|
2596 | htim->State = HAL_TIM_STATE_READY; |
3412 | TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY); |
- | 3413 | TIM_CHANNEL_N_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY); |
|
- | 3414 | } |
|
- | 3415 | else |
|
- | 3416 | { |
|
- | 3417 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY); |
|
- | 3418 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY); |
|
- | 3419 | TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY); |
|
- | 3420 | TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY); |
|
- | 3421 | } |
|
2597 | 3422 | ||
2598 | /* Return function status */ |
3423 | /* Return function status */ |
2599 | return HAL_OK; |
3424 | return HAL_OK; |
2600 | } |
3425 | } |
2601 | 3426 | ||
2602 | /** |
3427 | /** |
2603 | * @brief Starts the TIM Encoder Interface in DMA mode. |
3428 | * @brief Starts the TIM Encoder Interface in DMA mode. |
2604 | * @param htim : TIM Encoder Interface handle |
3429 | * @param htim TIM Encoder Interface handle |
2605 | * @param Channel : TIM Channels to be enabled |
3430 | * @param Channel TIM Channels to be enabled |
2606 | * This parameter can be one of the following values: |
3431 | * This parameter can be one of the following values: |
2607 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
3432 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
2608 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
3433 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
2609 | * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected |
3434 | * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected |
2610 | * @param pData1 : The destination Buffer address for IC1. |
3435 | * @param pData1 The destination Buffer address for IC1. |
2611 | * @param pData2 : The destination Buffer address for IC2. |
3436 | * @param pData2 The destination Buffer address for IC2. |
2612 | * @param Length : The length of data to be transferred from TIM peripheral to memory. |
3437 | * @param Length The length of data to be transferred from TIM peripheral to memory. |
2613 | * @retval HAL status |
3438 | * @retval HAL status |
2614 | */ |
3439 | */ |
2615 | HAL_StatusTypeDef HAL_TIM_Encoder_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData1, uint32_t *pData2, uint16_t Length) |
3440 | HAL_StatusTypeDef HAL_TIM_Encoder_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData1, |
- | 3441 | uint32_t *pData2, uint16_t Length) |
|
2616 | { |
3442 | { |
- | 3443 | HAL_TIM_ChannelStateTypeDef channel_1_state = TIM_CHANNEL_STATE_GET(htim, TIM_CHANNEL_1); |
|
- | 3444 | HAL_TIM_ChannelStateTypeDef channel_2_state = TIM_CHANNEL_STATE_GET(htim, TIM_CHANNEL_2); |
|
- | 3445 | HAL_TIM_ChannelStateTypeDef complementary_channel_1_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_1); |
|
- | 3446 | HAL_TIM_ChannelStateTypeDef complementary_channel_2_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_2); |
|
- | 3447 | ||
2617 | /* Check the parameters */ |
3448 | /* Check the parameters */ |
2618 | assert_param(IS_TIM_DMA_CC_INSTANCE(htim->Instance)); |
3449 | assert_param(IS_TIM_ENCODER_INTERFACE_INSTANCE(htim->Instance)); |
2619 | 3450 | ||
- | 3451 | /* Set the TIM channel(s) state */ |
|
2620 | if((htim->State == HAL_TIM_STATE_BUSY)) |
3452 | if (Channel == TIM_CHANNEL_1) |
2621 | { |
3453 | { |
- | 3454 | if ((channel_1_state == HAL_TIM_CHANNEL_STATE_BUSY) |
|
- | 3455 | || (complementary_channel_1_state == HAL_TIM_CHANNEL_STATE_BUSY)) |
|
- | 3456 | { |
|
2622 | return HAL_BUSY; |
3457 | return HAL_BUSY; |
- | 3458 | } |
|
- | 3459 | else if ((channel_1_state == HAL_TIM_CHANNEL_STATE_READY) |
|
- | 3460 | && (complementary_channel_1_state == HAL_TIM_CHANNEL_STATE_READY)) |
|
- | 3461 | { |
|
- | 3462 | if ((pData1 == NULL) && (Length > 0U)) |
|
- | 3463 | { |
|
- | 3464 | return HAL_ERROR; |
|
- | 3465 | } |
|
- | 3466 | else |
|
- | 3467 | { |
|
- | 3468 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_BUSY); |
|
- | 3469 | TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_BUSY); |
|
- | 3470 | } |
|
- | 3471 | } |
|
- | 3472 | else |
|
- | 3473 | { |
|
- | 3474 | return HAL_ERROR; |
|
- | 3475 | } |
|
2623 | } |
3476 | } |
2624 | else if((htim->State == HAL_TIM_STATE_READY)) |
3477 | else if (Channel == TIM_CHANNEL_2) |
2625 | { |
3478 | { |
- | 3479 | if ((channel_2_state == HAL_TIM_CHANNEL_STATE_BUSY) |
|
- | 3480 | || (complementary_channel_2_state == HAL_TIM_CHANNEL_STATE_BUSY)) |
|
- | 3481 | { |
|
- | 3482 | return HAL_BUSY; |
|
- | 3483 | } |
|
- | 3484 | else if ((channel_2_state == HAL_TIM_CHANNEL_STATE_READY) |
|
- | 3485 | && (complementary_channel_2_state == HAL_TIM_CHANNEL_STATE_READY)) |
|
- | 3486 | { |
|
2626 | if((((pData1 == 0U) || (pData2 == 0U) )) && (Length > 0U)) |
3487 | if ((pData2 == NULL) && (Length > 0U)) |
- | 3488 | { |
|
- | 3489 | return HAL_ERROR; |
|
- | 3490 | } |
|
- | 3491 | else |
|
- | 3492 | { |
|
- | 3493 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_BUSY); |
|
- | 3494 | TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_BUSY); |
|
- | 3495 | } |
|
- | 3496 | } |
|
- | 3497 | else |
|
2627 | { |
3498 | { |
2628 | return HAL_ERROR; |
3499 | return HAL_ERROR; |
2629 | } |
3500 | } |
- | 3501 | } |
|
- | 3502 | else |
|
- | 3503 | { |
|
- | 3504 | if ((channel_1_state == HAL_TIM_CHANNEL_STATE_BUSY) |
|
- | 3505 | || (channel_2_state == HAL_TIM_CHANNEL_STATE_BUSY) |
|
- | 3506 | || (complementary_channel_1_state == HAL_TIM_CHANNEL_STATE_BUSY) |
|
- | 3507 | || (complementary_channel_2_state == HAL_TIM_CHANNEL_STATE_BUSY)) |
|
- | 3508 | { |
|
- | 3509 | return HAL_BUSY; |
|
- | 3510 | } |
|
- | 3511 | else if ((channel_1_state == HAL_TIM_CHANNEL_STATE_READY) |
|
- | 3512 | && (channel_2_state == HAL_TIM_CHANNEL_STATE_READY) |
|
- | 3513 | && (complementary_channel_1_state == HAL_TIM_CHANNEL_STATE_READY) |
|
- | 3514 | && (complementary_channel_2_state == HAL_TIM_CHANNEL_STATE_READY)) |
|
- | 3515 | { |
|
- | 3516 | if ((((pData1 == NULL) || (pData2 == NULL))) && (Length > 0U)) |
|
- | 3517 | { |
|
- | 3518 | return HAL_ERROR; |
|
- | 3519 | } |
|
- | 3520 | else |
|
- | 3521 | { |
|
- | 3522 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_BUSY); |
|
- | 3523 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_BUSY); |
|
- | 3524 | TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_BUSY); |
|
- | 3525 | TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_BUSY); |
|
- | 3526 | } |
|
- | 3527 | } |
|
2630 | else |
3528 | else |
2631 | { |
3529 | { |
2632 | htim->State = HAL_TIM_STATE_BUSY; |
3530 | return HAL_ERROR; |
2633 | } |
3531 | } |
2634 | } |
3532 | } |
2635 | 3533 | ||
2636 | switch (Channel) |
3534 | switch (Channel) |
2637 | { |
3535 | { |
2638 | case TIM_CHANNEL_1: |
3536 | case TIM_CHANNEL_1: |
2639 | { |
3537 | { |
2640 | /* Set the DMA Period elapsed callback */ |
3538 | /* Set the DMA capture callbacks */ |
2641 | htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMACaptureCplt; |
3539 | htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMACaptureCplt; |
- | 3540 | htim->hdma[TIM_DMA_ID_CC1]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt; |
|
2642 | 3541 | ||
2643 | /* Set the DMA error callback */ |
3542 | /* Set the DMA error callback */ |
2644 | htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ; |
3543 | htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ; |
2645 | 3544 | ||
2646 | /* Enable the DMA channel */ |
3545 | /* Enable the DMA channel */ |
2647 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)&htim->Instance->CCR1, (uint32_t )pData1, Length); |
3546 | if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)&htim->Instance->CCR1, (uint32_t)pData1, Length) != HAL_OK) |
- | 3547 | { |
|
- | 3548 | /* Return error status */ |
|
- | 3549 | return HAL_ERROR; |
|
2648 | 3550 | } |
|
2649 | /* Enable the TIM Input Capture DMA request */ |
3551 | /* Enable the TIM Input Capture DMA request */ |
2650 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1); |
3552 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1); |
2651 | 3553 | ||
2652 | /* Enable the Peripheral */ |
3554 | /* Enable the Peripheral */ |
2653 | __HAL_TIM_ENABLE(htim); |
3555 | __HAL_TIM_ENABLE(htim); |
2654 | 3556 | ||
2655 | /* Enable the Capture compare channel */ |
3557 | /* Enable the Capture compare channel */ |
2656 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE); |
3558 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE); |
- | 3559 | break; |
|
2657 | } |
3560 | } |
2658 | break; |
- | |
2659 | 3561 | ||
2660 | case TIM_CHANNEL_2: |
3562 | case TIM_CHANNEL_2: |
2661 | { |
3563 | { |
2662 | /* Set the DMA Period elapsed callback */ |
3564 | /* Set the DMA capture callbacks */ |
2663 | htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMACaptureCplt; |
3565 | htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMACaptureCplt; |
- | 3566 | htim->hdma[TIM_DMA_ID_CC2]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt; |
|
2664 | 3567 | ||
2665 | /* Set the DMA error callback */ |
3568 | /* Set the DMA error callback */ |
2666 | htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError; |
3569 | htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError; |
2667 | /* Enable the DMA channel */ |
3570 | /* Enable the DMA channel */ |
2668 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)&htim->Instance->CCR2, (uint32_t)pData2, Length); |
3571 | if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)&htim->Instance->CCR2, (uint32_t)pData2, Length) != HAL_OK) |
- | 3572 | { |
|
- | 3573 | /* Return error status */ |
|
- | 3574 | return HAL_ERROR; |
|
2669 | 3575 | } |
|
2670 | /* Enable the TIM Input Capture DMA request */ |
3576 | /* Enable the TIM Input Capture DMA request */ |
2671 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2); |
3577 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2); |
2672 | 3578 | ||
2673 | /* Enable the Peripheral */ |
3579 | /* Enable the Peripheral */ |
2674 | __HAL_TIM_ENABLE(htim); |
3580 | __HAL_TIM_ENABLE(htim); |
2675 | 3581 | ||
2676 | /* Enable the Capture compare channel */ |
3582 | /* Enable the Capture compare channel */ |
2677 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE); |
3583 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE); |
- | 3584 | break; |
|
2678 | } |
3585 | } |
2679 | break; |
- | |
2680 | 3586 | ||
2681 | case TIM_CHANNEL_ALL: |
3587 | case TIM_CHANNEL_ALL: |
2682 | { |
3588 | { |
2683 | /* Set the DMA Period elapsed callback */ |
3589 | /* Set the DMA capture callbacks */ |
2684 | htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMACaptureCplt; |
3590 | htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMACaptureCplt; |
- | 3591 | htim->hdma[TIM_DMA_ID_CC1]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt; |
|
2685 | 3592 | ||
2686 | /* Set the DMA error callback */ |
3593 | /* Set the DMA error callback */ |
2687 | htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ; |
3594 | htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ; |
2688 | 3595 | ||
2689 | /* Enable the DMA channel */ |
3596 | /* Enable the DMA channel */ |
2690 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)&htim->Instance->CCR1, (uint32_t)pData1, Length); |
3597 | if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)&htim->Instance->CCR1, (uint32_t)pData1, Length) != HAL_OK) |
- | 3598 | { |
|
- | 3599 | /* Return error status */ |
|
- | 3600 | return HAL_ERROR; |
|
- | 3601 | } |
|
2691 | 3602 | ||
2692 | /* Set the DMA Period elapsed callback */ |
3603 | /* Set the DMA capture callbacks */ |
2693 | htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMACaptureCplt; |
3604 | htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMACaptureCplt; |
- | 3605 | htim->hdma[TIM_DMA_ID_CC2]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt; |
|
2694 | 3606 | ||
2695 | /* Set the DMA error callback */ |
3607 | /* Set the DMA error callback */ |
2696 | htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError ; |
3608 | htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError ; |
2697 | 3609 | ||
2698 | /* Enable the DMA channel */ |
3610 | /* Enable the DMA channel */ |
2699 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)&htim->Instance->CCR2, (uint32_t)pData2, Length); |
3611 | if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)&htim->Instance->CCR2, (uint32_t)pData2, Length) != HAL_OK) |
- | 3612 | { |
|
- | 3613 | /* Return error status */ |
|
- | 3614 | return HAL_ERROR; |
|
2700 | 3615 | } |
|
2701 | /* Enable the Peripheral */ |
3616 | /* Enable the Peripheral */ |
2702 | __HAL_TIM_ENABLE(htim); |
3617 | __HAL_TIM_ENABLE(htim); |
2703 | 3618 | ||
2704 | /* Enable the Capture compare channel */ |
3619 | /* Enable the Capture compare channel */ |
2705 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE); |
3620 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE); |
2706 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE); |
3621 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE); |
2707 | 3622 | ||
2708 | /* Enable the TIM Input Capture DMA request */ |
3623 | /* Enable the TIM Input Capture DMA request */ |
2709 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1); |
3624 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1); |
2710 | /* Enable the TIM Input Capture DMA request */ |
3625 | /* Enable the TIM Input Capture DMA request */ |
2711 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2); |
3626 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2); |
- | 3627 | break; |
|
2712 | } |
3628 | } |
2713 | break; |
- | |
2714 | 3629 | ||
2715 | default: |
3630 | default: |
2716 | break; |
3631 | break; |
2717 | } |
3632 | } |
- | 3633 | ||
2718 | /* Return function status */ |
3634 | /* Return function status */ |
2719 | return HAL_OK; |
3635 | return HAL_OK; |
2720 | } |
3636 | } |
2721 | 3637 | ||
2722 | /** |
3638 | /** |
2723 | * @brief Stops the TIM Encoder Interface in DMA mode. |
3639 | * @brief Stops the TIM Encoder Interface in DMA mode. |
2724 | * @param htim : TIM Encoder Interface handle |
3640 | * @param htim TIM Encoder Interface handle |
2725 | * @param Channel : TIM Channels to be enabled |
3641 | * @param Channel TIM Channels to be enabled |
2726 | * This parameter can be one of the following values: |
3642 | * This parameter can be one of the following values: |
2727 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
3643 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
2728 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
3644 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
2729 | * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected |
3645 | * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected |
2730 | * @retval HAL status |
3646 | * @retval HAL status |
2731 | */ |
3647 | */ |
2732 | HAL_StatusTypeDef HAL_TIM_Encoder_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel) |
3648 | HAL_StatusTypeDef HAL_TIM_Encoder_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel) |
2733 | { |
3649 | { |
2734 | /* Check the parameters */ |
3650 | /* Check the parameters */ |
2735 | assert_param(IS_TIM_DMA_CC_INSTANCE(htim->Instance)); |
3651 | assert_param(IS_TIM_ENCODER_INTERFACE_INSTANCE(htim->Instance)); |
2736 | 3652 | ||
2737 | /* Disable the Input Capture channels 1 and 2 |
3653 | /* Disable the Input Capture channels 1 and 2 |
2738 | (in the EncoderInterface the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2) */ |
3654 | (in the EncoderInterface the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2) */ |
2739 | if(Channel == TIM_CHANNEL_1) |
3655 | if (Channel == TIM_CHANNEL_1) |
2740 | { |
3656 | { |
2741 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE); |
3657 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE); |
2742 | 3658 | ||
2743 | /* Disable the capture compare DMA Request 1 */ |
3659 | /* Disable the capture compare DMA Request 1 */ |
2744 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1); |
3660 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1); |
- | 3661 | (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC1]); |
|
2745 | } |
3662 | } |
2746 | else if(Channel == TIM_CHANNEL_2) |
3663 | else if (Channel == TIM_CHANNEL_2) |
2747 | { |
3664 | { |
2748 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE); |
3665 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE); |
2749 | 3666 | ||
2750 | /* Disable the capture compare DMA Request 2 */ |
3667 | /* Disable the capture compare DMA Request 2 */ |
2751 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2); |
3668 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2); |
- | 3669 | (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC2]); |
|
2752 | } |
3670 | } |
2753 | else |
3671 | else |
2754 | { |
3672 | { |
2755 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE); |
3673 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE); |
2756 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE); |
3674 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE); |
2757 | 3675 | ||
2758 | /* Disable the capture compare DMA Request 1 and 2 */ |
3676 | /* Disable the capture compare DMA Request 1 and 2 */ |
2759 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1); |
3677 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1); |
2760 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2); |
3678 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2); |
- | 3679 | (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC1]); |
|
- | 3680 | (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC2]); |
|
2761 | } |
3681 | } |
2762 | 3682 | ||
2763 | /* Disable the Peripheral */ |
3683 | /* Disable the Peripheral */ |
2764 | __HAL_TIM_DISABLE(htim); |
3684 | __HAL_TIM_DISABLE(htim); |
2765 | 3685 | ||
2766 | /* Change the htim state */ |
3686 | /* Set the TIM channel(s) state */ |
- | 3687 | if ((Channel == TIM_CHANNEL_1) || (Channel == TIM_CHANNEL_2)) |
|
- | 3688 | { |
|
2767 | htim->State = HAL_TIM_STATE_READY; |
3689 | TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY); |
- | 3690 | TIM_CHANNEL_N_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY); |
|
- | 3691 | } |
|
- | 3692 | else |
|
- | 3693 | { |
|
- | 3694 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY); |
|
- | 3695 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY); |
|
- | 3696 | TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY); |
|
- | 3697 | TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY); |
|
- | 3698 | } |
|
2768 | 3699 | ||
2769 | /* Return function status */ |
3700 | /* Return function status */ |
2770 | return HAL_OK; |
3701 | return HAL_OK; |
2771 | } |
3702 | } |
2772 | 3703 | ||
2773 | /** |
3704 | /** |
2774 | * @} |
3705 | * @} |
2775 | */ |
3706 | */ |
2776 | /** @defgroup TIM_Exported_Functions_Group7 TIM IRQ handler management |
3707 | /** @defgroup TIM_Exported_Functions_Group7 TIM IRQ handler management |
2777 | * @brief IRQ handler management |
3708 | * @brief TIM IRQ handler management |
2778 | * |
3709 | * |
2779 | @verbatim |
3710 | @verbatim |
2780 | ============================================================================== |
3711 | ============================================================================== |
2781 | ##### IRQ handler management ##### |
3712 | ##### IRQ handler management ##### |
2782 | ============================================================================== |
3713 | ============================================================================== |
2783 | [..] |
3714 | [..] |
2784 | This section provides Timer IRQ handler function. |
3715 | This section provides Timer IRQ handler function. |
Line 2786... | Line 3717... | ||
2786 | @endverbatim |
3717 | @endverbatim |
2787 | * @{ |
3718 | * @{ |
2788 | */ |
3719 | */ |
2789 | /** |
3720 | /** |
2790 | * @brief This function handles TIM interrupts requests. |
3721 | * @brief This function handles TIM interrupts requests. |
2791 | * @param htim : TIM handle |
3722 | * @param htim TIM handle |
2792 | * @retval None |
3723 | * @retval None |
2793 | */ |
3724 | */ |
2794 | void HAL_TIM_IRQHandler(TIM_HandleTypeDef *htim) |
3725 | void HAL_TIM_IRQHandler(TIM_HandleTypeDef *htim) |
2795 | { |
3726 | { |
2796 | /* Capture compare 1 event */ |
3727 | /* Capture compare 1 event */ |
2797 | if(__HAL_TIM_GET_FLAG(htim, TIM_FLAG_CC1) != RESET) |
3728 | if (__HAL_TIM_GET_FLAG(htim, TIM_FLAG_CC1) != RESET) |
2798 | { |
3729 | { |
2799 | if(__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_CC1) !=RESET) |
3730 | if (__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_CC1) != RESET) |
2800 | { |
3731 | { |
2801 | { |
3732 | { |
2802 | __HAL_TIM_CLEAR_IT(htim, TIM_IT_CC1); |
3733 | __HAL_TIM_CLEAR_IT(htim, TIM_IT_CC1); |
2803 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_1; |
3734 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_1; |
2804 | 3735 | ||
2805 | /* Input capture event */ |
3736 | /* Input capture event */ |
2806 | if((htim->Instance->CCMR1 & TIM_CCMR1_CC1S) != 0x00U) |
3737 | if ((htim->Instance->CCMR1 & TIM_CCMR1_CC1S) != 0x00U) |
2807 | { |
3738 | { |
- | 3739 | #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) |
|
- | 3740 | htim->IC_CaptureCallback(htim); |
|
- | 3741 | #else |
|
2808 | HAL_TIM_IC_CaptureCallback(htim); |
3742 | HAL_TIM_IC_CaptureCallback(htim); |
- | 3743 | #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */ |
|
2809 | } |
3744 | } |
2810 | /* Output compare event */ |
3745 | /* Output compare event */ |
2811 | else |
3746 | else |
2812 | { |
3747 | { |
- | 3748 | #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) |
|
- | 3749 | htim->OC_DelayElapsedCallback(htim); |
|
- | 3750 | htim->PWM_PulseFinishedCallback(htim); |
|
- | 3751 | #else |
|
2813 | HAL_TIM_OC_DelayElapsedCallback(htim); |
3752 | HAL_TIM_OC_DelayElapsedCallback(htim); |
2814 | HAL_TIM_PWM_PulseFinishedCallback(htim); |
3753 | HAL_TIM_PWM_PulseFinishedCallback(htim); |
- | 3754 | #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */ |
|
2815 | } |
3755 | } |
2816 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED; |
3756 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED; |
2817 | } |
3757 | } |
2818 | } |
3758 | } |
2819 | } |
3759 | } |
2820 | /* Capture compare 2 event */ |
3760 | /* Capture compare 2 event */ |
2821 | if(__HAL_TIM_GET_FLAG(htim, TIM_FLAG_CC2) != RESET) |
3761 | if (__HAL_TIM_GET_FLAG(htim, TIM_FLAG_CC2) != RESET) |
2822 | { |
3762 | { |
2823 | if(__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_CC2) !=RESET) |
3763 | if (__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_CC2) != RESET) |
2824 | { |
3764 | { |
2825 | __HAL_TIM_CLEAR_IT(htim, TIM_IT_CC2); |
3765 | __HAL_TIM_CLEAR_IT(htim, TIM_IT_CC2); |
2826 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_2; |
3766 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_2; |
2827 | /* Input capture event */ |
3767 | /* Input capture event */ |
2828 | if((htim->Instance->CCMR1 & TIM_CCMR1_CC2S) != 0x00U) |
3768 | if ((htim->Instance->CCMR1 & TIM_CCMR1_CC2S) != 0x00U) |
2829 | { |
3769 | { |
- | 3770 | #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) |
|
- | 3771 | htim->IC_CaptureCallback(htim); |
|
- | 3772 | #else |
|
2830 | HAL_TIM_IC_CaptureCallback(htim); |
3773 | HAL_TIM_IC_CaptureCallback(htim); |
- | 3774 | #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */ |
|
2831 | } |
3775 | } |
2832 | /* Output compare event */ |
3776 | /* Output compare event */ |
2833 | else |
3777 | else |
2834 | { |
3778 | { |
- | 3779 | #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) |
|
- | 3780 | htim->OC_DelayElapsedCallback(htim); |
|
- | 3781 | htim->PWM_PulseFinishedCallback(htim); |
|
- | 3782 | #else |
|
2835 | HAL_TIM_OC_DelayElapsedCallback(htim); |
3783 | HAL_TIM_OC_DelayElapsedCallback(htim); |
2836 | HAL_TIM_PWM_PulseFinishedCallback(htim); |
3784 | HAL_TIM_PWM_PulseFinishedCallback(htim); |
- | 3785 | #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */ |
|
2837 | } |
3786 | } |
2838 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED; |
3787 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED; |
2839 | } |
3788 | } |
2840 | } |
3789 | } |
2841 | /* Capture compare 3 event */ |
3790 | /* Capture compare 3 event */ |
2842 | if(__HAL_TIM_GET_FLAG(htim, TIM_FLAG_CC3) != RESET) |
3791 | if (__HAL_TIM_GET_FLAG(htim, TIM_FLAG_CC3) != RESET) |
2843 | { |
3792 | { |
2844 | if(__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_CC3) !=RESET) |
3793 | if (__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_CC3) != RESET) |
2845 | { |
3794 | { |
2846 | __HAL_TIM_CLEAR_IT(htim, TIM_IT_CC3); |
3795 | __HAL_TIM_CLEAR_IT(htim, TIM_IT_CC3); |
2847 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_3; |
3796 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_3; |
2848 | /* Input capture event */ |
3797 | /* Input capture event */ |
2849 | if((htim->Instance->CCMR2 & TIM_CCMR2_CC3S) != 0x00U) |
3798 | if ((htim->Instance->CCMR2 & TIM_CCMR2_CC3S) != 0x00U) |
2850 | { |
3799 | { |
- | 3800 | #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) |
|
- | 3801 | htim->IC_CaptureCallback(htim); |
|
- | 3802 | #else |
|
2851 | HAL_TIM_IC_CaptureCallback(htim); |
3803 | HAL_TIM_IC_CaptureCallback(htim); |
- | 3804 | #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */ |
|
2852 | } |
3805 | } |
2853 | /* Output compare event */ |
3806 | /* Output compare event */ |
2854 | else |
3807 | else |
2855 | { |
3808 | { |
- | 3809 | #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) |
|
- | 3810 | htim->OC_DelayElapsedCallback(htim); |
|
- | 3811 | htim->PWM_PulseFinishedCallback(htim); |
|
- | 3812 | #else |
|
2856 | HAL_TIM_OC_DelayElapsedCallback(htim); |
3813 | HAL_TIM_OC_DelayElapsedCallback(htim); |
2857 | HAL_TIM_PWM_PulseFinishedCallback(htim); |
3814 | HAL_TIM_PWM_PulseFinishedCallback(htim); |
- | 3815 | #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */ |
|
2858 | } |
3816 | } |
2859 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED; |
3817 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED; |
2860 | } |
3818 | } |
2861 | } |
3819 | } |
2862 | /* Capture compare 4 event */ |
3820 | /* Capture compare 4 event */ |
2863 | if(__HAL_TIM_GET_FLAG(htim, TIM_FLAG_CC4) != RESET) |
3821 | if (__HAL_TIM_GET_FLAG(htim, TIM_FLAG_CC4) != RESET) |
2864 | { |
3822 | { |
2865 | if(__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_CC4) !=RESET) |
3823 | if (__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_CC4) != RESET) |
2866 | { |
3824 | { |
2867 | __HAL_TIM_CLEAR_IT(htim, TIM_IT_CC4); |
3825 | __HAL_TIM_CLEAR_IT(htim, TIM_IT_CC4); |
2868 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_4; |
3826 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_4; |
2869 | /* Input capture event */ |
3827 | /* Input capture event */ |
2870 | if((htim->Instance->CCMR2 & TIM_CCMR2_CC4S) != 0x00U) |
3828 | if ((htim->Instance->CCMR2 & TIM_CCMR2_CC4S) != 0x00U) |
2871 | { |
3829 | { |
- | 3830 | #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) |
|
- | 3831 | htim->IC_CaptureCallback(htim); |
|
- | 3832 | #else |
|
2872 | HAL_TIM_IC_CaptureCallback(htim); |
3833 | HAL_TIM_IC_CaptureCallback(htim); |
- | 3834 | #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */ |
|
2873 | } |
3835 | } |
2874 | /* Output compare event */ |
3836 | /* Output compare event */ |
2875 | else |
3837 | else |
2876 | { |
3838 | { |
- | 3839 | #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) |
|
- | 3840 | htim->OC_DelayElapsedCallback(htim); |
|
- | 3841 | htim->PWM_PulseFinishedCallback(htim); |
|
- | 3842 | #else |
|
2877 | HAL_TIM_OC_DelayElapsedCallback(htim); |
3843 | HAL_TIM_OC_DelayElapsedCallback(htim); |
2878 | HAL_TIM_PWM_PulseFinishedCallback(htim); |
3844 | HAL_TIM_PWM_PulseFinishedCallback(htim); |
- | 3845 | #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */ |
|
2879 | } |
3846 | } |
2880 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED; |
3847 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED; |
2881 | } |
3848 | } |
2882 | } |
3849 | } |
2883 | /* TIM Update event */ |
3850 | /* TIM Update event */ |
2884 | if(__HAL_TIM_GET_FLAG(htim, TIM_FLAG_UPDATE) != RESET) |
3851 | if (__HAL_TIM_GET_FLAG(htim, TIM_FLAG_UPDATE) != RESET) |
2885 | { |
3852 | { |
2886 | if(__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_UPDATE) !=RESET) |
3853 | if (__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_UPDATE) != RESET) |
2887 | { |
3854 | { |
2888 | __HAL_TIM_CLEAR_IT(htim, TIM_IT_UPDATE); |
3855 | __HAL_TIM_CLEAR_IT(htim, TIM_IT_UPDATE); |
- | 3856 | #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) |
|
- | 3857 | htim->PeriodElapsedCallback(htim); |
|
- | 3858 | #else |
|
2889 | HAL_TIM_PeriodElapsedCallback(htim); |
3859 | HAL_TIM_PeriodElapsedCallback(htim); |
- | 3860 | #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */ |
|
2890 | } |
3861 | } |
2891 | } |
3862 | } |
2892 | /* TIM Break input event */ |
3863 | /* TIM Break input event */ |
2893 | if(__HAL_TIM_GET_FLAG(htim, TIM_FLAG_BREAK) != RESET) |
3864 | if (__HAL_TIM_GET_FLAG(htim, TIM_FLAG_BREAK) != RESET) |
2894 | { |
3865 | { |
2895 | if(__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_BREAK) !=RESET) |
3866 | if (__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_BREAK) != RESET) |
2896 | { |
3867 | { |
2897 | __HAL_TIM_CLEAR_IT(htim, TIM_IT_BREAK); |
3868 | __HAL_TIM_CLEAR_IT(htim, TIM_IT_BREAK); |
- | 3869 | #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) |
|
- | 3870 | htim->BreakCallback(htim); |
|
- | 3871 | #else |
|
2898 | HAL_TIMEx_BreakCallback(htim); |
3872 | HAL_TIMEx_BreakCallback(htim); |
- | 3873 | #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */ |
|
2899 | } |
3874 | } |
2900 | } |
3875 | } |
2901 | /* TIM Trigger detection event */ |
3876 | /* TIM Trigger detection event */ |
2902 | if(__HAL_TIM_GET_FLAG(htim, TIM_FLAG_TRIGGER) != RESET) |
3877 | if (__HAL_TIM_GET_FLAG(htim, TIM_FLAG_TRIGGER) != RESET) |
2903 | { |
3878 | { |
2904 | if(__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_TRIGGER) !=RESET) |
3879 | if (__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_TRIGGER) != RESET) |
2905 | { |
3880 | { |
2906 | __HAL_TIM_CLEAR_IT(htim, TIM_IT_TRIGGER); |
3881 | __HAL_TIM_CLEAR_IT(htim, TIM_IT_TRIGGER); |
- | 3882 | #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) |
|
- | 3883 | htim->TriggerCallback(htim); |
|
- | 3884 | #else |
|
2907 | HAL_TIM_TriggerCallback(htim); |
3885 | HAL_TIM_TriggerCallback(htim); |
- | 3886 | #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */ |
|
2908 | } |
3887 | } |
2909 | } |
3888 | } |
2910 | /* TIM commutation event */ |
3889 | /* TIM commutation event */ |
2911 | if(__HAL_TIM_GET_FLAG(htim, TIM_FLAG_COM) != RESET) |
3890 | if (__HAL_TIM_GET_FLAG(htim, TIM_FLAG_COM) != RESET) |
2912 | { |
3891 | { |
2913 | if(__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_COM) !=RESET) |
3892 | if (__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_COM) != RESET) |
2914 | { |
3893 | { |
2915 | __HAL_TIM_CLEAR_IT(htim, TIM_FLAG_COM); |
3894 | __HAL_TIM_CLEAR_IT(htim, TIM_FLAG_COM); |
- | 3895 | #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) |
|
- | 3896 | htim->CommutationCallback(htim); |
|
- | 3897 | #else |
|
2916 | HAL_TIMEx_CommutationCallback(htim); |
3898 | HAL_TIMEx_CommutCallback(htim); |
- | 3899 | #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */ |
|
2917 | } |
3900 | } |
2918 | } |
3901 | } |
2919 | } |
3902 | } |
2920 | 3903 | ||
2921 | /** |
3904 | /** |
2922 | * @} |
3905 | * @} |
2923 | */ |
3906 | */ |
2924 | 3907 | ||
2925 | /** @defgroup TIM_Exported_Functions_Group8 Peripheral Control functions |
3908 | /** @defgroup TIM_Exported_Functions_Group8 TIM Peripheral Control functions |
2926 | * @brief Peripheral Control functions |
3909 | * @brief TIM Peripheral Control functions |
2927 | * |
3910 | * |
2928 | @verbatim |
3911 | @verbatim |
2929 | ============================================================================== |
3912 | ============================================================================== |
2930 | ##### Peripheral Control functions ##### |
3913 | ##### Peripheral Control functions ##### |
2931 | ============================================================================== |
3914 | ============================================================================== |
2932 | [..] |
3915 | [..] |
2933 | This section provides functions allowing to: |
3916 | This section provides functions allowing to: |
Line 2942... | Line 3925... | ||
2942 | */ |
3925 | */ |
2943 | 3926 | ||
2944 | /** |
3927 | /** |
2945 | * @brief Initializes the TIM Output Compare Channels according to the specified |
3928 | * @brief Initializes the TIM Output Compare Channels according to the specified |
2946 | * parameters in the TIM_OC_InitTypeDef. |
3929 | * parameters in the TIM_OC_InitTypeDef. |
2947 | * @param htim : TIM Output Compare handle |
3930 | * @param htim TIM Output Compare handle |
2948 | * @param sConfig : TIM Output Compare configuration structure |
3931 | * @param sConfig TIM Output Compare configuration structure |
2949 | * @param Channel : TIM Channels to be enabled |
3932 | * @param Channel TIM Channels to configure |
2950 | * This parameter can be one of the following values: |
3933 | * This parameter can be one of the following values: |
2951 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
3934 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
2952 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
3935 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
2953 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
3936 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
2954 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
3937 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
2955 | * @retval HAL status |
3938 | * @retval HAL status |
2956 | */ |
3939 | */ |
2957 | HAL_StatusTypeDef HAL_TIM_OC_ConfigChannel(TIM_HandleTypeDef *htim, TIM_OC_InitTypeDef* sConfig, uint32_t Channel) |
3940 | HAL_StatusTypeDef HAL_TIM_OC_ConfigChannel(TIM_HandleTypeDef *htim, |
- | 3941 | TIM_OC_InitTypeDef *sConfig, |
|
- | 3942 | uint32_t Channel) |
|
2958 | { |
3943 | { |
2959 | /* Check the parameters */ |
3944 | /* Check the parameters */ |
2960 | assert_param(IS_TIM_CHANNELS(Channel)); |
3945 | assert_param(IS_TIM_CHANNELS(Channel)); |
2961 | assert_param(IS_TIM_OC_MODE(sConfig->OCMode)); |
3946 | assert_param(IS_TIM_OC_MODE(sConfig->OCMode)); |
2962 | assert_param(IS_TIM_OC_POLARITY(sConfig->OCPolarity)); |
3947 | assert_param(IS_TIM_OC_POLARITY(sConfig->OCPolarity)); |
2963 | 3948 | ||
2964 | /* Check input state */ |
3949 | /* Process Locked */ |
2965 | __HAL_LOCK(htim); |
3950 | __HAL_LOCK(htim); |
2966 | 3951 | ||
2967 | htim->State = HAL_TIM_STATE_BUSY; |
- | |
2968 | - | ||
2969 | switch (Channel) |
3952 | switch (Channel) |
2970 | { |
3953 | { |
2971 | case TIM_CHANNEL_1: |
3954 | case TIM_CHANNEL_1: |
2972 | { |
3955 | { |
- | 3956 | /* Check the parameters */ |
|
2973 | assert_param(IS_TIM_CC1_INSTANCE(htim->Instance)); |
3957 | assert_param(IS_TIM_CC1_INSTANCE(htim->Instance)); |
- | 3958 | ||
2974 | /* Configure the TIM Channel 1 in Output Compare */ |
3959 | /* Configure the TIM Channel 1 in Output Compare */ |
2975 | TIM_OC1_SetConfig(htim->Instance, sConfig); |
3960 | TIM_OC1_SetConfig(htim->Instance, sConfig); |
- | 3961 | break; |
|
2976 | } |
3962 | } |
2977 | break; |
- | |
2978 | 3963 | ||
2979 | case TIM_CHANNEL_2: |
3964 | case TIM_CHANNEL_2: |
2980 | { |
3965 | { |
- | 3966 | /* Check the parameters */ |
|
2981 | assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); |
3967 | assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); |
- | 3968 | ||
2982 | /* Configure the TIM Channel 2 in Output Compare */ |
3969 | /* Configure the TIM Channel 2 in Output Compare */ |
2983 | TIM_OC2_SetConfig(htim->Instance, sConfig); |
3970 | TIM_OC2_SetConfig(htim->Instance, sConfig); |
- | 3971 | break; |
|
2984 | } |
3972 | } |
2985 | break; |
- | |
2986 | 3973 | ||
2987 | case TIM_CHANNEL_3: |
3974 | case TIM_CHANNEL_3: |
2988 | { |
3975 | { |
- | 3976 | /* Check the parameters */ |
|
2989 | assert_param(IS_TIM_CC3_INSTANCE(htim->Instance)); |
3977 | assert_param(IS_TIM_CC3_INSTANCE(htim->Instance)); |
- | 3978 | ||
2990 | /* Configure the TIM Channel 3 in Output Compare */ |
3979 | /* Configure the TIM Channel 3 in Output Compare */ |
2991 | TIM_OC3_SetConfig(htim->Instance, sConfig); |
3980 | TIM_OC3_SetConfig(htim->Instance, sConfig); |
- | 3981 | break; |
|
2992 | } |
3982 | } |
2993 | break; |
- | |
2994 | 3983 | ||
2995 | case TIM_CHANNEL_4: |
3984 | case TIM_CHANNEL_4: |
2996 | { |
3985 | { |
- | 3986 | /* Check the parameters */ |
|
2997 | assert_param(IS_TIM_CC4_INSTANCE(htim->Instance)); |
3987 | assert_param(IS_TIM_CC4_INSTANCE(htim->Instance)); |
- | 3988 | ||
2998 | /* Configure the TIM Channel 4 in Output Compare */ |
3989 | /* Configure the TIM Channel 4 in Output Compare */ |
2999 | TIM_OC4_SetConfig(htim->Instance, sConfig); |
3990 | TIM_OC4_SetConfig(htim->Instance, sConfig); |
- | 3991 | break; |
|
3000 | } |
3992 | } |
3001 | break; |
- | |
3002 | 3993 | ||
3003 | default: |
3994 | default: |
3004 | break; |
3995 | break; |
3005 | } |
3996 | } |
3006 | htim->State = HAL_TIM_STATE_READY; |
- | |
3007 | 3997 | ||
3008 | __HAL_UNLOCK(htim); |
3998 | __HAL_UNLOCK(htim); |
3009 | 3999 | ||
3010 | return HAL_OK; |
4000 | return HAL_OK; |
3011 | } |
4001 | } |
3012 | 4002 | ||
3013 | /** |
4003 | /** |
3014 | * @brief Initializes the TIM Input Capture Channels according to the specified |
4004 | * @brief Initializes the TIM Input Capture Channels according to the specified |
3015 | * parameters in the TIM_IC_InitTypeDef. |
4005 | * parameters in the TIM_IC_InitTypeDef. |
3016 | * @param htim : TIM IC handle |
4006 | * @param htim TIM IC handle |
3017 | * @param sConfig : TIM Input Capture configuration structure |
4007 | * @param sConfig TIM Input Capture configuration structure |
3018 | * @param Channel : TIM Channels to be enabled |
4008 | * @param Channel TIM Channel to configure |
3019 | * This parameter can be one of the following values: |
4009 | * This parameter can be one of the following values: |
3020 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
4010 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
3021 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
4011 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
3022 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
4012 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
3023 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
4013 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
3024 | * @retval HAL status |
4014 | * @retval HAL status |
3025 | */ |
4015 | */ |
3026 | HAL_StatusTypeDef HAL_TIM_IC_ConfigChannel(TIM_HandleTypeDef *htim, TIM_IC_InitTypeDef* sConfig, uint32_t Channel) |
4016 | HAL_StatusTypeDef HAL_TIM_IC_ConfigChannel(TIM_HandleTypeDef *htim, TIM_IC_InitTypeDef *sConfig, uint32_t Channel) |
3027 | { |
4017 | { |
3028 | /* Check the parameters */ |
4018 | /* Check the parameters */ |
3029 | assert_param(IS_TIM_CC1_INSTANCE(htim->Instance)); |
4019 | assert_param(IS_TIM_CC1_INSTANCE(htim->Instance)); |
3030 | assert_param(IS_TIM_IC_POLARITY(sConfig->ICPolarity)); |
4020 | assert_param(IS_TIM_IC_POLARITY(sConfig->ICPolarity)); |
3031 | assert_param(IS_TIM_IC_SELECTION(sConfig->ICSelection)); |
4021 | assert_param(IS_TIM_IC_SELECTION(sConfig->ICSelection)); |
3032 | assert_param(IS_TIM_IC_PRESCALER(sConfig->ICPrescaler)); |
4022 | assert_param(IS_TIM_IC_PRESCALER(sConfig->ICPrescaler)); |
3033 | assert_param(IS_TIM_IC_FILTER(sConfig->ICFilter)); |
4023 | assert_param(IS_TIM_IC_FILTER(sConfig->ICFilter)); |
3034 | 4024 | ||
- | 4025 | /* Process Locked */ |
|
3035 | __HAL_LOCK(htim); |
4026 | __HAL_LOCK(htim); |
3036 | 4027 | ||
3037 | htim->State = HAL_TIM_STATE_BUSY; |
- | |
3038 | - | ||
3039 | if (Channel == TIM_CHANNEL_1) |
4028 | if (Channel == TIM_CHANNEL_1) |
3040 | { |
4029 | { |
3041 | /* TI1 Configuration */ |
4030 | /* TI1 Configuration */ |
3042 | TIM_TI1_SetConfig(htim->Instance, |
4031 | TIM_TI1_SetConfig(htim->Instance, |
3043 | sConfig->ICPolarity, |
4032 | sConfig->ICPolarity, |
3044 | sConfig->ICSelection, |
4033 | sConfig->ICSelection, |
3045 | sConfig->ICFilter); |
4034 | sConfig->ICFilter); |
3046 | 4035 | ||
3047 | /* Reset the IC1PSC Bits */ |
4036 | /* Reset the IC1PSC Bits */ |
3048 | htim->Instance->CCMR1 &= ~TIM_CCMR1_IC1PSC; |
4037 | htim->Instance->CCMR1 &= ~TIM_CCMR1_IC1PSC; |
3049 | 4038 | ||
3050 | /* Set the IC1PSC value */ |
4039 | /* Set the IC1PSC value */ |
Line 3070... | Line 4059... | ||
3070 | { |
4059 | { |
3071 | /* TI3 Configuration */ |
4060 | /* TI3 Configuration */ |
3072 | assert_param(IS_TIM_CC3_INSTANCE(htim->Instance)); |
4061 | assert_param(IS_TIM_CC3_INSTANCE(htim->Instance)); |
3073 | 4062 | ||
3074 | TIM_TI3_SetConfig(htim->Instance, |
4063 | TIM_TI3_SetConfig(htim->Instance, |
3075 | sConfig->ICPolarity, |
4064 | sConfig->ICPolarity, |
3076 | sConfig->ICSelection, |
4065 | sConfig->ICSelection, |
3077 | sConfig->ICFilter); |
4066 | sConfig->ICFilter); |
3078 | 4067 | ||
3079 | /* Reset the IC3PSC Bits */ |
4068 | /* Reset the IC3PSC Bits */ |
3080 | htim->Instance->CCMR2 &= ~TIM_CCMR2_IC3PSC; |
4069 | htim->Instance->CCMR2 &= ~TIM_CCMR2_IC3PSC; |
3081 | 4070 | ||
3082 | /* Set the IC3PSC value */ |
4071 | /* Set the IC3PSC value */ |
Line 3086... | Line 4075... | ||
3086 | { |
4075 | { |
3087 | /* TI4 Configuration */ |
4076 | /* TI4 Configuration */ |
3088 | assert_param(IS_TIM_CC4_INSTANCE(htim->Instance)); |
4077 | assert_param(IS_TIM_CC4_INSTANCE(htim->Instance)); |
3089 | 4078 | ||
3090 | TIM_TI4_SetConfig(htim->Instance, |
4079 | TIM_TI4_SetConfig(htim->Instance, |
3091 | sConfig->ICPolarity, |
4080 | sConfig->ICPolarity, |
3092 | sConfig->ICSelection, |
4081 | sConfig->ICSelection, |
3093 | sConfig->ICFilter); |
4082 | sConfig->ICFilter); |
3094 | 4083 | ||
3095 | /* Reset the IC4PSC Bits */ |
4084 | /* Reset the IC4PSC Bits */ |
3096 | htim->Instance->CCMR2 &= ~TIM_CCMR2_IC4PSC; |
4085 | htim->Instance->CCMR2 &= ~TIM_CCMR2_IC4PSC; |
3097 | 4086 | ||
3098 | /* Set the IC4PSC value */ |
4087 | /* Set the IC4PSC value */ |
3099 | htim->Instance->CCMR2 |= (sConfig->ICPrescaler << 8U); |
4088 | htim->Instance->CCMR2 |= (sConfig->ICPrescaler << 8U); |
3100 | } |
4089 | } |
3101 | 4090 | ||
3102 | htim->State = HAL_TIM_STATE_READY; |
- | |
3103 | - | ||
3104 | __HAL_UNLOCK(htim); |
4091 | __HAL_UNLOCK(htim); |
3105 | 4092 | ||
3106 | return HAL_OK; |
4093 | return HAL_OK; |
3107 | } |
4094 | } |
3108 | 4095 | ||
3109 | /** |
4096 | /** |
3110 | * @brief Initializes the TIM PWM channels according to the specified |
4097 | * @brief Initializes the TIM PWM channels according to the specified |
3111 | * parameters in the TIM_OC_InitTypeDef. |
4098 | * parameters in the TIM_OC_InitTypeDef. |
3112 | * @param htim : TIM handle |
4099 | * @param htim TIM PWM handle |
3113 | * @param sConfig : TIM PWM configuration structure |
4100 | * @param sConfig TIM PWM configuration structure |
3114 | * @param Channel : TIM Channels to be enabled |
4101 | * @param Channel TIM Channels to be configured |
3115 | * This parameter can be one of the following values: |
4102 | * This parameter can be one of the following values: |
3116 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
4103 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
3117 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
4104 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
3118 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
4105 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
3119 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
4106 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
3120 | * @retval HAL status |
4107 | * @retval HAL status |
3121 | */ |
4108 | */ |
3122 | HAL_StatusTypeDef HAL_TIM_PWM_ConfigChannel(TIM_HandleTypeDef *htim, TIM_OC_InitTypeDef* sConfig, uint32_t Channel) |
4109 | HAL_StatusTypeDef HAL_TIM_PWM_ConfigChannel(TIM_HandleTypeDef *htim, |
- | 4110 | TIM_OC_InitTypeDef *sConfig, |
|
- | 4111 | uint32_t Channel) |
|
3123 | { |
4112 | { |
3124 | __HAL_LOCK(htim); |
- | |
3125 | - | ||
3126 | /* Check the parameters */ |
4113 | /* Check the parameters */ |
3127 | assert_param(IS_TIM_CHANNELS(Channel)); |
4114 | assert_param(IS_TIM_CHANNELS(Channel)); |
3128 | assert_param(IS_TIM_PWM_MODE(sConfig->OCMode)); |
4115 | assert_param(IS_TIM_PWM_MODE(sConfig->OCMode)); |
3129 | assert_param(IS_TIM_OC_POLARITY(sConfig->OCPolarity)); |
4116 | assert_param(IS_TIM_OC_POLARITY(sConfig->OCPolarity)); |
3130 | assert_param(IS_TIM_FAST_STATE(sConfig->OCFastMode)); |
4117 | assert_param(IS_TIM_FAST_STATE(sConfig->OCFastMode)); |
3131 | 4118 | ||
- | 4119 | /* Process Locked */ |
|
3132 | htim->State = HAL_TIM_STATE_BUSY; |
4120 | __HAL_LOCK(htim); |
3133 | 4121 | ||
3134 | switch (Channel) |
4122 | switch (Channel) |
3135 | { |
4123 | { |
3136 | case TIM_CHANNEL_1: |
4124 | case TIM_CHANNEL_1: |
3137 | { |
4125 | { |
- | 4126 | /* Check the parameters */ |
|
3138 | assert_param(IS_TIM_CC1_INSTANCE(htim->Instance)); |
4127 | assert_param(IS_TIM_CC1_INSTANCE(htim->Instance)); |
- | 4128 | ||
3139 | /* Configure the Channel 1 in PWM mode */ |
4129 | /* Configure the Channel 1 in PWM mode */ |
3140 | TIM_OC1_SetConfig(htim->Instance, sConfig); |
4130 | TIM_OC1_SetConfig(htim->Instance, sConfig); |
3141 | 4131 | ||
3142 | /* Set the Preload enable bit for channel1 */ |
4132 | /* Set the Preload enable bit for channel1 */ |
3143 | htim->Instance->CCMR1 |= TIM_CCMR1_OC1PE; |
4133 | htim->Instance->CCMR1 |= TIM_CCMR1_OC1PE; |
3144 | 4134 | ||
3145 | /* Configure the Output Fast mode */ |
4135 | /* Configure the Output Fast mode */ |
3146 | htim->Instance->CCMR1 &= ~TIM_CCMR1_OC1FE; |
4136 | htim->Instance->CCMR1 &= ~TIM_CCMR1_OC1FE; |
3147 | htim->Instance->CCMR1 |= sConfig->OCFastMode; |
4137 | htim->Instance->CCMR1 |= sConfig->OCFastMode; |
- | 4138 | break; |
|
3148 | } |
4139 | } |
3149 | break; |
- | |
3150 | 4140 | ||
3151 | case TIM_CHANNEL_2: |
4141 | case TIM_CHANNEL_2: |
3152 | { |
4142 | { |
- | 4143 | /* Check the parameters */ |
|
3153 | assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); |
4144 | assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); |
- | 4145 | ||
3154 | /* Configure the Channel 2 in PWM mode */ |
4146 | /* Configure the Channel 2 in PWM mode */ |
3155 | TIM_OC2_SetConfig(htim->Instance, sConfig); |
4147 | TIM_OC2_SetConfig(htim->Instance, sConfig); |
3156 | 4148 | ||
3157 | /* Set the Preload enable bit for channel2 */ |
4149 | /* Set the Preload enable bit for channel2 */ |
3158 | htim->Instance->CCMR1 |= TIM_CCMR1_OC2PE; |
4150 | htim->Instance->CCMR1 |= TIM_CCMR1_OC2PE; |
3159 | 4151 | ||
3160 | /* Configure the Output Fast mode */ |
4152 | /* Configure the Output Fast mode */ |
3161 | htim->Instance->CCMR1 &= ~TIM_CCMR1_OC2FE; |
4153 | htim->Instance->CCMR1 &= ~TIM_CCMR1_OC2FE; |
3162 | htim->Instance->CCMR1 |= sConfig->OCFastMode << 8; |
4154 | htim->Instance->CCMR1 |= sConfig->OCFastMode << 8U; |
- | 4155 | break; |
|
3163 | } |
4156 | } |
3164 | break; |
- | |
3165 | 4157 | ||
3166 | case TIM_CHANNEL_3: |
4158 | case TIM_CHANNEL_3: |
3167 | { |
4159 | { |
- | 4160 | /* Check the parameters */ |
|
3168 | assert_param(IS_TIM_CC3_INSTANCE(htim->Instance)); |
4161 | assert_param(IS_TIM_CC3_INSTANCE(htim->Instance)); |
- | 4162 | ||
3169 | /* Configure the Channel 3 in PWM mode */ |
4163 | /* Configure the Channel 3 in PWM mode */ |
3170 | TIM_OC3_SetConfig(htim->Instance, sConfig); |
4164 | TIM_OC3_SetConfig(htim->Instance, sConfig); |
3171 | 4165 | ||
3172 | /* Set the Preload enable bit for channel3 */ |
4166 | /* Set the Preload enable bit for channel3 */ |
3173 | htim->Instance->CCMR2 |= TIM_CCMR2_OC3PE; |
4167 | htim->Instance->CCMR2 |= TIM_CCMR2_OC3PE; |
3174 | 4168 | ||
3175 | /* Configure the Output Fast mode */ |
4169 | /* Configure the Output Fast mode */ |
3176 | htim->Instance->CCMR2 &= ~TIM_CCMR2_OC3FE; |
4170 | htim->Instance->CCMR2 &= ~TIM_CCMR2_OC3FE; |
3177 | htim->Instance->CCMR2 |= sConfig->OCFastMode; |
4171 | htim->Instance->CCMR2 |= sConfig->OCFastMode; |
- | 4172 | break; |
|
3178 | } |
4173 | } |
3179 | break; |
- | |
3180 | 4174 | ||
3181 | case TIM_CHANNEL_4: |
4175 | case TIM_CHANNEL_4: |
3182 | { |
4176 | { |
- | 4177 | /* Check the parameters */ |
|
3183 | assert_param(IS_TIM_CC4_INSTANCE(htim->Instance)); |
4178 | assert_param(IS_TIM_CC4_INSTANCE(htim->Instance)); |
- | 4179 | ||
3184 | /* Configure the Channel 4 in PWM mode */ |
4180 | /* Configure the Channel 4 in PWM mode */ |
3185 | TIM_OC4_SetConfig(htim->Instance, sConfig); |
4181 | TIM_OC4_SetConfig(htim->Instance, sConfig); |
3186 | 4182 | ||
3187 | /* Set the Preload enable bit for channel4 */ |
4183 | /* Set the Preload enable bit for channel4 */ |
3188 | htim->Instance->CCMR2 |= TIM_CCMR2_OC4PE; |
4184 | htim->Instance->CCMR2 |= TIM_CCMR2_OC4PE; |
3189 | 4185 | ||
3190 | /* Configure the Output Fast mode */ |
4186 | /* Configure the Output Fast mode */ |
3191 | htim->Instance->CCMR2 &= ~TIM_CCMR2_OC4FE; |
4187 | htim->Instance->CCMR2 &= ~TIM_CCMR2_OC4FE; |
3192 | htim->Instance->CCMR2 |= sConfig->OCFastMode << 8; |
4188 | htim->Instance->CCMR2 |= sConfig->OCFastMode << 8U; |
- | 4189 | break; |
|
3193 | } |
4190 | } |
3194 | break; |
- | |
3195 | 4191 | ||
3196 | default: |
4192 | default: |
3197 | break; |
4193 | break; |
3198 | } |
4194 | } |
3199 | 4195 | ||
3200 | htim->State = HAL_TIM_STATE_READY; |
- | |
3201 | - | ||
3202 | __HAL_UNLOCK(htim); |
4196 | __HAL_UNLOCK(htim); |
3203 | 4197 | ||
3204 | return HAL_OK; |
4198 | return HAL_OK; |
3205 | } |
4199 | } |
3206 | 4200 | ||
3207 | /** |
4201 | /** |
3208 | * @brief Initializes the TIM One Pulse Channels according to the specified |
4202 | * @brief Initializes the TIM One Pulse Channels according to the specified |
3209 | * parameters in the TIM_OnePulse_InitTypeDef. |
4203 | * parameters in the TIM_OnePulse_InitTypeDef. |
3210 | * @param htim : TIM One Pulse handle |
4204 | * @param htim TIM One Pulse handle |
3211 | * @param sConfig : TIM One Pulse configuration structure |
4205 | * @param sConfig TIM One Pulse configuration structure |
3212 | * @param OutputChannel : TIM Channels to be enabled |
4206 | * @param OutputChannel TIM output channel to configure |
3213 | * This parameter can be one of the following values: |
4207 | * This parameter can be one of the following values: |
3214 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
4208 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
3215 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
4209 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
3216 | * @param InputChannel : TIM Channels to be enabled |
4210 | * @param InputChannel TIM input Channel to configure |
3217 | * This parameter can be one of the following values: |
4211 | * This parameter can be one of the following values: |
3218 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
4212 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
3219 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
4213 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
- | 4214 | * @note To output a waveform with a minimum delay user can enable the fast |
|
- | 4215 | * mode by calling the @ref __HAL_TIM_ENABLE_OCxFAST macro. Then CCx |
|
- | 4216 | * output is forced in response to the edge detection on TIx input, |
|
- | 4217 | * without taking in account the comparison. |
|
3220 | * @retval HAL status |
4218 | * @retval HAL status |
3221 | */ |
4219 | */ |
3222 | HAL_StatusTypeDef HAL_TIM_OnePulse_ConfigChannel(TIM_HandleTypeDef *htim, TIM_OnePulse_InitTypeDef* sConfig, uint32_t OutputChannel, uint32_t InputChannel) |
4220 | HAL_StatusTypeDef HAL_TIM_OnePulse_ConfigChannel(TIM_HandleTypeDef *htim, TIM_OnePulse_InitTypeDef *sConfig, |
- | 4221 | uint32_t OutputChannel, uint32_t InputChannel) |
|
3223 | { |
4222 | { |
3224 | TIM_OC_InitTypeDef temp1; |
4223 | TIM_OC_InitTypeDef temp1; |
3225 | 4224 | ||
3226 | /* Check the parameters */ |
4225 | /* Check the parameters */ |
3227 | assert_param(IS_TIM_OPM_CHANNELS(OutputChannel)); |
4226 | assert_param(IS_TIM_OPM_CHANNELS(OutputChannel)); |
3228 | assert_param(IS_TIM_OPM_CHANNELS(InputChannel)); |
4227 | assert_param(IS_TIM_OPM_CHANNELS(InputChannel)); |
3229 | 4228 | ||
3230 | if(OutputChannel != InputChannel) |
4229 | if (OutputChannel != InputChannel) |
3231 | { |
4230 | { |
- | 4231 | /* Process Locked */ |
|
3232 | __HAL_LOCK(htim); |
4232 | __HAL_LOCK(htim); |
3233 | 4233 | ||
3234 | htim->State = HAL_TIM_STATE_BUSY; |
4234 | htim->State = HAL_TIM_STATE_BUSY; |
3235 | 4235 | ||
3236 | /* Extract the Ouput compare configuration from sConfig structure */ |
4236 | /* Extract the Output compare configuration from sConfig structure */ |
3237 | temp1.OCMode = sConfig->OCMode; |
4237 | temp1.OCMode = sConfig->OCMode; |
3238 | temp1.Pulse = sConfig->Pulse; |
4238 | temp1.Pulse = sConfig->Pulse; |
3239 | temp1.OCPolarity = sConfig->OCPolarity; |
4239 | temp1.OCPolarity = sConfig->OCPolarity; |
3240 | temp1.OCNPolarity = sConfig->OCNPolarity; |
4240 | temp1.OCNPolarity = sConfig->OCNPolarity; |
3241 | temp1.OCIdleState = sConfig->OCIdleState; |
4241 | temp1.OCIdleState = sConfig->OCIdleState; |
3242 | temp1.OCNIdleState = sConfig->OCNIdleState; |
4242 | temp1.OCNIdleState = sConfig->OCNIdleState; |
3243 | 4243 | ||
3244 | switch (OutputChannel) |
4244 | switch (OutputChannel) |
3245 | { |
- | |
3246 | case TIM_CHANNEL_1: |
- | |
3247 | { |
4245 | { |
- | 4246 | case TIM_CHANNEL_1: |
|
- | 4247 | { |
|
3248 | assert_param(IS_TIM_CC1_INSTANCE(htim->Instance)); |
4248 | assert_param(IS_TIM_CC1_INSTANCE(htim->Instance)); |
3249 | 4249 | ||
3250 | TIM_OC1_SetConfig(htim->Instance, &temp1); |
4250 | TIM_OC1_SetConfig(htim->Instance, &temp1); |
3251 | } |
4251 | break; |
3252 | break; |
4252 | } |
3253 | case TIM_CHANNEL_2: |
4253 | case TIM_CHANNEL_2: |
3254 | { |
4254 | { |
3255 | assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); |
4255 | assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); |
3256 | 4256 | ||
3257 | TIM_OC2_SetConfig(htim->Instance, &temp1); |
4257 | TIM_OC2_SetConfig(htim->Instance, &temp1); |
- | 4258 | break; |
|
- | 4259 | } |
|
- | 4260 | default: |
|
- | 4261 | break; |
|
3258 | } |
4262 | } |
3259 | break; |
- | |
3260 | default: |
- | |
3261 | break; |
- | |
3262 | } |
4263 | |
3263 | switch (InputChannel) |
4264 | switch (InputChannel) |
3264 | { |
- | |
3265 | case TIM_CHANNEL_1: |
- | |
3266 | { |
4265 | { |
- | 4266 | case TIM_CHANNEL_1: |
|
- | 4267 | { |
|
3267 | assert_param(IS_TIM_CC1_INSTANCE(htim->Instance)); |
4268 | assert_param(IS_TIM_CC1_INSTANCE(htim->Instance)); |
3268 | 4269 | ||
3269 | TIM_TI1_SetConfig(htim->Instance, sConfig->ICPolarity, |
4270 | TIM_TI1_SetConfig(htim->Instance, sConfig->ICPolarity, |
3270 | sConfig->ICSelection, sConfig->ICFilter); |
4271 | sConfig->ICSelection, sConfig->ICFilter); |
3271 | 4272 | ||
3272 | /* Reset the IC1PSC Bits */ |
4273 | /* Reset the IC1PSC Bits */ |
3273 | htim->Instance->CCMR1 &= ~TIM_CCMR1_IC1PSC; |
4274 | htim->Instance->CCMR1 &= ~TIM_CCMR1_IC1PSC; |
3274 | 4275 | ||
3275 | /* Select the Trigger source */ |
4276 | /* Select the Trigger source */ |
3276 | htim->Instance->SMCR &= ~TIM_SMCR_TS; |
4277 | htim->Instance->SMCR &= ~TIM_SMCR_TS; |
3277 | htim->Instance->SMCR |= TIM_TS_TI1FP1; |
4278 | htim->Instance->SMCR |= TIM_TS_TI1FP1; |
3278 | 4279 | ||
3279 | /* Select the Slave Mode */ |
4280 | /* Select the Slave Mode */ |
3280 | htim->Instance->SMCR &= ~TIM_SMCR_SMS; |
4281 | htim->Instance->SMCR &= ~TIM_SMCR_SMS; |
3281 | htim->Instance->SMCR |= TIM_SLAVEMODE_TRIGGER; |
4282 | htim->Instance->SMCR |= TIM_SLAVEMODE_TRIGGER; |
3282 | } |
4283 | break; |
3283 | break; |
4284 | } |
3284 | case TIM_CHANNEL_2: |
4285 | case TIM_CHANNEL_2: |
3285 | { |
4286 | { |
3286 | assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); |
4287 | assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); |
3287 | 4288 | ||
3288 | TIM_TI2_SetConfig(htim->Instance, sConfig->ICPolarity, |
4289 | TIM_TI2_SetConfig(htim->Instance, sConfig->ICPolarity, |
3289 | sConfig->ICSelection, sConfig->ICFilter); |
4290 | sConfig->ICSelection, sConfig->ICFilter); |
3290 | 4291 | ||
3291 | /* Reset the IC2PSC Bits */ |
4292 | /* Reset the IC2PSC Bits */ |
3292 | htim->Instance->CCMR1 &= ~TIM_CCMR1_IC2PSC; |
4293 | htim->Instance->CCMR1 &= ~TIM_CCMR1_IC2PSC; |
3293 | 4294 | ||
3294 | /* Select the Trigger source */ |
4295 | /* Select the Trigger source */ |
3295 | htim->Instance->SMCR &= ~TIM_SMCR_TS; |
4296 | htim->Instance->SMCR &= ~TIM_SMCR_TS; |
3296 | htim->Instance->SMCR |= TIM_TS_TI2FP2; |
4297 | htim->Instance->SMCR |= TIM_TS_TI2FP2; |
3297 | 4298 | ||
3298 | /* Select the Slave Mode */ |
4299 | /* Select the Slave Mode */ |
3299 | htim->Instance->SMCR &= ~TIM_SMCR_SMS; |
4300 | htim->Instance->SMCR &= ~TIM_SMCR_SMS; |
3300 | htim->Instance->SMCR |= TIM_SLAVEMODE_TRIGGER; |
4301 | htim->Instance->SMCR |= TIM_SLAVEMODE_TRIGGER; |
3301 | } |
4302 | break; |
3302 | break; |
4303 | } |
3303 | 4304 | ||
3304 | default: |
4305 | default: |
3305 | break; |
4306 | break; |
3306 | } |
4307 | } |
3307 | 4308 | ||
3308 | htim->State = HAL_TIM_STATE_READY; |
4309 | htim->State = HAL_TIM_STATE_READY; |
3309 | 4310 | ||
3310 | __HAL_UNLOCK(htim); |
4311 | __HAL_UNLOCK(htim); |
3311 | 4312 | ||
3312 | return HAL_OK; |
4313 | return HAL_OK; |
3313 | } |
4314 | } |
3314 | else |
4315 | else |
3315 | { |
4316 | { |
3316 | return HAL_ERROR; |
4317 | return HAL_ERROR; |
3317 | } |
4318 | } |
3318 | } |
4319 | } |
3319 | 4320 | ||
3320 | /** |
4321 | /** |
3321 | * @brief Configure the DMA Burst to transfer Data from the memory to the TIM peripheral |
4322 | * @brief Configure the DMA Burst to transfer Data from the memory to the TIM peripheral |
3322 | * @param htim : TIM handle |
4323 | * @param htim TIM handle |
3323 | * @param BurstBaseAddress : TIM Base address from where the DMA will start the Data write |
4324 | * @param BurstBaseAddress TIM Base address from where the DMA will start the Data write |
3324 | * This parameter can be one of the following values: |
4325 | * This parameter can be one of the following values: |
3325 | * @arg TIM_DMABASE_CR1 |
4326 | * @arg TIM_DMABASE_CR1 |
3326 | * @arg TIM_DMABASE_CR2 |
4327 | * @arg TIM_DMABASE_CR2 |
3327 | * @arg TIM_DMABASE_SMCR |
4328 | * @arg TIM_DMABASE_SMCR |
3328 | * @arg TIM_DMABASE_DIER |
4329 | * @arg TIM_DMABASE_DIER |
3329 | * @arg TIM_DMABASE_SR |
4330 | * @arg TIM_DMABASE_SR |
3330 | * @arg TIM_DMABASE_EGR |
4331 | * @arg TIM_DMABASE_EGR |
3331 | * @arg TIM_DMABASE_CCMR1 |
4332 | * @arg TIM_DMABASE_CCMR1 |
3332 | * @arg TIM_DMABASE_CCMR2 |
4333 | * @arg TIM_DMABASE_CCMR2 |
3333 | * @arg TIM_DMABASE_CCER |
4334 | * @arg TIM_DMABASE_CCER |
3334 | * @arg TIM_DMABASE_CNT |
4335 | * @arg TIM_DMABASE_CNT |
3335 | * @arg TIM_DMABASE_PSC |
4336 | * @arg TIM_DMABASE_PSC |
3336 | * @arg TIM_DMABASE_ARR |
4337 | * @arg TIM_DMABASE_ARR |
3337 | * @arg TIM_DMABASE_RCR |
4338 | * @arg TIM_DMABASE_RCR |
3338 | * @arg TIM_DMABASE_CCR1 |
4339 | * @arg TIM_DMABASE_CCR1 |
3339 | * @arg TIM_DMABASE_CCR2 |
4340 | * @arg TIM_DMABASE_CCR2 |
3340 | * @arg TIM_DMABASE_CCR3 |
4341 | * @arg TIM_DMABASE_CCR3 |
3341 | * @arg TIM_DMABASE_CCR4 |
4342 | * @arg TIM_DMABASE_CCR4 |
3342 | * @arg TIM_DMABASE_BDTR |
4343 | * @arg TIM_DMABASE_BDTR |
3343 | * @arg TIM_DMABASE_DCR |
- | |
3344 | * @param BurstRequestSrc : TIM DMA Request sources |
4344 | * @param BurstRequestSrc TIM DMA Request sources |
3345 | * This parameter can be one of the following values: |
4345 | * This parameter can be one of the following values: |
3346 | * @arg TIM_DMA_UPDATE: TIM update Interrupt source |
4346 | * @arg TIM_DMA_UPDATE: TIM update Interrupt source |
3347 | * @arg TIM_DMA_CC1: TIM Capture Compare 1 DMA source |
4347 | * @arg TIM_DMA_CC1: TIM Capture Compare 1 DMA source |
3348 | * @arg TIM_DMA_CC2: TIM Capture Compare 2 DMA source |
4348 | * @arg TIM_DMA_CC2: TIM Capture Compare 2 DMA source |
3349 | * @arg TIM_DMA_CC3: TIM Capture Compare 3 DMA source |
4349 | * @arg TIM_DMA_CC3: TIM Capture Compare 3 DMA source |
3350 | * @arg TIM_DMA_CC4: TIM Capture Compare 4 DMA source |
4350 | * @arg TIM_DMA_CC4: TIM Capture Compare 4 DMA source |
3351 | * @arg TIM_DMA_COM: TIM Commutation DMA source |
4351 | * @arg TIM_DMA_COM: TIM Commutation DMA source |
3352 | * @arg TIM_DMA_TRIGGER: TIM Trigger DMA source |
4352 | * @arg TIM_DMA_TRIGGER: TIM Trigger DMA source |
3353 | * @param BurstBuffer : The Buffer address. |
4353 | * @param BurstBuffer The Buffer address. |
3354 | * @param BurstLength : DMA Burst length. This parameter can be one value |
4354 | * @param BurstLength DMA Burst length. This parameter can be one value |
3355 | * between: TIM_DMABURSTLENGTH_1TRANSFER and TIM_DMABURSTLENGTH_18TRANSFERS. |
4355 | * between: TIM_DMABURSTLENGTH_1TRANSFER and TIM_DMABURSTLENGTH_18TRANSFERS. |
- | 4356 | * @note This function should be used only when BurstLength is equal to DMA data transfer length. |
|
3356 | * @retval HAL status |
4357 | * @retval HAL status |
3357 | */ |
4358 | */ |
3358 | HAL_StatusTypeDef HAL_TIM_DMABurst_WriteStart(TIM_HandleTypeDef *htim, uint32_t BurstBaseAddress, uint32_t BurstRequestSrc, |
4359 | HAL_StatusTypeDef HAL_TIM_DMABurst_WriteStart(TIM_HandleTypeDef *htim, uint32_t BurstBaseAddress, |
- | 4360 | uint32_t BurstRequestSrc, uint32_t *BurstBuffer, uint32_t BurstLength) |
|
- | 4361 | { |
|
- | 4362 | return HAL_TIM_DMABurst_MultiWriteStart(htim, BurstBaseAddress, BurstRequestSrc, BurstBuffer, BurstLength, |
|
- | 4363 | ((BurstLength) >> 8U) + 1U); |
|
- | 4364 | } |
|
- | 4365 | ||
- | 4366 | /** |
|
- | 4367 | * @brief Configure the DMA Burst to transfer multiple Data from the memory to the TIM peripheral |
|
- | 4368 | * @param htim TIM handle |
|
- | 4369 | * @param BurstBaseAddress TIM Base address from where the DMA will start the Data write |
|
- | 4370 | * This parameter can be one of the following values: |
|
- | 4371 | * @arg TIM_DMABASE_CR1 |
|
- | 4372 | * @arg TIM_DMABASE_CR2 |
|
- | 4373 | * @arg TIM_DMABASE_SMCR |
|
- | 4374 | * @arg TIM_DMABASE_DIER |
|
- | 4375 | * @arg TIM_DMABASE_SR |
|
- | 4376 | * @arg TIM_DMABASE_EGR |
|
- | 4377 | * @arg TIM_DMABASE_CCMR1 |
|
- | 4378 | * @arg TIM_DMABASE_CCMR2 |
|
- | 4379 | * @arg TIM_DMABASE_CCER |
|
- | 4380 | * @arg TIM_DMABASE_CNT |
|
- | 4381 | * @arg TIM_DMABASE_PSC |
|
- | 4382 | * @arg TIM_DMABASE_ARR |
|
- | 4383 | * @arg TIM_DMABASE_RCR |
|
- | 4384 | * @arg TIM_DMABASE_CCR1 |
|
- | 4385 | * @arg TIM_DMABASE_CCR2 |
|
- | 4386 | * @arg TIM_DMABASE_CCR3 |
|
- | 4387 | * @arg TIM_DMABASE_CCR4 |
|
- | 4388 | * @arg TIM_DMABASE_BDTR |
|
- | 4389 | * @param BurstRequestSrc TIM DMA Request sources |
|
- | 4390 | * This parameter can be one of the following values: |
|
- | 4391 | * @arg TIM_DMA_UPDATE: TIM update Interrupt source |
|
- | 4392 | * @arg TIM_DMA_CC1: TIM Capture Compare 1 DMA source |
|
- | 4393 | * @arg TIM_DMA_CC2: TIM Capture Compare 2 DMA source |
|
- | 4394 | * @arg TIM_DMA_CC3: TIM Capture Compare 3 DMA source |
|
- | 4395 | * @arg TIM_DMA_CC4: TIM Capture Compare 4 DMA source |
|
- | 4396 | * @arg TIM_DMA_COM: TIM Commutation DMA source |
|
- | 4397 | * @arg TIM_DMA_TRIGGER: TIM Trigger DMA source |
|
- | 4398 | * @param BurstBuffer The Buffer address. |
|
- | 4399 | * @param BurstLength DMA Burst length. This parameter can be one value |
|
- | 4400 | * between: TIM_DMABURSTLENGTH_1TRANSFER and TIM_DMABURSTLENGTH_18TRANSFERS. |
|
- | 4401 | * @param DataLength Data length. This parameter can be one value |
|
- | 4402 | * between 1 and 0xFFFF. |
|
- | 4403 | * @retval HAL status |
|
- | 4404 | */ |
|
- | 4405 | HAL_StatusTypeDef HAL_TIM_DMABurst_MultiWriteStart(TIM_HandleTypeDef *htim, uint32_t BurstBaseAddress, |
|
- | 4406 | uint32_t BurstRequestSrc, uint32_t *BurstBuffer, |
|
3359 | uint32_t* BurstBuffer, uint32_t BurstLength) |
4407 | uint32_t BurstLength, uint32_t DataLength) |
3360 | { |
4408 | { |
3361 | /* Check the parameters */ |
4409 | /* Check the parameters */ |
3362 | assert_param(IS_TIM_DMABURST_INSTANCE(htim->Instance)); |
4410 | assert_param(IS_TIM_DMABURST_INSTANCE(htim->Instance)); |
3363 | assert_param(IS_TIM_DMA_BASE(BurstBaseAddress)); |
4411 | assert_param(IS_TIM_DMA_BASE(BurstBaseAddress)); |
3364 | assert_param(IS_TIM_DMA_SOURCE(BurstRequestSrc)); |
4412 | assert_param(IS_TIM_DMA_SOURCE(BurstRequestSrc)); |
3365 | assert_param(IS_TIM_DMA_LENGTH(BurstLength)); |
4413 | assert_param(IS_TIM_DMA_LENGTH(BurstLength)); |
- | 4414 | assert_param(IS_TIM_DMA_DATA_LENGTH(DataLength)); |
|
3366 | 4415 | ||
3367 | if((htim->State == HAL_TIM_STATE_BUSY)) |
4416 | if (htim->DMABurstState == HAL_DMA_BURST_STATE_BUSY) |
3368 | { |
4417 | { |
3369 | return HAL_BUSY; |
4418 | return HAL_BUSY; |
3370 | } |
4419 | } |
3371 | else if((htim->State == HAL_TIM_STATE_READY)) |
4420 | else if (htim->DMABurstState == HAL_DMA_BURST_STATE_READY) |
3372 | { |
4421 | { |
3373 | if((BurstBuffer == 0U) && (BurstLength > 0U)) |
4422 | if ((BurstBuffer == NULL) && (BurstLength > 0U)) |
3374 | { |
4423 | { |
3375 | return HAL_ERROR; |
4424 | return HAL_ERROR; |
3376 | } |
4425 | } |
3377 | else |
4426 | else |
3378 | { |
4427 | { |
3379 | htim->State = HAL_TIM_STATE_BUSY; |
4428 | htim->DMABurstState = HAL_DMA_BURST_STATE_BUSY; |
3380 | } |
4429 | } |
3381 | } |
4430 | } |
- | 4431 | else |
|
- | 4432 | { |
|
- | 4433 | /* nothing to do */ |
|
- | 4434 | } |
|
3382 | switch(BurstRequestSrc) |
4435 | switch (BurstRequestSrc) |
3383 | { |
4436 | { |
3384 | case TIM_DMA_UPDATE: |
4437 | case TIM_DMA_UPDATE: |
3385 | { |
4438 | { |
3386 | /* Set the DMA Period elapsed callback */ |
4439 | /* Set the DMA Period elapsed callbacks */ |
3387 | htim->hdma[TIM_DMA_ID_UPDATE]->XferCpltCallback = TIM_DMAPeriodElapsedCplt; |
4440 | htim->hdma[TIM_DMA_ID_UPDATE]->XferCpltCallback = TIM_DMAPeriodElapsedCplt; |
- | 4441 | htim->hdma[TIM_DMA_ID_UPDATE]->XferHalfCpltCallback = TIM_DMAPeriodElapsedHalfCplt; |
|
3388 | 4442 | ||
3389 | /* Set the DMA error callback */ |
4443 | /* Set the DMA error callback */ |
3390 | htim->hdma[TIM_DMA_ID_UPDATE]->XferErrorCallback = TIM_DMAError ; |
4444 | htim->hdma[TIM_DMA_ID_UPDATE]->XferErrorCallback = TIM_DMAError ; |
3391 | 4445 | ||
3392 | /* Enable the DMA channel */ |
4446 | /* Enable the DMA channel */ |
3393 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_UPDATE], (uint32_t)BurstBuffer, (uint32_t)&htim->Instance->DMAR, ((BurstLength) >> 8U) + 1U); |
4447 | if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_UPDATE], (uint32_t)BurstBuffer, |
- | 4448 | (uint32_t)&htim->Instance->DMAR, DataLength) != HAL_OK) |
|
- | 4449 | { |
|
- | 4450 | /* Return error status */ |
|
- | 4451 | return HAL_ERROR; |
|
- | 4452 | } |
|
- | 4453 | break; |
|
3394 | } |
4454 | } |
3395 | break; |
- | |
3396 | case TIM_DMA_CC1: |
4455 | case TIM_DMA_CC1: |
3397 | { |
4456 | { |
3398 | /* Set the DMA Period elapsed callback */ |
4457 | /* Set the DMA compare callbacks */ |
3399 | htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMADelayPulseCplt; |
4458 | htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMADelayPulseCplt; |
- | 4459 | htim->hdma[TIM_DMA_ID_CC1]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt; |
|
3400 | 4460 | ||
3401 | /* Set the DMA error callback */ |
4461 | /* Set the DMA error callback */ |
3402 | htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ; |
4462 | htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ; |
3403 | 4463 | ||
3404 | /* Enable the DMA channel */ |
4464 | /* Enable the DMA channel */ |
3405 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)BurstBuffer, (uint32_t)&htim->Instance->DMAR, ((BurstLength) >> 8U) + 1U); |
4465 | if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)BurstBuffer, |
- | 4466 | (uint32_t)&htim->Instance->DMAR, DataLength) != HAL_OK) |
|
- | 4467 | { |
|
- | 4468 | /* Return error status */ |
|
- | 4469 | return HAL_ERROR; |
|
- | 4470 | } |
|
- | 4471 | break; |
|
3406 | } |
4472 | } |
3407 | break; |
- | |
3408 | case TIM_DMA_CC2: |
4473 | case TIM_DMA_CC2: |
3409 | { |
4474 | { |
3410 | /* Set the DMA Period elapsed callback */ |
4475 | /* Set the DMA compare callbacks */ |
3411 | htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMADelayPulseCplt; |
4476 | htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMADelayPulseCplt; |
- | 4477 | htim->hdma[TIM_DMA_ID_CC2]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt; |
|
3412 | 4478 | ||
3413 | /* Set the DMA error callback */ |
4479 | /* Set the DMA error callback */ |
3414 | htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError ; |
4480 | htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError ; |
3415 | 4481 | ||
3416 | /* Enable the DMA channel */ |
4482 | /* Enable the DMA channel */ |
3417 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)BurstBuffer, (uint32_t)&htim->Instance->DMAR, ((BurstLength) >> 8U) + 1U); |
4483 | if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)BurstBuffer, |
- | 4484 | (uint32_t)&htim->Instance->DMAR, DataLength) != HAL_OK) |
|
- | 4485 | { |
|
- | 4486 | /* Return error status */ |
|
- | 4487 | return HAL_ERROR; |
|
- | 4488 | } |
|
- | 4489 | break; |
|
3418 | } |
4490 | } |
3419 | break; |
- | |
3420 | case TIM_DMA_CC3: |
4491 | case TIM_DMA_CC3: |
3421 | { |
4492 | { |
3422 | /* Set the DMA Period elapsed callback */ |
4493 | /* Set the DMA compare callbacks */ |
3423 | htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMADelayPulseCplt; |
4494 | htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMADelayPulseCplt; |
- | 4495 | htim->hdma[TIM_DMA_ID_CC3]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt; |
|
3424 | 4496 | ||
3425 | /* Set the DMA error callback */ |
4497 | /* Set the DMA error callback */ |
3426 | htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = TIM_DMAError ; |
4498 | htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = TIM_DMAError ; |
3427 | 4499 | ||
3428 | /* Enable the DMA channel */ |
4500 | /* Enable the DMA channel */ |
3429 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)BurstBuffer, (uint32_t)&htim->Instance->DMAR, ((BurstLength) >> 8U) + 1U); |
4501 | if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)BurstBuffer, |
- | 4502 | (uint32_t)&htim->Instance->DMAR, DataLength) != HAL_OK) |
|
- | 4503 | { |
|
- | 4504 | /* Return error status */ |
|
- | 4505 | return HAL_ERROR; |
|
- | 4506 | } |
|
- | 4507 | break; |
|
3430 | } |
4508 | } |
3431 | break; |
- | |
3432 | case TIM_DMA_CC4: |
4509 | case TIM_DMA_CC4: |
3433 | { |
4510 | { |
3434 | /* Set the DMA Period elapsed callback */ |
4511 | /* Set the DMA compare callbacks */ |
3435 | htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = TIM_DMADelayPulseCplt; |
4512 | htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = TIM_DMADelayPulseCplt; |
- | 4513 | htim->hdma[TIM_DMA_ID_CC4]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt; |
|
3436 | 4514 | ||
3437 | /* Set the DMA error callback */ |
4515 | /* Set the DMA error callback */ |
3438 | htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = TIM_DMAError ; |
4516 | htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = TIM_DMAError ; |
3439 | 4517 | ||
3440 | /* Enable the DMA channel */ |
4518 | /* Enable the DMA channel */ |
3441 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)BurstBuffer, (uint32_t)&htim->Instance->DMAR, ((BurstLength) >> 8U) + 1U); |
4519 | if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)BurstBuffer, |
- | 4520 | (uint32_t)&htim->Instance->DMAR, DataLength) != HAL_OK) |
|
- | 4521 | { |
|
- | 4522 | /* Return error status */ |
|
- | 4523 | return HAL_ERROR; |
|
- | 4524 | } |
|
- | 4525 | break; |
|
3442 | } |
4526 | } |
3443 | break; |
- | |
3444 | case TIM_DMA_COM: |
4527 | case TIM_DMA_COM: |
3445 | { |
4528 | { |
3446 | /* Set the DMA Period elapsed callback */ |
4529 | /* Set the DMA commutation callbacks */ |
3447 | htim->hdma[TIM_DMA_ID_COMMUTATION]->XferCpltCallback = TIMEx_DMACommutationCplt; |
4530 | htim->hdma[TIM_DMA_ID_COMMUTATION]->XferCpltCallback = TIMEx_DMACommutationCplt; |
- | 4531 | htim->hdma[TIM_DMA_ID_COMMUTATION]->XferHalfCpltCallback = TIMEx_DMACommutationHalfCplt; |
|
3448 | 4532 | ||
3449 | /* Set the DMA error callback */ |
4533 | /* Set the DMA error callback */ |
3450 | htim->hdma[TIM_DMA_ID_COMMUTATION]->XferErrorCallback = TIM_DMAError ; |
4534 | htim->hdma[TIM_DMA_ID_COMMUTATION]->XferErrorCallback = TIM_DMAError ; |
3451 | 4535 | ||
3452 | /* Enable the DMA channel */ |
4536 | /* Enable the DMA channel */ |
3453 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_COMMUTATION], (uint32_t)BurstBuffer, (uint32_t)&htim->Instance->DMAR, ((BurstLength) >> 8U) + 1U); |
4537 | if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_COMMUTATION], (uint32_t)BurstBuffer, |
- | 4538 | (uint32_t)&htim->Instance->DMAR, DataLength) != HAL_OK) |
|
- | 4539 | { |
|
- | 4540 | /* Return error status */ |
|
- | 4541 | return HAL_ERROR; |
|
- | 4542 | } |
|
- | 4543 | break; |
|
3454 | } |
4544 | } |
3455 | break; |
- | |
3456 | case TIM_DMA_TRIGGER: |
4545 | case TIM_DMA_TRIGGER: |
3457 | { |
4546 | { |
3458 | /* Set the DMA Period elapsed callback */ |
4547 | /* Set the DMA trigger callbacks */ |
3459 | htim->hdma[TIM_DMA_ID_TRIGGER]->XferCpltCallback = TIM_DMATriggerCplt; |
4548 | htim->hdma[TIM_DMA_ID_TRIGGER]->XferCpltCallback = TIM_DMATriggerCplt; |
- | 4549 | htim->hdma[TIM_DMA_ID_TRIGGER]->XferHalfCpltCallback = TIM_DMATriggerHalfCplt; |
|
3460 | 4550 | ||
3461 | /* Set the DMA error callback */ |
4551 | /* Set the DMA error callback */ |
3462 | htim->hdma[TIM_DMA_ID_TRIGGER]->XferErrorCallback = TIM_DMAError ; |
4552 | htim->hdma[TIM_DMA_ID_TRIGGER]->XferErrorCallback = TIM_DMAError ; |
3463 | 4553 | ||
3464 | /* Enable the DMA channel */ |
4554 | /* Enable the DMA channel */ |
3465 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_TRIGGER], (uint32_t)BurstBuffer, (uint32_t)&htim->Instance->DMAR, ((BurstLength) >> 8U) + 1U); |
4555 | if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_TRIGGER], (uint32_t)BurstBuffer, |
- | 4556 | (uint32_t)&htim->Instance->DMAR, DataLength) != HAL_OK) |
|
- | 4557 | { |
|
- | 4558 | /* Return error status */ |
|
- | 4559 | return HAL_ERROR; |
|
- | 4560 | } |
|
- | 4561 | break; |
|
3466 | } |
4562 | } |
3467 | break; |
- | |
3468 | default: |
4563 | default: |
3469 | break; |
4564 | break; |
3470 | } |
4565 | } |
3471 | /* configure the DMA Burst Mode */ |
- | |
3472 | htim->Instance->DCR = BurstBaseAddress | BurstLength; |
- | |
3473 | - | ||
3474 | /* Enable the TIM DMA Request */ |
- | |
3475 | __HAL_TIM_ENABLE_DMA(htim, BurstRequestSrc); |
- | |
3476 | 4566 | ||
- | 4567 | /* Configure the DMA Burst Mode */ |
|
- | 4568 | htim->Instance->DCR = (BurstBaseAddress | BurstLength); |
|
3477 | htim->State = HAL_TIM_STATE_READY; |
4569 | /* Enable the TIM DMA Request */ |
- | 4570 | __HAL_TIM_ENABLE_DMA(htim, BurstRequestSrc); |
|
3478 | 4571 | ||
3479 | /* Return function status */ |
4572 | /* Return function status */ |
3480 | return HAL_OK; |
4573 | return HAL_OK; |
3481 | } |
4574 | } |
3482 | 4575 | ||
3483 | /** |
4576 | /** |
3484 | * @brief Stops the TIM DMA Burst mode |
4577 | * @brief Stops the TIM DMA Burst mode |
3485 | * @param htim : TIM handle |
4578 | * @param htim TIM handle |
3486 | * @param BurstRequestSrc : TIM DMA Request sources to disable |
4579 | * @param BurstRequestSrc TIM DMA Request sources to disable |
3487 | * @retval HAL status |
4580 | * @retval HAL status |
3488 | */ |
4581 | */ |
3489 | HAL_StatusTypeDef HAL_TIM_DMABurst_WriteStop(TIM_HandleTypeDef *htim, uint32_t BurstRequestSrc) |
4582 | HAL_StatusTypeDef HAL_TIM_DMABurst_WriteStop(TIM_HandleTypeDef *htim, uint32_t BurstRequestSrc) |
3490 | { |
4583 | { |
3491 | /* Check the parameters */ |
4584 | /* Check the parameters */ |
3492 | assert_param(IS_TIM_DMA_SOURCE(BurstRequestSrc)); |
4585 | assert_param(IS_TIM_DMA_SOURCE(BurstRequestSrc)); |
3493 | 4586 | ||
3494 | /* Abort the DMA transfer (at least disable the DMA channel) */ |
4587 | /* Abort the DMA transfer (at least disable the DMA channel) */ |
3495 | switch(BurstRequestSrc) |
4588 | switch (BurstRequestSrc) |
3496 | { |
4589 | { |
3497 | case TIM_DMA_UPDATE: |
4590 | case TIM_DMA_UPDATE: |
3498 | { |
4591 | { |
3499 | HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_UPDATE]); |
4592 | (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_UPDATE]); |
- | 4593 | break; |
|
3500 | } |
4594 | } |
3501 | break; |
- | |
3502 | case TIM_DMA_CC1: |
4595 | case TIM_DMA_CC1: |
3503 | { |
4596 | { |
3504 | HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_CC1]); |
4597 | (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC1]); |
- | 4598 | break; |
|
3505 | } |
4599 | } |
3506 | break; |
- | |
3507 | case TIM_DMA_CC2: |
4600 | case TIM_DMA_CC2: |
3508 | { |
4601 | { |
3509 | HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_CC2]); |
4602 | (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC2]); |
- | 4603 | break; |
|
3510 | } |
4604 | } |
3511 | break; |
- | |
3512 | case TIM_DMA_CC3: |
4605 | case TIM_DMA_CC3: |
3513 | { |
4606 | { |
3514 | HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_CC3]); |
4607 | (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC3]); |
- | 4608 | break; |
|
3515 | } |
4609 | } |
3516 | break; |
- | |
3517 | case TIM_DMA_CC4: |
4610 | case TIM_DMA_CC4: |
3518 | { |
4611 | { |
3519 | HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_CC4]); |
4612 | (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC4]); |
- | 4613 | break; |
|
3520 | } |
4614 | } |
3521 | break; |
- | |
3522 | case TIM_DMA_COM: |
4615 | case TIM_DMA_COM: |
3523 | { |
4616 | { |
3524 | HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_COMMUTATION]); |
4617 | (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_COMMUTATION]); |
- | 4618 | break; |
|
3525 | } |
4619 | } |
3526 | break; |
- | |
3527 | case TIM_DMA_TRIGGER: |
4620 | case TIM_DMA_TRIGGER: |
3528 | { |
4621 | { |
3529 | HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_TRIGGER]); |
4622 | (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_TRIGGER]); |
- | 4623 | break; |
|
3530 | } |
4624 | } |
3531 | break; |
- | |
3532 | default: |
4625 | default: |
3533 | break; |
4626 | break; |
3534 | } |
4627 | } |
3535 | 4628 | ||
3536 | /* Disable the TIM Update DMA request */ |
4629 | /* Disable the TIM Update DMA request */ |
3537 | __HAL_TIM_DISABLE_DMA(htim, BurstRequestSrc); |
4630 | __HAL_TIM_DISABLE_DMA(htim, BurstRequestSrc); |
3538 | 4631 | ||
- | 4632 | /* Change the DMA burst operation state */ |
|
- | 4633 | htim->DMABurstState = HAL_DMA_BURST_STATE_READY; |
|
- | 4634 | ||
3539 | /* Return function status */ |
4635 | /* Return function status */ |
3540 | return HAL_OK; |
4636 | return HAL_OK; |
3541 | } |
4637 | } |
3542 | 4638 | ||
3543 | /** |
4639 | /** |
3544 | * @brief Configure the DMA Burst to transfer Data from the TIM peripheral to the memory |
4640 | * @brief Configure the DMA Burst to transfer Data from the TIM peripheral to the memory |
3545 | * @param htim : TIM handle |
4641 | * @param htim TIM handle |
3546 | * @param BurstBaseAddress : TIM Base address from where the DMA will starts the Data read |
4642 | * @param BurstBaseAddress TIM Base address from where the DMA will start the Data read |
3547 | * This parameter can be one of the following values: |
4643 | * This parameter can be one of the following values: |
3548 | * @arg TIM_DMABASE_CR1 |
4644 | * @arg TIM_DMABASE_CR1 |
3549 | * @arg TIM_DMABASE_CR2 |
4645 | * @arg TIM_DMABASE_CR2 |
3550 | * @arg TIM_DMABASE_SMCR |
4646 | * @arg TIM_DMABASE_SMCR |
3551 | * @arg TIM_DMABASE_DIER |
4647 | * @arg TIM_DMABASE_DIER |
3552 | * @arg TIM_DMABASE_SR |
4648 | * @arg TIM_DMABASE_SR |
3553 | * @arg TIM_DMABASE_EGR |
4649 | * @arg TIM_DMABASE_EGR |
3554 | * @arg TIM_DMABASE_CCMR1 |
4650 | * @arg TIM_DMABASE_CCMR1 |
3555 | * @arg TIM_DMABASE_CCMR2 |
4651 | * @arg TIM_DMABASE_CCMR2 |
3556 | * @arg TIM_DMABASE_CCER |
4652 | * @arg TIM_DMABASE_CCER |
3557 | * @arg TIM_DMABASE_CNT |
4653 | * @arg TIM_DMABASE_CNT |
3558 | * @arg TIM_DMABASE_PSC |
4654 | * @arg TIM_DMABASE_PSC |
3559 | * @arg TIM_DMABASE_ARR |
4655 | * @arg TIM_DMABASE_ARR |
3560 | * @arg TIM_DMABASE_RCR |
4656 | * @arg TIM_DMABASE_RCR |
3561 | * @arg TIM_DMABASE_CCR1 |
4657 | * @arg TIM_DMABASE_CCR1 |
3562 | * @arg TIM_DMABASE_CCR2 |
4658 | * @arg TIM_DMABASE_CCR2 |
3563 | * @arg TIM_DMABASE_CCR3 |
4659 | * @arg TIM_DMABASE_CCR3 |
3564 | * @arg TIM_DMABASE_CCR4 |
4660 | * @arg TIM_DMABASE_CCR4 |
3565 | * @arg TIM_DMABASE_BDTR |
4661 | * @arg TIM_DMABASE_BDTR |
3566 | * @arg TIM_DMABASE_DCR |
- | |
3567 | * @param BurstRequestSrc : TIM DMA Request sources |
4662 | * @param BurstRequestSrc TIM DMA Request sources |
3568 | * This parameter can be one of the following values: |
4663 | * This parameter can be one of the following values: |
3569 | * @arg TIM_DMA_UPDATE: TIM update Interrupt source |
4664 | * @arg TIM_DMA_UPDATE: TIM update Interrupt source |
3570 | * @arg TIM_DMA_CC1: TIM Capture Compare 1 DMA source |
4665 | * @arg TIM_DMA_CC1: TIM Capture Compare 1 DMA source |
3571 | * @arg TIM_DMA_CC2: TIM Capture Compare 2 DMA source |
4666 | * @arg TIM_DMA_CC2: TIM Capture Compare 2 DMA source |
3572 | * @arg TIM_DMA_CC3: TIM Capture Compare 3 DMA source |
4667 | * @arg TIM_DMA_CC3: TIM Capture Compare 3 DMA source |
3573 | * @arg TIM_DMA_CC4: TIM Capture Compare 4 DMA source |
4668 | * @arg TIM_DMA_CC4: TIM Capture Compare 4 DMA source |
3574 | * @arg TIM_DMA_COM: TIM Commutation DMA source |
4669 | * @arg TIM_DMA_COM: TIM Commutation DMA source |
3575 | * @arg TIM_DMA_TRIGGER: TIM Trigger DMA source |
4670 | * @arg TIM_DMA_TRIGGER: TIM Trigger DMA source |
3576 | * @param BurstBuffer : The Buffer address. |
4671 | * @param BurstBuffer The Buffer address. |
3577 | * @param BurstLength : DMA Burst length. This parameter can be one value |
4672 | * @param BurstLength DMA Burst length. This parameter can be one value |
3578 | * between: TIM_DMABURSTLENGTH_1TRANSFER and TIM_DMABURSTLENGTH_18TRANSFERS. |
4673 | * between: TIM_DMABURSTLENGTH_1TRANSFER and TIM_DMABURSTLENGTH_18TRANSFERS. |
- | 4674 | * @note This function should be used only when BurstLength is equal to DMA data transfer length. |
|
3579 | * @retval HAL status |
4675 | * @retval HAL status |
3580 | */ |
4676 | */ |
3581 | HAL_StatusTypeDef HAL_TIM_DMABurst_ReadStart(TIM_HandleTypeDef *htim, uint32_t BurstBaseAddress, uint32_t BurstRequestSrc, |
4677 | HAL_StatusTypeDef HAL_TIM_DMABurst_ReadStart(TIM_HandleTypeDef *htim, uint32_t BurstBaseAddress, |
- | 4678 | uint32_t BurstRequestSrc, uint32_t *BurstBuffer, uint32_t BurstLength) |
|
- | 4679 | { |
|
- | 4680 | return HAL_TIM_DMABurst_MultiReadStart(htim, BurstBaseAddress, BurstRequestSrc, BurstBuffer, BurstLength, |
|
- | 4681 | ((BurstLength) >> 8U) + 1U); |
|
- | 4682 | } |
|
- | 4683 | ||
- | 4684 | /** |
|
- | 4685 | * @brief Configure the DMA Burst to transfer Data from the TIM peripheral to the memory |
|
- | 4686 | * @param htim TIM handle |
|
- | 4687 | * @param BurstBaseAddress TIM Base address from where the DMA will start the Data read |
|
- | 4688 | * This parameter can be one of the following values: |
|
- | 4689 | * @arg TIM_DMABASE_CR1 |
|
- | 4690 | * @arg TIM_DMABASE_CR2 |
|
- | 4691 | * @arg TIM_DMABASE_SMCR |
|
- | 4692 | * @arg TIM_DMABASE_DIER |
|
- | 4693 | * @arg TIM_DMABASE_SR |
|
- | 4694 | * @arg TIM_DMABASE_EGR |
|
- | 4695 | * @arg TIM_DMABASE_CCMR1 |
|
- | 4696 | * @arg TIM_DMABASE_CCMR2 |
|
- | 4697 | * @arg TIM_DMABASE_CCER |
|
- | 4698 | * @arg TIM_DMABASE_CNT |
|
- | 4699 | * @arg TIM_DMABASE_PSC |
|
- | 4700 | * @arg TIM_DMABASE_ARR |
|
- | 4701 | * @arg TIM_DMABASE_RCR |
|
- | 4702 | * @arg TIM_DMABASE_CCR1 |
|
- | 4703 | * @arg TIM_DMABASE_CCR2 |
|
- | 4704 | * @arg TIM_DMABASE_CCR3 |
|
- | 4705 | * @arg TIM_DMABASE_CCR4 |
|
- | 4706 | * @arg TIM_DMABASE_BDTR |
|
- | 4707 | * @param BurstRequestSrc TIM DMA Request sources |
|
- | 4708 | * This parameter can be one of the following values: |
|
- | 4709 | * @arg TIM_DMA_UPDATE: TIM update Interrupt source |
|
- | 4710 | * @arg TIM_DMA_CC1: TIM Capture Compare 1 DMA source |
|
- | 4711 | * @arg TIM_DMA_CC2: TIM Capture Compare 2 DMA source |
|
- | 4712 | * @arg TIM_DMA_CC3: TIM Capture Compare 3 DMA source |
|
- | 4713 | * @arg TIM_DMA_CC4: TIM Capture Compare 4 DMA source |
|
- | 4714 | * @arg TIM_DMA_COM: TIM Commutation DMA source |
|
- | 4715 | * @arg TIM_DMA_TRIGGER: TIM Trigger DMA source |
|
- | 4716 | * @param BurstBuffer The Buffer address. |
|
- | 4717 | * @param BurstLength DMA Burst length. This parameter can be one value |
|
- | 4718 | * between: TIM_DMABURSTLENGTH_1TRANSFER and TIM_DMABURSTLENGTH_18TRANSFERS. |
|
- | 4719 | * @param DataLength Data length. This parameter can be one value |
|
- | 4720 | * between 1 and 0xFFFF. |
|
- | 4721 | * @retval HAL status |
|
- | 4722 | */ |
|
- | 4723 | HAL_StatusTypeDef HAL_TIM_DMABurst_MultiReadStart(TIM_HandleTypeDef *htim, uint32_t BurstBaseAddress, |
|
- | 4724 | uint32_t BurstRequestSrc, uint32_t *BurstBuffer, |
|
3582 | uint32_t *BurstBuffer, uint32_t BurstLength) |
4725 | uint32_t BurstLength, uint32_t DataLength) |
3583 | { |
4726 | { |
3584 | /* Check the parameters */ |
4727 | /* Check the parameters */ |
3585 | assert_param(IS_TIM_DMABURST_INSTANCE(htim->Instance)); |
4728 | assert_param(IS_TIM_DMABURST_INSTANCE(htim->Instance)); |
3586 | assert_param(IS_TIM_DMA_BASE(BurstBaseAddress)); |
4729 | assert_param(IS_TIM_DMA_BASE(BurstBaseAddress)); |
3587 | assert_param(IS_TIM_DMA_SOURCE(BurstRequestSrc)); |
4730 | assert_param(IS_TIM_DMA_SOURCE(BurstRequestSrc)); |
3588 | assert_param(IS_TIM_DMA_LENGTH(BurstLength)); |
4731 | assert_param(IS_TIM_DMA_LENGTH(BurstLength)); |
- | 4732 | assert_param(IS_TIM_DMA_DATA_LENGTH(DataLength)); |
|
3589 | 4733 | ||
3590 | if((htim->State == HAL_TIM_STATE_BUSY)) |
4734 | if (htim->DMABurstState == HAL_DMA_BURST_STATE_BUSY) |
3591 | { |
4735 | { |
3592 | return HAL_BUSY; |
4736 | return HAL_BUSY; |
3593 | } |
4737 | } |
3594 | else if((htim->State == HAL_TIM_STATE_READY)) |
4738 | else if (htim->DMABurstState == HAL_DMA_BURST_STATE_READY) |
3595 | { |
4739 | { |
3596 | if((BurstBuffer == 0U) && (BurstLength > 0U)) |
4740 | if ((BurstBuffer == NULL) && (BurstLength > 0U)) |
3597 | { |
4741 | { |
3598 | return HAL_ERROR; |
4742 | return HAL_ERROR; |
3599 | } |
4743 | } |
3600 | else |
4744 | else |
3601 | { |
4745 | { |
3602 | htim->State = HAL_TIM_STATE_BUSY; |
4746 | htim->DMABurstState = HAL_DMA_BURST_STATE_BUSY; |
3603 | } |
4747 | } |
3604 | } |
4748 | } |
- | 4749 | else |
|
- | 4750 | { |
|
- | 4751 | /* nothing to do */ |
|
- | 4752 | } |
|
3605 | switch(BurstRequestSrc) |
4753 | switch (BurstRequestSrc) |
3606 | { |
4754 | { |
3607 | case TIM_DMA_UPDATE: |
4755 | case TIM_DMA_UPDATE: |
3608 | { |
4756 | { |
3609 | /* Set the DMA Period elapsed callback */ |
4757 | /* Set the DMA Period elapsed callbacks */ |
3610 | htim->hdma[TIM_DMA_ID_UPDATE]->XferCpltCallback = TIM_DMAPeriodElapsedCplt; |
4758 | htim->hdma[TIM_DMA_ID_UPDATE]->XferCpltCallback = TIM_DMAPeriodElapsedCplt; |
- | 4759 | htim->hdma[TIM_DMA_ID_UPDATE]->XferHalfCpltCallback = TIM_DMAPeriodElapsedHalfCplt; |
|
3611 | 4760 | ||
3612 | /* Set the DMA error callback */ |
4761 | /* Set the DMA error callback */ |
3613 | htim->hdma[TIM_DMA_ID_UPDATE]->XferErrorCallback = TIM_DMAError ; |
4762 | htim->hdma[TIM_DMA_ID_UPDATE]->XferErrorCallback = TIM_DMAError ; |
3614 | 4763 | ||
3615 | /* Enable the DMA channel */ |
4764 | /* Enable the DMA channel */ |
3616 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_UPDATE], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, ((BurstLength) >> 8U) + 1U); |
4765 | if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_UPDATE], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, |
- | 4766 | DataLength) != HAL_OK) |
|
- | 4767 | { |
|
- | 4768 | /* Return error status */ |
|
- | 4769 | return HAL_ERROR; |
|
- | 4770 | } |
|
- | 4771 | break; |
|
3617 | } |
4772 | } |
3618 | break; |
- | |
3619 | case TIM_DMA_CC1: |
4773 | case TIM_DMA_CC1: |
3620 | { |
4774 | { |
3621 | /* Set the DMA Period elapsed callback */ |
4775 | /* Set the DMA capture callbacks */ |
3622 | htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMACaptureCplt; |
4776 | htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMACaptureCplt; |
- | 4777 | htim->hdma[TIM_DMA_ID_CC1]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt; |
|
3623 | 4778 | ||
3624 | /* Set the DMA error callback */ |
4779 | /* Set the DMA error callback */ |
3625 | htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ; |
4780 | htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ; |
3626 | 4781 | ||
3627 | /* Enable the DMA channel */ |
4782 | /* Enable the DMA channel */ |
3628 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, ((BurstLength) >> 8U) + 1U); |
4783 | if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, |
- | 4784 | DataLength) != HAL_OK) |
|
- | 4785 | { |
|
- | 4786 | /* Return error status */ |
|
- | 4787 | return HAL_ERROR; |
|
- | 4788 | } |
|
- | 4789 | break; |
|
3629 | } |
4790 | } |
3630 | break; |
- | |
3631 | case TIM_DMA_CC2: |
4791 | case TIM_DMA_CC2: |
3632 | { |
4792 | { |
3633 | /* Set the DMA Period elapsed callback */ |
4793 | /* Set the DMA capture callbacks */ |
3634 | htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMACaptureCplt; |
4794 | htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMACaptureCplt; |
- | 4795 | htim->hdma[TIM_DMA_ID_CC2]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt; |
|
3635 | 4796 | ||
3636 | /* Set the DMA error callback */ |
4797 | /* Set the DMA error callback */ |
3637 | htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError ; |
4798 | htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError ; |
3638 | 4799 | ||
3639 | /* Enable the DMA channel */ |
4800 | /* Enable the DMA channel */ |
3640 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, ((BurstLength) >> 8U) + 1U); |
4801 | if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, |
- | 4802 | DataLength) != HAL_OK) |
|
- | 4803 | { |
|
- | 4804 | /* Return error status */ |
|
- | 4805 | return HAL_ERROR; |
|
- | 4806 | } |
|
- | 4807 | break; |
|
3641 | } |
4808 | } |
3642 | break; |
- | |
3643 | case TIM_DMA_CC3: |
4809 | case TIM_DMA_CC3: |
3644 | { |
4810 | { |
3645 | /* Set the DMA Period elapsed callback */ |
4811 | /* Set the DMA capture callbacks */ |
3646 | htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMACaptureCplt; |
4812 | htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMACaptureCplt; |
- | 4813 | htim->hdma[TIM_DMA_ID_CC3]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt; |
|
3647 | 4814 | ||
3648 | /* Set the DMA error callback */ |
4815 | /* Set the DMA error callback */ |
3649 | htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = TIM_DMAError ; |
4816 | htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = TIM_DMAError ; |
3650 | 4817 | ||
3651 | /* Enable the DMA channel */ |
4818 | /* Enable the DMA channel */ |
3652 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, ((BurstLength) >> 8U) + 1U); |
4819 | if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, |
- | 4820 | DataLength) != HAL_OK) |
|
- | 4821 | { |
|
- | 4822 | /* Return error status */ |
|
- | 4823 | return HAL_ERROR; |
|
- | 4824 | } |
|
- | 4825 | break; |
|
3653 | } |
4826 | } |
3654 | break; |
- | |
3655 | case TIM_DMA_CC4: |
4827 | case TIM_DMA_CC4: |
3656 | { |
4828 | { |
3657 | /* Set the DMA Period elapsed callback */ |
4829 | /* Set the DMA capture callbacks */ |
3658 | htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = TIM_DMACaptureCplt; |
4830 | htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = TIM_DMACaptureCplt; |
- | 4831 | htim->hdma[TIM_DMA_ID_CC4]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt; |
|
3659 | 4832 | ||
3660 | /* Set the DMA error callback */ |
4833 | /* Set the DMA error callback */ |
3661 | htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = TIM_DMAError ; |
4834 | htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = TIM_DMAError ; |
3662 | 4835 | ||
3663 | /* Enable the DMA channel */ |
4836 | /* Enable the DMA channel */ |
3664 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, ((BurstLength) >> 8U) + 1U); |
4837 | if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, |
- | 4838 | DataLength) != HAL_OK) |
|
- | 4839 | { |
|
- | 4840 | /* Return error status */ |
|
- | 4841 | return HAL_ERROR; |
|
- | 4842 | } |
|
- | 4843 | break; |
|
3665 | } |
4844 | } |
3666 | break; |
- | |
3667 | case TIM_DMA_COM: |
4845 | case TIM_DMA_COM: |
3668 | { |
4846 | { |
3669 | /* Set the DMA Period elapsed callback */ |
4847 | /* Set the DMA commutation callbacks */ |
3670 | htim->hdma[TIM_DMA_ID_COMMUTATION]->XferCpltCallback = TIMEx_DMACommutationCplt; |
4848 | htim->hdma[TIM_DMA_ID_COMMUTATION]->XferCpltCallback = TIMEx_DMACommutationCplt; |
- | 4849 | htim->hdma[TIM_DMA_ID_COMMUTATION]->XferHalfCpltCallback = TIMEx_DMACommutationHalfCplt; |
|
3671 | 4850 | ||
3672 | /* Set the DMA error callback */ |
4851 | /* Set the DMA error callback */ |
3673 | htim->hdma[TIM_DMA_ID_COMMUTATION]->XferErrorCallback = TIM_DMAError ; |
4852 | htim->hdma[TIM_DMA_ID_COMMUTATION]->XferErrorCallback = TIM_DMAError ; |
3674 | 4853 | ||
3675 | /* Enable the DMA channel */ |
4854 | /* Enable the DMA channel */ |
3676 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_COMMUTATION], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, ((BurstLength) >> 8U) + 1U); |
4855 | if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_COMMUTATION], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, |
- | 4856 | DataLength) != HAL_OK) |
|
- | 4857 | { |
|
- | 4858 | /* Return error status */ |
|
- | 4859 | return HAL_ERROR; |
|
- | 4860 | } |
|
- | 4861 | break; |
|
3677 | } |
4862 | } |
3678 | break; |
- | |
3679 | case TIM_DMA_TRIGGER: |
4863 | case TIM_DMA_TRIGGER: |
3680 | { |
4864 | { |
3681 | /* Set the DMA Period elapsed callback */ |
4865 | /* Set the DMA trigger callbacks */ |
3682 | htim->hdma[TIM_DMA_ID_TRIGGER]->XferCpltCallback = TIM_DMATriggerCplt; |
4866 | htim->hdma[TIM_DMA_ID_TRIGGER]->XferCpltCallback = TIM_DMATriggerCplt; |
- | 4867 | htim->hdma[TIM_DMA_ID_TRIGGER]->XferHalfCpltCallback = TIM_DMATriggerHalfCplt; |
|
3683 | 4868 | ||
3684 | /* Set the DMA error callback */ |
4869 | /* Set the DMA error callback */ |
3685 | htim->hdma[TIM_DMA_ID_TRIGGER]->XferErrorCallback = TIM_DMAError ; |
4870 | htim->hdma[TIM_DMA_ID_TRIGGER]->XferErrorCallback = TIM_DMAError ; |
3686 | 4871 | ||
3687 | /* Enable the DMA channel */ |
4872 | /* Enable the DMA channel */ |
3688 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_TRIGGER], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, ((BurstLength) >> 8U) + 1U); |
4873 | if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_TRIGGER], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, |
- | 4874 | DataLength) != HAL_OK) |
|
- | 4875 | { |
|
- | 4876 | /* Return error status */ |
|
- | 4877 | return HAL_ERROR; |
|
- | 4878 | } |
|
- | 4879 | break; |
|
3689 | } |
4880 | } |
3690 | break; |
- | |
3691 | default: |
4881 | default: |
3692 | break; |
4882 | break; |
3693 | } |
4883 | } |
3694 | 4884 | ||
3695 | /* configure the DMA Burst Mode */ |
4885 | /* Configure the DMA Burst Mode */ |
3696 | htim->Instance->DCR = BurstBaseAddress | BurstLength; |
4886 | htim->Instance->DCR = (BurstBaseAddress | BurstLength); |
3697 | 4887 | ||
3698 | /* Enable the TIM DMA Request */ |
4888 | /* Enable the TIM DMA Request */ |
3699 | __HAL_TIM_ENABLE_DMA(htim, BurstRequestSrc); |
4889 | __HAL_TIM_ENABLE_DMA(htim, BurstRequestSrc); |
3700 | 4890 | ||
3701 | htim->State = HAL_TIM_STATE_READY; |
- | |
3702 | - | ||
3703 | /* Return function status */ |
4891 | /* Return function status */ |
3704 | return HAL_OK; |
4892 | return HAL_OK; |
3705 | } |
4893 | } |
3706 | 4894 | ||
3707 | /** |
4895 | /** |
3708 | * @brief Stop the DMA burst reading |
4896 | * @brief Stop the DMA burst reading |
3709 | * @param htim : TIM handle |
4897 | * @param htim TIM handle |
3710 | * @param BurstRequestSrc : TIM DMA Request sources to disable. |
4898 | * @param BurstRequestSrc TIM DMA Request sources to disable. |
3711 | * @retval HAL status |
4899 | * @retval HAL status |
3712 | */ |
4900 | */ |
3713 | HAL_StatusTypeDef HAL_TIM_DMABurst_ReadStop(TIM_HandleTypeDef *htim, uint32_t BurstRequestSrc) |
4901 | HAL_StatusTypeDef HAL_TIM_DMABurst_ReadStop(TIM_HandleTypeDef *htim, uint32_t BurstRequestSrc) |
3714 | { |
4902 | { |
3715 | /* Check the parameters */ |
4903 | /* Check the parameters */ |
3716 | assert_param(IS_TIM_DMA_SOURCE(BurstRequestSrc)); |
4904 | assert_param(IS_TIM_DMA_SOURCE(BurstRequestSrc)); |
3717 | 4905 | ||
3718 | /* Abort the DMA transfer (at least disable the DMA channel) */ |
4906 | /* Abort the DMA transfer (at least disable the DMA channel) */ |
3719 | switch(BurstRequestSrc) |
4907 | switch (BurstRequestSrc) |
3720 | { |
4908 | { |
3721 | case TIM_DMA_UPDATE: |
4909 | case TIM_DMA_UPDATE: |
3722 | { |
4910 | { |
3723 | HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_UPDATE]); |
4911 | (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_UPDATE]); |
- | 4912 | break; |
|
3724 | } |
4913 | } |
3725 | break; |
- | |
3726 | case TIM_DMA_CC1: |
4914 | case TIM_DMA_CC1: |
3727 | { |
4915 | { |
3728 | HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_CC1]); |
4916 | (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC1]); |
- | 4917 | break; |
|
3729 | } |
4918 | } |
3730 | break; |
- | |
3731 | case TIM_DMA_CC2: |
4919 | case TIM_DMA_CC2: |
3732 | { |
4920 | { |
3733 | HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_CC2]); |
4921 | (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC2]); |
- | 4922 | break; |
|
3734 | } |
4923 | } |
3735 | break; |
- | |
3736 | case TIM_DMA_CC3: |
4924 | case TIM_DMA_CC3: |
3737 | { |
4925 | { |
3738 | HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_CC3]); |
4926 | (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC3]); |
- | 4927 | break; |
|
3739 | } |
4928 | } |
3740 | break; |
- | |
3741 | case TIM_DMA_CC4: |
4929 | case TIM_DMA_CC4: |
3742 | { |
4930 | { |
3743 | HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_CC4]); |
4931 | (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC4]); |
- | 4932 | break; |
|
3744 | } |
4933 | } |
3745 | break; |
- | |
3746 | case TIM_DMA_COM: |
4934 | case TIM_DMA_COM: |
3747 | { |
4935 | { |
3748 | HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_COMMUTATION]); |
4936 | (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_COMMUTATION]); |
- | 4937 | break; |
|
3749 | } |
4938 | } |
3750 | break; |
- | |
3751 | case TIM_DMA_TRIGGER: |
4939 | case TIM_DMA_TRIGGER: |
3752 | { |
4940 | { |
3753 | HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_TRIGGER]); |
4941 | (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_TRIGGER]); |
- | 4942 | break; |
|
3754 | } |
4943 | } |
3755 | break; |
- | |
3756 | default: |
4944 | default: |
3757 | break; |
4945 | break; |
3758 | } |
4946 | } |
3759 | 4947 | ||
3760 | /* Disable the TIM Update DMA request */ |
4948 | /* Disable the TIM Update DMA request */ |
3761 | __HAL_TIM_DISABLE_DMA(htim, BurstRequestSrc); |
4949 | __HAL_TIM_DISABLE_DMA(htim, BurstRequestSrc); |
3762 | 4950 | ||
- | 4951 | /* Change the DMA burst operation state */ |
|
- | 4952 | htim->DMABurstState = HAL_DMA_BURST_STATE_READY; |
|
- | 4953 | ||
3763 | /* Return function status */ |
4954 | /* Return function status */ |
3764 | return HAL_OK; |
4955 | return HAL_OK; |
3765 | } |
4956 | } |
3766 | 4957 | ||
3767 | /** |
4958 | /** |
3768 | * @brief Generate a software event |
4959 | * @brief Generate a software event |
3769 | * @param htim : TIM handle |
4960 | * @param htim TIM handle |
3770 | * @param EventSource : specifies the event source. |
4961 | * @param EventSource specifies the event source. |
3771 | * This parameter can be one of the following values: |
4962 | * This parameter can be one of the following values: |
3772 | * @arg TIM_EVENTSOURCE_UPDATE: Timer update Event source |
4963 | * @arg TIM_EVENTSOURCE_UPDATE: Timer update Event source |
3773 | * @arg TIM_EVENTSOURCE_CC1: Timer Capture Compare 1 Event source |
4964 | * @arg TIM_EVENTSOURCE_CC1: Timer Capture Compare 1 Event source |
3774 | * @arg TIM_EVENTSOURCE_CC2: Timer Capture Compare 2 Event source |
4965 | * @arg TIM_EVENTSOURCE_CC2: Timer Capture Compare 2 Event source |
3775 | * @arg TIM_EVENTSOURCE_CC3: Timer Capture Compare 3 Event source |
4966 | * @arg TIM_EVENTSOURCE_CC3: Timer Capture Compare 3 Event source |
3776 | * @arg TIM_EVENTSOURCE_CC4: Timer Capture Compare 4 Event source |
4967 | * @arg TIM_EVENTSOURCE_CC4: Timer Capture Compare 4 Event source |
3777 | * @arg TIM_EVENTSOURCE_COM: Timer COM event source |
4968 | * @arg TIM_EVENTSOURCE_COM: Timer COM event source |
3778 | * @arg TIM_EVENTSOURCE_TRIGGER: Timer Trigger Event source |
4969 | * @arg TIM_EVENTSOURCE_TRIGGER: Timer Trigger Event source |
3779 | * @arg TIM_EVENTSOURCE_BREAK: Timer Break event source |
4970 | * @arg TIM_EVENTSOURCE_BREAK: Timer Break event source |
3780 | * @note TIM6 and TIM7 can only generate an update event. |
4971 | * @note Basic timers can only generate an update event. |
3781 | * @note TIM_EVENTSOURCE_COM and TIM_EVENTSOURCE_BREAK are used only with TIM1, TIM15, TIM16 and TIM17. |
4972 | * @note TIM_EVENTSOURCE_COM is relevant only with advanced timer instances. |
- | 4973 | * @note TIM_EVENTSOURCE_BREAK are relevant only for timer instances |
|
- | 4974 | * supporting a break input. |
|
3782 | * @retval HAL status |
4975 | * @retval HAL status |
3783 | */ |
4976 | */ |
3784 | 4977 | ||
3785 | HAL_StatusTypeDef HAL_TIM_GenerateEvent(TIM_HandleTypeDef *htim, uint32_t EventSource) |
4978 | HAL_StatusTypeDef HAL_TIM_GenerateEvent(TIM_HandleTypeDef *htim, uint32_t EventSource) |
3786 | { |
4979 | { |
Line 3806... | Line 4999... | ||
3806 | return HAL_OK; |
4999 | return HAL_OK; |
3807 | } |
5000 | } |
3808 | 5001 | ||
3809 | /** |
5002 | /** |
3810 | * @brief Configures the OCRef clear feature |
5003 | * @brief Configures the OCRef clear feature |
3811 | * @param htim : TIM handle |
5004 | * @param htim TIM handle |
3812 | * @param sClearInputConfig : pointer to a TIM_ClearInputConfigTypeDef structure that |
5005 | * @param sClearInputConfig pointer to a TIM_ClearInputConfigTypeDef structure that |
3813 | * contains the OCREF clear feature and parameters for the TIM peripheral. |
5006 | * contains the OCREF clear feature and parameters for the TIM peripheral. |
3814 | * @param Channel : specifies the TIM Channel |
5007 | * @param Channel specifies the TIM Channel |
3815 | * This parameter can be one of the following values: |
5008 | * This parameter can be one of the following values: |
3816 | * @arg TIM_CHANNEL_1: TIM Channel 1 |
5009 | * @arg TIM_CHANNEL_1: TIM Channel 1 |
3817 | * @arg TIM_CHANNEL_2: TIM Channel 2 |
5010 | * @arg TIM_CHANNEL_2: TIM Channel 2 |
3818 | * @arg TIM_CHANNEL_3: TIM Channel 3 |
5011 | * @arg TIM_CHANNEL_3: TIM Channel 3 |
3819 | * @arg TIM_CHANNEL_4: TIM Channel 4 |
5012 | * @arg TIM_CHANNEL_4: TIM Channel 4 |
3820 | * @retval HAL status |
5013 | * @retval HAL status |
3821 | */ |
5014 | */ |
3822 | HAL_StatusTypeDef HAL_TIM_ConfigOCrefClear(TIM_HandleTypeDef *htim, TIM_ClearInputConfigTypeDef * sClearInputConfig, uint32_t Channel) |
5015 | HAL_StatusTypeDef HAL_TIM_ConfigOCrefClear(TIM_HandleTypeDef *htim, |
- | 5016 | TIM_ClearInputConfigTypeDef *sClearInputConfig, |
|
- | 5017 | uint32_t Channel) |
|
3823 | { |
5018 | { |
3824 | uint32_t tmpsmcr = 0U; |
- | |
3825 | - | ||
3826 | /* Check the parameters */ |
5019 | /* Check the parameters */ |
3827 | assert_param(IS_TIM_OCXREF_CLEAR_INSTANCE(htim->Instance)); |
5020 | assert_param(IS_TIM_OCXREF_CLEAR_INSTANCE(htim->Instance)); |
3828 | assert_param(IS_TIM_CLEARINPUT_SOURCE(sClearInputConfig->ClearInputSource)); |
5021 | assert_param(IS_TIM_CLEARINPUT_SOURCE(sClearInputConfig->ClearInputSource)); |
3829 | assert_param(IS_TIM_CLEARINPUT_POLARITY(sClearInputConfig->ClearInputPolarity)); |
- | |
3830 | assert_param(IS_TIM_CLEARINPUT_PRESCALER(sClearInputConfig->ClearInputPrescaler)); |
- | |
3831 | assert_param(IS_TIM_CLEARINPUT_FILTER(sClearInputConfig->ClearInputFilter)); |
- | |
3832 | 5022 | ||
3833 | /* Process Locked */ |
5023 | /* Process Locked */ |
3834 | __HAL_LOCK(htim); |
5024 | __HAL_LOCK(htim); |
3835 | 5025 | ||
3836 | htim->State = HAL_TIM_STATE_BUSY; |
5026 | htim->State = HAL_TIM_STATE_BUSY; |
3837 | 5027 | ||
3838 | switch (sClearInputConfig->ClearInputSource) |
5028 | switch (sClearInputConfig->ClearInputSource) |
3839 | { |
5029 | { |
3840 | case TIM_CLEARINPUTSOURCE_NONE: |
5030 | case TIM_CLEARINPUTSOURCE_NONE: |
3841 | { |
5031 | { |
3842 | - | ||
3843 | /* Clear the ETR Bits */ |
5032 | /* Clear the OCREF clear selection bit and the the ETR Bits */ |
3844 | tmpsmcr &= ~(TIM_SMCR_ETF | TIM_SMCR_ETPS | TIM_SMCR_ECE | TIM_SMCR_ETP); |
5033 | CLEAR_BIT(htim->Instance->SMCR, (TIM_SMCR_ETF | TIM_SMCR_ETPS | TIM_SMCR_ECE | TIM_SMCR_ETP)); |
3845 | - | ||
3846 | /* Set TIMx_SMCR */ |
5034 | break; |
3847 | htim->Instance->SMCR = tmpsmcr; |
- | |
3848 | } |
5035 | } |
3849 | break; |
- | |
3850 | 5036 | ||
3851 | case TIM_CLEARINPUTSOURCE_ETR: |
5037 | case TIM_CLEARINPUTSOURCE_ETR: |
3852 | { |
5038 | { |
- | 5039 | /* Check the parameters */ |
|
- | 5040 | assert_param(IS_TIM_CLEARINPUT_POLARITY(sClearInputConfig->ClearInputPolarity)); |
|
- | 5041 | assert_param(IS_TIM_CLEARINPUT_PRESCALER(sClearInputConfig->ClearInputPrescaler)); |
|
- | 5042 | assert_param(IS_TIM_CLEARINPUT_FILTER(sClearInputConfig->ClearInputFilter)); |
|
- | 5043 | ||
- | 5044 | /* When OCRef clear feature is used with ETR source, ETR prescaler must be off */ |
|
- | 5045 | if (sClearInputConfig->ClearInputPrescaler != TIM_CLEARINPUTPRESCALER_DIV1) |
|
- | 5046 | { |
|
- | 5047 | htim->State = HAL_TIM_STATE_READY; |
|
- | 5048 | __HAL_UNLOCK(htim); |
|
- | 5049 | return HAL_ERROR; |
|
- | 5050 | } |
|
- | 5051 | ||
3853 | TIM_ETR_SetConfig(htim->Instance, |
5052 | TIM_ETR_SetConfig(htim->Instance, |
3854 | sClearInputConfig->ClearInputPrescaler, |
5053 | sClearInputConfig->ClearInputPrescaler, |
3855 | sClearInputConfig->ClearInputPolarity, |
5054 | sClearInputConfig->ClearInputPolarity, |
3856 | sClearInputConfig->ClearInputFilter); |
5055 | sClearInputConfig->ClearInputFilter); |
3857 | 5056 | break; |
|
3858 | } |
5057 | } |
3859 | break; |
5058 | |
3860 | default: |
5059 | default: |
3861 | break; |
5060 | break; |
3862 | } |
5061 | } |
3863 | 5062 | ||
3864 | switch (Channel) |
5063 | switch (Channel) |
3865 | { |
5064 | { |
3866 | case TIM_CHANNEL_1: |
5065 | case TIM_CHANNEL_1: |
- | 5066 | { |
|
- | 5067 | if (sClearInputConfig->ClearInputState != (uint32_t)DISABLE) |
|
3867 | { |
5068 | { |
3868 | if(sClearInputConfig->ClearInputState != RESET) |
- | |
3869 | { |
- | |
3870 | /* Enable the Ocref clear feature for Channel 1 */ |
5069 | /* Enable the OCREF clear feature for Channel 1 */ |
3871 | htim->Instance->CCMR1 |= TIM_CCMR1_OC1CE; |
5070 | SET_BIT(htim->Instance->CCMR1, TIM_CCMR1_OC1CE); |
3872 | } |
5071 | } |
3873 | else |
5072 | else |
3874 | { |
5073 | { |
3875 | /* Disable the Ocref clear feature for Channel 1 */ |
5074 | /* Disable the OCREF clear feature for Channel 1 */ |
3876 | htim->Instance->CCMR1 &= ~TIM_CCMR1_OC1CE; |
5075 | CLEAR_BIT(htim->Instance->CCMR1, TIM_CCMR1_OC1CE); |
3877 | } |
- | |
3878 | } |
5076 | } |
3879 | break; |
5077 | break; |
- | 5078 | } |
|
3880 | case TIM_CHANNEL_2: |
5079 | case TIM_CHANNEL_2: |
- | 5080 | { |
|
- | 5081 | if (sClearInputConfig->ClearInputState != (uint32_t)DISABLE) |
|
3881 | { |
5082 | { |
3882 | assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); |
- | |
3883 | if(sClearInputConfig->ClearInputState != RESET) |
- | |
3884 | { |
- | |
3885 | /* Enable the Ocref clear feature for Channel 2 */ |
5083 | /* Enable the OCREF clear feature for Channel 2 */ |
3886 | htim->Instance->CCMR1 |= TIM_CCMR1_OC2CE; |
5084 | SET_BIT(htim->Instance->CCMR1, TIM_CCMR1_OC2CE); |
3887 | } |
5085 | } |
3888 | else |
5086 | else |
3889 | { |
5087 | { |
3890 | /* Disable the Ocref clear feature for Channel 2 */ |
5088 | /* Disable the OCREF clear feature for Channel 2 */ |
3891 | htim->Instance->CCMR1 &= ~TIM_CCMR1_OC2CE; |
5089 | CLEAR_BIT(htim->Instance->CCMR1, TIM_CCMR1_OC2CE); |
3892 | } |
- | |
3893 | } |
5090 | } |
3894 | break; |
5091 | break; |
- | 5092 | } |
|
3895 | case TIM_CHANNEL_3: |
5093 | case TIM_CHANNEL_3: |
- | 5094 | { |
|
- | 5095 | if (sClearInputConfig->ClearInputState != (uint32_t)DISABLE) |
|
3896 | { |
5096 | { |
3897 | assert_param(IS_TIM_CC3_INSTANCE(htim->Instance)); |
- | |
3898 | if(sClearInputConfig->ClearInputState != RESET) |
- | |
3899 | { |
- | |
3900 | /* Enable the Ocref clear feature for Channel 3 */ |
5097 | /* Enable the OCREF clear feature for Channel 3 */ |
3901 | htim->Instance->CCMR2 |= TIM_CCMR2_OC3CE; |
5098 | SET_BIT(htim->Instance->CCMR2, TIM_CCMR2_OC3CE); |
3902 | } |
5099 | } |
3903 | else |
5100 | else |
3904 | { |
5101 | { |
3905 | /* Disable the Ocref clear feature for Channel 3 */ |
5102 | /* Disable the OCREF clear feature for Channel 3 */ |
3906 | htim->Instance->CCMR2 &= ~TIM_CCMR2_OC3CE; |
5103 | CLEAR_BIT(htim->Instance->CCMR2, TIM_CCMR2_OC3CE); |
3907 | } |
- | |
3908 | } |
5104 | } |
3909 | break; |
5105 | break; |
- | 5106 | } |
|
3910 | case TIM_CHANNEL_4: |
5107 | case TIM_CHANNEL_4: |
- | 5108 | { |
|
- | 5109 | if (sClearInputConfig->ClearInputState != (uint32_t)DISABLE) |
|
3911 | { |
5110 | { |
3912 | assert_param(IS_TIM_CC4_INSTANCE(htim->Instance)); |
- | |
3913 | if(sClearInputConfig->ClearInputState != RESET) |
- | |
3914 | { |
- | |
3915 | /* Enable the Ocref clear feature for Channel 4 */ |
5111 | /* Enable the OCREF clear feature for Channel 4 */ |
3916 | htim->Instance->CCMR2 |= TIM_CCMR2_OC4CE; |
5112 | SET_BIT(htim->Instance->CCMR2, TIM_CCMR2_OC4CE); |
3917 | } |
5113 | } |
3918 | else |
5114 | else |
3919 | { |
5115 | { |
3920 | /* Disable the Ocref clear feature for Channel 4 */ |
5116 | /* Disable the OCREF clear feature for Channel 4 */ |
3921 | htim->Instance->CCMR2 &= ~TIM_CCMR2_OC4CE; |
5117 | CLEAR_BIT(htim->Instance->CCMR2, TIM_CCMR2_OC4CE); |
3922 | } |
- | |
3923 | } |
5118 | } |
3924 | break; |
5119 | break; |
- | 5120 | } |
|
3925 | default: |
5121 | default: |
3926 | break; |
5122 | break; |
3927 | } |
5123 | } |
3928 | 5124 | ||
3929 | htim->State = HAL_TIM_STATE_READY; |
5125 | htim->State = HAL_TIM_STATE_READY; |
3930 | 5126 | ||
3931 | __HAL_UNLOCK(htim); |
5127 | __HAL_UNLOCK(htim); |
Line 3933... | Line 5129... | ||
3933 | return HAL_OK; |
5129 | return HAL_OK; |
3934 | } |
5130 | } |
3935 | 5131 | ||
3936 | /** |
5132 | /** |
3937 | * @brief Configures the clock source to be used |
5133 | * @brief Configures the clock source to be used |
3938 | * @param htim : TIM handle |
5134 | * @param htim TIM handle |
3939 | * @param sClockSourceConfig : pointer to a TIM_ClockConfigTypeDef structure that |
5135 | * @param sClockSourceConfig pointer to a TIM_ClockConfigTypeDef structure that |
3940 | * contains the clock source information for the TIM peripheral. |
5136 | * contains the clock source information for the TIM peripheral. |
3941 | * @retval HAL status |
5137 | * @retval HAL status |
3942 | */ |
5138 | */ |
3943 | HAL_StatusTypeDef HAL_TIM_ConfigClockSource(TIM_HandleTypeDef *htim, TIM_ClockConfigTypeDef * sClockSourceConfig) |
5139 | HAL_StatusTypeDef HAL_TIM_ConfigClockSource(TIM_HandleTypeDef *htim, TIM_ClockConfigTypeDef *sClockSourceConfig) |
3944 | { |
5140 | { |
3945 | uint32_t tmpsmcr = 0U; |
5141 | uint32_t tmpsmcr; |
3946 | 5142 | ||
3947 | /* Process Locked */ |
5143 | /* Process Locked */ |
3948 | __HAL_LOCK(htim); |
5144 | __HAL_LOCK(htim); |
3949 | 5145 | ||
3950 | htim->State = HAL_TIM_STATE_BUSY; |
5146 | htim->State = HAL_TIM_STATE_BUSY; |
Line 3958... | Line 5154... | ||
3958 | tmpsmcr &= ~(TIM_SMCR_ETF | TIM_SMCR_ETPS | TIM_SMCR_ECE | TIM_SMCR_ETP); |
5154 | tmpsmcr &= ~(TIM_SMCR_ETF | TIM_SMCR_ETPS | TIM_SMCR_ECE | TIM_SMCR_ETP); |
3959 | htim->Instance->SMCR = tmpsmcr; |
5155 | htim->Instance->SMCR = tmpsmcr; |
3960 | 5156 | ||
3961 | switch (sClockSourceConfig->ClockSource) |
5157 | switch (sClockSourceConfig->ClockSource) |
3962 | { |
5158 | { |
3963 | case TIM_CLOCKSOURCE_INTERNAL: |
5159 | case TIM_CLOCKSOURCE_INTERNAL: |
3964 | { |
5160 | { |
3965 | assert_param(IS_TIM_INSTANCE(htim->Instance)); |
5161 | assert_param(IS_TIM_INSTANCE(htim->Instance)); |
3966 | /* Disable slave mode to clock the prescaler directly with the internal clock */ |
- | |
3967 | htim->Instance->SMCR &= ~TIM_SMCR_SMS; |
5162 | break; |
3968 | } |
5163 | } |
3969 | break; |
- | |
3970 | 5164 | ||
3971 | case TIM_CLOCKSOURCE_ETRMODE1: |
5165 | case TIM_CLOCKSOURCE_ETRMODE1: |
3972 | { |
5166 | { |
3973 | /* Check whether or not the timer instance supports external trigger input mode 1 (ETRF)*/ |
5167 | /* Check whether or not the timer instance supports external trigger input mode 1 (ETRF)*/ |
3974 | assert_param(IS_TIM_CLOCKSOURCE_ETRMODE1_INSTANCE(htim->Instance)); |
5168 | assert_param(IS_TIM_CLOCKSOURCE_ETRMODE1_INSTANCE(htim->Instance)); |
3975 | 5169 | ||
3976 | /* Check ETR input conditioning related parameters */ |
5170 | /* Check ETR input conditioning related parameters */ |
3977 | assert_param(IS_TIM_CLOCKPRESCALER(sClockSourceConfig->ClockPrescaler)); |
5171 | assert_param(IS_TIM_CLOCKPRESCALER(sClockSourceConfig->ClockPrescaler)); |
3978 | assert_param(IS_TIM_CLOCKPOLARITY(sClockSourceConfig->ClockPolarity)); |
5172 | assert_param(IS_TIM_CLOCKPOLARITY(sClockSourceConfig->ClockPolarity)); |
3979 | assert_param(IS_TIM_CLOCKFILTER(sClockSourceConfig->ClockFilter)); |
5173 | assert_param(IS_TIM_CLOCKFILTER(sClockSourceConfig->ClockFilter)); |
3980 | 5174 | ||
3981 | /* Configure the ETR Clock source */ |
5175 | /* Configure the ETR Clock source */ |
3982 | TIM_ETR_SetConfig(htim->Instance, |
5176 | TIM_ETR_SetConfig(htim->Instance, |
3983 | sClockSourceConfig->ClockPrescaler, |
5177 | sClockSourceConfig->ClockPrescaler, |
3984 | sClockSourceConfig->ClockPolarity, |
5178 | sClockSourceConfig->ClockPolarity, |
3985 | sClockSourceConfig->ClockFilter); |
5179 | sClockSourceConfig->ClockFilter); |
3986 | /* Get the TIMx SMCR register value */ |
- | |
3987 | tmpsmcr = htim->Instance->SMCR; |
- | |
3988 | /* Reset the SMS and TS Bits */ |
- | |
3989 | tmpsmcr &= ~(TIM_SMCR_SMS | TIM_SMCR_TS); |
- | |
- | 5180 | ||
3990 | /* Select the External clock mode1 and the ETRF trigger */ |
5181 | /* Select the External clock mode1 and the ETRF trigger */ |
- | 5182 | tmpsmcr = htim->Instance->SMCR; |
|
3991 | tmpsmcr |= (TIM_SLAVEMODE_EXTERNAL1 | TIM_CLOCKSOURCE_ETRMODE1); |
5183 | tmpsmcr |= (TIM_SLAVEMODE_EXTERNAL1 | TIM_CLOCKSOURCE_ETRMODE1); |
3992 | /* Write to TIMx SMCR */ |
5184 | /* Write to TIMx SMCR */ |
3993 | htim->Instance->SMCR = tmpsmcr; |
5185 | htim->Instance->SMCR = tmpsmcr; |
- | 5186 | break; |
|
3994 | } |
5187 | } |
3995 | break; |
- | |
3996 | 5188 | ||
3997 | case TIM_CLOCKSOURCE_ETRMODE2: |
5189 | case TIM_CLOCKSOURCE_ETRMODE2: |
3998 | { |
5190 | { |
3999 | /* Check whether or not the timer instance supports external trigger input mode 2 (ETRF)*/ |
5191 | /* Check whether or not the timer instance supports external trigger input mode 2 (ETRF)*/ |
4000 | assert_param(IS_TIM_CLOCKSOURCE_ETRMODE2_INSTANCE(htim->Instance)); |
5192 | assert_param(IS_TIM_CLOCKSOURCE_ETRMODE2_INSTANCE(htim->Instance)); |
4001 | 5193 | ||
4002 | /* Check ETR input conditioning related parameters */ |
5194 | /* Check ETR input conditioning related parameters */ |
4003 | assert_param(IS_TIM_CLOCKPRESCALER(sClockSourceConfig->ClockPrescaler)); |
5195 | assert_param(IS_TIM_CLOCKPRESCALER(sClockSourceConfig->ClockPrescaler)); |
4004 | assert_param(IS_TIM_CLOCKPOLARITY(sClockSourceConfig->ClockPolarity)); |
5196 | assert_param(IS_TIM_CLOCKPOLARITY(sClockSourceConfig->ClockPolarity)); |
4005 | assert_param(IS_TIM_CLOCKFILTER(sClockSourceConfig->ClockFilter)); |
5197 | assert_param(IS_TIM_CLOCKFILTER(sClockSourceConfig->ClockFilter)); |
4006 | 5198 | ||
4007 | /* Configure the ETR Clock source */ |
5199 | /* Configure the ETR Clock source */ |
4008 | TIM_ETR_SetConfig(htim->Instance, |
5200 | TIM_ETR_SetConfig(htim->Instance, |
4009 | sClockSourceConfig->ClockPrescaler, |
5201 | sClockSourceConfig->ClockPrescaler, |
4010 | sClockSourceConfig->ClockPolarity, |
5202 | sClockSourceConfig->ClockPolarity, |
4011 | sClockSourceConfig->ClockFilter); |
5203 | sClockSourceConfig->ClockFilter); |
4012 | /* Enable the External clock mode2 */ |
5204 | /* Enable the External clock mode2 */ |
4013 | htim->Instance->SMCR |= TIM_SMCR_ECE; |
5205 | htim->Instance->SMCR |= TIM_SMCR_ECE; |
- | 5206 | break; |
|
4014 | } |
5207 | } |
4015 | break; |
- | |
4016 | 5208 | ||
4017 | case TIM_CLOCKSOURCE_TI1: |
5209 | case TIM_CLOCKSOURCE_TI1: |
4018 | { |
5210 | { |
4019 | /* Check whether or not the timer instance supports external clock mode 1 */ |
5211 | /* Check whether or not the timer instance supports external clock mode 1 */ |
4020 | assert_param(IS_TIM_CLOCKSOURCE_TIX_INSTANCE(htim->Instance)); |
5212 | assert_param(IS_TIM_CLOCKSOURCE_TIX_INSTANCE(htim->Instance)); |
4021 | 5213 | ||
4022 | /* Check TI1 input conditioning related parameters */ |
5214 | /* Check TI1 input conditioning related parameters */ |
4023 | assert_param(IS_TIM_CLOCKPOLARITY(sClockSourceConfig->ClockPolarity)); |
5215 | assert_param(IS_TIM_CLOCKPOLARITY(sClockSourceConfig->ClockPolarity)); |
4024 | assert_param(IS_TIM_CLOCKFILTER(sClockSourceConfig->ClockFilter)); |
5216 | assert_param(IS_TIM_CLOCKFILTER(sClockSourceConfig->ClockFilter)); |
4025 | 5217 | ||
4026 | TIM_TI1_ConfigInputStage(htim->Instance, |
5218 | TIM_TI1_ConfigInputStage(htim->Instance, |
4027 | sClockSourceConfig->ClockPolarity, |
5219 | sClockSourceConfig->ClockPolarity, |
4028 | sClockSourceConfig->ClockFilter); |
5220 | sClockSourceConfig->ClockFilter); |
4029 | TIM_ITRx_SetConfig(htim->Instance, TIM_CLOCKSOURCE_TI1); |
5221 | TIM_ITRx_SetConfig(htim->Instance, TIM_CLOCKSOURCE_TI1); |
- | 5222 | break; |
|
4030 | } |
5223 | } |
4031 | break; |
5224 | |
4032 | case TIM_CLOCKSOURCE_TI2: |
5225 | case TIM_CLOCKSOURCE_TI2: |
4033 | { |
5226 | { |
4034 | /* Check whether or not the timer instance supports external clock mode 1 (ETRF)*/ |
5227 | /* Check whether or not the timer instance supports external clock mode 1 (ETRF)*/ |
4035 | assert_param(IS_TIM_CLOCKSOURCE_TIX_INSTANCE(htim->Instance)); |
5228 | assert_param(IS_TIM_CLOCKSOURCE_TIX_INSTANCE(htim->Instance)); |
4036 | 5229 | ||
4037 | /* Check TI2 input conditioning related parameters */ |
5230 | /* Check TI2 input conditioning related parameters */ |
4038 | assert_param(IS_TIM_CLOCKPOLARITY(sClockSourceConfig->ClockPolarity)); |
5231 | assert_param(IS_TIM_CLOCKPOLARITY(sClockSourceConfig->ClockPolarity)); |
4039 | assert_param(IS_TIM_CLOCKFILTER(sClockSourceConfig->ClockFilter)); |
5232 | assert_param(IS_TIM_CLOCKFILTER(sClockSourceConfig->ClockFilter)); |
4040 | 5233 | ||
4041 | TIM_TI2_ConfigInputStage(htim->Instance, |
5234 | TIM_TI2_ConfigInputStage(htim->Instance, |
4042 | sClockSourceConfig->ClockPolarity, |
5235 | sClockSourceConfig->ClockPolarity, |
4043 | sClockSourceConfig->ClockFilter); |
5236 | sClockSourceConfig->ClockFilter); |
4044 | TIM_ITRx_SetConfig(htim->Instance, TIM_CLOCKSOURCE_TI2); |
5237 | TIM_ITRx_SetConfig(htim->Instance, TIM_CLOCKSOURCE_TI2); |
- | 5238 | break; |
|
4045 | } |
5239 | } |
4046 | break; |
5240 | |
4047 | case TIM_CLOCKSOURCE_TI1ED: |
5241 | case TIM_CLOCKSOURCE_TI1ED: |
4048 | { |
5242 | { |
4049 | /* Check whether or not the timer instance supports external clock mode 1 */ |
5243 | /* Check whether or not the timer instance supports external clock mode 1 */ |
4050 | assert_param(IS_TIM_CLOCKSOURCE_TIX_INSTANCE(htim->Instance)); |
5244 | assert_param(IS_TIM_CLOCKSOURCE_TIX_INSTANCE(htim->Instance)); |
4051 | 5245 | ||
4052 | /* Check TI1 input conditioning related parameters */ |
5246 | /* Check TI1 input conditioning related parameters */ |
Line 4055... | Line 5249... | ||
4055 | 5249 | ||
4056 | TIM_TI1_ConfigInputStage(htim->Instance, |
5250 | TIM_TI1_ConfigInputStage(htim->Instance, |
4057 | sClockSourceConfig->ClockPolarity, |
5251 | sClockSourceConfig->ClockPolarity, |
4058 | sClockSourceConfig->ClockFilter); |
5252 | sClockSourceConfig->ClockFilter); |
4059 | TIM_ITRx_SetConfig(htim->Instance, TIM_CLOCKSOURCE_TI1ED); |
5253 | TIM_ITRx_SetConfig(htim->Instance, TIM_CLOCKSOURCE_TI1ED); |
- | 5254 | break; |
|
4060 | } |
5255 | } |
4061 | break; |
- | |
4062 | case TIM_CLOCKSOURCE_ITR0: |
- | |
4063 | { |
- | |
4064 | /* Check whether or not the timer instance supports external clock mode 1 */ |
- | |
4065 | assert_param(IS_TIM_CLOCKSOURCE_ITRX_INSTANCE(htim->Instance)); |
- | |
4066 | - | ||
4067 | TIM_ITRx_SetConfig(htim->Instance, TIM_CLOCKSOURCE_ITR0); |
- | |
4068 | } |
- | |
4069 | break; |
- | |
4070 | case TIM_CLOCKSOURCE_ITR1: |
- | |
4071 | { |
- | |
4072 | /* Check whether or not the timer instance supports external clock mode 1 */ |
- | |
4073 | assert_param(IS_TIM_CLOCKSOURCE_ITRX_INSTANCE(htim->Instance)); |
- | |
4074 | - | ||
4075 | TIM_ITRx_SetConfig(htim->Instance, TIM_CLOCKSOURCE_ITR1); |
- | |
4076 | } |
- | |
4077 | break; |
- | |
4078 | case TIM_CLOCKSOURCE_ITR2: |
- | |
4079 | { |
- | |
4080 | /* Check whether or not the timer instance supports external clock mode 1 */ |
- | |
4081 | assert_param(IS_TIM_CLOCKSOURCE_ITRX_INSTANCE(htim->Instance)); |
- | |
4082 | 5256 | ||
4083 | TIM_ITRx_SetConfig(htim->Instance, TIM_CLOCKSOURCE_ITR2); |
5257 | case TIM_CLOCKSOURCE_ITR0: |
4084 | } |
5258 | case TIM_CLOCKSOURCE_ITR1: |
4085 | break; |
5259 | case TIM_CLOCKSOURCE_ITR2: |
4086 | case TIM_CLOCKSOURCE_ITR3: |
5260 | case TIM_CLOCKSOURCE_ITR3: |
4087 | { |
5261 | { |
4088 | /* Check whether or not the timer instance supports external clock mode 1 */ |
5262 | /* Check whether or not the timer instance supports internal trigger input */ |
4089 | assert_param(IS_TIM_CLOCKSOURCE_ITRX_INSTANCE(htim->Instance)); |
5263 | assert_param(IS_TIM_CLOCKSOURCE_ITRX_INSTANCE(htim->Instance)); |
4090 | 5264 | ||
4091 | TIM_ITRx_SetConfig(htim->Instance, TIM_CLOCKSOURCE_ITR3); |
5265 | TIM_ITRx_SetConfig(htim->Instance, sClockSourceConfig->ClockSource); |
4092 | } |
5266 | break; |
4093 | break; |
5267 | } |
4094 | 5268 | ||
4095 | default: |
5269 | default: |
4096 | break; |
5270 | break; |
4097 | } |
5271 | } |
4098 | htim->State = HAL_TIM_STATE_READY; |
5272 | htim->State = HAL_TIM_STATE_READY; |
4099 | 5273 | ||
4100 | __HAL_UNLOCK(htim); |
5274 | __HAL_UNLOCK(htim); |
4101 | 5275 | ||
Line 4103... | Line 5277... | ||
4103 | } |
5277 | } |
4104 | 5278 | ||
4105 | /** |
5279 | /** |
4106 | * @brief Selects the signal connected to the TI1 input: direct from CH1_input |
5280 | * @brief Selects the signal connected to the TI1 input: direct from CH1_input |
4107 | * or a XOR combination between CH1_input, CH2_input & CH3_input |
5281 | * or a XOR combination between CH1_input, CH2_input & CH3_input |
4108 | * @param htim : TIM handle. |
5282 | * @param htim TIM handle. |
4109 | * @param TI1_Selection : Indicate whether or not channel 1 is connected to the |
5283 | * @param TI1_Selection Indicate whether or not channel 1 is connected to the |
4110 | * output of a XOR gate. |
5284 | * output of a XOR gate. |
4111 | * This parameter can be one of the following values: |
5285 | * This parameter can be one of the following values: |
4112 | * @arg TIM_TI1SELECTION_CH1: The TIMx_CH1 pin is connected to TI1 input |
5286 | * @arg TIM_TI1SELECTION_CH1: The TIMx_CH1 pin is connected to TI1 input |
4113 | * @arg TIM_TI1SELECTION_XORCOMBINATION: The TIMx_CH1, CH2 and CH3 |
5287 | * @arg TIM_TI1SELECTION_XORCOMBINATION: The TIMx_CH1, CH2 and CH3 |
4114 | * pins are connected to the TI1 input (XOR combination) |
5288 | * pins are connected to the TI1 input (XOR combination) |
4115 | * @retval HAL status |
5289 | * @retval HAL status |
4116 | */ |
5290 | */ |
4117 | HAL_StatusTypeDef HAL_TIM_ConfigTI1Input(TIM_HandleTypeDef *htim, uint32_t TI1_Selection) |
5291 | HAL_StatusTypeDef HAL_TIM_ConfigTI1Input(TIM_HandleTypeDef *htim, uint32_t TI1_Selection) |
4118 | { |
5292 | { |
4119 | uint32_t tmpcr2 = 0U; |
5293 | uint32_t tmpcr2; |
4120 | 5294 | ||
4121 | /* Check the parameters */ |
5295 | /* Check the parameters */ |
4122 | assert_param(IS_TIM_XOR_INSTANCE(htim->Instance)); |
5296 | assert_param(IS_TIM_XOR_INSTANCE(htim->Instance)); |
4123 | assert_param(IS_TIM_TI1SELECTION(TI1_Selection)); |
5297 | assert_param(IS_TIM_TI1SELECTION(TI1_Selection)); |
4124 | 5298 | ||
Line 4126... | Line 5300... | ||
4126 | tmpcr2 = htim->Instance->CR2; |
5300 | tmpcr2 = htim->Instance->CR2; |
4127 | 5301 | ||
4128 | /* Reset the TI1 selection */ |
5302 | /* Reset the TI1 selection */ |
4129 | tmpcr2 &= ~TIM_CR2_TI1S; |
5303 | tmpcr2 &= ~TIM_CR2_TI1S; |
4130 | 5304 | ||
4131 | /* Set the the TI1 selection */ |
5305 | /* Set the TI1 selection */ |
4132 | tmpcr2 |= TI1_Selection; |
5306 | tmpcr2 |= TI1_Selection; |
4133 | 5307 | ||
4134 | /* Write to TIMxCR2 */ |
5308 | /* Write to TIMxCR2 */ |
4135 | htim->Instance->CR2 = tmpcr2; |
5309 | htim->Instance->CR2 = tmpcr2; |
4136 | 5310 | ||
4137 | return HAL_OK; |
5311 | return HAL_OK; |
4138 | } |
5312 | } |
4139 | 5313 | ||
4140 | /** |
5314 | /** |
4141 | * @brief Configures the TIM in Slave mode |
5315 | * @brief Configures the TIM in Slave mode |
4142 | * @param htim : TIM handle. |
5316 | * @param htim TIM handle. |
4143 | * @param sSlaveConfig : pointer to a TIM_SlaveConfigTypeDef structure that |
5317 | * @param sSlaveConfig pointer to a TIM_SlaveConfigTypeDef structure that |
4144 | * contains the selected trigger (internal trigger input, filtered |
5318 | * contains the selected trigger (internal trigger input, filtered |
4145 | * timer input or external trigger input) and the ) and the Slave |
5319 | * timer input or external trigger input) and the Slave mode |
4146 | * mode (Disable, Reset, Gated, Trigger, External clock mode 1). |
5320 | * (Disable, Reset, Gated, Trigger, External clock mode 1). |
4147 | * @retval HAL status |
5321 | * @retval HAL status |
4148 | */ |
5322 | */ |
4149 | HAL_StatusTypeDef HAL_TIM_SlaveConfigSynchronization(TIM_HandleTypeDef *htim, TIM_SlaveConfigTypeDef * sSlaveConfig) |
5323 | HAL_StatusTypeDef HAL_TIM_SlaveConfigSynchro(TIM_HandleTypeDef *htim, TIM_SlaveConfigTypeDef *sSlaveConfig) |
4150 | { |
5324 | { |
4151 | /* Check the parameters */ |
5325 | /* Check the parameters */ |
4152 | assert_param(IS_TIM_SLAVE_INSTANCE(htim->Instance)); |
5326 | assert_param(IS_TIM_SLAVE_INSTANCE(htim->Instance)); |
4153 | assert_param(IS_TIM_SLAVE_MODE(sSlaveConfig->SlaveMode)); |
5327 | assert_param(IS_TIM_SLAVE_MODE(sSlaveConfig->SlaveMode)); |
4154 | assert_param(IS_TIM_TRIGGER_SELECTION(sSlaveConfig->InputTrigger)); |
5328 | assert_param(IS_TIM_TRIGGER_SELECTION(sSlaveConfig->InputTrigger)); |
4155 | 5329 | ||
4156 | __HAL_LOCK(htim); |
5330 | __HAL_LOCK(htim); |
4157 | 5331 | ||
4158 | htim->State = HAL_TIM_STATE_BUSY; |
5332 | htim->State = HAL_TIM_STATE_BUSY; |
4159 | 5333 | ||
4160 | TIM_SlaveTimer_SetConfig(htim, sSlaveConfig); |
5334 | if (TIM_SlaveTimer_SetConfig(htim, sSlaveConfig) != HAL_OK) |
- | 5335 | { |
|
- | 5336 | htim->State = HAL_TIM_STATE_READY; |
|
- | 5337 | __HAL_UNLOCK(htim); |
|
- | 5338 | return HAL_ERROR; |
|
- | 5339 | } |
|
4161 | 5340 | ||
4162 | /* Disable Trigger Interrupt */ |
5341 | /* Disable Trigger Interrupt */ |
4163 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_TRIGGER); |
5342 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_TRIGGER); |
4164 | 5343 | ||
4165 | /* Disable Trigger DMA request */ |
5344 | /* Disable Trigger DMA request */ |
Line 4168... | Line 5347... | ||
4168 | htim->State = HAL_TIM_STATE_READY; |
5347 | htim->State = HAL_TIM_STATE_READY; |
4169 | 5348 | ||
4170 | __HAL_UNLOCK(htim); |
5349 | __HAL_UNLOCK(htim); |
4171 | 5350 | ||
4172 | return HAL_OK; |
5351 | return HAL_OK; |
4173 | } |
5352 | } |
4174 | 5353 | ||
4175 | /** |
5354 | /** |
4176 | * @brief Configures the TIM in Slave mode in interrupt mode |
5355 | * @brief Configures the TIM in Slave mode in interrupt mode |
4177 | * @param htim: TIM handle. |
5356 | * @param htim TIM handle. |
4178 | * @param sSlaveConfig: pointer to a TIM_SlaveConfigTypeDef structure that |
5357 | * @param sSlaveConfig pointer to a TIM_SlaveConfigTypeDef structure that |
4179 | * contains the selected trigger (internal trigger input, filtered |
5358 | * contains the selected trigger (internal trigger input, filtered |
4180 | * timer input or external trigger input) and the ) and the Slave |
5359 | * timer input or external trigger input) and the Slave mode |
4181 | * mode (Disable, Reset, Gated, Trigger, External clock mode 1). |
5360 | * (Disable, Reset, Gated, Trigger, External clock mode 1). |
4182 | * @retval HAL status |
5361 | * @retval HAL status |
4183 | */ |
5362 | */ |
4184 | HAL_StatusTypeDef HAL_TIM_SlaveConfigSynchronization_IT(TIM_HandleTypeDef *htim, |
5363 | HAL_StatusTypeDef HAL_TIM_SlaveConfigSynchro_IT(TIM_HandleTypeDef *htim, |
4185 | TIM_SlaveConfigTypeDef * sSlaveConfig) |
5364 | TIM_SlaveConfigTypeDef *sSlaveConfig) |
4186 | { |
5365 | { |
4187 | /* Check the parameters */ |
5366 | /* Check the parameters */ |
4188 | assert_param(IS_TIM_SLAVE_INSTANCE(htim->Instance)); |
5367 | assert_param(IS_TIM_SLAVE_INSTANCE(htim->Instance)); |
4189 | assert_param(IS_TIM_SLAVE_MODE(sSlaveConfig->SlaveMode)); |
5368 | assert_param(IS_TIM_SLAVE_MODE(sSlaveConfig->SlaveMode)); |
4190 | assert_param(IS_TIM_TRIGGER_SELECTION(sSlaveConfig->InputTrigger)); |
5369 | assert_param(IS_TIM_TRIGGER_SELECTION(sSlaveConfig->InputTrigger)); |
4191 | 5370 | ||
4192 | __HAL_LOCK(htim); |
5371 | __HAL_LOCK(htim); |
4193 | 5372 | ||
4194 | htim->State = HAL_TIM_STATE_BUSY; |
5373 | htim->State = HAL_TIM_STATE_BUSY; |
4195 | 5374 | ||
4196 | TIM_SlaveTimer_SetConfig(htim, sSlaveConfig); |
5375 | if (TIM_SlaveTimer_SetConfig(htim, sSlaveConfig) != HAL_OK) |
- | 5376 | { |
|
- | 5377 | htim->State = HAL_TIM_STATE_READY; |
|
- | 5378 | __HAL_UNLOCK(htim); |
|
- | 5379 | return HAL_ERROR; |
|
- | 5380 | } |
|
4197 | 5381 | ||
4198 | /* Enable Trigger Interrupt */ |
5382 | /* Enable Trigger Interrupt */ |
4199 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_TRIGGER); |
5383 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_TRIGGER); |
4200 | 5384 | ||
4201 | /* Disable Trigger DMA request */ |
5385 | /* Disable Trigger DMA request */ |
Line 4208... | Line 5392... | ||
4208 | return HAL_OK; |
5392 | return HAL_OK; |
4209 | } |
5393 | } |
4210 | 5394 | ||
4211 | /** |
5395 | /** |
4212 | * @brief Read the captured value from Capture Compare unit |
5396 | * @brief Read the captured value from Capture Compare unit |
4213 | * @param htim : TIM handle. |
5397 | * @param htim TIM handle. |
4214 | * @param Channel : TIM Channels to be enabled |
5398 | * @param Channel TIM Channels to be enabled |
4215 | * This parameter can be one of the following values: |
5399 | * This parameter can be one of the following values: |
4216 | * @arg TIM_CHANNEL_1 : TIM Channel 1 selected |
5400 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
4217 | * @arg TIM_CHANNEL_2 : TIM Channel 2 selected |
5401 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
4218 | * @arg TIM_CHANNEL_3 : TIM Channel 3 selected |
5402 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
4219 | * @arg TIM_CHANNEL_4 : TIM Channel 4 selected |
5403 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
4220 | * @retval Captured value |
5404 | * @retval Captured value |
4221 | */ |
5405 | */ |
4222 | uint32_t HAL_TIM_ReadCapturedValue(TIM_HandleTypeDef *htim, uint32_t Channel) |
5406 | uint32_t HAL_TIM_ReadCapturedValue(TIM_HandleTypeDef *htim, uint32_t Channel) |
4223 | { |
5407 | { |
4224 | uint32_t tmpreg = 0U; |
5408 | uint32_t tmpreg = 0U; |
4225 | 5409 | ||
4226 | __HAL_LOCK(htim); |
- | |
4227 | - | ||
4228 | switch (Channel) |
5410 | switch (Channel) |
4229 | { |
5411 | { |
4230 | case TIM_CHANNEL_1: |
5412 | case TIM_CHANNEL_1: |
4231 | { |
5413 | { |
4232 | /* Check the parameters */ |
5414 | /* Check the parameters */ |
4233 | assert_param(IS_TIM_CC1_INSTANCE(htim->Instance)); |
5415 | assert_param(IS_TIM_CC1_INSTANCE(htim->Instance)); |
4234 | 5416 | ||
4235 | /* Return the capture 1 value */ |
5417 | /* Return the capture 1 value */ |
4236 | tmpreg = htim->Instance->CCR1; |
5418 | tmpreg = htim->Instance->CCR1; |
4237 | 5419 | ||
4238 | break; |
5420 | break; |
4239 | } |
5421 | } |
4240 | case TIM_CHANNEL_2: |
5422 | case TIM_CHANNEL_2: |
4241 | { |
5423 | { |
4242 | /* Check the parameters */ |
5424 | /* Check the parameters */ |
4243 | assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); |
5425 | assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); |
4244 | 5426 | ||
4245 | /* Return the capture 2 value */ |
5427 | /* Return the capture 2 value */ |
4246 | tmpreg = htim->Instance->CCR2; |
5428 | tmpreg = htim->Instance->CCR2; |
4247 | 5429 | ||
4248 | break; |
5430 | break; |
4249 | } |
5431 | } |
4250 | 5432 | ||
4251 | case TIM_CHANNEL_3: |
5433 | case TIM_CHANNEL_3: |
4252 | { |
5434 | { |
4253 | /* Check the parameters */ |
5435 | /* Check the parameters */ |
4254 | assert_param(IS_TIM_CC3_INSTANCE(htim->Instance)); |
5436 | assert_param(IS_TIM_CC3_INSTANCE(htim->Instance)); |
4255 | 5437 | ||
4256 | /* Return the capture 3 value */ |
5438 | /* Return the capture 3 value */ |
4257 | tmpreg = htim->Instance->CCR3; |
5439 | tmpreg = htim->Instance->CCR3; |
4258 | 5440 | ||
4259 | break; |
5441 | break; |
4260 | } |
5442 | } |
4261 | 5443 | ||
4262 | case TIM_CHANNEL_4: |
5444 | case TIM_CHANNEL_4: |
4263 | { |
5445 | { |
4264 | /* Check the parameters */ |
5446 | /* Check the parameters */ |
4265 | assert_param(IS_TIM_CC4_INSTANCE(htim->Instance)); |
5447 | assert_param(IS_TIM_CC4_INSTANCE(htim->Instance)); |
4266 | 5448 | ||
4267 | /* Return the capture 4 value */ |
5449 | /* Return the capture 4 value */ |
4268 | tmpreg = htim->Instance->CCR4; |
5450 | tmpreg = htim->Instance->CCR4; |
4269 | 5451 | ||
4270 | break; |
5452 | break; |
4271 | } |
5453 | } |
4272 | 5454 | ||
4273 | default: |
5455 | default: |
4274 | break; |
5456 | break; |
4275 | } |
5457 | } |
4276 | 5458 | ||
4277 | __HAL_UNLOCK(htim); |
- | |
4278 | return tmpreg; |
5459 | return tmpreg; |
4279 | } |
5460 | } |
4280 | 5461 | ||
4281 | /** |
5462 | /** |
4282 | * @} |
5463 | * @} |
4283 | */ |
5464 | */ |
4284 | 5465 | ||
4285 | /** @defgroup TIM_Exported_Functions_Group9 TIM Callbacks functions |
5466 | /** @defgroup TIM_Exported_Functions_Group9 TIM Callbacks functions |
4286 | * @brief TIM Callbacks functions |
5467 | * @brief TIM Callbacks functions |
4287 | * |
5468 | * |
4288 | @verbatim |
5469 | @verbatim |
4289 | ============================================================================== |
5470 | ============================================================================== |
4290 | ##### TIM Callbacks functions ##### |
5471 | ##### TIM Callbacks functions ##### |
4291 | ============================================================================== |
5472 | ============================================================================== |
4292 | [..] |
5473 | [..] |
4293 | This section provides TIM callback functions: |
5474 | This section provides TIM callback functions: |
4294 | (+) Timer Period elapsed callback |
5475 | (+) TIM Period elapsed callback |
4295 | (+) Timer Output Compare callback |
5476 | (+) TIM Output Compare callback |
4296 | (+) Timer Input capture callback |
5477 | (+) TIM Input capture callback |
4297 | (+) Timer Trigger callback |
5478 | (+) TIM Trigger callback |
4298 | (+) Timer Error callback |
5479 | (+) TIM Error callback |
4299 | 5480 | ||
4300 | @endverbatim |
5481 | @endverbatim |
4301 | * @{ |
5482 | * @{ |
4302 | */ |
5483 | */ |
4303 | 5484 | ||
4304 | /** |
5485 | /** |
4305 | * @brief Period elapsed callback in non blocking mode |
5486 | * @brief Period elapsed callback in non-blocking mode |
4306 | * @param htim : TIM handle |
5487 | * @param htim TIM handle |
4307 | * @retval None |
5488 | * @retval None |
4308 | */ |
5489 | */ |
4309 | __weak void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) |
5490 | __weak void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) |
4310 | { |
5491 | { |
4311 | /* Prevent unused argument(s) compilation warning */ |
5492 | /* Prevent unused argument(s) compilation warning */ |
4312 | UNUSED(htim); |
5493 | UNUSED(htim); |
- | 5494 | ||
4313 | /* NOTE : This function Should not be modified, when the callback is needed, |
5495 | /* NOTE : This function should not be modified, when the callback is needed, |
4314 | the __HAL_TIM_PeriodElapsedCallback could be implemented in the user file |
5496 | the HAL_TIM_PeriodElapsedCallback could be implemented in the user file |
4315 | */ |
5497 | */ |
- | 5498 | } |
|
- | 5499 | ||
- | 5500 | /** |
|
- | 5501 | * @brief Period elapsed half complete callback in non-blocking mode |
|
- | 5502 | * @param htim TIM handle |
|
- | 5503 | * @retval None |
|
- | 5504 | */ |
|
- | 5505 | __weak void HAL_TIM_PeriodElapsedHalfCpltCallback(TIM_HandleTypeDef *htim) |
|
- | 5506 | { |
|
- | 5507 | /* Prevent unused argument(s) compilation warning */ |
|
- | 5508 | UNUSED(htim); |
|
4316 | 5509 | ||
- | 5510 | /* NOTE : This function should not be modified, when the callback is needed, |
|
- | 5511 | the HAL_TIM_PeriodElapsedHalfCpltCallback could be implemented in the user file |
|
- | 5512 | */ |
|
4317 | } |
5513 | } |
- | 5514 | ||
4318 | /** |
5515 | /** |
4319 | * @brief Output Compare callback in non blocking mode |
5516 | * @brief Output Compare callback in non-blocking mode |
4320 | * @param htim : TIM OC handle |
5517 | * @param htim TIM OC handle |
4321 | * @retval None |
5518 | * @retval None |
4322 | */ |
5519 | */ |
4323 | __weak void HAL_TIM_OC_DelayElapsedCallback(TIM_HandleTypeDef *htim) |
5520 | __weak void HAL_TIM_OC_DelayElapsedCallback(TIM_HandleTypeDef *htim) |
4324 | { |
5521 | { |
4325 | /* Prevent unused argument(s) compilation warning */ |
5522 | /* Prevent unused argument(s) compilation warning */ |
4326 | UNUSED(htim); |
5523 | UNUSED(htim); |
- | 5524 | ||
4327 | /* NOTE : This function Should not be modified, when the callback is needed, |
5525 | /* NOTE : This function should not be modified, when the callback is needed, |
4328 | the __HAL_TIM_OC_DelayElapsedCallback could be implemented in the user file |
5526 | the HAL_TIM_OC_DelayElapsedCallback could be implemented in the user file |
4329 | */ |
5527 | */ |
4330 | } |
5528 | } |
- | 5529 | ||
4331 | /** |
5530 | /** |
4332 | * @brief Input Capture callback in non blocking mode |
5531 | * @brief Input Capture callback in non-blocking mode |
4333 | * @param htim : TIM IC handle |
5532 | * @param htim TIM IC handle |
4334 | * @retval None |
5533 | * @retval None |
4335 | */ |
5534 | */ |
4336 | __weak void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim) |
5535 | __weak void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim) |
4337 | { |
5536 | { |
4338 | /* Prevent unused argument(s) compilation warning */ |
5537 | /* Prevent unused argument(s) compilation warning */ |
4339 | UNUSED(htim); |
5538 | UNUSED(htim); |
- | 5539 | ||
4340 | /* NOTE : This function Should not be modified, when the callback is needed, |
5540 | /* NOTE : This function should not be modified, when the callback is needed, |
4341 | the __HAL_TIM_IC_CaptureCallback could be implemented in the user file |
5541 | the HAL_TIM_IC_CaptureCallback could be implemented in the user file |
4342 | */ |
5542 | */ |
4343 | } |
5543 | } |
4344 | 5544 | ||
4345 | /** |
5545 | /** |
- | 5546 | * @brief Input Capture half complete callback in non-blocking mode |
|
- | 5547 | * @param htim TIM IC handle |
|
- | 5548 | * @retval None |
|
- | 5549 | */ |
|
- | 5550 | __weak void HAL_TIM_IC_CaptureHalfCpltCallback(TIM_HandleTypeDef *htim) |
|
- | 5551 | { |
|
- | 5552 | /* Prevent unused argument(s) compilation warning */ |
|
- | 5553 | UNUSED(htim); |
|
- | 5554 | ||
- | 5555 | /* NOTE : This function should not be modified, when the callback is needed, |
|
- | 5556 | the HAL_TIM_IC_CaptureHalfCpltCallback could be implemented in the user file |
|
- | 5557 | */ |
|
- | 5558 | } |
|
- | 5559 | ||
- | 5560 | /** |
|
4346 | * @brief PWM Pulse finished callback in non blocking mode |
5561 | * @brief PWM Pulse finished callback in non-blocking mode |
4347 | * @param htim : TIM handle |
5562 | * @param htim TIM handle |
4348 | * @retval None |
5563 | * @retval None |
4349 | */ |
5564 | */ |
4350 | __weak void HAL_TIM_PWM_PulseFinishedCallback(TIM_HandleTypeDef *htim) |
5565 | __weak void HAL_TIM_PWM_PulseFinishedCallback(TIM_HandleTypeDef *htim) |
4351 | { |
5566 | { |
4352 | /* Prevent unused argument(s) compilation warning */ |
5567 | /* Prevent unused argument(s) compilation warning */ |
4353 | UNUSED(htim); |
5568 | UNUSED(htim); |
- | 5569 | ||
4354 | /* NOTE : This function Should not be modified, when the callback is needed, |
5570 | /* NOTE : This function should not be modified, when the callback is needed, |
4355 | the __HAL_TIM_PWM_PulseFinishedCallback could be implemented in the user file |
5571 | the HAL_TIM_PWM_PulseFinishedCallback could be implemented in the user file |
- | 5572 | */ |
|
- | 5573 | } |
|
- | 5574 | ||
- | 5575 | /** |
|
- | 5576 | * @brief PWM Pulse finished half complete callback in non-blocking mode |
|
- | 5577 | * @param htim TIM handle |
|
- | 5578 | * @retval None |
|
- | 5579 | */ |
|
- | 5580 | __weak void HAL_TIM_PWM_PulseFinishedHalfCpltCallback(TIM_HandleTypeDef *htim) |
|
- | 5581 | { |
|
- | 5582 | /* Prevent unused argument(s) compilation warning */ |
|
- | 5583 | UNUSED(htim); |
|
- | 5584 | ||
- | 5585 | /* NOTE : This function should not be modified, when the callback is needed, |
|
- | 5586 | the HAL_TIM_PWM_PulseFinishedHalfCpltCallback could be implemented in the user file |
|
4356 | */ |
5587 | */ |
4357 | } |
5588 | } |
4358 | 5589 | ||
4359 | /** |
5590 | /** |
4360 | * @brief Hall Trigger detection callback in non blocking mode |
5591 | * @brief Hall Trigger detection callback in non-blocking mode |
4361 | * @param htim : TIM handle |
5592 | * @param htim TIM handle |
4362 | * @retval None |
5593 | * @retval None |
4363 | */ |
5594 | */ |
4364 | __weak void HAL_TIM_TriggerCallback(TIM_HandleTypeDef *htim) |
5595 | __weak void HAL_TIM_TriggerCallback(TIM_HandleTypeDef *htim) |
4365 | { |
5596 | { |
4366 | /* Prevent unused argument(s) compilation warning */ |
5597 | /* Prevent unused argument(s) compilation warning */ |
4367 | UNUSED(htim); |
5598 | UNUSED(htim); |
- | 5599 | ||
4368 | /* NOTE : This function Should not be modified, when the callback is needed, |
5600 | /* NOTE : This function should not be modified, when the callback is needed, |
4369 | the HAL_TIM_TriggerCallback could be implemented in the user file |
5601 | the HAL_TIM_TriggerCallback could be implemented in the user file |
4370 | */ |
5602 | */ |
4371 | } |
5603 | } |
4372 | 5604 | ||
4373 | /** |
5605 | /** |
- | 5606 | * @brief Hall Trigger detection half complete callback in non-blocking mode |
|
- | 5607 | * @param htim TIM handle |
|
- | 5608 | * @retval None |
|
- | 5609 | */ |
|
- | 5610 | __weak void HAL_TIM_TriggerHalfCpltCallback(TIM_HandleTypeDef *htim) |
|
- | 5611 | { |
|
- | 5612 | /* Prevent unused argument(s) compilation warning */ |
|
- | 5613 | UNUSED(htim); |
|
- | 5614 | ||
- | 5615 | /* NOTE : This function should not be modified, when the callback is needed, |
|
- | 5616 | the HAL_TIM_TriggerHalfCpltCallback could be implemented in the user file |
|
- | 5617 | */ |
|
- | 5618 | } |
|
- | 5619 | ||
- | 5620 | /** |
|
4374 | * @brief Timer error callback in non blocking mode |
5621 | * @brief Timer error callback in non-blocking mode |
4375 | * @param htim : TIM handle |
5622 | * @param htim TIM handle |
4376 | * @retval None |
5623 | * @retval None |
4377 | */ |
5624 | */ |
4378 | __weak void HAL_TIM_ErrorCallback(TIM_HandleTypeDef *htim) |
5625 | __weak void HAL_TIM_ErrorCallback(TIM_HandleTypeDef *htim) |
4379 | { |
5626 | { |
4380 | /* Prevent unused argument(s) compilation warning */ |
5627 | /* Prevent unused argument(s) compilation warning */ |
4381 | UNUSED(htim); |
5628 | UNUSED(htim); |
- | 5629 | ||
4382 | /* NOTE : This function Should not be modified, when the callback is needed, |
5630 | /* NOTE : This function should not be modified, when the callback is needed, |
4383 | the HAL_TIM_ErrorCallback could be implemented in the user file |
5631 | the HAL_TIM_ErrorCallback could be implemented in the user file |
4384 | */ |
5632 | */ |
4385 | } |
5633 | } |
4386 | 5634 | ||
- | 5635 | #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) |
|
- | 5636 | /** |
|
- | 5637 | * @brief Register a User TIM callback to be used instead of the weak predefined callback |
|
- | 5638 | * @param htim tim handle |
|
- | 5639 | * @param CallbackID ID of the callback to be registered |
|
- | 5640 | * This parameter can be one of the following values: |
|
- | 5641 | * @arg @ref HAL_TIM_BASE_MSPINIT_CB_ID Base MspInit Callback ID |
|
- | 5642 | * @arg @ref HAL_TIM_BASE_MSPDEINIT_CB_ID Base MspDeInit Callback ID |
|
- | 5643 | * @arg @ref HAL_TIM_IC_MSPINIT_CB_ID IC MspInit Callback ID |
|
- | 5644 | * @arg @ref HAL_TIM_IC_MSPDEINIT_CB_ID IC MspDeInit Callback ID |
|
- | 5645 | * @arg @ref HAL_TIM_OC_MSPINIT_CB_ID OC MspInit Callback ID |
|
- | 5646 | * @arg @ref HAL_TIM_OC_MSPDEINIT_CB_ID OC MspDeInit Callback ID |
|
- | 5647 | * @arg @ref HAL_TIM_PWM_MSPINIT_CB_ID PWM MspInit Callback ID |
|
- | 5648 | * @arg @ref HAL_TIM_PWM_MSPDEINIT_CB_ID PWM MspDeInit Callback ID |
|
- | 5649 | * @arg @ref HAL_TIM_ONE_PULSE_MSPINIT_CB_ID One Pulse MspInit Callback ID |
|
- | 5650 | * @arg @ref HAL_TIM_ONE_PULSE_MSPDEINIT_CB_ID One Pulse MspDeInit Callback ID |
|
- | 5651 | * @arg @ref HAL_TIM_ENCODER_MSPINIT_CB_ID Encoder MspInit Callback ID |
|
- | 5652 | * @arg @ref HAL_TIM_ENCODER_MSPDEINIT_CB_ID Encoder MspDeInit Callback ID |
|
- | 5653 | * @arg @ref HAL_TIM_HALL_SENSOR_MSPINIT_CB_ID Hall Sensor MspInit Callback ID |
|
- | 5654 | * @arg @ref HAL_TIM_HALL_SENSOR_MSPDEINIT_CB_ID Hall Sensor MspDeInit Callback ID |
|
- | 5655 | * @arg @ref HAL_TIM_PERIOD_ELAPSED_CB_ID Period Elapsed Callback ID |
|
- | 5656 | * @arg @ref HAL_TIM_PERIOD_ELAPSED_HALF_CB_ID Period Elapsed half complete Callback ID |
|
- | 5657 | * @arg @ref HAL_TIM_TRIGGER_CB_ID Trigger Callback ID |
|
- | 5658 | * @arg @ref HAL_TIM_TRIGGER_HALF_CB_ID Trigger half complete Callback ID |
|
- | 5659 | * @arg @ref HAL_TIM_IC_CAPTURE_CB_ID Input Capture Callback ID |
|
- | 5660 | * @arg @ref HAL_TIM_IC_CAPTURE_HALF_CB_ID Input Capture half complete Callback ID |
|
- | 5661 | * @arg @ref HAL_TIM_OC_DELAY_ELAPSED_CB_ID Output Compare Delay Elapsed Callback ID |
|
- | 5662 | * @arg @ref HAL_TIM_PWM_PULSE_FINISHED_CB_ID PWM Pulse Finished Callback ID |
|
- | 5663 | * @arg @ref HAL_TIM_PWM_PULSE_FINISHED_HALF_CB_ID PWM Pulse Finished half complete Callback ID |
|
- | 5664 | * @arg @ref HAL_TIM_ERROR_CB_ID Error Callback ID |
|
- | 5665 | * @arg @ref HAL_TIM_COMMUTATION_CB_ID Commutation Callback ID |
|
- | 5666 | * @arg @ref HAL_TIM_COMMUTATION_HALF_CB_ID Commutation half complete Callback ID |
|
- | 5667 | * @arg @ref HAL_TIM_BREAK_CB_ID Break Callback ID |
|
- | 5668 | * @param pCallback pointer to the callback function |
|
- | 5669 | * @retval status |
|
- | 5670 | */ |
|
- | 5671 | HAL_StatusTypeDef HAL_TIM_RegisterCallback(TIM_HandleTypeDef *htim, HAL_TIM_CallbackIDTypeDef CallbackID, |
|
- | 5672 | pTIM_CallbackTypeDef pCallback) |
|
- | 5673 | { |
|
- | 5674 | HAL_StatusTypeDef status = HAL_OK; |
|
- | 5675 | ||
- | 5676 | if (pCallback == NULL) |
|
- | 5677 | { |
|
- | 5678 | return HAL_ERROR; |
|
- | 5679 | } |
|
- | 5680 | /* Process locked */ |
|
- | 5681 | __HAL_LOCK(htim); |
|
- | 5682 | ||
- | 5683 | if (htim->State == HAL_TIM_STATE_READY) |
|
- | 5684 | { |
|
- | 5685 | switch (CallbackID) |
|
- | 5686 | { |
|
- | 5687 | case HAL_TIM_BASE_MSPINIT_CB_ID : |
|
- | 5688 | htim->Base_MspInitCallback = pCallback; |
|
- | 5689 | break; |
|
- | 5690 | ||
- | 5691 | case HAL_TIM_BASE_MSPDEINIT_CB_ID : |
|
- | 5692 | htim->Base_MspDeInitCallback = pCallback; |
|
- | 5693 | break; |
|
- | 5694 | ||
- | 5695 | case HAL_TIM_IC_MSPINIT_CB_ID : |
|
- | 5696 | htim->IC_MspInitCallback = pCallback; |
|
- | 5697 | break; |
|
- | 5698 | ||
- | 5699 | case HAL_TIM_IC_MSPDEINIT_CB_ID : |
|
- | 5700 | htim->IC_MspDeInitCallback = pCallback; |
|
- | 5701 | break; |
|
- | 5702 | ||
- | 5703 | case HAL_TIM_OC_MSPINIT_CB_ID : |
|
- | 5704 | htim->OC_MspInitCallback = pCallback; |
|
- | 5705 | break; |
|
- | 5706 | ||
- | 5707 | case HAL_TIM_OC_MSPDEINIT_CB_ID : |
|
- | 5708 | htim->OC_MspDeInitCallback = pCallback; |
|
- | 5709 | break; |
|
- | 5710 | ||
- | 5711 | case HAL_TIM_PWM_MSPINIT_CB_ID : |
|
- | 5712 | htim->PWM_MspInitCallback = pCallback; |
|
- | 5713 | break; |
|
- | 5714 | ||
- | 5715 | case HAL_TIM_PWM_MSPDEINIT_CB_ID : |
|
- | 5716 | htim->PWM_MspDeInitCallback = pCallback; |
|
- | 5717 | break; |
|
- | 5718 | ||
- | 5719 | case HAL_TIM_ONE_PULSE_MSPINIT_CB_ID : |
|
- | 5720 | htim->OnePulse_MspInitCallback = pCallback; |
|
- | 5721 | break; |
|
- | 5722 | ||
- | 5723 | case HAL_TIM_ONE_PULSE_MSPDEINIT_CB_ID : |
|
- | 5724 | htim->OnePulse_MspDeInitCallback = pCallback; |
|
- | 5725 | break; |
|
- | 5726 | ||
- | 5727 | case HAL_TIM_ENCODER_MSPINIT_CB_ID : |
|
- | 5728 | htim->Encoder_MspInitCallback = pCallback; |
|
- | 5729 | break; |
|
- | 5730 | ||
- | 5731 | case HAL_TIM_ENCODER_MSPDEINIT_CB_ID : |
|
- | 5732 | htim->Encoder_MspDeInitCallback = pCallback; |
|
- | 5733 | break; |
|
- | 5734 | ||
- | 5735 | case HAL_TIM_HALL_SENSOR_MSPINIT_CB_ID : |
|
- | 5736 | htim->HallSensor_MspInitCallback = pCallback; |
|
- | 5737 | break; |
|
- | 5738 | ||
- | 5739 | case HAL_TIM_HALL_SENSOR_MSPDEINIT_CB_ID : |
|
- | 5740 | htim->HallSensor_MspDeInitCallback = pCallback; |
|
- | 5741 | break; |
|
- | 5742 | ||
- | 5743 | case HAL_TIM_PERIOD_ELAPSED_CB_ID : |
|
- | 5744 | htim->PeriodElapsedCallback = pCallback; |
|
- | 5745 | break; |
|
- | 5746 | ||
- | 5747 | case HAL_TIM_PERIOD_ELAPSED_HALF_CB_ID : |
|
- | 5748 | htim->PeriodElapsedHalfCpltCallback = pCallback; |
|
- | 5749 | break; |
|
- | 5750 | ||
- | 5751 | case HAL_TIM_TRIGGER_CB_ID : |
|
- | 5752 | htim->TriggerCallback = pCallback; |
|
- | 5753 | break; |
|
- | 5754 | ||
- | 5755 | case HAL_TIM_TRIGGER_HALF_CB_ID : |
|
- | 5756 | htim->TriggerHalfCpltCallback = pCallback; |
|
- | 5757 | break; |
|
- | 5758 | ||
- | 5759 | case HAL_TIM_IC_CAPTURE_CB_ID : |
|
- | 5760 | htim->IC_CaptureCallback = pCallback; |
|
- | 5761 | break; |
|
- | 5762 | ||
- | 5763 | case HAL_TIM_IC_CAPTURE_HALF_CB_ID : |
|
- | 5764 | htim->IC_CaptureHalfCpltCallback = pCallback; |
|
- | 5765 | break; |
|
- | 5766 | ||
- | 5767 | case HAL_TIM_OC_DELAY_ELAPSED_CB_ID : |
|
- | 5768 | htim->OC_DelayElapsedCallback = pCallback; |
|
- | 5769 | break; |
|
- | 5770 | ||
- | 5771 | case HAL_TIM_PWM_PULSE_FINISHED_CB_ID : |
|
- | 5772 | htim->PWM_PulseFinishedCallback = pCallback; |
|
- | 5773 | break; |
|
- | 5774 | ||
- | 5775 | case HAL_TIM_PWM_PULSE_FINISHED_HALF_CB_ID : |
|
- | 5776 | htim->PWM_PulseFinishedHalfCpltCallback = pCallback; |
|
- | 5777 | break; |
|
- | 5778 | ||
- | 5779 | case HAL_TIM_ERROR_CB_ID : |
|
- | 5780 | htim->ErrorCallback = pCallback; |
|
- | 5781 | break; |
|
- | 5782 | ||
- | 5783 | case HAL_TIM_COMMUTATION_CB_ID : |
|
- | 5784 | htim->CommutationCallback = pCallback; |
|
- | 5785 | break; |
|
- | 5786 | ||
- | 5787 | case HAL_TIM_COMMUTATION_HALF_CB_ID : |
|
- | 5788 | htim->CommutationHalfCpltCallback = pCallback; |
|
- | 5789 | break; |
|
- | 5790 | ||
- | 5791 | case HAL_TIM_BREAK_CB_ID : |
|
- | 5792 | htim->BreakCallback = pCallback; |
|
- | 5793 | break; |
|
- | 5794 | ||
- | 5795 | default : |
|
- | 5796 | /* Return error status */ |
|
- | 5797 | status = HAL_ERROR; |
|
- | 5798 | break; |
|
- | 5799 | } |
|
- | 5800 | } |
|
- | 5801 | else if (htim->State == HAL_TIM_STATE_RESET) |
|
- | 5802 | { |
|
- | 5803 | switch (CallbackID) |
|
- | 5804 | { |
|
- | 5805 | case HAL_TIM_BASE_MSPINIT_CB_ID : |
|
- | 5806 | htim->Base_MspInitCallback = pCallback; |
|
- | 5807 | break; |
|
- | 5808 | ||
- | 5809 | case HAL_TIM_BASE_MSPDEINIT_CB_ID : |
|
- | 5810 | htim->Base_MspDeInitCallback = pCallback; |
|
- | 5811 | break; |
|
- | 5812 | ||
- | 5813 | case HAL_TIM_IC_MSPINIT_CB_ID : |
|
- | 5814 | htim->IC_MspInitCallback = pCallback; |
|
- | 5815 | break; |
|
- | 5816 | ||
- | 5817 | case HAL_TIM_IC_MSPDEINIT_CB_ID : |
|
- | 5818 | htim->IC_MspDeInitCallback = pCallback; |
|
- | 5819 | break; |
|
- | 5820 | ||
- | 5821 | case HAL_TIM_OC_MSPINIT_CB_ID : |
|
- | 5822 | htim->OC_MspInitCallback = pCallback; |
|
- | 5823 | break; |
|
- | 5824 | ||
- | 5825 | case HAL_TIM_OC_MSPDEINIT_CB_ID : |
|
- | 5826 | htim->OC_MspDeInitCallback = pCallback; |
|
- | 5827 | break; |
|
- | 5828 | ||
- | 5829 | case HAL_TIM_PWM_MSPINIT_CB_ID : |
|
- | 5830 | htim->PWM_MspInitCallback = pCallback; |
|
- | 5831 | break; |
|
- | 5832 | ||
- | 5833 | case HAL_TIM_PWM_MSPDEINIT_CB_ID : |
|
- | 5834 | htim->PWM_MspDeInitCallback = pCallback; |
|
- | 5835 | break; |
|
- | 5836 | ||
- | 5837 | case HAL_TIM_ONE_PULSE_MSPINIT_CB_ID : |
|
- | 5838 | htim->OnePulse_MspInitCallback = pCallback; |
|
- | 5839 | break; |
|
- | 5840 | ||
- | 5841 | case HAL_TIM_ONE_PULSE_MSPDEINIT_CB_ID : |
|
- | 5842 | htim->OnePulse_MspDeInitCallback = pCallback; |
|
- | 5843 | break; |
|
- | 5844 | ||
- | 5845 | case HAL_TIM_ENCODER_MSPINIT_CB_ID : |
|
- | 5846 | htim->Encoder_MspInitCallback = pCallback; |
|
- | 5847 | break; |
|
- | 5848 | ||
- | 5849 | case HAL_TIM_ENCODER_MSPDEINIT_CB_ID : |
|
- | 5850 | htim->Encoder_MspDeInitCallback = pCallback; |
|
- | 5851 | break; |
|
- | 5852 | ||
- | 5853 | case HAL_TIM_HALL_SENSOR_MSPINIT_CB_ID : |
|
- | 5854 | htim->HallSensor_MspInitCallback = pCallback; |
|
- | 5855 | break; |
|
- | 5856 | ||
- | 5857 | case HAL_TIM_HALL_SENSOR_MSPDEINIT_CB_ID : |
|
- | 5858 | htim->HallSensor_MspDeInitCallback = pCallback; |
|
- | 5859 | break; |
|
- | 5860 | ||
- | 5861 | default : |
|
- | 5862 | /* Return error status */ |
|
- | 5863 | status = HAL_ERROR; |
|
- | 5864 | break; |
|
- | 5865 | } |
|
- | 5866 | } |
|
- | 5867 | else |
|
- | 5868 | { |
|
- | 5869 | /* Return error status */ |
|
- | 5870 | status = HAL_ERROR; |
|
- | 5871 | } |
|
- | 5872 | ||
- | 5873 | /* Release Lock */ |
|
- | 5874 | __HAL_UNLOCK(htim); |
|
- | 5875 | ||
- | 5876 | return status; |
|
- | 5877 | } |
|
- | 5878 | ||
- | 5879 | /** |
|
- | 5880 | * @brief Unregister a TIM callback |
|
- | 5881 | * TIM callback is redirected to the weak predefined callback |
|
- | 5882 | * @param htim tim handle |
|
- | 5883 | * @param CallbackID ID of the callback to be unregistered |
|
- | 5884 | * This parameter can be one of the following values: |
|
- | 5885 | * @arg @ref HAL_TIM_BASE_MSPINIT_CB_ID Base MspInit Callback ID |
|
- | 5886 | * @arg @ref HAL_TIM_BASE_MSPDEINIT_CB_ID Base MspDeInit Callback ID |
|
- | 5887 | * @arg @ref HAL_TIM_IC_MSPINIT_CB_ID IC MspInit Callback ID |
|
- | 5888 | * @arg @ref HAL_TIM_IC_MSPDEINIT_CB_ID IC MspDeInit Callback ID |
|
- | 5889 | * @arg @ref HAL_TIM_OC_MSPINIT_CB_ID OC MspInit Callback ID |
|
- | 5890 | * @arg @ref HAL_TIM_OC_MSPDEINIT_CB_ID OC MspDeInit Callback ID |
|
- | 5891 | * @arg @ref HAL_TIM_PWM_MSPINIT_CB_ID PWM MspInit Callback ID |
|
- | 5892 | * @arg @ref HAL_TIM_PWM_MSPDEINIT_CB_ID PWM MspDeInit Callback ID |
|
- | 5893 | * @arg @ref HAL_TIM_ONE_PULSE_MSPINIT_CB_ID One Pulse MspInit Callback ID |
|
- | 5894 | * @arg @ref HAL_TIM_ONE_PULSE_MSPDEINIT_CB_ID One Pulse MspDeInit Callback ID |
|
- | 5895 | * @arg @ref HAL_TIM_ENCODER_MSPINIT_CB_ID Encoder MspInit Callback ID |
|
- | 5896 | * @arg @ref HAL_TIM_ENCODER_MSPDEINIT_CB_ID Encoder MspDeInit Callback ID |
|
- | 5897 | * @arg @ref HAL_TIM_HALL_SENSOR_MSPINIT_CB_ID Hall Sensor MspInit Callback ID |
|
- | 5898 | * @arg @ref HAL_TIM_HALL_SENSOR_MSPDEINIT_CB_ID Hall Sensor MspDeInit Callback ID |
|
- | 5899 | * @arg @ref HAL_TIM_PERIOD_ELAPSED_CB_ID Period Elapsed Callback ID |
|
- | 5900 | * @arg @ref HAL_TIM_PERIOD_ELAPSED_HALF_CB_ID Period Elapsed half complete Callback ID |
|
- | 5901 | * @arg @ref HAL_TIM_TRIGGER_CB_ID Trigger Callback ID |
|
- | 5902 | * @arg @ref HAL_TIM_TRIGGER_HALF_CB_ID Trigger half complete Callback ID |
|
- | 5903 | * @arg @ref HAL_TIM_IC_CAPTURE_CB_ID Input Capture Callback ID |
|
- | 5904 | * @arg @ref HAL_TIM_IC_CAPTURE_HALF_CB_ID Input Capture half complete Callback ID |
|
- | 5905 | * @arg @ref HAL_TIM_OC_DELAY_ELAPSED_CB_ID Output Compare Delay Elapsed Callback ID |
|
- | 5906 | * @arg @ref HAL_TIM_PWM_PULSE_FINISHED_CB_ID PWM Pulse Finished Callback ID |
|
- | 5907 | * @arg @ref HAL_TIM_PWM_PULSE_FINISHED_HALF_CB_ID PWM Pulse Finished half complete Callback ID |
|
- | 5908 | * @arg @ref HAL_TIM_ERROR_CB_ID Error Callback ID |
|
- | 5909 | * @arg @ref HAL_TIM_COMMUTATION_CB_ID Commutation Callback ID |
|
- | 5910 | * @arg @ref HAL_TIM_COMMUTATION_HALF_CB_ID Commutation half complete Callback ID |
|
- | 5911 | * @arg @ref HAL_TIM_BREAK_CB_ID Break Callback ID |
|
- | 5912 | * @retval status |
|
- | 5913 | */ |
|
- | 5914 | HAL_StatusTypeDef HAL_TIM_UnRegisterCallback(TIM_HandleTypeDef *htim, HAL_TIM_CallbackIDTypeDef CallbackID) |
|
- | 5915 | { |
|
- | 5916 | HAL_StatusTypeDef status = HAL_OK; |
|
- | 5917 | ||
- | 5918 | /* Process locked */ |
|
- | 5919 | __HAL_LOCK(htim); |
|
- | 5920 | ||
- | 5921 | if (htim->State == HAL_TIM_STATE_READY) |
|
- | 5922 | { |
|
- | 5923 | switch (CallbackID) |
|
- | 5924 | { |
|
- | 5925 | case HAL_TIM_BASE_MSPINIT_CB_ID : |
|
- | 5926 | htim->Base_MspInitCallback = HAL_TIM_Base_MspInit; /* Legacy weak Base MspInit Callback */ |
|
- | 5927 | break; |
|
- | 5928 | ||
- | 5929 | case HAL_TIM_BASE_MSPDEINIT_CB_ID : |
|
- | 5930 | htim->Base_MspDeInitCallback = HAL_TIM_Base_MspDeInit; /* Legacy weak Base Msp DeInit Callback */ |
|
- | 5931 | break; |
|
- | 5932 | ||
- | 5933 | case HAL_TIM_IC_MSPINIT_CB_ID : |
|
- | 5934 | htim->IC_MspInitCallback = HAL_TIM_IC_MspInit; /* Legacy weak IC Msp Init Callback */ |
|
- | 5935 | break; |
|
- | 5936 | ||
- | 5937 | case HAL_TIM_IC_MSPDEINIT_CB_ID : |
|
- | 5938 | htim->IC_MspDeInitCallback = HAL_TIM_IC_MspDeInit; /* Legacy weak IC Msp DeInit Callback */ |
|
- | 5939 | break; |
|
- | 5940 | ||
- | 5941 | case HAL_TIM_OC_MSPINIT_CB_ID : |
|
- | 5942 | htim->OC_MspInitCallback = HAL_TIM_OC_MspInit; /* Legacy weak OC Msp Init Callback */ |
|
- | 5943 | break; |
|
- | 5944 | ||
- | 5945 | case HAL_TIM_OC_MSPDEINIT_CB_ID : |
|
- | 5946 | htim->OC_MspDeInitCallback = HAL_TIM_OC_MspDeInit; /* Legacy weak OC Msp DeInit Callback */ |
|
- | 5947 | break; |
|
- | 5948 | ||
- | 5949 | case HAL_TIM_PWM_MSPINIT_CB_ID : |
|
- | 5950 | htim->PWM_MspInitCallback = HAL_TIM_PWM_MspInit; /* Legacy weak PWM Msp Init Callback */ |
|
- | 5951 | break; |
|
- | 5952 | ||
- | 5953 | case HAL_TIM_PWM_MSPDEINIT_CB_ID : |
|
- | 5954 | htim->PWM_MspDeInitCallback = HAL_TIM_PWM_MspDeInit; /* Legacy weak PWM Msp DeInit Callback */ |
|
- | 5955 | break; |
|
- | 5956 | ||
- | 5957 | case HAL_TIM_ONE_PULSE_MSPINIT_CB_ID : |
|
- | 5958 | htim->OnePulse_MspInitCallback = HAL_TIM_OnePulse_MspInit; /* Legacy weak One Pulse Msp Init Callback */ |
|
- | 5959 | break; |
|
- | 5960 | ||
- | 5961 | case HAL_TIM_ONE_PULSE_MSPDEINIT_CB_ID : |
|
- | 5962 | htim->OnePulse_MspDeInitCallback = HAL_TIM_OnePulse_MspDeInit; /* Legacy weak One Pulse Msp DeInit Callback */ |
|
- | 5963 | break; |
|
- | 5964 | ||
- | 5965 | case HAL_TIM_ENCODER_MSPINIT_CB_ID : |
|
- | 5966 | htim->Encoder_MspInitCallback = HAL_TIM_Encoder_MspInit; /* Legacy weak Encoder Msp Init Callback */ |
|
- | 5967 | break; |
|
- | 5968 | ||
- | 5969 | case HAL_TIM_ENCODER_MSPDEINIT_CB_ID : |
|
- | 5970 | htim->Encoder_MspDeInitCallback = HAL_TIM_Encoder_MspDeInit; /* Legacy weak Encoder Msp DeInit Callback */ |
|
- | 5971 | break; |
|
- | 5972 | ||
- | 5973 | case HAL_TIM_HALL_SENSOR_MSPINIT_CB_ID : |
|
- | 5974 | htim->HallSensor_MspInitCallback = HAL_TIMEx_HallSensor_MspInit; /* Legacy weak Hall Sensor Msp Init Callback */ |
|
- | 5975 | break; |
|
- | 5976 | ||
- | 5977 | case HAL_TIM_HALL_SENSOR_MSPDEINIT_CB_ID : |
|
- | 5978 | htim->HallSensor_MspDeInitCallback = HAL_TIMEx_HallSensor_MspDeInit; /* Legacy weak Hall Sensor Msp DeInit Callback */ |
|
- | 5979 | break; |
|
- | 5980 | ||
- | 5981 | case HAL_TIM_PERIOD_ELAPSED_CB_ID : |
|
- | 5982 | htim->PeriodElapsedCallback = HAL_TIM_PeriodElapsedCallback; /* Legacy weak Period Elapsed Callback */ |
|
- | 5983 | break; |
|
- | 5984 | ||
- | 5985 | case HAL_TIM_PERIOD_ELAPSED_HALF_CB_ID : |
|
- | 5986 | htim->PeriodElapsedHalfCpltCallback = HAL_TIM_PeriodElapsedHalfCpltCallback; /* Legacy weak Period Elapsed half complete Callback */ |
|
- | 5987 | break; |
|
- | 5988 | ||
- | 5989 | case HAL_TIM_TRIGGER_CB_ID : |
|
- | 5990 | htim->TriggerCallback = HAL_TIM_TriggerCallback; /* Legacy weak Trigger Callback */ |
|
- | 5991 | break; |
|
- | 5992 | ||
- | 5993 | case HAL_TIM_TRIGGER_HALF_CB_ID : |
|
- | 5994 | htim->TriggerHalfCpltCallback = HAL_TIM_TriggerHalfCpltCallback; /* Legacy weak Trigger half complete Callback */ |
|
- | 5995 | break; |
|
- | 5996 | ||
- | 5997 | case HAL_TIM_IC_CAPTURE_CB_ID : |
|
- | 5998 | htim->IC_CaptureCallback = HAL_TIM_IC_CaptureCallback; /* Legacy weak IC Capture Callback */ |
|
- | 5999 | break; |
|
- | 6000 | ||
- | 6001 | case HAL_TIM_IC_CAPTURE_HALF_CB_ID : |
|
- | 6002 | htim->IC_CaptureHalfCpltCallback = HAL_TIM_IC_CaptureHalfCpltCallback; /* Legacy weak IC Capture half complete Callback */ |
|
- | 6003 | break; |
|
- | 6004 | ||
- | 6005 | case HAL_TIM_OC_DELAY_ELAPSED_CB_ID : |
|
- | 6006 | htim->OC_DelayElapsedCallback = HAL_TIM_OC_DelayElapsedCallback; /* Legacy weak OC Delay Elapsed Callback */ |
|
- | 6007 | break; |
|
- | 6008 | ||
- | 6009 | case HAL_TIM_PWM_PULSE_FINISHED_CB_ID : |
|
- | 6010 | htim->PWM_PulseFinishedCallback = HAL_TIM_PWM_PulseFinishedCallback; /* Legacy weak PWM Pulse Finished Callback */ |
|
- | 6011 | break; |
|
- | 6012 | ||
- | 6013 | case HAL_TIM_PWM_PULSE_FINISHED_HALF_CB_ID : |
|
- | 6014 | htim->PWM_PulseFinishedHalfCpltCallback = HAL_TIM_PWM_PulseFinishedHalfCpltCallback; /* Legacy weak PWM Pulse Finished half complete Callback */ |
|
- | 6015 | break; |
|
- | 6016 | ||
- | 6017 | case HAL_TIM_ERROR_CB_ID : |
|
- | 6018 | htim->ErrorCallback = HAL_TIM_ErrorCallback; /* Legacy weak Error Callback */ |
|
- | 6019 | break; |
|
- | 6020 | ||
- | 6021 | case HAL_TIM_COMMUTATION_CB_ID : |
|
- | 6022 | htim->CommutationCallback = HAL_TIMEx_CommutCallback; /* Legacy weak Commutation Callback */ |
|
- | 6023 | break; |
|
- | 6024 | ||
- | 6025 | case HAL_TIM_COMMUTATION_HALF_CB_ID : |
|
- | 6026 | htim->CommutationHalfCpltCallback = HAL_TIMEx_CommutHalfCpltCallback; /* Legacy weak Commutation half complete Callback */ |
|
- | 6027 | break; |
|
- | 6028 | ||
- | 6029 | case HAL_TIM_BREAK_CB_ID : |
|
- | 6030 | htim->BreakCallback = HAL_TIMEx_BreakCallback; /* Legacy weak Break Callback */ |
|
- | 6031 | break; |
|
- | 6032 | ||
- | 6033 | default : |
|
- | 6034 | /* Return error status */ |
|
- | 6035 | status = HAL_ERROR; |
|
- | 6036 | break; |
|
- | 6037 | } |
|
- | 6038 | } |
|
- | 6039 | else if (htim->State == HAL_TIM_STATE_RESET) |
|
- | 6040 | { |
|
- | 6041 | switch (CallbackID) |
|
- | 6042 | { |
|
- | 6043 | case HAL_TIM_BASE_MSPINIT_CB_ID : |
|
- | 6044 | htim->Base_MspInitCallback = HAL_TIM_Base_MspInit; /* Legacy weak Base MspInit Callback */ |
|
- | 6045 | break; |
|
- | 6046 | ||
- | 6047 | case HAL_TIM_BASE_MSPDEINIT_CB_ID : |
|
- | 6048 | htim->Base_MspDeInitCallback = HAL_TIM_Base_MspDeInit; /* Legacy weak Base Msp DeInit Callback */ |
|
- | 6049 | break; |
|
- | 6050 | ||
- | 6051 | case HAL_TIM_IC_MSPINIT_CB_ID : |
|
- | 6052 | htim->IC_MspInitCallback = HAL_TIM_IC_MspInit; /* Legacy weak IC Msp Init Callback */ |
|
- | 6053 | break; |
|
- | 6054 | ||
- | 6055 | case HAL_TIM_IC_MSPDEINIT_CB_ID : |
|
- | 6056 | htim->IC_MspDeInitCallback = HAL_TIM_IC_MspDeInit; /* Legacy weak IC Msp DeInit Callback */ |
|
- | 6057 | break; |
|
- | 6058 | ||
- | 6059 | case HAL_TIM_OC_MSPINIT_CB_ID : |
|
- | 6060 | htim->OC_MspInitCallback = HAL_TIM_OC_MspInit; /* Legacy weak OC Msp Init Callback */ |
|
- | 6061 | break; |
|
- | 6062 | ||
- | 6063 | case HAL_TIM_OC_MSPDEINIT_CB_ID : |
|
- | 6064 | htim->OC_MspDeInitCallback = HAL_TIM_OC_MspDeInit; /* Legacy weak OC Msp DeInit Callback */ |
|
- | 6065 | break; |
|
- | 6066 | ||
- | 6067 | case HAL_TIM_PWM_MSPINIT_CB_ID : |
|
- | 6068 | htim->PWM_MspInitCallback = HAL_TIM_PWM_MspInit; /* Legacy weak PWM Msp Init Callback */ |
|
- | 6069 | break; |
|
- | 6070 | ||
- | 6071 | case HAL_TIM_PWM_MSPDEINIT_CB_ID : |
|
- | 6072 | htim->PWM_MspDeInitCallback = HAL_TIM_PWM_MspDeInit; /* Legacy weak PWM Msp DeInit Callback */ |
|
- | 6073 | break; |
|
- | 6074 | ||
- | 6075 | case HAL_TIM_ONE_PULSE_MSPINIT_CB_ID : |
|
- | 6076 | htim->OnePulse_MspInitCallback = HAL_TIM_OnePulse_MspInit; /* Legacy weak One Pulse Msp Init Callback */ |
|
- | 6077 | break; |
|
- | 6078 | ||
- | 6079 | case HAL_TIM_ONE_PULSE_MSPDEINIT_CB_ID : |
|
- | 6080 | htim->OnePulse_MspDeInitCallback = HAL_TIM_OnePulse_MspDeInit; /* Legacy weak One Pulse Msp DeInit Callback */ |
|
- | 6081 | break; |
|
- | 6082 | ||
- | 6083 | case HAL_TIM_ENCODER_MSPINIT_CB_ID : |
|
- | 6084 | htim->Encoder_MspInitCallback = HAL_TIM_Encoder_MspInit; /* Legacy weak Encoder Msp Init Callback */ |
|
- | 6085 | break; |
|
- | 6086 | ||
- | 6087 | case HAL_TIM_ENCODER_MSPDEINIT_CB_ID : |
|
- | 6088 | htim->Encoder_MspDeInitCallback = HAL_TIM_Encoder_MspDeInit; /* Legacy weak Encoder Msp DeInit Callback */ |
|
- | 6089 | break; |
|
- | 6090 | ||
- | 6091 | case HAL_TIM_HALL_SENSOR_MSPINIT_CB_ID : |
|
- | 6092 | htim->HallSensor_MspInitCallback = HAL_TIMEx_HallSensor_MspInit; /* Legacy weak Hall Sensor Msp Init Callback */ |
|
- | 6093 | break; |
|
- | 6094 | ||
- | 6095 | case HAL_TIM_HALL_SENSOR_MSPDEINIT_CB_ID : |
|
- | 6096 | htim->HallSensor_MspDeInitCallback = HAL_TIMEx_HallSensor_MspDeInit; /* Legacy weak Hall Sensor Msp DeInit Callback */ |
|
- | 6097 | break; |
|
- | 6098 | ||
- | 6099 | default : |
|
- | 6100 | /* Return error status */ |
|
- | 6101 | status = HAL_ERROR; |
|
- | 6102 | break; |
|
- | 6103 | } |
|
- | 6104 | } |
|
- | 6105 | else |
|
- | 6106 | { |
|
- | 6107 | /* Return error status */ |
|
- | 6108 | status = HAL_ERROR; |
|
- | 6109 | } |
|
- | 6110 | ||
- | 6111 | /* Release Lock */ |
|
- | 6112 | __HAL_UNLOCK(htim); |
|
- | 6113 | ||
- | 6114 | return status; |
|
- | 6115 | } |
|
- | 6116 | #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */ |
|
- | 6117 | ||
4387 | /** |
6118 | /** |
4388 | * @} |
6119 | * @} |
4389 | */ |
6120 | */ |
4390 | 6121 | ||
4391 | /** @defgroup TIM_Exported_Functions_Group10 Peripheral State functions |
6122 | /** @defgroup TIM_Exported_Functions_Group10 TIM Peripheral State functions |
4392 | * @brief Peripheral State functions |
6123 | * @brief TIM Peripheral State functions |
4393 | * |
6124 | * |
4394 | @verbatim |
6125 | @verbatim |
4395 | ============================================================================== |
6126 | ============================================================================== |
4396 | ##### Peripheral State functions ##### |
6127 | ##### Peripheral State functions ##### |
4397 | ============================================================================== |
6128 | ============================================================================== |
4398 | [..] |
6129 | [..] |
4399 | This subsection permit to get in run-time the status of the peripheral |
6130 | This subsection permits to get in run-time the status of the peripheral |
4400 | and the data flow. |
6131 | and the data flow. |
4401 | 6132 | ||
4402 | @endverbatim |
6133 | @endverbatim |
4403 | * @{ |
6134 | * @{ |
4404 | */ |
6135 | */ |
4405 | 6136 | ||
4406 | /** |
6137 | /** |
4407 | * @brief Return the TIM Base state |
6138 | * @brief Return the TIM Base handle state. |
4408 | * @param htim : TIM Base handle |
6139 | * @param htim TIM Base handle |
4409 | * @retval HAL state |
6140 | * @retval HAL state |
4410 | */ |
6141 | */ |
4411 | HAL_TIM_StateTypeDef HAL_TIM_Base_GetState(TIM_HandleTypeDef *htim) |
6142 | HAL_TIM_StateTypeDef HAL_TIM_Base_GetState(TIM_HandleTypeDef *htim) |
4412 | { |
6143 | { |
4413 | return htim->State; |
6144 | return htim->State; |
4414 | } |
6145 | } |
4415 | 6146 | ||
4416 | /** |
6147 | /** |
4417 | * @brief Return the TIM OC state |
6148 | * @brief Return the TIM OC handle state. |
4418 | * @param htim : TIM Ouput Compare handle |
6149 | * @param htim TIM Output Compare handle |
4419 | * @retval HAL state |
6150 | * @retval HAL state |
4420 | */ |
6151 | */ |
4421 | HAL_TIM_StateTypeDef HAL_TIM_OC_GetState(TIM_HandleTypeDef *htim) |
6152 | HAL_TIM_StateTypeDef HAL_TIM_OC_GetState(TIM_HandleTypeDef *htim) |
4422 | { |
6153 | { |
4423 | return htim->State; |
6154 | return htim->State; |
4424 | } |
6155 | } |
4425 | 6156 | ||
4426 | /** |
6157 | /** |
4427 | * @brief Return the TIM PWM state |
6158 | * @brief Return the TIM PWM handle state. |
4428 | * @param htim : TIM handle |
6159 | * @param htim TIM handle |
4429 | * @retval HAL state |
6160 | * @retval HAL state |
4430 | */ |
6161 | */ |
4431 | HAL_TIM_StateTypeDef HAL_TIM_PWM_GetState(TIM_HandleTypeDef *htim) |
6162 | HAL_TIM_StateTypeDef HAL_TIM_PWM_GetState(TIM_HandleTypeDef *htim) |
4432 | { |
6163 | { |
4433 | return htim->State; |
6164 | return htim->State; |
4434 | } |
6165 | } |
4435 | 6166 | ||
4436 | /** |
6167 | /** |
4437 | * @brief Return the TIM Input Capture state |
6168 | * @brief Return the TIM Input Capture handle state. |
4438 | * @param htim : TIM IC handle |
6169 | * @param htim TIM IC handle |
4439 | * @retval HAL state |
6170 | * @retval HAL state |
4440 | */ |
6171 | */ |
4441 | HAL_TIM_StateTypeDef HAL_TIM_IC_GetState(TIM_HandleTypeDef *htim) |
6172 | HAL_TIM_StateTypeDef HAL_TIM_IC_GetState(TIM_HandleTypeDef *htim) |
4442 | { |
6173 | { |
4443 | return htim->State; |
6174 | return htim->State; |
4444 | } |
6175 | } |
4445 | 6176 | ||
4446 | /** |
6177 | /** |
4447 | * @brief Return the TIM One Pulse Mode state |
6178 | * @brief Return the TIM One Pulse Mode handle state. |
4448 | * @param htim : TIM OPM handle |
6179 | * @param htim TIM OPM handle |
4449 | * @retval HAL state |
6180 | * @retval HAL state |
4450 | */ |
6181 | */ |
4451 | HAL_TIM_StateTypeDef HAL_TIM_OnePulse_GetState(TIM_HandleTypeDef *htim) |
6182 | HAL_TIM_StateTypeDef HAL_TIM_OnePulse_GetState(TIM_HandleTypeDef *htim) |
4452 | { |
6183 | { |
4453 | return htim->State; |
6184 | return htim->State; |
4454 | } |
6185 | } |
4455 | 6186 | ||
4456 | /** |
6187 | /** |
4457 | * @brief Return the TIM Encoder Mode state |
6188 | * @brief Return the TIM Encoder Mode handle state. |
4458 | * @param htim : TIM Encoder handle |
6189 | * @param htim TIM Encoder Interface handle |
4459 | * @retval HAL state |
6190 | * @retval HAL state |
4460 | */ |
6191 | */ |
4461 | HAL_TIM_StateTypeDef HAL_TIM_Encoder_GetState(TIM_HandleTypeDef *htim) |
6192 | HAL_TIM_StateTypeDef HAL_TIM_Encoder_GetState(TIM_HandleTypeDef *htim) |
4462 | { |
6193 | { |
4463 | return htim->State; |
6194 | return htim->State; |
4464 | } |
6195 | } |
4465 | 6196 | ||
4466 | /** |
6197 | /** |
- | 6198 | * @brief Return the TIM Encoder Mode handle state. |
|
- | 6199 | * @param htim TIM handle |
|
- | 6200 | * @retval Active channel |
|
- | 6201 | */ |
|
- | 6202 | HAL_TIM_ActiveChannel HAL_TIM_GetActiveChannel(TIM_HandleTypeDef *htim) |
|
- | 6203 | { |
|
- | 6204 | return htim->Channel; |
|
- | 6205 | } |
|
- | 6206 | ||
- | 6207 | /** |
|
- | 6208 | * @brief Return actual state of the TIM channel. |
|
- | 6209 | * @param htim TIM handle |
|
- | 6210 | * @param Channel TIM Channel |
|
- | 6211 | * This parameter can be one of the following values: |
|
- | 6212 | * @arg TIM_CHANNEL_1: TIM Channel 1 |
|
- | 6213 | * @arg TIM_CHANNEL_2: TIM Channel 2 |
|
- | 6214 | * @arg TIM_CHANNEL_3: TIM Channel 3 |
|
- | 6215 | * @arg TIM_CHANNEL_4: TIM Channel 4 |
|
- | 6216 | * @arg TIM_CHANNEL_5: TIM Channel 5 |
|
- | 6217 | * @arg TIM_CHANNEL_6: TIM Channel 6 |
|
- | 6218 | * @retval TIM Channel state |
|
- | 6219 | */ |
|
- | 6220 | HAL_TIM_ChannelStateTypeDef HAL_TIM_GetChannelState(TIM_HandleTypeDef *htim, uint32_t Channel) |
|
- | 6221 | { |
|
- | 6222 | HAL_TIM_ChannelStateTypeDef channel_state; |
|
- | 6223 | ||
- | 6224 | /* Check the parameters */ |
|
- | 6225 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
|
- | 6226 | ||
- | 6227 | channel_state = TIM_CHANNEL_STATE_GET(htim, Channel); |
|
- | 6228 | ||
- | 6229 | return channel_state; |
|
- | 6230 | } |
|
- | 6231 | ||
- | 6232 | /** |
|
- | 6233 | * @brief Return actual state of a DMA burst operation. |
|
- | 6234 | * @param htim TIM handle |
|
- | 6235 | * @retval DMA burst state |
|
- | 6236 | */ |
|
- | 6237 | HAL_TIM_DMABurstStateTypeDef HAL_TIM_DMABurstState(TIM_HandleTypeDef *htim) |
|
- | 6238 | { |
|
- | 6239 | /* Check the parameters */ |
|
- | 6240 | assert_param(IS_TIM_DMABURST_INSTANCE(htim->Instance)); |
|
- | 6241 | ||
- | 6242 | return htim->DMABurstState; |
|
- | 6243 | } |
|
- | 6244 | ||
- | 6245 | /** |
|
4467 | * @} |
6246 | * @} |
4468 | */ |
6247 | */ |
4469 | 6248 | ||
4470 | /** |
6249 | /** |
4471 | * @} |
6250 | * @} |
4472 | */ |
6251 | */ |
4473 | 6252 | ||
4474 | /** @addtogroup TIM_Private_Functions |
6253 | /** @defgroup TIM_Private_Functions TIM Private Functions |
4475 | * @{ |
6254 | * @{ |
4476 | */ |
6255 | */ |
4477 | 6256 | ||
4478 | /** |
6257 | /** |
4479 | * @brief TIM DMA error callback |
6258 | * @brief TIM DMA error callback |
4480 | * @param hdma : pointer to DMA handle. |
6259 | * @param hdma pointer to DMA handle. |
4481 | * @retval None |
6260 | * @retval None |
4482 | */ |
6261 | */ |
4483 | void TIM_DMAError(DMA_HandleTypeDef *hdma) |
6262 | void TIM_DMAError(DMA_HandleTypeDef *hdma) |
4484 | { |
6263 | { |
4485 | TIM_HandleTypeDef* htim = ( TIM_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; |
6264 | TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent; |
4486 | 6265 | ||
- | 6266 | if (hdma == htim->hdma[TIM_DMA_ID_CC1]) |
|
- | 6267 | { |
|
- | 6268 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_1; |
|
- | 6269 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY); |
|
- | 6270 | } |
|
- | 6271 | else if (hdma == htim->hdma[TIM_DMA_ID_CC2]) |
|
- | 6272 | { |
|
- | 6273 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_2; |
|
- | 6274 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY); |
|
- | 6275 | } |
|
- | 6276 | else if (hdma == htim->hdma[TIM_DMA_ID_CC3]) |
|
- | 6277 | { |
|
- | 6278 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_3; |
|
- | 6279 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_3, HAL_TIM_CHANNEL_STATE_READY); |
|
- | 6280 | } |
|
- | 6281 | else if (hdma == htim->hdma[TIM_DMA_ID_CC4]) |
|
- | 6282 | { |
|
- | 6283 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_4; |
|
- | 6284 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_4, HAL_TIM_CHANNEL_STATE_READY); |
|
- | 6285 | } |
|
- | 6286 | else |
|
- | 6287 | { |
|
4487 | htim->State= HAL_TIM_STATE_READY; |
6288 | htim->State = HAL_TIM_STATE_READY; |
- | 6289 | } |
|
4488 | 6290 | ||
- | 6291 | #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) |
|
- | 6292 | htim->ErrorCallback(htim); |
|
- | 6293 | #else |
|
4489 | HAL_TIM_ErrorCallback(htim); |
6294 | HAL_TIM_ErrorCallback(htim); |
- | 6295 | #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */ |
|
- | 6296 | ||
- | 6297 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED; |
|
4490 | } |
6298 | } |
4491 | 6299 | ||
4492 | /** |
6300 | /** |
4493 | * @brief TIM DMA Delay Pulse complete callback. |
6301 | * @brief TIM DMA Delay Pulse complete callback. |
4494 | * @param hdma : pointer to DMA handle. |
6302 | * @param hdma pointer to DMA handle. |
4495 | * @retval None |
6303 | * @retval None |
4496 | */ |
6304 | */ |
4497 | void TIM_DMADelayPulseCplt(DMA_HandleTypeDef *hdma) |
6305 | static void TIM_DMADelayPulseCplt(DMA_HandleTypeDef *hdma) |
4498 | { |
6306 | { |
4499 | TIM_HandleTypeDef* htim = ( TIM_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; |
6307 | TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent; |
4500 | - | ||
4501 | htim->State= HAL_TIM_STATE_READY; |
- | |
4502 | 6308 | ||
4503 | if (hdma == htim->hdma[TIM_DMA_ID_CC1]) |
6309 | if (hdma == htim->hdma[TIM_DMA_ID_CC1]) |
4504 | { |
6310 | { |
4505 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_1; |
6311 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_1; |
- | 6312 | ||
- | 6313 | if (hdma->Init.Mode == DMA_NORMAL) |
|
- | 6314 | { |
|
- | 6315 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY); |
|
- | 6316 | } |
|
4506 | } |
6317 | } |
4507 | else if (hdma == htim->hdma[TIM_DMA_ID_CC2]) |
6318 | else if (hdma == htim->hdma[TIM_DMA_ID_CC2]) |
4508 | { |
6319 | { |
4509 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_2; |
6320 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_2; |
- | 6321 | ||
- | 6322 | if (hdma->Init.Mode == DMA_NORMAL) |
|
- | 6323 | { |
|
- | 6324 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY); |
|
- | 6325 | } |
|
4510 | } |
6326 | } |
4511 | else if (hdma == htim->hdma[TIM_DMA_ID_CC3]) |
6327 | else if (hdma == htim->hdma[TIM_DMA_ID_CC3]) |
4512 | { |
6328 | { |
4513 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_3; |
6329 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_3; |
- | 6330 | ||
- | 6331 | if (hdma->Init.Mode == DMA_NORMAL) |
|
- | 6332 | { |
|
- | 6333 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_3, HAL_TIM_CHANNEL_STATE_READY); |
|
- | 6334 | } |
|
4514 | } |
6335 | } |
4515 | else if (hdma == htim->hdma[TIM_DMA_ID_CC4]) |
6336 | else if (hdma == htim->hdma[TIM_DMA_ID_CC4]) |
4516 | { |
6337 | { |
4517 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_4; |
6338 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_4; |
- | 6339 | ||
- | 6340 | if (hdma->Init.Mode == DMA_NORMAL) |
|
- | 6341 | { |
|
- | 6342 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_4, HAL_TIM_CHANNEL_STATE_READY); |
|
- | 6343 | } |
|
- | 6344 | } |
|
- | 6345 | else |
|
- | 6346 | { |
|
- | 6347 | /* nothing to do */ |
|
4518 | } |
6348 | } |
4519 | 6349 | ||
- | 6350 | #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) |
|
- | 6351 | htim->PWM_PulseFinishedCallback(htim); |
|
- | 6352 | #else |
|
4520 | HAL_TIM_PWM_PulseFinishedCallback(htim); |
6353 | HAL_TIM_PWM_PulseFinishedCallback(htim); |
- | 6354 | #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */ |
|
4521 | 6355 | ||
4522 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED; |
6356 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED; |
4523 | } |
6357 | } |
- | 6358 | ||
- | 6359 | /** |
|
- | 6360 | * @brief TIM DMA Delay Pulse half complete callback. |
|
- | 6361 | * @param hdma pointer to DMA handle. |
|
- | 6362 | * @retval None |
|
- | 6363 | */ |
|
- | 6364 | void TIM_DMADelayPulseHalfCplt(DMA_HandleTypeDef *hdma) |
|
- | 6365 | { |
|
- | 6366 | TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent; |
|
- | 6367 | ||
- | 6368 | if (hdma == htim->hdma[TIM_DMA_ID_CC1]) |
|
- | 6369 | { |
|
- | 6370 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_1; |
|
- | 6371 | } |
|
- | 6372 | else if (hdma == htim->hdma[TIM_DMA_ID_CC2]) |
|
- | 6373 | { |
|
- | 6374 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_2; |
|
- | 6375 | } |
|
- | 6376 | else if (hdma == htim->hdma[TIM_DMA_ID_CC3]) |
|
- | 6377 | { |
|
- | 6378 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_3; |
|
- | 6379 | } |
|
- | 6380 | else if (hdma == htim->hdma[TIM_DMA_ID_CC4]) |
|
- | 6381 | { |
|
- | 6382 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_4; |
|
- | 6383 | } |
|
- | 6384 | else |
|
- | 6385 | { |
|
- | 6386 | /* nothing to do */ |
|
- | 6387 | } |
|
- | 6388 | ||
- | 6389 | #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) |
|
- | 6390 | htim->PWM_PulseFinishedHalfCpltCallback(htim); |
|
- | 6391 | #else |
|
- | 6392 | HAL_TIM_PWM_PulseFinishedHalfCpltCallback(htim); |
|
- | 6393 | #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */ |
|
- | 6394 | ||
- | 6395 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED; |
|
- | 6396 | } |
|
- | 6397 | ||
4524 | /** |
6398 | /** |
4525 | * @brief TIM DMA Capture complete callback. |
6399 | * @brief TIM DMA Capture complete callback. |
4526 | * @param hdma : pointer to DMA handle. |
6400 | * @param hdma pointer to DMA handle. |
4527 | * @retval None |
6401 | * @retval None |
4528 | */ |
6402 | */ |
4529 | void TIM_DMACaptureCplt(DMA_HandleTypeDef *hdma) |
6403 | void TIM_DMACaptureCplt(DMA_HandleTypeDef *hdma) |
4530 | { |
6404 | { |
4531 | TIM_HandleTypeDef* htim = ( TIM_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; |
6405 | TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent; |
4532 | - | ||
4533 | htim->State= HAL_TIM_STATE_READY; |
- | |
4534 | 6406 | ||
4535 | if (hdma == htim->hdma[TIM_DMA_ID_CC1]) |
6407 | if (hdma == htim->hdma[TIM_DMA_ID_CC1]) |
4536 | { |
6408 | { |
4537 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_1; |
6409 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_1; |
- | 6410 | ||
- | 6411 | if (hdma->Init.Mode == DMA_NORMAL) |
|
- | 6412 | { |
|
- | 6413 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY); |
|
- | 6414 | TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY); |
|
- | 6415 | } |
|
4538 | } |
6416 | } |
4539 | else if (hdma == htim->hdma[TIM_DMA_ID_CC2]) |
6417 | else if (hdma == htim->hdma[TIM_DMA_ID_CC2]) |
4540 | { |
6418 | { |
4541 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_2; |
6419 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_2; |
- | 6420 | ||
- | 6421 | if (hdma->Init.Mode == DMA_NORMAL) |
|
- | 6422 | { |
|
- | 6423 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY); |
|
- | 6424 | TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY); |
|
- | 6425 | } |
|
4542 | } |
6426 | } |
4543 | else if (hdma == htim->hdma[TIM_DMA_ID_CC3]) |
6427 | else if (hdma == htim->hdma[TIM_DMA_ID_CC3]) |
4544 | { |
6428 | { |
4545 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_3; |
6429 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_3; |
- | 6430 | ||
- | 6431 | if (hdma->Init.Mode == DMA_NORMAL) |
|
- | 6432 | { |
|
- | 6433 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_3, HAL_TIM_CHANNEL_STATE_READY); |
|
- | 6434 | TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_3, HAL_TIM_CHANNEL_STATE_READY); |
|
- | 6435 | } |
|
4546 | } |
6436 | } |
4547 | else if (hdma == htim->hdma[TIM_DMA_ID_CC4]) |
6437 | else if (hdma == htim->hdma[TIM_DMA_ID_CC4]) |
4548 | { |
6438 | { |
4549 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_4; |
6439 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_4; |
- | 6440 | ||
- | 6441 | if (hdma->Init.Mode == DMA_NORMAL) |
|
- | 6442 | { |
|
- | 6443 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_4, HAL_TIM_CHANNEL_STATE_READY); |
|
- | 6444 | TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_4, HAL_TIM_CHANNEL_STATE_READY); |
|
- | 6445 | } |
|
- | 6446 | } |
|
- | 6447 | else |
|
- | 6448 | { |
|
- | 6449 | /* nothing to do */ |
|
4550 | } |
6450 | } |
4551 | 6451 | ||
- | 6452 | #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) |
|
- | 6453 | htim->IC_CaptureCallback(htim); |
|
- | 6454 | #else |
|
4552 | HAL_TIM_IC_CaptureCallback(htim); |
6455 | HAL_TIM_IC_CaptureCallback(htim); |
- | 6456 | #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */ |
|
- | 6457 | ||
- | 6458 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED; |
|
- | 6459 | } |
|
- | 6460 | ||
- | 6461 | /** |
|
- | 6462 | * @brief TIM DMA Capture half complete callback. |
|
- | 6463 | * @param hdma pointer to DMA handle. |
|
- | 6464 | * @retval None |
|
- | 6465 | */ |
|
- | 6466 | void TIM_DMACaptureHalfCplt(DMA_HandleTypeDef *hdma) |
|
- | 6467 | { |
|
- | 6468 | TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent; |
|
- | 6469 | ||
- | 6470 | if (hdma == htim->hdma[TIM_DMA_ID_CC1]) |
|
- | 6471 | { |
|
- | 6472 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_1; |
|
- | 6473 | } |
|
- | 6474 | else if (hdma == htim->hdma[TIM_DMA_ID_CC2]) |
|
- | 6475 | { |
|
- | 6476 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_2; |
|
- | 6477 | } |
|
- | 6478 | else if (hdma == htim->hdma[TIM_DMA_ID_CC3]) |
|
- | 6479 | { |
|
- | 6480 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_3; |
|
- | 6481 | } |
|
- | 6482 | else if (hdma == htim->hdma[TIM_DMA_ID_CC4]) |
|
- | 6483 | { |
|
- | 6484 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_4; |
|
- | 6485 | } |
|
- | 6486 | else |
|
- | 6487 | { |
|
- | 6488 | /* nothing to do */ |
|
- | 6489 | } |
|
- | 6490 | ||
- | 6491 | #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) |
|
- | 6492 | htim->IC_CaptureHalfCpltCallback(htim); |
|
- | 6493 | #else |
|
- | 6494 | HAL_TIM_IC_CaptureHalfCpltCallback(htim); |
|
- | 6495 | #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */ |
|
4553 | 6496 | ||
4554 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED; |
6497 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED; |
4555 | } |
6498 | } |
4556 | 6499 | ||
4557 | /** |
6500 | /** |
4558 | * @brief TIM DMA Period Elapse complete callback. |
6501 | * @brief TIM DMA Period Elapse complete callback. |
4559 | * @param hdma : pointer to DMA handle. |
6502 | * @param hdma pointer to DMA handle. |
4560 | * @retval None |
6503 | * @retval None |
4561 | */ |
6504 | */ |
4562 | static void TIM_DMAPeriodElapsedCplt(DMA_HandleTypeDef *hdma) |
6505 | static void TIM_DMAPeriodElapsedCplt(DMA_HandleTypeDef *hdma) |
4563 | { |
6506 | { |
4564 | TIM_HandleTypeDef* htim = ( TIM_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; |
6507 | TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent; |
4565 | 6508 | ||
- | 6509 | if (htim->hdma[TIM_DMA_ID_UPDATE]->Init.Mode == DMA_NORMAL) |
|
- | 6510 | { |
|
4566 | htim->State= HAL_TIM_STATE_READY; |
6511 | htim->State = HAL_TIM_STATE_READY; |
- | 6512 | } |
|
4567 | 6513 | ||
- | 6514 | #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) |
|
- | 6515 | htim->PeriodElapsedCallback(htim); |
|
- | 6516 | #else |
|
4568 | HAL_TIM_PeriodElapsedCallback(htim); |
6517 | HAL_TIM_PeriodElapsedCallback(htim); |
- | 6518 | #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */ |
|
- | 6519 | } |
|
- | 6520 | ||
- | 6521 | /** |
|
- | 6522 | * @brief TIM DMA Period Elapse half complete callback. |
|
- | 6523 | * @param hdma pointer to DMA handle. |
|
- | 6524 | * @retval None |
|
- | 6525 | */ |
|
- | 6526 | static void TIM_DMAPeriodElapsedHalfCplt(DMA_HandleTypeDef *hdma) |
|
- | 6527 | { |
|
- | 6528 | TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent; |
|
- | 6529 | ||
- | 6530 | #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) |
|
- | 6531 | htim->PeriodElapsedHalfCpltCallback(htim); |
|
- | 6532 | #else |
|
- | 6533 | HAL_TIM_PeriodElapsedHalfCpltCallback(htim); |
|
- | 6534 | #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */ |
|
4569 | } |
6535 | } |
4570 | 6536 | ||
4571 | /** |
6537 | /** |
4572 | * @brief TIM DMA Trigger callback. |
6538 | * @brief TIM DMA Trigger callback. |
4573 | * @param hdma : pointer to DMA handle. |
6539 | * @param hdma pointer to DMA handle. |
4574 | * @retval None |
6540 | * @retval None |
4575 | */ |
6541 | */ |
4576 | static void TIM_DMATriggerCplt(DMA_HandleTypeDef *hdma) |
6542 | static void TIM_DMATriggerCplt(DMA_HandleTypeDef *hdma) |
4577 | { |
6543 | { |
4578 | TIM_HandleTypeDef* htim = ( TIM_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; |
6544 | TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent; |
4579 | 6545 | ||
- | 6546 | if (htim->hdma[TIM_DMA_ID_TRIGGER]->Init.Mode == DMA_NORMAL) |
|
- | 6547 | { |
|
4580 | htim->State= HAL_TIM_STATE_READY; |
6548 | htim->State = HAL_TIM_STATE_READY; |
- | 6549 | } |
|
4581 | 6550 | ||
- | 6551 | #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) |
|
- | 6552 | htim->TriggerCallback(htim); |
|
- | 6553 | #else |
|
4582 | HAL_TIM_TriggerCallback(htim); |
6554 | HAL_TIM_TriggerCallback(htim); |
- | 6555 | #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */ |
|
- | 6556 | } |
|
- | 6557 | ||
- | 6558 | /** |
|
- | 6559 | * @brief TIM DMA Trigger half complete callback. |
|
- | 6560 | * @param hdma pointer to DMA handle. |
|
- | 6561 | * @retval None |
|
- | 6562 | */ |
|
- | 6563 | static void TIM_DMATriggerHalfCplt(DMA_HandleTypeDef *hdma) |
|
- | 6564 | { |
|
- | 6565 | TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent; |
|
- | 6566 | ||
- | 6567 | #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) |
|
- | 6568 | htim->TriggerHalfCpltCallback(htim); |
|
- | 6569 | #else |
|
- | 6570 | HAL_TIM_TriggerHalfCpltCallback(htim); |
|
- | 6571 | #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */ |
|
4583 | } |
6572 | } |
4584 | 6573 | ||
4585 | /** |
6574 | /** |
4586 | * @brief Time Base configuration |
6575 | * @brief Time Base configuration |
4587 | * @param TIMx : TIM periheral |
6576 | * @param TIMx TIM peripheral |
4588 | * @param Structure : TIM Base configuration structure |
6577 | * @param Structure TIM Base configuration structure |
4589 | * @retval None |
6578 | * @retval None |
4590 | */ |
6579 | */ |
4591 | void TIM_Base_SetConfig(TIM_TypeDef *TIMx, TIM_Base_InitTypeDef *Structure) |
6580 | void TIM_Base_SetConfig(TIM_TypeDef *TIMx, TIM_Base_InitTypeDef *Structure) |
4592 | { |
6581 | { |
4593 | uint32_t tmpcr1 = 0U; |
6582 | uint32_t tmpcr1; |
4594 | tmpcr1 = TIMx->CR1; |
6583 | tmpcr1 = TIMx->CR1; |
4595 | 6584 | ||
4596 | /* Set TIM Time Base Unit parameters ---------------------------------------*/ |
6585 | /* Set TIM Time Base Unit parameters ---------------------------------------*/ |
4597 | if (IS_TIM_COUNTER_MODE_SELECT_INSTANCE(TIMx)) |
6586 | if (IS_TIM_COUNTER_MODE_SELECT_INSTANCE(TIMx)) |
4598 | { |
6587 | { |
4599 | /* Select the Counter Mode */ |
6588 | /* Select the Counter Mode */ |
4600 | tmpcr1 &= ~(TIM_CR1_DIR | TIM_CR1_CMS); |
6589 | tmpcr1 &= ~(TIM_CR1_DIR | TIM_CR1_CMS); |
4601 | tmpcr1 |= Structure->CounterMode; |
6590 | tmpcr1 |= Structure->CounterMode; |
4602 | } |
6591 | } |
4603 | 6592 | ||
4604 | if(IS_TIM_CLOCK_DIVISION_INSTANCE(TIMx)) |
6593 | if (IS_TIM_CLOCK_DIVISION_INSTANCE(TIMx)) |
4605 | { |
6594 | { |
4606 | /* Set the clock division */ |
6595 | /* Set the clock division */ |
4607 | tmpcr1 &= ~TIM_CR1_CKD; |
6596 | tmpcr1 &= ~TIM_CR1_CKD; |
4608 | tmpcr1 |= (uint32_t)Structure->ClockDivision; |
6597 | tmpcr1 |= (uint32_t)Structure->ClockDivision; |
4609 | } |
6598 | } |
4610 | 6599 | ||
4611 | /* Set the auto-reload preload */ |
6600 | /* Set the auto-reload preload */ |
4612 | tmpcr1 &= ~TIM_CR1_ARPE; |
- | |
4613 | tmpcr1 |= (uint32_t)Structure->AutoReloadPreload; |
6601 | MODIFY_REG(tmpcr1, TIM_CR1_ARPE, Structure->AutoReloadPreload); |
4614 | 6602 | ||
4615 | TIMx->CR1 = tmpcr1; |
6603 | TIMx->CR1 = tmpcr1; |
4616 | 6604 | ||
4617 | /* Set the Autoreload value */ |
6605 | /* Set the Autoreload value */ |
4618 | TIMx->ARR = (uint32_t)Structure->Period ; |
6606 | TIMx->ARR = (uint32_t)Structure->Period ; |
4619 | 6607 | ||
4620 | /* Set the Prescaler value */ |
6608 | /* Set the Prescaler value */ |
4621 | TIMx->PSC = (uint32_t)Structure->Prescaler; |
6609 | TIMx->PSC = Structure->Prescaler; |
4622 | 6610 | ||
4623 | if (IS_TIM_REPETITION_COUNTER_INSTANCE(TIMx)) |
6611 | if (IS_TIM_REPETITION_COUNTER_INSTANCE(TIMx)) |
4624 | { |
6612 | { |
4625 | /* Set the Repetition Counter value */ |
6613 | /* Set the Repetition Counter value */ |
4626 | TIMx->RCR = Structure->RepetitionCounter; |
6614 | TIMx->RCR = Structure->RepetitionCounter; |
4627 | } |
6615 | } |
4628 | 6616 | ||
4629 | /* Generate an update event to reload the Prescaler |
6617 | /* Generate an update event to reload the Prescaler |
4630 | and the repetition counter(only for TIM1 and TIM8) value immediatly */ |
6618 | and the repetition counter (only for advanced timer) value immediately */ |
4631 | TIMx->EGR = TIM_EGR_UG; |
6619 | TIMx->EGR = TIM_EGR_UG; |
4632 | } |
6620 | } |
4633 | 6621 | ||
4634 | /** |
6622 | /** |
4635 | * @brief Time Ouput Compare 1 configuration |
6623 | * @brief Timer Output Compare 1 configuration |
4636 | * @param TIMx to select the TIM peripheral |
6624 | * @param TIMx to select the TIM peripheral |
4637 | * @param OC_Config : The ouput configuration structure |
6625 | * @param OC_Config The output configuration structure |
4638 | * @retval None |
6626 | * @retval None |
4639 | */ |
6627 | */ |
4640 | static void TIM_OC1_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config) |
6628 | static void TIM_OC1_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config) |
4641 | { |
6629 | { |
4642 | uint32_t tmpccmrx = 0U; |
6630 | uint32_t tmpccmrx; |
4643 | uint32_t tmpccer = 0U; |
6631 | uint32_t tmpccer; |
4644 | uint32_t tmpcr2 = 0U; |
6632 | uint32_t tmpcr2; |
4645 | 6633 | ||
4646 | /* Disable the Channel 1: Reset the CC1E Bit */ |
6634 | /* Disable the Channel 1: Reset the CC1E Bit */ |
4647 | TIMx->CCER &= ~TIM_CCER_CC1E; |
6635 | TIMx->CCER &= ~TIM_CCER_CC1E; |
4648 | 6636 | ||
4649 | /* Get the TIMx CCER register value */ |
6637 | /* Get the TIMx CCER register value */ |
4650 | tmpccer = TIMx->CCER; |
6638 | tmpccer = TIMx->CCER; |
4651 | /* Get the TIMx CR2 register value */ |
6639 | /* Get the TIMx CR2 register value */ |
Line 4663... | Line 6651... | ||
4663 | /* Reset the Output Polarity level */ |
6651 | /* Reset the Output Polarity level */ |
4664 | tmpccer &= ~TIM_CCER_CC1P; |
6652 | tmpccer &= ~TIM_CCER_CC1P; |
4665 | /* Set the Output Compare Polarity */ |
6653 | /* Set the Output Compare Polarity */ |
4666 | tmpccer |= OC_Config->OCPolarity; |
6654 | tmpccer |= OC_Config->OCPolarity; |
4667 | 6655 | ||
4668 | if(IS_TIM_CCXN_INSTANCE(TIMx, TIM_CHANNEL_1)) |
6656 | if (IS_TIM_CCXN_INSTANCE(TIMx, TIM_CHANNEL_1)) |
4669 | { |
6657 | { |
4670 | /* Check parameters */ |
6658 | /* Check parameters */ |
4671 | assert_param(IS_TIM_OCN_POLARITY(OC_Config->OCNPolarity)); |
6659 | assert_param(IS_TIM_OCN_POLARITY(OC_Config->OCNPolarity)); |
4672 | 6660 | ||
4673 | /* Reset the Output N Polarity level */ |
6661 | /* Reset the Output N Polarity level */ |
Line 4676... | Line 6664... | ||
4676 | tmpccer |= OC_Config->OCNPolarity; |
6664 | tmpccer |= OC_Config->OCNPolarity; |
4677 | /* Reset the Output N State */ |
6665 | /* Reset the Output N State */ |
4678 | tmpccer &= ~TIM_CCER_CC1NE; |
6666 | tmpccer &= ~TIM_CCER_CC1NE; |
4679 | } |
6667 | } |
4680 | 6668 | ||
4681 | if(IS_TIM_BREAK_INSTANCE(TIMx)) |
6669 | if (IS_TIM_BREAK_INSTANCE(TIMx)) |
4682 | { |
6670 | { |
4683 | /* Check parameters */ |
6671 | /* Check parameters */ |
4684 | assert_param(IS_TIM_OCNIDLE_STATE(OC_Config->OCNIdleState)); |
6672 | assert_param(IS_TIM_OCNIDLE_STATE(OC_Config->OCNIdleState)); |
4685 | assert_param(IS_TIM_OCIDLE_STATE(OC_Config->OCIdleState)); |
6673 | assert_param(IS_TIM_OCIDLE_STATE(OC_Config->OCIdleState)); |
4686 | 6674 | ||
Line 4690... | Line 6678... | ||
4690 | /* Set the Output Idle state */ |
6678 | /* Set the Output Idle state */ |
4691 | tmpcr2 |= OC_Config->OCIdleState; |
6679 | tmpcr2 |= OC_Config->OCIdleState; |
4692 | /* Set the Output N Idle state */ |
6680 | /* Set the Output N Idle state */ |
4693 | tmpcr2 |= OC_Config->OCNIdleState; |
6681 | tmpcr2 |= OC_Config->OCNIdleState; |
4694 | } |
6682 | } |
- | 6683 | ||
4695 | /* Write to TIMx CR2 */ |
6684 | /* Write to TIMx CR2 */ |
4696 | TIMx->CR2 = tmpcr2; |
6685 | TIMx->CR2 = tmpcr2; |
4697 | 6686 | ||
4698 | /* Write to TIMx CCMR1 */ |
6687 | /* Write to TIMx CCMR1 */ |
4699 | TIMx->CCMR1 = tmpccmrx; |
6688 | TIMx->CCMR1 = tmpccmrx; |
Line 4704... | Line 6693... | ||
4704 | /* Write to TIMx CCER */ |
6693 | /* Write to TIMx CCER */ |
4705 | TIMx->CCER = tmpccer; |
6694 | TIMx->CCER = tmpccer; |
4706 | } |
6695 | } |
4707 | 6696 | ||
4708 | /** |
6697 | /** |
4709 | * @brief Time Ouput Compare 2 configuration |
6698 | * @brief Timer Output Compare 2 configuration |
4710 | * @param TIMx to select the TIM peripheral |
6699 | * @param TIMx to select the TIM peripheral |
4711 | * @param OC_Config : The ouput configuration structure |
6700 | * @param OC_Config The output configuration structure |
4712 | * @retval None |
6701 | * @retval None |
4713 | */ |
6702 | */ |
4714 | void TIM_OC2_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config) |
6703 | void TIM_OC2_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config) |
4715 | { |
6704 | { |
4716 | uint32_t tmpccmrx = 0U; |
6705 | uint32_t tmpccmrx; |
4717 | uint32_t tmpccer = 0U; |
6706 | uint32_t tmpccer; |
4718 | uint32_t tmpcr2 = 0U; |
6707 | uint32_t tmpcr2; |
4719 | 6708 | ||
4720 | /* Disable the Channel 2: Reset the CC2E Bit */ |
6709 | /* Disable the Channel 2: Reset the CC2E Bit */ |
4721 | TIMx->CCER &= ~TIM_CCER_CC2E; |
6710 | TIMx->CCER &= ~TIM_CCER_CC2E; |
4722 | 6711 | ||
4723 | /* Get the TIMx CCER register value */ |
6712 | /* Get the TIMx CCER register value */ |
Line 4738... | Line 6727... | ||
4738 | /* Reset the Output Polarity level */ |
6727 | /* Reset the Output Polarity level */ |
4739 | tmpccer &= ~TIM_CCER_CC2P; |
6728 | tmpccer &= ~TIM_CCER_CC2P; |
4740 | /* Set the Output Compare Polarity */ |
6729 | /* Set the Output Compare Polarity */ |
4741 | tmpccer |= (OC_Config->OCPolarity << 4U); |
6730 | tmpccer |= (OC_Config->OCPolarity << 4U); |
4742 | 6731 | ||
4743 | if(IS_TIM_CCXN_INSTANCE(TIMx, TIM_CHANNEL_2)) |
6732 | if (IS_TIM_CCXN_INSTANCE(TIMx, TIM_CHANNEL_2)) |
4744 | { |
6733 | { |
4745 | assert_param(IS_TIM_OCN_POLARITY(OC_Config->OCNPolarity)); |
6734 | assert_param(IS_TIM_OCN_POLARITY(OC_Config->OCNPolarity)); |
4746 | 6735 | ||
4747 | /* Reset the Output N Polarity level */ |
6736 | /* Reset the Output N Polarity level */ |
4748 | tmpccer &= ~TIM_CCER_CC2NP; |
6737 | tmpccer &= ~TIM_CCER_CC2NP; |
Line 4751... | Line 6740... | ||
4751 | /* Reset the Output N State */ |
6740 | /* Reset the Output N State */ |
4752 | tmpccer &= ~TIM_CCER_CC2NE; |
6741 | tmpccer &= ~TIM_CCER_CC2NE; |
4753 | 6742 | ||
4754 | } |
6743 | } |
4755 | 6744 | ||
4756 | if(IS_TIM_BREAK_INSTANCE(TIMx)) |
6745 | if (IS_TIM_BREAK_INSTANCE(TIMx)) |
4757 | { |
6746 | { |
4758 | /* Check parameters */ |
6747 | /* Check parameters */ |
4759 | assert_param(IS_TIM_OCNIDLE_STATE(OC_Config->OCNIdleState)); |
6748 | assert_param(IS_TIM_OCNIDLE_STATE(OC_Config->OCNIdleState)); |
4760 | assert_param(IS_TIM_OCIDLE_STATE(OC_Config->OCIdleState)); |
6749 | assert_param(IS_TIM_OCIDLE_STATE(OC_Config->OCIdleState)); |
4761 | 6750 | ||
4762 | /* Reset the Output Compare and Output Compare N IDLE State */ |
6751 | /* Reset the Output Compare and Output Compare N IDLE State */ |
4763 | tmpcr2 &= ~TIM_CR2_OIS2; |
6752 | tmpcr2 &= ~TIM_CR2_OIS2; |
4764 | tmpcr2 &= ~TIM_CR2_OIS2N; |
6753 | tmpcr2 &= ~TIM_CR2_OIS2N; |
4765 | /* Set the Output Idle state */ |
6754 | /* Set the Output Idle state */ |
4766 | tmpcr2 |= (OC_Config->OCIdleState << 2); |
6755 | tmpcr2 |= (OC_Config->OCIdleState << 2U); |
4767 | /* Set the Output N Idle state */ |
6756 | /* Set the Output N Idle state */ |
4768 | tmpcr2 |= (OC_Config->OCNIdleState << 2); |
6757 | tmpcr2 |= (OC_Config->OCNIdleState << 2U); |
4769 | } |
6758 | } |
4770 | 6759 | ||
4771 | /* Write to TIMx CR2 */ |
6760 | /* Write to TIMx CR2 */ |
4772 | TIMx->CR2 = tmpcr2; |
6761 | TIMx->CR2 = tmpcr2; |
4773 | 6762 | ||
Line 4780... | Line 6769... | ||
4780 | /* Write to TIMx CCER */ |
6769 | /* Write to TIMx CCER */ |
4781 | TIMx->CCER = tmpccer; |
6770 | TIMx->CCER = tmpccer; |
4782 | } |
6771 | } |
4783 | 6772 | ||
4784 | /** |
6773 | /** |
4785 | * @brief Time Ouput Compare 3 configuration |
6774 | * @brief Timer Output Compare 3 configuration |
4786 | * @param TIMx to select the TIM peripheral |
6775 | * @param TIMx to select the TIM peripheral |
4787 | * @param OC_Config : The ouput configuration structure |
6776 | * @param OC_Config The output configuration structure |
4788 | * @retval None |
6777 | * @retval None |
4789 | */ |
6778 | */ |
4790 | static void TIM_OC3_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config) |
6779 | static void TIM_OC3_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config) |
4791 | { |
6780 | { |
4792 | uint32_t tmpccmrx = 0U; |
6781 | uint32_t tmpccmrx; |
4793 | uint32_t tmpccer = 0U; |
6782 | uint32_t tmpccer; |
4794 | uint32_t tmpcr2 = 0U; |
6783 | uint32_t tmpcr2; |
4795 | 6784 | ||
4796 | /* Disable the Channel 3: Reset the CC2E Bit */ |
6785 | /* Disable the Channel 3: Reset the CC2E Bit */ |
4797 | TIMx->CCER &= ~TIM_CCER_CC3E; |
6786 | TIMx->CCER &= ~TIM_CCER_CC3E; |
4798 | 6787 | ||
4799 | /* Get the TIMx CCER register value */ |
6788 | /* Get the TIMx CCER register value */ |
Line 4813... | Line 6802... | ||
4813 | /* Reset the Output Polarity level */ |
6802 | /* Reset the Output Polarity level */ |
4814 | tmpccer &= ~TIM_CCER_CC3P; |
6803 | tmpccer &= ~TIM_CCER_CC3P; |
4815 | /* Set the Output Compare Polarity */ |
6804 | /* Set the Output Compare Polarity */ |
4816 | tmpccer |= (OC_Config->OCPolarity << 8U); |
6805 | tmpccer |= (OC_Config->OCPolarity << 8U); |
4817 | 6806 | ||
4818 | if(IS_TIM_CCXN_INSTANCE(TIMx, TIM_CHANNEL_3)) |
6807 | if (IS_TIM_CCXN_INSTANCE(TIMx, TIM_CHANNEL_3)) |
4819 | { |
6808 | { |
4820 | assert_param(IS_TIM_OCN_POLARITY(OC_Config->OCNPolarity)); |
6809 | assert_param(IS_TIM_OCN_POLARITY(OC_Config->OCNPolarity)); |
4821 | 6810 | ||
4822 | /* Reset the Output N Polarity level */ |
6811 | /* Reset the Output N Polarity level */ |
4823 | tmpccer &= ~TIM_CCER_CC3NP; |
6812 | tmpccer &= ~TIM_CCER_CC3NP; |
Line 4825... | Line 6814... | ||
4825 | tmpccer |= (OC_Config->OCNPolarity << 8U); |
6814 | tmpccer |= (OC_Config->OCNPolarity << 8U); |
4826 | /* Reset the Output N State */ |
6815 | /* Reset the Output N State */ |
4827 | tmpccer &= ~TIM_CCER_CC3NE; |
6816 | tmpccer &= ~TIM_CCER_CC3NE; |
4828 | } |
6817 | } |
4829 | 6818 | ||
4830 | if(IS_TIM_BREAK_INSTANCE(TIMx)) |
6819 | if (IS_TIM_BREAK_INSTANCE(TIMx)) |
4831 | { |
6820 | { |
4832 | /* Check parameters */ |
6821 | /* Check parameters */ |
4833 | assert_param(IS_TIM_OCNIDLE_STATE(OC_Config->OCNIdleState)); |
6822 | assert_param(IS_TIM_OCNIDLE_STATE(OC_Config->OCNIdleState)); |
4834 | assert_param(IS_TIM_OCIDLE_STATE(OC_Config->OCIdleState)); |
6823 | assert_param(IS_TIM_OCIDLE_STATE(OC_Config->OCIdleState)); |
4835 | 6824 | ||
Line 4854... | Line 6843... | ||
4854 | /* Write to TIMx CCER */ |
6843 | /* Write to TIMx CCER */ |
4855 | TIMx->CCER = tmpccer; |
6844 | TIMx->CCER = tmpccer; |
4856 | } |
6845 | } |
4857 | 6846 | ||
4858 | /** |
6847 | /** |
4859 | * @brief Time Ouput Compare 4 configuration |
6848 | * @brief Timer Output Compare 4 configuration |
4860 | * @param TIMx to select the TIM peripheral |
6849 | * @param TIMx to select the TIM peripheral |
4861 | * @param OC_Config : The ouput configuration structure |
6850 | * @param OC_Config The output configuration structure |
4862 | * @retval None |
6851 | * @retval None |
4863 | */ |
6852 | */ |
4864 | static void TIM_OC4_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config) |
6853 | static void TIM_OC4_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config) |
4865 | { |
6854 | { |
4866 | uint32_t tmpccmrx = 0U; |
6855 | uint32_t tmpccmrx; |
4867 | uint32_t tmpccer = 0U; |
6856 | uint32_t tmpccer; |
4868 | uint32_t tmpcr2 = 0U; |
6857 | uint32_t tmpcr2; |
4869 | 6858 | ||
4870 | /* Disable the Channel 4: Reset the CC4E Bit */ |
6859 | /* Disable the Channel 4: Reset the CC4E Bit */ |
4871 | TIMx->CCER &= ~TIM_CCER_CC4E; |
6860 | TIMx->CCER &= ~TIM_CCER_CC4E; |
4872 | 6861 | ||
4873 | /* Get the TIMx CCER register value */ |
6862 | /* Get the TIMx CCER register value */ |
Line 4888... | Line 6877... | ||
4888 | /* Reset the Output Polarity level */ |
6877 | /* Reset the Output Polarity level */ |
4889 | tmpccer &= ~TIM_CCER_CC4P; |
6878 | tmpccer &= ~TIM_CCER_CC4P; |
4890 | /* Set the Output Compare Polarity */ |
6879 | /* Set the Output Compare Polarity */ |
4891 | tmpccer |= (OC_Config->OCPolarity << 12U); |
6880 | tmpccer |= (OC_Config->OCPolarity << 12U); |
4892 | 6881 | ||
4893 | if(IS_TIM_BREAK_INSTANCE(TIMx)) |
6882 | if (IS_TIM_BREAK_INSTANCE(TIMx)) |
4894 | { |
6883 | { |
- | 6884 | /* Check parameters */ |
|
4895 | assert_param(IS_TIM_OCIDLE_STATE(OC_Config->OCIdleState)); |
6885 | assert_param(IS_TIM_OCIDLE_STATE(OC_Config->OCIdleState)); |
4896 | 6886 | ||
4897 | /* Reset the Output Compare IDLE State */ |
6887 | /* Reset the Output Compare IDLE State */ |
4898 | tmpcr2 &= ~TIM_CR2_OIS4; |
6888 | tmpcr2 &= ~TIM_CR2_OIS4; |
- | 6889 | ||
4899 | /* Set the Output Idle state */ |
6890 | /* Set the Output Idle state */ |
4900 | tmpcr2 |= (OC_Config->OCIdleState << 6); |
6891 | tmpcr2 |= (OC_Config->OCIdleState << 6U); |
4901 | } |
6892 | } |
4902 | 6893 | ||
4903 | /* Write to TIMx CR2 */ |
6894 | /* Write to TIMx CR2 */ |
4904 | TIMx->CR2 = tmpcr2; |
6895 | TIMx->CR2 = tmpcr2; |
4905 | 6896 | ||
Line 4911... | Line 6902... | ||
4911 | 6902 | ||
4912 | /* Write to TIMx CCER */ |
6903 | /* Write to TIMx CCER */ |
4913 | TIMx->CCER = tmpccer; |
6904 | TIMx->CCER = tmpccer; |
4914 | } |
6905 | } |
4915 | 6906 | ||
4916 | - | ||
4917 | /** |
6907 | /** |
4918 | * @brief Time Slave configuration |
6908 | * @brief Slave Timer configuration function |
4919 | * @param htim: pointer to a TIM_HandleTypeDef structure that contains |
6909 | * @param htim TIM handle |
4920 | * the configuration information for TIM module. |
- | |
4921 | * @param sSlaveConfig: The slave configuration structure |
6910 | * @param sSlaveConfig Slave timer configuration |
4922 | * @retval None |
6911 | * @retval None |
4923 | */ |
6912 | */ |
4924 | static void TIM_SlaveTimer_SetConfig(TIM_HandleTypeDef *htim, |
6913 | static HAL_StatusTypeDef TIM_SlaveTimer_SetConfig(TIM_HandleTypeDef *htim, |
4925 | TIM_SlaveConfigTypeDef * sSlaveConfig) |
6914 | TIM_SlaveConfigTypeDef *sSlaveConfig) |
4926 | { |
6915 | { |
4927 | uint32_t tmpsmcr = 0U; |
6916 | uint32_t tmpsmcr; |
4928 | uint32_t tmpccmr1 = 0U; |
6917 | uint32_t tmpccmr1; |
4929 | uint32_t tmpccer = 0U; |
6918 | uint32_t tmpccer; |
4930 | 6919 | ||
4931 | /* Get the TIMx SMCR register value */ |
6920 | /* Get the TIMx SMCR register value */ |
4932 | tmpsmcr = htim->Instance->SMCR; |
6921 | tmpsmcr = htim->Instance->SMCR; |
4933 | 6922 | ||
4934 | /* Reset the Trigger Selection Bits */ |
6923 | /* Reset the Trigger Selection Bits */ |
Line 4945... | Line 6934... | ||
4945 | htim->Instance->SMCR = tmpsmcr; |
6934 | htim->Instance->SMCR = tmpsmcr; |
4946 | 6935 | ||
4947 | /* Configure the trigger prescaler, filter, and polarity */ |
6936 | /* Configure the trigger prescaler, filter, and polarity */ |
4948 | switch (sSlaveConfig->InputTrigger) |
6937 | switch (sSlaveConfig->InputTrigger) |
4949 | { |
6938 | { |
4950 | case TIM_TS_ETRF: |
6939 | case TIM_TS_ETRF: |
4951 | { |
6940 | { |
4952 | /* Check the parameters */ |
6941 | /* Check the parameters */ |
4953 | assert_param(IS_TIM_CLOCKSOURCE_ETRMODE1_INSTANCE(htim->Instance)); |
6942 | assert_param(IS_TIM_CLOCKSOURCE_ETRMODE1_INSTANCE(htim->Instance)); |
4954 | assert_param(IS_TIM_TRIGGERPRESCALER(sSlaveConfig->TriggerPrescaler)); |
6943 | assert_param(IS_TIM_TRIGGERPRESCALER(sSlaveConfig->TriggerPrescaler)); |
4955 | assert_param(IS_TIM_TRIGGERPOLARITY(sSlaveConfig->TriggerPolarity)); |
6944 | assert_param(IS_TIM_TRIGGERPOLARITY(sSlaveConfig->TriggerPolarity)); |
Line 4957... | Line 6946... | ||
4957 | /* Configure the ETR Trigger source */ |
6946 | /* Configure the ETR Trigger source */ |
4958 | TIM_ETR_SetConfig(htim->Instance, |
6947 | TIM_ETR_SetConfig(htim->Instance, |
4959 | sSlaveConfig->TriggerPrescaler, |
6948 | sSlaveConfig->TriggerPrescaler, |
4960 | sSlaveConfig->TriggerPolarity, |
6949 | sSlaveConfig->TriggerPolarity, |
4961 | sSlaveConfig->TriggerFilter); |
6950 | sSlaveConfig->TriggerFilter); |
- | 6951 | break; |
|
4962 | } |
6952 | } |
4963 | break; |
- | |
4964 | 6953 | ||
4965 | case TIM_TS_TI1F_ED: |
6954 | case TIM_TS_TI1F_ED: |
4966 | { |
6955 | { |
4967 | /* Check the parameters */ |
6956 | /* Check the parameters */ |
4968 | assert_param(IS_TIM_CC1_INSTANCE(htim->Instance)); |
6957 | assert_param(IS_TIM_CC1_INSTANCE(htim->Instance)); |
4969 | assert_param(IS_TIM_TRIGGERFILTER(sSlaveConfig->TriggerFilter)); |
6958 | assert_param(IS_TIM_TRIGGERFILTER(sSlaveConfig->TriggerFilter)); |
4970 | 6959 | ||
- | 6960 | if (sSlaveConfig->SlaveMode == TIM_SLAVEMODE_GATED) |
|
- | 6961 | { |
|
- | 6962 | return HAL_ERROR; |
|
- | 6963 | } |
|
- | 6964 | ||
4971 | /* Disable the Channel 1: Reset the CC1E Bit */ |
6965 | /* Disable the Channel 1: Reset the CC1E Bit */ |
4972 | tmpccer = htim->Instance->CCER; |
6966 | tmpccer = htim->Instance->CCER; |
4973 | htim->Instance->CCER &= ~TIM_CCER_CC1E; |
6967 | htim->Instance->CCER &= ~TIM_CCER_CC1E; |
4974 | tmpccmr1 = htim->Instance->CCMR1; |
6968 | tmpccmr1 = htim->Instance->CCMR1; |
4975 | 6969 | ||
Line 4978... | Line 6972... | ||
4978 | tmpccmr1 |= ((sSlaveConfig->TriggerFilter) << 4U); |
6972 | tmpccmr1 |= ((sSlaveConfig->TriggerFilter) << 4U); |
4979 | 6973 | ||
4980 | /* Write to TIMx CCMR1 and CCER registers */ |
6974 | /* Write to TIMx CCMR1 and CCER registers */ |
4981 | htim->Instance->CCMR1 = tmpccmr1; |
6975 | htim->Instance->CCMR1 = tmpccmr1; |
4982 | htim->Instance->CCER = tmpccer; |
6976 | htim->Instance->CCER = tmpccer; |
4983 | 6977 | break; |
|
4984 | } |
6978 | } |
4985 | break; |
- | |
4986 | 6979 | ||
4987 | case TIM_TS_TI1FP1: |
6980 | case TIM_TS_TI1FP1: |
4988 | { |
6981 | { |
4989 | /* Check the parameters */ |
6982 | /* Check the parameters */ |
4990 | assert_param(IS_TIM_CC1_INSTANCE(htim->Instance)); |
6983 | assert_param(IS_TIM_CC1_INSTANCE(htim->Instance)); |
4991 | assert_param(IS_TIM_TRIGGERPOLARITY(sSlaveConfig->TriggerPolarity)); |
6984 | assert_param(IS_TIM_TRIGGERPOLARITY(sSlaveConfig->TriggerPolarity)); |
4992 | assert_param(IS_TIM_TRIGGERFILTER(sSlaveConfig->TriggerFilter)); |
6985 | assert_param(IS_TIM_TRIGGERFILTER(sSlaveConfig->TriggerFilter)); |
4993 | 6986 | ||
4994 | /* Configure TI1 Filter and Polarity */ |
6987 | /* Configure TI1 Filter and Polarity */ |
4995 | TIM_TI1_ConfigInputStage(htim->Instance, |
6988 | TIM_TI1_ConfigInputStage(htim->Instance, |
4996 | sSlaveConfig->TriggerPolarity, |
6989 | sSlaveConfig->TriggerPolarity, |
4997 | sSlaveConfig->TriggerFilter); |
6990 | sSlaveConfig->TriggerFilter); |
- | 6991 | break; |
|
4998 | } |
6992 | } |
4999 | break; |
- | |
5000 | 6993 | ||
5001 | case TIM_TS_TI2FP2: |
6994 | case TIM_TS_TI2FP2: |
5002 | { |
6995 | { |
5003 | /* Check the parameters */ |
6996 | /* Check the parameters */ |
5004 | assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); |
6997 | assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); |
5005 | assert_param(IS_TIM_TRIGGERPOLARITY(sSlaveConfig->TriggerPolarity)); |
6998 | assert_param(IS_TIM_TRIGGERPOLARITY(sSlaveConfig->TriggerPolarity)); |
5006 | assert_param(IS_TIM_TRIGGERFILTER(sSlaveConfig->TriggerFilter)); |
6999 | assert_param(IS_TIM_TRIGGERFILTER(sSlaveConfig->TriggerFilter)); |
5007 | 7000 | ||
5008 | /* Configure TI2 Filter and Polarity */ |
7001 | /* Configure TI2 Filter and Polarity */ |
5009 | TIM_TI2_ConfigInputStage(htim->Instance, |
7002 | TIM_TI2_ConfigInputStage(htim->Instance, |
5010 | sSlaveConfig->TriggerPolarity, |
7003 | sSlaveConfig->TriggerPolarity, |
5011 | sSlaveConfig->TriggerFilter); |
7004 | sSlaveConfig->TriggerFilter); |
5012 | } |
- | |
5013 | break; |
- | |
5014 | - | ||
5015 | case TIM_TS_ITR0: |
- | |
5016 | { |
- | |
5017 | /* Check the parameter */ |
- | |
5018 | assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); |
- | |
5019 | } |
- | |
5020 | break; |
- | |
5021 | - | ||
5022 | case TIM_TS_ITR1: |
- | |
5023 | { |
- | |
5024 | /* Check the parameter */ |
- | |
5025 | assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); |
- | |
5026 | } |
- | |
5027 | break; |
7005 | break; |
5028 | - | ||
5029 | case TIM_TS_ITR2: |
- | |
5030 | { |
- | |
5031 | /* Check the parameter */ |
- | |
5032 | assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); |
- | |
5033 | } |
7006 | } |
5034 | break; |
- | |
5035 | 7007 | ||
- | 7008 | case TIM_TS_ITR0: |
|
- | 7009 | case TIM_TS_ITR1: |
|
- | 7010 | case TIM_TS_ITR2: |
|
5036 | case TIM_TS_ITR3: |
7011 | case TIM_TS_ITR3: |
5037 | { |
7012 | { |
5038 | /* Check the parameter */ |
7013 | /* Check the parameter */ |
5039 | assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); |
7014 | assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); |
5040 | } |
7015 | break; |
5041 | break; |
7016 | } |
5042 | 7017 | ||
5043 | default: |
7018 | default: |
5044 | break; |
7019 | break; |
5045 | } |
7020 | } |
- | 7021 | return HAL_OK; |
|
5046 | } |
7022 | } |
5047 | 7023 | ||
5048 | /** |
7024 | /** |
5049 | * @brief Configure the TI1 as Input. |
7025 | * @brief Configure the TI1 as Input. |
5050 | * @param TIMx to select the TIM peripheral. |
7026 | * @param TIMx to select the TIM peripheral. |
5051 | * @param TIM_ICPolarity : The Input Polarity. |
7027 | * @param TIM_ICPolarity The Input Polarity. |
5052 | * This parameter can be one of the following values: |
7028 | * This parameter can be one of the following values: |
5053 | * @arg TIM_ICPOLARITY_RISING |
7029 | * @arg TIM_ICPOLARITY_RISING |
5054 | * @arg TIM_ICPOLARITY_FALLING |
7030 | * @arg TIM_ICPOLARITY_FALLING |
5055 | * @arg TIM_ICPOLARITY_BOTHEDGE |
7031 | * @arg TIM_ICPOLARITY_BOTHEDGE |
5056 | * @param TIM_ICSelection : specifies the input to be used. |
7032 | * @param TIM_ICSelection specifies the input to be used. |
5057 | * This parameter can be one of the following values: |
7033 | * This parameter can be one of the following values: |
5058 | * @arg TIM_ICSELECTION_DIRECTTI: TIM Input 1 is selected to be connected to IC1. |
7034 | * @arg TIM_ICSELECTION_DIRECTTI: TIM Input 1 is selected to be connected to IC1. |
5059 | * @arg TIM_ICSELECTION_INDIRECTTI: TIM Input 1 is selected to be connected to IC2. |
7035 | * @arg TIM_ICSELECTION_INDIRECTTI: TIM Input 1 is selected to be connected to IC2. |
5060 | * @arg TIM_ICSELECTION_TRC: TIM Input 1 is selected to be connected to TRC. |
7036 | * @arg TIM_ICSELECTION_TRC: TIM Input 1 is selected to be connected to TRC. |
5061 | * @param TIM_ICFilter : Specifies the Input Capture Filter. |
7037 | * @param TIM_ICFilter Specifies the Input Capture Filter. |
5062 | * This parameter must be a value between 0x00 and 0x0F. |
7038 | * This parameter must be a value between 0x00 and 0x0F. |
5063 | * @retval None |
7039 | * @retval None |
5064 | * @note TIM_ICFilter and TIM_ICPolarity are not used in INDIRECT mode as TI2FP1 |
7040 | * @note TIM_ICFilter and TIM_ICPolarity are not used in INDIRECT mode as TI2FP1 |
5065 | * (on channel2 path) is used as the input signal. Therefore CCMR1 must be |
7041 | * (on channel2 path) is used as the input signal. Therefore CCMR1 must be |
5066 | * protected against un-initialized filter and polarity values. |
7042 | * protected against un-initialized filter and polarity values. |
5067 | */ |
7043 | */ |
5068 | void TIM_TI1_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection, |
7044 | void TIM_TI1_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection, |
5069 | uint32_t TIM_ICFilter) |
7045 | uint32_t TIM_ICFilter) |
5070 | { |
7046 | { |
5071 | uint32_t tmpccmr1 = 0U; |
7047 | uint32_t tmpccmr1; |
5072 | uint32_t tmpccer = 0U; |
7048 | uint32_t tmpccer; |
5073 | 7049 | ||
5074 | /* Disable the Channel 1: Reset the CC1E Bit */ |
7050 | /* Disable the Channel 1: Reset the CC1E Bit */ |
5075 | TIMx->CCER &= ~TIM_CCER_CC1E; |
7051 | TIMx->CCER &= ~TIM_CCER_CC1E; |
5076 | tmpccmr1 = TIMx->CCMR1; |
7052 | tmpccmr1 = TIMx->CCMR1; |
5077 | tmpccer = TIMx->CCER; |
7053 | tmpccer = TIMx->CCER; |
5078 | 7054 | ||
5079 | /* Select the Input */ |
7055 | /* Select the Input */ |
5080 | if(IS_TIM_CC2_INSTANCE(TIMx) != RESET) |
7056 | if (IS_TIM_CC2_INSTANCE(TIMx) != RESET) |
5081 | { |
7057 | { |
5082 | tmpccmr1 &= ~TIM_CCMR1_CC1S; |
7058 | tmpccmr1 &= ~TIM_CCMR1_CC1S; |
5083 | tmpccmr1 |= TIM_ICSelection; |
7059 | tmpccmr1 |= TIM_ICSelection; |
5084 | } |
7060 | } |
5085 | else |
7061 | else |
Line 5100... | Line 7076... | ||
5100 | TIMx->CCER = tmpccer; |
7076 | TIMx->CCER = tmpccer; |
5101 | } |
7077 | } |
5102 | 7078 | ||
5103 | /** |
7079 | /** |
5104 | * @brief Configure the Polarity and Filter for TI1. |
7080 | * @brief Configure the Polarity and Filter for TI1. |
5105 | * @param TIMx to select the TIM peripheral. |
7081 | * @param TIMx to select the TIM peripheral. |
5106 | * @param TIM_ICPolarity : The Input Polarity. |
7082 | * @param TIM_ICPolarity The Input Polarity. |
5107 | * This parameter can be one of the following values: |
7083 | * This parameter can be one of the following values: |
5108 | * @arg TIM_ICPOLARITY_RISING |
7084 | * @arg TIM_ICPOLARITY_RISING |
5109 | * @arg TIM_ICPOLARITY_FALLING |
7085 | * @arg TIM_ICPOLARITY_FALLING |
5110 | * @arg TIM_ICPOLARITY_BOTHEDGE |
7086 | * @arg TIM_ICPOLARITY_BOTHEDGE |
5111 | * @param TIM_ICFilter : Specifies the Input Capture Filter. |
7087 | * @param TIM_ICFilter Specifies the Input Capture Filter. |
5112 | * This parameter must be a value between 0x00 and 0x0F. |
7088 | * This parameter must be a value between 0x00 and 0x0F. |
5113 | * @retval None |
7089 | * @retval None |
5114 | */ |
7090 | */ |
5115 | static void TIM_TI1_ConfigInputStage(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICFilter) |
7091 | static void TIM_TI1_ConfigInputStage(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICFilter) |
5116 | { |
7092 | { |
5117 | uint32_t tmpccmr1 = 0U; |
7093 | uint32_t tmpccmr1; |
5118 | uint32_t tmpccer = 0U; |
7094 | uint32_t tmpccer; |
5119 | 7095 | ||
5120 | /* Disable the Channel 1: Reset the CC1E Bit */ |
7096 | /* Disable the Channel 1: Reset the CC1E Bit */ |
5121 | tmpccer = TIMx->CCER; |
7097 | tmpccer = TIMx->CCER; |
5122 | TIMx->CCER &= ~TIM_CCER_CC1E; |
7098 | TIMx->CCER &= ~TIM_CCER_CC1E; |
5123 | tmpccmr1 = TIMx->CCMR1; |
7099 | tmpccmr1 = TIMx->CCMR1; |
Line 5135... | Line 7111... | ||
5135 | TIMx->CCER = tmpccer; |
7111 | TIMx->CCER = tmpccer; |
5136 | } |
7112 | } |
5137 | 7113 | ||
5138 | /** |
7114 | /** |
5139 | * @brief Configure the TI2 as Input. |
7115 | * @brief Configure the TI2 as Input. |
5140 | * @param TIMx to select the TIM peripheral |
7116 | * @param TIMx to select the TIM peripheral |
5141 | * @param TIM_ICPolarity : The Input Polarity. |
7117 | * @param TIM_ICPolarity The Input Polarity. |
5142 | * This parameter can be one of the following values: |
7118 | * This parameter can be one of the following values: |
5143 | * @arg TIM_ICPOLARITY_RISING |
7119 | * @arg TIM_ICPOLARITY_RISING |
5144 | * @arg TIM_ICPOLARITY_FALLING |
7120 | * @arg TIM_ICPOLARITY_FALLING |
5145 | * @arg TIM_ICPOLARITY_BOTHEDGE |
7121 | * @arg TIM_ICPOLARITY_BOTHEDGE |
5146 | * @param TIM_ICSelection : specifies the input to be used. |
7122 | * @param TIM_ICSelection specifies the input to be used. |
5147 | * This parameter can be one of the following values: |
7123 | * This parameter can be one of the following values: |
5148 | * @arg TIM_ICSELECTION_DIRECTTI: TIM Input 2 is selected to be connected to IC2. |
7124 | * @arg TIM_ICSELECTION_DIRECTTI: TIM Input 2 is selected to be connected to IC2. |
5149 | * @arg TIM_ICSELECTION_INDIRECTTI: TIM Input 2 is selected to be connected to IC1. |
7125 | * @arg TIM_ICSELECTION_INDIRECTTI: TIM Input 2 is selected to be connected to IC1. |
5150 | * @arg TIM_ICSELECTION_TRC: TIM Input 2 is selected to be connected to TRC. |
7126 | * @arg TIM_ICSELECTION_TRC: TIM Input 2 is selected to be connected to TRC. |
5151 | * @param TIM_ICFilter : Specifies the Input Capture Filter. |
7127 | * @param TIM_ICFilter Specifies the Input Capture Filter. |
5152 | * This parameter must be a value between 0x00 and 0x0F. |
7128 | * This parameter must be a value between 0x00 and 0x0F. |
5153 | * @retval None |
7129 | * @retval None |
5154 | * @note TIM_ICFilter and TIM_ICPolarity are not used in INDIRECT mode as TI1FP2 |
7130 | * @note TIM_ICFilter and TIM_ICPolarity are not used in INDIRECT mode as TI1FP2 |
5155 | * (on channel1 path) is used as the input signal. Therefore CCMR1 must be |
7131 | * (on channel1 path) is used as the input signal. Therefore CCMR1 must be |
5156 | * protected against un-initialized filter and polarity values. |
7132 | * protected against un-initialized filter and polarity values. |
5157 | */ |
7133 | */ |
5158 | static void TIM_TI2_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection, |
7134 | static void TIM_TI2_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection, |
5159 | uint32_t TIM_ICFilter) |
7135 | uint32_t TIM_ICFilter) |
5160 | { |
7136 | { |
5161 | uint32_t tmpccmr1 = 0U; |
7137 | uint32_t tmpccmr1; |
5162 | uint32_t tmpccer = 0U; |
7138 | uint32_t tmpccer; |
5163 | 7139 | ||
5164 | /* Disable the Channel 2: Reset the CC2E Bit */ |
7140 | /* Disable the Channel 2: Reset the CC2E Bit */ |
5165 | TIMx->CCER &= ~TIM_CCER_CC2E; |
7141 | TIMx->CCER &= ~TIM_CCER_CC2E; |
5166 | tmpccmr1 = TIMx->CCMR1; |
7142 | tmpccmr1 = TIMx->CCMR1; |
5167 | tmpccer = TIMx->CCER; |
7143 | tmpccer = TIMx->CCER; |
Line 5183... | Line 7159... | ||
5183 | TIMx->CCER = tmpccer; |
7159 | TIMx->CCER = tmpccer; |
5184 | } |
7160 | } |
5185 | 7161 | ||
5186 | /** |
7162 | /** |
5187 | * @brief Configure the Polarity and Filter for TI2. |
7163 | * @brief Configure the Polarity and Filter for TI2. |
5188 | * @param TIMx to select the TIM peripheral. |
7164 | * @param TIMx to select the TIM peripheral. |
5189 | * @param TIM_ICPolarity : The Input Polarity. |
7165 | * @param TIM_ICPolarity The Input Polarity. |
5190 | * This parameter can be one of the following values: |
7166 | * This parameter can be one of the following values: |
5191 | * @arg TIM_ICPOLARITY_RISING |
7167 | * @arg TIM_ICPOLARITY_RISING |
5192 | * @arg TIM_ICPOLARITY_FALLING |
7168 | * @arg TIM_ICPOLARITY_FALLING |
5193 | * @arg TIM_ICPOLARITY_BOTHEDGE |
7169 | * @arg TIM_ICPOLARITY_BOTHEDGE |
5194 | * @param TIM_ICFilter : Specifies the Input Capture Filter. |
7170 | * @param TIM_ICFilter Specifies the Input Capture Filter. |
5195 | * This parameter must be a value between 0x00 and 0x0F. |
7171 | * This parameter must be a value between 0x00 and 0x0F. |
5196 | * @retval None |
7172 | * @retval None |
5197 | */ |
7173 | */ |
5198 | static void TIM_TI2_ConfigInputStage(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICFilter) |
7174 | static void TIM_TI2_ConfigInputStage(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICFilter) |
5199 | { |
7175 | { |
5200 | uint32_t tmpccmr1 = 0U; |
7176 | uint32_t tmpccmr1; |
5201 | uint32_t tmpccer = 0U; |
7177 | uint32_t tmpccer; |
5202 | 7178 | ||
5203 | /* Disable the Channel 2: Reset the CC2E Bit */ |
7179 | /* Disable the Channel 2: Reset the CC2E Bit */ |
5204 | TIMx->CCER &= ~TIM_CCER_CC2E; |
7180 | TIMx->CCER &= ~TIM_CCER_CC2E; |
5205 | tmpccmr1 = TIMx->CCMR1; |
7181 | tmpccmr1 = TIMx->CCMR1; |
5206 | tmpccer = TIMx->CCER; |
7182 | tmpccer = TIMx->CCER; |
Line 5218... | Line 7194... | ||
5218 | TIMx->CCER = tmpccer; |
7194 | TIMx->CCER = tmpccer; |
5219 | } |
7195 | } |
5220 | 7196 | ||
5221 | /** |
7197 | /** |
5222 | * @brief Configure the TI3 as Input. |
7198 | * @brief Configure the TI3 as Input. |
5223 | * @param TIMx to select the TIM peripheral |
7199 | * @param TIMx to select the TIM peripheral |
5224 | * @param TIM_ICPolarity : The Input Polarity. |
7200 | * @param TIM_ICPolarity The Input Polarity. |
5225 | * This parameter can be one of the following values: |
7201 | * This parameter can be one of the following values: |
5226 | * @arg TIM_ICPOLARITY_RISING |
7202 | * @arg TIM_ICPOLARITY_RISING |
5227 | * @arg TIM_ICPOLARITY_FALLING |
7203 | * @arg TIM_ICPOLARITY_FALLING |
5228 | * @param TIM_ICSelection : specifies the input to be used. |
7204 | * @param TIM_ICSelection specifies the input to be used. |
5229 | * This parameter can be one of the following values: |
7205 | * This parameter can be one of the following values: |
5230 | * @arg TIM_ICSELECTION_DIRECTTI: TIM Input 3 is selected to be connected to IC3. |
7206 | * @arg TIM_ICSELECTION_DIRECTTI: TIM Input 3 is selected to be connected to IC3. |
5231 | * @arg TIM_ICSELECTION_INDIRECTTI: TIM Input 3 is selected to be connected to IC4. |
7207 | * @arg TIM_ICSELECTION_INDIRECTTI: TIM Input 3 is selected to be connected to IC4. |
5232 | * @arg TIM_ICSELECTION_TRC: TIM Input 3 is selected to be connected to TRC. |
7208 | * @arg TIM_ICSELECTION_TRC: TIM Input 3 is selected to be connected to TRC. |
5233 | * @param TIM_ICFilter : Specifies the Input Capture Filter. |
7209 | * @param TIM_ICFilter Specifies the Input Capture Filter. |
5234 | * This parameter must be a value between 0x00 and 0x0F. |
7210 | * This parameter must be a value between 0x00 and 0x0F. |
5235 | * @retval None |
7211 | * @retval None |
5236 | * @note TIM_ICFilter and TIM_ICPolarity are not used in INDIRECT mode as TI3FP4 |
7212 | * @note TIM_ICFilter and TIM_ICPolarity are not used in INDIRECT mode as TI3FP4 |
5237 | * (on channel1 path) is used as the input signal. Therefore CCMR2 must be |
7213 | * (on channel1 path) is used as the input signal. Therefore CCMR2 must be |
5238 | * protected against un-initialized filter and polarity values. |
7214 | * protected against un-initialized filter and polarity values. |
5239 | */ |
7215 | */ |
5240 | static void TIM_TI3_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection, |
7216 | static void TIM_TI3_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection, |
5241 | uint32_t TIM_ICFilter) |
7217 | uint32_t TIM_ICFilter) |
5242 | { |
7218 | { |
5243 | uint32_t tmpccmr2 = 0U; |
7219 | uint32_t tmpccmr2; |
5244 | uint32_t tmpccer = 0U; |
7220 | uint32_t tmpccer; |
5245 | 7221 | ||
5246 | /* Disable the Channel 3: Reset the CC3E Bit */ |
7222 | /* Disable the Channel 3: Reset the CC3E Bit */ |
5247 | TIMx->CCER &= ~TIM_CCER_CC3E; |
7223 | TIMx->CCER &= ~TIM_CCER_CC3E; |
5248 | tmpccmr2 = TIMx->CCMR2; |
7224 | tmpccmr2 = TIMx->CCMR2; |
5249 | tmpccer = TIMx->CCER; |
7225 | tmpccer = TIMx->CCER; |
Line 5256... | Line 7232... | ||
5256 | tmpccmr2 &= ~TIM_CCMR2_IC3F; |
7232 | tmpccmr2 &= ~TIM_CCMR2_IC3F; |
5257 | tmpccmr2 |= ((TIM_ICFilter << 4U) & TIM_CCMR2_IC3F); |
7233 | tmpccmr2 |= ((TIM_ICFilter << 4U) & TIM_CCMR2_IC3F); |
5258 | 7234 | ||
5259 | /* Select the Polarity and set the CC3E Bit */ |
7235 | /* Select the Polarity and set the CC3E Bit */ |
5260 | tmpccer &= ~(TIM_CCER_CC3P); |
7236 | tmpccer &= ~(TIM_CCER_CC3P); |
5261 | tmpccer |= ((TIM_ICPolarity << 8U) & (TIM_CCER_CC3P)); |
7237 | tmpccer |= ((TIM_ICPolarity << 8U) & TIM_CCER_CC3P); |
5262 | 7238 | ||
5263 | /* Write to TIMx CCMR2 and CCER registers */ |
7239 | /* Write to TIMx CCMR2 and CCER registers */ |
5264 | TIMx->CCMR2 = tmpccmr2; |
7240 | TIMx->CCMR2 = tmpccmr2; |
5265 | TIMx->CCER = tmpccer; |
7241 | TIMx->CCER = tmpccer; |
5266 | } |
7242 | } |
5267 | 7243 | ||
5268 | /** |
7244 | /** |
5269 | * @brief Configure the TI4 as Input. |
7245 | * @brief Configure the TI4 as Input. |
5270 | * @param TIMx to select the TIM peripheral |
7246 | * @param TIMx to select the TIM peripheral |
5271 | * @param TIM_ICPolarity : The Input Polarity. |
7247 | * @param TIM_ICPolarity The Input Polarity. |
5272 | * This parameter can be one of the following values: |
7248 | * This parameter can be one of the following values: |
5273 | * @arg TIM_ICPOLARITY_RISING |
7249 | * @arg TIM_ICPOLARITY_RISING |
5274 | * @arg TIM_ICPOLARITY_FALLING |
7250 | * @arg TIM_ICPOLARITY_FALLING |
5275 | * @param TIM_ICSelection : specifies the input to be used. |
7251 | * @param TIM_ICSelection specifies the input to be used. |
5276 | * This parameter can be one of the following values: |
7252 | * This parameter can be one of the following values: |
5277 | * @arg TIM_ICSELECTION_DIRECTTI: TIM Input 4 is selected to be connected to IC4. |
7253 | * @arg TIM_ICSELECTION_DIRECTTI: TIM Input 4 is selected to be connected to IC4. |
5278 | * @arg TIM_ICSELECTION_INDIRECTTI: TIM Input 4 is selected to be connected to IC3. |
7254 | * @arg TIM_ICSELECTION_INDIRECTTI: TIM Input 4 is selected to be connected to IC3. |
5279 | * @arg TIM_ICSELECTION_TRC: TIM Input 4 is selected to be connected to TRC. |
7255 | * @arg TIM_ICSELECTION_TRC: TIM Input 4 is selected to be connected to TRC. |
5280 | * @param TIM_ICFilter : Specifies the Input Capture Filter. |
7256 | * @param TIM_ICFilter Specifies the Input Capture Filter. |
5281 | * This parameter must be a value between 0x00 and 0x0F. |
7257 | * This parameter must be a value between 0x00 and 0x0F. |
5282 | * @note TIM_ICFilter and TIM_ICPolarity are not used in INDIRECT mode as TI4FP3 |
7258 | * @note TIM_ICFilter and TIM_ICPolarity are not used in INDIRECT mode as TI4FP3 |
5283 | * (on channel1 path) is used as the input signal. Therefore CCMR2 must be |
7259 | * (on channel1 path) is used as the input signal. Therefore CCMR2 must be |
5284 | * protected against un-initialized filter and polarity values. |
7260 | * protected against un-initialized filter and polarity values. |
5285 | * @retval None |
7261 | * @retval None |
5286 | */ |
7262 | */ |
5287 | static void TIM_TI4_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection, |
7263 | static void TIM_TI4_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection, |
5288 | uint32_t TIM_ICFilter) |
7264 | uint32_t TIM_ICFilter) |
5289 | { |
7265 | { |
5290 | uint32_t tmpccmr2 = 0U; |
7266 | uint32_t tmpccmr2; |
5291 | uint32_t tmpccer = 0U; |
7267 | uint32_t tmpccer; |
5292 | 7268 | ||
5293 | /* Disable the Channel 4: Reset the CC4E Bit */ |
7269 | /* Disable the Channel 4: Reset the CC4E Bit */ |
5294 | TIMx->CCER &= ~TIM_CCER_CC4E; |
7270 | TIMx->CCER &= ~TIM_CCER_CC4E; |
5295 | tmpccmr2 = TIMx->CCMR2; |
7271 | tmpccmr2 = TIMx->CCMR2; |
5296 | tmpccer = TIMx->CCER; |
7272 | tmpccer = TIMx->CCER; |
Line 5302... | Line 7278... | ||
5302 | /* Set the filter */ |
7278 | /* Set the filter */ |
5303 | tmpccmr2 &= ~TIM_CCMR2_IC4F; |
7279 | tmpccmr2 &= ~TIM_CCMR2_IC4F; |
5304 | tmpccmr2 |= ((TIM_ICFilter << 12U) & TIM_CCMR2_IC4F); |
7280 | tmpccmr2 |= ((TIM_ICFilter << 12U) & TIM_CCMR2_IC4F); |
5305 | 7281 | ||
5306 | /* Select the Polarity and set the CC4E Bit */ |
7282 | /* Select the Polarity and set the CC4E Bit */ |
5307 | tmpccer &= ~TIM_CCER_CC4P; |
7283 | tmpccer &= ~(TIM_CCER_CC4P); |
5308 | tmpccer |= ((TIM_ICPolarity << 12U) & TIM_CCER_CC4P); |
7284 | tmpccer |= ((TIM_ICPolarity << 12U) & TIM_CCER_CC4P); |
5309 | 7285 | ||
5310 | /* Write to TIMx CCMR2 and CCER registers */ |
7286 | /* Write to TIMx CCMR2 and CCER registers */ |
5311 | TIMx->CCMR2 = tmpccmr2; |
7287 | TIMx->CCMR2 = tmpccmr2; |
5312 | TIMx->CCER = tmpccer ; |
7288 | TIMx->CCER = tmpccer ; |
5313 | } |
7289 | } |
5314 | 7290 | ||
5315 | /** |
7291 | /** |
5316 | * @brief Selects the Input Trigger source |
7292 | * @brief Selects the Input Trigger source |
5317 | * @param TIMx to select the TIM peripheral |
7293 | * @param TIMx to select the TIM peripheral |
5318 | * @param InputTriggerSource : The Input Trigger source. |
7294 | * @param InputTriggerSource The Input Trigger source. |
5319 | * This parameter can be one of the following values: |
7295 | * This parameter can be one of the following values: |
5320 | * @arg TIM_TS_ITR0 : Internal Trigger 0 |
7296 | * @arg TIM_TS_ITR0: Internal Trigger 0 |
5321 | * @arg TIM_TS_ITR1 : Internal Trigger 1 |
7297 | * @arg TIM_TS_ITR1: Internal Trigger 1 |
5322 | * @arg TIM_TS_ITR2 : Internal Trigger 2 |
7298 | * @arg TIM_TS_ITR2: Internal Trigger 2 |
5323 | * @arg TIM_TS_ITR3 : Internal Trigger 3 |
7299 | * @arg TIM_TS_ITR3: Internal Trigger 3 |
5324 | * @arg TIM_TS_TI1F_ED : TI1 Edge Detector |
7300 | * @arg TIM_TS_TI1F_ED: TI1 Edge Detector |
5325 | * @arg TIM_TS_TI1FP1 : Filtered Timer Input 1 |
7301 | * @arg TIM_TS_TI1FP1: Filtered Timer Input 1 |
5326 | * @arg TIM_TS_TI2FP2 : Filtered Timer Input 2 |
7302 | * @arg TIM_TS_TI2FP2: Filtered Timer Input 2 |
5327 | * @arg TIM_TS_ETRF : External Trigger input |
7303 | * @arg TIM_TS_ETRF: External Trigger input |
5328 | * @retval None |
7304 | * @retval None |
5329 | */ |
7305 | */ |
5330 | static void TIM_ITRx_SetConfig(TIM_TypeDef *TIMx, uint16_t InputTriggerSource) |
7306 | static void TIM_ITRx_SetConfig(TIM_TypeDef *TIMx, uint32_t InputTriggerSource) |
5331 | { |
7307 | { |
5332 | uint32_t tmpsmcr = 0U; |
7308 | uint32_t tmpsmcr; |
5333 | 7309 | ||
5334 | /* Get the TIMx SMCR register value */ |
7310 | /* Get the TIMx SMCR register value */ |
5335 | tmpsmcr = TIMx->SMCR; |
7311 | tmpsmcr = TIMx->SMCR; |
5336 | /* Reset the TS Bits */ |
7312 | /* Reset the TS Bits */ |
5337 | tmpsmcr &= ~TIM_SMCR_TS; |
7313 | tmpsmcr &= ~TIM_SMCR_TS; |
5338 | /* Set the Input Trigger source and the slave mode*/ |
7314 | /* Set the Input Trigger source and the slave mode*/ |
5339 | tmpsmcr |= InputTriggerSource | TIM_SLAVEMODE_EXTERNAL1; |
7315 | tmpsmcr |= (InputTriggerSource | TIM_SLAVEMODE_EXTERNAL1); |
5340 | /* Write to TIMx SMCR */ |
7316 | /* Write to TIMx SMCR */ |
5341 | TIMx->SMCR = tmpsmcr; |
7317 | TIMx->SMCR = tmpsmcr; |
5342 | } |
7318 | } |
5343 | /** |
7319 | /** |
5344 | * @brief Configures the TIMx External Trigger (ETR). |
7320 | * @brief Configures the TIMx External Trigger (ETR). |
5345 | * @param TIMx to select the TIM peripheral |
7321 | * @param TIMx to select the TIM peripheral |
5346 | * @param TIM_ExtTRGPrescaler : The external Trigger Prescaler. |
7322 | * @param TIM_ExtTRGPrescaler The external Trigger Prescaler. |
5347 | * This parameter can be one of the following values: |
7323 | * This parameter can be one of the following values: |
5348 | * @arg TIM_ETRPRESCALER_DIV1: ETRP Prescaler OFF. |
7324 | * @arg TIM_ETRPRESCALER_DIV1: ETRP Prescaler OFF. |
5349 | * @arg TIM_ETRPRESCALER_DIV2: ETRP frequency divided by 2. |
7325 | * @arg TIM_ETRPRESCALER_DIV2: ETRP frequency divided by 2. |
5350 | * @arg TIM_ETRPRESCALER_DIV4: ETRP frequency divided by 4. |
7326 | * @arg TIM_ETRPRESCALER_DIV4: ETRP frequency divided by 4. |
5351 | * @arg TIM_ETRPRESCALER_DIV8: ETRP frequency divided by 8. |
7327 | * @arg TIM_ETRPRESCALER_DIV8: ETRP frequency divided by 8. |
5352 | * @param TIM_ExtTRGPolarity : The external Trigger Polarity. |
7328 | * @param TIM_ExtTRGPolarity The external Trigger Polarity. |
5353 | * This parameter can be one of the following values: |
7329 | * This parameter can be one of the following values: |
5354 | * @arg TIM_ETRPOLARITY_INVERTED: active low or falling edge active. |
7330 | * @arg TIM_ETRPOLARITY_INVERTED: active low or falling edge active. |
5355 | * @arg TIM_ETRPOLARITY_NONINVERTED: active high or rising edge active. |
7331 | * @arg TIM_ETRPOLARITY_NONINVERTED: active high or rising edge active. |
5356 | * @param ExtTRGFilter : External Trigger Filter. |
7332 | * @param ExtTRGFilter External Trigger Filter. |
5357 | * This parameter must be a value between 0x00 and 0x0F |
7333 | * This parameter must be a value between 0x00 and 0x0F |
5358 | * @retval None |
7334 | * @retval None |
5359 | */ |
7335 | */ |
5360 | static void TIM_ETR_SetConfig(TIM_TypeDef* TIMx, uint32_t TIM_ExtTRGPrescaler, |
7336 | void TIM_ETR_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ExtTRGPrescaler, |
5361 | uint32_t TIM_ExtTRGPolarity, uint32_t ExtTRGFilter) |
7337 | uint32_t TIM_ExtTRGPolarity, uint32_t ExtTRGFilter) |
5362 | { |
7338 | { |
5363 | uint32_t tmpsmcr = 0U; |
7339 | uint32_t tmpsmcr; |
5364 | 7340 | ||
5365 | tmpsmcr = TIMx->SMCR; |
7341 | tmpsmcr = TIMx->SMCR; |
5366 | 7342 | ||
5367 | /* Reset the ETR Bits */ |
7343 | /* Reset the ETR Bits */ |
5368 | tmpsmcr &= ~(TIM_SMCR_ETF | TIM_SMCR_ETPS | TIM_SMCR_ECE | TIM_SMCR_ETP); |
7344 | tmpsmcr &= ~(TIM_SMCR_ETF | TIM_SMCR_ETPS | TIM_SMCR_ECE | TIM_SMCR_ETP); |
Line 5374... | Line 7350... | ||
5374 | TIMx->SMCR = tmpsmcr; |
7350 | TIMx->SMCR = tmpsmcr; |
5375 | } |
7351 | } |
5376 | 7352 | ||
5377 | /** |
7353 | /** |
5378 | * @brief Enables or disables the TIM Capture Compare Channel x. |
7354 | * @brief Enables or disables the TIM Capture Compare Channel x. |
5379 | * @param TIMx to select the TIM peripheral |
7355 | * @param TIMx to select the TIM peripheral |
5380 | * @param Channel : specifies the TIM Channel |
7356 | * @param Channel specifies the TIM Channel |
5381 | * This parameter can be one of the following values: |
7357 | * This parameter can be one of the following values: |
5382 | * @arg TIM_CHANNEL_1: TIM Channel 1 |
7358 | * @arg TIM_CHANNEL_1: TIM Channel 1 |
5383 | * @arg TIM_CHANNEL_2: TIM Channel 2 |
7359 | * @arg TIM_CHANNEL_2: TIM Channel 2 |
5384 | * @arg TIM_CHANNEL_3: TIM Channel 3 |
7360 | * @arg TIM_CHANNEL_3: TIM Channel 3 |
5385 | * @arg TIM_CHANNEL_4: TIM Channel 4 |
7361 | * @arg TIM_CHANNEL_4: TIM Channel 4 |
5386 | * @param ChannelState : specifies the TIM Channel CCxE bit new state. |
7362 | * @param ChannelState specifies the TIM Channel CCxE bit new state. |
5387 | * This parameter can be: TIM_CCx_ENABLE or TIM_CCx_Disable. |
7363 | * This parameter can be: TIM_CCx_ENABLE or TIM_CCx_DISABLE. |
5388 | * @retval None |
7364 | * @retval None |
5389 | */ |
7365 | */ |
5390 | void TIM_CCxChannelCmd(TIM_TypeDef* TIMx, uint32_t Channel, uint32_t ChannelState) |
7366 | void TIM_CCxChannelCmd(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t ChannelState) |
5391 | { |
7367 | { |
5392 | uint32_t tmp = 0U; |
7368 | uint32_t tmp; |
5393 | 7369 | ||
5394 | /* Check the parameters */ |
7370 | /* Check the parameters */ |
5395 | assert_param(IS_TIM_CC1_INSTANCE(TIMx)); |
7371 | assert_param(IS_TIM_CC1_INSTANCE(TIMx)); |
5396 | assert_param(IS_TIM_CHANNELS(Channel)); |
7372 | assert_param(IS_TIM_CHANNELS(Channel)); |
5397 | 7373 | ||
5398 | tmp = TIM_CCER_CC1E << Channel; |
7374 | tmp = TIM_CCER_CC1E << (Channel & 0x1FU); /* 0x1FU = 31 bits max shift */ |
5399 | 7375 | ||
5400 | /* Reset the CCxE Bit */ |
7376 | /* Reset the CCxE Bit */ |
5401 | TIMx->CCER &= ~tmp; |
7377 | TIMx->CCER &= ~tmp; |
5402 | 7378 | ||
5403 | /* Set or reset the CCxE Bit */ |
7379 | /* Set or reset the CCxE Bit */ |
5404 | TIMx->CCER |= (uint32_t)(ChannelState << Channel); |
7380 | TIMx->CCER |= (uint32_t)(ChannelState << (Channel & 0x1FU)); /* 0x1FU = 31 bits max shift */ |
- | 7381 | } |
|
- | 7382 | ||
- | 7383 | #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) |
|
- | 7384 | /** |
|
- | 7385 | * @brief Reset interrupt callbacks to the legacy weak callbacks. |
|
- | 7386 | * @param htim pointer to a TIM_HandleTypeDef structure that contains |
|
- | 7387 | * the configuration information for TIM module. |
|
- | 7388 | * @retval None |
|
- | 7389 | */ |
|
- | 7390 | void TIM_ResetCallback(TIM_HandleTypeDef *htim) |
|
- | 7391 | { |
|
- | 7392 | /* Reset the TIM callback to the legacy weak callbacks */ |
|
- | 7393 | htim->PeriodElapsedCallback = HAL_TIM_PeriodElapsedCallback; /* Legacy weak PeriodElapsedCallback */ |
|
- | 7394 | htim->PeriodElapsedHalfCpltCallback = HAL_TIM_PeriodElapsedHalfCpltCallback; /* Legacy weak PeriodElapsedHalfCpltCallback */ |
|
- | 7395 | htim->TriggerCallback = HAL_TIM_TriggerCallback; /* Legacy weak TriggerCallback */ |
|
- | 7396 | htim->TriggerHalfCpltCallback = HAL_TIM_TriggerHalfCpltCallback; /* Legacy weak TriggerHalfCpltCallback */ |
|
- | 7397 | htim->IC_CaptureCallback = HAL_TIM_IC_CaptureCallback; /* Legacy weak IC_CaptureCallback */ |
|
- | 7398 | htim->IC_CaptureHalfCpltCallback = HAL_TIM_IC_CaptureHalfCpltCallback; /* Legacy weak IC_CaptureHalfCpltCallback */ |
|
- | 7399 | htim->OC_DelayElapsedCallback = HAL_TIM_OC_DelayElapsedCallback; /* Legacy weak OC_DelayElapsedCallback */ |
|
- | 7400 | htim->PWM_PulseFinishedCallback = HAL_TIM_PWM_PulseFinishedCallback; /* Legacy weak PWM_PulseFinishedCallback */ |
|
- | 7401 | htim->PWM_PulseFinishedHalfCpltCallback = HAL_TIM_PWM_PulseFinishedHalfCpltCallback; /* Legacy weak PWM_PulseFinishedHalfCpltCallback */ |
|
- | 7402 | htim->ErrorCallback = HAL_TIM_ErrorCallback; /* Legacy weak ErrorCallback */ |
|
- | 7403 | htim->CommutationCallback = HAL_TIMEx_CommutCallback; /* Legacy weak CommutationCallback */ |
|
- | 7404 | htim->CommutationHalfCpltCallback = HAL_TIMEx_CommutHalfCpltCallback; /* Legacy weak CommutationHalfCpltCallback */ |
|
- | 7405 | htim->BreakCallback = HAL_TIMEx_BreakCallback; /* Legacy weak BreakCallback */ |
|
5405 | } |
7406 | } |
- | 7407 | #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */ |
|
5406 | 7408 | ||
5407 | /** |
7409 | /** |
5408 | * @} |
7410 | * @} |
5409 | */ |
7411 | */ |
5410 | 7412 |