33. Basic timers (TIM6/TIM7)

33.1 TIM6/TIM7 introduction

The basic timers TIM6/TIM7 consist in a 16-bit autoreload counter driven by a programmable prescaler.

They can be used as generic timers for time-base generation.

The basic timer can also be used for triggering the digital-to-analog converter. This is done with the trigger output of the timer.

The timers are completely independent, and do not share any resources.

33.2 TIM6/TIM7 main features

Basic timer (TIM6/TIM7) features include:

33.3 TIM6/TIM7 functional description

33.3.1 TIM6/TIM7 block diagram

Figure 418. Basic timer block diagram

Figure 418. Basic timer block diagram showing connections between 32-bit APB bus, tim_pck, tim_ker_ck, Trigger controller (with Control, Enable, Count, tim_trgo), IRQ interface (tim_upd_it), DMA interface (tim_upd_dma), PSC prescaler (tim_psc_ck to tim_cnt_ck), CNT counter, and Auto-reload register with UEV and Update signals.

Notes:
Reg Preload registers transferred to active registers on U event according to control bit
Event
Interrupt & DMA

MSv62381V1

Figure 418. Basic timer block diagram showing connections between 32-bit APB bus, tim_pck, tim_ker_ck, Trigger controller (with Control, Enable, Count, tim_trgo), IRQ interface (tim_upd_it), DMA interface (tim_upd_dma), PSC prescaler (tim_psc_ck to tim_cnt_ck), CNT counter, and Auto-reload register with UEV and Update signals.

33.3.2 TIM6/TIM7 internal signals

The table in this section summarizes the TIM inputs and outputs.

Table 328. TIM internal input/output signals

Internal signal nameSignal typeDescription
tim_pclkInputTimer APB clock
tim_ker_ckInputTimer kernel clock. This clock must be synchronous with tim_pclk (derived from the same source). The clock ratio tim_ker_ck/tim_pclk must be an integer: 1, 2, 3,..., 16 (maximum value)
tim_trgoOutputInternal trigger output. This trigger can trigger other on-chip peripherals (DAC).
tim_upd_itOutputTimer update event interrupt
tim_upd_dmaOutputTimer update dma request

33.3.3 TIM6/TIM7 clocks

The timer bus interface is clocked by the tim_pclk APB clock.

The counter clock tim_ker_ck is connected to the tim_pclk input.

The CEN (in the TIM_CR1 register) and UG bits (in the TIM_EGR register) are actual control bits and can be changed only by software (except for UG that remains cleared automatically). As soon as the CEN bit is written to 1, the prescaler is clocked by the internal clock tim_ker_ck.

Figure 419 shows the behavior of the control circuit and the upcounter in normal mode, without prescaler.

Figure 419. Control circuit in normal mode, internal clock divided by 1

Timing diagram for Figure 419 showing the control circuit in normal mode with internal clock divided by 1. The diagram includes waveforms for tim_ker_ck, CEN, UG, counter initialization (internal), tim_cnt_ck, tim_psc_ck, and the Counter register. The Counter register is shown as a sequence of 16-bit words (31, 32, 33, 34, 35, 36, 00, 01, 02, 03, 04, 05, 06, 07).

The diagram illustrates the timing relationship between various signals in normal mode with the internal clock divided by 1. The tim_ker_ck signal is a continuous square wave. The CEN signal is a high pulse that initiates the counter. The UG signal is a high pulse that triggers the counter initialization. The counter initialization (internal) signal is a high pulse that occurs after the UG signal. The tim_cnt_ck and tim_psc_ck signals are square waves that are synchronized with the tim_ker_ck signal. The Counter register is shown as a sequence of 16-bit words (31, 32, 33, 34, 35, 36, 00, 01, 02, 03, 04, 05, 06, 07). The counter register is updated on the rising edge of the tim_ker_ck signal. The counter register is shown as a sequence of 16-bit words (31, 32, 33, 34, 35, 36, 00, 01, 02, 03, 04, 05, 06, 07). The counter register is updated on the rising edge of the tim_ker_ck signal.

Timing diagram for Figure 419 showing the control circuit in normal mode with internal clock divided by 1. The diagram includes waveforms for tim_ker_ck, CEN, UG, counter initialization (internal), tim_cnt_ck, tim_psc_ck, and the Counter register. The Counter register is shown as a sequence of 16-bit words (31, 32, 33, 34, 35, 36, 00, 01, 02, 03, 04, 05, 06, 07).

