2 ******************************************************************************
3 * @file stm32f30x_tim.c
4 * @author MCD Application Team
7 * @brief This file provides firmware functions to manage the following
8 * functionalities of the TIM peripheral:
9 * + TimeBase management
10 * + Output Compare management
11 * + Input Capture management
12 * + Advanced-control timers (TIM1 and TIM8) specific features
13 * + Interrupts, DMA and flags management
15 * + Synchronization management
16 * + Specific interface management
17 * + Specific remapping management
21 ==============================================================================
22 ##### How to use this driver #####
23 ==============================================================================
24 [..] This driver provides functions to configure and program the TIM
25 of all stm32f30x devices.
26 These functions are split in 9 groups:
28 (#) TIM TimeBase management: this group includes all needed functions
29 to configure the TM Timebase unit:
30 (++) Set/Get Prescaler
31 (++) Set/Get Autoreload
32 (++) Counter modes configuration
33 (++) Set Clock division
34 (++) Select the One Pulse mode
35 (++) Update Request Configuration
36 (++) Update Disable Configuration
37 (++) Auto-Preload Configuration
38 (++) Enable/Disable the counter
40 (#) TIM Output Compare management: this group includes all needed
41 functions to configure the Capture/Compare unit used in Output
43 (++) Configure each channel, independently, in Output Compare mode
44 (++) Select the output compare modes
45 (++) Select the Polarities of each channel
46 (++) Set/Get the Capture/Compare register values
47 (++) Select the Output Compare Fast mode
48 (++) Select the Output Compare Forced mode
49 (++) Output Compare-Preload Configuration
50 (++) Clear Output Compare Reference
51 (++) Select the OCREF Clear signal
52 (++) Enable/Disable the Capture/Compare Channels
54 (#) TIM Input Capture management: this group includes all needed
55 functions to configure the Capture/Compare unit used in
57 (++) Configure each channel in input capture mode
58 (++) Configure Channel1/2 in PWM Input mode
59 (++) Set the Input Capture Prescaler
60 (++) Get the Capture/Compare values
62 (#) Advanced-control timers (TIM1 and TIM8) specific features
63 (++) Configures the Break input, dead time, Lock level, the OSSI,
64 the OSSR State and the AOE(automatic output enable)
65 (++) Enable/Disable the TIM peripheral Main Outputs
66 (++) Select the Commutation event
67 (++) Set/Reset the Capture Compare Preload Control bit
69 (#) TIM interrupts, DMA and flags management
70 (++) Enable/Disable interrupt sources
72 (++) Clear flags/ Pending bits
73 (++) Enable/Disable DMA requests
74 (++) Configure DMA burst mode
75 (++) Select CaptureCompare DMA request
77 (#) TIM clocks management: this group includes all needed functions
78 to configure the clock controller unit:
79 (++) Select internal/External clock
80 (++) Select the external clock mode: ETR(Mode1/Mode2), TIx or ITRx
82 (#) TIM synchronization management: this group includes all needed
83 functions to configure the Synchronization unit:
84 (++) Select Input Trigger
85 (++) Select Output Trigger
86 (++) Select Master Slave Mode
87 (++) ETR Configuration when used as external trigger
89 (#) TIM specific interface management, this group includes all
90 needed functions to use the specific TIM interface:
91 (++) Encoder Interface Configuration
92 (++) Select Hall Sensor
94 (#) TIM specific remapping management includes the Remapping
95 configuration of specific timers
99 ******************************************************************************
102 * <h2><center>© COPYRIGHT 2014 STMicroelectronics</center></h2>
104 * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
105 * You may not use this file except in compliance with the License.
106 * You may obtain a copy of the License at:
108 * http://www.st.com/software_license_agreement_liberty_v2
110 * Unless required by applicable law or agreed to in writing, software
111 * distributed under the License is distributed on an "AS IS" BASIS,
112 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
113 * See the License for the specific language governing permissions and
114 * limitations under the License.
116 ******************************************************************************
119 /* Includes ------------------------------------------------------------------*/
120 #include "stm32f30x_tim.h"
121 #include "stm32f30x_rcc.h"
123 /** @addtogroup STM32F30x_StdPeriph_Driver
128 * @brief TIM driver modules
132 /* Private typedef -----------------------------------------------------------*/
133 /* Private define ------------------------------------------------------------*/
135 /* ---------------------- TIM registers bit mask ------------------------ */
136 #define SMCR_ETR_MASK ((uint16_t)0x00FF)
137 #define CCMR_OFFSET ((uint16_t)0x0018)
138 #define CCER_CCE_SET ((uint16_t)0x0001)
139 #define CCER_CCNE_SET ((uint16_t)0x0004)
140 #define CCMR_OC13M_MASK ((uint32_t)0xFFFEFF8F)
141 #define CCMR_OC24M_MASK ((uint32_t)0xFEFF8FFF)
143 /* Private macro -------------------------------------------------------------*/
144 /* Private variables ---------------------------------------------------------*/
145 /* Private function prototypes -----------------------------------------------*/
146 static void TI1_Config(TIM_TypeDef
* TIMx
, uint16_t TIM_ICPolarity
, uint16_t TIM_ICSelection
,
147 uint16_t TIM_ICFilter
);
148 static void TI2_Config(TIM_TypeDef
* TIMx
, uint16_t TIM_ICPolarity
, uint16_t TIM_ICSelection
,
149 uint16_t TIM_ICFilter
);
150 static void TI3_Config(TIM_TypeDef
* TIMx
, uint16_t TIM_ICPolarity
, uint16_t TIM_ICSelection
,
151 uint16_t TIM_ICFilter
);
152 static void TI4_Config(TIM_TypeDef
* TIMx
, uint16_t TIM_ICPolarity
, uint16_t TIM_ICSelection
,
153 uint16_t TIM_ICFilter
);
155 /* Private functions ---------------------------------------------------------*/
157 /** @defgroup TIM_Private_Functions
161 /** @defgroup TIM_Group1 TimeBase management functions
162 * @brief TimeBase management functions
165 ===============================================================================
166 ##### TimeBase management functions #####
167 ===============================================================================
170 *** TIM Driver: how to use it in Timing(Time base) Mode ***
171 ============================================================
173 To use the Timer in Timing(Time base) mode, the following steps are mandatory:
175 (#) Enable TIM clock using
176 RCC_APBxPeriphClockCmd(RCC_APBxPeriph_TIMx, ENABLE) function
177 (#) Fill the TIM_TimeBaseInitStruct with the desired parameters.
178 (#) Call TIM_TimeBaseInit(TIMx, &TIM_TimeBaseInitStruct) to configure
180 with the corresponding configuration
181 (#) Enable the NVIC if you need to generate the update interrupt.
182 (#) Enable the corresponding interrupt using the function
183 TIM_ITConfig(TIMx, TIM_IT_Update)
184 (#) Call the TIM_Cmd(ENABLE) function to enable the TIM counter.
186 (@) All other functions can be used separately to modify, if needed,
187 a specific feature of the Timer.
194 * @brief Deinitializes the TIMx peripheral registers to their default reset values.
195 * @param TIMx: where x can be 1, 2, 3, 4, 6 ,7 ,8, 15, 16 or 17 to select the TIM peripheral.
199 void TIM_DeInit(TIM_TypeDef
* TIMx
)
201 /* Check the parameters */
202 assert_param(IS_TIM_ALL_PERIPH(TIMx
));
206 RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM1
, ENABLE
);
207 RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM1
, DISABLE
);
209 else if (TIMx
== TIM2
)
211 RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM2
, ENABLE
);
212 RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM2
, DISABLE
);
214 else if (TIMx
== TIM3
)
216 RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM3
, ENABLE
);
217 RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM3
, DISABLE
);
219 else if (TIMx
== TIM4
)
221 RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM4
, ENABLE
);
222 RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM4
, DISABLE
);
224 else if (TIMx
== TIM6
)
226 RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM6
, ENABLE
);
227 RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM6
, DISABLE
);
229 else if (TIMx
== TIM7
)
231 RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM7
, ENABLE
);
232 RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM7
, DISABLE
);
234 else if (TIMx
== TIM8
)
236 RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM8
, ENABLE
);
237 RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM8
, DISABLE
);
239 else if (TIMx
== TIM15
)
241 RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM15
, ENABLE
);
242 RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM15
, DISABLE
);
244 else if (TIMx
== TIM16
)
246 RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM16
, ENABLE
);
247 RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM16
, DISABLE
);
253 RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM17
, ENABLE
);
254 RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM17
, DISABLE
);
260 * @brief Initializes the TIMx Time Base Unit peripheral according to
261 * the specified parameters in the TIM_TimeBaseInitStruct.
262 * @param TIMx: where x can be 1, 2, 3, 4, 6 ,7 ,8, 15, 16 or 17 to select the TIM peripheral.
263 * @param TIM_TimeBaseInitStruct: pointer to a TIM_TimeBaseInitTypeDef structure
264 * that contains the configuration information for the specified TIM peripheral.
267 void TIM_TimeBaseInit(TIM_TypeDef
* TIMx
, TIM_TimeBaseInitTypeDef
* TIM_TimeBaseInitStruct
)
271 /* Check the parameters */
272 assert_param(IS_TIM_ALL_PERIPH(TIMx
));
273 assert_param(IS_TIM_COUNTER_MODE(TIM_TimeBaseInitStruct
->TIM_CounterMode
));
274 assert_param(IS_TIM_CKD_DIV(TIM_TimeBaseInitStruct
->TIM_ClockDivision
));
278 if((TIMx
== TIM1
) || (TIMx
== TIM8
)|| (TIMx
== TIM2
) ||
279 (TIMx
== TIM3
)|| (TIMx
== TIM4
))
281 /* Select the Counter Mode */
282 tmpcr1
&= (uint16_t)(~(TIM_CR1_DIR
| TIM_CR1_CMS
));
283 tmpcr1
|= (uint32_t)TIM_TimeBaseInitStruct
->TIM_CounterMode
;
286 if((TIMx
!= TIM6
) && (TIMx
!= TIM7
))
288 /* Set the clock division */
289 tmpcr1
&= (uint16_t)(~TIM_CR1_CKD
);
290 tmpcr1
|= (uint32_t)TIM_TimeBaseInitStruct
->TIM_ClockDivision
;
295 /* Set the Autoreload value */
296 TIMx
->ARR
= TIM_TimeBaseInitStruct
->TIM_Period
;
298 /* Set the Prescaler value */
299 TIMx
->PSC
= TIM_TimeBaseInitStruct
->TIM_Prescaler
;
301 if ((TIMx
== TIM1
) || (TIMx
== TIM8
)|| (TIMx
== TIM15
) ||
302 (TIMx
== TIM16
) || (TIMx
== TIM17
))
304 /* Set the Repetition Counter value */
305 TIMx
->RCR
= TIM_TimeBaseInitStruct
->TIM_RepetitionCounter
;
308 /* Generate an update event to reload the Prescaler
309 and the repetition counter(only for TIM1 and TIM8) value immediatly */
310 TIMx
->EGR
= TIM_PSCReloadMode_Immediate
;
314 * @brief Fills each TIM_TimeBaseInitStruct member with its default value.
315 * @param TIM_TimeBaseInitStruct : pointer to a TIM_TimeBaseInitTypeDef
316 * structure which will be initialized.
319 void TIM_TimeBaseStructInit(TIM_TimeBaseInitTypeDef
* TIM_TimeBaseInitStruct
)
321 /* Set the default configuration */
322 TIM_TimeBaseInitStruct
->TIM_Period
= 0xFFFFFFFF;
323 TIM_TimeBaseInitStruct
->TIM_Prescaler
= 0x0000;
324 TIM_TimeBaseInitStruct
->TIM_ClockDivision
= TIM_CKD_DIV1
;
325 TIM_TimeBaseInitStruct
->TIM_CounterMode
= TIM_CounterMode_Up
;
326 TIM_TimeBaseInitStruct
->TIM_RepetitionCounter
= 0x0000;
330 * @brief Configures the TIMx Prescaler.
331 * @param TIMx: where x can be 1, 2, 3, 4, 8, 15, 16 or 17 to select the TIM peripheral.
332 * @param Prescaler: specifies the Prescaler Register value
333 * @param TIM_PSCReloadMode: specifies the TIM Prescaler Reload mode
334 * This parameter can be one of the following values:
335 * @arg TIM_PSCReloadMode_Update: The Prescaler is loaded at the update event.
336 * @arg TIM_PSCReloadMode_Immediate: The Prescaler is loaded immediatly.
339 void TIM_PrescalerConfig(TIM_TypeDef
* TIMx
, uint16_t Prescaler
, uint16_t TIM_PSCReloadMode
)
341 /* Check the parameters */
342 assert_param(IS_TIM_ALL_PERIPH(TIMx
));
343 assert_param(IS_TIM_PRESCALER_RELOAD(TIM_PSCReloadMode
));
344 /* Set the Prescaler value */
345 TIMx
->PSC
= Prescaler
;
346 /* Set or reset the UG Bit */
347 TIMx
->EGR
= TIM_PSCReloadMode
;
351 * @brief Specifies the TIMx Counter Mode to be used.
352 * @param TIMx: where x can be 1, 2, 3, 4 or 8 to select the TIM peripheral.
353 * @param TIM_CounterMode: specifies the Counter Mode to be used
354 * This parameter can be one of the following values:
355 * @arg TIM_CounterMode_Up: TIM Up Counting Mode
356 * @arg TIM_CounterMode_Down: TIM Down Counting Mode
357 * @arg TIM_CounterMode_CenterAligned1: TIM Center Aligned Mode1
358 * @arg TIM_CounterMode_CenterAligned2: TIM Center Aligned Mode2
359 * @arg TIM_CounterMode_CenterAligned3: TIM Center Aligned Mode3
362 void TIM_CounterModeConfig(TIM_TypeDef
* TIMx
, uint16_t TIM_CounterMode
)
366 /* Check the parameters */
367 assert_param(IS_TIM_LIST3_PERIPH(TIMx
));
368 assert_param(IS_TIM_COUNTER_MODE(TIM_CounterMode
));
372 /* Reset the CMS and DIR Bits */
373 tmpcr1
&= (uint16_t)~(TIM_CR1_DIR
| TIM_CR1_CMS
);
375 /* Set the Counter Mode */
376 tmpcr1
|= TIM_CounterMode
;
378 /* Write to TIMx CR1 register */
383 * @brief Sets the TIMx Counter Register value
384 * @param TIMx: where x can be 1, 2, 3, 4, 6 ,7 ,8, 15, 16 or 17 to select the TIM peripheral.
385 * @param Counter: specifies the Counter register new value.
388 void TIM_SetCounter(TIM_TypeDef
* TIMx
, uint32_t Counter
)
390 /* Check the parameters */
391 assert_param(IS_TIM_ALL_PERIPH(TIMx
));
393 /* Set the Counter Register value */
398 * @brief Sets the TIMx Autoreload Register value
399 * @param TIMx: where x can be 1, 2, 3, 4, 6 ,7 ,8, 15, 16 or 17 to select the TIM peripheral.
400 * @param Autoreload: specifies the Autoreload register new value.
403 void TIM_SetAutoreload(TIM_TypeDef
* TIMx
, uint32_t Autoreload
)
405 /* Check the parameters */
406 assert_param(IS_TIM_ALL_PERIPH(TIMx
));
408 /* Set the Autoreload Register value */
409 TIMx
->ARR
= Autoreload
;
413 * @brief Gets the TIMx Counter value.
414 * @param TIMx: where x can be 1, 2, 3, 4, 6 ,7 ,8, 15, 16 or 17 to select the TIM peripheral.
415 * @retval Counter Register value
417 uint32_t TIM_GetCounter(TIM_TypeDef
* TIMx
)
419 /* Check the parameters */
420 assert_param(IS_TIM_ALL_PERIPH(TIMx
));
422 /* Get the Counter Register value */
427 * @brief Gets the TIMx Prescaler value.
428 * @param TIMx: where x can be 1, 2, 3, 4, 6 ,7 ,8, 15, 16 or 17 to select the TIM peripheral.
429 * @retval Prescaler Register value.
431 uint16_t TIM_GetPrescaler(TIM_TypeDef
* TIMx
)
433 /* Check the parameters */
434 assert_param(IS_TIM_ALL_PERIPH(TIMx
));
436 /* Get the Prescaler Register value */
441 * @brief Enables or Disables the TIMx Update event.
442 * @param TIMx: where x can be 1, 2, 3, 4, 6 ,7 ,8, 15, 16 or 17 to select the TIM peripheral.
443 * @param NewState: new state of the TIMx UDIS bit
444 * This parameter can be: ENABLE or DISABLE.
447 void TIM_UpdateDisableConfig(TIM_TypeDef
* TIMx
, FunctionalState NewState
)
449 /* Check the parameters */
450 assert_param(IS_TIM_ALL_PERIPH(TIMx
));
451 assert_param(IS_FUNCTIONAL_STATE(NewState
));
453 if (NewState
!= DISABLE
)
455 /* Set the Update Disable Bit */
456 TIMx
->CR1
|= TIM_CR1_UDIS
;
460 /* Reset the Update Disable Bit */
461 TIMx
->CR1
&= (uint16_t)~TIM_CR1_UDIS
;
466 * @brief Configures the TIMx Update Request Interrupt source.
467 * @param TIMx: where x can be 1, 2, 3, 4, 6 ,7 ,8, 15, 16 or 17 to select the TIM peripheral.
468 * @param TIM_UpdateSource: specifies the Update source.
469 * This parameter can be one of the following values:
470 * @arg TIM_UpdateSource_Regular: Source of update is the counter
471 * overflow/underflow or the setting of UG bit, or an update
472 * generation through the slave mode controller.
473 * @arg TIM_UpdateSource_Global: Source of update is counter overflow/underflow.
476 void TIM_UpdateRequestConfig(TIM_TypeDef
* TIMx
, uint16_t TIM_UpdateSource
)
478 /* Check the parameters */
479 assert_param(IS_TIM_ALL_PERIPH(TIMx
));
480 assert_param(IS_TIM_UPDATE_SOURCE(TIM_UpdateSource
));
482 if (TIM_UpdateSource
!= TIM_UpdateSource_Global
)
484 /* Set the URS Bit */
485 TIMx
->CR1
|= TIM_CR1_URS
;
489 /* Reset the URS Bit */
490 TIMx
->CR1
&= (uint16_t)~TIM_CR1_URS
;
495 * @brief Sets or resets the update interrupt flag (UIF)status bit Remapping.
496 * when sets, reading TIMx_CNT register returns UIF bit instead of CNT[31]
497 * @param TIMx: where x can be 1, 2, 3, 4, 6 ,7 ,8, 15, 16 or 17 to select the TIM peripheral.
498 * @param NewState: new state of the UIFREMAP bit.
499 * This parameter can be: ENABLE or DISABLE.
502 void TIM_UIFRemap(TIM_TypeDef
* TIMx
, FunctionalState NewState
)
504 /* Check the parameters */
505 assert_param(IS_TIM_ALL_PERIPH(TIMx
));
506 assert_param(IS_FUNCTIONAL_STATE(NewState
));
508 if (NewState
!= DISABLE
)
510 /* Enable the TIM Counter */
511 TIMx
->CR1
|= TIM_CR1_UIFREMAP
;
515 /* Disable the TIM Counter */
516 TIMx
->CR1
&= (uint16_t)~TIM_CR1_UIFREMAP
;
521 * @brief Enables or disables TIMx peripheral Preload register on ARR.
522 * @param TIMx: where x can be 1, 2, 3, 4, 6 ,7 ,8, 15, 16 or 17 to select the TIM peripheral.
523 * @param NewState: new state of the TIMx peripheral Preload register
524 * This parameter can be: ENABLE or DISABLE.
527 void TIM_ARRPreloadConfig(TIM_TypeDef
* TIMx
, FunctionalState NewState
)
529 /* Check the parameters */
530 assert_param(IS_TIM_ALL_PERIPH(TIMx
));
531 assert_param(IS_FUNCTIONAL_STATE(NewState
));
533 if (NewState
!= DISABLE
)
535 /* Set the ARR Preload Bit */
536 TIMx
->CR1
|= TIM_CR1_ARPE
;
540 /* Reset the ARR Preload Bit */
541 TIMx
->CR1
&= (uint16_t)~TIM_CR1_ARPE
;
546 * @brief Selects the TIMx's One Pulse Mode.
547 * @param TIMx: where x can be 1, 2, 3, 4, 6 ,7 ,8, 15, 16 or 17 to select the TIM peripheral.
548 * @param TIM_OPMode: specifies the OPM Mode to be used.
549 * This parameter can be one of the following values:
550 * @arg TIM_OPMode_Single
551 * @arg TIM_OPMode_Repetitive
554 void TIM_SelectOnePulseMode(TIM_TypeDef
* TIMx
, uint16_t TIM_OPMode
)
556 /* Check the parameters */
557 assert_param(IS_TIM_ALL_PERIPH(TIMx
));
558 assert_param(IS_TIM_OPM_MODE(TIM_OPMode
));
560 /* Reset the OPM Bit */
561 TIMx
->CR1
&= (uint16_t)~TIM_CR1_OPM
;
563 /* Configure the OPM Mode */
564 TIMx
->CR1
|= TIM_OPMode
;
568 * @brief Sets the TIMx Clock Division value.
569 * @param TIMx: where x can be 1, 2, 3, 4, 8, 15, 16 or 17, to select the TIM peripheral.
570 * @param TIM_CKD: specifies the clock division value.
571 * This parameter can be one of the following value:
572 * @arg TIM_CKD_DIV1: TDTS = Tck_tim
573 * @arg TIM_CKD_DIV2: TDTS = 2*Tck_tim
574 * @arg TIM_CKD_DIV4: TDTS = 4*Tck_tim
577 void TIM_SetClockDivision(TIM_TypeDef
* TIMx
, uint16_t TIM_CKD
)
579 /* Check the parameters */
580 assert_param(IS_TIM_LIST1_PERIPH(TIMx
));
581 assert_param(IS_TIM_CKD_DIV(TIM_CKD
));
583 /* Reset the CKD Bits */
584 TIMx
->CR1
&= (uint16_t)(~TIM_CR1_CKD
);
586 /* Set the CKD value */
587 TIMx
->CR1
|= TIM_CKD
;
591 * @brief Enables or disables the specified TIM peripheral.
592 * @param TIMx: where x can be 1, 2, 3, 4, 6, 7, 8, 15, 16 or 17 to select
593 * the TIMx peripheral.
594 * @param NewState: new state of the TIMx peripheral.
595 * This parameter can be: ENABLE or DISABLE.
598 void TIM_Cmd(TIM_TypeDef
* TIMx
, FunctionalState NewState
)
600 /* Check the parameters */
601 assert_param(IS_TIM_ALL_PERIPH(TIMx
));
602 assert_param(IS_FUNCTIONAL_STATE(NewState
));
604 if (NewState
!= DISABLE
)
606 /* Enable the TIM Counter */
607 TIMx
->CR1
|= TIM_CR1_CEN
;
611 /* Disable the TIM Counter */
612 TIMx
->CR1
&= (uint16_t)~TIM_CR1_CEN
;
619 /** @defgroup TIM_Group2 Output Compare management functions
620 * @brief Output Compare management functions
623 ===============================================================================
624 ##### Output Compare management functions #####
625 ===============================================================================
627 *** TIM Driver: how to use it in Output Compare Mode ***
628 ========================================================
630 To use the Timer in Output Compare mode, the following steps are mandatory:
632 (#) Enable TIM clock using RCC_APBxPeriphClockCmd(RCC_APBxPeriph_TIMx, ENABLE) function
634 (#) Configure the TIM pins by configuring the corresponding GPIO pins
636 (#) Configure the Time base unit as described in the first part of this driver,
637 if needed, else the Timer will run with the default configuration:
638 (++) Autoreload value = 0xFFFF
639 (++) Prescaler value = 0x0000
640 (++) Counter mode = Up counting
641 (++) Clock Division = TIM_CKD_DIV1
642 (#) Fill the TIM_OCInitStruct with the desired parameters including:
643 (++) The TIM Output Compare mode: TIM_OCMode
644 (++) TIM Output State: TIM_OutputState
645 (++) TIM Pulse value: TIM_Pulse
646 (++) TIM Output Compare Polarity : TIM_OCPolarity
648 (#) Call TIM_OCxInit(TIMx, &TIM_OCInitStruct) to configure the desired channel with the
649 corresponding configuration
651 (#) Call the TIM_Cmd(ENABLE) function to enable the TIM counter.
653 (@) All other functions can be used separately to modify, if needed,
654 a specific feature of the Timer.
656 (@) In case of PWM mode, this function is mandatory:
657 TIM_OCxPreloadConfig(TIMx, TIM_OCPreload_ENABLE);
659 (@) If the corresponding interrupt or DMA request are needed, the user should:
660 (#@) Enable the NVIC (or the DMA) to use the TIM interrupts (or DMA requests).
661 (#@) Enable the corresponding interrupt (or DMA request) using the function
662 TIM_ITConfig(TIMx, TIM_IT_CCx) (or TIM_DMA_Cmd(TIMx, TIM_DMA_CCx))
669 * @brief Initializes the TIMx Channel1 according to the specified parameters in
670 * the TIM_OCInitStruct.
671 * @param TIMx: where x can be 1, 2, 3, 4, 8, 15, 16 or 17, to select the TIM peripheral.
672 * @param TIM_OCInitStruct: pointer to a TIM_OCInitTypeDef structure that contains
673 * the configuration information for the specified TIM peripheral.
676 void TIM_OC1Init(TIM_TypeDef
* TIMx
, TIM_OCInitTypeDef
* TIM_OCInitStruct
)
678 uint32_t tmpccmrx
= 0, tmpccer
= 0, tmpcr2
= 0;
680 /* Check the parameters */
681 assert_param(IS_TIM_LIST1_PERIPH(TIMx
));
682 assert_param(IS_TIM_OC_MODE(TIM_OCInitStruct
->TIM_OCMode
));
683 assert_param(IS_TIM_OUTPUT_STATE(TIM_OCInitStruct
->TIM_OutputState
));
684 assert_param(IS_TIM_OC_POLARITY(TIM_OCInitStruct
->TIM_OCPolarity
));
686 /* Disable the Channel 1: Reset the CC1E Bit */
687 TIMx
->CCER
&= (uint32_t)~TIM_CCER_CC1E
;
689 /* Get the TIMx CCER register value */
690 tmpccer
= TIMx
->CCER
;
691 /* Get the TIMx CR2 register value */
694 /* Get the TIMx CCMR1 register value */
695 tmpccmrx
= TIMx
->CCMR1
;
697 /* Reset the Output Compare Mode Bits */
698 tmpccmrx
&= (uint32_t)~TIM_CCMR1_OC1M
;
699 tmpccmrx
&= (uint32_t)~TIM_CCMR1_CC1S
;
700 /* Select the Output Compare Mode */
701 tmpccmrx
|= TIM_OCInitStruct
->TIM_OCMode
;
703 /* Reset the Output Polarity level */
704 tmpccer
&= (uint32_t)~TIM_CCER_CC1P
;
705 /* Set the Output Compare Polarity */
706 tmpccer
|= TIM_OCInitStruct
->TIM_OCPolarity
;
708 /* Set the Output State */
709 tmpccer
|= TIM_OCInitStruct
->TIM_OutputState
;
711 if((TIMx
== TIM1
) || (TIMx
== TIM8
) || (TIMx
== TIM15
) || (TIMx
== TIM16
) || (TIMx
== TIM17
))
713 assert_param(IS_TIM_OUTPUTN_STATE(TIM_OCInitStruct
->TIM_OutputNState
));
714 assert_param(IS_TIM_OCN_POLARITY(TIM_OCInitStruct
->TIM_OCNPolarity
));
715 assert_param(IS_TIM_OCNIDLE_STATE(TIM_OCInitStruct
->TIM_OCNIdleState
));
716 assert_param(IS_TIM_OCIDLE_STATE(TIM_OCInitStruct
->TIM_OCIdleState
));
718 /* Reset the Output N Polarity level */
719 tmpccer
&= (uint32_t)~TIM_CCER_CC1NP
;
720 /* Set the Output N Polarity */
721 tmpccer
|= TIM_OCInitStruct
->TIM_OCNPolarity
;
722 /* Reset the Output N State */
723 tmpccer
&= (uint32_t)~TIM_CCER_CC1NE
;
725 /* Set the Output N State */
726 tmpccer
|= TIM_OCInitStruct
->TIM_OutputNState
;
727 /* Reset the Output Compare and Output Compare N IDLE State */
728 tmpcr2
&= (uint32_t)~TIM_CR2_OIS1
;
729 tmpcr2
&= (uint32_t)~TIM_CR2_OIS1N
;
730 /* Set the Output Idle state */
731 tmpcr2
|= TIM_OCInitStruct
->TIM_OCIdleState
;
732 /* Set the Output N Idle state */
733 tmpcr2
|= TIM_OCInitStruct
->TIM_OCNIdleState
;
735 /* Write to TIMx CR2 */
738 /* Write to TIMx CCMR1 */
739 TIMx
->CCMR1
= tmpccmrx
;
741 /* Set the Capture Compare Register value */
742 TIMx
->CCR1
= TIM_OCInitStruct
->TIM_Pulse
;
744 /* Write to TIMx CCER */
745 TIMx
->CCER
= tmpccer
;
749 * @brief Initializes the TIMx Channel2 according to the specified parameters
750 * in the TIM_OCInitStruct.
751 * @param TIMx: where x can be 1, 2, 3, 4, 8 or 15 to select the TIM peripheral.
752 * @param TIM_OCInitStruct: pointer to a TIM_OCInitTypeDef structure that contains
753 * the configuration information for the specified TIM peripheral.
756 void TIM_OC2Init(TIM_TypeDef
* TIMx
, TIM_OCInitTypeDef
* TIM_OCInitStruct
)
758 uint32_t tmpccmrx
= 0, tmpccer
= 0, tmpcr2
= 0;
760 /* Check the parameters */
761 assert_param(IS_TIM_LIST2_PERIPH(TIMx
));
762 assert_param(IS_TIM_OC_MODE(TIM_OCInitStruct
->TIM_OCMode
));
763 assert_param(IS_TIM_OUTPUT_STATE(TIM_OCInitStruct
->TIM_OutputState
));
764 assert_param(IS_TIM_OC_POLARITY(TIM_OCInitStruct
->TIM_OCPolarity
));
766 /* Disable the Channel 2: Reset the CC2E Bit */
767 TIMx
->CCER
&= (uint32_t)~TIM_CCER_CC2E
;
769 /* Get the TIMx CCER register value */
770 tmpccer
= TIMx
->CCER
;
771 /* Get the TIMx CR2 register value */
774 /* Get the TIMx CCMR1 register value */
775 tmpccmrx
= TIMx
->CCMR1
;
777 /* Reset the Output Compare mode and Capture/Compare selection Bits */
778 tmpccmrx
&= (uint32_t)~TIM_CCMR1_OC2M
;
779 tmpccmrx
&= (uint32_t)~TIM_CCMR1_CC2S
;
781 /* Select the Output Compare Mode */
782 tmpccmrx
|= (uint32_t)(TIM_OCInitStruct
->TIM_OCMode
<< 8);
784 /* Reset the Output Polarity level */
785 tmpccer
&= (uint32_t)~TIM_CCER_CC2P
;
786 /* Set the Output Compare Polarity */
787 tmpccer
|= (uint32_t)((uint32_t)TIM_OCInitStruct
->TIM_OCPolarity
<< 4);
789 /* Set the Output State */
790 tmpccer
|= (uint32_t)((uint32_t)TIM_OCInitStruct
->TIM_OutputState
<< 4);
792 if((TIMx
== TIM1
) || (TIMx
== TIM8
))
794 assert_param(IS_TIM_OUTPUTN_STATE(TIM_OCInitStruct
->TIM_OutputNState
));
795 assert_param(IS_TIM_OCN_POLARITY(TIM_OCInitStruct
->TIM_OCNPolarity
));
796 assert_param(IS_TIM_OCNIDLE_STATE(TIM_OCInitStruct
->TIM_OCNIdleState
));
797 assert_param(IS_TIM_OCIDLE_STATE(TIM_OCInitStruct
->TIM_OCIdleState
));
799 /* Reset the Output N Polarity level */
800 tmpccer
&= (uint32_t)~TIM_CCER_CC2NP
;
801 /* Set the Output N Polarity */
802 tmpccer
|= (uint32_t)((uint32_t)TIM_OCInitStruct
->TIM_OCNPolarity
<< 4);
803 /* Reset the Output N State */
804 tmpccer
&= (uint32_t)~TIM_CCER_CC2NE
;
806 /* Set the Output N State */
807 tmpccer
|= (uint32_t)((uint32_t)TIM_OCInitStruct
->TIM_OutputNState
<< 4);
808 /* Reset the Output Compare and Output Compare N IDLE State */
809 tmpcr2
&= (uint32_t)~TIM_CR2_OIS2
;
810 tmpcr2
&= (uint32_t)~TIM_CR2_OIS2N
;
811 /* Set the Output Idle state */
812 tmpcr2
|= (uint32_t)((uint32_t)TIM_OCInitStruct
->TIM_OCIdleState
<< 2);
813 /* Set the Output N Idle state */
814 tmpcr2
|= (uint32_t)((uint32_t)TIM_OCInitStruct
->TIM_OCNIdleState
<< 2);
816 /* Write to TIMx CR2 */
819 /* Write to TIMx CCMR1 */
820 TIMx
->CCMR1
= tmpccmrx
;
822 /* Set the Capture Compare Register value */
823 TIMx
->CCR2
= TIM_OCInitStruct
->TIM_Pulse
;
825 /* Write to TIMx CCER */
826 TIMx
->CCER
= tmpccer
;
830 * @brief Initializes the TIMx Channel3 according to the specified parameters
831 * in the TIM_OCInitStruct.
832 * @param TIMx: where x can be 1, 2, 3, 4 or 8 to select the TIM peripheral.
833 * @param TIM_OCInitStruct: pointer to a TIM_OCInitTypeDef structure that contains
834 * the configuration information for the specified TIM peripheral.
837 void TIM_OC3Init(TIM_TypeDef
* TIMx
, TIM_OCInitTypeDef
* TIM_OCInitStruct
)
839 uint32_t tmpccmrx
= 0, tmpccer
= 0, tmpcr2
= 0;
841 /* Check the parameters */
842 assert_param(IS_TIM_LIST3_PERIPH(TIMx
));
843 assert_param(IS_TIM_OC_MODE(TIM_OCInitStruct
->TIM_OCMode
));
844 assert_param(IS_TIM_OUTPUT_STATE(TIM_OCInitStruct
->TIM_OutputState
));
845 assert_param(IS_TIM_OC_POLARITY(TIM_OCInitStruct
->TIM_OCPolarity
));
847 /* Disable the Channel 3: Reset the CC2E Bit */
848 TIMx
->CCER
&= (uint32_t)~TIM_CCER_CC3E
;
850 /* Get the TIMx CCER register value */
851 tmpccer
= TIMx
->CCER
;
852 /* Get the TIMx CR2 register value */
855 /* Get the TIMx CCMR2 register value */
856 tmpccmrx
= TIMx
->CCMR2
;
858 /* Reset the Output Compare mode and Capture/Compare selection Bits */
859 tmpccmrx
&= (uint32_t)~TIM_CCMR2_OC3M
;
860 tmpccmrx
&= (uint32_t)~TIM_CCMR2_CC3S
;
861 /* Select the Output Compare Mode */
862 tmpccmrx
|= TIM_OCInitStruct
->TIM_OCMode
;
864 /* Reset the Output Polarity level */
865 tmpccer
&= (uint32_t)~TIM_CCER_CC3P
;
866 /* Set the Output Compare Polarity */
867 tmpccer
|= (uint32_t)((uint32_t)TIM_OCInitStruct
->TIM_OCPolarity
<< 8);
869 /* Set the Output State */
870 tmpccer
|= (uint32_t)((uint32_t)TIM_OCInitStruct
->TIM_OutputState
<< 8);
872 if((TIMx
== TIM1
) || (TIMx
== TIM8
))
874 assert_param(IS_TIM_OUTPUTN_STATE(TIM_OCInitStruct
->TIM_OutputNState
));
875 assert_param(IS_TIM_OCN_POLARITY(TIM_OCInitStruct
->TIM_OCNPolarity
));
876 assert_param(IS_TIM_OCNIDLE_STATE(TIM_OCInitStruct
->TIM_OCNIdleState
));
877 assert_param(IS_TIM_OCIDLE_STATE(TIM_OCInitStruct
->TIM_OCIdleState
));
879 /* Reset the Output N Polarity level */
880 tmpccer
&= (uint32_t)~TIM_CCER_CC3NP
;
881 /* Set the Output N Polarity */
882 tmpccer
|= (uint32_t)((uint32_t)TIM_OCInitStruct
->TIM_OCNPolarity
<< 8);
883 /* Reset the Output N State */
884 tmpccer
&= (uint32_t)~TIM_CCER_CC3NE
;
886 /* Set the Output N State */
887 tmpccer
|= (uint32_t)((uint32_t)TIM_OCInitStruct
->TIM_OutputNState
<< 8);
888 /* Reset the Output Compare and Output Compare N IDLE State */
889 tmpcr2
&= (uint32_t)~TIM_CR2_OIS3
;
890 tmpcr2
&= (uint32_t)~TIM_CR2_OIS3N
;
891 /* Set the Output Idle state */
892 tmpcr2
|= (uint32_t)((uint32_t)TIM_OCInitStruct
->TIM_OCIdleState
<< 4);
893 /* Set the Output N Idle state */
894 tmpcr2
|= (uint32_t)((uint32_t)TIM_OCInitStruct
->TIM_OCNIdleState
<< 4);
896 /* Write to TIMx CR2 */
899 /* Write to TIMx CCMR2 */
900 TIMx
->CCMR2
= tmpccmrx
;
902 /* Set the Capture Compare Register value */
903 TIMx
->CCR3
= TIM_OCInitStruct
->TIM_Pulse
;
905 /* Write to TIMx CCER */
906 TIMx
->CCER
= tmpccer
;
910 * @brief Initializes the TIMx Channel4 according to the specified parameters
911 * in the TIM_OCInitStruct.
912 * @param TIMx: where x can be 1, 2, 3, 4 or 8 to select the TIM peripheral.
913 * @param TIM_OCInitStruct: pointer to a TIM_OCInitTypeDef structure that contains
914 * the configuration information for the specified TIM peripheral.
917 void TIM_OC4Init(TIM_TypeDef
* TIMx
, TIM_OCInitTypeDef
* TIM_OCInitStruct
)
919 uint32_t tmpccmrx
= 0, tmpccer
= 0, tmpcr2
= 0;
921 /* Check the parameters */
922 assert_param(IS_TIM_LIST3_PERIPH(TIMx
));
923 assert_param(IS_TIM_OC_MODE(TIM_OCInitStruct
->TIM_OCMode
));
924 assert_param(IS_TIM_OUTPUT_STATE(TIM_OCInitStruct
->TIM_OutputState
));
925 assert_param(IS_TIM_OC_POLARITY(TIM_OCInitStruct
->TIM_OCPolarity
));
927 /* Disable the Channel 4: Reset the CC4E Bit */
928 TIMx
->CCER
&= (uint32_t)~TIM_CCER_CC4E
;
930 /* Get the TIMx CCER register value */
931 tmpccer
= TIMx
->CCER
;
932 /* Get the TIMx CR2 register value */
935 /* Get the TIMx CCMR2 register value */
936 tmpccmrx
= TIMx
->CCMR2
;
938 /* Reset the Output Compare mode and Capture/Compare selection Bits */
939 tmpccmrx
&= (uint32_t)~TIM_CCMR2_OC4M
;
940 tmpccmrx
&= (uint32_t)~TIM_CCMR2_CC4S
;
942 /* Select the Output Compare Mode */
943 tmpccmrx
|= (uint32_t)(TIM_OCInitStruct
->TIM_OCMode
<< 8);
945 /* Reset the Output Polarity level */
946 tmpccer
&= (uint32_t)~TIM_CCER_CC4P
;
947 /* Set the Output Compare Polarity */
948 tmpccer
|= (uint32_t)((uint32_t)TIM_OCInitStruct
->TIM_OCPolarity
<< 12);
950 /* Set the Output State */
951 tmpccer
|= (uint32_t)((uint32_t)TIM_OCInitStruct
->TIM_OutputState
<< 12);
953 if((TIMx
== TIM1
) || (TIMx
== TIM8
))
955 assert_param(IS_TIM_OCIDLE_STATE(TIM_OCInitStruct
->TIM_OCIdleState
));
956 /* Reset the Output Compare IDLE State */
957 tmpcr2
&=(uint32_t) ~TIM_CR2_OIS4
;
958 /* Set the Output Idle state */
959 tmpcr2
|= (uint32_t)((uint32_t)TIM_OCInitStruct
->TIM_OCIdleState
<< 6);
961 /* Write to TIMx CR2 */
964 /* Write to TIMx CCMR2 */
965 TIMx
->CCMR2
= tmpccmrx
;
967 /* Set the Capture Compare Register value */
968 TIMx
->CCR4
= TIM_OCInitStruct
->TIM_Pulse
;
970 /* Write to TIMx CCER */
971 TIMx
->CCER
= tmpccer
;
975 * @brief Initializes the TIMx Channel5 according to the specified parameters
976 * in the TIM_OCInitStruct.
977 * @param TIMx: where x can be 1 or 8 to select the TIM peripheral.
978 * @param TIM_OCInitStruct: pointer to a TIM_OCInitTypeDef structure that contains
979 * the configuration information for the specified TIM peripheral.
982 void TIM_OC5Init(TIM_TypeDef
* TIMx
, TIM_OCInitTypeDef
* TIM_OCInitStruct
)
984 uint32_t tmpccmrx
= 0, tmpccer
= 0, tmpcr2
= 0;
986 /* Check the parameters */
987 assert_param(IS_TIM_LIST4_PERIPH(TIMx
));
988 assert_param(IS_TIM_OC_MODE(TIM_OCInitStruct
->TIM_OCMode
));
989 assert_param(IS_TIM_OUTPUT_STATE(TIM_OCInitStruct
->TIM_OutputState
));
990 assert_param(IS_TIM_OC_POLARITY(TIM_OCInitStruct
->TIM_OCPolarity
));
992 /* Disable the Channel 5: Reset the CC5E Bit */
993 TIMx
->CCER
&= (uint32_t)~TIM_CCER_CC5E
; /* to be verified*/
995 /* Get the TIMx CCER register value */
996 tmpccer
= TIMx
->CCER
;
997 /* Get the TIMx CR2 register value */
1000 /* Get the TIMx CCMR3 register value */
1001 tmpccmrx
= TIMx
->CCMR3
;
1003 /* Reset the Output Compare mode and Capture/Compare selection Bits */
1004 tmpccmrx
&= (uint32_t)~TIM_CCMR3_OC5M
;
1006 /* Select the Output Compare Mode */
1007 tmpccmrx
|= (uint32_t)(TIM_OCInitStruct
->TIM_OCMode
);
1009 /* Reset the Output Polarity level */
1010 tmpccer
&= (uint32_t)~TIM_CCER_CC5P
;
1011 /* Set the Output Compare Polarity */
1012 tmpccer
|= (uint32_t)((uint32_t)TIM_OCInitStruct
->TIM_OCPolarity
<< 16);
1014 /* Set the Output State */
1015 tmpccer
|= (uint32_t)((uint32_t)TIM_OCInitStruct
->TIM_OutputState
<< 16);
1017 if((TIMx
== TIM1
) || (TIMx
== TIM8
))
1019 assert_param(IS_TIM_OCIDLE_STATE(TIM_OCInitStruct
->TIM_OCIdleState
));
1020 /* Reset the Output Compare IDLE State */
1021 tmpcr2
&=(uint32_t) ~TIM_CR2_OIS5
;
1022 /* Set the Output Idle state */
1023 tmpcr2
|= (uint32_t)((uint32_t)TIM_OCInitStruct
->TIM_OCIdleState
<< 16);
1025 /* Write to TIMx CR2 */
1028 /* Write to TIMx CCMR2 */
1029 TIMx
->CCMR3
= tmpccmrx
;
1031 /* Set the Capture Compare Register value */
1032 TIMx
->CCR5
= TIM_OCInitStruct
->TIM_Pulse
;
1034 /* Write to TIMx CCER */
1035 TIMx
->CCER
= tmpccer
;
1039 * @brief Initializes the TIMx Channel6 according to the specified parameters
1040 * in the TIM_OCInitStruct.
1041 * @param TIMx: where x can be 1 or 8 to select the TIM peripheral.
1042 * @param TIM_OCInitStruct: pointer to a TIM_OCInitTypeDef structure that contains
1043 * the configuration information for the specified TIM peripheral.
1046 void TIM_OC6Init(TIM_TypeDef
* TIMx
, TIM_OCInitTypeDef
* TIM_OCInitStruct
)
1048 uint32_t tmpccmrx
= 0, tmpccer
= 0, tmpcr2
= 0;
1050 /* Check the parameters */
1051 assert_param(IS_TIM_LIST4_PERIPH(TIMx
));
1052 assert_param(IS_TIM_OC_MODE(TIM_OCInitStruct
->TIM_OCMode
));
1053 assert_param(IS_TIM_OUTPUT_STATE(TIM_OCInitStruct
->TIM_OutputState
));
1054 assert_param(IS_TIM_OC_POLARITY(TIM_OCInitStruct
->TIM_OCPolarity
));
1056 /* Disable the Channel 5: Reset the CC5E Bit */
1057 TIMx
->CCER
&= (uint32_t)~TIM_CCER_CC6E
; /* to be verified*/
1059 /* Get the TIMx CCER register value */
1060 tmpccer
= TIMx
->CCER
;
1061 /* Get the TIMx CR2 register value */
1064 /* Get the TIMx CCMR3 register value */
1065 tmpccmrx
= TIMx
->CCMR3
;
1067 /* Reset the Output Compare mode and Capture/Compare selection Bits */
1068 tmpccmrx
&= (uint32_t)~TIM_CCMR3_OC6M
;
1070 /* Select the Output Compare Mode */
1071 tmpccmrx
|= (uint32_t)(TIM_OCInitStruct
->TIM_OCMode
<< 8);
1073 /* Reset the Output Polarity level */
1074 tmpccer
&= (uint32_t)~TIM_CCER_CC6P
;
1075 /* Set the Output Compare Polarity */
1076 tmpccer
|= (uint32_t)((uint32_t)TIM_OCInitStruct
->TIM_OCPolarity
<< 20);
1078 /* Set the Output State */
1079 tmpccer
|= (uint32_t)((uint32_t)TIM_OCInitStruct
->TIM_OutputState
<< 20);
1081 if((TIMx
== TIM1
) || (TIMx
== TIM8
))
1083 assert_param(IS_TIM_OCIDLE_STATE(TIM_OCInitStruct
->TIM_OCIdleState
));
1084 /* Reset the Output Compare IDLE State */
1085 tmpcr2
&=(uint32_t) ~TIM_CR2_OIS6
;
1086 /* Set the Output Idle state */
1087 tmpcr2
|= (uint16_t)(TIM_OCInitStruct
->TIM_OCIdleState
<< 18);
1089 /* Write to TIMx CR2 */
1092 /* Write to TIMx CCMR2 */
1093 TIMx
->CCMR3
= tmpccmrx
;
1095 /* Set the Capture Compare Register value */
1096 TIMx
->CCR6
= TIM_OCInitStruct
->TIM_Pulse
;
1098 /* Write to TIMx CCER */
1099 TIMx
->CCER
= tmpccer
;
1103 * @brief Selects the TIM Group Channel 5 and Channel 1,
1104 OC1REFC is the logical AND of OC1REFC and OC5REF.
1105 * @param TIMx: where x can be 1 or 8 to select the TIMx peripheral
1106 * @param NewState: new state of the Commutation event.
1107 * This parameter can be: ENABLE or DISABLE.
1110 void TIM_SelectGC5C1(TIM_TypeDef
* TIMx
, FunctionalState NewState
)
1112 /* Check the parameters */
1113 assert_param(IS_TIM_LIST4_PERIPH(TIMx
));
1114 assert_param(IS_FUNCTIONAL_STATE(NewState
));
1116 if (NewState
!= DISABLE
)
1118 /* Set the GC5C1 Bit */
1119 TIMx
->CCR5
|= TIM_CCR5_GC5C1
;
1123 /* Reset the GC5C1 Bit */
1124 TIMx
->CCR5
&= (uint32_t)~TIM_CCR5_GC5C1
;
1129 * @brief Selects the TIM Group Channel 5 and Channel 2,
1130 OC2REFC is the logical AND of OC2REFC and OC5REF.
1131 * @param TIMx: where x can be 1 or 8 to select the TIMx peripheral
1132 * @param NewState: new state of the Commutation event.
1133 * This parameter can be: ENABLE or DISABLE.
1136 void TIM_SelectGC5C2(TIM_TypeDef
* TIMx
, FunctionalState NewState
)
1138 /* Check the parameters */
1139 assert_param(IS_TIM_LIST4_PERIPH(TIMx
));
1140 assert_param(IS_FUNCTIONAL_STATE(NewState
));
1142 if (NewState
!= DISABLE
)
1144 /* Set the GC5C2 Bit */
1145 TIMx
->CCR5
|= TIM_CCR5_GC5C2
;
1149 /* Reset the GC5C2 Bit */
1150 TIMx
->CCR5
&= (uint32_t)~TIM_CCR5_GC5C2
;
1156 * @brief Selects the TIM Group Channel 5 and Channel 3,
1157 OC3REFC is the logical AND of OC3REFC and OC5REF.
1158 * @param TIMx: where x can be 1 or 8 to select the TIMx peripheral
1159 * @param NewState: new state of the Commutation event.
1160 * This parameter can be: ENABLE or DISABLE.
1163 void TIM_SelectGC5C3(TIM_TypeDef
* TIMx
, FunctionalState NewState
)
1165 /* Check the parameters */
1166 assert_param(IS_TIM_LIST4_PERIPH(TIMx
));
1167 assert_param(IS_FUNCTIONAL_STATE(NewState
));
1169 if (NewState
!= DISABLE
)
1171 /* Set the GC5C3 Bit */
1172 TIMx
->CCR5
|= TIM_CCR5_GC5C3
;
1176 /* Reset the GC5C3 Bit */
1177 TIMx
->CCR5
&= (uint32_t)~TIM_CCR5_GC5C3
;
1182 * @brief Fills each TIM_OCInitStruct member with its default value.
1183 * @param TIM_OCInitStruct: pointer to a TIM_OCInitTypeDef structure which will
1187 void TIM_OCStructInit(TIM_OCInitTypeDef
* TIM_OCInitStruct
)
1189 /* Set the default configuration */
1190 TIM_OCInitStruct
->TIM_OCMode
= TIM_OCMode_Timing
;
1191 TIM_OCInitStruct
->TIM_OutputState
= TIM_OutputState_Disable
;
1192 TIM_OCInitStruct
->TIM_OutputNState
= TIM_OutputNState_Disable
;
1193 TIM_OCInitStruct
->TIM_Pulse
= 0x00000000;
1194 TIM_OCInitStruct
->TIM_OCPolarity
= TIM_OCPolarity_High
;
1195 TIM_OCInitStruct
->TIM_OCNPolarity
= TIM_OCPolarity_High
;
1196 TIM_OCInitStruct
->TIM_OCIdleState
= TIM_OCIdleState_Reset
;
1197 TIM_OCInitStruct
->TIM_OCNIdleState
= TIM_OCNIdleState_Reset
;
1201 * @brief Selects the TIM Output Compare Mode.
1202 * @note This function disables the selected channel before changing the Output
1203 * Compare Mode. If needed, user has to enable this channel using
1204 * TIM_CCxCmd() and TIM_CCxNCmd() functions.
1205 * @param TIMx: where x can be 1, 2, 3, 4, 8, 15, 16 or 17 to select the TIM peripheral.
1206 * @param TIM_Channel: specifies the TIM Channel
1207 * This parameter can be one of the following values:
1208 * @arg TIM_Channel_1: TIM Channel 1
1209 * @arg TIM_Channel_2: TIM Channel 2
1210 * @arg TIM_Channel_3: TIM Channel 3
1211 * @arg TIM_Channel_4: TIM Channel 4
1212 * @param TIM_OCMode: specifies the TIM Output Compare Mode.
1213 * This parameter can be one of the following values:
1214 * @arg TIM_OCMode_Timing
1215 * @arg TIM_OCMode_Active
1216 * @arg TIM_OCMode_Toggle
1217 * @arg TIM_OCMode_PWM1
1218 * @arg TIM_OCMode_PWM2
1219 * @arg TIM_ForcedAction_Active
1220 * @arg TIM_ForcedAction_InActive
1221 * @arg TIM_OCMode_Retrigerrable_OPM1
1222 * @arg TIM_OCMode_Retrigerrable_OPM2
1223 * @arg TIM_OCMode_Combined_PWM1
1224 * @arg TIM_OCMode_Combined_PWM2
1225 * @arg TIM_OCMode_Asymmetric_PWM1
1226 * @arg TIM_OCMode_Asymmetric_PWM2
1229 void TIM_SelectOCxM(TIM_TypeDef
* TIMx
, uint16_t TIM_Channel
, uint32_t TIM_OCMode
)
1234 /* Check the parameters */
1235 assert_param(IS_TIM_LIST1_PERIPH(TIMx
));
1236 assert_param(IS_TIM_CHANNEL(TIM_Channel
));
1237 assert_param(IS_TIM_OCM(TIM_OCMode
));
1239 tmp
= (uint32_t) TIMx
;
1242 tmp1
= CCER_CCE_SET
<< (uint16_t)TIM_Channel
;
1244 /* Disable the Channel: Reset the CCxE Bit */
1245 TIMx
->CCER
&= (uint16_t) ~tmp1
;
1247 if((TIM_Channel
== TIM_Channel_1
) ||(TIM_Channel
== TIM_Channel_3
))
1249 tmp
+= (TIM_Channel
>>1);
1251 /* Reset the OCxM bits in the CCMRx register */
1252 *(__IO
uint32_t *) tmp
&= CCMR_OC13M_MASK
;
1254 /* Configure the OCxM bits in the CCMRx register */
1255 *(__IO
uint32_t *) tmp
|= TIM_OCMode
;
1259 tmp
+= (uint32_t)(TIM_Channel
- (uint32_t)4)>> (uint32_t)1;
1261 /* Reset the OCxM bits in the CCMRx register */
1262 *(__IO
uint32_t *) tmp
&= CCMR_OC24M_MASK
;
1264 /* Configure the OCxM bits in the CCMRx register */
1265 *(__IO
uint32_t *) tmp
|= (uint32_t)(TIM_OCMode
<< 8);
1270 * @brief Sets the TIMx Capture Compare1 Register value
1271 * @param TIMx: where x can be 1, 2, 3, 4, 8, 15, 16 or 17 to select the TIM peripheral.
1272 * @param Compare1: specifies the Capture Compare1 register new value.
1275 void TIM_SetCompare1(TIM_TypeDef
* TIMx
, uint32_t Compare1
)
1277 /* Check the parameters */
1278 assert_param(IS_TIM_LIST1_PERIPH(TIMx
));
1280 /* Set the Capture Compare1 Register value */
1281 TIMx
->CCR1
= Compare1
;
1285 * @brief Sets the TIMx Capture Compare2 Register value
1286 * @param TIMx: where x can be 1, 2, 3, 4, 8 or 15 to select the TIM
1288 * @param Compare2: specifies the Capture Compare2 register new value.
1291 void TIM_SetCompare2(TIM_TypeDef
* TIMx
, uint32_t Compare2
)
1293 /* Check the parameters */
1294 assert_param(IS_TIM_LIST2_PERIPH(TIMx
));
1296 /* Set the Capture Compare2 Register value */
1297 TIMx
->CCR2
= Compare2
;
1301 * @brief Sets the TIMx Capture Compare3 Register value
1302 * @param TIMx: where x can be 1, 2, 3, 4, 5 or 8 to select the TIM peripheral.
1303 * @param Compare3: specifies the Capture Compare3 register new value.
1306 void TIM_SetCompare3(TIM_TypeDef
* TIMx
, uint32_t Compare3
)
1308 /* Check the parameters */
1309 assert_param(IS_TIM_LIST3_PERIPH(TIMx
));
1311 /* Set the Capture Compare3 Register value */
1312 TIMx
->CCR3
= Compare3
;
1316 * @brief Sets the TIMx Capture Compare4 Register value
1317 * @param TIMx: where x can be 1, 2, 3, 4, 5 or 8 to select the TIM peripheral.
1318 * @param Compare4: specifies the Capture Compare4 register new value.
1321 void TIM_SetCompare4(TIM_TypeDef
* TIMx
, uint32_t Compare4
)
1323 /* Check the parameters */
1324 assert_param(IS_TIM_LIST3_PERIPH(TIMx
));
1326 /* Set the Capture Compare4 Register value */
1327 TIMx
->CCR4
= Compare4
;
1331 * @brief Sets the TIMx Capture Compare5 Register value
1332 * @param TIMx: where x can be 1 or 8 to select the TIM peripheral.
1333 * @param Compare5: specifies the Capture Compare5 register new value.
1336 void TIM_SetCompare5(TIM_TypeDef
* TIMx
, uint32_t Compare5
)
1338 /* Check the parameters */
1339 assert_param(IS_TIM_LIST4_PERIPH(TIMx
));
1341 /* Set the Capture Compare5 Register value */
1342 TIMx
->CCR5
= Compare5
;
1346 * @brief Sets the TIMx Capture Compare6 Register value
1347 * @param TIMx: where x can be 1 or 8 to select the TIM peripheral.
1348 * @param Compare6: specifies the Capture Compare5 register new value.
1351 void TIM_SetCompare6(TIM_TypeDef
* TIMx
, uint32_t Compare6
)
1353 /* Check the parameters */
1354 assert_param(IS_TIM_LIST4_PERIPH(TIMx
));
1356 /* Set the Capture Compare6 Register value */
1357 TIMx
->CCR6
= Compare6
;
1361 * @brief Forces the TIMx output 1 waveform to active or inactive level.
1362 * @param TIMx: where x can be 1, 2, 3, 4, 8, 15, 16 or 17 to select the TIM peripheral.
1363 * @param TIM_ForcedAction: specifies the forced Action to be set to the output waveform.
1364 * This parameter can be one of the following values:
1365 * @arg TIM_ForcedAction_Active: Force active level on OC1REF
1366 * @arg TIM_ForcedAction_InActive: Force inactive level on OC1REF.
1369 void TIM_ForcedOC1Config(TIM_TypeDef
* TIMx
, uint16_t TIM_ForcedAction
)
1371 uint32_t tmpccmr1
= 0;
1373 /* Check the parameters */
1374 assert_param(IS_TIM_LIST1_PERIPH(TIMx
));
1375 assert_param(IS_TIM_FORCED_ACTION(TIM_ForcedAction
));
1376 tmpccmr1
= TIMx
->CCMR1
;
1378 /* Reset the OC1M Bits */
1379 tmpccmr1
&= (uint32_t)~TIM_CCMR1_OC1M
;
1381 /* Configure The Forced output Mode */
1382 tmpccmr1
|= TIM_ForcedAction
;
1384 /* Write to TIMx CCMR1 register */
1385 TIMx
->CCMR1
= tmpccmr1
;
1389 * @brief Forces the TIMx output 2 waveform to active or inactive level.
1390 * @param TIMx: where x can be 1, 2, 3, 4, 8 or 15 to select the TIM
1392 * @param TIM_ForcedAction: specifies the forced Action to be set to the output waveform.
1393 * This parameter can be one of the following values:
1394 * @arg TIM_ForcedAction_Active: Force active level on OC2REF
1395 * @arg TIM_ForcedAction_InActive: Force inactive level on OC2REF.
1398 void TIM_ForcedOC2Config(TIM_TypeDef
* TIMx
, uint16_t TIM_ForcedAction
)
1400 uint32_t tmpccmr1
= 0;
1402 /* Check the parameters */
1403 assert_param(IS_TIM_LIST2_PERIPH(TIMx
));
1404 assert_param(IS_TIM_FORCED_ACTION(TIM_ForcedAction
));
1405 tmpccmr1
= TIMx
->CCMR1
;
1407 /* Reset the OC2M Bits */
1408 tmpccmr1
&= (uint32_t)~TIM_CCMR1_OC2M
;
1410 /* Configure The Forced output Mode */
1411 tmpccmr1
|= ((uint32_t)TIM_ForcedAction
<< 8);
1413 /* Write to TIMx CCMR1 register */
1414 TIMx
->CCMR1
= tmpccmr1
;
1418 * @brief Forces the TIMx output 3 waveform to active or inactive level.
1419 * @param TIMx: where x can be 1, 2, 3, 4 or 8 to select the TIM peripheral.
1420 * @param TIM_ForcedAction: specifies the forced Action to be set to the output waveform.
1421 * This parameter can be one of the following values:
1422 * @arg TIM_ForcedAction_Active: Force active level on OC3REF
1423 * @arg TIM_ForcedAction_InActive: Force inactive level on OC3REF.
1426 void TIM_ForcedOC3Config(TIM_TypeDef
* TIMx
, uint16_t TIM_ForcedAction
)
1428 uint32_t tmpccmr2
= 0;
1430 /* Check the parameters */
1431 assert_param(IS_TIM_LIST3_PERIPH(TIMx
));
1432 assert_param(IS_TIM_FORCED_ACTION(TIM_ForcedAction
));
1434 tmpccmr2
= TIMx
->CCMR2
;
1436 /* Reset the OC1M Bits */
1437 tmpccmr2
&= (uint32_t)~TIM_CCMR2_OC3M
;
1439 /* Configure The Forced output Mode */
1440 tmpccmr2
|= TIM_ForcedAction
;
1442 /* Write to TIMx CCMR2 register */
1443 TIMx
->CCMR2
= tmpccmr2
;
1447 * @brief Forces the TIMx output 4 waveform to active or inactive level.
1448 * @param TIMx: where x can be 1, 2, 3, 4 or 8 to select the TIM peripheral.
1449 * @param TIM_ForcedAction: specifies the forced Action to be set to the output waveform.
1450 * This parameter can be one of the following values:
1451 * @arg TIM_ForcedAction_Active: Force active level on OC4REF
1452 * @arg TIM_ForcedAction_InActive: Force inactive level on OC4REF.
1455 void TIM_ForcedOC4Config(TIM_TypeDef
* TIMx
, uint16_t TIM_ForcedAction
)
1457 uint32_t tmpccmr2
= 0;
1459 /* Check the parameters */
1460 assert_param(IS_TIM_LIST3_PERIPH(TIMx
));
1461 assert_param(IS_TIM_FORCED_ACTION(TIM_ForcedAction
));
1462 tmpccmr2
= TIMx
->CCMR2
;
1464 /* Reset the OC2M Bits */
1465 tmpccmr2
&= (uint32_t)~TIM_CCMR2_OC4M
;
1467 /* Configure The Forced output Mode */
1468 tmpccmr2
|= ((uint32_t)TIM_ForcedAction
<< 8);
1470 /* Write to TIMx CCMR2 register */
1471 TIMx
->CCMR2
= tmpccmr2
;
1475 * @brief Forces the TIMx output 5 waveform to active or inactive level.
1476 * @param TIMx: where x can be 1 or 8 to select the TIM peripheral.
1477 * @param TIM_ForcedAction: specifies the forced Action to be set to the output waveform.
1478 * This parameter can be one of the following values:
1479 * @arg TIM_ForcedAction_Active: Force active level on OC5REF
1480 * @arg TIM_ForcedAction_InActive: Force inactive level on OC5REF.
1483 void TIM_ForcedOC5Config(TIM_TypeDef
* TIMx
, uint16_t TIM_ForcedAction
)
1485 uint32_t tmpccmr3
= 0;
1487 /* Check the parameters */
1488 assert_param(IS_TIM_LIST4_PERIPH(TIMx
));
1489 assert_param(IS_TIM_FORCED_ACTION(TIM_ForcedAction
));
1490 tmpccmr3
= TIMx
->CCMR3
;
1492 /* Reset the OC5M Bits */
1493 tmpccmr3
&= (uint32_t)~TIM_CCMR3_OC5M
;
1495 /* Configure The Forced output Mode */
1496 tmpccmr3
|= (uint32_t)(TIM_ForcedAction
);
1498 /* Write to TIMx CCMR3 register */
1499 TIMx
->CCMR3
= tmpccmr3
;
1503 * @brief Forces the TIMx output 6 waveform to active or inactive level.
1504 * @param TIMx: where x can be 1 or 8 to select the TIM peripheral.
1505 * @param TIM_ForcedAction: specifies the forced Action to be set to the output waveform.
1506 * This parameter can be one of the following values:
1507 * @arg TIM_ForcedAction_Active: Force active level on OC5REF
1508 * @arg TIM_ForcedAction_InActive: Force inactive level on OC5REF.
1511 void TIM_ForcedOC6Config(TIM_TypeDef
* TIMx
, uint16_t TIM_ForcedAction
)
1513 uint32_t tmpccmr3
= 0;
1515 /* Check the parameters */
1516 assert_param(IS_TIM_LIST4_PERIPH(TIMx
));
1517 assert_param(IS_TIM_FORCED_ACTION(TIM_ForcedAction
));
1518 tmpccmr3
= TIMx
->CCMR3
;
1520 /* Reset the OC6M Bits */
1521 tmpccmr3
&= (uint32_t)~TIM_CCMR3_OC6M
;
1523 /* Configure The Forced output Mode */
1524 tmpccmr3
|= ((uint32_t)TIM_ForcedAction
<< 8);
1526 /* Write to TIMx CCMR3 register */
1527 TIMx
->CCMR3
= tmpccmr3
;
1531 * @brief Enables or disables the TIMx peripheral Preload register on CCR1.
1532 * @param TIMx: where x can be 1, 2, 3, 4, 8, 15, 16 or 17 to select the TIM peripheral.
1533 * @param TIM_OCPreload: new state of the TIMx peripheral Preload register
1534 * This parameter can be one of the following values:
1535 * @arg TIM_OCPreload_Enable
1536 * @arg TIM_OCPreload_Disable
1539 void TIM_OC1PreloadConfig(TIM_TypeDef
* TIMx
, uint16_t TIM_OCPreload
)
1541 uint32_t tmpccmr1
= 0;
1543 /* Check the parameters */
1544 assert_param(IS_TIM_LIST1_PERIPH(TIMx
));
1545 assert_param(IS_TIM_OCPRELOAD_STATE(TIM_OCPreload
));
1547 tmpccmr1
= TIMx
->CCMR1
;
1549 /* Reset the OC1PE Bit */
1550 tmpccmr1
&= (uint32_t)(~TIM_CCMR1_OC1PE
);
1552 /* Enable or Disable the Output Compare Preload feature */
1553 tmpccmr1
|= TIM_OCPreload
;
1555 /* Write to TIMx CCMR1 register */
1556 TIMx
->CCMR1
= tmpccmr1
;
1560 * @brief Enables or disables the TIMx peripheral Preload register on CCR2.
1561 * @param TIMx: where x can be 1, 2, 3, 4, 8 or 15 to select the TIM
1563 * @param TIM_OCPreload: new state of the TIMx peripheral Preload register
1564 * This parameter can be one of the following values:
1565 * @arg TIM_OCPreload_Enable
1566 * @arg TIM_OCPreload_Disable
1569 void TIM_OC2PreloadConfig(TIM_TypeDef
* TIMx
, uint16_t TIM_OCPreload
)
1571 uint32_t tmpccmr1
= 0;
1573 /* Check the parameters */
1574 assert_param(IS_TIM_LIST2_PERIPH(TIMx
));
1575 assert_param(IS_TIM_OCPRELOAD_STATE(TIM_OCPreload
));
1577 tmpccmr1
= TIMx
->CCMR1
;
1579 /* Reset the OC2PE Bit */
1580 tmpccmr1
&= (uint32_t)(~TIM_CCMR1_OC2PE
);
1582 /* Enable or Disable the Output Compare Preload feature */
1583 tmpccmr1
|= ((uint32_t)TIM_OCPreload
<< 8);
1585 /* Write to TIMx CCMR1 register */
1586 TIMx
->CCMR1
= tmpccmr1
;
1590 * @brief Enables or disables the TIMx peripheral Preload register on CCR3.
1591 * @param TIMx: where x can be 1, 2, 3, 4 or 8 to select the TIM peripheral.
1592 * @param TIM_OCPreload: new state of the TIMx peripheral Preload register
1593 * This parameter can be one of the following values:
1594 * @arg TIM_OCPreload_Enable
1595 * @arg TIM_OCPreload_Disable
1598 void TIM_OC3PreloadConfig(TIM_TypeDef
* TIMx
, uint16_t TIM_OCPreload
)
1600 uint32_t tmpccmr2
= 0;
1602 /* Check the parameters */
1603 assert_param(IS_TIM_LIST3_PERIPH(TIMx
));
1604 assert_param(IS_TIM_OCPRELOAD_STATE(TIM_OCPreload
));
1606 tmpccmr2
= TIMx
->CCMR2
;
1608 /* Reset the OC3PE Bit */
1609 tmpccmr2
&= (uint32_t)(~TIM_CCMR2_OC3PE
);
1611 /* Enable or Disable the Output Compare Preload feature */
1612 tmpccmr2
|= TIM_OCPreload
;
1614 /* Write to TIMx CCMR2 register */
1615 TIMx
->CCMR2
= tmpccmr2
;
1619 * @brief Enables or disables the TIMx peripheral Preload register on CCR4.
1620 * @param TIMx: where x can be 1, 2, 3, 4 or 8 to select the TIM peripheral.
1621 * @param TIM_OCPreload: new state of the TIMx peripheral Preload register
1622 * This parameter can be one of the following values:
1623 * @arg TIM_OCPreload_Enable
1624 * @arg TIM_OCPreload_Disable
1627 void TIM_OC4PreloadConfig(TIM_TypeDef
* TIMx
, uint16_t TIM_OCPreload
)
1629 uint32_t tmpccmr2
= 0;
1631 /* Check the parameters */
1632 assert_param(IS_TIM_LIST3_PERIPH(TIMx
));
1633 assert_param(IS_TIM_OCPRELOAD_STATE(TIM_OCPreload
));
1635 tmpccmr2
= TIMx
->CCMR2
;
1637 /* Reset the OC4PE Bit */
1638 tmpccmr2
&= (uint32_t)(~TIM_CCMR2_OC4PE
);
1640 /* Enable or Disable the Output Compare Preload feature */
1641 tmpccmr2
|= ((uint32_t)TIM_OCPreload
<< 8);
1643 /* Write to TIMx CCMR2 register */
1644 TIMx
->CCMR2
= tmpccmr2
;
1648 * @brief Enables or disables the TIMx peripheral Preload register on CCR5.
1649 * @param TIMx: where x can be 1 or 8 to select the TIM peripheral.
1650 * @param TIM_OCPreload: new state of the TIMx peripheral Preload register
1651 * This parameter can be one of the following values:
1652 * @arg TIM_OCPreload_Enable
1653 * @arg TIM_OCPreload_Disable
1656 void TIM_OC5PreloadConfig(TIM_TypeDef
* TIMx
, uint16_t TIM_OCPreload
)
1658 uint32_t tmpccmr3
= 0;
1660 /* Check the parameters */
1661 assert_param(IS_TIM_LIST4_PERIPH(TIMx
));
1662 assert_param(IS_TIM_OCPRELOAD_STATE(TIM_OCPreload
));
1664 tmpccmr3
= TIMx
->CCMR3
;
1666 /* Reset the OC5PE Bit */
1667 tmpccmr3
&= (uint32_t)(~TIM_CCMR3_OC5PE
);
1669 /* Enable or Disable the Output Compare Preload feature */
1670 tmpccmr3
|= (uint32_t)(TIM_OCPreload
);
1672 /* Write to TIMx CCMR3 register */
1673 TIMx
->CCMR3
= tmpccmr3
;
1677 * @brief Enables or disables the TIMx peripheral Preload register on CCR6.
1678 * @param TIMx: where x can be 1 or 8 to select the TIM peripheral.
1679 * @param TIM_OCPreload: new state of the TIMx peripheral Preload register
1680 * This parameter can be one of the following values:
1681 * @arg TIM_OCPreload_Enable
1682 * @arg TIM_OCPreload_Disable
1685 void TIM_OC6PreloadConfig(TIM_TypeDef
* TIMx
, uint16_t TIM_OCPreload
)
1687 uint32_t tmpccmr3
= 0;
1689 /* Check the parameters */
1690 assert_param(IS_TIM_LIST4_PERIPH(TIMx
));
1691 assert_param(IS_TIM_OCPRELOAD_STATE(TIM_OCPreload
));
1693 tmpccmr3
= TIMx
->CCMR3
;
1695 /* Reset the OC5PE Bit */
1696 tmpccmr3
&= (uint32_t)(~TIM_CCMR3_OC6PE
);
1698 /* Enable or Disable the Output Compare Preload feature */
1699 tmpccmr3
|= ((uint32_t)TIM_OCPreload
<< 8);
1701 /* Write to TIMx CCMR3 register */
1702 TIMx
->CCMR3
= tmpccmr3
;
1706 * @brief Configures the TIMx Output Compare 1 Fast feature.
1707 * @param TIMx: where x can be 1, 2, 3, 4, 8, 15, 16 or 17 to select the TIM peripheral.
1708 * @param TIM_OCFast: new state of the Output Compare Fast Enable Bit.
1709 * This parameter can be one of the following values:
1710 * @arg TIM_OCFast_Enable: TIM output compare fast enable
1711 * @arg TIM_OCFast_Disable: TIM output compare fast disable
1714 void TIM_OC1FastConfig(TIM_TypeDef
* TIMx
, uint16_t TIM_OCFast
)
1716 uint32_t tmpccmr1
= 0;
1718 /* Check the parameters */
1719 assert_param(IS_TIM_LIST1_PERIPH(TIMx
));
1720 assert_param(IS_TIM_OCFAST_STATE(TIM_OCFast
));
1722 /* Get the TIMx CCMR1 register value */
1723 tmpccmr1
= TIMx
->CCMR1
;
1725 /* Reset the OC1FE Bit */
1726 tmpccmr1
&= (uint32_t)~TIM_CCMR1_OC1FE
;
1728 /* Enable or Disable the Output Compare Fast Bit */
1729 tmpccmr1
|= TIM_OCFast
;
1731 /* Write to TIMx CCMR1 */
1732 TIMx
->CCMR1
= tmpccmr1
;
1736 * @brief Configures the TIMx Output Compare 2 Fast feature.
1737 * @param TIMx: where x can be 1, 2, 3, 4, 8 or 15 to select the TIM
1739 * @param TIM_OCFast: new state of the Output Compare Fast Enable Bit.
1740 * This parameter can be one of the following values:
1741 * @arg TIM_OCFast_Enable: TIM output compare fast enable
1742 * @arg TIM_OCFast_Disable: TIM output compare fast disable
1745 void TIM_OC2FastConfig(TIM_TypeDef
* TIMx
, uint16_t TIM_OCFast
)
1747 uint32_t tmpccmr1
= 0;
1749 /* Check the parameters */
1750 assert_param(IS_TIM_LIST2_PERIPH(TIMx
));
1751 assert_param(IS_TIM_OCFAST_STATE(TIM_OCFast
));
1753 /* Get the TIMx CCMR1 register value */
1754 tmpccmr1
= TIMx
->CCMR1
;
1756 /* Reset the OC2FE Bit */
1757 tmpccmr1
&= (uint32_t)(~TIM_CCMR1_OC2FE
);
1759 /* Enable or Disable the Output Compare Fast Bit */
1760 tmpccmr1
|= ((uint32_t)TIM_OCFast
<< 8);
1762 /* Write to TIMx CCMR1 */
1763 TIMx
->CCMR1
= tmpccmr1
;
1767 * @brief Configures the TIMx Output Compare 3 Fast feature.
1768 * @param TIMx: where x can be 1, 2, 3, 4 or 8 to select the TIM peripheral.
1769 * @param TIM_OCFast: new state of the Output Compare Fast Enable Bit.
1770 * This parameter can be one of the following values:
1771 * @arg TIM_OCFast_Enable: TIM output compare fast enable
1772 * @arg TIM_OCFast_Disable: TIM output compare fast disable
1775 void TIM_OC3FastConfig(TIM_TypeDef
* TIMx
, uint16_t TIM_OCFast
)
1777 uint32_t tmpccmr2
= 0;
1779 /* Check the parameters */
1780 assert_param(IS_TIM_LIST3_PERIPH(TIMx
));
1781 assert_param(IS_TIM_OCFAST_STATE(TIM_OCFast
));
1783 /* Get the TIMx CCMR2 register value */
1784 tmpccmr2
= TIMx
->CCMR2
;
1786 /* Reset the OC3FE Bit */
1787 tmpccmr2
&= (uint32_t)~TIM_CCMR2_OC3FE
;
1789 /* Enable or Disable the Output Compare Fast Bit */
1790 tmpccmr2
|= TIM_OCFast
;
1792 /* Write to TIMx CCMR2 */
1793 TIMx
->CCMR2
= tmpccmr2
;
1797 * @brief Configures the TIMx Output Compare 4 Fast feature.
1798 * @param TIMx: where x can be 1, 2, 3, 4 or 8 to select the TIM peripheral.
1799 * @param TIM_OCFast: new state of the Output Compare Fast Enable Bit.
1800 * This parameter can be one of the following values:
1801 * @arg TIM_OCFast_Enable: TIM output compare fast enable
1802 * @arg TIM_OCFast_Disable: TIM output compare fast disable
1805 void TIM_OC4FastConfig(TIM_TypeDef
* TIMx
, uint16_t TIM_OCFast
)
1807 uint32_t tmpccmr2
= 0;
1809 /* Check the parameters */
1810 assert_param(IS_TIM_LIST3_PERIPH(TIMx
));
1811 assert_param(IS_TIM_OCFAST_STATE(TIM_OCFast
));
1813 /* Get the TIMx CCMR2 register value */
1814 tmpccmr2
= TIMx
->CCMR2
;
1816 /* Reset the OC4FE Bit */
1817 tmpccmr2
&= (uint32_t)(~TIM_CCMR2_OC4FE
);
1819 /* Enable or Disable the Output Compare Fast Bit */
1820 tmpccmr2
|= ((uint32_t)TIM_OCFast
<< 8);
1822 /* Write to TIMx CCMR2 */
1823 TIMx
->CCMR2
= tmpccmr2
;
1827 * @brief Clears or safeguards the OCREF1 signal on an external event
1828 * @param TIMx: where x can be 1, 2, 3, 4, 8, 15, 16 or 17 to select the TIM peripheral.
1829 * @param TIM_OCClear: new state of the Output Compare Clear Enable Bit.
1830 * This parameter can be one of the following values:
1831 * @arg TIM_OCClear_Enable: TIM Output clear enable
1832 * @arg TIM_OCClear_Disable: TIM Output clear disable
1835 void TIM_ClearOC1Ref(TIM_TypeDef
* TIMx
, uint16_t TIM_OCClear
)
1837 uint32_t tmpccmr1
= 0;
1839 /* Check the parameters */
1840 assert_param(IS_TIM_LIST1_PERIPH(TIMx
));
1841 assert_param(IS_TIM_OCCLEAR_STATE(TIM_OCClear
));
1843 tmpccmr1
= TIMx
->CCMR1
;
1845 /* Reset the OC1CE Bit */
1846 tmpccmr1
&= (uint32_t)~TIM_CCMR1_OC1CE
;
1848 /* Enable or Disable the Output Compare Clear Bit */
1849 tmpccmr1
|= TIM_OCClear
;
1851 /* Write to TIMx CCMR1 register */
1852 TIMx
->CCMR1
= tmpccmr1
;
1856 * @brief Clears or safeguards the OCREF2 signal on an external event
1857 * @param TIMx: where x can be 1, 2, 3, 4, 8 or 15 to select the TIM
1859 * @param TIM_OCClear: new state of the Output Compare Clear Enable Bit.
1860 * This parameter can be one of the following values:
1861 * @arg TIM_OCClear_Enable: TIM Output clear enable
1862 * @arg TIM_OCClear_Disable: TIM Output clear disable
1865 void TIM_ClearOC2Ref(TIM_TypeDef
* TIMx
, uint16_t TIM_OCClear
)
1867 uint32_t tmpccmr1
= 0;
1869 /* Check the parameters */
1870 assert_param(IS_TIM_LIST2_PERIPH(TIMx
));
1871 assert_param(IS_TIM_OCCLEAR_STATE(TIM_OCClear
));
1873 tmpccmr1
= TIMx
->CCMR1
;
1875 /* Reset the OC2CE Bit */
1876 tmpccmr1
&= (uint32_t)~TIM_CCMR1_OC2CE
;
1878 /* Enable or Disable the Output Compare Clear Bit */
1879 tmpccmr1
|= ((uint32_t)TIM_OCClear
<< 8);
1881 /* Write to TIMx CCMR1 register */
1882 TIMx
->CCMR1
= tmpccmr1
;
1886 * @brief Clears or safeguards the OCREF3 signal on an external event
1887 * @param TIMx: where x can be 1, 2, 3, 4 or 8 to select the TIM peripheral.
1888 * @param TIM_OCClear: new state of the Output Compare Clear Enable Bit.
1889 * This parameter can be one of the following values:
1890 * @arg TIM_OCClear_Enable: TIM Output clear enable
1891 * @arg TIM_OCClear_Disable: TIM Output clear disable
1894 void TIM_ClearOC3Ref(TIM_TypeDef
* TIMx
, uint16_t TIM_OCClear
)
1896 uint32_t tmpccmr2
= 0;
1898 /* Check the parameters */
1899 assert_param(IS_TIM_LIST3_PERIPH(TIMx
));
1900 assert_param(IS_TIM_OCCLEAR_STATE(TIM_OCClear
));
1902 tmpccmr2
= TIMx
->CCMR2
;
1904 /* Reset the OC3CE Bit */
1905 tmpccmr2
&= (uint32_t)~TIM_CCMR2_OC3CE
;
1907 /* Enable or Disable the Output Compare Clear Bit */
1908 tmpccmr2
|= TIM_OCClear
;
1910 /* Write to TIMx CCMR2 register */
1911 TIMx
->CCMR2
= tmpccmr2
;
1915 * @brief Clears or safeguards the OCREF4 signal on an external event
1916 * @param TIMx: where x can be 1, 2, 3, 4 or 8 to select the TIM peripheral.
1917 * @param TIM_OCClear: new state of the Output Compare Clear Enable Bit.
1918 * This parameter can be one of the following values:
1919 * @arg TIM_OCClear_Enable: TIM Output clear enable
1920 * @arg TIM_OCClear_Disable: TIM Output clear disable
1923 void TIM_ClearOC4Ref(TIM_TypeDef
* TIMx
, uint16_t TIM_OCClear
)
1925 uint32_t tmpccmr2
= 0;
1927 /* Check the parameters */
1928 assert_param(IS_TIM_LIST3_PERIPH(TIMx
));
1929 assert_param(IS_TIM_OCCLEAR_STATE(TIM_OCClear
));
1931 tmpccmr2
= TIMx
->CCMR2
;
1933 /* Reset the OC4CE Bit */
1934 tmpccmr2
&= (uint32_t)~TIM_CCMR2_OC4CE
;
1936 /* Enable or Disable the Output Compare Clear Bit */
1937 tmpccmr2
|= ((uint32_t)TIM_OCClear
<< 8);
1939 /* Write to TIMx CCMR2 register */
1940 TIMx
->CCMR2
= tmpccmr2
;
1944 * @brief Clears or safeguards the OCREF5 signal on an external event
1945 * @param TIMx: where x can be 1 or 8 to select the TIM peripheral.
1946 * @param TIM_OCClear: new state of the Output Compare Clear Enable Bit.
1947 * This parameter can be one of the following values:
1948 * @arg TIM_OCClear_Enable: TIM Output clear enable
1949 * @arg TIM_OCClear_Disable: TIM Output clear disable
1952 void TIM_ClearOC5Ref(TIM_TypeDef
* TIMx
, uint16_t TIM_OCClear
)
1954 uint32_t tmpccmr3
= 0;
1956 /* Check the parameters */
1957 assert_param(IS_TIM_LIST4_PERIPH(TIMx
));
1958 assert_param(IS_TIM_OCCLEAR_STATE(TIM_OCClear
));
1960 tmpccmr3
= TIMx
->CCMR3
;
1962 /* Reset the OC5CE Bit */
1963 tmpccmr3
&= (uint32_t)~TIM_CCMR3_OC5CE
;
1965 /* Enable or Disable the Output Compare Clear Bit */
1966 tmpccmr3
|= (uint32_t)(TIM_OCClear
);
1968 /* Write to TIMx CCMR3 register */
1969 TIMx
->CCMR3
= tmpccmr3
;
1973 * @brief Clears or safeguards the OCREF6 signal on an external event
1974 * @param TIMx: where x can be 1 or 8 to select the TIM peripheral.
1975 * @param TIM_OCClear: new state of the Output Compare Clear Enable Bit.
1976 * This parameter can be one of the following values:
1977 * @arg TIM_OCClear_Enable: TIM Output clear enable
1978 * @arg TIM_OCClear_Disable: TIM Output clear disable
1981 void TIM_ClearOC6Ref(TIM_TypeDef
* TIMx
, uint16_t TIM_OCClear
)
1983 uint32_t tmpccmr3
= 0;
1985 /* Check the parameters */
1986 assert_param(IS_TIM_LIST4_PERIPH(TIMx
));
1987 assert_param(IS_TIM_OCCLEAR_STATE(TIM_OCClear
));
1989 tmpccmr3
= TIMx
->CCMR3
;
1991 /* Reset the OC5CE Bit */
1992 tmpccmr3
&= (uint32_t)~TIM_CCMR3_OC6CE
;
1994 /* Enable or Disable the Output Compare Clear Bit */
1995 tmpccmr3
|= ((uint32_t)TIM_OCClear
<< 8);
1997 /* Write to TIMx CCMR3 register */
1998 TIMx
->CCMR3
= tmpccmr3
;
2002 * @brief Selects the OCReference Clear source.
2003 * @param TIMx: where x can be 1, 2, 3, 4, 8, 15, 16 or 17 to select the TIM peripheral.
2004 * @param TIM_OCReferenceClear: specifies the OCReference Clear source.
2005 * This parameter can be one of the following values:
2006 * @arg TIM_OCReferenceClear_ETRF: The internal OCreference clear input is connected to ETRF.
2007 * @arg TIM_OCReferenceClear_OCREFCLR: The internal OCreference clear input is connected to OCREF_CLR input.
2010 void TIM_SelectOCREFClear(TIM_TypeDef
* TIMx
, uint16_t TIM_OCReferenceClear
)
2012 /* Check the parameters */
2013 assert_param(IS_TIM_LIST2_PERIPH(TIMx
));
2014 assert_param(TIM_OCREFERENCECECLEAR_SOURCE(TIM_OCReferenceClear
));
2016 /* Set the TIM_OCReferenceClear source */
2017 TIMx
->SMCR
&= (uint16_t)~((uint16_t)TIM_SMCR_OCCS
);
2018 TIMx
->SMCR
|= TIM_OCReferenceClear
;
2022 * @brief Configures the TIMx channel 1 polarity.
2023 * @param TIMx: where x can be 1, 2, 3, 4, 8, 15, 16 or 17 to select the TIM peripheral.
2024 * @param TIM_OCPolarity: specifies the OC1 Polarity
2025 * This parameter can be one of the following values:
2026 * @arg TIM_OCPolarity_High: Output Compare active high
2027 * @arg TIM_OCPolarity_Low: Output Compare active low
2030 void TIM_OC1PolarityConfig(TIM_TypeDef
* TIMx
, uint16_t TIM_OCPolarity
)
2032 uint32_t tmpccer
= 0;
2034 /* Check the parameters */
2035 assert_param(IS_TIM_LIST1_PERIPH(TIMx
));
2036 assert_param(IS_TIM_OC_POLARITY(TIM_OCPolarity
));
2038 tmpccer
= TIMx
->CCER
;
2040 /* Set or Reset the CC1P Bit */
2041 tmpccer
&= (uint32_t)(~TIM_CCER_CC1P
);
2042 tmpccer
|= TIM_OCPolarity
;
2044 /* Write to TIMx CCER register */
2045 TIMx
->CCER
= tmpccer
;
2049 * @brief Configures the TIMx Channel 1N polarity.
2050 * @param TIMx: where x can be 1, 8, 15, 16 or 17 to select the TIM peripheral.
2051 * @param TIM_OCNPolarity: specifies the OC1N Polarity
2052 * This parameter can be one of the following values:
2053 * @arg TIM_OCNPolarity_High: Output Compare active high
2054 * @arg TIM_OCNPolarity_Low: Output Compare active low
2057 void TIM_OC1NPolarityConfig(TIM_TypeDef
* TIMx
, uint16_t TIM_OCNPolarity
)
2059 uint32_t tmpccer
= 0;
2060 /* Check the parameters */
2061 assert_param(IS_TIM_LIST6_PERIPH(TIMx
));
2062 assert_param(IS_TIM_OCN_POLARITY(TIM_OCNPolarity
));
2064 tmpccer
= TIMx
->CCER
;
2066 /* Set or Reset the CC1NP Bit */
2067 tmpccer
&= (uint32_t)~TIM_CCER_CC1NP
;
2068 tmpccer
|= TIM_OCNPolarity
;
2070 /* Write to TIMx CCER register */
2071 TIMx
->CCER
= tmpccer
;
2075 * @brief Configures the TIMx channel 2 polarity.
2076 * @param TIMx: where x can be 1, 2, 3, 4 8 or 15 to select the TIM
2078 * @param TIM_OCPolarity: specifies the OC2 Polarity
2079 * This parameter can be one of the following values:
2080 * @arg TIM_OCPolarity_High: Output Compare active high
2081 * @arg TIM_OCPolarity_Low: Output Compare active low
2084 void TIM_OC2PolarityConfig(TIM_TypeDef
* TIMx
, uint16_t TIM_OCPolarity
)
2086 uint32_t tmpccer
= 0;
2088 /* Check the parameters */
2089 assert_param(IS_TIM_LIST2_PERIPH(TIMx
));
2090 assert_param(IS_TIM_OC_POLARITY(TIM_OCPolarity
));
2092 tmpccer
= TIMx
->CCER
;
2094 /* Set or Reset the CC2P Bit */
2095 tmpccer
&= (uint32_t)(~TIM_CCER_CC2P
);
2096 tmpccer
|= ((uint32_t)TIM_OCPolarity
<< 4);
2098 /* Write to TIMx CCER register */
2099 TIMx
->CCER
= tmpccer
;
2103 * @brief Configures the TIMx Channel 2N polarity.
2104 * @param TIMx: where x can be 1 or 8 to select the TIM peripheral.
2105 * @param TIM_OCNPolarity: specifies the OC2N Polarity
2106 * This parameter can be one of the following values:
2107 * @arg TIM_OCNPolarity_High: Output Compare active high
2108 * @arg TIM_OCNPolarity_Low: Output Compare active low
2111 void TIM_OC2NPolarityConfig(TIM_TypeDef
* TIMx
, uint16_t TIM_OCNPolarity
)
2113 uint32_t tmpccer
= 0;
2115 /* Check the parameters */
2116 assert_param(IS_TIM_LIST4_PERIPH(TIMx
));
2117 assert_param(IS_TIM_OCN_POLARITY(TIM_OCNPolarity
));
2119 tmpccer
= TIMx
->CCER
;
2121 /* Set or Reset the CC2NP Bit */
2122 tmpccer
&= (uint32_t)~TIM_CCER_CC2NP
;
2123 tmpccer
|= ((uint32_t)TIM_OCNPolarity
<< 4);
2125 /* Write to TIMx CCER register */
2126 TIMx
->CCER
= tmpccer
;
2130 * @brief Configures the TIMx channel 3 polarity.
2131 * @param TIMx: where x can be 1, 2, 3, 4 or 8 to select the TIM peripheral.
2132 * @param TIM_OCPolarity: specifies the OC3 Polarity
2133 * This parameter can be one of the following values:
2134 * @arg TIM_OCPolarity_High: Output Compare active high
2135 * @arg TIM_OCPolarity_Low: Output Compare active low
2138 void TIM_OC3PolarityConfig(TIM_TypeDef
* TIMx
, uint16_t TIM_OCPolarity
)
2140 uint32_t tmpccer
= 0;
2142 /* Check the parameters */
2143 assert_param(IS_TIM_LIST3_PERIPH(TIMx
));
2144 assert_param(IS_TIM_OC_POLARITY(TIM_OCPolarity
));
2146 tmpccer
= TIMx
->CCER
;
2148 /* Set or Reset the CC3P Bit */
2149 tmpccer
&= (uint32_t)~TIM_CCER_CC3P
;
2150 tmpccer
|= ((uint32_t)TIM_OCPolarity
<< 8);
2152 /* Write to TIMx CCER register */
2153 TIMx
->CCER
= tmpccer
;
2157 * @brief Configures the TIMx Channel 3N polarity.
2158 * @param TIMx: where x can be 1 or 8 to select the TIM peripheral.
2159 * @param TIM_OCNPolarity: specifies the OC3N Polarity
2160 * This parameter can be one of the following values:
2161 * @arg TIM_OCNPolarity_High: Output Compare active high
2162 * @arg TIM_OCNPolarity_Low: Output Compare active low
2165 void TIM_OC3NPolarityConfig(TIM_TypeDef
* TIMx
, uint16_t TIM_OCNPolarity
)
2167 uint32_t tmpccer
= 0;
2169 /* Check the parameters */
2170 assert_param(IS_TIM_LIST4_PERIPH(TIMx
));
2171 assert_param(IS_TIM_OCN_POLARITY(TIM_OCNPolarity
));
2173 tmpccer
= TIMx
->CCER
;
2175 /* Set or Reset the CC3NP Bit */
2176 tmpccer
&= (uint32_t)~TIM_CCER_CC3NP
;
2177 tmpccer
|= ((uint32_t)TIM_OCNPolarity
<< 8);
2179 /* Write to TIMx CCER register */
2180 TIMx
->CCER
= tmpccer
;
2184 * @brief Configures the TIMx channel 4 polarity.
2185 * @param TIMx: where x can be 1, 2, 3, 4 or 8 to select the TIM peripheral.
2186 * @param TIM_OCPolarity: specifies the OC4 Polarity
2187 * This parameter can be one of the following values:
2188 * @arg TIM_OCPolarity_High: Output Compare active high
2189 * @arg TIM_OCPolarity_Low: Output Compare active low
2192 void TIM_OC4PolarityConfig(TIM_TypeDef
* TIMx
, uint16_t TIM_OCPolarity
)
2194 uint32_t tmpccer
= 0;
2196 /* Check the parameters */
2197 assert_param(IS_TIM_LIST3_PERIPH(TIMx
));
2198 assert_param(IS_TIM_OC_POLARITY(TIM_OCPolarity
));
2200 tmpccer
= TIMx
->CCER
;
2202 /* Set or Reset the CC4P Bit */
2203 tmpccer
&= (uint32_t)~TIM_CCER_CC4P
;
2204 tmpccer
|= ((uint32_t)TIM_OCPolarity
<< 12);
2206 /* Write to TIMx CCER register */
2207 TIMx
->CCER
= tmpccer
;
2211 * @brief Configures the TIMx channel 5 polarity.
2212 * @param TIMx: where x can be 1 or 8 to select the TIM peripheral.
2213 * @param TIM_OCPolarity: specifies the OC5 Polarity
2214 * This parameter can be one of the following values:
2215 * @arg TIM_OCPolarity_High: Output Compare active high
2216 * @arg TIM_OCPolarity_Low: Output Compare active low
2219 void TIM_OC5PolarityConfig(TIM_TypeDef
* TIMx
, uint16_t TIM_OCPolarity
)
2221 uint32_t tmpccer
= 0;
2223 /* Check the parameters */
2224 assert_param(IS_TIM_LIST4_PERIPH(TIMx
));
2225 assert_param(IS_TIM_OC_POLARITY(TIM_OCPolarity
));
2227 tmpccer
= TIMx
->CCER
;
2229 /* Set or Reset the CC5P Bit */
2230 tmpccer
&= (uint32_t)~TIM_CCER_CC5P
;
2231 tmpccer
|= ((uint32_t)TIM_OCPolarity
<< 16);
2233 /* Write to TIMx CCER register */
2234 TIMx
->CCER
= tmpccer
;
2238 * @brief Configures the TIMx channel 6 polarity.
2239 * @param TIMx: where x can be 1 or 8 to select the TIM peripheral.
2240 * @param TIM_OCPolarity: specifies the OC6 Polarity
2241 * This parameter can be one of the following values:
2242 * @arg TIM_OCPolarity_High: Output Compare active high
2243 * @arg TIM_OCPolarity_Low: Output Compare active low
2246 void TIM_OC6PolarityConfig(TIM_TypeDef
* TIMx
, uint16_t TIM_OCPolarity
)
2248 uint32_t tmpccer
= 0;
2250 /* Check the parameters */
2251 assert_param(IS_TIM_LIST4_PERIPH(TIMx
));
2252 assert_param(IS_TIM_OC_POLARITY(TIM_OCPolarity
));
2254 tmpccer
= TIMx
->CCER
;
2256 /* Set or Reset the CC6P Bit */
2257 tmpccer
&= (uint32_t)~TIM_CCER_CC6P
;
2258 tmpccer
|= ((uint32_t)TIM_OCPolarity
<< 20);
2260 /* Write to TIMx CCER register */
2261 TIMx
->CCER
= tmpccer
;
2265 * @brief Enables or disables the TIM Capture Compare Channel x.
2266 * @param TIMx: where x can be 1, 2, 3, 4, 8, 15, 16 or 17 to select the TIM peripheral.
2267 * @param TIM_Channel: specifies the TIM Channel
2268 * This parameter can be one of the following values:
2269 * @arg TIM_Channel_1: TIM Channel 1
2270 * @arg TIM_Channel_2: TIM Channel 2
2271 * @arg TIM_Channel_3: TIM Channel 3
2272 * @arg TIM_Channel_4: TIM Channel 4
2273 * @arg TIM_Channel_5: TIM Channel 5
2274 * @arg TIM_Channel_6: TIM Channel 6
2275 * @param TIM_CCx: specifies the TIM Channel CCxE bit new state.
2276 * This parameter can be: TIM_CCx_Enable or TIM_CCx_Disable.
2279 void TIM_CCxCmd(TIM_TypeDef
* TIMx
, uint16_t TIM_Channel
, uint16_t TIM_CCx
)
2283 /* Check the parameters */
2284 assert_param(IS_TIM_LIST1_PERIPH(TIMx
));
2285 assert_param(IS_TIM_CHANNEL(TIM_Channel
));
2286 assert_param(IS_TIM_CCX(TIM_CCx
));
2288 tmp
= (uint32_t)CCER_CCE_SET
<< (uint32_t)TIM_Channel
;
2290 /* Reset the CCxE Bit */
2291 TIMx
->CCER
&= (uint32_t)(~tmp
);
2293 /* Set or reset the CCxE Bit */
2294 TIMx
->CCER
|= ((uint32_t)TIM_CCx
<< (uint32_t)TIM_Channel
);
2298 * @brief Enables or disables the TIM Capture Compare Channel xN.
2299 * @param TIMx: where x can be 1, 8, 15, 16 or 17 to select the TIM peripheral.
2300 * @param TIM_Channel: specifies the TIM Channel
2301 * This parameter can be one of the following values:
2302 * @arg TIM_Channel_1: TIM Channel 1
2303 * @arg TIM_Channel_2: TIM Channel 2
2304 * @arg TIM_Channel_3: TIM Channel 3
2305 * @param TIM_CCxN: specifies the TIM Channel CCxNE bit new state.
2306 * This parameter can be: TIM_CCxN_Enable or TIM_CCxN_Disable.
2309 void TIM_CCxNCmd(TIM_TypeDef
* TIMx
, uint16_t TIM_Channel
, uint16_t TIM_CCxN
)
2313 /* Check the parameters */
2314 assert_param(IS_TIM_LIST6_PERIPH(TIMx
));
2315 assert_param(IS_TIM_COMPLEMENTARY_CHANNEL(TIM_Channel
));
2316 assert_param(IS_TIM_CCXN(TIM_CCxN
));
2318 tmp
= (uint32_t)CCER_CCNE_SET
<< (uint32_t)TIM_Channel
;
2320 /* Reset the CCxNE Bit */
2321 TIMx
->CCER
&= (uint32_t) ~tmp
;
2323 /* Set or reset the CCxNE Bit */
2324 TIMx
->CCER
|= ((uint32_t)TIM_CCxN
<< (uint32_t)TIM_Channel
);
2330 /** @defgroup TIM_Group3 Input Capture management functions
2331 * @brief Input Capture management functions
2334 ===============================================================================
2335 ##### Input Capture management functions #####
2336 ===============================================================================
2338 *** TIM Driver: how to use it in Input Capture Mode ***
2339 =======================================================
2341 To use the Timer in Input Capture mode, the following steps are mandatory:
2343 (#) Enable TIM clock using RCC_APBxPeriphClockCmd(RCC_APBxPeriph_TIMx, ENABLE) function
2345 (#) Configure the TIM pins by configuring the corresponding GPIO pins
2347 (#) Configure the Time base unit as described in the first part of this driver,
2348 if needed, else the Timer will run with the default configuration:
2349 (++) Autoreload value = 0xFFFF
2350 (++) Prescaler value = 0x0000
2351 (++) Counter mode = Up counting
2352 (++) Clock Division = TIM_CKD_DIV1
2354 (#) Fill the TIM_ICInitStruct with the desired parameters including:
2355 (++) TIM Channel: TIM_Channel
2356 (++) TIM Input Capture polarity: TIM_ICPolarity
2357 (++) TIM Input Capture selection: TIM_ICSelection
2358 (++) TIM Input Capture Prescaler: TIM_ICPrescaler
2359 (++) TIM Input CApture filter value: TIM_ICFilter
2361 (#) Call TIM_ICInit(TIMx, &TIM_ICInitStruct) to configure the desired channel with the
2362 corresponding configuration and to measure only frequency or duty cycle of the input signal,
2364 Call TIM_PWMIConfig(TIMx, &TIM_ICInitStruct) to configure the desired channels with the
2365 corresponding configuration and to measure the frequency and the duty cycle of the input signal
2367 (#) Enable the NVIC or the DMA to read the measured frequency.
2369 (#) Enable the corresponding interrupt (or DMA request) to read the Captured value,
2370 using the function TIM_ITConfig(TIMx, TIM_IT_CCx) (or TIM_DMA_Cmd(TIMx, TIM_DMA_CCx))
2372 (#) Call the TIM_Cmd(ENABLE) function to enable the TIM counter.
2374 (#) Use TIM_GetCapturex(TIMx); to read the captured value.
2376 (@) All other functions can be used separately to modify, if needed,
2377 a specific feature of the Timer.
2384 * @brief Initializes the TIM peripheral according to the specified parameters
2385 * in the TIM_ICInitStruct.
2386 * @param TIMx: where x can be 1, 2, 3, 4, 8, 15, 16 or 17 to select the TIM peripheral.
2387 * @param TIM_ICInitStruct: pointer to a TIM_ICInitTypeDef structure that contains
2388 * the configuration information for the specified TIM peripheral.
2391 void TIM_ICInit(TIM_TypeDef
* TIMx
, TIM_ICInitTypeDef
* TIM_ICInitStruct
)
2393 /* Check the parameters */
2394 assert_param(IS_TIM_LIST1_PERIPH(TIMx
));
2395 assert_param(IS_TIM_IC_POLARITY(TIM_ICInitStruct
->TIM_ICPolarity
));
2396 assert_param(IS_TIM_IC_SELECTION(TIM_ICInitStruct
->TIM_ICSelection
));
2397 assert_param(IS_TIM_IC_PRESCALER(TIM_ICInitStruct
->TIM_ICPrescaler
));
2398 assert_param(IS_TIM_IC_FILTER(TIM_ICInitStruct
->TIM_ICFilter
));
2400 if (TIM_ICInitStruct
->TIM_Channel
== TIM_Channel_1
)
2402 /* TI1 Configuration */
2403 TI1_Config(TIMx
, TIM_ICInitStruct
->TIM_ICPolarity
,
2404 TIM_ICInitStruct
->TIM_ICSelection
,
2405 TIM_ICInitStruct
->TIM_ICFilter
);
2406 /* Set the Input Capture Prescaler value */
2407 TIM_SetIC1Prescaler(TIMx
, TIM_ICInitStruct
->TIM_ICPrescaler
);
2409 else if (TIM_ICInitStruct
->TIM_Channel
== TIM_Channel_2
)
2411 /* TI2 Configuration */
2412 TI2_Config(TIMx
, TIM_ICInitStruct
->TIM_ICPolarity
,
2413 TIM_ICInitStruct
->TIM_ICSelection
,
2414 TIM_ICInitStruct
->TIM_ICFilter
);
2415 /* Set the Input Capture Prescaler value */
2416 TIM_SetIC2Prescaler(TIMx
, TIM_ICInitStruct
->TIM_ICPrescaler
);
2418 else if (TIM_ICInitStruct
->TIM_Channel
== TIM_Channel_3
)
2420 /* TI3 Configuration */
2421 TI3_Config(TIMx
, TIM_ICInitStruct
->TIM_ICPolarity
,
2422 TIM_ICInitStruct
->TIM_ICSelection
,
2423 TIM_ICInitStruct
->TIM_ICFilter
);
2424 /* Set the Input Capture Prescaler value */
2425 TIM_SetIC3Prescaler(TIMx
, TIM_ICInitStruct
->TIM_ICPrescaler
);
2429 /* TI4 Configuration */
2430 TI4_Config(TIMx
, TIM_ICInitStruct
->TIM_ICPolarity
,
2431 TIM_ICInitStruct
->TIM_ICSelection
,
2432 TIM_ICInitStruct
->TIM_ICFilter
);
2433 /* Set the Input Capture Prescaler value */
2434 TIM_SetIC4Prescaler(TIMx
, TIM_ICInitStruct
->TIM_ICPrescaler
);
2439 * @brief Fills each TIM_ICInitStruct member with its default value.
2440 * @param TIM_ICInitStruct: pointer to a TIM_ICInitTypeDef structure which will
2444 void TIM_ICStructInit(TIM_ICInitTypeDef
* TIM_ICInitStruct
)
2446 /* Set the default configuration */
2447 TIM_ICInitStruct
->TIM_Channel
= TIM_Channel_1
;
2448 TIM_ICInitStruct
->TIM_ICPolarity
= TIM_ICPolarity_Rising
;
2449 TIM_ICInitStruct
->TIM_ICSelection
= TIM_ICSelection_DirectTI
;
2450 TIM_ICInitStruct
->TIM_ICPrescaler
= TIM_ICPSC_DIV1
;
2451 TIM_ICInitStruct
->TIM_ICFilter
= 0x00;
2455 * @brief Configures the TIM peripheral according to the specified parameters
2456 * in the TIM_ICInitStruct to measure an external PWM signal.
2457 * @param TIMx: where x can be 1, 2, 3, 4, 8 or 15 to select the TIM
2459 * @param TIM_ICInitStruct: pointer to a TIM_ICInitTypeDef structure that contains
2460 * the configuration information for the specified TIM peripheral.
2463 void TIM_PWMIConfig(TIM_TypeDef
* TIMx
, TIM_ICInitTypeDef
* TIM_ICInitStruct
)
2465 uint16_t icoppositepolarity
= TIM_ICPolarity_Rising
;
2466 uint16_t icoppositeselection
= TIM_ICSelection_DirectTI
;
2468 /* Check the parameters */
2469 assert_param(IS_TIM_LIST2_PERIPH(TIMx
));
2471 /* Select the Opposite Input Polarity */
2472 if (TIM_ICInitStruct
->TIM_ICPolarity
== TIM_ICPolarity_Rising
)
2474 icoppositepolarity
= TIM_ICPolarity_Falling
;
2478 icoppositepolarity
= TIM_ICPolarity_Rising
;
2480 /* Select the Opposite Input */
2481 if (TIM_ICInitStruct
->TIM_ICSelection
== TIM_ICSelection_DirectTI
)
2483 icoppositeselection
= TIM_ICSelection_IndirectTI
;
2487 icoppositeselection
= TIM_ICSelection_DirectTI
;
2489 if (TIM_ICInitStruct
->TIM_Channel
== TIM_Channel_1
)
2491 /* TI1 Configuration */
2492 TI1_Config(TIMx
, TIM_ICInitStruct
->TIM_ICPolarity
, TIM_ICInitStruct
->TIM_ICSelection
,
2493 TIM_ICInitStruct
->TIM_ICFilter
);
2494 /* Set the Input Capture Prescaler value */
2495 TIM_SetIC1Prescaler(TIMx
, TIM_ICInitStruct
->TIM_ICPrescaler
);
2496 /* TI2 Configuration */
2497 TI2_Config(TIMx
, icoppositepolarity
, icoppositeselection
, TIM_ICInitStruct
->TIM_ICFilter
);
2498 /* Set the Input Capture Prescaler value */
2499 TIM_SetIC2Prescaler(TIMx
, TIM_ICInitStruct
->TIM_ICPrescaler
);
2503 /* TI2 Configuration */
2504 TI2_Config(TIMx
, TIM_ICInitStruct
->TIM_ICPolarity
, TIM_ICInitStruct
->TIM_ICSelection
,
2505 TIM_ICInitStruct
->TIM_ICFilter
);
2506 /* Set the Input Capture Prescaler value */
2507 TIM_SetIC2Prescaler(TIMx
, TIM_ICInitStruct
->TIM_ICPrescaler
);
2508 /* TI1 Configuration */
2509 TI1_Config(TIMx
, icoppositepolarity
, icoppositeselection
, TIM_ICInitStruct
->TIM_ICFilter
);
2510 /* Set the Input Capture Prescaler value */
2511 TIM_SetIC1Prescaler(TIMx
, TIM_ICInitStruct
->TIM_ICPrescaler
);
2516 * @brief Gets the TIMx Input Capture 1 value.
2517 * @param TIMx: where x can be 1, 2, 3, 4, 8, 15, 16 or 17 to select the TIM peripheral.
2518 * @retval Capture Compare 1 Register value.
2520 uint32_t TIM_GetCapture1(TIM_TypeDef
* TIMx
)
2522 /* Check the parameters */
2523 assert_param(IS_TIM_LIST1_PERIPH(TIMx
));
2525 /* Get the Capture 1 Register value */
2530 * @brief Gets the TIMx Input Capture 2 value.
2531 * @param TIMx: where x can be 1, 2, 3, 4, 8 or 15 to select the TIM
2533 * @retval Capture Compare 2 Register value.
2535 uint32_t TIM_GetCapture2(TIM_TypeDef
* TIMx
)
2537 /* Check the parameters */
2538 assert_param(IS_TIM_LIST2_PERIPH(TIMx
));
2540 /* Get the Capture 2 Register value */
2545 * @brief Gets the TIMx Input Capture 3 value.
2546 * @param TIMx: where x can be 1, 2, 3, 4 or 8 to select the TIM peripheral.
2547 * @retval Capture Compare 3 Register value.
2549 uint32_t TIM_GetCapture3(TIM_TypeDef
* TIMx
)
2551 /* Check the parameters */
2552 assert_param(IS_TIM_LIST3_PERIPH(TIMx
));
2554 /* Get the Capture 3 Register value */
2559 * @brief Gets the TIMx Input Capture 4 value.
2560 * @param TIMx: where x can be 1, 2, 3, 4 or 8 to select the TIM peripheral.
2561 * @retval Capture Compare 4 Register value.
2563 uint32_t TIM_GetCapture4(TIM_TypeDef
* TIMx
)
2565 /* Check the parameters */
2566 assert_param(IS_TIM_LIST3_PERIPH(TIMx
));
2568 /* Get the Capture 4 Register value */
2573 * @brief Sets the TIMx Input Capture 1 prescaler.
2574 * @param TIMx: where x can be 1, 2, 3, 4, 8, 15, 16 or 17 to select the TIM peripheral.
2575 * @param TIM_ICPSC: specifies the Input Capture1 prescaler new value.
2576 * This parameter can be one of the following values:
2577 * @arg TIM_ICPSC_DIV1: no prescaler
2578 * @arg TIM_ICPSC_DIV2: capture is done once every 2 events
2579 * @arg TIM_ICPSC_DIV4: capture is done once every 4 events
2580 * @arg TIM_ICPSC_DIV8: capture is done once every 8 events
2583 void TIM_SetIC1Prescaler(TIM_TypeDef
* TIMx
, uint16_t TIM_ICPSC
)
2585 /* Check the parameters */
2586 assert_param(IS_TIM_LIST1_PERIPH(TIMx
));
2587 assert_param(IS_TIM_IC_PRESCALER(TIM_ICPSC
));
2589 /* Reset the IC1PSC Bits */
2590 TIMx
->CCMR1
&= (uint32_t)~TIM_CCMR1_IC1PSC
;
2592 /* Set the IC1PSC value */
2593 TIMx
->CCMR1
|= TIM_ICPSC
;
2597 * @brief Sets the TIMx Input Capture 2 prescaler.
2598 * @param TIMx: where x can be 1, 2, 3, 4, 8 or 15 to select the TIM
2600 * @param TIM_ICPSC: specifies the Input Capture2 prescaler new value.
2601 * This parameter can be one of the following values:
2602 * @arg TIM_ICPSC_DIV1: no prescaler
2603 * @arg TIM_ICPSC_DIV2: capture is done once every 2 events
2604 * @arg TIM_ICPSC_DIV4: capture is done once every 4 events
2605 * @arg TIM_ICPSC_DIV8: capture is done once every 8 events
2608 void TIM_SetIC2Prescaler(TIM_TypeDef
* TIMx
, uint16_t TIM_ICPSC
)
2610 /* Check the parameters */
2611 assert_param(IS_TIM_LIST2_PERIPH(TIMx
));
2612 assert_param(IS_TIM_IC_PRESCALER(TIM_ICPSC
));
2614 /* Reset the IC2PSC Bits */
2615 TIMx
->CCMR1
&= (uint32_t)~TIM_CCMR1_IC2PSC
;
2617 /* Set the IC2PSC value */
2618 TIMx
->CCMR1
|= (uint32_t)((uint32_t)TIM_ICPSC
<< 8);
2622 * @brief Sets the TIMx Input Capture 3 prescaler.
2623 * @param TIMx: where x can be 1, 2, 3, 4 or 8 to select the TIM peripheral.
2624 * @param TIM_ICPSC: specifies the Input Capture3 prescaler new value.
2625 * This parameter can be one of the following values:
2626 * @arg TIM_ICPSC_DIV1: no prescaler
2627 * @arg TIM_ICPSC_DIV2: capture is done once every 2 events
2628 * @arg TIM_ICPSC_DIV4: capture is done once every 4 events
2629 * @arg TIM_ICPSC_DIV8: capture is done once every 8 events
2632 void TIM_SetIC3Prescaler(TIM_TypeDef
* TIMx
, uint16_t TIM_ICPSC
)
2634 /* Check the parameters */
2635 assert_param(IS_TIM_LIST3_PERIPH(TIMx
));
2636 assert_param(IS_TIM_IC_PRESCALER(TIM_ICPSC
));
2638 /* Reset the IC3PSC Bits */
2639 TIMx
->CCMR2
&= (uint16_t)~TIM_CCMR2_IC3PSC
;
2641 /* Set the IC3PSC value */
2642 TIMx
->CCMR2
|= TIM_ICPSC
;
2646 * @brief Sets the TIMx Input Capture 4 prescaler.
2647 * @param TIMx: where x can be 1, 2, 3, 4 or 8 to select the TIM peripheral.
2648 * @param TIM_ICPSC: specifies the Input Capture4 prescaler new value.
2649 * This parameter can be one of the following values:
2650 * @arg TIM_ICPSC_DIV1: no prescaler
2651 * @arg TIM_ICPSC_DIV2: capture is done once every 2 events
2652 * @arg TIM_ICPSC_DIV4: capture is done once every 4 events
2653 * @arg TIM_ICPSC_DIV8: capture is done once every 8 events
2656 void TIM_SetIC4Prescaler(TIM_TypeDef
* TIMx
, uint16_t TIM_ICPSC
)
2658 /* Check the parameters */
2659 assert_param(IS_TIM_LIST3_PERIPH(TIMx
));
2660 assert_param(IS_TIM_IC_PRESCALER(TIM_ICPSC
));
2662 /* Reset the IC4PSC Bits */
2663 TIMx
->CCMR2
&= (uint16_t)~TIM_CCMR2_IC4PSC
;
2665 /* Set the IC4PSC value */
2666 TIMx
->CCMR2
|= (uint16_t)(TIM_ICPSC
<< 8);
2672 /** @defgroup TIM_Group4 Advanced-control timers (TIM1 and TIM8) specific features
2673 * @brief Advanced-control timers (TIM1 and TIM8) specific features
2676 ===============================================================================
2677 ##### Advanced-control timers (TIM1 and TIM8) specific features #####
2678 ===============================================================================
2680 *** TIM Driver: how to use the Break feature ***
2681 ================================================
2683 After configuring the Timer channel(s) in the appropriate Output Compare mode:
2685 (#) Fill the TIM_BDTRInitStruct with the desired parameters for the Timer
2686 Break Polarity, dead time, Lock level, the OSSI/OSSR State and the
2687 AOE(automatic output enable).
2689 (#) Call TIM_BDTRConfig(TIMx, &TIM_BDTRInitStruct) to configure the Timer
2691 (#) Enable the Main Output using TIM_CtrlPWMOutputs(TIM1, ENABLE)
2693 (#) Once the break even occurs, the Timer's output signals are put in reset
2694 state or in a known state (according to the configuration made in
2695 TIM_BDTRConfig() function).
2702 * @brief Configures the Break feature, dead time, Lock level, OSSI/OSSR State
2703 * and the AOE(automatic output enable).
2704 * @param TIMx: where x can be 1, 8, 15, 16 or 17 to select the TIM
2705 * @param TIM_BDTRInitStruct: pointer to a TIM_BDTRInitTypeDef structure that
2706 * contains the BDTR Register configuration information for the TIM peripheral.
2709 void TIM_BDTRConfig(TIM_TypeDef
* TIMx
, TIM_BDTRInitTypeDef
*TIM_BDTRInitStruct
)
2711 /* Check the parameters */
2712 assert_param(IS_TIM_LIST6_PERIPH(TIMx
));
2713 assert_param(IS_TIM_OSSR_STATE(TIM_BDTRInitStruct
->TIM_OSSRState
));
2714 assert_param(IS_TIM_OSSI_STATE(TIM_BDTRInitStruct
->TIM_OSSIState
));
2715 assert_param(IS_TIM_LOCK_LEVEL(TIM_BDTRInitStruct
->TIM_LOCKLevel
));
2716 assert_param(IS_TIM_BREAK_STATE(TIM_BDTRInitStruct
->TIM_Break
));
2717 assert_param(IS_TIM_BREAK_POLARITY(TIM_BDTRInitStruct
->TIM_BreakPolarity
));
2718 assert_param(IS_TIM_AUTOMATIC_OUTPUT_STATE(TIM_BDTRInitStruct
->TIM_AutomaticOutput
));
2720 /* Set the Lock level, the Break enable Bit and the Polarity, the OSSR State,
2721 the OSSI State, the dead time value and the Automatic Output Enable Bit */
2722 TIMx
->BDTR
= (uint32_t)TIM_BDTRInitStruct
->TIM_OSSRState
| TIM_BDTRInitStruct
->TIM_OSSIState
|
2723 TIM_BDTRInitStruct
->TIM_LOCKLevel
| TIM_BDTRInitStruct
->TIM_DeadTime
|
2724 TIM_BDTRInitStruct
->TIM_Break
| TIM_BDTRInitStruct
->TIM_BreakPolarity
|
2725 TIM_BDTRInitStruct
->TIM_AutomaticOutput
;
2729 * @brief Configures the Break1 feature.
2730 * @param TIMx: where x can be 1 or 8 to select the TIM
2731 * @param TIM_Break1Polarity: specifies the Break1 polarity.
2732 * This parameter can be one of the following values:
2733 * @arg TIM_Break1Polarity_Low: Break1 input is active low
2734 * @arg TIM_Break1Polarity_High: Break1 input is active high
2735 * @param TIM_Break1Filter: specifies the Break1 filter value.
2736 * This parameter must be a value between 0x00 and 0x0F
2739 void TIM_Break1Config(TIM_TypeDef
* TIMx
, uint32_t TIM_Break1Polarity
, uint8_t TIM_Break1Filter
)
2740 { /* Check the parameters */
2741 assert_param(IS_TIM_LIST4_PERIPH(TIMx
));
2742 assert_param(IS_TIM_BREAK1_FILTER(TIM_Break1Filter
));
2744 /* Reset the BKP and BKF Bits */
2745 TIMx
->BDTR
&= (uint32_t)~ (TIM_BDTR_BKP
| TIM_BDTR_BKF
);
2746 /* Configure the Break1 polarity and filter */
2747 TIMx
->BDTR
|= TIM_Break1Polarity
|((uint32_t)TIM_Break1Filter
<< 16);
2751 * @brief Configures the Break2 feature.
2752 * @param TIMx: where x can be 1 or 8 to select the TIM
2753 * @param TIM_Break2Polarity: specifies the Break2 polarity.
2754 * This parameter can be one of the following values:
2755 * @arg TIM_Break2Polarity_Low: Break2 input is active low
2756 * @arg TIM_Break2Polarity_High: Break2 input is active high
2757 * @param TIM_Break2Filter: specifies the Break2 filter value.
2758 * This parameter must be a value between 0x00 and 0x0F
2761 void TIM_Break2Config(TIM_TypeDef
* TIMx
, uint32_t TIM_Break2Polarity
, uint8_t TIM_Break2Filter
)
2763 /* Check the parameters */
2764 assert_param(IS_TIM_LIST4_PERIPH(TIMx
));
2765 assert_param(IS_TIM_BREAK2_FILTER(TIM_Break2Filter
));
2767 /* Reset the BKP and BKF Bits */
2768 TIMx
->BDTR
&= (uint32_t)~ (TIM_BDTR_BK2P
| TIM_BDTR_BK2F
);
2770 /* Configure the Break1 polarity and filter */
2771 TIMx
->BDTR
|= TIM_Break2Polarity
|((uint32_t)TIM_Break2Filter
<< 20);
2775 * @brief Enables or disables the TIM Break1 input.
2776 * @param TIMx: where x can be 1, 8, 1, 16 or 17 to select the TIMx peripheral.
2777 * @param NewState: new state of the TIM Break1 input.
2778 * This parameter can be: ENABLE or DISABLE.
2781 void TIM_Break1Cmd(TIM_TypeDef
* TIMx
, FunctionalState NewState
)
2783 /* Check the parameters */
2784 assert_param(IS_TIM_LIST6_PERIPH(TIMx
));
2785 assert_param(IS_FUNCTIONAL_STATE(NewState
));
2787 if (NewState
!= DISABLE
)
2789 /* Enable the Break1 */
2790 TIMx
->BDTR
|= TIM_BDTR_BKE
;
2794 /* Disable the Break1 */
2795 TIMx
->BDTR
&= (uint32_t)~TIM_BDTR_BKE
;
2800 * @brief Enables or disables the TIM Break2 input.
2801 * @param TIMx: where x can be 1 or 8 to select the TIMx peripheral.
2802 * @param NewState: new state of the TIM Break2 input.
2803 * This parameter can be: ENABLE or DISABLE.
2806 void TIM_Break2Cmd(TIM_TypeDef
* TIMx
, FunctionalState NewState
)
2808 /* Check the parameters */
2809 assert_param(IS_TIM_LIST4_PERIPH(TIMx
));
2810 assert_param(IS_FUNCTIONAL_STATE(NewState
));
2812 if (NewState
!= DISABLE
)
2814 /* Enable the Break1 */
2815 TIMx
->BDTR
|= TIM_BDTR_BK2E
;
2819 /* Disable the Break1 */
2820 TIMx
->BDTR
&= (uint32_t)~TIM_BDTR_BK2E
;
2825 * @brief Fills each TIM_BDTRInitStruct member with its default value.
2826 * @param TIM_BDTRInitStruct: pointer to a TIM_BDTRInitTypeDef structure which
2827 * will be initialized.
2830 void TIM_BDTRStructInit(TIM_BDTRInitTypeDef
* TIM_BDTRInitStruct
)
2832 /* Set the default configuration */
2833 TIM_BDTRInitStruct
->TIM_OSSRState
= TIM_OSSRState_Disable
;
2834 TIM_BDTRInitStruct
->TIM_OSSIState
= TIM_OSSIState_Disable
;
2835 TIM_BDTRInitStruct
->TIM_LOCKLevel
= TIM_LOCKLevel_OFF
;
2836 TIM_BDTRInitStruct
->TIM_DeadTime
= 0x00;
2837 TIM_BDTRInitStruct
->TIM_Break
= TIM_Break_Disable
;
2838 TIM_BDTRInitStruct
->TIM_BreakPolarity
= TIM_BreakPolarity_Low
;
2839 TIM_BDTRInitStruct
->TIM_AutomaticOutput
= TIM_AutomaticOutput_Disable
;
2843 * @brief Enables or disables the TIM peripheral Main Outputs.
2844 * @param TIMx: where x can be 1, 8, 15, 16 or 17 to select the TIMx peripheral.
2845 * @param NewState: new state of the TIM peripheral Main Outputs.
2846 * This parameter can be: ENABLE or DISABLE.
2849 void TIM_CtrlPWMOutputs(TIM_TypeDef
* TIMx
, FunctionalState NewState
)
2851 /* Check the parameters */
2852 assert_param(IS_TIM_LIST6_PERIPH(TIMx
));
2853 assert_param(IS_FUNCTIONAL_STATE(NewState
));
2855 if (NewState
!= DISABLE
)
2857 /* Enable the TIM Main Output */
2858 TIMx
->BDTR
|= TIM_BDTR_MOE
;
2862 /* Disable the TIM Main Output */
2863 TIMx
->BDTR
&= (uint16_t)~TIM_BDTR_MOE
;
2868 * @brief Selects the TIM peripheral Commutation event.
2869 * @param TIMx: where x can be 1, 8, 15, 16 or 17 to select the TIMx peripheral
2870 * @param NewState: new state of the Commutation event.
2871 * This parameter can be: ENABLE or DISABLE.
2874 void TIM_SelectCOM(TIM_TypeDef
* TIMx
, FunctionalState NewState
)
2876 /* Check the parameters */
2877 assert_param(IS_TIM_LIST6_PERIPH(TIMx
));
2878 assert_param(IS_FUNCTIONAL_STATE(NewState
));
2880 if (NewState
!= DISABLE
)
2882 /* Set the COM Bit */
2883 TIMx
->CR2
|= TIM_CR2_CCUS
;
2887 /* Reset the COM Bit */
2888 TIMx
->CR2
&= (uint16_t)~TIM_CR2_CCUS
;
2893 * @brief Sets or Resets the TIM peripheral Capture Compare Preload Control bit.
2894 * @param TIMx: where x can be 1 or 8 to select the TIMx peripheral
2895 * @param NewState: new state of the Capture Compare Preload Control bit
2896 * This parameter can be: ENABLE or DISABLE.
2899 void TIM_CCPreloadControl(TIM_TypeDef
* TIMx
, FunctionalState NewState
)
2901 /* Check the parameters */
2902 assert_param(IS_TIM_LIST6_PERIPH(TIMx
));
2903 assert_param(IS_FUNCTIONAL_STATE(NewState
));
2904 if (NewState
!= DISABLE
)
2906 /* Set the CCPC Bit */
2907 TIMx
->CR2
|= TIM_CR2_CCPC
;
2911 /* Reset the CCPC Bit */
2912 TIMx
->CR2
&= (uint16_t)~TIM_CR2_CCPC
;
2919 /** @defgroup TIM_Group5 Interrupts DMA and flags management functions
2920 * @brief Interrupts, DMA and flags management functions
2923 ===============================================================================
2924 ##### Interrupts, DMA and flags management functions #####
2925 ===============================================================================
2932 * @brief Enables or disables the specified TIM interrupts.
2933 * @param TIMx: where x can be 1, 2, 3, 4, 6, 7, 8, 15, 16 or 17 to select the TIMx peripheral.
2934 * @param TIM_IT: specifies the TIM interrupts sources to be enabled or disabled.
2935 * This parameter can be any combination of the following values:
2936 * @arg TIM_IT_Update: TIM update Interrupt source
2937 * @arg TIM_IT_CC1: TIM Capture Compare 1 Interrupt source
2938 * @arg TIM_IT_CC2: TIM Capture Compare 2 Interrupt source
2939 * @arg TIM_IT_CC3: TIM Capture Compare 3 Interrupt source
2940 * @arg TIM_IT_CC4: TIM Capture Compare 4 Interrupt source
2941 * @arg TIM_IT_COM: TIM Commutation Interrupt source
2942 * @arg TIM_IT_Trigger: TIM Trigger Interrupt source
2943 * @arg TIM_IT_Break: TIM Break Interrupt source
2945 * @note For TIM6 and TIM7 only the parameter TIM_IT_Update can be used
2946 * @note For TIM9 and TIM12 only one of the following parameters can be used: TIM_IT_Update,
2947 * TIM_IT_CC1, TIM_IT_CC2 or TIM_IT_Trigger.
2948 * @note For TIM10, TIM11, TIM13 and TIM14 only one of the following parameters can
2949 * be used: TIM_IT_Update or TIM_IT_CC1
2950 * @note TIM_IT_COM and TIM_IT_Break can be used only with TIM1 and TIM8
2952 * @param NewState: new state of the TIM interrupts.
2953 * This parameter can be: ENABLE or DISABLE.
2956 void TIM_ITConfig(TIM_TypeDef
* TIMx
, uint16_t TIM_IT
, FunctionalState NewState
)
2958 /* Check the parameters */
2959 assert_param(IS_TIM_ALL_PERIPH(TIMx
));
2960 assert_param(IS_TIM_IT(TIM_IT
));
2961 assert_param(IS_FUNCTIONAL_STATE(NewState
));
2963 if (NewState
!= DISABLE
)
2965 /* Enable the Interrupt sources */
2966 TIMx
->DIER
|= TIM_IT
;
2970 /* Disable the Interrupt sources */
2971 TIMx
->DIER
&= (uint16_t)~TIM_IT
;
2976 * @brief Configures the TIMx event to be generate by software.
2977 * @param TIMx: where x can be 1, 2, 3, 4, 6, 7, 8, 15, 16 or 17 to select the TIM peripheral.
2978 * @param TIM_EventSource: specifies the event source.
2979 * This parameter can be one or more of the following values:
2980 * @arg TIM_EventSource_Update: Timer update Event source
2981 * @arg TIM_EventSource_CC1: Timer Capture Compare 1 Event source
2982 * @arg TIM_EventSource_CC2: Timer Capture Compare 2 Event source
2983 * @arg TIM_EventSource_CC3: Timer Capture Compare 3 Event source
2984 * @arg TIM_EventSource_CC4: Timer Capture Compare 4 Event source
2985 * @arg TIM_EventSource_COM: Timer COM event source
2986 * @arg TIM_EventSource_Trigger: Timer Trigger Event source
2987 * @arg TIM_EventSource_Break: Timer Break event source
2989 * @note TIM6 and TIM7 can only generate an update event.
2990 * @note TIM_EventSource_COM and TIM_EventSource_Break are used only with TIM1 and TIM8.
2994 void TIM_GenerateEvent(TIM_TypeDef
* TIMx
, uint16_t TIM_EventSource
)
2996 /* Check the parameters */
2997 assert_param(IS_TIM_ALL_PERIPH(TIMx
));
2998 assert_param(IS_TIM_EVENT_SOURCE(TIM_EventSource
));
3000 /* Set the event sources */
3001 TIMx
->EGR
= TIM_EventSource
;
3005 * @brief Checks whether the specified TIM flag is set or not.
3006 * @param TIMx: where x can be 1, 2, 3, 4, 6, 7, 8, 15, 16 or 17 to select the TIM peripheral.
3007 * @param TIM_FLAG: specifies the flag to check.
3008 * This parameter can be one of the following values:
3009 * @arg TIM_FLAG_Update: TIM update Flag
3010 * @arg TIM_FLAG_CC1: TIM Capture Compare 1 Flag
3011 * @arg TIM_FLAG_CC2: TIM Capture Compare 2 Flag
3012 * @arg TIM_FLAG_CC3: TIM Capture Compare 3 Flag
3013 * @arg TIM_FLAG_CC4: TIM Capture Compare 4 Flag
3014 * @arg TIM_FLAG_CC5: TIM Capture Compare 5 Flag
3015 * @arg TIM_FLAG_CC6: TIM Capture Compare 6 Flag
3016 * @arg TIM_FLAG_COM: TIM Commutation Flag
3017 * @arg TIM_FLAG_Trigger: TIM Trigger Flag
3018 * @arg TIM_FLAG_Break: TIM Break Flag
3019 * @arg TIM_FLAG_CC1OF: TIM Capture Compare 1 over capture Flag
3020 * @arg TIM_FLAG_CC2OF: TIM Capture Compare 2 over capture Flag
3021 * @arg TIM_FLAG_CC3OF: TIM Capture Compare 3 over capture Flag
3022 * @arg TIM_FLAG_CC4OF: TIM Capture Compare 4 over capture Flag
3024 * @note TIM6 and TIM7 can have only one update flag.
3025 * @note TIM_FLAG_COM and TIM_FLAG_Break are used only with TIM1 and TIM8.
3027 * @retval The new state of TIM_FLAG (SET or RESET).
3029 FlagStatus
TIM_GetFlagStatus(TIM_TypeDef
* TIMx
, uint32_t TIM_FLAG
)
3031 ITStatus bitstatus
= RESET
;
3032 /* Check the parameters */
3033 assert_param(IS_TIM_ALL_PERIPH(TIMx
));
3034 assert_param(IS_TIM_GET_FLAG(TIM_FLAG
));
3037 if ((TIMx
->SR
& TIM_FLAG
) != RESET
)
3049 * @brief Clears the TIMx's pending flags.
3050 * @param TIMx: where x can be 1, 2, 3, 4, 6, 7, 8, 15, 16 or 17 to select the TIM peripheral.
3051 * @param TIM_FLAG: specifies the flag bit to clear.
3052 * This parameter can be any combination of the following values:
3053 * @arg TIM_FLAG_Update: TIM update Flag
3054 * @arg TIM_FLAG_CC1: TIM Capture Compare 1 Flag
3055 * @arg TIM_FLAG_CC2: TIM Capture Compare 2 Flag
3056 * @arg TIM_FLAG_CC3: TIM Capture Compare 3 Flag
3057 * @arg TIM_FLAG_CC4: TIM Capture Compare 4 Flag
3058 * @arg TIM_FLAG_CC5: TIM Capture Compare 5 Flag
3059 * @arg TIM_FLAG_CC6: TIM Capture Compare 6 Flag
3060 * @arg TIM_FLAG_COM: TIM Commutation Flag
3061 * @arg TIM_FLAG_Trigger: TIM Trigger Flag
3062 * @arg TIM_FLAG_Break: TIM Break Flag
3063 * @arg TIM_FLAG_CC1OF: TIM Capture Compare 1 over capture Flag
3064 * @arg TIM_FLAG_CC2OF: TIM Capture Compare 2 over capture Flag
3065 * @arg TIM_FLAG_CC3OF: TIM Capture Compare 3 over capture Flag
3066 * @arg TIM_FLAG_CC4OF: TIM Capture Compare 4 over capture Flag
3068 * @note TIM6 and TIM7 can have only one update flag.
3069 * @note TIM_FLAG_COM and TIM_FLAG_Break are used only with TIM1 and TIM8.
3073 void TIM_ClearFlag(TIM_TypeDef
* TIMx
, uint16_t TIM_FLAG
)
3075 /* Check the parameters */
3076 assert_param(IS_TIM_ALL_PERIPH(TIMx
));
3078 /* Clear the flags */
3079 TIMx
->SR
= (uint16_t)~TIM_FLAG
;
3083 * @brief Checks whether the TIM interrupt has occurred or not.
3084 * @param TIMx: where x can be 1, 2, 3, 4, 6, 7, 8, 15, 16 or 17 to select the TIM peripheral.
3085 * @param TIM_IT: specifies the TIM interrupt source to check.
3086 * This parameter can be one of the following values:
3087 * @arg TIM_IT_Update: TIM update Interrupt source
3088 * @arg TIM_IT_CC1: TIM Capture Compare 1 Interrupt source
3089 * @arg TIM_IT_CC2: TIM Capture Compare 2 Interrupt source
3090 * @arg TIM_IT_CC3: TIM Capture Compare 3 Interrupt source
3091 * @arg TIM_IT_CC4: TIM Capture Compare 4 Interrupt source
3092 * @arg TIM_IT_COM: TIM Commutation Interrupt source
3093 * @arg TIM_IT_Trigger: TIM Trigger Interrupt source
3094 * @arg TIM_IT_Break: TIM Break Interrupt source
3096 * @note TIM6 and TIM7 can generate only an update interrupt.
3097 * @note TIM_IT_COM and TIM_IT_Break are used only with TIM1 and TIM8.
3099 * @retval The new state of the TIM_IT(SET or RESET).
3101 ITStatus
TIM_GetITStatus(TIM_TypeDef
* TIMx
, uint16_t TIM_IT
)
3103 ITStatus bitstatus
= RESET
;
3104 uint16_t itstatus
= 0x0, itenable
= 0x0;
3105 /* Check the parameters */
3106 assert_param(IS_TIM_ALL_PERIPH(TIMx
));
3107 assert_param(IS_TIM_GET_IT(TIM_IT
));
3109 itstatus
= TIMx
->SR
& TIM_IT
;
3111 itenable
= TIMx
->DIER
& TIM_IT
;
3112 if ((itstatus
!= (uint16_t)RESET
) && (itenable
!= (uint16_t)RESET
))
3124 * @brief Clears the TIMx's interrupt pending bits.
3125 * @param TIMx: where x can be 1, 2, 3, 4, 6, 7, 8, 15, 16 or 17 to select the TIM peripheral.
3126 * @param TIM_IT: specifies the pending bit to clear.
3127 * This parameter can be any combination of the following values:
3128 * @arg TIM_IT_Update: TIM1 update Interrupt source
3129 * @arg TIM_IT_CC1: TIM Capture Compare 1 Interrupt source
3130 * @arg TIM_IT_CC2: TIM Capture Compare 2 Interrupt source
3131 * @arg TIM_IT_CC3: TIM Capture Compare 3 Interrupt source
3132 * @arg TIM_IT_CC4: TIM Capture Compare 4 Interrupt source
3133 * @arg TIM_IT_COM: TIM Commutation Interrupt source
3134 * @arg TIM_IT_Trigger: TIM Trigger Interrupt source
3135 * @arg TIM_IT_Break: TIM Break Interrupt source
3137 * @note TIM6 and TIM7 can generate only an update interrupt.
3138 * @note TIM_IT_COM and TIM_IT_Break are used only with TIM1 and TIM8.
3142 void TIM_ClearITPendingBit(TIM_TypeDef
* TIMx
, uint16_t TIM_IT
)
3144 /* Check the parameters */
3145 assert_param(IS_TIM_ALL_PERIPH(TIMx
));
3147 /* Clear the IT pending Bit */
3148 TIMx
->SR
= (uint16_t)~TIM_IT
;
3152 * @brief Configures the TIMx's DMA interface.
3153 * @param TIMx: where x can be 1, 2, 3, 4 or 8 to select the TIM peripheral.
3154 * @param TIM_DMABase: DMA Base address.
3155 * This parameter can be one of the following values:
3156 * @arg TIM_DMABase_CR1
3157 * @arg TIM_DMABase_CR2
3158 * @arg TIM_DMABase_SMCR
3159 * @arg TIM_DMABase_DIER
3160 * @arg TIM1_DMABase_SR
3161 * @arg TIM_DMABase_EGR
3162 * @arg TIM_DMABase_CCMR1
3163 * @arg TIM_DMABase_CCMR2
3164 * @arg TIM_DMABase_CCER
3165 * @arg TIM_DMABase_CNT
3166 * @arg TIM_DMABase_PSC
3167 * @arg TIM_DMABase_ARR
3168 * @arg TIM_DMABase_RCR
3169 * @arg TIM_DMABase_CCR1
3170 * @arg TIM_DMABase_CCR2
3171 * @arg TIM_DMABase_CCR3
3172 * @arg TIM_DMABase_CCR4
3173 * @arg TIM_DMABase_BDTR
3174 * @arg TIM_DMABase_DCR
3175 * @param TIM_DMABurstLength: DMA Burst length. This parameter can be one value
3176 * between: TIM_DMABurstLength_1Transfer and TIM_DMABurstLength_18Transfers.
3179 void TIM_DMAConfig(TIM_TypeDef
* TIMx
, uint16_t TIM_DMABase
, uint16_t TIM_DMABurstLength
)
3181 /* Check the parameters */
3182 assert_param(IS_TIM_LIST1_PERIPH(TIMx
));
3183 assert_param(IS_TIM_DMA_BASE(TIM_DMABase
));
3184 assert_param(IS_TIM_DMA_LENGTH(TIM_DMABurstLength
));
3186 /* Set the DMA Base and the DMA Burst Length */
3187 TIMx
->DCR
= TIM_DMABase
| TIM_DMABurstLength
;
3191 * @brief Enables or disables the TIMx's DMA Requests.
3192 * @param TIMx: where x can be 1, 2, 3, 4, 6, 7, 8, 15, 16 or 17 to select the TIM peripheral.
3193 * @param TIM_DMASource: specifies the DMA Request sources.
3194 * This parameter can be any combination of the following values:
3195 * @arg TIM_DMA_Update: TIM update Interrupt source
3196 * @arg TIM_DMA_CC1: TIM Capture Compare 1 DMA source
3197 * @arg TIM_DMA_CC2: TIM Capture Compare 2 DMA source
3198 * @arg TIM_DMA_CC3: TIM Capture Compare 3 DMA source
3199 * @arg TIM_DMA_CC4: TIM Capture Compare 4 DMA source
3200 * @arg TIM_DMA_COM: TIM Commutation DMA source
3201 * @arg TIM_DMA_Trigger: TIM Trigger DMA source
3202 * @param NewState: new state of the DMA Request sources.
3203 * This parameter can be: ENABLE or DISABLE.
3206 void TIM_DMACmd(TIM_TypeDef
* TIMx
, uint16_t TIM_DMASource
, FunctionalState NewState
)
3208 /* Check the parameters */
3209 assert_param(IS_TIM_ALL_PERIPH(TIMx
));
3210 assert_param(IS_TIM_DMA_SOURCE(TIM_DMASource
));
3211 assert_param(IS_FUNCTIONAL_STATE(NewState
));
3213 if (NewState
!= DISABLE
)
3215 /* Enable the DMA sources */
3216 TIMx
->DIER
|= TIM_DMASource
;
3220 /* Disable the DMA sources */
3221 TIMx
->DIER
&= (uint16_t)~TIM_DMASource
;
3226 * @brief Selects the TIMx peripheral Capture Compare DMA source.
3227 * @param TIMx: where x can be 1, 2, 3, 4, 8, 15, 16 or 17 to select the TIM peripheral.
3228 * @param NewState: new state of the Capture Compare DMA source
3229 * This parameter can be: ENABLE or DISABLE.
3232 void TIM_SelectCCDMA(TIM_TypeDef
* TIMx
, FunctionalState NewState
)
3234 /* Check the parameters */
3235 assert_param(IS_TIM_LIST1_PERIPH(TIMx
));
3236 assert_param(IS_FUNCTIONAL_STATE(NewState
));
3238 if (NewState
!= DISABLE
)
3240 /* Set the CCDS Bit */
3241 TIMx
->CR2
|= TIM_CR2_CCDS
;
3245 /* Reset the CCDS Bit */
3246 TIMx
->CR2
&= (uint16_t)~TIM_CR2_CCDS
;
3253 /** @defgroup TIM_Group6 Clocks management functions
3254 * @brief Clocks management functions
3257 ===============================================================================
3258 ##### Clocks management functions #####
3259 ===============================================================================
3266 * @brief Configures the TIMx internal Clock
3267 * @param TIMx: where x can be 1, 2, 3, 4, 8 or 15 to select the TIM
3271 void TIM_InternalClockConfig(TIM_TypeDef
* TIMx
)
3273 /* Check the parameters */
3274 assert_param(IS_TIM_LIST2_PERIPH(TIMx
));
3276 /* Disable slave mode to clock the prescaler directly with the internal clock */
3277 TIMx
->SMCR
&= (uint16_t)~TIM_SMCR_SMS
;
3281 * @brief Configures the TIMx Internal Trigger as External Clock
3282 * @param TIMx: where x can be 1, 2, 3, 4, 8 or 15 to select the TIM
3284 * @param TIM_InputTriggerSource: Trigger source.
3285 * This parameter can be one of the following values:
3286 * @arg TIM_TS_ITR0: Internal Trigger 0
3287 * @arg TIM_TS_ITR1: Internal Trigger 1
3288 * @arg TIM_TS_ITR2: Internal Trigger 2
3289 * @arg TIM_TS_ITR3: Internal Trigger 3
3292 void TIM_ITRxExternalClockConfig(TIM_TypeDef
* TIMx
, uint16_t TIM_InputTriggerSource
)
3294 /* Check the parameters */
3295 assert_param(IS_TIM_LIST2_PERIPH(TIMx
));
3296 assert_param(IS_TIM_INTERNAL_TRIGGER_SELECTION(TIM_InputTriggerSource
));
3298 /* Select the Internal Trigger */
3299 TIM_SelectInputTrigger(TIMx
, TIM_InputTriggerSource
);
3301 /* Select the External clock mode1 */
3302 TIMx
->SMCR
|= TIM_SlaveMode_External1
;
3306 * @brief Configures the TIMx Trigger as External Clock
3307 * @param TIMx: where x can be 1, 2, 3, 4, 8 or 15
3308 * to select the TIM peripheral.
3309 * @param TIM_TIxExternalCLKSource: Trigger source.
3310 * This parameter can be one of the following values:
3311 * @arg TIM_TIxExternalCLK1Source_TI1ED: TI1 Edge Detector
3312 * @arg TIM_TIxExternalCLK1Source_TI1: Filtered Timer Input 1
3313 * @arg TIM_TIxExternalCLK1Source_TI2: Filtered Timer Input 2
3314 * @param TIM_ICPolarity: specifies the TIx Polarity.
3315 * This parameter can be one of the following values:
3316 * @arg TIM_ICPolarity_Rising
3317 * @arg TIM_ICPolarity_Falling
3318 * @param ICFilter: specifies the filter value.
3319 * This parameter must be a value between 0x0 and 0xF.
3322 void TIM_TIxExternalClockConfig(TIM_TypeDef
* TIMx
, uint16_t TIM_TIxExternalCLKSource
,
3323 uint16_t TIM_ICPolarity
, uint16_t ICFilter
)
3325 /* Check the parameters */
3326 assert_param(IS_TIM_LIST2_PERIPH(TIMx
));
3327 assert_param(IS_TIM_IC_POLARITY(TIM_ICPolarity
));
3328 assert_param(IS_TIM_IC_FILTER(ICFilter
));
3330 /* Configure the Timer Input Clock Source */
3331 if (TIM_TIxExternalCLKSource
== TIM_TIxExternalCLK1Source_TI2
)
3333 TI2_Config(TIMx
, TIM_ICPolarity
, TIM_ICSelection_DirectTI
, ICFilter
);
3337 TI1_Config(TIMx
, TIM_ICPolarity
, TIM_ICSelection_DirectTI
, ICFilter
);
3339 /* Select the Trigger source */
3340 TIM_SelectInputTrigger(TIMx
, TIM_TIxExternalCLKSource
);
3341 /* Select the External clock mode1 */
3342 TIMx
->SMCR
|= TIM_SlaveMode_External1
;
3346 * @brief Configures the External clock Mode1
3347 * @param TIMx: where x can be 1, 2, 3, 4 or 8 to select the TIM peripheral.
3348 * @param TIM_ExtTRGPrescaler: The external Trigger Prescaler.
3349 * This parameter can be one of the following values:
3350 * @arg TIM_ExtTRGPSC_OFF: ETRP Prescaler OFF.
3351 * @arg TIM_ExtTRGPSC_DIV2: ETRP frequency divided by 2.
3352 * @arg TIM_ExtTRGPSC_DIV4: ETRP frequency divided by 4.
3353 * @arg TIM_ExtTRGPSC_DIV8: ETRP frequency divided by 8.
3354 * @param TIM_ExtTRGPolarity: The external Trigger Polarity.
3355 * This parameter can be one of the following values:
3356 * @arg TIM_ExtTRGPolarity_Inverted: active low or falling edge active.
3357 * @arg TIM_ExtTRGPolarity_NonInverted: active high or rising edge active.
3358 * @param ExtTRGFilter: External Trigger Filter.
3359 * This parameter must be a value between 0x00 and 0x0F
3362 void TIM_ETRClockMode1Config(TIM_TypeDef
* TIMx
, uint16_t TIM_ExtTRGPrescaler
,
3363 uint16_t TIM_ExtTRGPolarity
, uint16_t ExtTRGFilter
)
3365 uint16_t tmpsmcr
= 0;
3367 /* Check the parameters */
3368 assert_param(IS_TIM_LIST3_PERIPH(TIMx
));
3369 assert_param(IS_TIM_EXT_PRESCALER(TIM_ExtTRGPrescaler
));
3370 assert_param(IS_TIM_EXT_POLARITY(TIM_ExtTRGPolarity
));
3371 assert_param(IS_TIM_EXT_FILTER(ExtTRGFilter
));
3372 /* Configure the ETR Clock source */
3373 TIM_ETRConfig(TIMx
, TIM_ExtTRGPrescaler
, TIM_ExtTRGPolarity
, ExtTRGFilter
);
3375 /* Get the TIMx SMCR register value */
3376 tmpsmcr
= TIMx
->SMCR
;
3378 /* Reset the SMS Bits */
3379 tmpsmcr
&= (uint16_t)~TIM_SMCR_SMS
;
3381 /* Select the External clock mode1 */
3382 tmpsmcr
|= TIM_SlaveMode_External1
;
3384 /* Select the Trigger selection : ETRF */
3385 tmpsmcr
&= (uint16_t)~TIM_SMCR_TS
;
3386 tmpsmcr
|= TIM_TS_ETRF
;
3388 /* Write to TIMx SMCR */
3389 TIMx
->SMCR
= tmpsmcr
;
3393 * @brief Configures the External clock Mode2
3394 * @param TIMx: where x can be 1, 2, 3, 4 or 8 to select the TIM peripheral.
3395 * @param TIM_ExtTRGPrescaler: The external Trigger Prescaler.
3396 * This parameter can be one of the following values:
3397 * @arg TIM_ExtTRGPSC_OFF: ETRP Prescaler OFF.
3398 * @arg TIM_ExtTRGPSC_DIV2: ETRP frequency divided by 2.
3399 * @arg TIM_ExtTRGPSC_DIV4: ETRP frequency divided by 4.
3400 * @arg TIM_ExtTRGPSC_DIV8: ETRP frequency divided by 8.
3401 * @param TIM_ExtTRGPolarity: The external Trigger Polarity.
3402 * This parameter can be one of the following values:
3403 * @arg TIM_ExtTRGPolarity_Inverted: active low or falling edge active.
3404 * @arg TIM_ExtTRGPolarity_NonInverted: active high or rising edge active.
3405 * @param ExtTRGFilter: External Trigger Filter.
3406 * This parameter must be a value between 0x00 and 0x0F
3409 void TIM_ETRClockMode2Config(TIM_TypeDef
* TIMx
, uint16_t TIM_ExtTRGPrescaler
,
3410 uint16_t TIM_ExtTRGPolarity
, uint16_t ExtTRGFilter
)
3412 /* Check the parameters */
3413 assert_param(IS_TIM_LIST3_PERIPH(TIMx
));
3414 assert_param(IS_TIM_EXT_PRESCALER(TIM_ExtTRGPrescaler
));
3415 assert_param(IS_TIM_EXT_POLARITY(TIM_ExtTRGPolarity
));
3416 assert_param(IS_TIM_EXT_FILTER(ExtTRGFilter
));
3418 /* Configure the ETR Clock source */
3419 TIM_ETRConfig(TIMx
, TIM_ExtTRGPrescaler
, TIM_ExtTRGPolarity
, ExtTRGFilter
);
3421 /* Enable the External clock mode2 */
3422 TIMx
->SMCR
|= TIM_SMCR_ECE
;
3428 /** @defgroup TIM_Group7 Synchronization management functions
3429 * @brief Synchronization management functions
3432 ===============================================================================
3433 ##### Synchronization management functions #####
3434 ===============================================================================
3436 *** TIM Driver: how to use it in synchronization Mode ***
3437 =========================================================
3438 [..] Case of two/several Timers
3440 (#) Configure the Master Timers using the following functions:
3441 (++) void TIM_SelectOutputTrigger(TIM_TypeDef* TIMx, uint16_t TIM_TRGOSource);
3442 (++) void TIM_SelectMasterSlaveMode(TIM_TypeDef* TIMx, uint16_t TIM_MasterSlaveMode);
3443 (#) Configure the Slave Timers using the following functions:
3444 (++) void TIM_SelectInputTrigger(TIM_TypeDef* TIMx, uint16_t TIM_InputTriggerSource);
3445 (++) void TIM_SelectSlaveMode(TIM_TypeDef* TIMx, uint16_t TIM_SlaveMode);
3447 [..] Case of Timers and external trigger(ETR pin)
3449 (#) Configure the External trigger using this function:
3450 (++) void TIM_ETRConfig(TIM_TypeDef* TIMx, uint16_t TIM_ExtTRGPrescaler, uint16_t TIM_ExtTRGPolarity,
3451 uint16_t ExtTRGFilter);
3452 (#) Configure the Slave Timers using the following functions:
3453 (++) void TIM_SelectInputTrigger(TIM_TypeDef* TIMx, uint16_t TIM_InputTriggerSource);
3454 (++) void TIM_SelectSlaveMode(TIM_TypeDef* TIMx, uint16_t TIM_SlaveMode);
3461 * @brief Selects the Input Trigger source
3462 * @param TIMx: where x can be 1, 2, 3, 4, 8 or 15
3463 * to select the TIM peripheral.
3464 * @param TIM_InputTriggerSource: The Input Trigger source.
3465 * This parameter can be one of the following values:
3466 * @arg TIM_TS_ITR0: Internal Trigger 0
3467 * @arg TIM_TS_ITR1: Internal Trigger 1
3468 * @arg TIM_TS_ITR2: Internal Trigger 2
3469 * @arg TIM_TS_ITR3: Internal Trigger 3
3470 * @arg TIM_TS_TI1F_ED: TI1 Edge Detector
3471 * @arg TIM_TS_TI1FP1: Filtered Timer Input 1
3472 * @arg TIM_TS_TI2FP2: Filtered Timer Input 2
3473 * @arg TIM_TS_ETRF: External Trigger input
3476 void TIM_SelectInputTrigger(TIM_TypeDef
* TIMx
, uint16_t TIM_InputTriggerSource
)
3478 uint16_t tmpsmcr
= 0;
3480 /* Check the parameters */
3481 assert_param(IS_TIM_LIST2_PERIPH(TIMx
));
3482 assert_param(IS_TIM_TRIGGER_SELECTION(TIM_InputTriggerSource
));
3484 /* Get the TIMx SMCR register value */
3485 tmpsmcr
= TIMx
->SMCR
;
3487 /* Reset the TS Bits */
3488 tmpsmcr
&= (uint16_t)~TIM_SMCR_TS
;
3490 /* Set the Input Trigger source */
3491 tmpsmcr
|= TIM_InputTriggerSource
;
3493 /* Write to TIMx SMCR */
3494 TIMx
->SMCR
= tmpsmcr
;
3498 * @brief Selects the TIMx Trigger Output Mode.
3499 * @param TIMx: where x can be 1, 2, 3, 4, 5, 6, 7, 8 or 15 to select the TIM peripheral.
3501 * @param TIM_TRGOSource: specifies the Trigger Output source.
3502 * This parameter can be one of the following values:
3505 * @arg TIM_TRGOSource_Reset: The UG bit in the TIM_EGR register is used as the trigger output(TRGO)
3506 * @arg TIM_TRGOSource_Enable: The Counter Enable CEN is used as the trigger output(TRGO)
3507 * @arg TIM_TRGOSource_Update: The update event is selected as the trigger output(TRGO)
3509 * - For all TIMx except TIM6 and TIM7
3510 * @arg TIM_TRGOSource_OC1: The trigger output sends a positive pulse when the CC1IF flag
3511 * is to be set, as soon as a capture or compare match occurs(TRGO)
3512 * @arg TIM_TRGOSource_OC1Ref: OC1REF signal is used as the trigger output(TRGO)
3513 * @arg TIM_TRGOSource_OC2Ref: OC2REF signal is used as the trigger output(TRGO)
3514 * @arg TIM_TRGOSource_OC3Ref: OC3REF signal is used as the trigger output(TRGO)
3515 * @arg TIM_TRGOSource_OC4Ref: OC4REF signal is used as the trigger output(TRGO)
3519 void TIM_SelectOutputTrigger(TIM_TypeDef
* TIMx
, uint16_t TIM_TRGOSource
)
3521 /* Check the parameters */
3522 assert_param(IS_TIM_LIST7_PERIPH(TIMx
));
3523 assert_param(IS_TIM_TRGO_SOURCE(TIM_TRGOSource
));
3525 /* Reset the MMS Bits */
3526 TIMx
->CR2
&= (uint16_t)~TIM_CR2_MMS
;
3527 /* Select the TRGO source */
3528 TIMx
->CR2
|= TIM_TRGOSource
;
3532 * @brief Selects the TIMx Trigger Output Mode2 (TRGO2).
3533 * @param TIMx: where x can be 1 or 8 to select the TIM peripheral.
3535 * @param TIM_TRGO2Source: specifies the Trigger Output source.
3536 * This parameter can be one of the following values:
3539 * @arg TIM_TRGOSource_Reset: The UG bit in the TIM_EGR register is used as the trigger output(TRGO2)
3540 * @arg TIM_TRGOSource_Enable: The Counter Enable CEN is used as the trigger output(TRGO2)
3541 * @arg TIM_TRGOSource_Update: The update event is selected as the trigger output(TRGO2)
3542 * @arg TIM_TRGOSource_OC1: The trigger output sends a positive pulse when the CC1IF flag
3543 * is to be set, as soon as a capture or compare match occurs(TRGO2)
3544 * @arg TIM_TRGOSource_OC1Ref: OC1REF signal is used as the trigger output(TRGO2)
3545 * @arg TIM_TRGOSource_OC2Ref: OC2REF signal is used as the trigger output(TRGO2)
3546 * @arg TIM_TRGOSource_OC3Ref: OC3REF signal is used as the trigger output(TRGO2)
3547 * @arg TIM_TRGOSource_OC4Ref: OC4REF signal is used as the trigger output(TRGO2)
3548 * @arg TIM_TRGO2Source_OC4Ref_RisingFalling: OC4Ref Rising and Falling are used as the trigger output(TRGO2)
3549 * @arg TIM_TRGO2Source_OC6Ref_RisingFalling: OC6Ref Rising and Falling are used as the trigger output(TRGO2)
3550 * @arg TIM_TRGO2Source_OC4RefRising_OC6RefRising: OC4Ref Rising and OC6Ref Rising are used as the trigger output(TRGO2)
3551 * @arg TIM_TRGO2Source_OC4RefRising_OC6RefFalling: OC4Ref Rising and OC6Ref Falling are used as the trigger output(TRGO2)
3552 * @arg TIM_TRGO2Source_OC5RefRising_OC6RefRising: OC5Ref Rising and OC6Ref Rising are used as the trigger output(TRGO2)
3553 * @arg TIM_TRGO2Source_OC5RefRising_OC6RefFalling: OC5Ref Rising and OC6Ref Falling are used as the trigger output(TRGO2)
3557 void TIM_SelectOutputTrigger2(TIM_TypeDef
* TIMx
, uint32_t TIM_TRGO2Source
)
3559 /* Check the parameters */
3560 assert_param(IS_TIM_LIST4_PERIPH(TIMx
));
3561 assert_param(IS_TIM_TRGO2_SOURCE(TIM_TRGO2Source
));
3563 /* Reset the MMS Bits */
3564 TIMx
->CR2
&= (uint32_t)~TIM_CR2_MMS2
;
3565 /* Select the TRGO source */
3566 TIMx
->CR2
|= TIM_TRGO2Source
;
3570 * @brief Selects the TIMx Slave Mode.
3571 * @param TIMx: where x can be 1, 2, 3, 4, 8 or 15 to select the TIM peripheral.
3572 * @param TIM_SlaveMode: specifies the Timer Slave Mode.
3573 * This parameter can be one of the following values:
3574 * @arg TIM_SlaveMode_Reset: Rising edge of the selected trigger signal(TRGI) reinitialize
3575 * the counter and triggers an update of the registers
3576 * @arg TIM_SlaveMode_Gated: The counter clock is enabled when the trigger signal (TRGI) is high
3577 * @arg TIM_SlaveMode_Trigger: The counter starts at a rising edge of the trigger TRGI
3578 * @arg TIM_SlaveMode_External1: Rising edges of the selected trigger (TRGI) clock the counter
3579 * @arg TIM_SlaveMode_Combined_ResetTrigger: Rising edge of the selected trigger input (TRGI)
3580 * reinitializes the counter, generates an update
3581 * of the registers and starts the counter.
3584 void TIM_SelectSlaveMode(TIM_TypeDef
* TIMx
, uint32_t TIM_SlaveMode
)
3586 /* Check the parameters */
3587 assert_param(IS_TIM_LIST2_PERIPH(TIMx
));
3588 assert_param(IS_TIM_SLAVE_MODE(TIM_SlaveMode
));
3590 /* Reset the SMS Bits */
3591 TIMx
->SMCR
&= (uint32_t)~TIM_SMCR_SMS
;
3593 /* Select the Slave Mode */
3594 TIMx
->SMCR
|= (uint32_t)TIM_SlaveMode
;
3598 * @brief Sets or Resets the TIMx Master/Slave Mode.
3599 * @param TIMx: where x can be 1, 2, 3, 4, 8 or 15 to select the TIM peripheral.
3600 * @param TIM_MasterSlaveMode: specifies the Timer Master Slave Mode.
3601 * This parameter can be one of the following values:
3602 * @arg TIM_MasterSlaveMode_Enable: synchronization between the current timer
3603 * and its slaves (through TRGO)
3604 * @arg TIM_MasterSlaveMode_Disable: No action
3607 void TIM_SelectMasterSlaveMode(TIM_TypeDef
* TIMx
, uint16_t TIM_MasterSlaveMode
)
3609 /* Check the parameters */
3610 assert_param(IS_TIM_LIST2_PERIPH(TIMx
));
3611 assert_param(IS_TIM_MSM_STATE(TIM_MasterSlaveMode
));
3613 /* Reset the MSM Bit */
3614 TIMx
->SMCR
&= (uint16_t)~TIM_SMCR_MSM
;
3616 /* Set or Reset the MSM Bit */
3617 TIMx
->SMCR
|= TIM_MasterSlaveMode
;
3621 * @brief Configures the TIMx External Trigger (ETR).
3622 * @param TIMx: where x can be 1, 2, 3, 4 or 8 to select the TIM peripheral.
3623 * @param TIM_ExtTRGPrescaler: The external Trigger Prescaler.
3624 * This parameter can be one of the following values:
3625 * @arg TIM_ExtTRGPSC_OFF: ETRP Prescaler OFF.
3626 * @arg TIM_ExtTRGPSC_DIV2: ETRP frequency divided by 2.
3627 * @arg TIM_ExtTRGPSC_DIV4: ETRP frequency divided by 4.
3628 * @arg TIM_ExtTRGPSC_DIV8: ETRP frequency divided by 8.
3629 * @param TIM_ExtTRGPolarity: The external Trigger Polarity.
3630 * This parameter can be one of the following values:
3631 * @arg TIM_ExtTRGPolarity_Inverted: active low or falling edge active.
3632 * @arg TIM_ExtTRGPolarity_NonInverted: active high or rising edge active.
3633 * @param ExtTRGFilter: External Trigger Filter.
3634 * This parameter must be a value between 0x00 and 0x0F
3637 void TIM_ETRConfig(TIM_TypeDef
* TIMx
, uint16_t TIM_ExtTRGPrescaler
,
3638 uint16_t TIM_ExtTRGPolarity
, uint16_t ExtTRGFilter
)
3640 uint16_t tmpsmcr
= 0;
3642 /* Check the parameters */
3643 assert_param(IS_TIM_LIST3_PERIPH(TIMx
));
3644 assert_param(IS_TIM_EXT_PRESCALER(TIM_ExtTRGPrescaler
));
3645 assert_param(IS_TIM_EXT_POLARITY(TIM_ExtTRGPolarity
));
3646 assert_param(IS_TIM_EXT_FILTER(ExtTRGFilter
));
3648 tmpsmcr
= TIMx
->SMCR
;
3650 /* Reset the ETR Bits */
3651 tmpsmcr
&= SMCR_ETR_MASK
;
3653 /* Set the Prescaler, the Filter value and the Polarity */
3654 tmpsmcr
|= (uint16_t)(TIM_ExtTRGPrescaler
| (uint16_t)(TIM_ExtTRGPolarity
| (uint16_t)(ExtTRGFilter
<< (uint16_t)8)));
3656 /* Write to TIMx SMCR */
3657 TIMx
->SMCR
= tmpsmcr
;
3663 /** @defgroup TIM_Group8 Specific interface management functions
3664 * @brief Specific interface management functions
3667 ===============================================================================
3668 ##### Specific interface management functions #####
3669 ===============================================================================
3676 * @brief Configures the TIMx Encoder Interface.
3677 * @param TIMx: where x can be 1, 2, 3, 4 or 8 to select the TIM
3679 * @param TIM_EncoderMode: specifies the TIMx Encoder Mode.
3680 * This parameter can be one of the following values:
3681 * @arg TIM_EncoderMode_TI1: Counter counts on TI1FP1 edge depending on TI2FP2 level.
3682 * @arg TIM_EncoderMode_TI2: Counter counts on TI2FP2 edge depending on TI1FP1 level.
3683 * @arg TIM_EncoderMode_TI12: Counter counts on both TI1FP1 and TI2FP2 edges depending
3684 * on the level of the other input.
3685 * @param TIM_IC1Polarity: specifies the IC1 Polarity
3686 * This parameter can be one of the following values:
3687 * @arg TIM_ICPolarity_Falling: IC Falling edge.
3688 * @arg TIM_ICPolarity_Rising: IC Rising edge.
3689 * @param TIM_IC2Polarity: specifies the IC2 Polarity
3690 * This parameter can be one of the following values:
3691 * @arg TIM_ICPolarity_Falling: IC Falling edge.
3692 * @arg TIM_ICPolarity_Rising: IC Rising edge.
3695 void TIM_EncoderInterfaceConfig(TIM_TypeDef
* TIMx
, uint16_t TIM_EncoderMode
,
3696 uint16_t TIM_IC1Polarity
, uint16_t TIM_IC2Polarity
)
3698 uint16_t tmpsmcr
= 0;
3699 uint16_t tmpccmr1
= 0;
3700 uint16_t tmpccer
= 0;
3702 /* Check the parameters */
3703 assert_param(IS_TIM_LIST3_PERIPH(TIMx
));
3704 assert_param(IS_TIM_ENCODER_MODE(TIM_EncoderMode
));
3705 assert_param(IS_TIM_IC_POLARITY(TIM_IC1Polarity
));
3706 assert_param(IS_TIM_IC_POLARITY(TIM_IC2Polarity
));
3708 /* Get the TIMx SMCR register value */
3709 tmpsmcr
= TIMx
->SMCR
;
3711 /* Get the TIMx CCMR1 register value */
3712 tmpccmr1
= TIMx
->CCMR1
;
3714 /* Get the TIMx CCER register value */
3715 tmpccer
= TIMx
->CCER
;
3717 /* Set the encoder Mode */
3718 tmpsmcr
&= (uint16_t)~TIM_SMCR_SMS
;
3719 tmpsmcr
|= TIM_EncoderMode
;
3721 /* Select the Capture Compare 1 and the Capture Compare 2 as input */
3722 tmpccmr1
&= ((uint16_t)~TIM_CCMR1_CC1S
) & ((uint16_t)~TIM_CCMR1_CC2S
);
3723 tmpccmr1
|= TIM_CCMR1_CC1S_0
| TIM_CCMR1_CC2S_0
;
3725 /* Set the TI1 and the TI2 Polarities */
3726 tmpccer
&= ((uint16_t)~TIM_CCER_CC1P
) & ((uint16_t)~TIM_CCER_CC2P
);
3727 tmpccer
|= (uint16_t)(TIM_IC1Polarity
| (uint16_t)(TIM_IC2Polarity
<< (uint16_t)4));
3729 /* Write to TIMx SMCR */
3730 TIMx
->SMCR
= tmpsmcr
;
3732 /* Write to TIMx CCMR1 */
3733 TIMx
->CCMR1
= tmpccmr1
;
3735 /* Write to TIMx CCER */
3736 TIMx
->CCER
= tmpccer
;
3740 * @brief Enables or disables the TIMx's Hall sensor interface.
3741 * @param TIMx: where x can be 1, 2, 3, 4, 8 or 15 to select the TIM
3743 * @param NewState: new state of the TIMx Hall sensor interface.
3744 * This parameter can be: ENABLE or DISABLE.
3747 void TIM_SelectHallSensor(TIM_TypeDef
* TIMx
, FunctionalState NewState
)
3749 /* Check the parameters */
3750 assert_param(IS_TIM_LIST2_PERIPH(TIMx
));
3751 assert_param(IS_FUNCTIONAL_STATE(NewState
));
3753 if (NewState
!= DISABLE
)
3755 /* Set the TI1S Bit */
3756 TIMx
->CR2
|= TIM_CR2_TI1S
;
3760 /* Reset the TI1S Bit */
3761 TIMx
->CR2
&= (uint16_t)~TIM_CR2_TI1S
;
3768 /** @defgroup TIM_Group9 Specific remapping management function
3769 * @brief Specific remapping management function
3772 ===============================================================================
3773 ##### Specific remapping management function #####
3774 ===============================================================================
3781 * @brief Configures the TIM16 Remapping input Capabilities.
3782 * @param TIMx: where x can be 1, 8 or 16 to select the TIM peripheral.
3783 * @param TIM_Remap: specifies the TIM input reampping source.
3784 * This parameter can be one of the following values:
3785 * @arg TIM16_GPIO: TIM16 Channel 1 is connected to GPIO.
3786 * @arg TIM16_RTC_CLK: TIM16 Channel 1 is connected to RTC input clock.
3787 * @arg TIM16_HSE_DIV32: TIM16 Channel 1 is connected to HSE/32 clock.
3788 * @arg TIM16_MCO: TIM16 Channel 1 is connected to MCO clock.
3789 * @arg TIM1_ADC1_AWDG1: TIM1 ETR is connected to ADC1 AWDG1.
3790 * @arg TIM1_ADC1_AWDG2: TIM1 ETR is connected to ADC1 AWDG2.
3791 * @arg TIM1_ADC1_AWDG3: TIM1 ETR is connected to ADC1 AWDG3.
3792 * @arg TIM1_ADC4_AWDG1: TIM1 ETR is connected to ADC4 AWDG1.
3793 * @arg TIM1_ADC4_AWDG2: TIM1 ETR is connected to ADC4 AWDG2.
3794 * @arg TIM1_ADC4_AWDG3: TIM1 ETR is connected to ADC4 AWDG3.
3795 * @arg TIM8_ADC2_AWDG1: TIM8 ETR is connected to ADC2 AWDG1.
3796 * @arg TIM8_ADC2_AWDG2: TIM8 ETR is connected to ADC2 AWDG2.
3797 * @arg TIM8_ADC2_AWDG3: TIM8 ETR is connected to ADC2 AWDG3.
3798 * @arg TIM8_ADC4_AWDG1: TIM8 ETR is connected to ADC4 AWDG1.
3799 * @arg TIM8_ADC4_AWDG2: TIM8 ETR is connected to ADC4 AWDG2.
3800 * @arg TIM8_ADC4_AWDG3: TIM8 ETR is connected to ADC4 AWDG3.
3803 void TIM_RemapConfig(TIM_TypeDef
* TIMx
, uint16_t TIM_Remap
)
3805 /* Check the parameters */
3806 assert_param(IS_TIM_LIST8_PERIPH(TIMx
));
3807 assert_param(IS_TIM_REMAP(TIM_Remap
));
3809 /* Set the Timer remapping configuration */
3810 TIMx
->OR
= TIM_Remap
;
3817 * @brief Configure the TI1 as Input.
3818 * @param TIMx: where x can be 1, 2, 3, 4, 5, 8, 9, 10, 11, 12, 13 or 14
3819 * to select the TIM peripheral.
3820 * @param TIM_ICPolarity : The Input Polarity.
3821 * This parameter can be one of the following values:
3822 * @arg TIM_ICPolarity_Rising
3823 * @arg TIM_ICPolarity_Falling
3824 * @arg TIM_ICPolarity_BothEdge
3825 * @param TIM_ICSelection: specifies the input to be used.
3826 * This parameter can be one of the following values:
3827 * @arg TIM_ICSelection_DirectTI: TIM Input 1 is selected to be connected to IC1.
3828 * @arg TIM_ICSelection_IndirectTI: TIM Input 1 is selected to be connected to IC2.
3829 * @arg TIM_ICSelection_TRC: TIM Input 1 is selected to be connected to TRC.
3830 * @param TIM_ICFilter: Specifies the Input Capture Filter.
3831 * This parameter must be a value between 0x00 and 0x0F.
3834 static void TI1_Config(TIM_TypeDef
* TIMx
, uint16_t TIM_ICPolarity
, uint16_t TIM_ICSelection
,
3835 uint16_t TIM_ICFilter
)
3837 uint32_t tmpccmr1
= 0, tmpccer
= 0;
3839 /* Disable the Channel 1: Reset the CC1E Bit */
3840 TIMx
->CCER
&= (uint32_t)~TIM_CCER_CC1E
;
3841 tmpccmr1
= TIMx
->CCMR1
;
3842 tmpccer
= TIMx
->CCER
;
3844 /* Select the Input and set the filter */
3845 tmpccmr1
&= ((uint32_t)~TIM_CCMR1_CC1S
) & ((uint32_t)~TIM_CCMR1_IC1F
);
3846 tmpccmr1
|= (uint32_t)(TIM_ICSelection
| (uint32_t)((uint32_t)TIM_ICFilter
<< 4));
3848 /* Select the Polarity and set the CC1E Bit */
3849 tmpccer
&= (uint32_t)~(TIM_CCER_CC1P
| TIM_CCER_CC1NP
);
3850 tmpccer
|= (uint32_t)(TIM_ICPolarity
| (uint32_t)TIM_CCER_CC1E
);
3852 /* Write to TIMx CCMR1 and CCER registers */
3853 TIMx
->CCMR1
= tmpccmr1
;
3854 TIMx
->CCER
= tmpccer
;
3858 * @brief Configure the TI2 as Input.
3859 * @param TIMx: where x can be 1, 2, 3, 4, 5, 8, 9 or 12 to select the TIM
3861 * @param TIM_ICPolarity : The Input Polarity.
3862 * This parameter can be one of the following values:
3863 * @arg TIM_ICPolarity_Rising
3864 * @arg TIM_ICPolarity_Falling
3865 * @arg TIM_ICPolarity_BothEdge
3866 * @param TIM_ICSelection: specifies the input to be used.
3867 * This parameter can be one of the following values:
3868 * @arg TIM_ICSelection_DirectTI: TIM Input 2 is selected to be connected to IC2.
3869 * @arg TIM_ICSelection_IndirectTI: TIM Input 2 is selected to be connected to IC1.
3870 * @arg TIM_ICSelection_TRC: TIM Input 2 is selected to be connected to TRC.
3871 * @param TIM_ICFilter: Specifies the Input Capture Filter.
3872 * This parameter must be a value between 0x00 and 0x0F.
3875 static void TI2_Config(TIM_TypeDef
* TIMx
, uint16_t TIM_ICPolarity
, uint16_t TIM_ICSelection
,
3876 uint16_t TIM_ICFilter
)
3878 uint32_t tmpccmr1
= 0, tmpccer
= 0, tmp
= 0;
3880 /* Disable the Channel 2: Reset the CC2E Bit */
3881 TIMx
->CCER
&= (uint16_t)~TIM_CCER_CC2E
;
3882 tmpccmr1
= TIMx
->CCMR1
;
3883 tmpccer
= TIMx
->CCER
;
3884 tmp
= (uint16_t)(TIM_ICPolarity
<< 4);
3886 /* Select the Input and set the filter */
3887 tmpccmr1
&= ((uint32_t)~TIM_CCMR1_CC2S
) & ((uint32_t)~TIM_CCMR1_IC2F
);
3888 tmpccmr1
|= (uint32_t)((uint32_t)TIM_ICFilter
<< 12);
3889 tmpccmr1
|= (uint32_t)((uint32_t)TIM_ICSelection
<< 8);
3891 /* Select the Polarity and set the CC2E Bit */
3892 tmpccer
&= (uint16_t)~(TIM_CCER_CC2P
| TIM_CCER_CC2NP
);
3893 tmpccer
|= (uint16_t)(tmp
| (uint16_t)TIM_CCER_CC2E
);
3895 /* Write to TIMx CCMR1 and CCER registers */
3896 TIMx
->CCMR1
= tmpccmr1
;
3897 TIMx
->CCER
= tmpccer
;
3901 * @brief Configure the TI3 as Input.
3902 * @param TIMx: where x can be 1, 2, 3, 4, 5 or 8 to select the TIM peripheral.
3903 * @param TIM_ICPolarity : The Input Polarity.
3904 * This parameter can be one of the following values:
3905 * @arg TIM_ICPolarity_Rising
3906 * @arg TIM_ICPolarity_Falling
3907 * @arg TIM_ICPolarity_BothEdge
3908 * @param TIM_ICSelection: specifies the input to be used.
3909 * This parameter can be one of the following values:
3910 * @arg TIM_ICSelection_DirectTI: TIM Input 3 is selected to be connected to IC3.
3911 * @arg TIM_ICSelection_IndirectTI: TIM Input 3 is selected to be connected to IC4.
3912 * @arg TIM_ICSelection_TRC: TIM Input 3 is selected to be connected to TRC.
3913 * @param TIM_ICFilter: Specifies the Input Capture Filter.
3914 * This parameter must be a value between 0x00 and 0x0F.
3917 static void TI3_Config(TIM_TypeDef
* TIMx
, uint16_t TIM_ICPolarity
, uint16_t TIM_ICSelection
,
3918 uint16_t TIM_ICFilter
)
3920 uint16_t tmpccmr2
= 0, tmpccer
= 0, tmp
= 0;
3922 /* Disable the Channel 3: Reset the CC3E Bit */
3923 TIMx
->CCER
&= (uint16_t)~TIM_CCER_CC3E
;
3924 tmpccmr2
= TIMx
->CCMR2
;
3925 tmpccer
= TIMx
->CCER
;
3926 tmp
= (uint16_t)(TIM_ICPolarity
<< 8);
3928 /* Select the Input and set the filter */
3929 tmpccmr2
&= ((uint16_t)~TIM_CCMR1_CC1S
) & ((uint16_t)~TIM_CCMR2_IC3F
);
3930 tmpccmr2
|= (uint16_t)(TIM_ICSelection
| (uint16_t)(TIM_ICFilter
<< (uint16_t)4));
3932 /* Select the Polarity and set the CC3E Bit */
3933 tmpccer
&= (uint16_t)~(TIM_CCER_CC3P
| TIM_CCER_CC3NP
);
3934 tmpccer
|= (uint16_t)(tmp
| (uint16_t)TIM_CCER_CC3E
);
3936 /* Write to TIMx CCMR2 and CCER registers */
3937 TIMx
->CCMR2
= tmpccmr2
;
3938 TIMx
->CCER
= tmpccer
;
3942 * @brief Configure the TI4 as Input.
3943 * @param TIMx: where x can be 1, 2, 3, 4, 5 or 8 to select the TIM peripheral.
3944 * @param TIM_ICPolarity : The Input Polarity.
3945 * This parameter can be one of the following values:
3946 * @arg TIM_ICPolarity_Rising
3947 * @arg TIM_ICPolarity_Falling
3948 * @arg TIM_ICPolarity_BothEdge
3949 * @param TIM_ICSelection: specifies the input to be used.
3950 * This parameter can be one of the following values:
3951 * @arg TIM_ICSelection_DirectTI: TIM Input 4 is selected to be connected to IC4.
3952 * @arg TIM_ICSelection_IndirectTI: TIM Input 4 is selected to be connected to IC3.
3953 * @arg TIM_ICSelection_TRC: TIM Input 4 is selected to be connected to TRC.
3954 * @param TIM_ICFilter: Specifies the Input Capture Filter.
3955 * This parameter must be a value between 0x00 and 0x0F.
3958 static void TI4_Config(TIM_TypeDef
* TIMx
, uint16_t TIM_ICPolarity
, uint16_t TIM_ICSelection
,
3959 uint16_t TIM_ICFilter
)
3961 uint16_t tmpccmr2
= 0, tmpccer
= 0, tmp
= 0;
3963 /* Disable the Channel 4: Reset the CC4E Bit */
3964 TIMx
->CCER
&= (uint16_t)~TIM_CCER_CC4E
;
3965 tmpccmr2
= TIMx
->CCMR2
;
3966 tmpccer
= TIMx
->CCER
;
3967 tmp
= (uint16_t)(TIM_ICPolarity
<< 12);
3969 /* Select the Input and set the filter */
3970 tmpccmr2
&= ((uint16_t)~TIM_CCMR1_CC2S
) & ((uint16_t)~TIM_CCMR1_IC2F
);
3971 tmpccmr2
|= (uint16_t)(TIM_ICSelection
<< 8);
3972 tmpccmr2
|= (uint16_t)(TIM_ICFilter
<< 12);
3974 /* Select the Polarity and set the CC4E Bit */
3975 tmpccer
&= (uint16_t)~(TIM_CCER_CC4P
| TIM_CCER_CC4NP
);
3976 tmpccer
|= (uint16_t)(tmp
| (uint16_t)TIM_CCER_CC4E
);
3978 /* Write to TIMx CCMR2 and CCER registers */
3979 TIMx
->CCMR2
= tmpccmr2
;
3980 TIMx
->CCER
= tmpccer
;
3995 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/