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