33.3.4 Time-base unit

The main block of the programmable timer is a 16-bit upcounter with its related autoreload register. The counter clock can be divided by a prescaler.

The counter, the autoreload register and the prescaler register can be written or read by software. This is true even when the counter is running.

The time-base unit includes:

The autoreload register is preloaded. The preload register is accessed each time an attempt is made to write or read the autoreload register. The contents of the preload register are transferred into the shadow register permanently or at each update event UEV, depending on the autoreload preload enable bit (ARPE) in the TIM_CR1 register. The update event is sent when the counter reaches the overflow value and if the UDIS bit equals 0 in the TIM_CR1 register. It can also be generated by software. The generation of the update event is described in detail for each configuration.

Note: An update overrun status bit (UIOVRF in TIM_SR register) indicates that an update request occurred while an update interrupt is pending (update interrupt flag set). This bit is useful when debugging closed loop applications, to indicate that:

- the update interrupt service routine is too long with respect to the interval between consecutive update events

- the update interrupt service routine was served too late with respect to the subsequent update event

The counter is clocked by the prescaler output tim_cnt_ck, which is enabled only when the counter enable bit (CEN) in the TIM_CR1 register is set.

Note that the actual counter enable signal tim_cnt_en is set one clock cycle after CEN bit set.

Prescaler description

The prescaler can divide the counter clock frequency by any factor between 1 and 65536. It is based on a 16-bit counter controlled through a 16-bit register (in the TIM_PSC register). It can be changed on the fly as the TIM_PSC control register is buffered. The new prescaler ratio is taken into account at the next update event.

Figure 420 and Figure 421 give some examples of the counter behavior when the prescaler ratio is changed on the fly.

Figure 420. Counter timing diagram with prescaler division change from 1 to 2

Timing diagram showing signals: tim_psc_ck, CEN, tim_cnt_ck, Counter register, Update event (UEV), Prescaler control register, Prescaler buffer, and Prescaler counter. It illustrates the change of prescaler division from 1 to 2.
Timing diagram showing signals: tim_psc_ck, CEN, tim_cnt_ck, Counter register, Update event (UEV), Prescaler control register, Prescaler buffer, and Prescaler counter. It illustrates the change of prescaler division from 1 to 2.

Figure 421. Counter timing diagram with prescaler division change from 1 to 4

Timing diagram showing the relationship between tim_psc_ck, CEN, tim_cnt_ck, Counter register, Update event (UEV), Prescaler control register, Prescaler buffer, and Prescaler counter during a prescaler division change from 1 to 4.

The diagram illustrates the timing of a prescaler division change from 1 to 4. It shows the following signals and registers over time:

MSv80082V1

Timing diagram showing the relationship between tim_psc_ck, CEN, tim_cnt_ck, Counter register, Update event (UEV), Prescaler control register, Prescaler buffer, and Prescaler counter during a prescaler division change from 1 to 4.

33.3.5 Counting mode

The counter counts from 0 to the autoreload value (contents of the TIM_ARR register), then restarts from 0 and generates a counter overflow event.

An update event can be generated at each counter overflow or by setting the UG bit in the TIM_EGR register (by software or by using the slave mode controller).

The UEV event can be disabled by software by setting the UDIS bit in the TIM_CR1 register. This avoids updating the shadow registers while writing new values into the preload registers. In this way, no update event occurs until the UDIS bit has been written to 0, however, the counter and the prescaler counter both restart from 0 (but the prescale rate does not change). In addition, if the URS (update request selection) bit in the TIM_CR1 register is set, setting the UG bit generates an update event UEV, but the UIF flag is not set (so no interrupt or DMA request is sent).

When an update event occurs, all the registers are updated and the update flag (UIF bit in the TIM_SR register) is set (depending on the URS bit):

The following figures show some examples of the counter behavior for different clock frequencies when TIM_ARR = 0x36.

Figure 422. Counter timing diagram, internal clock divided by 1

Timing diagram for counter with internal clock divided by 1. Shows tim_psc_ck, CEN, tim_cnt_ck, Counter register (31-07), Counter overflow, Update event (UEV), and Update interrupt flag (UIF).

