STM32_manual.pdf

(9851 KB) Pobierz
Low-, medium- and high-density STM32F101xx, STM32F102xx and STM32F103xx advanced ARM-based 32-bit MCUs
RM0008
Reference manual
Low-, medium- and high-density STM32F101xx, STM32F102xx
and STM32F103xx advanced ARM-based 32-bit MCUs
Introduction
This reference manual targets application developers. It provides complete information on
how to use the low-, medium- and high-density STM32F101xx, STM32F102xx and
STM32F103xx microcontroller memory and peripherals. The low-, medium- and high-
density STM32F101xx, STM32F102xx and STM32F103xx will be referred to as
STM32F10xxx throughout the document, unless otherwise specified.
The STM32F10xxx is a family of microcontrollers with different memory sizes, packages and
peripherals.
For ordering information, mechanical and electrical device characteristics please refer to the
low-, medium- and high-density STM32F101xx and STM32F103xx datasheets and to the
low- and medium-density STM32F102xx datasheets.
For information on programming, erasing and protection of the internal Flash memory
please refer to the STM32F10xxx Flash programming manual.
For information on the ARM Cortex™-M3 core, please refer to the Cortex™-M3 Technical
Reference Manual .
Related documents
Available from www.arm.com :
Cortex™-M3 Technical Reference Manual, available from:
http://infocenter.arm.com/help/topic/com.arm.doc.ddi0337e/DDI0337E_cortex_m3_r1p1_trm.pdf
Available from www.st.com :
STM32F101xx STM32F103xx datasheets
STM32F10xxx Flash programming manual
December 2008
Rev 7
1/679
745912646.002.png
Contents
RM0008
Contents
1
Documentation conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
1.1
List of abbreviations for registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
1.2
Glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
1.3
Peripheral availability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
2
Memory and bus architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
2.1
System architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
2.2
Memory organization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
2.3
Memory map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
2.3.1
Embedded SRAM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
2.3.2
Bit banding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
2.3.3
Embedded Flash memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
2.4
Boot configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
3
CRC calculation unit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
3.1
CRC introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
3.2
CRC main features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
3.3
CRC functional description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
3.4
CRC registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
3.4.1
Data register (CRC_DR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
3.4.2
Independent data register (CRC_IDR) . . . . . . . . . . . . . . . . . . . . . . . . . 44
3.4.3
Control register (CRC_CR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
3.4.4
CRC register map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
4
Power control (PWR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
4.1
Power supplies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
4.1.1
Independent A/D converter supply and reference voltage . . . . . . . . . . . 46
4.1.2
Battery backup domain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
4.1.3
Voltage regulator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
4.2
Power supply supervisor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
4.2.1
Power on reset (POR)/power down reset (PDR) . . . . . . . . . . . . . . . . . . 47
4.2.2
Programmable voltage detector (PVD) . . . . . . . . . . . . . . . . . . . . . . . . . 48
4.3
Low-power modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
2/679
745912646.003.png
RM0008
Contents
4.3.1
Slowing down system clocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
4.3.2
Peripheral clock gating . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
4.3.3
Sleep mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
4.3.4
Stop mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
4.3.5
Standby mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
4.3.6
Auto-wakeup (AWU) from low-power mode . . . . . . . . . . . . . . . . . . . . . . 54
4.4
Power control registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
4.4.1
Power control register (PWR_CR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
4.4.2
Power control/status register (PWR_CSR) . . . . . . . . . . . . . . . . . . . . . . 56
4.4.3
PWR register map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
5
Backup registers (BKP) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
5.1
BKP introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
5.2
BKP main features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
5.3
BKP functional description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
5.3.1
Tamper detection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
5.3.2
RTC calibration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
5.4
BKP registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
5.4.1
Backup data register x (BKP_DRx) (x = 1 ..42) . . . . . . . . . . . . . . . . . . . 60
5.4.2
RTC clock calibration register (BKP_RTCCR) . . . . . . . . . . . . . . . . . . . . 60
5.4.3
Backup control register (BKP_CR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
5.4.4
Backup control/status register (BKP_CSR) . . . . . . . . . . . . . . . . . . . . . . 62
5.4.5
BKP register map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
6
Reset and clock control (RCC) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
6.1
Reset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
6.1.1
System reset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
6.1.2
Power reset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
6.1.3
Backup domain reset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
6.2
Clocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
6.2.1
HSE clock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
6.2.2
HSI clock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
6.2.3
PLL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
6.2.4
LSE clock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
6.2.5
LSI clock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
6.2.6
System clock (SYSCLK) selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
3/679
745912646.004.png
Contents
RM0008
6.2.7 Clock security system (CSS) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
6.2.8 RTC clock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
6.2.9 Watchdog clock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
6.2.10 Clock-out capability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
6.3
RCC registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
6.3.1 Clock control register (RCC_CR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
6.3.2 Clock configuration register (RCC_CFGR) . . . . . . . . . . . . . . . . . . . . . . 75
6.3.3 Clock interrupt register (RCC_CIR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
6.3.4 APB2 peripheral reset register (RCC_APB2RSTR) . . . . . . . . . . . . . . . 80
6.3.5 APB1 peripheral reset register (RCC_APB1RSTR) . . . . . . . . . . . . . . . 82
6.3.6 AHB peripheral clock enable register (RCC_AHBENR) . . . . . . . . . . . . 84
6.3.7 APB2 peripheral clock enable register (RCC_APB2ENR) . . . . . . . . . . . 85
6.3.8 APB1 peripheral clock enable register (RCC_APB1ENR) . . . . . . . . . . . 87
6.3.9 Backup domain control register (RCC_BDCR) . . . . . . . . . . . . . . . . . . . 89
6.3.10 Control/status register (RCC_CSR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
6.3.11 RCC register map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
7
General-purpose and alternate-function I/Os (GPIOs and AFIOs) . . . 94
7.1
GPIO functional description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
7.1.1 General-purpose I/O (GPIO) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
7.1.2 Atomic bit set or reset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
7.1.3 External interrupt/wakeup lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
7.1.4 Alternate functions (AF) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
7.1.5 Software remapping of I/O alternate functions . . . . . . . . . . . . . . . . . . . 97
7.1.6 GPIO locking mechanism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
7.1.7 Input configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
7.1.8 Output configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
7.1.9 Alternate function configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
7.1.10 Analog input configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
7.2
GPIO registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
7.2.1
Port configuration register low (GPIOx_CRL) (x=A..G) . . . . . . . . . . . . 101
7.2.2
Port configuration register high (GPIOx_CRH) (x=A..G) . . . . . . . . . . . 102
7.2.3
Port input data register (GPIOx_IDR) (x=A..G) . . . . . . . . . . . . . . . . . . 102
7.2.4
Port output data register (GPIOx_ODR) (x=A..G) . . . . . . . . . . . . . . . . 103
7.2.5
Port bit set/reset register (GPIOx_BSRR) (x=A..G) . . . . . . . . . . . . . . . 103
7.2.6
Port bit reset register (GPIOx_BRR) (x=A..G) . . . . . . . . . . . . . . . . . . . 103
7.2.7
Port configuration lock register (GPIOx_LCKR) (x=A..G) . . . . . . . . . . 104
4/679
745912646.005.png
RM0008
Contents
7.3
Alternate function I/O and debug configuration (AFIO) . . . . . . . . . . . . . 105
7.3.1
Using OSC32_IN/OSC32_OUT pins as GPIO ports PC14/PC15 . . . . 105
7.3.2
Using OSC_IN/OSC_OUT pins as GPIO ports PD0/PD1 . . . . . . . . . . 105
7.3.3
CAN alternate function remapping . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
7.3.4
JTAG/SWD alternate function remapping . . . . . . . . . . . . . . . . . . . . . . 105
7.3.5
ADC alternate function remapping . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
7.3.6
Timer alternate function remapping . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
7.3.7
USART Alternate function remapping . . . . . . . . . . . . . . . . . . . . . . . . . 109
7.3.8
I2C 1 alternate function remapping . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
7.3.9
SPI 1 alternate function remapping . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
7.4
AFIO registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
7.4.1
Event control register (AFIO_EVCR) . . . . . . . . . . . . . . . . . . . . . . . . . . 110
7.4.2
AF remap and debug I/O configuration register (AFIO_MAPR) . . . . . . 111
7.4.3
External interrupt configuration register 1 (AFIO_EXTICR1) . . . . . . . . 114
7.4.4
External interrupt configuration register 2 (AFIO_EXTICR2) . . . . . . . . 114
7.4.5
External interrupt configuration register 3 (AFIO_EXTICR3) . . . . . . . . 115
7.4.6
External interrupt configuration register 4 (AFIO_EXTICR4) . . . . . . . . 115
7.5
GPIO and AFIO register maps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
8
Interrupts and events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
8.1
Nested vectored interrupt controller (NVIC) . . . . . . . . . . . . . . . . . . . . . . 117
8.1.1
SysTick calibration value register . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
8.1.2
Interrupt and exception vectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
8.2
External interrupt/event controller (EXTI) . . . . . . . . . . . . . . . . . . . . . . . . 120
8.2.1
Main features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
8.2.2
Block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
8.2.3
Wakeup event management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
8.2.4
Functional description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
8.2.5
External interrupt/event line mapping . . . . . . . . . . . . . . . . . . . . . . . . . 122
8.3
EXTI registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
8.3.1
Interrupt mask register (EXTI_IMR) . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
8.3.2
Event mask register (EXTI_EMR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
8.3.3
Rising trigger selection register (EXTI_RTSR) . . . . . . . . . . . . . . . . . . 125
8.3.4
Falling trigger selection register (EXTI_FTSR) . . . . . . . . . . . . . . . . . . 125
8.3.5
Software interrupt event register (EXTI_SWIER) . . . . . . . . . . . . . . . . . 126
8.3.6
Pending register (EXTI_PR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
5/679
745912646.001.png
Zgłoś jeśli naruszono regulamin