Rev 49 | Rev 61 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 49 | Rev 50 | ||
|---|---|---|---|
| Line 1... | Line 1... | ||
| 1 | /** |
1 | /** |
| 2 | ****************************************************************************** |
2 | ****************************************************************************** |
| 3 | * @file stm32l1xx_hal_tim.c |
3 | * @file stm32l1xx_hal_tim.c |
| 4 | * @author MCD Application Team |
4 | * @author MCD Application Team |
| 5 | * @version V1.2.0 |
- | |
| 6 | * @date 01-July-2016 |
- | |
| 7 | * @brief TIM HAL module driver |
5 | * @brief TIM HAL module driver. |
| 8 | * This file provides firmware functions to manage the following |
6 | * This file provides firmware functions to manage the following |
| 9 | * functionalities of the Timer (TIM) peripheral: |
7 | * functionalities of the Timer (TIM) peripheral: |
| 10 | * + Time Base Initialization |
8 | * + TIM Time Base Initialization |
| 11 | * + Time Base Start |
9 | * + TIM Time Base Start |
| 12 | * + Time Base Start Interruption |
10 | * + TIM Time Base Start Interruption |
| 13 | * + Time Base Start DMA |
11 | * + TIM Time Base Start DMA |
| 14 | * + Time Output Compare/PWM Initialization |
12 | * + TIM Output Compare/PWM Initialization |
| 15 | * + Time Output Compare/PWM Channel Configuration |
13 | * + TIM Output Compare/PWM Channel Configuration |
| 16 | * + Time Output Compare/PWM Start |
14 | * + TIM Output Compare/PWM Start |
| 17 | * + Time Output Compare/PWM Start Interruption |
15 | * + TIM Output Compare/PWM Start Interruption |
| 18 | * + Time Output Compare/PWM Start DMA |
16 | * + TIM Output Compare/PWM Start DMA |
| 19 | * + Time Input Capture Initialization |
17 | * + TIM Input Capture Initialization |
| 20 | * + Time Input Capture Channel Configuration |
18 | * + TIM Input Capture Channel Configuration |
| 21 | * + Time Input Capture Start |
19 | * + TIM Input Capture Start |
| 22 | * + Time Input Capture Start Interruption |
20 | * + TIM Input Capture Start Interruption |
| 23 | * + Time Input Capture Start DMA |
21 | * + TIM Input Capture Start DMA |
| 24 | * + Time One Pulse Initialization |
22 | * + TIM One Pulse Initialization |
| 25 | * + Time One Pulse Channel Configuration |
23 | * + TIM One Pulse Channel Configuration |
| 26 | * + Time One Pulse Start |
24 | * + TIM One Pulse Start |
| 27 | * + Time Encoder Interface Initialization |
25 | * + TIM Encoder Interface Initialization |
| 28 | * + Time Encoder Interface Start |
26 | * + TIM Encoder Interface Start |
| 29 | * + Time Encoder Interface Start Interruption |
27 | * + TIM Encoder Interface Start Interruption |
| 30 | * + Time Encoder Interface Start DMA |
28 | * + TIM Encoder Interface Start DMA |
| 31 | * + Commutation Event configuration with Interruption and DMA |
29 | * + Commutation Event configuration with Interruption and DMA |
| 32 | * + Time OCRef clear configuration |
30 | * + TIM OCRef clear configuration |
| 33 | * + Time External Clock configuration |
31 | * + TIM External Clock configuration |
| 34 | * + Time Master and Slave synchronization configuration |
- | |
| 35 | @verbatim |
32 | @verbatim |
| 36 | ============================================================================== |
33 | ============================================================================== |
| 37 | ##### TIMER Generic features ##### |
34 | ##### TIMER Generic features ##### |
| 38 | ============================================================================== |
35 | ============================================================================== |
| 39 | [..] The Timer features include: |
36 | [..] The Timer features include: |
| Line 44... | Line 41... | ||
| 44 | (++) Input Capture |
41 | (++) Input Capture |
| 45 | (++) Output Compare |
42 | (++) Output Compare |
| 46 | (++) PWM generation (Edge and Center-aligned Mode) |
43 | (++) PWM generation (Edge and Center-aligned Mode) |
| 47 | (++) One-pulse mode output |
44 | (++) One-pulse mode output |
| 48 | (#) Synchronization circuit to control the timer with external signals and to interconnect |
45 | (#) Synchronization circuit to control the timer with external signals and to interconnect |
| 49 | several timers together. |
46 | several timers together. |
| 50 | (#) Supports incremental (quadrature) encoder |
47 | (#) Supports incremental encoder for positioning purposes |
| 51 | 48 | ||
| 52 | ##### How to use this driver ##### |
49 | ##### How to use this driver ##### |
| 53 | ================================================================================ |
50 | ============================================================================== |
| 54 | [..] |
51 | [..] |
| 55 | (#) Initialize the TIM low level resources by implementing the following functions |
52 | (#) Initialize the TIM low level resources by implementing the following functions |
| 56 | depending from feature used : |
53 | depending on the selected feature: |
| 57 | (++) Time Base : HAL_TIM_Base_MspInit() |
54 | (++) Time Base : HAL_TIM_Base_MspInit() |
| 58 | (++) Input Capture : HAL_TIM_IC_MspInit() |
55 | (++) Input Capture : HAL_TIM_IC_MspInit() |
| 59 | (++) Output Compare : HAL_TIM_OC_MspInit() |
56 | (++) Output Compare : HAL_TIM_OC_MspInit() |
| 60 | (++) PWM generation : HAL_TIM_PWM_MspInit() |
57 | (++) PWM generation : HAL_TIM_PWM_MspInit() |
| 61 | (++) One-pulse mode output : HAL_TIM_OnePulse_MspInit() |
58 | (++) One-pulse mode output : HAL_TIM_OnePulse_MspInit() |
| Line 96... | Line 93... | ||
| 96 | 93 | ||
| 97 | (#) The DMA Burst is managed with the two following functions: |
94 | (#) The DMA Burst is managed with the two following functions: |
| 98 | HAL_TIM_DMABurst_WriteStart() |
95 | HAL_TIM_DMABurst_WriteStart() |
| 99 | HAL_TIM_DMABurst_ReadStart() |
96 | HAL_TIM_DMABurst_ReadStart() |
| 100 | 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 | (+) PeriodElapsedCallback : TIM Period Elapsed Callback. |
|
| - | 131 | (+) PeriodElapsedHalfCpltCallback : TIM Period Elapsed half complete Callback. |
|
| - | 132 | (+) TriggerCallback : TIM Trigger Callback. |
|
| - | 133 | (+) TriggerHalfCpltCallback : TIM Trigger half complete Callback. |
|
| - | 134 | (+) IC_CaptureCallback : TIM Input Capture Callback. |
|
| - | 135 | (+) IC_CaptureHalfCpltCallback : TIM Input Capture half complete Callback. |
|
| - | 136 | (+) OC_DelayElapsedCallback : TIM Output Compare Delay Elapsed Callback. |
|
| - | 137 | (+) PWM_PulseFinishedCallback : TIM PWM Pulse Finished Callback. |
|
| - | 138 | (+) PWM_PulseFinishedHalfCpltCallback : TIM PWM Pulse Finished half complete Callback. |
|
| - | 139 | (+) ErrorCallback : TIM Error Callback. |
|
| - | 140 | ||
| - | 141 | [..] |
|
| - | 142 | By default, after the Init and when the state is HAL_TIM_STATE_RESET |
|
| - | 143 | all interrupt callbacks are set to the corresponding weak functions: |
|
| - | 144 | examples @ref HAL_TIM_TriggerCallback(), @ref HAL_TIM_ErrorCallback(). |
|
| - | 145 | ||
| - | 146 | [..] |
|
| - | 147 | Exception done for MspInit and MspDeInit functions that are reset to the legacy weak |
|
| - | 148 | functionalities in the Init / DeInit only when these callbacks are null |
|
| - | 149 | (not registered beforehand). If not, MspInit or MspDeInit are not null, the Init / DeInit |
|
| - | 150 | keep and use the user MspInit / MspDeInit callbacks(registered beforehand) |
|
| - | 151 | ||
| - | 152 | [..] |
|
| - | 153 | Callbacks can be registered / unregistered in HAL_TIM_STATE_READY state only. |
|
| - | 154 | Exception done MspInit / MspDeInit that can be registered / unregistered |
|
| - | 155 | in HAL_TIM_STATE_READY or HAL_TIM_STATE_RESET state, |
|
| - | 156 | thus registered(user) MspInit / DeInit callbacks can be used during the Init / DeInit. |
|
| - | 157 | In that case first register the MspInit/MspDeInit user callbacks |
|
| - | 158 | using @ref HAL_TIM_RegisterCallback() before calling DeInit or Init function. |
|
| - | 159 | ||
| - | 160 | [..] |
|
| - | 161 | When The compilation define USE_HAL_TIM_REGISTER_CALLBACKS is set to 0 or |
|
| - | 162 | not defined, the callback registration feature is not available and all callbacks |
|
| - | 163 | are set to the corresponding weak functions. |
|
| - | 164 | ||
| 101 | @endverbatim |
165 | @endverbatim |
| 102 | ****************************************************************************** |
166 | ****************************************************************************** |
| 103 | * @attention |
167 | * @attention |
| 104 | * |
168 | * |
| 105 | * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> |
169 | * <h2><center>© Copyright (c) 2016 STMicroelectronics. |
| 106 | * |
- | |
| 107 | * Redistribution and use in source and binary forms, with or without modification, |
- | |
| 108 | * are permitted provided that the following conditions are met: |
- | |
| 109 | * 1. Redistributions of source code must retain the above copyright notice, |
- | |
| 110 | * this list of conditions and the following disclaimer. |
- | |
| 111 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
- | |
| 112 | * this list of conditions and the following disclaimer in the documentation |
- | |
| 113 | * and/or other materials provided with the distribution. |
- | |
| 114 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
- | |
| 115 | * may be used to endorse or promote products derived from this software |
- | |
| 116 | * without specific prior written permission. |
170 | * All rights reserved.</center></h2> |
| 117 | * |
171 | * |
| 118 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
172 | * This software component is licensed by ST under BSD 3-Clause license, |
| 119 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
- | |
| 120 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
- | |
| 121 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
- | |
| 122 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
- | |
| 123 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
173 | * the "License"; You may not use this file except in compliance with the |
| 124 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
174 | * License. You may obtain a copy of the License at: |
| 125 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
- | |
| 126 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
- | |
| 127 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
175 | * opensource.org/licenses/BSD-3-Clause |
| 128 | * |
176 | * |
| 129 | ****************************************************************************** |
177 | ****************************************************************************** |
| 130 | */ |
178 | */ |
| 131 | 179 | ||
| 132 | /* Includes ------------------------------------------------------------------*/ |
180 | /* Includes ------------------------------------------------------------------*/ |
| Line 143... | Line 191... | ||
| 143 | 191 | ||
| 144 | #ifdef HAL_TIM_MODULE_ENABLED |
192 | #ifdef HAL_TIM_MODULE_ENABLED |
| 145 | 193 | ||
| 146 | /* Private typedef -----------------------------------------------------------*/ |
194 | /* Private typedef -----------------------------------------------------------*/ |
| 147 | /* Private define ------------------------------------------------------------*/ |
195 | /* Private define ------------------------------------------------------------*/ |
| 148 | /* Private macro -------------------------------------------------------------*/ |
196 | /* Private macros ------------------------------------------------------------*/ |
| 149 | /* Private variables ---------------------------------------------------------*/ |
197 | /* Private variables ---------------------------------------------------------*/ |
| 150 | /* Private function prototypes -----------------------------------------------*/ |
198 | /* Private function prototypes -----------------------------------------------*/ |
| 151 | /** @defgroup TIM_Private_Functions TIM Private Functions |
199 | /** @addtogroup TIM_Private_Functions |
| 152 | * @{ |
200 | * @{ |
| 153 | */ |
201 | */ |
| 154 | static void TIM_Base_SetConfig(TIM_TypeDef *TIMx, TIM_Base_InitTypeDef *Structure); |
202 | static void TIM_Base_SetConfig(TIM_TypeDef *TIMx, TIM_Base_InitTypeDef *Structure); |
| 155 | static void TIM_OC1_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config); |
203 | static void TIM_OC1_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config); |
| 156 | static void TIM_OC2_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config); |
204 | static void TIM_OC2_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config); |
| 157 | static void TIM_OC3_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config); |
205 | static void TIM_OC3_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config); |
| 158 | static void TIM_OC4_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config); |
206 | static void TIM_OC4_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config); |
| 159 | static void TIM_TI1_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection, uint32_t TIM_ICFilter); |
207 | static void TIM_TI1_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection, |
| - | 208 | uint32_t TIM_ICFilter); |
|
| 160 | static void TIM_TI1_ConfigInputStage(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICFilter); |
209 | static void TIM_TI1_ConfigInputStage(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICFilter); |
| 161 | static void TIM_TI2_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection, uint32_t TIM_ICFilter); |
210 | static void TIM_TI2_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection, |
| - | 211 | uint32_t TIM_ICFilter); |
|
| 162 | static void TIM_TI2_ConfigInputStage(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICFilter); |
212 | static void TIM_TI2_ConfigInputStage(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICFilter); |
| 163 | static void TIM_TI3_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection, uint32_t TIM_ICFilter); |
213 | static void TIM_TI3_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection, |
| - | 214 | uint32_t TIM_ICFilter); |
|
| 164 | static void TIM_TI4_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection, uint32_t TIM_ICFilter); |
215 | static void TIM_TI4_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection, |
| - | 216 | uint32_t TIM_ICFilter); |
|
| 165 | static void TIM_ETR_SetConfig(TIM_TypeDef* TIMx, uint32_t TIM_ExtTRGPrescaler, uint32_t TIM_ExtTRGPolarity, uint32_t ExtTRGFilter); |
217 | static void TIM_ITRx_SetConfig(TIM_TypeDef *TIMx, uint32_t InputTriggerSource); |
| 166 | static void TIM_ITRx_SetConfig(TIM_TypeDef* TIMx, uint16_t InputTriggerSource); |
218 | static void TIM_ETR_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ExtTRGPrescaler, |
| - | 219 | uint32_t TIM_ExtTRGPolarity, uint32_t ExtTRGFilter); |
|
| 167 | static void TIM_CCxChannelCmd(TIM_TypeDef* TIMx, uint32_t Channel, uint32_t ChannelState); |
220 | static void TIM_CCxChannelCmd(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t ChannelState); |
| 168 | static void TIM_DMAPeriodElapsedCplt(DMA_HandleTypeDef *hdma); |
221 | static void TIM_DMAPeriodElapsedCplt(DMA_HandleTypeDef *hdma); |
| - | 222 | static void TIM_DMAPeriodElapsedHalfCplt(DMA_HandleTypeDef *hdma); |
|
| 169 | static void TIM_DMATriggerCplt(DMA_HandleTypeDef *hdma); |
223 | static void TIM_DMATriggerCplt(DMA_HandleTypeDef *hdma); |
| - | 224 | static void TIM_DMATriggerHalfCplt(DMA_HandleTypeDef *hdma); |
|
| - | 225 | static HAL_StatusTypeDef TIM_SlaveTimer_SetConfig(TIM_HandleTypeDef *htim, |
|
| 170 | static void TIM_SlaveTimer_SetConfig(TIM_HandleTypeDef *htim, TIM_SlaveConfigTypeDef * sSlaveConfig); |
226 | TIM_SlaveConfigTypeDef *sSlaveConfig); |
| 171 | - | ||
| 172 | /** |
227 | /** |
| 173 | * @} |
228 | * @} |
| 174 | */ |
229 | */ |
| 175 | - | ||
| 176 | /* Exported functions ---------------------------------------------------------*/ |
230 | /* Exported functions --------------------------------------------------------*/ |
| 177 | 231 | ||
| 178 | /** @defgroup TIM_Exported_Functions TIM Exported Functions |
232 | /** @defgroup TIM_Exported_Functions TIM Exported Functions |
| 179 | * @{ |
233 | * @{ |
| 180 | */ |
234 | */ |
| 181 | 235 | ||
| 182 | /** @defgroup TIM_Exported_Functions_Group1 Time Base functions |
236 | /** @defgroup TIM_Exported_Functions_Group1 TIM Time Base functions |
| 183 | * @brief Time Base functions |
237 | * @brief Time Base functions |
| 184 | * |
238 | * |
| 185 | @verbatim |
239 | @verbatim |
| 186 | ============================================================================== |
240 | ============================================================================== |
| 187 | ##### Time Base functions ##### |
241 | ##### Time Base functions ##### |
| 188 | ============================================================================== |
242 | ============================================================================== |
| 189 | [..] |
243 | [..] |
| Line 200... | Line 254... | ||
| 200 | @endverbatim |
254 | @endverbatim |
| 201 | * @{ |
255 | * @{ |
| 202 | */ |
256 | */ |
| 203 | /** |
257 | /** |
| 204 | * @brief Initializes the TIM Time base Unit according to the specified |
258 | * @brief Initializes the TIM Time base Unit according to the specified |
| 205 | * parameters in the TIM_HandleTypeDef and create the associated handle. |
259 | * parameters in the TIM_HandleTypeDef and initialize the associated handle. |
| - | 260 | * @note Switching from Center Aligned counter mode to Edge counter mode (or reverse) |
|
| - | 261 | * requires a timer reset to avoid unexpected direction |
|
| - | 262 | * due to DIR bit readonly in center aligned mode. |
|
| - | 263 | * Ex: call @ref HAL_TIM_Base_DeInit() before HAL_TIM_Base_Init() |
|
| 206 | * @param htim: TIM Base handle |
264 | * @param htim TIM Base handle |
| 207 | * @retval HAL status |
265 | * @retval HAL status |
| 208 | */ |
266 | */ |
| 209 | HAL_StatusTypeDef HAL_TIM_Base_Init(TIM_HandleTypeDef *htim) |
267 | HAL_StatusTypeDef HAL_TIM_Base_Init(TIM_HandleTypeDef *htim) |
| 210 | { |
268 | { |
| 211 | /* Check the TIM handle allocation */ |
269 | /* Check the TIM handle allocation */ |
| 212 | if(htim == NULL) |
270 | if (htim == NULL) |
| 213 | { |
271 | { |
| 214 | return HAL_ERROR; |
272 | return HAL_ERROR; |
| 215 | } |
273 | } |
| 216 | 274 | ||
| 217 | /* Check the parameters */ |
275 | /* Check the parameters */ |
| 218 | assert_param(IS_TIM_INSTANCE(htim->Instance)); |
276 | assert_param(IS_TIM_INSTANCE(htim->Instance)); |
| 219 | assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode)); |
277 | assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode)); |
| 220 | assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision)); |
278 | assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision)); |
| - | 279 | assert_param(IS_TIM_AUTORELOAD_PRELOAD(htim->Init.AutoReloadPreload)); |
|
| 221 | 280 | ||
| 222 | if(htim->State == HAL_TIM_STATE_RESET) |
281 | if (htim->State == HAL_TIM_STATE_RESET) |
| 223 | { |
282 | { |
| 224 | /* Allocate lock resource and initialize it */ |
283 | /* Allocate lock resource and initialize it */ |
| 225 | htim->Lock = HAL_UNLOCKED; |
284 | htim->Lock = HAL_UNLOCKED; |
| 226 | 285 | ||
| - | 286 | #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) |
|
| - | 287 | /* Reset interrupt callbacks to legacy weak callbacks */ |
|
| - | 288 | TIM_ResetCallback(htim); |
|
| - | 289 | ||
| - | 290 | if (htim->Base_MspInitCallback == NULL) |
|
| - | 291 | { |
|
| - | 292 | htim->Base_MspInitCallback = HAL_TIM_Base_MspInit; |
|
| - | 293 | } |
|
| - | 294 | /* Init the low level hardware : GPIO, CLOCK, NVIC */ |
|
| - | 295 | htim->Base_MspInitCallback(htim); |
|
| - | 296 | #else |
|
| 227 | /* Init the low level hardware : GPIO, CLOCK, NVIC */ |
297 | /* Init the low level hardware : GPIO, CLOCK, NVIC */ |
| 228 | HAL_TIM_Base_MspInit(htim); |
298 | HAL_TIM_Base_MspInit(htim); |
| - | 299 | #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */ |
|
| 229 | } |
300 | } |
| 230 | 301 | ||
| 231 | /* Set the TIM state */ |
302 | /* Set the TIM state */ |
| 232 | htim->State= HAL_TIM_STATE_BUSY; |
303 | htim->State = HAL_TIM_STATE_BUSY; |
| 233 | 304 | ||
| 234 | /* Set the Time Base configuration */ |
305 | /* Set the Time Base configuration */ |
| 235 | TIM_Base_SetConfig(htim->Instance, &htim->Init); |
306 | TIM_Base_SetConfig(htim->Instance, &htim->Init); |
| 236 | 307 | ||
| - | 308 | /* Initialize the DMA burst operation state */ |
|
| - | 309 | htim->DMABurstState = HAL_DMA_BURST_STATE_READY; |
|
| - | 310 | ||
| - | 311 | /* Initialize the TIM channels state */ |
|
| - | 312 | TIM_CHANNEL_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); |
|
| 260 | 352 | ||
| 261 | /* Change TIM state */ |
353 | /* Change TIM state */ |
| 262 | htim->State = HAL_TIM_STATE_RESET; |
354 | htim->State = HAL_TIM_STATE_RESET; |
| 263 | 355 | ||
| 264 | /* Release Lock */ |
356 | /* Release Lock */ |
| Line 267... | Line 359... | ||
| 267 | return HAL_OK; |
359 | return HAL_OK; |
| 268 | } |
360 | } |
| 269 | 361 | ||
| 270 | /** |
362 | /** |
| 271 | * @brief Initializes the TIM Base MSP. |
363 | * @brief Initializes the TIM Base MSP. |
| 272 | * @param htim: TIM handle |
364 | * @param htim TIM Base handle |
| 273 | * @retval None |
365 | * @retval None |
| 274 | */ |
366 | */ |
| 275 | __weak void HAL_TIM_Base_MspInit(TIM_HandleTypeDef *htim) |
367 | __weak void HAL_TIM_Base_MspInit(TIM_HandleTypeDef *htim) |
| 276 | { |
368 | { |
| 277 | /* Prevent unused argument(s) compilation warning */ |
369 | /* Prevent unused argument(s) compilation warning */ |
| 278 | UNUSED(htim); |
370 | UNUSED(htim); |
| 279 | 371 | ||
| 280 | /* NOTE : This function Should not be modified, when the callback is needed, |
372 | /* NOTE : This function should not be modified, when the callback is needed, |
| 281 | the HAL_TIM_Base_MspInit could be implemented in the user file |
373 | the HAL_TIM_Base_MspInit could be implemented in the user file |
| 282 | */ |
374 | */ |
| 283 | } |
375 | } |
| 284 | 376 | ||
| 285 | /** |
377 | /** |
| 286 | * @brief DeInitializes TIM Base MSP. |
378 | * @brief DeInitializes TIM Base MSP. |
| 287 | * @param htim: TIM handle |
379 | * @param htim TIM Base handle |
| 288 | * @retval None |
380 | * @retval None |
| 289 | */ |
381 | */ |
| 290 | __weak void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef *htim) |
382 | __weak void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef *htim) |
| 291 | { |
383 | { |
| 292 | /* Prevent unused argument(s) compilation warning */ |
384 | /* Prevent unused argument(s) compilation warning */ |
| 293 | UNUSED(htim); |
385 | UNUSED(htim); |
| 294 | 386 | ||
| 295 | /* NOTE : This function Should not be modified, when the callback is needed, |
387 | /* NOTE : This function should not be modified, when the callback is needed, |
| 296 | the HAL_TIM_Base_MspDeInit could be implemented in the user file |
388 | the HAL_TIM_Base_MspDeInit could be implemented in the user file |
| 297 | */ |
389 | */ |
| 298 | } |
390 | } |
| 299 | 391 | ||
| 300 | 392 | ||
| 301 | /** |
393 | /** |
| 302 | * @brief Starts the TIM Base generation. |
394 | * @brief Starts the TIM Base generation. |
| 303 | * @param htim : TIM handle |
395 | * @param htim TIM Base handle |
| 304 | * @retval HAL status |
396 | * @retval HAL status |
| 305 | */ |
397 | */ |
| 306 | HAL_StatusTypeDef HAL_TIM_Base_Start(TIM_HandleTypeDef *htim) |
398 | HAL_StatusTypeDef HAL_TIM_Base_Start(TIM_HandleTypeDef *htim) |
| 307 | { |
399 | { |
| - | 400 | uint32_t tmpsmcr; |
|
| - | 401 | ||
| 308 | /* Check the parameters */ |
402 | /* Check the parameters */ |
| 309 | assert_param(IS_TIM_INSTANCE(htim->Instance)); |
403 | assert_param(IS_TIM_INSTANCE(htim->Instance)); |
| 310 | 404 | ||
| 311 | /* Set the TIM state */ |
405 | /* Check the TIM state */ |
| 312 | htim->State= HAL_TIM_STATE_BUSY; |
406 | if (htim->State != HAL_TIM_STATE_READY) |
| - | 407 | { |
|
| - | 408 | return HAL_ERROR; |
|
| - | 409 | } |
|
| 313 | 410 | ||
| 314 | /* Enable the Peripheral */ |
411 | /* Set the TIM state */ |
| 315 | __HAL_TIM_ENABLE(htim); |
412 | htim->State = HAL_TIM_STATE_BUSY; |
| 316 | 413 | ||
| - | 414 | /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */ |
|
| - | 415 | if (IS_TIM_SLAVE_INSTANCE(htim->Instance)) |
|
| - | 416 | { |
|
| - | 417 | tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS; |
|
| - | 418 | if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr)) |
|
| - | 419 | { |
|
| 317 | /* Change the TIM state*/ |
420 | __HAL_TIM_ENABLE(htim); |
| - | 421 | } |
|
| - | 422 | } |
|
| - | 423 | else |
|
| - | 424 | { |
|
| 318 | htim->State= HAL_TIM_STATE_READY; |
425 | __HAL_TIM_ENABLE(htim); |
| - | 426 | } |
|
| 319 | 427 | ||
| 320 | /* Return function status */ |
428 | /* Return function status */ |
| 321 | return HAL_OK; |
429 | return HAL_OK; |
| 322 | } |
430 | } |
| 323 | 431 | ||
| 324 | /** |
432 | /** |
| 325 | * @brief Stops the TIM Base generation. |
433 | * @brief Stops the TIM Base generation. |
| 326 | * @param htim : TIM handle |
434 | * @param htim TIM Base handle |
| 327 | * @retval HAL status |
435 | * @retval HAL status |
| 328 | */ |
436 | */ |
| 329 | HAL_StatusTypeDef HAL_TIM_Base_Stop(TIM_HandleTypeDef *htim) |
437 | HAL_StatusTypeDef HAL_TIM_Base_Stop(TIM_HandleTypeDef *htim) |
| 330 | { |
438 | { |
| 331 | /* Check the parameters */ |
439 | /* Check the parameters */ |
| 332 | assert_param(IS_TIM_INSTANCE(htim->Instance)); |
440 | assert_param(IS_TIM_INSTANCE(htim->Instance)); |
| 333 | 441 | ||
| 334 | /* Set the TIM state */ |
- | |
| 335 | htim->State= HAL_TIM_STATE_BUSY; |
- | |
| 336 | - | ||
| 337 | /* Disable the Peripheral */ |
442 | /* Disable the Peripheral */ |
| 338 | __HAL_TIM_DISABLE(htim); |
443 | __HAL_TIM_DISABLE(htim); |
| 339 | 444 | ||
| 340 | /* Change the TIM state*/ |
445 | /* Set the TIM state */ |
| 341 | htim->State= HAL_TIM_STATE_READY; |
446 | htim->State = HAL_TIM_STATE_READY; |
| 342 | 447 | ||
| 343 | /* Return function status */ |
448 | /* Return function status */ |
| 344 | return HAL_OK; |
449 | return HAL_OK; |
| 345 | } |
450 | } |
| 346 | 451 | ||
| 347 | /** |
452 | /** |
| 348 | * @brief Starts the TIM Base generation in interrupt mode. |
453 | * @brief Starts the TIM Base generation in interrupt mode. |
| 349 | * @param htim : TIM handle |
454 | * @param htim TIM Base handle |
| 350 | * @retval HAL status |
455 | * @retval HAL status |
| 351 | */ |
456 | */ |
| 352 | HAL_StatusTypeDef HAL_TIM_Base_Start_IT(TIM_HandleTypeDef *htim) |
457 | HAL_StatusTypeDef HAL_TIM_Base_Start_IT(TIM_HandleTypeDef *htim) |
| 353 | { |
458 | { |
| - | 459 | uint32_t tmpsmcr; |
|
| - | 460 | ||
| 354 | /* Check the parameters */ |
461 | /* Check the parameters */ |
| 355 | assert_param(IS_TIM_INSTANCE(htim->Instance)); |
462 | assert_param(IS_TIM_INSTANCE(htim->Instance)); |
| 356 | 463 | ||
| 357 | /* Enable the TIM Update interrupt */ |
464 | /* Check the TIM state */ |
| 358 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_UPDATE); |
465 | if (htim->State != HAL_TIM_STATE_READY) |
| - | 466 | { |
|
| - | 467 | return HAL_ERROR; |
|
| - | 468 | } |
|
| - | 469 | ||
| - | 470 | /* Set the TIM state */ |
|
| - | 471 | htim->State = HAL_TIM_STATE_BUSY; |
|
| 359 | 472 | ||
| 360 | /* Enable the Peripheral */ |
473 | /* Enable the TIM Update interrupt */ |
| - | 474 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_UPDATE); |
|
| - | 475 | ||
| - | 476 | /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */ |
|
| - | 477 | if (IS_TIM_SLAVE_INSTANCE(htim->Instance)) |
|
| - | 478 | { |
|
| - | 479 | tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS; |
|
| - | 480 | if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr)) |
|
| - | 481 | { |
|
| - | 482 | __HAL_TIM_ENABLE(htim); |
|
| - | 483 | } |
|
| - | 484 | } |
|
| - | 485 | else |
|
| - | 486 | { |
|
| 361 | __HAL_TIM_ENABLE(htim); |
487 | __HAL_TIM_ENABLE(htim); |
| - | 488 | } |
|
| 362 | 489 | ||
| 363 | /* Return function status */ |
490 | /* Return function status */ |
| 364 | return HAL_OK; |
491 | return HAL_OK; |
| 365 | } |
492 | } |
| 366 | 493 | ||
| 367 | /** |
494 | /** |
| 368 | * @brief Stops the TIM Base generation in interrupt mode. |
495 | * @brief Stops the TIM Base generation in interrupt mode. |
| 369 | * @param htim : TIM handle |
496 | * @param htim TIM Base handle |
| 370 | * @retval HAL status |
497 | * @retval HAL status |
| 371 | */ |
498 | */ |
| 372 | HAL_StatusTypeDef HAL_TIM_Base_Stop_IT(TIM_HandleTypeDef *htim) |
499 | HAL_StatusTypeDef HAL_TIM_Base_Stop_IT(TIM_HandleTypeDef *htim) |
| 373 | { |
500 | { |
| 374 | /* Check the parameters */ |
501 | /* Check the parameters */ |
| 375 | assert_param(IS_TIM_INSTANCE(htim->Instance)); |
502 | assert_param(IS_TIM_INSTANCE(htim->Instance)); |
| - | 503 | ||
| 376 | /* Disable the TIM Update interrupt */ |
504 | /* Disable the TIM Update interrupt */ |
| 377 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_UPDATE); |
505 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_UPDATE); |
| 378 | 506 | ||
| 379 | /* Disable the Peripheral */ |
507 | /* Disable the Peripheral */ |
| 380 | __HAL_TIM_DISABLE(htim); |
508 | __HAL_TIM_DISABLE(htim); |
| 381 | 509 | ||
| - | 510 | /* Set the TIM state */ |
|
| - | 511 | htim->State = HAL_TIM_STATE_READY; |
|
| - | 512 | ||
| 382 | /* Return function status */ |
513 | /* Return function status */ |
| 383 | return HAL_OK; |
514 | return HAL_OK; |
| 384 | } |
515 | } |
| 385 | 516 | ||
| 386 | /** |
517 | /** |
| 387 | * @brief Starts the TIM Base generation in DMA mode. |
518 | * @brief Starts the TIM Base generation in DMA mode. |
| 388 | * @param htim : TIM handle |
519 | * @param htim TIM Base handle |
| 389 | * @param pData: The source Buffer address. |
520 | * @param pData The source Buffer address. |
| 390 | * @param Length: The length of data to be transferred from memory to peripheral. |
521 | * @param Length The length of data to be transferred from memory to peripheral. |
| 391 | * @retval HAL status |
522 | * @retval HAL status |
| 392 | */ |
523 | */ |
| 393 | HAL_StatusTypeDef HAL_TIM_Base_Start_DMA(TIM_HandleTypeDef *htim, uint32_t *pData, uint16_t Length) |
524 | HAL_StatusTypeDef HAL_TIM_Base_Start_DMA(TIM_HandleTypeDef *htim, uint32_t *pData, uint16_t Length) |
| 394 | { |
525 | { |
| - | 526 | uint32_t tmpsmcr; |
|
| - | 527 | ||
| 395 | /* Check the parameters */ |
528 | /* Check the parameters */ |
| 396 | assert_param(IS_TIM_DMA_INSTANCE(htim->Instance)); |
529 | assert_param(IS_TIM_DMA_INSTANCE(htim->Instance)); |
| 397 | 530 | ||
| - | 531 | /* Set the TIM state */ |
|
| 398 | if((htim->State == HAL_TIM_STATE_BUSY)) |
532 | if (htim->State == HAL_TIM_STATE_BUSY) |
| 399 | { |
533 | { |
| 400 | return HAL_BUSY; |
534 | return HAL_BUSY; |
| 401 | } |
535 | } |
| 402 | else if((htim->State == HAL_TIM_STATE_READY)) |
536 | else if (htim->State == HAL_TIM_STATE_READY) |
| 403 | { |
537 | { |
| 404 | if((pData == 0 ) && (Length > 0)) |
538 | if ((pData == NULL) && (Length > 0U)) |
| 405 | { |
539 | { |
| 406 | return HAL_ERROR; |
540 | return HAL_ERROR; |
| 407 | } |
541 | } |
| 408 | else |
542 | else |
| 409 | { |
543 | { |
| Line 413... | Line 547... | ||
| 413 | else |
547 | else |
| 414 | { |
548 | { |
| 415 | return HAL_ERROR; |
549 | return HAL_ERROR; |
| 416 | } |
550 | } |
| 417 | 551 | ||
| 418 | /* Set the DMA Period elapsed callback */ |
552 | /* Set the DMA Period elapsed callbacks */ |
| 419 | htim->hdma[TIM_DMA_ID_UPDATE]->XferCpltCallback = TIM_DMAPeriodElapsedCplt; |
553 | htim->hdma[TIM_DMA_ID_UPDATE]->XferCpltCallback = TIM_DMAPeriodElapsedCplt; |
| - | 554 | htim->hdma[TIM_DMA_ID_UPDATE]->XferHalfCpltCallback = TIM_DMAPeriodElapsedHalfCplt; |
|
| 420 | 555 | ||
| 421 | /* Set the DMA error callback */ |
556 | /* Set the DMA error callback */ |
| 422 | htim->hdma[TIM_DMA_ID_UPDATE]->XferErrorCallback = TIM_DMAError ; |
557 | htim->hdma[TIM_DMA_ID_UPDATE]->XferErrorCallback = TIM_DMAError ; |
| 423 | 558 | ||
| 424 | /* Enable the DMA channel */ |
559 | /* Enable the DMA channel */ |
| 425 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_UPDATE], (uint32_t)pData, (uint32_t)&htim->Instance->ARR, Length); |
560 | if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_UPDATE], (uint32_t)pData, (uint32_t)&htim->Instance->ARR, Length) != HAL_OK) |
| - | 561 | { |
|
| - | 562 | return HAL_ERROR; |
|
| - | 563 | } |
|
| 426 | 564 | ||
| 427 | /* Enable the TIM Update DMA request */ |
565 | /* Enable the TIM Update DMA request */ |
| 428 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_UPDATE); |
566 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_UPDATE); |
| 429 | 567 | ||
| - | 568 | /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */ |
|
| - | 569 | if (IS_TIM_SLAVE_INSTANCE(htim->Instance)) |
|
| - | 570 | { |
|
| - | 571 | tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS; |
|
| - | 572 | if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr)) |
|
| - | 573 | { |
|
| 430 | /* Enable the Peripheral */ |
574 | __HAL_TIM_ENABLE(htim); |
| - | 575 | } |
|
| - | 576 | } |
|
| - | 577 | else |
|
| - | 578 | { |
|
| 431 | __HAL_TIM_ENABLE(htim); |
579 | __HAL_TIM_ENABLE(htim); |
| - | 580 | } |
|
| 432 | 581 | ||
| 433 | /* Return function status */ |
582 | /* Return function status */ |
| 434 | return HAL_OK; |
583 | return HAL_OK; |
| 435 | } |
584 | } |
| 436 | 585 | ||
| 437 | /** |
586 | /** |
| 438 | * @brief Stops the TIM Base generation in DMA mode. |
587 | * @brief Stops the TIM Base generation in DMA mode. |
| 439 | * @param htim : TIM handle |
588 | * @param htim TIM Base handle |
| 440 | * @retval HAL status |
589 | * @retval HAL status |
| 441 | */ |
590 | */ |
| 442 | HAL_StatusTypeDef HAL_TIM_Base_Stop_DMA(TIM_HandleTypeDef *htim) |
591 | HAL_StatusTypeDef HAL_TIM_Base_Stop_DMA(TIM_HandleTypeDef *htim) |
| 443 | { |
592 | { |
| 444 | /* Check the parameters */ |
593 | /* Check the parameters */ |
| 445 | assert_param(IS_TIM_DMA_INSTANCE(htim->Instance)); |
594 | assert_param(IS_TIM_DMA_INSTANCE(htim->Instance)); |
| 446 | 595 | ||
| 447 | /* Disable the TIM Update DMA request */ |
596 | /* Disable the TIM Update DMA request */ |
| 448 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_UPDATE); |
597 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_UPDATE); |
| 449 | 598 | ||
| - | 599 | (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_UPDATE]); |
|
| - | 600 | ||
| 450 | /* Disable the Peripheral */ |
601 | /* Disable the Peripheral */ |
| 451 | __HAL_TIM_DISABLE(htim); |
602 | __HAL_TIM_DISABLE(htim); |
| 452 | 603 | ||
| 453 | /* Change the htim state */ |
604 | /* Set the TIM state */ |
| 454 | htim->State = HAL_TIM_STATE_READY; |
605 | htim->State = HAL_TIM_STATE_READY; |
| 455 | 606 | ||
| 456 | /* Return function status */ |
607 | /* Return function status */ |
| 457 | return HAL_OK; |
608 | return HAL_OK; |
| 458 | } |
609 | } |
| 459 | 610 | ||
| 460 | /** |
611 | /** |
| 461 | * @} |
612 | * @} |
| 462 | */ |
613 | */ |
| 463 | 614 | ||
| 464 | /** @defgroup TIM_Exported_Functions_Group2 Time Output Compare functions |
615 | /** @defgroup TIM_Exported_Functions_Group2 TIM Output Compare functions |
| 465 | * @brief Time Output Compare functions |
616 | * @brief TIM Output Compare functions |
| 466 | * |
617 | * |
| 467 | @verbatim |
618 | @verbatim |
| 468 | ============================================================================== |
619 | ============================================================================== |
| 469 | ##### Time Output Compare functions ##### |
620 | ##### TIM Output Compare functions ##### |
| 470 | ============================================================================== |
621 | ============================================================================== |
| 471 | [..] |
622 | [..] |
| 472 | This section provides functions allowing to: |
623 | This section provides functions allowing to: |
| 473 | (+) Initialize and configure the TIM Output Compare. |
624 | (+) Initialize and configure the TIM Output Compare. |
| 474 | (+) De-initialize the TIM Output Compare. |
625 | (+) De-initialize the TIM Output Compare. |
| 475 | (+) Start the Time Output Compare. |
626 | (+) Start the TIM Output Compare. |
| 476 | (+) Stop the Time Output Compare. |
627 | (+) Stop the TIM Output Compare. |
| 477 | (+) Start the Time Output Compare and enable interrupt. |
628 | (+) Start the TIM Output Compare and enable interrupt. |
| 478 | (+) Stop the Time Output Compare and disable interrupt. |
629 | (+) Stop the TIM Output Compare and disable interrupt. |
| 479 | (+) Start the Time Output Compare and enable DMA transfer. |
630 | (+) Start the TIM Output Compare and enable DMA transfer. |
| 480 | (+) Stop the Time Output Compare and disable DMA transfer. |
631 | (+) Stop the TIM Output Compare and disable DMA transfer. |
| 481 | 632 | ||
| 482 | @endverbatim |
633 | @endverbatim |
| 483 | * @{ |
634 | * @{ |
| 484 | */ |
635 | */ |
| 485 | /** |
636 | /** |
| 486 | * @brief Initializes the TIM Output Compare according to the specified |
637 | * @brief Initializes the TIM Output Compare according to the specified |
| 487 | * parameters in the TIM_HandleTypeDef and create the associated handle. |
638 | * parameters in the TIM_HandleTypeDef and initializes the associated handle. |
| - | 639 | * @note Switching from Center Aligned counter mode to Edge counter mode (or reverse) |
|
| - | 640 | * requires a timer reset to avoid unexpected direction |
|
| - | 641 | * due to DIR bit readonly in center aligned mode. |
|
| - | 642 | * Ex: call @ref HAL_TIM_OC_DeInit() before HAL_TIM_OC_Init() |
|
| 488 | * @param htim: TIM Output Compare handle |
643 | * @param htim TIM Output Compare handle |
| 489 | * @retval HAL status |
644 | * @retval HAL status |
| 490 | */ |
645 | */ |
| 491 | HAL_StatusTypeDef HAL_TIM_OC_Init(TIM_HandleTypeDef* htim) |
646 | HAL_StatusTypeDef HAL_TIM_OC_Init(TIM_HandleTypeDef *htim) |
| 492 | { |
647 | { |
| 493 | /* Check the TIM handle allocation */ |
648 | /* Check the TIM handle allocation */ |
| 494 | if(htim == NULL) |
649 | if (htim == NULL) |
| 495 | { |
650 | { |
| 496 | return HAL_ERROR; |
651 | return HAL_ERROR; |
| 497 | } |
652 | } |
| 498 | 653 | ||
| 499 | /* Check the parameters */ |
654 | /* Check the parameters */ |
| 500 | assert_param(IS_TIM_INSTANCE(htim->Instance)); |
655 | assert_param(IS_TIM_INSTANCE(htim->Instance)); |
| 501 | assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode)); |
656 | assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode)); |
| 502 | assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision)); |
657 | assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision)); |
| - | 658 | assert_param(IS_TIM_AUTORELOAD_PRELOAD(htim->Init.AutoReloadPreload)); |
|
| 503 | 659 | ||
| 504 | if(htim->State == HAL_TIM_STATE_RESET) |
660 | if (htim->State == HAL_TIM_STATE_RESET) |
| 505 | { |
661 | { |
| 506 | /* Allocate lock resource and initialize it */ |
662 | /* Allocate lock resource and initialize it */ |
| 507 | htim->Lock = HAL_UNLOCKED; |
663 | htim->Lock = HAL_UNLOCKED; |
| 508 | 664 | ||
| - | 665 | #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) |
|
| - | 666 | /* Reset interrupt callbacks to legacy weak callbacks */ |
|
| - | 667 | TIM_ResetCallback(htim); |
|
| - | 668 | ||
| - | 669 | if (htim->OC_MspInitCallback == NULL) |
|
| - | 670 | { |
|
| - | 671 | htim->OC_MspInitCallback = HAL_TIM_OC_MspInit; |
|
| - | 672 | } |
|
| - | 673 | /* Init the low level hardware : GPIO, CLOCK, NVIC */ |
|
| - | 674 | htim->OC_MspInitCallback(htim); |
|
| - | 675 | #else |
|
| 509 | /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */ |
676 | /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */ |
| 510 | HAL_TIM_OC_MspInit(htim); |
677 | HAL_TIM_OC_MspInit(htim); |
| - | 678 | #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */ |
|
| 511 | } |
679 | } |
| 512 | 680 | ||
| 513 | /* Set the TIM state */ |
681 | /* Set the TIM state */ |
| 514 | htim->State= HAL_TIM_STATE_BUSY; |
682 | htim->State = HAL_TIM_STATE_BUSY; |
| 515 | 683 | ||
| 516 | /* Init the base time for the Output Compare */ |
684 | /* Init the base time for the Output Compare */ |
| 517 | TIM_Base_SetConfig(htim->Instance, &htim->Init); |
685 | TIM_Base_SetConfig(htim->Instance, &htim->Init); |
| 518 | 686 | ||
| - | 687 | /* Initialize the DMA burst operation state */ |
|
| - | 688 | htim->DMABurstState = HAL_DMA_BURST_STATE_READY; |
|
| - | 689 | ||
| - | 690 | /* Initialize the TIM channels state */ |
|
| - | 691 | TIM_CHANNEL_STATE_SET_ALL(htim, HAL_TIM_CHANNEL_STATE_READY); |
|
| - | 692 | ||
| 519 | /* Initialize the TIM state*/ |
693 | /* Initialize the TIM state*/ |
| 520 | htim->State= HAL_TIM_STATE_READY; |
694 | htim->State = HAL_TIM_STATE_READY; |
| 521 | 695 | ||
| 522 | return HAL_OK; |
696 | return HAL_OK; |
| 523 | } |
697 | } |
| 524 | 698 | ||
| 525 | /** |
699 | /** |
| 526 | * @brief DeInitializes the TIM peripheral |
700 | * @brief DeInitializes the TIM peripheral |
| 527 | * @param htim: TIM Output Compare handle |
701 | * @param htim TIM Output Compare handle |
| 528 | * @retval HAL status |
702 | * @retval HAL status |
| 529 | */ |
703 | */ |
| 530 | HAL_StatusTypeDef HAL_TIM_OC_DeInit(TIM_HandleTypeDef *htim) |
704 | HAL_StatusTypeDef HAL_TIM_OC_DeInit(TIM_HandleTypeDef *htim) |
| 531 | { |
705 | { |
| 532 | /* Check the parameters */ |
706 | /* Check the parameters */ |
| 533 | assert_param(IS_TIM_INSTANCE(htim->Instance)); |
707 | assert_param(IS_TIM_INSTANCE(htim->Instance)); |
| 534 | 708 | ||
| 535 | htim->State = HAL_TIM_STATE_BUSY; |
709 | htim->State = HAL_TIM_STATE_BUSY; |
| 536 | 710 | ||
| 537 | /* Disable the TIM Peripheral Clock */ |
711 | /* Disable the TIM Peripheral Clock */ |
| 538 | __HAL_TIM_DISABLE(htim); |
712 | __HAL_TIM_DISABLE(htim); |
| 539 | 713 | ||
| - | 714 | #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) |
|
| - | 715 | if (htim->OC_MspDeInitCallback == NULL) |
|
| - | 716 | { |
|
| - | 717 | htim->OC_MspDeInitCallback = HAL_TIM_OC_MspDeInit; |
|
| - | 718 | } |
|
| - | 719 | /* DeInit the low level hardware */ |
|
| - | 720 | htim->OC_MspDeInitCallback(htim); |
|
| - | 721 | #else |
|
| 540 | /* DeInit the low level hardware: GPIO, CLOCK, NVIC and DMA */ |
722 | /* DeInit the low level hardware: GPIO, CLOCK, NVIC and DMA */ |
| 541 | HAL_TIM_OC_MspDeInit(htim); |
723 | HAL_TIM_OC_MspDeInit(htim); |
| - | 724 | #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */ |
|
| - | 725 | ||
| - | 726 | /* Change the DMA burst operation state */ |
|
| - | 727 | htim->DMABurstState = HAL_DMA_BURST_STATE_RESET; |
|
| - | 728 | ||
| - | 729 | /* Change the TIM channels state */ |
|
| - | 730 | TIM_CHANNEL_STATE_SET_ALL(htim, HAL_TIM_CHANNEL_STATE_RESET); |
|
| 542 | 731 | ||
| 543 | /* Change TIM state */ |
732 | /* Change TIM state */ |
| 544 | htim->State = HAL_TIM_STATE_RESET; |
733 | htim->State = HAL_TIM_STATE_RESET; |
| 545 | 734 | ||
| 546 | /* Release Lock */ |
735 | /* Release Lock */ |
| Line 549... | Line 738... | ||
| 549 | return HAL_OK; |
738 | return HAL_OK; |
| 550 | } |
739 | } |
| 551 | 740 | ||
| 552 | /** |
741 | /** |
| 553 | * @brief Initializes the TIM Output Compare MSP. |
742 | * @brief Initializes the TIM Output Compare MSP. |
| 554 | * @param htim: TIM handle |
743 | * @param htim TIM Output Compare handle |
| 555 | * @retval None |
744 | * @retval None |
| 556 | */ |
745 | */ |
| 557 | __weak void HAL_TIM_OC_MspInit(TIM_HandleTypeDef *htim) |
746 | __weak void HAL_TIM_OC_MspInit(TIM_HandleTypeDef *htim) |
| 558 | { |
747 | { |
| 559 | /* Prevent unused argument(s) compilation warning */ |
748 | /* Prevent unused argument(s) compilation warning */ |
| 560 | UNUSED(htim); |
749 | UNUSED(htim); |
| 561 | 750 | ||
| 562 | /* NOTE : This function Should not be modified, when the callback is needed, |
751 | /* NOTE : This function should not be modified, when the callback is needed, |
| 563 | the HAL_TIM_OC_MspInit could be implemented in the user file |
752 | the HAL_TIM_OC_MspInit could be implemented in the user file |
| 564 | */ |
753 | */ |
| 565 | } |
754 | } |
| 566 | 755 | ||
| 567 | /** |
756 | /** |
| 568 | * @brief DeInitializes TIM Output Compare MSP. |
757 | * @brief DeInitializes TIM Output Compare MSP. |
| 569 | * @param htim: TIM handle |
758 | * @param htim TIM Output Compare handle |
| 570 | * @retval None |
759 | * @retval None |
| 571 | */ |
760 | */ |
| 572 | __weak void HAL_TIM_OC_MspDeInit(TIM_HandleTypeDef *htim) |
761 | __weak void HAL_TIM_OC_MspDeInit(TIM_HandleTypeDef *htim) |
| 573 | { |
762 | { |
| 574 | /* Prevent unused argument(s) compilation warning */ |
763 | /* Prevent unused argument(s) compilation warning */ |
| 575 | UNUSED(htim); |
764 | UNUSED(htim); |
| 576 | 765 | ||
| 577 | /* NOTE : This function Should not be modified, when the callback is needed, |
766 | /* NOTE : This function should not be modified, when the callback is needed, |
| 578 | the HAL_TIM_OC_MspDeInit could be implemented in the user file |
767 | the HAL_TIM_OC_MspDeInit could be implemented in the user file |
| 579 | */ |
768 | */ |
| 580 | } |
769 | } |
| 581 | 770 | ||
| 582 | /** |
771 | /** |
| 583 | * @brief Starts the TIM Output Compare signal generation. |
772 | * @brief Starts the TIM Output Compare signal generation. |
| 584 | * @param htim : TIM Output Compare handle |
773 | * @param htim TIM Output Compare handle |
| 585 | * @param Channel : TIM Channel to be enabled |
774 | * @param Channel TIM Channel to be enabled |
| 586 | * This parameter can be one of the following values: |
775 | * This parameter can be one of the following values: |
| 587 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
776 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
| 588 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
777 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
| 589 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
778 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
| 590 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
779 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
| 591 | * @retval HAL status |
780 | * @retval HAL status |
| 592 | */ |
781 | */ |
| 593 | HAL_StatusTypeDef HAL_TIM_OC_Start(TIM_HandleTypeDef *htim, uint32_t Channel) |
782 | HAL_StatusTypeDef HAL_TIM_OC_Start(TIM_HandleTypeDef *htim, uint32_t Channel) |
| 594 | { |
783 | { |
| - | 784 | uint32_t tmpsmcr; |
|
| - | 785 | ||
| 595 | /* Check the parameters */ |
786 | /* Check the parameters */ |
| 596 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
787 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
| 597 | 788 | ||
| - | 789 | /* Check the TIM channel state */ |
|
| - | 790 | if (TIM_CHANNEL_STATE_GET(htim, Channel) != HAL_TIM_CHANNEL_STATE_READY) |
|
| - | 791 | { |
|
| - | 792 | return HAL_ERROR; |
|
| - | 793 | } |
|
| - | 794 | ||
| - | 795 | /* Set the TIM channel state */ |
|
| - | 796 | TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_BUSY); |
|
| - | 797 | ||
| 598 | /* Enable the Output compare channel */ |
798 | /* Enable the Output compare channel */ |
| 599 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE); |
799 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE); |
| 600 | 800 | ||
| - | 801 | /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */ |
|
| - | 802 | if (IS_TIM_SLAVE_INSTANCE(htim->Instance)) |
|
| - | 803 | { |
|
| - | 804 | tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS; |
|
| - | 805 | if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr)) |
|
| - | 806 | { |
|
| 601 | /* Enable the Peripheral */ |
807 | __HAL_TIM_ENABLE(htim); |
| - | 808 | } |
|
| - | 809 | } |
|
| - | 810 | else |
|
| - | 811 | { |
|
| 602 | __HAL_TIM_ENABLE(htim); |
812 | __HAL_TIM_ENABLE(htim); |
| - | 813 | } |
|
| 603 | 814 | ||
| 604 | /* Return function status */ |
815 | /* Return function status */ |
| 605 | return HAL_OK; |
816 | return HAL_OK; |
| 606 | } |
817 | } |
| 607 | 818 | ||
| 608 | /** |
819 | /** |
| 609 | * @brief Stops the TIM Output Compare signal generation. |
820 | * @brief Stops the TIM Output Compare signal generation. |
| 610 | * @param htim : TIM handle |
821 | * @param htim TIM Output Compare handle |
| 611 | * @param Channel : TIM Channel to be disabled |
822 | * @param Channel TIM Channel to be disabled |
| 612 | * This parameter can be one of the following values: |
823 | * This parameter can be one of the following values: |
| 613 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
824 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
| 614 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
825 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
| 615 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
826 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
| 616 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
827 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
| 617 | * @retval HAL status |
828 | * @retval HAL status |
| 618 | */ |
829 | */ |
| 619 | HAL_StatusTypeDef HAL_TIM_OC_Stop(TIM_HandleTypeDef *htim, uint32_t Channel) |
830 | HAL_StatusTypeDef HAL_TIM_OC_Stop(TIM_HandleTypeDef *htim, uint32_t Channel) |
| 620 | { |
831 | { |
| 621 | /* Check the parameters */ |
832 | /* Check the parameters */ |
| 622 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
833 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
| 623 | 834 | ||
| Line 625... | Line 836... | ||
| 625 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE); |
836 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE); |
| 626 | 837 | ||
| 627 | /* Disable the Peripheral */ |
838 | /* Disable the Peripheral */ |
| 628 | __HAL_TIM_DISABLE(htim); |
839 | __HAL_TIM_DISABLE(htim); |
| 629 | 840 | ||
| - | 841 | /* Set the TIM channel state */ |
|
| - | 842 | TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY); |
|
| - | 843 | ||
| 630 | /* Return function status */ |
844 | /* Return function status */ |
| 631 | return HAL_OK; |
845 | return HAL_OK; |
| 632 | } |
846 | } |
| 633 | 847 | ||
| 634 | /** |
848 | /** |
| 635 | * @brief Starts the TIM Output Compare signal generation in interrupt mode. |
849 | * @brief Starts the TIM Output Compare signal generation in interrupt mode. |
| 636 | * @param htim : TIM OC handle |
850 | * @param htim TIM Output Compare handle |
| 637 | * @param Channel : TIM Channel to be enabled |
851 | * @param Channel TIM Channel to be enabled |
| 638 | * This parameter can be one of the following values: |
852 | * This parameter can be one of the following values: |
| 639 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
853 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
| 640 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
854 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
| 641 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
855 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
| 642 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
856 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
| 643 | * @retval HAL status |
857 | * @retval HAL status |
| 644 | */ |
858 | */ |
| 645 | HAL_StatusTypeDef HAL_TIM_OC_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel) |
859 | HAL_StatusTypeDef HAL_TIM_OC_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel) |
| 646 | { |
860 | { |
| - | 861 | uint32_t tmpsmcr; |
|
| - | 862 | ||
| 647 | /* Check the parameters */ |
863 | /* Check the parameters */ |
| 648 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
864 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
| 649 | 865 | ||
| - | 866 | /* Check the TIM channel state */ |
|
| - | 867 | if (TIM_CHANNEL_STATE_GET(htim, Channel) != HAL_TIM_CHANNEL_STATE_READY) |
|
| - | 868 | { |
|
| - | 869 | return HAL_ERROR; |
|
| - | 870 | } |
|
| - | 871 | ||
| - | 872 | /* Set the TIM channel state */ |
|
| - | 873 | TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_BUSY); |
|
| - | 874 | ||
| 650 | switch (Channel) |
875 | switch (Channel) |
| 651 | { |
876 | { |
| 652 | case TIM_CHANNEL_1: |
877 | case TIM_CHANNEL_1: |
| 653 | { |
878 | { |
| 654 | /* Enable the TIM Capture/Compare 1 interrupt */ |
879 | /* Enable the TIM Capture/Compare 1 interrupt */ |
| 655 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1); |
880 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1); |
| - | 881 | break; |
|
| 656 | } |
882 | } |
| 657 | break; |
- | |
| 658 | 883 | ||
| 659 | case TIM_CHANNEL_2: |
884 | case TIM_CHANNEL_2: |
| 660 | { |
885 | { |
| 661 | /* Enable the TIM Capture/Compare 2 interrupt */ |
886 | /* Enable the TIM Capture/Compare 2 interrupt */ |
| 662 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2); |
887 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2); |
| - | 888 | break; |
|
| 663 | } |
889 | } |
| 664 | break; |
- | |
| 665 | 890 | ||
| 666 | case TIM_CHANNEL_3: |
891 | case TIM_CHANNEL_3: |
| 667 | { |
892 | { |
| 668 | /* Enable the TIM Capture/Compare 3 interrupt */ |
893 | /* Enable the TIM Capture/Compare 3 interrupt */ |
| 669 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC3); |
894 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC3); |
| - | 895 | break; |
|
| 670 | } |
896 | } |
| 671 | break; |
- | |
| 672 | 897 | ||
| 673 | case TIM_CHANNEL_4: |
898 | case TIM_CHANNEL_4: |
| 674 | { |
899 | { |
| 675 | /* Enable the TIM Capture/Compare 4 interrupt */ |
900 | /* Enable the TIM Capture/Compare 4 interrupt */ |
| 676 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC4); |
901 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC4); |
| - | 902 | break; |
|
| 677 | } |
903 | } |
| 678 | break; |
- | |
| 679 | 904 | ||
| 680 | default: |
905 | default: |
| 681 | break; |
906 | break; |
| 682 | } |
907 | } |
| 683 | 908 | ||
| 684 | /* Enable the Output compare channel */ |
909 | /* Enable the Output compare channel */ |
| 685 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE); |
910 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE); |
| 686 | 911 | ||
| - | 912 | /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */ |
|
| - | 913 | if (IS_TIM_SLAVE_INSTANCE(htim->Instance)) |
|
| - | 914 | { |
|
| - | 915 | tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS; |
|
| - | 916 | if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr)) |
|
| - | 917 | { |
|
| 687 | /* Enable the Peripheral */ |
918 | __HAL_TIM_ENABLE(htim); |
| - | 919 | } |
|
| - | 920 | } |
|
| - | 921 | else |
|
| - | 922 | { |
|
| 688 | __HAL_TIM_ENABLE(htim); |
923 | __HAL_TIM_ENABLE(htim); |
| - | 924 | } |
|
| 689 | 925 | ||
| 690 | /* Return function status */ |
926 | /* Return function status */ |
| 691 | return HAL_OK; |
927 | return HAL_OK; |
| 692 | } |
928 | } |
| 693 | 929 | ||
| 694 | /** |
930 | /** |
| 695 | * @brief Stops the TIM Output Compare signal generation in interrupt mode. |
931 | * @brief Stops the TIM Output Compare signal generation in interrupt mode. |
| 696 | * @param htim : TIM Output Compare handle |
932 | * @param htim TIM Output Compare handle |
| 697 | * @param Channel : TIM Channel to be disabled |
933 | * @param Channel TIM Channel to be disabled |
| 698 | * This parameter can be one of the following values: |
934 | * This parameter can be one of the following values: |
| 699 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
935 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
| 700 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
936 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
| 701 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
937 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
| 702 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
938 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
| 703 | * @retval HAL status |
939 | * @retval HAL status |
| 704 | */ |
940 | */ |
| 705 | HAL_StatusTypeDef HAL_TIM_OC_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel) |
941 | HAL_StatusTypeDef HAL_TIM_OC_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel) |
| 706 | { |
942 | { |
| 707 | /* Check the parameters */ |
943 | /* Check the parameters */ |
| 708 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
944 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
| 709 | 945 | ||
| Line 711... | Line 947... | ||
| 711 | { |
947 | { |
| 712 | case TIM_CHANNEL_1: |
948 | case TIM_CHANNEL_1: |
| 713 | { |
949 | { |
| 714 | /* Disable the TIM Capture/Compare 1 interrupt */ |
950 | /* Disable the TIM Capture/Compare 1 interrupt */ |
| 715 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1); |
951 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1); |
| - | 952 | break; |
|
| 716 | } |
953 | } |
| 717 | break; |
- | |
| 718 | 954 | ||
| 719 | case TIM_CHANNEL_2: |
955 | case TIM_CHANNEL_2: |
| 720 | { |
956 | { |
| 721 | /* Disable the TIM Capture/Compare 2 interrupt */ |
957 | /* Disable the TIM Capture/Compare 2 interrupt */ |
| 722 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2); |
958 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2); |
| - | 959 | break; |
|
| 723 | } |
960 | } |
| 724 | break; |
- | |
| 725 | 961 | ||
| 726 | case TIM_CHANNEL_3: |
962 | case TIM_CHANNEL_3: |
| 727 | { |
963 | { |
| 728 | /* Disable the TIM Capture/Compare 3 interrupt */ |
964 | /* Disable the TIM Capture/Compare 3 interrupt */ |
| 729 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC3); |
965 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC3); |
| - | 966 | break; |
|
| 730 | } |
967 | } |
| 731 | break; |
- | |
| 732 | 968 | ||
| 733 | case TIM_CHANNEL_4: |
969 | case TIM_CHANNEL_4: |
| 734 | { |
970 | { |
| 735 | /* Disable the TIM Capture/Compare 4 interrupt */ |
971 | /* Disable the TIM Capture/Compare 4 interrupt */ |
| 736 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC4); |
972 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC4); |
| - | 973 | break; |
|
| 737 | } |
974 | } |
| 738 | break; |
- | |
| 739 | 975 | ||
| 740 | default: |
976 | default: |
| 741 | break; |
977 | break; |
| 742 | } |
978 | } |
| 743 | 979 | ||
| 744 | /* Disable the Output compare channel */ |
980 | /* Disable the Output compare channel */ |
| 745 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE); |
981 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE); |
| 746 | 982 | ||
| 747 | /* Disable the Peripheral */ |
983 | /* Disable the Peripheral */ |
| 748 | __HAL_TIM_DISABLE(htim); |
984 | __HAL_TIM_DISABLE(htim); |
| 749 | 985 | ||
| - | 986 | /* Set the TIM channel state */ |
|
| - | 987 | TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY); |
|
| - | 988 | ||
| 750 | /* Return function status */ |
989 | /* Return function status */ |
| 751 | return HAL_OK; |
990 | return HAL_OK; |
| 752 | } |
991 | } |
| 753 | 992 | ||
| 754 | /** |
993 | /** |
| 755 | * @brief Starts the TIM Output Compare signal generation in DMA mode. |
994 | * @brief Starts the TIM Output Compare signal generation in DMA mode. |
| 756 | * @param htim : TIM Output Compare handle |
995 | * @param htim TIM Output Compare handle |
| 757 | * @param Channel : TIM Channel to be enabled |
996 | * @param Channel TIM Channel to be enabled |
| 758 | * This parameter can be one of the following values: |
997 | * This parameter can be one of the following values: |
| 759 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
998 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
| 760 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
999 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
| 761 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
1000 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
| 762 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
1001 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
| 763 | * @param pData: The source Buffer address. |
1002 | * @param pData The source Buffer address. |
| 764 | * @param Length: The length of data to be transferred from memory to TIM peripheral |
1003 | * @param Length The length of data to be transferred from memory to TIM peripheral |
| 765 | * @retval HAL status |
1004 | * @retval HAL status |
| 766 | */ |
1005 | */ |
| 767 | HAL_StatusTypeDef HAL_TIM_OC_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length) |
1006 | HAL_StatusTypeDef HAL_TIM_OC_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length) |
| 768 | { |
1007 | { |
| - | 1008 | uint32_t tmpsmcr; |
|
| - | 1009 | ||
| 769 | /* Check the parameters */ |
1010 | /* Check the parameters */ |
| 770 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
1011 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
| 771 | 1012 | ||
| - | 1013 | /* Set the TIM channel state */ |
|
| 772 | if((htim->State == HAL_TIM_STATE_BUSY)) |
1014 | if (TIM_CHANNEL_STATE_GET(htim, Channel) == HAL_TIM_CHANNEL_STATE_BUSY) |
| 773 | { |
1015 | { |
| 774 | return HAL_BUSY; |
1016 | return HAL_BUSY; |
| 775 | } |
1017 | } |
| 776 | else if((htim->State == HAL_TIM_STATE_READY)) |
1018 | else if (TIM_CHANNEL_STATE_GET(htim, Channel) == HAL_TIM_CHANNEL_STATE_READY) |
| 777 | { |
1019 | { |
| 778 | if(((uint32_t)pData == 0 ) && (Length > 0)) |
1020 | if ((pData == NULL) && (Length > 0U)) |
| 779 | { |
1021 | { |
| 780 | return HAL_ERROR; |
1022 | return HAL_ERROR; |
| 781 | } |
1023 | } |
| 782 | else |
1024 | else |
| 783 | { |
1025 | { |
| 784 | htim->State = HAL_TIM_STATE_BUSY; |
1026 | TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_BUSY); |
| 785 | } |
1027 | } |
| 786 | } |
1028 | } |
| 787 | else |
1029 | else |
| 788 | { |
1030 | { |
| 789 | return HAL_ERROR; |
1031 | return HAL_ERROR; |
| Line 791... | Line 1033... | ||
| 791 | 1033 | ||
| 792 | switch (Channel) |
1034 | switch (Channel) |
| 793 | { |
1035 | { |
| 794 | case TIM_CHANNEL_1: |
1036 | case TIM_CHANNEL_1: |
| 795 | { |
1037 | { |
| 796 | /* Set the DMA Period elapsed callback */ |
1038 | /* Set the DMA compare callbacks */ |
| 797 | htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMADelayPulseCplt; |
1039 | htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMADelayPulseCplt; |
| - | 1040 | htim->hdma[TIM_DMA_ID_CC1]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt; |
|
| 798 | 1041 | ||
| 799 | /* Set the DMA error callback */ |
1042 | /* Set the DMA error callback */ |
| 800 | htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ; |
1043 | htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ; |
| 801 | 1044 | ||
| 802 | /* Enable the DMA channel */ |
1045 | /* Enable the DMA channel */ |
| 803 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)pData, (uint32_t)&htim->Instance->CCR1, Length); |
1046 | if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)pData, (uint32_t)&htim->Instance->CCR1, Length) != HAL_OK) |
| - | 1047 | { |
|
| - | 1048 | return HAL_ERROR; |
|
| - | 1049 | } |
|
| 804 | 1050 | ||
| 805 | /* Enable the TIM Capture/Compare 1 DMA request */ |
1051 | /* Enable the TIM Capture/Compare 1 DMA request */ |
| 806 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1); |
1052 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1); |
| - | 1053 | break; |
|
| 807 | } |
1054 | } |
| 808 | break; |
- | |
| 809 | 1055 | ||
| 810 | case TIM_CHANNEL_2: |
1056 | case TIM_CHANNEL_2: |
| 811 | { |
1057 | { |
| 812 | /* Set the DMA Period elapsed callback */ |
1058 | /* Set the DMA compare callbacks */ |
| 813 | htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMADelayPulseCplt; |
1059 | htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMADelayPulseCplt; |
| - | 1060 | htim->hdma[TIM_DMA_ID_CC2]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt; |
|
| 814 | 1061 | ||
| 815 | /* Set the DMA error callback */ |
1062 | /* Set the DMA error callback */ |
| 816 | htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError ; |
1063 | htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError ; |
| 817 | 1064 | ||
| 818 | /* Enable the DMA channel */ |
1065 | /* Enable the DMA channel */ |
| 819 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)pData, (uint32_t)&htim->Instance->CCR2, Length); |
1066 | if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)pData, (uint32_t)&htim->Instance->CCR2, Length) != HAL_OK) |
| - | 1067 | { |
|
| - | 1068 | return HAL_ERROR; |
|
| - | 1069 | } |
|
| 820 | 1070 | ||
| 821 | /* Enable the TIM Capture/Compare 2 DMA request */ |
1071 | /* Enable the TIM Capture/Compare 2 DMA request */ |
| 822 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2); |
1072 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2); |
| - | 1073 | break; |
|
| 823 | } |
1074 | } |
| 824 | break; |
- | |
| 825 | 1075 | ||
| 826 | case TIM_CHANNEL_3: |
1076 | case TIM_CHANNEL_3: |
| 827 | { |
1077 | { |
| 828 | /* Set the DMA Period elapsed callback */ |
1078 | /* Set the DMA compare callbacks */ |
| 829 | htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMADelayPulseCplt; |
1079 | htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMADelayPulseCplt; |
| - | 1080 | htim->hdma[TIM_DMA_ID_CC3]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt; |
|
| 830 | 1081 | ||
| 831 | /* Set the DMA error callback */ |
1082 | /* Set the DMA error callback */ |
| 832 | htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = TIM_DMAError ; |
1083 | htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = TIM_DMAError ; |
| 833 | 1084 | ||
| 834 | /* Enable the DMA channel */ |
1085 | /* Enable the DMA channel */ |
| 835 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)pData, (uint32_t)&htim->Instance->CCR3,Length); |
1086 | if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)pData, (uint32_t)&htim->Instance->CCR3, Length) != HAL_OK) |
| - | 1087 | { |
|
| - | 1088 | return HAL_ERROR; |
|
| 836 | 1089 | } |
|
| 837 | /* Enable the TIM Capture/Compare 3 DMA request */ |
1090 | /* Enable the TIM Capture/Compare 3 DMA request */ |
| 838 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC3); |
1091 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC3); |
| - | 1092 | break; |
|
| 839 | } |
1093 | } |
| 840 | break; |
- | |
| 841 | 1094 | ||
| 842 | case TIM_CHANNEL_4: |
1095 | case TIM_CHANNEL_4: |
| 843 | { |
1096 | { |
| 844 | /* Set the DMA Period elapsed callback */ |
1097 | /* Set the DMA compare callbacks */ |
| 845 | htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = TIM_DMADelayPulseCplt; |
1098 | htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = TIM_DMADelayPulseCplt; |
| - | 1099 | htim->hdma[TIM_DMA_ID_CC4]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt; |
|
| 846 | 1100 | ||
| 847 | /* Set the DMA error callback */ |
1101 | /* Set the DMA error callback */ |
| 848 | htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = TIM_DMAError ; |
1102 | htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = TIM_DMAError ; |
| 849 | 1103 | ||
| 850 | /* Enable the DMA channel */ |
1104 | /* Enable the DMA channel */ |
| 851 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)pData, (uint32_t)&htim->Instance->CCR4, Length); |
1105 | if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)pData, (uint32_t)&htim->Instance->CCR4, Length) != HAL_OK) |
| - | 1106 | { |
|
| - | 1107 | return HAL_ERROR; |
|
| 852 | 1108 | } |
|
| 853 | /* Enable the TIM Capture/Compare 4 DMA request */ |
1109 | /* Enable the TIM Capture/Compare 4 DMA request */ |
| 854 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC4); |
1110 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC4); |
| - | 1111 | break; |
|
| 855 | } |
1112 | } |
| 856 | break; |
- | |
| 857 | 1113 | ||
| 858 | default: |
1114 | default: |
| 859 | break; |
1115 | break; |
| 860 | } |
1116 | } |
| 861 | 1117 | ||
| 862 | /* Enable the Output compare channel */ |
1118 | /* Enable the Output compare channel */ |
| 863 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE); |
1119 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE); |
| 864 | 1120 | ||
| - | 1121 | /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */ |
|
| - | 1122 | if (IS_TIM_SLAVE_INSTANCE(htim->Instance)) |
|
| - | 1123 | { |
|
| - | 1124 | tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS; |
|
| - | 1125 | if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr)) |
|
| - | 1126 | { |
|
| 865 | /* Enable the Peripheral */ |
1127 | __HAL_TIM_ENABLE(htim); |
| - | 1128 | } |
|
| - | 1129 | } |
|
| - | 1130 | else |
|
| - | 1131 | { |
|
| 866 | __HAL_TIM_ENABLE(htim); |
1132 | __HAL_TIM_ENABLE(htim); |
| - | 1133 | } |
|
| 867 | 1134 | ||
| 868 | /* Return function status */ |
1135 | /* Return function status */ |
| 869 | return HAL_OK; |
1136 | return HAL_OK; |
| 870 | } |
1137 | } |
| 871 | 1138 | ||
| 872 | /** |
1139 | /** |
| 873 | * @brief Stops the TIM Output Compare signal generation in DMA mode. |
1140 | * @brief Stops the TIM Output Compare signal generation in DMA mode. |
| 874 | * @param htim : TIM Output Compare handle |
1141 | * @param htim TIM Output Compare handle |
| 875 | * @param Channel : TIM Channel to be disabled |
1142 | * @param Channel TIM Channel to be disabled |
| 876 | * This parameter can be one of the following values: |
1143 | * This parameter can be one of the following values: |
| 877 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
1144 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
| 878 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
1145 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
| 879 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
1146 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
| 880 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
1147 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
| 881 | * @retval HAL status |
1148 | * @retval HAL status |
| 882 | */ |
1149 | */ |
| 883 | HAL_StatusTypeDef HAL_TIM_OC_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel) |
1150 | HAL_StatusTypeDef HAL_TIM_OC_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel) |
| 884 | { |
1151 | { |
| 885 | /* Check the parameters */ |
1152 | /* Check the parameters */ |
| 886 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
1153 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
| 887 | 1154 | ||
| Line 889... | Line 1156... | ||
| 889 | { |
1156 | { |
| 890 | case TIM_CHANNEL_1: |
1157 | case TIM_CHANNEL_1: |
| 891 | { |
1158 | { |
| 892 | /* Disable the TIM Capture/Compare 1 DMA request */ |
1159 | /* Disable the TIM Capture/Compare 1 DMA request */ |
| 893 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1); |
1160 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1); |
| - | 1161 | (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC1]); |
|
| - | 1162 | break; |
|
| 894 | } |
1163 | } |
| 895 | break; |
- | |
| 896 | 1164 | ||
| 897 | case TIM_CHANNEL_2: |
1165 | case TIM_CHANNEL_2: |
| 898 | { |
1166 | { |
| 899 | /* Disable the TIM Capture/Compare 2 DMA request */ |
1167 | /* Disable the TIM Capture/Compare 2 DMA request */ |
| 900 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2); |
1168 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2); |
| - | 1169 | (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC2]); |
|
| - | 1170 | break; |
|
| 901 | } |
1171 | } |
| 902 | break; |
- | |
| 903 | 1172 | ||
| 904 | case TIM_CHANNEL_3: |
1173 | case TIM_CHANNEL_3: |
| 905 | { |
1174 | { |
| 906 | /* Disable the TIM Capture/Compare 3 DMA request */ |
1175 | /* Disable the TIM Capture/Compare 3 DMA request */ |
| 907 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC3); |
1176 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC3); |
| - | 1177 | (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC3]); |
|
| - | 1178 | break; |
|
| 908 | } |
1179 | } |
| 909 | break; |
- | |
| 910 | 1180 | ||
| 911 | case TIM_CHANNEL_4: |
1181 | case TIM_CHANNEL_4: |
| 912 | { |
1182 | { |
| 913 | /* Disable the TIM Capture/Compare 4 interrupt */ |
1183 | /* Disable the TIM Capture/Compare 4 interrupt */ |
| 914 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC4); |
1184 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC4); |
| - | 1185 | (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC4]); |
|
| - | 1186 | break; |
|
| 915 | } |
1187 | } |
| 916 | break; |
- | |
| 917 | 1188 | ||
| 918 | default: |
1189 | default: |
| 919 | break; |
1190 | break; |
| 920 | } |
1191 | } |
| 921 | 1192 | ||
| 922 | /* Disable the Output compare channel */ |
1193 | /* Disable the Output compare channel */ |
| 923 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE); |
1194 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE); |
| 924 | 1195 | ||
| 925 | /* Disable the Peripheral */ |
1196 | /* Disable the Peripheral */ |
| 926 | __HAL_TIM_DISABLE(htim); |
1197 | __HAL_TIM_DISABLE(htim); |
| 927 | 1198 | ||
| 928 | /* Change the htim state */ |
1199 | /* Set the TIM channel state */ |
| 929 | htim->State = HAL_TIM_STATE_READY; |
1200 | TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY); |
| 930 | 1201 | ||
| 931 | /* Return function status */ |
1202 | /* Return function status */ |
| 932 | return HAL_OK; |
1203 | return HAL_OK; |
| 933 | } |
1204 | } |
| 934 | 1205 | ||
| 935 | /** |
1206 | /** |
| 936 | * @} |
1207 | * @} |
| 937 | */ |
1208 | */ |
| 938 | 1209 | ||
| 939 | /** @defgroup TIM_Exported_Functions_Group3 Time PWM functions |
1210 | /** @defgroup TIM_Exported_Functions_Group3 TIM PWM functions |
| 940 | * @brief Time PWM functions |
1211 | * @brief TIM PWM functions |
| 941 | * |
1212 | * |
| 942 | @verbatim |
1213 | @verbatim |
| 943 | ============================================================================== |
1214 | ============================================================================== |
| 944 | ##### Time PWM functions ##### |
1215 | ##### TIM PWM functions ##### |
| 945 | ============================================================================== |
1216 | ============================================================================== |
| 946 | [..] |
1217 | [..] |
| 947 | This section provides functions allowing to: |
1218 | This section provides functions allowing to: |
| 948 | (+) Initialize and configure the TIM PWM. |
1219 | (+) Initialize and configure the TIM PWM. |
| 949 | (+) De-initialize the TIM PWM. |
1220 | (+) De-initialize the TIM PWM. |
| 950 | (+) Start the Time PWM. |
1221 | (+) Start the TIM PWM. |
| 951 | (+) Stop the Time PWM. |
1222 | (+) Stop the TIM PWM. |
| 952 | (+) Start the Time PWM and enable interrupt. |
1223 | (+) Start the TIM PWM and enable interrupt. |
| 953 | (+) Stop the Time PWM and disable interrupt. |
1224 | (+) Stop the TIM PWM and disable interrupt. |
| 954 | (+) Start the Time PWM and enable DMA transfer. |
1225 | (+) Start the TIM PWM and enable DMA transfer. |
| 955 | (+) Stop the Time PWM and disable DMA transfer. |
1226 | (+) Stop the TIM PWM and disable DMA transfer. |
| 956 | 1227 | ||
| 957 | @endverbatim |
1228 | @endverbatim |
| 958 | * @{ |
1229 | * @{ |
| 959 | */ |
1230 | */ |
| 960 | /** |
1231 | /** |
| 961 | * @brief Initializes the TIM PWM Time Base according to the specified |
1232 | * @brief Initializes the TIM PWM Time Base according to the specified |
| 962 | * parameters in the TIM_HandleTypeDef and create the associated handle. |
1233 | * parameters in the TIM_HandleTypeDef and initializes the associated handle. |
| - | 1234 | * @note Switching from Center Aligned counter mode to Edge counter mode (or reverse) |
|
| - | 1235 | * requires a timer reset to avoid unexpected direction |
|
| - | 1236 | * due to DIR bit readonly in center aligned mode. |
|
| - | 1237 | * Ex: call @ref HAL_TIM_PWM_DeInit() before HAL_TIM_PWM_Init() |
|
| 963 | * @param htim: TIM handle |
1238 | * @param htim TIM PWM handle |
| 964 | * @retval HAL status |
1239 | * @retval HAL status |
| 965 | */ |
1240 | */ |
| 966 | HAL_StatusTypeDef HAL_TIM_PWM_Init(TIM_HandleTypeDef *htim) |
1241 | HAL_StatusTypeDef HAL_TIM_PWM_Init(TIM_HandleTypeDef *htim) |
| 967 | { |
1242 | { |
| 968 | /* Check the TIM handle allocation */ |
1243 | /* Check the TIM handle allocation */ |
| 969 | if(htim == NULL) |
1244 | if (htim == NULL) |
| 970 | { |
1245 | { |
| 971 | return HAL_ERROR; |
1246 | return HAL_ERROR; |
| 972 | } |
1247 | } |
| 973 | 1248 | ||
| 974 | /* Check the parameters */ |
1249 | /* Check the parameters */ |
| 975 | assert_param(IS_TIM_INSTANCE(htim->Instance)); |
1250 | assert_param(IS_TIM_INSTANCE(htim->Instance)); |
| 976 | assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode)); |
1251 | assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode)); |
| 977 | assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision)); |
1252 | assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision)); |
| - | 1253 | assert_param(IS_TIM_AUTORELOAD_PRELOAD(htim->Init.AutoReloadPreload)); |
|
| 978 | 1254 | ||
| 979 | if(htim->State == HAL_TIM_STATE_RESET) |
1255 | if (htim->State == HAL_TIM_STATE_RESET) |
| 980 | { |
1256 | { |
| 981 | /* Allocate lock resource and initialize it */ |
1257 | /* Allocate lock resource and initialize it */ |
| 982 | htim->Lock = HAL_UNLOCKED; |
1258 | htim->Lock = HAL_UNLOCKED; |
| 983 | 1259 | ||
| - | 1260 | #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) |
|
| - | 1261 | /* Reset interrupt callbacks to legacy weak callbacks */ |
|
| - | 1262 | TIM_ResetCallback(htim); |
|
| - | 1263 | ||
| - | 1264 | if (htim->PWM_MspInitCallback == NULL) |
|
| - | 1265 | { |
|
| - | 1266 | htim->PWM_MspInitCallback = HAL_TIM_PWM_MspInit; |
|
| - | 1267 | } |
|
| - | 1268 | /* Init the low level hardware : GPIO, CLOCK, NVIC */ |
|
| - | 1269 | htim->PWM_MspInitCallback(htim); |
|
| - | 1270 | #else |
|
| 984 | /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */ |
1271 | /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */ |
| 985 | HAL_TIM_PWM_MspInit(htim); |
1272 | HAL_TIM_PWM_MspInit(htim); |
| - | 1273 | #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */ |
|
| 986 | } |
1274 | } |
| 987 | 1275 | ||
| 988 | /* Set the TIM state */ |
1276 | /* Set the TIM state */ |
| 989 | htim->State= HAL_TIM_STATE_BUSY; |
1277 | htim->State = HAL_TIM_STATE_BUSY; |
| 990 | 1278 | ||
| 991 | /* Init the base time for the PWM */ |
1279 | /* Init the base time for the PWM */ |
| 992 | TIM_Base_SetConfig(htim->Instance, &htim->Init); |
1280 | TIM_Base_SetConfig(htim->Instance, &htim->Init); |
| 993 | 1281 | ||
| - | 1282 | /* Initialize the DMA burst operation state */ |
|
| - | 1283 | htim->DMABurstState = HAL_DMA_BURST_STATE_READY; |
|
| - | 1284 | ||
| - | 1285 | /* Initialize the TIM channels state */ |
|
| - | 1286 | TIM_CHANNEL_STATE_SET_ALL(htim, HAL_TIM_CHANNEL_STATE_READY); |
|
| - | 1287 | ||
| 994 | /* Initialize the TIM state*/ |
1288 | /* Initialize the TIM state*/ |
| 995 | htim->State= HAL_TIM_STATE_READY; |
1289 | htim->State = HAL_TIM_STATE_READY; |
| 996 | 1290 | ||
| 997 | return HAL_OK; |
1291 | return HAL_OK; |
| 998 | } |
1292 | } |
| 999 | 1293 | ||
| 1000 | /** |
1294 | /** |
| 1001 | * @brief DeInitializes the TIM peripheral |
1295 | * @brief DeInitializes the TIM peripheral |
| 1002 | * @param htim: TIM handle |
1296 | * @param htim TIM PWM handle |
| 1003 | * @retval HAL status |
1297 | * @retval HAL status |
| 1004 | */ |
1298 | */ |
| 1005 | HAL_StatusTypeDef HAL_TIM_PWM_DeInit(TIM_HandleTypeDef *htim) |
1299 | HAL_StatusTypeDef HAL_TIM_PWM_DeInit(TIM_HandleTypeDef *htim) |
| 1006 | { |
1300 | { |
| 1007 | /* Check the parameters */ |
1301 | /* Check the parameters */ |
| Line 1010... | Line 1304... | ||
| 1010 | htim->State = HAL_TIM_STATE_BUSY; |
1304 | htim->State = HAL_TIM_STATE_BUSY; |
| 1011 | 1305 | ||
| 1012 | /* Disable the TIM Peripheral Clock */ |
1306 | /* Disable the TIM Peripheral Clock */ |
| 1013 | __HAL_TIM_DISABLE(htim); |
1307 | __HAL_TIM_DISABLE(htim); |
| 1014 | 1308 | ||
| - | 1309 | #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) |
|
| - | 1310 | if (htim->PWM_MspDeInitCallback == NULL) |
|
| - | 1311 | { |
|
| - | 1312 | htim->PWM_MspDeInitCallback = HAL_TIM_PWM_MspDeInit; |
|
| - | 1313 | } |
|
| - | 1314 | /* DeInit the low level hardware */ |
|
| - | 1315 | htim->PWM_MspDeInitCallback(htim); |
|
| - | 1316 | #else |
|
| 1015 | /* DeInit the low level hardware: GPIO, CLOCK, NVIC and DMA */ |
1317 | /* DeInit the low level hardware: GPIO, CLOCK, NVIC and DMA */ |
| 1016 | HAL_TIM_PWM_MspDeInit(htim); |
1318 | HAL_TIM_PWM_MspDeInit(htim); |
| - | 1319 | #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */ |
|
| - | 1320 | ||
| - | 1321 | /* Change the DMA burst operation state */ |
|
| - | 1322 | htim->DMABurstState = HAL_DMA_BURST_STATE_RESET; |
|
| - | 1323 | ||
| - | 1324 | /* Change the TIM channels state */ |
|
| - | 1325 | TIM_CHANNEL_STATE_SET_ALL(htim, HAL_TIM_CHANNEL_STATE_RESET); |
|
| 1017 | 1326 | ||
| 1018 | /* Change TIM state */ |
1327 | /* Change TIM state */ |
| 1019 | htim->State = HAL_TIM_STATE_RESET; |
1328 | htim->State = HAL_TIM_STATE_RESET; |
| 1020 | 1329 | ||
| 1021 | /* Release Lock */ |
1330 | /* Release Lock */ |
| Line 1024... | Line 1333... | ||
| 1024 | return HAL_OK; |
1333 | return HAL_OK; |
| 1025 | } |
1334 | } |
| 1026 | 1335 | ||
| 1027 | /** |
1336 | /** |
| 1028 | * @brief Initializes the TIM PWM MSP. |
1337 | * @brief Initializes the TIM PWM MSP. |
| 1029 | * @param htim: TIM handle |
1338 | * @param htim TIM PWM handle |
| 1030 | * @retval None |
1339 | * @retval None |
| 1031 | */ |
1340 | */ |
| 1032 | __weak void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef *htim) |
1341 | __weak void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef *htim) |
| 1033 | { |
1342 | { |
| 1034 | /* Prevent unused argument(s) compilation warning */ |
1343 | /* Prevent unused argument(s) compilation warning */ |
| 1035 | UNUSED(htim); |
1344 | UNUSED(htim); |
| 1036 | 1345 | ||
| 1037 | /* NOTE : This function Should not be modified, when the callback is needed, |
1346 | /* NOTE : This function should not be modified, when the callback is needed, |
| 1038 | the HAL_TIM_PWM_MspInit could be implemented in the user file |
1347 | the HAL_TIM_PWM_MspInit could be implemented in the user file |
| 1039 | */ |
1348 | */ |
| 1040 | } |
1349 | } |
| 1041 | 1350 | ||
| 1042 | /** |
1351 | /** |
| 1043 | * @brief DeInitializes TIM PWM MSP. |
1352 | * @brief DeInitializes TIM PWM MSP. |
| 1044 | * @param htim: TIM handle |
1353 | * @param htim TIM PWM handle |
| 1045 | * @retval None |
1354 | * @retval None |
| 1046 | */ |
1355 | */ |
| 1047 | __weak void HAL_TIM_PWM_MspDeInit(TIM_HandleTypeDef *htim) |
1356 | __weak void HAL_TIM_PWM_MspDeInit(TIM_HandleTypeDef *htim) |
| 1048 | { |
1357 | { |
| 1049 | /* Prevent unused argument(s) compilation warning */ |
1358 | /* Prevent unused argument(s) compilation warning */ |
| 1050 | UNUSED(htim); |
1359 | UNUSED(htim); |
| 1051 | 1360 | ||
| 1052 | /* NOTE : This function Should not be modified, when the callback is needed, |
1361 | /* NOTE : This function should not be modified, when the callback is needed, |
| 1053 | the HAL_TIM_PWM_MspDeInit could be implemented in the user file |
1362 | the HAL_TIM_PWM_MspDeInit could be implemented in the user file |
| 1054 | */ |
1363 | */ |
| 1055 | } |
1364 | } |
| 1056 | 1365 | ||
| 1057 | /** |
1366 | /** |
| 1058 | * @brief Starts the PWM signal generation. |
1367 | * @brief Starts the PWM signal generation. |
| 1059 | * @param htim : TIM handle |
1368 | * @param htim TIM handle |
| 1060 | * @param Channel : TIM Channels to be enabled |
1369 | * @param Channel TIM Channels to be enabled |
| 1061 | * This parameter can be one of the following values: |
1370 | * This parameter can be one of the following values: |
| 1062 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
1371 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
| 1063 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
1372 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
| 1064 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
1373 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
| 1065 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
1374 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
| 1066 | * @retval HAL status |
1375 | * @retval HAL status |
| 1067 | */ |
1376 | */ |
| 1068 | HAL_StatusTypeDef HAL_TIM_PWM_Start(TIM_HandleTypeDef *htim, uint32_t Channel) |
1377 | HAL_StatusTypeDef HAL_TIM_PWM_Start(TIM_HandleTypeDef *htim, uint32_t Channel) |
| 1069 | { |
1378 | { |
| - | 1379 | uint32_t tmpsmcr; |
|
| - | 1380 | ||
| 1070 | /* Check the parameters */ |
1381 | /* Check the parameters */ |
| 1071 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
1382 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
| 1072 | 1383 | ||
| - | 1384 | /* Check the TIM channel state */ |
|
| - | 1385 | if (TIM_CHANNEL_STATE_GET(htim, Channel) != HAL_TIM_CHANNEL_STATE_READY) |
|
| - | 1386 | { |
|
| - | 1387 | return HAL_ERROR; |
|
| - | 1388 | } |
|
| - | 1389 | ||
| - | 1390 | /* Set the TIM channel state */ |
|
| - | 1391 | TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_BUSY); |
|
| - | 1392 | ||
| 1073 | /* Enable the Capture compare channel */ |
1393 | /* Enable the Capture compare channel */ |
| 1074 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE); |
1394 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE); |
| 1075 | 1395 | ||
| - | 1396 | /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */ |
|
| - | 1397 | if (IS_TIM_SLAVE_INSTANCE(htim->Instance)) |
|
| - | 1398 | { |
|
| - | 1399 | tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS; |
|
| - | 1400 | if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr)) |
|
| - | 1401 | { |
|
| 1076 | /* Enable the Peripheral */ |
1402 | __HAL_TIM_ENABLE(htim); |
| - | 1403 | } |
|
| - | 1404 | } |
|
| - | 1405 | else |
|
| - | 1406 | { |
|
| 1077 | __HAL_TIM_ENABLE(htim); |
1407 | __HAL_TIM_ENABLE(htim); |
| - | 1408 | } |
|
| 1078 | 1409 | ||
| 1079 | /* Return function status */ |
1410 | /* Return function status */ |
| 1080 | return HAL_OK; |
1411 | return HAL_OK; |
| 1081 | } |
1412 | } |
| 1082 | 1413 | ||
| 1083 | /** |
1414 | /** |
| 1084 | * @brief Stops the PWM signal generation. |
1415 | * @brief Stops the PWM signal generation. |
| 1085 | * @param htim : TIM handle |
1416 | * @param htim TIM PWM handle |
| 1086 | * @param Channel : TIM Channels to be disabled |
1417 | * @param Channel TIM Channels to be disabled |
| 1087 | * This parameter can be one of the following values: |
1418 | * This parameter can be one of the following values: |
| 1088 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
1419 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
| 1089 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
1420 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
| 1090 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
1421 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
| 1091 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
1422 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
| 1092 | * @retval HAL status |
1423 | * @retval HAL status |
| 1093 | */ |
1424 | */ |
| 1094 | HAL_StatusTypeDef HAL_TIM_PWM_Stop(TIM_HandleTypeDef *htim, uint32_t Channel) |
1425 | HAL_StatusTypeDef HAL_TIM_PWM_Stop(TIM_HandleTypeDef *htim, uint32_t Channel) |
| 1095 | { |
1426 | { |
| 1096 | /* Check the parameters */ |
1427 | /* Check the parameters */ |
| 1097 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
1428 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
| 1098 | 1429 | ||
| Line 1100... | Line 1431... | ||
| 1100 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE); |
1431 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE); |
| 1101 | 1432 | ||
| 1102 | /* Disable the Peripheral */ |
1433 | /* Disable the Peripheral */ |
| 1103 | __HAL_TIM_DISABLE(htim); |
1434 | __HAL_TIM_DISABLE(htim); |
| 1104 | 1435 | ||
| 1105 | /* Change the htim state */ |
1436 | /* Set the TIM channel state */ |
| 1106 | htim->State = HAL_TIM_STATE_READY; |
1437 | TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY); |
| 1107 | 1438 | ||
| 1108 | /* Return function status */ |
1439 | /* Return function status */ |
| 1109 | return HAL_OK; |
1440 | return HAL_OK; |
| 1110 | } |
1441 | } |
| 1111 | 1442 | ||
| 1112 | /** |
1443 | /** |
| 1113 | * @brief Starts the PWM signal generation in interrupt mode. |
1444 | * @brief Starts the PWM signal generation in interrupt mode. |
| 1114 | * @param htim : TIM handle |
1445 | * @param htim TIM PWM handle |
| 1115 | * @param Channel : TIM Channel to be enabled |
1446 | * @param Channel TIM Channel to be enabled |
| 1116 | * This parameter can be one of the following values: |
1447 | * This parameter can be one of the following values: |
| 1117 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
1448 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
| 1118 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
1449 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
| 1119 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
1450 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
| 1120 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
1451 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
| 1121 | * @retval HAL status |
1452 | * @retval HAL status |
| 1122 | */ |
1453 | */ |
| 1123 | HAL_StatusTypeDef HAL_TIM_PWM_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel) |
1454 | HAL_StatusTypeDef HAL_TIM_PWM_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel) |
| 1124 | { |
1455 | { |
| - | 1456 | uint32_t tmpsmcr; |
|
| 1125 | /* Check the parameters */ |
1457 | /* Check the parameters */ |
| 1126 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
1458 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
| 1127 | 1459 | ||
| - | 1460 | /* Check the TIM channel state */ |
|
| - | 1461 | if (TIM_CHANNEL_STATE_GET(htim, Channel) != HAL_TIM_CHANNEL_STATE_READY) |
|
| - | 1462 | { |
|
| - | 1463 | return HAL_ERROR; |
|
| - | 1464 | } |
|
| - | 1465 | ||
| - | 1466 | /* Set the TIM channel state */ |
|
| - | 1467 | TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_BUSY); |
|
| - | 1468 | ||
| 1128 | switch (Channel) |
1469 | switch (Channel) |
| 1129 | { |
1470 | { |
| 1130 | case TIM_CHANNEL_1: |
1471 | case TIM_CHANNEL_1: |
| 1131 | { |
1472 | { |
| 1132 | /* Enable the TIM Capture/Compare 1 interrupt */ |
1473 | /* Enable the TIM Capture/Compare 1 interrupt */ |
| 1133 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1); |
1474 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1); |
| - | 1475 | break; |
|
| 1134 | } |
1476 | } |
| 1135 | break; |
- | |
| 1136 | 1477 | ||
| 1137 | case TIM_CHANNEL_2: |
1478 | case TIM_CHANNEL_2: |
| 1138 | { |
1479 | { |
| 1139 | /* Enable the TIM Capture/Compare 2 interrupt */ |
1480 | /* Enable the TIM Capture/Compare 2 interrupt */ |
| 1140 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2); |
1481 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2); |
| - | 1482 | break; |
|
| 1141 | } |
1483 | } |
| 1142 | break; |
- | |
| 1143 | 1484 | ||
| 1144 | case TIM_CHANNEL_3: |
1485 | case TIM_CHANNEL_3: |
| 1145 | { |
1486 | { |
| 1146 | /* Enable the TIM Capture/Compare 3 interrupt */ |
1487 | /* Enable the TIM Capture/Compare 3 interrupt */ |
| 1147 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC3); |
1488 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC3); |
| - | 1489 | break; |
|
| 1148 | } |
1490 | } |
| 1149 | break; |
- | |
| 1150 | 1491 | ||
| 1151 | case TIM_CHANNEL_4: |
1492 | case TIM_CHANNEL_4: |
| 1152 | { |
1493 | { |
| 1153 | /* Enable the TIM Capture/Compare 4 interrupt */ |
1494 | /* Enable the TIM Capture/Compare 4 interrupt */ |
| 1154 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC4); |
1495 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC4); |
| - | 1496 | break; |
|
| 1155 | } |
1497 | } |
| 1156 | break; |
- | |
| 1157 | 1498 | ||
| 1158 | default: |
1499 | default: |
| 1159 | break; |
1500 | break; |
| 1160 | } |
1501 | } |
| 1161 | 1502 | ||
| 1162 | /* Enable the Capture compare channel */ |
1503 | /* Enable the Capture compare channel */ |
| 1163 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE); |
1504 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE); |
| 1164 | 1505 | ||
| - | 1506 | /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */ |
|
| - | 1507 | if (IS_TIM_SLAVE_INSTANCE(htim->Instance)) |
|
| - | 1508 | { |
|
| - | 1509 | tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS; |
|
| - | 1510 | if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr)) |
|
| - | 1511 | { |
|
| 1165 | /* Enable the Peripheral */ |
1512 | __HAL_TIM_ENABLE(htim); |
| - | 1513 | } |
|
| - | 1514 | } |
|
| - | 1515 | else |
|
| - | 1516 | { |
|
| 1166 | __HAL_TIM_ENABLE(htim); |
1517 | __HAL_TIM_ENABLE(htim); |
| - | 1518 | } |
|
| 1167 | 1519 | ||
| 1168 | /* Return function status */ |
1520 | /* Return function status */ |
| 1169 | return HAL_OK; |
1521 | return HAL_OK; |
| 1170 | } |
1522 | } |
| 1171 | 1523 | ||
| 1172 | /** |
1524 | /** |
| 1173 | * @brief Stops the PWM signal generation in interrupt mode. |
1525 | * @brief Stops the PWM signal generation in interrupt mode. |
| 1174 | * @param htim : TIM handle |
1526 | * @param htim TIM PWM handle |
| 1175 | * @param Channel : TIM Channels to be disabled |
1527 | * @param Channel TIM Channels to be disabled |
| 1176 | * This parameter can be one of the following values: |
1528 | * This parameter can be one of the following values: |
| 1177 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
1529 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
| 1178 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
1530 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
| 1179 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
1531 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
| 1180 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
1532 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
| 1181 | * @retval HAL status |
1533 | * @retval HAL status |
| 1182 | */ |
1534 | */ |
| 1183 | HAL_StatusTypeDef HAL_TIM_PWM_Stop_IT (TIM_HandleTypeDef *htim, uint32_t Channel) |
1535 | HAL_StatusTypeDef HAL_TIM_PWM_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel) |
| 1184 | { |
1536 | { |
| 1185 | /* Check the parameters */ |
1537 | /* Check the parameters */ |
| 1186 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
1538 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
| 1187 | 1539 | ||
| 1188 | switch (Channel) |
1540 | switch (Channel) |
| 1189 | { |
1541 | { |
| 1190 | case TIM_CHANNEL_1: |
1542 | case TIM_CHANNEL_1: |
| 1191 | { |
1543 | { |
| 1192 | /* Disable the TIM Capture/Compare 1 interrupt */ |
1544 | /* Disable the TIM Capture/Compare 1 interrupt */ |
| 1193 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1); |
1545 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1); |
| - | 1546 | break; |
|
| 1194 | } |
1547 | } |
| 1195 | break; |
- | |
| 1196 | 1548 | ||
| 1197 | case TIM_CHANNEL_2: |
1549 | case TIM_CHANNEL_2: |
| 1198 | { |
1550 | { |
| 1199 | /* Disable the TIM Capture/Compare 2 interrupt */ |
1551 | /* Disable the TIM Capture/Compare 2 interrupt */ |
| 1200 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2); |
1552 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2); |
| - | 1553 | break; |
|
| 1201 | } |
1554 | } |
| 1202 | break; |
- | |
| 1203 | 1555 | ||
| 1204 | case TIM_CHANNEL_3: |
1556 | case TIM_CHANNEL_3: |
| 1205 | { |
1557 | { |
| 1206 | /* Disable the TIM Capture/Compare 3 interrupt */ |
1558 | /* Disable the TIM Capture/Compare 3 interrupt */ |
| 1207 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC3); |
1559 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC3); |
| - | 1560 | break; |
|
| 1208 | } |
1561 | } |
| 1209 | break; |
- | |
| 1210 | 1562 | ||
| 1211 | case TIM_CHANNEL_4: |
1563 | case TIM_CHANNEL_4: |
| 1212 | { |
1564 | { |
| 1213 | /* Disable the TIM Capture/Compare 4 interrupt */ |
1565 | /* Disable the TIM Capture/Compare 4 interrupt */ |
| 1214 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC4); |
1566 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC4); |
| - | 1567 | break; |
|
| 1215 | } |
1568 | } |
| 1216 | break; |
- | |
| 1217 | 1569 | ||
| 1218 | default: |
1570 | default: |
| 1219 | break; |
1571 | break; |
| 1220 | } |
1572 | } |
| 1221 | 1573 | ||
| 1222 | /* Disable the Capture compare channel */ |
1574 | /* Disable the Capture compare channel */ |
| 1223 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE); |
1575 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE); |
| 1224 | 1576 | ||
| 1225 | - | ||
| 1226 | /* Disable the Peripheral */ |
1577 | /* Disable the Peripheral */ |
| 1227 | __HAL_TIM_DISABLE(htim); |
1578 | __HAL_TIM_DISABLE(htim); |
| 1228 | 1579 | ||
| - | 1580 | /* Set the TIM channel state */ |
|
| - | 1581 | TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY); |
|
| - | 1582 | ||
| 1229 | /* Return function status */ |
1583 | /* Return function status */ |
| 1230 | return HAL_OK; |
1584 | return HAL_OK; |
| 1231 | } |
1585 | } |
| 1232 | 1586 | ||
| 1233 | /** |
1587 | /** |
| 1234 | * @brief Starts the TIM PWM signal generation in DMA mode. |
1588 | * @brief Starts the TIM PWM signal generation in DMA mode. |
| 1235 | * @param htim : TIM handle |
1589 | * @param htim TIM PWM handle |
| 1236 | * @param Channel : TIM Channels to be enabled |
1590 | * @param Channel TIM Channels to be enabled |
| 1237 | * This parameter can be one of the following values: |
1591 | * This parameter can be one of the following values: |
| 1238 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
1592 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
| 1239 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
1593 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
| 1240 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
1594 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
| 1241 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
1595 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
| 1242 | * @param pData: The source Buffer address. |
1596 | * @param pData The source Buffer address. |
| 1243 | * @param Length: The length of data to be transferred from memory to TIM peripheral |
1597 | * @param Length The length of data to be transferred from memory to TIM peripheral |
| 1244 | * @retval HAL status |
1598 | * @retval HAL status |
| 1245 | */ |
1599 | */ |
| 1246 | HAL_StatusTypeDef HAL_TIM_PWM_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length) |
1600 | HAL_StatusTypeDef HAL_TIM_PWM_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length) |
| 1247 | { |
1601 | { |
| - | 1602 | uint32_t tmpsmcr; |
|
| - | 1603 | ||
| 1248 | /* Check the parameters */ |
1604 | /* Check the parameters */ |
| 1249 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
1605 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
| 1250 | 1606 | ||
| - | 1607 | /* Set the TIM channel state */ |
|
| 1251 | if((htim->State == HAL_TIM_STATE_BUSY)) |
1608 | if (TIM_CHANNEL_STATE_GET(htim, Channel) == HAL_TIM_CHANNEL_STATE_BUSY) |
| 1252 | { |
1609 | { |
| 1253 | return HAL_BUSY; |
1610 | return HAL_BUSY; |
| 1254 | } |
1611 | } |
| 1255 | else if((htim->State == HAL_TIM_STATE_READY)) |
1612 | else if (TIM_CHANNEL_STATE_GET(htim, Channel) == HAL_TIM_CHANNEL_STATE_READY) |
| 1256 | { |
1613 | { |
| 1257 | if(((uint32_t)pData == 0 ) && (Length > 0)) |
1614 | if ((pData == NULL) && (Length > 0U)) |
| 1258 | { |
1615 | { |
| 1259 | return HAL_ERROR; |
1616 | return HAL_ERROR; |
| 1260 | } |
1617 | } |
| 1261 | else |
1618 | else |
| 1262 | { |
1619 | { |
| 1263 | htim->State = HAL_TIM_STATE_BUSY; |
1620 | TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_BUSY); |
| 1264 | } |
1621 | } |
| 1265 | } |
1622 | } |
| 1266 | else |
1623 | else |
| 1267 | { |
1624 | { |
| 1268 | return HAL_ERROR; |
1625 | return HAL_ERROR; |
| Line 1270... | Line 1627... | ||
| 1270 | 1627 | ||
| 1271 | switch (Channel) |
1628 | switch (Channel) |
| 1272 | { |
1629 | { |
| 1273 | case TIM_CHANNEL_1: |
1630 | case TIM_CHANNEL_1: |
| 1274 | { |
1631 | { |
| 1275 | /* Set the DMA Period elapsed callback */ |
1632 | /* Set the DMA compare callbacks */ |
| 1276 | htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMADelayPulseCplt; |
1633 | htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMADelayPulseCplt; |
| - | 1634 | htim->hdma[TIM_DMA_ID_CC1]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt; |
|
| 1277 | 1635 | ||
| 1278 | /* Set the DMA error callback */ |
1636 | /* Set the DMA error callback */ |
| 1279 | htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ; |
1637 | htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ; |
| 1280 | 1638 | ||
| 1281 | /* Enable the DMA channel */ |
1639 | /* Enable the DMA channel */ |
| 1282 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)pData, (uint32_t)&htim->Instance->CCR1, Length); |
1640 | if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)pData, (uint32_t)&htim->Instance->CCR1, Length) != HAL_OK) |
| - | 1641 | { |
|
| - | 1642 | return HAL_ERROR; |
|
| - | 1643 | } |
|
| 1283 | 1644 | ||
| 1284 | /* Enable the TIM Capture/Compare 1 DMA request */ |
1645 | /* Enable the TIM Capture/Compare 1 DMA request */ |
| 1285 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1); |
1646 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1); |
| - | 1647 | break; |
|
| 1286 | } |
1648 | } |
| 1287 | break; |
- | |
| 1288 | 1649 | ||
| 1289 | case TIM_CHANNEL_2: |
1650 | case TIM_CHANNEL_2: |
| 1290 | { |
1651 | { |
| 1291 | /* Set the DMA Period elapsed callback */ |
1652 | /* Set the DMA compare callbacks */ |
| 1292 | htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMADelayPulseCplt; |
1653 | htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMADelayPulseCplt; |
| - | 1654 | htim->hdma[TIM_DMA_ID_CC2]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt; |
|
| 1293 | 1655 | ||
| 1294 | /* Set the DMA error callback */ |
1656 | /* Set the DMA error callback */ |
| 1295 | htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError ; |
1657 | htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError ; |
| 1296 | 1658 | ||
| 1297 | /* Enable the DMA channel */ |
1659 | /* Enable the DMA channel */ |
| 1298 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)pData, (uint32_t)&htim->Instance->CCR2, Length); |
1660 | if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)pData, (uint32_t)&htim->Instance->CCR2, Length) != HAL_OK) |
| - | 1661 | { |
|
| - | 1662 | return HAL_ERROR; |
|
| 1299 | 1663 | } |
|
| 1300 | /* Enable the TIM Capture/Compare 2 DMA request */ |
1664 | /* Enable the TIM Capture/Compare 2 DMA request */ |
| 1301 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2); |
1665 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2); |
| - | 1666 | break; |
|
| 1302 | } |
1667 | } |
| 1303 | break; |
- | |
| 1304 | 1668 | ||
| 1305 | case TIM_CHANNEL_3: |
1669 | case TIM_CHANNEL_3: |
| 1306 | { |
1670 | { |
| 1307 | /* Set the DMA Period elapsed callback */ |
1671 | /* Set the DMA compare callbacks */ |
| 1308 | htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMADelayPulseCplt; |
1672 | htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMADelayPulseCplt; |
| - | 1673 | htim->hdma[TIM_DMA_ID_CC3]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt; |
|
| 1309 | 1674 | ||
| 1310 | /* Set the DMA error callback */ |
1675 | /* Set the DMA error callback */ |
| 1311 | htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = TIM_DMAError ; |
1676 | htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = TIM_DMAError ; |
| 1312 | 1677 | ||
| 1313 | /* Enable the DMA channel */ |
1678 | /* Enable the DMA channel */ |
| 1314 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)pData, (uint32_t)&htim->Instance->CCR3,Length); |
1679 | if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)pData, (uint32_t)&htim->Instance->CCR3, Length) != HAL_OK) |
| - | 1680 | { |
|
| - | 1681 | return HAL_ERROR; |
|
| 1315 | 1682 | } |
|
| 1316 | /* Enable the TIM Output Capture/Compare 3 request */ |
1683 | /* Enable the TIM Output Capture/Compare 3 request */ |
| 1317 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC3); |
1684 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC3); |
| - | 1685 | break; |
|
| 1318 | } |
1686 | } |
| 1319 | break; |
- | |
| 1320 | 1687 | ||
| 1321 | case TIM_CHANNEL_4: |
1688 | case TIM_CHANNEL_4: |
| 1322 | { |
1689 | { |
| 1323 | /* Set the DMA Period elapsed callback */ |
1690 | /* Set the DMA compare callbacks */ |
| 1324 | htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = TIM_DMADelayPulseCplt; |
1691 | htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = TIM_DMADelayPulseCplt; |
| - | 1692 | htim->hdma[TIM_DMA_ID_CC4]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt; |
|
| 1325 | 1693 | ||
| 1326 | /* Set the DMA error callback */ |
1694 | /* Set the DMA error callback */ |
| 1327 | htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = TIM_DMAError ; |
1695 | htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = TIM_DMAError ; |
| 1328 | 1696 | ||
| 1329 | /* Enable the DMA channel */ |
1697 | /* Enable the DMA channel */ |
| 1330 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)pData, (uint32_t)&htim->Instance->CCR4, Length); |
1698 | if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)pData, (uint32_t)&htim->Instance->CCR4, Length) != HAL_OK) |
| - | 1699 | { |
|
| - | 1700 | return HAL_ERROR; |
|
| 1331 | 1701 | } |
|
| 1332 | /* Enable the TIM Capture/Compare 4 DMA request */ |
1702 | /* Enable the TIM Capture/Compare 4 DMA request */ |
| 1333 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC4); |
1703 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC4); |
| - | 1704 | break; |
|
| 1334 | } |
1705 | } |
| 1335 | break; |
- | |
| 1336 | 1706 | ||
| 1337 | default: |
1707 | default: |
| 1338 | break; |
1708 | break; |
| 1339 | } |
1709 | } |
| 1340 | 1710 | ||
| 1341 | /* Enable the Capture compare channel */ |
1711 | /* Enable the Capture compare channel */ |
| 1342 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE); |
1712 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE); |
| 1343 | 1713 | ||
| - | 1714 | /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */ |
|
| - | 1715 | if (IS_TIM_SLAVE_INSTANCE(htim->Instance)) |
|
| - | 1716 | { |
|
| - | 1717 | tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS; |
|
| - | 1718 | if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr)) |
|
| - | 1719 | { |
|
| 1344 | /* Enable the Peripheral */ |
1720 | __HAL_TIM_ENABLE(htim); |
| - | 1721 | } |
|
| - | 1722 | } |
|
| - | 1723 | else |
|
| - | 1724 | { |
|
| 1345 | __HAL_TIM_ENABLE(htim); |
1725 | __HAL_TIM_ENABLE(htim); |
| - | 1726 | } |
|
| 1346 | 1727 | ||
| 1347 | /* Return function status */ |
1728 | /* Return function status */ |
| 1348 | return HAL_OK; |
1729 | return HAL_OK; |
| 1349 | } |
1730 | } |
| 1350 | 1731 | ||
| 1351 | /** |
1732 | /** |
| 1352 | * @brief Stops the TIM PWM signal generation in DMA mode. |
1733 | * @brief Stops the TIM PWM signal generation in DMA mode. |
| 1353 | * @param htim : TIM handle |
1734 | * @param htim TIM PWM handle |
| 1354 | * @param Channel : TIM Channels to be disabled |
1735 | * @param Channel TIM Channels to be disabled |
| 1355 | * This parameter can be one of the following values: |
1736 | * This parameter can be one of the following values: |
| 1356 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
1737 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
| 1357 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
1738 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
| 1358 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
1739 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
| 1359 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
1740 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
| 1360 | * @retval HAL status |
1741 | * @retval HAL status |
| 1361 | */ |
1742 | */ |
| 1362 | HAL_StatusTypeDef HAL_TIM_PWM_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel) |
1743 | HAL_StatusTypeDef HAL_TIM_PWM_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel) |
| 1363 | { |
1744 | { |
| 1364 | /* Check the parameters */ |
1745 | /* Check the parameters */ |
| 1365 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
1746 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
| 1366 | 1747 | ||
| Line 1368... | Line 1749... | ||
| 1368 | { |
1749 | { |
| 1369 | case TIM_CHANNEL_1: |
1750 | case TIM_CHANNEL_1: |
| 1370 | { |
1751 | { |
| 1371 | /* Disable the TIM Capture/Compare 1 DMA request */ |
1752 | /* Disable the TIM Capture/Compare 1 DMA request */ |
| 1372 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1); |
1753 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1); |
| - | 1754 | (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC1]); |
|
| - | 1755 | break; |
|
| 1373 | } |
1756 | } |
| 1374 | break; |
- | |
| 1375 | 1757 | ||
| 1376 | case TIM_CHANNEL_2: |
1758 | case TIM_CHANNEL_2: |
| 1377 | { |
1759 | { |
| 1378 | /* Disable the TIM Capture/Compare 2 DMA request */ |
1760 | /* Disable the TIM Capture/Compare 2 DMA request */ |
| 1379 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2); |
1761 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2); |
| - | 1762 | (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC2]); |
|
| - | 1763 | break; |
|
| 1380 | } |
1764 | } |
| 1381 | break; |
- | |
| 1382 | 1765 | ||
| 1383 | case TIM_CHANNEL_3: |
1766 | case TIM_CHANNEL_3: |
| 1384 | { |
1767 | { |
| 1385 | /* Disable the TIM Capture/Compare 3 DMA request */ |
1768 | /* Disable the TIM Capture/Compare 3 DMA request */ |
| 1386 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC3); |
1769 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC3); |
| - | 1770 | (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC3]); |
|
| - | 1771 | break; |
|
| 1387 | } |
1772 | } |
| 1388 | break; |
- | |
| 1389 | 1773 | ||
| 1390 | case TIM_CHANNEL_4: |
1774 | case TIM_CHANNEL_4: |
| 1391 | { |
1775 | { |
| 1392 | /* Disable the TIM Capture/Compare 4 interrupt */ |
1776 | /* Disable the TIM Capture/Compare 4 interrupt */ |
| 1393 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC4); |
1777 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC4); |
| - | 1778 | (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC4]); |
|
| - | 1779 | break; |
|
| 1394 | } |
1780 | } |
| 1395 | break; |
- | |
| 1396 | 1781 | ||
| 1397 | default: |
1782 | default: |
| 1398 | break; |
1783 | break; |
| 1399 | } |
1784 | } |
| 1400 | 1785 | ||
| 1401 | /* Disable the Capture compare channel */ |
1786 | /* Disable the Capture compare channel */ |
| 1402 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE); |
1787 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE); |
| 1403 | 1788 | ||
| 1404 | /* Disable the Peripheral */ |
1789 | /* Disable the Peripheral */ |
| 1405 | __HAL_TIM_DISABLE(htim); |
1790 | __HAL_TIM_DISABLE(htim); |
| 1406 | 1791 | ||
| 1407 | /* Change the htim state */ |
1792 | /* Set the TIM channel state */ |
| 1408 | htim->State = HAL_TIM_STATE_READY; |
1793 | TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY); |
| 1409 | 1794 | ||
| 1410 | /* Return function status */ |
1795 | /* Return function status */ |
| 1411 | return HAL_OK; |
1796 | return HAL_OK; |
| 1412 | } |
1797 | } |
| 1413 | 1798 | ||
| 1414 | /** |
1799 | /** |
| 1415 | * @} |
1800 | * @} |
| 1416 | */ |
1801 | */ |
| 1417 | 1802 | ||
| 1418 | /** @defgroup TIM_Exported_Functions_Group4 Time Input Capture functions |
1803 | /** @defgroup TIM_Exported_Functions_Group4 TIM Input Capture functions |
| 1419 | * @brief Time Input Capture functions |
1804 | * @brief TIM Input Capture functions |
| 1420 | * |
1805 | * |
| 1421 | @verbatim |
1806 | @verbatim |
| 1422 | ============================================================================== |
1807 | ============================================================================== |
| 1423 | ##### Time Input Capture functions ##### |
1808 | ##### TIM Input Capture functions ##### |
| 1424 | ============================================================================== |
1809 | ============================================================================== |
| 1425 | [..] |
1810 | [..] |
| 1426 | This section provides functions allowing to: |
1811 | This section provides functions allowing to: |
| 1427 | (+) Initialize and configure the TIM Input Capture. |
1812 | (+) Initialize and configure the TIM Input Capture. |
| 1428 | (+) De-initialize the TIM Input Capture. |
1813 | (+) De-initialize the TIM Input Capture. |
| 1429 | (+) Start the Time Input Capture. |
1814 | (+) Start the TIM Input Capture. |
| 1430 | (+) Stop the Time Input Capture. |
1815 | (+) Stop the TIM Input Capture. |
| 1431 | (+) Start the Time Input Capture and enable interrupt. |
1816 | (+) Start the TIM Input Capture and enable interrupt. |
| 1432 | (+) Stop the Time Input Capture and disable interrupt. |
1817 | (+) Stop the TIM Input Capture and disable interrupt. |
| 1433 | (+) Start the Time Input Capture and enable DMA transfer. |
1818 | (+) Start the TIM Input Capture and enable DMA transfer. |
| 1434 | (+) Stop the Time Input Capture and disable DMA transfer. |
1819 | (+) Stop the TIM Input Capture and disable DMA transfer. |
| 1435 | 1820 | ||
| 1436 | @endverbatim |
1821 | @endverbatim |
| 1437 | * @{ |
1822 | * @{ |
| 1438 | */ |
1823 | */ |
| 1439 | /** |
1824 | /** |
| 1440 | * @brief Initializes the TIM Input Capture Time base according to the specified |
1825 | * @brief Initializes the TIM Input Capture Time base according to the specified |
| 1441 | * parameters in the TIM_HandleTypeDef and create the associated handle. |
1826 | * parameters in the TIM_HandleTypeDef and initializes the associated handle. |
| - | 1827 | * @note Switching from Center Aligned counter mode to Edge counter mode (or reverse) |
|
| - | 1828 | * requires a timer reset to avoid unexpected direction |
|
| - | 1829 | * due to DIR bit readonly in center aligned mode. |
|
| - | 1830 | * Ex: call @ref HAL_TIM_IC_DeInit() before HAL_TIM_IC_Init() |
|
| 1442 | * @param htim: TIM Input Capture handle |
1831 | * @param htim TIM Input Capture handle |
| 1443 | * @retval HAL status |
1832 | * @retval HAL status |
| 1444 | */ |
1833 | */ |
| 1445 | HAL_StatusTypeDef HAL_TIM_IC_Init(TIM_HandleTypeDef *htim) |
1834 | HAL_StatusTypeDef HAL_TIM_IC_Init(TIM_HandleTypeDef *htim) |
| 1446 | { |
1835 | { |
| 1447 | /* Check the TIM handle allocation */ |
1836 | /* Check the TIM handle allocation */ |
| 1448 | if(htim == NULL) |
1837 | if (htim == NULL) |
| 1449 | { |
1838 | { |
| 1450 | return HAL_ERROR; |
1839 | return HAL_ERROR; |
| 1451 | } |
1840 | } |
| 1452 | 1841 | ||
| 1453 | /* Check the parameters */ |
1842 | /* Check the parameters */ |
| 1454 | assert_param(IS_TIM_INSTANCE(htim->Instance)); |
1843 | assert_param(IS_TIM_INSTANCE(htim->Instance)); |
| 1455 | assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode)); |
1844 | assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode)); |
| 1456 | assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision)); |
1845 | assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision)); |
| - | 1846 | assert_param(IS_TIM_AUTORELOAD_PRELOAD(htim->Init.AutoReloadPreload)); |
|
| 1457 | 1847 | ||
| 1458 | if(htim->State == HAL_TIM_STATE_RESET) |
1848 | if (htim->State == HAL_TIM_STATE_RESET) |
| 1459 | { |
1849 | { |
| 1460 | /* Allocate lock resource and initialize it */ |
1850 | /* Allocate lock resource and initialize it */ |
| 1461 | htim->Lock = HAL_UNLOCKED; |
1851 | htim->Lock = HAL_UNLOCKED; |
| 1462 | 1852 | ||
| - | 1853 | #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) |
|
| - | 1854 | /* Reset interrupt callbacks to legacy weak callbacks */ |
|
| - | 1855 | TIM_ResetCallback(htim); |
|
| - | 1856 | ||
| - | 1857 | if (htim->IC_MspInitCallback == NULL) |
|
| - | 1858 | { |
|
| - | 1859 | htim->IC_MspInitCallback = HAL_TIM_IC_MspInit; |
|
| - | 1860 | } |
|
| - | 1861 | /* Init the low level hardware : GPIO, CLOCK, NVIC */ |
|
| - | 1862 | htim->IC_MspInitCallback(htim); |
|
| - | 1863 | #else |
|
| 1463 | /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */ |
1864 | /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */ |
| 1464 | HAL_TIM_IC_MspInit(htim); |
1865 | HAL_TIM_IC_MspInit(htim); |
| - | 1866 | #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */ |
|
| 1465 | } |
1867 | } |
| 1466 | 1868 | ||
| 1467 | /* Set the TIM state */ |
1869 | /* Set the TIM state */ |
| 1468 | htim->State= HAL_TIM_STATE_BUSY; |
1870 | htim->State = HAL_TIM_STATE_BUSY; |
| 1469 | 1871 | ||
| 1470 | /* Init the base time for the input capture */ |
1872 | /* Init the base time for the input capture */ |
| 1471 | TIM_Base_SetConfig(htim->Instance, &htim->Init); |
1873 | TIM_Base_SetConfig(htim->Instance, &htim->Init); |
| 1472 | 1874 | ||
| - | 1875 | /* Initialize the DMA burst operation state */ |
|
| - | 1876 | htim->DMABurstState = HAL_DMA_BURST_STATE_READY; |
|
| - | 1877 | ||
| - | 1878 | /* Initialize the TIM channels state */ |
|
| - | 1879 | TIM_CHANNEL_STATE_SET_ALL(htim, HAL_TIM_CHANNEL_STATE_READY); |
|
| - | 1880 | ||
| 1473 | /* Initialize the TIM state*/ |
1881 | /* Initialize the TIM state*/ |
| 1474 | htim->State= HAL_TIM_STATE_READY; |
1882 | htim->State = HAL_TIM_STATE_READY; |
| 1475 | 1883 | ||
| 1476 | return HAL_OK; |
1884 | return HAL_OK; |
| 1477 | } |
1885 | } |
| 1478 | 1886 | ||
| 1479 | /** |
1887 | /** |
| 1480 | * @brief DeInitializes the TIM peripheral |
1888 | * @brief DeInitializes the TIM peripheral |
| 1481 | * @param htim: TIM Input Capture handle |
1889 | * @param htim TIM Input Capture handle |
| 1482 | * @retval HAL status |
1890 | * @retval HAL status |
| 1483 | */ |
1891 | */ |
| 1484 | HAL_StatusTypeDef HAL_TIM_IC_DeInit(TIM_HandleTypeDef *htim) |
1892 | HAL_StatusTypeDef HAL_TIM_IC_DeInit(TIM_HandleTypeDef *htim) |
| 1485 | { |
1893 | { |
| 1486 | /* Check the parameters */ |
1894 | /* Check the parameters */ |
| Line 1489... | Line 1897... | ||
| 1489 | htim->State = HAL_TIM_STATE_BUSY; |
1897 | htim->State = HAL_TIM_STATE_BUSY; |
| 1490 | 1898 | ||
| 1491 | /* Disable the TIM Peripheral Clock */ |
1899 | /* Disable the TIM Peripheral Clock */ |
| 1492 | __HAL_TIM_DISABLE(htim); |
1900 | __HAL_TIM_DISABLE(htim); |
| 1493 | 1901 | ||
| - | 1902 | #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) |
|
| - | 1903 | if (htim->IC_MspDeInitCallback == NULL) |
|
| - | 1904 | { |
|
| - | 1905 | htim->IC_MspDeInitCallback = HAL_TIM_IC_MspDeInit; |
|
| - | 1906 | } |
|
| - | 1907 | /* DeInit the low level hardware */ |
|
| - | 1908 | htim->IC_MspDeInitCallback(htim); |
|
| - | 1909 | #else |
|
| 1494 | /* DeInit the low level hardware: GPIO, CLOCK, NVIC and DMA */ |
1910 | /* DeInit the low level hardware: GPIO, CLOCK, NVIC and DMA */ |
| 1495 | HAL_TIM_IC_MspDeInit(htim); |
1911 | HAL_TIM_IC_MspDeInit(htim); |
| - | 1912 | #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */ |
|
| - | 1913 | ||
| - | 1914 | /* Change the DMA burst operation state */ |
|
| - | 1915 | htim->DMABurstState = HAL_DMA_BURST_STATE_RESET; |
|
| - | 1916 | ||
| - | 1917 | /* Change the TIM channels state */ |
|
| - | 1918 | TIM_CHANNEL_STATE_SET_ALL(htim, HAL_TIM_CHANNEL_STATE_RESET); |
|
| 1496 | 1919 | ||
| 1497 | /* Change TIM state */ |
1920 | /* Change TIM state */ |
| 1498 | htim->State = HAL_TIM_STATE_RESET; |
1921 | htim->State = HAL_TIM_STATE_RESET; |
| 1499 | 1922 | ||
| 1500 | /* Release Lock */ |
1923 | /* Release Lock */ |
| Line 1503... | Line 1926... | ||
| 1503 | return HAL_OK; |
1926 | return HAL_OK; |
| 1504 | } |
1927 | } |
| 1505 | 1928 | ||
| 1506 | /** |
1929 | /** |
| 1507 | * @brief Initializes the TIM Input Capture MSP. |
1930 | * @brief Initializes the TIM Input Capture MSP. |
| 1508 | * @param htim: TIM handle |
1931 | * @param htim TIM Input Capture handle |
| 1509 | * @retval None |
1932 | * @retval None |
| 1510 | */ |
1933 | */ |
| 1511 | __weak void HAL_TIM_IC_MspInit(TIM_HandleTypeDef *htim) |
1934 | __weak void HAL_TIM_IC_MspInit(TIM_HandleTypeDef *htim) |
| 1512 | { |
1935 | { |
| 1513 | /* Prevent unused argument(s) compilation warning */ |
1936 | /* Prevent unused argument(s) compilation warning */ |
| 1514 | UNUSED(htim); |
1937 | UNUSED(htim); |
| 1515 | 1938 | ||
| 1516 | /* NOTE : This function Should not be modified, when the callback is needed, |
1939 | /* NOTE : This function should not be modified, when the callback is needed, |
| 1517 | the HAL_TIM_IC_MspInit could be implemented in the user file |
1940 | the HAL_TIM_IC_MspInit could be implemented in the user file |
| 1518 | */ |
1941 | */ |
| 1519 | } |
1942 | } |
| 1520 | 1943 | ||
| 1521 | /** |
1944 | /** |
| 1522 | * @brief DeInitializes TIM Input Capture MSP. |
1945 | * @brief DeInitializes TIM Input Capture MSP. |
| 1523 | * @param htim: TIM handle |
1946 | * @param htim TIM handle |
| 1524 | * @retval None |
1947 | * @retval None |
| 1525 | */ |
1948 | */ |
| 1526 | __weak void HAL_TIM_IC_MspDeInit(TIM_HandleTypeDef *htim) |
1949 | __weak void HAL_TIM_IC_MspDeInit(TIM_HandleTypeDef *htim) |
| 1527 | { |
1950 | { |
| 1528 | /* Prevent unused argument(s) compilation warning */ |
1951 | /* Prevent unused argument(s) compilation warning */ |
| 1529 | UNUSED(htim); |
1952 | UNUSED(htim); |
| 1530 | 1953 | ||
| 1531 | /* NOTE : This function Should not be modified, when the callback is needed, |
1954 | /* NOTE : This function should not be modified, when the callback is needed, |
| 1532 | the HAL_TIM_IC_MspDeInit could be implemented in the user file |
1955 | the HAL_TIM_IC_MspDeInit could be implemented in the user file |
| 1533 | */ |
1956 | */ |
| 1534 | } |
1957 | } |
| 1535 | 1958 | ||
| 1536 | /** |
1959 | /** |
| 1537 | * @brief Starts the TIM Input Capture measurement. |
1960 | * @brief Starts the TIM Input Capture measurement. |
| 1538 | * @param htim : TIM Input Capture handle |
1961 | * @param htim TIM Input Capture handle |
| 1539 | * @param Channel : TIM Channels to be enabled |
1962 | * @param Channel TIM Channels to be enabled |
| 1540 | * This parameter can be one of the following values: |
1963 | * This parameter can be one of the following values: |
| 1541 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
1964 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
| 1542 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
1965 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
| 1543 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
1966 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
| 1544 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
1967 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
| 1545 | * @retval HAL status |
1968 | * @retval HAL status |
| 1546 | */ |
1969 | */ |
| 1547 | HAL_StatusTypeDef HAL_TIM_IC_Start (TIM_HandleTypeDef *htim, uint32_t Channel) |
1970 | HAL_StatusTypeDef HAL_TIM_IC_Start(TIM_HandleTypeDef *htim, uint32_t Channel) |
| 1548 | { |
1971 | { |
| - | 1972 | uint32_t tmpsmcr; |
|
| - | 1973 | HAL_TIM_ChannelStateTypeDef channel_state = TIM_CHANNEL_STATE_GET(htim, Channel); |
|
| - | 1974 | ||
| 1549 | /* Check the parameters */ |
1975 | /* Check the parameters */ |
| 1550 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
1976 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
| 1551 | 1977 | ||
| - | 1978 | /* Check the TIM channel state */ |
|
| - | 1979 | if (channel_state != HAL_TIM_CHANNEL_STATE_READY) |
|
| - | 1980 | { |
|
| - | 1981 | return HAL_ERROR; |
|
| - | 1982 | } |
|
| - | 1983 | ||
| - | 1984 | /* Set the TIM channel state */ |
|
| - | 1985 | TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_BUSY); |
|
| - | 1986 | ||
| 1552 | /* Enable the Input Capture channel */ |
1987 | /* Enable the Input Capture channel */ |
| 1553 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE); |
1988 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE); |
| 1554 | 1989 | ||
| - | 1990 | /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */ |
|
| - | 1991 | if (IS_TIM_SLAVE_INSTANCE(htim->Instance)) |
|
| - | 1992 | { |
|
| - | 1993 | tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS; |
|
| - | 1994 | if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr)) |
|
| - | 1995 | { |
|
| 1555 | /* Enable the Peripheral */ |
1996 | __HAL_TIM_ENABLE(htim); |
| - | 1997 | } |
|
| - | 1998 | } |
|
| - | 1999 | else |
|
| - | 2000 | { |
|
| 1556 | __HAL_TIM_ENABLE(htim); |
2001 | __HAL_TIM_ENABLE(htim); |
| - | 2002 | } |
|
| 1557 | 2003 | ||
| 1558 | /* Return function status */ |
2004 | /* Return function status */ |
| 1559 | return HAL_OK; |
2005 | return HAL_OK; |
| 1560 | } |
2006 | } |
| 1561 | 2007 | ||
| 1562 | /** |
2008 | /** |
| 1563 | * @brief Stops the TIM Input Capture measurement. |
2009 | * @brief Stops the TIM Input Capture measurement. |
| 1564 | * @param htim : TIM handle |
2010 | * @param htim TIM Input Capture handle |
| 1565 | * @param Channel : TIM Channels to be disabled |
2011 | * @param Channel TIM Channels to be disabled |
| 1566 | * This parameter can be one of the following values: |
2012 | * This parameter can be one of the following values: |
| 1567 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
2013 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
| 1568 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
2014 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
| 1569 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
2015 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
| 1570 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
2016 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
| 1571 | * @retval HAL status |
2017 | * @retval HAL status |
| 1572 | */ |
2018 | */ |
| 1573 | HAL_StatusTypeDef HAL_TIM_IC_Stop(TIM_HandleTypeDef *htim, uint32_t Channel) |
2019 | HAL_StatusTypeDef HAL_TIM_IC_Stop(TIM_HandleTypeDef *htim, uint32_t Channel) |
| 1574 | { |
2020 | { |
| 1575 | /* Check the parameters */ |
2021 | /* Check the parameters */ |
| 1576 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
2022 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
| 1577 | 2023 | ||
| Line 1579... | Line 2025... | ||
| 1579 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE); |
2025 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE); |
| 1580 | 2026 | ||
| 1581 | /* Disable the Peripheral */ |
2027 | /* Disable the Peripheral */ |
| 1582 | __HAL_TIM_DISABLE(htim); |
2028 | __HAL_TIM_DISABLE(htim); |
| 1583 | 2029 | ||
| - | 2030 | /* Set the TIM channel state */ |
|
| - | 2031 | TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY); |
|
| - | 2032 | ||
| 1584 | /* Return function status */ |
2033 | /* Return function status */ |
| 1585 | return HAL_OK; |
2034 | return HAL_OK; |
| 1586 | } |
2035 | } |
| 1587 | 2036 | ||
| 1588 | /** |
2037 | /** |
| 1589 | * @brief Starts the TIM Input Capture measurement in interrupt mode. |
2038 | * @brief Starts the TIM Input Capture measurement in interrupt mode. |
| 1590 | * @param htim : TIM Input Capture handle |
2039 | * @param htim TIM Input Capture handle |
| 1591 | * @param Channel : TIM Channels to be enabled |
2040 | * @param Channel TIM Channels to be enabled |
| 1592 | * This parameter can be one of the following values: |
2041 | * This parameter can be one of the following values: |
| 1593 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
2042 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
| 1594 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
2043 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
| 1595 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
2044 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
| 1596 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
2045 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
| 1597 | * @retval HAL status |
2046 | * @retval HAL status |
| 1598 | */ |
2047 | */ |
| 1599 | HAL_StatusTypeDef HAL_TIM_IC_Start_IT (TIM_HandleTypeDef *htim, uint32_t Channel) |
2048 | HAL_StatusTypeDef HAL_TIM_IC_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel) |
| 1600 | { |
2049 | { |
| - | 2050 | uint32_t tmpsmcr; |
|
| - | 2051 | HAL_TIM_ChannelStateTypeDef channel_state = TIM_CHANNEL_STATE_GET(htim, Channel); |
|
| - | 2052 | ||
| 1601 | /* Check the parameters */ |
2053 | /* Check the parameters */ |
| 1602 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
2054 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
| 1603 | 2055 | ||
| - | 2056 | /* Check the TIM channel state */ |
|
| - | 2057 | if (channel_state != HAL_TIM_CHANNEL_STATE_READY) |
|
| - | 2058 | { |
|
| - | 2059 | return HAL_ERROR; |
|
| - | 2060 | } |
|
| - | 2061 | ||
| - | 2062 | /* Set the TIM channel state */ |
|
| - | 2063 | TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_BUSY); |
|
| - | 2064 | ||
| 1604 | switch (Channel) |
2065 | switch (Channel) |
| 1605 | { |
2066 | { |
| 1606 | case TIM_CHANNEL_1: |
2067 | case TIM_CHANNEL_1: |
| 1607 | { |
2068 | { |
| 1608 | /* Enable the TIM Capture/Compare 1 interrupt */ |
2069 | /* Enable the TIM Capture/Compare 1 interrupt */ |
| 1609 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1); |
2070 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1); |
| - | 2071 | break; |
|
| 1610 | } |
2072 | } |
| 1611 | break; |
- | |
| 1612 | 2073 | ||
| 1613 | case TIM_CHANNEL_2: |
2074 | case TIM_CHANNEL_2: |
| 1614 | { |
2075 | { |
| 1615 | /* Enable the TIM Capture/Compare 2 interrupt */ |
2076 | /* Enable the TIM Capture/Compare 2 interrupt */ |
| 1616 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2); |
2077 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2); |
| - | 2078 | break; |
|
| 1617 | } |
2079 | } |
| 1618 | break; |
- | |
| 1619 | 2080 | ||
| 1620 | case TIM_CHANNEL_3: |
2081 | case TIM_CHANNEL_3: |
| 1621 | { |
2082 | { |
| 1622 | /* Enable the TIM Capture/Compare 3 interrupt */ |
2083 | /* Enable the TIM Capture/Compare 3 interrupt */ |
| 1623 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC3); |
2084 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC3); |
| - | 2085 | break; |
|
| 1624 | } |
2086 | } |
| 1625 | break; |
- | |
| 1626 | 2087 | ||
| 1627 | case TIM_CHANNEL_4: |
2088 | case TIM_CHANNEL_4: |
| 1628 | { |
2089 | { |
| 1629 | /* Enable the TIM Capture/Compare 4 interrupt */ |
2090 | /* Enable the TIM Capture/Compare 4 interrupt */ |
| 1630 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC4); |
2091 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC4); |
| - | 2092 | break; |
|
| 1631 | } |
2093 | } |
| 1632 | break; |
- | |
| 1633 | 2094 | ||
| 1634 | default: |
2095 | default: |
| 1635 | break; |
2096 | break; |
| 1636 | } |
2097 | } |
| 1637 | /* Enable the Input Capture channel */ |
2098 | /* Enable the Input Capture channel */ |
| 1638 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE); |
2099 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE); |
| 1639 | 2100 | ||
| - | 2101 | /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */ |
|
| - | 2102 | if (IS_TIM_SLAVE_INSTANCE(htim->Instance)) |
|
| - | 2103 | { |
|
| - | 2104 | tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS; |
|
| - | 2105 | if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr)) |
|
| - | 2106 | { |
|
| 1640 | /* Enable the Peripheral */ |
2107 | __HAL_TIM_ENABLE(htim); |
| - | 2108 | } |
|
| - | 2109 | } |
|
| - | 2110 | else |
|
| - | 2111 | { |
|
| 1641 | __HAL_TIM_ENABLE(htim); |
2112 | __HAL_TIM_ENABLE(htim); |
| - | 2113 | } |
|
| 1642 | 2114 | ||
| 1643 | /* Return function status */ |
2115 | /* Return function status */ |
| 1644 | return HAL_OK; |
2116 | return HAL_OK; |
| 1645 | } |
2117 | } |
| 1646 | 2118 | ||
| 1647 | /** |
2119 | /** |
| 1648 | * @brief Stops the TIM Input Capture measurement in interrupt mode. |
2120 | * @brief Stops the TIM Input Capture measurement in interrupt mode. |
| 1649 | * @param htim : TIM handle |
2121 | * @param htim TIM Input Capture handle |
| 1650 | * @param Channel : TIM Channels to be disabled |
2122 | * @param Channel TIM Channels to be disabled |
| 1651 | * This parameter can be one of the following values: |
2123 | * This parameter can be one of the following values: |
| 1652 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
2124 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
| 1653 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
2125 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
| 1654 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
2126 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
| 1655 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
2127 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
| 1656 | * @retval HAL status |
2128 | * @retval HAL status |
| 1657 | */ |
2129 | */ |
| 1658 | HAL_StatusTypeDef HAL_TIM_IC_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel) |
2130 | HAL_StatusTypeDef HAL_TIM_IC_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel) |
| 1659 | { |
2131 | { |
| 1660 | /* Check the parameters */ |
2132 | /* Check the parameters */ |
| 1661 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
2133 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
| 1662 | 2134 | ||
| Line 1664... | Line 2136... | ||
| 1664 | { |
2136 | { |
| 1665 | case TIM_CHANNEL_1: |
2137 | case TIM_CHANNEL_1: |
| 1666 | { |
2138 | { |
| 1667 | /* Disable the TIM Capture/Compare 1 interrupt */ |
2139 | /* Disable the TIM Capture/Compare 1 interrupt */ |
| 1668 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1); |
2140 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1); |
| - | 2141 | break; |
|
| 1669 | } |
2142 | } |
| 1670 | break; |
- | |
| 1671 | 2143 | ||
| 1672 | case TIM_CHANNEL_2: |
2144 | case TIM_CHANNEL_2: |
| 1673 | { |
2145 | { |
| 1674 | /* Disable the TIM Capture/Compare 2 interrupt */ |
2146 | /* Disable the TIM Capture/Compare 2 interrupt */ |
| 1675 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2); |
2147 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2); |
| - | 2148 | break; |
|
| 1676 | } |
2149 | } |
| 1677 | break; |
- | |
| 1678 | 2150 | ||
| 1679 | case TIM_CHANNEL_3: |
2151 | case TIM_CHANNEL_3: |
| 1680 | { |
2152 | { |
| 1681 | /* Disable the TIM Capture/Compare 3 interrupt */ |
2153 | /* Disable the TIM Capture/Compare 3 interrupt */ |
| 1682 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC3); |
2154 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC3); |
| - | 2155 | break; |
|
| 1683 | } |
2156 | } |
| 1684 | break; |
- | |
| 1685 | 2157 | ||
| 1686 | case TIM_CHANNEL_4: |
2158 | case TIM_CHANNEL_4: |
| 1687 | { |
2159 | { |
| 1688 | /* Disable the TIM Capture/Compare 4 interrupt */ |
2160 | /* Disable the TIM Capture/Compare 4 interrupt */ |
| 1689 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC4); |
2161 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC4); |
| - | 2162 | break; |
|
| 1690 | } |
2163 | } |
| 1691 | break; |
- | |
| 1692 | 2164 | ||
| 1693 | default: |
2165 | default: |
| 1694 | break; |
2166 | break; |
| 1695 | } |
2167 | } |
| 1696 | 2168 | ||
| 1697 | /* Disable the Input Capture channel */ |
2169 | /* Disable the Input Capture channel */ |
| 1698 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE); |
2170 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE); |
| 1699 | 2171 | ||
| 1700 | /* Disable the Peripheral */ |
2172 | /* Disable the Peripheral */ |
| 1701 | __HAL_TIM_DISABLE(htim); |
2173 | __HAL_TIM_DISABLE(htim); |
| 1702 | 2174 | ||
| - | 2175 | /* Set the TIM channel state */ |
|
| - | 2176 | TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY); |
|
| - | 2177 | ||
| 1703 | /* Return function status */ |
2178 | /* Return function status */ |
| 1704 | return HAL_OK; |
2179 | return HAL_OK; |
| 1705 | } |
2180 | } |
| 1706 | 2181 | ||
| 1707 | /** |
2182 | /** |
| 1708 | * @brief Starts the TIM Input Capture measurement in DMA mode. |
2183 | * @brief Starts the TIM Input Capture measurement in DMA mode. |
| 1709 | * @param htim : TIM Input Capture handle |
2184 | * @param htim TIM Input Capture handle |
| 1710 | * @param Channel : TIM Channels to be enabled |
2185 | * @param Channel TIM Channels to be enabled |
| 1711 | * This parameter can be one of the following values: |
2186 | * This parameter can be one of the following values: |
| 1712 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
2187 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
| 1713 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
2188 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
| 1714 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
2189 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
| 1715 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
2190 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
| 1716 | * @param pData: The destination Buffer address. |
2191 | * @param pData The destination Buffer address. |
| 1717 | * @param Length: The length of data to be transferred from TIM peripheral to memory. |
2192 | * @param Length The length of data to be transferred from TIM peripheral to memory. |
| 1718 | * @retval HAL status |
2193 | * @retval HAL status |
| 1719 | */ |
2194 | */ |
| 1720 | HAL_StatusTypeDef HAL_TIM_IC_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length) |
2195 | HAL_StatusTypeDef HAL_TIM_IC_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length) |
| 1721 | { |
2196 | { |
| - | 2197 | uint32_t tmpsmcr; |
|
| - | 2198 | HAL_TIM_ChannelStateTypeDef channel_state = TIM_CHANNEL_STATE_GET(htim, Channel); |
|
| - | 2199 | ||
| 1722 | /* Check the parameters */ |
2200 | /* Check the parameters */ |
| 1723 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
2201 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
| 1724 | assert_param(IS_TIM_DMA_CC_INSTANCE(htim->Instance)); |
2202 | assert_param(IS_TIM_DMA_CC_INSTANCE(htim->Instance)); |
| 1725 | 2203 | ||
| - | 2204 | /* Set the TIM channel state */ |
|
| 1726 | if((htim->State == HAL_TIM_STATE_BUSY)) |
2205 | if (channel_state == HAL_TIM_CHANNEL_STATE_BUSY) |
| 1727 | { |
2206 | { |
| 1728 | return HAL_BUSY; |
2207 | return HAL_BUSY; |
| 1729 | } |
2208 | } |
| 1730 | else if((htim->State == HAL_TIM_STATE_READY)) |
2209 | if (channel_state == HAL_TIM_CHANNEL_STATE_READY) |
| 1731 | { |
2210 | { |
| 1732 | if((pData == 0 ) && (Length > 0)) |
2211 | if ((pData == NULL) && (Length > 0U)) |
| 1733 | { |
2212 | { |
| 1734 | return HAL_ERROR; |
2213 | return HAL_ERROR; |
| 1735 | } |
2214 | } |
| 1736 | else |
2215 | else |
| 1737 | { |
2216 | { |
| 1738 | htim->State = HAL_TIM_STATE_BUSY; |
2217 | TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_BUSY); |
| 1739 | } |
2218 | } |
| 1740 | } |
2219 | } |
| 1741 | else |
2220 | else |
| 1742 | { |
2221 | { |
| 1743 | return HAL_ERROR; |
2222 | return HAL_ERROR; |
| Line 1745... | Line 2224... | ||
| 1745 | 2224 | ||
| 1746 | switch (Channel) |
2225 | switch (Channel) |
| 1747 | { |
2226 | { |
| 1748 | case TIM_CHANNEL_1: |
2227 | case TIM_CHANNEL_1: |
| 1749 | { |
2228 | { |
| 1750 | /* Set the DMA Period elapsed callback */ |
2229 | /* Set the DMA capture callbacks */ |
| 1751 | htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMACaptureCplt; |
2230 | htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMACaptureCplt; |
| - | 2231 | htim->hdma[TIM_DMA_ID_CC1]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt; |
|
| 1752 | 2232 | ||
| 1753 | /* Set the DMA error callback */ |
2233 | /* Set the DMA error callback */ |
| 1754 | htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ; |
2234 | htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ; |
| 1755 | 2235 | ||
| 1756 | /* Enable the DMA channel */ |
2236 | /* Enable the DMA channel */ |
| 1757 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)&htim->Instance->CCR1, (uint32_t)pData, Length); |
2237 | if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)&htim->Instance->CCR1, (uint32_t)pData, Length) != HAL_OK) |
| - | 2238 | { |
|
| - | 2239 | return HAL_ERROR; |
|
| 1758 | 2240 | } |
|
| 1759 | /* Enable the TIM Capture/Compare 1 DMA request */ |
2241 | /* Enable the TIM Capture/Compare 1 DMA request */ |
| 1760 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1); |
2242 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1); |
| - | 2243 | break; |
|
| 1761 | } |
2244 | } |
| 1762 | break; |
- | |
| 1763 | 2245 | ||
| 1764 | case TIM_CHANNEL_2: |
2246 | case TIM_CHANNEL_2: |
| 1765 | { |
2247 | { |
| 1766 | /* Set the DMA Period elapsed callback */ |
2248 | /* Set the DMA capture callbacks */ |
| 1767 | htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMACaptureCplt; |
2249 | htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMACaptureCplt; |
| - | 2250 | htim->hdma[TIM_DMA_ID_CC2]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt; |
|
| 1768 | 2251 | ||
| 1769 | /* Set the DMA error callback */ |
2252 | /* Set the DMA error callback */ |
| 1770 | htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError ; |
2253 | htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError ; |
| 1771 | 2254 | ||
| 1772 | /* Enable the DMA channel */ |
2255 | /* Enable the DMA channel */ |
| 1773 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)&htim->Instance->CCR2, (uint32_t)pData, Length); |
2256 | if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)&htim->Instance->CCR2, (uint32_t)pData, Length) != HAL_OK) |
| - | 2257 | { |
|
| - | 2258 | return HAL_ERROR; |
|
| 1774 | 2259 | } |
|
| 1775 | /* Enable the TIM Capture/Compare 2 DMA request */ |
2260 | /* Enable the TIM Capture/Compare 2 DMA request */ |
| 1776 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2); |
2261 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2); |
| - | 2262 | break; |
|
| 1777 | } |
2263 | } |
| 1778 | break; |
- | |
| 1779 | 2264 | ||
| 1780 | case TIM_CHANNEL_3: |
2265 | case TIM_CHANNEL_3: |
| 1781 | { |
2266 | { |
| 1782 | /* Set the DMA Period elapsed callback */ |
2267 | /* Set the DMA capture callbacks */ |
| 1783 | htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMACaptureCplt; |
2268 | htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMACaptureCplt; |
| - | 2269 | htim->hdma[TIM_DMA_ID_CC3]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt; |
|
| 1784 | 2270 | ||
| 1785 | /* Set the DMA error callback */ |
2271 | /* Set the DMA error callback */ |
| 1786 | htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = TIM_DMAError ; |
2272 | htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = TIM_DMAError ; |
| 1787 | 2273 | ||
| 1788 | /* Enable the DMA channel */ |
2274 | /* Enable the DMA channel */ |
| 1789 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)&htim->Instance->CCR3, (uint32_t)pData, Length); |
2275 | if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)&htim->Instance->CCR3, (uint32_t)pData, Length) != HAL_OK) |
| - | 2276 | { |
|
| - | 2277 | return HAL_ERROR; |
|
| 1790 | 2278 | } |
|
| 1791 | /* Enable the TIM Capture/Compare 3 DMA request */ |
2279 | /* Enable the TIM Capture/Compare 3 DMA request */ |
| 1792 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC3); |
2280 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC3); |
| - | 2281 | break; |
|
| 1793 | } |
2282 | } |
| 1794 | break; |
- | |
| 1795 | 2283 | ||
| 1796 | case TIM_CHANNEL_4: |
2284 | case TIM_CHANNEL_4: |
| 1797 | { |
2285 | { |
| 1798 | /* Set the DMA Period elapsed callback */ |
2286 | /* Set the DMA capture callbacks */ |
| 1799 | htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = TIM_DMACaptureCplt; |
2287 | htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = TIM_DMACaptureCplt; |
| - | 2288 | htim->hdma[TIM_DMA_ID_CC4]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt; |
|
| 1800 | 2289 | ||
| 1801 | /* Set the DMA error callback */ |
2290 | /* Set the DMA error callback */ |
| 1802 | htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = TIM_DMAError ; |
2291 | htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = TIM_DMAError ; |
| 1803 | 2292 | ||
| 1804 | /* Enable the DMA channel */ |
2293 | /* Enable the DMA channel */ |
| 1805 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)&htim->Instance->CCR4, (uint32_t)pData, Length); |
2294 | if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)&htim->Instance->CCR4, (uint32_t)pData, Length) != HAL_OK) |
| - | 2295 | { |
|
| - | 2296 | return HAL_ERROR; |
|
| 1806 | 2297 | } |
|
| 1807 | /* Enable the TIM Capture/Compare 4 DMA request */ |
2298 | /* Enable the TIM Capture/Compare 4 DMA request */ |
| 1808 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC4); |
2299 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC4); |
| - | 2300 | break; |
|
| 1809 | } |
2301 | } |
| 1810 | break; |
- | |
| 1811 | 2302 | ||
| 1812 | default: |
2303 | default: |
| 1813 | break; |
2304 | break; |
| 1814 | } |
2305 | } |
| 1815 | 2306 | ||
| 1816 | /* Enable the Input Capture channel */ |
2307 | /* Enable the Input Capture channel */ |
| 1817 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE); |
2308 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE); |
| 1818 | 2309 | ||
| - | 2310 | /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */ |
|
| - | 2311 | if (IS_TIM_SLAVE_INSTANCE(htim->Instance)) |
|
| - | 2312 | { |
|
| - | 2313 | tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS; |
|
| - | 2314 | if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr)) |
|
| - | 2315 | { |
|
| 1819 | /* Enable the Peripheral */ |
2316 | __HAL_TIM_ENABLE(htim); |
| - | 2317 | } |
|
| - | 2318 | } |
|
| - | 2319 | else |
|
| - | 2320 | { |
|
| 1820 | __HAL_TIM_ENABLE(htim); |
2321 | __HAL_TIM_ENABLE(htim); |
| - | 2322 | } |
|
| 1821 | 2323 | ||
| 1822 | /* Return function status */ |
2324 | /* Return function status */ |
| 1823 | return HAL_OK; |
2325 | return HAL_OK; |
| 1824 | } |
2326 | } |
| 1825 | 2327 | ||
| 1826 | /** |
2328 | /** |
| 1827 | * @brief Stops the TIM Input Capture measurement in DMA mode. |
2329 | * @brief Stops the TIM Input Capture measurement in DMA mode. |
| 1828 | * @param htim : TIM Input Capture handle |
2330 | * @param htim TIM Input Capture handle |
| 1829 | * @param Channel : TIM Channels to be disabled |
2331 | * @param Channel TIM Channels to be disabled |
| 1830 | * This parameter can be one of the following values: |
2332 | * This parameter can be one of the following values: |
| 1831 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
2333 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
| 1832 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
2334 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
| 1833 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
2335 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
| 1834 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
2336 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
| 1835 | * @retval HAL status |
2337 | * @retval HAL status |
| 1836 | */ |
2338 | */ |
| 1837 | HAL_StatusTypeDef HAL_TIM_IC_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel) |
2339 | HAL_StatusTypeDef HAL_TIM_IC_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel) |
| 1838 | { |
2340 | { |
| 1839 | /* Check the parameters */ |
2341 | /* Check the parameters */ |
| 1840 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
2342 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
| 1841 | assert_param(IS_TIM_DMA_CC_INSTANCE(htim->Instance)); |
2343 | assert_param(IS_TIM_DMA_CC_INSTANCE(htim->Instance)); |
| 1842 | 2344 | ||
| - | 2345 | /* Disable the Input Capture channel */ |
|
| - | 2346 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE); |
|
| - | 2347 | ||
| 1843 | switch (Channel) |
2348 | switch (Channel) |
| 1844 | { |
2349 | { |
| 1845 | case TIM_CHANNEL_1: |
2350 | case TIM_CHANNEL_1: |
| 1846 | { |
2351 | { |
| 1847 | /* Disable the TIM Capture/Compare 1 DMA request */ |
2352 | /* Disable the TIM Capture/Compare 1 DMA request */ |
| 1848 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1); |
2353 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1); |
| - | 2354 | (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC1]); |
|
| - | 2355 | break; |
|
| 1849 | } |
2356 | } |
| 1850 | break; |
- | |
| 1851 | 2357 | ||
| 1852 | case TIM_CHANNEL_2: |
2358 | case TIM_CHANNEL_2: |
| 1853 | { |
2359 | { |
| 1854 | /* Disable the TIM Capture/Compare 2 DMA request */ |
2360 | /* Disable the TIM Capture/Compare 2 DMA request */ |
| 1855 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2); |
2361 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2); |
| - | 2362 | (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC2]); |
|
| - | 2363 | break; |
|
| 1856 | } |
2364 | } |
| 1857 | break; |
- | |
| 1858 | 2365 | ||
| 1859 | case TIM_CHANNEL_3: |
2366 | case TIM_CHANNEL_3: |
| 1860 | { |
2367 | { |
| 1861 | /* Disable the TIM Capture/Compare 3 DMA request */ |
2368 | /* Disable the TIM Capture/Compare 3 DMA request */ |
| 1862 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC3); |
2369 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC3); |
| - | 2370 | (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC3]); |
|
| - | 2371 | break; |
|
| 1863 | } |
2372 | } |
| 1864 | break; |
- | |
| 1865 | 2373 | ||
| 1866 | case TIM_CHANNEL_4: |
2374 | case TIM_CHANNEL_4: |
| 1867 | { |
2375 | { |
| 1868 | /* Disable the TIM Capture/Compare 4 DMA request */ |
2376 | /* Disable the TIM Capture/Compare 4 DMA request */ |
| 1869 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC4); |
2377 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC4); |
| - | 2378 | (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC4]); |
|
| - | 2379 | break; |
|
| 1870 | } |
2380 | } |
| 1871 | break; |
- | |
| 1872 | 2381 | ||
| 1873 | default: |
2382 | default: |
| 1874 | break; |
2383 | break; |
| 1875 | } |
2384 | } |
| 1876 | 2385 | ||
| 1877 | /* Disable the Input Capture channel */ |
- | |
| 1878 | TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE); |
- | |
| 1879 | - | ||
| 1880 | /* Disable the Peripheral */ |
2386 | /* Disable the Peripheral */ |
| 1881 | __HAL_TIM_DISABLE(htim); |
2387 | __HAL_TIM_DISABLE(htim); |
| 1882 | 2388 | ||
| 1883 | /* Change the htim state */ |
2389 | /* Set the TIM channel state */ |
| 1884 | htim->State = HAL_TIM_STATE_READY; |
2390 | TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY); |
| 1885 | 2391 | ||
| 1886 | /* Return function status */ |
2392 | /* Return function status */ |
| 1887 | return HAL_OK; |
2393 | return HAL_OK; |
| 1888 | } |
2394 | } |
| 1889 | /** |
2395 | /** |
| 1890 | * @} |
2396 | * @} |
| 1891 | */ |
2397 | */ |
| 1892 | 2398 | ||
| 1893 | /** @defgroup TIM_Exported_Functions_Group5 Time One Pulse functions |
2399 | /** @defgroup TIM_Exported_Functions_Group5 TIM One Pulse functions |
| 1894 | * @brief Time One Pulse functions |
2400 | * @brief TIM One Pulse functions |
| 1895 | * |
2401 | * |
| 1896 | @verbatim |
2402 | @verbatim |
| 1897 | ============================================================================== |
2403 | ============================================================================== |
| 1898 | ##### Time One Pulse functions ##### |
2404 | ##### TIM One Pulse functions ##### |
| 1899 | ============================================================================== |
2405 | ============================================================================== |
| 1900 | [..] |
2406 | [..] |
| 1901 | This section provides functions allowing to: |
2407 | This section provides functions allowing to: |
| 1902 | (+) Initialize and configure the TIM One Pulse. |
2408 | (+) Initialize and configure the TIM One Pulse. |
| 1903 | (+) De-initialize the TIM One Pulse. |
2409 | (+) De-initialize the TIM One Pulse. |
| 1904 | (+) Start the Time One Pulse. |
2410 | (+) Start the TIM One Pulse. |
| 1905 | (+) Stop the Time One Pulse. |
2411 | (+) Stop the TIM One Pulse. |
| 1906 | (+) Start the Time One Pulse and enable interrupt. |
2412 | (+) Start the TIM One Pulse and enable interrupt. |
| 1907 | (+) Stop the Time One Pulse and disable interrupt. |
2413 | (+) Stop the TIM One Pulse and disable interrupt. |
| 1908 | (+) Start the Time One Pulse and enable DMA transfer. |
2414 | (+) Start the TIM One Pulse and enable DMA transfer. |
| 1909 | (+) Stop the Time One Pulse and disable DMA transfer. |
2415 | (+) Stop the TIM One Pulse and disable DMA transfer. |
| 1910 | 2416 | ||
| 1911 | @endverbatim |
2417 | @endverbatim |
| 1912 | * @{ |
2418 | * @{ |
| 1913 | */ |
2419 | */ |
| 1914 | /** |
2420 | /** |
| 1915 | * @brief Initializes the TIM One Pulse Time Base according to the specified |
2421 | * @brief Initializes the TIM One Pulse Time Base according to the specified |
| 1916 | * parameters in the TIM_HandleTypeDef and create the associated handle. |
2422 | * parameters in the TIM_HandleTypeDef and initializes the associated handle. |
| - | 2423 | * @note Switching from Center Aligned counter mode to Edge counter mode (or reverse) |
|
| - | 2424 | * requires a timer reset to avoid unexpected direction |
|
| - | 2425 | * due to DIR bit readonly in center aligned mode. |
|
| - | 2426 | * Ex: call @ref HAL_TIM_OnePulse_DeInit() before HAL_TIM_OnePulse_Init() |
|
| - | 2427 | * @note When the timer instance is initialized in One Pulse mode, timer |
|
| - | 2428 | * channels 1 and channel 2 are reserved and cannot be used for other |
|
| - | 2429 | * purpose. |
|
| 1917 | * @param htim: TIM OnePulse handle |
2430 | * @param htim TIM One Pulse handle |
| 1918 | * @param OnePulseMode: Select the One pulse mode. |
2431 | * @param OnePulseMode Select the One pulse mode. |
| 1919 | * This parameter can be one of the following values: |
2432 | * This parameter can be one of the following values: |
| 1920 | * @arg TIM_OPMODE_SINGLE: Only one pulse will be generated. |
2433 | * @arg TIM_OPMODE_SINGLE: Only one pulse will be generated. |
| 1921 | * @arg TIM_OPMODE_REPETITIVE: Repetitive pulses wil be generated. |
2434 | * @arg TIM_OPMODE_REPETITIVE: Repetitive pulses will be generated. |
| 1922 | * @retval HAL status |
2435 | * @retval HAL status |
| 1923 | */ |
2436 | */ |
| 1924 | HAL_StatusTypeDef HAL_TIM_OnePulse_Init(TIM_HandleTypeDef *htim, uint32_t OnePulseMode) |
2437 | HAL_StatusTypeDef HAL_TIM_OnePulse_Init(TIM_HandleTypeDef *htim, uint32_t OnePulseMode) |
| 1925 | { |
2438 | { |
| 1926 | /* Check the TIM handle allocation */ |
2439 | /* Check the TIM handle allocation */ |
| 1927 | if(htim == NULL) |
2440 | if (htim == NULL) |
| 1928 | { |
2441 | { |
| 1929 | return HAL_ERROR; |
2442 | return HAL_ERROR; |
| 1930 | } |
2443 | } |
| 1931 | 2444 | ||
| 1932 | /* Check the parameters */ |
2445 | /* Check the parameters */ |
| 1933 | assert_param(IS_TIM_INSTANCE(htim->Instance)); |
2446 | assert_param(IS_TIM_INSTANCE(htim->Instance)); |
| 1934 | assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode)); |
2447 | assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode)); |
| 1935 | assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision)); |
2448 | assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision)); |
| 1936 | assert_param(IS_TIM_OPM_MODE(OnePulseMode)); |
2449 | assert_param(IS_TIM_OPM_MODE(OnePulseMode)); |
| - | 2450 | assert_param(IS_TIM_AUTORELOAD_PRELOAD(htim->Init.AutoReloadPreload)); |
|
| 1937 | 2451 | ||
| 1938 | if(htim->State == HAL_TIM_STATE_RESET) |
2452 | if (htim->State == HAL_TIM_STATE_RESET) |
| 1939 | { |
2453 | { |
| 1940 | /* Allocate lock resource and initialize it */ |
2454 | /* Allocate lock resource and initialize it */ |
| 1941 | htim->Lock = HAL_UNLOCKED; |
2455 | htim->Lock = HAL_UNLOCKED; |
| 1942 | 2456 | ||
| - | 2457 | #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) |
|
| - | 2458 | /* Reset interrupt callbacks to legacy weak callbacks */ |
|
| - | 2459 | TIM_ResetCallback(htim); |
|
| - | 2460 | ||
| - | 2461 | if (htim->OnePulse_MspInitCallback == NULL) |
|
| - | 2462 | { |
|
| - | 2463 | htim->OnePulse_MspInitCallback = HAL_TIM_OnePulse_MspInit; |
|
| - | 2464 | } |
|
| - | 2465 | /* Init the low level hardware : GPIO, CLOCK, NVIC */ |
|
| - | 2466 | htim->OnePulse_MspInitCallback(htim); |
|
| - | 2467 | #else |
|
| 1943 | /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */ |
2468 | /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */ |
| 1944 | HAL_TIM_OnePulse_MspInit(htim); |
2469 | HAL_TIM_OnePulse_MspInit(htim); |
| - | 2470 | #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */ |
|
| 1945 | } |
2471 | } |
| 1946 | 2472 | ||
| 1947 | /* Set the TIM state */ |
2473 | /* Set the TIM state */ |
| 1948 | htim->State= HAL_TIM_STATE_BUSY; |
2474 | htim->State = HAL_TIM_STATE_BUSY; |
| 1949 | 2475 | ||
| 1950 | /* Configure the Time base in the One Pulse Mode */ |
2476 | /* Configure the Time base in the One Pulse Mode */ |
| 1951 | TIM_Base_SetConfig(htim->Instance, &htim->Init); |
2477 | TIM_Base_SetConfig(htim->Instance, &htim->Init); |
| 1952 | 2478 | ||
| 1953 | /* Reset the OPM Bit */ |
2479 | /* Reset the OPM Bit */ |
| 1954 | htim->Instance->CR1 &= ~TIM_CR1_OPM; |
2480 | htim->Instance->CR1 &= ~TIM_CR1_OPM; |
| 1955 | 2481 | ||
| 1956 | /* Configure the OPM Mode */ |
2482 | /* Configure the OPM Mode */ |
| 1957 | htim->Instance->CR1 |= OnePulseMode; |
2483 | htim->Instance->CR1 |= OnePulseMode; |
| 1958 | 2484 | ||
| - | 2485 | /* Initialize the DMA burst operation state */ |
|
| - | 2486 | htim->DMABurstState = HAL_DMA_BURST_STATE_READY; |
|
| - | 2487 | ||
| - | 2488 | /* Initialize the TIM channels state */ |
|
| - | 2489 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY); |
|
| - | 2490 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY); |
|
| - | 2491 | ||
| 1959 | /* Initialize the TIM state*/ |
2492 | /* Initialize the TIM state*/ |
| 1960 | htim->State= HAL_TIM_STATE_READY; |
2493 | htim->State = HAL_TIM_STATE_READY; |
| 1961 | 2494 | ||
| 1962 | return HAL_OK; |
2495 | return HAL_OK; |
| 1963 | } |
2496 | } |
| 1964 | 2497 | ||
| 1965 | /** |
2498 | /** |
| 1966 | * @brief DeInitializes the TIM One Pulse |
2499 | * @brief DeInitializes the TIM One Pulse |
| 1967 | * @param htim: TIM One Pulse handle |
2500 | * @param htim TIM One Pulse handle |
| 1968 | * @retval HAL status |
2501 | * @retval HAL status |
| 1969 | */ |
2502 | */ |
| 1970 | HAL_StatusTypeDef HAL_TIM_OnePulse_DeInit(TIM_HandleTypeDef *htim) |
2503 | HAL_StatusTypeDef HAL_TIM_OnePulse_DeInit(TIM_HandleTypeDef *htim) |
| 1971 | { |
2504 | { |
| 1972 | /* Check the parameters */ |
2505 | /* Check the parameters */ |
| Line 1975... | Line 2508... | ||
| 1975 | htim->State = HAL_TIM_STATE_BUSY; |
2508 | htim->State = HAL_TIM_STATE_BUSY; |
| 1976 | 2509 | ||
| 1977 | /* Disable the TIM Peripheral Clock */ |
2510 | /* Disable the TIM Peripheral Clock */ |
| 1978 | __HAL_TIM_DISABLE(htim); |
2511 | __HAL_TIM_DISABLE(htim); |
| 1979 | 2512 | ||
| - | 2513 | #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) |
|
| - | 2514 | if (htim->OnePulse_MspDeInitCallback == NULL) |
|
| - | 2515 | { |
|
| - | 2516 | htim->OnePulse_MspDeInitCallback = HAL_TIM_OnePulse_MspDeInit; |
|
| - | 2517 | } |
|
| - | 2518 | /* DeInit the low level hardware */ |
|
| - | 2519 | htim->OnePulse_MspDeInitCallback(htim); |
|
| - | 2520 | #else |
|
| 1980 | /* DeInit the low level hardware: GPIO, CLOCK, NVIC */ |
2521 | /* DeInit the low level hardware: GPIO, CLOCK, NVIC */ |
| 1981 | HAL_TIM_OnePulse_MspDeInit(htim); |
2522 | HAL_TIM_OnePulse_MspDeInit(htim); |
| - | 2523 | #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */ |
|
| - | 2524 | ||
| - | 2525 | /* Change the DMA burst operation state */ |
|
| - | 2526 | htim->DMABurstState = HAL_DMA_BURST_STATE_RESET; |
|
| - | 2527 | ||
| - | 2528 | /* Set the TIM channel state */ |
|
| - | 2529 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_RESET); |
|
| - | 2530 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_RESET); |
|
| 1982 | 2531 | ||
| 1983 | /* Change TIM state */ |
2532 | /* Change TIM state */ |
| 1984 | htim->State = HAL_TIM_STATE_RESET; |
2533 | htim->State = HAL_TIM_STATE_RESET; |
| 1985 | 2534 | ||
| 1986 | /* Release Lock */ |
2535 | /* Release Lock */ |
| Line 1989... | Line 2538... | ||
| 1989 | return HAL_OK; |
2538 | return HAL_OK; |
| 1990 | } |
2539 | } |
| 1991 | 2540 | ||
| 1992 | /** |
2541 | /** |
| 1993 | * @brief Initializes the TIM One Pulse MSP. |
2542 | * @brief Initializes the TIM One Pulse MSP. |
| 1994 | * @param htim: TIM handle |
2543 | * @param htim TIM One Pulse handle |
| 1995 | * @retval None |
2544 | * @retval None |
| 1996 | */ |
2545 | */ |
| 1997 | __weak void HAL_TIM_OnePulse_MspInit(TIM_HandleTypeDef *htim) |
2546 | __weak void HAL_TIM_OnePulse_MspInit(TIM_HandleTypeDef *htim) |
| 1998 | { |
2547 | { |
| 1999 | /* Prevent unused argument(s) compilation warning */ |
2548 | /* Prevent unused argument(s) compilation warning */ |
| 2000 | UNUSED(htim); |
2549 | UNUSED(htim); |
| 2001 | 2550 | ||
| 2002 | /* NOTE : This function Should not be modified, when the callback is needed, |
2551 | /* NOTE : This function should not be modified, when the callback is needed, |
| 2003 | the HAL_TIM_OnePulse_MspInit could be implemented in the user file |
2552 | the HAL_TIM_OnePulse_MspInit could be implemented in the user file |
| 2004 | */ |
2553 | */ |
| 2005 | } |
2554 | } |
| 2006 | 2555 | ||
| 2007 | /** |
2556 | /** |
| 2008 | * @brief DeInitializes TIM One Pulse MSP. |
2557 | * @brief DeInitializes TIM One Pulse MSP. |
| 2009 | * @param htim: TIM handle |
2558 | * @param htim TIM One Pulse handle |
| 2010 | * @retval None |
2559 | * @retval None |
| 2011 | */ |
2560 | */ |
| 2012 | __weak void HAL_TIM_OnePulse_MspDeInit(TIM_HandleTypeDef *htim) |
2561 | __weak void HAL_TIM_OnePulse_MspDeInit(TIM_HandleTypeDef *htim) |
| 2013 | { |
2562 | { |
| 2014 | /* Prevent unused argument(s) compilation warning */ |
2563 | /* Prevent unused argument(s) compilation warning */ |
| 2015 | UNUSED(htim); |
2564 | UNUSED(htim); |
| 2016 | 2565 | ||
| 2017 | /* NOTE : This function Should not be modified, when the callback is needed, |
2566 | /* NOTE : This function should not be modified, when the callback is needed, |
| 2018 | the HAL_TIM_OnePulse_MspDeInit could be implemented in the user file |
2567 | the HAL_TIM_OnePulse_MspDeInit could be implemented in the user file |
| 2019 | */ |
2568 | */ |
| 2020 | } |
2569 | } |
| 2021 | 2570 | ||
| 2022 | /** |
2571 | /** |
| 2023 | * @brief Starts the TIM One Pulse signal generation. |
2572 | * @brief Starts the TIM One Pulse signal generation. |
| 2024 | * @param htim : TIM One Pulse handle |
2573 | * @param htim TIM One Pulse handle |
| 2025 | * @param OutputChannel : TIM Channels to be enabled |
2574 | * @param OutputChannel TIM Channels to be enabled |
| 2026 | * This parameter can be one of the following values: |
2575 | * This parameter can be one of the following values: |
| 2027 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
2576 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
| 2028 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
2577 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
| 2029 | * @retval HAL status |
2578 | * @retval HAL status |
| 2030 | */ |
2579 | */ |
| 2031 | HAL_StatusTypeDef HAL_TIM_OnePulse_Start(TIM_HandleTypeDef *htim, uint32_t OutputChannel) |
2580 | HAL_StatusTypeDef HAL_TIM_OnePulse_Start(TIM_HandleTypeDef *htim, uint32_t OutputChannel) |
| 2032 | { |
2581 | { |
| - | 2582 | HAL_TIM_ChannelStateTypeDef channel_1_state = TIM_CHANNEL_STATE_GET(htim, TIM_CHANNEL_1); |
|
| - | 2583 | HAL_TIM_ChannelStateTypeDef channel_2_state = TIM_CHANNEL_STATE_GET(htim, TIM_CHANNEL_2); |
|
| - | 2584 | ||
| - | 2585 | /* Prevent unused argument(s) compilation warning */ |
|
| - | 2586 | UNUSED(OutputChannel); |
|
| - | 2587 | ||
| - | 2588 | /* Check the TIM channels state */ |
|
| - | 2589 | if ((channel_1_state != HAL_TIM_CHANNEL_STATE_READY) |
|
| - | 2590 | || (channel_2_state != HAL_TIM_CHANNEL_STATE_READY)) |
|
| - | 2591 | { |
|
| - | 2592 | return HAL_ERROR; |
|
| - | 2593 | } |
|
| - | 2594 | ||
| - | 2595 | /* Set the TIM channels state */ |
|
| - | 2596 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_BUSY); |
|
| - | 2597 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_BUSY); |
|
| - | 2598 | ||
| 2033 | /* Enable the Capture compare and the Input Capture channels |
2599 | /* Enable the Capture compare and the Input Capture channels |
| 2034 | (in the OPM Mode the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2) |
2600 | (in the OPM Mode the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2) |
| 2035 | if TIM_CHANNEL_1 is used as output, the TIM_CHANNEL_2 will be used as input and |
2601 | if TIM_CHANNEL_1 is used as output, the TIM_CHANNEL_2 will be used as input and |
| 2036 | if TIM_CHANNEL_1 is used as input, the TIM_CHANNEL_2 will be used as output |
2602 | if TIM_CHANNEL_1 is used as input, the TIM_CHANNEL_2 will be used as output |
| 2037 | in all combinations, the TIM_CHANNEL_1 and TIM_CHANNEL_2 should be enabled together |
2603 | in all combinations, the TIM_CHANNEL_1 and TIM_CHANNEL_2 should be enabled together |
| Line 2046... | Line 2612... | ||
| 2046 | return HAL_OK; |
2612 | return HAL_OK; |
| 2047 | } |
2613 | } |
| 2048 | 2614 | ||
| 2049 | /** |
2615 | /** |
| 2050 | * @brief Stops the TIM One Pulse signal generation. |
2616 | * @brief Stops the TIM One Pulse signal generation. |
| 2051 | * @param htim : TIM One Pulse handle |
2617 | * @param htim TIM One Pulse handle |
| 2052 | * @param OutputChannel : TIM Channels to be disable |
2618 | * @param OutputChannel TIM Channels to be disable |
| 2053 | * This parameter can be one of the following values: |
2619 | * This parameter can be one of the following values: |
| 2054 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
2620 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
| 2055 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
2621 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
| 2056 | * @retval HAL status |
2622 | * @retval HAL status |
| 2057 | */ |
2623 | */ |
| 2058 | HAL_StatusTypeDef HAL_TIM_OnePulse_Stop(TIM_HandleTypeDef *htim, uint32_t OutputChannel) |
2624 | HAL_StatusTypeDef HAL_TIM_OnePulse_Stop(TIM_HandleTypeDef *htim, uint32_t OutputChannel) |
| 2059 | { |
2625 | { |
| - | 2626 | /* Prevent unused argument(s) compilation warning */ |
|
| - | 2627 | UNUSED(OutputChannel); |
|
| - | 2628 | ||
| 2060 | /* Disable the Capture compare and the Input Capture channels |
2629 | /* Disable the Capture compare and the Input Capture channels |
| 2061 | (in the OPM Mode the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2) |
2630 | (in the OPM Mode the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2) |
| 2062 | if TIM_CHANNEL_1 is used as output, the TIM_CHANNEL_2 will be used as input and |
2631 | if TIM_CHANNEL_1 is used as output, the TIM_CHANNEL_2 will be used as input and |
| 2063 | if TIM_CHANNEL_1 is used as input, the TIM_CHANNEL_2 will be used as output |
2632 | if TIM_CHANNEL_1 is used as input, the TIM_CHANNEL_2 will be used as output |
| 2064 | in all combinations, the TIM_CHANNEL_1 and TIM_CHANNEL_2 should be disabled together */ |
2633 | in all combinations, the TIM_CHANNEL_1 and TIM_CHANNEL_2 should be disabled together */ |
| Line 2067... | Line 2636... | ||
| 2067 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE); |
2636 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE); |
| 2068 | 2637 | ||
| 2069 | /* Disable the Peripheral */ |
2638 | /* Disable the Peripheral */ |
| 2070 | __HAL_TIM_DISABLE(htim); |
2639 | __HAL_TIM_DISABLE(htim); |
| 2071 | 2640 | ||
| - | 2641 | /* Set the TIM channels state */ |
|
| - | 2642 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY); |
|
| - | 2643 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY); |
|
| - | 2644 | ||
| 2072 | /* Return function status */ |
2645 | /* Return function status */ |
| 2073 | return HAL_OK; |
2646 | return HAL_OK; |
| 2074 | } |
2647 | } |
| 2075 | 2648 | ||
| 2076 | /** |
2649 | /** |
| 2077 | * @brief Starts the TIM One Pulse signal generation in interrupt mode. |
2650 | * @brief Starts the TIM One Pulse signal generation in interrupt mode. |
| 2078 | * @param htim : TIM One Pulse handle |
2651 | * @param htim TIM One Pulse handle |
| 2079 | * @param OutputChannel : TIM Channels to be enabled |
2652 | * @param OutputChannel TIM Channels to be enabled |
| 2080 | * This parameter can be one of the following values: |
2653 | * This parameter can be one of the following values: |
| 2081 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
2654 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
| 2082 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
2655 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
| 2083 | * @retval HAL status |
2656 | * @retval HAL status |
| 2084 | */ |
2657 | */ |
| 2085 | HAL_StatusTypeDef HAL_TIM_OnePulse_Start_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel) |
2658 | HAL_StatusTypeDef HAL_TIM_OnePulse_Start_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel) |
| 2086 | { |
2659 | { |
| - | 2660 | HAL_TIM_ChannelStateTypeDef channel_1_state = TIM_CHANNEL_STATE_GET(htim, TIM_CHANNEL_1); |
|
| - | 2661 | HAL_TIM_ChannelStateTypeDef channel_2_state = TIM_CHANNEL_STATE_GET(htim, TIM_CHANNEL_2); |
|
| - | 2662 | ||
| - | 2663 | /* Prevent unused argument(s) compilation warning */ |
|
| - | 2664 | UNUSED(OutputChannel); |
|
| - | 2665 | ||
| - | 2666 | /* Check the TIM channels state */ |
|
| - | 2667 | if ((channel_1_state != HAL_TIM_CHANNEL_STATE_READY) |
|
| - | 2668 | || (channel_2_state != HAL_TIM_CHANNEL_STATE_READY)) |
|
| - | 2669 | { |
|
| - | 2670 | return HAL_ERROR; |
|
| - | 2671 | } |
|
| - | 2672 | ||
| - | 2673 | /* Set the TIM channels state */ |
|
| - | 2674 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_BUSY); |
|
| - | 2675 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_BUSY); |
|
| - | 2676 | ||
| 2087 | /* Enable the Capture compare and the Input Capture channels |
2677 | /* Enable the Capture compare and the Input Capture channels |
| 2088 | (in the OPM Mode the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2) |
2678 | (in the OPM Mode the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2) |
| 2089 | if TIM_CHANNEL_1 is used as output, the TIM_CHANNEL_2 will be used as input and |
2679 | if TIM_CHANNEL_1 is used as output, the TIM_CHANNEL_2 will be used as input and |
| 2090 | if TIM_CHANNEL_1 is used as input, the TIM_CHANNEL_2 will be used as output |
2680 | if TIM_CHANNEL_1 is used as input, the TIM_CHANNEL_2 will be used as output |
| 2091 | in all combinations, the TIM_CHANNEL_1 and TIM_CHANNEL_2 should be enabled together |
2681 | in all combinations, the TIM_CHANNEL_1 and TIM_CHANNEL_2 should be enabled together |
| Line 2106... | Line 2696... | ||
| 2106 | return HAL_OK; |
2696 | return HAL_OK; |
| 2107 | } |
2697 | } |
| 2108 | 2698 | ||
| 2109 | /** |
2699 | /** |
| 2110 | * @brief Stops the TIM One Pulse signal generation in interrupt mode. |
2700 | * @brief Stops the TIM One Pulse signal generation in interrupt mode. |
| 2111 | * @param htim : TIM One Pulse handle |
2701 | * @param htim TIM One Pulse handle |
| 2112 | * @param OutputChannel : TIM Channels to be enabled |
2702 | * @param OutputChannel TIM Channels to be enabled |
| 2113 | * This parameter can be one of the following values: |
2703 | * This parameter can be one of the following values: |
| 2114 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
2704 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
| 2115 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
2705 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
| 2116 | * @retval HAL status |
2706 | * @retval HAL status |
| 2117 | */ |
2707 | */ |
| 2118 | HAL_StatusTypeDef HAL_TIM_OnePulse_Stop_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel) |
2708 | HAL_StatusTypeDef HAL_TIM_OnePulse_Stop_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel) |
| 2119 | { |
2709 | { |
| - | 2710 | /* Prevent unused argument(s) compilation warning */ |
|
| - | 2711 | UNUSED(OutputChannel); |
|
| - | 2712 | ||
| 2120 | /* Disable the TIM Capture/Compare 1 interrupt */ |
2713 | /* Disable the TIM Capture/Compare 1 interrupt */ |
| 2121 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1); |
2714 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1); |
| 2122 | 2715 | ||
| 2123 | /* Disable the TIM Capture/Compare 2 interrupt */ |
2716 | /* Disable the TIM Capture/Compare 2 interrupt */ |
| 2124 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2); |
2717 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2); |
| Line 2130... | Line 2723... | ||
| 2130 | in all combinations, the TIM_CHANNEL_1 and TIM_CHANNEL_2 should be disabled together */ |
2723 | in all combinations, the TIM_CHANNEL_1 and TIM_CHANNEL_2 should be disabled together */ |
| 2131 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE); |
2724 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE); |
| 2132 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE); |
2725 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE); |
| 2133 | 2726 | ||
| 2134 | /* Disable the Peripheral */ |
2727 | /* Disable the Peripheral */ |
| 2135 | __HAL_TIM_DISABLE(htim); |
2728 | __HAL_TIM_DISABLE(htim); |
| - | 2729 | ||
| - | 2730 | /* Set the TIM channels state */ |
|
| - | 2731 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY); |
|
| - | 2732 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY); |
|
| 2136 | 2733 | ||
| 2137 | /* Return function status */ |
2734 | /* Return function status */ |
| 2138 | return HAL_OK; |
2735 | return HAL_OK; |
| 2139 | } |
2736 | } |
| 2140 | 2737 | ||
| 2141 | /** |
2738 | /** |
| 2142 | * @} |
2739 | * @} |
| 2143 | */ |
2740 | */ |
| 2144 | 2741 | ||
| 2145 | /** @defgroup TIM_Exported_Functions_Group6 Time Encoder functions |
2742 | /** @defgroup TIM_Exported_Functions_Group6 TIM Encoder functions |
| 2146 | * @brief Time Encoder functions |
2743 | * @brief TIM Encoder functions |
| 2147 | * |
2744 | * |
| 2148 | @verbatim |
2745 | @verbatim |
| 2149 | ============================================================================== |
2746 | ============================================================================== |
| 2150 | ##### Time Encoder functions ##### |
2747 | ##### TIM Encoder functions ##### |
| 2151 | ============================================================================== |
2748 | ============================================================================== |
| 2152 | [..] |
2749 | [..] |
| 2153 | This section provides functions allowing to: |
2750 | This section provides functions allowing to: |
| 2154 | (+) Initialize and configure the TIM Encoder. |
2751 | (+) Initialize and configure the TIM Encoder. |
| 2155 | (+) De-initialize the TIM Encoder. |
2752 | (+) De-initialize the TIM Encoder. |
| 2156 | (+) Start the Time Encoder. |
2753 | (+) Start the TIM Encoder. |
| 2157 | (+) Stop the Time Encoder. |
2754 | (+) Stop the TIM Encoder. |
| 2158 | (+) Start the Time Encoder and enable interrupt. |
2755 | (+) Start the TIM Encoder and enable interrupt. |
| 2159 | (+) Stop the Time Encoder and disable interrupt. |
2756 | (+) Stop the TIM Encoder and disable interrupt. |
| 2160 | (+) Start the Time Encoder and enable DMA transfer. |
2757 | (+) Start the TIM Encoder and enable DMA transfer. |
| 2161 | (+) Stop the Time Encoder and disable DMA transfer. |
2758 | (+) Stop the TIM Encoder and disable DMA transfer. |
| 2162 | 2759 | ||
| 2163 | @endverbatim |
2760 | @endverbatim |
| 2164 | * @{ |
2761 | * @{ |
| 2165 | */ |
2762 | */ |
| 2166 | /** |
2763 | /** |
| 2167 | * @brief Initializes the TIM Encoder Interface and create the associated handle. |
2764 | * @brief Initializes the TIM Encoder Interface and initialize the associated handle. |
| - | 2765 | * @note Switching from Center Aligned counter mode to Edge counter mode (or reverse) |
|
| - | 2766 | * requires a timer reset to avoid unexpected direction |
|
| - | 2767 | * due to DIR bit readonly in center aligned mode. |
|
| - | 2768 | * Ex: call @ref HAL_TIM_Encoder_DeInit() before HAL_TIM_Encoder_Init() |
|
| - | 2769 | * @note Encoder mode and External clock mode 2 are not compatible and must not be selected together |
|
| - | 2770 | * Ex: A call for @ref HAL_TIM_Encoder_Init will erase the settings of @ref HAL_TIM_ConfigClockSource |
|
| - | 2771 | * using TIM_CLOCKSOURCE_ETRMODE2 and vice versa |
|
| - | 2772 | * @note When the timer instance is initialized in Encoder mode, timer |
|
| - | 2773 | * channels 1 and channel 2 are reserved and cannot be used for other |
|
| - | 2774 | * purpose. |
|
| 2168 | * @param htim: TIM Encoder Interface handle |
2775 | * @param htim TIM Encoder Interface handle |
| 2169 | * @param sConfig: TIM Encoder Interface configuration structure |
2776 | * @param sConfig TIM Encoder Interface configuration structure |
| 2170 | * @retval HAL status |
2777 | * @retval HAL status |
| 2171 | */ |
2778 | */ |
| 2172 | HAL_StatusTypeDef HAL_TIM_Encoder_Init(TIM_HandleTypeDef *htim, TIM_Encoder_InitTypeDef* sConfig) |
2779 | HAL_StatusTypeDef HAL_TIM_Encoder_Init(TIM_HandleTypeDef *htim, TIM_Encoder_InitTypeDef *sConfig) |
| 2173 | { |
2780 | { |
| 2174 | uint32_t tmpsmcr = 0; |
2781 | uint32_t tmpsmcr; |
| 2175 | uint32_t tmpccmr1 = 0; |
2782 | uint32_t tmpccmr1; |
| 2176 | uint32_t tmpccer = 0; |
2783 | uint32_t tmpccer; |
| 2177 | 2784 | ||
| 2178 | /* Check the TIM handle allocation */ |
2785 | /* Check the TIM handle allocation */ |
| 2179 | if(htim == NULL) |
2786 | if (htim == NULL) |
| 2180 | { |
2787 | { |
| 2181 | return HAL_ERROR; |
2788 | return HAL_ERROR; |
| 2182 | } |
2789 | } |
| 2183 | 2790 | ||
| 2184 | /* Check the parameters */ |
2791 | /* Check the parameters */ |
| 2185 | assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); |
2792 | assert_param(IS_TIM_ENCODER_INTERFACE_INSTANCE(htim->Instance)); |
| - | 2793 | assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode)); |
|
| - | 2794 | assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision)); |
|
| - | 2795 | assert_param(IS_TIM_AUTORELOAD_PRELOAD(htim->Init.AutoReloadPreload)); |
|
| 2186 | assert_param(IS_TIM_ENCODER_MODE(sConfig->EncoderMode)); |
2796 | assert_param(IS_TIM_ENCODER_MODE(sConfig->EncoderMode)); |
| 2187 | assert_param(IS_TIM_IC_SELECTION(sConfig->IC1Selection)); |
2797 | assert_param(IS_TIM_IC_SELECTION(sConfig->IC1Selection)); |
| 2188 | assert_param(IS_TIM_IC_SELECTION(sConfig->IC2Selection)); |
2798 | assert_param(IS_TIM_IC_SELECTION(sConfig->IC2Selection)); |
| 2189 | assert_param(IS_TIM_IC_POLARITY(sConfig->IC1Polarity)); |
2799 | assert_param(IS_TIM_ENCODERINPUT_POLARITY(sConfig->IC1Polarity)); |
| 2190 | assert_param(IS_TIM_IC_POLARITY(sConfig->IC2Polarity)); |
2800 | assert_param(IS_TIM_ENCODERINPUT_POLARITY(sConfig->IC2Polarity)); |
| 2191 | assert_param(IS_TIM_IC_PRESCALER(sConfig->IC1Prescaler)); |
2801 | assert_param(IS_TIM_IC_PRESCALER(sConfig->IC1Prescaler)); |
| 2192 | assert_param(IS_TIM_IC_PRESCALER(sConfig->IC2Prescaler)); |
2802 | assert_param(IS_TIM_IC_PRESCALER(sConfig->IC2Prescaler)); |
| 2193 | assert_param(IS_TIM_IC_FILTER(sConfig->IC1Filter)); |
2803 | assert_param(IS_TIM_IC_FILTER(sConfig->IC1Filter)); |
| 2194 | assert_param(IS_TIM_IC_FILTER(sConfig->IC2Filter)); |
2804 | assert_param(IS_TIM_IC_FILTER(sConfig->IC2Filter)); |
| 2195 | 2805 | ||
| 2196 | if(htim->State == HAL_TIM_STATE_RESET) |
2806 | if (htim->State == HAL_TIM_STATE_RESET) |
| 2197 | { |
2807 | { |
| 2198 | /* Allocate lock resource and initialize it */ |
2808 | /* Allocate lock resource and initialize it */ |
| 2199 | htim->Lock = HAL_UNLOCKED; |
2809 | htim->Lock = HAL_UNLOCKED; |
| 2200 | 2810 | ||
| - | 2811 | #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) |
|
| - | 2812 | /* Reset interrupt callbacks to legacy weak callbacks */ |
|
| - | 2813 | TIM_ResetCallback(htim); |
|
| - | 2814 | ||
| - | 2815 | if (htim->Encoder_MspInitCallback == NULL) |
|
| - | 2816 | { |
|
| - | 2817 | htim->Encoder_MspInitCallback = HAL_TIM_Encoder_MspInit; |
|
| - | 2818 | } |
|
| - | 2819 | /* Init the low level hardware : GPIO, CLOCK, NVIC */ |
|
| - | 2820 | htim->Encoder_MspInitCallback(htim); |
|
| - | 2821 | #else |
|
| 2201 | /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */ |
2822 | /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */ |
| 2202 | HAL_TIM_Encoder_MspInit(htim); |
2823 | HAL_TIM_Encoder_MspInit(htim); |
| - | 2824 | #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */ |
|
| 2203 | } |
2825 | } |
| 2204 | 2826 | ||
| 2205 | /* Set the TIM state */ |
2827 | /* Set the TIM state */ |
| 2206 | htim->State= HAL_TIM_STATE_BUSY; |
2828 | htim->State = HAL_TIM_STATE_BUSY; |
| 2207 | 2829 | ||
| 2208 | /* Reset the SMS bits */ |
2830 | /* Reset the SMS and ECE bits */ |
| 2209 | htim->Instance->SMCR &= ~TIM_SMCR_SMS; |
2831 | htim->Instance->SMCR &= ~(TIM_SMCR_SMS | TIM_SMCR_ECE); |
| 2210 | 2832 | ||
| 2211 | /* Configure the Time base in the Encoder Mode */ |
2833 | /* Configure the Time base in the Encoder Mode */ |
| 2212 | TIM_Base_SetConfig(htim->Instance, &htim->Init); |
2834 | TIM_Base_SetConfig(htim->Instance, &htim->Init); |
| 2213 | 2835 | ||
| 2214 | /* Get the TIMx SMCR register value */ |
2836 | /* Get the TIMx SMCR register value */ |
| Line 2223... | Line 2845... | ||
| 2223 | /* Set the encoder Mode */ |
2845 | /* Set the encoder Mode */ |
| 2224 | tmpsmcr |= sConfig->EncoderMode; |
2846 | tmpsmcr |= sConfig->EncoderMode; |
| 2225 | 2847 | ||
| 2226 | /* Select the Capture Compare 1 and the Capture Compare 2 as input */ |
2848 | /* Select the Capture Compare 1 and the Capture Compare 2 as input */ |
| 2227 | tmpccmr1 &= ~(TIM_CCMR1_CC1S | TIM_CCMR1_CC2S); |
2849 | tmpccmr1 &= ~(TIM_CCMR1_CC1S | TIM_CCMR1_CC2S); |
| 2228 | tmpccmr1 |= (sConfig->IC1Selection | (sConfig->IC2Selection << 8)); |
2850 | tmpccmr1 |= (sConfig->IC1Selection | (sConfig->IC2Selection << 8U)); |
| 2229 | 2851 | ||
| 2230 | /* Set the the Capture Compare 1 and the Capture Compare 2 prescalers and filters */ |
2852 | /* Set the Capture Compare 1 and the Capture Compare 2 prescalers and filters */ |
| 2231 | tmpccmr1 &= ~(TIM_CCMR1_IC1PSC | TIM_CCMR1_IC2PSC); |
2853 | tmpccmr1 &= ~(TIM_CCMR1_IC1PSC | TIM_CCMR1_IC2PSC); |
| 2232 | tmpccmr1 &= ~(TIM_CCMR1_IC1F | TIM_CCMR1_IC2F); |
2854 | tmpccmr1 &= ~(TIM_CCMR1_IC1F | TIM_CCMR1_IC2F); |
| 2233 | tmpccmr1 |= sConfig->IC1Prescaler | (sConfig->IC2Prescaler << 8); |
2855 | tmpccmr1 |= sConfig->IC1Prescaler | (sConfig->IC2Prescaler << 8U); |
| 2234 | tmpccmr1 |= (sConfig->IC1Filter << 4) | (sConfig->IC2Filter << 12); |
2856 | tmpccmr1 |= (sConfig->IC1Filter << 4U) | (sConfig->IC2Filter << 12U); |
| 2235 | 2857 | ||
| 2236 | /* Set the TI1 and the TI2 Polarities */ |
2858 | /* Set the TI1 and the TI2 Polarities */ |
| 2237 | tmpccer &= ~(TIM_CCER_CC1P | TIM_CCER_CC2P); |
2859 | tmpccer &= ~(TIM_CCER_CC1P | TIM_CCER_CC2P); |
| 2238 | tmpccer &= ~(TIM_CCER_CC1NP | TIM_CCER_CC2NP); |
2860 | tmpccer &= ~(TIM_CCER_CC1NP | TIM_CCER_CC2NP); |
| 2239 | tmpccer |= sConfig->IC1Polarity | (sConfig->IC2Polarity << 4); |
2861 | tmpccer |= sConfig->IC1Polarity | (sConfig->IC2Polarity << 4U); |
| 2240 | 2862 | ||
| 2241 | /* Write to TIMx SMCR */ |
2863 | /* Write to TIMx SMCR */ |
| 2242 | htim->Instance->SMCR = tmpsmcr; |
2864 | htim->Instance->SMCR = tmpsmcr; |
| 2243 | 2865 | ||
| 2244 | /* Write to TIMx CCMR1 */ |
2866 | /* Write to TIMx CCMR1 */ |
| 2245 | htim->Instance->CCMR1 = tmpccmr1; |
2867 | htim->Instance->CCMR1 = tmpccmr1; |
| 2246 | 2868 | ||
| 2247 | /* Write to TIMx CCER */ |
2869 | /* Write to TIMx CCER */ |
| 2248 | htim->Instance->CCER = tmpccer; |
2870 | htim->Instance->CCER = tmpccer; |
| 2249 | 2871 | ||
| - | 2872 | /* Initialize the DMA burst operation state */ |
|
| - | 2873 | htim->DMABurstState = HAL_DMA_BURST_STATE_READY; |
|
| - | 2874 | ||
| - | 2875 | /* Set the TIM channels state */ |
|
| - | 2876 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY); |
|
| - | 2877 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY); |
|
| - | 2878 | ||
| 2250 | /* Initialize the TIM state*/ |
2879 | /* Initialize the TIM state*/ |
| 2251 | htim->State= HAL_TIM_STATE_READY; |
2880 | htim->State = HAL_TIM_STATE_READY; |
| 2252 | 2881 | ||
| 2253 | return HAL_OK; |
2882 | return HAL_OK; |
| 2254 | } |
2883 | } |
| 2255 | 2884 | ||
| 2256 | 2885 | ||
| 2257 | /** |
2886 | /** |
| 2258 | * @brief DeInitializes the TIM Encoder interface |
2887 | * @brief DeInitializes the TIM Encoder interface |
| 2259 | * @param htim: TIM Encoder handle |
2888 | * @param htim TIM Encoder Interface handle |
| 2260 | * @retval HAL status |
2889 | * @retval HAL status |
| 2261 | */ |
2890 | */ |
| 2262 | HAL_StatusTypeDef HAL_TIM_Encoder_DeInit(TIM_HandleTypeDef *htim) |
2891 | HAL_StatusTypeDef HAL_TIM_Encoder_DeInit(TIM_HandleTypeDef *htim) |
| 2263 | { |
2892 | { |
| 2264 | /* Check the parameters */ |
2893 | /* Check the parameters */ |
| Line 2267... | Line 2896... | ||
| 2267 | htim->State = HAL_TIM_STATE_BUSY; |
2896 | htim->State = HAL_TIM_STATE_BUSY; |
| 2268 | 2897 | ||
| 2269 | /* Disable the TIM Peripheral Clock */ |
2898 | /* Disable the TIM Peripheral Clock */ |
| 2270 | __HAL_TIM_DISABLE(htim); |
2899 | __HAL_TIM_DISABLE(htim); |
| 2271 | 2900 | ||
| - | 2901 | #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) |
|
| - | 2902 | if (htim->Encoder_MspDeInitCallback == NULL) |
|
| - | 2903 | { |
|
| - | 2904 | htim->Encoder_MspDeInitCallback = HAL_TIM_Encoder_MspDeInit; |
|
| - | 2905 | } |
|
| - | 2906 | /* DeInit the low level hardware */ |
|
| - | 2907 | htim->Encoder_MspDeInitCallback(htim); |
|
| - | 2908 | #else |
|
| 2272 | /* DeInit the low level hardware: GPIO, CLOCK, NVIC */ |
2909 | /* DeInit the low level hardware: GPIO, CLOCK, NVIC */ |
| 2273 | HAL_TIM_Encoder_MspDeInit(htim); |
2910 | HAL_TIM_Encoder_MspDeInit(htim); |
| - | 2911 | #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */ |
|
| - | 2912 | ||
| - | 2913 | /* Change the DMA burst operation state */ |
|
| - | 2914 | htim->DMABurstState = HAL_DMA_BURST_STATE_RESET; |
|
| - | 2915 | ||
| - | 2916 | /* Set the TIM channels state */ |
|
| - | 2917 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_RESET); |
|
| - | 2918 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_RESET); |
|
| 2274 | 2919 | ||
| 2275 | /* Change TIM state */ |
2920 | /* Change TIM state */ |
| 2276 | htim->State = HAL_TIM_STATE_RESET; |
2921 | htim->State = HAL_TIM_STATE_RESET; |
| 2277 | 2922 | ||
| 2278 | /* Release Lock */ |
2923 | /* Release Lock */ |
| Line 2281... | Line 2926... | ||
| 2281 | return HAL_OK; |
2926 | return HAL_OK; |
| 2282 | } |
2927 | } |
| 2283 | 2928 | ||
| 2284 | /** |
2929 | /** |
| 2285 | * @brief Initializes the TIM Encoder Interface MSP. |
2930 | * @brief Initializes the TIM Encoder Interface MSP. |
| 2286 | * @param htim: TIM handle |
2931 | * @param htim TIM Encoder Interface handle |
| 2287 | * @retval None |
2932 | * @retval None |
| 2288 | */ |
2933 | */ |
| 2289 | __weak void HAL_TIM_Encoder_MspInit(TIM_HandleTypeDef *htim) |
2934 | __weak void HAL_TIM_Encoder_MspInit(TIM_HandleTypeDef *htim) |
| 2290 | { |
2935 | { |
| 2291 | /* Prevent unused argument(s) compilation warning */ |
2936 | /* Prevent unused argument(s) compilation warning */ |
| 2292 | UNUSED(htim); |
2937 | UNUSED(htim); |
| 2293 | 2938 | ||
| 2294 | /* NOTE : This function Should not be modified, when the callback is needed, |
2939 | /* NOTE : This function should not be modified, when the callback is needed, |
| 2295 | the HAL_TIM_Encoder_MspInit could be implemented in the user file |
2940 | the HAL_TIM_Encoder_MspInit could be implemented in the user file |
| 2296 | */ |
2941 | */ |
| 2297 | } |
2942 | } |
| 2298 | 2943 | ||
| 2299 | /** |
2944 | /** |
| 2300 | * @brief DeInitializes TIM Encoder Interface MSP. |
2945 | * @brief DeInitializes TIM Encoder Interface MSP. |
| 2301 | * @param htim: TIM handle |
2946 | * @param htim TIM Encoder Interface handle |
| 2302 | * @retval None |
2947 | * @retval None |
| 2303 | */ |
2948 | */ |
| 2304 | __weak void HAL_TIM_Encoder_MspDeInit(TIM_HandleTypeDef *htim) |
2949 | __weak void HAL_TIM_Encoder_MspDeInit(TIM_HandleTypeDef *htim) |
| 2305 | { |
2950 | { |
| 2306 | /* Prevent unused argument(s) compilation warning */ |
2951 | /* Prevent unused argument(s) compilation warning */ |
| 2307 | UNUSED(htim); |
2952 | UNUSED(htim); |
| 2308 | 2953 | ||
| 2309 | /* NOTE : This function Should not be modified, when the callback is needed, |
2954 | /* NOTE : This function should not be modified, when the callback is needed, |
| 2310 | the HAL_TIM_Encoder_MspDeInit could be implemented in the user file |
2955 | the HAL_TIM_Encoder_MspDeInit could be implemented in the user file |
| 2311 | */ |
2956 | */ |
| 2312 | } |
2957 | } |
| 2313 | 2958 | ||
| 2314 | /** |
2959 | /** |
| 2315 | * @brief Starts the TIM Encoder Interface. |
2960 | * @brief Starts the TIM Encoder Interface. |
| 2316 | * @param htim : TIM Encoder Interface handle |
2961 | * @param htim TIM Encoder Interface handle |
| 2317 | * @param Channel : TIM Channels to be enabled |
2962 | * @param Channel TIM Channels to be enabled |
| 2318 | * This parameter can be one of the following values: |
2963 | * This parameter can be one of the following values: |
| 2319 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
2964 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
| 2320 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
2965 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
| 2321 | * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected |
2966 | * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected |
| 2322 | * @retval HAL status |
2967 | * @retval HAL status |
| 2323 | */ |
2968 | */ |
| 2324 | HAL_StatusTypeDef HAL_TIM_Encoder_Start(TIM_HandleTypeDef *htim, uint32_t Channel) |
2969 | HAL_StatusTypeDef HAL_TIM_Encoder_Start(TIM_HandleTypeDef *htim, uint32_t Channel) |
| 2325 | { |
2970 | { |
| - | 2971 | HAL_TIM_ChannelStateTypeDef channel_1_state = TIM_CHANNEL_STATE_GET(htim, TIM_CHANNEL_1); |
|
| - | 2972 | HAL_TIM_ChannelStateTypeDef channel_2_state = TIM_CHANNEL_STATE_GET(htim, TIM_CHANNEL_2); |
|
| - | 2973 | ||
| 2326 | /* Check the parameters */ |
2974 | /* Check the parameters */ |
| 2327 | assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); |
2975 | assert_param(IS_TIM_ENCODER_INTERFACE_INSTANCE(htim->Instance)); |
| - | 2976 | ||
| - | 2977 | /* Set the TIM channel(s) state */ |
|
| - | 2978 | if (Channel == TIM_CHANNEL_1) |
|
| - | 2979 | { |
|
| - | 2980 | if (channel_1_state != HAL_TIM_CHANNEL_STATE_READY) |
|
| - | 2981 | { |
|
| - | 2982 | return HAL_ERROR; |
|
| - | 2983 | } |
|
| - | 2984 | else |
|
| - | 2985 | { |
|
| - | 2986 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_BUSY); |
|
| - | 2987 | } |
|
| - | 2988 | } |
|
| - | 2989 | else if (Channel == TIM_CHANNEL_2) |
|
| - | 2990 | { |
|
| - | 2991 | if (channel_2_state != HAL_TIM_CHANNEL_STATE_READY) |
|
| - | 2992 | { |
|
| - | 2993 | return HAL_ERROR; |
|
| - | 2994 | } |
|
| - | 2995 | else |
|
| - | 2996 | { |
|
| - | 2997 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_BUSY); |
|
| - | 2998 | } |
|
| - | 2999 | } |
|
| - | 3000 | else |
|
| - | 3001 | { |
|
| - | 3002 | if ((channel_1_state != HAL_TIM_CHANNEL_STATE_READY) |
|
| - | 3003 | || (channel_2_state != HAL_TIM_CHANNEL_STATE_READY)) |
|
| - | 3004 | { |
|
| - | 3005 | return HAL_ERROR; |
|
| - | 3006 | } |
|
| - | 3007 | else |
|
| - | 3008 | { |
|
| - | 3009 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_BUSY); |
|
| - | 3010 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_BUSY); |
|
| - | 3011 | } |
|
| - | 3012 | } |
|
| 2328 | 3013 | ||
| 2329 | /* Enable the encoder interface channels */ |
3014 | /* Enable the encoder interface channels */ |
| 2330 | switch (Channel) |
3015 | switch (Channel) |
| 2331 | { |
3016 | { |
| 2332 | case TIM_CHANNEL_1: |
3017 | case TIM_CHANNEL_1: |
| 2333 | { |
3018 | { |
| 2334 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE); |
3019 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE); |
| 2335 | break; |
3020 | break; |
| 2336 | } |
3021 | } |
| - | 3022 | ||
| 2337 | case TIM_CHANNEL_2: |
3023 | case TIM_CHANNEL_2: |
| 2338 | { |
3024 | { |
| 2339 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE); |
3025 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE); |
| 2340 | break; |
3026 | break; |
| 2341 | } |
3027 | } |
| - | 3028 | ||
| 2342 | default : |
3029 | default : |
| 2343 | { |
3030 | { |
| 2344 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE); |
3031 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE); |
| 2345 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE); |
3032 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE); |
| 2346 | break; |
3033 | break; |
| 2347 | } |
3034 | } |
| 2348 | } |
3035 | } |
| 2349 | /* Enable the Peripheral */ |
3036 | /* Enable the Peripheral */ |
| 2350 | __HAL_TIM_ENABLE(htim); |
3037 | __HAL_TIM_ENABLE(htim); |
| 2351 | 3038 | ||
| Line 2353... | Line 3040... | ||
| 2353 | return HAL_OK; |
3040 | return HAL_OK; |
| 2354 | } |
3041 | } |
| 2355 | 3042 | ||
| 2356 | /** |
3043 | /** |
| 2357 | * @brief Stops the TIM Encoder Interface. |
3044 | * @brief Stops the TIM Encoder Interface. |
| 2358 | * @param htim : TIM Encoder Interface handle |
3045 | * @param htim TIM Encoder Interface handle |
| 2359 | * @param Channel : TIM Channels to be disabled |
3046 | * @param Channel TIM Channels to be disabled |
| 2360 | * This parameter can be one of the following values: |
3047 | * This parameter can be one of the following values: |
| 2361 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
3048 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
| 2362 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
3049 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
| 2363 | * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected |
3050 | * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected |
| 2364 | * @retval HAL status |
3051 | * @retval HAL status |
| 2365 | */ |
3052 | */ |
| 2366 | HAL_StatusTypeDef HAL_TIM_Encoder_Stop(TIM_HandleTypeDef *htim, uint32_t Channel) |
3053 | HAL_StatusTypeDef HAL_TIM_Encoder_Stop(TIM_HandleTypeDef *htim, uint32_t Channel) |
| 2367 | { |
3054 | { |
| 2368 | /* Check the parameters */ |
3055 | /* Check the parameters */ |
| 2369 | assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); |
3056 | assert_param(IS_TIM_ENCODER_INTERFACE_INSTANCE(htim->Instance)); |
| 2370 | 3057 | ||
| 2371 | /* Disable the Input Capture channels 1 and 2 |
3058 | /* Disable the Input Capture channels 1 and 2 |
| 2372 | (in the EncoderInterface the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2) */ |
3059 | (in the EncoderInterface the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2) */ |
| 2373 | switch (Channel) |
3060 | switch (Channel) |
| 2374 | { |
3061 | { |
| 2375 | case TIM_CHANNEL_1: |
3062 | case TIM_CHANNEL_1: |
| 2376 | { |
3063 | { |
| 2377 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE); |
3064 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE); |
| 2378 | break; |
3065 | break; |
| 2379 | } |
3066 | } |
| - | 3067 | ||
| 2380 | case TIM_CHANNEL_2: |
3068 | case TIM_CHANNEL_2: |
| 2381 | { |
3069 | { |
| 2382 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE); |
3070 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE); |
| 2383 | break; |
3071 | break; |
| 2384 | } |
3072 | } |
| - | 3073 | ||
| 2385 | default : |
3074 | default : |
| 2386 | { |
3075 | { |
| 2387 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE); |
3076 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE); |
| 2388 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE); |
3077 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE); |
| 2389 | break; |
3078 | break; |
| 2390 | } |
3079 | } |
| 2391 | } |
3080 | } |
| 2392 | 3081 | ||
| 2393 | /* Disable the Peripheral */ |
3082 | /* Disable the Peripheral */ |
| 2394 | __HAL_TIM_DISABLE(htim); |
3083 | __HAL_TIM_DISABLE(htim); |
| 2395 | 3084 | ||
| - | 3085 | /* Set the TIM channel(s) state */ |
|
| - | 3086 | if ((Channel == TIM_CHANNEL_1) || (Channel == TIM_CHANNEL_2)) |
|
| - | 3087 | { |
|
| - | 3088 | TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY); |
|
| - | 3089 | } |
|
| - | 3090 | else |
|
| - | 3091 | { |
|
| - | 3092 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY); |
|
| - | 3093 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY); |
|
| - | 3094 | } |
|
| - | 3095 | ||
| 2396 | /* Return function status */ |
3096 | /* Return function status */ |
| 2397 | return HAL_OK; |
3097 | return HAL_OK; |
| 2398 | } |
3098 | } |
| 2399 | 3099 | ||
| 2400 | /** |
3100 | /** |
| 2401 | * @brief Starts the TIM Encoder Interface in interrupt mode. |
3101 | * @brief Starts the TIM Encoder Interface in interrupt mode. |
| 2402 | * @param htim : TIM Encoder Interface handle |
3102 | * @param htim TIM Encoder Interface handle |
| 2403 | * @param Channel : TIM Channels to be enabled |
3103 | * @param Channel TIM Channels to be enabled |
| 2404 | * This parameter can be one of the following values: |
3104 | * This parameter can be one of the following values: |
| 2405 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
3105 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
| 2406 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
3106 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
| 2407 | * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected |
3107 | * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected |
| 2408 | * @retval HAL status |
3108 | * @retval HAL status |
| 2409 | */ |
3109 | */ |
| 2410 | HAL_StatusTypeDef HAL_TIM_Encoder_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel) |
3110 | HAL_StatusTypeDef HAL_TIM_Encoder_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel) |
| 2411 | { |
3111 | { |
| - | 3112 | HAL_TIM_ChannelStateTypeDef channel_1_state = TIM_CHANNEL_STATE_GET(htim, TIM_CHANNEL_1); |
|
| - | 3113 | HAL_TIM_ChannelStateTypeDef channel_2_state = TIM_CHANNEL_STATE_GET(htim, TIM_CHANNEL_2); |
|
| - | 3114 | ||
| 2412 | /* Check the parameters */ |
3115 | /* Check the parameters */ |
| 2413 | assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); |
3116 | assert_param(IS_TIM_ENCODER_INTERFACE_INSTANCE(htim->Instance)); |
| - | 3117 | ||
| - | 3118 | /* Set the TIM channel(s) state */ |
|
| - | 3119 | if (Channel == TIM_CHANNEL_1) |
|
| - | 3120 | { |
|
| - | 3121 | if (channel_1_state != HAL_TIM_CHANNEL_STATE_READY) |
|
| - | 3122 | { |
|
| - | 3123 | return HAL_ERROR; |
|
| - | 3124 | } |
|
| - | 3125 | else |
|
| - | 3126 | { |
|
| - | 3127 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_BUSY); |
|
| - | 3128 | } |
|
| - | 3129 | } |
|
| - | 3130 | else if (Channel == TIM_CHANNEL_2) |
|
| - | 3131 | { |
|
| - | 3132 | if (channel_2_state != HAL_TIM_CHANNEL_STATE_READY) |
|
| - | 3133 | { |
|
| - | 3134 | return HAL_ERROR; |
|
| - | 3135 | } |
|
| - | 3136 | else |
|
| - | 3137 | { |
|
| - | 3138 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_BUSY); |
|
| - | 3139 | } |
|
| - | 3140 | } |
|
| - | 3141 | else |
|
| - | 3142 | { |
|
| - | 3143 | if ((channel_1_state != HAL_TIM_CHANNEL_STATE_READY) |
|
| - | 3144 | || (channel_2_state != HAL_TIM_CHANNEL_STATE_READY)) |
|
| - | 3145 | { |
|
| - | 3146 | return HAL_ERROR; |
|
| - | 3147 | } |
|
| - | 3148 | else |
|
| - | 3149 | { |
|
| - | 3150 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_BUSY); |
|
| - | 3151 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_BUSY); |
|
| - | 3152 | } |
|
| - | 3153 | } |
|
| 2414 | 3154 | ||
| 2415 | /* Enable the encoder interface channels */ |
3155 | /* Enable the encoder interface channels */ |
| 2416 | /* Enable the capture compare Interrupts 1 and/or 2 */ |
3156 | /* Enable the capture compare Interrupts 1 and/or 2 */ |
| 2417 | switch (Channel) |
3157 | switch (Channel) |
| 2418 | { |
3158 | { |
| 2419 | case TIM_CHANNEL_1: |
3159 | case TIM_CHANNEL_1: |
| 2420 | { |
3160 | { |
| 2421 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE); |
3161 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE); |
| 2422 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1); |
3162 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1); |
| 2423 | break; |
3163 | break; |
| 2424 | } |
3164 | } |
| - | 3165 | ||
| 2425 | case TIM_CHANNEL_2: |
3166 | case TIM_CHANNEL_2: |
| 2426 | { |
3167 | { |
| 2427 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE); |
3168 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE); |
| 2428 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2); |
3169 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2); |
| 2429 | break; |
3170 | break; |
| 2430 | } |
3171 | } |
| - | 3172 | ||
| 2431 | default : |
3173 | default : |
| 2432 | { |
3174 | { |
| 2433 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE); |
3175 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE); |
| 2434 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE); |
3176 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE); |
| 2435 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1); |
3177 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1); |
| 2436 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2); |
3178 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2); |
| 2437 | break; |
3179 | break; |
| 2438 | } |
3180 | } |
| 2439 | } |
3181 | } |
| 2440 | 3182 | ||
| 2441 | /* Enable the Peripheral */ |
3183 | /* Enable the Peripheral */ |
| 2442 | __HAL_TIM_ENABLE(htim); |
3184 | __HAL_TIM_ENABLE(htim); |
| Line 2445... | Line 3187... | ||
| 2445 | return HAL_OK; |
3187 | return HAL_OK; |
| 2446 | } |
3188 | } |
| 2447 | 3189 | ||
| 2448 | /** |
3190 | /** |
| 2449 | * @brief Stops the TIM Encoder Interface in interrupt mode. |
3191 | * @brief Stops the TIM Encoder Interface in interrupt mode. |
| 2450 | * @param htim : TIM Encoder Interface handle |
3192 | * @param htim TIM Encoder Interface handle |
| 2451 | * @param Channel : TIM Channels to be disabled |
3193 | * @param Channel TIM Channels to be disabled |
| 2452 | * This parameter can be one of the following values: |
3194 | * This parameter can be one of the following values: |
| 2453 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
3195 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
| 2454 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
3196 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
| 2455 | * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected |
3197 | * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected |
| 2456 | * @retval HAL status |
3198 | * @retval HAL status |
| 2457 | */ |
3199 | */ |
| 2458 | HAL_StatusTypeDef HAL_TIM_Encoder_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel) |
3200 | HAL_StatusTypeDef HAL_TIM_Encoder_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel) |
| 2459 | { |
3201 | { |
| 2460 | /* Check the parameters */ |
3202 | /* Check the parameters */ |
| 2461 | assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); |
3203 | assert_param(IS_TIM_ENCODER_INTERFACE_INSTANCE(htim->Instance)); |
| 2462 | 3204 | ||
| 2463 | /* Disable the Input Capture channels 1 and 2 |
3205 | /* Disable the Input Capture channels 1 and 2 |
| 2464 | (in the EncoderInterface the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2) */ |
3206 | (in the EncoderInterface the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2) */ |
| 2465 | if(Channel == TIM_CHANNEL_1) |
3207 | if (Channel == TIM_CHANNEL_1) |
| 2466 | { |
3208 | { |
| 2467 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE); |
3209 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE); |
| 2468 | 3210 | ||
| 2469 | /* Disable the capture compare Interrupts 1 */ |
3211 | /* Disable the capture compare Interrupts 1 */ |
| 2470 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1); |
3212 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1); |
| 2471 | } |
3213 | } |
| 2472 | else if(Channel == TIM_CHANNEL_2) |
3214 | else if (Channel == TIM_CHANNEL_2) |
| 2473 | { |
3215 | { |
| 2474 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE); |
3216 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE); |
| 2475 | 3217 | ||
| 2476 | /* Disable the capture compare Interrupts 2 */ |
3218 | /* Disable the capture compare Interrupts 2 */ |
| 2477 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2); |
3219 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2); |
| 2478 | } |
3220 | } |
| 2479 | else |
3221 | else |
| 2480 | { |
3222 | { |
| 2481 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE); |
3223 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE); |
| 2482 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE); |
3224 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE); |
| Line 2487... | Line 3229... | ||
| 2487 | } |
3229 | } |
| 2488 | 3230 | ||
| 2489 | /* Disable the Peripheral */ |
3231 | /* Disable the Peripheral */ |
| 2490 | __HAL_TIM_DISABLE(htim); |
3232 | __HAL_TIM_DISABLE(htim); |
| 2491 | 3233 | ||
| 2492 | /* Change the htim state */ |
3234 | /* Set the TIM channel(s) state */ |
| - | 3235 | if ((Channel == TIM_CHANNEL_1) || (Channel == TIM_CHANNEL_2)) |
|
| - | 3236 | { |
|
| 2493 | htim->State = HAL_TIM_STATE_READY; |
3237 | TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY); |
| - | 3238 | } |
|
| - | 3239 | else |
|
| - | 3240 | { |
|
| - | 3241 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY); |
|
| - | 3242 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY); |
|
| - | 3243 | } |
|
| 2494 | 3244 | ||
| 2495 | /* Return function status */ |
3245 | /* Return function status */ |
| 2496 | return HAL_OK; |
3246 | return HAL_OK; |
| 2497 | } |
3247 | } |
| 2498 | 3248 | ||
| 2499 | /** |
3249 | /** |
| 2500 | * @brief Starts the TIM Encoder Interface in DMA mode. |
3250 | * @brief Starts the TIM Encoder Interface in DMA mode. |
| 2501 | * @param htim : TIM Encoder Interface handle |
3251 | * @param htim TIM Encoder Interface handle |
| 2502 | * @param Channel : TIM Channels to be enabled |
3252 | * @param Channel TIM Channels to be enabled |
| 2503 | * This parameter can be one of the following values: |
3253 | * This parameter can be one of the following values: |
| 2504 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
3254 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
| 2505 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
3255 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
| 2506 | * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected |
3256 | * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected |
| 2507 | * @param pData1: The destination Buffer address for IC1. |
3257 | * @param pData1 The destination Buffer address for IC1. |
| 2508 | * @param pData2: The destination Buffer address for IC2. |
3258 | * @param pData2 The destination Buffer address for IC2. |
| 2509 | * @param Length: The length of data to be transferred from TIM peripheral to memory. |
3259 | * @param Length The length of data to be transferred from TIM peripheral to memory. |
| 2510 | * @retval HAL status |
3260 | * @retval HAL status |
| 2511 | */ |
3261 | */ |
| 2512 | HAL_StatusTypeDef HAL_TIM_Encoder_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData1, uint32_t *pData2, uint16_t Length) |
3262 | HAL_StatusTypeDef HAL_TIM_Encoder_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData1, |
| - | 3263 | uint32_t *pData2, uint16_t Length) |
|
| 2513 | { |
3264 | { |
| - | 3265 | HAL_TIM_ChannelStateTypeDef channel_1_state = TIM_CHANNEL_STATE_GET(htim, TIM_CHANNEL_1); |
|
| - | 3266 | HAL_TIM_ChannelStateTypeDef channel_2_state = TIM_CHANNEL_STATE_GET(htim, TIM_CHANNEL_2); |
|
| - | 3267 | ||
| 2514 | /* Check the parameters */ |
3268 | /* Check the parameters */ |
| 2515 | assert_param(IS_TIM_DMA_CC_INSTANCE(htim->Instance)); |
3269 | assert_param(IS_TIM_ENCODER_INTERFACE_INSTANCE(htim->Instance)); |
| 2516 | 3270 | ||
| - | 3271 | /* Set the TIM channel(s) state */ |
|
| 2517 | if((htim->State == HAL_TIM_STATE_BUSY)) |
3272 | if (Channel == TIM_CHANNEL_1) |
| 2518 | { |
3273 | { |
| - | 3274 | if (channel_1_state == HAL_TIM_CHANNEL_STATE_BUSY) |
|
| - | 3275 | { |
|
| 2519 | return HAL_BUSY; |
3276 | return HAL_BUSY; |
| - | 3277 | } |
|
| - | 3278 | else if (channel_1_state == HAL_TIM_CHANNEL_STATE_READY) |
|
| - | 3279 | { |
|
| - | 3280 | if ((pData1 == NULL) && (Length > 0U)) |
|
| - | 3281 | { |
|
| - | 3282 | return HAL_ERROR; |
|
| - | 3283 | } |
|
| - | 3284 | else |
|
| - | 3285 | { |
|
| - | 3286 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_BUSY); |
|
| - | 3287 | } |
|
| - | 3288 | } |
|
| - | 3289 | else |
|
| - | 3290 | { |
|
| - | 3291 | return HAL_ERROR; |
|
| - | 3292 | } |
|
| 2520 | } |
3293 | } |
| 2521 | else if((htim->State == HAL_TIM_STATE_READY)) |
3294 | else if (Channel == TIM_CHANNEL_2) |
| 2522 | { |
3295 | { |
| 2523 | if((((pData1 == 0) || (pData2 == 0) )) && (Length > 0)) |
3296 | if (channel_2_state == HAL_TIM_CHANNEL_STATE_BUSY) |
| 2524 | { |
3297 | { |
| - | 3298 | return HAL_BUSY; |
|
| - | 3299 | } |
|
| - | 3300 | else if (channel_2_state == HAL_TIM_CHANNEL_STATE_READY) |
|
| - | 3301 | { |
|
| - | 3302 | if ((pData2 == NULL) && (Length > 0U)) |
|
| - | 3303 | { |
|
| 2525 | return HAL_ERROR; |
3304 | return HAL_ERROR; |
| - | 3305 | } |
|
| - | 3306 | else |
|
| - | 3307 | { |
|
| - | 3308 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_BUSY); |
|
| - | 3309 | } |
|
| 2526 | } |
3310 | } |
| 2527 | else |
3311 | else |
| 2528 | { |
3312 | { |
| 2529 | htim->State = HAL_TIM_STATE_BUSY; |
3313 | return HAL_ERROR; |
| 2530 | } |
3314 | } |
| 2531 | } |
3315 | } |
| 2532 | else |
3316 | else |
| 2533 | { |
3317 | { |
| - | 3318 | if ((channel_1_state == HAL_TIM_CHANNEL_STATE_BUSY) |
|
| - | 3319 | || (channel_2_state == HAL_TIM_CHANNEL_STATE_BUSY)) |
|
| - | 3320 | { |
|
| - | 3321 | return HAL_BUSY; |
|
| - | 3322 | } |
|
| - | 3323 | else if ((channel_1_state == HAL_TIM_CHANNEL_STATE_READY) |
|
| - | 3324 | && (channel_2_state == HAL_TIM_CHANNEL_STATE_READY)) |
|
| - | 3325 | { |
|
| - | 3326 | if ((((pData1 == NULL) || (pData2 == NULL))) && (Length > 0U)) |
|
| - | 3327 | { |
|
| - | 3328 | return HAL_ERROR; |
|
| - | 3329 | } |
|
| - | 3330 | else |
|
| - | 3331 | { |
|
| - | 3332 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_BUSY); |
|
| - | 3333 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_BUSY); |
|
| - | 3334 | } |
|
| - | 3335 | } |
|
| - | 3336 | else |
|
| - | 3337 | { |
|
| 2534 | return HAL_ERROR; |
3338 | return HAL_ERROR; |
| - | 3339 | } |
|
| 2535 | } |
3340 | } |
| 2536 | 3341 | ||
| 2537 | switch (Channel) |
3342 | switch (Channel) |
| 2538 | { |
3343 | { |
| 2539 | case TIM_CHANNEL_1: |
3344 | case TIM_CHANNEL_1: |
| 2540 | { |
3345 | { |
| 2541 | /* Set the DMA Period elapsed callback */ |
3346 | /* Set the DMA capture callbacks */ |
| 2542 | htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMACaptureCplt; |
3347 | htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMACaptureCplt; |
| - | 3348 | htim->hdma[TIM_DMA_ID_CC1]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt; |
|
| 2543 | 3349 | ||
| 2544 | /* Set the DMA error callback */ |
3350 | /* Set the DMA error callback */ |
| 2545 | htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ; |
3351 | htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ; |
| 2546 | 3352 | ||
| 2547 | /* Enable the DMA channel */ |
3353 | /* Enable the DMA channel */ |
| 2548 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)&htim->Instance->CCR1, (uint32_t )pData1, Length); |
3354 | if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)&htim->Instance->CCR1, (uint32_t)pData1, Length) != HAL_OK) |
| - | 3355 | { |
|
| - | 3356 | return HAL_ERROR; |
|
| 2549 | 3357 | } |
|
| 2550 | /* Enable the TIM Input Capture DMA request */ |
3358 | /* Enable the TIM Input Capture DMA request */ |
| 2551 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1); |
3359 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1); |
| 2552 | 3360 | ||
| 2553 | /* Enable the Peripheral */ |
3361 | /* Enable the Peripheral */ |
| 2554 | __HAL_TIM_ENABLE(htim); |
3362 | __HAL_TIM_ENABLE(htim); |
| 2555 | 3363 | ||
| 2556 | /* Enable the Capture compare channel */ |
3364 | /* Enable the Capture compare channel */ |
| 2557 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE); |
3365 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE); |
| - | 3366 | break; |
|
| 2558 | } |
3367 | } |
| 2559 | break; |
- | |
| 2560 | 3368 | ||
| 2561 | case TIM_CHANNEL_2: |
3369 | case TIM_CHANNEL_2: |
| 2562 | { |
3370 | { |
| 2563 | /* Set the DMA Period elapsed callback */ |
3371 | /* Set the DMA capture callbacks */ |
| 2564 | htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMACaptureCplt; |
3372 | htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMACaptureCplt; |
| - | 3373 | htim->hdma[TIM_DMA_ID_CC2]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt; |
|
| 2565 | 3374 | ||
| 2566 | /* Set the DMA error callback */ |
3375 | /* Set the DMA error callback */ |
| 2567 | htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError; |
3376 | htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError; |
| 2568 | /* Enable the DMA channel */ |
3377 | /* Enable the DMA channel */ |
| 2569 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)&htim->Instance->CCR2, (uint32_t)pData2, Length); |
3378 | if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)&htim->Instance->CCR2, (uint32_t)pData2, Length) != HAL_OK) |
| - | 3379 | { |
|
| - | 3380 | return HAL_ERROR; |
|
| 2570 | 3381 | } |
|
| 2571 | /* Enable the TIM Input Capture DMA request */ |
3382 | /* Enable the TIM Input Capture DMA request */ |
| 2572 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2); |
3383 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2); |
| 2573 | 3384 | ||
| 2574 | /* Enable the Peripheral */ |
3385 | /* Enable the Peripheral */ |
| 2575 | __HAL_TIM_ENABLE(htim); |
3386 | __HAL_TIM_ENABLE(htim); |
| 2576 | 3387 | ||
| 2577 | /* Enable the Capture compare channel */ |
3388 | /* Enable the Capture compare channel */ |
| 2578 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE); |
3389 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE); |
| - | 3390 | break; |
|
| 2579 | } |
3391 | } |
| 2580 | break; |
- | |
| 2581 | 3392 | ||
| 2582 | case TIM_CHANNEL_ALL: |
3393 | case TIM_CHANNEL_ALL: |
| 2583 | { |
3394 | { |
| 2584 | /* Set the DMA Period elapsed callback */ |
3395 | /* Set the DMA capture callbacks */ |
| 2585 | htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMACaptureCplt; |
3396 | htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMACaptureCplt; |
| - | 3397 | htim->hdma[TIM_DMA_ID_CC1]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt; |
|
| 2586 | 3398 | ||
| 2587 | /* Set the DMA error callback */ |
3399 | /* Set the DMA error callback */ |
| 2588 | htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ; |
3400 | htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ; |
| 2589 | 3401 | ||
| 2590 | /* Enable the DMA channel */ |
3402 | /* Enable the DMA channel */ |
| 2591 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)&htim->Instance->CCR1, (uint32_t)pData1, Length); |
3403 | if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)&htim->Instance->CCR1, (uint32_t)pData1, Length) != HAL_OK) |
| - | 3404 | { |
|
| - | 3405 | return HAL_ERROR; |
|
| - | 3406 | } |
|
| 2592 | 3407 | ||
| 2593 | /* Set the DMA Period elapsed callback */ |
3408 | /* Set the DMA capture callbacks */ |
| 2594 | htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMACaptureCplt; |
3409 | htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMACaptureCplt; |
| - | 3410 | htim->hdma[TIM_DMA_ID_CC2]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt; |
|
| 2595 | 3411 | ||
| 2596 | /* Set the DMA error callback */ |
3412 | /* Set the DMA error callback */ |
| 2597 | htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError ; |
3413 | htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError ; |
| 2598 | 3414 | ||
| 2599 | /* Enable the DMA channel */ |
3415 | /* Enable the DMA channel */ |
| 2600 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)&htim->Instance->CCR2, (uint32_t)pData2, Length); |
3416 | if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)&htim->Instance->CCR2, (uint32_t)pData2, Length) != HAL_OK) |
| - | 3417 | { |
|
| - | 3418 | return HAL_ERROR; |
|
| 2601 | 3419 | } |
|
| 2602 | /* Enable the Peripheral */ |
3420 | /* Enable the Peripheral */ |
| 2603 | __HAL_TIM_ENABLE(htim); |
3421 | __HAL_TIM_ENABLE(htim); |
| 2604 | 3422 | ||
| 2605 | /* Enable the Capture compare channel */ |
3423 | /* Enable the Capture compare channel */ |
| 2606 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE); |
3424 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE); |
| 2607 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE); |
3425 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE); |
| 2608 | 3426 | ||
| 2609 | /* Enable the TIM Input Capture DMA request */ |
3427 | /* Enable the TIM Input Capture DMA request */ |
| 2610 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1); |
3428 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1); |
| 2611 | /* Enable the TIM Input Capture DMA request */ |
3429 | /* Enable the TIM Input Capture DMA request */ |
| 2612 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2); |
3430 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2); |
| - | 3431 | break; |
|
| 2613 | } |
3432 | } |
| 2614 | break; |
- | |
| 2615 | 3433 | ||
| 2616 | default: |
3434 | default: |
| 2617 | break; |
3435 | break; |
| 2618 | } |
3436 | } |
| - | 3437 | ||
| 2619 | /* Return function status */ |
3438 | /* Return function status */ |
| 2620 | return HAL_OK; |
3439 | return HAL_OK; |
| 2621 | } |
3440 | } |
| 2622 | 3441 | ||
| 2623 | /** |
3442 | /** |
| 2624 | * @brief Stops the TIM Encoder Interface in DMA mode. |
3443 | * @brief Stops the TIM Encoder Interface in DMA mode. |
| 2625 | * @param htim : TIM Encoder Interface handle |
3444 | * @param htim TIM Encoder Interface handle |
| 2626 | * @param Channel : TIM Channels to be enabled |
3445 | * @param Channel TIM Channels to be enabled |
| 2627 | * This parameter can be one of the following values: |
3446 | * This parameter can be one of the following values: |
| 2628 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
3447 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
| 2629 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
3448 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
| 2630 | * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected |
3449 | * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected |
| 2631 | * @retval HAL status |
3450 | * @retval HAL status |
| 2632 | */ |
3451 | */ |
| 2633 | HAL_StatusTypeDef HAL_TIM_Encoder_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel) |
3452 | HAL_StatusTypeDef HAL_TIM_Encoder_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel) |
| 2634 | { |
3453 | { |
| 2635 | /* Check the parameters */ |
3454 | /* Check the parameters */ |
| 2636 | assert_param(IS_TIM_DMA_CC_INSTANCE(htim->Instance)); |
3455 | assert_param(IS_TIM_ENCODER_INTERFACE_INSTANCE(htim->Instance)); |
| 2637 | 3456 | ||
| 2638 | /* Disable the Input Capture channels 1 and 2 |
3457 | /* Disable the Input Capture channels 1 and 2 |
| 2639 | (in the EncoderInterface the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2) */ |
3458 | (in the EncoderInterface the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2) */ |
| 2640 | if(Channel == TIM_CHANNEL_1) |
3459 | if (Channel == TIM_CHANNEL_1) |
| 2641 | { |
3460 | { |
| 2642 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE); |
3461 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE); |
| 2643 | 3462 | ||
| 2644 | /* Disable the capture compare DMA Request 1 */ |
3463 | /* Disable the capture compare DMA Request 1 */ |
| 2645 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1); |
3464 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1); |
| - | 3465 | (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC1]); |
|
| 2646 | } |
3466 | } |
| 2647 | else if(Channel == TIM_CHANNEL_2) |
3467 | else if (Channel == TIM_CHANNEL_2) |
| 2648 | { |
3468 | { |
| 2649 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE); |
3469 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE); |
| 2650 | 3470 | ||
| 2651 | /* Disable the capture compare DMA Request 2 */ |
3471 | /* Disable the capture compare DMA Request 2 */ |
| 2652 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2); |
3472 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2); |
| - | 3473 | (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC2]); |
|
| 2653 | } |
3474 | } |
| 2654 | else |
3475 | else |
| 2655 | { |
3476 | { |
| 2656 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE); |
3477 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE); |
| 2657 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE); |
3478 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE); |
| 2658 | 3479 | ||
| 2659 | /* Disable the capture compare DMA Request 1 and 2 */ |
3480 | /* Disable the capture compare DMA Request 1 and 2 */ |
| 2660 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1); |
3481 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1); |
| 2661 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2); |
3482 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2); |
| - | 3483 | (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC1]); |
|
| - | 3484 | (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC2]); |
|
| 2662 | } |
3485 | } |
| 2663 | 3486 | ||
| 2664 | /* Disable the Peripheral */ |
3487 | /* Disable the Peripheral */ |
| 2665 | __HAL_TIM_DISABLE(htim); |
3488 | __HAL_TIM_DISABLE(htim); |
| 2666 | 3489 | ||
| 2667 | /* Change the htim state */ |
3490 | /* Set the TIM channel(s) state */ |
| - | 3491 | if ((Channel == TIM_CHANNEL_1) || (Channel == TIM_CHANNEL_2)) |
|
| - | 3492 | { |
|
| 2668 | htim->State = HAL_TIM_STATE_READY; |
3493 | TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY); |
| - | 3494 | } |
|
| - | 3495 | else |
|
| - | 3496 | { |
|
| - | 3497 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY); |
|
| - | 3498 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY); |
|
| - | 3499 | } |
|
| 2669 | 3500 | ||
| 2670 | /* Return function status */ |
3501 | /* Return function status */ |
| 2671 | return HAL_OK; |
3502 | return HAL_OK; |
| 2672 | } |
3503 | } |
| 2673 | 3504 | ||
| 2674 | /** |
3505 | /** |
| 2675 | * @} |
3506 | * @} |
| 2676 | */ |
3507 | */ |
| 2677 | /** @defgroup TIM_Exported_Functions_Group7 TIM IRQ handler management |
3508 | /** @defgroup TIM_Exported_Functions_Group7 TIM IRQ handler management |
| 2678 | * @brief IRQ handler management |
3509 | * @brief TIM IRQ handler management |
| 2679 | * |
3510 | * |
| 2680 | @verbatim |
3511 | @verbatim |
| 2681 | ============================================================================== |
3512 | ============================================================================== |
| 2682 | ##### IRQ handler management ##### |
3513 | ##### IRQ handler management ##### |
| 2683 | ============================================================================== |
3514 | ============================================================================== |
| 2684 | [..] |
3515 | [..] |
| Line 2687... | Line 3518... | ||
| 2687 | @endverbatim |
3518 | @endverbatim |
| 2688 | * @{ |
3519 | * @{ |
| 2689 | */ |
3520 | */ |
| 2690 | /** |
3521 | /** |
| 2691 | * @brief This function handles TIM interrupts requests. |
3522 | * @brief This function handles TIM interrupts requests. |
| 2692 | * @param htim: TIM handle |
3523 | * @param htim TIM handle |
| 2693 | * @retval None |
3524 | * @retval None |
| 2694 | */ |
3525 | */ |
| 2695 | void HAL_TIM_IRQHandler(TIM_HandleTypeDef *htim) |
3526 | void HAL_TIM_IRQHandler(TIM_HandleTypeDef *htim) |
| 2696 | { |
3527 | { |
| 2697 | /* Capture compare 1 event */ |
3528 | /* Capture compare 1 event */ |
| 2698 | if(__HAL_TIM_GET_FLAG(htim, TIM_FLAG_CC1) != RESET) |
3529 | if (__HAL_TIM_GET_FLAG(htim, TIM_FLAG_CC1) != RESET) |
| 2699 | { |
3530 | { |
| 2700 | if(__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_CC1) !=RESET) |
3531 | if (__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_CC1) != RESET) |
| 2701 | { |
3532 | { |
| 2702 | { |
3533 | { |
| 2703 | __HAL_TIM_CLEAR_IT(htim, TIM_IT_CC1); |
3534 | __HAL_TIM_CLEAR_IT(htim, TIM_IT_CC1); |
| 2704 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_1; |
3535 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_1; |
| 2705 | 3536 | ||
| 2706 | /* Input capture event */ |
3537 | /* Input capture event */ |
| 2707 | if((htim->Instance->CCMR1 & TIM_CCMR1_CC1S) != 0x00) |
3538 | if ((htim->Instance->CCMR1 & TIM_CCMR1_CC1S) != 0x00U) |
| 2708 | { |
3539 | { |
| - | 3540 | #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) |
|
| - | 3541 | htim->IC_CaptureCallback(htim); |
|
| - | 3542 | #else |
|
| 2709 | HAL_TIM_IC_CaptureCallback(htim); |
3543 | HAL_TIM_IC_CaptureCallback(htim); |
| - | 3544 | #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */ |
|
| 2710 | } |
3545 | } |
| 2711 | /* Output compare event */ |
3546 | /* Output compare event */ |
| 2712 | else |
3547 | else |
| 2713 | { |
3548 | { |
| - | 3549 | #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) |
|
| - | 3550 | htim->OC_DelayElapsedCallback(htim); |
|
| - | 3551 | htim->PWM_PulseFinishedCallback(htim); |
|
| - | 3552 | #else |
|
| 2714 | HAL_TIM_OC_DelayElapsedCallback(htim); |
3553 | HAL_TIM_OC_DelayElapsedCallback(htim); |
| 2715 | HAL_TIM_PWM_PulseFinishedCallback(htim); |
3554 | HAL_TIM_PWM_PulseFinishedCallback(htim); |
| - | 3555 | #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */ |
|
| 2716 | } |
3556 | } |
| 2717 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED; |
3557 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED; |
| 2718 | } |
3558 | } |
| 2719 | } |
3559 | } |
| 2720 | } |
3560 | } |
| 2721 | /* Capture compare 2 event */ |
3561 | /* Capture compare 2 event */ |
| 2722 | if(__HAL_TIM_GET_FLAG(htim, TIM_FLAG_CC2) != RESET) |
3562 | if (__HAL_TIM_GET_FLAG(htim, TIM_FLAG_CC2) != RESET) |
| 2723 | { |
3563 | { |
| 2724 | if(__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_CC2) !=RESET) |
3564 | if (__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_CC2) != RESET) |
| 2725 | { |
3565 | { |
| 2726 | __HAL_TIM_CLEAR_IT(htim, TIM_IT_CC2); |
3566 | __HAL_TIM_CLEAR_IT(htim, TIM_IT_CC2); |
| 2727 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_2; |
3567 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_2; |
| 2728 | /* Input capture event */ |
3568 | /* Input capture event */ |
| 2729 | if((htim->Instance->CCMR1 & TIM_CCMR1_CC2S) != 0x00) |
3569 | if ((htim->Instance->CCMR1 & TIM_CCMR1_CC2S) != 0x00U) |
| 2730 | { |
3570 | { |
| - | 3571 | #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) |
|
| - | 3572 | htim->IC_CaptureCallback(htim); |
|
| - | 3573 | #else |
|
| 2731 | HAL_TIM_IC_CaptureCallback(htim); |
3574 | HAL_TIM_IC_CaptureCallback(htim); |
| - | 3575 | #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */ |
|
| 2732 | } |
3576 | } |
| 2733 | /* Output compare event */ |
3577 | /* Output compare event */ |
| 2734 | else |
3578 | else |
| 2735 | { |
3579 | { |
| - | 3580 | #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) |
|
| - | 3581 | htim->OC_DelayElapsedCallback(htim); |
|
| - | 3582 | htim->PWM_PulseFinishedCallback(htim); |
|
| - | 3583 | #else |
|
| 2736 | HAL_TIM_OC_DelayElapsedCallback(htim); |
3584 | HAL_TIM_OC_DelayElapsedCallback(htim); |
| 2737 | HAL_TIM_PWM_PulseFinishedCallback(htim); |
3585 | HAL_TIM_PWM_PulseFinishedCallback(htim); |
| - | 3586 | #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */ |
|
| 2738 | } |
3587 | } |
| 2739 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED; |
3588 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED; |
| 2740 | } |
3589 | } |
| 2741 | } |
3590 | } |
| 2742 | /* Capture compare 3 event */ |
3591 | /* Capture compare 3 event */ |
| 2743 | if(__HAL_TIM_GET_FLAG(htim, TIM_FLAG_CC3) != RESET) |
3592 | if (__HAL_TIM_GET_FLAG(htim, TIM_FLAG_CC3) != RESET) |
| 2744 | { |
3593 | { |
| 2745 | if(__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_CC3) !=RESET) |
3594 | if (__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_CC3) != RESET) |
| 2746 | { |
3595 | { |
| 2747 | __HAL_TIM_CLEAR_IT(htim, TIM_IT_CC3); |
3596 | __HAL_TIM_CLEAR_IT(htim, TIM_IT_CC3); |
| 2748 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_3; |
3597 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_3; |
| 2749 | /* Input capture event */ |
3598 | /* Input capture event */ |
| 2750 | if((htim->Instance->CCMR2 & TIM_CCMR2_CC3S) != 0x00) |
3599 | if ((htim->Instance->CCMR2 & TIM_CCMR2_CC3S) != 0x00U) |
| 2751 | { |
3600 | { |
| - | 3601 | #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) |
|
| - | 3602 | htim->IC_CaptureCallback(htim); |
|
| - | 3603 | #else |
|
| 2752 | HAL_TIM_IC_CaptureCallback(htim); |
3604 | HAL_TIM_IC_CaptureCallback(htim); |
| - | 3605 | #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */ |
|
| 2753 | } |
3606 | } |
| 2754 | /* Output compare event */ |
3607 | /* Output compare event */ |
| 2755 | else |
3608 | else |
| 2756 | { |
3609 | { |
| - | 3610 | #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) |
|
| - | 3611 | htim->OC_DelayElapsedCallback(htim); |
|
| - | 3612 | htim->PWM_PulseFinishedCallback(htim); |
|
| - | 3613 | #else |
|
| 2757 | HAL_TIM_OC_DelayElapsedCallback(htim); |
3614 | HAL_TIM_OC_DelayElapsedCallback(htim); |
| 2758 | HAL_TIM_PWM_PulseFinishedCallback(htim); |
3615 | HAL_TIM_PWM_PulseFinishedCallback(htim); |
| - | 3616 | #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */ |
|
| 2759 | } |
3617 | } |
| 2760 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED; |
3618 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED; |
| 2761 | } |
3619 | } |
| 2762 | } |
3620 | } |
| 2763 | /* Capture compare 4 event */ |
3621 | /* Capture compare 4 event */ |
| 2764 | if(__HAL_TIM_GET_FLAG(htim, TIM_FLAG_CC4) != RESET) |
3622 | if (__HAL_TIM_GET_FLAG(htim, TIM_FLAG_CC4) != RESET) |
| 2765 | { |
3623 | { |
| 2766 | if(__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_CC4) !=RESET) |
3624 | if (__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_CC4) != RESET) |
| 2767 | { |
3625 | { |
| 2768 | __HAL_TIM_CLEAR_IT(htim, TIM_IT_CC4); |
3626 | __HAL_TIM_CLEAR_IT(htim, TIM_IT_CC4); |
| 2769 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_4; |
3627 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_4; |
| 2770 | /* Input capture event */ |
3628 | /* Input capture event */ |
| 2771 | if((htim->Instance->CCMR2 & TIM_CCMR2_CC4S) != 0x00) |
3629 | if ((htim->Instance->CCMR2 & TIM_CCMR2_CC4S) != 0x00U) |
| 2772 | { |
3630 | { |
| - | 3631 | #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) |
|
| - | 3632 | htim->IC_CaptureCallback(htim); |
|
| - | 3633 | #else |
|
| 2773 | HAL_TIM_IC_CaptureCallback(htim); |
3634 | HAL_TIM_IC_CaptureCallback(htim); |
| - | 3635 | #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */ |
|
| 2774 | } |
3636 | } |
| 2775 | /* Output compare event */ |
3637 | /* Output compare event */ |
| 2776 | else |
3638 | else |
| 2777 | { |
3639 | { |
| - | 3640 | #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) |
|
| - | 3641 | htim->OC_DelayElapsedCallback(htim); |
|
| - | 3642 | htim->PWM_PulseFinishedCallback(htim); |
|
| - | 3643 | #else |
|
| 2778 | HAL_TIM_OC_DelayElapsedCallback(htim); |
3644 | HAL_TIM_OC_DelayElapsedCallback(htim); |
| 2779 | HAL_TIM_PWM_PulseFinishedCallback(htim); |
3645 | HAL_TIM_PWM_PulseFinishedCallback(htim); |
| - | 3646 | #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */ |
|
| 2780 | } |
3647 | } |
| 2781 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED; |
3648 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED; |
| 2782 | } |
3649 | } |
| 2783 | } |
3650 | } |
| 2784 | /* TIM Update event */ |
3651 | /* TIM Update event */ |
| 2785 | if(__HAL_TIM_GET_FLAG(htim, TIM_FLAG_UPDATE) != RESET) |
3652 | if (__HAL_TIM_GET_FLAG(htim, TIM_FLAG_UPDATE) != RESET) |
| 2786 | { |
3653 | { |
| 2787 | if(__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_UPDATE) !=RESET) |
3654 | if (__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_UPDATE) != RESET) |
| 2788 | { |
3655 | { |
| 2789 | __HAL_TIM_CLEAR_IT(htim, TIM_IT_UPDATE); |
3656 | __HAL_TIM_CLEAR_IT(htim, TIM_IT_UPDATE); |
| - | 3657 | #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) |
|
| - | 3658 | htim->PeriodElapsedCallback(htim); |
|
| - | 3659 | #else |
|
| 2790 | HAL_TIM_PeriodElapsedCallback(htim); |
3660 | HAL_TIM_PeriodElapsedCallback(htim); |
| - | 3661 | #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */ |
|
| 2791 | } |
3662 | } |
| 2792 | } |
3663 | } |
| 2793 | /* TIM Trigger detection event */ |
3664 | /* TIM Trigger detection event */ |
| 2794 | if(__HAL_TIM_GET_FLAG(htim, TIM_FLAG_TRIGGER) != RESET) |
3665 | if (__HAL_TIM_GET_FLAG(htim, TIM_FLAG_TRIGGER) != RESET) |
| 2795 | { |
3666 | { |
| 2796 | if(__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_TRIGGER) !=RESET) |
3667 | if (__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_TRIGGER) != RESET) |
| 2797 | { |
3668 | { |
| 2798 | __HAL_TIM_CLEAR_IT(htim, TIM_IT_TRIGGER); |
3669 | __HAL_TIM_CLEAR_IT(htim, TIM_IT_TRIGGER); |
| - | 3670 | #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) |
|
| - | 3671 | htim->TriggerCallback(htim); |
|
| - | 3672 | #else |
|
| 2799 | HAL_TIM_TriggerCallback(htim); |
3673 | HAL_TIM_TriggerCallback(htim); |
| - | 3674 | #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */ |
|
| 2800 | } |
3675 | } |
| 2801 | } |
3676 | } |
| 2802 | } |
3677 | } |
| 2803 | 3678 | ||
| 2804 | /** |
3679 | /** |
| 2805 | * @} |
3680 | * @} |
| 2806 | */ |
3681 | */ |
| 2807 | 3682 | ||
| 2808 | /** @defgroup TIM_Exported_Functions_Group8 Peripheral Control functions |
3683 | /** @defgroup TIM_Exported_Functions_Group8 TIM Peripheral Control functions |
| 2809 | * @brief Peripheral Control functions |
3684 | * @brief TIM Peripheral Control functions |
| 2810 | * |
3685 | * |
| 2811 | @verbatim |
3686 | @verbatim |
| 2812 | ============================================================================== |
3687 | ============================================================================== |
| 2813 | ##### Peripheral Control functions ##### |
3688 | ##### Peripheral Control functions ##### |
| 2814 | ============================================================================== |
3689 | ============================================================================== |
| 2815 | [..] |
3690 | [..] |
| 2816 | This section provides functions allowing to: |
3691 | This section provides functions allowing to: |
| 2817 | (+) Configure The Input Output channels for OC, PWM, IC or One Pulse mode. |
3692 | (+) Configure The Input Output channels for OC, PWM, IC or One Pulse mode. |
| 2818 | (+) Configure External Clock source. |
3693 | (+) Configure External Clock source. |
| 2819 | (+) Configure Complementary channels, break features and dead time. |
- | |
| 2820 | (+) Configure Master and the Slave synchronization. |
3694 | (+) Configure Master and the Slave synchronization. |
| 2821 | (+) Configure the DMA Burst Mode. |
3695 | (+) Configure the DMA Burst Mode. |
| 2822 | 3696 | ||
| 2823 | @endverbatim |
3697 | @endverbatim |
| 2824 | * @{ |
3698 | * @{ |
| 2825 | */ |
3699 | */ |
| 2826 | 3700 | ||
| 2827 | /** |
3701 | /** |
| 2828 | * @brief Initializes the TIM Output Compare Channels according to the specified |
3702 | * @brief Initializes the TIM Output Compare Channels according to the specified |
| 2829 | * parameters in the TIM_OC_InitTypeDef. |
3703 | * parameters in the TIM_OC_InitTypeDef. |
| 2830 | * @param htim: TIM Output Compare handle |
3704 | * @param htim TIM Output Compare handle |
| 2831 | * @param sConfig: TIM Output Compare configuration structure |
3705 | * @param sConfig TIM Output Compare configuration structure |
| 2832 | * @param Channel : TIM Channels to configure |
3706 | * @param Channel TIM Channels to configure |
| 2833 | * This parameter can be one of the following values: |
3707 | * This parameter can be one of the following values: |
| 2834 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
3708 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
| 2835 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
3709 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
| 2836 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
3710 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
| 2837 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
3711 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
| 2838 | * @retval HAL status |
3712 | * @retval HAL status |
| 2839 | */ |
3713 | */ |
| 2840 | HAL_StatusTypeDef HAL_TIM_OC_ConfigChannel(TIM_HandleTypeDef *htim, TIM_OC_InitTypeDef* sConfig, uint32_t Channel) |
3714 | HAL_StatusTypeDef HAL_TIM_OC_ConfigChannel(TIM_HandleTypeDef *htim, |
| - | 3715 | TIM_OC_InitTypeDef *sConfig, |
|
| - | 3716 | uint32_t Channel) |
|
| 2841 | { |
3717 | { |
| 2842 | /* Check the parameters */ |
3718 | /* Check the parameters */ |
| 2843 | assert_param(IS_TIM_CHANNELS(Channel)); |
3719 | assert_param(IS_TIM_CHANNELS(Channel)); |
| 2844 | assert_param(IS_TIM_OC_MODE(sConfig->OCMode)); |
3720 | assert_param(IS_TIM_OC_MODE(sConfig->OCMode)); |
| 2845 | assert_param(IS_TIM_OC_POLARITY(sConfig->OCPolarity)); |
3721 | assert_param(IS_TIM_OC_POLARITY(sConfig->OCPolarity)); |
| 2846 | 3722 | ||
| 2847 | /* Check input state */ |
3723 | /* Process Locked */ |
| 2848 | __HAL_LOCK(htim); |
3724 | __HAL_LOCK(htim); |
| 2849 | 3725 | ||
| 2850 | htim->State = HAL_TIM_STATE_BUSY; |
- | |
| 2851 | - | ||
| 2852 | switch (Channel) |
3726 | switch (Channel) |
| 2853 | { |
3727 | { |
| 2854 | case TIM_CHANNEL_1: |
3728 | case TIM_CHANNEL_1: |
| 2855 | { |
3729 | { |
| - | 3730 | /* Check the parameters */ |
|
| 2856 | assert_param(IS_TIM_CC1_INSTANCE(htim->Instance)); |
3731 | assert_param(IS_TIM_CC1_INSTANCE(htim->Instance)); |
| - | 3732 | ||
| 2857 | /* Configure the TIM Channel 1 in Output Compare */ |
3733 | /* Configure the TIM Channel 1 in Output Compare */ |
| 2858 | TIM_OC1_SetConfig(htim->Instance, sConfig); |
3734 | TIM_OC1_SetConfig(htim->Instance, sConfig); |
| - | 3735 | break; |
|
| 2859 | } |
3736 | } |
| 2860 | break; |
- | |
| 2861 | 3737 | ||
| 2862 | case TIM_CHANNEL_2: |
3738 | case TIM_CHANNEL_2: |
| 2863 | { |
3739 | { |
| - | 3740 | /* Check the parameters */ |
|
| 2864 | assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); |
3741 | assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); |
| - | 3742 | ||
| 2865 | /* Configure the TIM Channel 2 in Output Compare */ |
3743 | /* Configure the TIM Channel 2 in Output Compare */ |
| 2866 | TIM_OC2_SetConfig(htim->Instance, sConfig); |
3744 | TIM_OC2_SetConfig(htim->Instance, sConfig); |
| - | 3745 | break; |
|
| 2867 | } |
3746 | } |
| 2868 | break; |
- | |
| 2869 | 3747 | ||
| 2870 | case TIM_CHANNEL_3: |
3748 | case TIM_CHANNEL_3: |
| 2871 | { |
3749 | { |
| - | 3750 | /* Check the parameters */ |
|
| 2872 | assert_param(IS_TIM_CC3_INSTANCE(htim->Instance)); |
3751 | assert_param(IS_TIM_CC3_INSTANCE(htim->Instance)); |
| - | 3752 | ||
| 2873 | /* Configure the TIM Channel 3 in Output Compare */ |
3753 | /* Configure the TIM Channel 3 in Output Compare */ |
| 2874 | TIM_OC3_SetConfig(htim->Instance, sConfig); |
3754 | TIM_OC3_SetConfig(htim->Instance, sConfig); |
| - | 3755 | break; |
|
| 2875 | } |
3756 | } |
| 2876 | break; |
- | |
| 2877 | 3757 | ||
| 2878 | case TIM_CHANNEL_4: |
3758 | case TIM_CHANNEL_4: |
| 2879 | { |
3759 | { |
| - | 3760 | /* Check the parameters */ |
|
| 2880 | assert_param(IS_TIM_CC4_INSTANCE(htim->Instance)); |
3761 | assert_param(IS_TIM_CC4_INSTANCE(htim->Instance)); |
| - | 3762 | ||
| 2881 | /* Configure the TIM Channel 4 in Output Compare */ |
3763 | /* Configure the TIM Channel 4 in Output Compare */ |
| 2882 | TIM_OC4_SetConfig(htim->Instance, sConfig); |
3764 | TIM_OC4_SetConfig(htim->Instance, sConfig); |
| - | 3765 | break; |
|
| 2883 | } |
3766 | } |
| 2884 | break; |
- | |
| 2885 | 3767 | ||
| 2886 | default: |
3768 | default: |
| 2887 | break; |
3769 | break; |
| 2888 | } |
3770 | } |
| 2889 | htim->State = HAL_TIM_STATE_READY; |
- | |
| 2890 | 3771 | ||
| 2891 | __HAL_UNLOCK(htim); |
3772 | __HAL_UNLOCK(htim); |
| 2892 | 3773 | ||
| 2893 | return HAL_OK; |
3774 | return HAL_OK; |
| 2894 | } |
3775 | } |
| 2895 | 3776 | ||
| 2896 | /** |
3777 | /** |
| 2897 | * @brief Initializes the TIM Input Capture Channels according to the specified |
3778 | * @brief Initializes the TIM Input Capture Channels according to the specified |
| 2898 | * parameters in the TIM_IC_InitTypeDef. |
3779 | * parameters in the TIM_IC_InitTypeDef. |
| 2899 | * @param htim: TIM IC handle |
3780 | * @param htim TIM IC handle |
| 2900 | * @param sConfig: TIM Input Capture configuration structure |
3781 | * @param sConfig TIM Input Capture configuration structure |
| 2901 | * @param Channel : TIM Channels to be enabled |
3782 | * @param Channel TIM Channel to configure |
| 2902 | * This parameter can be one of the following values: |
3783 | * This parameter can be one of the following values: |
| 2903 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
3784 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
| 2904 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
3785 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
| 2905 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
3786 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
| 2906 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
3787 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
| 2907 | * @retval HAL status |
3788 | * @retval HAL status |
| 2908 | */ |
3789 | */ |
| 2909 | HAL_StatusTypeDef HAL_TIM_IC_ConfigChannel(TIM_HandleTypeDef *htim, TIM_IC_InitTypeDef* sConfig, uint32_t Channel) |
3790 | HAL_StatusTypeDef HAL_TIM_IC_ConfigChannel(TIM_HandleTypeDef *htim, TIM_IC_InitTypeDef *sConfig, uint32_t Channel) |
| 2910 | { |
3791 | { |
| 2911 | /* Check the parameters */ |
3792 | /* Check the parameters */ |
| 2912 | assert_param(IS_TIM_CC1_INSTANCE(htim->Instance)); |
3793 | assert_param(IS_TIM_CC1_INSTANCE(htim->Instance)); |
| 2913 | assert_param(IS_TIM_IC_POLARITY(sConfig->ICPolarity)); |
3794 | assert_param(IS_TIM_IC_POLARITY(sConfig->ICPolarity)); |
| 2914 | assert_param(IS_TIM_IC_SELECTION(sConfig->ICSelection)); |
3795 | assert_param(IS_TIM_IC_SELECTION(sConfig->ICSelection)); |
| 2915 | assert_param(IS_TIM_IC_PRESCALER(sConfig->ICPrescaler)); |
3796 | assert_param(IS_TIM_IC_PRESCALER(sConfig->ICPrescaler)); |
| 2916 | assert_param(IS_TIM_IC_FILTER(sConfig->ICFilter)); |
3797 | assert_param(IS_TIM_IC_FILTER(sConfig->ICFilter)); |
| 2917 | 3798 | ||
| - | 3799 | /* Process Locked */ |
|
| 2918 | __HAL_LOCK(htim); |
3800 | __HAL_LOCK(htim); |
| 2919 | 3801 | ||
| 2920 | htim->State = HAL_TIM_STATE_BUSY; |
- | |
| 2921 | - | ||
| 2922 | if (Channel == TIM_CHANNEL_1) |
3802 | if (Channel == TIM_CHANNEL_1) |
| 2923 | { |
3803 | { |
| 2924 | /* TI1 Configuration */ |
3804 | /* TI1 Configuration */ |
| 2925 | TIM_TI1_SetConfig(htim->Instance, |
3805 | TIM_TI1_SetConfig(htim->Instance, |
| 2926 | sConfig->ICPolarity, |
3806 | sConfig->ICPolarity, |
| 2927 | sConfig->ICSelection, |
3807 | sConfig->ICSelection, |
| 2928 | sConfig->ICFilter); |
3808 | sConfig->ICFilter); |
| 2929 | 3809 | ||
| 2930 | /* Reset the IC1PSC Bits */ |
3810 | /* Reset the IC1PSC Bits */ |
| 2931 | htim->Instance->CCMR1 &= ~TIM_CCMR1_IC1PSC; |
3811 | htim->Instance->CCMR1 &= ~TIM_CCMR1_IC1PSC; |
| 2932 | 3812 | ||
| 2933 | /* Set the IC1PSC value */ |
3813 | /* Set the IC1PSC value */ |
| Line 2945... | Line 3825... | ||
| 2945 | 3825 | ||
| 2946 | /* Reset the IC2PSC Bits */ |
3826 | /* Reset the IC2PSC Bits */ |
| 2947 | htim->Instance->CCMR1 &= ~TIM_CCMR1_IC2PSC; |
3827 | htim->Instance->CCMR1 &= ~TIM_CCMR1_IC2PSC; |
| 2948 | 3828 | ||
| 2949 | /* Set the IC2PSC value */ |
3829 | /* Set the IC2PSC value */ |
| 2950 | htim->Instance->CCMR1 |= (sConfig->ICPrescaler << 8); |
3830 | htim->Instance->CCMR1 |= (sConfig->ICPrescaler << 8U); |
| 2951 | } |
3831 | } |
| 2952 | else if (Channel == TIM_CHANNEL_3) |
3832 | else if (Channel == TIM_CHANNEL_3) |
| 2953 | { |
3833 | { |
| 2954 | /* TI3 Configuration */ |
3834 | /* TI3 Configuration */ |
| 2955 | assert_param(IS_TIM_CC3_INSTANCE(htim->Instance)); |
3835 | assert_param(IS_TIM_CC3_INSTANCE(htim->Instance)); |
| 2956 | 3836 | ||
| 2957 | TIM_TI3_SetConfig(htim->Instance, |
3837 | TIM_TI3_SetConfig(htim->Instance, |
| 2958 | sConfig->ICPolarity, |
3838 | sConfig->ICPolarity, |
| 2959 | sConfig->ICSelection, |
3839 | sConfig->ICSelection, |
| 2960 | sConfig->ICFilter); |
3840 | sConfig->ICFilter); |
| 2961 | 3841 | ||
| 2962 | /* Reset the IC3PSC Bits */ |
3842 | /* Reset the IC3PSC Bits */ |
| 2963 | htim->Instance->CCMR2 &= ~TIM_CCMR2_IC3PSC; |
3843 | htim->Instance->CCMR2 &= ~TIM_CCMR2_IC3PSC; |
| 2964 | 3844 | ||
| 2965 | /* Set the IC3PSC value */ |
3845 | /* Set the IC3PSC value */ |
| Line 2969... | Line 3849... | ||
| 2969 | { |
3849 | { |
| 2970 | /* TI4 Configuration */ |
3850 | /* TI4 Configuration */ |
| 2971 | assert_param(IS_TIM_CC4_INSTANCE(htim->Instance)); |
3851 | assert_param(IS_TIM_CC4_INSTANCE(htim->Instance)); |
| 2972 | 3852 | ||
| 2973 | TIM_TI4_SetConfig(htim->Instance, |
3853 | TIM_TI4_SetConfig(htim->Instance, |
| 2974 | sConfig->ICPolarity, |
3854 | sConfig->ICPolarity, |
| 2975 | sConfig->ICSelection, |
3855 | sConfig->ICSelection, |
| 2976 | sConfig->ICFilter); |
3856 | sConfig->ICFilter); |
| 2977 | 3857 | ||
| 2978 | /* Reset the IC4PSC Bits */ |
3858 | /* Reset the IC4PSC Bits */ |
| 2979 | htim->Instance->CCMR2 &= ~TIM_CCMR2_IC4PSC; |
3859 | htim->Instance->CCMR2 &= ~TIM_CCMR2_IC4PSC; |
| 2980 | 3860 | ||
| 2981 | /* Set the IC4PSC value */ |
3861 | /* Set the IC4PSC value */ |
| 2982 | htim->Instance->CCMR2 |= (sConfig->ICPrescaler << 8); |
3862 | htim->Instance->CCMR2 |= (sConfig->ICPrescaler << 8U); |
| 2983 | } |
3863 | } |
| 2984 | 3864 | ||
| 2985 | htim->State = HAL_TIM_STATE_READY; |
- | |
| 2986 | - | ||
| 2987 | __HAL_UNLOCK(htim); |
3865 | __HAL_UNLOCK(htim); |
| 2988 | 3866 | ||
| 2989 | return HAL_OK; |
3867 | return HAL_OK; |
| 2990 | } |
3868 | } |
| 2991 | 3869 | ||
| 2992 | /** |
3870 | /** |
| 2993 | * @brief Initializes the TIM PWM channels according to the specified |
3871 | * @brief Initializes the TIM PWM channels according to the specified |
| 2994 | * parameters in the TIM_OC_InitTypeDef. |
3872 | * parameters in the TIM_OC_InitTypeDef. |
| 2995 | * @param htim: TIM PWM handle |
3873 | * @param htim TIM PWM handle |
| 2996 | * @param sConfig: TIM PWM configuration structure |
3874 | * @param sConfig TIM PWM configuration structure |
| 2997 | * @param Channel : TIM Channels to be configured |
3875 | * @param Channel TIM Channels to be configured |
| 2998 | * This parameter can be one of the following values: |
3876 | * This parameter can be one of the following values: |
| 2999 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
3877 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
| 3000 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
3878 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
| 3001 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
3879 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
| 3002 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
3880 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
| 3003 | * @retval HAL status |
3881 | * @retval HAL status |
| 3004 | */ |
3882 | */ |
| 3005 | HAL_StatusTypeDef HAL_TIM_PWM_ConfigChannel(TIM_HandleTypeDef *htim, TIM_OC_InitTypeDef* sConfig, uint32_t Channel) |
3883 | HAL_StatusTypeDef HAL_TIM_PWM_ConfigChannel(TIM_HandleTypeDef *htim, |
| - | 3884 | TIM_OC_InitTypeDef *sConfig, |
|
| - | 3885 | uint32_t Channel) |
|
| 3006 | { |
3886 | { |
| 3007 | __HAL_LOCK(htim); |
- | |
| 3008 | - | ||
| 3009 | /* Check the parameters */ |
3887 | /* Check the parameters */ |
| 3010 | assert_param(IS_TIM_CHANNELS(Channel)); |
3888 | assert_param(IS_TIM_CHANNELS(Channel)); |
| 3011 | assert_param(IS_TIM_PWM_MODE(sConfig->OCMode)); |
3889 | assert_param(IS_TIM_PWM_MODE(sConfig->OCMode)); |
| 3012 | assert_param(IS_TIM_OC_POLARITY(sConfig->OCPolarity)); |
3890 | assert_param(IS_TIM_OC_POLARITY(sConfig->OCPolarity)); |
| 3013 | assert_param(IS_TIM_FAST_STATE(sConfig->OCFastMode)); |
3891 | assert_param(IS_TIM_FAST_STATE(sConfig->OCFastMode)); |
| 3014 | 3892 | ||
| - | 3893 | /* Process Locked */ |
|
| 3015 | htim->State = HAL_TIM_STATE_BUSY; |
3894 | __HAL_LOCK(htim); |
| 3016 | 3895 | ||
| 3017 | switch (Channel) |
3896 | switch (Channel) |
| 3018 | { |
3897 | { |
| 3019 | case TIM_CHANNEL_1: |
3898 | case TIM_CHANNEL_1: |
| 3020 | { |
3899 | { |
| - | 3900 | /* Check the parameters */ |
|
| 3021 | assert_param(IS_TIM_CC1_INSTANCE(htim->Instance)); |
3901 | assert_param(IS_TIM_CC1_INSTANCE(htim->Instance)); |
| - | 3902 | ||
| 3022 | /* Configure the Channel 1 in PWM mode */ |
3903 | /* Configure the Channel 1 in PWM mode */ |
| 3023 | TIM_OC1_SetConfig(htim->Instance, sConfig); |
3904 | TIM_OC1_SetConfig(htim->Instance, sConfig); |
| 3024 | 3905 | ||
| 3025 | /* Set the Preload enable bit for channel1 */ |
3906 | /* Set the Preload enable bit for channel1 */ |
| 3026 | htim->Instance->CCMR1 |= TIM_CCMR1_OC1PE; |
3907 | htim->Instance->CCMR1 |= TIM_CCMR1_OC1PE; |
| 3027 | 3908 | ||
| 3028 | /* Configure the Output Fast mode */ |
3909 | /* Configure the Output Fast mode */ |
| 3029 | htim->Instance->CCMR1 &= ~TIM_CCMR1_OC1FE; |
3910 | htim->Instance->CCMR1 &= ~TIM_CCMR1_OC1FE; |
| 3030 | htim->Instance->CCMR1 |= sConfig->OCFastMode; |
3911 | htim->Instance->CCMR1 |= sConfig->OCFastMode; |
| - | 3912 | break; |
|
| 3031 | } |
3913 | } |
| 3032 | break; |
- | |
| 3033 | 3914 | ||
| 3034 | case TIM_CHANNEL_2: |
3915 | case TIM_CHANNEL_2: |
| 3035 | { |
3916 | { |
| - | 3917 | /* Check the parameters */ |
|
| 3036 | assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); |
3918 | assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); |
| - | 3919 | ||
| 3037 | /* Configure the Channel 2 in PWM mode */ |
3920 | /* Configure the Channel 2 in PWM mode */ |
| 3038 | TIM_OC2_SetConfig(htim->Instance, sConfig); |
3921 | TIM_OC2_SetConfig(htim->Instance, sConfig); |
| 3039 | 3922 | ||
| 3040 | /* Set the Preload enable bit for channel2 */ |
3923 | /* Set the Preload enable bit for channel2 */ |
| 3041 | htim->Instance->CCMR1 |= TIM_CCMR1_OC2PE; |
3924 | htim->Instance->CCMR1 |= TIM_CCMR1_OC2PE; |
| 3042 | 3925 | ||
| 3043 | /* Configure the Output Fast mode */ |
3926 | /* Configure the Output Fast mode */ |
| 3044 | htim->Instance->CCMR1 &= ~TIM_CCMR1_OC2FE; |
3927 | htim->Instance->CCMR1 &= ~TIM_CCMR1_OC2FE; |
| 3045 | htim->Instance->CCMR1 |= sConfig->OCFastMode << 8; |
3928 | htim->Instance->CCMR1 |= sConfig->OCFastMode << 8U; |
| - | 3929 | break; |
|
| 3046 | } |
3930 | } |
| 3047 | break; |
- | |
| 3048 | 3931 | ||
| 3049 | case TIM_CHANNEL_3: |
3932 | case TIM_CHANNEL_3: |
| 3050 | { |
3933 | { |
| - | 3934 | /* Check the parameters */ |
|
| 3051 | assert_param(IS_TIM_CC3_INSTANCE(htim->Instance)); |
3935 | assert_param(IS_TIM_CC3_INSTANCE(htim->Instance)); |
| - | 3936 | ||
| 3052 | /* Configure the Channel 3 in PWM mode */ |
3937 | /* Configure the Channel 3 in PWM mode */ |
| 3053 | TIM_OC3_SetConfig(htim->Instance, sConfig); |
3938 | TIM_OC3_SetConfig(htim->Instance, sConfig); |
| 3054 | 3939 | ||
| 3055 | /* Set the Preload enable bit for channel3 */ |
3940 | /* Set the Preload enable bit for channel3 */ |
| 3056 | htim->Instance->CCMR2 |= TIM_CCMR2_OC3PE; |
3941 | htim->Instance->CCMR2 |= TIM_CCMR2_OC3PE; |
| 3057 | 3942 | ||
| 3058 | /* Configure the Output Fast mode */ |
3943 | /* Configure the Output Fast mode */ |
| 3059 | htim->Instance->CCMR2 &= ~TIM_CCMR2_OC3FE; |
3944 | htim->Instance->CCMR2 &= ~TIM_CCMR2_OC3FE; |
| 3060 | htim->Instance->CCMR2 |= sConfig->OCFastMode; |
3945 | htim->Instance->CCMR2 |= sConfig->OCFastMode; |
| - | 3946 | break; |
|
| 3061 | } |
3947 | } |
| 3062 | break; |
- | |
| 3063 | 3948 | ||
| 3064 | case TIM_CHANNEL_4: |
3949 | case TIM_CHANNEL_4: |
| 3065 | { |
3950 | { |
| - | 3951 | /* Check the parameters */ |
|
| 3066 | assert_param(IS_TIM_CC4_INSTANCE(htim->Instance)); |
3952 | assert_param(IS_TIM_CC4_INSTANCE(htim->Instance)); |
| - | 3953 | ||
| 3067 | /* Configure the Channel 4 in PWM mode */ |
3954 | /* Configure the Channel 4 in PWM mode */ |
| 3068 | TIM_OC4_SetConfig(htim->Instance, sConfig); |
3955 | TIM_OC4_SetConfig(htim->Instance, sConfig); |
| 3069 | 3956 | ||
| 3070 | /* Set the Preload enable bit for channel4 */ |
3957 | /* Set the Preload enable bit for channel4 */ |
| 3071 | htim->Instance->CCMR2 |= TIM_CCMR2_OC4PE; |
3958 | htim->Instance->CCMR2 |= TIM_CCMR2_OC4PE; |
| 3072 | 3959 | ||
| 3073 | /* Configure the Output Fast mode */ |
3960 | /* Configure the Output Fast mode */ |
| 3074 | htim->Instance->CCMR2 &= ~TIM_CCMR2_OC4FE; |
3961 | htim->Instance->CCMR2 &= ~TIM_CCMR2_OC4FE; |
| 3075 | htim->Instance->CCMR2 |= sConfig->OCFastMode << 8; |
3962 | htim->Instance->CCMR2 |= sConfig->OCFastMode << 8U; |
| - | 3963 | break; |
|
| 3076 | } |
3964 | } |
| 3077 | break; |
- | |
| 3078 | 3965 | ||
| 3079 | default: |
3966 | default: |
| 3080 | break; |
3967 | break; |
| 3081 | } |
3968 | } |
| 3082 | 3969 | ||
| 3083 | htim->State = HAL_TIM_STATE_READY; |
- | |
| 3084 | - | ||
| 3085 | __HAL_UNLOCK(htim); |
3970 | __HAL_UNLOCK(htim); |
| 3086 | 3971 | ||
| 3087 | return HAL_OK; |
3972 | return HAL_OK; |
| 3088 | } |
3973 | } |
| 3089 | 3974 | ||
| 3090 | /** |
3975 | /** |
| 3091 | * @brief Initializes the TIM One Pulse Channels according to the specified |
3976 | * @brief Initializes the TIM One Pulse Channels according to the specified |
| 3092 | * parameters in the TIM_OnePulse_InitTypeDef. |
3977 | * parameters in the TIM_OnePulse_InitTypeDef. |
| 3093 | * @param htim: TIM One Pulse handle |
3978 | * @param htim TIM One Pulse handle |
| 3094 | * @param sConfig: TIM One Pulse configuration structure |
3979 | * @param sConfig TIM One Pulse configuration structure |
| 3095 | * @param OutputChannel : TIM Channels to be enabled |
3980 | * @param OutputChannel TIM output channel to configure |
| 3096 | * This parameter can be one of the following values: |
3981 | * This parameter can be one of the following values: |
| 3097 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
3982 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
| 3098 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
3983 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
| 3099 | * @param InputChannel : TIM Channels to be enabled |
3984 | * @param InputChannel TIM input Channel to configure |
| 3100 | * This parameter can be one of the following values: |
3985 | * This parameter can be one of the following values: |
| 3101 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
3986 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
| 3102 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
3987 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
| - | 3988 | * @note To output a waveform with a minimum delay user can enable the fast |
|
| - | 3989 | * mode by calling the @ref __HAL_TIM_ENABLE_OCxFAST macro. Then CCx |
|
| - | 3990 | * output is forced in response to the edge detection on TIx input, |
|
| - | 3991 | * without taking in account the comparison. |
|
| 3103 | * @retval HAL status |
3992 | * @retval HAL status |
| 3104 | */ |
3993 | */ |
| 3105 | HAL_StatusTypeDef HAL_TIM_OnePulse_ConfigChannel(TIM_HandleTypeDef *htim, TIM_OnePulse_InitTypeDef* sConfig, uint32_t OutputChannel, uint32_t InputChannel) |
3994 | HAL_StatusTypeDef HAL_TIM_OnePulse_ConfigChannel(TIM_HandleTypeDef *htim, TIM_OnePulse_InitTypeDef *sConfig, |
| - | 3995 | uint32_t OutputChannel, uint32_t InputChannel) |
|
| 3106 | { |
3996 | { |
| 3107 | TIM_OC_InitTypeDef temp1; |
3997 | TIM_OC_InitTypeDef temp1; |
| 3108 | 3998 | ||
| 3109 | /* Check the parameters */ |
3999 | /* Check the parameters */ |
| 3110 | assert_param(IS_TIM_OPM_CHANNELS(OutputChannel)); |
4000 | assert_param(IS_TIM_OPM_CHANNELS(OutputChannel)); |
| 3111 | assert_param(IS_TIM_OPM_CHANNELS(InputChannel)); |
4001 | assert_param(IS_TIM_OPM_CHANNELS(InputChannel)); |
| 3112 | 4002 | ||
| 3113 | if(OutputChannel != InputChannel) |
4003 | if (OutputChannel != InputChannel) |
| 3114 | { |
4004 | { |
| - | 4005 | /* Process Locked */ |
|
| 3115 | __HAL_LOCK(htim); |
4006 | __HAL_LOCK(htim); |
| 3116 | 4007 | ||
| 3117 | htim->State = HAL_TIM_STATE_BUSY; |
4008 | htim->State = HAL_TIM_STATE_BUSY; |
| 3118 | 4009 | ||
| 3119 | /* Extract the Ouput compare configuration from sConfig structure */ |
4010 | /* Extract the Output compare configuration from sConfig structure */ |
| 3120 | temp1.OCMode = sConfig->OCMode; |
4011 | temp1.OCMode = sConfig->OCMode; |
| 3121 | temp1.Pulse = sConfig->Pulse; |
4012 | temp1.Pulse = sConfig->Pulse; |
| 3122 | temp1.OCPolarity = sConfig->OCPolarity; |
4013 | temp1.OCPolarity = sConfig->OCPolarity; |
| 3123 | temp1.OCIdleState = sConfig->OCIdleState; |
- | |
| 3124 | 4014 | ||
| 3125 | switch (OutputChannel) |
4015 | switch (OutputChannel) |
| 3126 | { |
- | |
| 3127 | case TIM_CHANNEL_1: |
- | |
| 3128 | { |
4016 | { |
| - | 4017 | case TIM_CHANNEL_1: |
|
| - | 4018 | { |
|
| 3129 | assert_param(IS_TIM_CC1_INSTANCE(htim->Instance)); |
4019 | assert_param(IS_TIM_CC1_INSTANCE(htim->Instance)); |
| 3130 | 4020 | ||
| 3131 | TIM_OC1_SetConfig(htim->Instance, &temp1); |
4021 | TIM_OC1_SetConfig(htim->Instance, &temp1); |
| 3132 | } |
4022 | break; |
| 3133 | break; |
4023 | } |
| 3134 | case TIM_CHANNEL_2: |
4024 | case TIM_CHANNEL_2: |
| 3135 | { |
4025 | { |
| 3136 | assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); |
4026 | assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); |
| 3137 | 4027 | ||
| 3138 | TIM_OC2_SetConfig(htim->Instance, &temp1); |
4028 | TIM_OC2_SetConfig(htim->Instance, &temp1); |
| - | 4029 | break; |
|
| - | 4030 | } |
|
| - | 4031 | default: |
|
| - | 4032 | break; |
|
| 3139 | } |
4033 | } |
| 3140 | break; |
- | |
| 3141 | default: |
- | |
| 3142 | break; |
- | |
| 3143 | } |
4034 | |
| 3144 | switch (InputChannel) |
4035 | switch (InputChannel) |
| 3145 | { |
- | |
| 3146 | case TIM_CHANNEL_1: |
- | |
| 3147 | { |
4036 | { |
| - | 4037 | case TIM_CHANNEL_1: |
|
| - | 4038 | { |
|
| 3148 | assert_param(IS_TIM_CC1_INSTANCE(htim->Instance)); |
4039 | assert_param(IS_TIM_CC1_INSTANCE(htim->Instance)); |
| 3149 | 4040 | ||
| 3150 | TIM_TI1_SetConfig(htim->Instance, sConfig->ICPolarity, |
4041 | TIM_TI1_SetConfig(htim->Instance, sConfig->ICPolarity, |
| 3151 | sConfig->ICSelection, sConfig->ICFilter); |
4042 | sConfig->ICSelection, sConfig->ICFilter); |
| 3152 | 4043 | ||
| 3153 | /* Reset the IC1PSC Bits */ |
4044 | /* Reset the IC1PSC Bits */ |
| 3154 | htim->Instance->CCMR1 &= ~TIM_CCMR1_IC1PSC; |
4045 | htim->Instance->CCMR1 &= ~TIM_CCMR1_IC1PSC; |
| 3155 | 4046 | ||
| 3156 | /* Select the Trigger source */ |
4047 | /* Select the Trigger source */ |
| 3157 | htim->Instance->SMCR &= ~TIM_SMCR_TS; |
4048 | htim->Instance->SMCR &= ~TIM_SMCR_TS; |
| 3158 | htim->Instance->SMCR |= TIM_TS_TI1FP1; |
4049 | htim->Instance->SMCR |= TIM_TS_TI1FP1; |
| 3159 | 4050 | ||
| 3160 | /* Select the Slave Mode */ |
4051 | /* Select the Slave Mode */ |
| 3161 | htim->Instance->SMCR &= ~TIM_SMCR_SMS; |
4052 | htim->Instance->SMCR &= ~TIM_SMCR_SMS; |
| 3162 | htim->Instance->SMCR |= TIM_SLAVEMODE_TRIGGER; |
4053 | htim->Instance->SMCR |= TIM_SLAVEMODE_TRIGGER; |
| 3163 | } |
4054 | break; |
| 3164 | break; |
4055 | } |
| 3165 | case TIM_CHANNEL_2: |
4056 | case TIM_CHANNEL_2: |
| 3166 | { |
4057 | { |
| 3167 | assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); |
4058 | assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); |
| 3168 | 4059 | ||
| 3169 | TIM_TI2_SetConfig(htim->Instance, sConfig->ICPolarity, |
4060 | TIM_TI2_SetConfig(htim->Instance, sConfig->ICPolarity, |
| 3170 | sConfig->ICSelection, sConfig->ICFilter); |
4061 | sConfig->ICSelection, sConfig->ICFilter); |
| 3171 | 4062 | ||
| 3172 | /* Reset the IC2PSC Bits */ |
4063 | /* Reset the IC2PSC Bits */ |
| 3173 | htim->Instance->CCMR1 &= ~TIM_CCMR1_IC2PSC; |
4064 | htim->Instance->CCMR1 &= ~TIM_CCMR1_IC2PSC; |
| 3174 | 4065 | ||
| 3175 | /* Select the Trigger source */ |
4066 | /* Select the Trigger source */ |
| 3176 | htim->Instance->SMCR &= ~TIM_SMCR_TS; |
4067 | htim->Instance->SMCR &= ~TIM_SMCR_TS; |
| 3177 | htim->Instance->SMCR |= TIM_TS_TI2FP2; |
4068 | htim->Instance->SMCR |= TIM_TS_TI2FP2; |
| 3178 | 4069 | ||
| 3179 | /* Select the Slave Mode */ |
4070 | /* Select the Slave Mode */ |
| 3180 | htim->Instance->SMCR &= ~TIM_SMCR_SMS; |
4071 | htim->Instance->SMCR &= ~TIM_SMCR_SMS; |
| 3181 | htim->Instance->SMCR |= TIM_SLAVEMODE_TRIGGER; |
4072 | htim->Instance->SMCR |= TIM_SLAVEMODE_TRIGGER; |
| 3182 | } |
4073 | break; |
| 3183 | break; |
4074 | } |
| 3184 | 4075 | ||
| 3185 | default: |
4076 | default: |
| 3186 | break; |
4077 | break; |
| 3187 | } |
4078 | } |
| 3188 | 4079 | ||
| 3189 | htim->State = HAL_TIM_STATE_READY; |
4080 | htim->State = HAL_TIM_STATE_READY; |
| 3190 | 4081 | ||
| 3191 | __HAL_UNLOCK(htim); |
4082 | __HAL_UNLOCK(htim); |
| 3192 | 4083 | ||
| 3193 | return HAL_OK; |
4084 | return HAL_OK; |
| 3194 | } |
4085 | } |
| 3195 | else |
4086 | else |
| 3196 | { |
4087 | { |
| 3197 | return HAL_ERROR; |
4088 | return HAL_ERROR; |
| 3198 | } |
4089 | } |
| 3199 | } |
4090 | } |
| 3200 | 4091 | ||
| 3201 | /** |
4092 | /** |
| 3202 | * @brief Configure the DMA Burst to transfer Data from the memory to the TIM peripheral |
4093 | * @brief Configure the DMA Burst to transfer Data from the memory to the TIM peripheral |
| 3203 | * @param htim: TIM handle |
4094 | * @param htim TIM handle |
| 3204 | * @param BurstBaseAddress : TIM Base address from where the DMA will start the Data write |
4095 | * @param BurstBaseAddress TIM Base address from where the DMA will start the Data write |
| 3205 | * This parameter can be one of the following values: |
4096 | * This parameter can be one of the following values: |
| 3206 | * @arg TIM_DMABASE_CR1 |
4097 | * @arg TIM_DMABASE_CR1 |
| 3207 | * @arg TIM_DMABASE_CR2 |
4098 | * @arg TIM_DMABASE_CR2 |
| 3208 | * @arg TIM_DMABASE_SMCR |
4099 | * @arg TIM_DMABASE_SMCR |
| 3209 | * @arg TIM_DMABASE_DIER |
4100 | * @arg TIM_DMABASE_DIER |
| Line 3217... | Line 4108... | ||
| 3217 | * @arg TIM_DMABASE_ARR |
4108 | * @arg TIM_DMABASE_ARR |
| 3218 | * @arg TIM_DMABASE_CCR1 |
4109 | * @arg TIM_DMABASE_CCR1 |
| 3219 | * @arg TIM_DMABASE_CCR2 |
4110 | * @arg TIM_DMABASE_CCR2 |
| 3220 | * @arg TIM_DMABASE_CCR3 |
4111 | * @arg TIM_DMABASE_CCR3 |
| 3221 | * @arg TIM_DMABASE_CCR4 |
4112 | * @arg TIM_DMABASE_CCR4 |
| 3222 | * @arg TIM_DMABASE_DCR |
4113 | * @arg TIM_DMABASE_OR |
| 3223 | * @param BurstRequestSrc: TIM DMA Request sources |
4114 | * @param BurstRequestSrc TIM DMA Request sources |
| 3224 | * This parameter can be one of the following values: |
4115 | * This parameter can be one of the following values: |
| 3225 | * @arg TIM_DMA_UPDATE: TIM update Interrupt source |
4116 | * @arg TIM_DMA_UPDATE: TIM update Interrupt source |
| 3226 | * @arg TIM_DMA_CC1: TIM Capture Compare 1 DMA source |
4117 | * @arg TIM_DMA_CC1: TIM Capture Compare 1 DMA source |
| 3227 | * @arg TIM_DMA_CC2: TIM Capture Compare 2 DMA source |
4118 | * @arg TIM_DMA_CC2: TIM Capture Compare 2 DMA source |
| 3228 | * @arg TIM_DMA_CC3: TIM Capture Compare 3 DMA source |
4119 | * @arg TIM_DMA_CC3: TIM Capture Compare 3 DMA source |
| 3229 | * @arg TIM_DMA_CC4: TIM Capture Compare 4 DMA source |
4120 | * @arg TIM_DMA_CC4: TIM Capture Compare 4 DMA source |
| 3230 | * @arg TIM_DMA_TRIGGER: TIM Trigger DMA source |
4121 | * @arg TIM_DMA_TRIGGER: TIM Trigger DMA source |
| 3231 | * @param BurstBuffer: The Buffer address. |
4122 | * @param BurstBuffer The Buffer address. |
| 3232 | * @param BurstLength: DMA Burst length. This parameter can be one value |
4123 | * @param BurstLength DMA Burst length. This parameter can be one value |
| 3233 | * between: TIM_DMABURSTLENGTH_1TRANSFER and TIM_DMABURSTLENGTH_18TRANSFERS. |
4124 | * between: TIM_DMABURSTLENGTH_1TRANSFER and TIM_DMABURSTLENGTH_18TRANSFERS. |
| - | 4125 | * @note This function should be used only when BurstLength is equal to DMA data transfer length. |
|
| 3234 | * @retval HAL status |
4126 | * @retval HAL status |
| 3235 | */ |
4127 | */ |
| 3236 | HAL_StatusTypeDef HAL_TIM_DMABurst_WriteStart(TIM_HandleTypeDef *htim, uint32_t BurstBaseAddress, uint32_t BurstRequestSrc, |
4128 | HAL_StatusTypeDef HAL_TIM_DMABurst_WriteStart(TIM_HandleTypeDef *htim, uint32_t BurstBaseAddress, |
| - | 4129 | uint32_t BurstRequestSrc, uint32_t *BurstBuffer, uint32_t BurstLength) |
|
| - | 4130 | { |
|
| - | 4131 | return HAL_TIM_DMABurst_MultiWriteStart(htim, BurstBaseAddress, BurstRequestSrc, BurstBuffer, BurstLength, |
|
| - | 4132 | ((BurstLength) >> 8U) + 1U); |
|
| - | 4133 | } |
|
| - | 4134 | ||
| - | 4135 | /** |
|
| - | 4136 | * @brief Configure the DMA Burst to transfer multiple Data from the memory to the TIM peripheral |
|
| - | 4137 | * @param htim TIM handle |
|
| - | 4138 | * @param BurstBaseAddress TIM Base address from where the DMA will start the Data write |
|
| - | 4139 | * This parameter can be one of the following values: |
|
| - | 4140 | * @arg TIM_DMABASE_CR1 |
|
| - | 4141 | * @arg TIM_DMABASE_CR2 |
|
| - | 4142 | * @arg TIM_DMABASE_SMCR |
|
| - | 4143 | * @arg TIM_DMABASE_DIER |
|
| - | 4144 | * @arg TIM_DMABASE_SR |
|
| - | 4145 | * @arg TIM_DMABASE_EGR |
|
| - | 4146 | * @arg TIM_DMABASE_CCMR1 |
|
| - | 4147 | * @arg TIM_DMABASE_CCMR2 |
|
| - | 4148 | * @arg TIM_DMABASE_CCER |
|
| - | 4149 | * @arg TIM_DMABASE_CNT |
|
| - | 4150 | * @arg TIM_DMABASE_PSC |
|
| - | 4151 | * @arg TIM_DMABASE_ARR |
|
| - | 4152 | * @arg TIM_DMABASE_CCR1 |
|
| - | 4153 | * @arg TIM_DMABASE_CCR2 |
|
| - | 4154 | * @arg TIM_DMABASE_CCR3 |
|
| - | 4155 | * @arg TIM_DMABASE_CCR4 |
|
| - | 4156 | * @arg TIM_DMABASE_OR |
|
| - | 4157 | * @param BurstRequestSrc TIM DMA Request sources |
|
| - | 4158 | * This parameter can be one of the following values: |
|
| - | 4159 | * @arg TIM_DMA_UPDATE: TIM update Interrupt source |
|
| - | 4160 | * @arg TIM_DMA_CC1: TIM Capture Compare 1 DMA source |
|
| - | 4161 | * @arg TIM_DMA_CC2: TIM Capture Compare 2 DMA source |
|
| - | 4162 | * @arg TIM_DMA_CC3: TIM Capture Compare 3 DMA source |
|
| - | 4163 | * @arg TIM_DMA_CC4: TIM Capture Compare 4 DMA source |
|
| - | 4164 | * @arg TIM_DMA_TRIGGER: TIM Trigger DMA source |
|
| - | 4165 | * @param BurstBuffer The Buffer address. |
|
| - | 4166 | * @param BurstLength DMA Burst length. This parameter can be one value |
|
| - | 4167 | * between: TIM_DMABURSTLENGTH_1TRANSFER and TIM_DMABURSTLENGTH_18TRANSFERS. |
|
| - | 4168 | * @param DataLength Data length. This parameter can be one value |
|
| - | 4169 | * between 1 and 0xFFFF. |
|
| - | 4170 | * @retval HAL status |
|
| - | 4171 | */ |
|
| - | 4172 | HAL_StatusTypeDef HAL_TIM_DMABurst_MultiWriteStart(TIM_HandleTypeDef *htim, uint32_t BurstBaseAddress, |
|
| - | 4173 | uint32_t BurstRequestSrc, uint32_t *BurstBuffer, |
|
| 3237 | uint32_t* BurstBuffer, uint32_t BurstLength) |
4174 | uint32_t BurstLength, uint32_t DataLength) |
| 3238 | { |
4175 | { |
| 3239 | /* Check the parameters */ |
4176 | /* Check the parameters */ |
| 3240 | assert_param(IS_TIM_DMABURST_INSTANCE(htim->Instance)); |
4177 | assert_param(IS_TIM_DMABURST_INSTANCE(htim->Instance)); |
| 3241 | assert_param(IS_TIM_DMA_BASE(BurstBaseAddress)); |
4178 | assert_param(IS_TIM_DMA_BASE(BurstBaseAddress)); |
| 3242 | assert_param(IS_TIM_DMA_SOURCE(BurstRequestSrc)); |
4179 | assert_param(IS_TIM_DMA_SOURCE(BurstRequestSrc)); |
| 3243 | assert_param(IS_TIM_DMA_LENGTH(BurstLength)); |
4180 | assert_param(IS_TIM_DMA_LENGTH(BurstLength)); |
| - | 4181 | assert_param(IS_TIM_DMA_DATA_LENGTH(DataLength)); |
|
| 3244 | 4182 | ||
| 3245 | if((htim->State == HAL_TIM_STATE_BUSY)) |
4183 | if (htim->DMABurstState == HAL_DMA_BURST_STATE_BUSY) |
| 3246 | { |
4184 | { |
| 3247 | return HAL_BUSY; |
4185 | return HAL_BUSY; |
| 3248 | } |
4186 | } |
| 3249 | else if((htim->State == HAL_TIM_STATE_READY)) |
4187 | else if (htim->DMABurstState == HAL_DMA_BURST_STATE_READY) |
| 3250 | { |
4188 | { |
| 3251 | if((BurstBuffer == 0 ) && (BurstLength > 0)) |
4189 | if ((BurstBuffer == NULL) && (BurstLength > 0U)) |
| 3252 | { |
4190 | { |
| 3253 | return HAL_ERROR; |
4191 | return HAL_ERROR; |
| 3254 | } |
4192 | } |
| 3255 | else |
4193 | else |
| 3256 | { |
4194 | { |
| 3257 | htim->State = HAL_TIM_STATE_BUSY; |
4195 | htim->DMABurstState = HAL_DMA_BURST_STATE_BUSY; |
| 3258 | } |
4196 | } |
| 3259 | } |
4197 | } |
| 3260 | else |
4198 | else |
| 3261 | { |
4199 | { |
| 3262 | return HAL_ERROR; |
4200 | /* nothing to do */ |
| 3263 | } |
4201 | } |
| 3264 | - | ||
| 3265 | switch(BurstRequestSrc) |
4202 | switch (BurstRequestSrc) |
| 3266 | { |
4203 | { |
| 3267 | case TIM_DMA_UPDATE: |
4204 | case TIM_DMA_UPDATE: |
| 3268 | { |
4205 | { |
| 3269 | /* Set the DMA Period elapsed callback */ |
4206 | /* Set the DMA Period elapsed callbacks */ |
| 3270 | htim->hdma[TIM_DMA_ID_UPDATE]->XferCpltCallback = TIM_DMAPeriodElapsedCplt; |
4207 | htim->hdma[TIM_DMA_ID_UPDATE]->XferCpltCallback = TIM_DMAPeriodElapsedCplt; |
| - | 4208 | htim->hdma[TIM_DMA_ID_UPDATE]->XferHalfCpltCallback = TIM_DMAPeriodElapsedHalfCplt; |
|
| 3271 | 4209 | ||
| 3272 | /* Set the DMA error callback */ |
4210 | /* Set the DMA error callback */ |
| 3273 | htim->hdma[TIM_DMA_ID_UPDATE]->XferErrorCallback = TIM_DMAError ; |
4211 | htim->hdma[TIM_DMA_ID_UPDATE]->XferErrorCallback = TIM_DMAError ; |
| 3274 | 4212 | ||
| 3275 | /* Enable the DMA channel */ |
4213 | /* Enable the DMA channel */ |
| 3276 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_UPDATE], (uint32_t)BurstBuffer, (uint32_t)&htim->Instance->DMAR, ((BurstLength) >> 8) + 1); |
4214 | if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_UPDATE], (uint32_t)BurstBuffer, |
| - | 4215 | (uint32_t)&htim->Instance->DMAR, DataLength) != HAL_OK) |
|
| - | 4216 | { |
|
| - | 4217 | return HAL_ERROR; |
|
| - | 4218 | } |
|
| - | 4219 | break; |
|
| 3277 | } |
4220 | } |
| 3278 | break; |
- | |
| 3279 | case TIM_DMA_CC1: |
4221 | case TIM_DMA_CC1: |
| 3280 | { |
4222 | { |
| 3281 | /* Set the DMA Period elapsed callback */ |
4223 | /* Set the DMA compare callbacks */ |
| 3282 | htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMADelayPulseCplt; |
4224 | htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMADelayPulseCplt; |
| - | 4225 | htim->hdma[TIM_DMA_ID_CC1]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt; |
|
| 3283 | 4226 | ||
| 3284 | /* Set the DMA error callback */ |
4227 | /* Set the DMA error callback */ |
| 3285 | htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ; |
4228 | htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ; |
| 3286 | 4229 | ||
| 3287 | /* Enable the DMA channel */ |
4230 | /* Enable the DMA channel */ |
| 3288 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)BurstBuffer, (uint32_t)&htim->Instance->DMAR, ((BurstLength) >> 8) + 1); |
4231 | if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)BurstBuffer, |
| - | 4232 | (uint32_t)&htim->Instance->DMAR, DataLength) != HAL_OK) |
|
| - | 4233 | { |
|
| - | 4234 | return HAL_ERROR; |
|
| - | 4235 | } |
|
| - | 4236 | break; |
|
| 3289 | } |
4237 | } |
| 3290 | break; |
- | |
| 3291 | case TIM_DMA_CC2: |
4238 | case TIM_DMA_CC2: |
| 3292 | { |
4239 | { |
| 3293 | /* Set the DMA Period elapsed callback */ |
4240 | /* Set the DMA compare callbacks */ |
| 3294 | htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMADelayPulseCplt; |
4241 | htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMADelayPulseCplt; |
| - | 4242 | htim->hdma[TIM_DMA_ID_CC2]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt; |
|
| 3295 | 4243 | ||
| 3296 | /* Set the DMA error callback */ |
4244 | /* Set the DMA error callback */ |
| 3297 | htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError ; |
4245 | htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError ; |
| 3298 | 4246 | ||
| 3299 | /* Enable the DMA channel */ |
4247 | /* Enable the DMA channel */ |
| 3300 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)BurstBuffer, (uint32_t)&htim->Instance->DMAR, ((BurstLength) >> 8) + 1); |
4248 | if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)BurstBuffer, |
| - | 4249 | (uint32_t)&htim->Instance->DMAR, DataLength) != HAL_OK) |
|
| - | 4250 | { |
|
| - | 4251 | return HAL_ERROR; |
|
| - | 4252 | } |
|
| - | 4253 | break; |
|
| 3301 | } |
4254 | } |
| 3302 | break; |
- | |
| 3303 | case TIM_DMA_CC3: |
4255 | case TIM_DMA_CC3: |
| 3304 | { |
4256 | { |
| 3305 | /* Set the DMA Period elapsed callback */ |
4257 | /* Set the DMA compare callbacks */ |
| 3306 | htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMADelayPulseCplt; |
4258 | htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMADelayPulseCplt; |
| - | 4259 | htim->hdma[TIM_DMA_ID_CC3]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt; |
|
| 3307 | 4260 | ||
| 3308 | /* Set the DMA error callback */ |
4261 | /* Set the DMA error callback */ |
| 3309 | htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = TIM_DMAError ; |
4262 | htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = TIM_DMAError ; |
| 3310 | 4263 | ||
| 3311 | /* Enable the DMA channel */ |
4264 | /* Enable the DMA channel */ |
| 3312 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)BurstBuffer, (uint32_t)&htim->Instance->DMAR, ((BurstLength) >> 8) + 1); |
4265 | if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)BurstBuffer, |
| - | 4266 | (uint32_t)&htim->Instance->DMAR, DataLength) != HAL_OK) |
|
| - | 4267 | { |
|
| - | 4268 | return HAL_ERROR; |
|
| - | 4269 | } |
|
| - | 4270 | break; |
|
| 3313 | } |
4271 | } |
| 3314 | break; |
- | |
| 3315 | case TIM_DMA_CC4: |
4272 | case TIM_DMA_CC4: |
| 3316 | { |
4273 | { |
| 3317 | /* Set the DMA Period elapsed callback */ |
4274 | /* Set the DMA compare callbacks */ |
| 3318 | htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = TIM_DMADelayPulseCplt; |
4275 | htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = TIM_DMADelayPulseCplt; |
| - | 4276 | htim->hdma[TIM_DMA_ID_CC4]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt; |
|
| 3319 | 4277 | ||
| 3320 | /* Set the DMA error callback */ |
4278 | /* Set the DMA error callback */ |
| 3321 | htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = TIM_DMAError ; |
4279 | htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = TIM_DMAError ; |
| 3322 | 4280 | ||
| 3323 | /* Enable the DMA channel */ |
4281 | /* Enable the DMA channel */ |
| 3324 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)BurstBuffer, (uint32_t)&htim->Instance->DMAR, ((BurstLength) >> 8) + 1); |
4282 | if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)BurstBuffer, |
| - | 4283 | (uint32_t)&htim->Instance->DMAR, DataLength) != HAL_OK) |
|
| - | 4284 | { |
|
| - | 4285 | return HAL_ERROR; |
|
| - | 4286 | } |
|
| - | 4287 | break; |
|
| 3325 | } |
4288 | } |
| 3326 | break; |
- | |
| 3327 | case TIM_DMA_TRIGGER: |
4289 | case TIM_DMA_TRIGGER: |
| 3328 | { |
4290 | { |
| 3329 | /* Set the DMA Period elapsed callback */ |
4291 | /* Set the DMA trigger callbacks */ |
| 3330 | htim->hdma[TIM_DMA_ID_TRIGGER]->XferCpltCallback = TIM_DMATriggerCplt; |
4292 | htim->hdma[TIM_DMA_ID_TRIGGER]->XferCpltCallback = TIM_DMATriggerCplt; |
| - | 4293 | htim->hdma[TIM_DMA_ID_TRIGGER]->XferHalfCpltCallback = TIM_DMATriggerHalfCplt; |
|
| 3331 | 4294 | ||
| 3332 | /* Set the DMA error callback */ |
4295 | /* Set the DMA error callback */ |
| 3333 | htim->hdma[TIM_DMA_ID_TRIGGER]->XferErrorCallback = TIM_DMAError ; |
4296 | htim->hdma[TIM_DMA_ID_TRIGGER]->XferErrorCallback = TIM_DMAError ; |
| 3334 | 4297 | ||
| 3335 | /* Enable the DMA channel */ |
4298 | /* Enable the DMA channel */ |
| 3336 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_TRIGGER], (uint32_t)BurstBuffer, (uint32_t)&htim->Instance->DMAR, ((BurstLength) >> 8) + 1); |
4299 | if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_TRIGGER], (uint32_t)BurstBuffer, |
| - | 4300 | (uint32_t)&htim->Instance->DMAR, DataLength) != HAL_OK) |
|
| - | 4301 | { |
|
| - | 4302 | return HAL_ERROR; |
|
| - | 4303 | } |
|
| - | 4304 | break; |
|
| 3337 | } |
4305 | } |
| 3338 | break; |
- | |
| 3339 | default: |
4306 | default: |
| 3340 | break; |
4307 | break; |
| 3341 | } |
4308 | } |
| 3342 | /* configure the DMA Burst Mode */ |
- | |
| 3343 | htim->Instance->DCR = BurstBaseAddress | BurstLength; |
- | |
| 3344 | 4309 | ||
| - | 4310 | /* Configure the DMA Burst Mode */ |
|
| - | 4311 | htim->Instance->DCR = (BurstBaseAddress | BurstLength); |
|
| 3345 | /* Enable the TIM DMA Request */ |
4312 | /* Enable the TIM DMA Request */ |
| 3346 | __HAL_TIM_ENABLE_DMA(htim, BurstRequestSrc); |
4313 | __HAL_TIM_ENABLE_DMA(htim, BurstRequestSrc); |
| 3347 | - | ||
| 3348 | htim->State = HAL_TIM_STATE_READY; |
- | |
| 3349 | 4314 | ||
| 3350 | /* Return function status */ |
4315 | /* Return function status */ |
| 3351 | return HAL_OK; |
4316 | return HAL_OK; |
| 3352 | } |
4317 | } |
| 3353 | 4318 | ||
| 3354 | /** |
4319 | /** |
| 3355 | * @brief Stops the TIM DMA Burst mode |
4320 | * @brief Stops the TIM DMA Burst mode |
| 3356 | * @param htim: TIM handle |
4321 | * @param htim TIM handle |
| 3357 | * @param BurstRequestSrc: TIM DMA Request sources to disable |
4322 | * @param BurstRequestSrc TIM DMA Request sources to disable |
| 3358 | * @retval HAL status |
4323 | * @retval HAL status |
| 3359 | */ |
4324 | */ |
| 3360 | HAL_StatusTypeDef HAL_TIM_DMABurst_WriteStop(TIM_HandleTypeDef *htim, uint32_t BurstRequestSrc) |
4325 | HAL_StatusTypeDef HAL_TIM_DMABurst_WriteStop(TIM_HandleTypeDef *htim, uint32_t BurstRequestSrc) |
| 3361 | { |
4326 | { |
| - | 4327 | HAL_StatusTypeDef status = HAL_OK; |
|
| 3362 | /* Check the parameters */ |
4328 | /* Check the parameters */ |
| 3363 | assert_param(IS_TIM_DMA_SOURCE(BurstRequestSrc)); |
4329 | assert_param(IS_TIM_DMA_SOURCE(BurstRequestSrc)); |
| 3364 | 4330 | ||
| 3365 | /* Abort the DMA transfer (at least disable the DMA channel) */ |
4331 | /* Abort the DMA transfer (at least disable the DMA channel) */ |
| 3366 | switch(BurstRequestSrc) |
4332 | switch (BurstRequestSrc) |
| 3367 | { |
4333 | { |
| 3368 | case TIM_DMA_UPDATE: |
4334 | case TIM_DMA_UPDATE: |
| 3369 | { |
4335 | { |
| 3370 | HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_UPDATE]); |
4336 | (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_UPDATE]); |
| - | 4337 | break; |
|
| 3371 | } |
4338 | } |
| 3372 | break; |
- | |
| 3373 | case TIM_DMA_CC1: |
4339 | case TIM_DMA_CC1: |
| 3374 | { |
4340 | { |
| 3375 | HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_CC1]); |
4341 | (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC1]); |
| - | 4342 | break; |
|
| 3376 | } |
4343 | } |
| 3377 | break; |
- | |
| 3378 | case TIM_DMA_CC2: |
4344 | case TIM_DMA_CC2: |
| 3379 | { |
4345 | { |
| 3380 | HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_CC2]); |
4346 | (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC2]); |
| - | 4347 | break; |
|
| 3381 | } |
4348 | } |
| 3382 | break; |
- | |
| 3383 | case TIM_DMA_CC3: |
4349 | case TIM_DMA_CC3: |
| 3384 | { |
4350 | { |
| 3385 | HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_CC3]); |
4351 | status = HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC3]); |
| - | 4352 | break; |
|
| 3386 | } |
4353 | } |
| 3387 | break; |
- | |
| 3388 | case TIM_DMA_CC4: |
4354 | case TIM_DMA_CC4: |
| 3389 | { |
4355 | { |
| 3390 | HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_CC4]); |
4356 | (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC4]); |
| - | 4357 | break; |
|
| 3391 | } |
4358 | } |
| 3392 | break; |
- | |
| 3393 | case TIM_DMA_TRIGGER: |
4359 | case TIM_DMA_TRIGGER: |
| 3394 | { |
4360 | { |
| 3395 | HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_TRIGGER]); |
4361 | (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_TRIGGER]); |
| - | 4362 | break; |
|
| 3396 | } |
4363 | } |
| 3397 | break; |
- | |
| 3398 | default: |
4364 | default: |
| 3399 | break; |
4365 | break; |
| 3400 | } |
4366 | } |
| 3401 | 4367 | ||
| - | 4368 | if (HAL_OK == status) |
|
| - | 4369 | { |
|
| 3402 | /* Disable the TIM Update DMA request */ |
4370 | /* Disable the TIM Update DMA request */ |
| 3403 | __HAL_TIM_DISABLE_DMA(htim, BurstRequestSrc); |
4371 | __HAL_TIM_DISABLE_DMA(htim, BurstRequestSrc); |
| - | 4372 | } |
|
| - | 4373 | ||
| - | 4374 | /* Change the DMA burst operation state */ |
|
| - | 4375 | htim->DMABurstState = HAL_DMA_BURST_STATE_READY; |
|
| 3404 | 4376 | ||
| 3405 | /* Return function status */ |
4377 | /* Return function status */ |
| 3406 | return HAL_OK; |
4378 | return status; |
| 3407 | } |
4379 | } |
| 3408 | 4380 | ||
| 3409 | /** |
4381 | /** |
| 3410 | * @brief Configure the DMA Burst to transfer Data from the TIM peripheral to the memory |
4382 | * @brief Configure the DMA Burst to transfer Data from the TIM peripheral to the memory |
| 3411 | * @param htim: TIM handle |
4383 | * @param htim TIM handle |
| 3412 | * @param BurstBaseAddress : TIM Base address from where the DMA will starts the Data read |
4384 | * @param BurstBaseAddress TIM Base address from where the DMA will start the Data read |
| 3413 | * This parameter can be one of the following values: |
4385 | * This parameter can be one of the following values: |
| 3414 | * @arg TIM_DMABASE_CR1 |
4386 | * @arg TIM_DMABASE_CR1 |
| 3415 | * @arg TIM_DMABASE_CR2 |
4387 | * @arg TIM_DMABASE_CR2 |
| 3416 | * @arg TIM_DMABASE_SMCR |
4388 | * @arg TIM_DMABASE_SMCR |
| 3417 | * @arg TIM_DMABASE_DIER |
4389 | * @arg TIM_DMABASE_DIER |
| Line 3425... | Line 4397... | ||
| 3425 | * @arg TIM_DMABASE_ARR |
4397 | * @arg TIM_DMABASE_ARR |
| 3426 | * @arg TIM_DMABASE_CCR1 |
4398 | * @arg TIM_DMABASE_CCR1 |
| 3427 | * @arg TIM_DMABASE_CCR2 |
4399 | * @arg TIM_DMABASE_CCR2 |
| 3428 | * @arg TIM_DMABASE_CCR3 |
4400 | * @arg TIM_DMABASE_CCR3 |
| 3429 | * @arg TIM_DMABASE_CCR4 |
4401 | * @arg TIM_DMABASE_CCR4 |
| 3430 | * @arg TIM_DMABASE_DCR |
4402 | * @arg TIM_DMABASE_OR |
| 3431 | * @param BurstRequestSrc: TIM DMA Request sources |
4403 | * @param BurstRequestSrc TIM DMA Request sources |
| 3432 | * This parameter can be one of the following values: |
4404 | * This parameter can be one of the following values: |
| 3433 | * @arg TIM_DMA_UPDATE: TIM update Interrupt source |
4405 | * @arg TIM_DMA_UPDATE: TIM update Interrupt source |
| 3434 | * @arg TIM_DMA_CC1: TIM Capture Compare 1 DMA source |
4406 | * @arg TIM_DMA_CC1: TIM Capture Compare 1 DMA source |
| 3435 | * @arg TIM_DMA_CC2: TIM Capture Compare 2 DMA source |
4407 | * @arg TIM_DMA_CC2: TIM Capture Compare 2 DMA source |
| 3436 | * @arg TIM_DMA_CC3: TIM Capture Compare 3 DMA source |
4408 | * @arg TIM_DMA_CC3: TIM Capture Compare 3 DMA source |
| 3437 | * @arg TIM_DMA_CC4: TIM Capture Compare 4 DMA source |
4409 | * @arg TIM_DMA_CC4: TIM Capture Compare 4 DMA source |
| 3438 | * @arg TIM_DMA_TRIGGER: TIM Trigger DMA source |
4410 | * @arg TIM_DMA_TRIGGER: TIM Trigger DMA source |
| 3439 | * @param BurstBuffer: The Buffer address. |
4411 | * @param BurstBuffer The Buffer address. |
| 3440 | * @param BurstLength: DMA Burst length. This parameter can be one value |
4412 | * @param BurstLength DMA Burst length. This parameter can be one value |
| 3441 | * between: TIM_DMABURSTLENGTH_1TRANSFER and TIM_DMABURSTLENGTH_18TRANSFERS. |
4413 | * between: TIM_DMABURSTLENGTH_1TRANSFER and TIM_DMABURSTLENGTH_18TRANSFERS. |
| - | 4414 | * @note This function should be used only when BurstLength is equal to DMA data transfer length. |
|
| 3442 | * @retval HAL status |
4415 | * @retval HAL status |
| 3443 | */ |
4416 | */ |
| 3444 | HAL_StatusTypeDef HAL_TIM_DMABurst_ReadStart(TIM_HandleTypeDef *htim, uint32_t BurstBaseAddress, uint32_t BurstRequestSrc, |
4417 | HAL_StatusTypeDef HAL_TIM_DMABurst_ReadStart(TIM_HandleTypeDef *htim, uint32_t BurstBaseAddress, |
| - | 4418 | uint32_t BurstRequestSrc, uint32_t *BurstBuffer, uint32_t BurstLength) |
|
| - | 4419 | { |
|
| - | 4420 | return HAL_TIM_DMABurst_MultiReadStart(htim, BurstBaseAddress, BurstRequestSrc, BurstBuffer, BurstLength, |
|
| - | 4421 | ((BurstLength) >> 8U) + 1U); |
|
| - | 4422 | } |
|
| - | 4423 | ||
| - | 4424 | /** |
|
| - | 4425 | * @brief Configure the DMA Burst to transfer Data from the TIM peripheral to the memory |
|
| - | 4426 | * @param htim TIM handle |
|
| - | 4427 | * @param BurstBaseAddress TIM Base address from where the DMA will start the Data read |
|
| - | 4428 | * This parameter can be one of the following values: |
|
| - | 4429 | * @arg TIM_DMABASE_CR1 |
|
| - | 4430 | * @arg TIM_DMABASE_CR2 |
|
| - | 4431 | * @arg TIM_DMABASE_SMCR |
|
| - | 4432 | * @arg TIM_DMABASE_DIER |
|
| - | 4433 | * @arg TIM_DMABASE_SR |
|
| - | 4434 | * @arg TIM_DMABASE_EGR |
|
| - | 4435 | * @arg TIM_DMABASE_CCMR1 |
|
| - | 4436 | * @arg TIM_DMABASE_CCMR2 |
|
| - | 4437 | * @arg TIM_DMABASE_CCER |
|
| - | 4438 | * @arg TIM_DMABASE_CNT |
|
| - | 4439 | * @arg TIM_DMABASE_PSC |
|
| - | 4440 | * @arg TIM_DMABASE_ARR |
|
| - | 4441 | * @arg TIM_DMABASE_CCR1 |
|
| - | 4442 | * @arg TIM_DMABASE_CCR2 |
|
| - | 4443 | * @arg TIM_DMABASE_CCR3 |
|
| - | 4444 | * @arg TIM_DMABASE_CCR4 |
|
| - | 4445 | * @arg TIM_DMABASE_OR |
|
| - | 4446 | * @param BurstRequestSrc TIM DMA Request sources |
|
| - | 4447 | * This parameter can be one of the following values: |
|
| - | 4448 | * @arg TIM_DMA_UPDATE: TIM update Interrupt source |
|
| - | 4449 | * @arg TIM_DMA_CC1: TIM Capture Compare 1 DMA source |
|
| - | 4450 | * @arg TIM_DMA_CC2: TIM Capture Compare 2 DMA source |
|
| - | 4451 | * @arg TIM_DMA_CC3: TIM Capture Compare 3 DMA source |
|
| - | 4452 | * @arg TIM_DMA_CC4: TIM Capture Compare 4 DMA source |
|
| - | 4453 | * @arg TIM_DMA_TRIGGER: TIM Trigger DMA source |
|
| - | 4454 | * @param BurstBuffer The Buffer address. |
|
| - | 4455 | * @param BurstLength DMA Burst length. This parameter can be one value |
|
| - | 4456 | * between: TIM_DMABURSTLENGTH_1TRANSFER and TIM_DMABURSTLENGTH_18TRANSFERS. |
|
| - | 4457 | * @param DataLength Data length. This parameter can be one value |
|
| - | 4458 | * between 1 and 0xFFFF. |
|
| - | 4459 | * @retval HAL status |
|
| - | 4460 | */ |
|
| - | 4461 | HAL_StatusTypeDef HAL_TIM_DMABurst_MultiReadStart(TIM_HandleTypeDef *htim, uint32_t BurstBaseAddress, |
|
| - | 4462 | uint32_t BurstRequestSrc, uint32_t *BurstBuffer, |
|
| 3445 | uint32_t *BurstBuffer, uint32_t BurstLength) |
4463 | uint32_t BurstLength, uint32_t DataLength) |
| 3446 | { |
4464 | { |
| 3447 | /* Check the parameters */ |
4465 | /* Check the parameters */ |
| 3448 | assert_param(IS_TIM_DMABURST_INSTANCE(htim->Instance)); |
4466 | assert_param(IS_TIM_DMABURST_INSTANCE(htim->Instance)); |
| 3449 | assert_param(IS_TIM_DMA_BASE(BurstBaseAddress)); |
4467 | assert_param(IS_TIM_DMA_BASE(BurstBaseAddress)); |
| 3450 | assert_param(IS_TIM_DMA_SOURCE(BurstRequestSrc)); |
4468 | assert_param(IS_TIM_DMA_SOURCE(BurstRequestSrc)); |
| 3451 | assert_param(IS_TIM_DMA_LENGTH(BurstLength)); |
4469 | assert_param(IS_TIM_DMA_LENGTH(BurstLength)); |
| - | 4470 | assert_param(IS_TIM_DMA_DATA_LENGTH(DataLength)); |
|
| 3452 | 4471 | ||
| 3453 | if((htim->State == HAL_TIM_STATE_BUSY)) |
4472 | if (htim->DMABurstState == HAL_DMA_BURST_STATE_BUSY) |
| 3454 | { |
4473 | { |
| 3455 | return HAL_BUSY; |
4474 | return HAL_BUSY; |
| 3456 | } |
4475 | } |
| 3457 | else if((htim->State == HAL_TIM_STATE_READY)) |
4476 | else if (htim->DMABurstState == HAL_DMA_BURST_STATE_READY) |
| 3458 | { |
4477 | { |
| 3459 | if((BurstBuffer == 0 ) && (BurstLength > 0)) |
4478 | if ((BurstBuffer == NULL) && (BurstLength > 0U)) |
| 3460 | { |
4479 | { |
| 3461 | return HAL_ERROR; |
4480 | return HAL_ERROR; |
| 3462 | } |
4481 | } |
| 3463 | else |
4482 | else |
| 3464 | { |
4483 | { |
| 3465 | htim->State = HAL_TIM_STATE_BUSY; |
4484 | htim->DMABurstState = HAL_DMA_BURST_STATE_BUSY; |
| 3466 | } |
4485 | } |
| 3467 | } |
4486 | } |
| 3468 | else |
4487 | else |
| 3469 | { |
4488 | { |
| 3470 | return HAL_ERROR; |
4489 | /* nothing to do */ |
| 3471 | } |
4490 | } |
| 3472 | - | ||
| 3473 | switch(BurstRequestSrc) |
4491 | switch (BurstRequestSrc) |
| 3474 | { |
4492 | { |
| 3475 | case TIM_DMA_UPDATE: |
4493 | case TIM_DMA_UPDATE: |
| 3476 | { |
4494 | { |
| 3477 | /* Set the DMA Period elapsed callback */ |
4495 | /* Set the DMA Period elapsed callbacks */ |
| 3478 | htim->hdma[TIM_DMA_ID_UPDATE]->XferCpltCallback = TIM_DMAPeriodElapsedCplt; |
4496 | htim->hdma[TIM_DMA_ID_UPDATE]->XferCpltCallback = TIM_DMAPeriodElapsedCplt; |
| - | 4497 | htim->hdma[TIM_DMA_ID_UPDATE]->XferHalfCpltCallback = TIM_DMAPeriodElapsedHalfCplt; |
|
| 3479 | 4498 | ||
| 3480 | /* Set the DMA error callback */ |
4499 | /* Set the DMA error callback */ |
| 3481 | htim->hdma[TIM_DMA_ID_UPDATE]->XferErrorCallback = TIM_DMAError ; |
4500 | htim->hdma[TIM_DMA_ID_UPDATE]->XferErrorCallback = TIM_DMAError ; |
| 3482 | 4501 | ||
| 3483 | /* Enable the DMA channel */ |
4502 | /* Enable the DMA channel */ |
| 3484 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_UPDATE], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, ((BurstLength) >> 8) + 1); |
4503 | if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_UPDATE], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, |
| - | 4504 | DataLength) != HAL_OK) |
|
| - | 4505 | { |
|
| - | 4506 | return HAL_ERROR; |
|
| - | 4507 | } |
|
| - | 4508 | break; |
|
| 3485 | } |
4509 | } |
| 3486 | break; |
- | |
| 3487 | case TIM_DMA_CC1: |
4510 | case TIM_DMA_CC1: |
| 3488 | { |
4511 | { |
| 3489 | /* Set the DMA Period elapsed callback */ |
4512 | /* Set the DMA capture callbacks */ |
| 3490 | htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMACaptureCplt; |
4513 | htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMACaptureCplt; |
| - | 4514 | htim->hdma[TIM_DMA_ID_CC1]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt; |
|
| 3491 | 4515 | ||
| 3492 | /* Set the DMA error callback */ |
4516 | /* Set the DMA error callback */ |
| 3493 | htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ; |
4517 | htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ; |
| 3494 | 4518 | ||
| 3495 | /* Enable the DMA channel */ |
4519 | /* Enable the DMA channel */ |
| 3496 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, ((BurstLength) >> 8) + 1); |
4520 | if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, |
| - | 4521 | DataLength) != HAL_OK) |
|
| - | 4522 | { |
|
| - | 4523 | return HAL_ERROR; |
|
| - | 4524 | } |
|
| - | 4525 | break; |
|
| 3497 | } |
4526 | } |
| 3498 | break; |
- | |
| 3499 | case TIM_DMA_CC2: |
4527 | case TIM_DMA_CC2: |
| 3500 | { |
4528 | { |
| 3501 | /* Set the DMA Period elapsed callback */ |
4529 | /* Set the DMA capture callbacks */ |
| 3502 | htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMACaptureCplt; |
4530 | htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMACaptureCplt; |
| - | 4531 | htim->hdma[TIM_DMA_ID_CC2]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt; |
|
| 3503 | 4532 | ||
| 3504 | /* Set the DMA error callback */ |
4533 | /* Set the DMA error callback */ |
| 3505 | htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError ; |
4534 | htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError ; |
| 3506 | 4535 | ||
| 3507 | /* Enable the DMA channel */ |
4536 | /* Enable the DMA channel */ |
| 3508 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, ((BurstLength) >> 8) + 1); |
4537 | if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, |
| - | 4538 | DataLength) != HAL_OK) |
|
| - | 4539 | { |
|
| - | 4540 | return HAL_ERROR; |
|
| - | 4541 | } |
|
| - | 4542 | break; |
|
| 3509 | } |
4543 | } |
| 3510 | break; |
- | |
| 3511 | case TIM_DMA_CC3: |
4544 | case TIM_DMA_CC3: |
| 3512 | { |
4545 | { |
| 3513 | /* Set the DMA Period elapsed callback */ |
4546 | /* Set the DMA capture callbacks */ |
| 3514 | htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMACaptureCplt; |
4547 | htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMACaptureCplt; |
| - | 4548 | htim->hdma[TIM_DMA_ID_CC3]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt; |
|
| 3515 | 4549 | ||
| 3516 | /* Set the DMA error callback */ |
4550 | /* Set the DMA error callback */ |
| 3517 | htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = TIM_DMAError ; |
4551 | htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = TIM_DMAError ; |
| 3518 | 4552 | ||
| 3519 | /* Enable the DMA channel */ |
4553 | /* Enable the DMA channel */ |
| 3520 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, ((BurstLength) >> 8) + 1); |
4554 | if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, |
| - | 4555 | DataLength) != HAL_OK) |
|
| - | 4556 | { |
|
| - | 4557 | return HAL_ERROR; |
|
| - | 4558 | } |
|
| - | 4559 | break; |
|
| 3521 | } |
4560 | } |
| 3522 | break; |
- | |
| 3523 | case TIM_DMA_CC4: |
4561 | case TIM_DMA_CC4: |
| 3524 | { |
4562 | { |
| 3525 | /* Set the DMA Period elapsed callback */ |
4563 | /* Set the DMA capture callbacks */ |
| 3526 | htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = TIM_DMACaptureCplt; |
4564 | htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = TIM_DMACaptureCplt; |
| - | 4565 | htim->hdma[TIM_DMA_ID_CC4]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt; |
|
| 3527 | 4566 | ||
| 3528 | /* Set the DMA error callback */ |
4567 | /* Set the DMA error callback */ |
| 3529 | htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = TIM_DMAError ; |
4568 | htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = TIM_DMAError ; |
| 3530 | 4569 | ||
| 3531 | /* Enable the DMA channel */ |
4570 | /* Enable the DMA channel */ |
| 3532 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, ((BurstLength) >> 8) + 1); |
4571 | if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, |
| - | 4572 | DataLength) != HAL_OK) |
|
| - | 4573 | { |
|
| - | 4574 | return HAL_ERROR; |
|
| - | 4575 | } |
|
| - | 4576 | break; |
|
| 3533 | } |
4577 | } |
| 3534 | break; |
- | |
| 3535 | case TIM_DMA_TRIGGER: |
4578 | case TIM_DMA_TRIGGER: |
| 3536 | { |
4579 | { |
| 3537 | /* Set the DMA Period elapsed callback */ |
4580 | /* Set the DMA trigger callbacks */ |
| 3538 | htim->hdma[TIM_DMA_ID_TRIGGER]->XferCpltCallback = TIM_DMATriggerCplt; |
4581 | htim->hdma[TIM_DMA_ID_TRIGGER]->XferCpltCallback = TIM_DMATriggerCplt; |
| - | 4582 | htim->hdma[TIM_DMA_ID_TRIGGER]->XferHalfCpltCallback = TIM_DMATriggerHalfCplt; |
|
| 3539 | 4583 | ||
| 3540 | /* Set the DMA error callback */ |
4584 | /* Set the DMA error callback */ |
| 3541 | htim->hdma[TIM_DMA_ID_TRIGGER]->XferErrorCallback = TIM_DMAError ; |
4585 | htim->hdma[TIM_DMA_ID_TRIGGER]->XferErrorCallback = TIM_DMAError ; |
| 3542 | 4586 | ||
| 3543 | /* Enable the DMA channel */ |
4587 | /* Enable the DMA channel */ |
| 3544 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_TRIGGER], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, ((BurstLength) >> 8) + 1); |
4588 | if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_TRIGGER], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, |
| - | 4589 | DataLength) != HAL_OK) |
|
| - | 4590 | { |
|
| - | 4591 | return HAL_ERROR; |
|
| - | 4592 | } |
|
| - | 4593 | break; |
|
| 3545 | } |
4594 | } |
| 3546 | break; |
- | |
| 3547 | default: |
4595 | default: |
| 3548 | break; |
4596 | break; |
| 3549 | } |
4597 | } |
| 3550 | 4598 | ||
| 3551 | /* configure the DMA Burst Mode */ |
4599 | /* Configure the DMA Burst Mode */ |
| 3552 | htim->Instance->DCR = BurstBaseAddress | BurstLength; |
4600 | htim->Instance->DCR = (BurstBaseAddress | BurstLength); |
| 3553 | 4601 | ||
| 3554 | /* Enable the TIM DMA Request */ |
4602 | /* Enable the TIM DMA Request */ |
| 3555 | __HAL_TIM_ENABLE_DMA(htim, BurstRequestSrc); |
4603 | __HAL_TIM_ENABLE_DMA(htim, BurstRequestSrc); |
| 3556 | 4604 | ||
| 3557 | htim->State = HAL_TIM_STATE_READY; |
- | |
| 3558 | - | ||
| 3559 | /* Return function status */ |
4605 | /* Return function status */ |
| 3560 | return HAL_OK; |
4606 | return HAL_OK; |
| 3561 | } |
4607 | } |
| 3562 | 4608 | ||
| 3563 | /** |
4609 | /** |
| 3564 | * @brief Stop the DMA burst reading |
4610 | * @brief Stop the DMA burst reading |
| 3565 | * @param htim: TIM handle |
4611 | * @param htim TIM handle |
| 3566 | * @param BurstRequestSrc: TIM DMA Request sources to disable. |
4612 | * @param BurstRequestSrc TIM DMA Request sources to disable. |
| 3567 | * @retval HAL status |
4613 | * @retval HAL status |
| 3568 | */ |
4614 | */ |
| 3569 | HAL_StatusTypeDef HAL_TIM_DMABurst_ReadStop(TIM_HandleTypeDef *htim, uint32_t BurstRequestSrc) |
4615 | HAL_StatusTypeDef HAL_TIM_DMABurst_ReadStop(TIM_HandleTypeDef *htim, uint32_t BurstRequestSrc) |
| 3570 | { |
4616 | { |
| - | 4617 | HAL_StatusTypeDef status = HAL_OK; |
|
| 3571 | /* Check the parameters */ |
4618 | /* Check the parameters */ |
| 3572 | assert_param(IS_TIM_DMA_SOURCE(BurstRequestSrc)); |
4619 | assert_param(IS_TIM_DMA_SOURCE(BurstRequestSrc)); |
| 3573 | 4620 | ||
| 3574 | /* Abort the DMA transfer (at least disable the DMA channel) */ |
4621 | /* Abort the DMA transfer (at least disable the DMA channel) */ |
| 3575 | switch(BurstRequestSrc) |
4622 | switch (BurstRequestSrc) |
| 3576 | { |
4623 | { |
| 3577 | case TIM_DMA_UPDATE: |
4624 | case TIM_DMA_UPDATE: |
| 3578 | { |
4625 | { |
| 3579 | HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_UPDATE]); |
4626 | (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_UPDATE]); |
| - | 4627 | break; |
|
| 3580 | } |
4628 | } |
| 3581 | break; |
- | |
| 3582 | case TIM_DMA_CC1: |
4629 | case TIM_DMA_CC1: |
| 3583 | { |
4630 | { |
| 3584 | HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_CC1]); |
4631 | (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC1]); |
| - | 4632 | break; |
|
| 3585 | } |
4633 | } |
| 3586 | break; |
- | |
| 3587 | case TIM_DMA_CC2: |
4634 | case TIM_DMA_CC2: |
| 3588 | { |
4635 | { |
| 3589 | HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_CC2]); |
4636 | (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC2]); |
| - | 4637 | break; |
|
| 3590 | } |
4638 | } |
| 3591 | break; |
- | |
| 3592 | case TIM_DMA_CC3: |
4639 | case TIM_DMA_CC3: |
| 3593 | { |
4640 | { |
| 3594 | HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_CC3]); |
4641 | (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC3]); |
| - | 4642 | break; |
|
| 3595 | } |
4643 | } |
| 3596 | break; |
- | |
| 3597 | case TIM_DMA_CC4: |
4644 | case TIM_DMA_CC4: |
| 3598 | { |
4645 | { |
| 3599 | HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_CC4]); |
4646 | (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC4]); |
| - | 4647 | break; |
|
| 3600 | } |
4648 | } |
| 3601 | break; |
- | |
| 3602 | case TIM_DMA_TRIGGER: |
4649 | case TIM_DMA_TRIGGER: |
| 3603 | { |
4650 | { |
| 3604 | HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_TRIGGER]); |
4651 | (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_TRIGGER]); |
| - | 4652 | break; |
|
| 3605 | } |
4653 | } |
| 3606 | break; |
- | |
| 3607 | default: |
4654 | default: |
| 3608 | break; |
4655 | break; |
| 3609 | } |
4656 | } |
| 3610 | 4657 | ||
| - | 4658 | if (HAL_OK == status) |
|
| - | 4659 | { |
|
| 3611 | /* Disable the TIM Update DMA request */ |
4660 | /* Disable the TIM Update DMA request */ |
| 3612 | __HAL_TIM_DISABLE_DMA(htim, BurstRequestSrc); |
4661 | __HAL_TIM_DISABLE_DMA(htim, BurstRequestSrc); |
| - | 4662 | } |
|
| - | 4663 | ||
| - | 4664 | /* Change the DMA burst operation state */ |
|
| - | 4665 | htim->DMABurstState = HAL_DMA_BURST_STATE_READY; |
|
| 3613 | 4666 | ||
| 3614 | /* Return function status */ |
4667 | /* Return function status */ |
| 3615 | return HAL_OK; |
4668 | return status; |
| 3616 | } |
4669 | } |
| 3617 | 4670 | ||
| 3618 | /** |
4671 | /** |
| 3619 | * @brief Generate a software event |
4672 | * @brief Generate a software event |
| 3620 | * @param htim: TIM handle |
4673 | * @param htim TIM handle |
| 3621 | * @param EventSource: specifies the event source. |
4674 | * @param EventSource specifies the event source. |
| 3622 | * This parameter can be one of the following values: |
4675 | * This parameter can be one of the following values: |
| 3623 | * @arg TIM_EVENTSOURCE_UPDATE: Timer update Event source |
4676 | * @arg TIM_EVENTSOURCE_UPDATE: Timer update Event source |
| 3624 | * @arg TIM_EVENTSOURCE_CC1: Timer Capture Compare 1 Event source |
4677 | * @arg TIM_EVENTSOURCE_CC1: Timer Capture Compare 1 Event source |
| 3625 | * @arg TIM_EVENTSOURCE_CC2: Timer Capture Compare 2 Event source |
4678 | * @arg TIM_EVENTSOURCE_CC2: Timer Capture Compare 2 Event source |
| 3626 | * @arg TIM_EVENTSOURCE_CC3: Timer Capture Compare 3 Event source |
4679 | * @arg TIM_EVENTSOURCE_CC3: Timer Capture Compare 3 Event source |
| 3627 | * @arg TIM_EVENTSOURCE_CC4: Timer Capture Compare 4 Event source |
4680 | * @arg TIM_EVENTSOURCE_CC4: Timer Capture Compare 4 Event source |
| 3628 | * @arg TIM_EVENTSOURCE_TRIGGER: Timer Trigger Event source |
4681 | * @arg TIM_EVENTSOURCE_TRIGGER: Timer Trigger Event source |
| 3629 | * @note TIM6 and TIM7 can only generate an update event. |
4682 | * @note Basic timers can only generate an update event. |
| 3630 | * @retval HAL status |
4683 | * @retval HAL status |
| 3631 | */ |
4684 | */ |
| 3632 | 4685 | ||
| 3633 | HAL_StatusTypeDef HAL_TIM_GenerateEvent(TIM_HandleTypeDef *htim, uint32_t EventSource) |
4686 | HAL_StatusTypeDef HAL_TIM_GenerateEvent(TIM_HandleTypeDef *htim, uint32_t EventSource) |
| 3634 | { |
4687 | { |
| Line 3654... | Line 4707... | ||
| 3654 | return HAL_OK; |
4707 | return HAL_OK; |
| 3655 | } |
4708 | } |
| 3656 | 4709 | ||
| 3657 | /** |
4710 | /** |
| 3658 | * @brief Configures the OCRef clear feature |
4711 | * @brief Configures the OCRef clear feature |
| 3659 | * @param htim: TIM handle |
4712 | * @param htim TIM handle |
| 3660 | * @param sClearInputConfig: pointer to a TIM_ClearInputConfigTypeDef structure that |
4713 | * @param sClearInputConfig pointer to a TIM_ClearInputConfigTypeDef structure that |
| 3661 | * contains the OCREF clear feature and parameters for the TIM peripheral. |
4714 | * contains the OCREF clear feature and parameters for the TIM peripheral. |
| 3662 | * @param Channel: specifies the TIM Channel |
4715 | * @param Channel specifies the TIM Channel |
| 3663 | * This parameter can be one of the following values: |
4716 | * This parameter can be one of the following values: |
| 3664 | * @arg TIM_CHANNEL_1: TIM Channel 1 |
4717 | * @arg TIM_CHANNEL_1: TIM Channel 1 |
| 3665 | * @arg TIM_CHANNEL_2: TIM Channel 2 |
4718 | * @arg TIM_CHANNEL_2: TIM Channel 2 |
| 3666 | * @arg TIM_CHANNEL_3: TIM Channel 3 |
4719 | * @arg TIM_CHANNEL_3: TIM Channel 3 |
| 3667 | * @arg TIM_CHANNEL_4: TIM Channel 4 |
4720 | * @arg TIM_CHANNEL_4: TIM Channel 4 |
| 3668 | * @retval HAL status |
4721 | * @retval HAL status |
| 3669 | */ |
4722 | */ |
| 3670 | HAL_StatusTypeDef HAL_TIM_ConfigOCrefClear(TIM_HandleTypeDef *htim, TIM_ClearInputConfigTypeDef * sClearInputConfig, uint32_t Channel) |
4723 | HAL_StatusTypeDef HAL_TIM_ConfigOCrefClear(TIM_HandleTypeDef *htim, |
| - | 4724 | TIM_ClearInputConfigTypeDef *sClearInputConfig, |
|
| - | 4725 | uint32_t Channel) |
|
| 3671 | { |
4726 | { |
| 3672 | - | ||
| 3673 | /* Check the parameters */ |
4727 | /* Check the parameters */ |
| 3674 | assert_param(IS_TIM_OCXREF_CLEAR_INSTANCE(htim->Instance)); |
4728 | assert_param(IS_TIM_OCXREF_CLEAR_INSTANCE(htim->Instance)); |
| 3675 | assert_param(IS_TIM_CLEARINPUT_SOURCE(sClearInputConfig->ClearInputSource)); |
4729 | assert_param(IS_TIM_CLEARINPUT_SOURCE(sClearInputConfig->ClearInputSource)); |
| 3676 | assert_param(IS_TIM_CLEARINPUT_POLARITY(sClearInputConfig->ClearInputPolarity)); |
- | |
| 3677 | assert_param(IS_TIM_CLEARINPUT_PRESCALER(sClearInputConfig->ClearInputPrescaler)); |
- | |
| 3678 | assert_param(IS_TIM_CLEARINPUT_FILTER(sClearInputConfig->ClearInputFilter)); |
- | |
| 3679 | 4730 | ||
| 3680 | /* Process Locked */ |
4731 | /* Process Locked */ |
| 3681 | __HAL_LOCK(htim); |
4732 | __HAL_LOCK(htim); |
| 3682 | 4733 | ||
| 3683 | htim->State = HAL_TIM_STATE_BUSY; |
4734 | htim->State = HAL_TIM_STATE_BUSY; |
| 3684 | 4735 | ||
| 3685 | switch (sClearInputConfig->ClearInputSource) |
4736 | switch (sClearInputConfig->ClearInputSource) |
| 3686 | { |
4737 | { |
| 3687 | case TIM_CLEARINPUTSOURCE_NONE: |
4738 | case TIM_CLEARINPUTSOURCE_NONE: |
| 3688 | { |
4739 | { |
| 3689 | /* Clear the OCREF clear selection bit */ |
4740 | /* Clear the OCREF clear selection bit and the the ETR Bits */ |
| 3690 | CLEAR_BIT(htim->Instance->SMCR, TIM_SMCR_OCCS); |
- | |
| 3691 | - | ||
| 3692 | /* Clear the ETR Bits */ |
- | |
| 3693 | CLEAR_BIT(htim->Instance->SMCR, (TIM_SMCR_ETF | TIM_SMCR_ETPS | TIM_SMCR_ECE | TIM_SMCR_ETP)); |
4741 | CLEAR_BIT(htim->Instance->SMCR, (TIM_SMCR_OCCS | TIM_SMCR_ETF | TIM_SMCR_ETPS | TIM_SMCR_ECE | TIM_SMCR_ETP)); |
| 3694 | 4742 | break; |
|
| 3695 | } |
4743 | } |
| 3696 | break; |
- | |
| 3697 | - | ||
| 3698 | case TIM_CLEARINPUTSOURCE_OCREFCLR: |
4744 | case TIM_CLEARINPUTSOURCE_OCREFCLR: |
| 3699 | { |
4745 | { |
| 3700 | /* Clear the OCREF clear selection bit */ |
4746 | /* Clear the OCREF clear selection bit */ |
| 3701 | CLEAR_BIT(htim->Instance->SMCR, TIM_SMCR_OCCS); |
4747 | CLEAR_BIT(htim->Instance->SMCR, TIM_SMCR_OCCS); |
| 3702 | } |
4748 | } |
| 3703 | break; |
4749 | break; |
| 3704 | 4750 | ||
| 3705 | case TIM_CLEARINPUTSOURCE_ETR: |
4751 | case TIM_CLEARINPUTSOURCE_ETR: |
| 3706 | { |
4752 | { |
| - | 4753 | /* Check the parameters */ |
|
| - | 4754 | assert_param(IS_TIM_CLEARINPUT_POLARITY(sClearInputConfig->ClearInputPolarity)); |
|
| - | 4755 | assert_param(IS_TIM_CLEARINPUT_PRESCALER(sClearInputConfig->ClearInputPrescaler)); |
|
| - | 4756 | assert_param(IS_TIM_CLEARINPUT_FILTER(sClearInputConfig->ClearInputFilter)); |
|
| - | 4757 | ||
| - | 4758 | /* When OCRef clear feature is used with ETR source, ETR prescaler must be off */ |
|
| - | 4759 | if (sClearInputConfig->ClearInputPrescaler != TIM_CLEARINPUTPRESCALER_DIV1) |
|
| - | 4760 | { |
|
| - | 4761 | htim->State = HAL_TIM_STATE_READY; |
|
| - | 4762 | __HAL_UNLOCK(htim); |
|
| - | 4763 | return HAL_ERROR; |
|
| - | 4764 | } |
|
| - | 4765 | ||
| 3707 | TIM_ETR_SetConfig(htim->Instance, |
4766 | TIM_ETR_SetConfig(htim->Instance, |
| 3708 | sClearInputConfig->ClearInputPrescaler, |
4767 | sClearInputConfig->ClearInputPrescaler, |
| 3709 | sClearInputConfig->ClearInputPolarity, |
4768 | sClearInputConfig->ClearInputPolarity, |
| 3710 | sClearInputConfig->ClearInputFilter); |
4769 | sClearInputConfig->ClearInputFilter); |
| 3711 | 4770 | ||
| 3712 | /* Set the OCREF clear selection bit */ |
4771 | /* Set the OCREF clear selection bit */ |
| 3713 | SET_BIT(htim->Instance->SMCR, TIM_SMCR_OCCS); |
4772 | SET_BIT(htim->Instance->SMCR, TIM_SMCR_OCCS); |
| - | 4773 | break; |
|
| 3714 | } |
4774 | } |
| 3715 | break; |
- | |
| 3716 | - | ||
| 3717 | default: |
- | |
| 3718 | break; |
- | |
| 3719 | 4775 | ||
| - | 4776 | default: |
|
| - | 4777 | break; |
|
| 3720 | } |
4778 | } |
| 3721 | 4779 | ||
| 3722 | switch (Channel) |
4780 | switch (Channel) |
| 3723 | { |
4781 | { |
| 3724 | case TIM_CHANNEL_1: |
4782 | case TIM_CHANNEL_1: |
| - | 4783 | { |
|
| - | 4784 | if (sClearInputConfig->ClearInputState != (uint32_t)DISABLE) |
|
| 3725 | { |
4785 | { |
| 3726 | if(sClearInputConfig->ClearInputState != RESET) |
- | |
| 3727 | { |
- | |
| 3728 | /* Enable the Ocref clear feature for Channel 1 */ |
4786 | /* Enable the OCREF clear feature for Channel 1 */ |
| 3729 | htim->Instance->CCMR1 |= TIM_CCMR1_OC1CE; |
4787 | SET_BIT(htim->Instance->CCMR1, TIM_CCMR1_OC1CE); |
| 3730 | } |
4788 | } |
| 3731 | else |
4789 | else |
| 3732 | { |
4790 | { |
| 3733 | /* Disable the Ocref clear feature for Channel 1 */ |
4791 | /* Disable the OCREF clear feature for Channel 1 */ |
| 3734 | htim->Instance->CCMR1 &= ~TIM_CCMR1_OC1CE; |
4792 | CLEAR_BIT(htim->Instance->CCMR1, TIM_CCMR1_OC1CE); |
| 3735 | } |
- | |
| 3736 | } |
4793 | } |
| 3737 | break; |
4794 | break; |
| - | 4795 | } |
|
| 3738 | case TIM_CHANNEL_2: |
4796 | case TIM_CHANNEL_2: |
| - | 4797 | { |
|
| - | 4798 | if (sClearInputConfig->ClearInputState != (uint32_t)DISABLE) |
|
| 3739 | { |
4799 | { |
| 3740 | assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); |
- | |
| 3741 | if(sClearInputConfig->ClearInputState != RESET) |
- | |
| 3742 | { |
- | |
| 3743 | /* Enable the Ocref clear feature for Channel 2 */ |
4800 | /* Enable the OCREF clear feature for Channel 2 */ |
| 3744 | htim->Instance->CCMR1 |= TIM_CCMR1_OC2CE; |
4801 | SET_BIT(htim->Instance->CCMR1, TIM_CCMR1_OC2CE); |
| 3745 | } |
- | |
| 3746 | else |
- | |
| 3747 | { |
- | |
| 3748 | /* Disable the Ocref clear feature for Channel 2 */ |
- | |
| 3749 | htim->Instance->CCMR1 &= ~TIM_CCMR1_OC2CE; |
- | |
| 3750 | } |
- | |
| 3751 | } |
4802 | } |
| - | 4803 | else |
|
| - | 4804 | { |
|
| - | 4805 | /* Disable the OCREF clear feature for Channel 2 */ |
|
| - | 4806 | CLEAR_BIT(htim->Instance->CCMR1, TIM_CCMR1_OC2CE); |
|
| - | 4807 | } |
|
| 3752 | break; |
4808 | break; |
| - | 4809 | } |
|
| 3753 | case TIM_CHANNEL_3: |
4810 | case TIM_CHANNEL_3: |
| - | 4811 | { |
|
| - | 4812 | if (sClearInputConfig->ClearInputState != (uint32_t)DISABLE) |
|
| 3754 | { |
4813 | { |
| 3755 | assert_param(IS_TIM_CC3_INSTANCE(htim->Instance)); |
- | |
| 3756 | if(sClearInputConfig->ClearInputState != RESET) |
- | |
| 3757 | { |
- | |
| 3758 | /* Enable the Ocref clear feature for Channel 3 */ |
4814 | /* Enable the OCREF clear feature for Channel 3 */ |
| 3759 | htim->Instance->CCMR2 |= TIM_CCMR2_OC3CE; |
4815 | SET_BIT(htim->Instance->CCMR2, TIM_CCMR2_OC3CE); |
| 3760 | } |
- | |
| 3761 | else |
- | |
| 3762 | { |
- | |
| 3763 | /* Disable the Ocref clear feature for Channel 3 */ |
- | |
| 3764 | htim->Instance->CCMR2 &= ~TIM_CCMR2_OC3CE; |
- | |
| 3765 | } |
- | |
| 3766 | } |
4816 | } |
| - | 4817 | else |
|
| - | 4818 | { |
|
| - | 4819 | /* Disable the OCREF clear feature for Channel 3 */ |
|
| - | 4820 | CLEAR_BIT(htim->Instance->CCMR2, TIM_CCMR2_OC3CE); |
|
| - | 4821 | } |
|
| 3767 | break; |
4822 | break; |
| - | 4823 | } |
|
| 3768 | case TIM_CHANNEL_4: |
4824 | case TIM_CHANNEL_4: |
| - | 4825 | { |
|
| - | 4826 | if (sClearInputConfig->ClearInputState != (uint32_t)DISABLE) |
|
| 3769 | { |
4827 | { |
| 3770 | assert_param(IS_TIM_CC4_INSTANCE(htim->Instance)); |
- | |
| 3771 | if(sClearInputConfig->ClearInputState != RESET) |
- | |
| 3772 | { |
- | |
| 3773 | /* Enable the Ocref clear feature for Channel 4 */ |
4828 | /* Enable the OCREF clear feature for Channel 4 */ |
| 3774 | htim->Instance->CCMR2 |= TIM_CCMR2_OC4CE; |
4829 | SET_BIT(htim->Instance->CCMR2, TIM_CCMR2_OC4CE); |
| 3775 | } |
- | |
| 3776 | else |
- | |
| 3777 | { |
- | |
| 3778 | /* Disable the Ocref clear feature for Channel 4 */ |
- | |
| 3779 | htim->Instance->CCMR2 &= ~TIM_CCMR2_OC4CE; |
- | |
| 3780 | } |
- | |
| 3781 | } |
4830 | } |
| - | 4831 | else |
|
| - | 4832 | { |
|
| - | 4833 | /* Disable the OCREF clear feature for Channel 4 */ |
|
| - | 4834 | CLEAR_BIT(htim->Instance->CCMR2, TIM_CCMR2_OC4CE); |
|
| - | 4835 | } |
|
| 3782 | break; |
4836 | break; |
| - | 4837 | } |
|
| 3783 | default: |
4838 | default: |
| 3784 | break; |
4839 | break; |
| 3785 | } |
4840 | } |
| 3786 | 4841 | ||
| 3787 | htim->State = HAL_TIM_STATE_READY; |
4842 | htim->State = HAL_TIM_STATE_READY; |
| 3788 | 4843 | ||
| 3789 | __HAL_UNLOCK(htim); |
4844 | __HAL_UNLOCK(htim); |
| Line 3791... | Line 4846... | ||
| 3791 | return HAL_OK; |
4846 | return HAL_OK; |
| 3792 | } |
4847 | } |
| 3793 | 4848 | ||
| 3794 | /** |
4849 | /** |
| 3795 | * @brief Configures the clock source to be used |
4850 | * @brief Configures the clock source to be used |
| 3796 | * @param htim: TIM handle |
4851 | * @param htim TIM handle |
| 3797 | * @param sClockSourceConfig: pointer to a TIM_ClockConfigTypeDef structure that |
4852 | * @param sClockSourceConfig pointer to a TIM_ClockConfigTypeDef structure that |
| 3798 | * contains the clock source information for the TIM peripheral. |
4853 | * contains the clock source information for the TIM peripheral. |
| 3799 | * @retval HAL status |
4854 | * @retval HAL status |
| 3800 | */ |
4855 | */ |
| 3801 | HAL_StatusTypeDef HAL_TIM_ConfigClockSource(TIM_HandleTypeDef *htim, TIM_ClockConfigTypeDef * sClockSourceConfig) |
4856 | HAL_StatusTypeDef HAL_TIM_ConfigClockSource(TIM_HandleTypeDef *htim, TIM_ClockConfigTypeDef *sClockSourceConfig) |
| 3802 | { |
4857 | { |
| 3803 | uint32_t tmpsmcr = 0; |
4858 | uint32_t tmpsmcr; |
| 3804 | 4859 | ||
| 3805 | /* Process Locked */ |
4860 | /* Process Locked */ |
| 3806 | __HAL_LOCK(htim); |
4861 | __HAL_LOCK(htim); |
| 3807 | 4862 | ||
| 3808 | htim->State = HAL_TIM_STATE_BUSY; |
4863 | htim->State = HAL_TIM_STATE_BUSY; |
| Line 3816... | Line 4871... | ||
| 3816 | tmpsmcr &= ~(TIM_SMCR_ETF | TIM_SMCR_ETPS | TIM_SMCR_ECE | TIM_SMCR_ETP); |
4871 | tmpsmcr &= ~(TIM_SMCR_ETF | TIM_SMCR_ETPS | TIM_SMCR_ECE | TIM_SMCR_ETP); |
| 3817 | htim->Instance->SMCR = tmpsmcr; |
4872 | htim->Instance->SMCR = tmpsmcr; |
| 3818 | 4873 | ||
| 3819 | switch (sClockSourceConfig->ClockSource) |
4874 | switch (sClockSourceConfig->ClockSource) |
| 3820 | { |
4875 | { |
| 3821 | case TIM_CLOCKSOURCE_INTERNAL: |
4876 | case TIM_CLOCKSOURCE_INTERNAL: |
| 3822 | { |
4877 | { |
| 3823 | assert_param(IS_TIM_INSTANCE(htim->Instance)); |
4878 | assert_param(IS_TIM_INSTANCE(htim->Instance)); |
| 3824 | /* Disable slave mode to clock the prescaler directly with the internal clock */ |
- | |
| 3825 | htim->Instance->SMCR &= ~TIM_SMCR_SMS; |
4879 | break; |
| 3826 | } |
4880 | } |
| 3827 | break; |
- | |
| 3828 | 4881 | ||
| 3829 | case TIM_CLOCKSOURCE_ETRMODE1: |
4882 | case TIM_CLOCKSOURCE_ETRMODE1: |
| 3830 | { |
4883 | { |
| 3831 | /* Check whether or not the timer instance supports external trigger input mode 1 (ETRF)*/ |
4884 | /* Check whether or not the timer instance supports external trigger input mode 1 (ETRF)*/ |
| 3832 | assert_param(IS_TIM_CLOCKSOURCE_ETRMODE1_INSTANCE(htim->Instance)); |
4885 | assert_param(IS_TIM_CLOCKSOURCE_ETRMODE1_INSTANCE(htim->Instance)); |
| 3833 | 4886 | ||
| 3834 | /* Check ETR input conditioning related parameters */ |
4887 | /* Check ETR input conditioning related parameters */ |
| 3835 | assert_param(IS_TIM_CLOCKPRESCALER(sClockSourceConfig->ClockPrescaler)); |
4888 | assert_param(IS_TIM_CLOCKPRESCALER(sClockSourceConfig->ClockPrescaler)); |
| 3836 | assert_param(IS_TIM_CLOCKPOLARITY(sClockSourceConfig->ClockPolarity)); |
4889 | assert_param(IS_TIM_CLOCKPOLARITY(sClockSourceConfig->ClockPolarity)); |
| 3837 | assert_param(IS_TIM_CLOCKFILTER(sClockSourceConfig->ClockFilter)); |
4890 | assert_param(IS_TIM_CLOCKFILTER(sClockSourceConfig->ClockFilter)); |
| 3838 | 4891 | ||
| 3839 | /* Configure the ETR Clock source */ |
4892 | /* Configure the ETR Clock source */ |
| 3840 | TIM_ETR_SetConfig(htim->Instance, |
4893 | TIM_ETR_SetConfig(htim->Instance, |
| 3841 | sClockSourceConfig->ClockPrescaler, |
4894 | sClockSourceConfig->ClockPrescaler, |
| 3842 | sClockSourceConfig->ClockPolarity, |
4895 | sClockSourceConfig->ClockPolarity, |
| 3843 | sClockSourceConfig->ClockFilter); |
4896 | sClockSourceConfig->ClockFilter); |
| 3844 | /* Get the TIMx SMCR register value */ |
- | |
| 3845 | tmpsmcr = htim->Instance->SMCR; |
- | |
| 3846 | /* Reset the SMS and TS Bits */ |
- | |
| 3847 | tmpsmcr &= ~(TIM_SMCR_SMS | TIM_SMCR_TS); |
- | |
| - | 4897 | ||
| 3848 | /* Select the External clock mode1 and the ETRF trigger */ |
4898 | /* Select the External clock mode1 and the ETRF trigger */ |
| - | 4899 | tmpsmcr = htim->Instance->SMCR; |
|
| 3849 | tmpsmcr |= (TIM_SLAVEMODE_EXTERNAL1 | TIM_CLOCKSOURCE_ETRMODE1); |
4900 | tmpsmcr |= (TIM_SLAVEMODE_EXTERNAL1 | TIM_CLOCKSOURCE_ETRMODE1); |
| 3850 | /* Write to TIMx SMCR */ |
4901 | /* Write to TIMx SMCR */ |
| 3851 | htim->Instance->SMCR = tmpsmcr; |
4902 | htim->Instance->SMCR = tmpsmcr; |
| - | 4903 | break; |
|
| 3852 | } |
4904 | } |
| 3853 | break; |
- | |
| 3854 | 4905 | ||
| 3855 | case TIM_CLOCKSOURCE_ETRMODE2: |
4906 | case TIM_CLOCKSOURCE_ETRMODE2: |
| 3856 | { |
4907 | { |
| 3857 | /* Check whether or not the timer instance supports external trigger input mode 2 (ETRF)*/ |
4908 | /* Check whether or not the timer instance supports external trigger input mode 2 (ETRF)*/ |
| 3858 | assert_param(IS_TIM_CLOCKSOURCE_ETRMODE2_INSTANCE(htim->Instance)); |
4909 | assert_param(IS_TIM_CLOCKSOURCE_ETRMODE2_INSTANCE(htim->Instance)); |
| 3859 | 4910 | ||
| 3860 | /* Check ETR input conditioning related parameters */ |
4911 | /* Check ETR input conditioning related parameters */ |
| 3861 | assert_param(IS_TIM_CLOCKPRESCALER(sClockSourceConfig->ClockPrescaler)); |
4912 | assert_param(IS_TIM_CLOCKPRESCALER(sClockSourceConfig->ClockPrescaler)); |
| 3862 | assert_param(IS_TIM_CLOCKPOLARITY(sClockSourceConfig->ClockPolarity)); |
4913 | assert_param(IS_TIM_CLOCKPOLARITY(sClockSourceConfig->ClockPolarity)); |
| 3863 | assert_param(IS_TIM_CLOCKFILTER(sClockSourceConfig->ClockFilter)); |
4914 | assert_param(IS_TIM_CLOCKFILTER(sClockSourceConfig->ClockFilter)); |
| 3864 | 4915 | ||
| 3865 | /* Configure the ETR Clock source */ |
4916 | /* Configure the ETR Clock source */ |
| 3866 | TIM_ETR_SetConfig(htim->Instance, |
4917 | TIM_ETR_SetConfig(htim->Instance, |
| 3867 | sClockSourceConfig->ClockPrescaler, |
4918 | sClockSourceConfig->ClockPrescaler, |
| 3868 | sClockSourceConfig->ClockPolarity, |
4919 | sClockSourceConfig->ClockPolarity, |
| 3869 | sClockSourceConfig->ClockFilter); |
4920 | sClockSourceConfig->ClockFilter); |
| 3870 | /* Enable the External clock mode2 */ |
4921 | /* Enable the External clock mode2 */ |
| 3871 | htim->Instance->SMCR |= TIM_SMCR_ECE; |
4922 | htim->Instance->SMCR |= TIM_SMCR_ECE; |
| - | 4923 | break; |
|
| 3872 | } |
4924 | } |
| 3873 | break; |
- | |
| 3874 | 4925 | ||
| 3875 | case TIM_CLOCKSOURCE_TI1: |
4926 | case TIM_CLOCKSOURCE_TI1: |
| 3876 | { |
4927 | { |
| 3877 | /* Check whether or not the timer instance supports external clock mode 1 */ |
4928 | /* Check whether or not the timer instance supports external clock mode 1 */ |
| 3878 | assert_param(IS_TIM_CLOCKSOURCE_TIX_INSTANCE(htim->Instance)); |
4929 | assert_param(IS_TIM_CLOCKSOURCE_TIX_INSTANCE(htim->Instance)); |
| 3879 | 4930 | ||
| 3880 | /* Check TI1 input conditioning related parameters */ |
4931 | /* Check TI1 input conditioning related parameters */ |
| 3881 | assert_param(IS_TIM_CLOCKPOLARITY(sClockSourceConfig->ClockPolarity)); |
4932 | assert_param(IS_TIM_CLOCKPOLARITY(sClockSourceConfig->ClockPolarity)); |
| 3882 | assert_param(IS_TIM_CLOCKFILTER(sClockSourceConfig->ClockFilter)); |
4933 | assert_param(IS_TIM_CLOCKFILTER(sClockSourceConfig->ClockFilter)); |
| 3883 | 4934 | ||
| 3884 | TIM_TI1_ConfigInputStage(htim->Instance, |
4935 | TIM_TI1_ConfigInputStage(htim->Instance, |
| 3885 | sClockSourceConfig->ClockPolarity, |
4936 | sClockSourceConfig->ClockPolarity, |
| 3886 | sClockSourceConfig->ClockFilter); |
4937 | sClockSourceConfig->ClockFilter); |
| 3887 | TIM_ITRx_SetConfig(htim->Instance, TIM_CLOCKSOURCE_TI1); |
4938 | TIM_ITRx_SetConfig(htim->Instance, TIM_CLOCKSOURCE_TI1); |
| - | 4939 | break; |
|
| 3888 | } |
4940 | } |
| 3889 | break; |
4941 | |
| 3890 | case TIM_CLOCKSOURCE_TI2: |
4942 | case TIM_CLOCKSOURCE_TI2: |
| 3891 | { |
4943 | { |
| 3892 | /* Check whether or not the timer instance supports external clock mode 1 (ETRF)*/ |
4944 | /* Check whether or not the timer instance supports external clock mode 1 (ETRF)*/ |
| 3893 | assert_param(IS_TIM_CLOCKSOURCE_TIX_INSTANCE(htim->Instance)); |
4945 | assert_param(IS_TIM_CLOCKSOURCE_TIX_INSTANCE(htim->Instance)); |
| 3894 | 4946 | ||
| 3895 | /* Check TI2 input conditioning related parameters */ |
4947 | /* Check TI2 input conditioning related parameters */ |
| 3896 | assert_param(IS_TIM_CLOCKPOLARITY(sClockSourceConfig->ClockPolarity)); |
4948 | assert_param(IS_TIM_CLOCKPOLARITY(sClockSourceConfig->ClockPolarity)); |
| 3897 | assert_param(IS_TIM_CLOCKFILTER(sClockSourceConfig->ClockFilter)); |
4949 | assert_param(IS_TIM_CLOCKFILTER(sClockSourceConfig->ClockFilter)); |
| 3898 | 4950 | ||
| 3899 | TIM_TI2_ConfigInputStage(htim->Instance, |
4951 | TIM_TI2_ConfigInputStage(htim->Instance, |
| 3900 | sClockSourceConfig->ClockPolarity, |
4952 | sClockSourceConfig->ClockPolarity, |
| 3901 | sClockSourceConfig->ClockFilter); |
4953 | sClockSourceConfig->ClockFilter); |
| 3902 | TIM_ITRx_SetConfig(htim->Instance, TIM_CLOCKSOURCE_TI2); |
4954 | TIM_ITRx_SetConfig(htim->Instance, TIM_CLOCKSOURCE_TI2); |
| - | 4955 | break; |
|
| 3903 | } |
4956 | } |
| 3904 | break; |
4957 | |
| 3905 | case TIM_CLOCKSOURCE_TI1ED: |
4958 | case TIM_CLOCKSOURCE_TI1ED: |
| 3906 | { |
4959 | { |
| 3907 | /* Check whether or not the timer instance supports external clock mode 1 */ |
4960 | /* Check whether or not the timer instance supports external clock mode 1 */ |
| 3908 | assert_param(IS_TIM_CLOCKSOURCE_TIX_INSTANCE(htim->Instance)); |
4961 | assert_param(IS_TIM_CLOCKSOURCE_TIX_INSTANCE(htim->Instance)); |
| 3909 | 4962 | ||
| 3910 | /* Check TI1 input conditioning related parameters */ |
4963 | /* Check TI1 input conditioning related parameters */ |
| Line 3913... | Line 4966... | ||
| 3913 | 4966 | ||
| 3914 | TIM_TI1_ConfigInputStage(htim->Instance, |
4967 | TIM_TI1_ConfigInputStage(htim->Instance, |
| 3915 | sClockSourceConfig->ClockPolarity, |
4968 | sClockSourceConfig->ClockPolarity, |
| 3916 | sClockSourceConfig->ClockFilter); |
4969 | sClockSourceConfig->ClockFilter); |
| 3917 | TIM_ITRx_SetConfig(htim->Instance, TIM_CLOCKSOURCE_TI1ED); |
4970 | TIM_ITRx_SetConfig(htim->Instance, TIM_CLOCKSOURCE_TI1ED); |
| - | 4971 | break; |
|
| 3918 | } |
4972 | } |
| 3919 | break; |
- | |
| 3920 | case TIM_CLOCKSOURCE_ITR0: |
- | |
| 3921 | { |
- | |
| 3922 | /* Check whether or not the timer instance supports external clock mode 1 */ |
- | |
| 3923 | assert_param(IS_TIM_CLOCKSOURCE_ITRX_INSTANCE(htim->Instance)); |
- | |
| 3924 | - | ||
| 3925 | TIM_ITRx_SetConfig(htim->Instance, TIM_CLOCKSOURCE_ITR0); |
- | |
| 3926 | } |
- | |
| 3927 | break; |
- | |
| 3928 | case TIM_CLOCKSOURCE_ITR1: |
- | |
| 3929 | { |
- | |
| 3930 | /* Check whether or not the timer instance supports external clock mode 1 */ |
- | |
| 3931 | assert_param(IS_TIM_CLOCKSOURCE_ITRX_INSTANCE(htim->Instance)); |
- | |
| 3932 | - | ||
| 3933 | TIM_ITRx_SetConfig(htim->Instance, TIM_CLOCKSOURCE_ITR1); |
- | |
| 3934 | } |
- | |
| 3935 | break; |
- | |
| 3936 | case TIM_CLOCKSOURCE_ITR2: |
- | |
| 3937 | { |
- | |
| 3938 | /* Check whether or not the timer instance supports external clock mode 1 */ |
- | |
| 3939 | assert_param(IS_TIM_CLOCKSOURCE_ITRX_INSTANCE(htim->Instance)); |
- | |
| 3940 | 4973 | ||
| 3941 | TIM_ITRx_SetConfig(htim->Instance, TIM_CLOCKSOURCE_ITR2); |
4974 | case TIM_CLOCKSOURCE_ITR0: |
| 3942 | } |
4975 | case TIM_CLOCKSOURCE_ITR1: |
| 3943 | break; |
4976 | case TIM_CLOCKSOURCE_ITR2: |
| 3944 | case TIM_CLOCKSOURCE_ITR3: |
4977 | case TIM_CLOCKSOURCE_ITR3: |
| 3945 | { |
4978 | { |
| 3946 | /* Check whether or not the timer instance supports external clock mode 1 */ |
4979 | /* Check whether or not the timer instance supports internal trigger input */ |
| 3947 | assert_param(IS_TIM_CLOCKSOURCE_ITRX_INSTANCE(htim->Instance)); |
4980 | assert_param(IS_TIM_CLOCKSOURCE_ITRX_INSTANCE(htim->Instance)); |
| 3948 | 4981 | ||
| 3949 | TIM_ITRx_SetConfig(htim->Instance, TIM_CLOCKSOURCE_ITR3); |
4982 | TIM_ITRx_SetConfig(htim->Instance, sClockSourceConfig->ClockSource); |
| 3950 | } |
4983 | break; |
| 3951 | break; |
4984 | } |
| 3952 | 4985 | ||
| 3953 | default: |
4986 | default: |
| 3954 | break; |
4987 | break; |
| 3955 | } |
4988 | } |
| 3956 | htim->State = HAL_TIM_STATE_READY; |
4989 | htim->State = HAL_TIM_STATE_READY; |
| 3957 | 4990 | ||
| 3958 | __HAL_UNLOCK(htim); |
4991 | __HAL_UNLOCK(htim); |
| 3959 | 4992 | ||
| Line 3961... | Line 4994... | ||
| 3961 | } |
4994 | } |
| 3962 | 4995 | ||
| 3963 | /** |
4996 | /** |
| 3964 | * @brief Selects the signal connected to the TI1 input: direct from CH1_input |
4997 | * @brief Selects the signal connected to the TI1 input: direct from CH1_input |
| 3965 | * or a XOR combination between CH1_input, CH2_input & CH3_input |
4998 | * or a XOR combination between CH1_input, CH2_input & CH3_input |
| 3966 | * @param htim: TIM handle. |
4999 | * @param htim TIM handle. |
| 3967 | * @param TI1_Selection: Indicate whether or not channel 1 is connected to the |
5000 | * @param TI1_Selection Indicate whether or not channel 1 is connected to the |
| 3968 | * output of a XOR gate. |
5001 | * output of a XOR gate. |
| 3969 | * This parameter can be one of the following values: |
5002 | * This parameter can be one of the following values: |
| 3970 | * @arg TIM_TI1SELECTION_CH1: The TIMx_CH1 pin is connected to TI1 input |
5003 | * @arg TIM_TI1SELECTION_CH1: The TIMx_CH1 pin is connected to TI1 input |
| 3971 | * @arg TIM_TI1SELECTION_XORCOMBINATION: The TIMx_CH1, CH2 and CH3 |
5004 | * @arg TIM_TI1SELECTION_XORCOMBINATION: The TIMx_CH1, CH2 and CH3 |
| 3972 | * pins are connected to the TI1 input (XOR combination) |
5005 | * pins are connected to the TI1 input (XOR combination) |
| 3973 | * @retval HAL status |
5006 | * @retval HAL status |
| 3974 | */ |
5007 | */ |
| 3975 | HAL_StatusTypeDef HAL_TIM_ConfigTI1Input(TIM_HandleTypeDef *htim, uint32_t TI1_Selection) |
5008 | HAL_StatusTypeDef HAL_TIM_ConfigTI1Input(TIM_HandleTypeDef *htim, uint32_t TI1_Selection) |
| 3976 | { |
5009 | { |
| 3977 | uint32_t tmpcr2 = 0; |
5010 | uint32_t tmpcr2; |
| 3978 | 5011 | ||
| 3979 | /* Check the parameters */ |
5012 | /* Check the parameters */ |
| 3980 | assert_param(IS_TIM_XOR_INSTANCE(htim->Instance)); |
5013 | assert_param(IS_TIM_XOR_INSTANCE(htim->Instance)); |
| 3981 | assert_param(IS_TIM_TI1SELECTION(TI1_Selection)); |
5014 | assert_param(IS_TIM_TI1SELECTION(TI1_Selection)); |
| 3982 | 5015 | ||
| Line 3984... | Line 5017... | ||
| 3984 | tmpcr2 = htim->Instance->CR2; |
5017 | tmpcr2 = htim->Instance->CR2; |
| 3985 | 5018 | ||
| 3986 | /* Reset the TI1 selection */ |
5019 | /* Reset the TI1 selection */ |
| 3987 | tmpcr2 &= ~TIM_CR2_TI1S; |
5020 | tmpcr2 &= ~TIM_CR2_TI1S; |
| 3988 | 5021 | ||
| 3989 | /* Set the the TI1 selection */ |
5022 | /* Set the TI1 selection */ |
| 3990 | tmpcr2 |= TI1_Selection; |
5023 | tmpcr2 |= TI1_Selection; |
| 3991 | 5024 | ||
| 3992 | /* Write to TIMxCR2 */ |
5025 | /* Write to TIMxCR2 */ |
| 3993 | htim->Instance->CR2 = tmpcr2; |
5026 | htim->Instance->CR2 = tmpcr2; |
| 3994 | 5027 | ||
| 3995 | return HAL_OK; |
5028 | return HAL_OK; |
| 3996 | } |
5029 | } |
| 3997 | 5030 | ||
| 3998 | /** |
5031 | /** |
| 3999 | * @brief Configures the TIM in Slave mode |
5032 | * @brief Configures the TIM in Slave mode |
| 4000 | * @param htim : TIM handle. |
5033 | * @param htim TIM handle. |
| 4001 | * @param sSlaveConfig: pointer to a TIM_SlaveConfigTypeDef structure that |
5034 | * @param sSlaveConfig pointer to a TIM_SlaveConfigTypeDef structure that |
| 4002 | * contains the selected trigger (internal trigger input, filtered |
5035 | * contains the selected trigger (internal trigger input, filtered |
| 4003 | * timer input or external trigger input) and the ) and the Slave |
5036 | * timer input or external trigger input) and the Slave mode |
| 4004 | * mode (Disable, Reset, Gated, Trigger, External clock mode 1). |
5037 | * (Disable, Reset, Gated, Trigger, External clock mode 1). |
| 4005 | * @retval HAL status |
5038 | * @retval HAL status |
| 4006 | */ |
5039 | */ |
| 4007 | HAL_StatusTypeDef HAL_TIM_SlaveConfigSynchronization(TIM_HandleTypeDef *htim, TIM_SlaveConfigTypeDef * sSlaveConfig) |
5040 | HAL_StatusTypeDef HAL_TIM_SlaveConfigSynchro(TIM_HandleTypeDef *htim, TIM_SlaveConfigTypeDef *sSlaveConfig) |
| 4008 | { |
5041 | { |
| 4009 | /* Check the parameters */ |
5042 | /* Check the parameters */ |
| 4010 | assert_param(IS_TIM_SLAVE_INSTANCE(htim->Instance)); |
5043 | assert_param(IS_TIM_SLAVE_INSTANCE(htim->Instance)); |
| 4011 | assert_param(IS_TIM_SLAVE_MODE(sSlaveConfig->SlaveMode)); |
5044 | assert_param(IS_TIM_SLAVE_MODE(sSlaveConfig->SlaveMode)); |
| 4012 | assert_param(IS_TIM_TRIGGER_SELECTION(sSlaveConfig->InputTrigger)); |
5045 | assert_param(IS_TIM_TRIGGER_SELECTION(sSlaveConfig->InputTrigger)); |
| 4013 | 5046 | ||
| 4014 | __HAL_LOCK(htim); |
5047 | __HAL_LOCK(htim); |
| 4015 | 5048 | ||
| 4016 | htim->State = HAL_TIM_STATE_BUSY; |
5049 | htim->State = HAL_TIM_STATE_BUSY; |
| 4017 | 5050 | ||
| 4018 | TIM_SlaveTimer_SetConfig(htim, sSlaveConfig); |
5051 | if (TIM_SlaveTimer_SetConfig(htim, sSlaveConfig) != HAL_OK) |
| - | 5052 | { |
|
| - | 5053 | htim->State = HAL_TIM_STATE_READY; |
|
| - | 5054 | __HAL_UNLOCK(htim); |
|
| - | 5055 | return HAL_ERROR; |
|
| 4019 | 5056 | } |
|
| - | 5057 | ||
| 4020 | /* Disable Trigger Interrupt */ |
5058 | /* Disable Trigger Interrupt */ |
| 4021 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_TRIGGER); |
5059 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_TRIGGER); |
| 4022 | 5060 | ||
| 4023 | /* Disable Trigger DMA request */ |
5061 | /* Disable Trigger DMA request */ |
| 4024 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_TRIGGER); |
5062 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_TRIGGER); |
| 4025 | 5063 | ||
| 4026 | htim->State = HAL_TIM_STATE_READY; |
5064 | htim->State = HAL_TIM_STATE_READY; |
| 4027 | 5065 | ||
| 4028 | __HAL_UNLOCK(htim); |
5066 | __HAL_UNLOCK(htim); |
| 4029 | 5067 | ||
| 4030 | return HAL_OK; |
5068 | return HAL_OK; |
| 4031 | } |
5069 | } |
| 4032 | 5070 | ||
| 4033 | /** |
5071 | /** |
| 4034 | * @brief Configures the TIM in Slave mode in interrupt mode |
5072 | * @brief Configures the TIM in Slave mode in interrupt mode |
| 4035 | * @param htim: TIM handle. |
5073 | * @param htim TIM handle. |
| 4036 | * @param sSlaveConfig: pointer to a TIM_SlaveConfigTypeDef structure that |
5074 | * @param sSlaveConfig pointer to a TIM_SlaveConfigTypeDef structure that |
| 4037 | * contains the selected trigger (internal trigger input, filtered |
5075 | * contains the selected trigger (internal trigger input, filtered |
| 4038 | * timer input or external trigger input) and the ) and the Slave |
5076 | * timer input or external trigger input) and the Slave mode |
| 4039 | * mode (Disable, Reset, Gated, Trigger, External clock mode 1). |
5077 | * (Disable, Reset, Gated, Trigger, External clock mode 1). |
| 4040 | * @retval HAL status |
5078 | * @retval HAL status |
| 4041 | */ |
5079 | */ |
| 4042 | HAL_StatusTypeDef HAL_TIM_SlaveConfigSynchronization_IT(TIM_HandleTypeDef *htim, |
5080 | HAL_StatusTypeDef HAL_TIM_SlaveConfigSynchro_IT(TIM_HandleTypeDef *htim, |
| 4043 | TIM_SlaveConfigTypeDef * sSlaveConfig) |
5081 | TIM_SlaveConfigTypeDef *sSlaveConfig) |
| 4044 | { |
5082 | { |
| 4045 | /* Check the parameters */ |
5083 | /* Check the parameters */ |
| 4046 | assert_param(IS_TIM_SLAVE_INSTANCE(htim->Instance)); |
5084 | assert_param(IS_TIM_SLAVE_INSTANCE(htim->Instance)); |
| 4047 | assert_param(IS_TIM_SLAVE_MODE(sSlaveConfig->SlaveMode)); |
5085 | assert_param(IS_TIM_SLAVE_MODE(sSlaveConfig->SlaveMode)); |
| 4048 | assert_param(IS_TIM_TRIGGER_SELECTION(sSlaveConfig->InputTrigger)); |
5086 | assert_param(IS_TIM_TRIGGER_SELECTION(sSlaveConfig->InputTrigger)); |
| 4049 | 5087 | ||
| 4050 | __HAL_LOCK(htim); |
5088 | __HAL_LOCK(htim); |
| 4051 | 5089 | ||
| 4052 | htim->State = HAL_TIM_STATE_BUSY; |
5090 | htim->State = HAL_TIM_STATE_BUSY; |
| 4053 | 5091 | ||
| 4054 | TIM_SlaveTimer_SetConfig(htim, sSlaveConfig); |
5092 | if (TIM_SlaveTimer_SetConfig(htim, sSlaveConfig) != HAL_OK) |
| - | 5093 | { |
|
| - | 5094 | htim->State = HAL_TIM_STATE_READY; |
|
| - | 5095 | __HAL_UNLOCK(htim); |
|
| - | 5096 | return HAL_ERROR; |
|
| 4055 | 5097 | } |
|
| - | 5098 | ||
| 4056 | /* Enable Trigger Interrupt */ |
5099 | /* Enable Trigger Interrupt */ |
| 4057 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_TRIGGER); |
5100 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_TRIGGER); |
| 4058 | 5101 | ||
| 4059 | /* Disable Trigger DMA request */ |
5102 | /* Disable Trigger DMA request */ |
| 4060 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_TRIGGER); |
5103 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_TRIGGER); |
| 4061 | 5104 | ||
| 4062 | htim->State = HAL_TIM_STATE_READY; |
5105 | htim->State = HAL_TIM_STATE_READY; |
| 4063 | 5106 | ||
| 4064 | __HAL_UNLOCK(htim); |
5107 | __HAL_UNLOCK(htim); |
| 4065 | 5108 | ||
| 4066 | return HAL_OK; |
5109 | return HAL_OK; |
| 4067 | } |
5110 | } |
| 4068 | 5111 | ||
| 4069 | /** |
5112 | /** |
| 4070 | * @brief Read the captured value from Capture Compare unit |
5113 | * @brief Read the captured value from Capture Compare unit |
| 4071 | * @param htim: TIM handle. |
5114 | * @param htim TIM handle. |
| 4072 | * @param Channel : TIM Channels to be enabled |
5115 | * @param Channel TIM Channels to be enabled |
| 4073 | * This parameter can be one of the following values: |
5116 | * This parameter can be one of the following values: |
| 4074 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
5117 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
| 4075 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
5118 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
| 4076 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
5119 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
| 4077 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
5120 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
| 4078 | * @retval Captured value |
5121 | * @retval Captured value |
| 4079 | */ |
5122 | */ |
| 4080 | uint32_t HAL_TIM_ReadCapturedValue(TIM_HandleTypeDef *htim, uint32_t Channel) |
5123 | uint32_t HAL_TIM_ReadCapturedValue(TIM_HandleTypeDef *htim, uint32_t Channel) |
| 4081 | { |
5124 | { |
| 4082 | uint32_t tmpreg = 0; |
5125 | uint32_t tmpreg = 0U; |
| 4083 | - | ||
| 4084 | __HAL_LOCK(htim); |
- | |
| 4085 | 5126 | ||
| 4086 | switch (Channel) |
5127 | switch (Channel) |
| 4087 | { |
5128 | { |
| 4088 | case TIM_CHANNEL_1: |
5129 | case TIM_CHANNEL_1: |
| 4089 | { |
5130 | { |
| 4090 | /* Check the parameters */ |
5131 | /* Check the parameters */ |
| 4091 | assert_param(IS_TIM_CC1_INSTANCE(htim->Instance)); |
5132 | assert_param(IS_TIM_CC1_INSTANCE(htim->Instance)); |
| 4092 | 5133 | ||
| 4093 | /* Return the capture 1 value */ |
5134 | /* Return the capture 1 value */ |
| 4094 | tmpreg = htim->Instance->CCR1; |
5135 | tmpreg = htim->Instance->CCR1; |
| 4095 | 5136 | ||
| 4096 | break; |
5137 | break; |
| 4097 | } |
5138 | } |
| 4098 | case TIM_CHANNEL_2: |
5139 | case TIM_CHANNEL_2: |
| 4099 | { |
5140 | { |
| 4100 | /* Check the parameters */ |
5141 | /* Check the parameters */ |
| 4101 | assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); |
5142 | assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); |
| 4102 | 5143 | ||
| 4103 | /* Return the capture 2 value */ |
5144 | /* Return the capture 2 value */ |
| 4104 | tmpreg = htim->Instance->CCR2; |
5145 | tmpreg = htim->Instance->CCR2; |
| 4105 | 5146 | ||
| 4106 | break; |
5147 | break; |
| 4107 | } |
5148 | } |
| 4108 | 5149 | ||
| 4109 | case TIM_CHANNEL_3: |
5150 | case TIM_CHANNEL_3: |
| 4110 | { |
5151 | { |
| 4111 | /* Check the parameters */ |
5152 | /* Check the parameters */ |
| 4112 | assert_param(IS_TIM_CC3_INSTANCE(htim->Instance)); |
5153 | assert_param(IS_TIM_CC3_INSTANCE(htim->Instance)); |
| 4113 | 5154 | ||
| 4114 | /* Return the capture 3 value */ |
5155 | /* Return the capture 3 value */ |
| 4115 | tmpreg = htim->Instance->CCR3; |
5156 | tmpreg = htim->Instance->CCR3; |
| 4116 | 5157 | ||
| 4117 | break; |
5158 | break; |
| 4118 | } |
5159 | } |
| 4119 | 5160 | ||
| 4120 | case TIM_CHANNEL_4: |
5161 | case TIM_CHANNEL_4: |
| 4121 | { |
5162 | { |
| 4122 | /* Check the parameters */ |
5163 | /* Check the parameters */ |
| 4123 | assert_param(IS_TIM_CC4_INSTANCE(htim->Instance)); |
5164 | assert_param(IS_TIM_CC4_INSTANCE(htim->Instance)); |
| 4124 | 5165 | ||
| 4125 | /* Return the capture 4 value */ |
5166 | /* Return the capture 4 value */ |
| 4126 | tmpreg = htim->Instance->CCR4; |
5167 | tmpreg = htim->Instance->CCR4; |
| 4127 | 5168 | ||
| 4128 | break; |
5169 | break; |
| 4129 | } |
5170 | } |
| 4130 | 5171 | ||
| 4131 | default: |
5172 | default: |
| 4132 | break; |
5173 | break; |
| 4133 | } |
5174 | } |
| 4134 | 5175 | ||
| 4135 | __HAL_UNLOCK(htim); |
- | |
| 4136 | return tmpreg; |
5176 | return tmpreg; |
| 4137 | } |
5177 | } |
| 4138 | 5178 | ||
| 4139 | /** |
5179 | /** |
| 4140 | * @} |
5180 | * @} |
| 4141 | */ |
5181 | */ |
| 4142 | 5182 | ||
| 4143 | /** @defgroup TIM_Exported_Functions_Group9 TIM Callbacks functions |
5183 | /** @defgroup TIM_Exported_Functions_Group9 TIM Callbacks functions |
| 4144 | * @brief TIM Callbacks functions |
5184 | * @brief TIM Callbacks functions |
| 4145 | * |
5185 | * |
| 4146 | @verbatim |
5186 | @verbatim |
| 4147 | ============================================================================== |
5187 | ============================================================================== |
| 4148 | ##### TIM Callbacks functions ##### |
5188 | ##### TIM Callbacks functions ##### |
| 4149 | ============================================================================== |
5189 | ============================================================================== |
| 4150 | [..] |
5190 | [..] |
| 4151 | This section provides TIM callback functions: |
5191 | This section provides TIM callback functions: |
| 4152 | (+) Timer Period elapsed callback |
5192 | (+) TIM Period elapsed callback |
| 4153 | (+) Timer Output Compare callback |
5193 | (+) TIM Output Compare callback |
| 4154 | (+) Timer Input capture callback |
5194 | (+) TIM Input capture callback |
| 4155 | (+) Timer Trigger callback |
5195 | (+) TIM Trigger callback |
| 4156 | (+) Timer Error callback |
5196 | (+) TIM Error callback |
| 4157 | 5197 | ||
| 4158 | @endverbatim |
5198 | @endverbatim |
| 4159 | * @{ |
5199 | * @{ |
| 4160 | */ |
5200 | */ |
| 4161 | 5201 | ||
| 4162 | /** |
5202 | /** |
| 4163 | * @brief Period elapsed callback in non blocking mode |
5203 | * @brief Period elapsed callback in non-blocking mode |
| 4164 | * @param htim : TIM handle |
5204 | * @param htim TIM handle |
| 4165 | * @retval None |
5205 | * @retval None |
| 4166 | */ |
5206 | */ |
| 4167 | __weak void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) |
5207 | __weak void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) |
| 4168 | { |
5208 | { |
| 4169 | /* Prevent unused argument(s) compilation warning */ |
5209 | /* Prevent unused argument(s) compilation warning */ |
| 4170 | UNUSED(htim); |
5210 | UNUSED(htim); |
| 4171 | 5211 | ||
| 4172 | /* NOTE : This function Should not be modified, when the callback is needed, |
5212 | /* NOTE : This function should not be modified, when the callback is needed, |
| 4173 | the __HAL_TIM_PeriodElapsedCallback could be implemented in the user file |
5213 | the HAL_TIM_PeriodElapsedCallback could be implemented in the user file |
| 4174 | */ |
5214 | */ |
| - | 5215 | } |
|
| - | 5216 | ||
| - | 5217 | /** |
|
| - | 5218 | * @brief Period elapsed half complete callback in non-blocking mode |
|
| - | 5219 | * @param htim TIM handle |
|
| - | 5220 | * @retval None |
|
| - | 5221 | */ |
|
| - | 5222 | __weak void HAL_TIM_PeriodElapsedHalfCpltCallback(TIM_HandleTypeDef *htim) |
|
| - | 5223 | { |
|
| - | 5224 | /* Prevent unused argument(s) compilation warning */ |
|
| - | 5225 | UNUSED(htim); |
|
| 4175 | 5226 | ||
| - | 5227 | /* NOTE : This function should not be modified, when the callback is needed, |
|
| - | 5228 | the HAL_TIM_PeriodElapsedHalfCpltCallback could be implemented in the user file |
|
| - | 5229 | */ |
|
| 4176 | } |
5230 | } |
| - | 5231 | ||
| 4177 | /** |
5232 | /** |
| 4178 | * @brief Output Compare callback in non blocking mode |
5233 | * @brief Output Compare callback in non-blocking mode |
| 4179 | * @param htim : TIM OC handle |
5234 | * @param htim TIM OC handle |
| 4180 | * @retval None |
5235 | * @retval None |
| 4181 | */ |
5236 | */ |
| 4182 | __weak void HAL_TIM_OC_DelayElapsedCallback(TIM_HandleTypeDef *htim) |
5237 | __weak void HAL_TIM_OC_DelayElapsedCallback(TIM_HandleTypeDef *htim) |
| 4183 | { |
5238 | { |
| 4184 | /* Prevent unused argument(s) compilation warning */ |
5239 | /* Prevent unused argument(s) compilation warning */ |
| 4185 | UNUSED(htim); |
5240 | UNUSED(htim); |
| 4186 | 5241 | ||
| 4187 | /* NOTE : This function Should not be modified, when the callback is needed, |
5242 | /* NOTE : This function should not be modified, when the callback is needed, |
| 4188 | the __HAL_TIM_OC_DelayElapsedCallback could be implemented in the user file |
5243 | the HAL_TIM_OC_DelayElapsedCallback could be implemented in the user file |
| 4189 | */ |
5244 | */ |
| 4190 | } |
5245 | } |
| - | 5246 | ||
| 4191 | /** |
5247 | /** |
| 4192 | * @brief Input Capture callback in non blocking mode |
5248 | * @brief Input Capture callback in non-blocking mode |
| 4193 | * @param htim : TIM IC handle |
5249 | * @param htim TIM IC handle |
| 4194 | * @retval None |
5250 | * @retval None |
| 4195 | */ |
5251 | */ |
| 4196 | __weak void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim) |
5252 | __weak void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim) |
| 4197 | { |
5253 | { |
| 4198 | /* Prevent unused argument(s) compilation warning */ |
5254 | /* Prevent unused argument(s) compilation warning */ |
| 4199 | UNUSED(htim); |
5255 | UNUSED(htim); |
| 4200 | 5256 | ||
| 4201 | /* NOTE : This function Should not be modified, when the callback is needed, |
5257 | /* NOTE : This function should not be modified, when the callback is needed, |
| 4202 | the __HAL_TIM_IC_CaptureCallback could be implemented in the user file |
5258 | the HAL_TIM_IC_CaptureCallback could be implemented in the user file |
| - | 5259 | */ |
|
| - | 5260 | } |
|
| - | 5261 | ||
| - | 5262 | /** |
|
| - | 5263 | * @brief Input Capture half complete callback in non-blocking mode |
|
| - | 5264 | * @param htim TIM IC handle |
|
| - | 5265 | * @retval None |
|
| - | 5266 | */ |
|
| - | 5267 | __weak void HAL_TIM_IC_CaptureHalfCpltCallback(TIM_HandleTypeDef *htim) |
|
| - | 5268 | { |
|
| - | 5269 | /* Prevent unused argument(s) compilation warning */ |
|
| - | 5270 | UNUSED(htim); |
|
| - | 5271 | ||
| - | 5272 | /* NOTE : This function should not be modified, when the callback is needed, |
|
| - | 5273 | the HAL_TIM_IC_CaptureHalfCpltCallback could be implemented in the user file |
|
| 4203 | */ |
5274 | */ |
| 4204 | } |
5275 | } |
| 4205 | 5276 | ||
| 4206 | /** |
5277 | /** |
| 4207 | * @brief PWM Pulse finished callback in non blocking mode |
5278 | * @brief PWM Pulse finished callback in non-blocking mode |
| 4208 | * @param htim : TIM handle |
5279 | * @param htim TIM handle |
| 4209 | * @retval None |
5280 | * @retval None |
| 4210 | */ |
5281 | */ |
| 4211 | __weak void HAL_TIM_PWM_PulseFinishedCallback(TIM_HandleTypeDef *htim) |
5282 | __weak void HAL_TIM_PWM_PulseFinishedCallback(TIM_HandleTypeDef *htim) |
| 4212 | { |
5283 | { |
| 4213 | /* Prevent unused argument(s) compilation warning */ |
5284 | /* Prevent unused argument(s) compilation warning */ |
| 4214 | UNUSED(htim); |
5285 | UNUSED(htim); |
| 4215 | 5286 | ||
| 4216 | /* NOTE : This function Should not be modified, when the callback is needed, |
5287 | /* NOTE : This function should not be modified, when the callback is needed, |
| 4217 | the __HAL_TIM_PWM_PulseFinishedCallback could be implemented in the user file |
5288 | the HAL_TIM_PWM_PulseFinishedCallback could be implemented in the user file |
| 4218 | */ |
5289 | */ |
| 4219 | } |
5290 | } |
| 4220 | 5291 | ||
| 4221 | /** |
5292 | /** |
| - | 5293 | * @brief PWM Pulse finished half complete callback in non-blocking mode |
|
| - | 5294 | * @param htim TIM handle |
|
| - | 5295 | * @retval None |
|
| - | 5296 | */ |
|
| - | 5297 | __weak void HAL_TIM_PWM_PulseFinishedHalfCpltCallback(TIM_HandleTypeDef *htim) |
|
| - | 5298 | { |
|
| - | 5299 | /* Prevent unused argument(s) compilation warning */ |
|
| - | 5300 | UNUSED(htim); |
|
| - | 5301 | ||
| - | 5302 | /* NOTE : This function should not be modified, when the callback is needed, |
|
| - | 5303 | the HAL_TIM_PWM_PulseFinishedHalfCpltCallback could be implemented in the user file |
|
| - | 5304 | */ |
|
| - | 5305 | } |
|
| - | 5306 | ||
| - | 5307 | /** |
|
| 4222 | * @brief Hall Trigger detection callback in non blocking mode |
5308 | * @brief Hall Trigger detection callback in non-blocking mode |
| 4223 | * @param htim : TIM handle |
5309 | * @param htim TIM handle |
| 4224 | * @retval None |
5310 | * @retval None |
| 4225 | */ |
5311 | */ |
| 4226 | __weak void HAL_TIM_TriggerCallback(TIM_HandleTypeDef *htim) |
5312 | __weak void HAL_TIM_TriggerCallback(TIM_HandleTypeDef *htim) |
| 4227 | { |
5313 | { |
| 4228 | /* Prevent unused argument(s) compilation warning */ |
5314 | /* Prevent unused argument(s) compilation warning */ |
| 4229 | UNUSED(htim); |
5315 | UNUSED(htim); |
| 4230 | 5316 | ||
| 4231 | /* NOTE : This function Should not be modified, when the callback is needed, |
5317 | /* NOTE : This function should not be modified, when the callback is needed, |
| 4232 | the HAL_TIM_TriggerCallback could be implemented in the user file |
5318 | the HAL_TIM_TriggerCallback could be implemented in the user file |
| 4233 | */ |
5319 | */ |
| 4234 | } |
5320 | } |
| 4235 | 5321 | ||
| 4236 | /** |
5322 | /** |
| - | 5323 | * @brief Hall Trigger detection half complete callback in non-blocking mode |
|
| - | 5324 | * @param htim TIM handle |
|
| - | 5325 | * @retval None |
|
| - | 5326 | */ |
|
| - | 5327 | __weak void HAL_TIM_TriggerHalfCpltCallback(TIM_HandleTypeDef *htim) |
|
| - | 5328 | { |
|
| - | 5329 | /* Prevent unused argument(s) compilation warning */ |
|
| - | 5330 | UNUSED(htim); |
|
| - | 5331 | ||
| - | 5332 | /* NOTE : This function should not be modified, when the callback is needed, |
|
| - | 5333 | the HAL_TIM_TriggerHalfCpltCallback could be implemented in the user file |
|
| - | 5334 | */ |
|
| - | 5335 | } |
|
| - | 5336 | ||
| - | 5337 | /** |
|
| 4237 | * @brief Timer error callback in non blocking mode |
5338 | * @brief Timer error callback in non-blocking mode |
| 4238 | * @param htim : TIM handle |
5339 | * @param htim TIM handle |
| 4239 | * @retval None |
5340 | * @retval None |
| 4240 | */ |
5341 | */ |
| 4241 | __weak void HAL_TIM_ErrorCallback(TIM_HandleTypeDef *htim) |
5342 | __weak void HAL_TIM_ErrorCallback(TIM_HandleTypeDef *htim) |
| 4242 | { |
5343 | { |
| 4243 | /* Prevent unused argument(s) compilation warning */ |
5344 | /* Prevent unused argument(s) compilation warning */ |
| 4244 | UNUSED(htim); |
5345 | UNUSED(htim); |
| 4245 | 5346 | ||
| 4246 | /* NOTE : This function Should not be modified, when the callback is needed, |
5347 | /* NOTE : This function should not be modified, when the callback is needed, |
| 4247 | the HAL_TIM_ErrorCallback could be implemented in the user file |
5348 | the HAL_TIM_ErrorCallback could be implemented in the user file |
| 4248 | */ |
5349 | */ |
| 4249 | } |
5350 | } |
| 4250 | 5351 | ||
| - | 5352 | #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) |
|
| - | 5353 | /** |
|
| - | 5354 | * @brief Register a User TIM callback to be used instead of the weak predefined callback |
|
| - | 5355 | * @param htim tim handle |
|
| - | 5356 | * @param CallbackID ID of the callback to be registered |
|
| - | 5357 | * This parameter can be one of the following values: |
|
| - | 5358 | * @arg @ref HAL_TIM_BASE_MSPINIT_CB_ID Base MspInit Callback ID |
|
| - | 5359 | * @arg @ref HAL_TIM_BASE_MSPDEINIT_CB_ID Base MspDeInit Callback ID |
|
| - | 5360 | * @arg @ref HAL_TIM_IC_MSPINIT_CB_ID IC MspInit Callback ID |
|
| - | 5361 | * @arg @ref HAL_TIM_IC_MSPDEINIT_CB_ID IC MspDeInit Callback ID |
|
| - | 5362 | * @arg @ref HAL_TIM_OC_MSPINIT_CB_ID OC MspInit Callback ID |
|
| - | 5363 | * @arg @ref HAL_TIM_OC_MSPDEINIT_CB_ID OC MspDeInit Callback ID |
|
| - | 5364 | * @arg @ref HAL_TIM_PWM_MSPINIT_CB_ID PWM MspInit Callback ID |
|
| - | 5365 | * @arg @ref HAL_TIM_PWM_MSPDEINIT_CB_ID PWM MspDeInit Callback ID |
|
| - | 5366 | * @arg @ref HAL_TIM_ONE_PULSE_MSPINIT_CB_ID One Pulse MspInit Callback ID |
|
| - | 5367 | * @arg @ref HAL_TIM_ONE_PULSE_MSPDEINIT_CB_ID One Pulse MspDeInit Callback ID |
|
| - | 5368 | * @arg @ref HAL_TIM_ENCODER_MSPINIT_CB_ID Encoder MspInit Callback ID |
|
| - | 5369 | * @arg @ref HAL_TIM_ENCODER_MSPDEINIT_CB_ID Encoder MspDeInit Callback ID |
|
| - | 5370 | * @arg @ref HAL_TIM_PERIOD_ELAPSED_CB_ID Period Elapsed Callback ID |
|
| - | 5371 | * @arg @ref HAL_TIM_PERIOD_ELAPSED_HALF_CB_ID Period Elapsed half complete Callback ID |
|
| - | 5372 | * @arg @ref HAL_TIM_TRIGGER_CB_ID Trigger Callback ID |
|
| - | 5373 | * @arg @ref HAL_TIM_TRIGGER_HALF_CB_ID Trigger half complete Callback ID |
|
| - | 5374 | * @arg @ref HAL_TIM_IC_CAPTURE_CB_ID Input Capture Callback ID |
|
| - | 5375 | * @arg @ref HAL_TIM_IC_CAPTURE_HALF_CB_ID Input Capture half complete Callback ID |
|
| - | 5376 | * @arg @ref HAL_TIM_OC_DELAY_ELAPSED_CB_ID Output Compare Delay Elapsed Callback ID |
|
| - | 5377 | * @arg @ref HAL_TIM_PWM_PULSE_FINISHED_CB_ID PWM Pulse Finished Callback ID |
|
| - | 5378 | * @arg @ref HAL_TIM_PWM_PULSE_FINISHED_HALF_CB_ID PWM Pulse Finished half complete Callback ID |
|
| - | 5379 | * @arg @ref HAL_TIM_ERROR_CB_ID Error Callback ID |
|
| - | 5380 | * @param pCallback pointer to the callback function |
|
| - | 5381 | * @retval status |
|
| - | 5382 | */ |
|
| - | 5383 | HAL_StatusTypeDef HAL_TIM_RegisterCallback(TIM_HandleTypeDef *htim, HAL_TIM_CallbackIDTypeDef CallbackID, |
|
| - | 5384 | pTIM_CallbackTypeDef pCallback) |
|
| - | 5385 | { |
|
| - | 5386 | HAL_StatusTypeDef status = HAL_OK; |
|
| - | 5387 | ||
| - | 5388 | if (pCallback == NULL) |
|
| - | 5389 | { |
|
| - | 5390 | return HAL_ERROR; |
|
| - | 5391 | } |
|
| - | 5392 | /* Process locked */ |
|
| - | 5393 | __HAL_LOCK(htim); |
|
| - | 5394 | ||
| - | 5395 | if (htim->State == HAL_TIM_STATE_READY) |
|
| - | 5396 | { |
|
| - | 5397 | switch (CallbackID) |
|
| - | 5398 | { |
|
| - | 5399 | case HAL_TIM_BASE_MSPINIT_CB_ID : |
|
| - | 5400 | htim->Base_MspInitCallback = pCallback; |
|
| - | 5401 | break; |
|
| - | 5402 | ||
| - | 5403 | case HAL_TIM_BASE_MSPDEINIT_CB_ID : |
|
| - | 5404 | htim->Base_MspDeInitCallback = pCallback; |
|
| - | 5405 | break; |
|
| - | 5406 | ||
| - | 5407 | case HAL_TIM_IC_MSPINIT_CB_ID : |
|
| - | 5408 | htim->IC_MspInitCallback = pCallback; |
|
| - | 5409 | break; |
|
| - | 5410 | ||
| - | 5411 | case HAL_TIM_IC_MSPDEINIT_CB_ID : |
|
| - | 5412 | htim->IC_MspDeInitCallback = pCallback; |
|
| - | 5413 | break; |
|
| - | 5414 | ||
| - | 5415 | case HAL_TIM_OC_MSPINIT_CB_ID : |
|
| - | 5416 | htim->OC_MspInitCallback = pCallback; |
|
| - | 5417 | break; |
|
| - | 5418 | ||
| - | 5419 | case HAL_TIM_OC_MSPDEINIT_CB_ID : |
|
| - | 5420 | htim->OC_MspDeInitCallback = pCallback; |
|
| - | 5421 | break; |
|
| - | 5422 | ||
| - | 5423 | case HAL_TIM_PWM_MSPINIT_CB_ID : |
|
| - | 5424 | htim->PWM_MspInitCallback = pCallback; |
|
| - | 5425 | break; |
|
| - | 5426 | ||
| - | 5427 | case HAL_TIM_PWM_MSPDEINIT_CB_ID : |
|
| - | 5428 | htim->PWM_MspDeInitCallback = pCallback; |
|
| - | 5429 | break; |
|
| - | 5430 | ||
| - | 5431 | case HAL_TIM_ONE_PULSE_MSPINIT_CB_ID : |
|
| - | 5432 | htim->OnePulse_MspInitCallback = pCallback; |
|
| - | 5433 | break; |
|
| - | 5434 | ||
| - | 5435 | case HAL_TIM_ONE_PULSE_MSPDEINIT_CB_ID : |
|
| - | 5436 | htim->OnePulse_MspDeInitCallback = pCallback; |
|
| - | 5437 | break; |
|
| - | 5438 | ||
| - | 5439 | case HAL_TIM_ENCODER_MSPINIT_CB_ID : |
|
| - | 5440 | htim->Encoder_MspInitCallback = pCallback; |
|
| - | 5441 | break; |
|
| - | 5442 | ||
| - | 5443 | case HAL_TIM_ENCODER_MSPDEINIT_CB_ID : |
|
| - | 5444 | htim->Encoder_MspDeInitCallback = pCallback; |
|
| - | 5445 | break; |
|
| - | 5446 | ||
| - | 5447 | case HAL_TIM_PERIOD_ELAPSED_CB_ID : |
|
| - | 5448 | htim->PeriodElapsedCallback = pCallback; |
|
| - | 5449 | break; |
|
| - | 5450 | ||
| - | 5451 | case HAL_TIM_PERIOD_ELAPSED_HALF_CB_ID : |
|
| - | 5452 | htim->PeriodElapsedHalfCpltCallback = pCallback; |
|
| - | 5453 | break; |
|
| - | 5454 | ||
| - | 5455 | case HAL_TIM_TRIGGER_CB_ID : |
|
| - | 5456 | htim->TriggerCallback = pCallback; |
|
| - | 5457 | break; |
|
| - | 5458 | ||
| - | 5459 | case HAL_TIM_TRIGGER_HALF_CB_ID : |
|
| - | 5460 | htim->TriggerHalfCpltCallback = pCallback; |
|
| - | 5461 | break; |
|
| - | 5462 | ||
| - | 5463 | case HAL_TIM_IC_CAPTURE_CB_ID : |
|
| - | 5464 | htim->IC_CaptureCallback = pCallback; |
|
| - | 5465 | break; |
|
| - | 5466 | ||
| - | 5467 | case HAL_TIM_IC_CAPTURE_HALF_CB_ID : |
|
| - | 5468 | htim->IC_CaptureHalfCpltCallback = pCallback; |
|
| - | 5469 | break; |
|
| - | 5470 | ||
| - | 5471 | case HAL_TIM_OC_DELAY_ELAPSED_CB_ID : |
|
| - | 5472 | htim->OC_DelayElapsedCallback = pCallback; |
|
| - | 5473 | break; |
|
| - | 5474 | ||
| - | 5475 | case HAL_TIM_PWM_PULSE_FINISHED_CB_ID : |
|
| - | 5476 | htim->PWM_PulseFinishedCallback = pCallback; |
|
| - | 5477 | break; |
|
| - | 5478 | ||
| - | 5479 | case HAL_TIM_PWM_PULSE_FINISHED_HALF_CB_ID : |
|
| - | 5480 | htim->PWM_PulseFinishedHalfCpltCallback = pCallback; |
|
| - | 5481 | break; |
|
| - | 5482 | ||
| - | 5483 | case HAL_TIM_ERROR_CB_ID : |
|
| - | 5484 | htim->ErrorCallback = pCallback; |
|
| - | 5485 | break; |
|
| - | 5486 | ||
| - | 5487 | default : |
|
| - | 5488 | /* Return error status */ |
|
| - | 5489 | status = HAL_ERROR; |
|
| - | 5490 | break; |
|
| - | 5491 | } |
|
| - | 5492 | } |
|
| - | 5493 | else if (htim->State == HAL_TIM_STATE_RESET) |
|
| - | 5494 | { |
|
| - | 5495 | switch (CallbackID) |
|
| - | 5496 | { |
|
| - | 5497 | case HAL_TIM_BASE_MSPINIT_CB_ID : |
|
| - | 5498 | htim->Base_MspInitCallback = pCallback; |
|
| - | 5499 | break; |
|
| - | 5500 | ||
| - | 5501 | case HAL_TIM_BASE_MSPDEINIT_CB_ID : |
|
| - | 5502 | htim->Base_MspDeInitCallback = pCallback; |
|
| - | 5503 | break; |
|
| - | 5504 | ||
| - | 5505 | case HAL_TIM_IC_MSPINIT_CB_ID : |
|
| - | 5506 | htim->IC_MspInitCallback = pCallback; |
|
| - | 5507 | break; |
|
| - | 5508 | ||
| - | 5509 | case HAL_TIM_IC_MSPDEINIT_CB_ID : |
|
| - | 5510 | htim->IC_MspDeInitCallback = pCallback; |
|
| - | 5511 | break; |
|
| - | 5512 | ||
| - | 5513 | case HAL_TIM_OC_MSPINIT_CB_ID : |
|
| - | 5514 | htim->OC_MspInitCallback = pCallback; |
|
| - | 5515 | break; |
|
| - | 5516 | ||
| - | 5517 | case HAL_TIM_OC_MSPDEINIT_CB_ID : |
|
| - | 5518 | htim->OC_MspDeInitCallback = pCallback; |
|
| - | 5519 | break; |
|
| - | 5520 | ||
| - | 5521 | case HAL_TIM_PWM_MSPINIT_CB_ID : |
|
| - | 5522 | htim->PWM_MspInitCallback = pCallback; |
|
| - | 5523 | break; |
|
| - | 5524 | ||
| - | 5525 | case HAL_TIM_PWM_MSPDEINIT_CB_ID : |
|
| - | 5526 | htim->PWM_MspDeInitCallback = pCallback; |
|
| - | 5527 | break; |
|
| - | 5528 | ||
| - | 5529 | case HAL_TIM_ONE_PULSE_MSPINIT_CB_ID : |
|
| - | 5530 | htim->OnePulse_MspInitCallback = pCallback; |
|
| - | 5531 | break; |
|
| - | 5532 | ||
| - | 5533 | case HAL_TIM_ONE_PULSE_MSPDEINIT_CB_ID : |
|
| - | 5534 | htim->OnePulse_MspDeInitCallback = pCallback; |
|
| - | 5535 | break; |
|
| - | 5536 | ||
| - | 5537 | case HAL_TIM_ENCODER_MSPINIT_CB_ID : |
|
| - | 5538 | htim->Encoder_MspInitCallback = pCallback; |
|
| - | 5539 | break; |
|
| - | 5540 | ||
| - | 5541 | case HAL_TIM_ENCODER_MSPDEINIT_CB_ID : |
|
| - | 5542 | htim->Encoder_MspDeInitCallback = pCallback; |
|
| - | 5543 | break; |
|
| - | 5544 | ||
| - | 5545 | default : |
|
| - | 5546 | /* Return error status */ |
|
| - | 5547 | status = HAL_ERROR; |
|
| - | 5548 | break; |
|
| - | 5549 | } |
|
| - | 5550 | } |
|
| - | 5551 | else |
|
| - | 5552 | { |
|
| - | 5553 | /* Return error status */ |
|
| - | 5554 | status = HAL_ERROR; |
|
| - | 5555 | } |
|
| - | 5556 | ||
| - | 5557 | /* Release Lock */ |
|
| - | 5558 | __HAL_UNLOCK(htim); |
|
| - | 5559 | ||
| - | 5560 | return status; |
|
| - | 5561 | } |
|
| - | 5562 | ||
| - | 5563 | /** |
|
| - | 5564 | * @brief Unregister a TIM callback |
|
| - | 5565 | * TIM callback is redirected to the weak predefined callback |
|
| - | 5566 | * @param htim tim handle |
|
| - | 5567 | * @param CallbackID ID of the callback to be unregistered |
|
| - | 5568 | * This parameter can be one of the following values: |
|
| - | 5569 | * @arg @ref HAL_TIM_BASE_MSPINIT_CB_ID Base MspInit Callback ID |
|
| - | 5570 | * @arg @ref HAL_TIM_BASE_MSPDEINIT_CB_ID Base MspDeInit Callback ID |
|
| - | 5571 | * @arg @ref HAL_TIM_IC_MSPINIT_CB_ID IC MspInit Callback ID |
|
| - | 5572 | * @arg @ref HAL_TIM_IC_MSPDEINIT_CB_ID IC MspDeInit Callback ID |
|
| - | 5573 | * @arg @ref HAL_TIM_OC_MSPINIT_CB_ID OC MspInit Callback ID |
|
| - | 5574 | * @arg @ref HAL_TIM_OC_MSPDEINIT_CB_ID OC MspDeInit Callback ID |
|
| - | 5575 | * @arg @ref HAL_TIM_PWM_MSPINIT_CB_ID PWM MspInit Callback ID |
|
| - | 5576 | * @arg @ref HAL_TIM_PWM_MSPDEINIT_CB_ID PWM MspDeInit Callback ID |
|
| - | 5577 | * @arg @ref HAL_TIM_ONE_PULSE_MSPINIT_CB_ID One Pulse MspInit Callback ID |
|
| - | 5578 | * @arg @ref HAL_TIM_ONE_PULSE_MSPDEINIT_CB_ID One Pulse MspDeInit Callback ID |
|
| - | 5579 | * @arg @ref HAL_TIM_ENCODER_MSPINIT_CB_ID Encoder MspInit Callback ID |
|
| - | 5580 | * @arg @ref HAL_TIM_ENCODER_MSPDEINIT_CB_ID Encoder MspDeInit Callback ID |
|
| - | 5581 | * @arg @ref HAL_TIM_PERIOD_ELAPSED_CB_ID Period Elapsed Callback ID |
|
| - | 5582 | * @arg @ref HAL_TIM_PERIOD_ELAPSED_HALF_CB_ID Period Elapsed half complete Callback ID |
|
| - | 5583 | * @arg @ref HAL_TIM_TRIGGER_CB_ID Trigger Callback ID |
|
| - | 5584 | * @arg @ref HAL_TIM_TRIGGER_HALF_CB_ID Trigger half complete Callback ID |
|
| - | 5585 | * @arg @ref HAL_TIM_IC_CAPTURE_CB_ID Input Capture Callback ID |
|
| - | 5586 | * @arg @ref HAL_TIM_IC_CAPTURE_HALF_CB_ID Input Capture half complete Callback ID |
|
| - | 5587 | * @arg @ref HAL_TIM_OC_DELAY_ELAPSED_CB_ID Output Compare Delay Elapsed Callback ID |
|
| - | 5588 | * @arg @ref HAL_TIM_PWM_PULSE_FINISHED_CB_ID PWM Pulse Finished Callback ID |
|
| - | 5589 | * @arg @ref HAL_TIM_PWM_PULSE_FINISHED_HALF_CB_ID PWM Pulse Finished half complete Callback ID |
|
| - | 5590 | * @arg @ref HAL_TIM_ERROR_CB_ID Error Callback ID |
|
| - | 5591 | * @retval status |
|
| - | 5592 | */ |
|
| - | 5593 | HAL_StatusTypeDef HAL_TIM_UnRegisterCallback(TIM_HandleTypeDef *htim, HAL_TIM_CallbackIDTypeDef CallbackID) |
|
| - | 5594 | { |
|
| - | 5595 | HAL_StatusTypeDef status = HAL_OK; |
|
| - | 5596 | ||
| - | 5597 | /* Process locked */ |
|
| - | 5598 | __HAL_LOCK(htim); |
|
| - | 5599 | ||
| - | 5600 | if (htim->State == HAL_TIM_STATE_READY) |
|
| - | 5601 | { |
|
| - | 5602 | switch (CallbackID) |
|
| - | 5603 | { |
|
| - | 5604 | case HAL_TIM_BASE_MSPINIT_CB_ID : |
|
| - | 5605 | htim->Base_MspInitCallback = HAL_TIM_Base_MspInit; /* Legacy weak Base MspInit Callback */ |
|
| - | 5606 | break; |
|
| - | 5607 | ||
| - | 5608 | case HAL_TIM_BASE_MSPDEINIT_CB_ID : |
|
| - | 5609 | htim->Base_MspDeInitCallback = HAL_TIM_Base_MspDeInit; /* Legacy weak Base Msp DeInit Callback */ |
|
| - | 5610 | break; |
|
| - | 5611 | ||
| - | 5612 | case HAL_TIM_IC_MSPINIT_CB_ID : |
|
| - | 5613 | htim->IC_MspInitCallback = HAL_TIM_IC_MspInit; /* Legacy weak IC Msp Init Callback */ |
|
| - | 5614 | break; |
|
| - | 5615 | ||
| - | 5616 | case HAL_TIM_IC_MSPDEINIT_CB_ID : |
|
| - | 5617 | htim->IC_MspDeInitCallback = HAL_TIM_IC_MspDeInit; /* Legacy weak IC Msp DeInit Callback */ |
|
| - | 5618 | break; |
|
| - | 5619 | ||
| - | 5620 | case HAL_TIM_OC_MSPINIT_CB_ID : |
|
| - | 5621 | htim->OC_MspInitCallback = HAL_TIM_OC_MspInit; /* Legacy weak OC Msp Init Callback */ |
|
| - | 5622 | break; |
|
| - | 5623 | ||
| - | 5624 | case HAL_TIM_OC_MSPDEINIT_CB_ID : |
|
| - | 5625 | htim->OC_MspDeInitCallback = HAL_TIM_OC_MspDeInit; /* Legacy weak OC Msp DeInit Callback */ |
|
| - | 5626 | break; |
|
| - | 5627 | ||
| - | 5628 | case HAL_TIM_PWM_MSPINIT_CB_ID : |
|
| - | 5629 | htim->PWM_MspInitCallback = HAL_TIM_PWM_MspInit; /* Legacy weak PWM Msp Init Callback */ |
|
| - | 5630 | break; |
|
| - | 5631 | ||
| - | 5632 | case HAL_TIM_PWM_MSPDEINIT_CB_ID : |
|
| - | 5633 | htim->PWM_MspDeInitCallback = HAL_TIM_PWM_MspDeInit; /* Legacy weak PWM Msp DeInit Callback */ |
|
| - | 5634 | break; |
|
| - | 5635 | ||
| - | 5636 | case HAL_TIM_ONE_PULSE_MSPINIT_CB_ID : |
|
| - | 5637 | htim->OnePulse_MspInitCallback = HAL_TIM_OnePulse_MspInit; /* Legacy weak One Pulse Msp Init Callback */ |
|
| - | 5638 | break; |
|
| - | 5639 | ||
| - | 5640 | case HAL_TIM_ONE_PULSE_MSPDEINIT_CB_ID : |
|
| - | 5641 | htim->OnePulse_MspDeInitCallback = HAL_TIM_OnePulse_MspDeInit; /* Legacy weak One Pulse Msp DeInit Callback */ |
|
| - | 5642 | break; |
|
| - | 5643 | ||
| - | 5644 | case HAL_TIM_ENCODER_MSPINIT_CB_ID : |
|
| - | 5645 | htim->Encoder_MspInitCallback = HAL_TIM_Encoder_MspInit; /* Legacy weak Encoder Msp Init Callback */ |
|
| - | 5646 | break; |
|
| - | 5647 | ||
| - | 5648 | case HAL_TIM_ENCODER_MSPDEINIT_CB_ID : |
|
| - | 5649 | htim->Encoder_MspDeInitCallback = HAL_TIM_Encoder_MspDeInit; /* Legacy weak Encoder Msp DeInit Callback */ |
|
| - | 5650 | break; |
|
| - | 5651 | ||
| - | 5652 | case HAL_TIM_PERIOD_ELAPSED_CB_ID : |
|
| - | 5653 | htim->PeriodElapsedCallback = HAL_TIM_PeriodElapsedCallback; /* Legacy weak Period Elapsed Callback */ |
|
| - | 5654 | break; |
|
| - | 5655 | ||
| - | 5656 | case HAL_TIM_PERIOD_ELAPSED_HALF_CB_ID : |
|
| - | 5657 | htim->PeriodElapsedHalfCpltCallback = HAL_TIM_PeriodElapsedHalfCpltCallback; /* Legacy weak Period Elapsed half complete Callback */ |
|
| - | 5658 | break; |
|
| - | 5659 | ||
| - | 5660 | case HAL_TIM_TRIGGER_CB_ID : |
|
| - | 5661 | htim->TriggerCallback = HAL_TIM_TriggerCallback; /* Legacy weak Trigger Callback */ |
|
| - | 5662 | break; |
|
| - | 5663 | ||
| - | 5664 | case HAL_TIM_TRIGGER_HALF_CB_ID : |
|
| - | 5665 | htim->TriggerHalfCpltCallback = HAL_TIM_TriggerHalfCpltCallback; /* Legacy weak Trigger half complete Callback */ |
|
| - | 5666 | break; |
|
| - | 5667 | ||
| - | 5668 | case HAL_TIM_IC_CAPTURE_CB_ID : |
|
| - | 5669 | htim->IC_CaptureCallback = HAL_TIM_IC_CaptureCallback; /* Legacy weak IC Capture Callback */ |
|
| - | 5670 | break; |
|
| - | 5671 | ||
| - | 5672 | case HAL_TIM_IC_CAPTURE_HALF_CB_ID : |
|
| - | 5673 | htim->IC_CaptureHalfCpltCallback = HAL_TIM_IC_CaptureHalfCpltCallback; /* Legacy weak IC Capture half complete Callback */ |
|
| - | 5674 | break; |
|
| - | 5675 | ||
| - | 5676 | case HAL_TIM_OC_DELAY_ELAPSED_CB_ID : |
|
| - | 5677 | htim->OC_DelayElapsedCallback = HAL_TIM_OC_DelayElapsedCallback; /* Legacy weak OC Delay Elapsed Callback */ |
|
| - | 5678 | break; |
|
| - | 5679 | ||
| - | 5680 | case HAL_TIM_PWM_PULSE_FINISHED_CB_ID : |
|
| - | 5681 | htim->PWM_PulseFinishedCallback = HAL_TIM_PWM_PulseFinishedCallback; /* Legacy weak PWM Pulse Finished Callback */ |
|
| - | 5682 | break; |
|
| - | 5683 | ||
| - | 5684 | case HAL_TIM_PWM_PULSE_FINISHED_HALF_CB_ID : |
|
| - | 5685 | htim->PWM_PulseFinishedHalfCpltCallback = HAL_TIM_PWM_PulseFinishedHalfCpltCallback; /* Legacy weak PWM Pulse Finished half complete Callback */ |
|
| - | 5686 | break; |
|
| - | 5687 | ||
| - | 5688 | case HAL_TIM_ERROR_CB_ID : |
|
| - | 5689 | htim->ErrorCallback = HAL_TIM_ErrorCallback; /* Legacy weak Error Callback */ |
|
| - | 5690 | break; |
|
| - | 5691 | ||
| - | 5692 | default : |
|
| - | 5693 | /* Return error status */ |
|
| - | 5694 | status = HAL_ERROR; |
|
| - | 5695 | break; |
|
| - | 5696 | } |
|
| - | 5697 | } |
|
| - | 5698 | else if (htim->State == HAL_TIM_STATE_RESET) |
|
| - | 5699 | { |
|
| - | 5700 | switch (CallbackID) |
|
| - | 5701 | { |
|
| - | 5702 | case HAL_TIM_BASE_MSPINIT_CB_ID : |
|
| - | 5703 | htim->Base_MspInitCallback = HAL_TIM_Base_MspInit; /* Legacy weak Base MspInit Callback */ |
|
| - | 5704 | break; |
|
| - | 5705 | ||
| - | 5706 | case HAL_TIM_BASE_MSPDEINIT_CB_ID : |
|
| - | 5707 | htim->Base_MspDeInitCallback = HAL_TIM_Base_MspDeInit; /* Legacy weak Base Msp DeInit Callback */ |
|
| - | 5708 | break; |
|
| - | 5709 | ||
| - | 5710 | case HAL_TIM_IC_MSPINIT_CB_ID : |
|
| - | 5711 | htim->IC_MspInitCallback = HAL_TIM_IC_MspInit; /* Legacy weak IC Msp Init Callback */ |
|
| - | 5712 | break; |
|
| - | 5713 | ||
| - | 5714 | case HAL_TIM_IC_MSPDEINIT_CB_ID : |
|
| - | 5715 | htim->IC_MspDeInitCallback = HAL_TIM_IC_MspDeInit; /* Legacy weak IC Msp DeInit Callback */ |
|
| - | 5716 | break; |
|
| - | 5717 | ||
| - | 5718 | case HAL_TIM_OC_MSPINIT_CB_ID : |
|
| - | 5719 | htim->OC_MspInitCallback = HAL_TIM_OC_MspInit; /* Legacy weak OC Msp Init Callback */ |
|
| - | 5720 | break; |
|
| - | 5721 | ||
| - | 5722 | case HAL_TIM_OC_MSPDEINIT_CB_ID : |
|
| - | 5723 | htim->OC_MspDeInitCallback = HAL_TIM_OC_MspDeInit; /* Legacy weak OC Msp DeInit Callback */ |
|
| - | 5724 | break; |
|
| - | 5725 | ||
| - | 5726 | case HAL_TIM_PWM_MSPINIT_CB_ID : |
|
| - | 5727 | htim->PWM_MspInitCallback = HAL_TIM_PWM_MspInit; /* Legacy weak PWM Msp Init Callback */ |
|
| - | 5728 | break; |
|
| - | 5729 | ||
| - | 5730 | case HAL_TIM_PWM_MSPDEINIT_CB_ID : |
|
| - | 5731 | htim->PWM_MspDeInitCallback = HAL_TIM_PWM_MspDeInit; /* Legacy weak PWM Msp DeInit Callback */ |
|
| - | 5732 | break; |
|
| - | 5733 | ||
| - | 5734 | case HAL_TIM_ONE_PULSE_MSPINIT_CB_ID : |
|
| - | 5735 | htim->OnePulse_MspInitCallback = HAL_TIM_OnePulse_MspInit; /* Legacy weak One Pulse Msp Init Callback */ |
|
| - | 5736 | break; |
|
| - | 5737 | ||
| - | 5738 | case HAL_TIM_ONE_PULSE_MSPDEINIT_CB_ID : |
|
| - | 5739 | htim->OnePulse_MspDeInitCallback = HAL_TIM_OnePulse_MspDeInit; /* Legacy weak One Pulse Msp DeInit Callback */ |
|
| - | 5740 | break; |
|
| - | 5741 | ||
| - | 5742 | case HAL_TIM_ENCODER_MSPINIT_CB_ID : |
|
| - | 5743 | htim->Encoder_MspInitCallback = HAL_TIM_Encoder_MspInit; /* Legacy weak Encoder Msp Init Callback */ |
|
| - | 5744 | break; |
|
| - | 5745 | ||
| - | 5746 | case HAL_TIM_ENCODER_MSPDEINIT_CB_ID : |
|
| - | 5747 | htim->Encoder_MspDeInitCallback = HAL_TIM_Encoder_MspDeInit; /* Legacy weak Encoder Msp DeInit Callback */ |
|
| - | 5748 | break; |
|
| - | 5749 | ||
| - | 5750 | default : |
|
| - | 5751 | /* Return error status */ |
|
| - | 5752 | status = HAL_ERROR; |
|
| - | 5753 | break; |
|
| - | 5754 | } |
|
| - | 5755 | } |
|
| - | 5756 | else |
|
| - | 5757 | { |
|
| - | 5758 | /* Return error status */ |
|
| - | 5759 | status = HAL_ERROR; |
|
| - | 5760 | } |
|
| - | 5761 | ||
| - | 5762 | /* Release Lock */ |
|
| - | 5763 | __HAL_UNLOCK(htim); |
|
| - | 5764 | ||
| - | 5765 | return status; |
|
| - | 5766 | } |
|
| - | 5767 | #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */ |
|
| - | 5768 | ||
| 4251 | /** |
5769 | /** |
| 4252 | * @} |
5770 | * @} |
| 4253 | */ |
5771 | */ |
| 4254 | 5772 | ||
| 4255 | /** @defgroup TIM_Exported_Functions_Group10 Peripheral State functions |
5773 | /** @defgroup TIM_Exported_Functions_Group10 TIM Peripheral State functions |
| 4256 | * @brief Peripheral State functions |
5774 | * @brief TIM Peripheral State functions |
| 4257 | * |
5775 | * |
| 4258 | @verbatim |
5776 | @verbatim |
| 4259 | ============================================================================== |
5777 | ============================================================================== |
| 4260 | ##### Peripheral State functions ##### |
5778 | ##### Peripheral State functions ##### |
| 4261 | ============================================================================== |
5779 | ============================================================================== |
| 4262 | [..] |
5780 | [..] |
| 4263 | This subsection permit to get in run-time the status of the peripheral |
5781 | This subsection permits to get in run-time the status of the peripheral |
| 4264 | and the data flow. |
5782 | and the data flow. |
| 4265 | 5783 | ||
| 4266 | @endverbatim |
5784 | @endverbatim |
| 4267 | * @{ |
5785 | * @{ |
| 4268 | */ |
5786 | */ |
| 4269 | 5787 | ||
| 4270 | /** |
5788 | /** |
| 4271 | * @brief Return the TIM Base state |
5789 | * @brief Return the TIM Base handle state. |
| 4272 | * @param htim: TIM Base handle |
5790 | * @param htim TIM Base handle |
| 4273 | * @retval HAL state |
5791 | * @retval HAL state |
| 4274 | */ |
5792 | */ |
| 4275 | HAL_TIM_StateTypeDef HAL_TIM_Base_GetState(TIM_HandleTypeDef *htim) |
5793 | HAL_TIM_StateTypeDef HAL_TIM_Base_GetState(TIM_HandleTypeDef *htim) |
| 4276 | { |
5794 | { |
| 4277 | return htim->State; |
5795 | return htim->State; |
| 4278 | } |
5796 | } |
| 4279 | 5797 | ||
| 4280 | /** |
5798 | /** |
| 4281 | * @brief Return the TIM OC state |
5799 | * @brief Return the TIM OC handle state. |
| 4282 | * @param htim: TIM Ouput Compare handle |
5800 | * @param htim TIM Output Compare handle |
| 4283 | * @retval HAL state |
5801 | * @retval HAL state |
| 4284 | */ |
5802 | */ |
| 4285 | HAL_TIM_StateTypeDef HAL_TIM_OC_GetState(TIM_HandleTypeDef *htim) |
5803 | HAL_TIM_StateTypeDef HAL_TIM_OC_GetState(TIM_HandleTypeDef *htim) |
| 4286 | { |
5804 | { |
| 4287 | return htim->State; |
5805 | return htim->State; |
| 4288 | } |
5806 | } |
| 4289 | 5807 | ||
| 4290 | /** |
5808 | /** |
| 4291 | * @brief Return the TIM PWM state |
5809 | * @brief Return the TIM PWM handle state. |
| 4292 | * @param htim: TIM handle |
5810 | * @param htim TIM handle |
| 4293 | * @retval HAL state |
5811 | * @retval HAL state |
| 4294 | */ |
5812 | */ |
| 4295 | HAL_TIM_StateTypeDef HAL_TIM_PWM_GetState(TIM_HandleTypeDef *htim) |
5813 | HAL_TIM_StateTypeDef HAL_TIM_PWM_GetState(TIM_HandleTypeDef *htim) |
| 4296 | { |
5814 | { |
| 4297 | return htim->State; |
5815 | return htim->State; |
| 4298 | } |
5816 | } |
| 4299 | 5817 | ||
| 4300 | /** |
5818 | /** |
| 4301 | * @brief Return the TIM Input Capture state |
5819 | * @brief Return the TIM Input Capture handle state. |
| 4302 | * @param htim: TIM IC handle |
5820 | * @param htim TIM IC handle |
| 4303 | * @retval HAL state |
5821 | * @retval HAL state |
| 4304 | */ |
5822 | */ |
| 4305 | HAL_TIM_StateTypeDef HAL_TIM_IC_GetState(TIM_HandleTypeDef *htim) |
5823 | HAL_TIM_StateTypeDef HAL_TIM_IC_GetState(TIM_HandleTypeDef *htim) |
| 4306 | { |
5824 | { |
| 4307 | return htim->State; |
5825 | return htim->State; |
| 4308 | } |
5826 | } |
| 4309 | 5827 | ||
| 4310 | /** |
5828 | /** |
| 4311 | * @brief Return the TIM One Pulse Mode state |
5829 | * @brief Return the TIM One Pulse Mode handle state. |
| 4312 | * @param htim: TIM OPM handle |
5830 | * @param htim TIM OPM handle |
| 4313 | * @retval HAL state |
5831 | * @retval HAL state |
| 4314 | */ |
5832 | */ |
| 4315 | HAL_TIM_StateTypeDef HAL_TIM_OnePulse_GetState(TIM_HandleTypeDef *htim) |
5833 | HAL_TIM_StateTypeDef HAL_TIM_OnePulse_GetState(TIM_HandleTypeDef *htim) |
| 4316 | { |
5834 | { |
| 4317 | return htim->State; |
5835 | return htim->State; |
| 4318 | } |
5836 | } |
| 4319 | 5837 | ||
| 4320 | /** |
5838 | /** |
| 4321 | * @brief Return the TIM Encoder Mode state |
5839 | * @brief Return the TIM Encoder Mode handle state. |
| 4322 | * @param htim: TIM Encoder handle |
5840 | * @param htim TIM Encoder Interface handle |
| 4323 | * @retval HAL state |
5841 | * @retval HAL state |
| 4324 | */ |
5842 | */ |
| 4325 | HAL_TIM_StateTypeDef HAL_TIM_Encoder_GetState(TIM_HandleTypeDef *htim) |
5843 | HAL_TIM_StateTypeDef HAL_TIM_Encoder_GetState(TIM_HandleTypeDef *htim) |
| 4326 | { |
5844 | { |
| 4327 | return htim->State; |
5845 | return htim->State; |
| 4328 | } |
5846 | } |
| 4329 | 5847 | ||
| 4330 | /** |
5848 | /** |
| - | 5849 | * @brief Return the TIM Encoder Mode handle state. |
|
| - | 5850 | * @param htim TIM handle |
|
| - | 5851 | * @retval Active channel |
|
| - | 5852 | */ |
|
| - | 5853 | HAL_TIM_ActiveChannel HAL_TIM_GetActiveChannel(TIM_HandleTypeDef *htim) |
|
| - | 5854 | { |
|
| - | 5855 | return htim->Channel; |
|
| - | 5856 | } |
|
| - | 5857 | ||
| - | 5858 | /** |
|
| - | 5859 | * @brief Return actual state of the TIM channel. |
|
| - | 5860 | * @param htim TIM handle |
|
| - | 5861 | * @param Channel TIM Channel |
|
| - | 5862 | * This parameter can be one of the following values: |
|
| - | 5863 | * @arg TIM_CHANNEL_1: TIM Channel 1 |
|
| - | 5864 | * @arg TIM_CHANNEL_2: TIM Channel 2 |
|
| - | 5865 | * @arg TIM_CHANNEL_3: TIM Channel 3 |
|
| - | 5866 | * @arg TIM_CHANNEL_4: TIM Channel 4 |
|
| - | 5867 | * @arg TIM_CHANNEL_5: TIM Channel 5 |
|
| - | 5868 | * @arg TIM_CHANNEL_6: TIM Channel 6 |
|
| - | 5869 | * @retval TIM Channel state |
|
| - | 5870 | */ |
|
| - | 5871 | HAL_TIM_ChannelStateTypeDef HAL_TIM_GetChannelState(TIM_HandleTypeDef *htim, uint32_t Channel) |
|
| - | 5872 | { |
|
| - | 5873 | HAL_TIM_ChannelStateTypeDef channel_state; |
|
| - | 5874 | ||
| - | 5875 | /* Check the parameters */ |
|
| - | 5876 | assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel)); |
|
| - | 5877 | ||
| - | 5878 | channel_state = TIM_CHANNEL_STATE_GET(htim, Channel); |
|
| - | 5879 | ||
| - | 5880 | return channel_state; |
|
| - | 5881 | } |
|
| - | 5882 | ||
| - | 5883 | /** |
|
| - | 5884 | * @brief Return actual state of a DMA burst operation. |
|
| - | 5885 | * @param htim TIM handle |
|
| - | 5886 | * @retval DMA burst state |
|
| - | 5887 | */ |
|
| - | 5888 | HAL_TIM_DMABurstStateTypeDef HAL_TIM_DMABurstState(TIM_HandleTypeDef *htim) |
|
| - | 5889 | { |
|
| - | 5890 | /* Check the parameters */ |
|
| - | 5891 | assert_param(IS_TIM_DMABURST_INSTANCE(htim->Instance)); |
|
| - | 5892 | ||
| - | 5893 | return htim->DMABurstState; |
|
| - | 5894 | } |
|
| - | 5895 | ||
| - | 5896 | /** |
|
| - | 5897 | * @} |
|
| - | 5898 | */ |
|
| - | 5899 | ||
| - | 5900 | /** |
|
| - | 5901 | * @} |
|
| - | 5902 | */ |
|
| - | 5903 | ||
| - | 5904 | /** @defgroup TIM_Private_Functions TIM Private Functions |
|
| - | 5905 | * @{ |
|
| - | 5906 | */ |
|
| - | 5907 | ||
| - | 5908 | /** |
|
| 4331 | * @brief TIM DMA error callback |
5909 | * @brief TIM DMA error callback |
| 4332 | * @param hdma : pointer to DMA handle. |
5910 | * @param hdma pointer to DMA handle. |
| 4333 | * @retval None |
5911 | * @retval None |
| 4334 | */ |
5912 | */ |
| 4335 | void TIM_DMAError(DMA_HandleTypeDef *hdma) |
5913 | void TIM_DMAError(DMA_HandleTypeDef *hdma) |
| 4336 | { |
5914 | { |
| 4337 | TIM_HandleTypeDef* htim = ( TIM_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; |
5915 | TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent; |
| 4338 | 5916 | ||
| - | 5917 | if (hdma == htim->hdma[TIM_DMA_ID_CC1]) |
|
| - | 5918 | { |
|
| - | 5919 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_1; |
|
| - | 5920 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY); |
|
| - | 5921 | } |
|
| - | 5922 | else if (hdma == htim->hdma[TIM_DMA_ID_CC2]) |
|
| - | 5923 | { |
|
| - | 5924 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_2; |
|
| - | 5925 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY); |
|
| - | 5926 | } |
|
| - | 5927 | else if (hdma == htim->hdma[TIM_DMA_ID_CC3]) |
|
| - | 5928 | { |
|
| - | 5929 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_3; |
|
| - | 5930 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_3, HAL_TIM_CHANNEL_STATE_READY); |
|
| - | 5931 | } |
|
| - | 5932 | else if (hdma == htim->hdma[TIM_DMA_ID_CC4]) |
|
| - | 5933 | { |
|
| - | 5934 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_4; |
|
| - | 5935 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_4, HAL_TIM_CHANNEL_STATE_READY); |
|
| - | 5936 | } |
|
| - | 5937 | else |
|
| - | 5938 | { |
|
| 4339 | htim->State= HAL_TIM_STATE_READY; |
5939 | htim->State = HAL_TIM_STATE_READY; |
| - | 5940 | } |
|
| 4340 | 5941 | ||
| - | 5942 | #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) |
|
| - | 5943 | htim->ErrorCallback(htim); |
|
| - | 5944 | #else |
|
| 4341 | HAL_TIM_ErrorCallback(htim); |
5945 | HAL_TIM_ErrorCallback(htim); |
| - | 5946 | #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */ |
|
| - | 5947 | ||
| - | 5948 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED; |
|
| 4342 | } |
5949 | } |
| 4343 | 5950 | ||
| 4344 | /** |
5951 | /** |
| 4345 | * @brief TIM DMA Delay Pulse complete callback. |
5952 | * @brief TIM DMA Delay Pulse complete callback. |
| 4346 | * @param hdma : pointer to DMA handle. |
5953 | * @param hdma pointer to DMA handle. |
| 4347 | * @retval None |
5954 | * @retval None |
| 4348 | */ |
5955 | */ |
| 4349 | void TIM_DMADelayPulseCplt(DMA_HandleTypeDef *hdma) |
5956 | void TIM_DMADelayPulseCplt(DMA_HandleTypeDef *hdma) |
| 4350 | { |
5957 | { |
| 4351 | TIM_HandleTypeDef* htim = ( TIM_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; |
5958 | TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent; |
| 4352 | - | ||
| 4353 | htim->State= HAL_TIM_STATE_READY; |
- | |
| 4354 | 5959 | ||
| 4355 | if (hdma == htim->hdma[TIM_DMA_ID_CC1]) |
5960 | if (hdma == htim->hdma[TIM_DMA_ID_CC1]) |
| 4356 | { |
5961 | { |
| 4357 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_1; |
5962 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_1; |
| - | 5963 | ||
| - | 5964 | if (hdma->Init.Mode == DMA_NORMAL) |
|
| - | 5965 | { |
|
| - | 5966 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY); |
|
| - | 5967 | } |
|
| 4358 | } |
5968 | } |
| 4359 | else if (hdma == htim->hdma[TIM_DMA_ID_CC2]) |
5969 | else if (hdma == htim->hdma[TIM_DMA_ID_CC2]) |
| 4360 | { |
5970 | { |
| 4361 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_2; |
5971 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_2; |
| - | 5972 | ||
| - | 5973 | if (hdma->Init.Mode == DMA_NORMAL) |
|
| - | 5974 | { |
|
| - | 5975 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY); |
|
| - | 5976 | } |
|
| 4362 | } |
5977 | } |
| 4363 | else if (hdma == htim->hdma[TIM_DMA_ID_CC3]) |
5978 | else if (hdma == htim->hdma[TIM_DMA_ID_CC3]) |
| 4364 | { |
5979 | { |
| 4365 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_3; |
5980 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_3; |
| - | 5981 | ||
| - | 5982 | if (hdma->Init.Mode == DMA_NORMAL) |
|
| - | 5983 | { |
|
| - | 5984 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_3, HAL_TIM_CHANNEL_STATE_READY); |
|
| - | 5985 | } |
|
| 4366 | } |
5986 | } |
| 4367 | else if (hdma == htim->hdma[TIM_DMA_ID_CC4]) |
5987 | else if (hdma == htim->hdma[TIM_DMA_ID_CC4]) |
| 4368 | { |
5988 | { |
| 4369 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_4; |
5989 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_4; |
| - | 5990 | ||
| - | 5991 | if (hdma->Init.Mode == DMA_NORMAL) |
|
| - | 5992 | { |
|
| - | 5993 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_4, HAL_TIM_CHANNEL_STATE_READY); |
|
| - | 5994 | } |
|
| - | 5995 | } |
|
| - | 5996 | else |
|
| - | 5997 | { |
|
| - | 5998 | /* nothing to do */ |
|
| 4370 | } |
5999 | } |
| 4371 | 6000 | ||
| - | 6001 | #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) |
|
| - | 6002 | htim->PWM_PulseFinishedCallback(htim); |
|
| - | 6003 | #else |
|
| 4372 | HAL_TIM_PWM_PulseFinishedCallback(htim); |
6004 | HAL_TIM_PWM_PulseFinishedCallback(htim); |
| - | 6005 | #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */ |
|
| - | 6006 | ||
| - | 6007 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED; |
|
| - | 6008 | } |
|
| - | 6009 | ||
| - | 6010 | /** |
|
| - | 6011 | * @brief TIM DMA Delay Pulse half complete callback. |
|
| - | 6012 | * @param hdma pointer to DMA handle. |
|
| - | 6013 | * @retval None |
|
| - | 6014 | */ |
|
| - | 6015 | void TIM_DMADelayPulseHalfCplt(DMA_HandleTypeDef *hdma) |
|
| - | 6016 | { |
|
| - | 6017 | TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent; |
|
| - | 6018 | ||
| - | 6019 | if (hdma == htim->hdma[TIM_DMA_ID_CC1]) |
|
| - | 6020 | { |
|
| - | 6021 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_1; |
|
| - | 6022 | } |
|
| - | 6023 | else if (hdma == htim->hdma[TIM_DMA_ID_CC2]) |
|
| - | 6024 | { |
|
| - | 6025 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_2; |
|
| - | 6026 | } |
|
| - | 6027 | else if (hdma == htim->hdma[TIM_DMA_ID_CC3]) |
|
| - | 6028 | { |
|
| - | 6029 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_3; |
|
| - | 6030 | } |
|
| - | 6031 | else if (hdma == htim->hdma[TIM_DMA_ID_CC4]) |
|
| - | 6032 | { |
|
| - | 6033 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_4; |
|
| - | 6034 | } |
|
| - | 6035 | else |
|
| - | 6036 | { |
|
| - | 6037 | /* nothing to do */ |
|
| - | 6038 | } |
|
| - | 6039 | ||
| - | 6040 | #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) |
|
| - | 6041 | htim->PWM_PulseFinishedHalfCpltCallback(htim); |
|
| - | 6042 | #else |
|
| - | 6043 | HAL_TIM_PWM_PulseFinishedHalfCpltCallback(htim); |
|
| - | 6044 | #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */ |
|
| 4373 | 6045 | ||
| 4374 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED; |
6046 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED; |
| 4375 | } |
6047 | } |
| 4376 | 6048 | ||
| 4377 | /** |
6049 | /** |
| 4378 | * @brief TIM DMA Capture complete callback. |
6050 | * @brief TIM DMA Capture complete callback. |
| 4379 | * @param hdma : pointer to DMA handle. |
6051 | * @param hdma pointer to DMA handle. |
| 4380 | * @retval None |
6052 | * @retval None |
| 4381 | */ |
6053 | */ |
| 4382 | void TIM_DMACaptureCplt(DMA_HandleTypeDef *hdma) |
6054 | void TIM_DMACaptureCplt(DMA_HandleTypeDef *hdma) |
| 4383 | { |
6055 | { |
| 4384 | TIM_HandleTypeDef* htim = ( TIM_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; |
6056 | TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent; |
| 4385 | - | ||
| 4386 | htim->State= HAL_TIM_STATE_READY; |
- | |
| 4387 | 6057 | ||
| 4388 | if (hdma == htim->hdma[TIM_DMA_ID_CC1]) |
6058 | if (hdma == htim->hdma[TIM_DMA_ID_CC1]) |
| 4389 | { |
6059 | { |
| 4390 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_1; |
6060 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_1; |
| - | 6061 | ||
| - | 6062 | if (hdma->Init.Mode == DMA_NORMAL) |
|
| - | 6063 | { |
|
| - | 6064 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY); |
|
| - | 6065 | } |
|
| 4391 | } |
6066 | } |
| 4392 | else if (hdma == htim->hdma[TIM_DMA_ID_CC2]) |
6067 | else if (hdma == htim->hdma[TIM_DMA_ID_CC2]) |
| 4393 | { |
6068 | { |
| 4394 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_2; |
6069 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_2; |
| - | 6070 | ||
| - | 6071 | if (hdma->Init.Mode == DMA_NORMAL) |
|
| - | 6072 | { |
|
| - | 6073 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY); |
|
| - | 6074 | } |
|
| 4395 | } |
6075 | } |
| 4396 | else if (hdma == htim->hdma[TIM_DMA_ID_CC3]) |
6076 | else if (hdma == htim->hdma[TIM_DMA_ID_CC3]) |
| 4397 | { |
6077 | { |
| 4398 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_3; |
6078 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_3; |
| - | 6079 | ||
| - | 6080 | if (hdma->Init.Mode == DMA_NORMAL) |
|
| - | 6081 | { |
|
| - | 6082 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_3, HAL_TIM_CHANNEL_STATE_READY); |
|
| - | 6083 | } |
|
| 4399 | } |
6084 | } |
| 4400 | else if (hdma == htim->hdma[TIM_DMA_ID_CC4]) |
6085 | else if (hdma == htim->hdma[TIM_DMA_ID_CC4]) |
| 4401 | { |
6086 | { |
| 4402 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_4; |
6087 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_4; |
| - | 6088 | ||
| - | 6089 | if (hdma->Init.Mode == DMA_NORMAL) |
|
| - | 6090 | { |
|
| - | 6091 | TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_4, HAL_TIM_CHANNEL_STATE_READY); |
|
| - | 6092 | } |
|
| - | 6093 | } |
|
| - | 6094 | else |
|
| - | 6095 | { |
|
| - | 6096 | /* nothing to do */ |
|
| 4403 | } |
6097 | } |
| 4404 | 6098 | ||
| - | 6099 | #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) |
|
| - | 6100 | htim->IC_CaptureCallback(htim); |
|
| - | 6101 | #else |
|
| 4405 | HAL_TIM_IC_CaptureCallback(htim); |
6102 | HAL_TIM_IC_CaptureCallback(htim); |
| - | 6103 | #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */ |
|
| 4406 | 6104 | ||
| 4407 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED; |
6105 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED; |
| 4408 | } |
6106 | } |
| 4409 | 6107 | ||
| 4410 | /** |
6108 | /** |
| - | 6109 | * @brief TIM DMA Capture half complete callback. |
|
| - | 6110 | * @param hdma pointer to DMA handle. |
|
| 4411 | * @} |
6111 | * @retval None |
| 4412 | */ |
6112 | */ |
| - | 6113 | void TIM_DMACaptureHalfCplt(DMA_HandleTypeDef *hdma) |
|
| - | 6114 | { |
|
| - | 6115 | TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent; |
|
| 4413 | 6116 | ||
| - | 6117 | if (hdma == htim->hdma[TIM_DMA_ID_CC1]) |
|
| - | 6118 | { |
|
| - | 6119 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_1; |
|
| 4414 | /** |
6120 | } |
| - | 6121 | else if (hdma == htim->hdma[TIM_DMA_ID_CC2]) |
|
| - | 6122 | { |
|
| - | 6123 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_2; |
|
| - | 6124 | } |
|
| - | 6125 | else if (hdma == htim->hdma[TIM_DMA_ID_CC3]) |
|
| - | 6126 | { |
|
| - | 6127 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_3; |
|
| - | 6128 | } |
|
| - | 6129 | else if (hdma == htim->hdma[TIM_DMA_ID_CC4]) |
|
| - | 6130 | { |
|
| - | 6131 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_4; |
|
| 4415 | * @} |
6132 | } |
| - | 6133 | else |
|
| - | 6134 | { |
|
| - | 6135 | /* nothing to do */ |
|
| 4416 | */ |
6136 | } |
| 4417 | 6137 | ||
| - | 6138 | #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) |
|
| - | 6139 | htim->IC_CaptureHalfCpltCallback(htim); |
|
| - | 6140 | #else |
|
| - | 6141 | HAL_TIM_IC_CaptureHalfCpltCallback(htim); |
|
| - | 6142 | #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */ |
|
| 4418 | 6143 | ||
| 4419 | /** @addtogroup TIM_Private_Functions |
6144 | htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED; |
| 4420 | * @{ |
- | |
| 4421 | */ |
6145 | } |
| 4422 | 6146 | ||
| 4423 | /** |
6147 | /** |
| 4424 | * @brief TIM DMA Period Elapse complete callback. |
6148 | * @brief TIM DMA Period Elapse complete callback. |
| 4425 | * @param hdma : pointer to DMA handle. |
6149 | * @param hdma pointer to DMA handle. |
| 4426 | * @retval None |
6150 | * @retval None |
| 4427 | */ |
6151 | */ |
| 4428 | static void TIM_DMAPeriodElapsedCplt(DMA_HandleTypeDef *hdma) |
6152 | static void TIM_DMAPeriodElapsedCplt(DMA_HandleTypeDef *hdma) |
| 4429 | { |
6153 | { |
| 4430 | TIM_HandleTypeDef* htim = ( TIM_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; |
6154 | TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent; |
| 4431 | 6155 | ||
| - | 6156 | if (htim->hdma[TIM_DMA_ID_UPDATE]->Init.Mode == DMA_NORMAL) |
|
| - | 6157 | { |
|
| 4432 | htim->State= HAL_TIM_STATE_READY; |
6158 | htim->State = HAL_TIM_STATE_READY; |
| - | 6159 | } |
|
| 4433 | 6160 | ||
| - | 6161 | #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) |
|
| - | 6162 | htim->PeriodElapsedCallback(htim); |
|
| - | 6163 | #else |
|
| 4434 | HAL_TIM_PeriodElapsedCallback(htim); |
6164 | HAL_TIM_PeriodElapsedCallback(htim); |
| - | 6165 | #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */ |
|
| - | 6166 | } |
|
| - | 6167 | ||
| - | 6168 | /** |
|
| - | 6169 | * @brief TIM DMA Period Elapse half complete callback. |
|
| - | 6170 | * @param hdma pointer to DMA handle. |
|
| - | 6171 | * @retval None |
|
| - | 6172 | */ |
|
| - | 6173 | static void TIM_DMAPeriodElapsedHalfCplt(DMA_HandleTypeDef *hdma) |
|
| - | 6174 | { |
|
| - | 6175 | TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent; |
|
| - | 6176 | ||
| - | 6177 | #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) |
|
| - | 6178 | htim->PeriodElapsedHalfCpltCallback(htim); |
|
| - | 6179 | #else |
|
| - | 6180 | HAL_TIM_PeriodElapsedHalfCpltCallback(htim); |
|
| - | 6181 | #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */ |
|
| 4435 | } |
6182 | } |
| 4436 | 6183 | ||
| 4437 | /** |
6184 | /** |
| 4438 | * @brief TIM DMA Trigger callback. |
6185 | * @brief TIM DMA Trigger callback. |
| 4439 | * @param hdma : pointer to DMA handle. |
6186 | * @param hdma pointer to DMA handle. |
| 4440 | * @retval None |
6187 | * @retval None |
| 4441 | */ |
6188 | */ |
| 4442 | static void TIM_DMATriggerCplt(DMA_HandleTypeDef *hdma) |
6189 | static void TIM_DMATriggerCplt(DMA_HandleTypeDef *hdma) |
| 4443 | { |
6190 | { |
| 4444 | TIM_HandleTypeDef* htim = ( TIM_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; |
6191 | TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent; |
| 4445 | 6192 | ||
| - | 6193 | if (htim->hdma[TIM_DMA_ID_TRIGGER]->Init.Mode == DMA_NORMAL) |
|
| - | 6194 | { |
|
| 4446 | htim->State= HAL_TIM_STATE_READY; |
6195 | htim->State = HAL_TIM_STATE_READY; |
| - | 6196 | } |
|
| 4447 | 6197 | ||
| - | 6198 | #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) |
|
| - | 6199 | htim->TriggerCallback(htim); |
|
| - | 6200 | #else |
|
| 4448 | HAL_TIM_TriggerCallback(htim); |
6201 | HAL_TIM_TriggerCallback(htim); |
| - | 6202 | #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */ |
|
| - | 6203 | } |
|
| - | 6204 | ||
| - | 6205 | /** |
|
| - | 6206 | * @brief TIM DMA Trigger half complete callback. |
|
| - | 6207 | * @param hdma pointer to DMA handle. |
|
| - | 6208 | * @retval None |
|
| - | 6209 | */ |
|
| - | 6210 | static void TIM_DMATriggerHalfCplt(DMA_HandleTypeDef *hdma) |
|
| - | 6211 | { |
|
| - | 6212 | TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent; |
|
| - | 6213 | ||
| - | 6214 | #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) |
|
| - | 6215 | htim->TriggerHalfCpltCallback(htim); |
|
| - | 6216 | #else |
|
| - | 6217 | HAL_TIM_TriggerHalfCpltCallback(htim); |
|
| - | 6218 | #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */ |
|
| 4449 | } |
6219 | } |
| 4450 | 6220 | ||
| 4451 | /** |
6221 | /** |
| 4452 | * @brief Time Base configuration |
6222 | * @brief Time Base configuration |
| 4453 | * @param TIMx: TIM periheral |
6223 | * @param TIMx TIM peripheral |
| 4454 | * @param Structure: TIM Base configuration structure |
6224 | * @param Structure TIM Base configuration structure |
| 4455 | * @retval None |
6225 | * @retval None |
| 4456 | */ |
6226 | */ |
| 4457 | static void TIM_Base_SetConfig(TIM_TypeDef *TIMx, TIM_Base_InitTypeDef *Structure) |
6227 | void TIM_Base_SetConfig(TIM_TypeDef *TIMx, TIM_Base_InitTypeDef *Structure) |
| 4458 | { |
6228 | { |
| 4459 | uint32_t tmpcr1 = 0; |
6229 | uint32_t tmpcr1; |
| 4460 | tmpcr1 = TIMx->CR1; |
6230 | tmpcr1 = TIMx->CR1; |
| 4461 | 6231 | ||
| 4462 | /* Set TIM Time Base Unit parameters ---------------------------------------*/ |
6232 | /* Set TIM Time Base Unit parameters ---------------------------------------*/ |
| 4463 | if (IS_TIM_COUNTER_MODE_SELECT_INSTANCE(TIMx)) |
6233 | if (IS_TIM_COUNTER_MODE_SELECT_INSTANCE(TIMx)) |
| 4464 | { |
6234 | { |
| 4465 | /* Select the Counter Mode */ |
6235 | /* Select the Counter Mode */ |
| 4466 | tmpcr1 &= ~(TIM_CR1_DIR | TIM_CR1_CMS); |
6236 | tmpcr1 &= ~(TIM_CR1_DIR | TIM_CR1_CMS); |
| 4467 | tmpcr1 |= Structure->CounterMode; |
6237 | tmpcr1 |= Structure->CounterMode; |
| 4468 | } |
6238 | } |
| 4469 | 6239 | ||
| 4470 | if(IS_TIM_CLOCK_DIVISION_INSTANCE(TIMx)) |
6240 | if (IS_TIM_CLOCK_DIVISION_INSTANCE(TIMx)) |
| 4471 | { |
6241 | { |
| 4472 | /* Set the clock division */ |
6242 | /* Set the clock division */ |
| 4473 | tmpcr1 &= ~TIM_CR1_CKD; |
6243 | tmpcr1 &= ~TIM_CR1_CKD; |
| 4474 | tmpcr1 |= (uint32_t)Structure->ClockDivision; |
6244 | tmpcr1 |= (uint32_t)Structure->ClockDivision; |
| 4475 | } |
6245 | } |
| 4476 | 6246 | ||
| - | 6247 | /* Set the auto-reload preload */ |
|
| - | 6248 | MODIFY_REG(tmpcr1, TIM_CR1_ARPE, Structure->AutoReloadPreload); |
|
| - | 6249 | ||
| 4477 | TIMx->CR1 = tmpcr1; |
6250 | TIMx->CR1 = tmpcr1; |
| 4478 | 6251 | ||
| 4479 | /* Set the Autoreload value */ |
6252 | /* Set the Autoreload value */ |
| 4480 | TIMx->ARR = (uint32_t)Structure->Period ; |
6253 | TIMx->ARR = (uint32_t)Structure->Period ; |
| 4481 | 6254 | ||
| 4482 | /* Set the Prescaler value */ |
6255 | /* Set the Prescaler value */ |
| 4483 | TIMx->PSC = (uint32_t)Structure->Prescaler; |
6256 | TIMx->PSC = Structure->Prescaler; |
| 4484 | 6257 | ||
| 4485 | /* Generate an update event to reload the Prescaler */ |
6258 | /* Generate an update event to reload the Prescaler |
| - | 6259 | and the repetition counter (only for advanced timer) value immediately */ |
|
| 4486 | TIMx->EGR = TIM_EGR_UG; |
6260 | TIMx->EGR = TIM_EGR_UG; |
| 4487 | } |
6261 | } |
| 4488 | 6262 | ||
| 4489 | /** |
6263 | /** |
| 4490 | * @brief Time Ouput Compare 1 configuration |
6264 | * @brief Timer Output Compare 1 configuration |
| 4491 | * @param TIMx to select the TIM peripheral |
6265 | * @param TIMx to select the TIM peripheral |
| 4492 | * @param OC_Config: The ouput configuration structure |
6266 | * @param OC_Config The output configuration structure |
| 4493 | * @retval None |
6267 | * @retval None |
| 4494 | */ |
6268 | */ |
| 4495 | static void TIM_OC1_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config) |
6269 | static void TIM_OC1_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config) |
| 4496 | { |
6270 | { |
| 4497 | uint32_t tmpccmrx = 0; |
6271 | uint32_t tmpccmrx; |
| 4498 | uint32_t tmpccer = 0; |
6272 | uint32_t tmpccer; |
| 4499 | uint32_t tmpcr2 = 0; |
6273 | uint32_t tmpcr2; |
| 4500 | 6274 | ||
| 4501 | /* Disable the Channel 1: Reset the CC1E Bit */ |
6275 | /* Disable the Channel 1: Reset the CC1E Bit */ |
| 4502 | TIMx->CCER &= ~TIM_CCER_CC1E; |
6276 | TIMx->CCER &= ~TIM_CCER_CC1E; |
| 4503 | 6277 | ||
| 4504 | /* Get the TIMx CCER register value */ |
6278 | /* Get the TIMx CCER register value */ |
| 4505 | tmpccer = TIMx->CCER; |
6279 | tmpccer = TIMx->CCER; |
| 4506 | /* Get the TIMx CR2 register value */ |
6280 | /* Get the TIMx CR2 register value */ |
| Line 4532... | Line 6306... | ||
| 4532 | /* Write to TIMx CCER */ |
6306 | /* Write to TIMx CCER */ |
| 4533 | TIMx->CCER = tmpccer; |
6307 | TIMx->CCER = tmpccer; |
| 4534 | } |
6308 | } |
| 4535 | 6309 | ||
| 4536 | /** |
6310 | /** |
| 4537 | * @brief Time Ouput Compare 2 configuration |
6311 | * @brief Timer Output Compare 2 configuration |
| 4538 | * @param TIMx to select the TIM peripheral |
6312 | * @param TIMx to select the TIM peripheral |
| 4539 | * @param OC_Config: The ouput configuration structure |
6313 | * @param OC_Config The output configuration structure |
| 4540 | * @retval None |
6314 | * @retval None |
| 4541 | */ |
6315 | */ |
| 4542 | static void TIM_OC2_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config) |
6316 | static void TIM_OC2_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config) |
| 4543 | { |
6317 | { |
| 4544 | uint32_t tmpccmrx = 0; |
6318 | uint32_t tmpccmrx; |
| 4545 | uint32_t tmpccer = 0; |
6319 | uint32_t tmpccer; |
| 4546 | uint32_t tmpcr2 = 0; |
6320 | uint32_t tmpcr2; |
| 4547 | 6321 | ||
| 4548 | /* Disable the Channel 2: Reset the CC2E Bit */ |
6322 | /* Disable the Channel 2: Reset the CC2E Bit */ |
| 4549 | TIMx->CCER &= ~TIM_CCER_CC2E; |
6323 | TIMx->CCER &= ~TIM_CCER_CC2E; |
| 4550 | 6324 | ||
| 4551 | /* Get the TIMx CCER register value */ |
6325 | /* Get the TIMx CCER register value */ |
| Line 4559... | Line 6333... | ||
| 4559 | /* Reset the Output Compare mode and Capture/Compare selection Bits */ |
6333 | /* Reset the Output Compare mode and Capture/Compare selection Bits */ |
| 4560 | tmpccmrx &= ~TIM_CCMR1_OC2M; |
6334 | tmpccmrx &= ~TIM_CCMR1_OC2M; |
| 4561 | tmpccmrx &= ~TIM_CCMR1_CC2S; |
6335 | tmpccmrx &= ~TIM_CCMR1_CC2S; |
| 4562 | 6336 | ||
| 4563 | /* Select the Output Compare Mode */ |
6337 | /* Select the Output Compare Mode */ |
| 4564 | tmpccmrx |= (OC_Config->OCMode << 8); |
6338 | tmpccmrx |= (OC_Config->OCMode << 8U); |
| 4565 | 6339 | ||
| 4566 | /* Reset the Output Polarity level */ |
6340 | /* Reset the Output Polarity level */ |
| 4567 | tmpccer &= ~TIM_CCER_CC2P; |
6341 | tmpccer &= ~TIM_CCER_CC2P; |
| 4568 | /* Set the Output Compare Polarity */ |
6342 | /* Set the Output Compare Polarity */ |
| 4569 | tmpccer |= (OC_Config->OCPolarity << 4); |
6343 | tmpccer |= (OC_Config->OCPolarity << 4U); |
| 4570 | 6344 | ||
| 4571 | /* Write to TIMx CR2 */ |
6345 | /* Write to TIMx CR2 */ |
| 4572 | TIMx->CR2 = tmpcr2; |
6346 | TIMx->CR2 = tmpcr2; |
| 4573 | 6347 | ||
| 4574 | /* Write to TIMx CCMR1 */ |
6348 | /* Write to TIMx CCMR1 */ |
| Line 4580... | Line 6354... | ||
| 4580 | /* Write to TIMx CCER */ |
6354 | /* Write to TIMx CCER */ |
| 4581 | TIMx->CCER = tmpccer; |
6355 | TIMx->CCER = tmpccer; |
| 4582 | } |
6356 | } |
| 4583 | 6357 | ||
| 4584 | /** |
6358 | /** |
| 4585 | * @brief Time Ouput Compare 3 configuration |
6359 | * @brief Timer Output Compare 3 configuration |
| 4586 | * @param TIMx to select the TIM peripheral |
6360 | * @param TIMx to select the TIM peripheral |
| 4587 | * @param OC_Config: The ouput configuration structure |
6361 | * @param OC_Config The output configuration structure |
| 4588 | * @retval None |
6362 | * @retval None |
| 4589 | */ |
6363 | */ |
| 4590 | static void TIM_OC3_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config) |
6364 | static void TIM_OC3_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config) |
| 4591 | { |
6365 | { |
| 4592 | uint32_t tmpccmrx = 0; |
6366 | uint32_t tmpccmrx; |
| 4593 | uint32_t tmpccer = 0; |
6367 | uint32_t tmpccer; |
| 4594 | uint32_t tmpcr2 = 0; |
6368 | uint32_t tmpcr2; |
| 4595 | 6369 | ||
| 4596 | /* Disable the Channel 3: Reset the CC2E Bit */ |
6370 | /* Disable the Channel 3: Reset the CC2E Bit */ |
| 4597 | TIMx->CCER &= ~TIM_CCER_CC3E; |
6371 | TIMx->CCER &= ~TIM_CCER_CC3E; |
| 4598 | 6372 | ||
| 4599 | /* Get the TIMx CCER register value */ |
6373 | /* Get the TIMx CCER register value */ |
| Line 4611... | Line 6385... | ||
| 4611 | tmpccmrx |= OC_Config->OCMode; |
6385 | tmpccmrx |= OC_Config->OCMode; |
| 4612 | 6386 | ||
| 4613 | /* Reset the Output Polarity level */ |
6387 | /* Reset the Output Polarity level */ |
| 4614 | tmpccer &= ~TIM_CCER_CC3P; |
6388 | tmpccer &= ~TIM_CCER_CC3P; |
| 4615 | /* Set the Output Compare Polarity */ |
6389 | /* Set the Output Compare Polarity */ |
| 4616 | tmpccer |= (OC_Config->OCPolarity << 8); |
6390 | tmpccer |= (OC_Config->OCPolarity << 8U); |
| 4617 | 6391 | ||
| 4618 | /* Write to TIMx CR2 */ |
6392 | /* Write to TIMx CR2 */ |
| 4619 | TIMx->CR2 = tmpcr2; |
6393 | TIMx->CR2 = tmpcr2; |
| 4620 | 6394 | ||
| 4621 | /* Write to TIMx CCMR2 */ |
6395 | /* Write to TIMx CCMR2 */ |
| Line 4627... | Line 6401... | ||
| 4627 | /* Write to TIMx CCER */ |
6401 | /* Write to TIMx CCER */ |
| 4628 | TIMx->CCER = tmpccer; |
6402 | TIMx->CCER = tmpccer; |
| 4629 | } |
6403 | } |
| 4630 | 6404 | ||
| 4631 | /** |
6405 | /** |
| 4632 | * @brief Time Ouput Compare 4 configuration |
6406 | * @brief Timer Output Compare 4 configuration |
| 4633 | * @param TIMx to select the TIM peripheral |
6407 | * @param TIMx to select the TIM peripheral |
| 4634 | * @param OC_Config: The ouput configuration structure |
6408 | * @param OC_Config The output configuration structure |
| 4635 | * @retval None |
6409 | * @retval None |
| 4636 | */ |
6410 | */ |
| 4637 | static void TIM_OC4_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config) |
6411 | static void TIM_OC4_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config) |
| 4638 | { |
6412 | { |
| 4639 | uint32_t tmpccmrx = 0; |
6413 | uint32_t tmpccmrx; |
| 4640 | uint32_t tmpccer = 0; |
6414 | uint32_t tmpccer; |
| 4641 | uint32_t tmpcr2 = 0; |
6415 | uint32_t tmpcr2; |
| 4642 | 6416 | ||
| 4643 | /* Disable the Channel 4: Reset the CC4E Bit */ |
6417 | /* Disable the Channel 4: Reset the CC4E Bit */ |
| 4644 | TIMx->CCER &= ~TIM_CCER_CC4E; |
6418 | TIMx->CCER &= ~TIM_CCER_CC4E; |
| 4645 | 6419 | ||
| 4646 | /* Get the TIMx CCER register value */ |
6420 | /* Get the TIMx CCER register value */ |
| Line 4654... | Line 6428... | ||
| 4654 | /* Reset the Output Compare mode and Capture/Compare selection Bits */ |
6428 | /* Reset the Output Compare mode and Capture/Compare selection Bits */ |
| 4655 | tmpccmrx &= ~TIM_CCMR2_OC4M; |
6429 | tmpccmrx &= ~TIM_CCMR2_OC4M; |
| 4656 | tmpccmrx &= ~TIM_CCMR2_CC4S; |
6430 | tmpccmrx &= ~TIM_CCMR2_CC4S; |
| 4657 | 6431 | ||
| 4658 | /* Select the Output Compare Mode */ |
6432 | /* Select the Output Compare Mode */ |
| 4659 | tmpccmrx |= (OC_Config->OCMode << 8); |
6433 | tmpccmrx |= (OC_Config->OCMode << 8U); |
| 4660 | 6434 | ||
| 4661 | /* Reset the Output Polarity level */ |
6435 | /* Reset the Output Polarity level */ |
| 4662 | tmpccer &= ~TIM_CCER_CC4P; |
6436 | tmpccer &= ~TIM_CCER_CC4P; |
| 4663 | /* Set the Output Compare Polarity */ |
6437 | /* Set the Output Compare Polarity */ |
| 4664 | tmpccer |= (OC_Config->OCPolarity << 12); |
6438 | tmpccer |= (OC_Config->OCPolarity << 12U); |
| 4665 | 6439 | ||
| 4666 | /* Write to TIMx CR2 */ |
6440 | /* Write to TIMx CR2 */ |
| 4667 | TIMx->CR2 = tmpcr2; |
6441 | TIMx->CR2 = tmpcr2; |
| 4668 | 6442 | ||
| 4669 | /* Write to TIMx CCMR2 */ |
6443 | /* Write to TIMx CCMR2 */ |
| Line 4674... | Line 6448... | ||
| 4674 | 6448 | ||
| 4675 | /* Write to TIMx CCER */ |
6449 | /* Write to TIMx CCER */ |
| 4676 | TIMx->CCER = tmpccer; |
6450 | TIMx->CCER = tmpccer; |
| 4677 | } |
6451 | } |
| 4678 | 6452 | ||
| 4679 | - | ||
| 4680 | /** |
6453 | /** |
| 4681 | * @brief Time Slave configuration |
6454 | * @brief Slave Timer configuration function |
| 4682 | * @param htim: pointer to a TIM_HandleTypeDef structure that contains |
6455 | * @param htim TIM handle |
| 4683 | * the configuration information for TIM module. |
- | |
| 4684 | * @param sSlaveConfig: The slave configuration structure |
6456 | * @param sSlaveConfig Slave timer configuration |
| 4685 | * @retval None |
6457 | * @retval None |
| 4686 | */ |
6458 | */ |
| 4687 | static void TIM_SlaveTimer_SetConfig(TIM_HandleTypeDef *htim, |
6459 | static HAL_StatusTypeDef TIM_SlaveTimer_SetConfig(TIM_HandleTypeDef *htim, |
| 4688 | TIM_SlaveConfigTypeDef * sSlaveConfig) |
6460 | TIM_SlaveConfigTypeDef *sSlaveConfig) |
| 4689 | { |
6461 | { |
| 4690 | uint32_t tmpsmcr = 0; |
6462 | uint32_t tmpsmcr; |
| 4691 | uint32_t tmpccmr1 = 0; |
6463 | uint32_t tmpccmr1; |
| 4692 | uint32_t tmpccer = 0; |
6464 | uint32_t tmpccer; |
| 4693 | 6465 | ||
| 4694 | /* Get the TIMx SMCR register value */ |
6466 | /* Get the TIMx SMCR register value */ |
| 4695 | tmpsmcr = htim->Instance->SMCR; |
6467 | tmpsmcr = htim->Instance->SMCR; |
| 4696 | 6468 | ||
| 4697 | /* Reset the Trigger Selection Bits */ |
6469 | /* Reset the Trigger Selection Bits */ |
| 4698 | tmpsmcr &= ~TIM_SMCR_TS; |
6470 | tmpsmcr &= ~TIM_SMCR_TS; |
| 4699 | /* Set the Input Trigger source */ |
6471 | /* Set the Input Trigger source */ |
| Line 4704... | Line 6476... | ||
| 4704 | /* Set the slave mode */ |
6476 | /* Set the slave mode */ |
| 4705 | tmpsmcr |= sSlaveConfig->SlaveMode; |
6477 | tmpsmcr |= sSlaveConfig->SlaveMode; |
| 4706 | 6478 | ||
| 4707 | /* Write to TIMx SMCR */ |
6479 | /* Write to TIMx SMCR */ |
| 4708 | htim->Instance->SMCR = tmpsmcr; |
6480 | htim->Instance->SMCR = tmpsmcr; |
| 4709 | 6481 | ||
| 4710 | /* Configure the trigger prescaler, filter, and polarity */ |
6482 | /* Configure the trigger prescaler, filter, and polarity */ |
| 4711 | switch (sSlaveConfig->InputTrigger) |
6483 | switch (sSlaveConfig->InputTrigger) |
| 4712 | { |
6484 | { |
| 4713 | case TIM_TS_ETRF: |
6485 | case TIM_TS_ETRF: |
| 4714 | { |
6486 | { |
| 4715 | /* Check the parameters */ |
6487 | /* Check the parameters */ |
| 4716 | assert_param(IS_TIM_CLOCKSOURCE_ETRMODE1_INSTANCE(htim->Instance)); |
6488 | assert_param(IS_TIM_CLOCKSOURCE_ETRMODE1_INSTANCE(htim->Instance)); |
| 4717 | assert_param(IS_TIM_TRIGGERPRESCALER(sSlaveConfig->TriggerPrescaler)); |
6489 | assert_param(IS_TIM_TRIGGERPRESCALER(sSlaveConfig->TriggerPrescaler)); |
| 4718 | assert_param(IS_TIM_TRIGGERPOLARITY(sSlaveConfig->TriggerPolarity)); |
6490 | assert_param(IS_TIM_TRIGGERPOLARITY(sSlaveConfig->TriggerPolarity)); |
| 4719 | assert_param(IS_TIM_TRIGGERFILTER(sSlaveConfig->TriggerFilter)); |
6491 | assert_param(IS_TIM_TRIGGERFILTER(sSlaveConfig->TriggerFilter)); |
| 4720 | /* Configure the ETR Trigger source */ |
6492 | /* Configure the ETR Trigger source */ |
| 4721 | TIM_ETR_SetConfig(htim->Instance, |
6493 | TIM_ETR_SetConfig(htim->Instance, |
| 4722 | sSlaveConfig->TriggerPrescaler, |
6494 | sSlaveConfig->TriggerPrescaler, |
| 4723 | sSlaveConfig->TriggerPolarity, |
6495 | sSlaveConfig->TriggerPolarity, |
| 4724 | sSlaveConfig->TriggerFilter); |
6496 | sSlaveConfig->TriggerFilter); |
| - | 6497 | break; |
|
| 4725 | } |
6498 | } |
| 4726 | break; |
- | |
| 4727 | 6499 | ||
| 4728 | case TIM_TS_TI1F_ED: |
6500 | case TIM_TS_TI1F_ED: |
| 4729 | { |
6501 | { |
| 4730 | /* Check the parameters */ |
6502 | /* Check the parameters */ |
| 4731 | assert_param(IS_TIM_CC1_INSTANCE(htim->Instance)); |
6503 | assert_param(IS_TIM_CC1_INSTANCE(htim->Instance)); |
| 4732 | assert_param(IS_TIM_TRIGGERFILTER(sSlaveConfig->TriggerFilter)); |
6504 | assert_param(IS_TIM_TRIGGERFILTER(sSlaveConfig->TriggerFilter)); |
| - | 6505 | ||
| - | 6506 | if (sSlaveConfig->SlaveMode == TIM_SLAVEMODE_GATED) |
|
| - | 6507 | { |
|
| - | 6508 | return HAL_ERROR; |
|
| 4733 | 6509 | } |
|
| - | 6510 | ||
| 4734 | /* Disable the Channel 1: Reset the CC1E Bit */ |
6511 | /* Disable the Channel 1: Reset the CC1E Bit */ |
| 4735 | tmpccer = htim->Instance->CCER; |
6512 | tmpccer = htim->Instance->CCER; |
| 4736 | htim->Instance->CCER &= ~TIM_CCER_CC1E; |
6513 | htim->Instance->CCER &= ~TIM_CCER_CC1E; |
| 4737 | tmpccmr1 = htim->Instance->CCMR1; |
6514 | tmpccmr1 = htim->Instance->CCMR1; |
| 4738 | 6515 | ||
| 4739 | /* Set the filter */ |
6516 | /* Set the filter */ |
| 4740 | tmpccmr1 &= ~TIM_CCMR1_IC1F; |
6517 | tmpccmr1 &= ~TIM_CCMR1_IC1F; |
| 4741 | tmpccmr1 |= ((sSlaveConfig->TriggerFilter) << 4); |
6518 | tmpccmr1 |= ((sSlaveConfig->TriggerFilter) << 4U); |
| 4742 | 6519 | ||
| 4743 | /* Write to TIMx CCMR1 and CCER registers */ |
6520 | /* Write to TIMx CCMR1 and CCER registers */ |
| 4744 | htim->Instance->CCMR1 = tmpccmr1; |
6521 | htim->Instance->CCMR1 = tmpccmr1; |
| 4745 | htim->Instance->CCER = tmpccer; |
6522 | htim->Instance->CCER = tmpccer; |
| 4746 | 6523 | break; |
|
| 4747 | } |
6524 | } |
| 4748 | break; |
- | |
| 4749 | 6525 | ||
| 4750 | case TIM_TS_TI1FP1: |
6526 | case TIM_TS_TI1FP1: |
| 4751 | { |
6527 | { |
| 4752 | /* Check the parameters */ |
6528 | /* Check the parameters */ |
| 4753 | assert_param(IS_TIM_CC1_INSTANCE(htim->Instance)); |
6529 | assert_param(IS_TIM_CC1_INSTANCE(htim->Instance)); |
| 4754 | assert_param(IS_TIM_TRIGGERPOLARITY(sSlaveConfig->TriggerPolarity)); |
6530 | assert_param(IS_TIM_TRIGGERPOLARITY(sSlaveConfig->TriggerPolarity)); |
| 4755 | assert_param(IS_TIM_TRIGGERFILTER(sSlaveConfig->TriggerFilter)); |
6531 | assert_param(IS_TIM_TRIGGERFILTER(sSlaveConfig->TriggerFilter)); |
| 4756 | 6532 | ||
| 4757 | /* Configure TI1 Filter and Polarity */ |
6533 | /* Configure TI1 Filter and Polarity */ |
| 4758 | TIM_TI1_ConfigInputStage(htim->Instance, |
6534 | TIM_TI1_ConfigInputStage(htim->Instance, |
| 4759 | sSlaveConfig->TriggerPolarity, |
6535 | sSlaveConfig->TriggerPolarity, |
| 4760 | sSlaveConfig->TriggerFilter); |
6536 | sSlaveConfig->TriggerFilter); |
| - | 6537 | break; |
|
| 4761 | } |
6538 | } |
| 4762 | break; |
- | |
| 4763 | 6539 | ||
| 4764 | case TIM_TS_TI2FP2: |
6540 | case TIM_TS_TI2FP2: |
| 4765 | { |
6541 | { |
| 4766 | /* Check the parameters */ |
6542 | /* Check the parameters */ |
| 4767 | assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); |
6543 | assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); |
| 4768 | assert_param(IS_TIM_TRIGGERPOLARITY(sSlaveConfig->TriggerPolarity)); |
6544 | assert_param(IS_TIM_TRIGGERPOLARITY(sSlaveConfig->TriggerPolarity)); |
| 4769 | assert_param(IS_TIM_TRIGGERFILTER(sSlaveConfig->TriggerFilter)); |
6545 | assert_param(IS_TIM_TRIGGERFILTER(sSlaveConfig->TriggerFilter)); |
| 4770 | 6546 | ||
| 4771 | /* Configure TI2 Filter and Polarity */ |
6547 | /* Configure TI2 Filter and Polarity */ |
| 4772 | TIM_TI2_ConfigInputStage(htim->Instance, |
6548 | TIM_TI2_ConfigInputStage(htim->Instance, |
| 4773 | sSlaveConfig->TriggerPolarity, |
6549 | sSlaveConfig->TriggerPolarity, |
| 4774 | sSlaveConfig->TriggerFilter); |
6550 | sSlaveConfig->TriggerFilter); |
| 4775 | } |
- | |
| 4776 | break; |
- | |
| 4777 | - | ||
| 4778 | case TIM_TS_ITR0: |
- | |
| 4779 | { |
- | |
| 4780 | /* Check the parameter */ |
- | |
| 4781 | assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); |
- | |
| 4782 | } |
- | |
| 4783 | break; |
- | |
| 4784 | - | ||
| 4785 | case TIM_TS_ITR1: |
- | |
| 4786 | { |
- | |
| 4787 | /* Check the parameter */ |
- | |
| 4788 | assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); |
- | |
| 4789 | } |
- | |
| 4790 | break; |
- | |
| 4791 | - | ||
| 4792 | case TIM_TS_ITR2: |
- | |
| 4793 | { |
- | |
| 4794 | /* Check the parameter */ |
- | |
| 4795 | assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); |
- | |
| 4796 | } |
- | |
| 4797 | break; |
6551 | break; |
| 4798 | - | ||
| 4799 | case TIM_TS_ITR3: |
- | |
| 4800 | { |
- | |
| 4801 | /* Check the parameter */ |
- | |
| 4802 | assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); |
- | |
| 4803 | } |
6552 | } |
| - | 6553 | ||
| - | 6554 | case TIM_TS_ITR0: |
|
| - | 6555 | case TIM_TS_ITR1: |
|
| - | 6556 | case TIM_TS_ITR2: |
|
| - | 6557 | case TIM_TS_ITR3: |
|
| - | 6558 | { |
|
| - | 6559 | /* Check the parameter */ |
|
| - | 6560 | assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); |
|
| 4804 | break; |
6561 | break; |
| 4805 | 6562 | } |
|
| - | 6563 | ||
| 4806 | default: |
6564 | default: |
| 4807 | break; |
6565 | break; |
| 4808 | } |
6566 | } |
| - | 6567 | return HAL_OK; |
|
| 4809 | } |
6568 | } |
| 4810 | 6569 | ||
| 4811 | /** |
6570 | /** |
| 4812 | * @brief Configure the TI1 as Input. |
6571 | * @brief Configure the TI1 as Input. |
| 4813 | * @param TIMx to select the TIM peripheral. |
6572 | * @param TIMx to select the TIM peripheral. |
| 4814 | * @param TIM_ICPolarity : The Input Polarity. |
6573 | * @param TIM_ICPolarity The Input Polarity. |
| 4815 | * This parameter can be one of the following values: |
6574 | * This parameter can be one of the following values: |
| 4816 | * @arg TIM_ICPOLARITY_RISING |
6575 | * @arg TIM_ICPOLARITY_RISING |
| 4817 | * @arg TIM_ICPOLARITY_FALLING |
6576 | * @arg TIM_ICPOLARITY_FALLING |
| 4818 | * @arg TIM_ICPOLARITY_BOTHEDGE |
6577 | * @arg TIM_ICPOLARITY_BOTHEDGE |
| 4819 | * @param TIM_ICSelection: specifies the input to be used. |
6578 | * @param TIM_ICSelection specifies the input to be used. |
| 4820 | * This parameter can be one of the following values: |
6579 | * This parameter can be one of the following values: |
| 4821 | * @arg TIM_ICSELECTION_DIRECTTI: TIM Input 1 is selected to be connected to IC1. |
6580 | * @arg TIM_ICSELECTION_DIRECTTI: TIM Input 1 is selected to be connected to IC1. |
| 4822 | * @arg TIM_ICSELECTION_INDIRECTTI: TIM Input 1 is selected to be connected to IC2. |
6581 | * @arg TIM_ICSELECTION_INDIRECTTI: TIM Input 1 is selected to be connected to IC2. |
| 4823 | * @arg TIM_ICSELECTION_TRC: TIM Input 1 is selected to be connected to TRC. |
6582 | * @arg TIM_ICSELECTION_TRC: TIM Input 1 is selected to be connected to TRC. |
| 4824 | * @param TIM_ICFilter: Specifies the Input Capture Filter. |
6583 | * @param TIM_ICFilter Specifies the Input Capture Filter. |
| 4825 | * This parameter must be a value between 0x00 and 0x0F. |
6584 | * This parameter must be a value between 0x00 and 0x0F. |
| 4826 | * @retval None |
6585 | * @retval None |
| 4827 | * @note TIM_ICFilter and TIM_ICPolarity are not used in INDIRECT mode as TI2FP1 |
6586 | * @note TIM_ICFilter and TIM_ICPolarity are not used in INDIRECT mode as TI2FP1 |
| 4828 | * (on channel2 path) is used as the input signal. Therefore CCMR1 must be |
6587 | * (on channel2 path) is used as the input signal. Therefore CCMR1 must be |
| 4829 | * protected against un-initialized filter and polarity values. |
6588 | * protected against un-initialized filter and polarity values. |
| 4830 | */ |
6589 | */ |
| 4831 | static void TIM_TI1_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection, |
6590 | static void TIM_TI1_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection, |
| 4832 | uint32_t TIM_ICFilter) |
6591 | uint32_t TIM_ICFilter) |
| 4833 | { |
6592 | { |
| 4834 | uint32_t tmpccmr1 = 0; |
6593 | uint32_t tmpccmr1; |
| 4835 | uint32_t tmpccer = 0; |
6594 | uint32_t tmpccer; |
| 4836 | 6595 | ||
| 4837 | /* Disable the Channel 1: Reset the CC1E Bit */ |
6596 | /* Disable the Channel 1: Reset the CC1E Bit */ |
| 4838 | TIMx->CCER &= ~TIM_CCER_CC1E; |
6597 | TIMx->CCER &= ~TIM_CCER_CC1E; |
| 4839 | tmpccmr1 = TIMx->CCMR1; |
6598 | tmpccmr1 = TIMx->CCMR1; |
| 4840 | tmpccer = TIMx->CCER; |
6599 | tmpccer = TIMx->CCER; |
| 4841 | 6600 | ||
| 4842 | /* Select the Input */ |
6601 | /* Select the Input */ |
| 4843 | if(IS_TIM_CC2_INSTANCE(TIMx) != RESET) |
6602 | if (IS_TIM_CC2_INSTANCE(TIMx) != RESET) |
| 4844 | { |
6603 | { |
| 4845 | tmpccmr1 &= ~TIM_CCMR1_CC1S; |
6604 | tmpccmr1 &= ~TIM_CCMR1_CC1S; |
| 4846 | tmpccmr1 |= TIM_ICSelection; |
6605 | tmpccmr1 |= TIM_ICSelection; |
| 4847 | } |
6606 | } |
| 4848 | else |
6607 | else |
| Line 4850... | Line 6609... | ||
| 4850 | tmpccmr1 |= TIM_CCMR1_CC1S_0; |
6609 | tmpccmr1 |= TIM_CCMR1_CC1S_0; |
| 4851 | } |
6610 | } |
| 4852 | 6611 | ||
| 4853 | /* Set the filter */ |
6612 | /* Set the filter */ |
| 4854 | tmpccmr1 &= ~TIM_CCMR1_IC1F; |
6613 | tmpccmr1 &= ~TIM_CCMR1_IC1F; |
| 4855 | tmpccmr1 |= ((TIM_ICFilter << 4) & TIM_CCMR1_IC1F); |
6614 | tmpccmr1 |= ((TIM_ICFilter << 4U) & TIM_CCMR1_IC1F); |
| 4856 | 6615 | ||
| 4857 | /* Select the Polarity and set the CC1E Bit */ |
6616 | /* Select the Polarity and set the CC1E Bit */ |
| 4858 | tmpccer &= ~(TIM_CCER_CC1P | TIM_CCER_CC1NP); |
6617 | tmpccer &= ~(TIM_CCER_CC1P | TIM_CCER_CC1NP); |
| 4859 | tmpccer |= (TIM_ICPolarity & (TIM_CCER_CC1P | TIM_CCER_CC1NP)); |
6618 | tmpccer |= (TIM_ICPolarity & (TIM_CCER_CC1P | TIM_CCER_CC1NP)); |
| 4860 | 6619 | ||
| Line 4864... | Line 6623... | ||
| 4864 | } |
6623 | } |
| 4865 | 6624 | ||
| 4866 | /** |
6625 | /** |
| 4867 | * @brief Configure the Polarity and Filter for TI1. |
6626 | * @brief Configure the Polarity and Filter for TI1. |
| 4868 | * @param TIMx to select the TIM peripheral. |
6627 | * @param TIMx to select the TIM peripheral. |
| 4869 | * @param TIM_ICPolarity : The Input Polarity. |
6628 | * @param TIM_ICPolarity The Input Polarity. |
| 4870 | * This parameter can be one of the following values: |
6629 | * This parameter can be one of the following values: |
| 4871 | * @arg TIM_ICPOLARITY_RISING |
6630 | * @arg TIM_ICPOLARITY_RISING |
| 4872 | * @arg TIM_ICPOLARITY_FALLING |
6631 | * @arg TIM_ICPOLARITY_FALLING |
| 4873 | * @arg TIM_ICPOLARITY_BOTHEDGE |
6632 | * @arg TIM_ICPOLARITY_BOTHEDGE |
| 4874 | * @param TIM_ICFilter: Specifies the Input Capture Filter. |
6633 | * @param TIM_ICFilter Specifies the Input Capture Filter. |
| 4875 | * This parameter must be a value between 0x00 and 0x0F. |
6634 | * This parameter must be a value between 0x00 and 0x0F. |
| 4876 | * @retval None |
6635 | * @retval None |
| 4877 | */ |
6636 | */ |
| 4878 | static void TIM_TI1_ConfigInputStage(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICFilter) |
6637 | static void TIM_TI1_ConfigInputStage(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICFilter) |
| 4879 | { |
6638 | { |
| 4880 | uint32_t tmpccmr1 = 0; |
6639 | uint32_t tmpccmr1; |
| 4881 | uint32_t tmpccer = 0; |
6640 | uint32_t tmpccer; |
| 4882 | 6641 | ||
| 4883 | /* Disable the Channel 1: Reset the CC1E Bit */ |
6642 | /* Disable the Channel 1: Reset the CC1E Bit */ |
| 4884 | tmpccer = TIMx->CCER; |
6643 | tmpccer = TIMx->CCER; |
| 4885 | TIMx->CCER &= ~TIM_CCER_CC1E; |
6644 | TIMx->CCER &= ~TIM_CCER_CC1E; |
| 4886 | tmpccmr1 = TIMx->CCMR1; |
6645 | tmpccmr1 = TIMx->CCMR1; |
| 4887 | 6646 | ||
| 4888 | /* Set the filter */ |
6647 | /* Set the filter */ |
| 4889 | tmpccmr1 &= ~TIM_CCMR1_IC1F; |
6648 | tmpccmr1 &= ~TIM_CCMR1_IC1F; |
| 4890 | tmpccmr1 |= (TIM_ICFilter << 4); |
6649 | tmpccmr1 |= (TIM_ICFilter << 4U); |
| 4891 | 6650 | ||
| 4892 | /* Select the Polarity and set the CC1E Bit */ |
6651 | /* Select the Polarity and set the CC1E Bit */ |
| 4893 | tmpccer &= ~(TIM_CCER_CC1P | TIM_CCER_CC1NP); |
6652 | tmpccer &= ~(TIM_CCER_CC1P | TIM_CCER_CC1NP); |
| 4894 | tmpccer |= TIM_ICPolarity; |
6653 | tmpccer |= TIM_ICPolarity; |
| 4895 | 6654 | ||
| Line 4899... | Line 6658... | ||
| 4899 | } |
6658 | } |
| 4900 | 6659 | ||
| 4901 | /** |
6660 | /** |
| 4902 | * @brief Configure the TI2 as Input. |
6661 | * @brief Configure the TI2 as Input. |
| 4903 | * @param TIMx to select the TIM peripheral |
6662 | * @param TIMx to select the TIM peripheral |
| 4904 | * @param TIM_ICPolarity : The Input Polarity. |
6663 | * @param TIM_ICPolarity The Input Polarity. |
| 4905 | * This parameter can be one of the following values: |
6664 | * This parameter can be one of the following values: |
| 4906 | * @arg TIM_ICPOLARITY_RISING |
6665 | * @arg TIM_ICPOLARITY_RISING |
| 4907 | * @arg TIM_ICPOLARITY_FALLING |
6666 | * @arg TIM_ICPOLARITY_FALLING |
| 4908 | * @arg TIM_ICPOLARITY_BOTHEDGE |
6667 | * @arg TIM_ICPOLARITY_BOTHEDGE |
| 4909 | * @param TIM_ICSelection: specifies the input to be used. |
6668 | * @param TIM_ICSelection specifies the input to be used. |
| 4910 | * This parameter can be one of the following values: |
6669 | * This parameter can be one of the following values: |
| 4911 | * @arg TIM_ICSELECTION_DIRECTTI: TIM Input 2 is selected to be connected to IC2. |
6670 | * @arg TIM_ICSELECTION_DIRECTTI: TIM Input 2 is selected to be connected to IC2. |
| 4912 | * @arg TIM_ICSELECTION_INDIRECTTI: TIM Input 2 is selected to be connected to IC1. |
6671 | * @arg TIM_ICSELECTION_INDIRECTTI: TIM Input 2 is selected to be connected to IC1. |
| 4913 | * @arg TIM_ICSELECTION_TRC: TIM Input 2 is selected to be connected to TRC. |
6672 | * @arg TIM_ICSELECTION_TRC: TIM Input 2 is selected to be connected to TRC. |
| 4914 | * @param TIM_ICFilter: Specifies the Input Capture Filter. |
6673 | * @param TIM_ICFilter Specifies the Input Capture Filter. |
| 4915 | * This parameter must be a value between 0x00 and 0x0F. |
6674 | * This parameter must be a value between 0x00 and 0x0F. |
| 4916 | * @retval None |
6675 | * @retval None |
| 4917 | * @note TIM_ICFilter and TIM_ICPolarity are not used in INDIRECT mode as TI1FP2 |
6676 | * @note TIM_ICFilter and TIM_ICPolarity are not used in INDIRECT mode as TI1FP2 |
| 4918 | * (on channel1 path) is used as the input signal. Therefore CCMR1 must be |
6677 | * (on channel1 path) is used as the input signal. Therefore CCMR1 must be |
| 4919 | * protected against un-initialized filter and polarity values. |
6678 | * protected against un-initialized filter and polarity values. |
| 4920 | */ |
6679 | */ |
| 4921 | static void TIM_TI2_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection, |
6680 | static void TIM_TI2_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection, |
| 4922 | uint32_t TIM_ICFilter) |
6681 | uint32_t TIM_ICFilter) |
| 4923 | { |
6682 | { |
| 4924 | uint32_t tmpccmr1 = 0; |
6683 | uint32_t tmpccmr1; |
| 4925 | uint32_t tmpccer = 0; |
6684 | uint32_t tmpccer; |
| 4926 | 6685 | ||
| 4927 | /* Disable the Channel 2: Reset the CC2E Bit */ |
6686 | /* Disable the Channel 2: Reset the CC2E Bit */ |
| 4928 | TIMx->CCER &= ~TIM_CCER_CC2E; |
6687 | TIMx->CCER &= ~TIM_CCER_CC2E; |
| 4929 | tmpccmr1 = TIMx->CCMR1; |
6688 | tmpccmr1 = TIMx->CCMR1; |
| 4930 | tmpccer = TIMx->CCER; |
6689 | tmpccer = TIMx->CCER; |
| 4931 | 6690 | ||
| 4932 | /* Select the Input */ |
6691 | /* Select the Input */ |
| 4933 | tmpccmr1 &= ~TIM_CCMR1_CC2S; |
6692 | tmpccmr1 &= ~TIM_CCMR1_CC2S; |
| 4934 | tmpccmr1 |= (TIM_ICSelection << 8); |
6693 | tmpccmr1 |= (TIM_ICSelection << 8U); |
| 4935 | 6694 | ||
| 4936 | /* Set the filter */ |
6695 | /* Set the filter */ |
| 4937 | tmpccmr1 &= ~TIM_CCMR1_IC2F; |
6696 | tmpccmr1 &= ~TIM_CCMR1_IC2F; |
| 4938 | tmpccmr1 |= ((TIM_ICFilter << 12) & TIM_CCMR1_IC2F); |
6697 | tmpccmr1 |= ((TIM_ICFilter << 12U) & TIM_CCMR1_IC2F); |
| 4939 | 6698 | ||
| 4940 | /* Select the Polarity and set the CC2E Bit */ |
6699 | /* Select the Polarity and set the CC2E Bit */ |
| 4941 | tmpccer &= ~(TIM_CCER_CC2P | TIM_CCER_CC2NP); |
6700 | tmpccer &= ~(TIM_CCER_CC2P | TIM_CCER_CC2NP); |
| 4942 | tmpccer |= ((TIM_ICPolarity << 4) & (TIM_CCER_CC2P | TIM_CCER_CC2NP)); |
6701 | tmpccer |= ((TIM_ICPolarity << 4U) & (TIM_CCER_CC2P | TIM_CCER_CC2NP)); |
| 4943 | 6702 | ||
| 4944 | /* Write to TIMx CCMR1 and CCER registers */ |
6703 | /* Write to TIMx CCMR1 and CCER registers */ |
| 4945 | TIMx->CCMR1 = tmpccmr1 ; |
6704 | TIMx->CCMR1 = tmpccmr1 ; |
| 4946 | TIMx->CCER = tmpccer; |
6705 | TIMx->CCER = tmpccer; |
| 4947 | } |
6706 | } |
| 4948 | 6707 | ||
| 4949 | /** |
6708 | /** |
| 4950 | * @brief Configure the Polarity and Filter for TI2. |
6709 | * @brief Configure the Polarity and Filter for TI2. |
| 4951 | * @param TIMx to select the TIM peripheral. |
6710 | * @param TIMx to select the TIM peripheral. |
| 4952 | * @param TIM_ICPolarity : The Input Polarity. |
6711 | * @param TIM_ICPolarity The Input Polarity. |
| 4953 | * This parameter can be one of the following values: |
6712 | * This parameter can be one of the following values: |
| 4954 | * @arg TIM_ICPOLARITY_RISING |
6713 | * @arg TIM_ICPOLARITY_RISING |
| 4955 | * @arg TIM_ICPOLARITY_FALLING |
6714 | * @arg TIM_ICPOLARITY_FALLING |
| 4956 | * @arg TIM_ICPOLARITY_BOTHEDGE |
6715 | * @arg TIM_ICPOLARITY_BOTHEDGE |
| 4957 | * @param TIM_ICFilter: Specifies the Input Capture Filter. |
6716 | * @param TIM_ICFilter Specifies the Input Capture Filter. |
| 4958 | * This parameter must be a value between 0x00 and 0x0F. |
6717 | * This parameter must be a value between 0x00 and 0x0F. |
| 4959 | * @retval None |
6718 | * @retval None |
| 4960 | */ |
6719 | */ |
| 4961 | static void TIM_TI2_ConfigInputStage(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICFilter) |
6720 | static void TIM_TI2_ConfigInputStage(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICFilter) |
| 4962 | { |
6721 | { |
| 4963 | uint32_t tmpccmr1 = 0; |
6722 | uint32_t tmpccmr1; |
| 4964 | uint32_t tmpccer = 0; |
6723 | uint32_t tmpccer; |
| 4965 | 6724 | ||
| 4966 | /* Disable the Channel 2: Reset the CC2E Bit */ |
6725 | /* Disable the Channel 2: Reset the CC2E Bit */ |
| 4967 | TIMx->CCER &= ~TIM_CCER_CC2E; |
6726 | TIMx->CCER &= ~TIM_CCER_CC2E; |
| 4968 | tmpccmr1 = TIMx->CCMR1; |
6727 | tmpccmr1 = TIMx->CCMR1; |
| 4969 | tmpccer = TIMx->CCER; |
6728 | tmpccer = TIMx->CCER; |
| 4970 | 6729 | ||
| 4971 | /* Set the filter */ |
6730 | /* Set the filter */ |
| 4972 | tmpccmr1 &= ~TIM_CCMR1_IC2F; |
6731 | tmpccmr1 &= ~TIM_CCMR1_IC2F; |
| 4973 | tmpccmr1 |= (TIM_ICFilter << 12); |
6732 | tmpccmr1 |= (TIM_ICFilter << 12U); |
| 4974 | 6733 | ||
| 4975 | /* Select the Polarity and set the CC2E Bit */ |
6734 | /* Select the Polarity and set the CC2E Bit */ |
| 4976 | tmpccer &= ~(TIM_CCER_CC2P | TIM_CCER_CC2NP); |
6735 | tmpccer &= ~(TIM_CCER_CC2P | TIM_CCER_CC2NP); |
| 4977 | tmpccer |= (TIM_ICPolarity << 4); |
6736 | tmpccer |= (TIM_ICPolarity << 4U); |
| 4978 | 6737 | ||
| 4979 | /* Write to TIMx CCMR1 and CCER registers */ |
6738 | /* Write to TIMx CCMR1 and CCER registers */ |
| 4980 | TIMx->CCMR1 = tmpccmr1 ; |
6739 | TIMx->CCMR1 = tmpccmr1 ; |
| 4981 | TIMx->CCER = tmpccer; |
6740 | TIMx->CCER = tmpccer; |
| 4982 | } |
6741 | } |
| 4983 | 6742 | ||
| 4984 | /** |
6743 | /** |
| 4985 | * @brief Configure the TI3 as Input. |
6744 | * @brief Configure the TI3 as Input. |
| 4986 | * @param TIMx to select the TIM peripheral |
6745 | * @param TIMx to select the TIM peripheral |
| 4987 | * @param TIM_ICPolarity : The Input Polarity. |
6746 | * @param TIM_ICPolarity The Input Polarity. |
| 4988 | * This parameter can be one of the following values: |
6747 | * This parameter can be one of the following values: |
| 4989 | * @arg TIM_ICPOLARITY_RISING |
6748 | * @arg TIM_ICPOLARITY_RISING |
| 4990 | * @arg TIM_ICPOLARITY_FALLING |
6749 | * @arg TIM_ICPOLARITY_FALLING |
| 4991 | * @arg TIM_ICPOLARITY_BOTHEDGE |
6750 | * @arg TIM_ICPOLARITY_BOTHEDGE |
| 4992 | * @param TIM_ICSelection: specifies the input to be used. |
6751 | * @param TIM_ICSelection specifies the input to be used. |
| 4993 | * This parameter can be one of the following values: |
6752 | * This parameter can be one of the following values: |
| 4994 | * @arg TIM_ICSELECTION_DIRECTTI: TIM Input 3 is selected to be connected to IC3. |
6753 | * @arg TIM_ICSELECTION_DIRECTTI: TIM Input 3 is selected to be connected to IC3. |
| 4995 | * @arg TIM_ICSELECTION_INDIRECTTI: TIM Input 3 is selected to be connected to IC4. |
6754 | * @arg TIM_ICSELECTION_INDIRECTTI: TIM Input 3 is selected to be connected to IC4. |
| 4996 | * @arg TIM_ICSELECTION_TRC: TIM Input 3 is selected to be connected to TRC. |
6755 | * @arg TIM_ICSELECTION_TRC: TIM Input 3 is selected to be connected to TRC. |
| 4997 | * @param TIM_ICFilter: Specifies the Input Capture Filter. |
6756 | * @param TIM_ICFilter Specifies the Input Capture Filter. |
| 4998 | * This parameter must be a value between 0x00 and 0x0F. |
6757 | * This parameter must be a value between 0x00 and 0x0F. |
| 4999 | * @retval None |
6758 | * @retval None |
| 5000 | * @note TIM_ICFilter and TIM_ICPolarity are not used in INDIRECT mode as TI3FP4 |
6759 | * @note TIM_ICFilter and TIM_ICPolarity are not used in INDIRECT mode as TI3FP4 |
| 5001 | * (on channel1 path) is used as the input signal. Therefore CCMR2 must be |
6760 | * (on channel1 path) is used as the input signal. Therefore CCMR2 must be |
| 5002 | * protected against un-initialized filter and polarity values. |
6761 | * protected against un-initialized filter and polarity values. |
| 5003 | */ |
6762 | */ |
| 5004 | static void TIM_TI3_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection, |
6763 | static void TIM_TI3_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection, |
| 5005 | uint32_t TIM_ICFilter) |
6764 | uint32_t TIM_ICFilter) |
| 5006 | { |
6765 | { |
| 5007 | uint32_t tmpccmr2 = 0; |
6766 | uint32_t tmpccmr2; |
| 5008 | uint32_t tmpccer = 0; |
6767 | uint32_t tmpccer; |
| 5009 | 6768 | ||
| 5010 | /* Disable the Channel 3: Reset the CC3E Bit */ |
6769 | /* Disable the Channel 3: Reset the CC3E Bit */ |
| 5011 | TIMx->CCER &= ~TIM_CCER_CC3E; |
6770 | TIMx->CCER &= ~TIM_CCER_CC3E; |
| 5012 | tmpccmr2 = TIMx->CCMR2; |
6771 | tmpccmr2 = TIMx->CCMR2; |
| 5013 | tmpccer = TIMx->CCER; |
6772 | tmpccer = TIMx->CCER; |
| Line 5016... | Line 6775... | ||
| 5016 | tmpccmr2 &= ~TIM_CCMR2_CC3S; |
6775 | tmpccmr2 &= ~TIM_CCMR2_CC3S; |
| 5017 | tmpccmr2 |= TIM_ICSelection; |
6776 | tmpccmr2 |= TIM_ICSelection; |
| 5018 | 6777 | ||
| 5019 | /* Set the filter */ |
6778 | /* Set the filter */ |
| 5020 | tmpccmr2 &= ~TIM_CCMR2_IC3F; |
6779 | tmpccmr2 &= ~TIM_CCMR2_IC3F; |
| 5021 | tmpccmr2 |= ((TIM_ICFilter << 4) & TIM_CCMR2_IC3F); |
6780 | tmpccmr2 |= ((TIM_ICFilter << 4U) & TIM_CCMR2_IC3F); |
| 5022 | 6781 | ||
| 5023 | /* Select the Polarity and set the CC3E Bit */ |
6782 | /* Select the Polarity and set the CC3E Bit */ |
| 5024 | tmpccer &= ~(TIM_CCER_CC3P | TIM_CCER_CC3NP); |
6783 | tmpccer &= ~(TIM_CCER_CC3P | TIM_CCER_CC3NP); |
| 5025 | tmpccer |= ((TIM_ICPolarity << 8) & (TIM_CCER_CC3P | TIM_CCER_CC3NP)); |
6784 | tmpccer |= ((TIM_ICPolarity << 8U) & (TIM_CCER_CC3P | TIM_CCER_CC3NP)); |
| 5026 | 6785 | ||
| 5027 | /* Write to TIMx CCMR2 and CCER registers */ |
6786 | /* Write to TIMx CCMR2 and CCER registers */ |
| 5028 | TIMx->CCMR2 = tmpccmr2; |
6787 | TIMx->CCMR2 = tmpccmr2; |
| 5029 | TIMx->CCER = tmpccer; |
6788 | TIMx->CCER = tmpccer; |
| 5030 | } |
6789 | } |
| 5031 | 6790 | ||
| 5032 | /** |
6791 | /** |
| 5033 | * @brief Configure the TI4 as Input. |
6792 | * @brief Configure the TI4 as Input. |
| 5034 | * @param TIMx to select the TIM peripheral |
6793 | * @param TIMx to select the TIM peripheral |
| 5035 | * @param TIM_ICPolarity : The Input Polarity. |
6794 | * @param TIM_ICPolarity The Input Polarity. |
| 5036 | * This parameter can be one of the following values: |
6795 | * This parameter can be one of the following values: |
| 5037 | * @arg TIM_ICPOLARITY_RISING |
6796 | * @arg TIM_ICPOLARITY_RISING |
| 5038 | * @arg TIM_ICPOLARITY_FALLING |
6797 | * @arg TIM_ICPOLARITY_FALLING |
| 5039 | * @arg TIM_ICPOLARITY_BOTHEDGE |
6798 | * @arg TIM_ICPOLARITY_BOTHEDGE |
| 5040 | * @param TIM_ICSelection: specifies the input to be used. |
6799 | * @param TIM_ICSelection specifies the input to be used. |
| 5041 | * This parameter can be one of the following values: |
6800 | * This parameter can be one of the following values: |
| 5042 | * @arg TIM_ICSELECTION_DIRECTTI: TIM Input 4 is selected to be connected to IC4. |
6801 | * @arg TIM_ICSELECTION_DIRECTTI: TIM Input 4 is selected to be connected to IC4. |
| 5043 | * @arg TIM_ICSELECTION_INDIRECTTI: TIM Input 4 is selected to be connected to IC3. |
6802 | * @arg TIM_ICSELECTION_INDIRECTTI: TIM Input 4 is selected to be connected to IC3. |
| 5044 | * @arg TIM_ICSELECTION_TRC: TIM Input 4 is selected to be connected to TRC. |
6803 | * @arg TIM_ICSELECTION_TRC: TIM Input 4 is selected to be connected to TRC. |
| 5045 | * @param TIM_ICFilter: Specifies the Input Capture Filter. |
6804 | * @param TIM_ICFilter Specifies the Input Capture Filter. |
| 5046 | * This parameter must be a value between 0x00 and 0x0F. |
6805 | * This parameter must be a value between 0x00 and 0x0F. |
| 5047 | * @retval None |
- | |
| 5048 | * @note TIM_ICFilter and TIM_ICPolarity are not used in INDIRECT mode as TI4FP3 |
6806 | * @note TIM_ICFilter and TIM_ICPolarity are not used in INDIRECT mode as TI4FP3 |
| 5049 | * (on channel1 path) is used as the input signal. Therefore CCMR2 must be |
6807 | * (on channel1 path) is used as the input signal. Therefore CCMR2 must be |
| 5050 | * protected against un-initialized filter and polarity values. |
6808 | * protected against un-initialized filter and polarity values. |
| - | 6809 | * @retval None |
|
| 5051 | */ |
6810 | */ |
| 5052 | static void TIM_TI4_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection, |
6811 | static void TIM_TI4_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection, |
| 5053 | uint32_t TIM_ICFilter) |
6812 | uint32_t TIM_ICFilter) |
| 5054 | { |
6813 | { |
| 5055 | uint32_t tmpccmr2 = 0; |
6814 | uint32_t tmpccmr2; |
| 5056 | uint32_t tmpccer = 0; |
6815 | uint32_t tmpccer; |
| 5057 | 6816 | ||
| 5058 | /* Disable the Channel 4: Reset the CC4E Bit */ |
6817 | /* Disable the Channel 4: Reset the CC4E Bit */ |
| 5059 | TIMx->CCER &= ~TIM_CCER_CC4E; |
6818 | TIMx->CCER &= ~TIM_CCER_CC4E; |
| 5060 | tmpccmr2 = TIMx->CCMR2; |
6819 | tmpccmr2 = TIMx->CCMR2; |
| 5061 | tmpccer = TIMx->CCER; |
6820 | tmpccer = TIMx->CCER; |
| 5062 | 6821 | ||
| 5063 | /* Select the Input */ |
6822 | /* Select the Input */ |
| 5064 | tmpccmr2 &= ~TIM_CCMR2_CC4S; |
6823 | tmpccmr2 &= ~TIM_CCMR2_CC4S; |
| 5065 | tmpccmr2 |= (TIM_ICSelection << 8); |
6824 | tmpccmr2 |= (TIM_ICSelection << 8U); |
| 5066 | 6825 | ||
| 5067 | /* Set the filter */ |
6826 | /* Set the filter */ |
| 5068 | tmpccmr2 &= ~TIM_CCMR2_IC4F; |
6827 | tmpccmr2 &= ~TIM_CCMR2_IC4F; |
| 5069 | tmpccmr2 |= ((TIM_ICFilter << 12) & TIM_CCMR2_IC4F); |
6828 | tmpccmr2 |= ((TIM_ICFilter << 12U) & TIM_CCMR2_IC4F); |
| 5070 | 6829 | ||
| 5071 | /* Select the Polarity and set the CC4E Bit */ |
6830 | /* Select the Polarity and set the CC4E Bit */ |
| 5072 | tmpccer &= ~(TIM_CCER_CC4P | TIM_CCER_CC4NP); |
6831 | tmpccer &= ~(TIM_CCER_CC4P | TIM_CCER_CC4NP); |
| 5073 | tmpccer |= ((TIM_ICPolarity << 12) & (TIM_CCER_CC4P | TIM_CCER_CC4NP)); |
6832 | tmpccer |= ((TIM_ICPolarity << 12U) & (TIM_CCER_CC4P | TIM_CCER_CC4NP)); |
| 5074 | 6833 | ||
| 5075 | /* Write to TIMx CCMR2 and CCER registers */ |
6834 | /* Write to TIMx CCMR2 and CCER registers */ |
| 5076 | TIMx->CCMR2 = tmpccmr2; |
6835 | TIMx->CCMR2 = tmpccmr2; |
| 5077 | TIMx->CCER = tmpccer ; |
6836 | TIMx->CCER = tmpccer ; |
| 5078 | } |
6837 | } |
| 5079 | 6838 | ||
| 5080 | /** |
6839 | /** |
| 5081 | * @brief Selects the Input Trigger source |
6840 | * @brief Selects the Input Trigger source |
| 5082 | * @param TIMx to select the TIM peripheral |
6841 | * @param TIMx to select the TIM peripheral |
| 5083 | * @param InputTriggerSource: The Input Trigger source. |
6842 | * @param InputTriggerSource The Input Trigger source. |
| 5084 | * This parameter can be one of the following values: |
6843 | * This parameter can be one of the following values: |
| 5085 | * @arg TIM_TS_ITR0: Internal Trigger 0 |
6844 | * @arg TIM_TS_ITR0: Internal Trigger 0 |
| 5086 | * @arg TIM_TS_ITR1: Internal Trigger 1 |
6845 | * @arg TIM_TS_ITR1: Internal Trigger 1 |
| 5087 | * @arg TIM_TS_ITR2: Internal Trigger 2 |
6846 | * @arg TIM_TS_ITR2: Internal Trigger 2 |
| 5088 | * @arg TIM_TS_ITR3: Internal Trigger 3 |
6847 | * @arg TIM_TS_ITR3: Internal Trigger 3 |
| Line 5090... | Line 6849... | ||
| 5090 | * @arg TIM_TS_TI1FP1: Filtered Timer Input 1 |
6849 | * @arg TIM_TS_TI1FP1: Filtered Timer Input 1 |
| 5091 | * @arg TIM_TS_TI2FP2: Filtered Timer Input 2 |
6850 | * @arg TIM_TS_TI2FP2: Filtered Timer Input 2 |
| 5092 | * @arg TIM_TS_ETRF: External Trigger input |
6851 | * @arg TIM_TS_ETRF: External Trigger input |
| 5093 | * @retval None |
6852 | * @retval None |
| 5094 | */ |
6853 | */ |
| 5095 | static void TIM_ITRx_SetConfig(TIM_TypeDef *TIMx, uint16_t InputTriggerSource) |
6854 | static void TIM_ITRx_SetConfig(TIM_TypeDef *TIMx, uint32_t InputTriggerSource) |
| 5096 | { |
6855 | { |
| 5097 | uint32_t tmpsmcr = 0; |
6856 | uint32_t tmpsmcr; |
| 5098 | 6857 | ||
| 5099 | /* Get the TIMx SMCR register value */ |
6858 | /* Get the TIMx SMCR register value */ |
| 5100 | tmpsmcr = TIMx->SMCR; |
6859 | tmpsmcr = TIMx->SMCR; |
| 5101 | /* Reset the TS Bits */ |
6860 | /* Reset the TS Bits */ |
| 5102 | tmpsmcr &= ~TIM_SMCR_TS; |
6861 | tmpsmcr &= ~TIM_SMCR_TS; |
| 5103 | /* Set the Input Trigger source and the slave mode*/ |
6862 | /* Set the Input Trigger source and the slave mode*/ |
| 5104 | tmpsmcr |= InputTriggerSource | TIM_SLAVEMODE_EXTERNAL1; |
6863 | tmpsmcr |= (InputTriggerSource | TIM_SLAVEMODE_EXTERNAL1); |
| 5105 | /* Write to TIMx SMCR */ |
6864 | /* Write to TIMx SMCR */ |
| 5106 | TIMx->SMCR = tmpsmcr; |
6865 | TIMx->SMCR = tmpsmcr; |
| 5107 | } |
6866 | } |
| 5108 | /** |
6867 | /** |
| 5109 | * @brief Configures the TIMx External Trigger (ETR). |
6868 | * @brief Configures the TIMx External Trigger (ETR). |
| 5110 | * @param TIMx to select the TIM peripheral |
6869 | * @param TIMx to select the TIM peripheral |
| 5111 | * @param TIM_ExtTRGPrescaler: The external Trigger Prescaler. |
6870 | * @param TIM_ExtTRGPrescaler The external Trigger Prescaler. |
| 5112 | * This parameter can be one of the following values: |
6871 | * This parameter can be one of the following values: |
| 5113 | * @arg TIM_ETRPRESCALER_DIV1: ETRP Prescaler OFF. |
6872 | * @arg TIM_ETRPRESCALER_DIV1: ETRP Prescaler OFF. |
| 5114 | * @arg TIM_ETRPRESCALER_DIV2: ETRP frequency divided by 2. |
6873 | * @arg TIM_ETRPRESCALER_DIV2: ETRP frequency divided by 2. |
| 5115 | * @arg TIM_ETRPRESCALER_DIV4: ETRP frequency divided by 4. |
6874 | * @arg TIM_ETRPRESCALER_DIV4: ETRP frequency divided by 4. |
| 5116 | * @arg TIM_ETRPRESCALER_DIV8: ETRP frequency divided by 8. |
6875 | * @arg TIM_ETRPRESCALER_DIV8: ETRP frequency divided by 8. |
| 5117 | * @param TIM_ExtTRGPolarity: The external Trigger Polarity. |
6876 | * @param TIM_ExtTRGPolarity The external Trigger Polarity. |
| 5118 | * This parameter can be one of the following values: |
6877 | * This parameter can be one of the following values: |
| 5119 | * @arg TIM_ETRPOLARITY_INVERTED: active low or falling edge active. |
6878 | * @arg TIM_ETRPOLARITY_INVERTED: active low or falling edge active. |
| 5120 | * @arg TIM_ETRPOLARITY_NONINVERTED: active high or rising edge active. |
6879 | * @arg TIM_ETRPOLARITY_NONINVERTED: active high or rising edge active. |
| 5121 | * @param ExtTRGFilter: External Trigger Filter. |
6880 | * @param ExtTRGFilter External Trigger Filter. |
| 5122 | * This parameter must be a value between 0x00 and 0x0F |
6881 | * This parameter must be a value between 0x00 and 0x0F |
| 5123 | * @retval None |
6882 | * @retval None |
| 5124 | */ |
6883 | */ |
| 5125 | static void TIM_ETR_SetConfig(TIM_TypeDef* TIMx, uint32_t TIM_ExtTRGPrescaler, |
6884 | static void TIM_ETR_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ExtTRGPrescaler, |
| 5126 | uint32_t TIM_ExtTRGPolarity, uint32_t ExtTRGFilter) |
6885 | uint32_t TIM_ExtTRGPolarity, uint32_t ExtTRGFilter) |
| 5127 | { |
6886 | { |
| 5128 | uint32_t tmpsmcr = 0; |
6887 | uint32_t tmpsmcr; |
| 5129 | 6888 | ||
| 5130 | tmpsmcr = TIMx->SMCR; |
6889 | tmpsmcr = TIMx->SMCR; |
| 5131 | 6890 | ||
| 5132 | /* Reset the ETR Bits */ |
6891 | /* Reset the ETR Bits */ |
| 5133 | tmpsmcr &= (uint32_t)(~(TIM_SMCR_ETF | TIM_SMCR_ETPS | TIM_SMCR_ECE | TIM_SMCR_ETP)); |
6892 | tmpsmcr &= ~(TIM_SMCR_ETF | TIM_SMCR_ETPS | TIM_SMCR_ECE | TIM_SMCR_ETP); |
| 5134 | 6893 | ||
| 5135 | /* Set the Prescaler, the Filter value and the Polarity */ |
6894 | /* Set the Prescaler, the Filter value and the Polarity */ |
| 5136 | tmpsmcr |= (uint32_t)(TIM_ExtTRGPrescaler | (TIM_ExtTRGPolarity | (ExtTRGFilter << 8))); |
6895 | tmpsmcr |= (uint32_t)(TIM_ExtTRGPrescaler | (TIM_ExtTRGPolarity | (ExtTRGFilter << 8U))); |
| 5137 | 6896 | ||
| 5138 | /* Write to TIMx SMCR */ |
6897 | /* Write to TIMx SMCR */ |
| 5139 | TIMx->SMCR = tmpsmcr; |
6898 | TIMx->SMCR = tmpsmcr; |
| 5140 | } |
6899 | } |
| 5141 | 6900 | ||
| 5142 | /** |
6901 | /** |
| 5143 | * @brief Enables or disables the TIM Capture Compare Channel x. |
6902 | * @brief Enables or disables the TIM Capture Compare Channel x. |
| 5144 | * @param TIMx to select the TIM peripheral |
6903 | * @param TIMx to select the TIM peripheral |
| 5145 | * @param Channel: specifies the TIM Channel |
6904 | * @param Channel specifies the TIM Channel |
| 5146 | * This parameter can be one of the following values: |
6905 | * This parameter can be one of the following values: |
| 5147 | * @arg TIM_CHANNEL_1: TIM Channel 1 |
6906 | * @arg TIM_CHANNEL_1: TIM Channel 1 |
| 5148 | * @arg TIM_CHANNEL_2: TIM Channel 2 |
6907 | * @arg TIM_CHANNEL_2: TIM Channel 2 |
| 5149 | * @arg TIM_CHANNEL_3: TIM Channel 3 |
6908 | * @arg TIM_CHANNEL_3: TIM Channel 3 |
| 5150 | * @arg TIM_CHANNEL_4: TIM Channel 4 |
6909 | * @arg TIM_CHANNEL_4: TIM Channel 4 |
| 5151 | * @param ChannelState: specifies the TIM Channel CCxE bit new state. |
6910 | * @param ChannelState specifies the TIM Channel CCxE bit new state. |
| 5152 | * This parameter can be: TIM_CCx_ENABLE or TIM_CCx_Disable. |
6911 | * This parameter can be: TIM_CCx_ENABLE or TIM_CCx_DISABLE. |
| 5153 | * @retval None |
6912 | * @retval None |
| 5154 | */ |
6913 | */ |
| 5155 | static void TIM_CCxChannelCmd(TIM_TypeDef* TIMx, uint32_t Channel, uint32_t ChannelState) |
6914 | static void TIM_CCxChannelCmd(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t ChannelState) |
| 5156 | { |
6915 | { |
| 5157 | uint32_t tmp = 0; |
6916 | uint32_t tmp; |
| 5158 | 6917 | ||
| 5159 | /* Check the parameters */ |
6918 | /* Check the parameters */ |
| 5160 | assert_param(IS_TIM_CC1_INSTANCE(TIMx)); |
6919 | assert_param(IS_TIM_CC1_INSTANCE(TIMx)); |
| 5161 | assert_param(IS_TIM_CHANNELS(Channel)); |
6920 | assert_param(IS_TIM_CHANNELS(Channel)); |
| 5162 | 6921 | ||
| 5163 | tmp = TIM_CCER_CC1E << Channel; |
6922 | tmp = TIM_CCER_CC1E << (Channel & 0x1FU); /* 0x1FU = 31 bits max shift */ |
| 5164 | 6923 | ||
| 5165 | /* Reset the CCxE Bit */ |
6924 | /* Reset the CCxE Bit */ |
| 5166 | TIMx->CCER &= ~tmp; |
6925 | TIMx->CCER &= ~tmp; |
| 5167 | 6926 | ||
| 5168 | /* Set or reset the CCxE Bit */ |
6927 | /* Set or reset the CCxE Bit */ |
| 5169 | TIMx->CCER |= (uint32_t)(ChannelState << Channel); |
6928 | TIMx->CCER |= (uint32_t)(ChannelState << (Channel & 0x1FU)); /* 0x1FU = 31 bits max shift */ |
| - | 6929 | } |
|
| - | 6930 | ||
| - | 6931 | #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) |
|
| - | 6932 | /** |
|
| - | 6933 | * @brief Reset interrupt callbacks to the legacy weak callbacks. |
|
| - | 6934 | * @param htim pointer to a TIM_HandleTypeDef structure that contains |
|
| - | 6935 | * the configuration information for TIM module. |
|
| - | 6936 | * @retval None |
|
| - | 6937 | */ |
|
| - | 6938 | void TIM_ResetCallback(TIM_HandleTypeDef *htim) |
|
| - | 6939 | { |
|
| - | 6940 | /* Reset the TIM callback to the legacy weak callbacks */ |
|
| - | 6941 | htim->PeriodElapsedCallback = HAL_TIM_PeriodElapsedCallback; /* Legacy weak PeriodElapsedCallback */ |
|
| - | 6942 | htim->PeriodElapsedHalfCpltCallback = HAL_TIM_PeriodElapsedHalfCpltCallback; /* Legacy weak PeriodElapsedHalfCpltCallback */ |
|
| - | 6943 | htim->TriggerCallback = HAL_TIM_TriggerCallback; /* Legacy weak TriggerCallback */ |
|
| - | 6944 | htim->TriggerHalfCpltCallback = HAL_TIM_TriggerHalfCpltCallback; /* Legacy weak TriggerHalfCpltCallback */ |
|
| - | 6945 | htim->IC_CaptureCallback = HAL_TIM_IC_CaptureCallback; /* Legacy weak IC_CaptureCallback */ |
|
| - | 6946 | htim->IC_CaptureHalfCpltCallback = HAL_TIM_IC_CaptureHalfCpltCallback; /* Legacy weak IC_CaptureHalfCpltCallback */ |
|
| - | 6947 | htim->OC_DelayElapsedCallback = HAL_TIM_OC_DelayElapsedCallback; /* Legacy weak OC_DelayElapsedCallback */ |
|
| - | 6948 | htim->PWM_PulseFinishedCallback = HAL_TIM_PWM_PulseFinishedCallback; /* Legacy weak PWM_PulseFinishedCallback */ |
|
| - | 6949 | htim->PWM_PulseFinishedHalfCpltCallback = HAL_TIM_PWM_PulseFinishedHalfCpltCallback; /* Legacy weak PWM_PulseFinishedHalfCpltCallback */ |
|
| - | 6950 | htim->ErrorCallback = HAL_TIM_ErrorCallback; /* Legacy weak ErrorCallback */ |
|
| 5170 | } |
6951 | } |
| - | 6952 | #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */ |
|
| 5171 | 6953 | ||
| 5172 | /** |
6954 | /** |
| 5173 | * @} |
6955 | * @} |
| 5174 | */ |
6956 | */ |
| 5175 | 6957 | ||