This timing diagram illustrates the operation of a counter when the internal clock is divided by 1. The tim_psc_ck signal is a continuous square wave. The CEN signal is a low-to-high pulse that enables the counter. The tim_cnt_ck signal is a square wave with the same frequency as tim_psc_ck. The Counter register shows the count values: it starts at 31, increments to 32, 33, 34, 35, 36, and then wraps around to 00, 01, 02, 03, 04, 05, 06, 07. A Counter overflow pulse occurs on the rising edge of tim_cnt_ck when the counter transitions from 36 to 00. The Update event (UEV) pulse occurs on the rising edge of tim_cnt_ck when the counter transitions from 07 to 00. The Update interrupt flag (UIF) is set high on the rising edge of the UEV pulse. Vertical dashed lines indicate the timing of these events relative to the clock edges.

MSv50997V1

Timing diagram for counter with internal clock divided by 1. Shows tim_psc_ck, CEN, tim_cnt_ck, Counter register (31-07), Counter overflow, Update event (UEV), and Update interrupt flag (UIF).

Figure 423. Counter timing diagram, internal clock divided by 2

Timing diagram for counter with internal clock divided by 2. Shows tim_psc_ck, CEN, tim_cnt_ck, Counter register (0034-0003), Counter overflow, Update event (UEV), and Update interrupt flag (UIF).

This timing diagram illustrates the operation of a counter when the internal clock is divided by 2. The tim_psc_ck signal is a continuous square wave. The CEN signal is a low-to-high pulse that enables the counter. The tim_cnt_ck signal is a square wave with half the frequency of tim_psc_ck. The Counter register shows the count values: it starts at 0034, increments to 0035, 0036, and then wraps around to 0000, 0001, 0002, 0003. A Counter overflow pulse occurs on the rising edge of tim_cnt_ck when the counter transitions from 0036 to 0000. The Update event (UEV) pulse occurs on the rising edge of tim_cnt_ck when the counter transitions from 0003 to 0000. The Update interrupt flag (UIF) is set high on the rising edge of the UEV pulse. Vertical dashed lines indicate the timing of these events relative to the clock edges.

MSv62300V1

Timing diagram for counter with internal clock divided by 2. Shows tim_psc_ck, CEN, tim_cnt_ck, Counter register (0034-0003), Counter overflow, Update event (UEV), and Update interrupt flag (UIF).

Figure 424. Counter timing diagram, internal clock divided by 4

Timing diagram for Figure 424 showing tim_psc_ck, CEN, tim_cnt_ck, Counter register, Counter overflow, Update event (UEV), and Update interrupt flag (UIF).

This timing diagram illustrates the operation of a counter when the internal clock is divided by 4. The tim_psc_ck signal is a continuous clock. The CEN signal is an enable signal that starts high and then goes low. The tim_cnt_ck signal is the prescaled clock, which has a frequency 1/4 of tim_psc_ck. The Counter register shows the count values: 0035, 0036, 0000, and 0001. The Counter overflow signal is high when the counter reaches its maximum value (0035) and then rolls over to 0000. The Update event (UEV) signal is high when an update event occurs, which happens when the counter rolls over. The Update interrupt flag (UIF) signal is high when an update interrupt is generated, which happens when the counter rolls over and the CEN signal is high.

SignalValue/State
tim_psc_ckContinuous clock
CENHigh, then Low
tim_cnt_ckPrescaled clock (1/4 frequency)
Counter register0035, 0036, 0000, 0001
Counter overflowHigh at rollover
Update event (UEV)High at rollover
Update interrupt flag (UIF)High at rollover

MSv62301V1

Timing diagram for Figure 424 showing tim_psc_ck, CEN, tim_cnt_ck, Counter register, Counter overflow, Update event (UEV), and Update interrupt flag (UIF).

Figure 425. Counter timing diagram, internal clock divided by N

Timing diagram for Figure 425 showing tim_psc_ck, tim_cnt_ck, Counter register, Counter overflow, Update event (UEV), and Update interrupt flag (UIF).

This timing diagram illustrates the operation of a counter when the internal clock is divided by N. The tim_psc_ck signal is a continuous clock. The tim_cnt_ck signal is the prescaled clock, which has a frequency 1/N of tim_psc_ck. The Counter register shows the count values: 1F, 20, and 00. The Counter overflow signal is high when the counter reaches its maximum value (1F) and then rolls over to 00. The Update event (UEV) signal is high when an update event occurs, which happens when the counter rolls over. The Update interrupt flag (UIF) signal is high when an update interrupt is generated, which happens when the counter rolls over and the CEN signal is high.

SignalValue/State
tim_psc_ckContinuous clock
tim_cnt_ckPrescaled clock (1/N frequency)
Counter register1F, 20, 00
Counter overflowHigh at rollover
Update event (UEV)High at rollover
Update interrupt flag (UIF)High at rollover

