July 2012 Doc ID 15965 Rev 6 1/822
RM0038
Reference manual
STM32L151xx, STM32L152xx and STM32L162xx
advanced ARM-based 32-bit MCUs
Introduction
This reference manual targets application developers. It provides complete information on
how to use the STM32L151xx, STM32L152xx and STM32L162xx microcontroller memory
and peripherals. The STM32L151xx, STM32L152xx and STM32L162xx will be referred to
as STM32L15xxx throughout the document, unless otherwise specified.
The STM32L15xxx 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 datasheets.
For information on programming, erasing and protection of the internal Flash memory
please refer to the STM32L15xxx 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.ddi0337g/DDI0337G_cortex_m3_r2p0_trm.pdf
Available from www.st.com:
■
STM32L151xx STM32L152xx datasheets
■
STM32L162xx datasheet
■
STM32L15xxx Flash programming manual
Table 1. Applicable products
Type Product sub-class
Microcontroller
STM32L151xx, STM32L152xx and
STM32L162xx
www.st.com
Contents RM0038
2/822 Doc ID 15965 Rev 6
Contents
1 Documentation conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
1.1 List of abbreviations for registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
1.2 Peripheral availability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
2 Memory and bus architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
2.1 System architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
2.2 Memory organization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
2.3 Memory map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
2.3.1 Embedded SRAM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
2.3.2 Bit banding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
2.3.3 Embedded Flash memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
2.4 Boot configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
3 CRC calculation unit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
3.1 CRC introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
3.2 CRC main features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
3.3 CRC functional description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
3.4 CRC registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
3.4.1 Data register (CRC_DR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
3.4.2 Independent data register (CRC_IDR) . . . . . . . . . . . . . . . . . . . . . . . . . 56
3.4.3 Control register (CRC_CR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
3.4.4 CRC register map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
4 Power control (PWR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
4.1 Power supplies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
4.1.1 Independent A/D and DAC converter supply and reference voltage . . . 59
4.1.2 Independent LCD supply . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
4.1.3 RTC and RTC backup registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
4.1.4 Voltage regulator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
4.1.5 Dynamic voltage scaling management . . . . . . . . . . . . . . . . . . . . . . . . . 61
4.1.6 Dynamic voltage scaling configuration . . . . . . . . . . . . . . . . . . . . . . . . . . 63
4.1.7 Voltage regulator and clock management when VDD drops
below 2.0 V . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
RM0038 Contents
Doc ID 15965 Rev 6 3/822
4.1.8 Voltage regulator and clock management when modifying the
VCORE range . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
4.2 Power supply supervisor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
4.2.1 Power on reset (POR)/power down reset (PDR) . . . . . . . . . . . . . . . . . . 67
4.2.2 Brown out reset (BOR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
4.2.3 Programmable voltage detector (PVD) . . . . . . . . . . . . . . . . . . . . . . . . . 68
4.2.4 Internal voltage reference (VREFINT) . . . . . . . . . . . . . . . . . . . . . . . . . . 69
4.3 Low-power modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
4.3.1 Behavior of clocks in low power modes . . . . . . . . . . . . . . . . . . . . . . . . . 71
4.3.2 Slowing down system clocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
4.3.3 Peripheral clock gating . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
4.3.4 Low power run mode (LP run) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
4.3.5 Sleep mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
4.3.6 Low power sleep mode (LP sleep) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
4.3.7 Stop mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
4.3.8 Standby mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
4.3.9 Waking up the device from Stop and Standby modes using the RTC and
comparators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
4.4 Power control registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
4.4.1 PWR power control register (PWR_CR) . . . . . . . . . . . . . . . . . . . . . . . . 81
4.4.2 PWR power control/status register (PWR_CSR) . . . . . . . . . . . . . . . . . . 83
4.4.3 PWR register map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
5 Reset and clock control (RCC) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
5.1 Reset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
5.1.1 System reset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
5.1.2 Power reset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
5.1.3 RTC and backup registers reset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
5.2 Clocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
5.2.1 HSE clock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
5.2.2 HSI clock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
5.2.3 MSI clock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
5.2.4 PLL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
5.2.5 LSE clock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
5.2.6 LSI clock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
5.2.7 System clock (SYSCLK) selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
5.2.8 System clock source frequency versus voltage range . . . . . . . . . . . . . . 93
Contents RM0038
4/822 Doc ID 15965 Rev 6
5.2.9 Clock security system (CSS) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
5.2.10 Clock Security System on LSE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
5.2.11 RTC and LCD clock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
5.2.12 Watchdog clock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
5.2.13 Clock-out capability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
5.2.14 Internal/external clock measurement with TIM9/TIM10/TIM11 . . . . . . . 95
5.2.15 Clock-independent system clock sources for TIM9/TIM10/TIM11 . . . . . 96
5.3 RCC registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
5.3.1 Clock control register (RCC_CR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
5.3.2 Internal clock sources calibration register (RCC_ICSCR) . . . . . . . . . . . 99
5.3.3 Clock configuration register (RCC_CFGR) . . . . . . . . . . . . . . . . . . . . . 100
5.3.4 Clock interrupt register (RCC_CIR) . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
5.3.5 AHB peripheral reset register (RCC_AHBRSTR) . . . . . . . . . . . . . . . . 105
5.3.6 APB2 peripheral reset register (RCC_APB2RSTR) . . . . . . . . . . . . . . 107
5.3.7 APB1 peripheral reset register (RCC_APB1RSTR) . . . . . . . . . . . . . . 108
5.3.8 AHB peripheral clock enable register (RCC_AHBENR) . . . . . . . . . . . 111
5.3.9 APB2 peripheral clock enable register (RCC_APB2ENR) . . . . . . . . . . 113
5.3.10 APB1 peripheral clock enable register (RCC_APB1ENR) . . . . . . . . . . 115
5.3.11 AHB peripheral clock enable in low power mode register
(RCC_AHBLPENR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
5.3.12 APB2 peripheral clock enable in low power mode register
(RCC_APB2LPENR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
5.3.13 APB1 peripheral clock enable in low power mode register
(RCC_APB1LPENR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
5.3.14 Control/status register (RCC_CSR) . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
5.3.15 RCC register map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
6 General-purpose I/Os (GPIO) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
6.1 GPIO introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
6.2 GPIO main features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
6.3 GPIO functional description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
6.3.1 General-purpose I/O (GPIO) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
6.3.2 I/O pin multiplexer and mapping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
6.3.3 I/O port control registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
6.3.4 I/O port data registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
6.3.5 I/O data bitwise handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
6.3.6 GPIO locking mechanism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
6.3.7 I/O alternate function input/output . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
RM0038 Contents
Doc ID 15965 Rev 6 5/822
6.3.8 External interrupt/wakeup lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
6.3.9 Input configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
6.3.10 Output configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
6.3.11 Alternate function configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
6.3.12 Analog configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
6.3.13 Using the OSC32_IN/OSC32_OUT pins as GPIO PC14/PC15
port pins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
6.3.14 Using the OSC_IN/OSC_OUT pins as GPIO PH0/PH1 port pins . . . . 138
6.3.15 Selection of RTC_AF1 alternate functions . . . . . . . . . . . . . . . . . . . . . . 138
6.4 GPIO registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
6.4.1 GPIO port mode register (GPIOx_MODER) (x = A..H) . . . . . . . . . . . . 139
6.4.2 GPIO port output type register (GPIOx_OTYPER) (x = A..H) . . . . . . . 140
6.4.3 GPIO port output speed register (GPIOx_OSPEEDR)
(x = A..H) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
6.4.4 GPIO port pull-up/pull-down register (GPIOx_PUPDR)
(x = A..H) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
6.4.5 GPIO port input data register (GPIOx_IDR) (x = A..H) . . . . . . . . . . . . 141
6.4.6 GPIO port output data register (GPIOx_ODR) (x = A..H) . . . . . . . . . . 141
6.4.7 GPIO port bit set/reset register (GPIOx_BSRR) (x = A..H) . . . . . . . . . 142
6.4.8 GPIO port configuration lock register (GPIOx_LCKR)
(x = A..H) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
6.4.9 GPIO alternate function low register (GPIOx_AFRL) (x = A..H) . . . . . 143
6.4.10 GPIO alternate function high register (GPIOx_AFRH)
(x = A..H) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
6.4.11 GPIO register map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
7 System configuration controller (SYSCFG) and
routing interface (RI) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
7.1 SYSCFG and RI introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
7.2 RI main features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
7.3 RI functional description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
7.3.1 Special I/O configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
7.3.2 Input capture routing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
7.3.3 Reference voltage routing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
7.4 RI registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
7.4.1 RI input capture register (RI_ICR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
7.4.2 RI analog switches control register (RI_ASCR1) . . . . . . . . . . . . . . . . . 157
7.4.3 RI analog switch control register 2 (RI_ASCR2) . . . . . . . . . . . . . . . . . 159