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