MSv62302V1

Timing diagram for Figure 425 showing tim_psc_ck, tim_cnt_ck, Counter register, Counter overflow, Update event (UEV), and Update interrupt flag (UIF).

Figure 426. Counter timing diagram, update event when ARPE = 0 (TIM_ARR not preloaded)

Timing diagram for counter update event when ARPE = 0. It shows the relationship between tim_psc_ck, CEN, tim_cnt_ck, Counter register, Counter overflow, Update event (UEV), Update interrupt flag (UIF), and Auto-reload preload register.

The diagram illustrates the timing of a counter update event when ARPE = 0 and TIM_ARR is not preloaded. The counter register is 8 bits wide, with bits 31-36 shown as a single block and bits 00-07 shown individually. The counter overflow occurs when the counter reaches 36. The update event (UEV) occurs on the rising edge of the counter overflow signal. The update interrupt flag (UIF) is set on the rising edge of the UEV. The auto-reload preload register is shown with a value of FF, and a note indicates that a new value can be written to TIM_ARR.

SignalValue / State
tim_psc_ckPeriodic clock signal
CENCounter enable signal
tim_cnt_ckCounter clock signal
Counter registerBits 31, 32, 33, 34, 35, 36, 00, 01, 02, 03, 04, 05, 06, 07
Counter overflowHigh pulse at bit 36
Update event (UEV)High pulse on rising edge of counter overflow
Update interrupt flag (UIF)High pulse on rising edge of UEV
Auto-reload preload registerFF

Write a new value in TIM_ARR

MSv80083V1

Timing diagram for counter update event when ARPE = 0. It shows the relationship between tim_psc_ck, CEN, tim_cnt_ck, Counter register, Counter overflow, Update event (UEV), Update interrupt flag (UIF), and Auto-reload preload register.

Figure 427. Counter timing diagram, update event when ARPE = 1 (TIM_ARR preloaded)

Timing diagram for a counter with ARPE = 1. It shows the relationship between the prescaler clock (tim_psc_ck), counter clock (tim_cnt_ck), counter register values (F0 to 07), counter overflow, update event (UEV), update interrupt flag (UIF), and auto-reload registers (preload and shadow). A write to TIM_ARR is shown updating the preload register, which then updates the shadow register and the counter register after an overflow.

The diagram illustrates the timing of a counter when ARPE = 1. The counter register counts from F0 to F5, then overflows to 00. The counter overflow signal is high during the overflow. The update event (UEV) occurs at the end of the overflow. The update interrupt flag (UIF) is set at the end of the overflow. The auto-reload preload register is updated with a new value (F5) and the auto-reload shadow register is updated with the same value (F5) after the overflow. The counter register is then updated with the new value (F5) after the overflow.

Write a new value in TIM_ARR

MSv80084V1

Timing diagram for a counter with ARPE = 1. It shows the relationship between the prescaler clock (tim_psc_ck), counter clock (tim_cnt_ck), counter register values (F0 to 07), counter overflow, update event (UEV), update interrupt flag (UIF), and auto-reload registers (preload and shadow). A write to TIM_ARR is shown updating the preload register, which then updates the shadow register and the counter register after an overflow.

Dithering mode

The time base effective resolution can be increased by enabling the dithering mode, using the DITHER bit in the TIM_CR1 register. This affects the way the TIM_ARR is behaving, and is useful for adjusting the average counter period when the timer is used as a trigger (typically for a DAC).

The operating principle is to have the actual ARR value slightly changed (adding or not one timer clock period) over 16 consecutive counting periods, with predefined patterns. This allows a 16-fold resolution increase, considering the average counting period.

Figure 428 presents the dithering principle applied to four consecutive counting periods.

Timing diagram illustrating the dithering principle over four consecutive counting periods for average periods T = 12, T = 12 + 1/4, T = 12 + 1/2, T = 12 + 3/4, and T = 13.

Figure 428. Dithering principle

MSv47466V1

Timing diagram illustrating the dithering principle over four consecutive counting periods for average periods T = 12, T = 12 + 1/4, T = 12 + 1/2, T = 12 + 3/4, and T = 13.

When the dithering mode is enabled, the register coding is changed as follows (see Figure 429 for example):

Note: The following sequence must be followed when resetting the DITHEN bit:

  1. 1. CEN and ARPE bits must be reset
  2. 2. The DITHEN bit must be reset
  3. 3. The CEN bit can be set (eventually with ARPE = 1).

