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