RM0091
Reference manual
STM32F0x1/STM32F0x2/STM32F0x8
advanced ARM-based 32-bit MCUs
Introduction
This reference manual targets application developers. It provides complete information on
how to use the STM32F0x1/STM32F0x2/STM32F0x8 microcontroller memory and
peripherals.
It applies to the STM32F031x4/x6, STM32F051x4/x6/x8, STM32F071x8/xB,
STM32F042x4/x6, STM32F072x8/xB, STM32F038x6, STM32F048x6, STM32F058x8 and
STM32F078xB devices.
For the purpose of this manual, STM32F0x1/STM32F0x2/STM32F0x8 microcontrollers are
referred to as STM32F0xx.
The STM32F0xx is a family of microcontrollers with different memory sizes, packages and
peripherals.
For ordering information, mechanical and electrical device characteristics, please refer to
the corresponding datasheet.
For information on the ARM CORTEX-M0 core, please refer to the Cortex-M0 technical
reference manual.
Related documents
Cortex-M0 technical reference manual, available from: http://infocenter.arm.com
STM32F0xx Cortex-M0 programming manual (PM0215)
STM32F0xx datasheets available from our website: http://www.st.com
May 2014
DocID018940 Rev 6
1/988
www.st.com
Contents
RM0091
Contents
1
Documentation conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
1.1
List of abbreviations for registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
1.2
Glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
1.3
Peripheral availability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
System and memory overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
2.1
System architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
2.2
Memory organization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
2.2.2
Memory map and register boundary addresses . . . . . . . . . . . . . . . . . . 46
2.3
Embedded SRAM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
2.4
Flash memory overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
2.5
Boot configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Embedded Flash memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
3.1
Flash main features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
3.2
Flash memory functional description . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
3.3
2/988
2.2.1
3.2.1
Flash memory organization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
3.2.2
Read operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
3.2.3
Flash program and erase operations . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
Memory protection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
3.3.1
Read protection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
3.3.2
Write protection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
3.3.3
Option byte write protection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
3.4
Flash interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
3.5
Flash register description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
3.5.1
Flash access control register (FLASH_ACR) . . . . . . . . . . . . . . . . . . . . 66
3.5.2
Flash key register (FLASH_KEYR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
3.5.3
Flash option key register (FLASH_OPTKEYR) . . . . . . . . . . . . . . . . . . . 67
3.5.4
Flash status register (FLASH_SR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
3.5.5
Flash control register (FLASH_CR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
3.5.6
Flash address register (FLASH_AR) . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
3.5.7
Flash Option byte register (FLASH_OBR) . . . . . . . . . . . . . . . . . . . . . . . 70
DocID018940 Rev 6
RM0091
Contents
Write protection register (FLASH_WRPR) . . . . . . . . . . . . . . . . . . . . . . . 71
3.5.9
Flash register map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
Option bytes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
4.1
3.5.8
Option byte description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
4.1.1
User and read protection option bytes . . . . . . . . . . . . . . . . . . . . . . . . . . 74
4.1.2
User data option bytes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
4.1.3
Write protection option bytes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
4.1.4
Option byte map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
Cyclic redundancy check calculation unit (CRC) . . . . . . . . . . . . . . . . . 77
5.1
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
5.2
CRC main features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
5.3
CRC functional description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
5.4
CRC registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
5.4.1
Data register (CRC_DR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
5.4.2
Independent data register (CRC_IDR) . . . . . . . . . . . . . . . . . . . . . . . . . 80
5.4.3
Control register (CRC_CR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
5.4.4
Initial CRC value (CRC_INIT) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
5.4.5
CRC polynomial (CRC_POL) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
5.4.6
CRC register map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
Power control (PWR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
6.1
6.2
6.3
Power supplies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
6.1.1
Independent A/D and D/A converter supply and reference voltage . . . . 84
6.1.2
Independent I/O supply rail . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
6.1.3
Battery backup domain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
6.1.4
Voltage regulator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
Power supply supervisor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
6.2.1
Power on reset (POR) / power down reset (PDR) . . . . . . . . . . . . . . . . . 85
6.2.2
Programmable voltage detector (PVD) . . . . . . . . . . . . . . . . . . . . . . . . . 86
Low-power modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
6.3.1
Slowing down system clocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
6.3.2
Peripheral clock gating . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
6.3.3
Sleep mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
6.3.4
Stop mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
DocID018940 Rev 6
3/988
Contents
RM0091
6.4
Standby mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
6.3.6
Auto-wakeup from low-power mode . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
Power control registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
6.4.1
Power control register (PWR_CR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
6.4.2
Power control/status register (PWR_CSR) . . . . . . . . . . . . . . . . . . . . . . 95
6.4.3
PWR register map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
Reset and clock control (RCC) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
7.1
7.2
4/988
6.3.5
Reset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
7.1.1
Power reset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
7.1.2
System reset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
7.1.3
RTC domain reset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
Clocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
7.2.1
HSE clock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
7.2.2
HSI clock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
7.2.3
HSI48 clock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
7.2.4
PLL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
7.2.5
LSE clock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
7.2.6
LSI clock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
7.2.7
System clock (SYSCLK) selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
7.2.8
Clock security system (CSS) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
7.2.9
ADC clock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
7.2.10
RTC clock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
7.2.11
Independent watchdog clock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
7.2.12
Clock-out capability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
7.2.13
Internal/external clock measurement with TIM14 . . . . . . . . . . . . . . . . 109
7.3
Low-power modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .111
7.4
RCC registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
7.4.1
Clock control register (RCC_CR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
7.4.2
Clock configuration register (RCC_CFGR) . . . . . . . . . . . . . . . . . . . . . 115
7.4.3
Clock interrupt register (RCC_CIR) . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
7.4.4
APB peripheral reset register 2 (RCC_APB2RSTR) . . . . . . . . . . . . . . 121
7.4.5
APB peripheral reset register 1 (RCC_APB1RSTR) . . . . . . . . . . . . . . 123
7.4.6
AHB peripheral clock enable register (RCC_AHBENR) . . . . . . . . . . . . 126
7.4.7
APB peripheral clock enable register 2 (RCC_APB2ENR) . . . . . . . . . 127
7.4.8
APB peripheral clock enable register 1 (RCC_APB1ENR) . . . . . . . . . 129
7.4.9
RTC domain control register (RCC_BDCR) . . . . . . . . . . . . . . . . . . . . . 132
DocID018940 Rev 6
RM0091
Contents
7.4.10
Control/status register (RCC_CSR) . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
7.4.11
AHB peripheral reset register (RCC_AHBRSTR) . . . . . . . . . . . . . . . . 136
7.4.12
Clock configuration register 2 (RCC_CFGR2) . . . . . . . . . . . . . . . . . . . 138
7.4.13
Clock configuration register 3 (RCC_CFGR3) . . . . . . . . . . . . . . . . . . . 139
7.4.14
Clock control register 2 (RCC_CR2) . . . . . . . . . . . . . . . . . . . . . . . . . . 141
7.4.15
RCC register map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
Clock recovery system (CRS) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
8.1
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
8.2
CRS main features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
8.3
CRS functional description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
8.3.1
CRS block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
8.3.2
Synchronization input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
8.3.3
Frequency error measurement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
8.3.4
Frequency error evaluation and automatic trimming . . . . . . . . . . . . . . 148
8.3.5
CRS initialization and configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
8.4
CRS low-power modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
8.5
CRS interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
8.6
CRS registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
8.6.1
CRS control register (CRS_CR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
8.6.2
CRS configuration register (CRS_CFGR) . . . . . . . . . . . . . . . . . . . . . . 152
8.6.3
CRS interrupt and status register (CRS_ISR) . . . . . . . . . . . . . . . . . . . 153
8.6.4
CRS interrupt flag clear register (CRS_ICR) . . . . . . . . . . . . . . . . . . . . 155
8.6.5
CRS register map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
General-purpose I/Os (GPIO) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
9.1
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
9.2
GPIO main features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
9.3
GPIO functional description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
9.3.1
General-purpose I/O (GPIO) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
9.3.2
I/O pin alternate function multiplexer and mapping . . . . . . . . . . . . . . . 159
9.3.3
I/O port control registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160
9.3.4
I/O port data registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160
9.3.5
I/O data bitwise handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
9.3.6
GPIO locking mechanism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
9.3.7
I/O alternate function input/output . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
DocID018940 Rev 6
5/988
Contents
RM0091
9.4
10
External interrupt/wakeup lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
9.3.9
Input configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
9.3.10
Output configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
9.3.11
Alternate function configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
9.3.12
Analog configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
9.3.13
Using the HSE or LSE oscillator pins as GPIOs . . . . . . . . . . . . . . . . . 165
9.3.14
Using the GPIO pins in the RTC supply domain . . . . . . . . . . . . . . . . . 165
GPIO registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
9.4.1
GPIO port mode register (GPIOx_MODER) (x = A..F) . . . . . . . . . . . . 166
9.4.2
GPIO port output type register (GPIOx_OTYPER) (x = A..F) . . . . . . . 166
9.4.3
GPIO port output speed register (GPIOx_OSPEEDR)
(x = A..F) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
9.4.4
GPIO port pull-up/pull-down register (GPIOx_PUPDR)
(x = A..F) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
9.4.5
GPIO port input data register (GPIOx_IDR) (x = A..F) . . . . . . . . . . . . . 168
9.4.6
GPIO port output data register (GPIOx_ODR) (x = A..F) . . . . . . . . . . . 169
9.4.7
GPIO port bit set/reset register (GPIOx_BSRR) (x = A..F) . . . . . . . . . 169
9.4.8
GPIO port configuration lock register (GPIOx_LCKR)
(x = A..B) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
9.4.9
GPIO alternate function low register (GPIOx_AFRL) (x = A..E) . . . . . . 171
9.4.10
GPIO alternate function high register (GPIOx_AFRH)
(x = A..E) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
9.4.11
GPIO port bit reset register (GPIOx_BRR) (x = A..F) . . . . . . . . . . . . . 172
9.4.12
GPIO register map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
System configuration controller (SYSCFG) . . . . . . . . . . . . . . . . . . . . 175
10.1
6/988
9.3.8
SYSCFG registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175
10.1.1
SYSCFG configuration register 1 (SYSCFG_CFGR1) . . . . . . . . . . . . 175
10.1.2
SYSCFG external interrupt configuration register 1
(SYSCFG_EXTICR1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
10.1.3
SYSCFG external interrupt configuration register 2
(SYSCFG_EXTICR2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
10.1.4
SYSCFG external interrupt configuration register 3
(SYSCFG_EXTICR3) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180
10.1.5
SYSCFG external interrupt configuration register 4
(SYSCFG_EXTICR4) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
10.1.6
SYSCFG configuration register 2 (SYSCFG_CFGR2) . . . . . . . . . . . . 182
10.1.7
SYSCFG register maps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
DocID018940 Rev 6
RM0091
11
Contents
Direct memory access controller (DMA) . . . . . . . . . . . . . . . . . . . . . . . 184
11.1
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
11.2
DMA main features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
11.3
DMA functional description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
11.4
12
11.3.1
DMA transactions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
11.3.2
Arbiter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186
11.3.3
DMA channels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186
11.3.4
Programmable data width, data alignment and endians . . . . . . . . . . . 188
11.3.5
Error management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
11.3.6
DMA interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
11.3.7
DMA request mapping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190
DMA registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192
11.4.1
DMA interrupt status register (DMA_ISR) . . . . . . . . . . . . . . . . . . . . . . 192
11.4.2
DMA interrupt flag clear register (DMA_IFCR) . . . . . . . . . . . . . . . . . . 193
11.4.3
DMA channel x configuration register (DMA_CCRx) (x = 1..7,
where x= channel number) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194
11.4.4
DMA channel x number of data register (DMA_CNDTRx) (x = 1..7,
where x= channel number) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196
11.4.5
DMA channel x peripheral address register (DMA_CPARx) (x = 1..7,
where x = channel number) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196
11.4.6
DMA channel x memory address register (DMA_CMARx) (x = 1..7,
where x = channel number) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197
11.4.7
DMA register map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198
Interrupts and events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200
12.1
12.2
12.3
Nested vectored interrupt controller (NVIC) . . . . . . . . . . . . . . . . . . . . . . 200
12.1.1
NVIC main features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200
12.1.2
SysTick calibration value register . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200
12.1.3
Interrupt and exception vectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200
Extended interrupts and events controller (EXTI) . . . . . . . . . . . . . . . . . 202
12.2.1
Main features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202
12.2.2
Block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
12.2.3
Event management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
12.2.4
Functional description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
12.2.5
External and internal interrupt/event line mapping . . . . . . . . . . . . . . . 205
EXTI registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206
12.3.1
Interrupt mask register (EXTI_IMR) . . . . . . . . . . . . . . . . . . . . . . . . . . . 206
DocID018940 Rev 6
7/988
Contents
13
RM0091
12.3.2
Event mask register (EXTI_EMR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207
12.3.3
Rising trigger selection register (EXTI_RTSR) . . . . . . . . . . . . . . . . . . 207
12.3.4
Falling trigger selection register (EXTI_FTSR) . . . . . . . . . . . . . . . . . . 208
12.3.5
Software interrupt event register (EXTI_SWIER) . . . . . . . . . . . . . . . . 208
12.3.6
Pending register (EXTI_PR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209
12.3.7
EXTI register map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210
Analog-to-digital converter (ADC) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211
13.1
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211
13.2
ADC main features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212
13.3
ADC pins and internal signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213
13.4
ADC functional description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214
13.4.1
Calibration (ADCAL) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214
13.4.2
ADC on-off control (ADEN, ADDIS, ADRDY) . . . . . . . . . . . . . . . . . . . . 215
13.4.3
ADC clock (CKMODE) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216
13.4.4
Configuring the ADC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217
13.4.5
Channel selection (CHSEL, SCANDIR) . . . . . . . . . . . . . . . . . . . . . . . . 218
13.4.6
Programmable sampling time (SMP) . . . . . . . . . . . . . . . . . . . . . . . . . . 218
13.4.7
Single conversion mode (CONT=0) . . . . . . . . . . . . . . . . . . . . . . . . . . . 219
13.4.8
Continuous conversion mode (CONT=1) . . . . . . . . . . . . . . . . . . . . . . . 219
13.4.9
Starting conversions (ADSTART) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219
13.4.10 Timings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220
13.4.11 Stopping an ongoing conversion (ADSTP) . . . . . . . . . . . . . . . . . . . . . 221
13.5
13.6
13.7
8/988
Conversion on external trigger and trigger polarity (EXTSEL, EXTEN) . 221
13.5.1
Discontinuous mode (DISCEN) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222
13.5.2
Programmable resolution (RES) - fast conversion mode . . . . . . . . . . 223
13.5.3
End of conversion, end of sampling phase (EOC, EOSMP flags) . . . . 223
13.5.4
End of conversion sequence (EOSEQ flag) . . . . . . . . . . . . . . . . . . . . 225
13.5.5
Example timing diagrams (single/continuous modes . . . . . . . . . . . . . . . . .
hardware/software triggers) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225
Data management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227
13.6.1
Data register and data alignment (ADC_DR, ALIGN) . . . . . . . . . . . . . 227
13.6.2
ADC overrun (OVR, OVRMOD) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227
13.6.3
Managing a sequence of data converted without using the DMA . . . . 228
13.6.4
Managing converted data without using the DMA without overrun . . . 228
13.6.5
Managing converted data using the DMA . . . . . . . . . . . . . . . . . . . . . . 228
Low-power features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230
DocID018940 Rev 6
RM0091
Contents
13.7.1
Wait mode conversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230
13.7.2
Auto-off mode (AUTOFF) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230
13.8
Analog window watchdog (AWDEN, AWDSGL, AWDCH,
AWD_HTR/LTR, AWD) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
13.9
Temperature sensor and internal reference voltage . . . . . . . . . . . . . . . . 233
13.10 Battery voltage monitoring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235
13.11 ADC interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235
13.12 ADC registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236
13.12.1 ADC interrupt and status register (ADC_ISR) . . . . . . . . . . . . . . . . . . . 236
13.12.2 ADC interrupt enable register (ADC_IER) . . . . . . . . . . . . . . . . . . . . . . 237
13.12.3 ADC control register (ADC_CR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238
13.12.4 ADC configuration register 1 (ADC_CFGR1) . . . . . . . . . . . . . . . . . . . . 240
13.12.5 ADC configuration register 2 (ADC_CFGR2) . . . . . . . . . . . . . . . . . . . . 243
13.12.6 ADC sampling time register (ADC_SMPR) . . . . . . . . . . . . . . . . . . . . . 243
13.12.7 ADC watchdog threshold register (ADC_TR) . . . . . . . . . . . . . . . . . . . 244
13.12.8 ADC channel selection register (ADC_CHSELR) . . . . . . . . . . . . . . . . 245
13.12.9 ADC data register (ADC_DR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245
13.12.10 ADC common configuration register (ADC_CCR) . . . . . . . . . . . . . . . . 246
13.12.11 ADC register map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247
14
Digital-to-analog converter (DAC) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248
14.1
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248
14.2
DAC main features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248
14.3
Single mode functional description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249
14.4
14.3.1
DAC channel enable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249
14.3.2
DAC output buffer enable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250
14.3.3
DAC data format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250
14.3.4
DAC channel conversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250
14.3.5
DAC output voltage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251
14.3.6
DAC trigger selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 252
Dual mode functional description (STM32F07x devices) . . . . . . . . . . . . 252
14.4.1
DAC channel enable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 252
14.4.2
DAC output buffer enable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 252
14.4.3
DAC data format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253
14.4.4
DAC channel conversion in dual mode . . . . . . . . . . . . . . . . . . . . . . . . 254
14.4.5
Description of dual conversion modes . . . . . . . . . . . . . . . . . . . . . . . . . 254
DocID018940 Rev 6
9/988
Contents
RM0091
14.4.6
DAC output voltage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258
14.4.7
DAC trigger selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258
14.5
Noise generation (STM32F07x devices) . . . . . . . . . . . . . . . . . . . . . . . . 259
14.6
Triangle-wave generation (STM32F07x devices) . . . . . . . . . . . . . . . . . . 260
14.7
DMA request . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260
14.8
DAC registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261
14.8.1
DAC control register (DAC_CR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261
14.8.2
DAC software trigger register (DAC_SWTRIGR) . . . . . . . . . . . . . . . . . 265
14.8.3
DAC channel1 12-bit right-aligned data holding register
(DAC_DHR12R1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265
14.8.4
DAC channel1 12-bit left-aligned data holding register
(DAC_DHR12L1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266
14.8.5
DAC channel1 8-bit right-aligned data holding register
(DAC_DHR8R1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266
14.8.6
DAC channel2 12-bit right-aligned data holding register
(DAC_DHR12R2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266
14.8.7
DAC channel2 12-bit left-aligned data holding register
(DAC_DHR12L2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267
14.8.8
DAC channel2 8-bit right-aligned data holding register
(DAC_DHR8R2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267
14.8.9
Dual DAC 12-bit right-aligned data holding register
(DAC_DHR12RD) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 268
14.8.10 Dual DAC 12-bit left-aligned data holding register
(DAC_DHR12LD) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 268
14.8.11 Dual DAC 8-bit right-aligned data holding register
(DAC_DHR8RD) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269
14.8.12 DAC channel1 data output register (DAC_DOR1) . . . . . . . . . . . . . . . . 269
14.8.13 DAC channel2 data output register (DAC_DOR2) . . . . . . . . . . . . . . . . 269
14.8.14 DAC status register (DAC_SR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270
14.8.15 DAC register map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271
15
10/988
Comparator (COMP) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273
15.1
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273
15.2
COMP main features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273
15.3
COMP functional description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274
15.3.1
COMP block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274
15.3.2
COMP pins and internal signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274
15.3.3
COMP reset and clocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275
15.3.4
Comparator LOCK mechanism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275
DocID018940 Rev 6
RM0091
Contents
15.3.5
16
Hysteresis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275
15.4
Power mode
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 276
15.5
Interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 276
15.6
COMP registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277
15.6.1
COMP control and status register (COMP_CSR) . . . . . . . . . . . . . . . . 277
15.6.2
COMP register map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 280
Advanced-control timers (TIM1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281
16.1
TIM1 introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281
16.2
TIM1 main features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281
16.3
TIM1 functional description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283
16.3.1
Time-base unit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283
16.3.2
Counter modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285
16.3.3
Repetition counter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295
16.3.4
Clock sources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297
16.3.5
Capture/compare channels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 300
16.3.6
Input capture mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303
16.3.7
PWM input mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 304
16.3.8
Forced output mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305
16.3.9
Output compare mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305
16.3.10 PWM mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 306
16.3.11 Complementary outputs and dead-time insertion . . . . . . . . . . . . . . . . 310
16.3.12 Using the break function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 312
16.3.13 Clearing the OCxREF signal on an external event . . . . . . . . . . . . . . . 315
16.3.14 6-step PWM generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 317
16.3.15 One-pulse mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 318
16.3.16 Encoder interface mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319
16.3.17 Timer input XOR function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 323
16.3.18 Interfacing with Hall sensors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 323
16.3.19 TIMx and external trigger synchronization . . . . . . . . . . . . . . . . . . . . . . 325
16.3.20 Timer synchronization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 328
16.3.21 Debug mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 328
16.4
TIM1 registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 329
16.4.1
TIM1 control register 1 (TIM1_CR1) . . . . . . . . . . . . . . . . . . . . . . . . . . 329
16.4.2
TIM1 control register 2 (TIM1_CR2) . . . . . . . . . . . . . . . . . . . . . . . . . . 330
16.4.3
TIM1 slave mode control register (TIM1_SMCR) . . . . . . . . . . . . . . . . 332
DocID018940 Rev 6
11/988
Contents
RM0091
16.4.4
TIM1 DMA/interrupt enable register (TIM1_DIER) . . . . . . . . . . . . . . . . 334
16.4.5
TIM1 status register (TIM1_SR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 336
16.4.6
TIM1 event generation register (TIM1_EGR) . . . . . . . . . . . . . . . . . . . . 337
16.4.7
TIM1 capture/compare mode register 1 (TIM1_CCMR1) . . . . . . . . . . 339
16.4.8
TIM1 capture/compare mode register 2 (TIM1_CCMR2) . . . . . . . . . . 342
16.4.9
TIM1 capture/compare enable register (TIM1_CCER) . . . . . . . . . . . . 343
16.4.10 TIM1 counter (TIM1_CNT) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 347
16.4.11 TIM1 prescaler (TIM1_PSC) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 347
16.4.12 TIM1 auto-reload register (TIM1_ARR) . . . . . . . . . . . . . . . . . . . . . . . . 347
16.4.13 TIM1 repetition counter register (TIM1_RCR) . . . . . . . . . . . . . . . . . . . 348
16.4.14 TIM1 capture/compare register 1 (TIM1_CCR1) . . . . . . . . . . . . . . . . . 348
16.4.15 TIM1 capture/compare register 2 (TIM1_CCR2) . . . . . . . . . . . . . . . . . 349
16.4.16 TIM1 capture/compare register 3 (TIM1_CCR3) . . . . . . . . . . . . . . . . . 349
16.4.17 TIM1 capture/compare register 4 (TIM1_CCR4) . . . . . . . . . . . . . . . . . 350
16.4.18 TIM1 break and dead-time register (TIM1_BDTR) . . . . . . . . . . . . . . . 350
16.4.19 TIM1 DMA control register (TIM1_DCR) . . . . . . . . . . . . . . . . . . . . . . . 352
16.4.20 TIM1 DMA address for full transfer (TIM1_DMAR) . . . . . . . . . . . . . . . 353
16.4.21 TIM1 register map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 354
17
General-purpose timers (TIM2 and TIM3) . . . . . . . . . . . . . . . . . . . . . . 356
17.1
TIM2 and TIM3 introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 356
17.2
TIM2 and TIM3 main features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 356
17.3
TIM2 and TIM3 functional description . . . . . . . . . . . . . . . . . . . . . . . . . . 357
17.3.1
Time-base unit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 357
17.3.2
Counter modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 359
17.3.3
Clock sources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 370
17.3.4
Capture/compare channels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 373
17.3.5
Input capture mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 375
17.3.6
PWM input mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 377
17.3.7
Forced output mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 378
17.3.8
Output compare mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 378
17.3.9
PWM mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 379
17.3.10 One-pulse mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 383
17.3.11 Clearing the OCxREF signal on an external event . . . . . . . . . . . . . . . 385
17.3.12 Encoder interface mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 385
17.3.13 Timer input XOR function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 388
17.3.14 Timers and external trigger synchronization . . . . . . . . . . . . . . . . . . . . 389
12/988
DocID018940 Rev 6
RM0091
Contents
17.3.15 Timer synchronization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 392
17.3.16 Debug mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 398
17.4
TIM2 and TIM3 registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 399
17.4.1
TIM2 and TIM3 control register 1 (TIM2_CR1 and TIM3_CR1) . . . . . . 399
17.4.2
TIM2 and TIM3 control register 2 (TIM2_CR2 and TIM3_CR2) . . . . . . 401
17.4.3
TIM2 and TIM3 slave mode control register (TIM2_SMCR and
TIM3_SMCR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 402
17.4.4
TIM2 and TIM3 DMA/Interrupt enable register (TIM2_DIER and
TIM3_DIER) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 405
17.4.5
TIM2 and TIM3 status register (TIM2_SR and TIM3_SR) . . . . . . . . . . 406
17.4.6
TIM2 and TIM3 event generation register (TIM2_EGR and
TIM3_EGR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 408
17.4.7
TIM2 and TIM3 capture/compare mode register 1 (TIM2_CCMR1 and
TIM3_CCMR1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 409
17.4.8
TIM2 and TIM3 capture/compare mode register 2 (TIM2_CCMR2 and
TIM3_CCMR2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 412
17.4.9
TIM2 and TIM3 capture/compare enable register (TIM2_CCER and
TIM3_CCER) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 413
17.4.10 TIM2 and TIM3 counter (TIM2_CNT and TIM3_CNT) . . . . . . . . . . . . . 415
17.4.11 TIM2 and TIM3 prescaler (TIM2_PSC and TIM3_PSC) . . . . . . . . . . . 415
17.4.12 TIM2 and TIM3 auto-reload register (TIM2_ARR and TIM3_ARR) . . . 415
17.4.13 TIM2 and TIM3 capture/compare register 1 (TIM2_CCR1 and
TIM3_CCR1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 416
17.4.14 TIM2 and TIM3 capture/compare register 2 (TIM2_CCR2 and
TIM3_CCR2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 416
17.4.15 TIM2 and TIM3 capture/compare register 3 (TIM2_CCR3 and
TIM3_CCR3) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 417
17.4.16 TIM2 and TIM3 capture/compare register 4 (TIM2_CCR4 and
TIM3_CCR4) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 418
17.4.17 TIM2 and TIM3 DMA control register (TIM2_DCR and TIM3_DCR) . . 418
17.4.18 TIM2 and TIM3 DMA address for full transfer (TIM2_DMAR and
TIM3_DMAR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 419
17.4.19 TIM2 and TIM3 register map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 421
18
General-purpose timer (TIM14) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 423
18.1
TIM14 introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 423
18.2
TIM14 main features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 423
18.3
TIM14 functional description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 424
18.3.1
Time-base unit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 424
18.3.2
Counter modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 426
DocID018940 Rev 6
13/988
Contents
RM0091
18.4
18.3.3
Clock source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 429
18.3.4
Capture/compare channels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 429
18.3.5
Input capture mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 431
18.3.6
Forced output mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 432
18.3.7
Output compare mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 432
18.3.8
PWM mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 433
18.3.9
Debug mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 434
TIM14 registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 435
18.4.1
TIM14 control register 1 (TIM14_CR1) . . . . . . . . . . . . . . . . . . . . . . . . 435
18.4.2
TIM14 interrupt enable register (TIM14_DIER) . . . . . . . . . . . . . . . . . . 436
18.4.3
TIM14 status register (TIM14_SR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 436
18.4.4
TIM14 event generation register (TIM14_EGR) . . . . . . . . . . . . . . . . . . 437
18.4.5
TIM14 capture/compare mode register 1 (TIM14_CCMR1) . . . . . . . . 438
18.4.6
TIM14 capture/compare enable register (TIM14_CCER) . . . . . . . . . . 440
18.4.7
TIM14 counter (TIM14_CNT) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 441
18.4.8
TIM14 prescaler (TIM14_PSC) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 441
18.4.9
TIM14 auto-reload register (TIM14_ARR) . . . . . . . . . . . . . . . . . . . . . . 441
18.4.10 TIM14 capture/compare register 1 (TIM14_CCR1) . . . . . . . . . . . . . . . 442
18.4.11 TIM14 option register (TIM14_OR) . . . . . . . . . . . . . . . . . . . . . . . . . . . 442
18.4.12 TIM14 register map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 443
19
General-purpose timers (TIM15/16/17) . . . . . . . . . . . . . . . . . . . . . . . . 445
19.1
TIM15/16/17 introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 445
19.2
TIM15 main features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 445
19.3
TIM16 and TIM17 main features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 447
19.4
TIM15/16/17 functional description . . . . . . . . . . . . . . . . . . . . . . . . . . . . 449
19.4.1
Time-base unit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 449
19.4.2
Counter modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 451
19.4.3
Repetition counter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 455
19.4.4
Clock sources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 456
19.4.5
Capture/compare channels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 459
19.4.6
Input capture mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 462
19.4.7
PWM input mode (only for TIM15) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 463
19.4.8
Forced output mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 464
19.4.9
Output compare mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 464
19.4.10 PWM mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 465
19.4.11 Complementary outputs and dead-time insertion . . . . . . . . . . . . . . . . 467
14/988
DocID018940 Rev 6
RM0091
Contents
19.4.12 Using the break function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 469
19.4.13 One-pulse mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 472
19.4.14 TIM15 external trigger synchronization . . . . . . . . . . . . . . . . . . . . . . . . 474
19.4.15 Timer synchronization (TIM15) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 476
19.4.16 Debug mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 476
19.5
TIM15 registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 477
19.5.1
TIM15 control register 1 (TIM15_CR1) . . . . . . . . . . . . . . . . . . . . . . . . 477
19.5.2
TIM15 control register 2 (TIM15_CR2) . . . . . . . . . . . . . . . . . . . . . . . . 478
19.5.3
TIM15 slave mode control register (TIM15_SMCR) . . . . . . . . . . . . . . 480
19.5.4
TIM15 DMA/interrupt enable register (TIM15_DIER) . . . . . . . . . . . . . . 481
19.5.5
TIM15 status register (TIM15_SR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 482
19.5.6
TIM15 event generation register (TIM15_EGR) . . . . . . . . . . . . . . . . . . 484
19.5.7
TIM15 capture/compare mode register 1 (TIM15_CCMR1) . . . . . . . . 485
19.5.8
TIM15 capture/compare enable register (TIM15_CCER) . . . . . . . . . . 488
19.5.9
TIM15 counter (TIM15_CNT) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 491
19.5.10 TIM15 prescaler (TIM15_PSC) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 491
19.5.11 TIM15 auto-reload register (TIM15_ARR) . . . . . . . . . . . . . . . . . . . . . . 491
19.5.12 TIM15 repetition counter register (TIM15_RCR) . . . . . . . . . . . . . . . . . 492
19.5.13 TIM15 capture/compare register 1 (TIM15_CCR1) . . . . . . . . . . . . . . . 492
19.5.14 TIM15 capture/compare register 2 (TIM15_CCR2) . . . . . . . . . . . . . . . 493
19.5.15 TIM15 break and dead-time register (TIM15_BDTR) . . . . . . . . . . . . . 493
19.5.16 TIM15 DMA control register (TIM15_DCR) . . . . . . . . . . . . . . . . . . . . . 496
19.5.17 TIM15 DMA address for full transfer (TIM15_DMAR) . . . . . . . . . . . . . 496
19.5.18 TIM15 register map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 497
19.6
TIM16 and TIM17 registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 499
19.6.1
TIM16 and TIM17 control register 1 (TIM16_CR1 and TIM17_CR1) . . 499
19.6.2
TIM16 and TIM17 control register 2 (TIM16_CR2 and TIM17_CR2) . . 500
19.6.3
TIM16 and TIM17 DMA/interrupt enable register (TIM16_DIER and
TIM17_DIER) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 501
19.6.4
TIM16 and TIM17 status register (TIM16_SR and TIM17_SR) . . . . . . 502
19.6.5
TIM16 and TIM17 event generation register (TIM16_EGR and
TIM17_EGR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 503
19.6.6
TIM16 and TIM17 capture/compare mode register 1 (TIM16_CCMR1
and TIM17_CCMR1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 504
19.6.7
TIM16 and TIM17 capture/compare enable register (TIM16_CCER
and TIM17_CCER) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 508
19.6.8
TIM16 and TIM17 counter (TIM16_CNT and TIM17_CNT) . . . . . . . . . 510
19.6.9
TIM16 and TIM17 prescaler (TIM16_PSC and TIM17_PSC) . . . . . . . 510
DocID018940 Rev 6
15/988
Contents
RM0091
19.6.10 TIM16 and TIM17 auto-reload register (TIM16_ARR and
TIM17_ARR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 510
19.6.11 TIM16 and TIM17 repetition counter register (TIM16_RCR and
TIM17_RCR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 511
19.6.12 TIM16 and TIM17 capture/compare register 1 (TIM16_CCR1 and
TIM17_CCR1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 511
19.6.13 TIM16 and TIM17 break and dead-time register (TIM16_BDTR and
TIM17_BDTR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 512
19.6.14 TIM16 and TIM17 DMA control register (TIM16_DCR and
TIM17_DCR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 514
19.6.15 TIM16 and TIM17 DMA address for full transfer (TIM16_DMAR and
TIM17_DMAR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 514
19.6.16 TIM16 and TIM17 register map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 516
20
Basic timer (TIM6/TIM7) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 518
20.1
TIM6/TIM7 introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 518
20.2
TIM6/TIM7 main features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 518
20.3
TIM6/TIM7 functional description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 519
20.4
20.3.1
Time-base unit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 519
20.3.2
Counter modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 521
20.3.3
Clock source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 525
20.3.4
Debug mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 525
TIM6/TIM7 registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 526
20.4.1
TIM6/TIM7 control register 1 (TIMx_CR1) . . . . . . . . . . . . . . . . . . . . . . 526
20.4.2
TIM6/TIM7 control register 2 (TIMx_CR2) . . . . . . . . . . . . . . . . . . . . . . 527
20.4.3
TIM6/TIM7 DMA/Interrupt enable register (TIMx_DIER) . . . . . . . . . . . 527
20.4.4
TIM6/TIM7 status register (TIMx_SR) . . . . . . . . . . . . . . . . . . . . . . . . . 528
20.4.5
TIM6/TIM7 event generation register (TIMx_EGR) . . . . . . . . . . . . . . . 528
20.4.6
TIM6/TIM7 counter (TIMx_CNT) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 528
20.4.7
TIM6/TIM7 prescaler (TIMx_PSC) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 529
20.4.8
TIM6/TIM7 auto-reload register (TIMx_ARR) . . . . . . . . . . . . . . . . . . . 529
20.4.9
TIM6/TIM7 register map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 530
21
Infrared interface (IRTIM) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 531
22
Independent watchdog (IWDG) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 532
16/988
22.1
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 532
22.2
IWDG main features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 532
DocID018940 Rev 6
RM0091
Contents
22.3
22.4
23
22.3.1
IWDG block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 532
22.3.2
Window option . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 533
22.3.3
Hardware watchdog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 533
22.3.4
Register access protection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 534
22.3.5
Debug mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 534
IWDG registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 534
22.4.1
Key register (IWDG_KR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 534
22.4.2
Prescaler register (IWDG_PR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 535
22.4.3
Reload register (IWDG_RLR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 536
22.4.4
Status register (IWDG_SR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 537
22.4.5
Window register (IWDG_WINR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 538
22.4.6
IWDG register map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 539
System window watchdog (WWDG) . . . . . . . . . . . . . . . . . . . . . . . . . . 540
23.1
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 540
23.2
WWDG main features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 540
23.3
WWDG functional description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 540
23.4
24
IWDG functional description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 532
23.3.1
Enabling the watchdog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 541
23.3.2
Controlling the downcounter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 541
23.3.3
Advanced watchdog interrupt feature . . . . . . . . . . . . . . . . . . . . . . . . . 541
23.3.4
How to program the watchdog timeout . . . . . . . . . . . . . . . . . . . . . . . . 542
23.3.5
Debug mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 543
WWDG registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 543
23.4.1
Control register (WWDG_CR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 543
23.4.2
Configuration register (WWDG_CFR) . . . . . . . . . . . . . . . . . . . . . . . . . 544
23.4.3
Status register (WWDG_SR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 544
23.4.4
WWDG register map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 545
Real-time clock (RTC) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 546
24.1
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 546
24.2
RTC main features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 546
24.3
RTC implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 547
24.4
RTC functional description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 548
24.4.1
RTC block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 548
24.4.2
GPIOs controlled by the RTC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 550
DocID018940 Rev 6
17/988
Contents
RM0091
24.4.3
Clock and prescalers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 551
24.4.4
Real-time clock and calendar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 552
24.4.5
Programmable alarm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 553
24.4.6
Periodic auto-wakeup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 553
24.4.7
RTC initialization and configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . 554
24.4.8
Reading the calendar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 555
24.4.9
Resetting the RTC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 556
24.4.10 RTC synchronization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 557
24.4.11 RTC reference clock detection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 557
24.4.12 RTC smooth digital calibration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 558
24.4.13 Time-stamp function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 560
24.4.14 Tamper detection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 561
24.4.15 Calibration clock output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 562
24.4.16 Alarm output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 563
24.5
RTC low-power modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 563
24.6
RTC interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 563
24.7
RTC registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 564
24.7.1
RTC time register (RTC_TR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 565
24.7.2
RTC date register (RTC_DR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 566
24.7.3
RTC control register (RTC_CR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 567
24.7.4
RTC initialization and status register (RTC_ISR) . . . . . . . . . . . . . . . . . 570
24.7.5
RTC prescaler register (RTC_PRER) . . . . . . . . . . . . . . . . . . . . . . . . . 572
24.7.6
RTC wakeup timer register (RTC_WUTR) . . . . . . . . . . . . . . . . . . . . . . 573
24.7.7
RTC alarm A register (RTC_ALRMAR) . . . . . . . . . . . . . . . . . . . . . . . . 574
24.7.8
RTC write protection register (RTC_WPR) . . . . . . . . . . . . . . . . . . . . . 575
24.7.9
RTC sub second register (RTC_SSR) . . . . . . . . . . . . . . . . . . . . . . . . . 576
24.7.10 RTC shift control register (RTC_SHIFTR) . . . . . . . . . . . . . . . . . . . . . . 577
24.7.11 RTC timestamp time register (RTC_TSTR) . . . . . . . . . . . . . . . . . . . . . 578
24.7.12 RTC timestamp date register (RTC_TSDR) . . . . . . . . . . . . . . . . . . . . 579
24.7.13 RTC time-stamp sub second register (RTC_TSSSR) . . . . . . . . . . . . . 580
24.7.14 RTC calibration register (RTC_CALR) . . . . . . . . . . . . . . . . . . . . . . . . . 581
24.7.15 RTC tamper and alternate function configuration register
(RTC_TAFCR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 582
24.7.16 RTC alarm A sub second register (RTC_ALRMASSR) . . . . . . . . . . . . 585
24.7.17 RTC backup registers (RTC_BKPxR) . . . . . . . . . . . . . . . . . . . . . . . . . 586
24.7.18 RTC register map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 587
18/988
DocID018940 Rev 6
RM0091
25
Contents
Inter-integrated circuit (I2C) interface . . . . . . . . . . . . . . . . . . . . . . . . . 589
25.1
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 589
25.2
I2C main features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 589
25.3
I2C implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 590
25.4
I2C functional description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 590
25.4.1
I2C1 block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 591
25.4.2
I2C2 block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 592
25.4.3
I2C clock requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 592
25.4.4
Mode selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 593
25.4.5
I2C initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 594
25.4.6
Software reset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 598
25.4.7
Data transfer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 599
25.4.8
I2C slave mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 601
25.4.9
I2C master mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 610
25.4.10 I2Cx_TIMINGR register configuration examples . . . . . . . . . . . . . . . . . 622
25.4.11 SMBus specific features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 623
25.4.12 SMBus initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 626
25.4.13 SMBus: I2Cx_TIMEOUTR register configuration examples . . . . . . . . 628
25.4.14 SMBus slave mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 629
25.4.15 HSI Error conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 636
25.4.16 DMA requests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 638
25.4.17 Debug mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 639
25.5
I2C low-power modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 640
25.6
I2C interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 640
25.7
I2C registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 641
25.7.1
Control register 1 (I2Cx_CR1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 642
25.7.2
Control register 2 (I2Cx_CR2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 645
25.7.3
Own address 1 register (I2Cx_OAR1) . . . . . . . . . . . . . . . . . . . . . . . . . 648
25.7.4
Own address 2 register (I2Cx_OAR2) . . . . . . . . . . . . . . . . . . . . . . . . . 649
25.7.5
Timing register (I2Cx_TIMINGR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 650
25.7.6
Timeout register (I2Cx_TIMEOUTR) . . . . . . . . . . . . . . . . . . . . . . . . . . 651
25.7.7
Interrupt and Status register (I2Cx_ISR) . . . . . . . . . . . . . . . . . . . . . . . 652
25.7.8
Interrupt clear register (I2Cx_ICR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 654
25.7.9
PEC register (I2Cx_PECR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 655
25.7.10 Receive data register (I2Cx_RXDR) . . . . . . . . . . . . . . . . . . . . . . . . . . 656
25.7.11 Transmit data register (I2Cx_TXDR) . . . . . . . . . . . . . . . . . . . . . . . . . . 656
DocID018940 Rev 6
19/988
Contents
RM0091
25.7.12 I2C register map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 657
26
Universal synchronous asynchronous receiver
transmitter (USART) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 659
26.1
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 659
26.2
USART main features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 659
26.3
USART extended features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 660
26.4
USART implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 661
26.5
USART functional description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 662
26.5.1
USART character description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 664
26.5.2
Transmitter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 665
26.5.3
Receiver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 668
26.5.4
Baud rate generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 675
26.5.5
Tolerance of the USART receiver to clock deviation . . . . . . . . . . . . . . 677
26.5.6
Auto baud rate detection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 678
26.5.7
Multiprocessor communication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 679
26.5.8
Modbus communication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 681
26.5.9
Parity control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 682
26.5.10 LIN (local interconnection network) mode . . . . . . . . . . . . . . . . . . . . . . 683
26.5.11 USART synchronous mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 685
26.5.12 Single-wire half-duplex communication . . . . . . . . . . . . . . . . . . . . . . . . 687
26.5.13 Smartcard mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 688
26.5.14 IrDA SIR ENDEC block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 693
26.5.15 Continuous communication using DMA . . . . . . . . . . . . . . . . . . . . . . . . 695
26.5.16 RS232 Hardware flow control and RS485 Driver Enable . . . . . . . . . . 697
26.5.17 Wakeup from Stop mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 699
20/988
26.6
USART interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 700
26.7
USART registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 701
26.7.1
Control register 1 (USARTx_CR1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 701
26.7.2
Control register 2 (USARTx_CR2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 705
26.7.3
Control register 3 (USARTx_CR3) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 708
26.7.4
Baud rate register (USARTx_BRR) . . . . . . . . . . . . . . . . . . . . . . . . . . . 712
26.7.5
Guard time and prescaler register (USARTx_GTPR) . . . . . . . . . . . . . 712
26.7.6
Receiver timeout register (USARTx_RTOR) . . . . . . . . . . . . . . . . . . . . 713
26.7.7
Request register (USARTx_RQR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 714
26.7.8
Interrupt & status register (USARTx_ISR) . . . . . . . . . . . . . . . . . . . . . . 715
DocID018940 Rev 6
RM0091
Contents
26.7.9
Interrupt flag clear register (USARTx_ICR) . . . . . . . . . . . . . . . . . . . . . 720
26.7.10 Receive data register (USARTx_RDR) . . . . . . . . . . . . . . . . . . . . . . . . 721
26.7.11 Transmit data register (USARTx_TDR) . . . . . . . . . . . . . . . . . . . . . . . . 721
26.7.12 USART register map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 722
27
Serial peripheral interface / inter-IC sound (SPI/I2S) . . . . . . . . . . . . . 724
27.1
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 724
27.2
SPI main features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 724
27.3
I2S main features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 725
27.4
SPI/I2S implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 725
27.5
SPI functional description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 726
27.5.1
General description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 726
27.5.2
Communications between one master and one slave . . . . . . . . . . . . . 727
27.5.3
Standard multi-slave communication . . . . . . . . . . . . . . . . . . . . . . . . . . 729
27.5.4
Slave select (NSS) pin management . . . . . . . . . . . . . . . . . . . . . . . . . . 730
27.5.5
Communication formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 732
27.5.6
Configuration of SPI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 734
27.5.7
Procedure for enabling SPI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 735
27.5.8
Data transmission and reception procedures . . . . . . . . . . . . . . . . . . . 735
27.5.9
SPI status flags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 745
27.5.10 SPI error flags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 746
27.5.11 NSS pulse mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 747
27.5.12 TI mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 747
27.5.13 CRC calculation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 748
27.6
SPI interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 750
27.7
I2S functional description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 751
27.7.1
I2S general description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 751
27.7.2
Supported audio protocols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 752
27.7.3
Clock generator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 758
27.7.4
I2S master mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 761
27.7.5
I2S slave mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 762
27.7.6
I2S status flags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 764
27.7.7
I2S error flags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 765
27.7.8
DMA features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 766
27.8
I S interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 766
27.9
SPI and I2S registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 767
DocID018940 Rev 6
21/988
Contents
RM0091
27.9.1
SPI control register 1 (SPIx_CR1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 767
27.9.2
SPI control register 2 (SPIx_CR2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 769
27.9.3
SPI status register (SPIx_SR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 772
27.9.4
SPI data register (SPIx_DR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 774
27.9.5
SPI CRC polynomial register (SPIx_CRCPR) . . . . . . . . . . . . . . . . . . . 774
27.9.6
SPI Rx CRC register (SPIx_RXCRCR) . . . . . . . . . . . . . . . . . . . . . . . . 775
27.9.7
SPI Tx CRC register (SPIx_TXCRCR) . . . . . . . . . . . . . . . . . . . . . . . . 775
27.9.8
SPIx_I2S configuration register (SPIx_I2SCFGR) . . . . . . . . . . . . . . . . 776
27.9.9
SPIx_I2S prescaler register (SPIx_I2SPR) . . . . . . . . . . . . . . . . . . . . . 778
27.9.10 SPI/I2S register map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 779
28
Touch sensing controller (TSC) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 780
28.1
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 780
28.2
TSC main features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 780
28.3
TSC functional description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 781
28.3.1
TSC block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 781
28.3.2
Surface charge transfer acquisition overview . . . . . . . . . . . . . . . . . . . 781
28.3.3
Reset and clocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 783
28.3.4
Charge transfer acquisition sequence . . . . . . . . . . . . . . . . . . . . . . . . . 784
28.3.5
Spread spectrum feature . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 785
28.3.6
Max count error . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 785
28.3.7
Sampling capacitor I/O and channel I/O mode selection . . . . . . . . . . . 786
28.3.8
Acquisition mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 787
28.3.9
I/O hysteresis and analog switch control . . . . . . . . . . . . . . . . . . . . . . . 787
28.3.10 Capacitive sensing GPIOs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 788
22/988
28.4
TSC low-power modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 788
28.5
TSC interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 789
28.6
TSC registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 789
28.6.1
TSC control register (TSC_CR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 789
28.6.2
TSC interrupt enable register (TSC_IER) . . . . . . . . . . . . . . . . . . . . . . 791
28.6.3
TSC interrupt clear register (TSC_ICR) . . . . . . . . . . . . . . . . . . . . . . . . 792
28.6.4
TSC interrupt status register (TSC_ISR) . . . . . . . . . . . . . . . . . . . . . . . 793
28.6.5
TSC I/O hysteresis control register (TSC_IOHCR) . . . . . . . . . . . . . . . 793
28.6.6
TSC I/O analog switch control register (TSC_IOASCR) . . . . . . . . . . . 794
28.6.7
TSC I/O sampling control register (TSC_IOSCR) . . . . . . . . . . . . . . . . 795
28.6.8
TSC I/O channel control register (TSC_IOCCR) . . . . . . . . . . . . . . . . . 795
DocID018940 Rev 6
RM0091
Contents
28.6.9
TSC I/O group control status register (TSC_IOGCSR) . . . . . . . . . . . . 796
28.6.10 TSC I/O group x counter register (TSC_IOGxCR) (x = 1..8) . . . . . . . . 796
28.6.11 TSC register map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 797
29
Controller area network (bxCAN) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 799
29.1
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 799
29.2
bxCAN main features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 799
29.3
bxCAN general description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 800
29.4
29.5
29.3.1
CAN 2.0B active core . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 800
29.3.2
Control, status and configuration registers . . . . . . . . . . . . . . . . . . . . . 800
29.3.3
Tx mailboxes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 800
29.3.4
Acceptance filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 801
bxCAN operating modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 801
29.4.1
Initialization mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 801
29.4.2
Normal mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 802
29.4.3
Sleep mode (low-power) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 802
Test mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 803
29.5.1
Silent mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 803
29.5.2
Loop back mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 804
29.5.3
Loop back combined with silent mode . . . . . . . . . . . . . . . . . . . . . . . . . 804
29.6
Behavior in Debug mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 805
29.7
bxCAN functional description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 805
29.7.1
Transmission handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 805
29.7.2
Time triggered communication mode . . . . . . . . . . . . . . . . . . . . . . . . . . 807
29.7.3
Reception handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 807
29.7.4
Identifier filtering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 808
29.7.5
Message storage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 812
29.7.6
Error management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 814
29.7.7
Bit timing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 814
29.8
bxCAN interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 817
29.9
CAN registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 818
29.9.1
Register access protection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 818
29.9.2
CAN control and status registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 818
29.9.3
CAN mailbox registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 829
29.9.4
CAN filter registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 836
29.9.5
bxCAN register map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 840
DocID018940 Rev 6
23/988
Contents
30
RM0091
Universal serial bus full-speed device interface (USB) . . . . . . . . . . . 844
30.1
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 844
30.2
USB main features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 844
30.3
USB implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 844
30.4
USB functional description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 846
30.4.1
30.5
30.6
31
Programming considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 848
30.5.1
Generic USB device programming . . . . . . . . . . . . . . . . . . . . . . . . . . . 848
30.5.2
System and power-on reset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 848
30.5.3
Double-buffered endpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 853
30.5.4
Isochronous transfers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 856
30.5.5
Suspend/Resume events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 857
USB registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 859
30.6.1
Common registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 859
30.6.2
Endpoint-specific registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 867
30.6.3
Buffer descriptor table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 872
30.6.4
USB register map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 875
HDMI-CEC controller (HDMI-CEC) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 877
31.1
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 877
31.2
HDMI-CEC controller main features . . . . . . . . . . . . . . . . . . . . . . . . . . . . 878
31.3
HDMI-CEC functional description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 879
31.4
31.3.1
HDMI-CEC pin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 879
31.3.2
Message description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 880
31.3.3
Bit timing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 880
Arbitration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 881
31.4.1
31.5
31.6
24/988
Description of USB blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 847
SFT option bit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 882
Error handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 883
31.5.1
Bit error . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 883
31.5.2
Message error . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 883
31.5.3
Bit Rising Error (BRE) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 884
31.5.4
Short Bit Period Error (SBPE) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 884
31.5.5
Long Bit Period Error (LBPE) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 884
31.5.6
Transmission Error Detection (TXERR) . . . . . . . . . . . . . . . . . . . . . . . . 886
HDMI-CEC interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 887
DocID018940 Rev 6
RM0091
Contents
31.7
32
HDMI-CEC registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 888
31.7.1
CEC control register (CEC_CR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 888
31.7.2
CEC configuration register (CEC_CFGR) . . . . . . . . . . . . . . . . . . . . . . 889
31.7.3
CEC Tx data register (CEC_TXDR) . . . . . . . . . . . . . . . . . . . . . . . . . . . 892
31.7.4
CEC Rx Data Register (CEC_RXDR) . . . . . . . . . . . . . . . . . . . . . . . . . 892
31.7.5
CEC Interrupt and Status Register (CEC_ISR) . . . . . . . . . . . . . . . . . . 892
31.7.6
CEC interrupt enable register (CEC_IER) . . . . . . . . . . . . . . . . . . . . . . 894
31.7.7
HDMI-CEC register map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 896
Debug support (DBG) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 897
32.1
Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 897
32.2
Reference ARM documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 898
32.3
Pinout and debug port pins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 898
32.4
32.3.1
SWD port pins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 899
32.3.2
SW-DP pin assignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 899
32.3.3
Internal pull-up & pull-down on SWD pins . . . . . . . . . . . . . . . . . . . . . . 899
ID codes and locking mechanism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 899
32.4.1
32.5
MCU device ID code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 900
SWD port . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 900
32.5.1
SWD protocol introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 900
32.5.2
SWD protocol sequence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 901
32.5.3
SW-DP state machine (reset, idle states, ID code) . . . . . . . . . . . . . . . 902
32.5.4
DP and AP read/write accesses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 902
32.5.5
SW-DP registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 903
32.5.6
SW-AP registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 904
32.6
Core debug . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 904
32.7
BPU (Break Point Unit) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 905
32.7.1
32.8
32.9
BPU functionality . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 905
DWT (Data Watchpoint) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 905
32.8.1
DWT functionality . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 905
32.8.2
DWT Program Counter Sample Register . . . . . . . . . . . . . . . . . . . . . . 905
MCU debug component (DBGMCU) . . . . . . . . . . . . . . . . . . . . . . . . . . . 905
32.9.1
Debug support for low-power modes . . . . . . . . . . . . . . . . . . . . . . . . . . 906
32.9.2
Debug support for timers, watchdog and I2C . . . . . . . . . . . . . . . . . . . . 906
32.9.3
Debug MCU configuration register (DBGMCU_CR) . . . . . . . . . . . . . . 907
32.9.4
Debug MCU APB1 freeze register (DBGMCU_APB1_FZ) . . . . . . . . . 908
DocID018940 Rev 6
25/988
Contents
33
RM0091
32.9.5
Debug MCU APB2 freeze register (DBGMCU_APB2_FZ) . . . . . . . . . 910
32.9.6
DBG register map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 911
Device electronic signature . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 912
33.1
Unique device ID register (96 bits) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 912
33.2
Memory size data register . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 913
33.2.1
Flash size data register . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 913
Appendix A Code examples. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 914
A.1
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 914
A.2
Flash Operation code example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 914
A.3
A.4
A.5
A.2.1
Flash memory unlocking sequence code . . . . . . . . . . . . . . . . . . . . . . . 914
A.2.2
Main Flash programming sequence code example . . . . . . . . . . . . . . . 914
A.2.3
Page erase sequence code example . . . . . . . . . . . . . . . . . . . . . . . . . . 915
A.2.4
Mass erase sequence code example . . . . . . . . . . . . . . . . . . . . . . . . . . 915
A.2.5
Option byte unlocking sequence code example . . . . . . . . . . . . . . . . . . 916
A.2.6
Option byte programming sequence code example . . . . . . . . . . . . . . . 916
A.2.7
Option byte erasing sequence code example. . . . . . . . . . . . . . . . . . . . 917
Clock Controller. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 918
A.3.1
HSE start sequence code example . . . . . . . . . . . . . . . . . . . . . . . . . . . 918
A.3.2
PLL configuration modification code example . . . . . . . . . . . . . . . . . . . 919
A.3.3
MCO selection code example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 919
A.3.4
Clock measurement configuration with TIM14 code example . . . . . . . 920
GPIO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 921
A.4.1
Lock sequence code example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 921
A.4.2
Alternate function selection sequence code example . . . . . . . . . . . . . . 921
A.4.3
Analog GPIO configuration code example . . . . . . . . . . . . . . . . . . . . . . 922
DMA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 923
A.5.1
A.6
A.7
26/988
DMA Channel Configuration sequence code example . . . . . . . . . . . . . 923
Interrupts and event . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 924
A.6.1
NVIC initialization example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 924
A.6.2
External interrupt selection code example . . . . . . . . . . . . . . . . . . . . . . 924
ADC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 925
A.7.1
ADC Calibration code example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 925
A.7.2
ADC enable sequence code example. . . . . . . . . . . . . . . . . . . . . . . . . . 925
A.7.3
ADC disable sequence code example . . . . . . . . . . . . . . . . . . . . . . . . . 925
DocID018940 Rev 6
RM0091
Contents
A.8
A.9
A.7.4
ADC Clock selection code example . . . . . . . . . . . . . . . . . . . . . . . . . . . 926
A.7.5
Single conversion sequence code example - Software trigger . . . . . . . 926
A.7.6
Continuous conversion sequence code example - Software trigger. . . 927
A.7.7
Single conversion sequence code example - Hardware trigger . . . . . . 927
A.7.8
Continuous conversion sequence code example - Hardware trigger . . 927
A.7.9
DMA one shot mode sequence code example . . . . . . . . . . . . . . . . . . . 928
A.7.10
DMA circular mode sequence code example . . . . . . . . . . . . . . . . . . . . 928
A.7.11
Wait mode sequence code example. . . . . . . . . . . . . . . . . . . . . . . . . . . 929
A.7.12
Auto Off and no wait mode sequence code example . . . . . . . . . . . . . . 929
A.7.13
Auto Off and wait mode sequence code example. . . . . . . . . . . . . . . . . 929
A.7.14
Analog watchdog code example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 930
A.7.15
Temperature configuration code example. . . . . . . . . . . . . . . . . . . . . . . 930
A.7.16
Temperature computation code example . . . . . . . . . . . . . . . . . . . . . . . 930
DAC. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 931
A.8.1
Independent trigger without wave generation code example . . . . . . . . 931
A.8.2
Independent trigger with single LFSR generation code example . . . . . 931
A.8.3
Independent trigger with different LFSR generation code example . . . 931
A.8.4
Independent trigger with single triangle generation code example. . . . 932
A.8.5
Independent trigger with different triangle generation code example . . 932
A.8.6
Simultaneous software start code example . . . . . . . . . . . . . . . . . . . . . 933
A.8.7
Simultaneous trigger without wave generation code example . . . . . . . 933
A.8.8
Simultaneous trigger with single LFSR generation code example . . . . 933
A.8.9
Simultaneous trigger with different LFSR generation code example . . 934
A.8.10
Simultaneous trigger with single triangle generation code example . . . 934
A.8.11
Simultaneous trigger with different triangle generation code example . 934
A.8.12
DMA initialization code example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 935
Timers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 936
A.9.1
Upcounter on TI2 rising edge code example . . . . . . . . . . . . . . . . . . . . 936
A.9.2
Up counter on each 2 ETR rising edges code example . . . . . . . . . . . . 936
A.9.3
Input capture configuration code example . . . . . . . . . . . . . . . . . . . . . . 937
A.9.4
Input capture data management code example . . . . . . . . . . . . . . . . . . 937
A.9.5
PWM input configuration code example . . . . . . . . . . . . . . . . . . . . . . . . 938
A.9.6
PWM input with DMA configuration code example . . . . . . . . . . . . . . . . 939
A.9.7
Output compare configuration code example . . . . . . . . . . . . . . . . . . . . 939
A.9.8
Edge-aligned PWM configuration example. . . . . . . . . . . . . . . . . . . . . . 940
A.9.9
Center-aligned PWM configuration example . . . . . . . . . . . . . . . . . . . . 940
A.9.10
ETR configuration to clear OCxREF code example . . . . . . . . . . . . . . . 941
DocID018940 Rev 6
27/988
Contents
RM0091
A.10
A.11
A.12
A.13
A.14
A.15
28/988
A.9.11
Encoder interface code example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 942
A.9.12
Reset mode code example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 942
A.9.13
Gated mode code example. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 942
A.9.14
Trigger mode code example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 943
A.9.15
External clock mode 2 + trigger mode code example. . . . . . . . . . . . . . 943
A.9.16
One-Pulse mode code example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 944
A.9.17
Timer prescaling another timer code example . . . . . . . . . . . . . . . . . . . 944
A.9.18
Timer enabling another timer code example. . . . . . . . . . . . . . . . . . . . . 945
A.9.19
Master and slave synchronization code example . . . . . . . . . . . . . . . . . 946
A.9.20
Two timers synchronized by an external trigger code example . . . . . . 947
A.9.21
DMA burst feature code example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 949
IRTIM code example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 950
A.10.1
TIM16 and TIM17 configuration code example. . . . . . . . . . . . . . . . . . . 950
A.10.2
IRQHandler for IRTIM code example . . . . . . . . . . . . . . . . . . . . . . . . . . 951
bxCAN code example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 953
A.11.1
bxCAN initialization mode code example . . . . . . . . . . . . . . . . . . . . . . . 953
A.11.2
bxCAN transmit code example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 953
A.11.3
bxCAN receive code example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 954
DBG code example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 954
A.12.1
DBG read device ID code example . . . . . . . . . . . . . . . . . . . . . . . . . . . 954
A.12.2
DBG debug in Low-power mode code example . . . . . . . . . . . . . . . . . . 954
HDMI-CEC code example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 955
A.13.1
HDMI-CEC configure CEC code example . . . . . . . . . . . . . . . . . . . . . . 955
A.13.2
HDMI-CEC transmission with interrupt enabled code example . . . . . . 955
A.13.3
HDMI-CEC interrupt management code example . . . . . . . . . . . . . . . . 955
I2C code example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 956
A.14.1
I2C configured in master mode to receive code example. . . . . . . . . . . 956
A.14.2
I2C configured in master mode to transmit code example . . . . . . . . . . 956
A.14.3
I2C configured in slave mode code example . . . . . . . . . . . . . . . . . . . . 956
A.14.4
I2C master transmitter code example . . . . . . . . . . . . . . . . . . . . . . . . . . 956
A.14.5
I2C master receiver code example . . . . . . . . . . . . . . . . . . . . . . . . . . . . 957
A.14.6
I2C slave transmitter code example . . . . . . . . . . . . . . . . . . . . . . . . . . . 957
A.14.7
I2C slave receiver code example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 957
A.14.8
I2C configured in master mode to transmit with DMA code example . . 958
A.14.9
I2C configured in slave mode to receive with DMA code example . . . . 958
IWDG code example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 959
DocID018940 Rev 6
RM0091
Contents
A.16
A.17
A.18
A.19
A.15.1
IWDG configuration code example . . . . . . . . . . . . . . . . . . . . . . . . . . . . 959
A.15.2
IWDG configuration with window code example. . . . . . . . . . . . . . . . . . 959
RTC code example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 960
A.16.1
RTC calendar configuration code example. . . . . . . . . . . . . . . . . . . . . . 960
A.16.2
RTC alarm configuration code example . . . . . . . . . . . . . . . . . . . . . . . . 960
A.16.3
RTC WUT configuration code example . . . . . . . . . . . . . . . . . . . . . . . . 961
A.16.4
RTC read calendar code example . . . . . . . . . . . . . . . . . . . . . . . . . . . . 961
A.16.5
RTC calibration code example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 961
A.16.6
RTC tamper and time stamp configuration code example . . . . . . . . . . 962
A.16.7
RTC tamper and time stamp code example . . . . . . . . . . . . . . . . . . . . . 962
A.16.8
RTC clock output code example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 962
SPI code example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 964
A.17.1
SPI master configuration code example . . . . . . . . . . . . . . . . . . . . . . . . 964
A.17.2
SPI slave configuration code example . . . . . . . . . . . . . . . . . . . . . . . . . 964
A.17.3
SPI full duplex communication code example . . . . . . . . . . . . . . . . . . . 964
A.17.4
SPI interrupt code example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 964
A.17.5
SPI master configuration with DMA code example. . . . . . . . . . . . . . . . 964
A.17.6
SPI slave configuration with DMA code example . . . . . . . . . . . . . . . . . 965
TSC code example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 966
A.18.1
TSC configuration code example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 966
A.18.2
TSC interrupt code example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 966
USART code example. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 967
A.19.1
USART transmitter configuration code example. . . . . . . . . . . . . . . . . . 967
A.19.2
USART transmit byte code example. . . . . . . . . . . . . . . . . . . . . . . . . . . 967
A.19.3
USART transfer complete code example . . . . . . . . . . . . . . . . . . . . . . . 967
A.19.4
USART receiver configuration code example . . . . . . . . . . . . . . . . . . . . 967
A.19.5
USART receive byte code example . . . . . . . . . . . . . . . . . . . . . . . . . . . 967
A.19.6
USART LIN mode code example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 968
A.19.7
USART synchronous mode code example . . . . . . . . . . . . . . . . . . . . . . 968
A.19.8
USART single-wire half-duplex code example . . . . . . . . . . . . . . . . . . . 969
A.19.9
USART smartcard mode code example . . . . . . . . . . . . . . . . . . . . . . . . 969
A.19.10 USART IrDA mode code example . . . . . . . . . . . . . . . . . . . . . . . . . . . . 969
A.19.11 USART DMA code example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 970
A.19.12 USART hardware flow control code example . . . . . . . . . . . . . . . . . . . . 970
A.20
WWDG code example. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 972
A.20.1
WWDG configuration code example. . . . . . . . . . . . . . . . . . . . . . . . . . . 972
DocID018940 Rev 6
29/988
Contents
34
30/988
RM0091
Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 976
DocID018940 Rev 6
RM0091
List of tables
List of tables
Table 1.
Table 2.
Table 3.
Table 4.
Table 5.
Table 6.
Table 7.
Table 8.
Table 9.
Table 10.
Table 11.
Table 12.
Table 13.
Table 14.
Table 15.
Table 16.
Table 17.
Table 18.
Table 19.
Table 20.
Table 21.
Table 22.
Table 23.
Table 24.
Table 25.
Table 26.
Table 27.
Table 28.
Table 29.
Table 30.
Table 31.
Table 32.
Table 33.
Table 34.
Table 35.
Table 36.
Table 37.
Table 38.
Table 39.
Table 40.
Table 41.
Table 42.
Table 43.
Table 44.
Table 45.
Table 46.
Table 47.
STM32F0xx peripheral register boundary addresses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
STM32F0xx memory boundary addresses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
Boot modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Flash memory organization (STM32F03x, STM32F04x and STM32F05x devices) . . . . . . 55
Flash memory organization (STM32F07x devices) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
Flash memory read protection status . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
Access status versus protection level and execution modes . . . . . . . . . . . . . . . . . . . . . . . 64
Flash interrupt request . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
Flash interface - register map and reset values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
Option byte format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
Option byte organization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
Option byte map and ST production values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
CRC register map and reset values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
Low-power mode summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
Sleep-now . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
Sleep-on-exit. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
Stop mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
Standby mode. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
PWR register map and reset values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
RCC register map and reset values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
Effect of low-power modes on CRS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
Interrupt control bits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
CRS register map and reset values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
Port bit configuration table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158
GPIO register map and reset values. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
SYSCFG register map and reset values. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
Programmable data width & endian behavior (when bits PINC = MINC = 1) . . . . . . . . . . 188
DMA interrupt requests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
Summary of the DMA requests for each channel
on STM32F03x, STM32F04x and STM32F05x devices . . . . . . . . . . . . . . . . . . . . . . . . . . 190
Summary of the DMA requests for each channel on STM32F07x devices . . . . . . . . . . . 191
DMA register map and reset values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198
DMA register map and reset values (registers available on STM32F07x devices only). . 199
Vector table. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200
External interrupt/event controller register map and reset values. . . . . . . . . . . . . . . . . . . 210
ADC internal signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213
ADC pins. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213
Latency between trigger and start of conversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217
Configuring the trigger polarity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222
External triggers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222
tSAR timings depending on resolution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
Analog watchdog comparison. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
Analog watchdog channel selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
ADC interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235
ADC register map and reset values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247
DAC pins. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249
External triggers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 252
DAC register map and reset values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271
DocID018940 Rev 6
31/988
List of tables
Table 48.
Table 49.
Table 50.
Table 51.
Table 52.
Table 53.
Table 54.
Table 55.
Table 56.
Table 57.
Table 58.
Table 59.
Table 60.
Table 61.
Table 62.
Table 63.
Table 64.
Table 65.
Table 66.
Table 67.
Table 68.
Table 69.
Table 70.
Table 71.
Table 72.
Table 73.
Table 74.
Table 75.
Table 76.
Table 77.
Table 78.
Table 79.
Table 80.
Table 81.
Table 82.
Table 83.
Table 84.
Table 85.
Table 86.
Table 87.
Table 88.
Table 89.
Table 90.
Table 91.
Table 92.
Table 93.
Table 94.
Table 95.
32/988
RM0091
COMP register map and reset values. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 280
Counting direction versus encoder signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 321
TIMx Internal trigger connection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 334
Output control bits for complementary OCx and OCxN channels with
break feature. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 346
TIM1 register map and reset values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 354
Counting direction versus encoder signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 386
TIM2 and TIM3 internal trigger connection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 404
Output control bit for standard OCx channels. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 415
TIM2 and TIM3 register map and reset values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 421
Output control bit for standard OCx channels. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 440
TIM14 register map and reset values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 443
TIMx Internal trigger connection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 481
Output control bits for complementary OCx and OCxN channels with break feature . . . . 490
TIM15 register map and reset values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 497
Output control bits for complementary OCx and OCxN channels with break feature . . . . 509
TIM16 and TIM17 register map and reset values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 516
TIM6/TIM7 register map and reset values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 530
IWDG register map and reset values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 539
WWDG register map and reset values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 545
STM32F0xx RTC implementation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 547
RTC pin PC13 configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 550
LSE pin PC14 configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 551
LSE pin PC15 configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 551
Effect of low-power modes on RTC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 563
Interrupt control bits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 564
RTC register map and reset values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 587
STM32F0xx I2C implementation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 590
Comparison of analog vs. digital filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 594
I2C-SMBUS specification data setup and hold times . . . . . . . . . . . . . . . . . . . . . . . . . . . . 597
I2C Configuration table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 601
I2C-SMBUS specification clock timings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 611
Examples of timings settings for fI2CCLK = 8 MHz . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 622
Examples of timings settings for fI2CCLK = 16 MHz . . . . . . . . . . . . . . . . . . . . . . . . . . . . 622
Examples of timings settings for fI2CCLK = 48 MHz . . . . . . . . . . . . . . . . . . . . . . . . . . . . 623
SMBus timeout specifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 625
SMBUS with PEC configuration table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 627
Examples of TIMEOUTA settings for various I2CCLK frequencies
(max tTIMEOUT = 25 ms) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 628
Examples of TIMEOUTB settings for various I2CCLK frequencies . . . . . . . . . . . . . . . . . 629
Examples of TIMEOUTA settings for various I2CCLK frequencies
(max tIDLE = 50 s) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 629
low-power modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 640
I2C Interrupt requests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 640
I2C register map and reset values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 657
STM32F0xx USART implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 661
Noise detection from sampled data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 673
Error calculation for programmed baud rates at fCK = 72MHz in both cases of
oversampling by 16 or by 8. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 676
Tolerance of the USART receiver when BRR [3:0] = 0000. . . . . . . . . . . . . . . . . . . . . . . . 678
Tolerance of the USART receiver when BRR[3:0] is different from 0000 . . . . . . . . . . . . . 678
Frame formats. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 682
DocID018940 Rev 6
RM0091
Table 96.
Table 97.
Table 98.
Table 99.
Table 100.
Table 101.
Table 102.
Table 103.
Table 104.
Table 105.
Table 106.
Table 107.
Table 108.
Table 109.
Table 110.
Table 111.
Table 112.
Table 113.
Table 114.
Table 115.
Table 116.
Table 117.
Table 118.
Table 119.
Table 120.
Table 121.
Table 122.
Table 123.
Table 124.
Table 125.
Table 126.
Table 127.
Table 128.
Table 129.
Table 130.
Table 131.
Table 132.
Table 133.
Table 134.
Table 135.
Table 136.
Table 137.
List of tables
USART interrupt requests. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 700
USART register map and reset values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 722
STM32F0xx SPI implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 725
SPI interrupt requests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 750
Audio-frequency precision using standard 8 MHz HSE . . . . . . . . . . . . . . . . . . . . . . . . . . 760
I2S interrupt requests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 766
SPI register map and reset values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 779
Acquisition sequence summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 783
Spread spectrum deviation versus AHB clock frequency . . . . . . . . . . . . . . . . . . . . . . . . . 785
I/O state depending on its mode and IODEF bit value . . . . . . . . . . . . . . . . . . . . . . . . . . . 786
Capacitive sensing GPIOs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 788
Effect of low-power modes on TSC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 788
Interrupt control bits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 789
TSC register map and reset values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 797
Transmit mailbox mapping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 813
Receive mailbox mapping. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 813
bxCAN register map and reset values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 840
STM32F0xx USB implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 844
Double-buffering buffer flag definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 854
Bulk double-buffering memory buffers usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 855
Isochronous memory buffers usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 856
Resume event detection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 858
Reception status encoding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 870
Endpoint type encoding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 871
Endpoint kind meaning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 871
Transmission status encoding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 871
Definition of allocated buffer memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 875
USB register map and reset values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 875
HDMI pin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 879
Error handling timing parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 885
TXERR timing parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 886
HDMI-CEC interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 887
HDMI-CEC register map and reset values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 896
SW debug port pins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 899
Packet request (8-bits) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 901
ACK response (3 bits). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 901
DATA transfer (33 bits) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 901
SW-DP registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 903
32-bit debug port registers addressed through the shifted value A[3:2] . . . . . . . . . . . . . . 904
Core debug registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 904
DBG register map and reset values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 911
Document revision history. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 976
DocID018940 Rev 6
33/988
List of figures
RM0091
List of figures
Figure 1.
Figure 2.
Figure 3.
Figure 4.
Figure 5.
Figure 6.
Figure 7.
Figure 8.
Figure 9.
Figure 10.
Figure 11.
Figure 12.
Figure 13.
Figure 14.
Figure 15.
Figure 16.
Figure 17.
Figure 18.
Figure 19.
Figure 20.
Figure 21.
Figure 22.
Figure 23.
Figure 24.
Figure 25.
Figure 26.
Figure 27.
Figure 28.
Figure 29.
Figure 30.
Figure 31.
Figure 32.
Figure 33.
Figure 34.
Figure 35.
Figure 36.
Figure 37.
Figure 38.
Figure 39.
Figure 40.
Figure 41.
Figure 42.
Figure 43.
Figure 44.
Figure 45.
Figure 46.
Figure 47.
Figure 48.
34/988
System architecture (all features) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Memory map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Programming procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
Flash memory Page Erase procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
Flash memory Mass Erase procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
CRC calculation unit block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
Power supply overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
Power on reset/power down reset waveform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
PVD thresholds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
Simplified diagram of the reset circuit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
Clock tree (STM32F03x and STM32F05x devices) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
Clock tree (STM32F04x and STM32F07x devices) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
HSE/ LSE clock sources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
Frequency measurement with TIM14 in capture mode. . . . . . . . . . . . . . . . . . . . . . . . . . . 109
CRS block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
CRS counter behavior . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
Basic structure of an I/O port bit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158
Input floating/pull up/pull down configurations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
Output configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
Alternate function configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
High impedance-analog configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
DMA block diagram. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
Extended interrupts and events controller (EXTI) block diagram . . . . . . . . . . . . . . . . . . . 203
External interrupt/event GPIO mapping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
ADC block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214
ADC calibration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215
Enabling/disabling the ADC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216
ADC clock scheme . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216
Analog to digital conversion time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220
ADC conversion timings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
Stopping an ongoing conversion. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
Single conversions of a sequence, software trigger . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225
Continuous conversion of a sequence, software trigger . . . . . . . . . . . . . . . . . . . . . . . . . . 225
Single conversions of a sequence, hardware trigger . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226
Continuous conversions of a sequence, hardware trigger . . . . . . . . . . . . . . . . . . . . . . . . 226
Data alignment and resolution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227
Example of overrun (OVR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228
Wait mode conversion (continuous mode, software trigger). . . . . . . . . . . . . . . . . . . . . . . 230
Behavior with WAIT=0, AUTOFF=1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
Behavior with WAIT=1, AUTOFF=1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
Analog watchdog guarded area . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
Temperature sensor and VREFINT channel block diagram . . . . . . . . . . . . . . . . . . . . . . 233
DAC block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249
Data registers in single DAC channel mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250
Timing diagram for conversion with trigger disabled TEN = 0 . . . . . . . . . . . . . . . . . . . . . 251
Data registers in single DAC channel mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253
Data registers in dual DAC channel mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254
DAC LFSR register calculation algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259
DocID018940 Rev 6
RM0091
Figure 49.
Figure 50.
Figure 51.
Figure 52.
Figure 53.
Figure 54.
Figure 55.
Figure 56.
Figure 57.
Figure 58.
Figure 59.
Figure 60.
Figure 61.
Figure 62.
Figure 63.
Figure 64.
Figure 65.
Figure 66.
Figure 67.
Figure 68.
Figure 69.
Figure 70.
Figure 71.
Figure 72.
Figure 73.
Figure 74.
Figure 75.
Figure 76.
Figure 77.
Figure 78.
Figure 79.
Figure 80.
Figure 81.
Figure 82.
Figure 83.
Figure 84.
Figure 85.
Figure 86.
Figure 87.
Figure 88.
Figure 89.
Figure 90.
Figure 91.
Figure 92.
Figure 93.
Figure 94.
Figure 95.
Figure 96.
Figure 97.
Figure 98.
List of figures
DAC conversion (SW trigger enabled) with LFSR wave generation. . . . . . . . . . . . . . . . . 259
DAC triangle wave generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260
DAC conversion (SW trigger enabled) with triangle wave generation . . . . . . . . . . . . . . . 260
Comparator 1 and 2 block diagrams. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274
Comparator hysteresis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275
Advanced-control timer block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282
Counter timing diagram with prescaler division change from 1 to 2 . . . . . . . . . . . . . . . . . 284
Counter timing diagram with prescaler division change from 1 to 4 . . . . . . . . . . . . . . . . . 284
Counter timing diagram, internal clock divided by 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 286
Counter timing diagram, internal clock divided by 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 286
Counter timing diagram, internal clock divided by 4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287
Counter timing diagram, internal clock divided by N. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287
Counter timing diagram, update event when ARPE=0
(TIMx_ARR not preloaded) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 288
Counter timing diagram, update event when ARPE=1
(TIMx_ARR preloaded) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 288
Counter timing diagram, internal clock divided by 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289
Counter timing diagram, internal clock divided by 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290
Counter timing diagram, internal clock divided by 4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290
Counter timing diagram, internal clock divided by N. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290
Counter timing diagram, update event when repetition counter is not used . . . . . . . . . . . 291
Counter timing diagram, internal clock divided by 1, TIMx_ARR = 0x6 . . . . . . . . . . . . . . 292
Counter timing diagram, internal clock divided by 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 293
Counter timing diagram, internal clock divided by 4, TIMx_ARR=0x36 . . . . . . . . . . . . . . 293
Counter timing diagram, internal clock divided by N. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294
Counter timing diagram, update event with ARPE=1 (counter underflow) . . . . . . . . . . . . 294
Counter timing diagram, Update event with ARPE=1 (counter overflow) . . . . . . . . . . . . . 295
Update rate examples depending on mode and TIMx_RCR register settings . . . . . . . . . 296
Control circuit in normal mode, internal clock divided by 1 . . . . . . . . . . . . . . . . . . . . . . . . 297
TI2 external clock connection example. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 298
Control circuit in external clock mode 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299
External trigger input block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299
Control circuit in external clock mode 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 300
Capture/compare channel (example: channel 1 input stage) . . . . . . . . . . . . . . . . . . . . . . 301
Capture/compare channel 1 main circuit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 301
Output stage of capture/compare channel (channel 1 to 3) . . . . . . . . . . . . . . . . . . . . . . . 302
Output stage of capture/compare channel (channel 4). . . . . . . . . . . . . . . . . . . . . . . . . . . 302
PWM input mode timing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 304
Output compare mode, toggle on OC1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 306
Edge-aligned PWM waveforms (ARR=8) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 308
Center-aligned PWM waveforms (ARR=8) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 309
Complementary output with dead-time insertion. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 311
Dead-time waveforms with delay greater than the negative pulse. . . . . . . . . . . . . . . . . . 311
Dead-time waveforms with delay greater than the positive pulse. . . . . . . . . . . . . . . . . . . 311
Output behavior in response to a break . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314
Clearing TIMx OCxREF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 316
6-step generation, COM example (OSSR=1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 317
Example of one pulse mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 318
Example of counter operation in encoder interface mode. . . . . . . . . . . . . . . . . . . . . . . . . 322
Example of encoder interface mode with TI1FP1 polarity inverted. . . . . . . . . . . . . . . . . . 322
Example of hall sensor interface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 324
Control circuit in reset mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325
DocID018940 Rev 6
35/988
List of figures
Figure 99.
Figure 100.
Figure 101.
Figure 102.
Figure 103.
Figure 104.
Figure 105.
Figure 106.
Figure 107.
Figure 108.
Figure 109.
Figure 110.
Figure 111.
Figure 112.
Figure 113.
Figure 114.
Figure 115.
Figure 116.
Figure 117.
Figure 118.
Figure 119.
Figure 120.
Figure 121.
Figure 122.
Figure 123.
Figure 124.
Figure 125.
Figure 126.
Figure 127.
Figure 128.
Figure 129.
Figure 130.
Figure 131.
Figure 132.
Figure 133.
Figure 134.
Figure 135.
Figure 136.
Figure 137.
Figure 138.
Figure 139.
Figure 140.
Figure 141.
Figure 142.
Figure 143.
Figure 144.
Figure 145.
Figure 146.
Figure 147.
Figure 148.
36/988
RM0091
Control circuit in gated mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 326
Control circuit in trigger mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 327
Control circuit in external clock mode 2 + trigger mode . . . . . . . . . . . . . . . . . . . . . . . . . . 328
General-purpose timer block diagram (TIM2 and TIM3) . . . . . . . . . . . . . . . . . . . . . . . . . 357
Counter timing diagram with prescaler division change from 1 to 2 . . . . . . . . . . . . . . . . . 358
Counter timing diagram with prescaler division change from 1 to 4 . . . . . . . . . . . . . . . . . 359
Counter timing diagram, internal clock divided by 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 360
Counter timing diagram, internal clock divided by 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 360
Counter timing diagram, internal clock divided by 4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 361
Counter timing diagram, internal clock divided by N. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 361
Counter timing diagram, Update event when ARPE=0
(TIMx_ARR not preloaded) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 362
Counter timing diagram, Update event when ARPE=1
(TIMx_ARR preloaded) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 362
Counter timing diagram, internal clock divided by 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 363
Counter timing diagram, internal clock divided by 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 364
Counter timing diagram, internal clock divided by 4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 364
Counter timing diagram, internal clock divided by N. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 365
Counter timing diagram, Update event when repetition counter is not used . . . . . . . . . . 365
Counter timing diagram, internal clock divided by 1, TIMx_ARR=0x6 . . . . . . . . . . . . . . . 367
Counter timing diagram, internal clock divided by 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 367
Counter timing diagram, internal clock divided by 4, TIMx_ARR=0x36 . . . . . . . . . . . . . . 368
Counter timing diagram, internal clock divided by N. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 368
Counter timing diagram, Update event with ARPE=1 (counter underflow). . . . . . . . . . . . 369
Counter timing diagram, Update event with ARPE=1 (counter overflow) . . . . . . . . . . . . . 369
Control circuit in normal mode, internal clock divided by 1 . . . . . . . . . . . . . . . . . . . . . . . . 370
TI2 external clock connection example. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 371
Control circuit in external clock mode 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 372
External trigger input block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 372
Control circuit in external clock mode 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 373
Capture/compare channel (example: channel 1 input stage) . . . . . . . . . . . . . . . . . . . . . . 374
Capture/compare channel 1 main circuit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 374
Output stage of capture/compare channel (channel 1). . . . . . . . . . . . . . . . . . . . . . . . . . . 375
PWM input mode timing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 377
Output compare mode, toggle on OC1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 379
Edge-aligned PWM waveforms (ARR=8) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 380
Center-aligned PWM waveforms (ARR=8) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 382
Example of one-pulse mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 383
Clearing TIMx OCxREF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 385
Example of counter operation in encoder interface mode . . . . . . . . . . . . . . . . . . . . . . . . 387
Example of encoder interface mode with TI1FP1 polarity inverted . . . . . . . . . . . . . . . . . 387
Control circuit in reset mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 389
Control circuit in gated mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 390
Control circuit in trigger mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 391
Control circuit in external clock mode 2 + trigger mode . . . . . . . . . . . . . . . . . . . . . . . . . . 392
Master/Slave timer example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 393
Gating timer 2 with OC1REF of timer 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 394
Gating timer 2 with Enable of timer 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 395
Triggering timer 2 with update of timer 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 396
Triggering timer 2 with Enable of timer 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 397
Triggering timer 1 and 2 with timer 1 TI1 input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 398
General-purpose timer block diagram (TIM14) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 424
DocID018940 Rev 6
RM0091
Figure 149.
Figure 150.
Figure 151.
Figure 152.
Figure 153.
Figure 154.
Figure 155.
Figure 156.
Figure 157.
Figure 158.
Figure 159.
Figure 160.
Figure 161.
Figure 162.
Figure 163.
Figure 164.
Figure 165.
Figure 166.
Figure 167.
Figure 168.
Figure 169.
Figure 170.
Figure 171.
Figure 172.
Figure 173.
Figure 174.
Figure 175.
Figure 176.
Figure 177.
Figure 178.
Figure 179.
Figure 180.
Figure 181.
Figure 182.
Figure 183.
Figure 184.
Figure 185.
Figure 186.
Figure 187.
Figure 188.
Figure 189.
Figure 190.
Figure 191.
Figure 192.
Figure 193.
Figure 194.
Figure 195.
Figure 196.
List of figures
Counter timing diagram with prescaler division change from 1 to 2 . . . . . . . . . . . . . . . . . 425
Counter timing diagram with prescaler division change from 1 to 4 . . . . . . . . . . . . . . . . . 425
Counter timing diagram, internal clock divided by 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 426
Counter timing diagram, internal clock divided by 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 427
Counter timing diagram, internal clock divided by 4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 427
Counter timing diagram, internal clock divided by N. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 427
Counter timing diagram, update event when ARPE=0
(TIMx_ARR not preloaded) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 428
Counter timing diagram, update event when ARPE=1
(TIMx_ARR preloaded) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 428
Control circuit in normal mode, internal clock divided by 1 . . . . . . . . . . . . . . . . . . . . . . . . 429
Capture/compare channel (example: channel 1 input stage) . . . . . . . . . . . . . . . . . . . . . . 429
Capture/compare channel 1 main circuit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 430
Output stage of capture/compare channel (channel 1). . . . . . . . . . . . . . . . . . . . . . . . . . . 430
Output compare mode, toggle on OC1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 433
Edge-aligned PWM waveforms (ARR=8) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 434
TIM15 block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 446
TIM16 and TIM17 block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 448
Counter timing diagram with prescaler division change from 1 to 2 . . . . . . . . . . . . . . . . . 450
Counter timing diagram with prescaler division change from 1 to 4 . . . . . . . . . . . . . . . . . 450
Counter timing diagram, internal clock divided by 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 452
Counter timing diagram, internal clock divided by 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 453
Counter timing diagram, internal clock divided by 4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 453
Counter timing diagram, internal clock divided by N. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 454
Counter timing diagram, update event when ARPE=0
(TIMx_ARR not preloaded) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 454
Counter timing diagram, update event when ARPE=1
(TIMx_ARR preloaded) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 455
Update rate examples depending on mode and TIMx_RCR register settings . . . . . . . . . 456
Control circuit in normal mode, internal clock divided by 1 . . . . . . . . . . . . . . . . . . . . . . . . 457
TI2 external clock connection example. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 458
Control circuit in external clock mode 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 459
Capture/compare channel (example: channel 1 input stage) . . . . . . . . . . . . . . . . . . . . . . 460
Capture/compare channel 1 main circuit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 460
Output stage of capture/compare channel (channel 1). . . . . . . . . . . . . . . . . . . . . . . . . . . 461
Output stage of capture/compare channel (channel 2 for TIM15) . . . . . . . . . . . . . . . . . . 461
PWM input mode timing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 463
Output compare mode, toggle on OC1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 465
Edge-aligned PWM waveforms (ARR=8) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 467
Complementary output with dead-time insertion. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 468
Dead-time waveforms with delay greater than the negative pulse . . . . . . . . . . . . . . . . . . 468
Dead-time waveforms with delay greater than the positive pulse. . . . . . . . . . . . . . . . . . . 469
Output behavior in response to a break . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 471
Example of One-pulse mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 472
Control circuit in reset mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 474
Control circuit in gated mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 475
Control circuit in trigger mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 476
Basic timer block diagram. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 518
Counter timing diagram with prescaler division change from 1 to 2 . . . . . . . . . . . . . . . . . 520
Counter timing diagram with prescaler division change from 1 to 4 . . . . . . . . . . . . . . . . . 520
Counter timing diagram, internal clock divided by 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 521
Counter timing diagram, internal clock divided by 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 522
DocID018940 Rev 6
37/988
List of figures
RM0091
Figure 197. Counter timing diagram, internal clock divided by 4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 522
Figure 198. Counter timing diagram, internal clock divided by N. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 523
Figure 199. Counter timing diagram, update event when ARPE = 0
(TIMx_ARR not preloaded) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 523
Figure 200. Counter timing diagram, update event when ARPE=1
(TIMx_ARR preloaded) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 524
Figure 201. Control circuit in normal mode, internal clock divided by 1 . . . . . . . . . . . . . . . . . . . . . . . . 525
Figure 202. IR internal hardware connections with TIM16 and TIM17. . . . . . . . . . . . . . . . . . . . . . . . . 531
Figure 203. Independent watchdog block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 532
Figure 204. Watchdog block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 541
Figure 205. Window watchdog timing diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 542
Figure 206. RTC block diagram in STM32F03x, STM32F04x and STM32F05x devices . . . . . . . . . . 548
Figure 207. RTC block diagram for STM32F07x devices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 549
Figure 208. I2C1 block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 591
Figure 209. I2C2 block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 592
Figure 210. I2C bus protocol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 593
Figure 211. Setup and hold timings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 595
Figure 212. I2C initialization flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 598
Figure 213. Data reception . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 599
Figure 214. Data transmission . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 600
Figure 215. Slave initialization flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 603
Figure 216. Transfer sequence flowchart for I2C slave transmitter, NOSTRETCH=0. . . . . . . . . . . . . 605
Figure 217. Transfer sequence flowchart for I2C slave transmitter, NOSTRETCH=1. . . . . . . . . . . . . 606
Figure 218. Transfer bus diagrams for I2C slave transmitter. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 607
Figure 219. Transfer sequence flowchart for slave receiver with NOSTRETCH=0 . . . . . . . . . . . . . . . 608
Figure 220. Transfer sequence flowchart for slave receiver with NOSTRETCH=1 . . . . . . . . . . . . . . . 609
Figure 221. Transfer bus diagrams for I2C slave receiver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 609
Figure 222. Master clock generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 611
Figure 223. Master initialization flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 613
Figure 224. 10-bit address read access with HEAD10R=0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 613
Figure 225. 10-bit address read access with HEAD10R=1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 614
Figure 226. Transfer sequence flowchart for I2C master transmitter for N<=255 bytes . . . . . . . . . . . 615
Figure 227. Transfer sequence flowchart for I2C master transmitter for N>255 bytes . . . . . . . . . . . . 616
Figure 228. Transfer bus diagrams for I2C master transmitter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 617
Figure 229. Transfer sequence flowchart for I2C master receiver for N<=255 bytes . . . . . . . . . . . . . 619
Figure 230. Transfer sequence flowchart for I2C master receiver for N >255 bytes . . . . . . . . . . . . . . 620
Figure 231. Transfer bus diagrams for I2C master receiver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 621
Figure 232. Timeout intervals for tLOW:SEXT, tLOW:MEXT. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 626
Figure 233. Transfer sequence flowchart for SMBus slave transmitter N bytes + PEC. . . . . . . . . . . . 630
Figure 234. Transfer bus diagrams for SMBus slave transmitter (SBC=1) . . . . . . . . . . . . . . . . . . . . . 630
Figure 235. Transfer sequence flowchart for SMBus slave receiver N Bytes + PEC . . . . . . . . . . . . . 632
Figure 236. Bus transfer diagrams for SMBus slave receiver (SBC=1) . . . . . . . . . . . . . . . . . . . . . . . 633
Figure 237. Bus transfer diagrams for SMBus master transmitter . . . . . . . . . . . . . . . . . . . . . . . . . . . . 634
Figure 238. Bus transfer diagrams for SMBus master receiver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 636
Figure 239. I2C interrupt mapping diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 641
Figure 240. USART block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 663
Figure 241. Word length programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 665
Figure 242. Configurable stop bits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 666
Figure 243. TC/TXE behavior when transmitting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 668
Figure 244. Start bit detection when oversampling by 16 or 8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 669
Figure 245. Data sampling when oversampling by 16 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 673
Figure 246. Data sampling when oversampling by 8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 673
38/988
DocID018940 Rev 6
RM0091
Figure 247.
Figure 248.
Figure 249.
Figure 250.
Figure 251.
Figure 252.
Figure 253.
Figure 254.
Figure 255.
Figure 256.
Figure 257.
Figure 258.
Figure 259.
Figure 260.
Figure 261.
Figure 262.
Figure 263.
Figure 264.
Figure 265.
Figure 266.
Figure 267.
Figure 268.
Figure 269.
Figure 270.
Figure 271.
Figure 272.
Figure 273.
Figure 274.
Figure 275.
Figure 276.
Figure 277.
Figure 278.
Figure 279.
Figure 280.
Figure 281.
Figure 282.
Figure 283.
Figure 284.
Figure 285.
Figure 286.
Figure 287.
Figure 288.
Figure 289.
Figure 290.
Figure 291.
Figure 292.
Figure 293.
Figure 294.
Figure 295.
Figure 296.
List of figures
Mute mode using Idle line detection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 680
Mute mode using address mark detection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 681
Break detection in LIN mode (11-bit break length - LBDL bit is set) . . . . . . . . . . . . . . . . . 684
Break detection in LIN mode vs. Framing error detection. . . . . . . . . . . . . . . . . . . . . . . . . 685
USART example of synchronous transmission. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 686
USART data clock timing diagram (M bits = 00). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 686
USART data clock timing diagram (M bits = 01). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 687
RX data setup/hold time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 687
ISO 7816-3 asynchronous protocol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 689
Parity error detection using the 1.5 stop bits. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 690
IrDA SIR ENDEC- block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 694
IrDA data modulation (3/16) -Normal Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 694
Transmission using DMA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 696
Reception using DMA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 697
Hardware flow control between 2 USARTs. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 697
RS232 RTS flow control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 698
RS232 CTS flow control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 699
USART interrupt mapping diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 701
SPI block diagram. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 726
Full-duplex single master/ single slave application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 727
Half-duplex single master/ single slave application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 728
Simplex single master/single slave application (master in transmit-only/
slave in receive-only mode) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 729
Master and three independent slaves. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 730
Hardware/software slave select management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 731
Data clock timing diagram. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 733
Data alignment when data length is not equal to 8-bit or 16-bit . . . . . . . . . . . . . . . . . . . . 734
Packing data in FIFO for transmission and reception . . . . . . . . . . . . . . . . . . . . . . . . . . . . 738
Master full duplex communication. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 741
Slave full duplex communication. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 742
Master full duplex communication with CRC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 743
Master full duplex communication in packed mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 744
NSSP pulse generation in Motorola SPI master mode . . . . . . . . . . . . . . . . . . . . . . . . . . . 747
TI mode transfer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 748
I2S block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 751
I2S Philips protocol waveforms (16/32-bit full accuracy, CPOL = 0). . . . . . . . . . . . . . . . . 753
I2S Philips standard waveforms (24-bit frame with CPOL = 0) . . . . . . . . . . . . . . . . . . . . . 753
Transmitting 0x8EAA33 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 754
Receiving 0x8EAA33 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 754
I2S Philips standard (16-bit extended to 32-bit packet frame
with CPOL = 0) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 754
Example of 16-bit data frame extended to 32-bit channel frame . . . . . . . . . . . . . . . . . . . 754
MSB Justified 16-bit or 32-bit full-accuracy length with CPOL = 0 . . . . . . . . . . . . . . . . . . 755
MSB justified 24-bit frame length with CPOL = 0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 755
MSB justified 16-bit extended to 32-bit packet frame with CPOL = 0 . . . . . . . . . . . . . . . . 755
LSB justified 16-bit or 32-bit full-accuracy with CPOL = 0 . . . . . . . . . . . . . . . . . . . . . . . . 756
LSB justified 24-bit frame length with CPOL = 0. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 756
Operations required to transmit 0x3478AE. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 756
Operations required to receive 0x3478AE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 757
LSB justified 16-bit extended to 32-bit packet frame with CPOL = 0 . . . . . . . . . . . . . . . . 757
Example of 16-bit data frame extended to 32-bit channel frame . . . . . . . . . . . . . . . . . . . 757
PCM standard waveforms (16-bit) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 758
DocID018940 Rev 6
39/988
List of figures
Figure 297.
Figure 298.
Figure 299.
Figure 300.
Figure 301.
Figure 302.
Figure 303.
Figure 304.
Figure 305.
Figure 306.
Figure 307.
Figure 308.
Figure 309.
Figure 310.
Figure 311.
Figure 312.
Figure 313.
Figure 314.
Figure 315.
Figure 316.
Figure 317.
Figure 318.
Figure 319.
Figure 320.
Figure 321.
Figure 322.
Figure 323.
Figure 324.
Figure 325.
Figure 326.
Figure 327.
Figure 328.
Figure 329.
Figure 330.
Figure 331.
Figure 332.
40/988
RM0091
PCM standard waveforms (16-bit extended to 32-bit packet frame). . . . . . . . . . . . . . . . . 758
Audio sampling frequency definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 759
I2S clock generator architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 759
TSC block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 781
Surface charge transfer analog I/O group structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 782
Sampling capacitor voltage variation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 783
Charge transfer acquisition sequence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 784
Spread spectrum variation principle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 785
CAN network topology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 800
bxCAN operating modes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 803
bxCAN in silent mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 804
bxCAN in loop back mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 804
bxCAN in combined mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 805
Transmit mailbox states . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 806
Receive FIFO states . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 807
Filter bank scale configuration - register organization . . . . . . . . . . . . . . . . . . . . . . . . . . . 810
Example of filter numbering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 811
Filtering mechanism - example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 812
CAN error state diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 813
Bit timing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 815
CAN frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 816
Event flags and interrupt generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 817
Can mailbox registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 829
USB peripheral block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 846
Packet buffer areas with examples of buffer description table locations . . . . . . . . . . . . . 850
Block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 879
Message structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 880
Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 880
Bit timings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 881
Signal free time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 881
Arbitration phase. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 882
SFT of three nominal bit periods. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 882
Error bit timing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 883
Error handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 885
TXERR detection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 886
Block diagram of STM32F0xx MCU and Cortex-M0-level debug support . . . . . . . . . . . 897
DocID018940 Rev 6
RM0091
Documentation conventions
Documentation conventions
1.1
List of abbreviations for registers
The following abbreviations are used in register descriptions:
1.2
read/write (rw)
Software can read and write to these bits.
read-only (r)
Software can only read these bits.
write-only (w)
Software can only write to this bit. Reading the bit returns the reset
value.
read/clear (rc_w1)
Software can read as well as clear this bit by writing 1. Writing 0 has
no effect on the bit value.
read/clear (rc_w0)
Software can read as well as clear this bit by writing 0. Writing 1 has
no effect on the bit value.
read/clear by read
(rc_r)
Software can read this bit. Reading this bit automatically clears it to
0. Writing 0 has no effect on the bit value.
read/set (rs)
Software can read as well as set this bit. Writing 0 has no effect on
the bit value.
Reserved (Res.)
Reserved bit, must be kept at reset value.
Glossary
This section gives a brief definition of acronyms and abbreviations used in this document:
Word: data of 32-bit length.
Half-word: data of 16-bit length.
Byte: data of 8-bit length.
SWD-DP (SWD DEBUG PORT): SWD-DP provides a 2-pin (clock and data) interface
based on the Serial Wire Debug (SWD) protocol. Please refer to the Cortex-M0
technical reference manual.
IAP (in-application programming): IAP is the ability to re-program the Flash memory
of a microcontroller while the user program is running.
ICP (in-circuit programming): ICP is the ability to program the Flash memory of a
microcontroller using the JTAG protocol, the SWD protocol or the bootloader while the
device is mounted on the user application board.
Option bytes: product configuration bits stored in the Flash memory.
OBL: option byte loader.
AHB: advanced high-performance bus.
APB: advanced peripheral bus.
DocID018940 Rev 6
41/988
42
Documentation conventions
1.3
RM0091
Peripheral availability
For peripheral availability and number across all sales types, please refer to the particular
device datasheet.
42/988
DocID018940 Rev 6
RM0091
System and memory overview
System and memory overview
2.1
System architecture
The main system consists of:
Two masters:
Cortex-M0 core AHB bus
GP-DMA (general-purpose DMA)
Four slaves:
Internal SRAM
Internal Flash memory
AHB to APB, which connects all the APB peripherals
AHB dedicated to GPIO ports
These are interconnected using a multilayer AHB bus architecture as shown in Figure 1:
Figure 1. System architecture (all features)
&RUWH[
0
)/,7)
)ODVKLQWHUIDFH
6\VWHPEXV
65$0
%XVPDWUL[
'0$
&RQWUROOHU
&KDQQHOV
WR
)ODVKPHPRU\
$+%EXV
*3,2SRUWV
$%&'()
'0$
$+%EXV
$+%$3%
%ULGJH
5HVHWDQG
FORFN
FRQWUROOHU
5&&
7RXFK
VHQVLQJ
FRQWUROOHU
76&
&5&
'0$UHTXHVW
$3%EXV
6<6&)*
$'&
'$&
&203
7,0
7,07,0
7,07,07,07,0
7,0
,:'*
::'*
57&
&56
,&,&
86$5786$57
63,,663,
+'0,&(&
'%*0&8