Figure 429. Data format and register coding in dithering mode

Diagram showing register format and bit breakdown in dithering mode. Register format: b19 to b4 (MSB: 16-bits, integer part), b3 to b0 (LSB: 4-bits fractional part). Example: Total value 326 split into integer part 20 (Base compare value is 20 during 16 periods) and fractional part 6 (Additional 6 cycles are spread over the 16 periods).

MSv45753V2

Diagram showing register format and bit breakdown in dithering mode. Register format: b19 to b4 (MSB: 16-bits, integer part), b3 to b0 (LSB: 4-bits fractional part). Example: Total value 326 split into integer part 20 (Base compare value is 20 during 16 periods) and fractional part 6 (Additional 6 cycles are spread over the 16 periods).

The minimum frequency is given by the following formula:

\[\text{Resolution} = \frac{F_{\text{Tim}}}{F_{\text{pwm}}} \Rightarrow F_{\text{pwmMin}} = \frac{F_{\text{Tim}}}{\text{Max}_{\text{Resolution}}}\]

\[\text{Dithering mode disabled: } F_{\text{pwmMin}} = \frac{F_{\text{Tim}}}{65536}\]

\[\text{Dithering mode enabled: } F_{\text{pwmMin}} = \frac{F_{\text{Tim}}}{65535 + \frac{15}{16}}\]

Note: The maximum TIM_ARR value is limited to 0xFFFEF in dithering mode (corresponds to 65534 for the integer part and 15 for the dithered part).

As shown on Figure 430, the dithering mode is used to increase the PWM resolution whatever the PWM frequency.

Figure 430. FCnt resolution vs frequency

Graph showing Resolution vs F_Cnt for Dithering and No Dithering modes. The y-axis is Resolution (20-bit, 16-bit) and the x-axis is F_Cnt. Two curves are shown: 'Dithering' which starts at 20-bit resolution at F_Cnt min and decreases, and 'No Dithering' which starts at 16-bit resolution at F_Cnt min and decreases. A vertical dashed line marks F_Cnt min.
Graph showing Resolution vs F_Cnt for Dithering and No Dithering modes. The y-axis is Resolution (20-bit, 16-bit) and the x-axis is F_Cnt. Two curves are shown: 'Dithering' which starts at 20-bit resolution at F_Cnt min and decreases, and 'No Dithering' which starts at 16-bit resolution at F_Cnt min and decreases. A vertical dashed line marks F_Cnt min.

MSv50910V1

The period changes are spread over 16 consecutive periods, as described in Figure 431.

Figure 431. PWM dithering pattern

Diagram showing PWM dithering pattern over 16 counter periods. Counter period 1 to 16 are shown. ARR value is constant at 643. Auto-Reload value alternates between 41 and 40 in a specific sequence: 41, 40, 40, 40, 41, 40, 40, 40, 41, 40, 40, 40, 40, 40, 40, 40.
Counter period12345678910111213141516
ARR value643
Auto-Reload value41404040414040404140404040404040
Diagram showing PWM dithering pattern over 16 counter periods. Counter period 1 to 16 are shown. ARR value is constant at 643. Auto-Reload value alternates between 41 and 40 in a specific sequence: 41, 40, 40, 40, 41, 40, 40, 40, 41, 40, 40, 40, 40, 40, 40, 40.

MSv47465V1

The autoreload and compare values increments are spread following the specific patterns described in Table 329. The dithering sequence is done to have increments distributed as evenly as possible and minimize the overall ripple.

Table 329. TIM_ARR register change dithering pattern

-PWM period
LSB value12345678910111213141516
0000----------------
0001+1---------------
0010+1-------+1-------
0011+1---+1---+1-------
0100+1---+1---+1---+1---
0101+1-+1-+1---+1---+1---
0110+1-+1-+1---+1-+1-+1---
0111+1-+1-+1-+1-+1-+1-+1---
1000+1-+1-+1-+1-+1-+1-+1-+1-
1001+1+1+1-+1-+1-+1-+1-+1-+1-
1010+1+1+1-+1-+1-+1+1+1-+1-+1-
1011+1+1+1-+1+1+1-+1+1+1-+1-+1-
1100+1+1+1-+1+1+1-+1+1+1-+1+1+1-
1101+1+1+1+1+1+1+1-+1+1+1-+1+1+1-
1110+1+1+1+1+1+1+1-+1+1+1+1+1+1+1-
1111+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1-

