]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_MPU_STM32L4_Discovery_GCC_IAR_Keil/ST_Code/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_tim_ex.c
Rename STM32Cube to GCC for STM32L4 Discovery projects as GCC is
[freertos] / FreeRTOS / Demo / CORTEX_MPU_STM32L4_Discovery_GCC_IAR_Keil / ST_Code / Drivers / STM32L4xx_HAL_Driver / Src / stm32l4xx_hal_tim_ex.c
1 /**\r
2   ******************************************************************************\r
3   * @file    stm32l4xx_hal_tim_ex.c\r
4   * @author  MCD Application Team\r
5   * @brief   TIM HAL module driver.\r
6   *          This file provides firmware functions to manage the following\r
7   *          functionalities of the Timer Extended peripheral:\r
8   *           + Time Hall Sensor Interface Initialization\r
9   *           + Time Hall Sensor Interface Start\r
10   *           + Time Complementary signal break and dead time configuration\r
11   *           + Time Master and Slave synchronization configuration\r
12   *           + Time Output Compare/PWM Channel Configuration (for channels 5 and 6)\r
13   *           + Time OCRef clear configuration\r
14   *           + Timer remapping capabilities configuration\r
15   @verbatim\r
16   ==============================================================================\r
17                       ##### TIMER Extended features #####\r
18   ==============================================================================\r
19   [..]\r
20     The Timer Extended features include:\r
21     (#) Complementary outputs with programmable dead-time for :\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 on the selected feature:\r
36            (++) Hall Sensor output : HAL_TIMEx_HallSensor_MspInit()\r
37 \r
38      (#) Initialize the TIM low level resources :\r
39         (##) Enable the TIM interface clock using __HAL_RCC_TIMx_CLK_ENABLE();\r
40         (##) TIM pins configuration\r
41             (+++) Enable the clock for the TIM GPIOs using the following function:\r
42               __HAL_RCC_GPIOx_CLK_ENABLE();\r
43             (+++) Configure these TIM pins in Alternate function mode using HAL_GPIO_Init();\r
44 \r
45      (#) The external Clock can be configured, if needed (the default clock is the\r
46          internal clock from the APBx), using the following function:\r
47          HAL_TIM_ConfigClockSource, the clock configuration should be done before\r
48          any start function.\r
49 \r
50      (#) Configure the TIM in the desired functioning mode using one of the\r
51          initialization function of this driver:\r
52           (++) HAL_TIMEx_HallSensor_Init() and HAL_TIMEx_ConfigCommutEvent(): to use the\r
53                Timer Hall Sensor Interface and the commutation event with the corresponding\r
54                Interrupt and DMA request if needed (Note that One Timer is used to interface\r
55                with the Hall sensor Interface and another Timer should be used to use\r
56                the commutation event).\r
57 \r
58      (#) Activate the TIM peripheral using one of the start functions:\r
59            (++) Complementary Output Compare : HAL_TIMEx_OCN_Start(), HAL_TIMEx_OCN_Start_DMA(), HAL_TIMEx_OC_Start_IT()\r
60            (++) Complementary PWM generation : HAL_TIMEx_PWMN_Start(), HAL_TIMEx_PWMN_Start_DMA(), HAL_TIMEx_PWMN_Start_IT()\r
61            (++) Complementary One-pulse mode output : HAL_TIMEx_OnePulseN_Start(), HAL_TIMEx_OnePulseN_Start_IT()\r
62            (++) Hall Sensor output : HAL_TIMEx_HallSensor_Start(), HAL_TIMEx_HallSensor_Start_DMA(), HAL_TIMEx_HallSensor_Start_IT().\r
63 \r
64   @endverbatim\r
65   ******************************************************************************\r
66   * @attention\r
67   *\r
68   * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.\r
69   * All rights reserved.</center></h2>\r
70   *\r
71   * This software component is licensed by ST under BSD 3-Clause license,\r
72   * the "License"; You may not use this file except in compliance with the\r
73   * License. You may obtain a copy of the License at:\r
74   *                        opensource.org/licenses/BSD-3-Clause\r
75   *\r
76   ******************************************************************************\r
77   */\r
78 \r
79 /* Includes ------------------------------------------------------------------*/\r
80 #include "stm32l4xx_hal.h"\r
81 \r
82 /** @addtogroup STM32L4xx_HAL_Driver\r
83   * @{\r
84   */\r
85 \r
86 /** @defgroup TIMEx TIMEx\r
87   * @brief TIM Extended HAL module driver\r
88   * @{\r
89   */\r
90 \r
91 #ifdef HAL_TIM_MODULE_ENABLED\r
92 \r
93 /* Private typedef -----------------------------------------------------------*/\r
94 /* Private define ------------------------------------------------------------*/\r
95 /* Private macro -------------------------------------------------------------*/\r
96 /* Private variables ---------------------------------------------------------*/\r
97 /* Private function prototypes -----------------------------------------------*/\r
98 static void TIM_CCxNChannelCmd(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t ChannelNState);\r
99 \r
100 /* Exported functions --------------------------------------------------------*/\r
101 /** @defgroup TIMEx_Exported_Functions TIM Extended Exported Functions\r
102   * @{\r
103   */\r
104 \r
105 /** @defgroup TIMEx_Exported_Functions_Group1 Extended Timer Hall Sensor functions\r
106   * @brief    Timer Hall Sensor functions\r
107   *\r
108 @verbatim\r
109   ==============================================================================\r
110                       ##### Timer Hall Sensor functions #####\r
111   ==============================================================================\r
112   [..]\r
113     This section provides functions allowing to:\r
114     (+) Initialize and configure TIM HAL Sensor.\r
115     (+) De-initialize TIM HAL Sensor.\r
116     (+) Start the Hall Sensor Interface.\r
117     (+) Stop the Hall Sensor Interface.\r
118     (+) Start the Hall Sensor Interface and enable interrupts.\r
119     (+) Stop the Hall Sensor Interface and disable interrupts.\r
120     (+) Start the Hall Sensor Interface and enable DMA transfers.\r
121     (+) Stop the Hall Sensor Interface and disable DMA transfers.\r
122 \r
123 @endverbatim\r
124   * @{\r
125   */\r
126 /**\r
127   * @brief  Initializes the TIM Hall Sensor Interface and initialize the associated handle.\r
128   * @param  htim TIM Hall Sensor Interface handle\r
129   * @param  sConfig TIM Hall Sensor configuration structure\r
130   * @retval HAL status\r
131   */\r
132 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Init(TIM_HandleTypeDef *htim, TIM_HallSensor_InitTypeDef *sConfig)\r
133 {\r
134   TIM_OC_InitTypeDef OC_Config;\r
135 \r
136   /* Check the TIM handle allocation */\r
137   if (htim == NULL)\r
138   {\r
139     return HAL_ERROR;\r
140   }\r
141 \r
142   /* Check the parameters */\r
143   assert_param(IS_TIM_HALL_SENSOR_INTERFACE_INSTANCE(htim->Instance));\r
144   assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode));\r
145   assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision));\r
146   assert_param(IS_TIM_AUTORELOAD_PRELOAD(htim->Init.AutoReloadPreload));\r
147   assert_param(IS_TIM_IC_POLARITY(sConfig->IC1Polarity));\r
148   assert_param(IS_TIM_IC_PRESCALER(sConfig->IC1Prescaler));\r
149   assert_param(IS_TIM_IC_FILTER(sConfig->IC1Filter));\r
150 \r
151   if (htim->State == HAL_TIM_STATE_RESET)\r
152   {\r
153     /* Allocate lock resource and initialize it */\r
154     htim->Lock = HAL_UNLOCKED;\r
155 \r
156 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)\r
157     /* Reset interrupt callbacks to legacy week callbacks */\r
158     TIM_ResetCallback(htim);\r
159 \r
160     if (htim->HallSensor_MspInitCallback == NULL)\r
161     {\r
162       htim->HallSensor_MspInitCallback = HAL_TIMEx_HallSensor_MspInit;\r
163     }\r
164     /* Init the low level hardware : GPIO, CLOCK, NVIC */\r
165     htim->HallSensor_MspInitCallback(htim);\r
166 #else\r
167     /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */\r
168     HAL_TIMEx_HallSensor_MspInit(htim);\r
169 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */\r
170   }\r
171 \r
172   /* Set the TIM state */\r
173   htim->State = HAL_TIM_STATE_BUSY;\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 Interface 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 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)\r
235   if (htim->HallSensor_MspDeInitCallback == NULL)\r
236   {\r
237     htim->HallSensor_MspDeInitCallback = HAL_TIMEx_HallSensor_MspDeInit;\r
238   }\r
239   /* DeInit the low level hardware */\r
240   htim->HallSensor_MspDeInitCallback(htim);\r
241 #else\r
242   /* DeInit the low level hardware: GPIO, CLOCK, NVIC */\r
243   HAL_TIMEx_HallSensor_MspDeInit(htim);\r
244 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */\r
245 \r
246   /* Change TIM state */\r
247   htim->State = HAL_TIM_STATE_RESET;\r
248 \r
249   /* Release Lock */\r
250   __HAL_UNLOCK(htim);\r
251 \r
252   return HAL_OK;\r
253 }\r
254 \r
255 /**\r
256   * @brief  Initializes the TIM Hall Sensor MSP.\r
257   * @param  htim TIM Hall Sensor Interface handle\r
258   * @retval None\r
259   */\r
260 __weak void HAL_TIMEx_HallSensor_MspInit(TIM_HandleTypeDef *htim)\r
261 {\r
262   /* Prevent unused argument(s) compilation warning */\r
263   UNUSED(htim);\r
264 \r
265   /* NOTE : This function should not be modified, when the callback is needed,\r
266             the HAL_TIMEx_HallSensor_MspInit could be implemented in the user file\r
267    */\r
268 }\r
269 \r
270 /**\r
271   * @brief  DeInitializes TIM Hall Sensor MSP.\r
272   * @param  htim TIM Hall Sensor Interface handle\r
273   * @retval None\r
274   */\r
275 __weak void HAL_TIMEx_HallSensor_MspDeInit(TIM_HandleTypeDef *htim)\r
276 {\r
277   /* Prevent unused argument(s) compilation warning */\r
278   UNUSED(htim);\r
279 \r
280   /* NOTE : This function should not be modified, when the callback is needed,\r
281             the HAL_TIMEx_HallSensor_MspDeInit could be implemented in the user file\r
282    */\r
283 }\r
284 \r
285 /**\r
286   * @brief  Starts the TIM Hall Sensor Interface.\r
287   * @param  htim TIM Hall Sensor Interface handle\r
288   * @retval HAL status\r
289   */\r
290 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start(TIM_HandleTypeDef *htim)\r
291 {\r
292   uint32_t tmpsmcr;\r
293 \r
294   /* Check the parameters */\r
295   assert_param(IS_TIM_HALL_SENSOR_INTERFACE_INSTANCE(htim->Instance));\r
296 \r
297   /* Enable the Input Capture channel 1\r
298     (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
299   TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);\r
300 \r
301   /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */\r
302   tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;\r
303   if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))\r
304   {\r
305     __HAL_TIM_ENABLE(htim);\r
306   }\r
307 \r
308   /* Return function status */\r
309   return HAL_OK;\r
310 }\r
311 \r
312 /**\r
313   * @brief  Stops the TIM Hall sensor Interface.\r
314   * @param  htim TIM Hall Sensor Interface handle\r
315   * @retval HAL status\r
316   */\r
317 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop(TIM_HandleTypeDef *htim)\r
318 {\r
319   /* Check the parameters */\r
320   assert_param(IS_TIM_HALL_SENSOR_INTERFACE_INSTANCE(htim->Instance));\r
321 \r
322   /* Disable the Input Capture channels 1, 2 and 3\r
323     (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
324   TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);\r
325 \r
326   /* Disable the Peripheral */\r
327   __HAL_TIM_DISABLE(htim);\r
328 \r
329   /* Return function status */\r
330   return HAL_OK;\r
331 }\r
332 \r
333 /**\r
334   * @brief  Starts the TIM Hall Sensor Interface in interrupt mode.\r
335   * @param  htim TIM Hall Sensor Interface handle\r
336   * @retval HAL status\r
337   */\r
338 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start_IT(TIM_HandleTypeDef *htim)\r
339 {\r
340   uint32_t tmpsmcr;\r
341 \r
342   /* Check the parameters */\r
343   assert_param(IS_TIM_HALL_SENSOR_INTERFACE_INSTANCE(htim->Instance));\r
344 \r
345   /* Enable the capture compare Interrupts 1 event */\r
346   __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);\r
347 \r
348   /* Enable the Input Capture channel 1\r
349     (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
350   TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);\r
351 \r
352   /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */\r
353   tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;\r
354   if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))\r
355   {\r
356     __HAL_TIM_ENABLE(htim);\r
357   }\r
358 \r
359   /* Return function status */\r
360   return HAL_OK;\r
361 }\r
362 \r
363 /**\r
364   * @brief  Stops the TIM Hall Sensor Interface in interrupt mode.\r
365   * @param  htim TIM Hall Sensor Interface handle\r
366   * @retval HAL status\r
367   */\r
368 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_IT(TIM_HandleTypeDef *htim)\r
369 {\r
370   /* Check the parameters */\r
371   assert_param(IS_TIM_HALL_SENSOR_INTERFACE_INSTANCE(htim->Instance));\r
372 \r
373   /* Disable the Input Capture channel 1\r
374     (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
375   TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);\r
376 \r
377   /* Disable the capture compare Interrupts event */\r
378   __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);\r
379 \r
380   /* Disable the Peripheral */\r
381   __HAL_TIM_DISABLE(htim);\r
382 \r
383   /* Return function status */\r
384   return HAL_OK;\r
385 }\r
386 \r
387 /**\r
388   * @brief  Starts the TIM Hall Sensor Interface in DMA mode.\r
389   * @param  htim TIM Hall Sensor Interface handle\r
390   * @param  pData The destination Buffer address.\r
391   * @param  Length The length of data to be transferred from TIM peripheral to memory.\r
392   * @retval HAL status\r
393   */\r
394 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start_DMA(TIM_HandleTypeDef *htim, uint32_t *pData, uint16_t Length)\r
395 {\r
396   uint32_t tmpsmcr;\r
397 \r
398   /* Check the parameters */\r
399   assert_param(IS_TIM_HALL_SENSOR_INTERFACE_INSTANCE(htim->Instance));\r
400 \r
401   if ((htim->State == HAL_TIM_STATE_BUSY))\r
402   {\r
403     return HAL_BUSY;\r
404   }\r
405   else if ((htim->State == HAL_TIM_STATE_READY))\r
406   {\r
407     if (((uint32_t)pData == 0U) && (Length > 0U))\r
408     {\r
409       return HAL_ERROR;\r
410     }\r
411     else\r
412     {\r
413       htim->State = HAL_TIM_STATE_BUSY;\r
414     }\r
415   }\r
416   else\r
417   {\r
418     /* nothing to do */\r
419   }\r
420   /* Enable the Input Capture channel 1\r
421     (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
422   TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);\r
423 \r
424   /* Set the DMA Input Capture 1 Callbacks */\r
425   htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMACaptureCplt;\r
426   htim->hdma[TIM_DMA_ID_CC1]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt;\r
427   /* Set the DMA error callback */\r
428   htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ;\r
429 \r
430   /* Enable the DMA channel for Capture 1*/\r
431   if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)&htim->Instance->CCR1, (uint32_t)pData, Length) != HAL_OK)\r
432   {\r
433     return HAL_ERROR;\r
434   }\r
435   /* Enable the capture compare 1 Interrupt */\r
436   __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1);\r
437 \r
438   /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */\r
439   tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;\r
440   if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))\r
441   {\r
442     __HAL_TIM_ENABLE(htim);\r
443   }\r
444 \r
445   /* Return function status */\r
446   return HAL_OK;\r
447 }\r
448 \r
449 /**\r
450   * @brief  Stops the TIM Hall Sensor Interface in DMA mode.\r
451   * @param  htim TIM Hall Sensor Interface handle\r
452   * @retval HAL status\r
453   */\r
454 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_DMA(TIM_HandleTypeDef *htim)\r
455 {\r
456   /* Check the parameters */\r
457   assert_param(IS_TIM_HALL_SENSOR_INTERFACE_INSTANCE(htim->Instance));\r
458 \r
459   /* Disable the Input Capture channel 1\r
460     (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
461   TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);\r
462 \r
463 \r
464   /* Disable the capture compare Interrupts 1 event */\r
465   __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1);\r
466 \r
467   (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC1]);\r
468   /* Disable the Peripheral */\r
469   __HAL_TIM_DISABLE(htim);\r
470 \r
471   /* Return function status */\r
472   return HAL_OK;\r
473 }\r
474 \r
475 /**\r
476   * @}\r
477   */\r
478 \r
479 /** @defgroup TIMEx_Exported_Functions_Group2 Extended Timer Complementary Output Compare functions\r
480   *  @brief   Timer Complementary Output Compare functions\r
481   *\r
482 @verbatim\r
483   ==============================================================================\r
484               ##### Timer Complementary Output Compare functions #####\r
485   ==============================================================================\r
486   [..]\r
487     This section provides functions allowing to:\r
488     (+) Start the Complementary Output Compare/PWM.\r
489     (+) Stop the Complementary Output Compare/PWM.\r
490     (+) Start the Complementary Output Compare/PWM and enable interrupts.\r
491     (+) Stop the Complementary Output Compare/PWM and disable interrupts.\r
492     (+) Start the Complementary Output Compare/PWM and enable DMA transfers.\r
493     (+) Stop the Complementary Output Compare/PWM and disable DMA transfers.\r
494 \r
495 @endverbatim\r
496   * @{\r
497   */\r
498 \r
499 /**\r
500   * @brief  Starts the TIM Output Compare signal generation on the complementary\r
501   *         output.\r
502   * @param  htim TIM Output Compare handle\r
503   * @param  Channel TIM Channel to be enabled\r
504   *          This parameter can be one of the following values:\r
505   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected\r
506   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected\r
507   *            @arg TIM_CHANNEL_3: TIM Channel 3 selected\r
508   * @retval HAL status\r
509   */\r
510 HAL_StatusTypeDef HAL_TIMEx_OCN_Start(TIM_HandleTypeDef *htim, uint32_t Channel)\r
511 {\r
512   uint32_t tmpsmcr;\r
513 \r
514   /* Check the parameters */\r
515   assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));\r
516 \r
517   /* Enable the Capture compare channel N */\r
518   TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_ENABLE);\r
519 \r
520   /* Enable the Main Output */\r
521   __HAL_TIM_MOE_ENABLE(htim);\r
522 \r
523   /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */\r
524   tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;\r
525   if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))\r
526   {\r
527     __HAL_TIM_ENABLE(htim);\r
528   }\r
529 \r
530   /* Return function status */\r
531   return HAL_OK;\r
532 }\r
533 \r
534 /**\r
535   * @brief  Stops the TIM Output Compare signal generation on the complementary\r
536   *         output.\r
537   * @param  htim TIM handle\r
538   * @param  Channel TIM Channel to be disabled\r
539   *          This parameter can be one of the following values:\r
540   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected\r
541   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected\r
542   *            @arg TIM_CHANNEL_3: TIM Channel 3 selected\r
543   * @retval HAL status\r
544   */\r
545 HAL_StatusTypeDef HAL_TIMEx_OCN_Stop(TIM_HandleTypeDef *htim, uint32_t Channel)\r
546 {\r
547   /* Check the parameters */\r
548   assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));\r
549 \r
550   /* Disable the Capture compare channel N */\r
551   TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_DISABLE);\r
552 \r
553   /* Disable the Main Output */\r
554   __HAL_TIM_MOE_DISABLE(htim);\r
555 \r
556   /* Disable the Peripheral */\r
557   __HAL_TIM_DISABLE(htim);\r
558 \r
559   /* Return function status */\r
560   return HAL_OK;\r
561 }\r
562 \r
563 /**\r
564   * @brief  Starts the TIM Output Compare signal generation in interrupt mode\r
565   *         on the complementary output.\r
566   * @param  htim TIM OC handle\r
567   * @param  Channel TIM Channel to be enabled\r
568   *          This parameter can be one of the following values:\r
569   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected\r
570   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected\r
571   *            @arg TIM_CHANNEL_3: TIM Channel 3 selected\r
572   * @retval HAL status\r
573   */\r
574 HAL_StatusTypeDef HAL_TIMEx_OCN_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel)\r
575 {\r
576   uint32_t tmpsmcr;\r
577 \r
578   /* Check the parameters */\r
579   assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));\r
580 \r
581   switch (Channel)\r
582   {\r
583     case TIM_CHANNEL_1:\r
584     {\r
585       /* Enable the TIM Output Compare interrupt */\r
586       __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);\r
587       break;\r
588     }\r
589 \r
590     case TIM_CHANNEL_2:\r
591     {\r
592       /* Enable the TIM Output Compare interrupt */\r
593       __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);\r
594       break;\r
595     }\r
596 \r
597     case TIM_CHANNEL_3:\r
598     {\r
599       /* Enable the TIM Output Compare interrupt */\r
600       __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC3);\r
601       break;\r
602     }\r
603 \r
604 \r
605     default:\r
606       break;\r
607   }\r
608 \r
609   /* Enable the TIM Break interrupt */\r
610   __HAL_TIM_ENABLE_IT(htim, TIM_IT_BREAK);\r
611 \r
612   /* Enable the Capture compare channel N */\r
613   TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_ENABLE);\r
614 \r
615   /* Enable the Main Output */\r
616   __HAL_TIM_MOE_ENABLE(htim);\r
617 \r
618   /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */\r
619   tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;\r
620   if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))\r
621   {\r
622     __HAL_TIM_ENABLE(htim);\r
623   }\r
624 \r
625   /* Return function status */\r
626   return HAL_OK;\r
627 }\r
628 \r
629 /**\r
630   * @brief  Stops the TIM Output Compare signal generation in interrupt mode\r
631   *         on the complementary output.\r
632   * @param  htim TIM Output Compare handle\r
633   * @param  Channel TIM Channel to be disabled\r
634   *          This parameter can be one of the following values:\r
635   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected\r
636   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected\r
637   *            @arg TIM_CHANNEL_3: TIM Channel 3 selected\r
638   * @retval HAL status\r
639   */\r
640 HAL_StatusTypeDef HAL_TIMEx_OCN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel)\r
641 {\r
642   uint32_t tmpccer;\r
643   /* Check the parameters */\r
644   assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));\r
645 \r
646   switch (Channel)\r
647   {\r
648     case TIM_CHANNEL_1:\r
649     {\r
650       /* Disable the TIM Output Compare interrupt */\r
651       __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);\r
652       break;\r
653     }\r
654 \r
655     case TIM_CHANNEL_2:\r
656     {\r
657       /* Disable the TIM Output Compare interrupt */\r
658       __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);\r
659       break;\r
660     }\r
661 \r
662     case TIM_CHANNEL_3:\r
663     {\r
664       /* Disable the TIM Output Compare interrupt */\r
665       __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC3);\r
666       break;\r
667     }\r
668 \r
669     default:\r
670       break;\r
671   }\r
672 \r
673   /* Disable the Capture compare channel N */\r
674   TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_DISABLE);\r
675 \r
676   /* Disable the TIM Break interrupt (only if no more channel is active) */\r
677   tmpccer = htim->Instance->CCER;\r
678   if ((tmpccer & (TIM_CCER_CC1NE | TIM_CCER_CC2NE | TIM_CCER_CC3NE)) == (uint32_t)RESET)\r
679   {\r
680     __HAL_TIM_DISABLE_IT(htim, TIM_IT_BREAK);\r
681   }\r
682 \r
683   /* Disable the Main Output */\r
684   __HAL_TIM_MOE_DISABLE(htim);\r
685 \r
686   /* Disable the Peripheral */\r
687   __HAL_TIM_DISABLE(htim);\r
688 \r
689   /* Return function status */\r
690   return HAL_OK;\r
691 }\r
692 \r
693 /**\r
694   * @brief  Starts the TIM Output Compare signal generation in DMA mode\r
695   *         on the complementary output.\r
696   * @param  htim TIM Output Compare handle\r
697   * @param  Channel TIM Channel to be enabled\r
698   *          This parameter can be one of the following values:\r
699   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected\r
700   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected\r
701   *            @arg TIM_CHANNEL_3: TIM Channel 3 selected\r
702   * @param  pData The source Buffer address.\r
703   * @param  Length The length of data to be transferred from memory to TIM peripheral\r
704   * @retval HAL status\r
705   */\r
706 HAL_StatusTypeDef HAL_TIMEx_OCN_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length)\r
707 {\r
708   uint32_t tmpsmcr;\r
709 \r
710   /* Check the parameters */\r
711   assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));\r
712 \r
713   if ((htim->State == HAL_TIM_STATE_BUSY))\r
714   {\r
715     return HAL_BUSY;\r
716   }\r
717   else if ((htim->State == HAL_TIM_STATE_READY))\r
718   {\r
719     if (((uint32_t)pData == 0U) && (Length > 0U))\r
720     {\r
721       return HAL_ERROR;\r
722     }\r
723     else\r
724     {\r
725       htim->State = HAL_TIM_STATE_BUSY;\r
726     }\r
727   }\r
728   else\r
729   {\r
730     /* nothing to do  */\r
731   }\r
732 \r
733   switch (Channel)\r
734   {\r
735     case TIM_CHANNEL_1:\r
736     {\r
737       /* Set the DMA compare callbacks */\r
738       htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMADelayPulseCplt;\r
739       htim->hdma[TIM_DMA_ID_CC1]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt;\r
740 \r
741       /* Set the DMA error callback */\r
742       htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ;\r
743 \r
744       /* Enable the DMA channel */\r
745       if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)pData, (uint32_t)&htim->Instance->CCR1, Length) != HAL_OK)\r
746       {\r
747         return HAL_ERROR;\r
748       }\r
749       /* Enable the TIM Output Compare DMA request */\r
750       __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1);\r
751       break;\r
752     }\r
753 \r
754     case TIM_CHANNEL_2:\r
755     {\r
756       /* Set the DMA compare callbacks */\r
757       htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMADelayPulseCplt;\r
758       htim->hdma[TIM_DMA_ID_CC2]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt;\r
759 \r
760       /* Set the DMA error callback */\r
761       htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError ;\r
762 \r
763       /* Enable the DMA channel */\r
764       if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)pData, (uint32_t)&htim->Instance->CCR2, Length) != HAL_OK)\r
765       {\r
766         return HAL_ERROR;\r
767       }\r
768       /* Enable the TIM Output Compare DMA request */\r
769       __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2);\r
770       break;\r
771     }\r
772 \r
773     case TIM_CHANNEL_3:\r
774     {\r
775       /* Set the DMA compare callbacks */\r
776       htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMADelayPulseCplt;\r
777       htim->hdma[TIM_DMA_ID_CC3]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt;\r
778 \r
779       /* Set the DMA error callback */\r
780       htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = TIM_DMAError ;\r
781 \r
782       /* Enable the DMA channel */\r
783       if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)pData, (uint32_t)&htim->Instance->CCR3, Length) != HAL_OK)\r
784       {\r
785         return HAL_ERROR;\r
786       }\r
787       /* Enable the TIM Output Compare DMA request */\r
788       __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC3);\r
789       break;\r
790     }\r
791 \r
792     default:\r
793       break;\r
794   }\r
795 \r
796   /* Enable the Capture compare channel N */\r
797   TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_ENABLE);\r
798 \r
799   /* Enable the Main Output */\r
800   __HAL_TIM_MOE_ENABLE(htim);\r
801 \r
802   /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */\r
803   tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;\r
804   if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))\r
805   {\r
806     __HAL_TIM_ENABLE(htim);\r
807   }\r
808 \r
809   /* Return function status */\r
810   return HAL_OK;\r
811 }\r
812 \r
813 /**\r
814   * @brief  Stops the TIM Output Compare signal generation in DMA mode\r
815   *         on the complementary output.\r
816   * @param  htim TIM Output Compare handle\r
817   * @param  Channel TIM Channel to be disabled\r
818   *          This parameter can be one of the following values:\r
819   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected\r
820   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected\r
821   *            @arg TIM_CHANNEL_3: TIM Channel 3 selected\r
822   * @retval HAL status\r
823   */\r
824 HAL_StatusTypeDef HAL_TIMEx_OCN_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel)\r
825 {\r
826   /* Check the parameters */\r
827   assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));\r
828 \r
829   switch (Channel)\r
830   {\r
831     case TIM_CHANNEL_1:\r
832     {\r
833       /* Disable the TIM Output Compare DMA request */\r
834       __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1);\r
835       (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC1]);\r
836       break;\r
837     }\r
838 \r
839     case TIM_CHANNEL_2:\r
840     {\r
841       /* Disable the TIM Output Compare DMA request */\r
842       __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2);\r
843       (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC2]);\r
844       break;\r
845     }\r
846 \r
847     case TIM_CHANNEL_3:\r
848     {\r
849       /* Disable the TIM Output Compare DMA request */\r
850       __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC3);\r
851       (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC3]);\r
852       break;\r
853     }\r
854 \r
855     default:\r
856       break;\r
857   }\r
858 \r
859   /* Disable the Capture compare channel N */\r
860   TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_DISABLE);\r
861 \r
862   /* Disable the Main Output */\r
863   __HAL_TIM_MOE_DISABLE(htim);\r
864 \r
865   /* Disable the Peripheral */\r
866   __HAL_TIM_DISABLE(htim);\r
867 \r
868   /* Change the htim state */\r
869   htim->State = HAL_TIM_STATE_READY;\r
870 \r
871   /* Return function status */\r
872   return HAL_OK;\r
873 }\r
874 \r
875 /**\r
876   * @}\r
877   */\r
878 \r
879 /** @defgroup TIMEx_Exported_Functions_Group3 Extended Timer Complementary PWM functions\r
880   * @brief    Timer Complementary PWM functions\r
881   *\r
882 @verbatim\r
883   ==============================================================================\r
884                  ##### Timer Complementary PWM functions #####\r
885   ==============================================================================\r
886   [..]\r
887     This section provides functions allowing to:\r
888     (+) Start the Complementary PWM.\r
889     (+) Stop the Complementary PWM.\r
890     (+) Start the Complementary PWM and enable interrupts.\r
891     (+) Stop the Complementary PWM and disable interrupts.\r
892     (+) Start the Complementary PWM and enable DMA transfers.\r
893     (+) Stop the Complementary PWM and disable DMA transfers.\r
894     (+) Start the Complementary Input Capture measurement.\r
895     (+) Stop the Complementary Input Capture.\r
896     (+) Start the Complementary Input Capture and enable interrupts.\r
897     (+) Stop the Complementary Input Capture and disable interrupts.\r
898     (+) Start the Complementary Input Capture and enable DMA transfers.\r
899     (+) Stop the Complementary Input Capture and disable DMA transfers.\r
900     (+) Start the Complementary One Pulse generation.\r
901     (+) Stop the Complementary One Pulse.\r
902     (+) Start the Complementary One Pulse and enable interrupts.\r
903     (+) Stop the Complementary One Pulse and disable interrupts.\r
904 \r
905 @endverbatim\r
906   * @{\r
907   */\r
908 \r
909 /**\r
910   * @brief  Starts the PWM signal generation on the complementary output.\r
911   * @param  htim TIM handle\r
912   * @param  Channel TIM Channel to be enabled\r
913   *          This parameter can be one of the following values:\r
914   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected\r
915   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected\r
916   *            @arg TIM_CHANNEL_3: TIM Channel 3 selected\r
917   * @retval HAL status\r
918   */\r
919 HAL_StatusTypeDef HAL_TIMEx_PWMN_Start(TIM_HandleTypeDef *htim, uint32_t Channel)\r
920 {\r
921   uint32_t tmpsmcr;\r
922 \r
923   /* Check the parameters */\r
924   assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));\r
925 \r
926   /* Enable the complementary PWM output  */\r
927   TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_ENABLE);\r
928 \r
929   /* Enable the Main Output */\r
930   __HAL_TIM_MOE_ENABLE(htim);\r
931 \r
932   /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */\r
933   tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;\r
934   if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))\r
935   {\r
936     __HAL_TIM_ENABLE(htim);\r
937   }\r
938 \r
939   /* Return function status */\r
940   return HAL_OK;\r
941 }\r
942 \r
943 /**\r
944   * @brief  Stops the PWM signal generation on the complementary output.\r
945   * @param  htim TIM handle\r
946   * @param  Channel TIM Channel to be disabled\r
947   *          This parameter can be one of the following values:\r
948   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected\r
949   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected\r
950   *            @arg TIM_CHANNEL_3: TIM Channel 3 selected\r
951   * @retval HAL status\r
952   */\r
953 HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop(TIM_HandleTypeDef *htim, uint32_t Channel)\r
954 {\r
955   /* Check the parameters */\r
956   assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));\r
957 \r
958   /* Disable the complementary PWM output  */\r
959   TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_DISABLE);\r
960 \r
961   /* Disable the Main Output */\r
962   __HAL_TIM_MOE_DISABLE(htim);\r
963 \r
964   /* Disable the Peripheral */\r
965   __HAL_TIM_DISABLE(htim);\r
966 \r
967   /* Return function status */\r
968   return HAL_OK;\r
969 }\r
970 \r
971 /**\r
972   * @brief  Starts the PWM signal generation in interrupt mode on the\r
973   *         complementary output.\r
974   * @param  htim TIM handle\r
975   * @param  Channel TIM Channel to be disabled\r
976   *          This parameter can be one of the following values:\r
977   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected\r
978   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected\r
979   *            @arg TIM_CHANNEL_3: TIM Channel 3 selected\r
980   * @retval HAL status\r
981   */\r
982 HAL_StatusTypeDef HAL_TIMEx_PWMN_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel)\r
983 {\r
984   uint32_t tmpsmcr;\r
985 \r
986   /* Check the parameters */\r
987   assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));\r
988 \r
989   switch (Channel)\r
990   {\r
991     case TIM_CHANNEL_1:\r
992     {\r
993       /* Enable the TIM Capture/Compare 1 interrupt */\r
994       __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);\r
995       break;\r
996     }\r
997 \r
998     case TIM_CHANNEL_2:\r
999     {\r
1000       /* Enable the TIM Capture/Compare 2 interrupt */\r
1001       __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);\r
1002       break;\r
1003     }\r
1004 \r
1005     case TIM_CHANNEL_3:\r
1006     {\r
1007       /* Enable the TIM Capture/Compare 3 interrupt */\r
1008       __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC3);\r
1009       break;\r
1010     }\r
1011 \r
1012     default:\r
1013       break;\r
1014   }\r
1015 \r
1016   /* Enable the TIM Break interrupt */\r
1017   __HAL_TIM_ENABLE_IT(htim, TIM_IT_BREAK);\r
1018 \r
1019   /* Enable the complementary PWM output  */\r
1020   TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_ENABLE);\r
1021 \r
1022   /* Enable the Main Output */\r
1023   __HAL_TIM_MOE_ENABLE(htim);\r
1024 \r
1025   /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */\r
1026   tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;\r
1027   if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))\r
1028   {\r
1029     __HAL_TIM_ENABLE(htim);\r
1030   }\r
1031 \r
1032   /* Return function status */\r
1033   return HAL_OK;\r
1034 }\r
1035 \r
1036 /**\r
1037   * @brief  Stops the PWM signal generation in interrupt mode on the\r
1038   *         complementary output.\r
1039   * @param  htim TIM handle\r
1040   * @param  Channel TIM Channel to be disabled\r
1041   *          This parameter can be one of the following values:\r
1042   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected\r
1043   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected\r
1044   *            @arg TIM_CHANNEL_3: TIM Channel 3 selected\r
1045   * @retval HAL status\r
1046   */\r
1047 HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel)\r
1048 {\r
1049   uint32_t tmpccer;\r
1050 \r
1051   /* Check the parameters */\r
1052   assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));\r
1053 \r
1054   switch (Channel)\r
1055   {\r
1056     case TIM_CHANNEL_1:\r
1057     {\r
1058       /* Disable the TIM Capture/Compare 1 interrupt */\r
1059       __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);\r
1060       break;\r
1061     }\r
1062 \r
1063     case TIM_CHANNEL_2:\r
1064     {\r
1065       /* Disable the TIM Capture/Compare 2 interrupt */\r
1066       __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);\r
1067       break;\r
1068     }\r
1069 \r
1070     case TIM_CHANNEL_3:\r
1071     {\r
1072       /* Disable the TIM Capture/Compare 3 interrupt */\r
1073       __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC3);\r
1074       break;\r
1075     }\r
1076 \r
1077     default:\r
1078       break;\r
1079   }\r
1080 \r
1081   /* Disable the complementary PWM output  */\r
1082   TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_DISABLE);\r
1083 \r
1084   /* Disable the TIM Break interrupt (only if no more channel is active) */\r
1085   tmpccer = htim->Instance->CCER;\r
1086   if ((tmpccer & (TIM_CCER_CC1NE | TIM_CCER_CC2NE | TIM_CCER_CC3NE)) == (uint32_t)RESET)\r
1087   {\r
1088     __HAL_TIM_DISABLE_IT(htim, TIM_IT_BREAK);\r
1089   }\r
1090 \r
1091   /* Disable the Main Output */\r
1092   __HAL_TIM_MOE_DISABLE(htim);\r
1093 \r
1094   /* Disable the Peripheral */\r
1095   __HAL_TIM_DISABLE(htim);\r
1096 \r
1097   /* Return function status */\r
1098   return HAL_OK;\r
1099 }\r
1100 \r
1101 /**\r
1102   * @brief  Starts the TIM PWM signal generation in DMA mode on the\r
1103   *         complementary output\r
1104   * @param  htim TIM handle\r
1105   * @param  Channel TIM Channel to be enabled\r
1106   *          This parameter can be one of the following values:\r
1107   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected\r
1108   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected\r
1109   *            @arg TIM_CHANNEL_3: TIM Channel 3 selected\r
1110   * @param  pData The source Buffer address.\r
1111   * @param  Length The length of data to be transferred from memory to TIM peripheral\r
1112   * @retval HAL status\r
1113   */\r
1114 HAL_StatusTypeDef HAL_TIMEx_PWMN_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length)\r
1115 {\r
1116   uint32_t tmpsmcr;\r
1117 \r
1118   /* Check the parameters */\r
1119   assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));\r
1120 \r
1121   if ((htim->State == HAL_TIM_STATE_BUSY))\r
1122   {\r
1123     return HAL_BUSY;\r
1124   }\r
1125   else if ((htim->State == HAL_TIM_STATE_READY))\r
1126   {\r
1127     if (((uint32_t)pData == 0U) && (Length > 0U))\r
1128     {\r
1129       return HAL_ERROR;\r
1130     }\r
1131     else\r
1132     {\r
1133       htim->State = HAL_TIM_STATE_BUSY;\r
1134     }\r
1135   }\r
1136   else\r
1137   {\r
1138     /* nothing to do */\r
1139   }\r
1140   switch (Channel)\r
1141   {\r
1142     case TIM_CHANNEL_1:\r
1143     {\r
1144       /* Set the DMA compare callbacks */\r
1145       htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMADelayPulseCplt;\r
1146       htim->hdma[TIM_DMA_ID_CC1]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt;\r
1147 \r
1148       /* Set the DMA error callback */\r
1149       htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ;\r
1150 \r
1151       /* Enable the DMA channel */\r
1152       if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)pData, (uint32_t)&htim->Instance->CCR1, Length) != HAL_OK)\r
1153       {\r
1154         return HAL_ERROR;\r
1155       }\r
1156       /* Enable the TIM Capture/Compare 1 DMA request */\r
1157       __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1);\r
1158       break;\r
1159     }\r
1160 \r
1161     case TIM_CHANNEL_2:\r
1162     {\r
1163       /* Set the DMA compare callbacks */\r
1164       htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMADelayPulseCplt;\r
1165       htim->hdma[TIM_DMA_ID_CC2]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt;\r
1166 \r
1167       /* Set the DMA error callback */\r
1168       htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError ;\r
1169 \r
1170       /* Enable the DMA channel */\r
1171       if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)pData, (uint32_t)&htim->Instance->CCR2, Length) != HAL_OK)\r
1172       {\r
1173         return HAL_ERROR;\r
1174       }\r
1175       /* Enable the TIM Capture/Compare 2 DMA request */\r
1176       __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2);\r
1177       break;\r
1178     }\r
1179 \r
1180     case TIM_CHANNEL_3:\r
1181     {\r
1182       /* Set the DMA compare callbacks */\r
1183       htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMADelayPulseCplt;\r
1184       htim->hdma[TIM_DMA_ID_CC3]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt;\r
1185 \r
1186       /* Set the DMA error callback */\r
1187       htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = TIM_DMAError ;\r
1188 \r
1189       /* Enable the DMA channel */\r
1190       if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)pData, (uint32_t)&htim->Instance->CCR3, Length) != HAL_OK)\r
1191       {\r
1192         return HAL_ERROR;\r
1193       }\r
1194       /* Enable the TIM Capture/Compare 3 DMA request */\r
1195       __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC3);\r
1196       break;\r
1197     }\r
1198 \r
1199     default:\r
1200       break;\r
1201   }\r
1202 \r
1203   /* Enable the complementary PWM output  */\r
1204   TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_ENABLE);\r
1205 \r
1206   /* Enable the Main Output */\r
1207   __HAL_TIM_MOE_ENABLE(htim);\r
1208 \r
1209   /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */\r
1210   tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;\r
1211   if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))\r
1212   {\r
1213     __HAL_TIM_ENABLE(htim);\r
1214   }\r
1215 \r
1216   /* Return function status */\r
1217   return HAL_OK;\r
1218 }\r
1219 \r
1220 /**\r
1221   * @brief  Stops the TIM PWM signal generation in DMA mode on the complementary\r
1222   *         output\r
1223   * @param  htim TIM handle\r
1224   * @param  Channel TIM Channel to be disabled\r
1225   *          This parameter can be one of the following values:\r
1226   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected\r
1227   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected\r
1228   *            @arg TIM_CHANNEL_3: TIM Channel 3 selected\r
1229   * @retval HAL status\r
1230   */\r
1231 HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel)\r
1232 {\r
1233   /* Check the parameters */\r
1234   assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));\r
1235 \r
1236   switch (Channel)\r
1237   {\r
1238     case TIM_CHANNEL_1:\r
1239     {\r
1240       /* Disable the TIM Capture/Compare 1 DMA request */\r
1241       __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1);\r
1242       (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC1]);\r
1243       break;\r
1244     }\r
1245 \r
1246     case TIM_CHANNEL_2:\r
1247     {\r
1248       /* Disable the TIM Capture/Compare 2 DMA request */\r
1249       __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2);\r
1250       (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC2]);\r
1251       break;\r
1252     }\r
1253 \r
1254     case TIM_CHANNEL_3:\r
1255     {\r
1256       /* Disable the TIM Capture/Compare 3 DMA request */\r
1257       __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC3);\r
1258       (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC3]);\r
1259       break;\r
1260     }\r
1261 \r
1262     default:\r
1263       break;\r
1264   }\r
1265 \r
1266   /* Disable the complementary PWM output */\r
1267   TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_DISABLE);\r
1268 \r
1269   /* Disable the Main Output */\r
1270   __HAL_TIM_MOE_DISABLE(htim);\r
1271 \r
1272   /* Disable the Peripheral */\r
1273   __HAL_TIM_DISABLE(htim);\r
1274 \r
1275   /* Change the htim state */\r
1276   htim->State = HAL_TIM_STATE_READY;\r
1277 \r
1278   /* Return function status */\r
1279   return HAL_OK;\r
1280 }\r
1281 \r
1282 /**\r
1283   * @}\r
1284   */\r
1285 \r
1286 /** @defgroup TIMEx_Exported_Functions_Group4 Extended Timer Complementary One Pulse functions\r
1287   * @brief    Timer Complementary One Pulse functions\r
1288   *\r
1289 @verbatim\r
1290   ==============================================================================\r
1291                 ##### Timer Complementary One Pulse functions #####\r
1292   ==============================================================================\r
1293   [..]\r
1294     This section provides functions allowing to:\r
1295     (+) Start the Complementary One Pulse generation.\r
1296     (+) Stop the Complementary One Pulse.\r
1297     (+) Start the Complementary One Pulse and enable interrupts.\r
1298     (+) Stop the Complementary One Pulse and disable interrupts.\r
1299 \r
1300 @endverbatim\r
1301   * @{\r
1302   */\r
1303 \r
1304 /**\r
1305   * @brief  Starts the TIM One Pulse signal generation on the complementary\r
1306   *         output.\r
1307   * @param  htim TIM One Pulse handle\r
1308   * @param  OutputChannel TIM Channel to be enabled\r
1309   *          This parameter can be one of the following values:\r
1310   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected\r
1311   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected\r
1312   * @retval HAL status\r
1313   */\r
1314 HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Start(TIM_HandleTypeDef *htim, uint32_t OutputChannel)\r
1315 {\r
1316   /* Check the parameters */\r
1317   assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, OutputChannel));\r
1318 \r
1319   /* Enable the complementary One Pulse output */\r
1320   TIM_CCxNChannelCmd(htim->Instance, OutputChannel, TIM_CCxN_ENABLE);\r
1321 \r
1322   /* Enable the Main Output */\r
1323   __HAL_TIM_MOE_ENABLE(htim);\r
1324 \r
1325   /* Return function status */\r
1326   return HAL_OK;\r
1327 }\r
1328 \r
1329 /**\r
1330   * @brief  Stops the TIM One Pulse signal generation on the complementary\r
1331   *         output.\r
1332   * @param  htim TIM One Pulse handle\r
1333   * @param  OutputChannel TIM Channel to be disabled\r
1334   *          This parameter can be one of the following values:\r
1335   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected\r
1336   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected\r
1337   * @retval HAL status\r
1338   */\r
1339 HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Stop(TIM_HandleTypeDef *htim, uint32_t OutputChannel)\r
1340 {\r
1341 \r
1342   /* Check the parameters */\r
1343   assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, OutputChannel));\r
1344 \r
1345   /* Disable the complementary One Pulse output */\r
1346   TIM_CCxNChannelCmd(htim->Instance, OutputChannel, TIM_CCxN_DISABLE);\r
1347 \r
1348   /* Disable the Main Output */\r
1349   __HAL_TIM_MOE_DISABLE(htim);\r
1350 \r
1351   /* Disable the Peripheral */\r
1352   __HAL_TIM_DISABLE(htim);\r
1353 \r
1354   /* Return function status */\r
1355   return HAL_OK;\r
1356 }\r
1357 \r
1358 /**\r
1359   * @brief  Starts the TIM One Pulse signal generation in interrupt mode on the\r
1360   *         complementary channel.\r
1361   * @param  htim TIM One Pulse handle\r
1362   * @param  OutputChannel TIM Channel to be enabled\r
1363   *          This parameter can be one of the following values:\r
1364   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected\r
1365   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected\r
1366   * @retval HAL status\r
1367   */\r
1368 HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Start_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel)\r
1369 {\r
1370   /* Check the parameters */\r
1371   assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, OutputChannel));\r
1372 \r
1373   /* Enable the TIM Capture/Compare 1 interrupt */\r
1374   __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);\r
1375 \r
1376   /* Enable the TIM Capture/Compare 2 interrupt */\r
1377   __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);\r
1378 \r
1379   /* Enable the complementary One Pulse output */\r
1380   TIM_CCxNChannelCmd(htim->Instance, OutputChannel, TIM_CCxN_ENABLE);\r
1381 \r
1382   /* Enable the Main Output */\r
1383   __HAL_TIM_MOE_ENABLE(htim);\r
1384 \r
1385   /* Return function status */\r
1386   return HAL_OK;\r
1387 }\r
1388 \r
1389 /**\r
1390   * @brief  Stops the TIM One Pulse signal generation in interrupt mode on the\r
1391   *         complementary channel.\r
1392   * @param  htim TIM One Pulse handle\r
1393   * @param  OutputChannel TIM Channel to be disabled\r
1394   *          This parameter can be one of the following values:\r
1395   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected\r
1396   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected\r
1397   * @retval HAL status\r
1398   */\r
1399 HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel)\r
1400 {\r
1401   /* Check the parameters */\r
1402   assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, OutputChannel));\r
1403 \r
1404   /* Disable the TIM Capture/Compare 1 interrupt */\r
1405   __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);\r
1406 \r
1407   /* Disable the TIM Capture/Compare 2 interrupt */\r
1408   __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);\r
1409 \r
1410   /* Disable the complementary One Pulse output */\r
1411   TIM_CCxNChannelCmd(htim->Instance, OutputChannel, TIM_CCxN_DISABLE);\r
1412 \r
1413   /* Disable the Main Output */\r
1414   __HAL_TIM_MOE_DISABLE(htim);\r
1415 \r
1416   /* Disable the Peripheral */\r
1417   __HAL_TIM_DISABLE(htim);\r
1418 \r
1419   /* Return function status */\r
1420   return HAL_OK;\r
1421 }\r
1422 \r
1423 /**\r
1424   * @}\r
1425   */\r
1426 \r
1427 /** @defgroup TIMEx_Exported_Functions_Group5 Extended Peripheral Control functions\r
1428   * @brief    Peripheral Control functions\r
1429   *\r
1430 @verbatim\r
1431   ==============================================================================\r
1432                     ##### Peripheral Control functions #####\r
1433   ==============================================================================\r
1434   [..]\r
1435     This section provides functions allowing to:\r
1436       (+) Configure the commutation event in case of use of the Hall sensor interface.\r
1437       (+) Configure Output channels for OC and PWM mode.\r
1438 \r
1439       (+) Configure Complementary channels, break features and dead time.\r
1440       (+) Configure Master synchronization.\r
1441       (+) Configure timer remapping capabilities.\r
1442       (+) Enable or disable channel grouping.\r
1443 \r
1444 @endverbatim\r
1445   * @{\r
1446   */\r
1447 \r
1448 /**\r
1449   * @brief  Configure the TIM commutation event sequence.\r
1450   * @note  This function is mandatory to use the commutation event in order to\r
1451   *        update the configuration at each commutation detection on the TRGI input of the Timer,\r
1452   *        the typical use of this feature is with the use of another Timer(interface Timer)\r
1453   *        configured in Hall sensor interface, this interface Timer will generate the\r
1454   *        commutation at its TRGO output (connected to Timer used in this function) each time\r
1455   *        the TI1 of the Interface Timer detect a commutation at its input TI1.\r
1456   * @param  htim TIM handle\r
1457   * @param  InputTrigger the Internal trigger corresponding to the Timer Interfacing with the Hall sensor\r
1458   *          This parameter can be one of the following values:\r
1459   *            @arg TIM_TS_ITR0: Internal trigger 0 selected\r
1460   *            @arg TIM_TS_ITR1: Internal trigger 1 selected\r
1461   *            @arg TIM_TS_ITR2: Internal trigger 2 selected\r
1462   *            @arg TIM_TS_ITR3: Internal trigger 3 selected\r
1463   *            @arg TIM_TS_NONE: No trigger is needed\r
1464   * @param  CommutationSource the Commutation Event source\r
1465   *          This parameter can be one of the following values:\r
1466   *            @arg TIM_COMMUTATION_TRGI: Commutation source is the TRGI of the Interface Timer\r
1467   *            @arg TIM_COMMUTATION_SOFTWARE:  Commutation source is set by software using the COMG bit\r
1468   * @retval HAL status\r
1469   */\r
1470 HAL_StatusTypeDef HAL_TIMEx_ConfigCommutEvent(TIM_HandleTypeDef *htim, uint32_t  InputTrigger,\r
1471                                               uint32_t  CommutationSource)\r
1472 {\r
1473   /* Check the parameters */\r
1474   assert_param(IS_TIM_COMMUTATION_EVENT_INSTANCE(htim->Instance));\r
1475   assert_param(IS_TIM_INTERNAL_TRIGGEREVENT_SELECTION(InputTrigger));\r
1476 \r
1477   __HAL_LOCK(htim);\r
1478 \r
1479   if ((InputTrigger == TIM_TS_ITR0) || (InputTrigger == TIM_TS_ITR1) ||\r
1480       (InputTrigger == TIM_TS_ITR2) || (InputTrigger == TIM_TS_ITR3))\r
1481   {\r
1482     /* Select the Input trigger */\r
1483     htim->Instance->SMCR &= ~TIM_SMCR_TS;\r
1484     htim->Instance->SMCR |= InputTrigger;\r
1485   }\r
1486 \r
1487   /* Select the Capture Compare preload feature */\r
1488   htim->Instance->CR2 |= TIM_CR2_CCPC;\r
1489   /* Select the Commutation event source */\r
1490   htim->Instance->CR2 &= ~TIM_CR2_CCUS;\r
1491   htim->Instance->CR2 |= CommutationSource;\r
1492 \r
1493   /* Disable Commutation Interrupt */\r
1494   __HAL_TIM_DISABLE_IT(htim, TIM_IT_COM);\r
1495 \r
1496   /* Disable Commutation DMA request */\r
1497   __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_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 interrupt.\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   * @param  htim TIM handle\r
1513   * @param  InputTrigger the Internal trigger corresponding to the Timer Interfacing with the Hall sensor\r
1514   *          This parameter can be one of the following values:\r
1515   *            @arg TIM_TS_ITR0: Internal trigger 0 selected\r
1516   *            @arg TIM_TS_ITR1: Internal trigger 1 selected\r
1517   *            @arg TIM_TS_ITR2: Internal trigger 2 selected\r
1518   *            @arg TIM_TS_ITR3: Internal trigger 3 selected\r
1519   *            @arg TIM_TS_NONE: No trigger is needed\r
1520   * @param  CommutationSource the Commutation Event source\r
1521   *          This parameter can be one of the following values:\r
1522   *            @arg TIM_COMMUTATION_TRGI: Commutation source is the TRGI of the Interface Timer\r
1523   *            @arg TIM_COMMUTATION_SOFTWARE:  Commutation source is set by software using the COMG bit\r
1524   * @retval HAL status\r
1525   */\r
1526 HAL_StatusTypeDef HAL_TIMEx_ConfigCommutEvent_IT(TIM_HandleTypeDef *htim, uint32_t  InputTrigger,\r
1527                                                  uint32_t  CommutationSource)\r
1528 {\r
1529   /* Check the parameters */\r
1530   assert_param(IS_TIM_COMMUTATION_EVENT_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   /* Disable Commutation DMA request */\r
1550   __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_COM);\r
1551 \r
1552   /* Enable the Commutation Interrupt */\r
1553   __HAL_TIM_ENABLE_IT(htim, TIM_IT_COM);\r
1554 \r
1555   __HAL_UNLOCK(htim);\r
1556 \r
1557   return HAL_OK;\r
1558 }\r
1559 \r
1560 /**\r
1561   * @brief  Configure the TIM commutation event sequence with DMA.\r
1562   * @note  This function is mandatory to use the commutation event in order to\r
1563   *        update the configuration at each commutation detection on the TRGI input of the Timer,\r
1564   *        the typical use of this feature is with the use of another Timer(interface Timer)\r
1565   *        configured in Hall sensor interface, this interface Timer will generate the\r
1566   *        commutation at its TRGO output (connected to Timer used in this function) each time\r
1567   *        the TI1 of the Interface Timer detect a commutation at its input TI1.\r
1568   * @note  The user should configure the DMA in his own software, in This function only the COMDE bit is set\r
1569   * @param  htim TIM handle\r
1570   * @param  InputTrigger the Internal trigger corresponding to the Timer Interfacing with the Hall sensor\r
1571   *          This parameter can be one of the following values:\r
1572   *            @arg TIM_TS_ITR0: Internal trigger 0 selected\r
1573   *            @arg TIM_TS_ITR1: Internal trigger 1 selected\r
1574   *            @arg TIM_TS_ITR2: Internal trigger 2 selected\r
1575   *            @arg TIM_TS_ITR3: Internal trigger 3 selected\r
1576   *            @arg TIM_TS_NONE: No trigger is needed\r
1577   * @param  CommutationSource the Commutation Event source\r
1578   *          This parameter can be one of the following values:\r
1579   *            @arg TIM_COMMUTATION_TRGI: Commutation source is the TRGI of the Interface Timer\r
1580   *            @arg TIM_COMMUTATION_SOFTWARE:  Commutation source is set by software using the COMG bit\r
1581   * @retval HAL status\r
1582   */\r
1583 HAL_StatusTypeDef HAL_TIMEx_ConfigCommutEvent_DMA(TIM_HandleTypeDef *htim, uint32_t  InputTrigger,\r
1584                                                   uint32_t  CommutationSource)\r
1585 {\r
1586   /* Check the parameters */\r
1587   assert_param(IS_TIM_COMMUTATION_EVENT_INSTANCE(htim->Instance));\r
1588   assert_param(IS_TIM_INTERNAL_TRIGGEREVENT_SELECTION(InputTrigger));\r
1589 \r
1590   __HAL_LOCK(htim);\r
1591 \r
1592   if ((InputTrigger == TIM_TS_ITR0) || (InputTrigger == TIM_TS_ITR1) ||\r
1593       (InputTrigger == TIM_TS_ITR2) || (InputTrigger == TIM_TS_ITR3))\r
1594   {\r
1595     /* Select the Input trigger */\r
1596     htim->Instance->SMCR &= ~TIM_SMCR_TS;\r
1597     htim->Instance->SMCR |= InputTrigger;\r
1598   }\r
1599 \r
1600   /* Select the Capture Compare preload feature */\r
1601   htim->Instance->CR2 |= TIM_CR2_CCPC;\r
1602   /* Select the Commutation event source */\r
1603   htim->Instance->CR2 &= ~TIM_CR2_CCUS;\r
1604   htim->Instance->CR2 |= CommutationSource;\r
1605 \r
1606   /* Enable the Commutation DMA Request */\r
1607   /* Set the DMA Commutation Callback */\r
1608   htim->hdma[TIM_DMA_ID_COMMUTATION]->XferCpltCallback = TIMEx_DMACommutationCplt;\r
1609   htim->hdma[TIM_DMA_ID_COMMUTATION]->XferHalfCpltCallback = TIMEx_DMACommutationHalfCplt;\r
1610   /* Set the DMA error callback */\r
1611   htim->hdma[TIM_DMA_ID_COMMUTATION]->XferErrorCallback = TIM_DMAError;\r
1612 \r
1613   /* Disable Commutation Interrupt */\r
1614   __HAL_TIM_DISABLE_IT(htim, TIM_IT_COM);\r
1615 \r
1616   /* Enable the Commutation DMA Request */\r
1617   __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_COM);\r
1618 \r
1619   __HAL_UNLOCK(htim);\r
1620 \r
1621   return HAL_OK;\r
1622 }\r
1623 \r
1624 /**\r
1625   * @brief  Configures the TIM in master mode.\r
1626   * @param  htim TIM handle.\r
1627   * @param  sMasterConfig pointer to a TIM_MasterConfigTypeDef structure that\r
1628   *         contains the selected trigger output (TRGO) and the Master/Slave\r
1629   *         mode.\r
1630   * @retval HAL status\r
1631   */\r
1632 HAL_StatusTypeDef HAL_TIMEx_MasterConfigSynchronization(TIM_HandleTypeDef *htim,\r
1633                                                         TIM_MasterConfigTypeDef *sMasterConfig)\r
1634 {\r
1635   uint32_t tmpcr2;\r
1636   uint32_t tmpsmcr;\r
1637 \r
1638   /* Check the parameters */\r
1639   assert_param(IS_TIM_SYNCHRO_INSTANCE(htim->Instance));\r
1640   assert_param(IS_TIM_TRGO_SOURCE(sMasterConfig->MasterOutputTrigger));\r
1641   assert_param(IS_TIM_MSM_STATE(sMasterConfig->MasterSlaveMode));\r
1642 \r
1643   /* Check input state */\r
1644   __HAL_LOCK(htim);\r
1645 \r
1646   /* Change the handler state */\r
1647   htim->State = HAL_TIM_STATE_BUSY;\r
1648 \r
1649   /* Get the TIMx CR2 register value */\r
1650   tmpcr2 = htim->Instance->CR2;\r
1651 \r
1652   /* Get the TIMx SMCR register value */\r
1653   tmpsmcr = htim->Instance->SMCR;\r
1654 \r
1655   /* If the timer supports ADC synchronization through TRGO2, set the master mode selection 2 */\r
1656   if (IS_TIM_TRGO2_INSTANCE(htim->Instance))\r
1657   {\r
1658     /* Check the parameters */\r
1659     assert_param(IS_TIM_TRGO2_SOURCE(sMasterConfig->MasterOutputTrigger2));\r
1660 \r
1661     /* Clear the MMS2 bits */\r
1662     tmpcr2 &= ~TIM_CR2_MMS2;\r
1663     /* Select the TRGO2 source*/\r
1664     tmpcr2 |= sMasterConfig->MasterOutputTrigger2;\r
1665   }\r
1666 \r
1667   /* Reset the MMS Bits */\r
1668   tmpcr2 &= ~TIM_CR2_MMS;\r
1669   /* Select the TRGO source */\r
1670   tmpcr2 |=  sMasterConfig->MasterOutputTrigger;\r
1671 \r
1672   /* Reset the MSM Bit */\r
1673   tmpsmcr &= ~TIM_SMCR_MSM;\r
1674   /* Set master mode */\r
1675   tmpsmcr |= sMasterConfig->MasterSlaveMode;\r
1676 \r
1677   /* Update TIMx CR2 */\r
1678   htim->Instance->CR2 = tmpcr2;\r
1679 \r
1680   /* Update TIMx SMCR */\r
1681   htim->Instance->SMCR = tmpsmcr;\r
1682 \r
1683   /* Change the htim state */\r
1684   htim->State = HAL_TIM_STATE_READY;\r
1685 \r
1686   __HAL_UNLOCK(htim);\r
1687 \r
1688   return HAL_OK;\r
1689 }\r
1690 \r
1691 /**\r
1692   * @brief  Configures the Break feature, dead time, Lock level, OSSI/OSSR State\r
1693   *         and the AOE(automatic output enable).\r
1694   * @param  htim TIM handle\r
1695   * @param  sBreakDeadTimeConfig pointer to a TIM_ConfigBreakDeadConfigTypeDef structure that\r
1696   *         contains the BDTR Register configuration  information for the TIM peripheral.\r
1697   * @retval HAL status\r
1698   */\r
1699 HAL_StatusTypeDef HAL_TIMEx_ConfigBreakDeadTime(TIM_HandleTypeDef *htim,\r
1700                                                 TIM_BreakDeadTimeConfigTypeDef *sBreakDeadTimeConfig)\r
1701 {\r
1702   /* Keep this variable initialized to 0 as it is used to configure BDTR register */\r
1703   uint32_t tmpbdtr = 0U;\r
1704 \r
1705   /* Check the parameters */\r
1706   assert_param(IS_TIM_BREAK_INSTANCE(htim->Instance));\r
1707   assert_param(IS_TIM_OSSR_STATE(sBreakDeadTimeConfig->OffStateRunMode));\r
1708   assert_param(IS_TIM_OSSI_STATE(sBreakDeadTimeConfig->OffStateIDLEMode));\r
1709   assert_param(IS_TIM_LOCK_LEVEL(sBreakDeadTimeConfig->LockLevel));\r
1710   assert_param(IS_TIM_DEADTIME(sBreakDeadTimeConfig->DeadTime));\r
1711   assert_param(IS_TIM_BREAK_STATE(sBreakDeadTimeConfig->BreakState));\r
1712   assert_param(IS_TIM_BREAK_POLARITY(sBreakDeadTimeConfig->BreakPolarity));\r
1713   assert_param(IS_TIM_BREAK_FILTER(sBreakDeadTimeConfig->BreakFilter));\r
1714   assert_param(IS_TIM_AUTOMATIC_OUTPUT_STATE(sBreakDeadTimeConfig->AutomaticOutput));\r
1715 \r
1716   /* Check input state */\r
1717   __HAL_LOCK(htim);\r
1718 \r
1719   /* Set the Lock level, the Break enable Bit and the Polarity, the OSSR State,\r
1720      the OSSI State, the dead time value and the Automatic Output Enable Bit */\r
1721 \r
1722   /* Set the BDTR bits */\r
1723   MODIFY_REG(tmpbdtr, TIM_BDTR_DTG, sBreakDeadTimeConfig->DeadTime);\r
1724   MODIFY_REG(tmpbdtr, TIM_BDTR_LOCK, sBreakDeadTimeConfig->LockLevel);\r
1725   MODIFY_REG(tmpbdtr, TIM_BDTR_OSSI, sBreakDeadTimeConfig->OffStateIDLEMode);\r
1726   MODIFY_REG(tmpbdtr, TIM_BDTR_OSSR, sBreakDeadTimeConfig->OffStateRunMode);\r
1727   MODIFY_REG(tmpbdtr, TIM_BDTR_BKE, sBreakDeadTimeConfig->BreakState);\r
1728   MODIFY_REG(tmpbdtr, TIM_BDTR_BKP, sBreakDeadTimeConfig->BreakPolarity);\r
1729   MODIFY_REG(tmpbdtr, TIM_BDTR_AOE, sBreakDeadTimeConfig->AutomaticOutput);\r
1730   MODIFY_REG(tmpbdtr, TIM_BDTR_BKF, (sBreakDeadTimeConfig->BreakFilter << TIM_BDTR_BKF_Pos));\r
1731 \r
1732   if (IS_TIM_BKIN2_INSTANCE(htim->Instance))\r
1733   {\r
1734     /* Check the parameters */\r
1735     assert_param(IS_TIM_BREAK2_STATE(sBreakDeadTimeConfig->Break2State));\r
1736     assert_param(IS_TIM_BREAK2_POLARITY(sBreakDeadTimeConfig->Break2Polarity));\r
1737     assert_param(IS_TIM_BREAK_FILTER(sBreakDeadTimeConfig->Break2Filter));\r
1738 \r
1739     /* Set the BREAK2 input related BDTR bits */\r
1740     MODIFY_REG(tmpbdtr, TIM_BDTR_BK2F, (sBreakDeadTimeConfig->Break2Filter << TIM_BDTR_BK2F_Pos));\r
1741     MODIFY_REG(tmpbdtr, TIM_BDTR_BK2E, sBreakDeadTimeConfig->Break2State);\r
1742     MODIFY_REG(tmpbdtr, TIM_BDTR_BK2P, sBreakDeadTimeConfig->Break2Polarity);\r
1743   }\r
1744 \r
1745   /* Set TIMx_BDTR */\r
1746   htim->Instance->BDTR = tmpbdtr;\r
1747 \r
1748   __HAL_UNLOCK(htim);\r
1749 \r
1750   return HAL_OK;\r
1751 }\r
1752 \r
1753 /**\r
1754   * @brief  Configures the break input source.\r
1755   * @param  htim TIM handle.\r
1756   * @param  BreakInput Break input to configure\r
1757   *          This parameter can be one of the following values:\r
1758   *            @arg TIM_BREAKINPUT_BRK: Timer break input\r
1759   *            @arg TIM_BREAKINPUT_BRK2: Timer break 2 input\r
1760   * @param  sBreakInputConfig Break input source configuration\r
1761   * @retval HAL status\r
1762   */\r
1763 HAL_StatusTypeDef HAL_TIMEx_ConfigBreakInput(TIM_HandleTypeDef *htim,\r
1764                                              uint32_t BreakInput,\r
1765                                              TIMEx_BreakInputConfigTypeDef *sBreakInputConfig)\r
1766 \r
1767 {\r
1768   uint32_t tmporx;\r
1769   uint32_t bkin_enable_mask = 0U;\r
1770   uint32_t bkin_polarity_mask = 0U;\r
1771   uint32_t bkin_enable_bitpos = 0U;\r
1772   uint32_t bkin_polarity_bitpos = 0U;\r
1773 \r
1774   /* Check the parameters */\r
1775   assert_param(IS_TIM_BREAK_INSTANCE(htim->Instance));\r
1776   assert_param(IS_TIM_BREAKINPUT(BreakInput));\r
1777   assert_param(IS_TIM_BREAKINPUTSOURCE(sBreakInputConfig->Source));\r
1778   assert_param(IS_TIM_BREAKINPUTSOURCE_STATE(sBreakInputConfig->Enable));\r
1779 #if defined(DFSDM1_Channel0)\r
1780   if (sBreakInputConfig->Source != TIM_BREAKINPUTSOURCE_DFSDM1)\r
1781   {\r
1782     assert_param(IS_TIM_BREAKINPUTSOURCE_POLARITY(sBreakInputConfig->Polarity));\r
1783   }\r
1784 #else\r
1785   assert_param(IS_TIM_BREAKINPUTSOURCE_POLARITY(sBreakInputConfig->Polarity));\r
1786 #endif /* DFSDM1_Channel0 */\r
1787 \r
1788   /* Check input state */\r
1789   __HAL_LOCK(htim);\r
1790 \r
1791   switch (sBreakInputConfig->Source)\r
1792   {\r
1793     case TIM_BREAKINPUTSOURCE_BKIN:\r
1794     {\r
1795       bkin_enable_mask = TIM1_OR2_BKINE;\r
1796       bkin_enable_bitpos = TIM1_OR2_BKINE_Pos;\r
1797       bkin_polarity_mask = TIM1_OR2_BKINP;\r
1798       bkin_polarity_bitpos = TIM1_OR2_BKINP_Pos;\r
1799       break;\r
1800     }\r
1801     case TIM_BREAKINPUTSOURCE_COMP1:\r
1802     {\r
1803       bkin_enable_mask = TIM1_OR2_BKCMP1E;\r
1804       bkin_enable_bitpos = TIM1_OR2_BKCMP1E_Pos;\r
1805       bkin_polarity_mask = TIM1_OR2_BKCMP1P;\r
1806       bkin_polarity_bitpos = TIM1_OR2_BKCMP1P_Pos;\r
1807       break;\r
1808     }\r
1809     case TIM_BREAKINPUTSOURCE_COMP2:\r
1810     {\r
1811       bkin_enable_mask = TIM1_OR2_BKCMP2E;\r
1812       bkin_enable_bitpos = TIM1_OR2_BKCMP2E_Pos;\r
1813       bkin_polarity_mask = TIM1_OR2_BKCMP2P;\r
1814       bkin_polarity_bitpos = TIM1_OR2_BKCMP2P_Pos;\r
1815       break;\r
1816     }\r
1817 #if defined(DFSDM1_Channel0)\r
1818     case TIM_BREAKINPUTSOURCE_DFSDM1:\r
1819     {\r
1820       bkin_enable_mask = TIM1_OR2_BKDF1BK0E;\r
1821       bkin_enable_bitpos = 8U;\r
1822       break;\r
1823     }\r
1824 #endif /* DFSDM1_Channel0 */\r
1825 \r
1826     default:\r
1827       break;\r
1828   }\r
1829 \r
1830   switch (BreakInput)\r
1831   {\r
1832     case TIM_BREAKINPUT_BRK:\r
1833     {\r
1834       /* Get the TIMx_OR2 register value */\r
1835       tmporx = htim->Instance->OR2;\r
1836 \r
1837       /* Enable the break input */\r
1838       tmporx &= ~bkin_enable_mask;\r
1839       tmporx |= (sBreakInputConfig->Enable << bkin_enable_bitpos) & bkin_enable_mask;\r
1840 \r
1841       /* Set the break input polarity */\r
1842 #if defined(DFSDM1_Channel0)\r
1843       if (sBreakInputConfig->Source != TIM_BREAKINPUTSOURCE_DFSDM1)\r
1844 #endif /* DFSDM1_Channel0 */\r
1845       {\r
1846         tmporx &= ~bkin_polarity_mask;\r
1847         tmporx |= (sBreakInputConfig->Polarity << bkin_polarity_bitpos) & bkin_polarity_mask;\r
1848       }\r
1849 \r
1850       /* Set TIMx_OR2 */\r
1851       htim->Instance->OR2 = tmporx;\r
1852       break;\r
1853     }\r
1854     case TIM_BREAKINPUT_BRK2:\r
1855     {\r
1856       /* Get the TIMx_OR3 register value */\r
1857       tmporx = htim->Instance->OR3;\r
1858 \r
1859       /* Enable the break input */\r
1860       tmporx &= ~bkin_enable_mask;\r
1861       tmporx |= (sBreakInputConfig->Enable << bkin_enable_bitpos) & bkin_enable_mask;\r
1862 \r
1863       /* Set the break input polarity */\r
1864 #if defined(DFSDM1_Channel0)\r
1865       if (sBreakInputConfig->Source != TIM_BREAKINPUTSOURCE_DFSDM1)\r
1866 #endif /* DFSDM1_Channel0 */\r
1867       {\r
1868         tmporx &= ~bkin_polarity_mask;\r
1869         tmporx |= (sBreakInputConfig->Polarity << bkin_polarity_bitpos) & bkin_polarity_mask;\r
1870       }\r
1871 \r
1872       /* Set TIMx_OR3 */\r
1873       htim->Instance->OR3 = tmporx;\r
1874       break;\r
1875     }\r
1876     default:\r
1877       break;\r
1878   }\r
1879 \r
1880   __HAL_UNLOCK(htim);\r
1881 \r
1882   return HAL_OK;\r
1883 }\r
1884 \r
1885 /**\r
1886   * @brief  Configures the TIMx Remapping input capabilities.\r
1887   * @param  htim TIM handle.\r
1888   * @param  Remap specifies the TIM remapping source.\r
1889     @if STM32L422xx\r
1890   *         For TIM1, the parameter is a combination of 2 fields (field1 | field2):\r
1891   *\r
1892   *                   field1 can have the following values:\r
1893   *            @arg TIM_TIM1_ETR_ADC1_NONE:           TIM1_ETR is not connected to any ADC1 AWD (analog watchdog)\r
1894   *            @arg TIM_TIM1_ETR_ADC1_AWD1:           TIM1_ETR is connected to ADC1 AWD1\r
1895   *            @arg TIM_TIM1_ETR_ADC1_AWD2:           TIM1_ETR is connected to ADC1 AWD2\r
1896   *            @arg TIM_TIM1_ETR_ADC1_AWD3:           TIM1_ETR is connected to ADC1 AWD3\r
1897   *\r
1898   *                   field2 can have the following values:\r
1899   *            @arg TIM_TIM1_TI1_GPIO:                TIM1 TI1 is connected to GPIO\r
1900   *            @arg TIM_TIM1_TI1_COMP1:               TIM1 TI1 is connected to COMP1 output\r
1901   *\r
1902   @endif\r
1903 @if STM32L486xx\r
1904   *         For TIM1, the parameter is a combination of 4 fields (field1 | field2 | field3 | field4):\r
1905   *\r
1906   *                   field1 can have the following values:\r
1907   *            @arg TIM_TIM1_ETR_ADC1_NONE:           TIM1_ETR is not connected to any ADC1 AWD (analog watchdog)\r
1908   *            @arg TIM_TIM1_ETR_ADC1_AWD1:           TIM1_ETR is connected to ADC1 AWD1\r
1909   *            @arg TIM_TIM1_ETR_ADC1_AWD2:           TIM1_ETR is connected to ADC1 AWD2\r
1910   *            @arg TIM_TIM1_ETR_ADC1_AWD3:           TIM1_ETR is connected to ADC1 AWD3\r
1911   *\r
1912   *                   field2 can have the following values:\r
1913   *            @arg TIM_TIM1_ETR_ADC3_NONE:           TIM1_ETR is not connected to any ADC3 AWD (analog watchdog)\r
1914   *            @arg TIM_TIM1_ETR_ADC3_AWD1:           TIM1_ETR is connected to ADC3 AWD1\r
1915   *            @arg TIM_TIM1_ETR_ADC3_AWD2:           TIM1_ETR is connected to ADC3 AWD2\r
1916   *            @arg TIM_TIM1_ETR_ADC3_AWD3:           TIM1_ETR is connected to ADC3 AWD3\r
1917   *\r
1918   *                   field3 can have the following values:\r
1919   *            @arg TIM_TIM1_TI1_GPIO:                TIM1 TI1 is connected to GPIO\r
1920   *            @arg TIM_TIM1_TI1_COMP1:               TIM1 TI1 is connected to COMP1 output\r
1921   *\r
1922   *                   field4 can have the following values:\r
1923   *            @arg TIM_TIM1_ETR_COMP1:               TIM1_ETR is connected to COMP1 output\r
1924   *            @arg TIM_TIM1_ETR_COMP2:               TIM1_ETR is connected to COMP2 output\r
1925   *            @note  When field4 is set to TIM_TIM1_ETR_COMP1 or TIM_TIM1_ETR_COMP2 field1 and field2 values are not significant\r
1926   @endif\r
1927   @if STM32L443xx\r
1928   *         For TIM1, the parameter is a combination of 3 fields (field1 | field2 | field3):\r
1929   *\r
1930   *                   field1 can have the following values:\r
1931   *            @arg TIM_TIM1_ETR_ADC1_NONE:           TIM1_ETR is not connected to any ADC1 AWD (analog watchdog)\r
1932   *            @arg TIM_TIM1_ETR_ADC1_AWD1:           TIM1_ETR is connected to ADC1 AWD1\r
1933   *            @arg TIM_TIM1_ETR_ADC1_AWD2:           TIM1_ETR is connected to ADC1 AWD2\r
1934   *            @arg TIM_TIM1_ETR_ADC1_AWD3:           TIM1_ETR is connected to ADC1 AWD3\r
1935   *\r
1936   *                   field2 can have the following values:\r
1937   *            @arg TIM_TIM1_TI1_GPIO:                TIM1 TI1 is connected to GPIO\r
1938   *            @arg TIM_TIM1_TI1_COMP1:               TIM1 TI1 is connected to COMP1 output\r
1939   *\r
1940   *                   field3 can have the following values:\r
1941   *            @arg TIM_TIM1_ETR_COMP1:               TIM1_ETR is connected to COMP1 output\r
1942   *            @arg TIM_TIM1_ETR_COMP2:               TIM1_ETR is connected to COMP2 output\r
1943   *\r
1944   *            @note  When field3 is set to TIM_TIM1_ETR_COMP1 or TIM_TIM1_ETR_COMP2 field1 values is not significant\r
1945   *\r
1946   @endif\r
1947   @if STM32L486xx\r
1948   *         For TIM2, the parameter is a combination of 3 fields (field1 | field2 | field3):\r
1949   *\r
1950   *                   field1 can have the following values:\r
1951   *            @arg TIM_TIM2_ITR1_TIM8_TRGO:          TIM2_ITR1 is connected to TIM8_TRGO\r
1952   *            @arg TIM_TIM2_ITR1_OTG_FS_SOF:         TIM2_ITR1 is connected to OTG_FS SOF\r
1953   *\r
1954   *                   field2 can have the following values:\r
1955   *            @arg TIM_TIM2_ETR_GPIO:                TIM2_ETR is connected to GPIO\r
1956   *            @arg TIM_TIM2_ETR_LSE:                 TIM2_ETR is connected to LSE\r
1957   *            @arg TIM_TIM2_ETR_COMP1:               TIM2_ETR is connected to COMP1 output\r
1958   *            @arg TIM_TIM2_ETR_COMP2:               TIM2_ETR is connected to COMP2 output\r
1959   *\r
1960   *                   field3 can have the following values:\r
1961   *            @arg TIM_TIM2_TI4_GPIO:                TIM2 TI4 is connected to GPIO\r
1962   *            @arg TIM_TIM2_TI4_COMP1:               TIM2 TI4 is connected to COMP1 output\r
1963   *            @arg TIM_TIM2_TI4_COMP2:               TIM2 TI4 is connected to COMP2 output\r
1964   *            @arg TIM_TIM2_TI4_COMP1_COMP2:         TIM2 TI4 is connected to logical OR between COMP1 and COMP2 output\r
1965   @endif\r
1966   @if STM32L422xx\r
1967   *         For TIM2, the parameter is a combination of 3 fields (field1 | field2 | field3):\r
1968   *\r
1969   *                   field1 can have the following values:\r
1970   *            @arg TIM_TIM2_ITR1_NONE:               No internal trigger on TIM2_ITR1\r
1971   *            @arg TIM_TIM2_ITR1_USB_SOF:            TIM2_ITR1 is connected to USB SOF\r
1972   *\r
1973   *                   field2 can have the following values:\r
1974   *            @arg TIM_TIM2_ETR_GPIO:                TIM2_ETR is connected to GPIO\r
1975   *            @arg TIM_TIM2_ETR_LSE:                 TIM2_ETR is connected to LSE\r
1976   *            @arg TIM_TIM2_ETR_COMP1:               TIM2_ETR is connected to COMP1 output\r
1977   *\r
1978   *                   field3 can have the following values:\r
1979   *            @arg TIM_TIM2_TI4_GPIO:                TIM2 TI4 is connected to GPIO\r
1980   *            @arg TIM_TIM2_TI4_COMP1:               TIM2 TI4 is connected to COMP1 output\r
1981   *\r
1982   @endif\r
1983   @if STM32L443xx\r
1984   *         For TIM2, the parameter is a combination of 3 fields (field1 | field2 | field3):\r
1985   *\r
1986   *                   field1 can have the following values:\r
1987   *            @arg TIM_TIM2_ITR1_NONE:               No internal trigger on TIM2_ITR1\r
1988   *            @arg TIM_TIM2_ITR1_USB_SOF:            TIM2_ITR1 is connected to USB SOF\r
1989   *\r
1990   *                   field2 can have the following values:\r
1991   *            @arg TIM_TIM2_ETR_GPIO:                TIM2_ETR is connected to GPIO\r
1992   *            @arg TIM_TIM2_ETR_LSE:                 TIM2_ETR is connected to LSE\r
1993   *            @arg TIM_TIM2_ETR_COMP1:               TIM2_ETR is connected to COMP1 output\r
1994   *            @arg TIM_TIM2_ETR_COMP2:               TIM2_ETR is connected to COMP2 output\r
1995   *\r
1996   *                   field3 can have the following values:\r
1997   *            @arg TIM_TIM2_TI4_GPIO:                TIM2 TI4 is connected to GPIO\r
1998   *            @arg TIM_TIM2_TI4_COMP1:               TIM2 TI4 is connected to COMP1 output\r
1999   *            @arg TIM_TIM2_TI4_COMP2:               TIM2 TI4 is connected to COMP2 output\r
2000   *            @arg TIM_TIM2_TI4_COMP1_COMP2:         TIM2 TI4 is connected to logical OR between COMP1 and COMP2 output\r
2001   *\r
2002   @endif\r
2003   @if STM32L486xx\r
2004   *         For TIM3, the parameter is a combination 2 fields(field1 | field2):\r
2005   *\r
2006   *                   field1 can have the following values:\r
2007   *            @arg TIM_TIM3_TI1_GPIO:                TIM3 TI1 is connected to GPIO\r
2008   *            @arg TIM_TIM3_TI1_COMP1:               TIM3 TI1 is connected to COMP1 output\r
2009   *            @arg TIM_TIM3_TI1_COMP2:               TIM3 TI1 is connected to COMP2 output\r
2010   *            @arg TIM_TIM3_TI1_COMP1_COMP2:         TIM3 TI1 is connected to logical OR between COMP1 and COMP2 output\r
2011   *\r
2012   *                   field2 can have the following values:\r
2013   *            @arg TIM_TIM3_ETR_GPIO:                TIM3_ETR is connected to GPIO\r
2014   *            @arg TIM_TIM3_ETR_COMP1:               TIM3_ETR is connected to COMP1 output\r
2015   *\r
2016   @endif\r
2017   @if STM32L486xx\r
2018   *         For TIM8, the parameter is a combination of 3 fields (field1 | field2 | field3):\r
2019   *\r
2020   *                   field1 can have the following values:\r
2021   *            @arg TIM_TIM8_ETR_ADC2_NONE:          TIM8_ETR is not connected to any ADC2 AWD (analog watchdog)\r
2022   *            @arg TIM_TIM8_ETR_ADC2_AWD1:          TIM8_ETR is connected to ADC2 AWD1\r
2023   *            @arg TIM_TIM8_ETR_ADC2_AWD2:          TIM8_ETR is connected to ADC2 AWD2\r
2024   *            @arg TIM_TIM8_ETR_ADC2_AWD3:          TIM8_ETR is connected to ADC2 AWD3\r
2025   *\r
2026   *                   field2 can have the following values:\r
2027   *            @arg TIM_TIM8_ETR_ADC3_NONE:          TIM8_ETR is not connected to any ADC3 AWD (analog watchdog)\r
2028   *            @arg TIM_TIM8_ETR_ADC3_AWD1:          TIM8_ETR is connected to ADC3 AWD1\r
2029   *            @arg TIM_TIM8_ETR_ADC3_AWD2:          TIM8_ETR is connected to ADC3 AWD2\r
2030   *            @arg TIM_TIM8_ETR_ADC3_AWD3:          TIM8_ETR is connected to ADC3 AWD3\r
2031   *\r
2032   *                   field3 can have the following values:\r
2033   *            @arg TIM_TIM8_TI1_GPIO:               TIM8 TI1 is connected to GPIO\r
2034   *            @arg TIM_TIM8_TI1_COMP2:              TIM8 TI1 is connected to COMP2 output\r
2035   *\r
2036   *                   field4 can have the following values:\r
2037   *            @arg TIM_TIM8_ETR_COMP1:               TIM8_ETR is connected to COMP1 output\r
2038   *            @arg TIM_TIM8_ETR_COMP2:               TIM8_ETR is connected to COMP2 output\r
2039   *            @note  When field4 is set to TIM_TIM8_ETR_COMP1 or TIM_TIM8_ETR_COMP2 field1 and field2 values are not significant\r
2040   *\r
2041   @endif\r
2042   @if STM32L422xx\r
2043   *         For TIM15, the parameter is a combination of 2 fields (field1 | field2):\r
2044   *\r
2045   *                   field1 can have the following values:\r
2046   *            @arg TIM_TIM15_TI1_GPIO:              TIM15 TI1 is connected to GPIO\r
2047   *            @arg TIM_TIM15_TI1_LSE:               TIM15 TI1 is connected to LSE\r
2048   *\r
2049   *                   field2 can have the following values:\r
2050   *            @arg TIM_TIM15_ENCODERMODE_NONE:      No redirection\r
2051   *            @arg TIM_TIM15_ENCODERMODE_TIM2:      TIM2 IC1 and TIM2 IC2 are connected to TIM15 IC1 and TIM15 IC2 respectively\r
2052   *\r
2053   @endif\r
2054   @if STM32L443xx\r
2055   *         For TIM15, the parameter is a combination of 2 fields (field1 | field2):\r
2056   *\r
2057   *                   field1 can have the following values:\r
2058   *            @arg TIM_TIM15_TI1_GPIO:              TIM15 TI1 is connected to GPIO\r
2059   *            @arg TIM_TIM15_TI1_LSE:               TIM15 TI1 is connected to LSE\r
2060   *\r
2061   *                   field2 can have the following values:\r
2062   *            @arg TIM_TIM15_ENCODERMODE_NONE:      No redirection\r
2063   *            @arg TIM_TIM15_ENCODERMODE_TIM2:      TIM2 IC1 and TIM2 IC2 are connected to TIM15 IC1 and TIM15 IC2 respectively\r
2064   *            @arg TIM_TIM15_ENCODERMODE_TIM3:      TIM3 IC1 and TIM3 IC2 are connected to TIM15 IC1 and TIM15 IC2 respectively\r
2065   *            @arg TIM_TIM15_ENCODERMODE_TIM4:      TIM4 IC1 and TIM4 IC2 are connected to TIM15 IC1 and TIM15 IC2 respectively\r
2066   *\r
2067   @endif\r
2068   @if STM32L486xx\r
2069   *            @arg TIM_TIM16_TI1_GPIO:              TIM16 TI1 is connected to GPIO\r
2070   *            @arg TIM_TIM16_TI1_LSI:               TIM16 TI1 is connected to LSI\r
2071   *            @arg TIM_TIM16_TI1_LSE:               TIM16 TI1 is connected to LSE\r
2072   *            @arg TIM_TIM16_TI1_RTC:               TIM16 TI1 is connected to RTC wakeup interrupt\r
2073   *\r
2074   @endif\r
2075   @if STM32L422xx\r
2076   *         For TIM16, the parameter can have the following values:\r
2077   *            @arg TIM_TIM16_TI1_GPIO:              TIM16 TI1 is connected to GPIO\r
2078   *            @arg TIM_TIM16_TI1_LSI:               TIM16 TI1 is connected to LSI\r
2079   *            @arg TIM_TIM16_TI1_LSE:               TIM16 TI1 is connected to LSE\r
2080   *            @arg TIM_TIM16_TI1_RTC:               TIM16 TI1 is connected to RTC wakeup interrupt\r
2081   *            @arg TIM_TIM16_TI1_MSI:               TIM16 TI1 is connected to MSI  (contraints: MSI clock < 1/4 TIM APB clock)\r
2082   *            @arg TIM_TIM16_TI1_HSE_32:            TIM16 TI1 is connected to HSE div 32  (note that HSE div 32 must be selected as RTC clock source)\r
2083   *            @arg TIM_TIM16_TI1_MCO:               TIM16 TI1 is connected to MCO\r
2084   *\r
2085   @endif\r
2086   @if STM32L443xx\r
2087   *         For TIM16, the parameter can have the following values:\r
2088   *            @arg TIM_TIM16_TI1_GPIO:              TIM16 TI1 is connected to GPIO\r
2089   *            @arg TIM_TIM16_TI1_LSI:               TIM16 TI1 is connected to LSI\r
2090   *            @arg TIM_TIM16_TI1_LSE:               TIM16 TI1 is connected to LSE\r
2091   *            @arg TIM_TIM16_TI1_RTC:               TIM16 TI1 is connected to RTC wakeup interrupt\r
2092   *            @arg TIM_TIM16_TI1_MSI:               TIM16 TI1 is connected to MSI  (contraints: MSI clock < 1/4 TIM APB clock)\r
2093   *            @arg TIM_TIM16_TI1_HSE_32:            TIM16 TI1 is connected to HSE div 32  (note that HSE div 32 must be selected as RTC clock source)\r
2094   *            @arg TIM_TIM16_TI1_MCO:               TIM16 TI1 is connected to MCO\r
2095   *\r
2096   @endif\r
2097   @if STM32L486xx\r
2098   *         For TIM17, the parameter can have the following values:\r
2099   *            @arg TIM_TIM17_TI1_GPIO:              TIM17 TI1 is connected to GPIO\r
2100   *            @arg TIM_TIM17_TI1_MSI:               TIM17 TI1 is connected to MSI  (contraints: MSI clock < 1/4 TIM APB clock)\r
2101   *            @arg TIM_TIM17_TI1_HSE_32:            TIM17 TI1 is connected to HSE div 32\r
2102   *            @arg TIM_TIM17_TI1_MCO:               TIM17 TI1 is connected to MCO\r
2103   @endif\r
2104   *\r
2105   * @retval HAL status\r
2106   */\r
2107 HAL_StatusTypeDef HAL_TIMEx_RemapConfig(TIM_HandleTypeDef *htim, uint32_t Remap)\r
2108 {\r
2109   uint32_t tmpor1 = 0U;\r
2110   uint32_t tmpor2 = 0U;\r
2111 \r
2112   __HAL_LOCK(htim);\r
2113 \r
2114   /* Check parameters */\r
2115   assert_param(IS_TIM_REMAP_INSTANCE(htim->Instance));\r
2116   assert_param(IS_TIM_REMAP(Remap));\r
2117 \r
2118   /* Set ETR_SEL bit field (if required) */\r
2119   if (IS_TIM_ETRSEL_INSTANCE(htim->Instance))\r
2120   {\r
2121     tmpor2 = htim->Instance->OR2;\r
2122     tmpor2 &= ~TIM1_OR2_ETRSEL_Msk;\r
2123     tmpor2 |= (Remap & TIM1_OR2_ETRSEL_Msk);\r
2124 \r
2125     /* Set TIMx_OR2 */\r
2126     htim->Instance->OR2 = tmpor2;\r
2127   }\r
2128 \r
2129   /* Set other remapping capabilities */\r
2130   tmpor1 = Remap;\r
2131   tmpor1 &= ~TIM1_OR2_ETRSEL_Msk;\r
2132 \r
2133   /* Set TIMx_OR1 */\r
2134   htim->Instance->OR1 = tmpor1;\r
2135 \r
2136   __HAL_UNLOCK(htim);\r
2137 \r
2138   return HAL_OK;\r
2139 }\r
2140 \r
2141 /**\r
2142   * @brief  Group channel 5 and channel 1, 2 or 3\r
2143   * @param  htim TIM handle.\r
2144   * @param  Channels specifies the reference signal(s) the OC5REF is combined with.\r
2145   *         This parameter can be any combination of the following values:\r
2146   *         TIM_GROUPCH5_NONE: No effect of OC5REF on OC1REFC, OC2REFC and OC3REFC\r
2147   *         TIM_GROUPCH5_OC1REFC: OC1REFC is the logical AND of OC1REFC and OC5REF\r
2148   *         TIM_GROUPCH5_OC2REFC: OC2REFC is the logical AND of OC2REFC and OC5REF\r
2149   *         TIM_GROUPCH5_OC3REFC: OC3REFC is the logical AND of OC3REFC and OC5REF\r
2150   * @retval HAL status\r
2151   */\r
2152 HAL_StatusTypeDef HAL_TIMEx_GroupChannel5(TIM_HandleTypeDef *htim, uint32_t Channels)\r
2153 {\r
2154   /* Check parameters */\r
2155   assert_param(IS_TIM_COMBINED3PHASEPWM_INSTANCE(htim->Instance));\r
2156   assert_param(IS_TIM_GROUPCH5(Channels));\r
2157 \r
2158   /* Process Locked */\r
2159   __HAL_LOCK(htim);\r
2160 \r
2161   htim->State = HAL_TIM_STATE_BUSY;\r
2162 \r
2163   /* Clear GC5Cx bit fields */\r
2164   htim->Instance->CCR5 &= ~(TIM_CCR5_GC5C3 | TIM_CCR5_GC5C2 | TIM_CCR5_GC5C1);\r
2165 \r
2166   /* Set GC5Cx bit fields */\r
2167   htim->Instance->CCR5 |= Channels;\r
2168 \r
2169   /* Change the htim state */\r
2170   htim->State = HAL_TIM_STATE_READY;\r
2171 \r
2172   __HAL_UNLOCK(htim);\r
2173 \r
2174   return HAL_OK;\r
2175 }\r
2176 \r
2177 /**\r
2178   * @}\r
2179   */\r
2180 \r
2181 /** @defgroup TIMEx_Exported_Functions_Group6 Extended Callbacks functions\r
2182   * @brief    Extended Callbacks functions\r
2183   *\r
2184 @verbatim\r
2185   ==============================================================================\r
2186                     ##### Extended Callbacks functions #####\r
2187   ==============================================================================\r
2188   [..]\r
2189     This section provides Extended TIM callback functions:\r
2190     (+) Timer Commutation callback\r
2191     (+) Timer Break callback\r
2192 \r
2193 @endverbatim\r
2194   * @{\r
2195   */\r
2196 \r
2197 /**\r
2198   * @brief  Hall commutation changed callback in non-blocking mode\r
2199   * @param  htim TIM handle\r
2200   * @retval None\r
2201   */\r
2202 __weak void HAL_TIMEx_CommutCallback(TIM_HandleTypeDef *htim)\r
2203 {\r
2204   /* Prevent unused argument(s) compilation warning */\r
2205   UNUSED(htim);\r
2206 \r
2207   /* NOTE : This function should not be modified, when the callback is needed,\r
2208             the HAL_TIMEx_CommutCallback could be implemented in the user file\r
2209    */\r
2210 }\r
2211 /**\r
2212   * @brief  Hall commutation changed half complete callback in non-blocking mode\r
2213   * @param  htim TIM handle\r
2214   * @retval None\r
2215   */\r
2216 __weak void HAL_TIMEx_CommutHalfCpltCallback(TIM_HandleTypeDef *htim)\r
2217 {\r
2218   /* Prevent unused argument(s) compilation warning */\r
2219   UNUSED(htim);\r
2220 \r
2221   /* NOTE : This function should not be modified, when the callback is needed,\r
2222             the HAL_TIMEx_CommutHalfCpltCallback could be implemented in the user file\r
2223    */\r
2224 }\r
2225 \r
2226 /**\r
2227   * @brief  Hall Break detection callback in non-blocking mode\r
2228   * @param  htim TIM handle\r
2229   * @retval None\r
2230   */\r
2231 __weak void HAL_TIMEx_BreakCallback(TIM_HandleTypeDef *htim)\r
2232 {\r
2233   /* Prevent unused argument(s) compilation warning */\r
2234   UNUSED(htim);\r
2235 \r
2236   /* NOTE : This function should not be modified, when the callback is needed,\r
2237             the HAL_TIMEx_BreakCallback could be implemented in the user file\r
2238    */\r
2239 }\r
2240 \r
2241 /**\r
2242   * @brief  Hall Break2 detection callback in non blocking mode\r
2243   * @param  htim: TIM handle\r
2244   * @retval None\r
2245   */\r
2246 __weak void HAL_TIMEx_Break2Callback(TIM_HandleTypeDef *htim)\r
2247 {\r
2248   /* Prevent unused argument(s) compilation warning */\r
2249   UNUSED(htim);\r
2250 \r
2251   /* NOTE : This function Should not be modified, when the callback is needed,\r
2252             the HAL_TIMEx_Break2Callback could be implemented in the user file\r
2253    */\r
2254 }\r
2255 /**\r
2256   * @}\r
2257   */\r
2258 \r
2259 /** @defgroup TIMEx_Exported_Functions_Group7 Extended Peripheral State functions\r
2260   * @brief    Extended Peripheral State functions\r
2261   *\r
2262 @verbatim\r
2263   ==============================================================================\r
2264                 ##### Extended Peripheral State functions #####\r
2265   ==============================================================================\r
2266   [..]\r
2267     This subsection permits to get in run-time the status of the peripheral\r
2268     and the data flow.\r
2269 \r
2270 @endverbatim\r
2271   * @{\r
2272   */\r
2273 \r
2274 /**\r
2275   * @brief  Return the TIM Hall Sensor interface handle state.\r
2276   * @param  htim TIM Hall Sensor handle\r
2277   * @retval HAL state\r
2278   */\r
2279 HAL_TIM_StateTypeDef HAL_TIMEx_HallSensor_GetState(TIM_HandleTypeDef *htim)\r
2280 {\r
2281   return htim->State;\r
2282 }\r
2283 \r
2284 /**\r
2285   * @}\r
2286   */\r
2287 \r
2288 /**\r
2289   * @}\r
2290   */\r
2291 \r
2292 /* Private functions ---------------------------------------------------------*/\r
2293 /** @defgroup TIMEx_Private_Functions TIMEx Private Functions\r
2294   * @{\r
2295   */\r
2296 \r
2297 /**\r
2298   * @brief  TIM DMA Commutation callback.\r
2299   * @param  hdma pointer to DMA handle.\r
2300   * @retval None\r
2301   */\r
2302 void TIMEx_DMACommutationCplt(DMA_HandleTypeDef *hdma)\r
2303 {\r
2304   TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;\r
2305 \r
2306   /* Change the htim state */\r
2307   htim->State = HAL_TIM_STATE_READY;\r
2308 \r
2309 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)\r
2310   htim->CommutationCallback(htim);\r
2311 #else\r
2312   HAL_TIMEx_CommutCallback(htim);\r
2313 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */\r
2314 }\r
2315 \r
2316 /**\r
2317   * @brief  TIM DMA Commutation half complete callback.\r
2318   * @param  hdma pointer to DMA handle.\r
2319   * @retval None\r
2320   */\r
2321 void TIMEx_DMACommutationHalfCplt(DMA_HandleTypeDef *hdma)\r
2322 {\r
2323   TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;\r
2324 \r
2325   /* Change the htim state */\r
2326   htim->State = HAL_TIM_STATE_READY;\r
2327 \r
2328 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)\r
2329   htim->CommutationHalfCpltCallback(htim);\r
2330 #else\r
2331   HAL_TIMEx_CommutHalfCpltCallback(htim);\r
2332 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */\r
2333 }\r
2334 \r
2335 \r
2336 /**\r
2337   * @brief  Enables or disables the TIM Capture Compare Channel xN.\r
2338   * @param  TIMx to select the TIM peripheral\r
2339   * @param  Channel specifies the TIM Channel\r
2340   *          This parameter can be one of the following values:\r
2341   *            @arg TIM_CHANNEL_1: TIM Channel 1\r
2342   *            @arg TIM_CHANNEL_2: TIM Channel 2\r
2343   *            @arg TIM_CHANNEL_3: TIM Channel 3\r
2344   * @param  ChannelNState specifies the TIM Channel CCxNE bit new state.\r
2345   *          This parameter can be: TIM_CCxN_ENABLE or TIM_CCxN_Disable.\r
2346   * @retval None\r
2347   */\r
2348 static void TIM_CCxNChannelCmd(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t ChannelNState)\r
2349 {\r
2350   uint32_t tmp;\r
2351 \r
2352   tmp = TIM_CCER_CC1NE << (Channel & 0x1FU); /* 0x1FU = 31 bits max shift */\r
2353 \r
2354   /* Reset the CCxNE Bit */\r
2355   TIMx->CCER &=  ~tmp;\r
2356 \r
2357   /* Set or reset the CCxNE Bit */\r
2358   TIMx->CCER |= (uint32_t)(ChannelNState << (Channel & 0x1FU)); /* 0x1FU = 31 bits max shift */\r
2359 }\r
2360 /**\r
2361   * @}\r
2362   */\r
2363 \r
2364 #endif /* HAL_TIM_MODULE_ENABLED */\r
2365 /**\r
2366   * @}\r
2367   */\r
2368 \r
2369 /**\r
2370   * @}\r
2371   */\r
2372 \r
2373 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/\r