inport from local

Dependents:   Hobbyking_Cheetah_0511

Committer:
NYX
Date:
Mon Mar 16 06:35:48 2020 +0000
Revision:
0:85b3fd62ea1a
reinport to mbed;

Who changed what in which revision?

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