33.3.6 UIF bit remapping

The IUFREMAP bit in the TIM_CR1 register forces a continuous copy of the update interrupt flag UIF into the timer counter register's bit 31 (TIM_CNT[31]). This is used to atomically read both the counter value and a potential roll-over condition signaled by the UIFCPY flag. In particular cases, it can ease the calculations by avoiding race conditions caused for instance by a processing shared between a background task (counter reading) and an interrupt (update interrupt).

There is no latency between the assertions of the UIF and UIFCPY flags.

33.3.7 ADC triggers

The timer can generate an ADC triggering event with various internal signals, such as reset, enable or compare events.

Note: The clock of the slave peripherals (such as timer, ADC) receiving the tim_trgo signal must be enabled prior to receiving events from the master timer, and the clock frequency (prescaler) must not be changed on-the-fly while triggers are received from the master timer.

33.3.8 ADC synchronization

The timer operation can be synchronized to the ADC clock to trigger jitter-free ADC sampling. This function is enabled using the ADSYNC bit in the TIM_CR2 register.

This feature is useful when the timers and the ADCs are operating with semisynchronous clocks (clocks derived from a same source with integer ratio tim_ker_ck/adc_ker_ck), for instance adc_ker_ck = 75 MHz and tim_ker_ck = 150 MHz or 300 MHz.

ADSYNC must also be set when both peripherals are operating at the same frequency from the same clock source, when jitter-free operation is needed.

ADSYNC must not be set and jitter-free operation is not supported in the following cases:

When ADSYNC = 1, the timer operation is slightly changed: the counter enable and counter reset events are aligned to the adc_ker_ck ADC clock, to avoid any phase shift due to clocks enable in the RCC.

Jitter-free operation is guaranteed only when one of the two requirements below is met (depending on the selected trigger source).

  1. 1. The counter period must be a multiple of the ADC clock period

\[(\text{TIM\_PSC} + 1) \times (\text{TIM\_ARR} + 1) \times T_{\text{tim\_ker\_ck}} = n \times T_{\text{adc\_ker\_ck}}\]

  1. 2. The compare value must be a multiple of the ADC clock period

\[(\text{TIM\_PSC} + 1) \times \text{TIM\_CMPy} \times T_{\text{tim\_ker\_ck}} = m \times T_{\text{adc\_ker\_ck}}\]

Note: If none of the two above requirements are met, the trigger is still generated, but the latency is not constant and varies with the timer and ADC clocks phase shift.

Programming guidelines

The ADC synchronization feature must not be modified during run-time, once the counter is enabled and once the ADC has been configured for receiving triggers from the timer.

It is mandatory to follow the procedure below to use the ADC synchronization:

  1. 1. Enable the destination ADC clock
  2. 2. Configure the timer and set the ADSYNC bit
  3. 3. Configure the ADC and enable it (using ADSTART and/or JADSTART bits)
  4. 4. Start the timer (with the CEN counter enable bit)

33.3.9 TIM6/TIM7 DMA requests

The TIM6/TIM7 can generate a single DMA request, as shown in Table 330.

Table 330. DMA request

DMA request signalDMA requestEnable control bit
tim_upd_dmaUpdateUDE

33.3.10 Debug mode

When the microcontroller enters debug mode (Cortex-M33 core halted), the TIMx counter can either continue to work normally or be stopped.

The behavior in debug mode can be programmed with a dedicated configuration bit per timer in the Debug support (DBG) module.

For more details, refer to section Debug support (DBG).

33.3.11 TIM6/TIM7 low-power modes

Table 331. Effect of low-power modes on TIM6/TIM7

ModeDescription
SleepNo effect, peripheral is active. The interrupts can cause the device to exit from Sleep mode.
StopThe timer operation is stopped and the register content is kept. No interrupt can be generated.
StandbyThe timer is powered-down and must be reinitialized after exiting the Standby mode.

33.3.12 TIM6/TIM7 interrupts

The TIM6/TIM7 can generate a single interrupt, as shown in Table 332.

Table 332. Interrupt request

Interrupt acronymInterrupt eventEvent flagEnable control bitInterrupt clear methodExit from Sleep modeExit from Stop and Standby mode
TIM6
TIM7
UpdateUIFUIEwrite 0 in UIFYesNo

33.4 TIM6/TIM7 registers

Refer to Section 1.2 for a list of abbreviations used in register descriptions.

The peripheral registers can be accessed by half-words (16-bit) or words (32-bit).

