Arrow / Mbed OS DAPLink Reset
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers stm32f1xx_hal_tim_ex.c Source File

stm32f1xx_hal_tim_ex.c

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32f1xx_hal_tim_ex.c
00004   * @author  MCD Application Team
00005   * @version V1.0.4
00006   * @date    29-April-2016
00007   * @brief   TIM HAL module driver.
00008   *          This file provides firmware functions to manage the following
00009   *          functionalities of the Timer Extended peripheral:
00010   *           + Time Hall Sensor Interface Initialization
00011   *           + Time Hall Sensor Interface Start
00012   *           + Time Complementary signal bread and dead time configuration
00013   *           + Time Master and Slave synchronization configuration
00014   *           + Timer remapping capabilities configuration
00015   @verbatim
00016   ==============================================================================
00017                       ##### TIMER Extended features #####
00018   ==============================================================================
00019   [..]
00020     The Timer Extended features include:
00021     (#) Complementary outputs with programmable dead-time for :
00022         (++) Output Compare
00023         (++) PWM generation (Edge and Center-aligned Mode)
00024         (++) One-pulse mode output
00025     (#) Synchronization circuit to control the timer with external signals and to
00026         interconnect several timers together.
00027     (#) Break input to put the timer output signals in reset state or in a known state.
00028     (#) Supports incremental (quadrature) encoder and hall-sensor circuitry for
00029         positioning purposes
00030 
00031             ##### How to use this driver #####
00032   ==============================================================================
00033     [..]
00034      (#) Initialize the TIM low level resources by implementing the following functions
00035          depending from feature used :
00036            (++) Complementary Output Compare : HAL_TIM_OC_MspInit()
00037            (++) Complementary PWM generation : HAL_TIM_PWM_MspInit()
00038            (++) Complementary One-pulse mode output : HAL_TIM_OnePulse_MspInit()
00039            (++) Hall Sensor output : HAL_TIMEx_HallSensor_MspInit()
00040 
00041      (#) Initialize the TIM low level resources :
00042         (##) Enable the TIM interface clock using __HAL_RCC_TIMx_CLK_ENABLE();
00043         (##) TIM pins configuration
00044             (+++) Enable the clock for the TIM GPIOs using the following function:
00045               __HAL_RCC_GPIOx_CLK_ENABLE();
00046             (+++) Configure these TIM pins in Alternate function mode using HAL_GPIO_Init();
00047 
00048      (#) The external Clock can be configured, if needed (the default clock is the
00049          internal clock from the APBx), using the following function:
00050          HAL_TIM_ConfigClockSource, the clock configuration should be done before
00051          any start function.
00052 
00053      (#) Configure the TIM in the desired functioning mode using one of the
00054          initialization function of this driver:
00055           (++) HAL_TIMEx_HallSensor_Init and HAL_TIMEx_ConfigCommutationEvent: to use the
00056               Timer Hall Sensor Interface and the commutation event with the corresponding
00057               Interrupt and DMA request if needed (Note that One Timer is used to interface
00058              with the Hall sensor Interface and another Timer should be used to use
00059              the commutation event).
00060 
00061      (#) Activate the TIM peripheral using one of the start functions:
00062            (++) Complementary Output Compare : HAL_TIMEx_OCN_Start(), HAL_TIMEx_OCN_Start_DMA(), HAL_TIMEx_OCN_Start_IT()
00063            (++) Complementary PWM generation : HAL_TIMEx_PWMN_Start(), HAL_TIMEx_PWMN_Start_DMA(), HAL_TIMEx_PWMN_Start_IT()
00064            (++) Complementary One-pulse mode output : HAL_TIMEx_OnePulseN_Start(), HAL_TIMEx_OnePulseN_Start_IT()
00065            (++) Hall Sensor output : HAL_TIMEx_HallSensor_Start(), HAL_TIMEx_HallSensor_Start_DMA(), HAL_TIMEx_HallSensor_Start_IT().
00066 
00067 
00068   @endverbatim
00069   ******************************************************************************
00070   * @attention
00071   *
00072   * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
00073   *
00074   * Redistribution and use in source and binary forms, with or without modification,
00075   * are permitted provided that the following conditions are met:
00076   *   1. Redistributions of source code must retain the above copyright notice,
00077   *      this list of conditions and the following disclaimer.
00078   *   2. Redistributions in binary form must reproduce the above copyright notice,
00079   *      this list of conditions and the following disclaimer in the documentation
00080   *      and/or other materials provided with the distribution.
00081   *   3. Neither the name of STMicroelectronics nor the names of its contributors
00082   *      may be used to endorse or promote products derived from this software
00083   *      without specific prior written permission.
00084   *
00085   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00086   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00087   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00088   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00089   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00090   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00091   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00092   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00093   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00094   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00095   *
00096   ******************************************************************************
00097 */
00098 
00099 /* Includes ------------------------------------------------------------------*/
00100 #include "stm32f1xx_hal.h"
00101 
00102 /** @addtogroup STM32F1xx_HAL_Driver
00103   * @{
00104   */
00105 
00106 /** @defgroup TIMEx TIMEx
00107   * @brief TIM Extended HAL module driver
00108   * @{
00109   */
00110 
00111 #ifdef HAL_TIM_MODULE_ENABLED
00112 
00113 /* Private typedef -----------------------------------------------------------*/
00114 /* Private define ------------------------------------------------------------*/
00115 /* Private macro -------------------------------------------------------------*/
00116 /* Private variables ---------------------------------------------------------*/
00117 /* Private function prototypes -----------------------------------------------*/
00118 
00119 #if defined (STM32F100xB) || defined (STM32F100xE) ||                                                   \
00120     defined (STM32F103x6) || defined (STM32F103xB) || defined (STM32F103xE) || defined (STM32F103xG) || \
00121     defined (STM32F105xC) || defined (STM32F107xC)
00122 /** @defgroup TIMEx_Private_Functions TIMEx Private Functions
00123   * @{
00124   */
00125 static void TIM_CCxNChannelCmd(TIM_TypeDef* TIMx, uint32_t Channel, uint32_t ChannelNState);
00126 /**
00127   * @}
00128   */
00129 #endif /* defined(STM32F100xB) || defined(STM32F100xE) ||                                                 */
00130        /* defined(STM32F103x6) || defined(STM32F103xB) || defined(STM32F103xE) || defined(STM32F103xG) || */
00131        /* defined(STM32F105xC) || defined(STM32F107xC)                                                    */
00132 
00133 /* Exported functions ---------------------------------------------------------*/
00134 
00135 /** @defgroup TIMEx_Exported_Functions TIMEx Exported Functions
00136   * @{
00137   */
00138 
00139 
00140 /** @defgroup TIMEx_Exported_Functions_Group1 Timer Hall Sensor functions
00141  *  @brief    Timer Hall Sensor functions
00142  *
00143 @verbatim
00144   ==============================================================================
00145                       ##### Timer Hall Sensor functions #####
00146   ==============================================================================
00147   [..]
00148     This section provides functions allowing to:
00149     (+) Initialize and configure TIM HAL Sensor.
00150     (+) De-initialize TIM HAL Sensor.
00151     (+) Start the Hall Sensor Interface.
00152     (+) Stop the Hall Sensor Interface.
00153     (+) Start the Hall Sensor Interface and enable interrupts.
00154     (+) Stop the Hall Sensor Interface and disable interrupts.
00155     (+) Start the Hall Sensor Interface and enable DMA transfers.
00156     (+) Stop the Hall Sensor Interface and disable DMA transfers.
00157 
00158 @endverbatim
00159   * @{
00160   */
00161 /**
00162   * @brief  Initializes the TIM Hall Sensor Interface and create the associated handle.
00163   * @param  htim : TIM Encoder Interface handle
00164   * @param  sConfig : TIM Hall Sensor configuration structure
00165   * @retval HAL status
00166   */
00167 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Init(TIM_HandleTypeDef *htim, TIM_HallSensor_InitTypeDef* sConfig)
00168 {
00169   TIM_OC_InitTypeDef OC_Config;
00170 
00171   /* Check the TIM handle allocation */
00172   if(htim == NULL)
00173   {
00174     return HAL_ERROR;
00175   }
00176 
00177   assert_param(IS_TIM_XOR_INSTANCE(htim->Instance));
00178   assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode));
00179   assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision));
00180   assert_param(IS_TIM_IC_POLARITY(sConfig->IC1Polarity));
00181   assert_param(IS_TIM_IC_PRESCALER(sConfig->IC1Prescaler));
00182   assert_param(IS_TIM_IC_FILTER(sConfig->IC1Filter));
00183 
00184   if(htim->State == HAL_TIM_STATE_RESET)
00185   {
00186     /* Allocate lock resource and initialize it */
00187     htim->Lock = HAL_UNLOCKED;
00188     
00189     /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */
00190     HAL_TIMEx_HallSensor_MspInit(htim);
00191   }
00192 
00193   /* Set the TIM state */
00194   htim->State= HAL_TIM_STATE_BUSY;
00195 
00196   /* Configure the Time base in the Encoder Mode */
00197   TIM_Base_SetConfig(htim->Instance, &htim->Init);
00198 
00199   /* Configure the Channel 1 as Input Channel to interface with the three Outputs of the  Hall sensor */
00200   TIM_TI1_SetConfig(htim->Instance, sConfig->IC1Polarity, TIM_ICSELECTION_TRC, sConfig->IC1Filter);
00201 
00202   /* Reset the IC1PSC Bits */
00203   htim->Instance->CCMR1 &= ~TIM_CCMR1_IC1PSC;
00204   /* Set the IC1PSC value */
00205   htim->Instance->CCMR1 |= sConfig->IC1Prescaler;
00206 
00207   /* Enable the Hall sensor interface (XOR function of the three inputs) */
00208   htim->Instance->CR2 |= TIM_CR2_TI1S;
00209 
00210   /* Select the TIM_TS_TI1F_ED signal as Input trigger for the TIM */
00211   htim->Instance->SMCR &= ~TIM_SMCR_TS;
00212   htim->Instance->SMCR |= TIM_TS_TI1F_ED;
00213 
00214   /* Use the TIM_TS_TI1F_ED signal to reset the TIM counter each edge detection */
00215   htim->Instance->SMCR &= ~TIM_SMCR_SMS;
00216   htim->Instance->SMCR |= TIM_SLAVEMODE_RESET;
00217 
00218   /* Program channel 2 in PWM 2 mode with the desired Commutation_Delay*/
00219   OC_Config.OCFastMode = TIM_OCFAST_DISABLE;
00220   OC_Config.OCIdleState = TIM_OCIDLESTATE_RESET;
00221   OC_Config.OCMode = TIM_OCMODE_PWM2;
00222   OC_Config.OCNIdleState = TIM_OCNIDLESTATE_RESET;
00223   OC_Config.OCNPolarity = TIM_OCNPOLARITY_HIGH;
00224   OC_Config.OCPolarity = TIM_OCPOLARITY_HIGH;
00225   OC_Config.Pulse = sConfig->Commutation_Delay;
00226 
00227   TIM_OC2_SetConfig(htim->Instance, &OC_Config);
00228 
00229   /* Select OC2REF as trigger output on TRGO: write the MMS bits in the TIMx_CR2
00230     register to 101 */
00231   htim->Instance->CR2 &= ~TIM_CR2_MMS;
00232   htim->Instance->CR2 |= TIM_TRGO_OC2REF;
00233 
00234   /* Initialize the TIM state*/
00235   htim->State= HAL_TIM_STATE_READY;
00236 
00237   return HAL_OK;
00238 }
00239 
00240 /**
00241   * @brief  DeInitializes the TIM Hall Sensor interface
00242   * @param  htim : TIM Hall Sensor handle
00243   * @retval HAL status
00244   */
00245 HAL_StatusTypeDef HAL_TIMEx_HallSensor_DeInit(TIM_HandleTypeDef *htim)
00246 {
00247   /* Check the parameters */
00248   assert_param(IS_TIM_INSTANCE(htim->Instance));
00249 
00250   htim->State = HAL_TIM_STATE_BUSY;
00251 
00252   /* Disable the TIM Peripheral Clock */
00253   __HAL_TIM_DISABLE(htim);
00254 
00255   /* DeInit the low level hardware: GPIO, CLOCK, NVIC */
00256   HAL_TIMEx_HallSensor_MspDeInit(htim);
00257 
00258   /* Change TIM state */
00259   htim->State = HAL_TIM_STATE_RESET;
00260 
00261   /* Release Lock */
00262   __HAL_UNLOCK(htim);
00263 
00264   return HAL_OK;
00265 }
00266 
00267 /**
00268   * @brief  Initializes the TIM Hall Sensor MSP.
00269   * @param  htim : TIM handle
00270   * @retval None
00271   */
00272 __weak void HAL_TIMEx_HallSensor_MspInit(TIM_HandleTypeDef *htim)
00273 {
00274   /* Prevent unused argument(s) compilation warning */
00275   UNUSED(htim);
00276   /* NOTE : This function Should not be modified, when the callback is needed,
00277             the HAL_TIMEx_HallSensor_MspInit could be implemented in the user file
00278    */
00279 }
00280 
00281 /**
00282   * @brief  DeInitializes TIM Hall Sensor MSP.
00283   * @param  htim : TIM handle
00284   * @retval None
00285   */
00286 __weak void HAL_TIMEx_HallSensor_MspDeInit(TIM_HandleTypeDef *htim)
00287 {
00288   /* Prevent unused argument(s) compilation warning */
00289   UNUSED(htim);
00290   /* NOTE : This function Should not be modified, when the callback is needed,
00291             the HAL_TIMEx_HallSensor_MspDeInit could be implemented in the user file
00292    */
00293 }
00294 
00295 /**
00296   * @brief  Starts the TIM Hall Sensor Interface.
00297   * @param  htim : TIM Hall Sensor handle
00298   * @retval HAL status
00299   */
00300 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start(TIM_HandleTypeDef *htim)
00301 {
00302   /* Check the parameters */
00303   assert_param(IS_TIM_XOR_INSTANCE(htim->Instance));
00304 
00305   /* Enable the Input Capture channel 1
00306     (in the Hall Sensor Interface the 3 possible channels that are used are TIM_CHANNEL_1, TIM_CHANNEL_2 and TIM_CHANNEL_3) */
00307   TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
00308 
00309   /* Enable the Peripheral */
00310   __HAL_TIM_ENABLE(htim);
00311 
00312   /* Return function status */
00313   return HAL_OK;
00314 }
00315 
00316 /**
00317   * @brief  Stops the TIM Hall sensor Interface.
00318   * @param  htim : TIM Hall Sensor handle
00319   * @retval HAL status
00320   */
00321 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop(TIM_HandleTypeDef *htim)
00322 {
00323   /* Check the parameters */
00324   assert_param(IS_TIM_XOR_INSTANCE(htim->Instance));
00325 
00326   /* Disable the Input Capture channel 1
00327     (in the Hall Sensor Interface the 3 possible channels that are used are TIM_CHANNEL_1, TIM_CHANNEL_2 and TIM_CHANNEL_3) */
00328   TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
00329 
00330   /* Disable the Peripheral */
00331   __HAL_TIM_DISABLE(htim);
00332 
00333   /* Return function status */
00334   return HAL_OK;
00335 }
00336 
00337 /**
00338   * @brief  Starts the TIM Hall Sensor Interface in interrupt mode.
00339   * @param  htim : TIM Hall Sensor handle
00340   * @retval HAL status
00341   */
00342 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start_IT(TIM_HandleTypeDef *htim)
00343 {
00344   /* Check the parameters */
00345   assert_param(IS_TIM_XOR_INSTANCE(htim->Instance));
00346 
00347   /* Enable the capture compare Interrupts 1 event */
00348   __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
00349 
00350   /* Enable the Input Capture channel 1
00351     (in the Hall Sensor Interface the 3 possible channels that are used are TIM_CHANNEL_1, TIM_CHANNEL_2 and TIM_CHANNEL_3) */
00352   TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
00353 
00354   /* Enable the Peripheral */
00355   __HAL_TIM_ENABLE(htim);
00356 
00357   /* Return function status */
00358   return HAL_OK;
00359 }
00360 
00361 /**
00362   * @brief  Stops the TIM Hall Sensor Interface in interrupt mode.
00363   * @param  htim : TIM handle
00364   * @retval HAL status
00365   */
00366 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_IT(TIM_HandleTypeDef *htim)
00367 {
00368   /* Check the parameters */
00369   assert_param(IS_TIM_XOR_INSTANCE(htim->Instance));
00370 
00371   /* Disable the Input Capture channel 1
00372     (in the Hall Sensor Interface the 3 possible channels that are used are TIM_CHANNEL_1, TIM_CHANNEL_2 and TIM_CHANNEL_3) */
00373   TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
00374 
00375   /* Disable the capture compare Interrupts event */
00376   __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
00377 
00378   /* Disable the Peripheral */
00379   __HAL_TIM_DISABLE(htim);
00380 
00381   /* Return function status */
00382   return HAL_OK;
00383 }
00384 
00385 /**
00386   * @brief  Starts the TIM Hall Sensor Interface in DMA mode.
00387   * @param  htim : TIM Hall Sensor handle
00388   * @param  pData : The destination Buffer address.
00389   * @param  Length : The length of data to be transferred from TIM peripheral to memory.
00390   * @retval HAL status
00391   */
00392 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start_DMA(TIM_HandleTypeDef *htim, uint32_t *pData, uint16_t Length)
00393 {
00394   /* Check the parameters */
00395   assert_param(IS_TIM_XOR_INSTANCE(htim->Instance));
00396 
00397    if((htim->State == HAL_TIM_STATE_BUSY))
00398   {
00399      return HAL_BUSY;
00400   }
00401   else if((htim->State == HAL_TIM_STATE_READY))
00402   {
00403     if(((uint32_t)pData == 0 ) && (Length > 0))
00404     {
00405       return HAL_ERROR;
00406     }
00407     else
00408     {
00409       htim->State = HAL_TIM_STATE_BUSY;
00410     }
00411   }
00412   /* Enable the Input Capture channel 1
00413     (in the Hall Sensor Interface the 3 possible channels that are used are TIM_CHANNEL_1, TIM_CHANNEL_2 and TIM_CHANNEL_3) */
00414   TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
00415 
00416   /* Set the DMA Input Capture 1 Callback */
00417   htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMACaptureCplt;
00418   /* Set the DMA error callback */
00419   htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ;
00420 
00421   /* Enable the DMA channel for Capture 1*/
00422   HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)&htim->Instance->CCR1, (uint32_t)pData, Length);
00423 
00424   /* Enable the capture compare 1 Interrupt */
00425   __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1);
00426 
00427   /* Enable the Peripheral */
00428   __HAL_TIM_ENABLE(htim);
00429 
00430   /* Return function status */
00431   return HAL_OK;
00432 }
00433 
00434 /**
00435   * @brief  Stops the TIM Hall Sensor Interface in DMA mode.
00436   * @param  htim : TIM handle
00437   * @retval HAL status
00438   */
00439 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_DMA(TIM_HandleTypeDef *htim)
00440 {
00441   /* Check the parameters */
00442   assert_param(IS_TIM_XOR_INSTANCE(htim->Instance));
00443 
00444   /* Disable the Input Capture channel 1
00445     (in the Hall Sensor Interface the 3 possible channels that are used are TIM_CHANNEL_1, TIM_CHANNEL_2 and TIM_CHANNEL_3) */
00446   TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
00447 
00448 
00449   /* Disable the capture compare Interrupts 1 event */
00450   __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1);
00451 
00452   /* Disable the Peripheral */
00453   __HAL_TIM_DISABLE(htim);
00454 
00455   /* Return function status */
00456   return HAL_OK;
00457 }
00458 
00459 /**
00460   * @}
00461   */
00462 
00463 #if defined (STM32F100xB) || defined (STM32F100xE) ||                                                   \
00464     defined (STM32F103x6) || defined (STM32F103xB) || defined (STM32F103xE) || defined (STM32F103xG) || \
00465     defined (STM32F105xC) || defined (STM32F107xC)
00466 
00467 /** @defgroup TIMEx_Exported_Functions_Group2 Timer Complementary Output Compare functions
00468  *  @brief    Timer Complementary Output Compare functions
00469  *
00470 @verbatim
00471   ==============================================================================
00472               ##### Timer Complementary Output Compare functions #####
00473   ==============================================================================
00474   [..]
00475     This section provides functions allowing to:
00476     (+) Start the Complementary Output Compare/PWM.
00477     (+) Stop the Complementary Output Compare/PWM.
00478     (+) Start the Complementary Output Compare/PWM and enable interrupts.
00479     (+) Stop the Complementary Output Compare/PWM and disable interrupts.
00480     (+) Start the Complementary Output Compare/PWM and enable DMA transfers.
00481     (+) Stop the Complementary Output Compare/PWM and disable DMA transfers.
00482 
00483 @endverbatim
00484   * @{
00485   */
00486 
00487 /**
00488   * @brief  Starts the TIM Output Compare signal generation on the complementary
00489   *         output.
00490   * @param  htim : TIM Output Compare handle
00491   * @param  Channel : TIM Channel to be enabled
00492   *          This parameter can be one of the following values:
00493   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected
00494   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected
00495   *            @arg TIM_CHANNEL_3: TIM Channel 3 selected
00496   *            @arg TIM_CHANNEL_4: TIM Channel 4 selected
00497   * @retval HAL status
00498   */
00499 HAL_StatusTypeDef HAL_TIMEx_OCN_Start(TIM_HandleTypeDef *htim, uint32_t Channel)
00500 {
00501   /* Check the parameters */
00502   assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
00503 
00504   /* Enable the Capture compare channel N */
00505   TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_ENABLE);
00506 
00507   /* Enable the Main Ouput */
00508   __HAL_TIM_MOE_ENABLE(htim);
00509 
00510   /* Enable the Peripheral */
00511   __HAL_TIM_ENABLE(htim);
00512 
00513   /* Return function status */
00514   return HAL_OK;
00515 }
00516 
00517 /**
00518   * @brief  Stops the TIM Output Compare signal generation on the complementary
00519   *         output.
00520   * @param  htim : TIM handle
00521   * @param  Channel : TIM Channel to be disabled
00522   *          This parameter can be one of the following values:
00523   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected
00524   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected
00525   *            @arg TIM_CHANNEL_3: TIM Channel 3 selected
00526   *            @arg TIM_CHANNEL_4: TIM Channel 4 selected
00527   * @retval HAL status
00528   */
00529 HAL_StatusTypeDef HAL_TIMEx_OCN_Stop(TIM_HandleTypeDef *htim, uint32_t Channel)
00530 {
00531   /* Check the parameters */
00532   assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
00533 
00534   /* Disable the Capture compare channel N */
00535   TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_DISABLE);
00536 
00537   /* Disable the Main Ouput */
00538   __HAL_TIM_MOE_DISABLE(htim);
00539 
00540   /* Disable the Peripheral */
00541   __HAL_TIM_DISABLE(htim);
00542 
00543   /* Return function status */
00544   return HAL_OK;
00545 }
00546 
00547 /**
00548   * @brief  Starts the TIM Output Compare signal generation in interrupt mode
00549   *         on the complementary output.
00550   * @param  htim : TIM OC handle
00551   * @param  Channel : TIM Channel to be enabled
00552   *          This parameter can be one of the following values:
00553   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected
00554   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected
00555   *            @arg TIM_CHANNEL_3: TIM Channel 3 selected
00556   *            @arg TIM_CHANNEL_4: TIM Channel 4 selected
00557   * @retval HAL status
00558   */
00559 HAL_StatusTypeDef HAL_TIMEx_OCN_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
00560 {
00561   /* Check the parameters */
00562   assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
00563 
00564   switch (Channel)
00565   {
00566     case TIM_CHANNEL_1:
00567     {
00568       /* Enable the TIM Output Compare interrupt */
00569       __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
00570     }
00571     break;
00572 
00573     case TIM_CHANNEL_2:
00574     {
00575       /* Enable the TIM Output Compare interrupt */
00576       __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);
00577     }
00578     break;
00579 
00580     case TIM_CHANNEL_3:
00581     {
00582       /* Enable the TIM Output Compare interrupt */
00583       __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC3);
00584     }
00585     break;
00586 
00587     case TIM_CHANNEL_4:
00588     {
00589       /* Enable the TIM Output Compare interrupt */
00590       __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC4);
00591     }
00592     break;
00593 
00594     default:
00595     break;
00596   }
00597 
00598   /* Enable the TIM Break interrupt */
00599   __HAL_TIM_ENABLE_IT(htim, TIM_IT_BREAK);
00600 
00601   /* Enable the Capture compare channel N */
00602   TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_ENABLE);
00603 
00604   /* Enable the Main Ouput */
00605   __HAL_TIM_MOE_ENABLE(htim);
00606 
00607   /* Enable the Peripheral */
00608   __HAL_TIM_ENABLE(htim);
00609 
00610   /* Return function status */
00611   return HAL_OK;
00612 }
00613 
00614 /**
00615   * @brief  Stops the TIM Output Compare signal generation in interrupt mode
00616   *         on the complementary output.
00617   * @param  htim : TIM Output Compare handle
00618   * @param  Channel : TIM Channel to be disabled
00619   *          This parameter can be one of the following values:
00620   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected
00621   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected
00622   *            @arg TIM_CHANNEL_3: TIM Channel 3 selected
00623   *            @arg TIM_CHANNEL_4: TIM Channel 4 selected
00624   * @retval HAL status
00625   */
00626 HAL_StatusTypeDef HAL_TIMEx_OCN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
00627 {
00628   uint32_t tmpccer = 0;
00629 
00630   /* Check the parameters */
00631   assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
00632 
00633   switch (Channel)
00634   {
00635     case TIM_CHANNEL_1:
00636     {
00637       /* Disable the TIM Output Compare interrupt */
00638       __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
00639     }
00640     break;
00641 
00642     case TIM_CHANNEL_2:
00643     {
00644       /* Disable the TIM Output Compare interrupt */
00645       __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);
00646     }
00647     break;
00648 
00649     case TIM_CHANNEL_3:
00650     {
00651       /* Disable the TIM Output Compare interrupt */
00652       __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC3);
00653     }
00654     break;
00655 
00656     case TIM_CHANNEL_4:
00657     {
00658       /* Disable the TIM Output Compare interrupt */
00659       __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC4);
00660     }
00661     break;
00662 
00663     default:
00664     break;
00665   }
00666 
00667   /* Disable the Capture compare channel N */
00668   TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_DISABLE);
00669 
00670   /* Disable the TIM Break interrupt (only if no more channel is active) */
00671   tmpccer = htim->Instance->CCER;
00672   if ((tmpccer & (TIM_CCER_CC1NE | TIM_CCER_CC2NE | TIM_CCER_CC3NE)) == RESET)
00673   {
00674     __HAL_TIM_DISABLE_IT(htim, TIM_IT_BREAK);
00675   }
00676 
00677   /* Disable the Main Ouput */
00678   __HAL_TIM_MOE_DISABLE(htim);
00679 
00680   /* Disable the Peripheral */
00681   __HAL_TIM_DISABLE(htim);
00682 
00683   /* Return function status */
00684   return HAL_OK;
00685 }
00686 
00687 /**
00688   * @brief  Starts the TIM Output Compare signal generation in DMA mode
00689   *         on the complementary output.
00690   * @param  htim : TIM Output Compare handle
00691   * @param  Channel : TIM Channel to be enabled
00692   *          This parameter can be one of the following values:
00693   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected
00694   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected
00695   *            @arg TIM_CHANNEL_3: TIM Channel 3 selected
00696   *            @arg TIM_CHANNEL_4: TIM Channel 4 selected
00697   * @param  pData : The source Buffer address.
00698   * @param  Length : The length of data to be transferred from memory to TIM peripheral
00699   * @retval HAL status
00700   */
00701 HAL_StatusTypeDef HAL_TIMEx_OCN_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length)
00702 {
00703   /* Check the parameters */
00704   assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
00705 
00706   if((htim->State == HAL_TIM_STATE_BUSY))
00707   {
00708      return HAL_BUSY;
00709   }
00710   else if((htim->State == HAL_TIM_STATE_READY))
00711   {
00712     if(((uint32_t)pData == 0 ) && (Length > 0))
00713     {
00714       return HAL_ERROR;
00715     }
00716     else
00717     {
00718       htim->State = HAL_TIM_STATE_BUSY;
00719     }
00720   }
00721   switch (Channel)
00722   {
00723     case TIM_CHANNEL_1:
00724     {
00725       /* Set the DMA Period elapsed callback */
00726       htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMADelayPulseCplt;
00727 
00728       /* Set the DMA error callback */
00729       htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ;
00730 
00731       /* Enable the DMA channel */
00732       HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)pData, (uint32_t)&htim->Instance->CCR1, Length);
00733 
00734       /* Enable the TIM Output Compare DMA request */
00735       __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1);
00736     }
00737     break;
00738 
00739     case TIM_CHANNEL_2:
00740     {
00741       /* Set the DMA Period elapsed callback */
00742       htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMADelayPulseCplt;
00743 
00744       /* Set the DMA error callback */
00745       htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError ;
00746 
00747       /* Enable the DMA channel */
00748       HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)pData, (uint32_t)&htim->Instance->CCR2, Length);
00749 
00750       /* Enable the TIM Output Compare DMA request */
00751       __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2);
00752     }
00753     break;
00754 
00755     case TIM_CHANNEL_3:
00756 {
00757       /* Set the DMA Period elapsed callback */
00758       htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMADelayPulseCplt;
00759 
00760       /* Set the DMA error callback */
00761       htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = TIM_DMAError ;
00762 
00763       /* Enable the DMA channel */
00764       HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)pData, (uint32_t)&htim->Instance->CCR3,Length);
00765 
00766       /* Enable the TIM Output Compare DMA request */
00767       __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC3);
00768     }
00769     break;
00770 
00771     case TIM_CHANNEL_4:
00772     {
00773      /* Set the DMA Period elapsed callback */
00774       htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = TIM_DMADelayPulseCplt;
00775 
00776       /* Set the DMA error callback */
00777       htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = TIM_DMAError ;
00778 
00779       /* Enable the DMA channel */
00780       HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)pData, (uint32_t)&htim->Instance->CCR4, Length);
00781 
00782       /* Enable the TIM Output Compare DMA request */
00783       __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC4);
00784     }
00785     break;
00786 
00787     default:
00788     break;
00789   }
00790 
00791   /* Enable the Capture compare channel N */
00792   TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_ENABLE);
00793 
00794   /* Enable the Main Ouput */
00795   __HAL_TIM_MOE_ENABLE(htim);
00796 
00797   /* Enable the Peripheral */
00798   __HAL_TIM_ENABLE(htim);
00799 
00800   /* Return function status */
00801   return HAL_OK;
00802 }
00803 
00804 /**
00805   * @brief  Stops the TIM Output Compare signal generation in DMA mode
00806   *         on the complementary output.
00807   * @param  htim : TIM Output Compare handle
00808   * @param  Channel : TIM Channel to be disabled
00809   *          This parameter can be one of the following values:
00810   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected
00811   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected
00812   *            @arg TIM_CHANNEL_3: TIM Channel 3 selected
00813   *            @arg TIM_CHANNEL_4: TIM Channel 4 selected
00814   * @retval HAL status
00815   */
00816 HAL_StatusTypeDef HAL_TIMEx_OCN_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel)
00817 {
00818   /* Check the parameters */
00819   assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
00820 
00821   switch (Channel)
00822   {
00823     case TIM_CHANNEL_1:
00824     {
00825       /* Disable the TIM Output Compare DMA request */
00826       __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1);
00827     }
00828     break;
00829 
00830     case TIM_CHANNEL_2:
00831     {
00832       /* Disable the TIM Output Compare DMA request */
00833       __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2);
00834     }
00835     break;
00836 
00837     case TIM_CHANNEL_3:
00838     {
00839       /* Disable the TIM Output Compare DMA request */
00840       __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC3);
00841     }
00842     break;
00843 
00844     case TIM_CHANNEL_4:
00845     {
00846       /* Disable the TIM Output Compare interrupt */
00847       __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC4);
00848     }
00849     break;
00850 
00851     default:
00852     break;
00853   }
00854 
00855   /* Disable the Capture compare channel N */
00856   TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_DISABLE);
00857 
00858   /* Disable the Main Ouput */
00859   __HAL_TIM_MOE_DISABLE(htim);
00860 
00861   /* Disable the Peripheral */
00862   __HAL_TIM_DISABLE(htim);
00863 
00864   /* Change the htim state */
00865   htim->State = HAL_TIM_STATE_READY;
00866 
00867   /* Return function status */
00868   return HAL_OK;
00869 }
00870 
00871 /**
00872   * @}
00873   */
00874 
00875 /** @defgroup TIMEx_Exported_Functions_Group3 Timer Complementary PWM functions
00876  *  @brief    Timer Complementary PWM functions
00877  *
00878 @verbatim
00879   ==============================================================================
00880                  ##### Timer Complementary PWM functions #####
00881   ==============================================================================
00882   [..]
00883     This section provides functions allowing to:
00884     (+) Start the Complementary PWM.
00885     (+) Stop the Complementary PWM.
00886     (+) Start the Complementary PWM and enable interrupts.
00887     (+) Stop the Complementary PWM and disable interrupts.
00888     (+) Start the Complementary PWM and enable DMA transfers.
00889     (+) Stop the Complementary PWM and disable DMA transfers.
00890     (+) Start the Complementary Input Capture measurement.
00891     (+) Stop the Complementary Input Capture.
00892     (+) Start the Complementary Input Capture and enable interrupts.
00893     (+) Stop the Complementary Input Capture and disable interrupts.
00894     (+) Start the Complementary Input Capture and enable DMA transfers.
00895     (+) Stop the Complementary Input Capture and disable DMA transfers.
00896     (+) Start the Complementary One Pulse generation.
00897     (+) Stop the Complementary One Pulse.
00898     (+) Start the Complementary One Pulse and enable interrupts.
00899     (+) Stop the Complementary One Pulse and disable interrupts.
00900 
00901 @endverbatim
00902   * @{
00903   */
00904 
00905 /**
00906   * @brief  Starts the PWM signal generation on the complementary output.
00907   * @param  htim : TIM handle
00908   * @param  Channel : TIM Channel to be enabled
00909   *          This parameter can be one of the following values:
00910   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected
00911   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected
00912   *            @arg TIM_CHANNEL_3: TIM Channel 3 selected
00913   *            @arg TIM_CHANNEL_4: TIM Channel 4 selected
00914   * @retval HAL status
00915   */
00916 HAL_StatusTypeDef HAL_TIMEx_PWMN_Start(TIM_HandleTypeDef *htim, uint32_t Channel)
00917 {
00918   /* Check the parameters */
00919   assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
00920 
00921   /* Enable the complementary PWM output  */
00922   TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_ENABLE);
00923 
00924   /* Enable the Main Ouput */
00925   __HAL_TIM_MOE_ENABLE(htim);
00926 
00927   /* Enable the Peripheral */
00928   __HAL_TIM_ENABLE(htim);
00929 
00930   /* Return function status */
00931   return HAL_OK;
00932 }
00933 
00934 /**
00935   * @brief  Stops the PWM signal generation on the complementary output.
00936   * @param  htim : TIM handle
00937   * @param  Channel : TIM Channel to be disabled
00938   *          This parameter can be one of the following values:
00939   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected
00940   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected
00941   *            @arg TIM_CHANNEL_3: TIM Channel 3 selected
00942   *            @arg TIM_CHANNEL_4: TIM Channel 4 selected
00943   * @retval HAL status
00944   */
00945 HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop(TIM_HandleTypeDef *htim, uint32_t Channel)
00946 {
00947   /* Check the parameters */
00948   assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
00949 
00950   /* Disable the complementary PWM output  */
00951   TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_DISABLE);
00952 
00953   /* Disable the Main Ouput */
00954   __HAL_TIM_MOE_DISABLE(htim);
00955 
00956   /* Disable the Peripheral */
00957   __HAL_TIM_DISABLE(htim);
00958 
00959   /* Return function status */
00960   return HAL_OK;
00961 }
00962 
00963 /**
00964   * @brief  Starts the PWM signal generation in interrupt mode on the
00965   *         complementary output.
00966   * @param  htim : TIM handle
00967   * @param  Channel : TIM Channel to be disabled
00968   *          This parameter can be one of the following values:
00969   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected
00970   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected
00971   *            @arg TIM_CHANNEL_3: TIM Channel 3 selected
00972   *            @arg TIM_CHANNEL_4: TIM Channel 4 selected
00973   * @retval HAL status
00974   */
00975 HAL_StatusTypeDef HAL_TIMEx_PWMN_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
00976 {
00977   /* Check the parameters */
00978   assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
00979 
00980   switch (Channel)
00981   {
00982     case TIM_CHANNEL_1:
00983     {
00984       /* Enable the TIM Capture/Compare 1 interrupt */
00985       __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
00986     }
00987     break;
00988 
00989     case TIM_CHANNEL_2:
00990     {
00991       /* Enable the TIM Capture/Compare 2 interrupt */
00992       __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);
00993     }
00994     break;
00995 
00996     case TIM_CHANNEL_3:
00997     {
00998       /* Enable the TIM Capture/Compare 3 interrupt */
00999       __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC3);
01000     }
01001     break;
01002 
01003     case TIM_CHANNEL_4:
01004     {
01005       /* Enable the TIM Capture/Compare 4 interrupt */
01006       __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC4);
01007     }
01008     break;
01009 
01010     default:
01011     break;
01012   }
01013 
01014   /* Enable the TIM Break interrupt */
01015   __HAL_TIM_ENABLE_IT(htim, TIM_IT_BREAK);
01016 
01017   /* Enable the complementary PWM output  */
01018   TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_ENABLE);
01019 
01020   /* Enable the Main Ouput */
01021   __HAL_TIM_MOE_ENABLE(htim);
01022 
01023   /* Enable the Peripheral */
01024   __HAL_TIM_ENABLE(htim);
01025 
01026   /* Return function status */
01027   return HAL_OK;
01028 }
01029 
01030 /**
01031   * @brief  Stops the PWM signal generation in interrupt mode on the
01032   *         complementary output.
01033   * @param  htim : TIM handle
01034   * @param  Channel : TIM Channel to be disabled
01035   *          This parameter can be one of the following values:
01036   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected
01037   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected
01038   *            @arg TIM_CHANNEL_3: TIM Channel 3 selected
01039   *            @arg TIM_CHANNEL_4: TIM Channel 4 selected
01040   * @retval HAL status
01041   */
01042 HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop_IT (TIM_HandleTypeDef *htim, uint32_t Channel)
01043 {
01044   uint32_t tmpccer = 0;
01045 
01046   /* Check the parameters */
01047   assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
01048 
01049   switch (Channel)
01050   {
01051     case TIM_CHANNEL_1:
01052     {
01053       /* Disable the TIM Capture/Compare 1 interrupt */
01054       __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
01055     }
01056     break;
01057 
01058     case TIM_CHANNEL_2:
01059     {
01060       /* Disable the TIM Capture/Compare 2 interrupt */
01061       __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);
01062     }
01063     break;
01064 
01065     case TIM_CHANNEL_3:
01066     {
01067       /* Disable the TIM Capture/Compare 3 interrupt */
01068       __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC3);
01069     }
01070     break;
01071 
01072     case TIM_CHANNEL_4:
01073     {
01074       /* Disable the TIM Capture/Compare 3 interrupt */
01075       __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC4);
01076     }
01077     break;
01078 
01079     default:
01080     break;
01081   }
01082 
01083   /* Disable the complementary PWM output  */
01084   TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_DISABLE);
01085 
01086   /* Disable the TIM Break interrupt (only if no more channel is active) */
01087   tmpccer = htim->Instance->CCER;
01088   if ((tmpccer & (TIM_CCER_CC1NE | TIM_CCER_CC2NE | TIM_CCER_CC3NE)) == RESET)
01089   {
01090     __HAL_TIM_DISABLE_IT(htim, TIM_IT_BREAK);
01091   }
01092 
01093   /* Disable the Main Ouput */
01094   __HAL_TIM_MOE_DISABLE(htim);
01095 
01096   /* Disable the Peripheral */
01097   __HAL_TIM_DISABLE(htim);
01098 
01099   /* Return function status */
01100   return HAL_OK;
01101 }
01102 
01103 /**
01104   * @brief  Starts the TIM PWM signal generation in DMA mode on the
01105   *         complementary output
01106   * @param  htim : TIM handle
01107   * @param  Channel : TIM Channel to be enabled
01108   *          This parameter can be one of the following values:
01109   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected
01110   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected
01111   *            @arg TIM_CHANNEL_3: TIM Channel 3 selected
01112   *            @arg TIM_CHANNEL_4: TIM Channel 4 selected
01113   * @param  pData : The source Buffer address.
01114   * @param  Length : The length of data to be transferred from memory to TIM peripheral
01115   * @retval HAL status
01116   */
01117 HAL_StatusTypeDef HAL_TIMEx_PWMN_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length)
01118 {
01119   /* Check the parameters */
01120   assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
01121 
01122   if((htim->State == HAL_TIM_STATE_BUSY))
01123   {
01124      return HAL_BUSY;
01125   }
01126   else if((htim->State == HAL_TIM_STATE_READY))
01127   {
01128     if(((uint32_t)pData == 0 ) && (Length > 0))
01129     {
01130       return HAL_ERROR;
01131     }
01132     else
01133     {
01134       htim->State = HAL_TIM_STATE_BUSY;
01135     }
01136   }
01137   switch (Channel)
01138   {
01139     case TIM_CHANNEL_1:
01140     {
01141       /* Set the DMA Period elapsed callback */
01142       htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMADelayPulseCplt;
01143 
01144       /* Set the DMA error callback */
01145       htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ;
01146 
01147       /* Enable the DMA channel */
01148       HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)pData, (uint32_t)&htim->Instance->CCR1, Length);
01149 
01150       /* Enable the TIM Capture/Compare 1 DMA request */
01151       __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1);
01152     }
01153     break;
01154 
01155     case TIM_CHANNEL_2:
01156     {
01157       /* Set the DMA Period elapsed callback */
01158       htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMADelayPulseCplt;
01159 
01160       /* Set the DMA error callback */
01161       htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError ;
01162 
01163       /* Enable the DMA channel */
01164       HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)pData, (uint32_t)&htim->Instance->CCR2, Length);
01165 
01166       /* Enable the TIM Capture/Compare 2 DMA request */
01167       __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2);
01168     }
01169     break;
01170 
01171     case TIM_CHANNEL_3:
01172     {
01173       /* Set the DMA Period elapsed callback */
01174       htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMADelayPulseCplt;
01175 
01176       /* Set the DMA error callback */
01177       htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = TIM_DMAError ;
01178 
01179       /* Enable the DMA channel */
01180       HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)pData, (uint32_t)&htim->Instance->CCR3,Length);
01181 
01182       /* Enable the TIM Capture/Compare 3 DMA request */
01183       __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC3);
01184     }
01185     break;
01186 
01187     case TIM_CHANNEL_4:
01188     {
01189      /* Set the DMA Period elapsed callback */
01190       htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = TIM_DMADelayPulseCplt;
01191 
01192       /* Set the DMA error callback */
01193       htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = TIM_DMAError ;
01194 
01195       /* Enable the DMA channel */
01196       HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)pData, (uint32_t)&htim->Instance->CCR4, Length);
01197 
01198       /* Enable the TIM Capture/Compare 4 DMA request */
01199       __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC4);
01200     }
01201     break;
01202 
01203     default:
01204     break;
01205   }
01206 
01207   /* Enable the complementary PWM output  */
01208      TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_ENABLE);
01209 
01210   /* Enable the Main Ouput */
01211     __HAL_TIM_MOE_ENABLE(htim);
01212 
01213   /* Enable the Peripheral */
01214   __HAL_TIM_ENABLE(htim);
01215 
01216   /* Return function status */
01217   return HAL_OK;
01218 }
01219 
01220 /**
01221   * @brief  Stops the TIM PWM signal generation in DMA mode on the complementary
01222   *         output
01223   * @param  htim : TIM handle
01224   * @param  Channel : TIM Channel to be disabled
01225   *          This parameter can be one of the following values:
01226   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected
01227   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected
01228   *            @arg TIM_CHANNEL_3: TIM Channel 3 selected
01229   *            @arg TIM_CHANNEL_4: TIM Channel 4 selected
01230   * @retval HAL status
01231   */
01232 HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel)
01233 {
01234   /* Check the parameters */
01235   assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
01236 
01237   switch (Channel)
01238   {
01239     case TIM_CHANNEL_1:
01240     {
01241       /* Disable the TIM Capture/Compare 1 DMA request */
01242       __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1);
01243     }
01244     break;
01245 
01246     case TIM_CHANNEL_2:
01247     {
01248       /* Disable the TIM Capture/Compare 2 DMA request */
01249       __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2);
01250     }
01251     break;
01252 
01253     case TIM_CHANNEL_3:
01254     {
01255       /* Disable the TIM Capture/Compare 3 DMA request */
01256       __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC3);
01257     }
01258     break;
01259 
01260     case TIM_CHANNEL_4:
01261     {
01262       /* Disable the TIM Capture/Compare 4 DMA request */
01263       __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC4);
01264     }
01265     break;
01266 
01267     default:
01268     break;
01269   }
01270 
01271   /* Disable the complementary PWM output */
01272     TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_DISABLE);
01273 
01274   /* Disable the Main Ouput */
01275     __HAL_TIM_MOE_DISABLE(htim);
01276 
01277   /* Disable the Peripheral */
01278   __HAL_TIM_DISABLE(htim);
01279 
01280   /* Change the htim state */
01281   htim->State = HAL_TIM_STATE_READY;
01282 
01283   /* Return function status */
01284   return HAL_OK;
01285 }
01286 
01287 /**
01288   * @}
01289   */
01290 
01291 /** @defgroup TIMEx_Exported_Functions_Group4 Timer Complementary One Pulse functions
01292  *  @brief    Timer Complementary One Pulse functions
01293  *
01294 @verbatim
01295   ==============================================================================
01296                 ##### Timer Complementary One Pulse functions #####
01297   ==============================================================================
01298   [..]
01299     This section provides functions allowing to:
01300     (+) Start the Complementary One Pulse generation.
01301     (+) Stop the Complementary One Pulse.
01302     (+) Start the Complementary One Pulse and enable interrupts.
01303     (+) Stop the Complementary One Pulse and disable interrupts.
01304 
01305 @endverbatim
01306   * @{
01307   */
01308 
01309 /**
01310   * @brief  Starts the TIM One Pulse signal generation on the complemetary
01311   *         output.
01312   * @param  htim : TIM One Pulse handle
01313   * @param  OutputChannel : TIM Channel to be enabled
01314   *          This parameter can be one of the following values:
01315   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected
01316   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected
01317   * @retval HAL status
01318   */
01319 HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Start(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
01320   {
01321   /* Check the parameters */
01322   assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, OutputChannel));
01323 
01324   /* Enable the complementary One Pulse output */
01325   TIM_CCxNChannelCmd(htim->Instance, OutputChannel, TIM_CCxN_ENABLE);
01326 
01327   /* Enable the Main Ouput */
01328   __HAL_TIM_MOE_ENABLE(htim);
01329 
01330   /* Return function status */
01331   return HAL_OK;
01332 }
01333 
01334 /**
01335   * @brief  Stops the TIM One Pulse signal generation on the complementary
01336   *         output.
01337   * @param  htim : TIM One Pulse handle
01338   * @param  OutputChannel : TIM Channel to be disabled
01339   *          This parameter can be one of the following values:
01340   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected
01341   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected
01342   * @retval HAL status
01343   */
01344 HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Stop(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
01345 {
01346 
01347   /* Check the parameters */
01348   assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, OutputChannel));
01349 
01350   /* Disable the complementary One Pulse output */
01351   TIM_CCxNChannelCmd(htim->Instance, OutputChannel, TIM_CCxN_DISABLE);
01352 
01353   /* Disable the Main Ouput */
01354   __HAL_TIM_MOE_DISABLE(htim);
01355 
01356   /* Disable the Peripheral */
01357   __HAL_TIM_DISABLE(htim);
01358 
01359   /* Return function status */
01360   return HAL_OK;
01361 }
01362 
01363 /**
01364   * @brief  Starts the TIM One Pulse signal generation in interrupt mode on the
01365   *         complementary channel.
01366   * @param  htim : TIM One Pulse handle
01367   * @param  OutputChannel : TIM Channel to be enabled
01368   *          This parameter can be one of the following values:
01369   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected
01370   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected
01371   * @retval HAL status
01372   */
01373 HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Start_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
01374 {
01375   /* Check the parameters */
01376   assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, OutputChannel));
01377 
01378   /* Enable the TIM Capture/Compare 1 interrupt */
01379   __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
01380 
01381   /* Enable the TIM Capture/Compare 2 interrupt */
01382   __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);
01383 
01384   /* Enable the complementary One Pulse output */
01385   TIM_CCxNChannelCmd(htim->Instance, OutputChannel, TIM_CCxN_ENABLE);
01386 
01387   /* Enable the Main Ouput */
01388   __HAL_TIM_MOE_ENABLE(htim);
01389 
01390   /* Return function status */
01391   return HAL_OK;
01392   }
01393 
01394 /**
01395   * @brief  Stops the TIM One Pulse signal generation in interrupt mode on the
01396   *         complementary channel.
01397   * @param  htim : TIM One Pulse handle
01398   * @param  OutputChannel : TIM Channel to be disabled
01399   *          This parameter can be one of the following values:
01400   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected
01401   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected
01402   * @retval HAL status
01403   */
01404 HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
01405 {
01406   /* Check the parameters */
01407   assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, OutputChannel));
01408 
01409   /* Disable the TIM Capture/Compare 1 interrupt */
01410   __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
01411 
01412   /* Disable the TIM Capture/Compare 2 interrupt */
01413   __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);
01414 
01415   /* Disable the complementary One Pulse output */
01416   TIM_CCxNChannelCmd(htim->Instance, OutputChannel, TIM_CCxN_DISABLE);
01417 
01418   /* Disable the Main Ouput */
01419   __HAL_TIM_MOE_DISABLE(htim);
01420 
01421   /* Disable the Peripheral */
01422    __HAL_TIM_DISABLE(htim);
01423 
01424   /* Return function status */
01425   return HAL_OK;
01426 }
01427 
01428 /**
01429   * @}
01430   */
01431 
01432 #endif /* defined(STM32F100xB) || defined(STM32F100xE) ||                                                 */
01433        /* defined(STM32F103x6) || defined(STM32F103xB) || defined(STM32F103xE) || defined(STM32F103xG) || */
01434        /* defined(STM32F105xC) || defined(STM32F107xC)                                                    */
01435 
01436 /** @defgroup TIMEx_Exported_Functions_Group5 Peripheral Control functions
01437  *  @brief      Peripheral Control functions
01438  *
01439 @verbatim
01440   ==============================================================================
01441                     ##### Peripheral Control functions #####
01442   ==============================================================================
01443   [..]
01444     This section provides functions allowing to:
01445     (+) Configure the commutation event in case of use of the Hall sensor interface.
01446       (+) Configure Complementary channels, break features and dead time.
01447       (+) Configure Master synchronization.
01448 
01449 @endverbatim
01450   * @{
01451   */
01452 
01453 #if defined (STM32F100xB) || defined (STM32F100xE) ||                                                   \
01454     defined (STM32F103x6) || defined (STM32F103xB) || defined (STM32F103xE) || defined (STM32F103xG) || \
01455     defined (STM32F105xC) || defined (STM32F107xC)
01456 
01457 /**
01458   * @brief  Configure the TIM commutation event sequence.
01459   * @note: this function is mandatory to use the commutation event in order to
01460   *        update the configuration at each commutation detection on the TRGI input of the Timer,
01461   *        the typical use of this feature is with the use of another Timer(interface Timer)
01462   *        configured in Hall sensor interface, this interface Timer will generate the
01463   *        commutation at its TRGO output (connected to Timer used in this function) each time
01464   *        the TI1 of the Interface Timer detect a commutation at its input TI1.
01465   * @param  htim : TIM handle
01466   * @param  InputTrigger : the Internal trigger corresponding to the Timer Interfacing with the Hall sensor
01467   *          This parameter can be one of the following values:
01468   *            @arg TIM_TS_ITR0: Internal trigger 0 selected
01469   *            @arg TIM_TS_ITR1: Internal trigger 1 selected
01470   *            @arg TIM_TS_ITR2: Internal trigger 2 selected
01471   *            @arg TIM_TS_ITR3: Internal trigger 3 selected
01472   *            @arg TIM_TS_NONE: No trigger is needed
01473   * @param  CommutationSource : the Commutation Event source
01474   *          This parameter can be one of the following values:
01475   *            @arg TIM_COMMUTATION_TRGI: Commutation source is the TRGI of the Interface Timer
01476   *            @arg TIM_COMMUTATION_SOFTWARE:  Commutation source is set by software using the COMG bit
01477   * @retval HAL status
01478   */
01479 HAL_StatusTypeDef HAL_TIMEx_ConfigCommutationEvent(TIM_HandleTypeDef *htim, uint32_t  InputTrigger, uint32_t  CommutationSource)
01480 {
01481   /* Check the parameters */
01482   assert_param(IS_TIM_COMMUTATION_EVENT_INSTANCE(htim->Instance));
01483   assert_param(IS_TIM_INTERNAL_TRIGGEREVENT_SELECTION(InputTrigger));
01484 
01485   __HAL_LOCK(htim);
01486 
01487   if ((InputTrigger == TIM_TS_ITR0) || (InputTrigger == TIM_TS_ITR1) ||
01488       (InputTrigger == TIM_TS_ITR2) || (InputTrigger == TIM_TS_ITR3))
01489   {
01490     /* Select the Input trigger */
01491     htim->Instance->SMCR &= ~TIM_SMCR_TS;
01492     htim->Instance->SMCR |= InputTrigger;
01493   }
01494 
01495   /* Select the Capture Compare preload feature */
01496   htim->Instance->CR2 |= TIM_CR2_CCPC;
01497   /* Select the Commutation event source */
01498   htim->Instance->CR2 &= ~TIM_CR2_CCUS;
01499   htim->Instance->CR2 |= CommutationSource;
01500 
01501   __HAL_UNLOCK(htim);
01502 
01503   return HAL_OK;
01504 }
01505 
01506 /**
01507   * @brief  Configure the TIM commutation event sequence with interrupt.
01508   * @note: this function is mandatory to use the commutation event in order to
01509   *        update the configuration at each commutation detection on the TRGI input of the Timer,
01510   *        the typical use of this feature is with the use of another Timer(interface Timer)
01511   *        configured in Hall sensor interface, this interface Timer will generate the
01512   *        commutation at its TRGO output (connected to Timer used in this function) each time
01513   *        the TI1 of the Interface Timer detect a commutation at its input TI1.
01514   * @param  htim : TIM handle
01515   * @param  InputTrigger : the Internal trigger corresponding to the Timer Interfacing with the Hall sensor
01516   *          This parameter can be one of the following values:
01517   *            @arg TIM_TS_ITR0: Internal trigger 0 selected
01518   *            @arg TIM_TS_ITR1: Internal trigger 1 selected
01519   *            @arg TIM_TS_ITR2: Internal trigger 2 selected
01520   *            @arg TIM_TS_ITR3: Internal trigger 3 selected
01521   *            @arg TIM_TS_NONE: No trigger is needed
01522   * @param  CommutationSource : the Commutation Event source
01523   *          This parameter can be one of the following values:
01524   *            @arg TIM_COMMUTATION_TRGI: Commutation source is the TRGI of the Interface Timer
01525   *            @arg TIM_COMMUTATION_SOFTWARE:  Commutation source is set by software using the COMG bit
01526   * @retval HAL status
01527   */
01528 HAL_StatusTypeDef HAL_TIMEx_ConfigCommutationEvent_IT(TIM_HandleTypeDef *htim, uint32_t  InputTrigger, uint32_t  CommutationSource)
01529 {
01530   /* Check the parameters */
01531   assert_param(IS_TIM_COMMUTATION_EVENT_INSTANCE(htim->Instance));
01532   assert_param(IS_TIM_INTERNAL_TRIGGEREVENT_SELECTION(InputTrigger));
01533 
01534   __HAL_LOCK(htim);
01535 
01536   if ((InputTrigger == TIM_TS_ITR0) || (InputTrigger == TIM_TS_ITR1) ||
01537       (InputTrigger == TIM_TS_ITR2) || (InputTrigger == TIM_TS_ITR3))
01538   {
01539     /* Select the Input trigger */
01540     htim->Instance->SMCR &= ~TIM_SMCR_TS;
01541     htim->Instance->SMCR |= InputTrigger;
01542   }
01543 
01544   /* Select the Capture Compare preload feature */
01545   htim->Instance->CR2 |= TIM_CR2_CCPC;
01546   /* Select the Commutation event source */
01547   htim->Instance->CR2 &= ~TIM_CR2_CCUS;
01548   htim->Instance->CR2 |= CommutationSource;
01549 
01550   /* Enable the Commutation Interrupt Request */
01551   __HAL_TIM_ENABLE_IT(htim, TIM_IT_COM);
01552 
01553   __HAL_UNLOCK(htim);
01554 
01555   return HAL_OK;
01556 }
01557 
01558 /**
01559   * @brief  Configure the TIM commutation event sequence with DMA.
01560   * @note: this function is mandatory to use the commutation event in order to
01561   *        update the configuration at each commutation detection on the TRGI input of the Timer,
01562   *        the typical use of this feature is with the use of another Timer(interface Timer)
01563   *        configured in Hall sensor interface, this interface Timer will generate the
01564   *        commutation at its TRGO output (connected to Timer used in this function) each time
01565   *        the TI1 of the Interface Timer detect a commutation at its input TI1.
01566   * @note: The user should configure the DMA in his own software, in This function only the COMDE bit is set
01567   * @param  htim : TIM handle
01568   * @param  InputTrigger : the Internal trigger corresponding to the Timer Interfacing with the Hall sensor
01569   *          This parameter can be one of the following values:
01570   *            @arg TIM_TS_ITR0: Internal trigger 0 selected
01571   *            @arg TIM_TS_ITR1: Internal trigger 1 selected
01572   *            @arg TIM_TS_ITR2: Internal trigger 2 selected
01573   *            @arg TIM_TS_ITR3: Internal trigger 3 selected
01574   *            @arg TIM_TS_NONE: No trigger is needed
01575   * @param  CommutationSource : the Commutation Event source
01576   *          This parameter can be one of the following values:
01577   *            @arg TIM_COMMUTATION_TRGI: Commutation source is the TRGI of the Interface Timer
01578   *            @arg TIM_COMMUTATION_SOFTWARE:  Commutation source is set by software using the COMG bit
01579   * @retval HAL status
01580   */
01581 HAL_StatusTypeDef HAL_TIMEx_ConfigCommutationEvent_DMA(TIM_HandleTypeDef *htim, uint32_t  InputTrigger, uint32_t  CommutationSource)
01582 {
01583   /* Check the parameters */
01584   assert_param(IS_TIM_COMMUTATION_EVENT_INSTANCE(htim->Instance));
01585   assert_param(IS_TIM_INTERNAL_TRIGGEREVENT_SELECTION(InputTrigger));
01586 
01587   __HAL_LOCK(htim);
01588 
01589   if ((InputTrigger == TIM_TS_ITR0) || (InputTrigger == TIM_TS_ITR1) ||
01590       (InputTrigger == TIM_TS_ITR2) || (InputTrigger == TIM_TS_ITR3))
01591   {
01592     /* Select the Input trigger */
01593     htim->Instance->SMCR &= ~TIM_SMCR_TS;
01594     htim->Instance->SMCR |= InputTrigger;
01595   }
01596 
01597   /* Select the Capture Compare preload feature */
01598   htim->Instance->CR2 |= TIM_CR2_CCPC;
01599   /* Select the Commutation event source */
01600   htim->Instance->CR2 &= ~TIM_CR2_CCUS;
01601   htim->Instance->CR2 |= CommutationSource;
01602 
01603   /* Enable the Commutation DMA Request */
01604   /* Set the DMA Commutation Callback */
01605   htim->hdma[TIM_DMA_ID_COMMUTATION]->XferCpltCallback = TIMEx_DMACommutationCplt;
01606   /* Set the DMA error callback */
01607   htim->hdma[TIM_DMA_ID_COMMUTATION]->XferErrorCallback = TIM_DMAError;
01608 
01609   /* Enable the Commutation DMA Request */
01610   __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_COM);
01611 
01612   __HAL_UNLOCK(htim);
01613 
01614   return HAL_OK;
01615 }
01616 
01617 /**
01618   * @brief   Configures the Break feature, dead time, Lock level, OSSI/OSSR State
01619   *          and the AOE(automatic output enable).
01620   * @param  htim : TIM handle
01621   * @param  sBreakDeadTimeConfig : pointer to a TIM_ConfigBreakDeadConfigTypeDef structure that
01622   *         contains the BDTR Register configuration  information for the TIM peripheral.
01623   * @retval HAL status
01624   */
01625 HAL_StatusTypeDef HAL_TIMEx_ConfigBreakDeadTime(TIM_HandleTypeDef *htim,
01626                                                 TIM_BreakDeadTimeConfigTypeDef *sBreakDeadTimeConfig)
01627 {
01628   /* Check the parameters */
01629   assert_param(IS_TIM_BREAK_INSTANCE(htim->Instance));
01630   assert_param(IS_TIM_OSSR_STATE(sBreakDeadTimeConfig->OffStateRunMode));
01631   assert_param(IS_TIM_OSSI_STATE(sBreakDeadTimeConfig->OffStateIDLEMode));
01632   assert_param(IS_TIM_LOCK_LEVEL(sBreakDeadTimeConfig->LockLevel));
01633   assert_param(IS_TIM_DEADTIME(sBreakDeadTimeConfig->DeadTime));
01634   assert_param(IS_TIM_BREAK_STATE(sBreakDeadTimeConfig->BreakState));
01635   assert_param(IS_TIM_BREAK_POLARITY(sBreakDeadTimeConfig->BreakPolarity));
01636   assert_param(IS_TIM_AUTOMATIC_OUTPUT_STATE(sBreakDeadTimeConfig->AutomaticOutput));
01637 
01638   /* Process Locked */
01639   __HAL_LOCK(htim);
01640 
01641   htim->State = HAL_TIM_STATE_BUSY;
01642 
01643   /* Set the Lock level, the Break enable Bit and the Polarity, the OSSR State,
01644      the OSSI State, the dead time value and the Automatic Output Enable Bit */
01645   htim->Instance->BDTR = (uint32_t)sBreakDeadTimeConfig->OffStateRunMode  |
01646                                    sBreakDeadTimeConfig->OffStateIDLEMode |
01647                                    sBreakDeadTimeConfig->LockLevel        |
01648                                    sBreakDeadTimeConfig->DeadTime         |
01649                                    sBreakDeadTimeConfig->BreakState       |
01650                                    sBreakDeadTimeConfig->BreakPolarity    |
01651                                    sBreakDeadTimeConfig->AutomaticOutput;
01652 
01653 
01654   htim->State = HAL_TIM_STATE_READY;
01655 
01656   __HAL_UNLOCK(htim);
01657 
01658   return HAL_OK;
01659 }
01660 
01661 #endif /* defined(STM32F100xB) || defined(STM32F100xE) ||                                                 */
01662        /* defined(STM32F103x6) || defined(STM32F103xB) || defined(STM32F103xE) || defined(STM32F103xG) || */
01663        /* defined(STM32F105xC) || defined(STM32F107xC)                                                    */
01664 
01665 /**
01666   * @brief  Configures the TIM in master mode.
01667   * @param  htim : TIM handle.
01668   * @param  sMasterConfig : pointer to a TIM_MasterConfigTypeDef structure that
01669   *         contains the selected trigger output (TRGO) and the Master/Slave
01670   *         mode.
01671   * @retval HAL status
01672   */
01673 HAL_StatusTypeDef HAL_TIMEx_MasterConfigSynchronization(TIM_HandleTypeDef *htim, TIM_MasterConfigTypeDef * sMasterConfig)
01674 {
01675   /* Check the parameters */
01676   assert_param(IS_TIM_MASTER_INSTANCE(htim->Instance));
01677   assert_param(IS_TIM_TRGO_SOURCE(sMasterConfig->MasterOutputTrigger));
01678   assert_param(IS_TIM_MSM_STATE(sMasterConfig->MasterSlaveMode));
01679 
01680   __HAL_LOCK(htim);
01681 
01682   htim->State = HAL_TIM_STATE_BUSY;
01683 
01684   /* Reset the MMS Bits */
01685   htim->Instance->CR2 &= ~TIM_CR2_MMS;
01686   /* Select the TRGO source */
01687   htim->Instance->CR2 |=  sMasterConfig->MasterOutputTrigger;
01688 
01689   /* Reset the MSM Bit */
01690   htim->Instance->SMCR &= ~TIM_SMCR_MSM;
01691   /* Set or Reset the MSM Bit */
01692   htim->Instance->SMCR |= sMasterConfig->MasterSlaveMode;
01693 
01694   htim->State = HAL_TIM_STATE_READY;
01695 
01696   __HAL_UNLOCK(htim);
01697 
01698   return HAL_OK;
01699 }
01700 
01701 /**
01702   * @}
01703   */
01704 
01705 /** @defgroup TIMEx_Exported_Functions_Group6 Extension Callbacks functions
01706  *  @brief   Extension Callbacks functions
01707  *
01708 @verbatim
01709   ==============================================================================
01710                     ##### Extension Callbacks functions #####
01711   ==============================================================================
01712   [..]
01713     This section provides Extension TIM callback functions:
01714     (+) Timer Commutation callback
01715     (+) Timer Break callback
01716 
01717 @endverbatim
01718   * @{
01719   */
01720 
01721 /**
01722   * @brief  Hall commutation changed callback in non blocking mode
01723   * @param  htim : TIM handle
01724   * @retval None
01725   */
01726 __weak void HAL_TIMEx_CommutationCallback(TIM_HandleTypeDef *htim)
01727 {
01728   /* Prevent unused argument(s) compilation warning */
01729   UNUSED(htim);
01730   /* NOTE : This function Should not be modified, when the callback is needed,
01731             the HAL_TIMEx_CommutationCallback could be implemented in the user file
01732    */
01733 }
01734 
01735 /**
01736   * @brief  Hall Break detection callback in non blocking mode
01737   * @param  htim : TIM handle
01738   * @retval None
01739   */
01740 __weak void HAL_TIMEx_BreakCallback(TIM_HandleTypeDef *htim)
01741 {
01742   /* Prevent unused argument(s) compilation warning */
01743   UNUSED(htim);
01744   /* NOTE : This function Should not be modified, when the callback is needed,
01745             the HAL_TIMEx_BreakCallback could be implemented in the user file
01746    */
01747 }
01748 
01749 /**
01750   * @brief  TIM DMA Commutation callback.
01751   * @param  hdma : pointer to DMA handle.
01752   * @retval None
01753   */
01754 void TIMEx_DMACommutationCplt(DMA_HandleTypeDef *hdma)
01755 {
01756   TIM_HandleTypeDef* htim = ( TIM_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
01757 
01758   htim->State= HAL_TIM_STATE_READY;
01759 
01760   HAL_TIMEx_CommutationCallback(htim);
01761 }
01762 
01763 /**
01764   * @}
01765   */
01766 
01767 #if defined (STM32F100xB) || defined (STM32F100xE) ||                                                   \
01768     defined (STM32F103x6) || defined (STM32F103xB) || defined (STM32F103xE) || defined (STM32F103xG) || \
01769     defined (STM32F105xC) || defined (STM32F107xC)
01770 
01771 /** @defgroup TIMEx_Exported_Functions_Group7 Extension Peripheral State functions
01772  *  @brief   Extension Peripheral State functions
01773  *
01774 @verbatim
01775   ==============================================================================
01776                 ##### Extension Peripheral State functions #####
01777   ==============================================================================
01778   [..]
01779     This subsection permit to get in run-time the status of the peripheral
01780     and the data flow.
01781 
01782 @endverbatim
01783   * @{
01784   */
01785 
01786 /**
01787   * @brief  Return the TIM Hall Sensor interface state
01788   * @param  htim : TIM Hall Sensor handle
01789   * @retval HAL state
01790   */
01791 HAL_TIM_StateTypeDef HAL_TIMEx_HallSensor_GetState(TIM_HandleTypeDef *htim)
01792 {
01793   return htim->State;
01794 }
01795 
01796 /**
01797   * @}
01798   */
01799 #endif /* defined(STM32F100xB) || defined(STM32F100xE) ||                                                 */
01800        /* defined(STM32F103x6) || defined(STM32F103xB) || defined(STM32F103xE) || defined(STM32F103xG) || */
01801        /* defined(STM32F105xC) || defined(STM32F107xC)                                                    */
01802 
01803 /**
01804   * @}
01805   */
01806 
01807 #if defined (STM32F100xB) || defined (STM32F100xE) ||                                                   \
01808     defined (STM32F103x6) || defined (STM32F103xB) || defined (STM32F103xE) || defined (STM32F103xG) || \
01809     defined (STM32F105xC) || defined (STM32F107xC)
01810 
01811 /** @addtogroup TIMEx_Private_Functions
01812   * @{
01813   */
01814 
01815 /**
01816   * @brief  Enables or disables the TIM Capture Compare Channel xN.
01817   * @param  TIMx  to select the TIM peripheral
01818   * @param  Channel : specifies the TIM Channel
01819   *          This parameter can be one of the following values:
01820   *            @arg TIM_Channel_1: TIM Channel 1
01821   *            @arg TIM_Channel_2: TIM Channel 2
01822   *            @arg TIM_Channel_3: TIM Channel 3
01823   * @param  ChannelNState : specifies the TIM Channel CCxNE bit new state.
01824   *          This parameter can be: TIM_CCxN_ENABLE or TIM_CCxN_Disable.
01825   * @retval None
01826   */
01827 static void TIM_CCxNChannelCmd(TIM_TypeDef* TIMx, uint32_t Channel, uint32_t ChannelNState)
01828 {
01829   uint32_t tmp = 0;
01830 
01831   tmp = TIM_CCER_CC1NE << Channel;
01832 
01833   /* Reset the CCxNE Bit */
01834   TIMx->CCER  &=  ~tmp;
01835 
01836   /* Set or reset the CCxNE Bit */
01837   TIMx->CCER  |=  (uint32_t)(ChannelNState << Channel);
01838 }
01839 
01840 /**
01841   * @}
01842   */
01843 
01844 #endif /* defined(STM32F100xB) || defined(STM32F100xE) ||                                                 */
01845        /* defined(STM32F103x6) || defined(STM32F103xB) || defined(STM32F103xE) || defined(STM32F103xG) || */
01846        /* defined(STM32F105xC) || defined(STM32F107xC)                                                    */
01847 
01848 #endif /* HAL_TIM_MODULE_ENABLED */
01849 /**
01850   * @}
01851   */
01852 
01853 /**
01854   * @}
01855   */
01856 
01857 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/