Registered User mNo edit summary |
Registered User Tag: 2017 source edit |
||
(64 intermediate revisions by 9 users not shown) | |||
Line 1: | Line 1: | ||
<noinclude>{{ApplicableFor | |||
|MPUs list=STM32MP13x, STM32MP15x, STM32MP21x, STM32MP23x, STM32MP25x | |||
|MPUs checklist=STM32MP13x, STM32MP15x, STM32MP21x, STM32MP23x, STM32MP25x | |||
}} | |||
</noinclude> | |||
==Article purpose== | ==Article purpose== | ||
The purpose of this article is to | The purpose of this article is to: | ||
* briefly introduce the | * briefly introduce the TIM peripheral and its main features, | ||
* indicate the | * indicate the peripheral instances assignment at boot time and their assignment at runtime (including whether instances can be allocated to secure contexts), | ||
* list the software frameworks and drivers managing the peripheral, | |||
* explain how to configure the | * explain how to configure the peripheral. | ||
==Peripheral overview== | ==Peripheral overview== | ||
The TIM peripheral is a multi-channel timer unit, available in various configurations, depending on the instance used. There are basically following categories: advanced-control timers, general-purpose timers and basic timers. | The '''TIM''' peripheral is a multi-channel timer unit, available in various configurations, depending on the instance used. There are basically following categories: advanced-control timers, general-purpose timers and basic timers. | ||
The TIM can provide: PWM with complementary output and dead-time insertion, break detection, | The TIM can provide: PWM with complementary output and dead-time insertion, break detection, | ||
input capture<ref name="input_capture">[https://en.wikipedia.org/wiki/Input_capture Input capture]</ref>, | input capture<ref name="input_capture">[https://en.wikipedia.org/wiki/Input_capture Input capture]</ref>, | ||
quadrature encoder<ref name="quadrature_encoder">[https://en.wikipedia.org/wiki/Rotary_encoder#Incremental_encoder Quadrature encoder]</ref> interface (typically used for rotary encoders), trigger source for other internal peripherals like: ADC<ref name="adc_internal">[[ADC | quadrature encoder<ref name="quadrature_encoder">[https://en.wikipedia.org/wiki/Rotary_encoder#Incremental_encoder Quadrature encoder]</ref> interface (typically used for rotary encoders), trigger source for other internal peripherals like: ADC<ref name="adc_internal">[[ADC internal peripheral]]</ref>, DFSDM<ref name="dfsdm_internal">[[DFSDM internal peripheral]]</ref>. The full list can be found in Peripherals Interconnect matrix in the reference manual. | ||
The | The TIM peripheral is available in different configurations, depending on the selected instance : | ||
{| class="st-table" style="width: 100%;" | |||
|- style="background: {{STLightGrey}};" | |||
! style="width:16%; | TIM type | |||
! style="width:16%; | TIM instances | |||
Refer to [[ | ! style="width:16%; | Independent Channels | ||
! style="width:16%; | PWM | |||
! style="width:16%;" | External event counter <br/>Trigger source | |||
! style="width:16%;" | Quadrature encoder | |||
|- | |||
| advanced-control timers | |||
| TIM1/TIM8 || 6 || {{Y}} || {{Y}} || {{Y}} | |||
|- | |||
| rowspan="5" | general-purpose timers | |||
| TIM2/TIM3/TIM4/TIM5 || 4 || {{Y}} || {{Y}} || {{Y}} | |||
|- | |||
| style="border-bottom-style: dashed; border-bottom-color: {{STMediumGrey}};" | TIM12 || 2 || {{Y}} || {{Y}} || | |||
|- | |||
| TIM13/TIM14 || 1 || {{Y}} || || | |||
|- | |||
| style="border-bottom-style: dashed; border-bottom-color: {{STMediumGrey}};" | TIM15 || 2 || {{Y}} || {{Y}} || | |||
|- | |||
| TIM16/TIM17 || 1 || {{Y}} || || | |||
|- | |||
| basic timers | |||
| TIM6/TIM7 || || || || | |||
|} | |||
{{Info | Compare to TIM12, TIM13 and TIM14, the configuration of TIM15, TIM16 and TIM17 brings some features that are very useful for motor control (like break function, DMA burst mode control, complementary output with dead-time insertion, ...)}} | |||
===Additional instances to {{MicroprocessorDevice | device=2}} === | |||
{| class="st-table" style="width: 100%;" | |||
|- style="background: {{STLightGrey}};" | |||
! style="width:16%; | TIM type | |||
! style="width:16%; | TIM instances | |||
! style="width:16%; | Independent Channels | |||
! style="width:16%; | PWM | |||
! style="width:16%;" | External event counter <br/>Trigger source | |||
! style="width:16%;" | Quadrature encoder | |||
|- | |||
| general-purpose timers || TIM10/TIM11 || 1 || {{Y}} || || | |||
|} | |||
====Additional instances to {{MicroprocessorDevice | device=25}}==== | |||
{| class="st-table" style="width: 100%;" | |||
|- style="background: {{STLightGrey}};" | |||
! style="width:16%; | TIM type | |||
! style="width:16%; | TIM instances | |||
! style="width:16%; | Independent Channels | |||
! style="width:16%; | PWM | |||
! style="width:16%;" | External event counter <br/>Trigger source | |||
! style="width:16%;" | Quadrature encoder | |||
|- | |||
| advanced-control timers || TIM20 || 6 || {{Y}} || {{Y}} || {{Y}} | |||
|} | |||
Refer to the [[STM32 MPU resources#Reference manuals|STM32 MPU reference manuals]] for the complete list of features, and to the software frameworks and drivers, introduced below, to see which features are implemented. | |||
==Peripheral usage== | |||
This chapter is applicable in the scope of the '''OpenSTLinux BSP''' running on the Arm<sup>®</sup> Cortex<sup>®</sup>-A processor(s), and the '''FwST-M Package''' running on the Arm<sup>®</sup> Cortex<sup>®</sup>-M processor. | |||
===Boot time assignment=== | |||
====On {{MicroprocessorDevice | device=13}}==== | |||
{{#lst:STM32MP1_internal_peripherals_assignment_table_template|stm32mp1_boottime}} | |||
<section begin=stm32mp13_boottime /> | |||
| rowspan="3" | Core/Timers | |||
| rowspan="3" | [[TIM internal peripheral | TIM]] | |||
| TIMx (x = 1 to 8,<br/>APB2 group) | |||
| | |||
| | |||
| <span title="assignable peripheral" style="font-size:21px">☐</span> | |||
| | |||
|- | |||
| TIMx (x = 2 to 7,<br/>APB1 group) | |||
| | |||
| | |||
| <span title="assignable peripheral" style="font-size:21px">☐</span> | |||
| | |||
|- | |||
| TIMx (x = 12 to 17,<br/>APB6 group) | |||
| | |||
| <span title="assignable peripheral but not supported" style="font-size:21px">⬚</span> | |||
| <span title="assignable peripheral" style="font-size:21px">☐</span> | |||
| | |||
|- | |||
<section end=stm32mp13_boottime /> | |||
|} | |||
====On {{MicroprocessorDevice | device=15}}==== | |||
{{#lst:STM32MP1_internal_peripherals_assignment_table_template|stm32mp1_boottime}} | |||
<section begin=stm32mp15_boottime /> | |||
| rowspan="2" | Core/Timers | |||
| rowspan="2" | [[TIM internal peripheral | TIM]] | |||
| TIMx (x = 2 to 7, 12, 13, 14. APB1 group) | |||
| | |||
| | |||
| <span title="assignable peripheral" style="font-size:21px">☐</span> | |||
| | |||
|- | |||
| TIMx (x = 1, 8, 15, 16, 17. APB2 group) | |||
| | |||
| | |||
| <span title="assignable peripheral" style="font-size:21px">☐</span> | |||
| | |||
|- | |||
<section end=stm32mp15_boottime /> | |||
|} | |||
====On {{MicroprocessorDevice | device=21}} and {{MicroprocessorDevice | device=23}}==== | |||
=====For {{TrustedDomainFlavor|flavor=A35-TD}}===== | |||
{{#lst:STM32MP2_internal_peripherals_assignment_table_template|stm32mp2_a35_boottime}} | |||
<section begin=stm32mp21_a35_boottime /><section begin=stm32mp23_a35_boottime /> | |||
| rowspan="1" | Core/Timers | |||
| rowspan="1" | [[TIM internal peripheral | TIM]] | |||
| TIMx (x = 1 to 8, 10 to 17) | |||
| | |||
| <span title="assignable peripheral but not supported" style="font-size:21px">⬚</span> | |||
| <span title="assignable peripheral" style="font-size:21px">☐</span> | |||
| | |||
|- | |||
<section end=stm32mp21_a35_boottime /><section end=stm32mp23_a35_boottime /> | |||
|} | |||
=====For {{TrustedDomainFlavor|flavor=M33-TD}}===== | |||
{{#lst:STM32MP2_internal_peripherals_assignment_table_template|stm32mp2_m33_boottime}} | |||
<section begin=stm32mp21_m33_boottime /><section begin=stm32mp23_m33_boottime /> | |||
| rowspan="1" | Core/Timers | |||
| rowspan="1" | [[TIM internal peripheral | TIM]] | |||
| TIMx (x = 1 to 8, 10 to 17) | |||
| | |||
| <span title="assignable peripheral but not supported" style="font-size:21px">⬚</span> | |||
| <span title="assignable peripheral" style="font-size:21px">☐</span> | |||
| <span title="assignable peripheral but not supported" style="font-size:21px">⬚</span> | |||
| | |||
|- | |||
<section end=stm32mp21_m33_boottime /><section end=stm32mp23_m33_boottime /> | |||
|} | |||
====On {{MicroprocessorDevice | device=25}}==== | |||
=====For {{TrustedDomainFlavor|flavor=A35-TD}}===== | |||
{{#lst:STM32MP2_internal_peripherals_assignment_table_template|stm32mp2_a35_boottime}} | |||
<section begin=stm32mp25_a35_boottime /> | |||
| rowspan="1" | Core/Timers | |||
| rowspan="1" | [[TIM internal peripheral | TIM]] | |||
| TIMx (x = 1 to 8, 10 to 17, 20) | |||
| | |||
| <span title="assignable peripheral but not supported" style="font-size:21px">⬚</span> | |||
| <span title="assignable peripheral" style="font-size:21px">☐</span> | |||
| | |||
|- | |||
<section end=stm32mp25_a35_boottime /> | |||
|} | |||
=====For {{TrustedDomainFlavor|flavor=M33-TD}}===== | |||
{{#lst:STM32MP2_internal_peripherals_assignment_table_template|stm32mp2_m33_boottime}} | |||
<section begin=stm32mp25_m33_boottime /> | |||
| rowspan="1" | Core/Timers | |||
| rowspan="1" | [[TIM internal peripheral | TIM]] | |||
| TIMx (x = 1 to 8, 10 to 17, 20) | |||
| | |||
| <span title="assignable peripheral but not supported" style="font-size:21px">⬚</span> | |||
| <span title="assignable peripheral" style="font-size:21px">☐</span> | |||
| <span title="assignable peripheral but not supported" style="font-size:21px">⬚</span> | |||
| | |||
|- | |||
<section end=stm32mp25_m33_boottime /> | |||
|} | |||
===Runtime assignment=== | |||
====On {{MicroprocessorDevice | device=13}}==== | |||
'''TIM12''' and/or '''TIM15''' can be allocated to the Arm<sup>®</sup> Cortex<sup>®</sup>-A7 secure core to be controlled in the secure monitor ([[STM32 MPU OP-TEE overview|OP-TEE]]).<br /> | |||
'''TIM13''', '''TIM14''', '''TIM16''' and '''TIM17''' can also be allocated to the Arm<sup>®</sup> Cortex<sup>®</sup>-A7 secure context, but it is not supported yet by OpenSTLinux.<br> | |||
{{Info | RCC<ref name="rcc">[[RCC internal peripheral]]</ref> owns one prescaler per '''TIM group''' corresponding to '''APB1''', '''APB2''' and '''APB6''' buses: TIMG1PRE, TIMG2PRE and TIMG3PRE, respectively. TIMG3PRE is securable in RCC. The allocation to Cortex-A7 contexts should ideally be done on a per group basis to get independent clocking setup on each side, this is why the TIM instances groups are shown in the summary table below.}} | |||
{{#lst:STM32MP1_internal_peripherals_assignment_table_template|stm32mp13_runtime}} | |||
<section begin=stm32mp13_runtime /> | |||
| rowspan="14" | Core/Timers | |||
| rowspan="14" | [[TIM internal peripheral|TIM]] | |||
| TIM1 (APB2 group) | |||
| | |||
| <span title="assignable peripheral" style="font-size:21px">☐</span> | |||
| | |||
|- | |||
| TIM2 (APB1 group) | |||
| | |||
| <span title="assignable peripheral" style="font-size:21px">☐</span> | |||
| | |||
|- | |||
| TIM3 (APB1 group) | |||
| | |||
| <span title="assignable peripheral" style="font-size:21px">☐</span> | |||
| | |||
|- | |||
| TIM4 (APB1 group) | |||
| | |||
| <span title="assignable peripheral" style="font-size:21px">☐</span> | |||
| | |||
|- | |||
| TIM5 (APB1 group) | |||
| | |||
| <span title="assignable peripheral" style="font-size:21px">☐</span> | |||
| | |||
|- | |||
| TIM6 (APB1 group) | |||
| | |||
| <span title="assignable peripheral" style="font-size:21px">☐</span> | |||
| | |||
|- | |||
| TIM7 (APB1 group) | |||
| | |||
| <span title="assignable peripheral" style="font-size:21px">☐</span> | |||
| | |||
|- | |||
| TIM8 (APB2 group) | |||
| | |||
| <span title="assignable peripheral" style="font-size:21px">☐</span> | |||
| | |||
|- | |||
| TIM12 (APB6 group) | |||
| <span title="assignable peripheral" style="font-size:21px">☐</span> | |||
| <span title="assignable peripheral" style="font-size:21px">☐</span> | |||
| Assignment (single choice)<br>TIM12 or TIM15 can be used for HSI/CSI calibration<ref name="calib">[[How to activate internal oscillators calibration]]</ref> | |||
|- | |||
| TIM13 (APB6 group) | |||
| <span title="assignable peripheral" style="font-size:21px">☐</span> | |||
| <span title="assignable peripheral" style="font-size:21px">☐</span> | |||
| Assignment (single choice) | |||
|- | |||
| TIM14 (APB6 group) | |||
| <span title="assignable peripheral" style="font-size:21px">☐</span> | |||
| <span title="assignable peripheral" style="font-size:21px">☐</span> | |||
| Assignment (single choice) | |||
|- | |||
| TIM15 (APB6 group) | |||
| <span title="assignable peripheral" style="font-size:21px">☐</span> | |||
| <span title="assignable peripheral" style="font-size:21px">☐</span> | |||
| Assignment (single choice)<br>TIM12 or TIM15 can be used for HSI/CSI calibration<ref name="calib"/> | |||
|- | |||
| TIM16 (APB6 group) | |||
| <span title="assignable peripheral" style="font-size:21px">☐</span> | |||
| <span title="assignable peripheral" style="font-size:21px">☐</span> | |||
| Assignment (single choice) | |||
|- | |||
| TIM17 (APB6 group) | |||
| <span title="assignable peripheral" style="font-size:21px">☐</span> | |||
| <span title="assignable peripheral" style="font-size:21px">☐</span> | |||
| Assignment (single choice) | |||
|- | |||
<section end=stm32mp13_runtime /> | |||
|} | |||
====On {{MicroprocessorDevice | device=15}}==== | |||
'''TIM12''' and/or '''TIM15''' can be allocated to the Arm<sup>®</sup> Cortex<sup>®</sup>-A7 secure core to be controlled in the secure monitor ([[TF-A overview|TF-A]] or [[STM32 MPU OP-TEE overview|OP-TEE]]).<br /> | |||
{{Info | RCC<ref name="rcc">[[RCC internal peripheral]]</ref> owns one prescaler per '''TIM group''' corresponding to '''APB1''' and '''APB2''' buses: TIMG1PRE and TIMG2PRE, respectively. The allocation to Cortex-A7 or the Cortex-M4 should ideally be done on a per group basis to get independent clocking setup on each side, this is why the TIM instances groups are shown in the summary table below.}} | |||
{{#lst:STM32MP1_internal_peripherals_assignment_table_template|stm32mp15_runtime}} | |||
<section begin=stm32mp15_runtime /> | |||
| rowspan="14" | Core/Timers | |||
| rowspan="14" | [[TIM internal peripheral|TIM]] | |||
| TIM1 (APB2 group) | |||
| | |||
| <span title="assignable peripheral" style="font-size:21px">☐</span> | |||
| <span title="assignable peripheral" style="font-size:21px">☐</span> | |||
| Assignment (single choice) | |||
|- | |||
| TIM2 (APB1 group) | |||
| | |||
| <span title="assignable peripheral" style="font-size:21px">☐</span> | |||
| <span title="assignable peripheral" style="font-size:21px">☐</span> | |||
| Assignment (single choice) | |||
|- | |||
| TIM3 (APB1 group) | |||
| | |||
| <span title="assignable peripheral" style="font-size:21px">☐</span> | |||
| <span title="assignable peripheral" style="font-size:21px">☐</span> | |||
| Assignment (single choice) | |||
|- | |||
| TIM4 (APB1 group) | |||
| | |||
| <span title="assignable peripheral" style="font-size:21px">☐</span> | |||
| <span title="assignable peripheral" style="font-size:21px">☐</span> | |||
| Assignment (single choice) | |||
|- | |||
| TIM5 (APB1 group) | |||
| | |||
| <span title="assignable peripheral" style="font-size:21px">☐</span> | |||
| <span title="assignable peripheral" style="font-size:21px">☐</span> | |||
| Assignment (single choice) | |||
|- | |||
| TIM6 (APB1 group) | |||
| | |||
| <span title="assignable peripheral" style="font-size:21px">☐</span> | |||
| <span title="assignable peripheral" style="font-size:21px">☐</span> | |||
| Assignment (single choice) | |||
|- | |||
| TIM7 (APB1 group) | |||
| | |||
| <span title="assignable peripheral" style="font-size:21px">☐</span> | |||
| <span title="assignable peripheral" style="font-size:21px">☐</span> | |||
| Assignment (single choice) | |||
|- | |||
| TIM8 (APB2 group) | |||
| | |||
| <span title="assignable peripheral" style="font-size:21px">☐</span> | |||
| <span title="assignable peripheral" style="font-size:21px">☐</span> | |||
| Assignment (single choice) | |||
|- | |||
| TIM12 (APB1 group) | |||
| <span title="assignable peripheral" style="font-size:21px">☐</span> | |||
| <span title="assignable peripheral" style="font-size:21px">☐</span> | |||
| <span title="assignable peripheral" style="font-size:21px">☐</span> | |||
| Assignment (single choice)<br>TIM12 or TIM15 can be used for HSI/CSI calibration<ref name="calib">[[How to activate internal oscillators calibration]]</ref> | |||
|- | |||
| TIM13 (APB1 group) | |||
| | |||
| <span title="assignable peripheral" style="font-size:21px">☐</span> | |||
| <span title="assignable peripheral" style="font-size:21px">☐</span> | |||
| Assignment (single choice) | |||
|- | |||
| TIM14 (APB1 group) | |||
| | |||
| <span title="assignable peripheral" style="font-size:21px">☐</span> | |||
| <span title="assignable peripheral" style="font-size:21px">☐</span> | |||
| Assignment (single choice) | |||
|- | |||
| TIM15 (APB2 group) | |||
| <span title="assignable peripheral" style="font-size:21px">☐</span> | |||
| <span title="assignable peripheral" style="font-size:21px">☐</span> | |||
| <span title="assignable peripheral" style="font-size:21px">☐</span> | |||
| Assignment (single choice)<br>TIM12 or TIM15 can be used for HSI/CSI calibration<ref name="calib"/> | |||
|- | |||
| TIM16 (APB2 group) | |||
| | |||
| <span title="assignable peripheral" style="font-size:21px">☐</span> | |||
| <span title="assignable peripheral" style="font-size:21px">☐</span> | |||
| Assignment (single choice) | |||
|- | |||
| TIM17 (APB2 group) | |||
| | |||
| <span title="assignable peripheral" style="font-size:21px">☐</span> | |||
| <span title="assignable peripheral" style="font-size:21px">☐</span> | |||
| Assignment (single choice) | |||
|- | |||
<section end=stm32mp15_runtime /> | |||
|} | |||
====On {{MicroprocessorDevice | device=21}} and {{MicroprocessorDevice | device=23}}==== | |||
= | The tables below are applicable to any {{TrustedDomainFlavor | flavor=Any-TD}}. | ||
== | {{#lst:STM32MP2_internal_peripherals_assignment_table_template|stm32mp21_23_runtime}} | ||
=== | <section begin=stm32mp21_a35_runtime /><section begin=stm32mp21_m33_runtime /><section begin=stm32mp23_a35_runtime /><section begin=stm32mp23_m33_runtime /> | ||
| rowspan="1" | Core/Timers | |||
| rowspan="1" | [[TIM internal peripheral | TIM]] | |||
| TIMx (x = 1 to 8, 10 to 17) | |||
| <span title="assignable peripheral but not supported" style="font-size:21px">⬚</span><sup>OP-TEE</sup> | |||
| <span title="assignable peripheral" style="font-size:21px">☐</span> | |||
| <span title="assignable peripheral but not supported" style="font-size:21px">⬚</span> | |||
| <span title="assignable peripheral" style="font-size:21px">☐</span> | |||
| | |||
|- | |||
<section end=stm32mp21_a35_runtime /><section end=stm32mp21_m33_runtime /><section end=stm32mp23_a35_runtime /><section end=stm32mp23_m33_runtime /> | |||
|} | |||
= | ====On {{MicroprocessorDevice | device=25}} ==== | ||
==== | |||
The tables below are applicable to any {{TrustedDomainFlavor | flavor=Any-TD}}. | |||
{{#lst:STM32MP2_internal_peripherals_assignment_table_template|stm32mp25_runtime}} | |||
{{: | <section begin=stm32mp25_a35_runtime /><section begin=stm32mp25_m33_runtime /> | ||
| rowspan="1" | Core/Timers | |||
| rowspan="1" | [[TIM internal peripheral | TIM]] | |||
| TIMx (x = 1 to 8, 10 to 17, 20) | |||
| <span title="assignable peripheral but not supported" style="font-size:21px">⬚</span><sup>OP-TEE</sup> | |||
| <span title="assignable peripheral" style="font-size:21px">☐</span> | |||
| <span title="assignable peripheral but not supported" style="font-size:21px">⬚</span> | |||
| <span title="assignable peripheral" style="font-size:21px">☐</span> | |||
| | |||
| | |||
|- | |||
<section end=stm32mp25_a35_runtime /><section end=stm32mp25_m33_runtime /> | |||
|} | |||
== | ==Software frameworks and drivers== | ||
Below are listed the software frameworks and drivers managing the TIM peripheral for the embedded software components listed in the above tables. | |||
* '''Linux<sup>®</sup>''': [[PWM overview|PWM]], the [[IIO overview|IIO]], and the ''Counter'' frameworks | |||
* '''OP-TEE''': {{CodeSource | OP-TEE_OS | core/drivers/counter/stm32_tim.c | OP-TEE TIM driver}}, to perform HSI and CSI calibrations<ref name="calib"/> in [[RCC internal peripheral|RCC]] | |||
* '''U-Boot''': {{CodeSource | U-Boot | drivers/pwm/pwm-stm32.c | PWM driver}}, typically used for a PWM backlight | |||
* '''STM32Cube''': {{CodeSource | STM32CubeMP1 | Drivers/STM32MP1xx_HAL_Driver/Src/stm32mp1xx_hal_tim.c | HAL TIM driver}} | |||
==== | ==How to assign and configure the peripheral== | ||
The peripheral assignment can be done via the [[STM32CubeMX]] graphical tool (and manually completed if needed).<br /> | |||
This tool also helps to configure the peripheral: | |||
* partial device trees (pin control and clock tree) generation for the OpenSTLinux software components, | |||
* HAL initialization code generation for the STM32CubeMPU Package. | |||
The configuration is applied by the firmware running in the context in which the peripheral is assigned. | |||
For Linux kernel configuration, please refer to [[TIM device tree configuration]] and [[TIM_OpenSTLinux_drivers]] articles. | |||
==How to go further== | ==How to go further== | ||
STM32 cross-series timer overview<ref name="stm32_cross_series_timer_overview">[http://www.st.com/content/ccc/resource/technical/document/application_note/54/0f/67/eb/47/34/45/40/DM00042534.pdf/files/DM00042534.pdf/jcr:content/translations/en.DM00042534.pdf STM32 cross-series timer overview application note]</ref> application note. | STM32 cross-series timer overview<ref name="stm32_cross_series_timer_overview">[http://www.st.com/content/ccc/resource/technical/document/application_note/54/0f/67/eb/47/34/45/40/DM00042534.pdf/files/DM00042534.pdf/jcr:content/translations/en.DM00042534.pdf STM32 cross-series timer overview application note]</ref> application note. | ||
Latest revision as of 10:34, 26 June 2025
1. Article purpose[edit | edit source]
The purpose of this article is to:
- briefly introduce the TIM peripheral and its main features,
- indicate the peripheral instances assignment at boot time and their assignment at runtime (including whether instances can be allocated to secure contexts),
- list the software frameworks and drivers managing the peripheral,
- explain how to configure the peripheral.
2. Peripheral overview[edit | edit source]
The TIM peripheral is a multi-channel timer unit, available in various configurations, depending on the instance used. There are basically following categories: advanced-control timers, general-purpose timers and basic timers.
The TIM can provide: PWM with complementary output and dead-time insertion, break detection, input capture[1], quadrature encoder[2] interface (typically used for rotary encoders), trigger source for other internal peripherals like: ADC[3], DFSDM[4]. The full list can be found in Peripherals Interconnect matrix in the reference manual.
The TIM peripheral is available in different configurations, depending on the selected instance :
TIM type | TIM instances | Independent Channels | PWM | External event counter Trigger source |
Quadrature encoder |
---|---|---|---|---|---|
advanced-control timers | TIM1/TIM8 | 6 | ![]() |
![]() |
![]() |
general-purpose timers | TIM2/TIM3/TIM4/TIM5 | 4 | ![]() |
![]() |
![]() |
TIM12 | 2 | ![]() |
![]() |
||
TIM13/TIM14 | 1 | ![]() |
|||
TIM15 | 2 | ![]() |
![]() |
||
TIM16/TIM17 | 1 | ![]() |
|||
basic timers | TIM6/TIM7 |
![]() |
Compare to TIM12, TIM13 and TIM14, the configuration of TIM15, TIM16 and TIM17 brings some features that are very useful for motor control (like break function, DMA burst mode control, complementary output with dead-time insertion, ...) |
2.1. Additional instances to STM32MP2 series[edit | edit source]
TIM type | TIM instances | Independent Channels | PWM | External event counter Trigger source |
Quadrature encoder |
---|---|---|---|---|---|
general-purpose timers | TIM10/TIM11 | 1 | ![]() |
2.1.1. Additional instances to STM32MP25x lines
[edit | edit source]
TIM type | TIM instances | Independent Channels | PWM | External event counter Trigger source |
Quadrature encoder |
---|---|---|---|---|---|
advanced-control timers | TIM20 | 6 | ![]() |
![]() |
![]() |
Refer to the STM32 MPU reference manuals for the complete list of features, and to the software frameworks and drivers, introduced below, to see which features are implemented.
3. Peripheral usage[edit | edit source]
This chapter is applicable in the scope of the OpenSTLinux BSP running on the Arm® Cortex®-A processor(s), and the FwST-M Package running on the Arm® Cortex®-M processor.
3.1. Boot time assignment[edit | edit source]
3.1.1. On STM32MP13x lines
[edit | edit source]
Click on to expand or collapse the legend...
Domain | Peripheral | Boot time allocation | Comment ![]() | |||
---|---|---|---|---|---|---|
Instance | Cortex-A7 secure (ROM code) |
Cortex-A7 secure (TF-A BL2) |
Cortex-A7 nonsecure (U-Boot) | |||
Core/Timers | TIM | TIMx (x = 1 to 8, APB2 group) |
☐ | |||
TIMx (x = 2 to 7, APB1 group) |
☐ | |||||
TIMx (x = 12 to 17, APB6 group) |
⬚ | ☐ |
3.1.2. On STM32MP15x lines
[edit | edit source]
Click on to expand or collapse the legend...
Domain | Peripheral | Boot time allocation | Comment ![]() | |||
---|---|---|---|---|---|---|
Instance | Cortex-A7 secure (ROM code) |
Cortex-A7 secure (TF-A BL2) |
Cortex-A7 nonsecure (U-Boot) | |||
Core/Timers | TIM | TIMx (x = 2 to 7, 12, 13, 14. APB1 group) | ☐ | |||
TIMx (x = 1, 8, 15, 16, 17. APB2 group) | ☐ |
3.1.3. On STM32MP21x lines
and STM32MP23x lines
[edit | edit source]
3.1.3.1. For A35-TD flavor
[edit | edit source]
Click on to expand or collapse the legend...
Domain | Peripheral | Boot time allocation | Comment ![]() | |||
---|---|---|---|---|---|---|
Instance | Cortex-A35 secure (ROM code) |
Cortex-A35 secure (TF-A BL2) |
Cortex-A35 nonsecure (U-Boot) | |||
Core/Timers | TIM | TIMx (x = 1 to 8, 10 to 17) | ⬚ | ☐ |
3.1.3.2. For M33-TD flavor
[edit | edit source]
Click on to expand or collapse the legend...
Domain | Peripheral | Boot time allocation | Comment ![]() | ||||
---|---|---|---|---|---|---|---|
Instance | Cortex-A35 secure (ROM code) |
Cortex-A35 secure (TF-A BL2) |
Cortex-A35 nonsecure (U-Boot) |
Cortex-M33 secure (MCUboot) | |||
Core/Timers | TIM | TIMx (x = 1 to 8, 10 to 17) | ⬚ | ☐ | ⬚ |
3.1.4. On STM32MP25x lines
[edit | edit source]
3.1.4.1. For A35-TD flavor
[edit | edit source]
Click on to expand or collapse the legend...
Domain | Peripheral | Boot time allocation | Comment ![]() | |||
---|---|---|---|---|---|---|
Instance | Cortex-A35 secure (ROM code) |
Cortex-A35 secure (TF-A BL2) |
Cortex-A35 nonsecure (U-Boot) | |||
Core/Timers | TIM | TIMx (x = 1 to 8, 10 to 17, 20) | ⬚ | ☐ |
3.1.4.2. For M33-TD flavor
[edit | edit source]
Click on to expand or collapse the legend...
Domain | Peripheral | Boot time allocation | Comment ![]() | ||||
---|---|---|---|---|---|---|---|
Instance | Cortex-A35 secure (ROM code) |
Cortex-A35 secure (TF-A BL2) |
Cortex-A35 nonsecure (U-Boot) |
Cortex-M33 secure (MCUboot) | |||
Core/Timers | TIM | TIMx (x = 1 to 8, 10 to 17, 20) | ⬚ | ☐ | ⬚ |
3.2. Runtime assignment[edit | edit source]
3.2.1. On STM32MP13x lines
[edit | edit source]
TIM12 and/or TIM15 can be allocated to the Arm® Cortex®-A7 secure core to be controlled in the secure monitor (OP-TEE).
TIM13, TIM14, TIM16 and TIM17 can also be allocated to the Arm® Cortex®-A7 secure context, but it is not supported yet by OpenSTLinux.
![]() |
RCC[5] owns one prescaler per TIM group corresponding to APB1, APB2 and APB6 buses: TIMG1PRE, TIMG2PRE and TIMG3PRE, respectively. TIMG3PRE is securable in RCC. The allocation to Cortex-A7 contexts should ideally be done on a per group basis to get independent clocking setup on each side, this is why the TIM instances groups are shown in the summary table below. |
Click on to expand or collapse the legend...
Domain | Peripheral | Runtime allocation | Comment ![]() | ||
---|---|---|---|---|---|
Instance | Cortex-A7 secure (OP-TEE) |
Cortex-A7 nonsecure (Linux) | |||
Core/Timers | TIM | TIM1 (APB2 group) | ☐ | ||
TIM2 (APB1 group) | ☐ | ||||
TIM3 (APB1 group) | ☐ | ||||
TIM4 (APB1 group) | ☐ | ||||
TIM5 (APB1 group) | ☐ | ||||
TIM6 (APB1 group) | ☐ | ||||
TIM7 (APB1 group) | ☐ | ||||
TIM8 (APB2 group) | ☐ | ||||
TIM12 (APB6 group) | ☐ | ☐ | Assignment (single choice) TIM12 or TIM15 can be used for HSI/CSI calibration[6] | ||
TIM13 (APB6 group) | ☐ | ☐ | Assignment (single choice) | ||
TIM14 (APB6 group) | ☐ | ☐ | Assignment (single choice) | ||
TIM15 (APB6 group) | ☐ | ☐ | Assignment (single choice) TIM12 or TIM15 can be used for HSI/CSI calibration[6] | ||
TIM16 (APB6 group) | ☐ | ☐ | Assignment (single choice) | ||
TIM17 (APB6 group) | ☐ | ☐ | Assignment (single choice) |
3.2.2. On STM32MP15x lines
[edit | edit source]
TIM12 and/or TIM15 can be allocated to the Arm® Cortex®-A7 secure core to be controlled in the secure monitor (TF-A or OP-TEE).
![]() |
RCC[5] owns one prescaler per TIM group corresponding to APB1 and APB2 buses: TIMG1PRE and TIMG2PRE, respectively. The allocation to Cortex-A7 or the Cortex-M4 should ideally be done on a per group basis to get independent clocking setup on each side, this is why the TIM instances groups are shown in the summary table below. |
Click on to expand or collapse the legend...
Domain | Peripheral | Runtime allocation | Comment ![]() | |||
---|---|---|---|---|---|---|
Instance | Cortex-A7 secure (OP-TEE) |
Cortex-A7 nonsecure (Linux) |
Cortex-M4 (STM32Cube) | |||
Core/Timers | TIM | TIM1 (APB2 group) | ☐ | ☐ | Assignment (single choice) | |
TIM2 (APB1 group) | ☐ | ☐ | Assignment (single choice) | |||
TIM3 (APB1 group) | ☐ | ☐ | Assignment (single choice) | |||
TIM4 (APB1 group) | ☐ | ☐ | Assignment (single choice) | |||
TIM5 (APB1 group) | ☐ | ☐ | Assignment (single choice) | |||
TIM6 (APB1 group) | ☐ | ☐ | Assignment (single choice) | |||
TIM7 (APB1 group) | ☐ | ☐ | Assignment (single choice) | |||
TIM8 (APB2 group) | ☐ | ☐ | Assignment (single choice) | |||
TIM12 (APB1 group) | ☐ | ☐ | ☐ | Assignment (single choice) TIM12 or TIM15 can be used for HSI/CSI calibration[6] | ||
TIM13 (APB1 group) | ☐ | ☐ | Assignment (single choice) | |||
TIM14 (APB1 group) | ☐ | ☐ | Assignment (single choice) | |||
TIM15 (APB2 group) | ☐ | ☐ | ☐ | Assignment (single choice) TIM12 or TIM15 can be used for HSI/CSI calibration[6] | ||
TIM16 (APB2 group) | ☐ | ☐ | Assignment (single choice) | |||
TIM17 (APB2 group) | ☐ | ☐ | Assignment (single choice) |
3.2.3. On STM32MP21x lines
and STM32MP23x lines
[edit | edit source]
The tables below are applicable to any TD flavor (A35-TD or M33-TD) .
Click on to expand or collapse the legend...
Domain | Peripheral | Runtime allocation | Comment ![]() | ||||
---|---|---|---|---|---|---|---|
Instance | Cortex-A35 secure (OP-TEE / TF-A BL31) |
Cortex-A35 nonsecure (Linux) |
Cortex-M33 secure (TF-M) |
Cortex-M33 nonsecure (STM32Cube) | |||
Core/Timers | TIM | TIMx (x = 1 to 8, 10 to 17) | ⬚OP-TEE | ☐ | ⬚ | ☐ |
3.2.4. On STM32MP25x lines
[edit | edit source]
The tables below are applicable to any TD flavor (A35-TD or M33-TD) .
Click on to expand or collapse the legend...
Domain | Peripheral | Runtime allocation | Comment ![]() | |||||
---|---|---|---|---|---|---|---|---|
Instance | Cortex-A35 secure (OP-TEE / TF-A BL31) |
Cortex-A35 nonsecure (Linux) |
Cortex-M33 secure (TF-M) |
Cortex-M33 nonsecure (STM32Cube) |
Cortex-M0+ (STM32Cube) | |||
Core/Timers | TIM | TIMx (x = 1 to 8, 10 to 17, 20) | ⬚OP-TEE | ☐ | ⬚ | ☐ |
4. Software frameworks and drivers[edit | edit source]
Below are listed the software frameworks and drivers managing the TIM peripheral for the embedded software components listed in the above tables.
- Linux®: PWM, the IIO, and the Counter frameworks
- OP-TEE: OP-TEE TIM driver , to perform HSI and CSI calibrations[6] in RCC
- U-Boot: PWM driver , typically used for a PWM backlight
- STM32Cube: HAL TIM driver
5. How to assign and configure the peripheral[edit | edit source]
The peripheral assignment can be done via the STM32CubeMX graphical tool (and manually completed if needed).
This tool also helps to configure the peripheral:
- partial device trees (pin control and clock tree) generation for the OpenSTLinux software components,
- HAL initialization code generation for the STM32CubeMPU Package.
The configuration is applied by the firmware running in the context in which the peripheral is assigned.
For Linux kernel configuration, please refer to TIM device tree configuration and TIM_OpenSTLinux_drivers articles.
6. How to go further[edit | edit source]
STM32 cross-series timer overview[7] application note.
7. References[edit | edit source]