33.4.1 TIM control register 1 (TIM_CR1)

Address offset: 0x00

Reset value: 0x0000

1514131211109876543210
Res.Res.Res.DITH
EN
UIFRE
MAP
Res.Res.Res.ARPERes.Res.Res.OPMURSUDISCEN
rwrwrwrwrwrwrw

Bits 15:13 Reserved, must be kept at reset value.

Bit 12 DITHEN: Dithering enable

0: Dithering disabled

1: Dithering enabled

Note: The DITHEN bit can only be modified when CEN bit is reset.

Bit 11 UIFREMAP: UIF status bit remapping

0: No remapping. UIF status bit is not copied to TIM_CNT register bit 31.

1: Remapping enabled. UIF status bit is copied to TIM_CNT register bit 31.

Bits 10:8 Reserved, must be kept at reset value.

Bit 7 ARPE: Auto-reload preload enable

0: TIM_ARR register is not buffered.

1: TIM_ARR register is buffered.

Bits 6:4 Reserved, must be kept at reset value.

Bit 3 OPM: One-pulse mode

0: Counter is not stopped at update event

1: Counter stops counting at the next update event (clearing the CEN bit).

Bit 2 URS: Update request source

This bit is set and cleared by software to select the UEV event sources.

0: Any of the following events generates an update interrupt or DMA request if enabled.

These events can be:

1: Only counter overflow/underflow generates an update interrupt or DMA request if enabled.

Bit 1 UDIS: Update disable

This bit is set and cleared by software to enable/disable UEV event generation.

0: UEV enabled. The Update (UEV) event is generated by one of the following events:

Buffered registers are then loaded with their preload values.

1: UEV disabled. The Update event is not generated, shadow registers keep their value (ARR, PSC). However the counter and the prescaler are reinitialized if the UG bit is set or if a hardware reset is received from the slave mode controller.

Bit 0 CEN: Counter enable

0: Counter disabled

1: Counter enabled

CEN is cleared automatically in one-pulse mode, when an update event occurs.

33.4.2 TIM control register 2 (TIM_CR2)

Address offset: 0x04

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.AD
SYNC
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
rw
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.Res.MMS[2:0]Res.Res.Res.Res.
rwrwrw

Bits 31:29 Reserved, must be kept at reset value.

Bit 28 ADSYNC: ADC synchronization

0: The timer operates independently from the ADC

1: The timer operation is synchronized with the ADC clock to provide jitter-free sampling point. This mode can be enabled only with specific ADC / timer clock relationship. Refer to Section 33.3.8 for requirements.

The ADSYNC must not modified when the counter is enabled (CEN bit is set).

Bits 27:7 Reserved, must be kept at reset value.

Bits 6:4 MMS[2:0]: Master mode selection

These bits are used to select the information to be sent in master mode to slave timers for synchronization (TRGO). The combination is as follows:

000:Reset - the UG bit from the TIM_EGR register is used as a trigger output (tim_trgo).

001:Enable - the Counter enable signal, tim_cnt_en, is used as a trigger output (tim_trgo). It is useful to start several timers at the same time or to control a window in which a slave timer is enabled. The Counter Enable signal is generated when the CEN control bit is written.

010:Update - The update event is selected as a trigger output (tim_trgo). For instance a master timer can then be used as a prescaler for a slave timer.

Note: The clock of the slave timer or the peripheral receiving the tim_trgo must be enabled prior to receive events from the master timer, and must not be changed on-the-fly while triggers are received from the master timer.

Bits 3:0 Reserved, must be kept at reset value.

33.4.3 TIM DMA/interrupt enable register (TIM_DIER)

Address offset: 0x0C

Reset value: 0x0000

1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.UDERes.Res.Res.Res.Res.Res.Res.UIE
rwrw

Bits 15:9 Reserved, must be kept at reset value.

Bit 8 UDE: Update DMA request enable
0: Update DMA request disabled.
1: Update DMA request enabled.

Bits 7:1 Reserved, must be kept at reset value.

Bit 0 UIE: Update interrupt enable
0: Update interrupt disabled.
1: Update interrupt enabled.

33.4.4 TIM status register (TIM_SR)

Address offset: 0x10

Reset value: 0x0000 0000

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.UIOVR
F
Res.Res.Res.Res.Res.Res.Res.Res.
rc_w0
1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.UIF
rc_w0

Bits 31:25 Reserved, must be kept at reset value.

Bit 24 UIOVRF: Update Interrupt Overrun flag

