SPKT
Dependencies: F746_GUI SD_PlayerSkeleton F746_SAI_IO
SRC_STM32F7/targets/cmsis/TARGET_STM/TARGET_STM32F7/stm32f7xx_hal_tim_ex.c@0:8ede47d38d10, 2019-06-04 (annotated)
- Committer:
- phungductung
- Date:
- Tue Jun 04 21:37:21 2019 +0000
- Revision:
- 0:8ede47d38d10
SPKT
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
phungductung | 0:8ede47d38d10 | 1 | /** |
phungductung | 0:8ede47d38d10 | 2 | ****************************************************************************** |
phungductung | 0:8ede47d38d10 | 3 | * @file stm32f7xx_hal_tim_ex.c |
phungductung | 0:8ede47d38d10 | 4 | * @author MCD Application Team |
phungductung | 0:8ede47d38d10 | 5 | * @version V1.0.4 |
phungductung | 0:8ede47d38d10 | 6 | * @date 09-December-2015 |
phungductung | 0:8ede47d38d10 | 7 | * @brief TIM HAL module driver. |
phungductung | 0:8ede47d38d10 | 8 | * This file provides firmware functions to manage the following |
phungductung | 0:8ede47d38d10 | 9 | * functionalities of the Timer extension peripheral: |
phungductung | 0:8ede47d38d10 | 10 | * + Time Hall Sensor Interface Initialization |
phungductung | 0:8ede47d38d10 | 11 | * + Time Hall Sensor Interface Start |
phungductung | 0:8ede47d38d10 | 12 | * + Time Complementary signal bread and dead time configuration |
phungductung | 0:8ede47d38d10 | 13 | * + Time Master and Slave synchronization configuration |
phungductung | 0:8ede47d38d10 | 14 | * + Time Output Compare/PWM Channel Configuration (for channels 5 and 6) |
phungductung | 0:8ede47d38d10 | 15 | * + Time OCRef clear configuration |
phungductung | 0:8ede47d38d10 | 16 | * + Timer remapping capabilities configuration |
phungductung | 0:8ede47d38d10 | 17 | @verbatim |
phungductung | 0:8ede47d38d10 | 18 | ============================================================================== |
phungductung | 0:8ede47d38d10 | 19 | ##### TIMER Extended features ##### |
phungductung | 0:8ede47d38d10 | 20 | ============================================================================== |
phungductung | 0:8ede47d38d10 | 21 | [..] |
phungductung | 0:8ede47d38d10 | 22 | The Timer Extension features include: |
phungductung | 0:8ede47d38d10 | 23 | (#) Complementary outputs with programmable dead-time for : |
phungductung | 0:8ede47d38d10 | 24 | (++) Input Capture |
phungductung | 0:8ede47d38d10 | 25 | (++) Output Compare |
phungductung | 0:8ede47d38d10 | 26 | (++) PWM generation (Edge and Center-aligned Mode) |
phungductung | 0:8ede47d38d10 | 27 | (++) One-pulse mode output |
phungductung | 0:8ede47d38d10 | 28 | (#) Synchronization circuit to control the timer with external signals and to |
phungductung | 0:8ede47d38d10 | 29 | interconnect several timers together. |
phungductung | 0:8ede47d38d10 | 30 | (#) Break input to put the timer output signals in reset state or in a known state. |
phungductung | 0:8ede47d38d10 | 31 | (#) Supports incremental (quadrature) encoder and hall-sensor circuitry for |
phungductung | 0:8ede47d38d10 | 32 | positioning purposes |
phungductung | 0:8ede47d38d10 | 33 | |
phungductung | 0:8ede47d38d10 | 34 | ##### How to use this driver ##### |
phungductung | 0:8ede47d38d10 | 35 | ============================================================================== |
phungductung | 0:8ede47d38d10 | 36 | [..] |
phungductung | 0:8ede47d38d10 | 37 | (#) Initialize the TIM low level resources by implementing the following functions |
phungductung | 0:8ede47d38d10 | 38 | depending from feature used : |
phungductung | 0:8ede47d38d10 | 39 | (++) Complementary Output Compare : HAL_TIM_OC_MspInit() |
phungductung | 0:8ede47d38d10 | 40 | (++) Complementary PWM generation : HAL_TIM_PWM_MspInit() |
phungductung | 0:8ede47d38d10 | 41 | (++) Complementary One-pulse mode output : HAL_TIM_OnePulse_MspInit() |
phungductung | 0:8ede47d38d10 | 42 | (++) Hall Sensor output : HAL_TIM_HallSensor_MspInit() |
phungductung | 0:8ede47d38d10 | 43 | |
phungductung | 0:8ede47d38d10 | 44 | (#) Initialize the TIM low level resources : |
phungductung | 0:8ede47d38d10 | 45 | (##) Enable the TIM interface clock using __TIMx_CLK_ENABLE(); |
phungductung | 0:8ede47d38d10 | 46 | (##) TIM pins configuration |
phungductung | 0:8ede47d38d10 | 47 | (+++) Enable the clock for the TIM GPIOs using the following function: |
phungductung | 0:8ede47d38d10 | 48 | __GPIOx_CLK_ENABLE(); |
phungductung | 0:8ede47d38d10 | 49 | (+++) Configure these TIM pins in Alternate function mode using HAL_GPIO_Init(); |
phungductung | 0:8ede47d38d10 | 50 | |
phungductung | 0:8ede47d38d10 | 51 | (#) The external Clock can be configured, if needed (the default clock is the |
phungductung | 0:8ede47d38d10 | 52 | internal clock from the APBx), using the following function: |
phungductung | 0:8ede47d38d10 | 53 | HAL_TIM_ConfigClockSource, the clock configuration should be done before |
phungductung | 0:8ede47d38d10 | 54 | any start function. |
phungductung | 0:8ede47d38d10 | 55 | |
phungductung | 0:8ede47d38d10 | 56 | (#) Configure the TIM in the desired functioning mode using one of the |
phungductung | 0:8ede47d38d10 | 57 | initialization function of this driver: |
phungductung | 0:8ede47d38d10 | 58 | (++) HAL_TIMEx_HallSensor_Init and HAL_TIMEx_ConfigCommutationEvent: to use the |
phungductung | 0:8ede47d38d10 | 59 | Timer Hall Sensor Interface and the commutation event with the corresponding |
phungductung | 0:8ede47d38d10 | 60 | Interrupt and DMA request if needed (Note that One Timer is used to interface |
phungductung | 0:8ede47d38d10 | 61 | with the Hall sensor Interface and another Timer should be used to use |
phungductung | 0:8ede47d38d10 | 62 | the commutation event). |
phungductung | 0:8ede47d38d10 | 63 | |
phungductung | 0:8ede47d38d10 | 64 | (#) Activate the TIM peripheral using one of the start functions: |
phungductung | 0:8ede47d38d10 | 65 | (++) Complementary Output Compare : HAL_TIMEx_OCN_Start(), HAL_TIMEx_OCN_Start_DMA(), HAL_TIMEx_OC_Start_IT() |
phungductung | 0:8ede47d38d10 | 66 | (++) Complementary PWM generation : HAL_TIMEx_PWMN_Start(), HAL_TIMEx_PWMN_Start_DMA(), HAL_TIMEx_PWMN_Start_IT() |
phungductung | 0:8ede47d38d10 | 67 | (++) Complementary One-pulse mode output : HAL_TIMEx_OnePulseN_Start(), HAL_TIMEx_OnePulseN_Start_IT() |
phungductung | 0:8ede47d38d10 | 68 | (++) Hall Sensor output : HAL_TIMEx_HallSensor_Start(), HAL_TIMEx_HallSensor_Start_DMA(), HAL_TIMEx_HallSensor_Start_IT(). |
phungductung | 0:8ede47d38d10 | 69 | |
phungductung | 0:8ede47d38d10 | 70 | |
phungductung | 0:8ede47d38d10 | 71 | @endverbatim |
phungductung | 0:8ede47d38d10 | 72 | ****************************************************************************** |
phungductung | 0:8ede47d38d10 | 73 | * @attention |
phungductung | 0:8ede47d38d10 | 74 | * |
phungductung | 0:8ede47d38d10 | 75 | * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> |
phungductung | 0:8ede47d38d10 | 76 | * |
phungductung | 0:8ede47d38d10 | 77 | * Redistribution and use in source and binary forms, with or without modification, |
phungductung | 0:8ede47d38d10 | 78 | * are permitted provided that the following conditions are met: |
phungductung | 0:8ede47d38d10 | 79 | * 1. Redistributions of source code must retain the above copyright notice, |
phungductung | 0:8ede47d38d10 | 80 | * this list of conditions and the following disclaimer. |
phungductung | 0:8ede47d38d10 | 81 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
phungductung | 0:8ede47d38d10 | 82 | * this list of conditions and the following disclaimer in the documentation |
phungductung | 0:8ede47d38d10 | 83 | * and/or other materials provided with the distribution. |
phungductung | 0:8ede47d38d10 | 84 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
phungductung | 0:8ede47d38d10 | 85 | * may be used to endorse or promote products derived from this software |
phungductung | 0:8ede47d38d10 | 86 | * without specific prior written permission. |
phungductung | 0:8ede47d38d10 | 87 | * |
phungductung | 0:8ede47d38d10 | 88 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
phungductung | 0:8ede47d38d10 | 89 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
phungductung | 0:8ede47d38d10 | 90 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
phungductung | 0:8ede47d38d10 | 91 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
phungductung | 0:8ede47d38d10 | 92 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
phungductung | 0:8ede47d38d10 | 93 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
phungductung | 0:8ede47d38d10 | 94 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
phungductung | 0:8ede47d38d10 | 95 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
phungductung | 0:8ede47d38d10 | 96 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
phungductung | 0:8ede47d38d10 | 97 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
phungductung | 0:8ede47d38d10 | 98 | * |
phungductung | 0:8ede47d38d10 | 99 | ****************************************************************************** |
phungductung | 0:8ede47d38d10 | 100 | */ |
phungductung | 0:8ede47d38d10 | 101 | |
phungductung | 0:8ede47d38d10 | 102 | /* Includes ------------------------------------------------------------------*/ |
phungductung | 0:8ede47d38d10 | 103 | #include "stm32f7xx_hal.h" |
phungductung | 0:8ede47d38d10 | 104 | |
phungductung | 0:8ede47d38d10 | 105 | /** @addtogroup STM32F7xx_HAL_Driver |
phungductung | 0:8ede47d38d10 | 106 | * @{ |
phungductung | 0:8ede47d38d10 | 107 | */ |
phungductung | 0:8ede47d38d10 | 108 | |
phungductung | 0:8ede47d38d10 | 109 | /** @defgroup TIMEx TIMEx |
phungductung | 0:8ede47d38d10 | 110 | * @brief TIM Extended HAL module driver |
phungductung | 0:8ede47d38d10 | 111 | * @{ |
phungductung | 0:8ede47d38d10 | 112 | */ |
phungductung | 0:8ede47d38d10 | 113 | |
phungductung | 0:8ede47d38d10 | 114 | #ifdef HAL_TIM_MODULE_ENABLED |
phungductung | 0:8ede47d38d10 | 115 | |
phungductung | 0:8ede47d38d10 | 116 | /* Private typedef -----------------------------------------------------------*/ |
phungductung | 0:8ede47d38d10 | 117 | /* Private define ------------------------------------------------------------*/ |
phungductung | 0:8ede47d38d10 | 118 | #define BDTR_BKF_SHIFT (16) |
phungductung | 0:8ede47d38d10 | 119 | #define BDTR_BK2F_SHIFT (20) |
phungductung | 0:8ede47d38d10 | 120 | /* Private macro -------------------------------------------------------------*/ |
phungductung | 0:8ede47d38d10 | 121 | /* Private variables ---------------------------------------------------------*/ |
phungductung | 0:8ede47d38d10 | 122 | /* Private function prototypes -----------------------------------------------*/ |
phungductung | 0:8ede47d38d10 | 123 | /** @addtogroup TIMEx_Private_Functions |
phungductung | 0:8ede47d38d10 | 124 | * @{ |
phungductung | 0:8ede47d38d10 | 125 | */ |
phungductung | 0:8ede47d38d10 | 126 | static void TIM_CCxNChannelCmd(TIM_TypeDef* TIMx, uint32_t Channel, uint32_t ChannelNState); |
phungductung | 0:8ede47d38d10 | 127 | static void TIM_OC5_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config); |
phungductung | 0:8ede47d38d10 | 128 | static void TIM_OC6_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config); |
phungductung | 0:8ede47d38d10 | 129 | /** |
phungductung | 0:8ede47d38d10 | 130 | * @} |
phungductung | 0:8ede47d38d10 | 131 | */ |
phungductung | 0:8ede47d38d10 | 132 | /* Private functions ---------------------------------------------------------*/ |
phungductung | 0:8ede47d38d10 | 133 | |
phungductung | 0:8ede47d38d10 | 134 | /** @defgroup TIMEx_Exported_Functions TIMEx Exported Functions |
phungductung | 0:8ede47d38d10 | 135 | * @{ |
phungductung | 0:8ede47d38d10 | 136 | */ |
phungductung | 0:8ede47d38d10 | 137 | |
phungductung | 0:8ede47d38d10 | 138 | /** @defgroup TIMEx_Exported_Functions_Group1 Extended Timer Hall Sensor functions |
phungductung | 0:8ede47d38d10 | 139 | * @brief Timer Hall Sensor functions |
phungductung | 0:8ede47d38d10 | 140 | * |
phungductung | 0:8ede47d38d10 | 141 | @verbatim |
phungductung | 0:8ede47d38d10 | 142 | ============================================================================== |
phungductung | 0:8ede47d38d10 | 143 | ##### Timer Hall Sensor functions ##### |
phungductung | 0:8ede47d38d10 | 144 | ============================================================================== |
phungductung | 0:8ede47d38d10 | 145 | [..] |
phungductung | 0:8ede47d38d10 | 146 | This section provides functions allowing to: |
phungductung | 0:8ede47d38d10 | 147 | (+) Initialize and configure TIM HAL Sensor. |
phungductung | 0:8ede47d38d10 | 148 | (+) De-initialize TIM HAL Sensor. |
phungductung | 0:8ede47d38d10 | 149 | (+) Start the Hall Sensor Interface. |
phungductung | 0:8ede47d38d10 | 150 | (+) Stop the Hall Sensor Interface. |
phungductung | 0:8ede47d38d10 | 151 | (+) Start the Hall Sensor Interface and enable interrupts. |
phungductung | 0:8ede47d38d10 | 152 | (+) Stop the Hall Sensor Interface and disable interrupts. |
phungductung | 0:8ede47d38d10 | 153 | (+) Start the Hall Sensor Interface and enable DMA transfers. |
phungductung | 0:8ede47d38d10 | 154 | (+) Stop the Hall Sensor Interface and disable DMA transfers. |
phungductung | 0:8ede47d38d10 | 155 | |
phungductung | 0:8ede47d38d10 | 156 | @endverbatim |
phungductung | 0:8ede47d38d10 | 157 | * @{ |
phungductung | 0:8ede47d38d10 | 158 | */ |
phungductung | 0:8ede47d38d10 | 159 | /** |
phungductung | 0:8ede47d38d10 | 160 | * @brief Initializes the TIM Hall Sensor Interface and create the associated handle. |
phungductung | 0:8ede47d38d10 | 161 | * @param htim: pointer to a TIM_HandleTypeDef structure that contains |
phungductung | 0:8ede47d38d10 | 162 | * the configuration information for TIM module. |
phungductung | 0:8ede47d38d10 | 163 | * @param sConfig: TIM Hall Sensor configuration structure |
phungductung | 0:8ede47d38d10 | 164 | * @retval HAL status |
phungductung | 0:8ede47d38d10 | 165 | */ |
phungductung | 0:8ede47d38d10 | 166 | HAL_StatusTypeDef HAL_TIMEx_HallSensor_Init(TIM_HandleTypeDef *htim, TIM_HallSensor_InitTypeDef* sConfig) |
phungductung | 0:8ede47d38d10 | 167 | { |
phungductung | 0:8ede47d38d10 | 168 | TIM_OC_InitTypeDef OC_Config; |
phungductung | 0:8ede47d38d10 | 169 | |
phungductung | 0:8ede47d38d10 | 170 | /* Check the TIM handle allocation */ |
phungductung | 0:8ede47d38d10 | 171 | if(htim == NULL) |
phungductung | 0:8ede47d38d10 | 172 | { |
phungductung | 0:8ede47d38d10 | 173 | return HAL_ERROR; |
phungductung | 0:8ede47d38d10 | 174 | } |
phungductung | 0:8ede47d38d10 | 175 | |
phungductung | 0:8ede47d38d10 | 176 | assert_param(IS_TIM_XOR_INSTANCE(htim->Instance)); |
phungductung | 0:8ede47d38d10 | 177 | assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode)); |
phungductung | 0:8ede47d38d10 | 178 | assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision)); |
phungductung | 0:8ede47d38d10 | 179 | assert_param(IS_TIM_IC_POLARITY(sConfig->IC1Polarity)); |
phungductung | 0:8ede47d38d10 | 180 | assert_param(IS_TIM_IC_PRESCALER(sConfig->IC1Prescaler)); |
phungductung | 0:8ede47d38d10 | 181 | assert_param(IS_TIM_IC_FILTER(sConfig->IC1Filter)); |
phungductung | 0:8ede47d38d10 | 182 | |
phungductung | 0:8ede47d38d10 | 183 | /* Set the TIM state */ |
phungductung | 0:8ede47d38d10 | 184 | htim->State= HAL_TIM_STATE_BUSY; |
phungductung | 0:8ede47d38d10 | 185 | |
phungductung | 0:8ede47d38d10 | 186 | /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */ |
phungductung | 0:8ede47d38d10 | 187 | HAL_TIMEx_HallSensor_MspInit(htim); |
phungductung | 0:8ede47d38d10 | 188 | |
phungductung | 0:8ede47d38d10 | 189 | /* Configure the Time base in the Encoder Mode */ |
phungductung | 0:8ede47d38d10 | 190 | TIM_Base_SetConfig(htim->Instance, &htim->Init); |
phungductung | 0:8ede47d38d10 | 191 | |
phungductung | 0:8ede47d38d10 | 192 | /* Configure the Channel 1 as Input Channel to interface with the three Outputs of the Hall sensor */ |
phungductung | 0:8ede47d38d10 | 193 | TIM_TI1_SetConfig(htim->Instance, sConfig->IC1Polarity, TIM_ICSELECTION_TRC, sConfig->IC1Filter); |
phungductung | 0:8ede47d38d10 | 194 | |
phungductung | 0:8ede47d38d10 | 195 | /* Reset the IC1PSC Bits */ |
phungductung | 0:8ede47d38d10 | 196 | htim->Instance->CCMR1 &= ~TIM_CCMR1_IC1PSC; |
phungductung | 0:8ede47d38d10 | 197 | /* Set the IC1PSC value */ |
phungductung | 0:8ede47d38d10 | 198 | htim->Instance->CCMR1 |= sConfig->IC1Prescaler; |
phungductung | 0:8ede47d38d10 | 199 | |
phungductung | 0:8ede47d38d10 | 200 | /* Enable the Hall sensor interface (XOR function of the three inputs) */ |
phungductung | 0:8ede47d38d10 | 201 | htim->Instance->CR2 |= TIM_CR2_TI1S; |
phungductung | 0:8ede47d38d10 | 202 | |
phungductung | 0:8ede47d38d10 | 203 | /* Select the TIM_TS_TI1F_ED signal as Input trigger for the TIM */ |
phungductung | 0:8ede47d38d10 | 204 | htim->Instance->SMCR &= ~TIM_SMCR_TS; |
phungductung | 0:8ede47d38d10 | 205 | htim->Instance->SMCR |= TIM_TS_TI1F_ED; |
phungductung | 0:8ede47d38d10 | 206 | |
phungductung | 0:8ede47d38d10 | 207 | /* Use the TIM_TS_TI1F_ED signal to reset the TIM counter each edge detection */ |
phungductung | 0:8ede47d38d10 | 208 | htim->Instance->SMCR &= ~TIM_SMCR_SMS; |
phungductung | 0:8ede47d38d10 | 209 | htim->Instance->SMCR |= TIM_SLAVEMODE_RESET; |
phungductung | 0:8ede47d38d10 | 210 | |
phungductung | 0:8ede47d38d10 | 211 | /* Program channel 2 in PWM 2 mode with the desired Commutation_Delay*/ |
phungductung | 0:8ede47d38d10 | 212 | OC_Config.OCFastMode = TIM_OCFAST_DISABLE; |
phungductung | 0:8ede47d38d10 | 213 | OC_Config.OCIdleState = TIM_OCIDLESTATE_RESET; |
phungductung | 0:8ede47d38d10 | 214 | OC_Config.OCMode = TIM_OCMODE_PWM2; |
phungductung | 0:8ede47d38d10 | 215 | OC_Config.OCNIdleState = TIM_OCNIDLESTATE_RESET; |
phungductung | 0:8ede47d38d10 | 216 | OC_Config.OCNPolarity = TIM_OCNPOLARITY_HIGH; |
phungductung | 0:8ede47d38d10 | 217 | OC_Config.OCPolarity = TIM_OCPOLARITY_HIGH; |
phungductung | 0:8ede47d38d10 | 218 | OC_Config.Pulse = sConfig->Commutation_Delay; |
phungductung | 0:8ede47d38d10 | 219 | |
phungductung | 0:8ede47d38d10 | 220 | TIM_OC2_SetConfig(htim->Instance, &OC_Config); |
phungductung | 0:8ede47d38d10 | 221 | |
phungductung | 0:8ede47d38d10 | 222 | /* Select OC2REF as trigger output on TRGO: write the MMS bits in the TIMx_CR2 |
phungductung | 0:8ede47d38d10 | 223 | register to 101 */ |
phungductung | 0:8ede47d38d10 | 224 | htim->Instance->CR2 &= ~TIM_CR2_MMS; |
phungductung | 0:8ede47d38d10 | 225 | htim->Instance->CR2 |= TIM_TRGO_OC2REF; |
phungductung | 0:8ede47d38d10 | 226 | |
phungductung | 0:8ede47d38d10 | 227 | /* Initialize the TIM state*/ |
phungductung | 0:8ede47d38d10 | 228 | htim->State= HAL_TIM_STATE_READY; |
phungductung | 0:8ede47d38d10 | 229 | |
phungductung | 0:8ede47d38d10 | 230 | return HAL_OK; |
phungductung | 0:8ede47d38d10 | 231 | } |
phungductung | 0:8ede47d38d10 | 232 | |
phungductung | 0:8ede47d38d10 | 233 | /** |
phungductung | 0:8ede47d38d10 | 234 | * @brief DeInitializes the TIM Hall Sensor interface |
phungductung | 0:8ede47d38d10 | 235 | * @param htim: pointer to a TIM_HandleTypeDef structure that contains |
phungductung | 0:8ede47d38d10 | 236 | * the configuration information for TIM module. |
phungductung | 0:8ede47d38d10 | 237 | * @retval HAL status |
phungductung | 0:8ede47d38d10 | 238 | */ |
phungductung | 0:8ede47d38d10 | 239 | HAL_StatusTypeDef HAL_TIMEx_HallSensor_DeInit(TIM_HandleTypeDef *htim) |
phungductung | 0:8ede47d38d10 | 240 | { |
phungductung | 0:8ede47d38d10 | 241 | /* Check the parameters */ |
phungductung | 0:8ede47d38d10 | 242 | assert_param(IS_TIM_INSTANCE(htim->Instance)); |
phungductung | 0:8ede47d38d10 | 243 | |
phungductung | 0:8ede47d38d10 | 244 | htim->State = HAL_TIM_STATE_BUSY; |
phungductung | 0:8ede47d38d10 | 245 | |
phungductung | 0:8ede47d38d10 | 246 | /* Disable the TIM Peripheral Clock */ |
phungductung | 0:8ede47d38d10 | 247 | __HAL_TIM_DISABLE(htim); |
phungductung | 0:8ede47d38d10 | 248 | |
phungductung | 0:8ede47d38d10 | 249 | /* DeInit the low level hardware: GPIO, CLOCK, NVIC */ |
phungductung | 0:8ede47d38d10 | 250 | HAL_TIMEx_HallSensor_MspDeInit(htim); |
phungductung | 0:8ede47d38d10 | 251 | |
phungductung | 0:8ede47d38d10 | 252 | /* Change TIM state */ |
phungductung | 0:8ede47d38d10 | 253 | htim->State = HAL_TIM_STATE_RESET; |
phungductung | 0:8ede47d38d10 | 254 | |
phungductung | 0:8ede47d38d10 | 255 | /* Release Lock */ |
phungductung | 0:8ede47d38d10 | 256 | __HAL_UNLOCK(htim); |
phungductung | 0:8ede47d38d10 | 257 | |
phungductung | 0:8ede47d38d10 | 258 | return HAL_OK; |
phungductung | 0:8ede47d38d10 | 259 | } |
phungductung | 0:8ede47d38d10 | 260 | |
phungductung | 0:8ede47d38d10 | 261 | /** |
phungductung | 0:8ede47d38d10 | 262 | * @brief Initializes the TIM Hall Sensor MSP. |
phungductung | 0:8ede47d38d10 | 263 | * @param htim: pointer to a TIM_HandleTypeDef structure that contains |
phungductung | 0:8ede47d38d10 | 264 | * the configuration information for TIM module. |
phungductung | 0:8ede47d38d10 | 265 | * @retval None |
phungductung | 0:8ede47d38d10 | 266 | */ |
phungductung | 0:8ede47d38d10 | 267 | __weak void HAL_TIMEx_HallSensor_MspInit(TIM_HandleTypeDef *htim) |
phungductung | 0:8ede47d38d10 | 268 | { |
phungductung | 0:8ede47d38d10 | 269 | /* Prevent unused argument(s) compilation warning */ |
phungductung | 0:8ede47d38d10 | 270 | UNUSED(htim); |
phungductung | 0:8ede47d38d10 | 271 | |
phungductung | 0:8ede47d38d10 | 272 | /* NOTE : This function Should not be modified, when the callback is needed, |
phungductung | 0:8ede47d38d10 | 273 | the HAL_TIMEx_HallSensor_MspInit could be implemented in the user file |
phungductung | 0:8ede47d38d10 | 274 | */ |
phungductung | 0:8ede47d38d10 | 275 | } |
phungductung | 0:8ede47d38d10 | 276 | |
phungductung | 0:8ede47d38d10 | 277 | /** |
phungductung | 0:8ede47d38d10 | 278 | * @brief DeInitializes TIM Hall Sensor MSP. |
phungductung | 0:8ede47d38d10 | 279 | * @param htim: pointer to a TIM_HandleTypeDef structure that contains |
phungductung | 0:8ede47d38d10 | 280 | * the configuration information for TIM module. |
phungductung | 0:8ede47d38d10 | 281 | * @retval None |
phungductung | 0:8ede47d38d10 | 282 | */ |
phungductung | 0:8ede47d38d10 | 283 | __weak void HAL_TIMEx_HallSensor_MspDeInit(TIM_HandleTypeDef *htim) |
phungductung | 0:8ede47d38d10 | 284 | { |
phungductung | 0:8ede47d38d10 | 285 | /* Prevent unused argument(s) compilation warning */ |
phungductung | 0:8ede47d38d10 | 286 | UNUSED(htim); |
phungductung | 0:8ede47d38d10 | 287 | |
phungductung | 0:8ede47d38d10 | 288 | /* NOTE : This function Should not be modified, when the callback is needed, |
phungductung | 0:8ede47d38d10 | 289 | the HAL_TIMEx_HallSensor_MspDeInit could be implemented in the user file |
phungductung | 0:8ede47d38d10 | 290 | */ |
phungductung | 0:8ede47d38d10 | 291 | } |
phungductung | 0:8ede47d38d10 | 292 | |
phungductung | 0:8ede47d38d10 | 293 | /** |
phungductung | 0:8ede47d38d10 | 294 | * @brief Starts the TIM Hall Sensor Interface. |
phungductung | 0:8ede47d38d10 | 295 | * @param htim: pointer to a TIM_HandleTypeDef structure that contains |
phungductung | 0:8ede47d38d10 | 296 | * the configuration information for TIM module. |
phungductung | 0:8ede47d38d10 | 297 | * @retval HAL status |
phungductung | 0:8ede47d38d10 | 298 | */ |
phungductung | 0:8ede47d38d10 | 299 | HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start(TIM_HandleTypeDef *htim) |
phungductung | 0:8ede47d38d10 | 300 | { |
phungductung | 0:8ede47d38d10 | 301 | /* Check the parameters */ |
phungductung | 0:8ede47d38d10 | 302 | assert_param(IS_TIM_XOR_INSTANCE(htim->Instance)); |
phungductung | 0:8ede47d38d10 | 303 | |
phungductung | 0:8ede47d38d10 | 304 | /* Enable the Input Capture channels 1 |
phungductung | 0:8ede47d38d10 | 305 | (in the Hall Sensor Interface the Three possible channels that can be used are TIM_CHANNEL_1, TIM_CHANNEL_2 and TIM_CHANNEL_3) */ |
phungductung | 0:8ede47d38d10 | 306 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE); |
phungductung | 0:8ede47d38d10 | 307 | |
phungductung | 0:8ede47d38d10 | 308 | /* Enable the Peripheral */ |
phungductung | 0:8ede47d38d10 | 309 | __HAL_TIM_ENABLE(htim); |
phungductung | 0:8ede47d38d10 | 310 | |
phungductung | 0:8ede47d38d10 | 311 | /* Return function status */ |
phungductung | 0:8ede47d38d10 | 312 | return HAL_OK; |
phungductung | 0:8ede47d38d10 | 313 | } |
phungductung | 0:8ede47d38d10 | 314 | |
phungductung | 0:8ede47d38d10 | 315 | /** |
phungductung | 0:8ede47d38d10 | 316 | * @brief Stops the TIM Hall sensor Interface. |
phungductung | 0:8ede47d38d10 | 317 | * @param htim: pointer to a TIM_HandleTypeDef structure that contains |
phungductung | 0:8ede47d38d10 | 318 | * the configuration information for TIM module. |
phungductung | 0:8ede47d38d10 | 319 | * @retval HAL status |
phungductung | 0:8ede47d38d10 | 320 | */ |
phungductung | 0:8ede47d38d10 | 321 | HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop(TIM_HandleTypeDef *htim) |
phungductung | 0:8ede47d38d10 | 322 | { |
phungductung | 0:8ede47d38d10 | 323 | /* Check the parameters */ |
phungductung | 0:8ede47d38d10 | 324 | assert_param(IS_TIM_XOR_INSTANCE(htim->Instance)); |
phungductung | 0:8ede47d38d10 | 325 | |
phungductung | 0:8ede47d38d10 | 326 | /* Disable the Input Capture channels 1, 2 and 3 |
phungductung | 0:8ede47d38d10 | 327 | (in the Hall Sensor Interface the Three possible channels that can be used are TIM_CHANNEL_1, TIM_CHANNEL_2 and TIM_CHANNEL_3) */ |
phungductung | 0:8ede47d38d10 | 328 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE); |
phungductung | 0:8ede47d38d10 | 329 | |
phungductung | 0:8ede47d38d10 | 330 | /* Disable the Peripheral */ |
phungductung | 0:8ede47d38d10 | 331 | __HAL_TIM_DISABLE(htim); |
phungductung | 0:8ede47d38d10 | 332 | |
phungductung | 0:8ede47d38d10 | 333 | /* Return function status */ |
phungductung | 0:8ede47d38d10 | 334 | return HAL_OK; |
phungductung | 0:8ede47d38d10 | 335 | } |
phungductung | 0:8ede47d38d10 | 336 | |
phungductung | 0:8ede47d38d10 | 337 | /** |
phungductung | 0:8ede47d38d10 | 338 | * @brief Starts the TIM Hall Sensor Interface in interrupt mode. |
phungductung | 0:8ede47d38d10 | 339 | * @param htim: pointer to a TIM_HandleTypeDef structure that contains |
phungductung | 0:8ede47d38d10 | 340 | * the configuration information for TIM module. |
phungductung | 0:8ede47d38d10 | 341 | * @retval HAL status |
phungductung | 0:8ede47d38d10 | 342 | */ |
phungductung | 0:8ede47d38d10 | 343 | HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start_IT(TIM_HandleTypeDef *htim) |
phungductung | 0:8ede47d38d10 | 344 | { |
phungductung | 0:8ede47d38d10 | 345 | /* Check the parameters */ |
phungductung | 0:8ede47d38d10 | 346 | assert_param(IS_TIM_XOR_INSTANCE(htim->Instance)); |
phungductung | 0:8ede47d38d10 | 347 | |
phungductung | 0:8ede47d38d10 | 348 | /* Enable the capture compare Interrupts 1 event */ |
phungductung | 0:8ede47d38d10 | 349 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1); |
phungductung | 0:8ede47d38d10 | 350 | |
phungductung | 0:8ede47d38d10 | 351 | /* Enable the Input Capture channels 1 |
phungductung | 0:8ede47d38d10 | 352 | (in the Hall Sensor Interface the Three possible channels that can be used are TIM_CHANNEL_1, TIM_CHANNEL_2 and TIM_CHANNEL_3) */ |
phungductung | 0:8ede47d38d10 | 353 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE); |
phungductung | 0:8ede47d38d10 | 354 | |
phungductung | 0:8ede47d38d10 | 355 | /* Enable the Peripheral */ |
phungductung | 0:8ede47d38d10 | 356 | __HAL_TIM_ENABLE(htim); |
phungductung | 0:8ede47d38d10 | 357 | |
phungductung | 0:8ede47d38d10 | 358 | /* Return function status */ |
phungductung | 0:8ede47d38d10 | 359 | return HAL_OK; |
phungductung | 0:8ede47d38d10 | 360 | } |
phungductung | 0:8ede47d38d10 | 361 | |
phungductung | 0:8ede47d38d10 | 362 | /** |
phungductung | 0:8ede47d38d10 | 363 | * @brief Stops the TIM Hall Sensor Interface in interrupt mode. |
phungductung | 0:8ede47d38d10 | 364 | * @param htim: pointer to a TIM_HandleTypeDef structure that contains |
phungductung | 0:8ede47d38d10 | 365 | * the configuration information for TIM module. |
phungductung | 0:8ede47d38d10 | 366 | * @retval HAL status |
phungductung | 0:8ede47d38d10 | 367 | */ |
phungductung | 0:8ede47d38d10 | 368 | HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_IT(TIM_HandleTypeDef *htim) |
phungductung | 0:8ede47d38d10 | 369 | { |
phungductung | 0:8ede47d38d10 | 370 | /* Check the parameters */ |
phungductung | 0:8ede47d38d10 | 371 | assert_param(IS_TIM_XOR_INSTANCE(htim->Instance)); |
phungductung | 0:8ede47d38d10 | 372 | |
phungductung | 0:8ede47d38d10 | 373 | /* Disable the Input Capture channels 1 |
phungductung | 0:8ede47d38d10 | 374 | (in the Hall Sensor Interface the Three possible channels that can be used are TIM_CHANNEL_1, TIM_CHANNEL_2 and TIM_CHANNEL_3) */ |
phungductung | 0:8ede47d38d10 | 375 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE); |
phungductung | 0:8ede47d38d10 | 376 | |
phungductung | 0:8ede47d38d10 | 377 | /* Disable the capture compare Interrupts event */ |
phungductung | 0:8ede47d38d10 | 378 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1); |
phungductung | 0:8ede47d38d10 | 379 | |
phungductung | 0:8ede47d38d10 | 380 | /* Disable the Peripheral */ |
phungductung | 0:8ede47d38d10 | 381 | __HAL_TIM_DISABLE(htim); |
phungductung | 0:8ede47d38d10 | 382 | |
phungductung | 0:8ede47d38d10 | 383 | /* Return function status */ |
phungductung | 0:8ede47d38d10 | 384 | return HAL_OK; |
phungductung | 0:8ede47d38d10 | 385 | } |
phungductung | 0:8ede47d38d10 | 386 | |
phungductung | 0:8ede47d38d10 | 387 | /** |
phungductung | 0:8ede47d38d10 | 388 | * @brief Starts the TIM Hall Sensor Interface in DMA mode. |
phungductung | 0:8ede47d38d10 | 389 | * @param htim: pointer to a TIM_HandleTypeDef structure that contains |
phungductung | 0:8ede47d38d10 | 390 | * the configuration information for TIM module. |
phungductung | 0:8ede47d38d10 | 391 | * @param pData: The destination Buffer address. |
phungductung | 0:8ede47d38d10 | 392 | * @param Length: The length of data to be transferred from TIM peripheral to memory. |
phungductung | 0:8ede47d38d10 | 393 | * @retval HAL status |
phungductung | 0:8ede47d38d10 | 394 | */ |
phungductung | 0:8ede47d38d10 | 395 | HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start_DMA(TIM_HandleTypeDef *htim, uint32_t *pData, uint16_t Length) |
phungductung | 0:8ede47d38d10 | 396 | { |
phungductung | 0:8ede47d38d10 | 397 | /* Check the parameters */ |
phungductung | 0:8ede47d38d10 | 398 | assert_param(IS_TIM_XOR_INSTANCE(htim->Instance)); |
phungductung | 0:8ede47d38d10 | 399 | |
phungductung | 0:8ede47d38d10 | 400 | if((htim->State == HAL_TIM_STATE_BUSY)) |
phungductung | 0:8ede47d38d10 | 401 | { |
phungductung | 0:8ede47d38d10 | 402 | return HAL_BUSY; |
phungductung | 0:8ede47d38d10 | 403 | } |
phungductung | 0:8ede47d38d10 | 404 | else if((htim->State == HAL_TIM_STATE_READY)) |
phungductung | 0:8ede47d38d10 | 405 | { |
phungductung | 0:8ede47d38d10 | 406 | if(((uint32_t)pData == 0 ) && (Length > 0)) |
phungductung | 0:8ede47d38d10 | 407 | { |
phungductung | 0:8ede47d38d10 | 408 | return HAL_ERROR; |
phungductung | 0:8ede47d38d10 | 409 | } |
phungductung | 0:8ede47d38d10 | 410 | else |
phungductung | 0:8ede47d38d10 | 411 | { |
phungductung | 0:8ede47d38d10 | 412 | htim->State = HAL_TIM_STATE_BUSY; |
phungductung | 0:8ede47d38d10 | 413 | } |
phungductung | 0:8ede47d38d10 | 414 | } |
phungductung | 0:8ede47d38d10 | 415 | /* Enable the Input Capture channels 1 |
phungductung | 0:8ede47d38d10 | 416 | (in the Hall Sensor Interface the Three possible channels that can be used are TIM_CHANNEL_1, TIM_CHANNEL_2 and TIM_CHANNEL_3) */ |
phungductung | 0:8ede47d38d10 | 417 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE); |
phungductung | 0:8ede47d38d10 | 418 | |
phungductung | 0:8ede47d38d10 | 419 | /* Set the DMA Input Capture 1 Callback */ |
phungductung | 0:8ede47d38d10 | 420 | htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = HAL_TIM_DMACaptureCplt; |
phungductung | 0:8ede47d38d10 | 421 | /* Set the DMA error callback */ |
phungductung | 0:8ede47d38d10 | 422 | htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = HAL_TIM_DMAError ; |
phungductung | 0:8ede47d38d10 | 423 | |
phungductung | 0:8ede47d38d10 | 424 | /* Enable the DMA Stream for Capture 1*/ |
phungductung | 0:8ede47d38d10 | 425 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)&htim->Instance->CCR1, (uint32_t)pData, Length); |
phungductung | 0:8ede47d38d10 | 426 | |
phungductung | 0:8ede47d38d10 | 427 | /* Enable the capture compare 1 Interrupt */ |
phungductung | 0:8ede47d38d10 | 428 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1); |
phungductung | 0:8ede47d38d10 | 429 | |
phungductung | 0:8ede47d38d10 | 430 | /* Enable the Peripheral */ |
phungductung | 0:8ede47d38d10 | 431 | __HAL_TIM_ENABLE(htim); |
phungductung | 0:8ede47d38d10 | 432 | |
phungductung | 0:8ede47d38d10 | 433 | /* Return function status */ |
phungductung | 0:8ede47d38d10 | 434 | return HAL_OK; |
phungductung | 0:8ede47d38d10 | 435 | } |
phungductung | 0:8ede47d38d10 | 436 | |
phungductung | 0:8ede47d38d10 | 437 | /** |
phungductung | 0:8ede47d38d10 | 438 | * @brief Stops the TIM Hall Sensor Interface in DMA mode. |
phungductung | 0:8ede47d38d10 | 439 | * @param htim: pointer to a TIM_HandleTypeDef structure that contains |
phungductung | 0:8ede47d38d10 | 440 | * the configuration information for TIM module. |
phungductung | 0:8ede47d38d10 | 441 | * @retval HAL status |
phungductung | 0:8ede47d38d10 | 442 | */ |
phungductung | 0:8ede47d38d10 | 443 | HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_DMA(TIM_HandleTypeDef *htim) |
phungductung | 0:8ede47d38d10 | 444 | { |
phungductung | 0:8ede47d38d10 | 445 | /* Check the parameters */ |
phungductung | 0:8ede47d38d10 | 446 | assert_param(IS_TIM_XOR_INSTANCE(htim->Instance)); |
phungductung | 0:8ede47d38d10 | 447 | |
phungductung | 0:8ede47d38d10 | 448 | /* Disable the Input Capture channels 1 |
phungductung | 0:8ede47d38d10 | 449 | (in the Hall Sensor Interface the Three possible channels that can be used are TIM_CHANNEL_1, TIM_CHANNEL_2 and TIM_CHANNEL_3) */ |
phungductung | 0:8ede47d38d10 | 450 | TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE); |
phungductung | 0:8ede47d38d10 | 451 | |
phungductung | 0:8ede47d38d10 | 452 | |
phungductung | 0:8ede47d38d10 | 453 | /* Disable the capture compare Interrupts 1 event */ |
phungductung | 0:8ede47d38d10 | 454 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1); |
phungductung | 0:8ede47d38d10 | 455 | |
phungductung | 0:8ede47d38d10 | 456 | /* Disable the Peripheral */ |
phungductung | 0:8ede47d38d10 | 457 | __HAL_TIM_DISABLE(htim); |
phungductung | 0:8ede47d38d10 | 458 | |
phungductung | 0:8ede47d38d10 | 459 | /* Return function status */ |
phungductung | 0:8ede47d38d10 | 460 | return HAL_OK; |
phungductung | 0:8ede47d38d10 | 461 | } |
phungductung | 0:8ede47d38d10 | 462 | |
phungductung | 0:8ede47d38d10 | 463 | /** |
phungductung | 0:8ede47d38d10 | 464 | * @} |
phungductung | 0:8ede47d38d10 | 465 | */ |
phungductung | 0:8ede47d38d10 | 466 | |
phungductung | 0:8ede47d38d10 | 467 | /** @defgroup TIMEx_Exported_Functions_Group2 Extended Timer Complementary Output Compare functions |
phungductung | 0:8ede47d38d10 | 468 | * @brief Timer Complementary Output Compare functions |
phungductung | 0:8ede47d38d10 | 469 | * |
phungductung | 0:8ede47d38d10 | 470 | @verbatim |
phungductung | 0:8ede47d38d10 | 471 | ============================================================================== |
phungductung | 0:8ede47d38d10 | 472 | ##### Timer Complementary Output Compare functions ##### |
phungductung | 0:8ede47d38d10 | 473 | ============================================================================== |
phungductung | 0:8ede47d38d10 | 474 | [..] |
phungductung | 0:8ede47d38d10 | 475 | This section provides functions allowing to: |
phungductung | 0:8ede47d38d10 | 476 | (+) Start the Complementary Output Compare/PWM. |
phungductung | 0:8ede47d38d10 | 477 | (+) Stop the Complementary Output Compare/PWM. |
phungductung | 0:8ede47d38d10 | 478 | (+) Start the Complementary Output Compare/PWM and enable interrupts. |
phungductung | 0:8ede47d38d10 | 479 | (+) Stop the Complementary Output Compare/PWM and disable interrupts. |
phungductung | 0:8ede47d38d10 | 480 | (+) Start the Complementary Output Compare/PWM and enable DMA transfers. |
phungductung | 0:8ede47d38d10 | 481 | (+) Stop the Complementary Output Compare/PWM and disable DMA transfers. |
phungductung | 0:8ede47d38d10 | 482 | |
phungductung | 0:8ede47d38d10 | 483 | @endverbatim |
phungductung | 0:8ede47d38d10 | 484 | * @{ |
phungductung | 0:8ede47d38d10 | 485 | */ |
phungductung | 0:8ede47d38d10 | 486 | |
phungductung | 0:8ede47d38d10 | 487 | /** |
phungductung | 0:8ede47d38d10 | 488 | * @brief Starts the TIM Output Compare signal generation on the complementary |
phungductung | 0:8ede47d38d10 | 489 | * output. |
phungductung | 0:8ede47d38d10 | 490 | * @param htim: pointer to a TIM_HandleTypeDef structure that contains |
phungductung | 0:8ede47d38d10 | 491 | * the configuration information for TIM module. |
phungductung | 0:8ede47d38d10 | 492 | * @param Channel: TIM Channel to be enabled. |
phungductung | 0:8ede47d38d10 | 493 | * This parameter can be one of the following values: |
phungductung | 0:8ede47d38d10 | 494 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
phungductung | 0:8ede47d38d10 | 495 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
phungductung | 0:8ede47d38d10 | 496 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
phungductung | 0:8ede47d38d10 | 497 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
phungductung | 0:8ede47d38d10 | 498 | * @retval HAL status |
phungductung | 0:8ede47d38d10 | 499 | */ |
phungductung | 0:8ede47d38d10 | 500 | HAL_StatusTypeDef HAL_TIMEx_OCN_Start(TIM_HandleTypeDef *htim, uint32_t Channel) |
phungductung | 0:8ede47d38d10 | 501 | { |
phungductung | 0:8ede47d38d10 | 502 | /* Check the parameters */ |
phungductung | 0:8ede47d38d10 | 503 | assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel)); |
phungductung | 0:8ede47d38d10 | 504 | |
phungductung | 0:8ede47d38d10 | 505 | /* Enable the Capture compare channel N */ |
phungductung | 0:8ede47d38d10 | 506 | TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_ENABLE); |
phungductung | 0:8ede47d38d10 | 507 | |
phungductung | 0:8ede47d38d10 | 508 | /* Enable the Main Output */ |
phungductung | 0:8ede47d38d10 | 509 | __HAL_TIM_MOE_ENABLE(htim); |
phungductung | 0:8ede47d38d10 | 510 | |
phungductung | 0:8ede47d38d10 | 511 | /* Enable the Peripheral */ |
phungductung | 0:8ede47d38d10 | 512 | __HAL_TIM_ENABLE(htim); |
phungductung | 0:8ede47d38d10 | 513 | |
phungductung | 0:8ede47d38d10 | 514 | /* Return function status */ |
phungductung | 0:8ede47d38d10 | 515 | return HAL_OK; |
phungductung | 0:8ede47d38d10 | 516 | } |
phungductung | 0:8ede47d38d10 | 517 | |
phungductung | 0:8ede47d38d10 | 518 | /** |
phungductung | 0:8ede47d38d10 | 519 | * @brief Stops the TIM Output Compare signal generation on the complementary |
phungductung | 0:8ede47d38d10 | 520 | * output. |
phungductung | 0:8ede47d38d10 | 521 | * @param htim: pointer to a TIM_HandleTypeDef structure that contains |
phungductung | 0:8ede47d38d10 | 522 | * the configuration information for TIM module. |
phungductung | 0:8ede47d38d10 | 523 | * @param Channel: TIM Channel to be disabled. |
phungductung | 0:8ede47d38d10 | 524 | * This parameter can be one of the following values: |
phungductung | 0:8ede47d38d10 | 525 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
phungductung | 0:8ede47d38d10 | 526 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
phungductung | 0:8ede47d38d10 | 527 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
phungductung | 0:8ede47d38d10 | 528 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
phungductung | 0:8ede47d38d10 | 529 | * @retval HAL status |
phungductung | 0:8ede47d38d10 | 530 | */ |
phungductung | 0:8ede47d38d10 | 531 | HAL_StatusTypeDef HAL_TIMEx_OCN_Stop(TIM_HandleTypeDef *htim, uint32_t Channel) |
phungductung | 0:8ede47d38d10 | 532 | { |
phungductung | 0:8ede47d38d10 | 533 | /* Check the parameters */ |
phungductung | 0:8ede47d38d10 | 534 | assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel)); |
phungductung | 0:8ede47d38d10 | 535 | |
phungductung | 0:8ede47d38d10 | 536 | /* Disable the Capture compare channel N */ |
phungductung | 0:8ede47d38d10 | 537 | TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_DISABLE); |
phungductung | 0:8ede47d38d10 | 538 | |
phungductung | 0:8ede47d38d10 | 539 | /* Disable the Main Output */ |
phungductung | 0:8ede47d38d10 | 540 | __HAL_TIM_MOE_DISABLE(htim); |
phungductung | 0:8ede47d38d10 | 541 | |
phungductung | 0:8ede47d38d10 | 542 | /* Disable the Peripheral */ |
phungductung | 0:8ede47d38d10 | 543 | __HAL_TIM_DISABLE(htim); |
phungductung | 0:8ede47d38d10 | 544 | |
phungductung | 0:8ede47d38d10 | 545 | /* Return function status */ |
phungductung | 0:8ede47d38d10 | 546 | return HAL_OK; |
phungductung | 0:8ede47d38d10 | 547 | } |
phungductung | 0:8ede47d38d10 | 548 | |
phungductung | 0:8ede47d38d10 | 549 | /** |
phungductung | 0:8ede47d38d10 | 550 | * @brief Starts the TIM Output Compare signal generation in interrupt mode |
phungductung | 0:8ede47d38d10 | 551 | * on the complementary output. |
phungductung | 0:8ede47d38d10 | 552 | * @param htim: pointer to a TIM_HandleTypeDef structure that contains |
phungductung | 0:8ede47d38d10 | 553 | * the configuration information for TIM module. |
phungductung | 0:8ede47d38d10 | 554 | * @param Channel: TIM Channel to be enabled. |
phungductung | 0:8ede47d38d10 | 555 | * This parameter can be one of the following values: |
phungductung | 0:8ede47d38d10 | 556 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
phungductung | 0:8ede47d38d10 | 557 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
phungductung | 0:8ede47d38d10 | 558 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
phungductung | 0:8ede47d38d10 | 559 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
phungductung | 0:8ede47d38d10 | 560 | * @retval HAL status |
phungductung | 0:8ede47d38d10 | 561 | */ |
phungductung | 0:8ede47d38d10 | 562 | HAL_StatusTypeDef HAL_TIMEx_OCN_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel) |
phungductung | 0:8ede47d38d10 | 563 | { |
phungductung | 0:8ede47d38d10 | 564 | /* Check the parameters */ |
phungductung | 0:8ede47d38d10 | 565 | assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel)); |
phungductung | 0:8ede47d38d10 | 566 | |
phungductung | 0:8ede47d38d10 | 567 | switch (Channel) |
phungductung | 0:8ede47d38d10 | 568 | { |
phungductung | 0:8ede47d38d10 | 569 | case TIM_CHANNEL_1: |
phungductung | 0:8ede47d38d10 | 570 | { |
phungductung | 0:8ede47d38d10 | 571 | /* Enable the TIM Output Compare interrupt */ |
phungductung | 0:8ede47d38d10 | 572 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1); |
phungductung | 0:8ede47d38d10 | 573 | } |
phungductung | 0:8ede47d38d10 | 574 | break; |
phungductung | 0:8ede47d38d10 | 575 | |
phungductung | 0:8ede47d38d10 | 576 | case TIM_CHANNEL_2: |
phungductung | 0:8ede47d38d10 | 577 | { |
phungductung | 0:8ede47d38d10 | 578 | /* Enable the TIM Output Compare interrupt */ |
phungductung | 0:8ede47d38d10 | 579 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2); |
phungductung | 0:8ede47d38d10 | 580 | } |
phungductung | 0:8ede47d38d10 | 581 | break; |
phungductung | 0:8ede47d38d10 | 582 | |
phungductung | 0:8ede47d38d10 | 583 | case TIM_CHANNEL_3: |
phungductung | 0:8ede47d38d10 | 584 | { |
phungductung | 0:8ede47d38d10 | 585 | /* Enable the TIM Output Compare interrupt */ |
phungductung | 0:8ede47d38d10 | 586 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC3); |
phungductung | 0:8ede47d38d10 | 587 | } |
phungductung | 0:8ede47d38d10 | 588 | break; |
phungductung | 0:8ede47d38d10 | 589 | |
phungductung | 0:8ede47d38d10 | 590 | case TIM_CHANNEL_4: |
phungductung | 0:8ede47d38d10 | 591 | { |
phungductung | 0:8ede47d38d10 | 592 | /* Enable the TIM Output Compare interrupt */ |
phungductung | 0:8ede47d38d10 | 593 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC4); |
phungductung | 0:8ede47d38d10 | 594 | } |
phungductung | 0:8ede47d38d10 | 595 | break; |
phungductung | 0:8ede47d38d10 | 596 | |
phungductung | 0:8ede47d38d10 | 597 | default: |
phungductung | 0:8ede47d38d10 | 598 | break; |
phungductung | 0:8ede47d38d10 | 599 | } |
phungductung | 0:8ede47d38d10 | 600 | |
phungductung | 0:8ede47d38d10 | 601 | /* Enable the TIM Break interrupt */ |
phungductung | 0:8ede47d38d10 | 602 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_BREAK); |
phungductung | 0:8ede47d38d10 | 603 | |
phungductung | 0:8ede47d38d10 | 604 | /* Enable the Capture compare channel N */ |
phungductung | 0:8ede47d38d10 | 605 | TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_ENABLE); |
phungductung | 0:8ede47d38d10 | 606 | |
phungductung | 0:8ede47d38d10 | 607 | /* Enable the Main Output */ |
phungductung | 0:8ede47d38d10 | 608 | __HAL_TIM_MOE_ENABLE(htim); |
phungductung | 0:8ede47d38d10 | 609 | |
phungductung | 0:8ede47d38d10 | 610 | /* Enable the Peripheral */ |
phungductung | 0:8ede47d38d10 | 611 | __HAL_TIM_ENABLE(htim); |
phungductung | 0:8ede47d38d10 | 612 | |
phungductung | 0:8ede47d38d10 | 613 | /* Return function status */ |
phungductung | 0:8ede47d38d10 | 614 | return HAL_OK; |
phungductung | 0:8ede47d38d10 | 615 | } |
phungductung | 0:8ede47d38d10 | 616 | |
phungductung | 0:8ede47d38d10 | 617 | /** |
phungductung | 0:8ede47d38d10 | 618 | * @brief Stops the TIM Output Compare signal generation in interrupt mode |
phungductung | 0:8ede47d38d10 | 619 | * on the complementary output. |
phungductung | 0:8ede47d38d10 | 620 | * @param htim: pointer to a TIM_HandleTypeDef structure that contains |
phungductung | 0:8ede47d38d10 | 621 | * the configuration information for TIM module. |
phungductung | 0:8ede47d38d10 | 622 | * @param Channel: TIM Channel to be disabled. |
phungductung | 0:8ede47d38d10 | 623 | * This parameter can be one of the following values: |
phungductung | 0:8ede47d38d10 | 624 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
phungductung | 0:8ede47d38d10 | 625 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
phungductung | 0:8ede47d38d10 | 626 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
phungductung | 0:8ede47d38d10 | 627 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
phungductung | 0:8ede47d38d10 | 628 | * @retval HAL status |
phungductung | 0:8ede47d38d10 | 629 | */ |
phungductung | 0:8ede47d38d10 | 630 | HAL_StatusTypeDef HAL_TIMEx_OCN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel) |
phungductung | 0:8ede47d38d10 | 631 | { |
phungductung | 0:8ede47d38d10 | 632 | uint32_t tmpccer = 0; |
phungductung | 0:8ede47d38d10 | 633 | |
phungductung | 0:8ede47d38d10 | 634 | /* Check the parameters */ |
phungductung | 0:8ede47d38d10 | 635 | assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel)); |
phungductung | 0:8ede47d38d10 | 636 | |
phungductung | 0:8ede47d38d10 | 637 | switch (Channel) |
phungductung | 0:8ede47d38d10 | 638 | { |
phungductung | 0:8ede47d38d10 | 639 | case TIM_CHANNEL_1: |
phungductung | 0:8ede47d38d10 | 640 | { |
phungductung | 0:8ede47d38d10 | 641 | /* Disable the TIM Output Compare interrupt */ |
phungductung | 0:8ede47d38d10 | 642 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1); |
phungductung | 0:8ede47d38d10 | 643 | } |
phungductung | 0:8ede47d38d10 | 644 | break; |
phungductung | 0:8ede47d38d10 | 645 | |
phungductung | 0:8ede47d38d10 | 646 | case TIM_CHANNEL_2: |
phungductung | 0:8ede47d38d10 | 647 | { |
phungductung | 0:8ede47d38d10 | 648 | /* Disable the TIM Output Compare interrupt */ |
phungductung | 0:8ede47d38d10 | 649 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2); |
phungductung | 0:8ede47d38d10 | 650 | } |
phungductung | 0:8ede47d38d10 | 651 | break; |
phungductung | 0:8ede47d38d10 | 652 | |
phungductung | 0:8ede47d38d10 | 653 | case TIM_CHANNEL_3: |
phungductung | 0:8ede47d38d10 | 654 | { |
phungductung | 0:8ede47d38d10 | 655 | /* Disable the TIM Output Compare interrupt */ |
phungductung | 0:8ede47d38d10 | 656 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC3); |
phungductung | 0:8ede47d38d10 | 657 | } |
phungductung | 0:8ede47d38d10 | 658 | break; |
phungductung | 0:8ede47d38d10 | 659 | |
phungductung | 0:8ede47d38d10 | 660 | case TIM_CHANNEL_4: |
phungductung | 0:8ede47d38d10 | 661 | { |
phungductung | 0:8ede47d38d10 | 662 | /* Disable the TIM Output Compare interrupt */ |
phungductung | 0:8ede47d38d10 | 663 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC4); |
phungductung | 0:8ede47d38d10 | 664 | } |
phungductung | 0:8ede47d38d10 | 665 | break; |
phungductung | 0:8ede47d38d10 | 666 | |
phungductung | 0:8ede47d38d10 | 667 | default: |
phungductung | 0:8ede47d38d10 | 668 | break; |
phungductung | 0:8ede47d38d10 | 669 | } |
phungductung | 0:8ede47d38d10 | 670 | |
phungductung | 0:8ede47d38d10 | 671 | /* Disable the Capture compare channel N */ |
phungductung | 0:8ede47d38d10 | 672 | TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_DISABLE); |
phungductung | 0:8ede47d38d10 | 673 | |
phungductung | 0:8ede47d38d10 | 674 | /* Disable the TIM Break interrupt (only if no more channel is active) */ |
phungductung | 0:8ede47d38d10 | 675 | tmpccer = htim->Instance->CCER; |
phungductung | 0:8ede47d38d10 | 676 | if ((tmpccer & (TIM_CCER_CC1NE | TIM_CCER_CC2NE | TIM_CCER_CC3NE)) == RESET) |
phungductung | 0:8ede47d38d10 | 677 | { |
phungductung | 0:8ede47d38d10 | 678 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_BREAK); |
phungductung | 0:8ede47d38d10 | 679 | } |
phungductung | 0:8ede47d38d10 | 680 | |
phungductung | 0:8ede47d38d10 | 681 | /* Disable the Main Output */ |
phungductung | 0:8ede47d38d10 | 682 | __HAL_TIM_MOE_DISABLE(htim); |
phungductung | 0:8ede47d38d10 | 683 | |
phungductung | 0:8ede47d38d10 | 684 | /* Disable the Peripheral */ |
phungductung | 0:8ede47d38d10 | 685 | __HAL_TIM_DISABLE(htim); |
phungductung | 0:8ede47d38d10 | 686 | |
phungductung | 0:8ede47d38d10 | 687 | /* Return function status */ |
phungductung | 0:8ede47d38d10 | 688 | return HAL_OK; |
phungductung | 0:8ede47d38d10 | 689 | } |
phungductung | 0:8ede47d38d10 | 690 | |
phungductung | 0:8ede47d38d10 | 691 | /** |
phungductung | 0:8ede47d38d10 | 692 | * @brief Starts the TIM Output Compare signal generation in DMA mode |
phungductung | 0:8ede47d38d10 | 693 | * on the complementary output. |
phungductung | 0:8ede47d38d10 | 694 | * @param htim: pointer to a TIM_HandleTypeDef structure that contains |
phungductung | 0:8ede47d38d10 | 695 | * the configuration information for TIM module. |
phungductung | 0:8ede47d38d10 | 696 | * @param Channel: TIM Channel to be enabled. |
phungductung | 0:8ede47d38d10 | 697 | * This parameter can be one of the following values: |
phungductung | 0:8ede47d38d10 | 698 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
phungductung | 0:8ede47d38d10 | 699 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
phungductung | 0:8ede47d38d10 | 700 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
phungductung | 0:8ede47d38d10 | 701 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
phungductung | 0:8ede47d38d10 | 702 | * @param pData: The source Buffer address. |
phungductung | 0:8ede47d38d10 | 703 | * @param Length: The length of data to be transferred from memory to TIM peripheral |
phungductung | 0:8ede47d38d10 | 704 | * @retval HAL status |
phungductung | 0:8ede47d38d10 | 705 | */ |
phungductung | 0:8ede47d38d10 | 706 | HAL_StatusTypeDef HAL_TIMEx_OCN_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length) |
phungductung | 0:8ede47d38d10 | 707 | { |
phungductung | 0:8ede47d38d10 | 708 | /* Check the parameters */ |
phungductung | 0:8ede47d38d10 | 709 | assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel)); |
phungductung | 0:8ede47d38d10 | 710 | |
phungductung | 0:8ede47d38d10 | 711 | if((htim->State == HAL_TIM_STATE_BUSY)) |
phungductung | 0:8ede47d38d10 | 712 | { |
phungductung | 0:8ede47d38d10 | 713 | return HAL_BUSY; |
phungductung | 0:8ede47d38d10 | 714 | } |
phungductung | 0:8ede47d38d10 | 715 | else if((htim->State == HAL_TIM_STATE_READY)) |
phungductung | 0:8ede47d38d10 | 716 | { |
phungductung | 0:8ede47d38d10 | 717 | if(((uint32_t)pData == 0 ) && (Length > 0)) |
phungductung | 0:8ede47d38d10 | 718 | { |
phungductung | 0:8ede47d38d10 | 719 | return HAL_ERROR; |
phungductung | 0:8ede47d38d10 | 720 | } |
phungductung | 0:8ede47d38d10 | 721 | else |
phungductung | 0:8ede47d38d10 | 722 | { |
phungductung | 0:8ede47d38d10 | 723 | htim->State = HAL_TIM_STATE_BUSY; |
phungductung | 0:8ede47d38d10 | 724 | } |
phungductung | 0:8ede47d38d10 | 725 | } |
phungductung | 0:8ede47d38d10 | 726 | switch (Channel) |
phungductung | 0:8ede47d38d10 | 727 | { |
phungductung | 0:8ede47d38d10 | 728 | case TIM_CHANNEL_1: |
phungductung | 0:8ede47d38d10 | 729 | { |
phungductung | 0:8ede47d38d10 | 730 | /* Set the DMA Period elapsed callback */ |
phungductung | 0:8ede47d38d10 | 731 | htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = HAL_TIM_DMADelayPulseCplt; |
phungductung | 0:8ede47d38d10 | 732 | |
phungductung | 0:8ede47d38d10 | 733 | /* Set the DMA error callback */ |
phungductung | 0:8ede47d38d10 | 734 | htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = HAL_TIM_DMAError ; |
phungductung | 0:8ede47d38d10 | 735 | |
phungductung | 0:8ede47d38d10 | 736 | /* Enable the DMA Stream */ |
phungductung | 0:8ede47d38d10 | 737 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)pData, (uint32_t)&htim->Instance->CCR1, Length); |
phungductung | 0:8ede47d38d10 | 738 | |
phungductung | 0:8ede47d38d10 | 739 | /* Enable the TIM Output Compare DMA request */ |
phungductung | 0:8ede47d38d10 | 740 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1); |
phungductung | 0:8ede47d38d10 | 741 | } |
phungductung | 0:8ede47d38d10 | 742 | break; |
phungductung | 0:8ede47d38d10 | 743 | |
phungductung | 0:8ede47d38d10 | 744 | case TIM_CHANNEL_2: |
phungductung | 0:8ede47d38d10 | 745 | { |
phungductung | 0:8ede47d38d10 | 746 | /* Set the DMA Period elapsed callback */ |
phungductung | 0:8ede47d38d10 | 747 | htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = HAL_TIM_DMADelayPulseCplt; |
phungductung | 0:8ede47d38d10 | 748 | |
phungductung | 0:8ede47d38d10 | 749 | /* Set the DMA error callback */ |
phungductung | 0:8ede47d38d10 | 750 | htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = HAL_TIM_DMAError ; |
phungductung | 0:8ede47d38d10 | 751 | |
phungductung | 0:8ede47d38d10 | 752 | /* Enable the DMA Stream */ |
phungductung | 0:8ede47d38d10 | 753 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)pData, (uint32_t)&htim->Instance->CCR2, Length); |
phungductung | 0:8ede47d38d10 | 754 | |
phungductung | 0:8ede47d38d10 | 755 | /* Enable the TIM Output Compare DMA request */ |
phungductung | 0:8ede47d38d10 | 756 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2); |
phungductung | 0:8ede47d38d10 | 757 | } |
phungductung | 0:8ede47d38d10 | 758 | break; |
phungductung | 0:8ede47d38d10 | 759 | |
phungductung | 0:8ede47d38d10 | 760 | case TIM_CHANNEL_3: |
phungductung | 0:8ede47d38d10 | 761 | { |
phungductung | 0:8ede47d38d10 | 762 | /* Set the DMA Period elapsed callback */ |
phungductung | 0:8ede47d38d10 | 763 | htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = HAL_TIM_DMADelayPulseCplt; |
phungductung | 0:8ede47d38d10 | 764 | |
phungductung | 0:8ede47d38d10 | 765 | /* Set the DMA error callback */ |
phungductung | 0:8ede47d38d10 | 766 | htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = HAL_TIM_DMAError ; |
phungductung | 0:8ede47d38d10 | 767 | |
phungductung | 0:8ede47d38d10 | 768 | /* Enable the DMA Stream */ |
phungductung | 0:8ede47d38d10 | 769 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)pData, (uint32_t)&htim->Instance->CCR3,Length); |
phungductung | 0:8ede47d38d10 | 770 | |
phungductung | 0:8ede47d38d10 | 771 | /* Enable the TIM Output Compare DMA request */ |
phungductung | 0:8ede47d38d10 | 772 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC3); |
phungductung | 0:8ede47d38d10 | 773 | } |
phungductung | 0:8ede47d38d10 | 774 | break; |
phungductung | 0:8ede47d38d10 | 775 | |
phungductung | 0:8ede47d38d10 | 776 | case TIM_CHANNEL_4: |
phungductung | 0:8ede47d38d10 | 777 | { |
phungductung | 0:8ede47d38d10 | 778 | /* Set the DMA Period elapsed callback */ |
phungductung | 0:8ede47d38d10 | 779 | htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = HAL_TIM_DMADelayPulseCplt; |
phungductung | 0:8ede47d38d10 | 780 | |
phungductung | 0:8ede47d38d10 | 781 | /* Set the DMA error callback */ |
phungductung | 0:8ede47d38d10 | 782 | htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = HAL_TIM_DMAError ; |
phungductung | 0:8ede47d38d10 | 783 | |
phungductung | 0:8ede47d38d10 | 784 | /* Enable the DMA Stream */ |
phungductung | 0:8ede47d38d10 | 785 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)pData, (uint32_t)&htim->Instance->CCR4, Length); |
phungductung | 0:8ede47d38d10 | 786 | |
phungductung | 0:8ede47d38d10 | 787 | /* Enable the TIM Output Compare DMA request */ |
phungductung | 0:8ede47d38d10 | 788 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC4); |
phungductung | 0:8ede47d38d10 | 789 | } |
phungductung | 0:8ede47d38d10 | 790 | break; |
phungductung | 0:8ede47d38d10 | 791 | |
phungductung | 0:8ede47d38d10 | 792 | default: |
phungductung | 0:8ede47d38d10 | 793 | break; |
phungductung | 0:8ede47d38d10 | 794 | } |
phungductung | 0:8ede47d38d10 | 795 | |
phungductung | 0:8ede47d38d10 | 796 | /* Enable the Capture compare channel N */ |
phungductung | 0:8ede47d38d10 | 797 | TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_ENABLE); |
phungductung | 0:8ede47d38d10 | 798 | |
phungductung | 0:8ede47d38d10 | 799 | /* Enable the Main Output */ |
phungductung | 0:8ede47d38d10 | 800 | __HAL_TIM_MOE_ENABLE(htim); |
phungductung | 0:8ede47d38d10 | 801 | |
phungductung | 0:8ede47d38d10 | 802 | /* Enable the Peripheral */ |
phungductung | 0:8ede47d38d10 | 803 | __HAL_TIM_ENABLE(htim); |
phungductung | 0:8ede47d38d10 | 804 | |
phungductung | 0:8ede47d38d10 | 805 | /* Return function status */ |
phungductung | 0:8ede47d38d10 | 806 | return HAL_OK; |
phungductung | 0:8ede47d38d10 | 807 | } |
phungductung | 0:8ede47d38d10 | 808 | |
phungductung | 0:8ede47d38d10 | 809 | /** |
phungductung | 0:8ede47d38d10 | 810 | * @brief Stops the TIM Output Compare signal generation in DMA mode |
phungductung | 0:8ede47d38d10 | 811 | * on the complementary output. |
phungductung | 0:8ede47d38d10 | 812 | * @param htim: pointer to a TIM_HandleTypeDef structure that contains |
phungductung | 0:8ede47d38d10 | 813 | * the configuration information for TIM module. |
phungductung | 0:8ede47d38d10 | 814 | * @param Channel: TIM Channel to be disabled. |
phungductung | 0:8ede47d38d10 | 815 | * This parameter can be one of the following values: |
phungductung | 0:8ede47d38d10 | 816 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
phungductung | 0:8ede47d38d10 | 817 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
phungductung | 0:8ede47d38d10 | 818 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
phungductung | 0:8ede47d38d10 | 819 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
phungductung | 0:8ede47d38d10 | 820 | * @retval HAL status |
phungductung | 0:8ede47d38d10 | 821 | */ |
phungductung | 0:8ede47d38d10 | 822 | HAL_StatusTypeDef HAL_TIMEx_OCN_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel) |
phungductung | 0:8ede47d38d10 | 823 | { |
phungductung | 0:8ede47d38d10 | 824 | /* Check the parameters */ |
phungductung | 0:8ede47d38d10 | 825 | assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel)); |
phungductung | 0:8ede47d38d10 | 826 | |
phungductung | 0:8ede47d38d10 | 827 | switch (Channel) |
phungductung | 0:8ede47d38d10 | 828 | { |
phungductung | 0:8ede47d38d10 | 829 | case TIM_CHANNEL_1: |
phungductung | 0:8ede47d38d10 | 830 | { |
phungductung | 0:8ede47d38d10 | 831 | /* Disable the TIM Output Compare DMA request */ |
phungductung | 0:8ede47d38d10 | 832 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1); |
phungductung | 0:8ede47d38d10 | 833 | } |
phungductung | 0:8ede47d38d10 | 834 | break; |
phungductung | 0:8ede47d38d10 | 835 | |
phungductung | 0:8ede47d38d10 | 836 | case TIM_CHANNEL_2: |
phungductung | 0:8ede47d38d10 | 837 | { |
phungductung | 0:8ede47d38d10 | 838 | /* Disable the TIM Output Compare DMA request */ |
phungductung | 0:8ede47d38d10 | 839 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2); |
phungductung | 0:8ede47d38d10 | 840 | } |
phungductung | 0:8ede47d38d10 | 841 | break; |
phungductung | 0:8ede47d38d10 | 842 | |
phungductung | 0:8ede47d38d10 | 843 | case TIM_CHANNEL_3: |
phungductung | 0:8ede47d38d10 | 844 | { |
phungductung | 0:8ede47d38d10 | 845 | /* Disable the TIM Output Compare DMA request */ |
phungductung | 0:8ede47d38d10 | 846 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC3); |
phungductung | 0:8ede47d38d10 | 847 | } |
phungductung | 0:8ede47d38d10 | 848 | break; |
phungductung | 0:8ede47d38d10 | 849 | |
phungductung | 0:8ede47d38d10 | 850 | case TIM_CHANNEL_4: |
phungductung | 0:8ede47d38d10 | 851 | { |
phungductung | 0:8ede47d38d10 | 852 | /* Disable the TIM Output Compare interrupt */ |
phungductung | 0:8ede47d38d10 | 853 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC4); |
phungductung | 0:8ede47d38d10 | 854 | } |
phungductung | 0:8ede47d38d10 | 855 | break; |
phungductung | 0:8ede47d38d10 | 856 | |
phungductung | 0:8ede47d38d10 | 857 | default: |
phungductung | 0:8ede47d38d10 | 858 | break; |
phungductung | 0:8ede47d38d10 | 859 | } |
phungductung | 0:8ede47d38d10 | 860 | |
phungductung | 0:8ede47d38d10 | 861 | /* Disable the Capture compare channel N */ |
phungductung | 0:8ede47d38d10 | 862 | TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_DISABLE); |
phungductung | 0:8ede47d38d10 | 863 | |
phungductung | 0:8ede47d38d10 | 864 | /* Disable the Main Output */ |
phungductung | 0:8ede47d38d10 | 865 | __HAL_TIM_MOE_DISABLE(htim); |
phungductung | 0:8ede47d38d10 | 866 | |
phungductung | 0:8ede47d38d10 | 867 | /* Disable the Peripheral */ |
phungductung | 0:8ede47d38d10 | 868 | __HAL_TIM_DISABLE(htim); |
phungductung | 0:8ede47d38d10 | 869 | |
phungductung | 0:8ede47d38d10 | 870 | /* Change the htim state */ |
phungductung | 0:8ede47d38d10 | 871 | htim->State = HAL_TIM_STATE_READY; |
phungductung | 0:8ede47d38d10 | 872 | |
phungductung | 0:8ede47d38d10 | 873 | /* Return function status */ |
phungductung | 0:8ede47d38d10 | 874 | return HAL_OK; |
phungductung | 0:8ede47d38d10 | 875 | } |
phungductung | 0:8ede47d38d10 | 876 | |
phungductung | 0:8ede47d38d10 | 877 | /** |
phungductung | 0:8ede47d38d10 | 878 | * @} |
phungductung | 0:8ede47d38d10 | 879 | */ |
phungductung | 0:8ede47d38d10 | 880 | |
phungductung | 0:8ede47d38d10 | 881 | /** @defgroup TIMEx_Exported_Functions_Group3 Extended Timer Complementary PWM functions |
phungductung | 0:8ede47d38d10 | 882 | * @brief Timer Complementary PWM functions |
phungductung | 0:8ede47d38d10 | 883 | * |
phungductung | 0:8ede47d38d10 | 884 | @verbatim |
phungductung | 0:8ede47d38d10 | 885 | ============================================================================== |
phungductung | 0:8ede47d38d10 | 886 | ##### Timer Complementary PWM functions ##### |
phungductung | 0:8ede47d38d10 | 887 | ============================================================================== |
phungductung | 0:8ede47d38d10 | 888 | [..] |
phungductung | 0:8ede47d38d10 | 889 | This section provides functions allowing to: |
phungductung | 0:8ede47d38d10 | 890 | (+) Start the Complementary PWM. |
phungductung | 0:8ede47d38d10 | 891 | (+) Stop the Complementary PWM. |
phungductung | 0:8ede47d38d10 | 892 | (+) Start the Complementary PWM and enable interrupts. |
phungductung | 0:8ede47d38d10 | 893 | (+) Stop the Complementary PWM and disable interrupts. |
phungductung | 0:8ede47d38d10 | 894 | (+) Start the Complementary PWM and enable DMA transfers. |
phungductung | 0:8ede47d38d10 | 895 | (+) Stop the Complementary PWM and disable DMA transfers. |
phungductung | 0:8ede47d38d10 | 896 | (+) Start the Complementary Input Capture measurement. |
phungductung | 0:8ede47d38d10 | 897 | (+) Stop the Complementary Input Capture. |
phungductung | 0:8ede47d38d10 | 898 | (+) Start the Complementary Input Capture and enable interrupts. |
phungductung | 0:8ede47d38d10 | 899 | (+) Stop the Complementary Input Capture and disable interrupts. |
phungductung | 0:8ede47d38d10 | 900 | (+) Start the Complementary Input Capture and enable DMA transfers. |
phungductung | 0:8ede47d38d10 | 901 | (+) Stop the Complementary Input Capture and disable DMA transfers. |
phungductung | 0:8ede47d38d10 | 902 | (+) Start the Complementary One Pulse generation. |
phungductung | 0:8ede47d38d10 | 903 | (+) Stop the Complementary One Pulse. |
phungductung | 0:8ede47d38d10 | 904 | (+) Start the Complementary One Pulse and enable interrupts. |
phungductung | 0:8ede47d38d10 | 905 | (+) Stop the Complementary One Pulse and disable interrupts. |
phungductung | 0:8ede47d38d10 | 906 | |
phungductung | 0:8ede47d38d10 | 907 | @endverbatim |
phungductung | 0:8ede47d38d10 | 908 | * @{ |
phungductung | 0:8ede47d38d10 | 909 | */ |
phungductung | 0:8ede47d38d10 | 910 | |
phungductung | 0:8ede47d38d10 | 911 | /** |
phungductung | 0:8ede47d38d10 | 912 | * @brief Starts the PWM signal generation on the complementary output. |
phungductung | 0:8ede47d38d10 | 913 | * @param htim: pointer to a TIM_HandleTypeDef structure that contains |
phungductung | 0:8ede47d38d10 | 914 | * the configuration information for TIM module. |
phungductung | 0:8ede47d38d10 | 915 | * @param Channel: TIM Channel to be enabled. |
phungductung | 0:8ede47d38d10 | 916 | * This parameter can be one of the following values: |
phungductung | 0:8ede47d38d10 | 917 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
phungductung | 0:8ede47d38d10 | 918 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
phungductung | 0:8ede47d38d10 | 919 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
phungductung | 0:8ede47d38d10 | 920 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
phungductung | 0:8ede47d38d10 | 921 | * @retval HAL status |
phungductung | 0:8ede47d38d10 | 922 | */ |
phungductung | 0:8ede47d38d10 | 923 | HAL_StatusTypeDef HAL_TIMEx_PWMN_Start(TIM_HandleTypeDef *htim, uint32_t Channel) |
phungductung | 0:8ede47d38d10 | 924 | { |
phungductung | 0:8ede47d38d10 | 925 | /* Check the parameters */ |
phungductung | 0:8ede47d38d10 | 926 | assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel)); |
phungductung | 0:8ede47d38d10 | 927 | |
phungductung | 0:8ede47d38d10 | 928 | /* Enable the complementary PWM output */ |
phungductung | 0:8ede47d38d10 | 929 | TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_ENABLE); |
phungductung | 0:8ede47d38d10 | 930 | |
phungductung | 0:8ede47d38d10 | 931 | /* Enable the Main Output */ |
phungductung | 0:8ede47d38d10 | 932 | __HAL_TIM_MOE_ENABLE(htim); |
phungductung | 0:8ede47d38d10 | 933 | |
phungductung | 0:8ede47d38d10 | 934 | /* Enable the Peripheral */ |
phungductung | 0:8ede47d38d10 | 935 | __HAL_TIM_ENABLE(htim); |
phungductung | 0:8ede47d38d10 | 936 | |
phungductung | 0:8ede47d38d10 | 937 | /* Return function status */ |
phungductung | 0:8ede47d38d10 | 938 | return HAL_OK; |
phungductung | 0:8ede47d38d10 | 939 | } |
phungductung | 0:8ede47d38d10 | 940 | |
phungductung | 0:8ede47d38d10 | 941 | /** |
phungductung | 0:8ede47d38d10 | 942 | * @brief Stops the PWM signal generation on the complementary output. |
phungductung | 0:8ede47d38d10 | 943 | * @param htim: pointer to a TIM_HandleTypeDef structure that contains |
phungductung | 0:8ede47d38d10 | 944 | * the configuration information for TIM module. |
phungductung | 0:8ede47d38d10 | 945 | * @param Channel: TIM Channel to be disabled. |
phungductung | 0:8ede47d38d10 | 946 | * This parameter can be one of the following values: |
phungductung | 0:8ede47d38d10 | 947 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
phungductung | 0:8ede47d38d10 | 948 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
phungductung | 0:8ede47d38d10 | 949 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
phungductung | 0:8ede47d38d10 | 950 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
phungductung | 0:8ede47d38d10 | 951 | * @retval HAL status |
phungductung | 0:8ede47d38d10 | 952 | */ |
phungductung | 0:8ede47d38d10 | 953 | HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop(TIM_HandleTypeDef *htim, uint32_t Channel) |
phungductung | 0:8ede47d38d10 | 954 | { |
phungductung | 0:8ede47d38d10 | 955 | /* Check the parameters */ |
phungductung | 0:8ede47d38d10 | 956 | assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel)); |
phungductung | 0:8ede47d38d10 | 957 | |
phungductung | 0:8ede47d38d10 | 958 | /* Disable the complementary PWM output */ |
phungductung | 0:8ede47d38d10 | 959 | TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_DISABLE); |
phungductung | 0:8ede47d38d10 | 960 | |
phungductung | 0:8ede47d38d10 | 961 | /* Disable the Main Output */ |
phungductung | 0:8ede47d38d10 | 962 | __HAL_TIM_MOE_DISABLE(htim); |
phungductung | 0:8ede47d38d10 | 963 | |
phungductung | 0:8ede47d38d10 | 964 | /* Disable the Peripheral */ |
phungductung | 0:8ede47d38d10 | 965 | __HAL_TIM_DISABLE(htim); |
phungductung | 0:8ede47d38d10 | 966 | |
phungductung | 0:8ede47d38d10 | 967 | /* Return function status */ |
phungductung | 0:8ede47d38d10 | 968 | return HAL_OK; |
phungductung | 0:8ede47d38d10 | 969 | } |
phungductung | 0:8ede47d38d10 | 970 | |
phungductung | 0:8ede47d38d10 | 971 | /** |
phungductung | 0:8ede47d38d10 | 972 | * @brief Starts the PWM signal generation in interrupt mode on the |
phungductung | 0:8ede47d38d10 | 973 | * complementary output. |
phungductung | 0:8ede47d38d10 | 974 | * @param htim: pointer to a TIM_HandleTypeDef structure that contains |
phungductung | 0:8ede47d38d10 | 975 | * the configuration information for TIM module. |
phungductung | 0:8ede47d38d10 | 976 | * @param Channel: TIM Channel to be disabled. |
phungductung | 0:8ede47d38d10 | 977 | * This parameter can be one of the following values: |
phungductung | 0:8ede47d38d10 | 978 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
phungductung | 0:8ede47d38d10 | 979 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
phungductung | 0:8ede47d38d10 | 980 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
phungductung | 0:8ede47d38d10 | 981 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
phungductung | 0:8ede47d38d10 | 982 | * @retval HAL status |
phungductung | 0:8ede47d38d10 | 983 | */ |
phungductung | 0:8ede47d38d10 | 984 | HAL_StatusTypeDef HAL_TIMEx_PWMN_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel) |
phungductung | 0:8ede47d38d10 | 985 | { |
phungductung | 0:8ede47d38d10 | 986 | /* Check the parameters */ |
phungductung | 0:8ede47d38d10 | 987 | assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel)); |
phungductung | 0:8ede47d38d10 | 988 | |
phungductung | 0:8ede47d38d10 | 989 | switch (Channel) |
phungductung | 0:8ede47d38d10 | 990 | { |
phungductung | 0:8ede47d38d10 | 991 | case TIM_CHANNEL_1: |
phungductung | 0:8ede47d38d10 | 992 | { |
phungductung | 0:8ede47d38d10 | 993 | /* Enable the TIM Capture/Compare 1 interrupt */ |
phungductung | 0:8ede47d38d10 | 994 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1); |
phungductung | 0:8ede47d38d10 | 995 | } |
phungductung | 0:8ede47d38d10 | 996 | break; |
phungductung | 0:8ede47d38d10 | 997 | |
phungductung | 0:8ede47d38d10 | 998 | case TIM_CHANNEL_2: |
phungductung | 0:8ede47d38d10 | 999 | { |
phungductung | 0:8ede47d38d10 | 1000 | /* Enable the TIM Capture/Compare 2 interrupt */ |
phungductung | 0:8ede47d38d10 | 1001 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2); |
phungductung | 0:8ede47d38d10 | 1002 | } |
phungductung | 0:8ede47d38d10 | 1003 | break; |
phungductung | 0:8ede47d38d10 | 1004 | |
phungductung | 0:8ede47d38d10 | 1005 | case TIM_CHANNEL_3: |
phungductung | 0:8ede47d38d10 | 1006 | { |
phungductung | 0:8ede47d38d10 | 1007 | /* Enable the TIM Capture/Compare 3 interrupt */ |
phungductung | 0:8ede47d38d10 | 1008 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC3); |
phungductung | 0:8ede47d38d10 | 1009 | } |
phungductung | 0:8ede47d38d10 | 1010 | break; |
phungductung | 0:8ede47d38d10 | 1011 | |
phungductung | 0:8ede47d38d10 | 1012 | case TIM_CHANNEL_4: |
phungductung | 0:8ede47d38d10 | 1013 | { |
phungductung | 0:8ede47d38d10 | 1014 | /* Enable the TIM Capture/Compare 4 interrupt */ |
phungductung | 0:8ede47d38d10 | 1015 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC4); |
phungductung | 0:8ede47d38d10 | 1016 | } |
phungductung | 0:8ede47d38d10 | 1017 | break; |
phungductung | 0:8ede47d38d10 | 1018 | |
phungductung | 0:8ede47d38d10 | 1019 | default: |
phungductung | 0:8ede47d38d10 | 1020 | break; |
phungductung | 0:8ede47d38d10 | 1021 | } |
phungductung | 0:8ede47d38d10 | 1022 | |
phungductung | 0:8ede47d38d10 | 1023 | /* Enable the TIM Break interrupt */ |
phungductung | 0:8ede47d38d10 | 1024 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_BREAK); |
phungductung | 0:8ede47d38d10 | 1025 | |
phungductung | 0:8ede47d38d10 | 1026 | /* Enable the complementary PWM output */ |
phungductung | 0:8ede47d38d10 | 1027 | TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_ENABLE); |
phungductung | 0:8ede47d38d10 | 1028 | |
phungductung | 0:8ede47d38d10 | 1029 | /* Enable the Main Output */ |
phungductung | 0:8ede47d38d10 | 1030 | __HAL_TIM_MOE_ENABLE(htim); |
phungductung | 0:8ede47d38d10 | 1031 | |
phungductung | 0:8ede47d38d10 | 1032 | /* Enable the Peripheral */ |
phungductung | 0:8ede47d38d10 | 1033 | __HAL_TIM_ENABLE(htim); |
phungductung | 0:8ede47d38d10 | 1034 | |
phungductung | 0:8ede47d38d10 | 1035 | /* Return function status */ |
phungductung | 0:8ede47d38d10 | 1036 | return HAL_OK; |
phungductung | 0:8ede47d38d10 | 1037 | } |
phungductung | 0:8ede47d38d10 | 1038 | |
phungductung | 0:8ede47d38d10 | 1039 | /** |
phungductung | 0:8ede47d38d10 | 1040 | * @brief Stops the PWM signal generation in interrupt mode on the |
phungductung | 0:8ede47d38d10 | 1041 | * complementary output. |
phungductung | 0:8ede47d38d10 | 1042 | * @param htim: pointer to a TIM_HandleTypeDef structure that contains |
phungductung | 0:8ede47d38d10 | 1043 | * the configuration information for TIM module. |
phungductung | 0:8ede47d38d10 | 1044 | * @param Channel: TIM Channel to be disabled. |
phungductung | 0:8ede47d38d10 | 1045 | * This parameter can be one of the following values: |
phungductung | 0:8ede47d38d10 | 1046 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
phungductung | 0:8ede47d38d10 | 1047 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
phungductung | 0:8ede47d38d10 | 1048 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
phungductung | 0:8ede47d38d10 | 1049 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
phungductung | 0:8ede47d38d10 | 1050 | * @retval HAL status |
phungductung | 0:8ede47d38d10 | 1051 | */ |
phungductung | 0:8ede47d38d10 | 1052 | HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop_IT (TIM_HandleTypeDef *htim, uint32_t Channel) |
phungductung | 0:8ede47d38d10 | 1053 | { |
phungductung | 0:8ede47d38d10 | 1054 | uint32_t tmpccer = 0; |
phungductung | 0:8ede47d38d10 | 1055 | |
phungductung | 0:8ede47d38d10 | 1056 | /* Check the parameters */ |
phungductung | 0:8ede47d38d10 | 1057 | assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel)); |
phungductung | 0:8ede47d38d10 | 1058 | |
phungductung | 0:8ede47d38d10 | 1059 | switch (Channel) |
phungductung | 0:8ede47d38d10 | 1060 | { |
phungductung | 0:8ede47d38d10 | 1061 | case TIM_CHANNEL_1: |
phungductung | 0:8ede47d38d10 | 1062 | { |
phungductung | 0:8ede47d38d10 | 1063 | /* Disable the TIM Capture/Compare 1 interrupt */ |
phungductung | 0:8ede47d38d10 | 1064 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1); |
phungductung | 0:8ede47d38d10 | 1065 | } |
phungductung | 0:8ede47d38d10 | 1066 | break; |
phungductung | 0:8ede47d38d10 | 1067 | |
phungductung | 0:8ede47d38d10 | 1068 | case TIM_CHANNEL_2: |
phungductung | 0:8ede47d38d10 | 1069 | { |
phungductung | 0:8ede47d38d10 | 1070 | /* Disable the TIM Capture/Compare 2 interrupt */ |
phungductung | 0:8ede47d38d10 | 1071 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2); |
phungductung | 0:8ede47d38d10 | 1072 | } |
phungductung | 0:8ede47d38d10 | 1073 | break; |
phungductung | 0:8ede47d38d10 | 1074 | |
phungductung | 0:8ede47d38d10 | 1075 | case TIM_CHANNEL_3: |
phungductung | 0:8ede47d38d10 | 1076 | { |
phungductung | 0:8ede47d38d10 | 1077 | /* Disable the TIM Capture/Compare 3 interrupt */ |
phungductung | 0:8ede47d38d10 | 1078 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC3); |
phungductung | 0:8ede47d38d10 | 1079 | } |
phungductung | 0:8ede47d38d10 | 1080 | break; |
phungductung | 0:8ede47d38d10 | 1081 | |
phungductung | 0:8ede47d38d10 | 1082 | case TIM_CHANNEL_4: |
phungductung | 0:8ede47d38d10 | 1083 | { |
phungductung | 0:8ede47d38d10 | 1084 | /* Disable the TIM Capture/Compare 3 interrupt */ |
phungductung | 0:8ede47d38d10 | 1085 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC4); |
phungductung | 0:8ede47d38d10 | 1086 | } |
phungductung | 0:8ede47d38d10 | 1087 | break; |
phungductung | 0:8ede47d38d10 | 1088 | |
phungductung | 0:8ede47d38d10 | 1089 | default: |
phungductung | 0:8ede47d38d10 | 1090 | break; |
phungductung | 0:8ede47d38d10 | 1091 | } |
phungductung | 0:8ede47d38d10 | 1092 | |
phungductung | 0:8ede47d38d10 | 1093 | /* Disable the complementary PWM output */ |
phungductung | 0:8ede47d38d10 | 1094 | TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_DISABLE); |
phungductung | 0:8ede47d38d10 | 1095 | |
phungductung | 0:8ede47d38d10 | 1096 | /* Disable the TIM Break interrupt (only if no more channel is active) */ |
phungductung | 0:8ede47d38d10 | 1097 | tmpccer = htim->Instance->CCER; |
phungductung | 0:8ede47d38d10 | 1098 | if ((tmpccer & (TIM_CCER_CC1NE | TIM_CCER_CC2NE | TIM_CCER_CC3NE)) == RESET) |
phungductung | 0:8ede47d38d10 | 1099 | { |
phungductung | 0:8ede47d38d10 | 1100 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_BREAK); |
phungductung | 0:8ede47d38d10 | 1101 | } |
phungductung | 0:8ede47d38d10 | 1102 | |
phungductung | 0:8ede47d38d10 | 1103 | /* Disable the Main Output */ |
phungductung | 0:8ede47d38d10 | 1104 | __HAL_TIM_MOE_DISABLE(htim); |
phungductung | 0:8ede47d38d10 | 1105 | |
phungductung | 0:8ede47d38d10 | 1106 | /* Disable the Peripheral */ |
phungductung | 0:8ede47d38d10 | 1107 | __HAL_TIM_DISABLE(htim); |
phungductung | 0:8ede47d38d10 | 1108 | |
phungductung | 0:8ede47d38d10 | 1109 | /* Return function status */ |
phungductung | 0:8ede47d38d10 | 1110 | return HAL_OK; |
phungductung | 0:8ede47d38d10 | 1111 | } |
phungductung | 0:8ede47d38d10 | 1112 | |
phungductung | 0:8ede47d38d10 | 1113 | /** |
phungductung | 0:8ede47d38d10 | 1114 | * @brief Starts the TIM PWM signal generation in DMA mode on the |
phungductung | 0:8ede47d38d10 | 1115 | * complementary output |
phungductung | 0:8ede47d38d10 | 1116 | * @param htim: pointer to a TIM_HandleTypeDef structure that contains |
phungductung | 0:8ede47d38d10 | 1117 | * the configuration information for TIM module. |
phungductung | 0:8ede47d38d10 | 1118 | * @param Channel: TIM Channel to be enabled. |
phungductung | 0:8ede47d38d10 | 1119 | * This parameter can be one of the following values: |
phungductung | 0:8ede47d38d10 | 1120 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
phungductung | 0:8ede47d38d10 | 1121 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
phungductung | 0:8ede47d38d10 | 1122 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
phungductung | 0:8ede47d38d10 | 1123 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
phungductung | 0:8ede47d38d10 | 1124 | * @param pData: The source Buffer address. |
phungductung | 0:8ede47d38d10 | 1125 | * @param Length: The length of data to be transferred from memory to TIM peripheral |
phungductung | 0:8ede47d38d10 | 1126 | * @retval HAL status |
phungductung | 0:8ede47d38d10 | 1127 | */ |
phungductung | 0:8ede47d38d10 | 1128 | HAL_StatusTypeDef HAL_TIMEx_PWMN_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length) |
phungductung | 0:8ede47d38d10 | 1129 | { |
phungductung | 0:8ede47d38d10 | 1130 | /* Check the parameters */ |
phungductung | 0:8ede47d38d10 | 1131 | assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel)); |
phungductung | 0:8ede47d38d10 | 1132 | |
phungductung | 0:8ede47d38d10 | 1133 | if((htim->State == HAL_TIM_STATE_BUSY)) |
phungductung | 0:8ede47d38d10 | 1134 | { |
phungductung | 0:8ede47d38d10 | 1135 | return HAL_BUSY; |
phungductung | 0:8ede47d38d10 | 1136 | } |
phungductung | 0:8ede47d38d10 | 1137 | else if((htim->State == HAL_TIM_STATE_READY)) |
phungductung | 0:8ede47d38d10 | 1138 | { |
phungductung | 0:8ede47d38d10 | 1139 | if(((uint32_t)pData == 0 ) && (Length > 0)) |
phungductung | 0:8ede47d38d10 | 1140 | { |
phungductung | 0:8ede47d38d10 | 1141 | return HAL_ERROR; |
phungductung | 0:8ede47d38d10 | 1142 | } |
phungductung | 0:8ede47d38d10 | 1143 | else |
phungductung | 0:8ede47d38d10 | 1144 | { |
phungductung | 0:8ede47d38d10 | 1145 | htim->State = HAL_TIM_STATE_BUSY; |
phungductung | 0:8ede47d38d10 | 1146 | } |
phungductung | 0:8ede47d38d10 | 1147 | } |
phungductung | 0:8ede47d38d10 | 1148 | switch (Channel) |
phungductung | 0:8ede47d38d10 | 1149 | { |
phungductung | 0:8ede47d38d10 | 1150 | case TIM_CHANNEL_1: |
phungductung | 0:8ede47d38d10 | 1151 | { |
phungductung | 0:8ede47d38d10 | 1152 | /* Set the DMA Period elapsed callback */ |
phungductung | 0:8ede47d38d10 | 1153 | htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = HAL_TIM_DMADelayPulseCplt; |
phungductung | 0:8ede47d38d10 | 1154 | |
phungductung | 0:8ede47d38d10 | 1155 | /* Set the DMA error callback */ |
phungductung | 0:8ede47d38d10 | 1156 | htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = HAL_TIM_DMAError ; |
phungductung | 0:8ede47d38d10 | 1157 | |
phungductung | 0:8ede47d38d10 | 1158 | /* Enable the DMA Stream */ |
phungductung | 0:8ede47d38d10 | 1159 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)pData, (uint32_t)&htim->Instance->CCR1, Length); |
phungductung | 0:8ede47d38d10 | 1160 | |
phungductung | 0:8ede47d38d10 | 1161 | /* Enable the TIM Capture/Compare 1 DMA request */ |
phungductung | 0:8ede47d38d10 | 1162 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1); |
phungductung | 0:8ede47d38d10 | 1163 | } |
phungductung | 0:8ede47d38d10 | 1164 | break; |
phungductung | 0:8ede47d38d10 | 1165 | |
phungductung | 0:8ede47d38d10 | 1166 | case TIM_CHANNEL_2: |
phungductung | 0:8ede47d38d10 | 1167 | { |
phungductung | 0:8ede47d38d10 | 1168 | /* Set the DMA Period elapsed callback */ |
phungductung | 0:8ede47d38d10 | 1169 | htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = HAL_TIM_DMADelayPulseCplt; |
phungductung | 0:8ede47d38d10 | 1170 | |
phungductung | 0:8ede47d38d10 | 1171 | /* Set the DMA error callback */ |
phungductung | 0:8ede47d38d10 | 1172 | htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = HAL_TIM_DMAError ; |
phungductung | 0:8ede47d38d10 | 1173 | |
phungductung | 0:8ede47d38d10 | 1174 | /* Enable the DMA Stream */ |
phungductung | 0:8ede47d38d10 | 1175 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)pData, (uint32_t)&htim->Instance->CCR2, Length); |
phungductung | 0:8ede47d38d10 | 1176 | |
phungductung | 0:8ede47d38d10 | 1177 | /* Enable the TIM Capture/Compare 2 DMA request */ |
phungductung | 0:8ede47d38d10 | 1178 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2); |
phungductung | 0:8ede47d38d10 | 1179 | } |
phungductung | 0:8ede47d38d10 | 1180 | break; |
phungductung | 0:8ede47d38d10 | 1181 | |
phungductung | 0:8ede47d38d10 | 1182 | case TIM_CHANNEL_3: |
phungductung | 0:8ede47d38d10 | 1183 | { |
phungductung | 0:8ede47d38d10 | 1184 | /* Set the DMA Period elapsed callback */ |
phungductung | 0:8ede47d38d10 | 1185 | htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = HAL_TIM_DMADelayPulseCplt; |
phungductung | 0:8ede47d38d10 | 1186 | |
phungductung | 0:8ede47d38d10 | 1187 | /* Set the DMA error callback */ |
phungductung | 0:8ede47d38d10 | 1188 | htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = HAL_TIM_DMAError ; |
phungductung | 0:8ede47d38d10 | 1189 | |
phungductung | 0:8ede47d38d10 | 1190 | /* Enable the DMA Stream */ |
phungductung | 0:8ede47d38d10 | 1191 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)pData, (uint32_t)&htim->Instance->CCR3,Length); |
phungductung | 0:8ede47d38d10 | 1192 | |
phungductung | 0:8ede47d38d10 | 1193 | /* Enable the TIM Capture/Compare 3 DMA request */ |
phungductung | 0:8ede47d38d10 | 1194 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC3); |
phungductung | 0:8ede47d38d10 | 1195 | } |
phungductung | 0:8ede47d38d10 | 1196 | break; |
phungductung | 0:8ede47d38d10 | 1197 | |
phungductung | 0:8ede47d38d10 | 1198 | case TIM_CHANNEL_4: |
phungductung | 0:8ede47d38d10 | 1199 | { |
phungductung | 0:8ede47d38d10 | 1200 | /* Set the DMA Period elapsed callback */ |
phungductung | 0:8ede47d38d10 | 1201 | htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = HAL_TIM_DMADelayPulseCplt; |
phungductung | 0:8ede47d38d10 | 1202 | |
phungductung | 0:8ede47d38d10 | 1203 | /* Set the DMA error callback */ |
phungductung | 0:8ede47d38d10 | 1204 | htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = HAL_TIM_DMAError ; |
phungductung | 0:8ede47d38d10 | 1205 | |
phungductung | 0:8ede47d38d10 | 1206 | /* Enable the DMA Stream */ |
phungductung | 0:8ede47d38d10 | 1207 | HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)pData, (uint32_t)&htim->Instance->CCR4, Length); |
phungductung | 0:8ede47d38d10 | 1208 | |
phungductung | 0:8ede47d38d10 | 1209 | /* Enable the TIM Capture/Compare 4 DMA request */ |
phungductung | 0:8ede47d38d10 | 1210 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC4); |
phungductung | 0:8ede47d38d10 | 1211 | } |
phungductung | 0:8ede47d38d10 | 1212 | break; |
phungductung | 0:8ede47d38d10 | 1213 | |
phungductung | 0:8ede47d38d10 | 1214 | default: |
phungductung | 0:8ede47d38d10 | 1215 | break; |
phungductung | 0:8ede47d38d10 | 1216 | } |
phungductung | 0:8ede47d38d10 | 1217 | |
phungductung | 0:8ede47d38d10 | 1218 | /* Enable the complementary PWM output */ |
phungductung | 0:8ede47d38d10 | 1219 | TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_ENABLE); |
phungductung | 0:8ede47d38d10 | 1220 | |
phungductung | 0:8ede47d38d10 | 1221 | /* Enable the Main Output */ |
phungductung | 0:8ede47d38d10 | 1222 | __HAL_TIM_MOE_ENABLE(htim); |
phungductung | 0:8ede47d38d10 | 1223 | |
phungductung | 0:8ede47d38d10 | 1224 | /* Enable the Peripheral */ |
phungductung | 0:8ede47d38d10 | 1225 | __HAL_TIM_ENABLE(htim); |
phungductung | 0:8ede47d38d10 | 1226 | |
phungductung | 0:8ede47d38d10 | 1227 | /* Return function status */ |
phungductung | 0:8ede47d38d10 | 1228 | return HAL_OK; |
phungductung | 0:8ede47d38d10 | 1229 | } |
phungductung | 0:8ede47d38d10 | 1230 | |
phungductung | 0:8ede47d38d10 | 1231 | /** |
phungductung | 0:8ede47d38d10 | 1232 | * @brief Stops the TIM PWM signal generation in DMA mode on the complementary |
phungductung | 0:8ede47d38d10 | 1233 | * output |
phungductung | 0:8ede47d38d10 | 1234 | * @param htim: pointer to a TIM_HandleTypeDef structure that contains |
phungductung | 0:8ede47d38d10 | 1235 | * the configuration information for TIM module. |
phungductung | 0:8ede47d38d10 | 1236 | * @param Channel: TIM Channel to be disabled. |
phungductung | 0:8ede47d38d10 | 1237 | * This parameter can be one of the following values: |
phungductung | 0:8ede47d38d10 | 1238 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
phungductung | 0:8ede47d38d10 | 1239 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
phungductung | 0:8ede47d38d10 | 1240 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
phungductung | 0:8ede47d38d10 | 1241 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
phungductung | 0:8ede47d38d10 | 1242 | * @retval HAL status |
phungductung | 0:8ede47d38d10 | 1243 | */ |
phungductung | 0:8ede47d38d10 | 1244 | HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel) |
phungductung | 0:8ede47d38d10 | 1245 | { |
phungductung | 0:8ede47d38d10 | 1246 | /* Check the parameters */ |
phungductung | 0:8ede47d38d10 | 1247 | assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel)); |
phungductung | 0:8ede47d38d10 | 1248 | |
phungductung | 0:8ede47d38d10 | 1249 | switch (Channel) |
phungductung | 0:8ede47d38d10 | 1250 | { |
phungductung | 0:8ede47d38d10 | 1251 | case TIM_CHANNEL_1: |
phungductung | 0:8ede47d38d10 | 1252 | { |
phungductung | 0:8ede47d38d10 | 1253 | /* Disable the TIM Capture/Compare 1 DMA request */ |
phungductung | 0:8ede47d38d10 | 1254 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1); |
phungductung | 0:8ede47d38d10 | 1255 | } |
phungductung | 0:8ede47d38d10 | 1256 | break; |
phungductung | 0:8ede47d38d10 | 1257 | |
phungductung | 0:8ede47d38d10 | 1258 | case TIM_CHANNEL_2: |
phungductung | 0:8ede47d38d10 | 1259 | { |
phungductung | 0:8ede47d38d10 | 1260 | /* Disable the TIM Capture/Compare 2 DMA request */ |
phungductung | 0:8ede47d38d10 | 1261 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2); |
phungductung | 0:8ede47d38d10 | 1262 | } |
phungductung | 0:8ede47d38d10 | 1263 | break; |
phungductung | 0:8ede47d38d10 | 1264 | |
phungductung | 0:8ede47d38d10 | 1265 | case TIM_CHANNEL_3: |
phungductung | 0:8ede47d38d10 | 1266 | { |
phungductung | 0:8ede47d38d10 | 1267 | /* Disable the TIM Capture/Compare 3 DMA request */ |
phungductung | 0:8ede47d38d10 | 1268 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC3); |
phungductung | 0:8ede47d38d10 | 1269 | } |
phungductung | 0:8ede47d38d10 | 1270 | break; |
phungductung | 0:8ede47d38d10 | 1271 | |
phungductung | 0:8ede47d38d10 | 1272 | case TIM_CHANNEL_4: |
phungductung | 0:8ede47d38d10 | 1273 | { |
phungductung | 0:8ede47d38d10 | 1274 | /* Disable the TIM Capture/Compare 4 DMA request */ |
phungductung | 0:8ede47d38d10 | 1275 | __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC4); |
phungductung | 0:8ede47d38d10 | 1276 | } |
phungductung | 0:8ede47d38d10 | 1277 | break; |
phungductung | 0:8ede47d38d10 | 1278 | |
phungductung | 0:8ede47d38d10 | 1279 | default: |
phungductung | 0:8ede47d38d10 | 1280 | break; |
phungductung | 0:8ede47d38d10 | 1281 | } |
phungductung | 0:8ede47d38d10 | 1282 | |
phungductung | 0:8ede47d38d10 | 1283 | /* Disable the complementary PWM output */ |
phungductung | 0:8ede47d38d10 | 1284 | TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_DISABLE); |
phungductung | 0:8ede47d38d10 | 1285 | |
phungductung | 0:8ede47d38d10 | 1286 | /* Disable the Main Output */ |
phungductung | 0:8ede47d38d10 | 1287 | __HAL_TIM_MOE_DISABLE(htim); |
phungductung | 0:8ede47d38d10 | 1288 | |
phungductung | 0:8ede47d38d10 | 1289 | /* Disable the Peripheral */ |
phungductung | 0:8ede47d38d10 | 1290 | __HAL_TIM_DISABLE(htim); |
phungductung | 0:8ede47d38d10 | 1291 | |
phungductung | 0:8ede47d38d10 | 1292 | /* Change the htim state */ |
phungductung | 0:8ede47d38d10 | 1293 | htim->State = HAL_TIM_STATE_READY; |
phungductung | 0:8ede47d38d10 | 1294 | |
phungductung | 0:8ede47d38d10 | 1295 | /* Return function status */ |
phungductung | 0:8ede47d38d10 | 1296 | return HAL_OK; |
phungductung | 0:8ede47d38d10 | 1297 | } |
phungductung | 0:8ede47d38d10 | 1298 | |
phungductung | 0:8ede47d38d10 | 1299 | /** |
phungductung | 0:8ede47d38d10 | 1300 | * @} |
phungductung | 0:8ede47d38d10 | 1301 | */ |
phungductung | 0:8ede47d38d10 | 1302 | |
phungductung | 0:8ede47d38d10 | 1303 | /** @defgroup TIMEx_Exported_Functions_Group4 Extended Timer Complementary One Pulse functions |
phungductung | 0:8ede47d38d10 | 1304 | * @brief Timer Complementary One Pulse functions |
phungductung | 0:8ede47d38d10 | 1305 | * |
phungductung | 0:8ede47d38d10 | 1306 | @verbatim |
phungductung | 0:8ede47d38d10 | 1307 | ============================================================================== |
phungductung | 0:8ede47d38d10 | 1308 | ##### Timer Complementary One Pulse functions ##### |
phungductung | 0:8ede47d38d10 | 1309 | ============================================================================== |
phungductung | 0:8ede47d38d10 | 1310 | [..] |
phungductung | 0:8ede47d38d10 | 1311 | This section provides functions allowing to: |
phungductung | 0:8ede47d38d10 | 1312 | (+) Start the Complementary One Pulse generation. |
phungductung | 0:8ede47d38d10 | 1313 | (+) Stop the Complementary One Pulse. |
phungductung | 0:8ede47d38d10 | 1314 | (+) Start the Complementary One Pulse and enable interrupts. |
phungductung | 0:8ede47d38d10 | 1315 | (+) Stop the Complementary One Pulse and disable interrupts. |
phungductung | 0:8ede47d38d10 | 1316 | |
phungductung | 0:8ede47d38d10 | 1317 | @endverbatim |
phungductung | 0:8ede47d38d10 | 1318 | * @{ |
phungductung | 0:8ede47d38d10 | 1319 | */ |
phungductung | 0:8ede47d38d10 | 1320 | |
phungductung | 0:8ede47d38d10 | 1321 | /** |
phungductung | 0:8ede47d38d10 | 1322 | * @brief Starts the TIM One Pulse signal generation on the complemetary |
phungductung | 0:8ede47d38d10 | 1323 | * output. |
phungductung | 0:8ede47d38d10 | 1324 | * @param htim: pointer to a TIM_HandleTypeDef structure that contains |
phungductung | 0:8ede47d38d10 | 1325 | * the configuration information for TIM module. |
phungductung | 0:8ede47d38d10 | 1326 | * @param OutputChannel: TIM Channel to be enabled. |
phungductung | 0:8ede47d38d10 | 1327 | * This parameter can be one of the following values: |
phungductung | 0:8ede47d38d10 | 1328 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
phungductung | 0:8ede47d38d10 | 1329 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
phungductung | 0:8ede47d38d10 | 1330 | * @retval HAL status |
phungductung | 0:8ede47d38d10 | 1331 | */ |
phungductung | 0:8ede47d38d10 | 1332 | HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Start(TIM_HandleTypeDef *htim, uint32_t OutputChannel) |
phungductung | 0:8ede47d38d10 | 1333 | { |
phungductung | 0:8ede47d38d10 | 1334 | /* Check the parameters */ |
phungductung | 0:8ede47d38d10 | 1335 | assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, OutputChannel)); |
phungductung | 0:8ede47d38d10 | 1336 | |
phungductung | 0:8ede47d38d10 | 1337 | /* Enable the complementary One Pulse output */ |
phungductung | 0:8ede47d38d10 | 1338 | TIM_CCxNChannelCmd(htim->Instance, OutputChannel, TIM_CCxN_ENABLE); |
phungductung | 0:8ede47d38d10 | 1339 | |
phungductung | 0:8ede47d38d10 | 1340 | /* Enable the Main Output */ |
phungductung | 0:8ede47d38d10 | 1341 | __HAL_TIM_MOE_ENABLE(htim); |
phungductung | 0:8ede47d38d10 | 1342 | |
phungductung | 0:8ede47d38d10 | 1343 | /* Return function status */ |
phungductung | 0:8ede47d38d10 | 1344 | return HAL_OK; |
phungductung | 0:8ede47d38d10 | 1345 | } |
phungductung | 0:8ede47d38d10 | 1346 | |
phungductung | 0:8ede47d38d10 | 1347 | /** |
phungductung | 0:8ede47d38d10 | 1348 | * @brief Stops the TIM One Pulse signal generation on the complementary |
phungductung | 0:8ede47d38d10 | 1349 | * output. |
phungductung | 0:8ede47d38d10 | 1350 | * @param htim: pointer to a TIM_HandleTypeDef structure that contains |
phungductung | 0:8ede47d38d10 | 1351 | * the configuration information for TIM module. |
phungductung | 0:8ede47d38d10 | 1352 | * @param OutputChannel: TIM Channel to be disabled. |
phungductung | 0:8ede47d38d10 | 1353 | * This parameter can be one of the following values: |
phungductung | 0:8ede47d38d10 | 1354 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
phungductung | 0:8ede47d38d10 | 1355 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
phungductung | 0:8ede47d38d10 | 1356 | * @retval HAL status |
phungductung | 0:8ede47d38d10 | 1357 | */ |
phungductung | 0:8ede47d38d10 | 1358 | HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Stop(TIM_HandleTypeDef *htim, uint32_t OutputChannel) |
phungductung | 0:8ede47d38d10 | 1359 | { |
phungductung | 0:8ede47d38d10 | 1360 | |
phungductung | 0:8ede47d38d10 | 1361 | /* Check the parameters */ |
phungductung | 0:8ede47d38d10 | 1362 | assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, OutputChannel)); |
phungductung | 0:8ede47d38d10 | 1363 | |
phungductung | 0:8ede47d38d10 | 1364 | /* Disable the complementary One Pulse output */ |
phungductung | 0:8ede47d38d10 | 1365 | TIM_CCxNChannelCmd(htim->Instance, OutputChannel, TIM_CCxN_DISABLE); |
phungductung | 0:8ede47d38d10 | 1366 | |
phungductung | 0:8ede47d38d10 | 1367 | /* Disable the Main Output */ |
phungductung | 0:8ede47d38d10 | 1368 | __HAL_TIM_MOE_DISABLE(htim); |
phungductung | 0:8ede47d38d10 | 1369 | |
phungductung | 0:8ede47d38d10 | 1370 | /* Disable the Peripheral */ |
phungductung | 0:8ede47d38d10 | 1371 | __HAL_TIM_DISABLE(htim); |
phungductung | 0:8ede47d38d10 | 1372 | |
phungductung | 0:8ede47d38d10 | 1373 | /* Return function status */ |
phungductung | 0:8ede47d38d10 | 1374 | return HAL_OK; |
phungductung | 0:8ede47d38d10 | 1375 | } |
phungductung | 0:8ede47d38d10 | 1376 | |
phungductung | 0:8ede47d38d10 | 1377 | /** |
phungductung | 0:8ede47d38d10 | 1378 | * @brief Starts the TIM One Pulse signal generation in interrupt mode on the |
phungductung | 0:8ede47d38d10 | 1379 | * complementary channel. |
phungductung | 0:8ede47d38d10 | 1380 | * @param htim: pointer to a TIM_HandleTypeDef structure that contains |
phungductung | 0:8ede47d38d10 | 1381 | * the configuration information for TIM module. |
phungductung | 0:8ede47d38d10 | 1382 | * @param OutputChannel: TIM Channel to be enabled. |
phungductung | 0:8ede47d38d10 | 1383 | * This parameter can be one of the following values: |
phungductung | 0:8ede47d38d10 | 1384 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
phungductung | 0:8ede47d38d10 | 1385 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
phungductung | 0:8ede47d38d10 | 1386 | * @retval HAL status |
phungductung | 0:8ede47d38d10 | 1387 | */ |
phungductung | 0:8ede47d38d10 | 1388 | HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Start_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel) |
phungductung | 0:8ede47d38d10 | 1389 | { |
phungductung | 0:8ede47d38d10 | 1390 | /* Check the parameters */ |
phungductung | 0:8ede47d38d10 | 1391 | assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, OutputChannel)); |
phungductung | 0:8ede47d38d10 | 1392 | |
phungductung | 0:8ede47d38d10 | 1393 | /* Enable the TIM Capture/Compare 1 interrupt */ |
phungductung | 0:8ede47d38d10 | 1394 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1); |
phungductung | 0:8ede47d38d10 | 1395 | |
phungductung | 0:8ede47d38d10 | 1396 | /* Enable the TIM Capture/Compare 2 interrupt */ |
phungductung | 0:8ede47d38d10 | 1397 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2); |
phungductung | 0:8ede47d38d10 | 1398 | |
phungductung | 0:8ede47d38d10 | 1399 | /* Enable the complementary One Pulse output */ |
phungductung | 0:8ede47d38d10 | 1400 | TIM_CCxNChannelCmd(htim->Instance, OutputChannel, TIM_CCxN_ENABLE); |
phungductung | 0:8ede47d38d10 | 1401 | |
phungductung | 0:8ede47d38d10 | 1402 | /* Enable the Main Output */ |
phungductung | 0:8ede47d38d10 | 1403 | __HAL_TIM_MOE_ENABLE(htim); |
phungductung | 0:8ede47d38d10 | 1404 | |
phungductung | 0:8ede47d38d10 | 1405 | /* Return function status */ |
phungductung | 0:8ede47d38d10 | 1406 | return HAL_OK; |
phungductung | 0:8ede47d38d10 | 1407 | } |
phungductung | 0:8ede47d38d10 | 1408 | |
phungductung | 0:8ede47d38d10 | 1409 | /** |
phungductung | 0:8ede47d38d10 | 1410 | * @brief Stops the TIM One Pulse signal generation in interrupt mode on the |
phungductung | 0:8ede47d38d10 | 1411 | * complementary channel. |
phungductung | 0:8ede47d38d10 | 1412 | * @param htim: pointer to a TIM_HandleTypeDef structure that contains |
phungductung | 0:8ede47d38d10 | 1413 | * the configuration information for TIM module. |
phungductung | 0:8ede47d38d10 | 1414 | * @param OutputChannel: TIM Channel to be disabled. |
phungductung | 0:8ede47d38d10 | 1415 | * This parameter can be one of the following values: |
phungductung | 0:8ede47d38d10 | 1416 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
phungductung | 0:8ede47d38d10 | 1417 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
phungductung | 0:8ede47d38d10 | 1418 | * @retval HAL status |
phungductung | 0:8ede47d38d10 | 1419 | */ |
phungductung | 0:8ede47d38d10 | 1420 | HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel) |
phungductung | 0:8ede47d38d10 | 1421 | { |
phungductung | 0:8ede47d38d10 | 1422 | /* Check the parameters */ |
phungductung | 0:8ede47d38d10 | 1423 | assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, OutputChannel)); |
phungductung | 0:8ede47d38d10 | 1424 | |
phungductung | 0:8ede47d38d10 | 1425 | /* Disable the TIM Capture/Compare 1 interrupt */ |
phungductung | 0:8ede47d38d10 | 1426 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1); |
phungductung | 0:8ede47d38d10 | 1427 | |
phungductung | 0:8ede47d38d10 | 1428 | /* Disable the TIM Capture/Compare 2 interrupt */ |
phungductung | 0:8ede47d38d10 | 1429 | __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2); |
phungductung | 0:8ede47d38d10 | 1430 | |
phungductung | 0:8ede47d38d10 | 1431 | /* Disable the complementary One Pulse output */ |
phungductung | 0:8ede47d38d10 | 1432 | TIM_CCxNChannelCmd(htim->Instance, OutputChannel, TIM_CCxN_DISABLE); |
phungductung | 0:8ede47d38d10 | 1433 | |
phungductung | 0:8ede47d38d10 | 1434 | /* Disable the Main Output */ |
phungductung | 0:8ede47d38d10 | 1435 | __HAL_TIM_MOE_DISABLE(htim); |
phungductung | 0:8ede47d38d10 | 1436 | |
phungductung | 0:8ede47d38d10 | 1437 | /* Disable the Peripheral */ |
phungductung | 0:8ede47d38d10 | 1438 | __HAL_TIM_DISABLE(htim); |
phungductung | 0:8ede47d38d10 | 1439 | |
phungductung | 0:8ede47d38d10 | 1440 | /* Return function status */ |
phungductung | 0:8ede47d38d10 | 1441 | return HAL_OK; |
phungductung | 0:8ede47d38d10 | 1442 | } |
phungductung | 0:8ede47d38d10 | 1443 | |
phungductung | 0:8ede47d38d10 | 1444 | /** |
phungductung | 0:8ede47d38d10 | 1445 | * @} |
phungductung | 0:8ede47d38d10 | 1446 | */ |
phungductung | 0:8ede47d38d10 | 1447 | |
phungductung | 0:8ede47d38d10 | 1448 | /** @defgroup TIMEx_Exported_Functions_Group5 Extended Peripheral Control functions |
phungductung | 0:8ede47d38d10 | 1449 | * @brief Peripheral Control functions |
phungductung | 0:8ede47d38d10 | 1450 | * |
phungductung | 0:8ede47d38d10 | 1451 | @verbatim |
phungductung | 0:8ede47d38d10 | 1452 | ============================================================================== |
phungductung | 0:8ede47d38d10 | 1453 | ##### Peripheral Control functions ##### |
phungductung | 0:8ede47d38d10 | 1454 | ============================================================================== |
phungductung | 0:8ede47d38d10 | 1455 | [..] |
phungductung | 0:8ede47d38d10 | 1456 | This section provides functions allowing to: |
phungductung | 0:8ede47d38d10 | 1457 | (+) Configure The Input Output channels for OC, PWM, IC or One Pulse mode. |
phungductung | 0:8ede47d38d10 | 1458 | (+) Configure External Clock source. |
phungductung | 0:8ede47d38d10 | 1459 | (+) Configure Complementary channels, break features and dead time. |
phungductung | 0:8ede47d38d10 | 1460 | (+) Configure Master and the Slave synchronization. |
phungductung | 0:8ede47d38d10 | 1461 | (+) Configure the commutation event in case of use of the Hall sensor interface. |
phungductung | 0:8ede47d38d10 | 1462 | (+) Configure the DMA Burst Mode. |
phungductung | 0:8ede47d38d10 | 1463 | |
phungductung | 0:8ede47d38d10 | 1464 | @endverbatim |
phungductung | 0:8ede47d38d10 | 1465 | * @{ |
phungductung | 0:8ede47d38d10 | 1466 | */ |
phungductung | 0:8ede47d38d10 | 1467 | /** |
phungductung | 0:8ede47d38d10 | 1468 | * @brief Configure the TIM commutation event sequence. |
phungductung | 0:8ede47d38d10 | 1469 | * @note This function is mandatory to use the commutation event in order to |
phungductung | 0:8ede47d38d10 | 1470 | * update the configuration at each commutation detection on the TRGI input of the Timer, |
phungductung | 0:8ede47d38d10 | 1471 | * the typical use of this feature is with the use of another Timer(interface Timer) |
phungductung | 0:8ede47d38d10 | 1472 | * configured in Hall sensor interface, this interface Timer will generate the |
phungductung | 0:8ede47d38d10 | 1473 | * commutation at its TRGO output (connected to Timer used in this function) each time |
phungductung | 0:8ede47d38d10 | 1474 | * the TI1 of the Interface Timer detect a commutation at its input TI1. |
phungductung | 0:8ede47d38d10 | 1475 | * @param htim: pointer to a TIM_HandleTypeDef structure that contains |
phungductung | 0:8ede47d38d10 | 1476 | * the configuration information for TIM module. |
phungductung | 0:8ede47d38d10 | 1477 | * @param InputTrigger: the Internal trigger corresponding to the Timer Interfacing with the Hall sensor. |
phungductung | 0:8ede47d38d10 | 1478 | * This parameter can be one of the following values: |
phungductung | 0:8ede47d38d10 | 1479 | * @arg TIM_TS_ITR0: Internal trigger 0 selected |
phungductung | 0:8ede47d38d10 | 1480 | * @arg TIM_TS_ITR1: Internal trigger 1 selected |
phungductung | 0:8ede47d38d10 | 1481 | * @arg TIM_TS_ITR2: Internal trigger 2 selected |
phungductung | 0:8ede47d38d10 | 1482 | * @arg TIM_TS_ITR3: Internal trigger 3 selected |
phungductung | 0:8ede47d38d10 | 1483 | * @arg TIM_TS_NONE: No trigger is needed |
phungductung | 0:8ede47d38d10 | 1484 | * @param CommutationSource: the Commutation Event source. |
phungductung | 0:8ede47d38d10 | 1485 | * This parameter can be one of the following values: |
phungductung | 0:8ede47d38d10 | 1486 | * @arg TIM_COMMUTATION_TRGI: Commutation source is the TRGI of the Interface Timer |
phungductung | 0:8ede47d38d10 | 1487 | * @arg TIM_COMMUTATION_SOFTWARE: Commutation source is set by software using the COMG bit |
phungductung | 0:8ede47d38d10 | 1488 | * @retval HAL status |
phungductung | 0:8ede47d38d10 | 1489 | */ |
phungductung | 0:8ede47d38d10 | 1490 | HAL_StatusTypeDef HAL_TIMEx_ConfigCommutationEvent(TIM_HandleTypeDef *htim, uint32_t InputTrigger, uint32_t CommutationSource) |
phungductung | 0:8ede47d38d10 | 1491 | { |
phungductung | 0:8ede47d38d10 | 1492 | /* Check the parameters */ |
phungductung | 0:8ede47d38d10 | 1493 | assert_param(IS_TIM_ADVANCED_INSTANCE(htim->Instance)); |
phungductung | 0:8ede47d38d10 | 1494 | assert_param(IS_TIM_INTERNAL_TRIGGEREVENT_SELECTION(InputTrigger)); |
phungductung | 0:8ede47d38d10 | 1495 | |
phungductung | 0:8ede47d38d10 | 1496 | __HAL_LOCK(htim); |
phungductung | 0:8ede47d38d10 | 1497 | |
phungductung | 0:8ede47d38d10 | 1498 | if ((InputTrigger == TIM_TS_ITR0) || (InputTrigger == TIM_TS_ITR1) || |
phungductung | 0:8ede47d38d10 | 1499 | (InputTrigger == TIM_TS_ITR2) || (InputTrigger == TIM_TS_ITR3)) |
phungductung | 0:8ede47d38d10 | 1500 | { |
phungductung | 0:8ede47d38d10 | 1501 | /* Select the Input trigger */ |
phungductung | 0:8ede47d38d10 | 1502 | htim->Instance->SMCR &= ~TIM_SMCR_TS; |
phungductung | 0:8ede47d38d10 | 1503 | htim->Instance->SMCR |= InputTrigger; |
phungductung | 0:8ede47d38d10 | 1504 | } |
phungductung | 0:8ede47d38d10 | 1505 | |
phungductung | 0:8ede47d38d10 | 1506 | /* Select the Capture Compare preload feature */ |
phungductung | 0:8ede47d38d10 | 1507 | htim->Instance->CR2 |= TIM_CR2_CCPC; |
phungductung | 0:8ede47d38d10 | 1508 | /* Select the Commutation event source */ |
phungductung | 0:8ede47d38d10 | 1509 | htim->Instance->CR2 &= ~TIM_CR2_CCUS; |
phungductung | 0:8ede47d38d10 | 1510 | htim->Instance->CR2 |= CommutationSource; |
phungductung | 0:8ede47d38d10 | 1511 | |
phungductung | 0:8ede47d38d10 | 1512 | __HAL_UNLOCK(htim); |
phungductung | 0:8ede47d38d10 | 1513 | |
phungductung | 0:8ede47d38d10 | 1514 | return HAL_OK; |
phungductung | 0:8ede47d38d10 | 1515 | } |
phungductung | 0:8ede47d38d10 | 1516 | |
phungductung | 0:8ede47d38d10 | 1517 | /** |
phungductung | 0:8ede47d38d10 | 1518 | * @brief Configure the TIM commutation event sequence with interrupt. |
phungductung | 0:8ede47d38d10 | 1519 | * @note This function is mandatory to use the commutation event in order to |
phungductung | 0:8ede47d38d10 | 1520 | * update the configuration at each commutation detection on the TRGI input of the Timer, |
phungductung | 0:8ede47d38d10 | 1521 | * the typical use of this feature is with the use of another Timer(interface Timer) |
phungductung | 0:8ede47d38d10 | 1522 | * configured in Hall sensor interface, this interface Timer will generate the |
phungductung | 0:8ede47d38d10 | 1523 | * commutation at its TRGO output (connected to Timer used in this function) each time |
phungductung | 0:8ede47d38d10 | 1524 | * the TI1 of the Interface Timer detect a commutation at its input TI1. |
phungductung | 0:8ede47d38d10 | 1525 | * @param htim: pointer to a TIM_HandleTypeDef structure that contains |
phungductung | 0:8ede47d38d10 | 1526 | * the configuration information for TIM module. |
phungductung | 0:8ede47d38d10 | 1527 | * @param InputTrigger: the Internal trigger corresponding to the Timer Interfacing with the Hall sensor. |
phungductung | 0:8ede47d38d10 | 1528 | * This parameter can be one of the following values: |
phungductung | 0:8ede47d38d10 | 1529 | * @arg TIM_TS_ITR0: Internal trigger 0 selected |
phungductung | 0:8ede47d38d10 | 1530 | * @arg TIM_TS_ITR1: Internal trigger 1 selected |
phungductung | 0:8ede47d38d10 | 1531 | * @arg TIM_TS_ITR2: Internal trigger 2 selected |
phungductung | 0:8ede47d38d10 | 1532 | * @arg TIM_TS_ITR3: Internal trigger 3 selected |
phungductung | 0:8ede47d38d10 | 1533 | * @arg TIM_TS_NONE: No trigger is needed |
phungductung | 0:8ede47d38d10 | 1534 | * @param CommutationSource: the Commutation Event source. |
phungductung | 0:8ede47d38d10 | 1535 | * This parameter can be one of the following values: |
phungductung | 0:8ede47d38d10 | 1536 | * @arg TIM_COMMUTATION_TRGI: Commutation source is the TRGI of the Interface Timer |
phungductung | 0:8ede47d38d10 | 1537 | * @arg TIM_COMMUTATION_SOFTWARE: Commutation source is set by software using the COMG bit |
phungductung | 0:8ede47d38d10 | 1538 | * @retval HAL status |
phungductung | 0:8ede47d38d10 | 1539 | */ |
phungductung | 0:8ede47d38d10 | 1540 | HAL_StatusTypeDef HAL_TIMEx_ConfigCommutationEvent_IT(TIM_HandleTypeDef *htim, uint32_t InputTrigger, uint32_t CommutationSource) |
phungductung | 0:8ede47d38d10 | 1541 | { |
phungductung | 0:8ede47d38d10 | 1542 | /* Check the parameters */ |
phungductung | 0:8ede47d38d10 | 1543 | assert_param(IS_TIM_ADVANCED_INSTANCE(htim->Instance)); |
phungductung | 0:8ede47d38d10 | 1544 | assert_param(IS_TIM_INTERNAL_TRIGGEREVENT_SELECTION(InputTrigger)); |
phungductung | 0:8ede47d38d10 | 1545 | |
phungductung | 0:8ede47d38d10 | 1546 | __HAL_LOCK(htim); |
phungductung | 0:8ede47d38d10 | 1547 | |
phungductung | 0:8ede47d38d10 | 1548 | if ((InputTrigger == TIM_TS_ITR0) || (InputTrigger == TIM_TS_ITR1) || |
phungductung | 0:8ede47d38d10 | 1549 | (InputTrigger == TIM_TS_ITR2) || (InputTrigger == TIM_TS_ITR3)) |
phungductung | 0:8ede47d38d10 | 1550 | { |
phungductung | 0:8ede47d38d10 | 1551 | /* Select the Input trigger */ |
phungductung | 0:8ede47d38d10 | 1552 | htim->Instance->SMCR &= ~TIM_SMCR_TS; |
phungductung | 0:8ede47d38d10 | 1553 | htim->Instance->SMCR |= InputTrigger; |
phungductung | 0:8ede47d38d10 | 1554 | } |
phungductung | 0:8ede47d38d10 | 1555 | |
phungductung | 0:8ede47d38d10 | 1556 | /* Select the Capture Compare preload feature */ |
phungductung | 0:8ede47d38d10 | 1557 | htim->Instance->CR2 |= TIM_CR2_CCPC; |
phungductung | 0:8ede47d38d10 | 1558 | /* Select the Commutation event source */ |
phungductung | 0:8ede47d38d10 | 1559 | htim->Instance->CR2 &= ~TIM_CR2_CCUS; |
phungductung | 0:8ede47d38d10 | 1560 | htim->Instance->CR2 |= CommutationSource; |
phungductung | 0:8ede47d38d10 | 1561 | |
phungductung | 0:8ede47d38d10 | 1562 | /* Enable the Commutation Interrupt Request */ |
phungductung | 0:8ede47d38d10 | 1563 | __HAL_TIM_ENABLE_IT(htim, TIM_IT_COM); |
phungductung | 0:8ede47d38d10 | 1564 | |
phungductung | 0:8ede47d38d10 | 1565 | __HAL_UNLOCK(htim); |
phungductung | 0:8ede47d38d10 | 1566 | |
phungductung | 0:8ede47d38d10 | 1567 | return HAL_OK; |
phungductung | 0:8ede47d38d10 | 1568 | } |
phungductung | 0:8ede47d38d10 | 1569 | |
phungductung | 0:8ede47d38d10 | 1570 | /** |
phungductung | 0:8ede47d38d10 | 1571 | * @brief Configure the TIM commutation event sequence with DMA. |
phungductung | 0:8ede47d38d10 | 1572 | * @note This function is mandatory to use the commutation event in order to |
phungductung | 0:8ede47d38d10 | 1573 | * update the configuration at each commutation detection on the TRGI input of the Timer, |
phungductung | 0:8ede47d38d10 | 1574 | * the typical use of this feature is with the use of another Timer(interface Timer) |
phungductung | 0:8ede47d38d10 | 1575 | * configured in Hall sensor interface, this interface Timer will generate the |
phungductung | 0:8ede47d38d10 | 1576 | * commutation at its TRGO output (connected to Timer used in this function) each time |
phungductung | 0:8ede47d38d10 | 1577 | * the TI1 of the Interface Timer detect a commutation at its input TI1. |
phungductung | 0:8ede47d38d10 | 1578 | * @note: The user should configure the DMA in his own software, in This function only the COMDE bit is set |
phungductung | 0:8ede47d38d10 | 1579 | * @param htim: pointer to a TIM_HandleTypeDef structure that contains |
phungductung | 0:8ede47d38d10 | 1580 | * the configuration information for TIM module. |
phungductung | 0:8ede47d38d10 | 1581 | * @param InputTrigger: the Internal trigger corresponding to the Timer Interfacing with the Hall sensor. |
phungductung | 0:8ede47d38d10 | 1582 | * This parameter can be one of the following values: |
phungductung | 0:8ede47d38d10 | 1583 | * @arg TIM_TS_ITR0: Internal trigger 0 selected |
phungductung | 0:8ede47d38d10 | 1584 | * @arg TIM_TS_ITR1: Internal trigger 1 selected |
phungductung | 0:8ede47d38d10 | 1585 | * @arg TIM_TS_ITR2: Internal trigger 2 selected |
phungductung | 0:8ede47d38d10 | 1586 | * @arg TIM_TS_ITR3: Internal trigger 3 selected |
phungductung | 0:8ede47d38d10 | 1587 | * @arg TIM_TS_NONE: No trigger is needed |
phungductung | 0:8ede47d38d10 | 1588 | * @param CommutationSource: the Commutation Event source. |
phungductung | 0:8ede47d38d10 | 1589 | * This parameter can be one of the following values: |
phungductung | 0:8ede47d38d10 | 1590 | * @arg TIM_COMMUTATION_TRGI: Commutation source is the TRGI of the Interface Timer |
phungductung | 0:8ede47d38d10 | 1591 | * @arg TIM_COMMUTATION_SOFTWARE: Commutation source is set by software using the COMG bit |
phungductung | 0:8ede47d38d10 | 1592 | * @retval HAL status |
phungductung | 0:8ede47d38d10 | 1593 | */ |
phungductung | 0:8ede47d38d10 | 1594 | HAL_StatusTypeDef HAL_TIMEx_ConfigCommutationEvent_DMA(TIM_HandleTypeDef *htim, uint32_t InputTrigger, uint32_t CommutationSource) |
phungductung | 0:8ede47d38d10 | 1595 | { |
phungductung | 0:8ede47d38d10 | 1596 | /* Check the parameters */ |
phungductung | 0:8ede47d38d10 | 1597 | assert_param(IS_TIM_ADVANCED_INSTANCE(htim->Instance)); |
phungductung | 0:8ede47d38d10 | 1598 | assert_param(IS_TIM_INTERNAL_TRIGGEREVENT_SELECTION(InputTrigger)); |
phungductung | 0:8ede47d38d10 | 1599 | |
phungductung | 0:8ede47d38d10 | 1600 | __HAL_LOCK(htim); |
phungductung | 0:8ede47d38d10 | 1601 | |
phungductung | 0:8ede47d38d10 | 1602 | if ((InputTrigger == TIM_TS_ITR0) || (InputTrigger == TIM_TS_ITR1) || |
phungductung | 0:8ede47d38d10 | 1603 | (InputTrigger == TIM_TS_ITR2) || (InputTrigger == TIM_TS_ITR3)) |
phungductung | 0:8ede47d38d10 | 1604 | { |
phungductung | 0:8ede47d38d10 | 1605 | /* Select the Input trigger */ |
phungductung | 0:8ede47d38d10 | 1606 | htim->Instance->SMCR &= ~TIM_SMCR_TS; |
phungductung | 0:8ede47d38d10 | 1607 | htim->Instance->SMCR |= InputTrigger; |
phungductung | 0:8ede47d38d10 | 1608 | } |
phungductung | 0:8ede47d38d10 | 1609 | |
phungductung | 0:8ede47d38d10 | 1610 | /* Select the Capture Compare preload feature */ |
phungductung | 0:8ede47d38d10 | 1611 | htim->Instance->CR2 |= TIM_CR2_CCPC; |
phungductung | 0:8ede47d38d10 | 1612 | /* Select the Commutation event source */ |
phungductung | 0:8ede47d38d10 | 1613 | htim->Instance->CR2 &= ~TIM_CR2_CCUS; |
phungductung | 0:8ede47d38d10 | 1614 | htim->Instance->CR2 |= CommutationSource; |
phungductung | 0:8ede47d38d10 | 1615 | |
phungductung | 0:8ede47d38d10 | 1616 | /* Enable the Commutation DMA Request */ |
phungductung | 0:8ede47d38d10 | 1617 | /* Set the DMA Commutation Callback */ |
phungductung | 0:8ede47d38d10 | 1618 | htim->hdma[TIM_DMA_ID_COMMUTATION]->XferCpltCallback = HAL_TIMEx_DMACommutationCplt; |
phungductung | 0:8ede47d38d10 | 1619 | /* Set the DMA error callback */ |
phungductung | 0:8ede47d38d10 | 1620 | htim->hdma[TIM_DMA_ID_COMMUTATION]->XferErrorCallback = HAL_TIM_DMAError; |
phungductung | 0:8ede47d38d10 | 1621 | |
phungductung | 0:8ede47d38d10 | 1622 | /* Enable the Commutation DMA Request */ |
phungductung | 0:8ede47d38d10 | 1623 | __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_COM); |
phungductung | 0:8ede47d38d10 | 1624 | |
phungductung | 0:8ede47d38d10 | 1625 | __HAL_UNLOCK(htim); |
phungductung | 0:8ede47d38d10 | 1626 | |
phungductung | 0:8ede47d38d10 | 1627 | return HAL_OK; |
phungductung | 0:8ede47d38d10 | 1628 | } |
phungductung | 0:8ede47d38d10 | 1629 | |
phungductung | 0:8ede47d38d10 | 1630 | /** |
phungductung | 0:8ede47d38d10 | 1631 | * @brief Initializes the TIM Output Compare Channels according to the specified |
phungductung | 0:8ede47d38d10 | 1632 | * parameters in the TIM_OC_InitTypeDef. |
phungductung | 0:8ede47d38d10 | 1633 | * @param htim: TIM Output Compare handle |
phungductung | 0:8ede47d38d10 | 1634 | * @param sConfig: TIM Output Compare configuration structure |
phungductung | 0:8ede47d38d10 | 1635 | * @param Channel : TIM Channels to configure |
phungductung | 0:8ede47d38d10 | 1636 | * This parameter can be one of the following values: |
phungductung | 0:8ede47d38d10 | 1637 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
phungductung | 0:8ede47d38d10 | 1638 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
phungductung | 0:8ede47d38d10 | 1639 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
phungductung | 0:8ede47d38d10 | 1640 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
phungductung | 0:8ede47d38d10 | 1641 | * @arg TIM_CHANNEL_5: TIM Channel 5 selected |
phungductung | 0:8ede47d38d10 | 1642 | * @arg TIM_CHANNEL_6: TIM Channel 6 selected |
phungductung | 0:8ede47d38d10 | 1643 | * @arg TIM_CHANNEL_ALL: all output channels supported by the timer instance selected |
phungductung | 0:8ede47d38d10 | 1644 | * @retval HAL status |
phungductung | 0:8ede47d38d10 | 1645 | */ |
phungductung | 0:8ede47d38d10 | 1646 | HAL_StatusTypeDef HAL_TIM_OC_ConfigChannel(TIM_HandleTypeDef *htim, TIM_OC_InitTypeDef* sConfig, uint32_t Channel) |
phungductung | 0:8ede47d38d10 | 1647 | { |
phungductung | 0:8ede47d38d10 | 1648 | /* Check the parameters */ |
phungductung | 0:8ede47d38d10 | 1649 | assert_param(IS_TIM_CHANNELS(Channel)); |
phungductung | 0:8ede47d38d10 | 1650 | assert_param(IS_TIM_OC_MODE(sConfig->OCMode)); |
phungductung | 0:8ede47d38d10 | 1651 | assert_param(IS_TIM_OC_POLARITY(sConfig->OCPolarity)); |
phungductung | 0:8ede47d38d10 | 1652 | |
phungductung | 0:8ede47d38d10 | 1653 | /* Check input state */ |
phungductung | 0:8ede47d38d10 | 1654 | __HAL_LOCK(htim); |
phungductung | 0:8ede47d38d10 | 1655 | |
phungductung | 0:8ede47d38d10 | 1656 | htim->State = HAL_TIM_STATE_BUSY; |
phungductung | 0:8ede47d38d10 | 1657 | |
phungductung | 0:8ede47d38d10 | 1658 | switch (Channel) |
phungductung | 0:8ede47d38d10 | 1659 | { |
phungductung | 0:8ede47d38d10 | 1660 | case TIM_CHANNEL_1: |
phungductung | 0:8ede47d38d10 | 1661 | { |
phungductung | 0:8ede47d38d10 | 1662 | /* Check the parameters */ |
phungductung | 0:8ede47d38d10 | 1663 | assert_param(IS_TIM_CC1_INSTANCE(htim->Instance)); |
phungductung | 0:8ede47d38d10 | 1664 | |
phungductung | 0:8ede47d38d10 | 1665 | /* Configure the TIM Channel 1 in Output Compare */ |
phungductung | 0:8ede47d38d10 | 1666 | TIM_OC1_SetConfig(htim->Instance, sConfig); |
phungductung | 0:8ede47d38d10 | 1667 | } |
phungductung | 0:8ede47d38d10 | 1668 | break; |
phungductung | 0:8ede47d38d10 | 1669 | |
phungductung | 0:8ede47d38d10 | 1670 | case TIM_CHANNEL_2: |
phungductung | 0:8ede47d38d10 | 1671 | { |
phungductung | 0:8ede47d38d10 | 1672 | /* Check the parameters */ |
phungductung | 0:8ede47d38d10 | 1673 | assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); |
phungductung | 0:8ede47d38d10 | 1674 | |
phungductung | 0:8ede47d38d10 | 1675 | /* Configure the TIM Channel 2 in Output Compare */ |
phungductung | 0:8ede47d38d10 | 1676 | TIM_OC2_SetConfig(htim->Instance, sConfig); |
phungductung | 0:8ede47d38d10 | 1677 | } |
phungductung | 0:8ede47d38d10 | 1678 | break; |
phungductung | 0:8ede47d38d10 | 1679 | |
phungductung | 0:8ede47d38d10 | 1680 | case TIM_CHANNEL_3: |
phungductung | 0:8ede47d38d10 | 1681 | { |
phungductung | 0:8ede47d38d10 | 1682 | /* Check the parameters */ |
phungductung | 0:8ede47d38d10 | 1683 | assert_param(IS_TIM_CC3_INSTANCE(htim->Instance)); |
phungductung | 0:8ede47d38d10 | 1684 | |
phungductung | 0:8ede47d38d10 | 1685 | /* Configure the TIM Channel 3 in Output Compare */ |
phungductung | 0:8ede47d38d10 | 1686 | TIM_OC3_SetConfig(htim->Instance, sConfig); |
phungductung | 0:8ede47d38d10 | 1687 | } |
phungductung | 0:8ede47d38d10 | 1688 | break; |
phungductung | 0:8ede47d38d10 | 1689 | |
phungductung | 0:8ede47d38d10 | 1690 | case TIM_CHANNEL_4: |
phungductung | 0:8ede47d38d10 | 1691 | { |
phungductung | 0:8ede47d38d10 | 1692 | /* Check the parameters */ |
phungductung | 0:8ede47d38d10 | 1693 | assert_param(IS_TIM_CC4_INSTANCE(htim->Instance)); |
phungductung | 0:8ede47d38d10 | 1694 | |
phungductung | 0:8ede47d38d10 | 1695 | /* Configure the TIM Channel 4 in Output Compare */ |
phungductung | 0:8ede47d38d10 | 1696 | TIM_OC4_SetConfig(htim->Instance, sConfig); |
phungductung | 0:8ede47d38d10 | 1697 | } |
phungductung | 0:8ede47d38d10 | 1698 | break; |
phungductung | 0:8ede47d38d10 | 1699 | |
phungductung | 0:8ede47d38d10 | 1700 | case TIM_CHANNEL_5: |
phungductung | 0:8ede47d38d10 | 1701 | { |
phungductung | 0:8ede47d38d10 | 1702 | /* Check the parameters */ |
phungductung | 0:8ede47d38d10 | 1703 | assert_param(IS_TIM_CC5_INSTANCE(htim->Instance)); |
phungductung | 0:8ede47d38d10 | 1704 | |
phungductung | 0:8ede47d38d10 | 1705 | /* Configure the TIM Channel 5 in Output Compare */ |
phungductung | 0:8ede47d38d10 | 1706 | TIM_OC5_SetConfig(htim->Instance, sConfig); |
phungductung | 0:8ede47d38d10 | 1707 | } |
phungductung | 0:8ede47d38d10 | 1708 | break; |
phungductung | 0:8ede47d38d10 | 1709 | |
phungductung | 0:8ede47d38d10 | 1710 | case TIM_CHANNEL_6: |
phungductung | 0:8ede47d38d10 | 1711 | { |
phungductung | 0:8ede47d38d10 | 1712 | /* Check the parameters */ |
phungductung | 0:8ede47d38d10 | 1713 | assert_param(IS_TIM_CC6_INSTANCE(htim->Instance)); |
phungductung | 0:8ede47d38d10 | 1714 | |
phungductung | 0:8ede47d38d10 | 1715 | /* Configure the TIM Channel 6 in Output Compare */ |
phungductung | 0:8ede47d38d10 | 1716 | TIM_OC6_SetConfig(htim->Instance, sConfig); |
phungductung | 0:8ede47d38d10 | 1717 | } |
phungductung | 0:8ede47d38d10 | 1718 | break; |
phungductung | 0:8ede47d38d10 | 1719 | |
phungductung | 0:8ede47d38d10 | 1720 | default: |
phungductung | 0:8ede47d38d10 | 1721 | break; |
phungductung | 0:8ede47d38d10 | 1722 | } |
phungductung | 0:8ede47d38d10 | 1723 | |
phungductung | 0:8ede47d38d10 | 1724 | htim->State = HAL_TIM_STATE_READY; |
phungductung | 0:8ede47d38d10 | 1725 | |
phungductung | 0:8ede47d38d10 | 1726 | __HAL_UNLOCK(htim); |
phungductung | 0:8ede47d38d10 | 1727 | |
phungductung | 0:8ede47d38d10 | 1728 | return HAL_OK; |
phungductung | 0:8ede47d38d10 | 1729 | } |
phungductung | 0:8ede47d38d10 | 1730 | |
phungductung | 0:8ede47d38d10 | 1731 | /** |
phungductung | 0:8ede47d38d10 | 1732 | * @brief Initializes the TIM PWM channels according to the specified |
phungductung | 0:8ede47d38d10 | 1733 | * parameters in the TIM_OC_InitTypeDef. |
phungductung | 0:8ede47d38d10 | 1734 | * @param htim: TIM PWM handle |
phungductung | 0:8ede47d38d10 | 1735 | * @param sConfig: TIM PWM configuration structure |
phungductung | 0:8ede47d38d10 | 1736 | * @param Channel : TIM Channels to be configured |
phungductung | 0:8ede47d38d10 | 1737 | * This parameter can be one of the following values: |
phungductung | 0:8ede47d38d10 | 1738 | * @arg TIM_CHANNEL_1: TIM Channel 1 selected |
phungductung | 0:8ede47d38d10 | 1739 | * @arg TIM_CHANNEL_2: TIM Channel 2 selected |
phungductung | 0:8ede47d38d10 | 1740 | * @arg TIM_CHANNEL_3: TIM Channel 3 selected |
phungductung | 0:8ede47d38d10 | 1741 | * @arg TIM_CHANNEL_4: TIM Channel 4 selected |
phungductung | 0:8ede47d38d10 | 1742 | * @arg TIM_CHANNEL_5: TIM Channel 5 selected |
phungductung | 0:8ede47d38d10 | 1743 | * @arg TIM_CHANNEL_6: TIM Channel 6 selected |
phungductung | 0:8ede47d38d10 | 1744 | * @arg TIM_CHANNEL_ALL: all PWM channels supported by the timer instance selected |
phungductung | 0:8ede47d38d10 | 1745 | * @retval HAL status |
phungductung | 0:8ede47d38d10 | 1746 | */ |
phungductung | 0:8ede47d38d10 | 1747 | HAL_StatusTypeDef HAL_TIM_PWM_ConfigChannel(TIM_HandleTypeDef *htim, |
phungductung | 0:8ede47d38d10 | 1748 | TIM_OC_InitTypeDef* sConfig, |
phungductung | 0:8ede47d38d10 | 1749 | uint32_t Channel) |
phungductung | 0:8ede47d38d10 | 1750 | { |
phungductung | 0:8ede47d38d10 | 1751 | /* Check the parameters */ |
phungductung | 0:8ede47d38d10 | 1752 | assert_param(IS_TIM_CHANNELS(Channel)); |
phungductung | 0:8ede47d38d10 | 1753 | assert_param(IS_TIM_PWM_MODE(sConfig->OCMode)); |
phungductung | 0:8ede47d38d10 | 1754 | assert_param(IS_TIM_OC_POLARITY(sConfig->OCPolarity)); |
phungductung | 0:8ede47d38d10 | 1755 | assert_param(IS_TIM_FAST_STATE(sConfig->OCFastMode)); |
phungductung | 0:8ede47d38d10 | 1756 | |
phungductung | 0:8ede47d38d10 | 1757 | /* Check input state */ |
phungductung | 0:8ede47d38d10 | 1758 | __HAL_LOCK(htim); |
phungductung | 0:8ede47d38d10 | 1759 | |
phungductung | 0:8ede47d38d10 | 1760 | htim->State = HAL_TIM_STATE_BUSY; |
phungductung | 0:8ede47d38d10 | 1761 | |
phungductung | 0:8ede47d38d10 | 1762 | switch (Channel) |
phungductung | 0:8ede47d38d10 | 1763 | { |
phungductung | 0:8ede47d38d10 | 1764 | case TIM_CHANNEL_1: |
phungductung | 0:8ede47d38d10 | 1765 | { |
phungductung | 0:8ede47d38d10 | 1766 | /* Check the parameters */ |
phungductung | 0:8ede47d38d10 | 1767 | assert_param(IS_TIM_CC1_INSTANCE(htim->Instance)); |
phungductung | 0:8ede47d38d10 | 1768 | |
phungductung | 0:8ede47d38d10 | 1769 | /* Configure the Channel 1 in PWM mode */ |
phungductung | 0:8ede47d38d10 | 1770 | TIM_OC1_SetConfig(htim->Instance, sConfig); |
phungductung | 0:8ede47d38d10 | 1771 | |
phungductung | 0:8ede47d38d10 | 1772 | /* Set the Preload enable bit for channel1 */ |
phungductung | 0:8ede47d38d10 | 1773 | htim->Instance->CCMR1 |= TIM_CCMR1_OC1PE; |
phungductung | 0:8ede47d38d10 | 1774 | |
phungductung | 0:8ede47d38d10 | 1775 | /* Configure the Output Fast mode */ |
phungductung | 0:8ede47d38d10 | 1776 | htim->Instance->CCMR1 &= ~TIM_CCMR1_OC1FE; |
phungductung | 0:8ede47d38d10 | 1777 | htim->Instance->CCMR1 |= sConfig->OCFastMode; |
phungductung | 0:8ede47d38d10 | 1778 | } |
phungductung | 0:8ede47d38d10 | 1779 | break; |
phungductung | 0:8ede47d38d10 | 1780 | |
phungductung | 0:8ede47d38d10 | 1781 | case TIM_CHANNEL_2: |
phungductung | 0:8ede47d38d10 | 1782 | { |
phungductung | 0:8ede47d38d10 | 1783 | /* Check the parameters */ |
phungductung | 0:8ede47d38d10 | 1784 | assert_param(IS_TIM_CC2_INSTANCE(htim->Instance)); |
phungductung | 0:8ede47d38d10 | 1785 | |
phungductung | 0:8ede47d38d10 | 1786 | /* Configure the Channel 2 in PWM mode */ |
phungductung | 0:8ede47d38d10 | 1787 | TIM_OC2_SetConfig(htim->Instance, sConfig); |
phungductung | 0:8ede47d38d10 | 1788 | |
phungductung | 0:8ede47d38d10 | 1789 | /* Set the Preload enable bit for channel2 */ |
phungductung | 0:8ede47d38d10 | 1790 | htim->Instance->CCMR1 |= TIM_CCMR1_OC2PE; |
phungductung | 0:8ede47d38d10 | 1791 | |
phungductung | 0:8ede47d38d10 | 1792 | /* Configure the Output Fast mode */ |
phungductung | 0:8ede47d38d10 | 1793 | htim->Instance->CCMR1 &= ~TIM_CCMR1_OC2FE; |
phungductung | 0:8ede47d38d10 | 1794 | htim->Instance->CCMR1 |= sConfig->OCFastMode << 8; |
phungductung | 0:8ede47d38d10 | 1795 | } |
phungductung | 0:8ede47d38d10 | 1796 | break; |
phungductung | 0:8ede47d38d10 | 1797 | |
phungductung | 0:8ede47d38d10 | 1798 | case TIM_CHANNEL_3: |
phungductung | 0:8ede47d38d10 | 1799 | { |
phungductung | 0:8ede47d38d10 | 1800 | /* Check the parameters */ |
phungductung | 0:8ede47d38d10 | 1801 | assert_param(IS_TIM_CC3_INSTANCE(htim->Instance)); |
phungductung | 0:8ede47d38d10 | 1802 | |
phungductung | 0:8ede47d38d10 | 1803 | /* Configure the Channel 3 in PWM mode */ |
phungductung | 0:8ede47d38d10 | 1804 | TIM_OC3_SetConfig(htim->Instance, sConfig); |
phungductung | 0:8ede47d38d10 | 1805 | |
phungductung | 0:8ede47d38d10 | 1806 | /* Set the Preload enable bit for channel3 */ |
phungductung | 0:8ede47d38d10 | 1807 | htim->Instance->CCMR2 |= TIM_CCMR2_OC3PE; |
phungductung | 0:8ede47d38d10 | 1808 | |
phungductung | 0:8ede47d38d10 | 1809 | /* Configure the Output Fast mode */ |
phungductung | 0:8ede47d38d10 | 1810 | htim->Instance->CCMR2 &= ~TIM_CCMR2_OC3FE; |
phungductung | 0:8ede47d38d10 | 1811 | htim->Instance->CCMR2 |= sConfig->OCFastMode; |
phungductung | 0:8ede47d38d10 | 1812 | } |
phungductung | 0:8ede47d38d10 | 1813 | break; |
phungductung | 0:8ede47d38d10 | 1814 | |
phungductung | 0:8ede47d38d10 | 1815 | case TIM_CHANNEL_4: |
phungductung | 0:8ede47d38d10 | 1816 | { |
phungductung | 0:8ede47d38d10 | 1817 | /* Check the parameters */ |
phungductung | 0:8ede47d38d10 | 1818 | assert_param(IS_TIM_CC4_INSTANCE(htim->Instance)); |
phungductung | 0:8ede47d38d10 | 1819 | |
phungductung | 0:8ede47d38d10 | 1820 | /* Configure the Channel 4 in PWM mode */ |
phungductung | 0:8ede47d38d10 | 1821 | TIM_OC4_SetConfig(htim->Instance, sConfig); |
phungductung | 0:8ede47d38d10 | 1822 | |
phungductung | 0:8ede47d38d10 | 1823 | /* Set the Preload enable bit for channel4 */ |
phungductung | 0:8ede47d38d10 | 1824 | htim->Instance->CCMR2 |= TIM_CCMR2_OC4PE; |
phungductung | 0:8ede47d38d10 | 1825 | |
phungductung | 0:8ede47d38d10 | 1826 | /* Configure the Output Fast mode */ |
phungductung | 0:8ede47d38d10 | 1827 | htim->Instance->CCMR2 &= ~TIM_CCMR2_OC4FE; |
phungductung | 0:8ede47d38d10 | 1828 | htim->Instance->CCMR2 |= sConfig->OCFastMode << 8; |
phungductung | 0:8ede47d38d10 | 1829 | } |
phungductung | 0:8ede47d38d10 | 1830 | break; |
phungductung | 0:8ede47d38d10 | 1831 | |
phungductung | 0:8ede47d38d10 | 1832 | case TIM_CHANNEL_5: |
phungductung | 0:8ede47d38d10 | 1833 | { |
phungductung | 0:8ede47d38d10 | 1834 | /* Check the parameters */ |
phungductung | 0:8ede47d38d10 | 1835 | assert_param(IS_TIM_CC5_INSTANCE(htim->Instance)); |
phungductung | 0:8ede47d38d10 | 1836 | |
phungductung | 0:8ede47d38d10 | 1837 | /* Configure the Channel 5 in PWM mode */ |
phungductung | 0:8ede47d38d10 | 1838 | TIM_OC5_SetConfig(htim->Instance, sConfig); |
phungductung | 0:8ede47d38d10 | 1839 | |
phungductung | 0:8ede47d38d10 | 1840 | /* Set the Preload enable bit for channel5*/ |
phungductung | 0:8ede47d38d10 | 1841 | htim->Instance->CCMR3 |= TIM_CCMR3_OC5PE; |
phungductung | 0:8ede47d38d10 | 1842 | |
phungductung | 0:8ede47d38d10 | 1843 | /* Configure the Output Fast mode */ |
phungductung | 0:8ede47d38d10 | 1844 | htim->Instance->CCMR3 &= ~TIM_CCMR3_OC5FE; |
phungductung | 0:8ede47d38d10 | 1845 | htim->Instance->CCMR3 |= sConfig->OCFastMode; |
phungductung | 0:8ede47d38d10 | 1846 | } |
phungductung | 0:8ede47d38d10 | 1847 | break; |
phungductung | 0:8ede47d38d10 | 1848 | |
phungductung | 0:8ede47d38d10 | 1849 | case TIM_CHANNEL_6: |
phungductung | 0:8ede47d38d10 | 1850 | { |
phungductung | 0:8ede47d38d10 | 1851 | /* Check the parameters */ |
phungductung | 0:8ede47d38d10 | 1852 | assert_param(IS_TIM_CC6_INSTANCE(htim->Instance)); |
phungductung | 0:8ede47d38d10 | 1853 | |
phungductung | 0:8ede47d38d10 | 1854 | /* Configure the Channel 5 in PWM mode */ |
phungductung | 0:8ede47d38d10 | 1855 | TIM_OC6_SetConfig(htim->Instance, sConfig); |
phungductung | 0:8ede47d38d10 | 1856 | |
phungductung | 0:8ede47d38d10 | 1857 | /* Set the Preload enable bit for channel6 */ |
phungductung | 0:8ede47d38d10 | 1858 | htim->Instance->CCMR3 |= TIM_CCMR3_OC6PE; |
phungductung | 0:8ede47d38d10 | 1859 | |
phungductung | 0:8ede47d38d10 | 1860 | /* Configure the Output Fast mode */ |
phungductung | 0:8ede47d38d10 | 1861 | htim->Instance->CCMR3 &= ~TIM_CCMR3_OC6FE; |
phungductung | 0:8ede47d38d10 | 1862 | htim->Instance->CCMR3 |= sConfig->OCFastMode << 8; |
phungductung | 0:8ede47d38d10 | 1863 | } |
phungductung | 0:8ede47d38d10 | 1864 | break; |
phungductung | 0:8ede47d38d10 | 1865 | |
phungductung | 0:8ede47d38d10 | 1866 | default: |
phungductung | 0:8ede47d38d10 | 1867 | break; |
phungductung | 0:8ede47d38d10 | 1868 | } |
phungductung | 0:8ede47d38d10 | 1869 | |
phungductung | 0:8ede47d38d10 | 1870 | htim->State = HAL_TIM_STATE_READY; |
phungductung | 0:8ede47d38d10 | 1871 | |
phungductung | 0:8ede47d38d10 | 1872 | __HAL_UNLOCK(htim); |
phungductung | 0:8ede47d38d10 | 1873 | |
phungductung | 0:8ede47d38d10 | 1874 | return HAL_OK; |
phungductung | 0:8ede47d38d10 | 1875 | } |
phungductung | 0:8ede47d38d10 | 1876 | |
phungductung | 0:8ede47d38d10 | 1877 | /** |
phungductung | 0:8ede47d38d10 | 1878 | * @brief Configures the OCRef clear feature |
phungductung | 0:8ede47d38d10 | 1879 | * @param htim: TIM handle |
phungductung | 0:8ede47d38d10 | 1880 | * @param sClearInputConfig: pointer to a TIM_ClearInputConfigTypeDef structure that |
phungductung | 0:8ede47d38d10 | 1881 | * contains the OCREF clear feature and parameters for the TIM peripheral. |
phungductung | 0:8ede47d38d10 | 1882 | * @param Channel: specifies the TIM Channel |
phungductung | 0:8ede47d38d10 | 1883 | * This parameter can be one of the following values: |
phungductung | 0:8ede47d38d10 | 1884 | * @arg TIM_Channel_1: TIM Channel 1 |
phungductung | 0:8ede47d38d10 | 1885 | * @arg TIM_Channel_2: TIM Channel 2 |
phungductung | 0:8ede47d38d10 | 1886 | * @arg TIM_Channel_3: TIM Channel 3 |
phungductung | 0:8ede47d38d10 | 1887 | * @arg TIM_Channel_4: TIM Channel 4 |
phungductung | 0:8ede47d38d10 | 1888 | * @arg TIM_Channel_5: TIM Channel 5 |
phungductung | 0:8ede47d38d10 | 1889 | * @arg TIM_Channel_6: TIM Channel 6 |
phungductung | 0:8ede47d38d10 | 1890 | * @retval None |
phungductung | 0:8ede47d38d10 | 1891 | */ |
phungductung | 0:8ede47d38d10 | 1892 | HAL_StatusTypeDef HAL_TIM_ConfigOCrefClear(TIM_HandleTypeDef *htim, |
phungductung | 0:8ede47d38d10 | 1893 | TIM_ClearInputConfigTypeDef *sClearInputConfig, |
phungductung | 0:8ede47d38d10 | 1894 | uint32_t Channel) |
phungductung | 0:8ede47d38d10 | 1895 | { |
phungductung | 0:8ede47d38d10 | 1896 | uint32_t tmpsmcr = 0; |
phungductung | 0:8ede47d38d10 | 1897 | |
phungductung | 0:8ede47d38d10 | 1898 | /* Check the parameters */ |
phungductung | 0:8ede47d38d10 | 1899 | assert_param(IS_TIM_OCXREF_CLEAR_INSTANCE(htim->Instance)); |
phungductung | 0:8ede47d38d10 | 1900 | assert_param(IS_TIM_CLEARINPUT_SOURCE(sClearInputConfig->ClearInputSource)); |
phungductung | 0:8ede47d38d10 | 1901 | |
phungductung | 0:8ede47d38d10 | 1902 | /* Check input state */ |
phungductung | 0:8ede47d38d10 | 1903 | __HAL_LOCK(htim); |
phungductung | 0:8ede47d38d10 | 1904 | |
phungductung | 0:8ede47d38d10 | 1905 | switch (sClearInputConfig->ClearInputSource) |
phungductung | 0:8ede47d38d10 | 1906 | { |
phungductung | 0:8ede47d38d10 | 1907 | case TIM_CLEARINPUTSOURCE_NONE: |
phungductung | 0:8ede47d38d10 | 1908 | { |
phungductung | 0:8ede47d38d10 | 1909 | /* Clear the OCREF clear selection bit */ |
phungductung | 0:8ede47d38d10 | 1910 | tmpsmcr &= ~TIM_SMCR_OCCS; |
phungductung | 0:8ede47d38d10 | 1911 | |
phungductung | 0:8ede47d38d10 | 1912 | /* Clear the ETR Bits */ |
phungductung | 0:8ede47d38d10 | 1913 | tmpsmcr &= ~(TIM_SMCR_ETF | TIM_SMCR_ETPS | TIM_SMCR_ECE | TIM_SMCR_ETP); |
phungductung | 0:8ede47d38d10 | 1914 | |
phungductung | 0:8ede47d38d10 | 1915 | /* Set TIMx_SMCR */ |
phungductung | 0:8ede47d38d10 | 1916 | htim->Instance->SMCR = tmpsmcr; |
phungductung | 0:8ede47d38d10 | 1917 | } |
phungductung | 0:8ede47d38d10 | 1918 | break; |
phungductung | 0:8ede47d38d10 | 1919 | |
phungductung | 0:8ede47d38d10 | 1920 | case TIM_CLEARINPUTSOURCE_OCREFCLR: |
phungductung | 0:8ede47d38d10 | 1921 | { |
phungductung | 0:8ede47d38d10 | 1922 | /* Clear the OCREF clear selection bit */ |
phungductung | 0:8ede47d38d10 | 1923 | htim->Instance->SMCR &= ~TIM_SMCR_OCCS; |
phungductung | 0:8ede47d38d10 | 1924 | } |
phungductung | 0:8ede47d38d10 | 1925 | break; |
phungductung | 0:8ede47d38d10 | 1926 | |
phungductung | 0:8ede47d38d10 | 1927 | case TIM_CLEARINPUTSOURCE_ETR: |
phungductung | 0:8ede47d38d10 | 1928 | { |
phungductung | 0:8ede47d38d10 | 1929 | /* Check the parameters */ |
phungductung | 0:8ede47d38d10 | 1930 | assert_param(IS_TIM_CLEARINPUT_POLARITY(sClearInputConfig->ClearInputPolarity)); |
phungductung | 0:8ede47d38d10 | 1931 | assert_param(IS_TIM_CLEARINPUT_PRESCALER(sClearInputConfig->ClearInputPrescaler)); |
phungductung | 0:8ede47d38d10 | 1932 | assert_param(IS_TIM_CLEARINPUT_FILTER(sClearInputConfig->ClearInputFilter)); |
phungductung | 0:8ede47d38d10 | 1933 | |
phungductung | 0:8ede47d38d10 | 1934 | TIM_ETR_SetConfig(htim->Instance, |
phungductung | 0:8ede47d38d10 | 1935 | sClearInputConfig->ClearInputPrescaler, |
phungductung | 0:8ede47d38d10 | 1936 | sClearInputConfig->ClearInputPolarity, |
phungductung | 0:8ede47d38d10 | 1937 | sClearInputConfig->ClearInputFilter); |
phungductung | 0:8ede47d38d10 | 1938 | |
phungductung | 0:8ede47d38d10 | 1939 | /* Set the OCREF clear selection bit */ |
phungductung | 0:8ede47d38d10 | 1940 | htim->Instance->SMCR |= TIM_SMCR_OCCS; |
phungductung | 0:8ede47d38d10 | 1941 | } |
phungductung | 0:8ede47d38d10 | 1942 | break; |
phungductung | 0:8ede47d38d10 | 1943 | default: |
phungductung | 0:8ede47d38d10 | 1944 | break; |
phungductung | 0:8ede47d38d10 | 1945 | } |
phungductung | 0:8ede47d38d10 | 1946 | |
phungductung | 0:8ede47d38d10 | 1947 | switch (Channel) |
phungductung | 0:8ede47d38d10 | 1948 | { |
phungductung | 0:8ede47d38d10 | 1949 | case TIM_CHANNEL_1: |
phungductung | 0:8ede47d38d10 | 1950 | { |
phungductung | 0:8ede47d38d10 | 1951 | if(sClearInputConfig->ClearInputState != RESET) |
phungductung | 0:8ede47d38d10 | 1952 | { |
phungductung | 0:8ede47d38d10 | 1953 | /* Enable the Ocref clear feature for Channel 1 */ |
phungductung | 0:8ede47d38d10 | 1954 | htim->Instance->CCMR1 |= TIM_CCMR1_OC1CE; |
phungductung | 0:8ede47d38d10 | 1955 | } |
phungductung | 0:8ede47d38d10 | 1956 | else |
phungductung | 0:8ede47d38d10 | 1957 | { |
phungductung | 0:8ede47d38d10 | 1958 | /* Disable the Ocref clear feature for Channel 1 */ |
phungductung | 0:8ede47d38d10 | 1959 | htim->Instance->CCMR1 &= ~TIM_CCMR1_OC1CE; |
phungductung | 0:8ede47d38d10 | 1960 | } |
phungductung | 0:8ede47d38d10 | 1961 | } |
phungductung | 0:8ede47d38d10 | 1962 | break; |
phungductung | 0:8ede47d38d10 | 1963 | case TIM_CHANNEL_2: |
phungductung | 0:8ede47d38d10 | 1964 | { |
phungductung | 0:8ede47d38d10 | 1965 | if(sClearInputConfig->ClearInputState != RESET) |
phungductung | 0:8ede47d38d10 | 1966 | { |
phungductung | 0:8ede47d38d10 | 1967 | /* Enable the Ocref clear feature for Channel 2 */ |
phungductung | 0:8ede47d38d10 | 1968 | htim->Instance->CCMR1 |= TIM_CCMR1_OC2CE; |
phungductung | 0:8ede47d38d10 | 1969 | } |
phungductung | 0:8ede47d38d10 | 1970 | else |
phungductung | 0:8ede47d38d10 | 1971 | { |
phungductung | 0:8ede47d38d10 | 1972 | /* Disable the Ocref clear feature for Channel 2 */ |
phungductung | 0:8ede47d38d10 | 1973 | htim->Instance->CCMR1 &= ~TIM_CCMR1_OC2CE; |
phungductung | 0:8ede47d38d10 | 1974 | } |
phungductung | 0:8ede47d38d10 | 1975 | } |
phungductung | 0:8ede47d38d10 | 1976 | break; |
phungductung | 0:8ede47d38d10 | 1977 | case TIM_CHANNEL_3: |
phungductung | 0:8ede47d38d10 | 1978 | { |
phungductung | 0:8ede47d38d10 | 1979 | if(sClearInputConfig->ClearInputState != RESET) |
phungductung | 0:8ede47d38d10 | 1980 | { |
phungductung | 0:8ede47d38d10 | 1981 | /* Enable the Ocref clear feature for Channel 3 */ |
phungductung | 0:8ede47d38d10 | 1982 | htim->Instance->CCMR2 |= TIM_CCMR2_OC3CE; |
phungductung | 0:8ede47d38d10 | 1983 | } |
phungductung | 0:8ede47d38d10 | 1984 | else |
phungductung | 0:8ede47d38d10 | 1985 | { |
phungductung | 0:8ede47d38d10 | 1986 | /* Disable the Ocref clear feature for Channel 3 */ |
phungductung | 0:8ede47d38d10 | 1987 | htim->Instance->CCMR2 &= ~TIM_CCMR2_OC3CE; |
phungductung | 0:8ede47d38d10 | 1988 | } |
phungductung | 0:8ede47d38d10 | 1989 | } |
phungductung | 0:8ede47d38d10 | 1990 | break; |
phungductung | 0:8ede47d38d10 | 1991 | case TIM_CHANNEL_4: |
phungductung | 0:8ede47d38d10 | 1992 | { |
phungductung | 0:8ede47d38d10 | 1993 | if(sClearInputConfig->ClearInputState != RESET) |
phungductung | 0:8ede47d38d10 | 1994 | { |
phungductung | 0:8ede47d38d10 | 1995 | /* Enable the Ocref clear feature for Channel 4 */ |
phungductung | 0:8ede47d38d10 | 1996 | htim->Instance->CCMR2 |= TIM_CCMR2_OC4CE; |
phungductung | 0:8ede47d38d10 | 1997 | } |
phungductung | 0:8ede47d38d10 | 1998 | else |
phungductung | 0:8ede47d38d10 | 1999 | { |
phungductung | 0:8ede47d38d10 | 2000 | /* Disable the Ocref clear feature for Channel 4 */ |
phungductung | 0:8ede47d38d10 | 2001 | htim->Instance->CCMR2 &= ~TIM_CCMR2_OC4CE; |
phungductung | 0:8ede47d38d10 | 2002 | } |
phungductung | 0:8ede47d38d10 | 2003 | } |
phungductung | 0:8ede47d38d10 | 2004 | break; |
phungductung | 0:8ede47d38d10 | 2005 | case TIM_CHANNEL_5: |
phungductung | 0:8ede47d38d10 | 2006 | { |
phungductung | 0:8ede47d38d10 | 2007 | if(sClearInputConfig->ClearInputState != RESET) |
phungductung | 0:8ede47d38d10 | 2008 | { |
phungductung | 0:8ede47d38d10 | 2009 | /* Enable the Ocref clear feature for Channel 1 */ |
phungductung | 0:8ede47d38d10 | 2010 | htim->Instance->CCMR3 |= TIM_CCMR3_OC5CE; |
phungductung | 0:8ede47d38d10 | 2011 | } |
phungductung | 0:8ede47d38d10 | 2012 | else |
phungductung | 0:8ede47d38d10 | 2013 | { |
phungductung | 0:8ede47d38d10 | 2014 | /* Disable the Ocref clear feature for Channel 1 */ |
phungductung | 0:8ede47d38d10 | 2015 | htim->Instance->CCMR3 &= ~TIM_CCMR3_OC5CE; |
phungductung | 0:8ede47d38d10 | 2016 | } |
phungductung | 0:8ede47d38d10 | 2017 | } |
phungductung | 0:8ede47d38d10 | 2018 | break; |
phungductung | 0:8ede47d38d10 | 2019 | case TIM_CHANNEL_6: |
phungductung | 0:8ede47d38d10 | 2020 | { |
phungductung | 0:8ede47d38d10 | 2021 | if(sClearInputConfig->ClearInputState != RESET) |
phungductung | 0:8ede47d38d10 | 2022 | { |
phungductung | 0:8ede47d38d10 | 2023 | /* Enable the Ocref clear feature for Channel 1 */ |
phungductung | 0:8ede47d38d10 | 2024 | htim->Instance->CCMR3 |= TIM_CCMR3_OC6CE; |
phungductung | 0:8ede47d38d10 | 2025 | } |
phungductung | 0:8ede47d38d10 | 2026 | else |
phungductung | 0:8ede47d38d10 | 2027 | { |
phungductung | 0:8ede47d38d10 | 2028 | /* Disable the Ocref clear feature for Channel 1 */ |
phungductung | 0:8ede47d38d10 | 2029 | htim->Instance->CCMR3 &= ~TIM_CCMR3_OC6CE; |
phungductung | 0:8ede47d38d10 | 2030 | } |
phungductung | 0:8ede47d38d10 | 2031 | } |
phungductung | 0:8ede47d38d10 | 2032 | break; |
phungductung | 0:8ede47d38d10 | 2033 | default: |
phungductung | 0:8ede47d38d10 | 2034 | break; |
phungductung | 0:8ede47d38d10 | 2035 | } |
phungductung | 0:8ede47d38d10 | 2036 | |
phungductung | 0:8ede47d38d10 | 2037 | __HAL_UNLOCK(htim); |
phungductung | 0:8ede47d38d10 | 2038 | |
phungductung | 0:8ede47d38d10 | 2039 | return HAL_OK; |
phungductung | 0:8ede47d38d10 | 2040 | } |
phungductung | 0:8ede47d38d10 | 2041 | |
phungductung | 0:8ede47d38d10 | 2042 | /** |
phungductung | 0:8ede47d38d10 | 2043 | * @brief Configures the TIM in master mode. |
phungductung | 0:8ede47d38d10 | 2044 | * @param htim: pointer to a TIM_HandleTypeDef structure that contains |
phungductung | 0:8ede47d38d10 | 2045 | * the configuration information for TIM module. |
phungductung | 0:8ede47d38d10 | 2046 | * @param sMasterConfig: pointer to a TIM_MasterConfigTypeDef structure that |
phungductung | 0:8ede47d38d10 | 2047 | * contains the selected trigger output (TRGO) and the Master/Slave |
phungductung | 0:8ede47d38d10 | 2048 | * mode. |
phungductung | 0:8ede47d38d10 | 2049 | * @retval HAL status |
phungductung | 0:8ede47d38d10 | 2050 | */ |
phungductung | 0:8ede47d38d10 | 2051 | HAL_StatusTypeDef HAL_TIMEx_MasterConfigSynchronization(TIM_HandleTypeDef *htim, TIM_MasterConfigTypeDef * sMasterConfig) |
phungductung | 0:8ede47d38d10 | 2052 | { |
phungductung | 0:8ede47d38d10 | 2053 | uint32_t tmpcr2; |
phungductung | 0:8ede47d38d10 | 2054 | uint32_t tmpsmcr; |
phungductung | 0:8ede47d38d10 | 2055 | |
phungductung | 0:8ede47d38d10 | 2056 | /* Check the parameters */ |
phungductung | 0:8ede47d38d10 | 2057 | assert_param(IS_TIM_SYNCHRO_INSTANCE(htim->Instance)); |
phungductung | 0:8ede47d38d10 | 2058 | assert_param(IS_TIM_TRGO_SOURCE(sMasterConfig->MasterOutputTrigger)); |
phungductung | 0:8ede47d38d10 | 2059 | assert_param(IS_TIM_MSM_STATE(sMasterConfig->MasterSlaveMode)); |
phungductung | 0:8ede47d38d10 | 2060 | |
phungductung | 0:8ede47d38d10 | 2061 | /* Check input state */ |
phungductung | 0:8ede47d38d10 | 2062 | __HAL_LOCK(htim); |
phungductung | 0:8ede47d38d10 | 2063 | |
phungductung | 0:8ede47d38d10 | 2064 | /* Get the TIMx CR2 register value */ |
phungductung | 0:8ede47d38d10 | 2065 | tmpcr2 = htim->Instance->CR2; |
phungductung | 0:8ede47d38d10 | 2066 | |
phungductung | 0:8ede47d38d10 | 2067 | /* Get the TIMx SMCR register value */ |
phungductung | 0:8ede47d38d10 | 2068 | tmpsmcr = htim->Instance->SMCR; |
phungductung | 0:8ede47d38d10 | 2069 | |
phungductung | 0:8ede47d38d10 | 2070 | /* If the timer supports ADC synchronization through TRGO2, set the master mode selection 2 */ |
phungductung | 0:8ede47d38d10 | 2071 | if (IS_TIM_TRGO2_INSTANCE(htim->Instance)) |
phungductung | 0:8ede47d38d10 | 2072 | { |
phungductung | 0:8ede47d38d10 | 2073 | /* Check the parameters */ |
phungductung | 0:8ede47d38d10 | 2074 | assert_param(IS_TIM_TRGO2_SOURCE(sMasterConfig->MasterOutputTrigger2)); |
phungductung | 0:8ede47d38d10 | 2075 | |
phungductung | 0:8ede47d38d10 | 2076 | /* Clear the MMS2 bits */ |
phungductung | 0:8ede47d38d10 | 2077 | tmpcr2 &= ~TIM_CR2_MMS2; |
phungductung | 0:8ede47d38d10 | 2078 | /* Select the TRGO2 source*/ |
phungductung | 0:8ede47d38d10 | 2079 | tmpcr2 |= sMasterConfig->MasterOutputTrigger2; |
phungductung | 0:8ede47d38d10 | 2080 | } |
phungductung | 0:8ede47d38d10 | 2081 | |
phungductung | 0:8ede47d38d10 | 2082 | /* Reset the MMS Bits */ |
phungductung | 0:8ede47d38d10 | 2083 | tmpcr2 &= ~TIM_CR2_MMS; |
phungductung | 0:8ede47d38d10 | 2084 | /* Select the TRGO source */ |
phungductung | 0:8ede47d38d10 | 2085 | tmpcr2 |= sMasterConfig->MasterOutputTrigger; |
phungductung | 0:8ede47d38d10 | 2086 | |
phungductung | 0:8ede47d38d10 | 2087 | /* Reset the MSM Bit */ |
phungductung | 0:8ede47d38d10 | 2088 | tmpsmcr &= ~TIM_SMCR_MSM; |
phungductung | 0:8ede47d38d10 | 2089 | /* Set master mode */ |
phungductung | 0:8ede47d38d10 | 2090 | tmpsmcr |= sMasterConfig->MasterSlaveMode; |
phungductung | 0:8ede47d38d10 | 2091 | |
phungductung | 0:8ede47d38d10 | 2092 | /* Update TIMx CR2 */ |
phungductung | 0:8ede47d38d10 | 2093 | htim->Instance->CR2 = tmpcr2; |
phungductung | 0:8ede47d38d10 | 2094 | |
phungductung | 0:8ede47d38d10 | 2095 | /* Update TIMx SMCR */ |
phungductung | 0:8ede47d38d10 | 2096 | htim->Instance->SMCR = tmpsmcr; |
phungductung | 0:8ede47d38d10 | 2097 | |
phungductung | 0:8ede47d38d10 | 2098 | __HAL_UNLOCK(htim); |
phungductung | 0:8ede47d38d10 | 2099 | |
phungductung | 0:8ede47d38d10 | 2100 | return HAL_OK; |
phungductung | 0:8ede47d38d10 | 2101 | } |
phungductung | 0:8ede47d38d10 | 2102 | |
phungductung | 0:8ede47d38d10 | 2103 | /** |
phungductung | 0:8ede47d38d10 | 2104 | * @brief Configures the Break feature, dead time, Lock level, OSSI/OSSR State |
phungductung | 0:8ede47d38d10 | 2105 | * and the AOE(automatic output enable). |
phungductung | 0:8ede47d38d10 | 2106 | * @param htim: pointer to a TIM_HandleTypeDef structure that contains |
phungductung | 0:8ede47d38d10 | 2107 | * the configuration information for TIM module. |
phungductung | 0:8ede47d38d10 | 2108 | * @param sBreakDeadTimeConfig: pointer to a TIM_ConfigBreakDeadConfig_TypeDef structure that |
phungductung | 0:8ede47d38d10 | 2109 | * contains the BDTR Register configuration information for the TIM peripheral. |
phungductung | 0:8ede47d38d10 | 2110 | * @retval HAL status |
phungductung | 0:8ede47d38d10 | 2111 | */ |
phungductung | 0:8ede47d38d10 | 2112 | HAL_StatusTypeDef HAL_TIMEx_ConfigBreakDeadTime(TIM_HandleTypeDef *htim, |
phungductung | 0:8ede47d38d10 | 2113 | TIM_BreakDeadTimeConfigTypeDef * sBreakDeadTimeConfig) |
phungductung | 0:8ede47d38d10 | 2114 | { |
phungductung | 0:8ede47d38d10 | 2115 | uint32_t tmpbdtr = 0; |
phungductung | 0:8ede47d38d10 | 2116 | |
phungductung | 0:8ede47d38d10 | 2117 | /* Check the parameters */ |
phungductung | 0:8ede47d38d10 | 2118 | assert_param(IS_TIM_BREAK_INSTANCE(htim->Instance)); |
phungductung | 0:8ede47d38d10 | 2119 | assert_param(IS_TIM_OSSR_STATE(sBreakDeadTimeConfig->OffStateRunMode)); |
phungductung | 0:8ede47d38d10 | 2120 | assert_param(IS_TIM_OSSI_STATE(sBreakDeadTimeConfig->OffStateIDLEMode)); |
phungductung | 0:8ede47d38d10 | 2121 | assert_param(IS_TIM_LOCK_LEVEL(sBreakDeadTimeConfig->LockLevel)); |
phungductung | 0:8ede47d38d10 | 2122 | assert_param(IS_TIM_DEADTIME(sBreakDeadTimeConfig->DeadTime)); |
phungductung | 0:8ede47d38d10 | 2123 | assert_param(IS_TIM_BREAK_STATE(sBreakDeadTimeConfig->BreakState)); |
phungductung | 0:8ede47d38d10 | 2124 | assert_param(IS_TIM_BREAK_POLARITY(sBreakDeadTimeConfig->BreakPolarity)); |
phungductung | 0:8ede47d38d10 | 2125 | assert_param(IS_TIM_BREAK_FILTER(sBreakDeadTimeConfig->BreakFilter)); |
phungductung | 0:8ede47d38d10 | 2126 | assert_param(IS_TIM_AUTOMATIC_OUTPUT_STATE(sBreakDeadTimeConfig->AutomaticOutput)); |
phungductung | 0:8ede47d38d10 | 2127 | assert_param(IS_TIM_BREAK2_STATE(sBreakDeadTimeConfig->Break2State)); |
phungductung | 0:8ede47d38d10 | 2128 | assert_param(IS_TIM_BREAK2_POLARITY(sBreakDeadTimeConfig->Break2Polarity)); |
phungductung | 0:8ede47d38d10 | 2129 | assert_param(IS_TIM_BREAK_FILTER(sBreakDeadTimeConfig->Break2Filter)); |
phungductung | 0:8ede47d38d10 | 2130 | |
phungductung | 0:8ede47d38d10 | 2131 | /* Check input state */ |
phungductung | 0:8ede47d38d10 | 2132 | __HAL_LOCK(htim); |
phungductung | 0:8ede47d38d10 | 2133 | |
phungductung | 0:8ede47d38d10 | 2134 | htim->State = HAL_TIM_STATE_BUSY; |
phungductung | 0:8ede47d38d10 | 2135 | |
phungductung | 0:8ede47d38d10 | 2136 | /* Set the Lock level, the Break enable Bit and the Polarity, the OSSR State, |
phungductung | 0:8ede47d38d10 | 2137 | the OSSI State, the dead time value and the Automatic Output Enable Bit */ |
phungductung | 0:8ede47d38d10 | 2138 | |
phungductung | 0:8ede47d38d10 | 2139 | /* Clear the BDTR bits */ |
phungductung | 0:8ede47d38d10 | 2140 | tmpbdtr &= ~(TIM_BDTR_DTG | TIM_BDTR_LOCK | TIM_BDTR_OSSI | |
phungductung | 0:8ede47d38d10 | 2141 | TIM_BDTR_OSSR | TIM_BDTR_BKE | TIM_BDTR_BKP | |
phungductung | 0:8ede47d38d10 | 2142 | TIM_BDTR_AOE | TIM_BDTR_MOE | TIM_BDTR_BKF | |
phungductung | 0:8ede47d38d10 | 2143 | TIM_BDTR_BK2F | TIM_BDTR_BK2E | TIM_BDTR_BK2P); |
phungductung | 0:8ede47d38d10 | 2144 | |
phungductung | 0:8ede47d38d10 | 2145 | /* Set the BDTR bits */ |
phungductung | 0:8ede47d38d10 | 2146 | tmpbdtr |= sBreakDeadTimeConfig->DeadTime; |
phungductung | 0:8ede47d38d10 | 2147 | tmpbdtr |= sBreakDeadTimeConfig->LockLevel; |
phungductung | 0:8ede47d38d10 | 2148 | tmpbdtr |= sBreakDeadTimeConfig->OffStateIDLEMode; |
phungductung | 0:8ede47d38d10 | 2149 | tmpbdtr |= sBreakDeadTimeConfig->OffStateRunMode; |
phungductung | 0:8ede47d38d10 | 2150 | tmpbdtr |= sBreakDeadTimeConfig->BreakState; |
phungductung | 0:8ede47d38d10 | 2151 | tmpbdtr |= sBreakDeadTimeConfig->BreakPolarity; |
phungductung | 0:8ede47d38d10 | 2152 | tmpbdtr |= sBreakDeadTimeConfig->AutomaticOutput; |
phungductung | 0:8ede47d38d10 | 2153 | tmpbdtr |= (sBreakDeadTimeConfig->BreakFilter << BDTR_BKF_SHIFT); |
phungductung | 0:8ede47d38d10 | 2154 | tmpbdtr |= (sBreakDeadTimeConfig->Break2Filter << BDTR_BK2F_SHIFT); |
phungductung | 0:8ede47d38d10 | 2155 | tmpbdtr |= sBreakDeadTimeConfig->Break2State; |
phungductung | 0:8ede47d38d10 | 2156 | tmpbdtr |= sBreakDeadTimeConfig->Break2Polarity; |
phungductung | 0:8ede47d38d10 | 2157 | |
phungductung | 0:8ede47d38d10 | 2158 | /* Set TIMx_BDTR */ |
phungductung | 0:8ede47d38d10 | 2159 | htim->Instance->BDTR = tmpbdtr; |
phungductung | 0:8ede47d38d10 | 2160 | |
phungductung | 0:8ede47d38d10 | 2161 | __HAL_UNLOCK(htim); |
phungductung | 0:8ede47d38d10 | 2162 | |
phungductung | 0:8ede47d38d10 | 2163 | return HAL_OK; |
phungductung | 0:8ede47d38d10 | 2164 | } |
phungductung | 0:8ede47d38d10 | 2165 | |
phungductung | 0:8ede47d38d10 | 2166 | /** |
phungductung | 0:8ede47d38d10 | 2167 | * @brief Configures the TIM2, TIM5 and TIM11 Remapping input capabilities. |
phungductung | 0:8ede47d38d10 | 2168 | * @param htim: pointer to a TIM_HandleTypeDef structure that contains |
phungductung | 0:8ede47d38d10 | 2169 | * the configuration information for TIM module. |
phungductung | 0:8ede47d38d10 | 2170 | * @param Remap: specifies the TIM input remapping source. |
phungductung | 0:8ede47d38d10 | 2171 | * This parameter can be one of the following values: |
phungductung | 0:8ede47d38d10 | 2172 | * @arg TIM_TIM2_TIM8_TRGO: TIM2 ITR1 input is connected to TIM8 Trigger output(default) |
phungductung | 0:8ede47d38d10 | 2173 | * @arg TIM_TIM2_ETH_PTP: TIM2 ITR1 input is connected to ETH PTP trigger output. |
phungductung | 0:8ede47d38d10 | 2174 | * @arg TIM_TIM2_USBFS_SOF: TIM2 ITR1 input is connected to USB FS SOF. |
phungductung | 0:8ede47d38d10 | 2175 | * @arg TIM_TIM2_USBHS_SOF: TIM2 ITR1 input is connected to USB HS SOF. |
phungductung | 0:8ede47d38d10 | 2176 | * @arg TIM_TIM5_GPIO: TIM5 CH4 input is connected to dedicated Timer pin(default) |
phungductung | 0:8ede47d38d10 | 2177 | * @arg TIM_TIM5_LSI: TIM5 CH4 input is connected to LSI clock. |
phungductung | 0:8ede47d38d10 | 2178 | * @arg TIM_TIM5_LSE: TIM5 CH4 input is connected to LSE clock. |
phungductung | 0:8ede47d38d10 | 2179 | * @arg TIM_TIM5_RTC: TIM5 CH4 input is connected to RTC Output event. |
phungductung | 0:8ede47d38d10 | 2180 | * @arg TIM_TIM11_GPIO: TIM11 CH4 input is connected to dedicated Timer pin(default) |
phungductung | 0:8ede47d38d10 | 2181 | * @arg TIM_TIM11_SPDIF: SPDIF Frame synchronous |
phungductung | 0:8ede47d38d10 | 2182 | * @arg TIM_TIM11_HSE: TIM11 CH4 input is connected to HSE_RTC clock |
phungductung | 0:8ede47d38d10 | 2183 | * (HSE divided by a programmable prescaler) |
phungductung | 0:8ede47d38d10 | 2184 | * @arg TIM_TIM11_MCO1: TIM11 CH1 input is connected to MCO1 |
phungductung | 0:8ede47d38d10 | 2185 | * @retval HAL status |
phungductung | 0:8ede47d38d10 | 2186 | */ |
phungductung | 0:8ede47d38d10 | 2187 | HAL_StatusTypeDef HAL_TIMEx_RemapConfig(TIM_HandleTypeDef *htim, uint32_t Remap) |
phungductung | 0:8ede47d38d10 | 2188 | { |
phungductung | 0:8ede47d38d10 | 2189 | __HAL_LOCK(htim); |
phungductung | 0:8ede47d38d10 | 2190 | |
phungductung | 0:8ede47d38d10 | 2191 | /* Check parameters */ |
phungductung | 0:8ede47d38d10 | 2192 | assert_param(IS_TIM_REMAP_INSTANCE(htim->Instance)); |
phungductung | 0:8ede47d38d10 | 2193 | assert_param(IS_TIM_REMAP(Remap)); |
phungductung | 0:8ede47d38d10 | 2194 | |
phungductung | 0:8ede47d38d10 | 2195 | /* Set the Timer remapping configuration */ |
phungductung | 0:8ede47d38d10 | 2196 | htim->Instance->OR = Remap; |
phungductung | 0:8ede47d38d10 | 2197 | |
phungductung | 0:8ede47d38d10 | 2198 | htim->State = HAL_TIM_STATE_READY; |
phungductung | 0:8ede47d38d10 | 2199 | |
phungductung | 0:8ede47d38d10 | 2200 | __HAL_UNLOCK(htim); |
phungductung | 0:8ede47d38d10 | 2201 | |
phungductung | 0:8ede47d38d10 | 2202 | return HAL_OK; |
phungductung | 0:8ede47d38d10 | 2203 | } |
phungductung | 0:8ede47d38d10 | 2204 | |
phungductung | 0:8ede47d38d10 | 2205 | /** |
phungductung | 0:8ede47d38d10 | 2206 | * @brief Group channel 5 and channel 1, 2 or 3 |
phungductung | 0:8ede47d38d10 | 2207 | * @param htim: TIM handle. |
phungductung | 0:8ede47d38d10 | 2208 | * @param OCRef: specifies the reference signal(s) the OC5REF is combined with. |
phungductung | 0:8ede47d38d10 | 2209 | * This parameter can be any combination of the following values: |
phungductung | 0:8ede47d38d10 | 2210 | * TIM_GROUPCH5_NONE: No effect of OC5REF on OC1REFC, OC2REFC and OC3REFC |
phungductung | 0:8ede47d38d10 | 2211 | * TIM_GROUPCH5_OC1REFC: OC1REFC is the logical AND of OC1REFC and OC5REF |
phungductung | 0:8ede47d38d10 | 2212 | * TIM_GROUPCH5_OC2REFC: OC2REFC is the logical AND of OC2REFC and OC5REF |
phungductung | 0:8ede47d38d10 | 2213 | * TIM_GROUPCH5_OC3REFC: OC3REFC is the logical AND of OC3REFC and OC5REF |
phungductung | 0:8ede47d38d10 | 2214 | * @retval HAL status |
phungductung | 0:8ede47d38d10 | 2215 | */ |
phungductung | 0:8ede47d38d10 | 2216 | HAL_StatusTypeDef HAL_TIMEx_GroupChannel5(TIM_HandleTypeDef *htim, uint32_t OCRef) |
phungductung | 0:8ede47d38d10 | 2217 | { |
phungductung | 0:8ede47d38d10 | 2218 | /* Check parameters */ |
phungductung | 0:8ede47d38d10 | 2219 | assert_param(IS_TIM_COMBINED3PHASEPWM_INSTANCE(htim->Instance)); |
phungductung | 0:8ede47d38d10 | 2220 | assert_param(IS_TIM_GROUPCH5(OCRef)); |
phungductung | 0:8ede47d38d10 | 2221 | |
phungductung | 0:8ede47d38d10 | 2222 | /* Process Locked */ |
phungductung | 0:8ede47d38d10 | 2223 | __HAL_LOCK(htim); |
phungductung | 0:8ede47d38d10 | 2224 | |
phungductung | 0:8ede47d38d10 | 2225 | htim->State = HAL_TIM_STATE_BUSY; |
phungductung | 0:8ede47d38d10 | 2226 | |
phungductung | 0:8ede47d38d10 | 2227 | /* Clear GC5Cx bit fields */ |
phungductung | 0:8ede47d38d10 | 2228 | htim->Instance->CCR5 &= ~(TIM_CCR5_GC5C3|TIM_CCR5_GC5C2|TIM_CCR5_GC5C1); |
phungductung | 0:8ede47d38d10 | 2229 | |
phungductung | 0:8ede47d38d10 | 2230 | /* Set GC5Cx bit fields */ |
phungductung | 0:8ede47d38d10 | 2231 | htim->Instance->CCR5 |= OCRef; |
phungductung | 0:8ede47d38d10 | 2232 | |
phungductung | 0:8ede47d38d10 | 2233 | htim->State = HAL_TIM_STATE_READY; |
phungductung | 0:8ede47d38d10 | 2234 | |
phungductung | 0:8ede47d38d10 | 2235 | __HAL_UNLOCK(htim); |
phungductung | 0:8ede47d38d10 | 2236 | |
phungductung | 0:8ede47d38d10 | 2237 | return HAL_OK; |
phungductung | 0:8ede47d38d10 | 2238 | } |
phungductung | 0:8ede47d38d10 | 2239 | |
phungductung | 0:8ede47d38d10 | 2240 | /** |
phungductung | 0:8ede47d38d10 | 2241 | * @} |
phungductung | 0:8ede47d38d10 | 2242 | */ |
phungductung | 0:8ede47d38d10 | 2243 | |
phungductung | 0:8ede47d38d10 | 2244 | /** @defgroup TIMEx_Exported_Functions_Group6 Extended Callbacks functions |
phungductung | 0:8ede47d38d10 | 2245 | * @brief Extended Callbacks functions |
phungductung | 0:8ede47d38d10 | 2246 | * |
phungductung | 0:8ede47d38d10 | 2247 | @verbatim |
phungductung | 0:8ede47d38d10 | 2248 | ============================================================================== |
phungductung | 0:8ede47d38d10 | 2249 | ##### Extension Callbacks functions ##### |
phungductung | 0:8ede47d38d10 | 2250 | ============================================================================== |
phungductung | 0:8ede47d38d10 | 2251 | [..] |
phungductung | 0:8ede47d38d10 | 2252 | This section provides Extension TIM callback functions: |
phungductung | 0:8ede47d38d10 | 2253 | (+) Timer Commutation callback |
phungductung | 0:8ede47d38d10 | 2254 | (+) Timer Break callback |
phungductung | 0:8ede47d38d10 | 2255 | |
phungductung | 0:8ede47d38d10 | 2256 | @endverbatim |
phungductung | 0:8ede47d38d10 | 2257 | * @{ |
phungductung | 0:8ede47d38d10 | 2258 | */ |
phungductung | 0:8ede47d38d10 | 2259 | |
phungductung | 0:8ede47d38d10 | 2260 | /** |
phungductung | 0:8ede47d38d10 | 2261 | * @brief Hall commutation changed callback in non blocking mode |
phungductung | 0:8ede47d38d10 | 2262 | * @param htim: pointer to a TIM_HandleTypeDef structure that contains |
phungductung | 0:8ede47d38d10 | 2263 | * the configuration information for TIM module. |
phungductung | 0:8ede47d38d10 | 2264 | * @retval None |
phungductung | 0:8ede47d38d10 | 2265 | */ |
phungductung | 0:8ede47d38d10 | 2266 | __weak void HAL_TIMEx_CommutationCallback(TIM_HandleTypeDef *htim) |
phungductung | 0:8ede47d38d10 | 2267 | { |
phungductung | 0:8ede47d38d10 | 2268 | /* Prevent unused argument(s) compilation warning */ |
phungductung | 0:8ede47d38d10 | 2269 | UNUSED(htim); |
phungductung | 0:8ede47d38d10 | 2270 | |
phungductung | 0:8ede47d38d10 | 2271 | /* NOTE : This function Should not be modified, when the callback is needed, |
phungductung | 0:8ede47d38d10 | 2272 | the HAL_TIMEx_CommutationCallback could be implemented in the user file |
phungductung | 0:8ede47d38d10 | 2273 | */ |
phungductung | 0:8ede47d38d10 | 2274 | } |
phungductung | 0:8ede47d38d10 | 2275 | |
phungductung | 0:8ede47d38d10 | 2276 | /** |
phungductung | 0:8ede47d38d10 | 2277 | * @brief Hall Break detection callback in non blocking mode |
phungductung | 0:8ede47d38d10 | 2278 | * @param htim: pointer to a TIM_HandleTypeDef structure that contains |
phungductung | 0:8ede47d38d10 | 2279 | * the configuration information for TIM module. |
phungductung | 0:8ede47d38d10 | 2280 | * @retval None |
phungductung | 0:8ede47d38d10 | 2281 | */ |
phungductung | 0:8ede47d38d10 | 2282 | __weak void HAL_TIMEx_BreakCallback(TIM_HandleTypeDef *htim) |
phungductung | 0:8ede47d38d10 | 2283 | { |
phungductung | 0:8ede47d38d10 | 2284 | /* Prevent unused argument(s) compilation warning */ |
phungductung | 0:8ede47d38d10 | 2285 | UNUSED(htim); |
phungductung | 0:8ede47d38d10 | 2286 | |
phungductung | 0:8ede47d38d10 | 2287 | /* NOTE : This function Should not be modified, when the callback is needed, |
phungductung | 0:8ede47d38d10 | 2288 | the HAL_TIMEx_BreakCallback could be implemented in the user file |
phungductung | 0:8ede47d38d10 | 2289 | */ |
phungductung | 0:8ede47d38d10 | 2290 | } |
phungductung | 0:8ede47d38d10 | 2291 | |
phungductung | 0:8ede47d38d10 | 2292 | /** |
phungductung | 0:8ede47d38d10 | 2293 | * @} |
phungductung | 0:8ede47d38d10 | 2294 | */ |
phungductung | 0:8ede47d38d10 | 2295 | |
phungductung | 0:8ede47d38d10 | 2296 | /** @defgroup TIMEx_Exported_Functions_Group7 Extended Peripheral State functions |
phungductung | 0:8ede47d38d10 | 2297 | * @brief Extended Peripheral State functions |
phungductung | 0:8ede47d38d10 | 2298 | * |
phungductung | 0:8ede47d38d10 | 2299 | @verbatim |
phungductung | 0:8ede47d38d10 | 2300 | ============================================================================== |
phungductung | 0:8ede47d38d10 | 2301 | ##### Extension Peripheral State functions ##### |
phungductung | 0:8ede47d38d10 | 2302 | ============================================================================== |
phungductung | 0:8ede47d38d10 | 2303 | [..] |
phungductung | 0:8ede47d38d10 | 2304 | This subsection permits to get in run-time the status of the peripheral |
phungductung | 0:8ede47d38d10 | 2305 | and the data flow. |
phungductung | 0:8ede47d38d10 | 2306 | |
phungductung | 0:8ede47d38d10 | 2307 | @endverbatim |
phungductung | 0:8ede47d38d10 | 2308 | * @{ |
phungductung | 0:8ede47d38d10 | 2309 | */ |
phungductung | 0:8ede47d38d10 | 2310 | |
phungductung | 0:8ede47d38d10 | 2311 | /** |
phungductung | 0:8ede47d38d10 | 2312 | * @brief Return the TIM Hall Sensor interface state |
phungductung | 0:8ede47d38d10 | 2313 | * @param htim: pointer to a TIM_HandleTypeDef structure that contains |
phungductung | 0:8ede47d38d10 | 2314 | * the configuration information for TIM module. |
phungductung | 0:8ede47d38d10 | 2315 | * @retval HAL state |
phungductung | 0:8ede47d38d10 | 2316 | */ |
phungductung | 0:8ede47d38d10 | 2317 | HAL_TIM_StateTypeDef HAL_TIMEx_HallSensor_GetState(TIM_HandleTypeDef *htim) |
phungductung | 0:8ede47d38d10 | 2318 | { |
phungductung | 0:8ede47d38d10 | 2319 | return htim->State; |
phungductung | 0:8ede47d38d10 | 2320 | } |
phungductung | 0:8ede47d38d10 | 2321 | |
phungductung | 0:8ede47d38d10 | 2322 | /** |
phungductung | 0:8ede47d38d10 | 2323 | * @} |
phungductung | 0:8ede47d38d10 | 2324 | */ |
phungductung | 0:8ede47d38d10 | 2325 | |
phungductung | 0:8ede47d38d10 | 2326 | /** |
phungductung | 0:8ede47d38d10 | 2327 | * @brief TIM DMA Commutation callback. |
phungductung | 0:8ede47d38d10 | 2328 | * @param hdma: pointer to a DMA_HandleTypeDef structure that contains |
phungductung | 0:8ede47d38d10 | 2329 | * the configuration information for the specified DMA module. |
phungductung | 0:8ede47d38d10 | 2330 | * @retval None |
phungductung | 0:8ede47d38d10 | 2331 | */ |
phungductung | 0:8ede47d38d10 | 2332 | void HAL_TIMEx_DMACommutationCplt(DMA_HandleTypeDef *hdma) |
phungductung | 0:8ede47d38d10 | 2333 | { |
phungductung | 0:8ede47d38d10 | 2334 | TIM_HandleTypeDef* htim = ( TIM_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; |
phungductung | 0:8ede47d38d10 | 2335 | |
phungductung | 0:8ede47d38d10 | 2336 | htim->State= HAL_TIM_STATE_READY; |
phungductung | 0:8ede47d38d10 | 2337 | |
phungductung | 0:8ede47d38d10 | 2338 | HAL_TIMEx_CommutationCallback(htim); |
phungductung | 0:8ede47d38d10 | 2339 | } |
phungductung | 0:8ede47d38d10 | 2340 | |
phungductung | 0:8ede47d38d10 | 2341 | /** |
phungductung | 0:8ede47d38d10 | 2342 | * @brief Enables or disables the TIM Capture Compare Channel xN. |
phungductung | 0:8ede47d38d10 | 2343 | * @param TIMx to select the TIM peripheral |
phungductung | 0:8ede47d38d10 | 2344 | * @param Channel: specifies the TIM Channel |
phungductung | 0:8ede47d38d10 | 2345 | * This parameter can be one of the following values: |
phungductung | 0:8ede47d38d10 | 2346 | * @arg TIM_Channel_1: TIM Channel 1 |
phungductung | 0:8ede47d38d10 | 2347 | * @arg TIM_Channel_2: TIM Channel 2 |
phungductung | 0:8ede47d38d10 | 2348 | * @arg TIM_Channel_3: TIM Channel 3 |
phungductung | 0:8ede47d38d10 | 2349 | * @param ChannelNState: specifies the TIM Channel CCxNE bit new state. |
phungductung | 0:8ede47d38d10 | 2350 | * This parameter can be: TIM_CCxN_ENABLE or TIM_CCxN_Disable. |
phungductung | 0:8ede47d38d10 | 2351 | * @retval None |
phungductung | 0:8ede47d38d10 | 2352 | */ |
phungductung | 0:8ede47d38d10 | 2353 | static void TIM_CCxNChannelCmd(TIM_TypeDef* TIMx, uint32_t Channel, uint32_t ChannelNState) |
phungductung | 0:8ede47d38d10 | 2354 | { |
phungductung | 0:8ede47d38d10 | 2355 | uint32_t tmp = 0; |
phungductung | 0:8ede47d38d10 | 2356 | |
phungductung | 0:8ede47d38d10 | 2357 | /* Check the parameters */ |
phungductung | 0:8ede47d38d10 | 2358 | assert_param(IS_TIM_ADVANCED_INSTANCE(TIMx)); |
phungductung | 0:8ede47d38d10 | 2359 | assert_param(IS_TIM_COMPLEMENTARY_CHANNELS(Channel)); |
phungductung | 0:8ede47d38d10 | 2360 | |
phungductung | 0:8ede47d38d10 | 2361 | tmp = TIM_CCER_CC1NE << Channel; |
phungductung | 0:8ede47d38d10 | 2362 | |
phungductung | 0:8ede47d38d10 | 2363 | /* Reset the CCxNE Bit */ |
phungductung | 0:8ede47d38d10 | 2364 | TIMx->CCER &= ~tmp; |
phungductung | 0:8ede47d38d10 | 2365 | |
phungductung | 0:8ede47d38d10 | 2366 | /* Set or reset the CCxNE Bit */ |
phungductung | 0:8ede47d38d10 | 2367 | TIMx->CCER |= (uint32_t)(ChannelNState << Channel); |
phungductung | 0:8ede47d38d10 | 2368 | } |
phungductung | 0:8ede47d38d10 | 2369 | |
phungductung | 0:8ede47d38d10 | 2370 | /** |
phungductung | 0:8ede47d38d10 | 2371 | * @brief Timer Output Compare 5 configuration |
phungductung | 0:8ede47d38d10 | 2372 | * @param TIMx to select the TIM peripheral |
phungductung | 0:8ede47d38d10 | 2373 | * @param OC_Config: The output configuration structure |
phungductung | 0:8ede47d38d10 | 2374 | * @retval None |
phungductung | 0:8ede47d38d10 | 2375 | */ |
phungductung | 0:8ede47d38d10 | 2376 | static void TIM_OC5_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config) |
phungductung | 0:8ede47d38d10 | 2377 | { |
phungductung | 0:8ede47d38d10 | 2378 | uint32_t tmpccmrx = 0; |
phungductung | 0:8ede47d38d10 | 2379 | uint32_t tmpccer = 0; |
phungductung | 0:8ede47d38d10 | 2380 | uint32_t tmpcr2 = 0; |
phungductung | 0:8ede47d38d10 | 2381 | |
phungductung | 0:8ede47d38d10 | 2382 | /* Disable the output: Reset the CCxE Bit */ |
phungductung | 0:8ede47d38d10 | 2383 | TIMx->CCER &= ~TIM_CCER_CC5E; |
phungductung | 0:8ede47d38d10 | 2384 | |
phungductung | 0:8ede47d38d10 | 2385 | /* Get the TIMx CCER register value */ |
phungductung | 0:8ede47d38d10 | 2386 | tmpccer = TIMx->CCER; |
phungductung | 0:8ede47d38d10 | 2387 | /* Get the TIMx CR2 register value */ |
phungductung | 0:8ede47d38d10 | 2388 | tmpcr2 = TIMx->CR2; |
phungductung | 0:8ede47d38d10 | 2389 | /* Get the TIMx CCMR1 register value */ |
phungductung | 0:8ede47d38d10 | 2390 | tmpccmrx = TIMx->CCMR3; |
phungductung | 0:8ede47d38d10 | 2391 | |
phungductung | 0:8ede47d38d10 | 2392 | /* Reset the Output Compare Mode Bits */ |
phungductung | 0:8ede47d38d10 | 2393 | tmpccmrx &= ~(TIM_CCMR3_OC5M); |
phungductung | 0:8ede47d38d10 | 2394 | /* Select the Output Compare Mode */ |
phungductung | 0:8ede47d38d10 | 2395 | tmpccmrx |= OC_Config->OCMode; |
phungductung | 0:8ede47d38d10 | 2396 | |
phungductung | 0:8ede47d38d10 | 2397 | /* Reset the Output Polarity level */ |
phungductung | 0:8ede47d38d10 | 2398 | tmpccer &= ~TIM_CCER_CC5P; |
phungductung | 0:8ede47d38d10 | 2399 | /* Set the Output Compare Polarity */ |
phungductung | 0:8ede47d38d10 | 2400 | tmpccer |= (OC_Config->OCPolarity << 16); |
phungductung | 0:8ede47d38d10 | 2401 | |
phungductung | 0:8ede47d38d10 | 2402 | if(IS_TIM_BREAK_INSTANCE(TIMx)) |
phungductung | 0:8ede47d38d10 | 2403 | { |
phungductung | 0:8ede47d38d10 | 2404 | /* Reset the Output Compare IDLE State */ |
phungductung | 0:8ede47d38d10 | 2405 | tmpcr2 &= ~TIM_CR2_OIS5; |
phungductung | 0:8ede47d38d10 | 2406 | /* Set the Output Idle state */ |
phungductung | 0:8ede47d38d10 | 2407 | tmpcr2 |= (OC_Config->OCIdleState << 8); |
phungductung | 0:8ede47d38d10 | 2408 | } |
phungductung | 0:8ede47d38d10 | 2409 | /* Write to TIMx CR2 */ |
phungductung | 0:8ede47d38d10 | 2410 | TIMx->CR2 = tmpcr2; |
phungductung | 0:8ede47d38d10 | 2411 | |
phungductung | 0:8ede47d38d10 | 2412 | /* Write to TIMx CCMR3 */ |
phungductung | 0:8ede47d38d10 | 2413 | TIMx->CCMR3 = tmpccmrx; |
phungductung | 0:8ede47d38d10 | 2414 | |
phungductung | 0:8ede47d38d10 | 2415 | /* Set the Capture Compare Register value */ |
phungductung | 0:8ede47d38d10 | 2416 | TIMx->CCR5 = OC_Config->Pulse; |
phungductung | 0:8ede47d38d10 | 2417 | |
phungductung | 0:8ede47d38d10 | 2418 | /* Write to TIMx CCER */ |
phungductung | 0:8ede47d38d10 | 2419 | TIMx->CCER = tmpccer; |
phungductung | 0:8ede47d38d10 | 2420 | } |
phungductung | 0:8ede47d38d10 | 2421 | |
phungductung | 0:8ede47d38d10 | 2422 | /** |
phungductung | 0:8ede47d38d10 | 2423 | * @brief Timer Output Compare 6 configuration |
phungductung | 0:8ede47d38d10 | 2424 | * @param TIMx to select the TIM peripheral |
phungductung | 0:8ede47d38d10 | 2425 | * @param OC_Config: The output configuration structure |
phungductung | 0:8ede47d38d10 | 2426 | * @retval None |
phungductung | 0:8ede47d38d10 | 2427 | */ |
phungductung | 0:8ede47d38d10 | 2428 | static void TIM_OC6_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config) |
phungductung | 0:8ede47d38d10 | 2429 | { |
phungductung | 0:8ede47d38d10 | 2430 | uint32_t tmpccmrx = 0; |
phungductung | 0:8ede47d38d10 | 2431 | uint32_t tmpccer = 0; |
phungductung | 0:8ede47d38d10 | 2432 | uint32_t tmpcr2 = 0; |
phungductung | 0:8ede47d38d10 | 2433 | |
phungductung | 0:8ede47d38d10 | 2434 | /* Disable the output: Reset the CCxE Bit */ |
phungductung | 0:8ede47d38d10 | 2435 | TIMx->CCER &= ~TIM_CCER_CC6E; |
phungductung | 0:8ede47d38d10 | 2436 | |
phungductung | 0:8ede47d38d10 | 2437 | /* Get the TIMx CCER register value */ |
phungductung | 0:8ede47d38d10 | 2438 | tmpccer = TIMx->CCER; |
phungductung | 0:8ede47d38d10 | 2439 | /* Get the TIMx CR2 register value */ |
phungductung | 0:8ede47d38d10 | 2440 | tmpcr2 = TIMx->CR2; |
phungductung | 0:8ede47d38d10 | 2441 | /* Get the TIMx CCMR1 register value */ |
phungductung | 0:8ede47d38d10 | 2442 | tmpccmrx = TIMx->CCMR3; |
phungductung | 0:8ede47d38d10 | 2443 | |
phungductung | 0:8ede47d38d10 | 2444 | /* Reset the Output Compare Mode Bits */ |
phungductung | 0:8ede47d38d10 | 2445 | tmpccmrx &= ~(TIM_CCMR3_OC6M); |
phungductung | 0:8ede47d38d10 | 2446 | /* Select the Output Compare Mode */ |
phungductung | 0:8ede47d38d10 | 2447 | tmpccmrx |= (OC_Config->OCMode << 8); |
phungductung | 0:8ede47d38d10 | 2448 | |
phungductung | 0:8ede47d38d10 | 2449 | /* Reset the Output Polarity level */ |
phungductung | 0:8ede47d38d10 | 2450 | tmpccer &= (uint32_t)~TIM_CCER_CC6P; |
phungductung | 0:8ede47d38d10 | 2451 | /* Set the Output Compare Polarity */ |
phungductung | 0:8ede47d38d10 | 2452 | tmpccer |= (OC_Config->OCPolarity << 20); |
phungductung | 0:8ede47d38d10 | 2453 | |
phungductung | 0:8ede47d38d10 | 2454 | if(IS_TIM_BREAK_INSTANCE(TIMx)) |
phungductung | 0:8ede47d38d10 | 2455 | { |
phungductung | 0:8ede47d38d10 | 2456 | /* Reset the Output Compare IDLE State */ |
phungductung | 0:8ede47d38d10 | 2457 | tmpcr2 &= ~TIM_CR2_OIS6; |
phungductung | 0:8ede47d38d10 | 2458 | /* Set the Output Idle state */ |
phungductung | 0:8ede47d38d10 | 2459 | tmpcr2 |= (OC_Config->OCIdleState << 10); |
phungductung | 0:8ede47d38d10 | 2460 | } |
phungductung | 0:8ede47d38d10 | 2461 | |
phungductung | 0:8ede47d38d10 | 2462 | /* Write to TIMx CR2 */ |
phungductung | 0:8ede47d38d10 | 2463 | TIMx->CR2 = tmpcr2; |
phungductung | 0:8ede47d38d10 | 2464 | |
phungductung | 0:8ede47d38d10 | 2465 | /* Write to TIMx CCMR3 */ |
phungductung | 0:8ede47d38d10 | 2466 | TIMx->CCMR3 = tmpccmrx; |
phungductung | 0:8ede47d38d10 | 2467 | |
phungductung | 0:8ede47d38d10 | 2468 | /* Set the Capture Compare Register value */ |
phungductung | 0:8ede47d38d10 | 2469 | TIMx->CCR6 = OC_Config->Pulse; |
phungductung | 0:8ede47d38d10 | 2470 | |
phungductung | 0:8ede47d38d10 | 2471 | /* Write to TIMx CCER */ |
phungductung | 0:8ede47d38d10 | 2472 | TIMx->CCER = tmpccer; |
phungductung | 0:8ede47d38d10 | 2473 | } |
phungductung | 0:8ede47d38d10 | 2474 | |
phungductung | 0:8ede47d38d10 | 2475 | /** |
phungductung | 0:8ede47d38d10 | 2476 | * @} |
phungductung | 0:8ede47d38d10 | 2477 | */ |
phungductung | 0:8ede47d38d10 | 2478 | |
phungductung | 0:8ede47d38d10 | 2479 | #endif /* HAL_TIM_MODULE_ENABLED */ |
phungductung | 0:8ede47d38d10 | 2480 | /** |
phungductung | 0:8ede47d38d10 | 2481 | * @} |
phungductung | 0:8ede47d38d10 | 2482 | */ |
phungductung | 0:8ede47d38d10 | 2483 | |
phungductung | 0:8ede47d38d10 | 2484 | /** |
phungductung | 0:8ede47d38d10 | 2485 | * @} |
phungductung | 0:8ede47d38d10 | 2486 | */ |
phungductung | 0:8ede47d38d10 | 2487 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |