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