This flag is set by hardware when an update request occurs while an update interrupt is pending (update interrupt flag set). It is cleared by software by writing it to '0'.

0: No Update Interrupt Overrun

1: Update Interrupt Overrun

Bits 23:1 Reserved, must be kept at reset value.

Bit 0 UIF: Update interrupt flag

This bit is set by hardware on an update event. It is cleared by software.

0: No update occurred.

1: Update interrupt pending. This bit is set by hardware when the registers are updated:

–On counter overflow if UDIS = 0 in the TIM_CR1 register.

–When CNT is reinitialized by software using the UG bit in the TIM_EGR register, if URS = 0 and UDIS = 0 in the TIM_CR1 register.

33.4.5 TIM event generation register (TIM_EGR)

Address offset: 0x14

Reset value: 0x0000

1514131211109876543210
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.UG
w

Bits 15:1 Reserved, must be kept at reset value.

Bit 0 UG: Update generation

This bit can be set by software, it is automatically cleared by hardware.

0: No action.

1: Re-initializes the timer counter and generates an update of the registers. Note that the prescaler counter is cleared too (but the prescaler ratio is not affected).

33.4.6 TIM counter (TIM_CNT)

Address offset: 0x24

Reset value: 0x0000 0000

31302928272625242322212019181716
UIF
CPY
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.
r
1514131211109876543210
CNT[15:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bit 31 UIFCPY: UIF copy

This bit is a read-only copy of the UIF bit of the TIM_ISR register. If the UIFREMAP bit in TIM_CR1 is reset, bit 31 is reserved and read as 0.

Bits 30:16 Reserved, must be kept at reset value.

Bits 15:0 CNT[15:0]: Counter value

Non-dithering mode (DITHEN = 0)

The register holds the counter value.

Dithering mode (DITHEN = 1)

The register only holds the non-dithered part in CNT[15:0]. The fractional part is not available.

33.4.7 TIM prescaler (TIM_PSC)

Address offset: 0x28

Reset value: 0x0000

1514131211109876543210
PSC[15:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bits 15:0 PSC[15:0]: Prescaler value

The counter clock frequency \(f_{tim\_cnt\_ck}\) is equal to \(f_{tim\_psc\_ck} / (PSC[15:0] + 1)\).

PSC contains the value to be loaded into the active prescaler register at each update event. (including when the counter is cleared through UG bit of TIM_EGR register.

33.4.8 TIM autoreload register (TIM_ARR)

Address offset: 0x2C

Reset value: 0x0000 FFFF

31302928272625242322212019181716
Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.ARR[19:16]
rwrwrwrw
1514131211109876543210
ARR[15:0]
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bits 31:20 Reserved, must be kept at reset value.

Bits 19:0 ARR[19:0]: Auto-reload value

ARR is the value to be loaded into the actual auto-reload register.

Refer to Section 33.3.4: Time-base unit for more details about ARR update and behavior.

The counter is blocked while the auto-reload value is null.

Non-dithering mode (DITHER = 0)

The register holds the auto-reload value in ARR[15:0]. The ARR[19:16] bits are reserved.

Dithering mode (DITHER = 1)

The register holds the integer part in ARR[19:4]. The ARR[3:0] bitfield contains the dithered part.

33.4.9 TIM6/TIM7 register map

TIM6/TIM7 registers are mapped as 16-bit addressable registers as described in the table below:

Table 333. TIM6/TIM7 register map and reset values

OffsetRegister name313029282726252423222120191817161514131211109876543210
0x00TIM_CR1Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.DITHENUIFREMARes.Res.Res.ARPERes.Res.Res.OPMURSUDISCEN
Reset value0000000
0x04TIM_CR2Res.Res.Res.ADSYNCRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.MMS [2:0]Res.Res.Res.Res.Res.
Reset value0000
0x08ReservedRes.
0x0CTIM_DIERRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.UDERes.Res.Res.Res.Res.Res.Res.UIE
Reset value00
0x10TIM_SRRes.Res.Res.Res.Res.Res.Res.UIOVRFRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.UIF
Reset value00
0x14TIM_EGRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.UG
Reset value0
0x18-0x20ReservedRes.
0x24TIM_CNTUIFCPY or Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.CNT[15:0]
Reset value00000000000
0x28TIM_PSCRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.PSC[15:0]
Reset value0000000000
0x2CTIM_ARRRes.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.Res.ARR[19:0]
Reset value00001111111111111111

Refer to Section 2.2: Memory organization for the register boundary addresses.