001

Committer:
ganlikun
Date:
Sun Jun 12 14:02:44 2022 +0000
Revision:
0:13413ea9a877
00

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ganlikun 0:13413ea9a877 1 /**
ganlikun 0:13413ea9a877 2 ******************************************************************************
ganlikun 0:13413ea9a877 3 * @file stm32f4xx_hal_tim_ex.c
ganlikun 0:13413ea9a877 4 * @author MCD Application Team
ganlikun 0:13413ea9a877 5 * @version V1.7.1
ganlikun 0:13413ea9a877 6 * @date 14-April-2017
ganlikun 0:13413ea9a877 7 * @brief TIM HAL module driver.
ganlikun 0:13413ea9a877 8 * This file provides firmware functions to manage the following
ganlikun 0:13413ea9a877 9 * functionalities of the Timer extension peripheral:
ganlikun 0:13413ea9a877 10 * + Time Hall Sensor Interface Initialization
ganlikun 0:13413ea9a877 11 * + Time Hall Sensor Interface Start
ganlikun 0:13413ea9a877 12 * + Time Complementary signal bread and dead time configuration
ganlikun 0:13413ea9a877 13 * + Time Master and Slave synchronization configuration
ganlikun 0:13413ea9a877 14 @verbatim
ganlikun 0:13413ea9a877 15 ==============================================================================
ganlikun 0:13413ea9a877 16 ##### TIMER Extended features #####
ganlikun 0:13413ea9a877 17 ==============================================================================
ganlikun 0:13413ea9a877 18 [..]
ganlikun 0:13413ea9a877 19 The Timer Extension features include:
ganlikun 0:13413ea9a877 20 (#) Complementary outputs with programmable dead-time for :
ganlikun 0:13413ea9a877 21 (++) Input Capture
ganlikun 0:13413ea9a877 22 (++) Output Compare
ganlikun 0:13413ea9a877 23 (++) PWM generation (Edge and Center-aligned Mode)
ganlikun 0:13413ea9a877 24 (++) One-pulse mode output
ganlikun 0:13413ea9a877 25 (#) Synchronization circuit to control the timer with external signals and to
ganlikun 0:13413ea9a877 26 interconnect several timers together.
ganlikun 0:13413ea9a877 27 (#) Break input to put the timer output signals in reset state or in a known state.
ganlikun 0:13413ea9a877 28 (#) Supports incremental (quadrature) encoder and hall-sensor circuitry for
ganlikun 0:13413ea9a877 29 positioning purposes
ganlikun 0:13413ea9a877 30
ganlikun 0:13413ea9a877 31 ##### How to use this driver #####
ganlikun 0:13413ea9a877 32 ==============================================================================
ganlikun 0:13413ea9a877 33 [..]
ganlikun 0:13413ea9a877 34 (#) Initialize the TIM low level resources by implementing the following functions
ganlikun 0:13413ea9a877 35 depending from feature used :
ganlikun 0:13413ea9a877 36 (++) Complementary Output Compare : HAL_TIM_OC_MspInit()
ganlikun 0:13413ea9a877 37 (++) Complementary PWM generation : HAL_TIM_PWM_MspInit()
ganlikun 0:13413ea9a877 38 (++) Complementary One-pulse mode output : HAL_TIM_OnePulse_MspInit()
ganlikun 0:13413ea9a877 39 (++) Hall Sensor output : HAL_TIM_HallSensor_MspInit()
ganlikun 0:13413ea9a877 40
ganlikun 0:13413ea9a877 41 (#) Initialize the TIM low level resources :
ganlikun 0:13413ea9a877 42 (##) Enable the TIM interface clock using __TIMx_CLK_ENABLE();
ganlikun 0:13413ea9a877 43 (##) TIM pins configuration
ganlikun 0:13413ea9a877 44 (+++) Enable the clock for the TIM GPIOs using the following function:
ganlikun 0:13413ea9a877 45 __GPIOx_CLK_ENABLE();
ganlikun 0:13413ea9a877 46 (+++) Configure these TIM pins in Alternate function mode using HAL_GPIO_Init();
ganlikun 0:13413ea9a877 47
ganlikun 0:13413ea9a877 48 (#) The external Clock can be configured, if needed (the default clock is the
ganlikun 0:13413ea9a877 49 internal clock from the APBx), using the following function:
ganlikun 0:13413ea9a877 50 HAL_TIM_ConfigClockSource, the clock configuration should be done before
ganlikun 0:13413ea9a877 51 any start function.
ganlikun 0:13413ea9a877 52
ganlikun 0:13413ea9a877 53 (#) Configure the TIM in the desired functioning mode using one of the
ganlikun 0:13413ea9a877 54 initialization function of this driver:
ganlikun 0:13413ea9a877 55 (++) HAL_TIMEx_HallSensor_Init and HAL_TIMEx_ConfigCommutationEvent: to use the
ganlikun 0:13413ea9a877 56 Timer Hall Sensor Interface and the commutation event with the corresponding
ganlikun 0:13413ea9a877 57 Interrupt and DMA request if needed (Note that One Timer is used to interface
ganlikun 0:13413ea9a877 58 with the Hall sensor Interface and another Timer should be used to use
ganlikun 0:13413ea9a877 59 the commutation event).
ganlikun 0:13413ea9a877 60
ganlikun 0:13413ea9a877 61 (#) Activate the TIM peripheral using one of the start functions:
ganlikun 0:13413ea9a877 62 (++) Complementary Output Compare : HAL_TIMEx_OCN_Start(), HAL_TIMEx_OCN_Start_DMA(), HAL_TIMEx_OC_Start_IT()
ganlikun 0:13413ea9a877 63 (++) Complementary PWM generation : HAL_TIMEx_PWMN_Start(), HAL_TIMEx_PWMN_Start_DMA(), HAL_TIMEx_PWMN_Start_IT()
ganlikun 0:13413ea9a877 64 (++) Complementary One-pulse mode output : HAL_TIMEx_OnePulseN_Start(), HAL_TIMEx_OnePulseN_Start_IT()
ganlikun 0:13413ea9a877 65 (++) Hall Sensor output : HAL_TIMEx_HallSensor_Start(), HAL_TIMEx_HallSensor_Start_DMA(), HAL_TIMEx_HallSensor_Start_IT().
ganlikun 0:13413ea9a877 66
ganlikun 0:13413ea9a877 67
ganlikun 0:13413ea9a877 68 @endverbatim
ganlikun 0:13413ea9a877 69 ******************************************************************************
ganlikun 0:13413ea9a877 70 * @attention
ganlikun 0:13413ea9a877 71 *
ganlikun 0:13413ea9a877 72 * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
ganlikun 0:13413ea9a877 73 *
ganlikun 0:13413ea9a877 74 * Redistribution and use in source and binary forms, with or without modification,
ganlikun 0:13413ea9a877 75 * are permitted provided that the following conditions are met:
ganlikun 0:13413ea9a877 76 * 1. Redistributions of source code must retain the above copyright notice,
ganlikun 0:13413ea9a877 77 * this list of conditions and the following disclaimer.
ganlikun 0:13413ea9a877 78 * 2. Redistributions in binary form must reproduce the above copyright notice,
ganlikun 0:13413ea9a877 79 * this list of conditions and the following disclaimer in the documentation
ganlikun 0:13413ea9a877 80 * and/or other materials provided with the distribution.
ganlikun 0:13413ea9a877 81 * 3. Neither the name of STMicroelectronics nor the names of its contributors
ganlikun 0:13413ea9a877 82 * may be used to endorse or promote products derived from this software
ganlikun 0:13413ea9a877 83 * without specific prior written permission.
ganlikun 0:13413ea9a877 84 *
ganlikun 0:13413ea9a877 85 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
ganlikun 0:13413ea9a877 86 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
ganlikun 0:13413ea9a877 87 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
ganlikun 0:13413ea9a877 88 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
ganlikun 0:13413ea9a877 89 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
ganlikun 0:13413ea9a877 90 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
ganlikun 0:13413ea9a877 91 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
ganlikun 0:13413ea9a877 92 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
ganlikun 0:13413ea9a877 93 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
ganlikun 0:13413ea9a877 94 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
ganlikun 0:13413ea9a877 95 *
ganlikun 0:13413ea9a877 96 ******************************************************************************
ganlikun 0:13413ea9a877 97 */
ganlikun 0:13413ea9a877 98
ganlikun 0:13413ea9a877 99 /* Includes ------------------------------------------------------------------*/
ganlikun 0:13413ea9a877 100 #include "stm32f4xx_hal.h"
ganlikun 0:13413ea9a877 101
ganlikun 0:13413ea9a877 102 /** @addtogroup STM32F4xx_HAL_Driver
ganlikun 0:13413ea9a877 103 * @{
ganlikun 0:13413ea9a877 104 */
ganlikun 0:13413ea9a877 105
ganlikun 0:13413ea9a877 106 /** @defgroup TIMEx TIMEx
ganlikun 0:13413ea9a877 107 * @brief TIM HAL module driver
ganlikun 0:13413ea9a877 108 * @{
ganlikun 0:13413ea9a877 109 */
ganlikun 0:13413ea9a877 110
ganlikun 0:13413ea9a877 111 #ifdef HAL_TIM_MODULE_ENABLED
ganlikun 0:13413ea9a877 112
ganlikun 0:13413ea9a877 113 /* Private typedef -----------------------------------------------------------*/
ganlikun 0:13413ea9a877 114 /* Private define ------------------------------------------------------------*/
ganlikun 0:13413ea9a877 115 /* Private macro -------------------------------------------------------------*/
ganlikun 0:13413ea9a877 116 /* Private variables ---------------------------------------------------------*/
ganlikun 0:13413ea9a877 117 /** @addtogroup TIMEx_Private_Functions
ganlikun 0:13413ea9a877 118 * @{
ganlikun 0:13413ea9a877 119 */
ganlikun 0:13413ea9a877 120 /* Private function prototypes -----------------------------------------------*/
ganlikun 0:13413ea9a877 121 static void TIM_CCxNChannelCmd(TIM_TypeDef* TIMx, uint32_t Channel, uint32_t ChannelNState);
ganlikun 0:13413ea9a877 122 /**
ganlikun 0:13413ea9a877 123 * @}
ganlikun 0:13413ea9a877 124 */
ganlikun 0:13413ea9a877 125
ganlikun 0:13413ea9a877 126 /* Exported functions --------------------------------------------------------*/
ganlikun 0:13413ea9a877 127 /** @defgroup TIMEx_Exported_Functions TIM Exported Functions
ganlikun 0:13413ea9a877 128 * @{
ganlikun 0:13413ea9a877 129 */
ganlikun 0:13413ea9a877 130
ganlikun 0:13413ea9a877 131 /** @defgroup TIMEx_Exported_Functions_Group1 Timer Hall Sensor functions
ganlikun 0:13413ea9a877 132 * @brief Timer Hall Sensor functions
ganlikun 0:13413ea9a877 133 *
ganlikun 0:13413ea9a877 134 @verbatim
ganlikun 0:13413ea9a877 135 ==============================================================================
ganlikun 0:13413ea9a877 136 ##### Timer Hall Sensor functions #####
ganlikun 0:13413ea9a877 137 ==============================================================================
ganlikun 0:13413ea9a877 138 [..]
ganlikun 0:13413ea9a877 139 This section provides functions allowing to:
ganlikun 0:13413ea9a877 140 (+) Initialize and configure TIM HAL Sensor.
ganlikun 0:13413ea9a877 141 (+) De-initialize TIM HAL Sensor.
ganlikun 0:13413ea9a877 142 (+) Start the Hall Sensor Interface.
ganlikun 0:13413ea9a877 143 (+) Stop the Hall Sensor Interface.
ganlikun 0:13413ea9a877 144 (+) Start the Hall Sensor Interface and enable interrupts.
ganlikun 0:13413ea9a877 145 (+) Stop the Hall Sensor Interface and disable interrupts.
ganlikun 0:13413ea9a877 146 (+) Start the Hall Sensor Interface and enable DMA transfers.
ganlikun 0:13413ea9a877 147 (+) Stop the Hall Sensor Interface and disable DMA transfers.
ganlikun 0:13413ea9a877 148
ganlikun 0:13413ea9a877 149 @endverbatim
ganlikun 0:13413ea9a877 150 * @{
ganlikun 0:13413ea9a877 151 */
ganlikun 0:13413ea9a877 152 /**
ganlikun 0:13413ea9a877 153 * @brief Initializes the TIM Hall Sensor Interface and create the associated handle.
ganlikun 0:13413ea9a877 154 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 155 * the configuration information for TIM module.
ganlikun 0:13413ea9a877 156 * @param sConfig: TIM Hall Sensor configuration structure
ganlikun 0:13413ea9a877 157 * @retval HAL status
ganlikun 0:13413ea9a877 158 */
ganlikun 0:13413ea9a877 159 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Init(TIM_HandleTypeDef *htim, TIM_HallSensor_InitTypeDef* sConfig)
ganlikun 0:13413ea9a877 160 {
ganlikun 0:13413ea9a877 161 TIM_OC_InitTypeDef OC_Config;
ganlikun 0:13413ea9a877 162
ganlikun 0:13413ea9a877 163 /* Check the TIM handle allocation */
ganlikun 0:13413ea9a877 164 if(htim == NULL)
ganlikun 0:13413ea9a877 165 {
ganlikun 0:13413ea9a877 166 return HAL_ERROR;
ganlikun 0:13413ea9a877 167 }
ganlikun 0:13413ea9a877 168
ganlikun 0:13413ea9a877 169 assert_param(IS_TIM_XOR_INSTANCE(htim->Instance));
ganlikun 0:13413ea9a877 170 assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode));
ganlikun 0:13413ea9a877 171 assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision));
ganlikun 0:13413ea9a877 172 assert_param(IS_TIM_IC_POLARITY(sConfig->IC1Polarity));
ganlikun 0:13413ea9a877 173 assert_param(IS_TIM_IC_PRESCALER(sConfig->IC1Prescaler));
ganlikun 0:13413ea9a877 174 assert_param(IS_TIM_IC_FILTER(sConfig->IC1Filter));
ganlikun 0:13413ea9a877 175
ganlikun 0:13413ea9a877 176 /* Set the TIM state */
ganlikun 0:13413ea9a877 177 htim->State= HAL_TIM_STATE_BUSY;
ganlikun 0:13413ea9a877 178
ganlikun 0:13413ea9a877 179 /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */
ganlikun 0:13413ea9a877 180 HAL_TIMEx_HallSensor_MspInit(htim);
ganlikun 0:13413ea9a877 181
ganlikun 0:13413ea9a877 182 /* Configure the Time base in the Encoder Mode */
ganlikun 0:13413ea9a877 183 TIM_Base_SetConfig(htim->Instance, &htim->Init);
ganlikun 0:13413ea9a877 184
ganlikun 0:13413ea9a877 185 /* Configure the Channel 1 as Input Channel to interface with the three Outputs of the Hall sensor */
ganlikun 0:13413ea9a877 186 TIM_TI1_SetConfig(htim->Instance, sConfig->IC1Polarity, TIM_ICSELECTION_TRC, sConfig->IC1Filter);
ganlikun 0:13413ea9a877 187
ganlikun 0:13413ea9a877 188 /* Reset the IC1PSC Bits */
ganlikun 0:13413ea9a877 189 htim->Instance->CCMR1 &= ~TIM_CCMR1_IC1PSC;
ganlikun 0:13413ea9a877 190 /* Set the IC1PSC value */
ganlikun 0:13413ea9a877 191 htim->Instance->CCMR1 |= sConfig->IC1Prescaler;
ganlikun 0:13413ea9a877 192
ganlikun 0:13413ea9a877 193 /* Enable the Hall sensor interface (XOR function of the three inputs) */
ganlikun 0:13413ea9a877 194 htim->Instance->CR2 |= TIM_CR2_TI1S;
ganlikun 0:13413ea9a877 195
ganlikun 0:13413ea9a877 196 /* Select the TIM_TS_TI1F_ED signal as Input trigger for the TIM */
ganlikun 0:13413ea9a877 197 htim->Instance->SMCR &= ~TIM_SMCR_TS;
ganlikun 0:13413ea9a877 198 htim->Instance->SMCR |= TIM_TS_TI1F_ED;
ganlikun 0:13413ea9a877 199
ganlikun 0:13413ea9a877 200 /* Use the TIM_TS_TI1F_ED signal to reset the TIM counter each edge detection */
ganlikun 0:13413ea9a877 201 htim->Instance->SMCR &= ~TIM_SMCR_SMS;
ganlikun 0:13413ea9a877 202 htim->Instance->SMCR |= TIM_SLAVEMODE_RESET;
ganlikun 0:13413ea9a877 203
ganlikun 0:13413ea9a877 204 /* Program channel 2 in PWM 2 mode with the desired Commutation_Delay*/
ganlikun 0:13413ea9a877 205 OC_Config.OCFastMode = TIM_OCFAST_DISABLE;
ganlikun 0:13413ea9a877 206 OC_Config.OCIdleState = TIM_OCIDLESTATE_RESET;
ganlikun 0:13413ea9a877 207 OC_Config.OCMode = TIM_OCMODE_PWM2;
ganlikun 0:13413ea9a877 208 OC_Config.OCNIdleState = TIM_OCNIDLESTATE_RESET;
ganlikun 0:13413ea9a877 209 OC_Config.OCNPolarity = TIM_OCNPOLARITY_HIGH;
ganlikun 0:13413ea9a877 210 OC_Config.OCPolarity = TIM_OCPOLARITY_HIGH;
ganlikun 0:13413ea9a877 211 OC_Config.Pulse = sConfig->Commutation_Delay;
ganlikun 0:13413ea9a877 212
ganlikun 0:13413ea9a877 213 TIM_OC2_SetConfig(htim->Instance, &OC_Config);
ganlikun 0:13413ea9a877 214
ganlikun 0:13413ea9a877 215 /* Select OC2REF as trigger output on TRGO: write the MMS bits in the TIMx_CR2
ganlikun 0:13413ea9a877 216 register to 101 */
ganlikun 0:13413ea9a877 217 htim->Instance->CR2 &= ~TIM_CR2_MMS;
ganlikun 0:13413ea9a877 218 htim->Instance->CR2 |= TIM_TRGO_OC2REF;
ganlikun 0:13413ea9a877 219
ganlikun 0:13413ea9a877 220 /* Initialize the TIM state*/
ganlikun 0:13413ea9a877 221 htim->State= HAL_TIM_STATE_READY;
ganlikun 0:13413ea9a877 222
ganlikun 0:13413ea9a877 223 return HAL_OK;
ganlikun 0:13413ea9a877 224 }
ganlikun 0:13413ea9a877 225
ganlikun 0:13413ea9a877 226 /**
ganlikun 0:13413ea9a877 227 * @brief DeInitializes the TIM Hall Sensor interface
ganlikun 0:13413ea9a877 228 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 229 * the configuration information for TIM module.
ganlikun 0:13413ea9a877 230 * @retval HAL status
ganlikun 0:13413ea9a877 231 */
ganlikun 0:13413ea9a877 232 HAL_StatusTypeDef HAL_TIMEx_HallSensor_DeInit(TIM_HandleTypeDef *htim)
ganlikun 0:13413ea9a877 233 {
ganlikun 0:13413ea9a877 234 /* Check the parameters */
ganlikun 0:13413ea9a877 235 assert_param(IS_TIM_INSTANCE(htim->Instance));
ganlikun 0:13413ea9a877 236
ganlikun 0:13413ea9a877 237 htim->State = HAL_TIM_STATE_BUSY;
ganlikun 0:13413ea9a877 238
ganlikun 0:13413ea9a877 239 /* Disable the TIM Peripheral Clock */
ganlikun 0:13413ea9a877 240 __HAL_TIM_DISABLE(htim);
ganlikun 0:13413ea9a877 241
ganlikun 0:13413ea9a877 242 /* DeInit the low level hardware: GPIO, CLOCK, NVIC */
ganlikun 0:13413ea9a877 243 HAL_TIMEx_HallSensor_MspDeInit(htim);
ganlikun 0:13413ea9a877 244
ganlikun 0:13413ea9a877 245 /* Change TIM state */
ganlikun 0:13413ea9a877 246 htim->State = HAL_TIM_STATE_RESET;
ganlikun 0:13413ea9a877 247
ganlikun 0:13413ea9a877 248 /* Release Lock */
ganlikun 0:13413ea9a877 249 __HAL_UNLOCK(htim);
ganlikun 0:13413ea9a877 250
ganlikun 0:13413ea9a877 251 return HAL_OK;
ganlikun 0:13413ea9a877 252 }
ganlikun 0:13413ea9a877 253
ganlikun 0:13413ea9a877 254 /**
ganlikun 0:13413ea9a877 255 * @brief Initializes the TIM Hall Sensor MSP.
ganlikun 0:13413ea9a877 256 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 257 * the configuration information for TIM module.
ganlikun 0:13413ea9a877 258 * @retval None
ganlikun 0:13413ea9a877 259 */
ganlikun 0:13413ea9a877 260 __weak void HAL_TIMEx_HallSensor_MspInit(TIM_HandleTypeDef *htim)
ganlikun 0:13413ea9a877 261 {
ganlikun 0:13413ea9a877 262 /* Prevent unused argument(s) compilation warning */
ganlikun 0:13413ea9a877 263 UNUSED(htim);
ganlikun 0:13413ea9a877 264 /* NOTE : This function Should not be modified, when the callback is needed,
ganlikun 0:13413ea9a877 265 the HAL_TIMEx_HallSensor_MspInit could be implemented in the user file
ganlikun 0:13413ea9a877 266 */
ganlikun 0:13413ea9a877 267 }
ganlikun 0:13413ea9a877 268
ganlikun 0:13413ea9a877 269 /**
ganlikun 0:13413ea9a877 270 * @brief DeInitializes TIM Hall Sensor MSP.
ganlikun 0:13413ea9a877 271 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 272 * the configuration information for TIM module.
ganlikun 0:13413ea9a877 273 * @retval None
ganlikun 0:13413ea9a877 274 */
ganlikun 0:13413ea9a877 275 __weak void HAL_TIMEx_HallSensor_MspDeInit(TIM_HandleTypeDef *htim)
ganlikun 0:13413ea9a877 276 {
ganlikun 0:13413ea9a877 277 /* Prevent unused argument(s) compilation warning */
ganlikun 0:13413ea9a877 278 UNUSED(htim);
ganlikun 0:13413ea9a877 279 /* NOTE : This function Should not be modified, when the callback is needed,
ganlikun 0:13413ea9a877 280 the HAL_TIMEx_HallSensor_MspDeInit could be implemented in the user file
ganlikun 0:13413ea9a877 281 */
ganlikun 0:13413ea9a877 282 }
ganlikun 0:13413ea9a877 283
ganlikun 0:13413ea9a877 284 /**
ganlikun 0:13413ea9a877 285 * @brief Starts the TIM Hall Sensor Interface.
ganlikun 0:13413ea9a877 286 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 287 * the configuration information for TIM module.
ganlikun 0:13413ea9a877 288 * @retval HAL status
ganlikun 0:13413ea9a877 289 */
ganlikun 0:13413ea9a877 290 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start(TIM_HandleTypeDef *htim)
ganlikun 0:13413ea9a877 291 {
ganlikun 0:13413ea9a877 292 /* Check the parameters */
ganlikun 0:13413ea9a877 293 assert_param(IS_TIM_XOR_INSTANCE(htim->Instance));
ganlikun 0:13413ea9a877 294
ganlikun 0:13413ea9a877 295 /* Enable the Input Capture channels 1
ganlikun 0:13413ea9a877 296 (in the Hall Sensor Interface the Three possible channels that can be used are TIM_CHANNEL_1, TIM_CHANNEL_2 and TIM_CHANNEL_3) */
ganlikun 0:13413ea9a877 297 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
ganlikun 0:13413ea9a877 298
ganlikun 0:13413ea9a877 299 /* Enable the Peripheral */
ganlikun 0:13413ea9a877 300 __HAL_TIM_ENABLE(htim);
ganlikun 0:13413ea9a877 301
ganlikun 0:13413ea9a877 302 /* Return function status */
ganlikun 0:13413ea9a877 303 return HAL_OK;
ganlikun 0:13413ea9a877 304 }
ganlikun 0:13413ea9a877 305
ganlikun 0:13413ea9a877 306 /**
ganlikun 0:13413ea9a877 307 * @brief Stops the TIM Hall sensor Interface.
ganlikun 0:13413ea9a877 308 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 309 * the configuration information for TIM module.
ganlikun 0:13413ea9a877 310 * @retval HAL status
ganlikun 0:13413ea9a877 311 */
ganlikun 0:13413ea9a877 312 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop(TIM_HandleTypeDef *htim)
ganlikun 0:13413ea9a877 313 {
ganlikun 0:13413ea9a877 314 /* Check the parameters */
ganlikun 0:13413ea9a877 315 assert_param(IS_TIM_XOR_INSTANCE(htim->Instance));
ganlikun 0:13413ea9a877 316
ganlikun 0:13413ea9a877 317 /* Disable the Input Capture channels 1, 2 and 3
ganlikun 0:13413ea9a877 318 (in the Hall Sensor Interface the Three possible channels that can be used are TIM_CHANNEL_1, TIM_CHANNEL_2 and TIM_CHANNEL_3) */
ganlikun 0:13413ea9a877 319 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
ganlikun 0:13413ea9a877 320
ganlikun 0:13413ea9a877 321 /* Disable the Peripheral */
ganlikun 0:13413ea9a877 322 __HAL_TIM_DISABLE(htim);
ganlikun 0:13413ea9a877 323
ganlikun 0:13413ea9a877 324 /* Return function status */
ganlikun 0:13413ea9a877 325 return HAL_OK;
ganlikun 0:13413ea9a877 326 }
ganlikun 0:13413ea9a877 327
ganlikun 0:13413ea9a877 328 /**
ganlikun 0:13413ea9a877 329 * @brief Starts the TIM Hall Sensor Interface in interrupt mode.
ganlikun 0:13413ea9a877 330 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 331 * the configuration information for TIM module.
ganlikun 0:13413ea9a877 332 * @retval HAL status
ganlikun 0:13413ea9a877 333 */
ganlikun 0:13413ea9a877 334 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start_IT(TIM_HandleTypeDef *htim)
ganlikun 0:13413ea9a877 335 {
ganlikun 0:13413ea9a877 336 /* Check the parameters */
ganlikun 0:13413ea9a877 337 assert_param(IS_TIM_XOR_INSTANCE(htim->Instance));
ganlikun 0:13413ea9a877 338
ganlikun 0:13413ea9a877 339 /* Enable the capture compare Interrupts 1 event */
ganlikun 0:13413ea9a877 340 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
ganlikun 0:13413ea9a877 341
ganlikun 0:13413ea9a877 342 /* Enable the Input Capture channels 1
ganlikun 0:13413ea9a877 343 (in the Hall Sensor Interface the Three possible channels that can be used are TIM_CHANNEL_1, TIM_CHANNEL_2 and TIM_CHANNEL_3) */
ganlikun 0:13413ea9a877 344 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
ganlikun 0:13413ea9a877 345
ganlikun 0:13413ea9a877 346 /* Enable the Peripheral */
ganlikun 0:13413ea9a877 347 __HAL_TIM_ENABLE(htim);
ganlikun 0:13413ea9a877 348
ganlikun 0:13413ea9a877 349 /* Return function status */
ganlikun 0:13413ea9a877 350 return HAL_OK;
ganlikun 0:13413ea9a877 351 }
ganlikun 0:13413ea9a877 352
ganlikun 0:13413ea9a877 353 /**
ganlikun 0:13413ea9a877 354 * @brief Stops the TIM Hall Sensor Interface in interrupt mode.
ganlikun 0:13413ea9a877 355 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 356 * the configuration information for TIM module.
ganlikun 0:13413ea9a877 357 * @retval HAL status
ganlikun 0:13413ea9a877 358 */
ganlikun 0:13413ea9a877 359 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_IT(TIM_HandleTypeDef *htim)
ganlikun 0:13413ea9a877 360 {
ganlikun 0:13413ea9a877 361 /* Check the parameters */
ganlikun 0:13413ea9a877 362 assert_param(IS_TIM_XOR_INSTANCE(htim->Instance));
ganlikun 0:13413ea9a877 363
ganlikun 0:13413ea9a877 364 /* Disable the Input Capture channels 1
ganlikun 0:13413ea9a877 365 (in the Hall Sensor Interface the Three possible channels that can be used are TIM_CHANNEL_1, TIM_CHANNEL_2 and TIM_CHANNEL_3) */
ganlikun 0:13413ea9a877 366 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
ganlikun 0:13413ea9a877 367
ganlikun 0:13413ea9a877 368 /* Disable the capture compare Interrupts event */
ganlikun 0:13413ea9a877 369 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
ganlikun 0:13413ea9a877 370
ganlikun 0:13413ea9a877 371 /* Disable the Peripheral */
ganlikun 0:13413ea9a877 372 __HAL_TIM_DISABLE(htim);
ganlikun 0:13413ea9a877 373
ganlikun 0:13413ea9a877 374 /* Return function status */
ganlikun 0:13413ea9a877 375 return HAL_OK;
ganlikun 0:13413ea9a877 376 }
ganlikun 0:13413ea9a877 377
ganlikun 0:13413ea9a877 378 /**
ganlikun 0:13413ea9a877 379 * @brief Starts the TIM Hall Sensor Interface in DMA mode.
ganlikun 0:13413ea9a877 380 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 381 * the configuration information for TIM module.
ganlikun 0:13413ea9a877 382 * @param pData: The destination Buffer address.
ganlikun 0:13413ea9a877 383 * @param Length: The length of data to be transferred from TIM peripheral to memory.
ganlikun 0:13413ea9a877 384 * @retval HAL status
ganlikun 0:13413ea9a877 385 */
ganlikun 0:13413ea9a877 386 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start_DMA(TIM_HandleTypeDef *htim, uint32_t *pData, uint16_t Length)
ganlikun 0:13413ea9a877 387 {
ganlikun 0:13413ea9a877 388 /* Check the parameters */
ganlikun 0:13413ea9a877 389 assert_param(IS_TIM_XOR_INSTANCE(htim->Instance));
ganlikun 0:13413ea9a877 390
ganlikun 0:13413ea9a877 391 if((htim->State == HAL_TIM_STATE_BUSY))
ganlikun 0:13413ea9a877 392 {
ganlikun 0:13413ea9a877 393 return HAL_BUSY;
ganlikun 0:13413ea9a877 394 }
ganlikun 0:13413ea9a877 395 else if((htim->State == HAL_TIM_STATE_READY))
ganlikun 0:13413ea9a877 396 {
ganlikun 0:13413ea9a877 397 if(((uint32_t)pData == 0U) && (Length > 0))
ganlikun 0:13413ea9a877 398 {
ganlikun 0:13413ea9a877 399 return HAL_ERROR;
ganlikun 0:13413ea9a877 400 }
ganlikun 0:13413ea9a877 401 else
ganlikun 0:13413ea9a877 402 {
ganlikun 0:13413ea9a877 403 htim->State = HAL_TIM_STATE_BUSY;
ganlikun 0:13413ea9a877 404 }
ganlikun 0:13413ea9a877 405 }
ganlikun 0:13413ea9a877 406 /* Enable the Input Capture channels 1
ganlikun 0:13413ea9a877 407 (in the Hall Sensor Interface the Three possible channels that can be used are TIM_CHANNEL_1, TIM_CHANNEL_2 and TIM_CHANNEL_3) */
ganlikun 0:13413ea9a877 408 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
ganlikun 0:13413ea9a877 409
ganlikun 0:13413ea9a877 410 /* Set the DMA Input Capture 1 Callback */
ganlikun 0:13413ea9a877 411 htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMACaptureCplt;
ganlikun 0:13413ea9a877 412 /* Set the DMA error callback */
ganlikun 0:13413ea9a877 413 htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ;
ganlikun 0:13413ea9a877 414
ganlikun 0:13413ea9a877 415 /* Enable the DMA Stream for Capture 1*/
ganlikun 0:13413ea9a877 416 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)&htim->Instance->CCR1, (uint32_t)pData, Length);
ganlikun 0:13413ea9a877 417
ganlikun 0:13413ea9a877 418 /* Enable the capture compare 1 Interrupt */
ganlikun 0:13413ea9a877 419 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1);
ganlikun 0:13413ea9a877 420
ganlikun 0:13413ea9a877 421 /* Enable the Peripheral */
ganlikun 0:13413ea9a877 422 __HAL_TIM_ENABLE(htim);
ganlikun 0:13413ea9a877 423
ganlikun 0:13413ea9a877 424 /* Return function status */
ganlikun 0:13413ea9a877 425 return HAL_OK;
ganlikun 0:13413ea9a877 426 }
ganlikun 0:13413ea9a877 427
ganlikun 0:13413ea9a877 428 /**
ganlikun 0:13413ea9a877 429 * @brief Stops the TIM Hall Sensor Interface in DMA mode.
ganlikun 0:13413ea9a877 430 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 431 * the configuration information for TIM module.
ganlikun 0:13413ea9a877 432 * @retval HAL status
ganlikun 0:13413ea9a877 433 */
ganlikun 0:13413ea9a877 434 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_DMA(TIM_HandleTypeDef *htim)
ganlikun 0:13413ea9a877 435 {
ganlikun 0:13413ea9a877 436 /* Check the parameters */
ganlikun 0:13413ea9a877 437 assert_param(IS_TIM_XOR_INSTANCE(htim->Instance));
ganlikun 0:13413ea9a877 438
ganlikun 0:13413ea9a877 439 /* Disable the Input Capture channels 1
ganlikun 0:13413ea9a877 440 (in the Hall Sensor Interface the Three possible channels that can be used are TIM_CHANNEL_1, TIM_CHANNEL_2 and TIM_CHANNEL_3) */
ganlikun 0:13413ea9a877 441 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
ganlikun 0:13413ea9a877 442
ganlikun 0:13413ea9a877 443
ganlikun 0:13413ea9a877 444 /* Disable the capture compare Interrupts 1 event */
ganlikun 0:13413ea9a877 445 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1);
ganlikun 0:13413ea9a877 446
ganlikun 0:13413ea9a877 447 /* Disable the Peripheral */
ganlikun 0:13413ea9a877 448 __HAL_TIM_DISABLE(htim);
ganlikun 0:13413ea9a877 449
ganlikun 0:13413ea9a877 450 /* Return function status */
ganlikun 0:13413ea9a877 451 return HAL_OK;
ganlikun 0:13413ea9a877 452 }
ganlikun 0:13413ea9a877 453 /**
ganlikun 0:13413ea9a877 454 * @}
ganlikun 0:13413ea9a877 455 */
ganlikun 0:13413ea9a877 456
ganlikun 0:13413ea9a877 457 /** @defgroup TIMEx_Exported_Functions_Group2 Timer Complementary Output Compare functions
ganlikun 0:13413ea9a877 458 * @brief Timer Complementary Output Compare functions
ganlikun 0:13413ea9a877 459 *
ganlikun 0:13413ea9a877 460 @verbatim
ganlikun 0:13413ea9a877 461 ==============================================================================
ganlikun 0:13413ea9a877 462 ##### Timer Complementary Output Compare functions #####
ganlikun 0:13413ea9a877 463 ==============================================================================
ganlikun 0:13413ea9a877 464 [..]
ganlikun 0:13413ea9a877 465 This section provides functions allowing to:
ganlikun 0:13413ea9a877 466 (+) Start the Complementary Output Compare/PWM.
ganlikun 0:13413ea9a877 467 (+) Stop the Complementary Output Compare/PWM.
ganlikun 0:13413ea9a877 468 (+) Start the Complementary Output Compare/PWM and enable interrupts.
ganlikun 0:13413ea9a877 469 (+) Stop the Complementary Output Compare/PWM and disable interrupts.
ganlikun 0:13413ea9a877 470 (+) Start the Complementary Output Compare/PWM and enable DMA transfers.
ganlikun 0:13413ea9a877 471 (+) Stop the Complementary Output Compare/PWM and disable DMA transfers.
ganlikun 0:13413ea9a877 472
ganlikun 0:13413ea9a877 473 @endverbatim
ganlikun 0:13413ea9a877 474 * @{
ganlikun 0:13413ea9a877 475 */
ganlikun 0:13413ea9a877 476
ganlikun 0:13413ea9a877 477 /**
ganlikun 0:13413ea9a877 478 * @brief Starts the TIM Output Compare signal generation on the complementary
ganlikun 0:13413ea9a877 479 * output.
ganlikun 0:13413ea9a877 480 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 481 * the configuration information for TIM module.
ganlikun 0:13413ea9a877 482 * @param Channel: TIM Channel to be enabled.
ganlikun 0:13413ea9a877 483 * This parameter can be one of the following values:
ganlikun 0:13413ea9a877 484 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
ganlikun 0:13413ea9a877 485 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
ganlikun 0:13413ea9a877 486 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
ganlikun 0:13413ea9a877 487 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
ganlikun 0:13413ea9a877 488 * @retval HAL status
ganlikun 0:13413ea9a877 489 */
ganlikun 0:13413ea9a877 490 HAL_StatusTypeDef HAL_TIMEx_OCN_Start(TIM_HandleTypeDef *htim, uint32_t Channel)
ganlikun 0:13413ea9a877 491 {
ganlikun 0:13413ea9a877 492 /* Check the parameters */
ganlikun 0:13413ea9a877 493 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
ganlikun 0:13413ea9a877 494
ganlikun 0:13413ea9a877 495 /* Enable the Capture compare channel N */
ganlikun 0:13413ea9a877 496 TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_ENABLE);
ganlikun 0:13413ea9a877 497
ganlikun 0:13413ea9a877 498 /* Enable the Main Output */
ganlikun 0:13413ea9a877 499 __HAL_TIM_MOE_ENABLE(htim);
ganlikun 0:13413ea9a877 500
ganlikun 0:13413ea9a877 501 /* Enable the Peripheral */
ganlikun 0:13413ea9a877 502 __HAL_TIM_ENABLE(htim);
ganlikun 0:13413ea9a877 503
ganlikun 0:13413ea9a877 504 /* Return function status */
ganlikun 0:13413ea9a877 505 return HAL_OK;
ganlikun 0:13413ea9a877 506 }
ganlikun 0:13413ea9a877 507
ganlikun 0:13413ea9a877 508 /**
ganlikun 0:13413ea9a877 509 * @brief Stops the TIM Output Compare signal generation on the complementary
ganlikun 0:13413ea9a877 510 * output.
ganlikun 0:13413ea9a877 511 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 512 * the configuration information for TIM module.
ganlikun 0:13413ea9a877 513 * @param Channel: TIM Channel to be disabled.
ganlikun 0:13413ea9a877 514 * This parameter can be one of the following values:
ganlikun 0:13413ea9a877 515 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
ganlikun 0:13413ea9a877 516 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
ganlikun 0:13413ea9a877 517 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
ganlikun 0:13413ea9a877 518 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
ganlikun 0:13413ea9a877 519 * @retval HAL status
ganlikun 0:13413ea9a877 520 */
ganlikun 0:13413ea9a877 521 HAL_StatusTypeDef HAL_TIMEx_OCN_Stop(TIM_HandleTypeDef *htim, uint32_t Channel)
ganlikun 0:13413ea9a877 522 {
ganlikun 0:13413ea9a877 523 /* Check the parameters */
ganlikun 0:13413ea9a877 524 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
ganlikun 0:13413ea9a877 525
ganlikun 0:13413ea9a877 526 /* Disable the Capture compare channel N */
ganlikun 0:13413ea9a877 527 TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_DISABLE);
ganlikun 0:13413ea9a877 528
ganlikun 0:13413ea9a877 529 /* Disable the Main Output */
ganlikun 0:13413ea9a877 530 __HAL_TIM_MOE_DISABLE(htim);
ganlikun 0:13413ea9a877 531
ganlikun 0:13413ea9a877 532 /* Disable the Peripheral */
ganlikun 0:13413ea9a877 533 __HAL_TIM_DISABLE(htim);
ganlikun 0:13413ea9a877 534
ganlikun 0:13413ea9a877 535 /* Return function status */
ganlikun 0:13413ea9a877 536 return HAL_OK;
ganlikun 0:13413ea9a877 537 }
ganlikun 0:13413ea9a877 538
ganlikun 0:13413ea9a877 539 /**
ganlikun 0:13413ea9a877 540 * @brief Starts the TIM Output Compare signal generation in interrupt mode
ganlikun 0:13413ea9a877 541 * on the complementary output.
ganlikun 0:13413ea9a877 542 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 543 * the configuration information for TIM module.
ganlikun 0:13413ea9a877 544 * @param Channel: TIM Channel to be enabled.
ganlikun 0:13413ea9a877 545 * This parameter can be one of the following values:
ganlikun 0:13413ea9a877 546 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
ganlikun 0:13413ea9a877 547 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
ganlikun 0:13413ea9a877 548 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
ganlikun 0:13413ea9a877 549 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
ganlikun 0:13413ea9a877 550 * @retval HAL status
ganlikun 0:13413ea9a877 551 */
ganlikun 0:13413ea9a877 552 HAL_StatusTypeDef HAL_TIMEx_OCN_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
ganlikun 0:13413ea9a877 553 {
ganlikun 0:13413ea9a877 554 /* Check the parameters */
ganlikun 0:13413ea9a877 555 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
ganlikun 0:13413ea9a877 556
ganlikun 0:13413ea9a877 557 switch (Channel)
ganlikun 0:13413ea9a877 558 {
ganlikun 0:13413ea9a877 559 case TIM_CHANNEL_1:
ganlikun 0:13413ea9a877 560 {
ganlikun 0:13413ea9a877 561 /* Enable the TIM Output Compare interrupt */
ganlikun 0:13413ea9a877 562 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
ganlikun 0:13413ea9a877 563 }
ganlikun 0:13413ea9a877 564 break;
ganlikun 0:13413ea9a877 565
ganlikun 0:13413ea9a877 566 case TIM_CHANNEL_2:
ganlikun 0:13413ea9a877 567 {
ganlikun 0:13413ea9a877 568 /* Enable the TIM Output Compare interrupt */
ganlikun 0:13413ea9a877 569 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);
ganlikun 0:13413ea9a877 570 }
ganlikun 0:13413ea9a877 571 break;
ganlikun 0:13413ea9a877 572
ganlikun 0:13413ea9a877 573 case TIM_CHANNEL_3:
ganlikun 0:13413ea9a877 574 {
ganlikun 0:13413ea9a877 575 /* Enable the TIM Output Compare interrupt */
ganlikun 0:13413ea9a877 576 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC3);
ganlikun 0:13413ea9a877 577 }
ganlikun 0:13413ea9a877 578 break;
ganlikun 0:13413ea9a877 579
ganlikun 0:13413ea9a877 580 case TIM_CHANNEL_4:
ganlikun 0:13413ea9a877 581 {
ganlikun 0:13413ea9a877 582 /* Enable the TIM Output Compare interrupt */
ganlikun 0:13413ea9a877 583 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC4);
ganlikun 0:13413ea9a877 584 }
ganlikun 0:13413ea9a877 585 break;
ganlikun 0:13413ea9a877 586
ganlikun 0:13413ea9a877 587 default:
ganlikun 0:13413ea9a877 588 break;
ganlikun 0:13413ea9a877 589 }
ganlikun 0:13413ea9a877 590
ganlikun 0:13413ea9a877 591 /* Enable the TIM Break interrupt */
ganlikun 0:13413ea9a877 592 __HAL_TIM_ENABLE_IT(htim, TIM_IT_BREAK);
ganlikun 0:13413ea9a877 593
ganlikun 0:13413ea9a877 594 /* Enable the Capture compare channel N */
ganlikun 0:13413ea9a877 595 TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_ENABLE);
ganlikun 0:13413ea9a877 596
ganlikun 0:13413ea9a877 597 /* Enable the Main Output */
ganlikun 0:13413ea9a877 598 __HAL_TIM_MOE_ENABLE(htim);
ganlikun 0:13413ea9a877 599
ganlikun 0:13413ea9a877 600 /* Enable the Peripheral */
ganlikun 0:13413ea9a877 601 __HAL_TIM_ENABLE(htim);
ganlikun 0:13413ea9a877 602
ganlikun 0:13413ea9a877 603 /* Return function status */
ganlikun 0:13413ea9a877 604 return HAL_OK;
ganlikun 0:13413ea9a877 605 }
ganlikun 0:13413ea9a877 606
ganlikun 0:13413ea9a877 607 /**
ganlikun 0:13413ea9a877 608 * @brief Stops the TIM Output Compare signal generation in interrupt mode
ganlikun 0:13413ea9a877 609 * on the complementary output.
ganlikun 0:13413ea9a877 610 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 611 * the configuration information for TIM module.
ganlikun 0:13413ea9a877 612 * @param Channel: TIM Channel to be disabled.
ganlikun 0:13413ea9a877 613 * This parameter can be one of the following values:
ganlikun 0:13413ea9a877 614 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
ganlikun 0:13413ea9a877 615 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
ganlikun 0:13413ea9a877 616 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
ganlikun 0:13413ea9a877 617 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
ganlikun 0:13413ea9a877 618 * @retval HAL status
ganlikun 0:13413ea9a877 619 */
ganlikun 0:13413ea9a877 620 HAL_StatusTypeDef HAL_TIMEx_OCN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
ganlikun 0:13413ea9a877 621 {
ganlikun 0:13413ea9a877 622 /* Check the parameters */
ganlikun 0:13413ea9a877 623 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
ganlikun 0:13413ea9a877 624
ganlikun 0:13413ea9a877 625 switch (Channel)
ganlikun 0:13413ea9a877 626 {
ganlikun 0:13413ea9a877 627 case TIM_CHANNEL_1:
ganlikun 0:13413ea9a877 628 {
ganlikun 0:13413ea9a877 629 /* Disable the TIM Output Compare interrupt */
ganlikun 0:13413ea9a877 630 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
ganlikun 0:13413ea9a877 631 }
ganlikun 0:13413ea9a877 632 break;
ganlikun 0:13413ea9a877 633
ganlikun 0:13413ea9a877 634 case TIM_CHANNEL_2:
ganlikun 0:13413ea9a877 635 {
ganlikun 0:13413ea9a877 636 /* Disable the TIM Output Compare interrupt */
ganlikun 0:13413ea9a877 637 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);
ganlikun 0:13413ea9a877 638 }
ganlikun 0:13413ea9a877 639 break;
ganlikun 0:13413ea9a877 640
ganlikun 0:13413ea9a877 641 case TIM_CHANNEL_3:
ganlikun 0:13413ea9a877 642 {
ganlikun 0:13413ea9a877 643 /* Disable the TIM Output Compare interrupt */
ganlikun 0:13413ea9a877 644 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC3);
ganlikun 0:13413ea9a877 645 }
ganlikun 0:13413ea9a877 646 break;
ganlikun 0:13413ea9a877 647
ganlikun 0:13413ea9a877 648 case TIM_CHANNEL_4:
ganlikun 0:13413ea9a877 649 {
ganlikun 0:13413ea9a877 650 /* Disable the TIM Output Compare interrupt */
ganlikun 0:13413ea9a877 651 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC4);
ganlikun 0:13413ea9a877 652 }
ganlikun 0:13413ea9a877 653 break;
ganlikun 0:13413ea9a877 654
ganlikun 0:13413ea9a877 655 default:
ganlikun 0:13413ea9a877 656 break;
ganlikun 0:13413ea9a877 657 }
ganlikun 0:13413ea9a877 658
ganlikun 0:13413ea9a877 659 /* Disable the Capture compare channel N */
ganlikun 0:13413ea9a877 660 TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_DISABLE);
ganlikun 0:13413ea9a877 661
ganlikun 0:13413ea9a877 662 /* Disable the TIM Break interrupt (only if no more channel is active) */
ganlikun 0:13413ea9a877 663 if((READ_REG(htim->Instance->CCER) & (TIM_CCER_CC1NE | TIM_CCER_CC2NE | TIM_CCER_CC3NE)) == RESET)
ganlikun 0:13413ea9a877 664 {
ganlikun 0:13413ea9a877 665 __HAL_TIM_DISABLE_IT(htim, TIM_IT_BREAK);
ganlikun 0:13413ea9a877 666 }
ganlikun 0:13413ea9a877 667
ganlikun 0:13413ea9a877 668 /* Disable the Main Output */
ganlikun 0:13413ea9a877 669 __HAL_TIM_MOE_DISABLE(htim);
ganlikun 0:13413ea9a877 670
ganlikun 0:13413ea9a877 671 /* Disable the Peripheral */
ganlikun 0:13413ea9a877 672 __HAL_TIM_DISABLE(htim);
ganlikun 0:13413ea9a877 673
ganlikun 0:13413ea9a877 674 /* Return function status */
ganlikun 0:13413ea9a877 675 return HAL_OK;
ganlikun 0:13413ea9a877 676 }
ganlikun 0:13413ea9a877 677
ganlikun 0:13413ea9a877 678 /**
ganlikun 0:13413ea9a877 679 * @brief Starts the TIM Output Compare signal generation in DMA mode
ganlikun 0:13413ea9a877 680 * on the complementary output.
ganlikun 0:13413ea9a877 681 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 682 * the configuration information for TIM module.
ganlikun 0:13413ea9a877 683 * @param Channel: TIM Channel to be enabled.
ganlikun 0:13413ea9a877 684 * This parameter can be one of the following values:
ganlikun 0:13413ea9a877 685 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
ganlikun 0:13413ea9a877 686 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
ganlikun 0:13413ea9a877 687 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
ganlikun 0:13413ea9a877 688 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
ganlikun 0:13413ea9a877 689 * @param pData: The source Buffer address.
ganlikun 0:13413ea9a877 690 * @param Length: The length of data to be transferred from memory to TIM peripheral
ganlikun 0:13413ea9a877 691 * @retval HAL status
ganlikun 0:13413ea9a877 692 */
ganlikun 0:13413ea9a877 693 HAL_StatusTypeDef HAL_TIMEx_OCN_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length)
ganlikun 0:13413ea9a877 694 {
ganlikun 0:13413ea9a877 695 /* Check the parameters */
ganlikun 0:13413ea9a877 696 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
ganlikun 0:13413ea9a877 697
ganlikun 0:13413ea9a877 698 if((htim->State == HAL_TIM_STATE_BUSY))
ganlikun 0:13413ea9a877 699 {
ganlikun 0:13413ea9a877 700 return HAL_BUSY;
ganlikun 0:13413ea9a877 701 }
ganlikun 0:13413ea9a877 702 else if((htim->State == HAL_TIM_STATE_READY))
ganlikun 0:13413ea9a877 703 {
ganlikun 0:13413ea9a877 704 if(((uint32_t)pData == 0U) && (Length > 0))
ganlikun 0:13413ea9a877 705 {
ganlikun 0:13413ea9a877 706 return HAL_ERROR;
ganlikun 0:13413ea9a877 707 }
ganlikun 0:13413ea9a877 708 else
ganlikun 0:13413ea9a877 709 {
ganlikun 0:13413ea9a877 710 htim->State = HAL_TIM_STATE_BUSY;
ganlikun 0:13413ea9a877 711 }
ganlikun 0:13413ea9a877 712 }
ganlikun 0:13413ea9a877 713 switch (Channel)
ganlikun 0:13413ea9a877 714 {
ganlikun 0:13413ea9a877 715 case TIM_CHANNEL_1:
ganlikun 0:13413ea9a877 716 {
ganlikun 0:13413ea9a877 717 /* Set the DMA Period elapsed callback */
ganlikun 0:13413ea9a877 718 htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMADelayPulseCplt;
ganlikun 0:13413ea9a877 719
ganlikun 0:13413ea9a877 720 /* Set the DMA error callback */
ganlikun 0:13413ea9a877 721 htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ;
ganlikun 0:13413ea9a877 722
ganlikun 0:13413ea9a877 723 /* Enable the DMA Stream */
ganlikun 0:13413ea9a877 724 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)pData, (uint32_t)&htim->Instance->CCR1, Length);
ganlikun 0:13413ea9a877 725
ganlikun 0:13413ea9a877 726 /* Enable the TIM Output Compare DMA request */
ganlikun 0:13413ea9a877 727 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1);
ganlikun 0:13413ea9a877 728 }
ganlikun 0:13413ea9a877 729 break;
ganlikun 0:13413ea9a877 730
ganlikun 0:13413ea9a877 731 case TIM_CHANNEL_2:
ganlikun 0:13413ea9a877 732 {
ganlikun 0:13413ea9a877 733 /* Set the DMA Period elapsed callback */
ganlikun 0:13413ea9a877 734 htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMADelayPulseCplt;
ganlikun 0:13413ea9a877 735
ganlikun 0:13413ea9a877 736 /* Set the DMA error callback */
ganlikun 0:13413ea9a877 737 htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError ;
ganlikun 0:13413ea9a877 738
ganlikun 0:13413ea9a877 739 /* Enable the DMA Stream */
ganlikun 0:13413ea9a877 740 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)pData, (uint32_t)&htim->Instance->CCR2, Length);
ganlikun 0:13413ea9a877 741
ganlikun 0:13413ea9a877 742 /* Enable the TIM Output Compare DMA request */
ganlikun 0:13413ea9a877 743 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2);
ganlikun 0:13413ea9a877 744 }
ganlikun 0:13413ea9a877 745 break;
ganlikun 0:13413ea9a877 746
ganlikun 0:13413ea9a877 747 case TIM_CHANNEL_3:
ganlikun 0:13413ea9a877 748 {
ganlikun 0:13413ea9a877 749 /* Set the DMA Period elapsed callback */
ganlikun 0:13413ea9a877 750 htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMADelayPulseCplt;
ganlikun 0:13413ea9a877 751
ganlikun 0:13413ea9a877 752 /* Set the DMA error callback */
ganlikun 0:13413ea9a877 753 htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = TIM_DMAError ;
ganlikun 0:13413ea9a877 754
ganlikun 0:13413ea9a877 755 /* Enable the DMA Stream */
ganlikun 0:13413ea9a877 756 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)pData, (uint32_t)&htim->Instance->CCR3,Length);
ganlikun 0:13413ea9a877 757
ganlikun 0:13413ea9a877 758 /* Enable the TIM Output Compare DMA request */
ganlikun 0:13413ea9a877 759 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC3);
ganlikun 0:13413ea9a877 760 }
ganlikun 0:13413ea9a877 761 break;
ganlikun 0:13413ea9a877 762
ganlikun 0:13413ea9a877 763 case TIM_CHANNEL_4:
ganlikun 0:13413ea9a877 764 {
ganlikun 0:13413ea9a877 765 /* Set the DMA Period elapsed callback */
ganlikun 0:13413ea9a877 766 htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = TIM_DMADelayPulseCplt;
ganlikun 0:13413ea9a877 767
ganlikun 0:13413ea9a877 768 /* Set the DMA error callback */
ganlikun 0:13413ea9a877 769 htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = TIM_DMAError ;
ganlikun 0:13413ea9a877 770
ganlikun 0:13413ea9a877 771 /* Enable the DMA Stream */
ganlikun 0:13413ea9a877 772 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)pData, (uint32_t)&htim->Instance->CCR4, Length);
ganlikun 0:13413ea9a877 773
ganlikun 0:13413ea9a877 774 /* Enable the TIM Output Compare DMA request */
ganlikun 0:13413ea9a877 775 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC4);
ganlikun 0:13413ea9a877 776 }
ganlikun 0:13413ea9a877 777 break;
ganlikun 0:13413ea9a877 778
ganlikun 0:13413ea9a877 779 default:
ganlikun 0:13413ea9a877 780 break;
ganlikun 0:13413ea9a877 781 }
ganlikun 0:13413ea9a877 782
ganlikun 0:13413ea9a877 783 /* Enable the Capture compare channel N */
ganlikun 0:13413ea9a877 784 TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_ENABLE);
ganlikun 0:13413ea9a877 785
ganlikun 0:13413ea9a877 786 /* Enable the Main Output */
ganlikun 0:13413ea9a877 787 __HAL_TIM_MOE_ENABLE(htim);
ganlikun 0:13413ea9a877 788
ganlikun 0:13413ea9a877 789 /* Enable the Peripheral */
ganlikun 0:13413ea9a877 790 __HAL_TIM_ENABLE(htim);
ganlikun 0:13413ea9a877 791
ganlikun 0:13413ea9a877 792 /* Return function status */
ganlikun 0:13413ea9a877 793 return HAL_OK;
ganlikun 0:13413ea9a877 794 }
ganlikun 0:13413ea9a877 795
ganlikun 0:13413ea9a877 796 /**
ganlikun 0:13413ea9a877 797 * @brief Stops the TIM Output Compare signal generation in DMA mode
ganlikun 0:13413ea9a877 798 * on the complementary output.
ganlikun 0:13413ea9a877 799 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 800 * the configuration information for TIM module.
ganlikun 0:13413ea9a877 801 * @param Channel: TIM Channel to be disabled.
ganlikun 0:13413ea9a877 802 * This parameter can be one of the following values:
ganlikun 0:13413ea9a877 803 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
ganlikun 0:13413ea9a877 804 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
ganlikun 0:13413ea9a877 805 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
ganlikun 0:13413ea9a877 806 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
ganlikun 0:13413ea9a877 807 * @retval HAL status
ganlikun 0:13413ea9a877 808 */
ganlikun 0:13413ea9a877 809 HAL_StatusTypeDef HAL_TIMEx_OCN_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel)
ganlikun 0:13413ea9a877 810 {
ganlikun 0:13413ea9a877 811 /* Check the parameters */
ganlikun 0:13413ea9a877 812 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
ganlikun 0:13413ea9a877 813
ganlikun 0:13413ea9a877 814 switch (Channel)
ganlikun 0:13413ea9a877 815 {
ganlikun 0:13413ea9a877 816 case TIM_CHANNEL_1:
ganlikun 0:13413ea9a877 817 {
ganlikun 0:13413ea9a877 818 /* Disable the TIM Output Compare DMA request */
ganlikun 0:13413ea9a877 819 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1);
ganlikun 0:13413ea9a877 820 }
ganlikun 0:13413ea9a877 821 break;
ganlikun 0:13413ea9a877 822
ganlikun 0:13413ea9a877 823 case TIM_CHANNEL_2:
ganlikun 0:13413ea9a877 824 {
ganlikun 0:13413ea9a877 825 /* Disable the TIM Output Compare DMA request */
ganlikun 0:13413ea9a877 826 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2);
ganlikun 0:13413ea9a877 827 }
ganlikun 0:13413ea9a877 828 break;
ganlikun 0:13413ea9a877 829
ganlikun 0:13413ea9a877 830 case TIM_CHANNEL_3:
ganlikun 0:13413ea9a877 831 {
ganlikun 0:13413ea9a877 832 /* Disable the TIM Output Compare DMA request */
ganlikun 0:13413ea9a877 833 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC3);
ganlikun 0:13413ea9a877 834 }
ganlikun 0:13413ea9a877 835 break;
ganlikun 0:13413ea9a877 836
ganlikun 0:13413ea9a877 837 case TIM_CHANNEL_4:
ganlikun 0:13413ea9a877 838 {
ganlikun 0:13413ea9a877 839 /* Disable the TIM Output Compare interrupt */
ganlikun 0:13413ea9a877 840 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC4);
ganlikun 0:13413ea9a877 841 }
ganlikun 0:13413ea9a877 842 break;
ganlikun 0:13413ea9a877 843
ganlikun 0:13413ea9a877 844 default:
ganlikun 0:13413ea9a877 845 break;
ganlikun 0:13413ea9a877 846 }
ganlikun 0:13413ea9a877 847
ganlikun 0:13413ea9a877 848 /* Disable the Capture compare channel N */
ganlikun 0:13413ea9a877 849 TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_DISABLE);
ganlikun 0:13413ea9a877 850
ganlikun 0:13413ea9a877 851 /* Disable the Main Output */
ganlikun 0:13413ea9a877 852 __HAL_TIM_MOE_DISABLE(htim);
ganlikun 0:13413ea9a877 853
ganlikun 0:13413ea9a877 854 /* Disable the Peripheral */
ganlikun 0:13413ea9a877 855 __HAL_TIM_DISABLE(htim);
ganlikun 0:13413ea9a877 856
ganlikun 0:13413ea9a877 857 /* Change the htim state */
ganlikun 0:13413ea9a877 858 htim->State = HAL_TIM_STATE_READY;
ganlikun 0:13413ea9a877 859
ganlikun 0:13413ea9a877 860 /* Return function status */
ganlikun 0:13413ea9a877 861 return HAL_OK;
ganlikun 0:13413ea9a877 862 }
ganlikun 0:13413ea9a877 863 /**
ganlikun 0:13413ea9a877 864 * @}
ganlikun 0:13413ea9a877 865 */
ganlikun 0:13413ea9a877 866
ganlikun 0:13413ea9a877 867 /** @defgroup TIMEx_Exported_Functions_Group3 Timer Complementary PWM functions
ganlikun 0:13413ea9a877 868 * @brief Timer Complementary PWM functions
ganlikun 0:13413ea9a877 869 *
ganlikun 0:13413ea9a877 870 @verbatim
ganlikun 0:13413ea9a877 871 ==============================================================================
ganlikun 0:13413ea9a877 872 ##### Timer Complementary PWM functions #####
ganlikun 0:13413ea9a877 873 ==============================================================================
ganlikun 0:13413ea9a877 874 [..]
ganlikun 0:13413ea9a877 875 This section provides functions allowing to:
ganlikun 0:13413ea9a877 876 (+) Start the Complementary PWM.
ganlikun 0:13413ea9a877 877 (+) Stop the Complementary PWM.
ganlikun 0:13413ea9a877 878 (+) Start the Complementary PWM and enable interrupts.
ganlikun 0:13413ea9a877 879 (+) Stop the Complementary PWM and disable interrupts.
ganlikun 0:13413ea9a877 880 (+) Start the Complementary PWM and enable DMA transfers.
ganlikun 0:13413ea9a877 881 (+) Stop the Complementary PWM and disable DMA transfers.
ganlikun 0:13413ea9a877 882 (+) Start the Complementary Input Capture measurement.
ganlikun 0:13413ea9a877 883 (+) Stop the Complementary Input Capture.
ganlikun 0:13413ea9a877 884 (+) Start the Complementary Input Capture and enable interrupts.
ganlikun 0:13413ea9a877 885 (+) Stop the Complementary Input Capture and disable interrupts.
ganlikun 0:13413ea9a877 886 (+) Start the Complementary Input Capture and enable DMA transfers.
ganlikun 0:13413ea9a877 887 (+) Stop the Complementary Input Capture and disable DMA transfers.
ganlikun 0:13413ea9a877 888 (+) Start the Complementary One Pulse generation.
ganlikun 0:13413ea9a877 889 (+) Stop the Complementary One Pulse.
ganlikun 0:13413ea9a877 890 (+) Start the Complementary One Pulse and enable interrupts.
ganlikun 0:13413ea9a877 891 (+) Stop the Complementary One Pulse and disable interrupts.
ganlikun 0:13413ea9a877 892
ganlikun 0:13413ea9a877 893 @endverbatim
ganlikun 0:13413ea9a877 894 * @{
ganlikun 0:13413ea9a877 895 */
ganlikun 0:13413ea9a877 896
ganlikun 0:13413ea9a877 897 /**
ganlikun 0:13413ea9a877 898 * @brief Starts the PWM signal generation on the complementary output.
ganlikun 0:13413ea9a877 899 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 900 * the configuration information for TIM module.
ganlikun 0:13413ea9a877 901 * @param Channel: TIM Channel to be enabled.
ganlikun 0:13413ea9a877 902 * This parameter can be one of the following values:
ganlikun 0:13413ea9a877 903 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
ganlikun 0:13413ea9a877 904 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
ganlikun 0:13413ea9a877 905 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
ganlikun 0:13413ea9a877 906 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
ganlikun 0:13413ea9a877 907 * @retval HAL status
ganlikun 0:13413ea9a877 908 */
ganlikun 0:13413ea9a877 909 HAL_StatusTypeDef HAL_TIMEx_PWMN_Start(TIM_HandleTypeDef *htim, uint32_t Channel)
ganlikun 0:13413ea9a877 910 {
ganlikun 0:13413ea9a877 911 /* Check the parameters */
ganlikun 0:13413ea9a877 912 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
ganlikun 0:13413ea9a877 913
ganlikun 0:13413ea9a877 914 /* Enable the complementary PWM output */
ganlikun 0:13413ea9a877 915 TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_ENABLE);
ganlikun 0:13413ea9a877 916
ganlikun 0:13413ea9a877 917 /* Enable the Main Output */
ganlikun 0:13413ea9a877 918 __HAL_TIM_MOE_ENABLE(htim);
ganlikun 0:13413ea9a877 919
ganlikun 0:13413ea9a877 920 /* Enable the Peripheral */
ganlikun 0:13413ea9a877 921 __HAL_TIM_ENABLE(htim);
ganlikun 0:13413ea9a877 922
ganlikun 0:13413ea9a877 923 /* Return function status */
ganlikun 0:13413ea9a877 924 return HAL_OK;
ganlikun 0:13413ea9a877 925 }
ganlikun 0:13413ea9a877 926
ganlikun 0:13413ea9a877 927 /**
ganlikun 0:13413ea9a877 928 * @brief Stops the PWM signal generation on the complementary output.
ganlikun 0:13413ea9a877 929 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 930 * the configuration information for TIM module.
ganlikun 0:13413ea9a877 931 * @param Channel: TIM Channel to be disabled.
ganlikun 0:13413ea9a877 932 * This parameter can be one of the following values:
ganlikun 0:13413ea9a877 933 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
ganlikun 0:13413ea9a877 934 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
ganlikun 0:13413ea9a877 935 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
ganlikun 0:13413ea9a877 936 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
ganlikun 0:13413ea9a877 937 * @retval HAL status
ganlikun 0:13413ea9a877 938 */
ganlikun 0:13413ea9a877 939 HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop(TIM_HandleTypeDef *htim, uint32_t Channel)
ganlikun 0:13413ea9a877 940 {
ganlikun 0:13413ea9a877 941 /* Check the parameters */
ganlikun 0:13413ea9a877 942 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
ganlikun 0:13413ea9a877 943
ganlikun 0:13413ea9a877 944 /* Disable the complementary PWM output */
ganlikun 0:13413ea9a877 945 TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_DISABLE);
ganlikun 0:13413ea9a877 946
ganlikun 0:13413ea9a877 947 /* Disable the Main Output */
ganlikun 0:13413ea9a877 948 __HAL_TIM_MOE_DISABLE(htim);
ganlikun 0:13413ea9a877 949
ganlikun 0:13413ea9a877 950 /* Disable the Peripheral */
ganlikun 0:13413ea9a877 951 __HAL_TIM_DISABLE(htim);
ganlikun 0:13413ea9a877 952
ganlikun 0:13413ea9a877 953 /* Return function status */
ganlikun 0:13413ea9a877 954 return HAL_OK;
ganlikun 0:13413ea9a877 955 }
ganlikun 0:13413ea9a877 956
ganlikun 0:13413ea9a877 957 /**
ganlikun 0:13413ea9a877 958 * @brief Starts the PWM signal generation in interrupt mode on the
ganlikun 0:13413ea9a877 959 * complementary output.
ganlikun 0:13413ea9a877 960 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 961 * the configuration information for TIM module.
ganlikun 0:13413ea9a877 962 * @param Channel: TIM Channel to be disabled.
ganlikun 0:13413ea9a877 963 * This parameter can be one of the following values:
ganlikun 0:13413ea9a877 964 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
ganlikun 0:13413ea9a877 965 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
ganlikun 0:13413ea9a877 966 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
ganlikun 0:13413ea9a877 967 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
ganlikun 0:13413ea9a877 968 * @retval HAL status
ganlikun 0:13413ea9a877 969 */
ganlikun 0:13413ea9a877 970 HAL_StatusTypeDef HAL_TIMEx_PWMN_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
ganlikun 0:13413ea9a877 971 {
ganlikun 0:13413ea9a877 972 /* Check the parameters */
ganlikun 0:13413ea9a877 973 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
ganlikun 0:13413ea9a877 974
ganlikun 0:13413ea9a877 975 switch (Channel)
ganlikun 0:13413ea9a877 976 {
ganlikun 0:13413ea9a877 977 case TIM_CHANNEL_1:
ganlikun 0:13413ea9a877 978 {
ganlikun 0:13413ea9a877 979 /* Enable the TIM Capture/Compare 1 interrupt */
ganlikun 0:13413ea9a877 980 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
ganlikun 0:13413ea9a877 981 }
ganlikun 0:13413ea9a877 982 break;
ganlikun 0:13413ea9a877 983
ganlikun 0:13413ea9a877 984 case TIM_CHANNEL_2:
ganlikun 0:13413ea9a877 985 {
ganlikun 0:13413ea9a877 986 /* Enable the TIM Capture/Compare 2 interrupt */
ganlikun 0:13413ea9a877 987 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);
ganlikun 0:13413ea9a877 988 }
ganlikun 0:13413ea9a877 989 break;
ganlikun 0:13413ea9a877 990
ganlikun 0:13413ea9a877 991 case TIM_CHANNEL_3:
ganlikun 0:13413ea9a877 992 {
ganlikun 0:13413ea9a877 993 /* Enable the TIM Capture/Compare 3 interrupt */
ganlikun 0:13413ea9a877 994 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC3);
ganlikun 0:13413ea9a877 995 }
ganlikun 0:13413ea9a877 996 break;
ganlikun 0:13413ea9a877 997
ganlikun 0:13413ea9a877 998 case TIM_CHANNEL_4:
ganlikun 0:13413ea9a877 999 {
ganlikun 0:13413ea9a877 1000 /* Enable the TIM Capture/Compare 4 interrupt */
ganlikun 0:13413ea9a877 1001 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC4);
ganlikun 0:13413ea9a877 1002 }
ganlikun 0:13413ea9a877 1003 break;
ganlikun 0:13413ea9a877 1004
ganlikun 0:13413ea9a877 1005 default:
ganlikun 0:13413ea9a877 1006 break;
ganlikun 0:13413ea9a877 1007 }
ganlikun 0:13413ea9a877 1008
ganlikun 0:13413ea9a877 1009 /* Enable the TIM Break interrupt */
ganlikun 0:13413ea9a877 1010 __HAL_TIM_ENABLE_IT(htim, TIM_IT_BREAK);
ganlikun 0:13413ea9a877 1011
ganlikun 0:13413ea9a877 1012 /* Enable the complementary PWM output */
ganlikun 0:13413ea9a877 1013 TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_ENABLE);
ganlikun 0:13413ea9a877 1014
ganlikun 0:13413ea9a877 1015 /* Enable the Main Output */
ganlikun 0:13413ea9a877 1016 __HAL_TIM_MOE_ENABLE(htim);
ganlikun 0:13413ea9a877 1017
ganlikun 0:13413ea9a877 1018 /* Enable the Peripheral */
ganlikun 0:13413ea9a877 1019 __HAL_TIM_ENABLE(htim);
ganlikun 0:13413ea9a877 1020
ganlikun 0:13413ea9a877 1021 /* Return function status */
ganlikun 0:13413ea9a877 1022 return HAL_OK;
ganlikun 0:13413ea9a877 1023 }
ganlikun 0:13413ea9a877 1024
ganlikun 0:13413ea9a877 1025 /**
ganlikun 0:13413ea9a877 1026 * @brief Stops the PWM signal generation in interrupt mode on the
ganlikun 0:13413ea9a877 1027 * complementary output.
ganlikun 0:13413ea9a877 1028 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 1029 * the configuration information for TIM module.
ganlikun 0:13413ea9a877 1030 * @param Channel: TIM Channel to be disabled.
ganlikun 0:13413ea9a877 1031 * This parameter can be one of the following values:
ganlikun 0:13413ea9a877 1032 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
ganlikun 0:13413ea9a877 1033 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
ganlikun 0:13413ea9a877 1034 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
ganlikun 0:13413ea9a877 1035 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
ganlikun 0:13413ea9a877 1036 * @retval HAL status
ganlikun 0:13413ea9a877 1037 */
ganlikun 0:13413ea9a877 1038 HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop_IT (TIM_HandleTypeDef *htim, uint32_t Channel)
ganlikun 0:13413ea9a877 1039 {
ganlikun 0:13413ea9a877 1040 /* Check the parameters */
ganlikun 0:13413ea9a877 1041 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
ganlikun 0:13413ea9a877 1042
ganlikun 0:13413ea9a877 1043 switch (Channel)
ganlikun 0:13413ea9a877 1044 {
ganlikun 0:13413ea9a877 1045 case TIM_CHANNEL_1:
ganlikun 0:13413ea9a877 1046 {
ganlikun 0:13413ea9a877 1047 /* Disable the TIM Capture/Compare 1 interrupt */
ganlikun 0:13413ea9a877 1048 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
ganlikun 0:13413ea9a877 1049 }
ganlikun 0:13413ea9a877 1050 break;
ganlikun 0:13413ea9a877 1051
ganlikun 0:13413ea9a877 1052 case TIM_CHANNEL_2:
ganlikun 0:13413ea9a877 1053 {
ganlikun 0:13413ea9a877 1054 /* Disable the TIM Capture/Compare 2 interrupt */
ganlikun 0:13413ea9a877 1055 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);
ganlikun 0:13413ea9a877 1056 }
ganlikun 0:13413ea9a877 1057 break;
ganlikun 0:13413ea9a877 1058
ganlikun 0:13413ea9a877 1059 case TIM_CHANNEL_3:
ganlikun 0:13413ea9a877 1060 {
ganlikun 0:13413ea9a877 1061 /* Disable the TIM Capture/Compare 3 interrupt */
ganlikun 0:13413ea9a877 1062 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC3);
ganlikun 0:13413ea9a877 1063 }
ganlikun 0:13413ea9a877 1064 break;
ganlikun 0:13413ea9a877 1065
ganlikun 0:13413ea9a877 1066 case TIM_CHANNEL_4:
ganlikun 0:13413ea9a877 1067 {
ganlikun 0:13413ea9a877 1068 /* Disable the TIM Capture/Compare 3 interrupt */
ganlikun 0:13413ea9a877 1069 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC4);
ganlikun 0:13413ea9a877 1070 }
ganlikun 0:13413ea9a877 1071 break;
ganlikun 0:13413ea9a877 1072
ganlikun 0:13413ea9a877 1073 default:
ganlikun 0:13413ea9a877 1074 break;
ganlikun 0:13413ea9a877 1075 }
ganlikun 0:13413ea9a877 1076
ganlikun 0:13413ea9a877 1077 /* Disable the complementary PWM output */
ganlikun 0:13413ea9a877 1078 TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_DISABLE);
ganlikun 0:13413ea9a877 1079
ganlikun 0:13413ea9a877 1080 /* Disable the TIM Break interrupt (only if no more channel is active) */
ganlikun 0:13413ea9a877 1081 if((READ_REG(htim->Instance->CCER) & (TIM_CCER_CC1NE | TIM_CCER_CC2NE | TIM_CCER_CC3NE)) == RESET)
ganlikun 0:13413ea9a877 1082 {
ganlikun 0:13413ea9a877 1083 __HAL_TIM_DISABLE_IT(htim, TIM_IT_BREAK);
ganlikun 0:13413ea9a877 1084 }
ganlikun 0:13413ea9a877 1085
ganlikun 0:13413ea9a877 1086 /* Disable the Main Output */
ganlikun 0:13413ea9a877 1087 __HAL_TIM_MOE_DISABLE(htim);
ganlikun 0:13413ea9a877 1088
ganlikun 0:13413ea9a877 1089 /* Disable the Peripheral */
ganlikun 0:13413ea9a877 1090 __HAL_TIM_DISABLE(htim);
ganlikun 0:13413ea9a877 1091
ganlikun 0:13413ea9a877 1092 /* Return function status */
ganlikun 0:13413ea9a877 1093 return HAL_OK;
ganlikun 0:13413ea9a877 1094 }
ganlikun 0:13413ea9a877 1095
ganlikun 0:13413ea9a877 1096 /**
ganlikun 0:13413ea9a877 1097 * @brief Starts the TIM PWM signal generation in DMA mode on the
ganlikun 0:13413ea9a877 1098 * complementary output
ganlikun 0:13413ea9a877 1099 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 1100 * the configuration information for TIM module.
ganlikun 0:13413ea9a877 1101 * @param Channel: TIM Channel to be enabled.
ganlikun 0:13413ea9a877 1102 * This parameter can be one of the following values:
ganlikun 0:13413ea9a877 1103 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
ganlikun 0:13413ea9a877 1104 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
ganlikun 0:13413ea9a877 1105 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
ganlikun 0:13413ea9a877 1106 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
ganlikun 0:13413ea9a877 1107 * @param pData: The source Buffer address.
ganlikun 0:13413ea9a877 1108 * @param Length: The length of data to be transferred from memory to TIM peripheral
ganlikun 0:13413ea9a877 1109 * @retval HAL status
ganlikun 0:13413ea9a877 1110 */
ganlikun 0:13413ea9a877 1111 HAL_StatusTypeDef HAL_TIMEx_PWMN_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length)
ganlikun 0:13413ea9a877 1112 {
ganlikun 0:13413ea9a877 1113 /* Check the parameters */
ganlikun 0:13413ea9a877 1114 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
ganlikun 0:13413ea9a877 1115
ganlikun 0:13413ea9a877 1116 if((htim->State == HAL_TIM_STATE_BUSY))
ganlikun 0:13413ea9a877 1117 {
ganlikun 0:13413ea9a877 1118 return HAL_BUSY;
ganlikun 0:13413ea9a877 1119 }
ganlikun 0:13413ea9a877 1120 else if((htim->State == HAL_TIM_STATE_READY))
ganlikun 0:13413ea9a877 1121 {
ganlikun 0:13413ea9a877 1122 if(((uint32_t)pData == 0U) && (Length > 0))
ganlikun 0:13413ea9a877 1123 {
ganlikun 0:13413ea9a877 1124 return HAL_ERROR;
ganlikun 0:13413ea9a877 1125 }
ganlikun 0:13413ea9a877 1126 else
ganlikun 0:13413ea9a877 1127 {
ganlikun 0:13413ea9a877 1128 htim->State = HAL_TIM_STATE_BUSY;
ganlikun 0:13413ea9a877 1129 }
ganlikun 0:13413ea9a877 1130 }
ganlikun 0:13413ea9a877 1131 switch (Channel)
ganlikun 0:13413ea9a877 1132 {
ganlikun 0:13413ea9a877 1133 case TIM_CHANNEL_1:
ganlikun 0:13413ea9a877 1134 {
ganlikun 0:13413ea9a877 1135 /* Set the DMA Period elapsed callback */
ganlikun 0:13413ea9a877 1136 htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMADelayPulseCplt;
ganlikun 0:13413ea9a877 1137
ganlikun 0:13413ea9a877 1138 /* Set the DMA error callback */
ganlikun 0:13413ea9a877 1139 htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ;
ganlikun 0:13413ea9a877 1140
ganlikun 0:13413ea9a877 1141 /* Enable the DMA Stream */
ganlikun 0:13413ea9a877 1142 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)pData, (uint32_t)&htim->Instance->CCR1, Length);
ganlikun 0:13413ea9a877 1143
ganlikun 0:13413ea9a877 1144 /* Enable the TIM Capture/Compare 1 DMA request */
ganlikun 0:13413ea9a877 1145 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1);
ganlikun 0:13413ea9a877 1146 }
ganlikun 0:13413ea9a877 1147 break;
ganlikun 0:13413ea9a877 1148
ganlikun 0:13413ea9a877 1149 case TIM_CHANNEL_2:
ganlikun 0:13413ea9a877 1150 {
ganlikun 0:13413ea9a877 1151 /* Set the DMA Period elapsed callback */
ganlikun 0:13413ea9a877 1152 htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMADelayPulseCplt;
ganlikun 0:13413ea9a877 1153
ganlikun 0:13413ea9a877 1154 /* Set the DMA error callback */
ganlikun 0:13413ea9a877 1155 htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError ;
ganlikun 0:13413ea9a877 1156
ganlikun 0:13413ea9a877 1157 /* Enable the DMA Stream */
ganlikun 0:13413ea9a877 1158 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)pData, (uint32_t)&htim->Instance->CCR2, Length);
ganlikun 0:13413ea9a877 1159
ganlikun 0:13413ea9a877 1160 /* Enable the TIM Capture/Compare 2 DMA request */
ganlikun 0:13413ea9a877 1161 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2);
ganlikun 0:13413ea9a877 1162 }
ganlikun 0:13413ea9a877 1163 break;
ganlikun 0:13413ea9a877 1164
ganlikun 0:13413ea9a877 1165 case TIM_CHANNEL_3:
ganlikun 0:13413ea9a877 1166 {
ganlikun 0:13413ea9a877 1167 /* Set the DMA Period elapsed callback */
ganlikun 0:13413ea9a877 1168 htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMADelayPulseCplt;
ganlikun 0:13413ea9a877 1169
ganlikun 0:13413ea9a877 1170 /* Set the DMA error callback */
ganlikun 0:13413ea9a877 1171 htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = TIM_DMAError ;
ganlikun 0:13413ea9a877 1172
ganlikun 0:13413ea9a877 1173 /* Enable the DMA Stream */
ganlikun 0:13413ea9a877 1174 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)pData, (uint32_t)&htim->Instance->CCR3,Length);
ganlikun 0:13413ea9a877 1175
ganlikun 0:13413ea9a877 1176 /* Enable the TIM Capture/Compare 3 DMA request */
ganlikun 0:13413ea9a877 1177 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC3);
ganlikun 0:13413ea9a877 1178 }
ganlikun 0:13413ea9a877 1179 break;
ganlikun 0:13413ea9a877 1180
ganlikun 0:13413ea9a877 1181 case TIM_CHANNEL_4:
ganlikun 0:13413ea9a877 1182 {
ganlikun 0:13413ea9a877 1183 /* Set the DMA Period elapsed callback */
ganlikun 0:13413ea9a877 1184 htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = TIM_DMADelayPulseCplt;
ganlikun 0:13413ea9a877 1185
ganlikun 0:13413ea9a877 1186 /* Set the DMA error callback */
ganlikun 0:13413ea9a877 1187 htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = TIM_DMAError ;
ganlikun 0:13413ea9a877 1188
ganlikun 0:13413ea9a877 1189 /* Enable the DMA Stream */
ganlikun 0:13413ea9a877 1190 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)pData, (uint32_t)&htim->Instance->CCR4, Length);
ganlikun 0:13413ea9a877 1191
ganlikun 0:13413ea9a877 1192 /* Enable the TIM Capture/Compare 4 DMA request */
ganlikun 0:13413ea9a877 1193 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC4);
ganlikun 0:13413ea9a877 1194 }
ganlikun 0:13413ea9a877 1195 break;
ganlikun 0:13413ea9a877 1196
ganlikun 0:13413ea9a877 1197 default:
ganlikun 0:13413ea9a877 1198 break;
ganlikun 0:13413ea9a877 1199 }
ganlikun 0:13413ea9a877 1200
ganlikun 0:13413ea9a877 1201 /* Enable the complementary PWM output */
ganlikun 0:13413ea9a877 1202 TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_ENABLE);
ganlikun 0:13413ea9a877 1203
ganlikun 0:13413ea9a877 1204 /* Enable the Main Output */
ganlikun 0:13413ea9a877 1205 __HAL_TIM_MOE_ENABLE(htim);
ganlikun 0:13413ea9a877 1206
ganlikun 0:13413ea9a877 1207 /* Enable the Peripheral */
ganlikun 0:13413ea9a877 1208 __HAL_TIM_ENABLE(htim);
ganlikun 0:13413ea9a877 1209
ganlikun 0:13413ea9a877 1210 /* Return function status */
ganlikun 0:13413ea9a877 1211 return HAL_OK;
ganlikun 0:13413ea9a877 1212 }
ganlikun 0:13413ea9a877 1213
ganlikun 0:13413ea9a877 1214 /**
ganlikun 0:13413ea9a877 1215 * @brief Stops the TIM PWM signal generation in DMA mode on the complementary
ganlikun 0:13413ea9a877 1216 * output
ganlikun 0:13413ea9a877 1217 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 1218 * the configuration information for TIM module.
ganlikun 0:13413ea9a877 1219 * @param Channel: TIM Channel to be disabled.
ganlikun 0:13413ea9a877 1220 * This parameter can be one of the following values:
ganlikun 0:13413ea9a877 1221 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
ganlikun 0:13413ea9a877 1222 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
ganlikun 0:13413ea9a877 1223 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
ganlikun 0:13413ea9a877 1224 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
ganlikun 0:13413ea9a877 1225 * @retval HAL status
ganlikun 0:13413ea9a877 1226 */
ganlikun 0:13413ea9a877 1227 HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel)
ganlikun 0:13413ea9a877 1228 {
ganlikun 0:13413ea9a877 1229 /* Check the parameters */
ganlikun 0:13413ea9a877 1230 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
ganlikun 0:13413ea9a877 1231
ganlikun 0:13413ea9a877 1232 switch (Channel)
ganlikun 0:13413ea9a877 1233 {
ganlikun 0:13413ea9a877 1234 case TIM_CHANNEL_1:
ganlikun 0:13413ea9a877 1235 {
ganlikun 0:13413ea9a877 1236 /* Disable the TIM Capture/Compare 1 DMA request */
ganlikun 0:13413ea9a877 1237 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1);
ganlikun 0:13413ea9a877 1238 }
ganlikun 0:13413ea9a877 1239 break;
ganlikun 0:13413ea9a877 1240
ganlikun 0:13413ea9a877 1241 case TIM_CHANNEL_2:
ganlikun 0:13413ea9a877 1242 {
ganlikun 0:13413ea9a877 1243 /* Disable the TIM Capture/Compare 2 DMA request */
ganlikun 0:13413ea9a877 1244 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2);
ganlikun 0:13413ea9a877 1245 }
ganlikun 0:13413ea9a877 1246 break;
ganlikun 0:13413ea9a877 1247
ganlikun 0:13413ea9a877 1248 case TIM_CHANNEL_3:
ganlikun 0:13413ea9a877 1249 {
ganlikun 0:13413ea9a877 1250 /* Disable the TIM Capture/Compare 3 DMA request */
ganlikun 0:13413ea9a877 1251 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC3);
ganlikun 0:13413ea9a877 1252 }
ganlikun 0:13413ea9a877 1253 break;
ganlikun 0:13413ea9a877 1254
ganlikun 0:13413ea9a877 1255 case TIM_CHANNEL_4:
ganlikun 0:13413ea9a877 1256 {
ganlikun 0:13413ea9a877 1257 /* Disable the TIM Capture/Compare 4 DMA request */
ganlikun 0:13413ea9a877 1258 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC4);
ganlikun 0:13413ea9a877 1259 }
ganlikun 0:13413ea9a877 1260 break;
ganlikun 0:13413ea9a877 1261
ganlikun 0:13413ea9a877 1262 default:
ganlikun 0:13413ea9a877 1263 break;
ganlikun 0:13413ea9a877 1264 }
ganlikun 0:13413ea9a877 1265
ganlikun 0:13413ea9a877 1266 /* Disable the complementary PWM output */
ganlikun 0:13413ea9a877 1267 TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_DISABLE);
ganlikun 0:13413ea9a877 1268
ganlikun 0:13413ea9a877 1269 /* Disable the Main Output */
ganlikun 0:13413ea9a877 1270 __HAL_TIM_MOE_DISABLE(htim);
ganlikun 0:13413ea9a877 1271
ganlikun 0:13413ea9a877 1272 /* Disable the Peripheral */
ganlikun 0:13413ea9a877 1273 __HAL_TIM_DISABLE(htim);
ganlikun 0:13413ea9a877 1274
ganlikun 0:13413ea9a877 1275 /* Change the htim state */
ganlikun 0:13413ea9a877 1276 htim->State = HAL_TIM_STATE_READY;
ganlikun 0:13413ea9a877 1277
ganlikun 0:13413ea9a877 1278 /* Return function status */
ganlikun 0:13413ea9a877 1279 return HAL_OK;
ganlikun 0:13413ea9a877 1280 }
ganlikun 0:13413ea9a877 1281
ganlikun 0:13413ea9a877 1282 /**
ganlikun 0:13413ea9a877 1283 * @}
ganlikun 0:13413ea9a877 1284 */
ganlikun 0:13413ea9a877 1285
ganlikun 0:13413ea9a877 1286 /** @defgroup TIMEx_Exported_Functions_Group4 Timer Complementary One Pulse functions
ganlikun 0:13413ea9a877 1287 * @brief Timer Complementary One Pulse functions
ganlikun 0:13413ea9a877 1288 *
ganlikun 0:13413ea9a877 1289 @verbatim
ganlikun 0:13413ea9a877 1290 ==============================================================================
ganlikun 0:13413ea9a877 1291 ##### Timer Complementary One Pulse functions #####
ganlikun 0:13413ea9a877 1292 ==============================================================================
ganlikun 0:13413ea9a877 1293 [..]
ganlikun 0:13413ea9a877 1294 This section provides functions allowing to:
ganlikun 0:13413ea9a877 1295 (+) Start the Complementary One Pulse generation.
ganlikun 0:13413ea9a877 1296 (+) Stop the Complementary One Pulse.
ganlikun 0:13413ea9a877 1297 (+) Start the Complementary One Pulse and enable interrupts.
ganlikun 0:13413ea9a877 1298 (+) Stop the Complementary One Pulse and disable interrupts.
ganlikun 0:13413ea9a877 1299
ganlikun 0:13413ea9a877 1300 @endverbatim
ganlikun 0:13413ea9a877 1301 * @{
ganlikun 0:13413ea9a877 1302 */
ganlikun 0:13413ea9a877 1303
ganlikun 0:13413ea9a877 1304 /**
ganlikun 0:13413ea9a877 1305 * @brief Starts the TIM One Pulse signal generation on the complementary
ganlikun 0:13413ea9a877 1306 * output.
ganlikun 0:13413ea9a877 1307 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 1308 * the configuration information for TIM module.
ganlikun 0:13413ea9a877 1309 * @param OutputChannel: TIM Channel to be enabled.
ganlikun 0:13413ea9a877 1310 * This parameter can be one of the following values:
ganlikun 0:13413ea9a877 1311 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
ganlikun 0:13413ea9a877 1312 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
ganlikun 0:13413ea9a877 1313 * @retval HAL status
ganlikun 0:13413ea9a877 1314 */
ganlikun 0:13413ea9a877 1315 HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Start(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
ganlikun 0:13413ea9a877 1316 {
ganlikun 0:13413ea9a877 1317 /* Check the parameters */
ganlikun 0:13413ea9a877 1318 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, OutputChannel));
ganlikun 0:13413ea9a877 1319
ganlikun 0:13413ea9a877 1320 /* Enable the complementary One Pulse output */
ganlikun 0:13413ea9a877 1321 TIM_CCxNChannelCmd(htim->Instance, OutputChannel, TIM_CCxN_ENABLE);
ganlikun 0:13413ea9a877 1322
ganlikun 0:13413ea9a877 1323 /* Enable the Main Output */
ganlikun 0:13413ea9a877 1324 __HAL_TIM_MOE_ENABLE(htim);
ganlikun 0:13413ea9a877 1325
ganlikun 0:13413ea9a877 1326 /* Return function status */
ganlikun 0:13413ea9a877 1327 return HAL_OK;
ganlikun 0:13413ea9a877 1328 }
ganlikun 0:13413ea9a877 1329
ganlikun 0:13413ea9a877 1330 /**
ganlikun 0:13413ea9a877 1331 * @brief Stops the TIM One Pulse signal generation on the complementary
ganlikun 0:13413ea9a877 1332 * output.
ganlikun 0:13413ea9a877 1333 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 1334 * the configuration information for TIM module.
ganlikun 0:13413ea9a877 1335 * @param OutputChannel: TIM Channel to be disabled.
ganlikun 0:13413ea9a877 1336 * This parameter can be one of the following values:
ganlikun 0:13413ea9a877 1337 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
ganlikun 0:13413ea9a877 1338 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
ganlikun 0:13413ea9a877 1339 * @retval HAL status
ganlikun 0:13413ea9a877 1340 */
ganlikun 0:13413ea9a877 1341 HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Stop(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
ganlikun 0:13413ea9a877 1342 {
ganlikun 0:13413ea9a877 1343
ganlikun 0:13413ea9a877 1344 /* Check the parameters */
ganlikun 0:13413ea9a877 1345 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, OutputChannel));
ganlikun 0:13413ea9a877 1346
ganlikun 0:13413ea9a877 1347 /* Disable the complementary One Pulse output */
ganlikun 0:13413ea9a877 1348 TIM_CCxNChannelCmd(htim->Instance, OutputChannel, TIM_CCxN_DISABLE);
ganlikun 0:13413ea9a877 1349
ganlikun 0:13413ea9a877 1350 /* Disable the Main Output */
ganlikun 0:13413ea9a877 1351 __HAL_TIM_MOE_DISABLE(htim);
ganlikun 0:13413ea9a877 1352
ganlikun 0:13413ea9a877 1353 /* Disable the Peripheral */
ganlikun 0:13413ea9a877 1354 __HAL_TIM_DISABLE(htim);
ganlikun 0:13413ea9a877 1355
ganlikun 0:13413ea9a877 1356 /* Return function status */
ganlikun 0:13413ea9a877 1357 return HAL_OK;
ganlikun 0:13413ea9a877 1358 }
ganlikun 0:13413ea9a877 1359
ganlikun 0:13413ea9a877 1360 /**
ganlikun 0:13413ea9a877 1361 * @brief Starts the TIM One Pulse signal generation in interrupt mode on the
ganlikun 0:13413ea9a877 1362 * complementary channel.
ganlikun 0:13413ea9a877 1363 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 1364 * the configuration information for TIM module.
ganlikun 0:13413ea9a877 1365 * @param OutputChannel: TIM Channel to be enabled.
ganlikun 0:13413ea9a877 1366 * This parameter can be one of the following values:
ganlikun 0:13413ea9a877 1367 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
ganlikun 0:13413ea9a877 1368 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
ganlikun 0:13413ea9a877 1369 * @retval HAL status
ganlikun 0:13413ea9a877 1370 */
ganlikun 0:13413ea9a877 1371 HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Start_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
ganlikun 0:13413ea9a877 1372 {
ganlikun 0:13413ea9a877 1373 /* Check the parameters */
ganlikun 0:13413ea9a877 1374 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, OutputChannel));
ganlikun 0:13413ea9a877 1375
ganlikun 0:13413ea9a877 1376 /* Enable the TIM Capture/Compare 1 interrupt */
ganlikun 0:13413ea9a877 1377 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
ganlikun 0:13413ea9a877 1378
ganlikun 0:13413ea9a877 1379 /* Enable the TIM Capture/Compare 2 interrupt */
ganlikun 0:13413ea9a877 1380 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);
ganlikun 0:13413ea9a877 1381
ganlikun 0:13413ea9a877 1382 /* Enable the complementary One Pulse output */
ganlikun 0:13413ea9a877 1383 TIM_CCxNChannelCmd(htim->Instance, OutputChannel, TIM_CCxN_ENABLE);
ganlikun 0:13413ea9a877 1384
ganlikun 0:13413ea9a877 1385 /* Enable the Main Output */
ganlikun 0:13413ea9a877 1386 __HAL_TIM_MOE_ENABLE(htim);
ganlikun 0:13413ea9a877 1387
ganlikun 0:13413ea9a877 1388 /* Return function status */
ganlikun 0:13413ea9a877 1389 return HAL_OK;
ganlikun 0:13413ea9a877 1390 }
ganlikun 0:13413ea9a877 1391
ganlikun 0:13413ea9a877 1392 /**
ganlikun 0:13413ea9a877 1393 * @brief Stops the TIM One Pulse signal generation in interrupt mode on the
ganlikun 0:13413ea9a877 1394 * complementary channel.
ganlikun 0:13413ea9a877 1395 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 1396 * the configuration information for TIM module.
ganlikun 0:13413ea9a877 1397 * @param OutputChannel: TIM Channel to be disabled.
ganlikun 0:13413ea9a877 1398 * This parameter can be one of the following values:
ganlikun 0:13413ea9a877 1399 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
ganlikun 0:13413ea9a877 1400 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
ganlikun 0:13413ea9a877 1401 * @retval HAL status
ganlikun 0:13413ea9a877 1402 */
ganlikun 0:13413ea9a877 1403 HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
ganlikun 0:13413ea9a877 1404 {
ganlikun 0:13413ea9a877 1405 /* Check the parameters */
ganlikun 0:13413ea9a877 1406 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, OutputChannel));
ganlikun 0:13413ea9a877 1407
ganlikun 0:13413ea9a877 1408 /* Disable the TIM Capture/Compare 1 interrupt */
ganlikun 0:13413ea9a877 1409 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
ganlikun 0:13413ea9a877 1410
ganlikun 0:13413ea9a877 1411 /* Disable the TIM Capture/Compare 2 interrupt */
ganlikun 0:13413ea9a877 1412 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);
ganlikun 0:13413ea9a877 1413
ganlikun 0:13413ea9a877 1414 /* Disable the complementary One Pulse output */
ganlikun 0:13413ea9a877 1415 TIM_CCxNChannelCmd(htim->Instance, OutputChannel, TIM_CCxN_DISABLE);
ganlikun 0:13413ea9a877 1416
ganlikun 0:13413ea9a877 1417 /* Disable the Main Output */
ganlikun 0:13413ea9a877 1418 __HAL_TIM_MOE_DISABLE(htim);
ganlikun 0:13413ea9a877 1419
ganlikun 0:13413ea9a877 1420 /* Disable the Peripheral */
ganlikun 0:13413ea9a877 1421 __HAL_TIM_DISABLE(htim);
ganlikun 0:13413ea9a877 1422
ganlikun 0:13413ea9a877 1423 /* Return function status */
ganlikun 0:13413ea9a877 1424 return HAL_OK;
ganlikun 0:13413ea9a877 1425 }
ganlikun 0:13413ea9a877 1426 /**
ganlikun 0:13413ea9a877 1427 * @}
ganlikun 0:13413ea9a877 1428 */
ganlikun 0:13413ea9a877 1429
ganlikun 0:13413ea9a877 1430 /** @defgroup TIMEx_Exported_Functions_Group5 Peripheral Control functions
ganlikun 0:13413ea9a877 1431 * @brief Peripheral Control functions
ganlikun 0:13413ea9a877 1432 *
ganlikun 0:13413ea9a877 1433 @verbatim
ganlikun 0:13413ea9a877 1434 ==============================================================================
ganlikun 0:13413ea9a877 1435 ##### Peripheral Control functions #####
ganlikun 0:13413ea9a877 1436 ==============================================================================
ganlikun 0:13413ea9a877 1437 [..]
ganlikun 0:13413ea9a877 1438 This section provides functions allowing to:
ganlikun 0:13413ea9a877 1439 (+) Configure The Input Output channels for OC, PWM, IC or One Pulse mode.
ganlikun 0:13413ea9a877 1440 (+) Configure External Clock source.
ganlikun 0:13413ea9a877 1441 (+) Configure Complementary channels, break features and dead time.
ganlikun 0:13413ea9a877 1442 (+) Configure Master and the Slave synchronization.
ganlikun 0:13413ea9a877 1443 (+) Configure the commutation event in case of use of the Hall sensor interface.
ganlikun 0:13413ea9a877 1444 (+) Configure the DMA Burst Mode.
ganlikun 0:13413ea9a877 1445
ganlikun 0:13413ea9a877 1446 @endverbatim
ganlikun 0:13413ea9a877 1447 * @{
ganlikun 0:13413ea9a877 1448 */
ganlikun 0:13413ea9a877 1449 /**
ganlikun 0:13413ea9a877 1450 * @brief Configure the TIM commutation event sequence.
ganlikun 0:13413ea9a877 1451 * @note This function is mandatory to use the commutation event in order to
ganlikun 0:13413ea9a877 1452 * update the configuration at each commutation detection on the TRGI input of the Timer,
ganlikun 0:13413ea9a877 1453 * the typical use of this feature is with the use of another Timer(interface Timer)
ganlikun 0:13413ea9a877 1454 * configured in Hall sensor interface, this interface Timer will generate the
ganlikun 0:13413ea9a877 1455 * commutation at its TRGO output (connected to Timer used in this function) each time
ganlikun 0:13413ea9a877 1456 * the TI1 of the Interface Timer detect a commutation at its input TI1.
ganlikun 0:13413ea9a877 1457 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 1458 * the configuration information for TIM module.
ganlikun 0:13413ea9a877 1459 * @param InputTrigger: the Internal trigger corresponding to the Timer Interfacing with the Hall sensor.
ganlikun 0:13413ea9a877 1460 * This parameter can be one of the following values:
ganlikun 0:13413ea9a877 1461 * @arg TIM_TS_ITR0: Internal trigger 0 selected
ganlikun 0:13413ea9a877 1462 * @arg TIM_TS_ITR1: Internal trigger 1 selected
ganlikun 0:13413ea9a877 1463 * @arg TIM_TS_ITR2: Internal trigger 2 selected
ganlikun 0:13413ea9a877 1464 * @arg TIM_TS_ITR3: Internal trigger 3 selected
ganlikun 0:13413ea9a877 1465 * @arg TIM_TS_NONE: No trigger is needed
ganlikun 0:13413ea9a877 1466 * @param CommutationSource: the Commutation Event source.
ganlikun 0:13413ea9a877 1467 * This parameter can be one of the following values:
ganlikun 0:13413ea9a877 1468 * @arg TIM_COMMUTATION_TRGI: Commutation source is the TRGI of the Interface Timer
ganlikun 0:13413ea9a877 1469 * @arg TIM_COMMUTATION_SOFTWARE: Commutation source is set by software using the COMG bit
ganlikun 0:13413ea9a877 1470 * @retval HAL status
ganlikun 0:13413ea9a877 1471 */
ganlikun 0:13413ea9a877 1472 HAL_StatusTypeDef HAL_TIMEx_ConfigCommutationEvent(TIM_HandleTypeDef *htim, uint32_t InputTrigger, uint32_t CommutationSource)
ganlikun 0:13413ea9a877 1473 {
ganlikun 0:13413ea9a877 1474 /* Check the parameters */
ganlikun 0:13413ea9a877 1475 assert_param(IS_TIM_ADVANCED_INSTANCE(htim->Instance));
ganlikun 0:13413ea9a877 1476 assert_param(IS_TIM_INTERNAL_TRIGGEREVENT_SELECTION(InputTrigger));
ganlikun 0:13413ea9a877 1477
ganlikun 0:13413ea9a877 1478 __HAL_LOCK(htim);
ganlikun 0:13413ea9a877 1479
ganlikun 0:13413ea9a877 1480 if ((InputTrigger == TIM_TS_ITR0) || (InputTrigger == TIM_TS_ITR1) ||
ganlikun 0:13413ea9a877 1481 (InputTrigger == TIM_TS_ITR2) || (InputTrigger == TIM_TS_ITR3))
ganlikun 0:13413ea9a877 1482 {
ganlikun 0:13413ea9a877 1483 /* Select the Input trigger */
ganlikun 0:13413ea9a877 1484 htim->Instance->SMCR &= ~TIM_SMCR_TS;
ganlikun 0:13413ea9a877 1485 htim->Instance->SMCR |= InputTrigger;
ganlikun 0:13413ea9a877 1486 }
ganlikun 0:13413ea9a877 1487
ganlikun 0:13413ea9a877 1488 /* Select the Capture Compare preload feature */
ganlikun 0:13413ea9a877 1489 htim->Instance->CR2 |= TIM_CR2_CCPC;
ganlikun 0:13413ea9a877 1490 /* Select the Commutation event source */
ganlikun 0:13413ea9a877 1491 htim->Instance->CR2 &= ~TIM_CR2_CCUS;
ganlikun 0:13413ea9a877 1492 htim->Instance->CR2 |= CommutationSource;
ganlikun 0:13413ea9a877 1493
ganlikun 0:13413ea9a877 1494 __HAL_UNLOCK(htim);
ganlikun 0:13413ea9a877 1495
ganlikun 0:13413ea9a877 1496 return HAL_OK;
ganlikun 0:13413ea9a877 1497 }
ganlikun 0:13413ea9a877 1498
ganlikun 0:13413ea9a877 1499 /**
ganlikun 0:13413ea9a877 1500 * @brief Configure the TIM commutation event sequence with interrupt.
ganlikun 0:13413ea9a877 1501 * @note This function is mandatory to use the commutation event in order to
ganlikun 0:13413ea9a877 1502 * update the configuration at each commutation detection on the TRGI input of the Timer,
ganlikun 0:13413ea9a877 1503 * the typical use of this feature is with the use of another Timer(interface Timer)
ganlikun 0:13413ea9a877 1504 * configured in Hall sensor interface, this interface Timer will generate the
ganlikun 0:13413ea9a877 1505 * commutation at its TRGO output (connected to Timer used in this function) each time
ganlikun 0:13413ea9a877 1506 * the TI1 of the Interface Timer detect a commutation at its input TI1.
ganlikun 0:13413ea9a877 1507 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 1508 * the configuration information for TIM module.
ganlikun 0:13413ea9a877 1509 * @param InputTrigger: the Internal trigger corresponding to the Timer Interfacing with the Hall sensor.
ganlikun 0:13413ea9a877 1510 * This parameter can be one of the following values:
ganlikun 0:13413ea9a877 1511 * @arg TIM_TS_ITR0: Internal trigger 0 selected
ganlikun 0:13413ea9a877 1512 * @arg TIM_TS_ITR1: Internal trigger 1 selected
ganlikun 0:13413ea9a877 1513 * @arg TIM_TS_ITR2: Internal trigger 2 selected
ganlikun 0:13413ea9a877 1514 * @arg TIM_TS_ITR3: Internal trigger 3 selected
ganlikun 0:13413ea9a877 1515 * @arg TIM_TS_NONE: No trigger is needed
ganlikun 0:13413ea9a877 1516 * @param CommutationSource: the Commutation Event source.
ganlikun 0:13413ea9a877 1517 * This parameter can be one of the following values:
ganlikun 0:13413ea9a877 1518 * @arg TIM_COMMUTATION_TRGI: Commutation source is the TRGI of the Interface Timer
ganlikun 0:13413ea9a877 1519 * @arg TIM_COMMUTATION_SOFTWARE: Commutation source is set by software using the COMG bit
ganlikun 0:13413ea9a877 1520 * @retval HAL status
ganlikun 0:13413ea9a877 1521 */
ganlikun 0:13413ea9a877 1522 HAL_StatusTypeDef HAL_TIMEx_ConfigCommutationEvent_IT(TIM_HandleTypeDef *htim, uint32_t InputTrigger, uint32_t CommutationSource)
ganlikun 0:13413ea9a877 1523 {
ganlikun 0:13413ea9a877 1524 /* Check the parameters */
ganlikun 0:13413ea9a877 1525 assert_param(IS_TIM_ADVANCED_INSTANCE(htim->Instance));
ganlikun 0:13413ea9a877 1526 assert_param(IS_TIM_INTERNAL_TRIGGEREVENT_SELECTION(InputTrigger));
ganlikun 0:13413ea9a877 1527
ganlikun 0:13413ea9a877 1528 __HAL_LOCK(htim);
ganlikun 0:13413ea9a877 1529
ganlikun 0:13413ea9a877 1530 if ((InputTrigger == TIM_TS_ITR0) || (InputTrigger == TIM_TS_ITR1) ||
ganlikun 0:13413ea9a877 1531 (InputTrigger == TIM_TS_ITR2) || (InputTrigger == TIM_TS_ITR3))
ganlikun 0:13413ea9a877 1532 {
ganlikun 0:13413ea9a877 1533 /* Select the Input trigger */
ganlikun 0:13413ea9a877 1534 htim->Instance->SMCR &= ~TIM_SMCR_TS;
ganlikun 0:13413ea9a877 1535 htim->Instance->SMCR |= InputTrigger;
ganlikun 0:13413ea9a877 1536 }
ganlikun 0:13413ea9a877 1537
ganlikun 0:13413ea9a877 1538 /* Select the Capture Compare preload feature */
ganlikun 0:13413ea9a877 1539 htim->Instance->CR2 |= TIM_CR2_CCPC;
ganlikun 0:13413ea9a877 1540 /* Select the Commutation event source */
ganlikun 0:13413ea9a877 1541 htim->Instance->CR2 &= ~TIM_CR2_CCUS;
ganlikun 0:13413ea9a877 1542 htim->Instance->CR2 |= CommutationSource;
ganlikun 0:13413ea9a877 1543
ganlikun 0:13413ea9a877 1544 /* Enable the Commutation Interrupt Request */
ganlikun 0:13413ea9a877 1545 __HAL_TIM_ENABLE_IT(htim, TIM_IT_COM);
ganlikun 0:13413ea9a877 1546
ganlikun 0:13413ea9a877 1547 __HAL_UNLOCK(htim);
ganlikun 0:13413ea9a877 1548
ganlikun 0:13413ea9a877 1549 return HAL_OK;
ganlikun 0:13413ea9a877 1550 }
ganlikun 0:13413ea9a877 1551
ganlikun 0:13413ea9a877 1552 /**
ganlikun 0:13413ea9a877 1553 * @brief Configure the TIM commutation event sequence with DMA.
ganlikun 0:13413ea9a877 1554 * @note This function is mandatory to use the commutation event in order to
ganlikun 0:13413ea9a877 1555 * update the configuration at each commutation detection on the TRGI input of the Timer,
ganlikun 0:13413ea9a877 1556 * the typical use of this feature is with the use of another Timer(interface Timer)
ganlikun 0:13413ea9a877 1557 * configured in Hall sensor interface, this interface Timer will generate the
ganlikun 0:13413ea9a877 1558 * commutation at its TRGO output (connected to Timer used in this function) each time
ganlikun 0:13413ea9a877 1559 * the TI1 of the Interface Timer detect a commutation at its input TI1.
ganlikun 0:13413ea9a877 1560 * @note: The user should configure the DMA in his own software, in This function only the COMDE bit is set
ganlikun 0:13413ea9a877 1561 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 1562 * the configuration information for TIM module.
ganlikun 0:13413ea9a877 1563 * @param InputTrigger: the Internal trigger corresponding to the Timer Interfacing with the Hall sensor.
ganlikun 0:13413ea9a877 1564 * This parameter can be one of the following values:
ganlikun 0:13413ea9a877 1565 * @arg TIM_TS_ITR0: Internal trigger 0 selected
ganlikun 0:13413ea9a877 1566 * @arg TIM_TS_ITR1: Internal trigger 1 selected
ganlikun 0:13413ea9a877 1567 * @arg TIM_TS_ITR2: Internal trigger 2 selected
ganlikun 0:13413ea9a877 1568 * @arg TIM_TS_ITR3: Internal trigger 3 selected
ganlikun 0:13413ea9a877 1569 * @arg TIM_TS_NONE: No trigger is needed
ganlikun 0:13413ea9a877 1570 * @param CommutationSource: the Commutation Event source.
ganlikun 0:13413ea9a877 1571 * This parameter can be one of the following values:
ganlikun 0:13413ea9a877 1572 * @arg TIM_COMMUTATION_TRGI: Commutation source is the TRGI of the Interface Timer
ganlikun 0:13413ea9a877 1573 * @arg TIM_COMMUTATION_SOFTWARE: Commutation source is set by software using the COMG bit
ganlikun 0:13413ea9a877 1574 * @retval HAL status
ganlikun 0:13413ea9a877 1575 */
ganlikun 0:13413ea9a877 1576 HAL_StatusTypeDef HAL_TIMEx_ConfigCommutationEvent_DMA(TIM_HandleTypeDef *htim, uint32_t InputTrigger, uint32_t CommutationSource)
ganlikun 0:13413ea9a877 1577 {
ganlikun 0:13413ea9a877 1578 /* Check the parameters */
ganlikun 0:13413ea9a877 1579 assert_param(IS_TIM_ADVANCED_INSTANCE(htim->Instance));
ganlikun 0:13413ea9a877 1580 assert_param(IS_TIM_INTERNAL_TRIGGEREVENT_SELECTION(InputTrigger));
ganlikun 0:13413ea9a877 1581
ganlikun 0:13413ea9a877 1582 __HAL_LOCK(htim);
ganlikun 0:13413ea9a877 1583
ganlikun 0:13413ea9a877 1584 if ((InputTrigger == TIM_TS_ITR0) || (InputTrigger == TIM_TS_ITR1) ||
ganlikun 0:13413ea9a877 1585 (InputTrigger == TIM_TS_ITR2) || (InputTrigger == TIM_TS_ITR3))
ganlikun 0:13413ea9a877 1586 {
ganlikun 0:13413ea9a877 1587 /* Select the Input trigger */
ganlikun 0:13413ea9a877 1588 htim->Instance->SMCR &= ~TIM_SMCR_TS;
ganlikun 0:13413ea9a877 1589 htim->Instance->SMCR |= InputTrigger;
ganlikun 0:13413ea9a877 1590 }
ganlikun 0:13413ea9a877 1591
ganlikun 0:13413ea9a877 1592 /* Select the Capture Compare preload feature */
ganlikun 0:13413ea9a877 1593 htim->Instance->CR2 |= TIM_CR2_CCPC;
ganlikun 0:13413ea9a877 1594 /* Select the Commutation event source */
ganlikun 0:13413ea9a877 1595 htim->Instance->CR2 &= ~TIM_CR2_CCUS;
ganlikun 0:13413ea9a877 1596 htim->Instance->CR2 |= CommutationSource;
ganlikun 0:13413ea9a877 1597
ganlikun 0:13413ea9a877 1598 /* Enable the Commutation DMA Request */
ganlikun 0:13413ea9a877 1599 /* Set the DMA Commutation Callback */
ganlikun 0:13413ea9a877 1600 htim->hdma[TIM_DMA_ID_COMMUTATION]->XferCpltCallback = TIMEx_DMACommutationCplt;
ganlikun 0:13413ea9a877 1601 /* Set the DMA error callback */
ganlikun 0:13413ea9a877 1602 htim->hdma[TIM_DMA_ID_COMMUTATION]->XferErrorCallback = TIM_DMAError;
ganlikun 0:13413ea9a877 1603
ganlikun 0:13413ea9a877 1604 /* Enable the Commutation DMA Request */
ganlikun 0:13413ea9a877 1605 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_COM);
ganlikun 0:13413ea9a877 1606
ganlikun 0:13413ea9a877 1607 __HAL_UNLOCK(htim);
ganlikun 0:13413ea9a877 1608
ganlikun 0:13413ea9a877 1609 return HAL_OK;
ganlikun 0:13413ea9a877 1610 }
ganlikun 0:13413ea9a877 1611
ganlikun 0:13413ea9a877 1612 /**
ganlikun 0:13413ea9a877 1613 * @brief Configures the TIM in master mode.
ganlikun 0:13413ea9a877 1614 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 1615 * the configuration information for TIM module.
ganlikun 0:13413ea9a877 1616 * @param sMasterConfig: pointer to a TIM_MasterConfigTypeDef structure that
ganlikun 0:13413ea9a877 1617 * contains the selected trigger output (TRGO) and the Master/Slave
ganlikun 0:13413ea9a877 1618 * mode.
ganlikun 0:13413ea9a877 1619 * @retval HAL status
ganlikun 0:13413ea9a877 1620 */
ganlikun 0:13413ea9a877 1621 HAL_StatusTypeDef HAL_TIMEx_MasterConfigSynchronization(TIM_HandleTypeDef *htim, TIM_MasterConfigTypeDef * sMasterConfig)
ganlikun 0:13413ea9a877 1622 {
ganlikun 0:13413ea9a877 1623 /* Check the parameters */
ganlikun 0:13413ea9a877 1624 assert_param(IS_TIM_MASTER_INSTANCE(htim->Instance));
ganlikun 0:13413ea9a877 1625 assert_param(IS_TIM_TRGO_SOURCE(sMasterConfig->MasterOutputTrigger));
ganlikun 0:13413ea9a877 1626 assert_param(IS_TIM_MSM_STATE(sMasterConfig->MasterSlaveMode));
ganlikun 0:13413ea9a877 1627
ganlikun 0:13413ea9a877 1628 __HAL_LOCK(htim);
ganlikun 0:13413ea9a877 1629
ganlikun 0:13413ea9a877 1630 htim->State = HAL_TIM_STATE_BUSY;
ganlikun 0:13413ea9a877 1631
ganlikun 0:13413ea9a877 1632 /* Reset the MMS Bits */
ganlikun 0:13413ea9a877 1633 htim->Instance->CR2 &= ~TIM_CR2_MMS;
ganlikun 0:13413ea9a877 1634 /* Select the TRGO source */
ganlikun 0:13413ea9a877 1635 htim->Instance->CR2 |= sMasterConfig->MasterOutputTrigger;
ganlikun 0:13413ea9a877 1636
ganlikun 0:13413ea9a877 1637 /* Reset the MSM Bit */
ganlikun 0:13413ea9a877 1638 htim->Instance->SMCR &= ~TIM_SMCR_MSM;
ganlikun 0:13413ea9a877 1639 /* Set or Reset the MSM Bit */
ganlikun 0:13413ea9a877 1640 htim->Instance->SMCR |= sMasterConfig->MasterSlaveMode;
ganlikun 0:13413ea9a877 1641
ganlikun 0:13413ea9a877 1642 htim->State = HAL_TIM_STATE_READY;
ganlikun 0:13413ea9a877 1643
ganlikun 0:13413ea9a877 1644 __HAL_UNLOCK(htim);
ganlikun 0:13413ea9a877 1645
ganlikun 0:13413ea9a877 1646 return HAL_OK;
ganlikun 0:13413ea9a877 1647 }
ganlikun 0:13413ea9a877 1648
ganlikun 0:13413ea9a877 1649 /**
ganlikun 0:13413ea9a877 1650 * @brief Configures the Break feature, dead time, Lock level, OSSI/OSSR State
ganlikun 0:13413ea9a877 1651 * and the AOE(automatic output enable).
ganlikun 0:13413ea9a877 1652 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 1653 * the configuration information for TIM module.
ganlikun 0:13413ea9a877 1654 * @param sBreakDeadTimeConfig: pointer to a TIM_ConfigBreakDeadConfig_TypeDef structure that
ganlikun 0:13413ea9a877 1655 * contains the BDTR Register configuration information for the TIM peripheral.
ganlikun 0:13413ea9a877 1656 * @retval HAL status
ganlikun 0:13413ea9a877 1657 */
ganlikun 0:13413ea9a877 1658 HAL_StatusTypeDef HAL_TIMEx_ConfigBreakDeadTime(TIM_HandleTypeDef *htim,
ganlikun 0:13413ea9a877 1659 TIM_BreakDeadTimeConfigTypeDef * sBreakDeadTimeConfig)
ganlikun 0:13413ea9a877 1660 {
ganlikun 0:13413ea9a877 1661 uint32_t tmpbdtr = 0U;
ganlikun 0:13413ea9a877 1662
ganlikun 0:13413ea9a877 1663 /* Check the parameters */
ganlikun 0:13413ea9a877 1664 assert_param(IS_TIM_BREAK_INSTANCE(htim->Instance));
ganlikun 0:13413ea9a877 1665 assert_param(IS_TIM_OSSR_STATE(sBreakDeadTimeConfig->OffStateRunMode));
ganlikun 0:13413ea9a877 1666 assert_param(IS_TIM_OSSI_STATE(sBreakDeadTimeConfig->OffStateIDLEMode));
ganlikun 0:13413ea9a877 1667 assert_param(IS_TIM_LOCK_LEVEL(sBreakDeadTimeConfig->LockLevel));
ganlikun 0:13413ea9a877 1668 assert_param(IS_TIM_DEADTIME(sBreakDeadTimeConfig->DeadTime));
ganlikun 0:13413ea9a877 1669 assert_param(IS_TIM_BREAK_STATE(sBreakDeadTimeConfig->BreakState));
ganlikun 0:13413ea9a877 1670 assert_param(IS_TIM_BREAK_POLARITY(sBreakDeadTimeConfig->BreakPolarity));
ganlikun 0:13413ea9a877 1671 assert_param(IS_TIM_AUTOMATIC_OUTPUT_STATE(sBreakDeadTimeConfig->AutomaticOutput));
ganlikun 0:13413ea9a877 1672
ganlikun 0:13413ea9a877 1673 /* Check input state */
ganlikun 0:13413ea9a877 1674 __HAL_LOCK(htim);
ganlikun 0:13413ea9a877 1675
ganlikun 0:13413ea9a877 1676 /* Set the Lock level, the Break enable Bit and the Polarity, the OSSR State,
ganlikun 0:13413ea9a877 1677 the OSSI State, the dead time value and the Automatic Output Enable Bit */
ganlikun 0:13413ea9a877 1678
ganlikun 0:13413ea9a877 1679 /* Set the BDTR bits */
ganlikun 0:13413ea9a877 1680 MODIFY_REG(tmpbdtr, TIM_BDTR_DTG, sBreakDeadTimeConfig->DeadTime);
ganlikun 0:13413ea9a877 1681 MODIFY_REG(tmpbdtr, TIM_BDTR_LOCK, sBreakDeadTimeConfig->LockLevel);
ganlikun 0:13413ea9a877 1682 MODIFY_REG(tmpbdtr, TIM_BDTR_OSSI, sBreakDeadTimeConfig->OffStateIDLEMode);
ganlikun 0:13413ea9a877 1683 MODIFY_REG(tmpbdtr, TIM_BDTR_OSSR, sBreakDeadTimeConfig->OffStateRunMode);
ganlikun 0:13413ea9a877 1684 MODIFY_REG(tmpbdtr, TIM_BDTR_BKE, sBreakDeadTimeConfig->BreakState);
ganlikun 0:13413ea9a877 1685 MODIFY_REG(tmpbdtr, TIM_BDTR_BKP, sBreakDeadTimeConfig->BreakPolarity);
ganlikun 0:13413ea9a877 1686 MODIFY_REG(tmpbdtr, TIM_BDTR_AOE, sBreakDeadTimeConfig->AutomaticOutput);
ganlikun 0:13413ea9a877 1687 MODIFY_REG(tmpbdtr, TIM_BDTR_MOE, sBreakDeadTimeConfig->AutomaticOutput);
ganlikun 0:13413ea9a877 1688
ganlikun 0:13413ea9a877 1689 /* Set TIMx_BDTR */
ganlikun 0:13413ea9a877 1690 htim->Instance->BDTR = tmpbdtr;
ganlikun 0:13413ea9a877 1691
ganlikun 0:13413ea9a877 1692 __HAL_UNLOCK(htim);
ganlikun 0:13413ea9a877 1693
ganlikun 0:13413ea9a877 1694 return HAL_OK;
ganlikun 0:13413ea9a877 1695 }
ganlikun 0:13413ea9a877 1696
ganlikun 0:13413ea9a877 1697 /**
ganlikun 0:13413ea9a877 1698 * @brief Configures the TIM2, TIM5 and TIM11 Remapping input capabilities.
ganlikun 0:13413ea9a877 1699 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 1700 * the configuration information for TIM module.
ganlikun 0:13413ea9a877 1701 * @param Remap: specifies the TIM input remapping source.
ganlikun 0:13413ea9a877 1702 * This parameter can be one of the following values:
ganlikun 0:13413ea9a877 1703 * @arg TIM_TIM2_TIM8_TRGO: TIM2 ITR1 input is connected to TIM8 Trigger output(default)
ganlikun 0:13413ea9a877 1704 * @arg TIM_TIM2_ETH_PTP: TIM2 ITR1 input is connected to ETH PTP trigger output.
ganlikun 0:13413ea9a877 1705 * @arg TIM_TIM2_USBFS_SOF: TIM2 ITR1 input is connected to USB FS SOF.
ganlikun 0:13413ea9a877 1706 * @arg TIM_TIM2_USBHS_SOF: TIM2 ITR1 input is connected to USB HS SOF.
ganlikun 0:13413ea9a877 1707 * @arg TIM_TIM5_GPIO: TIM5 CH4 input is connected to dedicated Timer pin(default)
ganlikun 0:13413ea9a877 1708 * @arg TIM_TIM5_LSI: TIM5 CH4 input is connected to LSI clock.
ganlikun 0:13413ea9a877 1709 * @arg TIM_TIM5_LSE: TIM5 CH4 input is connected to LSE clock.
ganlikun 0:13413ea9a877 1710 * @arg TIM_TIM5_RTC: TIM5 CH4 input is connected to RTC Output event.
ganlikun 0:13413ea9a877 1711 * @arg TIM_TIM11_GPIO: TIM11 CH4 input is connected to dedicated Timer pin(default)
ganlikun 0:13413ea9a877 1712 * @arg TIM_TIM11_HSE: TIM11 CH4 input is connected to HSE_RTC clock
ganlikun 0:13413ea9a877 1713 * (HSE divided by a programmable prescaler)
ganlikun 0:13413ea9a877 1714 * @arg TIM_TIM9_TIM3_TRGO: TIM9 ITR1 input is connected to TIM3 Trigger output(default)
ganlikun 0:13413ea9a877 1715 * @arg TIM_TIM9_LPTIM: TIM9 ITR1 input is connected to LPTIM.
ganlikun 0:13413ea9a877 1716 * @arg TIM_TIM5_TIM3_TRGO: TIM5 ITR1 input is connected to TIM3 Trigger output(default)
ganlikun 0:13413ea9a877 1717 * @arg TIM_TIM5_LPTIM: TIM5 ITR1 input is connected to LPTIM.
ganlikun 0:13413ea9a877 1718 * @arg TIM_TIM1_TIM3_TRGO: TIM1 ITR2 input is connected to TIM3 Trigger output(default)
ganlikun 0:13413ea9a877 1719 * @arg TIM_TIM1_LPTIM: TIM1 ITR2 input is connected to LPTIM.
ganlikun 0:13413ea9a877 1720 * @retval HAL status
ganlikun 0:13413ea9a877 1721 */
ganlikun 0:13413ea9a877 1722 HAL_StatusTypeDef HAL_TIMEx_RemapConfig(TIM_HandleTypeDef *htim, uint32_t Remap)
ganlikun 0:13413ea9a877 1723 {
ganlikun 0:13413ea9a877 1724 __HAL_LOCK(htim);
ganlikun 0:13413ea9a877 1725
ganlikun 0:13413ea9a877 1726 /* Check parameters */
ganlikun 0:13413ea9a877 1727 assert_param(IS_TIM_REMAP_INSTANCE(htim->Instance));
ganlikun 0:13413ea9a877 1728 assert_param(IS_TIM_REMAP(Remap));
ganlikun 0:13413ea9a877 1729
ganlikun 0:13413ea9a877 1730 #if defined(LPTIM_OR_TIM1_ITR2_RMP)
ganlikun 0:13413ea9a877 1731 if ((Remap == TIM_TIM9_TIM3_TRGO)|| (Remap == TIM_TIM9_LPTIM)||(Remap ==TIM_TIM5_TIM3_TRGO)||\
ganlikun 0:13413ea9a877 1732 (Remap == TIM_TIM5_LPTIM)||(Remap == TIM_TIM1_TIM3_TRGO)|| (Remap == TIM_TIM1_LPTIM))
ganlikun 0:13413ea9a877 1733 {
ganlikun 0:13413ea9a877 1734 __HAL_RCC_LPTIM1_CLK_ENABLE();
ganlikun 0:13413ea9a877 1735
ganlikun 0:13413ea9a877 1736 LPTIM1->OR = (Remap& 0xEFFFFFFFU);
ganlikun 0:13413ea9a877 1737 }
ganlikun 0:13413ea9a877 1738 else
ganlikun 0:13413ea9a877 1739 {
ganlikun 0:13413ea9a877 1740 /* Set the Timer remapping configuration */
ganlikun 0:13413ea9a877 1741 htim->Instance->OR = Remap;
ganlikun 0:13413ea9a877 1742 }
ganlikun 0:13413ea9a877 1743 #else
ganlikun 0:13413ea9a877 1744 /* Set the Timer remapping configuration */
ganlikun 0:13413ea9a877 1745 htim->Instance->OR = Remap;
ganlikun 0:13413ea9a877 1746 #endif
ganlikun 0:13413ea9a877 1747 htim->State = HAL_TIM_STATE_READY;
ganlikun 0:13413ea9a877 1748
ganlikun 0:13413ea9a877 1749 __HAL_UNLOCK(htim);
ganlikun 0:13413ea9a877 1750
ganlikun 0:13413ea9a877 1751 return HAL_OK;
ganlikun 0:13413ea9a877 1752 }
ganlikun 0:13413ea9a877 1753
ganlikun 0:13413ea9a877 1754 /**
ganlikun 0:13413ea9a877 1755 * @}
ganlikun 0:13413ea9a877 1756 */
ganlikun 0:13413ea9a877 1757
ganlikun 0:13413ea9a877 1758 /** @defgroup TIMEx_Exported_Functions_Group6 Extension Callbacks functions
ganlikun 0:13413ea9a877 1759 * @brief Extension Callbacks functions
ganlikun 0:13413ea9a877 1760 *
ganlikun 0:13413ea9a877 1761 @verbatim
ganlikun 0:13413ea9a877 1762 ==============================================================================
ganlikun 0:13413ea9a877 1763 ##### Extension Callbacks functions #####
ganlikun 0:13413ea9a877 1764 ==============================================================================
ganlikun 0:13413ea9a877 1765 [..]
ganlikun 0:13413ea9a877 1766 This section provides Extension TIM callback functions:
ganlikun 0:13413ea9a877 1767 (+) Timer Commutation callback
ganlikun 0:13413ea9a877 1768 (+) Timer Break callback
ganlikun 0:13413ea9a877 1769
ganlikun 0:13413ea9a877 1770 @endverbatim
ganlikun 0:13413ea9a877 1771 * @{
ganlikun 0:13413ea9a877 1772 */
ganlikun 0:13413ea9a877 1773
ganlikun 0:13413ea9a877 1774 /**
ganlikun 0:13413ea9a877 1775 * @brief Hall commutation changed callback in non blocking mode
ganlikun 0:13413ea9a877 1776 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 1777 * the configuration information for TIM module.
ganlikun 0:13413ea9a877 1778 * @retval None
ganlikun 0:13413ea9a877 1779 */
ganlikun 0:13413ea9a877 1780 __weak void HAL_TIMEx_CommutationCallback(TIM_HandleTypeDef *htim)
ganlikun 0:13413ea9a877 1781 {
ganlikun 0:13413ea9a877 1782 /* Prevent unused argument(s) compilation warning */
ganlikun 0:13413ea9a877 1783 UNUSED(htim);
ganlikun 0:13413ea9a877 1784 /* NOTE : This function Should not be modified, when the callback is needed,
ganlikun 0:13413ea9a877 1785 the HAL_TIMEx_CommutationCallback could be implemented in the user file
ganlikun 0:13413ea9a877 1786 */
ganlikun 0:13413ea9a877 1787 }
ganlikun 0:13413ea9a877 1788
ganlikun 0:13413ea9a877 1789 /**
ganlikun 0:13413ea9a877 1790 * @brief Hall Break detection callback in non blocking mode
ganlikun 0:13413ea9a877 1791 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 1792 * the configuration information for TIM module.
ganlikun 0:13413ea9a877 1793 * @retval None
ganlikun 0:13413ea9a877 1794 */
ganlikun 0:13413ea9a877 1795 __weak void HAL_TIMEx_BreakCallback(TIM_HandleTypeDef *htim)
ganlikun 0:13413ea9a877 1796 {
ganlikun 0:13413ea9a877 1797 /* Prevent unused argument(s) compilation warning */
ganlikun 0:13413ea9a877 1798 UNUSED(htim);
ganlikun 0:13413ea9a877 1799 /* NOTE : This function Should not be modified, when the callback is needed,
ganlikun 0:13413ea9a877 1800 the HAL_TIMEx_BreakCallback could be implemented in the user file
ganlikun 0:13413ea9a877 1801 */
ganlikun 0:13413ea9a877 1802 }
ganlikun 0:13413ea9a877 1803 /**
ganlikun 0:13413ea9a877 1804 * @}
ganlikun 0:13413ea9a877 1805 */
ganlikun 0:13413ea9a877 1806
ganlikun 0:13413ea9a877 1807 /** @defgroup TIMEx_Exported_Functions_Group7 Extension Peripheral State functions
ganlikun 0:13413ea9a877 1808 * @brief Extension Peripheral State functions
ganlikun 0:13413ea9a877 1809 *
ganlikun 0:13413ea9a877 1810 @verbatim
ganlikun 0:13413ea9a877 1811 ==============================================================================
ganlikun 0:13413ea9a877 1812 ##### Extension Peripheral State functions #####
ganlikun 0:13413ea9a877 1813 ==============================================================================
ganlikun 0:13413ea9a877 1814 [..]
ganlikun 0:13413ea9a877 1815 This subsection permits to get in run-time the status of the peripheral
ganlikun 0:13413ea9a877 1816 and the data flow.
ganlikun 0:13413ea9a877 1817
ganlikun 0:13413ea9a877 1818 @endverbatim
ganlikun 0:13413ea9a877 1819 * @{
ganlikun 0:13413ea9a877 1820 */
ganlikun 0:13413ea9a877 1821
ganlikun 0:13413ea9a877 1822 /**
ganlikun 0:13413ea9a877 1823 * @brief Return the TIM Hall Sensor interface state
ganlikun 0:13413ea9a877 1824 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 1825 * the configuration information for TIM module.
ganlikun 0:13413ea9a877 1826 * @retval HAL state
ganlikun 0:13413ea9a877 1827 */
ganlikun 0:13413ea9a877 1828 HAL_TIM_StateTypeDef HAL_TIMEx_HallSensor_GetState(TIM_HandleTypeDef *htim)
ganlikun 0:13413ea9a877 1829 {
ganlikun 0:13413ea9a877 1830 return htim->State;
ganlikun 0:13413ea9a877 1831 }
ganlikun 0:13413ea9a877 1832
ganlikun 0:13413ea9a877 1833 /**
ganlikun 0:13413ea9a877 1834 * @}
ganlikun 0:13413ea9a877 1835 */
ganlikun 0:13413ea9a877 1836
ganlikun 0:13413ea9a877 1837 /**
ganlikun 0:13413ea9a877 1838 * @brief TIM DMA Commutation callback.
ganlikun 0:13413ea9a877 1839 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
ganlikun 0:13413ea9a877 1840 * the configuration information for the specified DMA module.
ganlikun 0:13413ea9a877 1841 * @retval None
ganlikun 0:13413ea9a877 1842 */
ganlikun 0:13413ea9a877 1843 void TIMEx_DMACommutationCplt(DMA_HandleTypeDef *hdma)
ganlikun 0:13413ea9a877 1844 {
ganlikun 0:13413ea9a877 1845 TIM_HandleTypeDef* htim = ( TIM_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
ganlikun 0:13413ea9a877 1846
ganlikun 0:13413ea9a877 1847 htim->State= HAL_TIM_STATE_READY;
ganlikun 0:13413ea9a877 1848
ganlikun 0:13413ea9a877 1849 HAL_TIMEx_CommutationCallback(htim);
ganlikun 0:13413ea9a877 1850 }
ganlikun 0:13413ea9a877 1851 /**
ganlikun 0:13413ea9a877 1852 * @}
ganlikun 0:13413ea9a877 1853 */
ganlikun 0:13413ea9a877 1854
ganlikun 0:13413ea9a877 1855 /**
ganlikun 0:13413ea9a877 1856 * @brief Enables or disables the TIM Capture Compare Channel xN.
ganlikun 0:13413ea9a877 1857 * @param TIMx to select the TIM peripheral
ganlikun 0:13413ea9a877 1858 * @param Channel: specifies the TIM Channel
ganlikun 0:13413ea9a877 1859 * This parameter can be one of the following values:
ganlikun 0:13413ea9a877 1860 * @arg TIM_Channel_1: TIM Channel 1
ganlikun 0:13413ea9a877 1861 * @arg TIM_Channel_2: TIM Channel 2
ganlikun 0:13413ea9a877 1862 * @arg TIM_Channel_3: TIM Channel 3
ganlikun 0:13413ea9a877 1863 * @param ChannelNState: specifies the TIM Channel CCxNE bit new state.
ganlikun 0:13413ea9a877 1864 * This parameter can be: TIM_CCxN_ENABLE or TIM_CCxN_Disable.
ganlikun 0:13413ea9a877 1865 * @retval None
ganlikun 0:13413ea9a877 1866 */
ganlikun 0:13413ea9a877 1867 static void TIM_CCxNChannelCmd(TIM_TypeDef* TIMx, uint32_t Channel, uint32_t ChannelNState)
ganlikun 0:13413ea9a877 1868 {
ganlikun 0:13413ea9a877 1869 uint32_t tmp = 0U;
ganlikun 0:13413ea9a877 1870
ganlikun 0:13413ea9a877 1871 /* Check the parameters */
ganlikun 0:13413ea9a877 1872 assert_param(IS_TIM_CC4_INSTANCE(TIMx));
ganlikun 0:13413ea9a877 1873 assert_param(IS_TIM_COMPLEMENTARY_CHANNELS(Channel));
ganlikun 0:13413ea9a877 1874
ganlikun 0:13413ea9a877 1875 tmp = TIM_CCER_CC1NE << Channel;
ganlikun 0:13413ea9a877 1876
ganlikun 0:13413ea9a877 1877 /* Reset the CCxNE Bit */
ganlikun 0:13413ea9a877 1878 TIMx->CCER &= ~tmp;
ganlikun 0:13413ea9a877 1879
ganlikun 0:13413ea9a877 1880 /* Set or reset the CCxNE Bit */
ganlikun 0:13413ea9a877 1881 TIMx->CCER |= (uint32_t)(ChannelNState << Channel);
ganlikun 0:13413ea9a877 1882 }
ganlikun 0:13413ea9a877 1883
ganlikun 0:13413ea9a877 1884 /**
ganlikun 0:13413ea9a877 1885 * @}
ganlikun 0:13413ea9a877 1886 */
ganlikun 0:13413ea9a877 1887
ganlikun 0:13413ea9a877 1888 #endif /* HAL_TIM_MODULE_ENABLED */
ganlikun 0:13413ea9a877 1889 /**
ganlikun 0:13413ea9a877 1890 * @}
ganlikun 0:13413ea9a877 1891 */
ganlikun 0:13413ea9a877 1892
ganlikun 0:13413ea9a877 1893 /**
ganlikun 0:13413ea9a877 1894 * @}
ganlikun 0:13413ea9a877 1895 */
ganlikun 0:13413ea9a877 1896 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
ganlikun 0:13413ea9a877 1897