RM0367-STM32L0x3

Introduction

This reference manual targets application developers. It provides complete information on how to use the STM32L0x3 microcontroller memory and peripherals.

The STM32L0x3 is a line 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 the Arm ® Cortex ® -M0+ core, refer to the Cortex ® -M0+ Technical Reference Manual .

The STM32L0x3 microcontrollers include state-of-the-art patented technology.

Contents

1Documentation conventions . . . . .52
1.1General information . . . . .52
1.2List of abbreviations for registers . . . . .52
1.3Glossary . . . . .53
1.4Availability of peripherals . . . . .53
1.5Product category definition . . . . .53
2System and memory overview . . . . .56
2.1System architecture . . . . .56
2.1.1S0: Cortex®-bus . . . . .57
2.1.2S1: DMA-bus . . . . .57
2.1.3BusMatrix . . . . .57
AHB/APB bridges . . . . .57
2.2Memory organization . . . . .58
2.2.1Introduction . . . . .58
2.2.2Memory map and register boundary addresses . . . . .59
2.3Embedded SRAM . . . . .64
2.4Boot configuration . . . . .64
Bank swapping (category 5 devices only) . . . . .65
Physical remap . . . . .65
Embedded bootloader . . . . .65
3Flash program memory and data EEPROM (FLASH) . . . . .66
3.1Introduction . . . . .66
3.2NVM main features . . . . .66
3.3NVM functional description . . . . .67
3.3.1NVM organization . . . . .67
3.3.2Dual-bank boot capability . . . . .71
3.3.3Reading the NVM . . . . .72
Protocol to read . . . . .72
Relation between CPU frequency/Operation mode/NVM read time . . . . .73
Data buffering . . . . .75
3.3.4Writing/erasing the NVM . . . . .81
Write/erase protocol . . . . .81
Unlocking/locking operations . . . . .82
Detailed description of NVM write/erase operations. . . . .85
Parallel write half-page Flash program memory. . . . .91
Status register . . . . .95
3.4    Memory protection . . . . .96
3.4.1    RDP (Read Out Protection) . . . . .97
3.4.2    PcROP (Proprietary Code Read-Out Protection) . . . . .98
3.4.3    Protections against unwanted write/erase operations . . . . .100
3.4.4    Write/erase protection management . . . . .101
3.4.5    Protection errors . . . . .102
Write protection error flag (WRPERR) . . . . .102
Read error (RDERR) . . . . .102
3.5    NVM interrupts . . . . .102
3.5.1    Hard fault . . . . .103
3.6    Memory interface management . . . . .103
3.6.1    Operation priority and evolution . . . . .103
Read . . . . .103
Write/erase . . . . .103
Option byte loading. . . . .104
3.6.2    Sequence of operations . . . . .104
Read as data while write . . . . .104
Fetch while write. . . . .104
Write while another write operation is ongoing. . . . .105
3.6.3    Change the number of wait states while reading . . . . .105
3.6.4    Power-down . . . . .105
3.7    Flash register description . . . . .106
Read registers . . . . .106
Write to registers . . . . .106
3.7.1    Access control register (FLASH_ACR) . . . . .107
3.7.2    Program and erase control register (FLASH_PECR) . . . . .108
3.7.3    Power-down key register (FLASH_PDKEYR) . . . . .112
3.7.4    PECR unlock key register (FLASH_PEKEYR) . . . . .112
3.7.5    Program and erase key register (FLASH_PRGKEYR) . . . . .112
3.7.6    Option bytes unlock key register (FLASH_OPTKEYR) . . . . .113
3.7.7    Status register (FLASH_SR) . . . . .114
3.7.8    Option bytes register (FLASH_OPTR) . . . . .116
3.7.9    Write protection register 1 (FLASH_WRPROT1) . . . . .118
3.7.10   Write protection register 2 (FLASH_WRPROT2) . . . . .119
Segments properties . . . . .134
5.3.5    Firewall initialization . . . . .134
5.3.6    Firewall states . . . . .135
Opening the Firewall . . . . .136
Closing the Firewall . . . . .136
5.4    Firewall registers . . . . .137
5.4.1    Code segment start address (FW_CSSA) . . . . .137
5.4.2    Code segment length (FW_CSL) . . . . .137
5.4.3    Non-volatile data segment start address (FW_NVDSSA) . . . . .138
5.4.4    Non-volatile data segment length (FW_NVDDSL) . . . . .138
5.4.5    Volatile data segment start address (FW_VDSSA) . . . . .139
5.4.6    Volatile data segment length (FW_VDSL) . . . . .139
5.4.7    Configuration register (FW_CR) . . . . .140
5.4.8    Firewall register map . . . . .141
6    Power control (PWR) . . . . .142
6.1    Power supplies . . . . .142
6.1.1    Independent A/D and DAC converter supply and reference voltage . . . . .143
On packages with V REF+ pin . . . . .143
On packages without V REF+ pin . . . . .143
6.1.2    Independent LCD supply . . . . .144
6.1.3    RTC and RTC backup registers . . . . .144
RTC registers access . . . . .144
6.1.4    Voltage regulator . . . . .145
6.1.5    Dynamic voltage scaling management . . . . .145
Range 1 . . . . .145
Range 2 and 3 . . . . .146
6.1.6    Dynamic voltage scaling configuration . . . . .147
6.1.7    Voltage regulator and clock management when VDD drops below 1.71 V . . . . .147
6.1.8    Voltage regulator and clock management when modifying the VCORE range . . . . .147
6.1.9    Voltage range and limitations when VDD ranges from 1.71 V to 2.0 V . . . . .148
6.2    Power supply supervisor . . . . .148
6.2.1    Power-on reset (POR)/power-down reset (PDR) . . . . .150
6.2.2    Brown out reset (BOR) . . . . .150
6.2.3    Programmable voltage detector (PVD) . . . . .151
6.2.4    Internal voltage reference (VREFINT) . . . . .152
7.1Reset .....173
7.1.1System reset .....173
Software reset .....173
Low-power management reset .....173
Option byte loader reset .....173
7.1.2Power reset .....174
7.1.3RTC and backup registers reset .....174
7.2Clocks .....175
7.2.1HSE clock .....178
External source (HSE bypass) .....179
External crystal/ceramic resonator (HSE crystal) .....179
7.2.2HSI16 clock .....179
Calibration .....179
7.2.3MSI clock .....180
Calibration .....180
7.2.4HSI48 clock .....180
7.2.5PLL .....181
7.2.6LSE clock .....182
External source (LSE bypass) .....182
7.2.7LSI clock .....182
LSI measurement .....182
7.2.8System clock (SYSCLK) selection .....183
7.2.9System clock source frequency versus voltage range .....183
7.2.10HSE clock security system (CSS) .....183
7.2.11LSE Clock Security System .....184
7.2.12RTC and LCD clock .....184
7.2.13Watchdog clock .....185
7.2.14Clock-out capability .....185
7.2.15Internal/external clock measurement using TIM21 .....185
7.2.16Clock-independent system clock sources for TIM2/TIM21/TIM22 .....186
7.3RCC registers .....187
7.3.1Clock control register (RCC_CR) .....187
7.3.2Internal clock sources calibration register (RCC_ICSCR) .....190
7.3.3Clock recovery RC register (RCC_CRRRCR) .....191
7.3.4Clock configuration register (RCC_CFGR) .....192
7.3.5Clock interrupt enable register (RCC_CIER) .....194
7.3.6Clock interrupt flag register (RCC_CIFR) .....196
7.3.7Clock interrupt clear register (RCC_CICR) .....197
7.3.8GPIO reset register (RCC_IOPRSTR) . . . . .198
7.3.9AHB peripheral reset register (RCC_AHBRSTR) . . . . .199
7.3.10APB2 peripheral reset register (RCC_APB2RSTR) . . . . .200
7.3.11APB1 peripheral reset register (RCC_APB1RSTR) . . . . .201
7.3.12GPIO clock enable register (RCC_IOPENR) . . . . .204
7.3.13AHB peripheral clock enable register (RCC_AHBENR) . . . . .205
7.3.14APB2 peripheral clock enable register (RCC_APB2ENR) . . . . .207
7.3.15APB1 peripheral clock enable register (RCC_APB1ENR) . . . . .209
7.3.16GPIO clock enable in Sleep mode register (RCC_IOPSMENR) . . . . .212
7.3.17AHB peripheral clock enable in Sleep mode register (RCC_AHBSMENR) . . . . .213
7.3.18APB2 peripheral clock enable in Sleep mode register (RCC_APB2SMENR) . . . . .214
7.3.19APB1 peripheral clock enable in Sleep mode register (RCC_APB1SMENR) . . . . .215
7.3.20Clock configuration register (RCC_CCIPR) . . . . .217
7.3.21Control/status register (RCC_CSR) . . . . .219
7.3.22RCC register map . . . . .223
8Clock recovery system (CRS) . . . . .226
8.1Introduction . . . . .226
8.2CRS main features . . . . .226
8.3CRS implementation . . . . .226
8.4CRS functional description . . . . .227
8.4.1CRS block diagram . . . . .227
8.4.2Synchronization input . . . . .227
8.4.3Frequency error measurement . . . . .228
8.4.4Frequency error evaluation and automatic trimming . . . . .228
8.4.5CRS initialization and configuration . . . . .229
RELOAD value . . . . .229
FELIM value . . . . .229
8.5CRS low-power modes . . . . .230
8.6CRS interrupts . . . . .230
8.7CRS registers . . . . .231
8.7.1CRS control register (CRS_CR) . . . . .231
8.7.2CRS configuration register (CRS_CFGR) . . . . .232
8.7.3CRS interrupt and status register (CRS_ISR) . . . . .233
8.7.4CRS interrupt flag clear register (CRS_ICR) . . . . .235
8.7.5CRS register map . . . . .235
9General-purpose I/Os (GPIO) . . . . .237
9.1Introduction . . . . .237
9.2GPIO main features . . . . .237
9.3GPIO functional description . . . . .237
9.3.1General-purpose I/O (GPIO) . . . . .239
9.3.2I/O pin alternate function multiplexer and mapping . . . . .240
9.3.3I/O port control registers . . . . .241
9.3.4I/O port data registers . . . . .241
9.3.5I/O data bitwise handling . . . . .241
9.3.6GPIO locking mechanism . . . . .241
9.3.7I/O alternate function input/output . . . . .242
9.3.8External interrupt/wakeup lines . . . . .242
9.3.9Input configuration . . . . .242
9.3.10Output configuration . . . . .243
9.3.11Alternate function configuration . . . . .244
9.3.12Analog configuration . . . . .245
9.3.13Using the HSE or LSE oscillator pins as GPIOs . . . . .246
9.3.14Using the GPIO pins in the RTC supply domain . . . . .246
9.4GPIO registers . . . . .246
9.4.1GPIO port mode register (GPIOx_MODER)
(x = A to E and H) . . . . .
246
9.4.2GPIO port output type register (GPIOx_OTYPER)
(x = A to E and H) . . . . .
247
9.4.3GPIO port output speed register (GPIOx_OSPEEDR)
(x = A to E and H) . . . . .
247
9.4.4GPIO port pull-up/pull-down register (GPIOx_PUPDR)
(x = A to E and H) . . . . .
248
9.4.5GPIO port input data register (GPIOx_IDR)
(x = A to E and H) . . . . .
248
9.4.6GPIO port output data register (GPIOx_ODR)
(x = A to E and H) . . . . .
249
9.4.7GPIO port bit set/reset register (GPIOx_BSRR)
(x = A to E and H) . . . . .
249
9.4.8GPIO port configuration lock register (GPIOx_LCKR)
(x = A to E and H) . . . . .
249
Circular mode (in memory-to-peripheral/peripheral-to-memory transfers) . . . . .272
Memory-to-memory mode . . . . .272
Peripheral-to-peripheral mode . . . . .273
Programming transfer direction, assigning source/destination . . . . .273
11.4.5 DMA data width, alignment and endianness . . . . .273
Addressing AHB peripherals not supporting byte/half-word write transfers . . . . .274
11.4.6 DMA error management . . . . .275
11.5 DMA interrupts . . . . .275
11.6 DMA registers . . . . .275
11.6.1 DMA interrupt status register (DMA_ISR) . . . . .276
11.6.2 DMA interrupt flag clear register (DMA_IFCR) . . . . .278
11.6.3 DMA channel x configuration register (DMA_CCRx) . . . . .279
11.6.4 DMA channel x number of data to transfer register (DMA_CNDTRx) . . . . .282
11.6.5 DMA channel x peripheral address register (DMA_CPARx) . . . . .283
11.6.6 DMA channel x memory address register (DMA_CMARx) . . . . .283
11.6.7 DMA channel selection register (DMA_CSELR) . . . . .285
11.6.8 DMA register map . . . . .285
12 Nested vectored interrupt controller (NVIC) . . . . .288
12.1 Main features . . . . .288
12.2 SysTick calibration value register . . . . .288
12.3 Interrupt and exception vectors . . . . .288
13 Extended interrupt and event controller (EXTI) . . . . .291
13.1 Introduction . . . . .291
13.2 EXTI main features . . . . .291
13.3 EXTI functional description . . . . .291
13.3.1 EXTI block diagram . . . . .292
13.3.2 Wakeup event management . . . . .292
13.3.3 Peripherals asynchronous interrupts . . . . .293
13.3.4 Hardware interrupt selection . . . . .293
13.3.5 Hardware event selection . . . . .293
13.3.6 Software interrupt/event selection . . . . .293
13.4 EXTI interrupt/event line mapping . . . . .294
13.5 EXTI registers . . . . .296
13.5.1 EXTI interrupt mask register (EXTI_IMR) . . . . .296
13.5.2 EXTI event mask register (EXTI_EMR) . . . . .296
13.5.3EXTI rising edge trigger selection register (EXTI_RTSR) . . . . .297
13.5.4Falling edge trigger selection register (EXTI_FTSR) . . . . .298
13.5.5EXTI software interrupt event register (EXTI_SWIER) . . . . .298
13.5.6EXTI pending register (EXTI_PR) . . . . .299
13.5.7EXTI register map . . . . .300
14Analog-to-digital converter (ADC) . . . . .301
14.1Introduction . . . . .301
14.2ADC main features . . . . .302
14.3ADC functional description . . . . .303
14.3.1ADC pins and internal signals . . . . .303
14.3.2ADC voltage regulator (ADVREGEN) . . . . .304
Analog reference for the ADC internal voltage regulator . . . . .304
ADVREG enable sequence . . . . .305
ADVREG disable sequence . . . . .305
14.3.3Calibration (ADCAL) . . . . .305
Calibration factor forcing software procedure . . . . .307
14.3.4ADC on-off control (ADEN, ADDIS, ADRDY) . . . . .307
14.3.5ADC clock (CKMODE, PRESC[3:0], LFMEN) . . . . .308
Low frequency . . . . .309
14.3.6ADC connectivity . . . . .310
14.3.7Configuring the ADC . . . . .311
14.3.8Channel selection (CHSEL, SCANDIR) . . . . .311
Temperature sensor, V REFINT and LCD_VLCD1 internal channels . . . . .311
14.3.9Programmable sampling time (SMP) . . . . .312
14.3.10Single conversion mode (CONT = 0) . . . . .312
14.3.11Continuous conversion mode (CONT = 1) . . . . .313
14.3.12Starting conversions (ADSTART) . . . . .313
14.3.13Timings . . . . .314
14.3.14Stopping an ongoing conversion (ADSTP) . . . . .315
14.4Conversion on external trigger and trigger polarity (EXTSEL, EXTEN) . . . . .315
14.4.1Discontinuous mode (DISCEN) . . . . .316
14.4.2Programmable resolution (RES) - Fast conversion mode . . . . .316
14.4.3End of conversion, end of sampling phase (EOC, EOSMP flags) . . . . .317
14.4.4End of conversion sequence (EOS flag) . . . . .317
14.4.5Example timing diagrams (single/continuous modes
hardware/software triggers) . . . . .
318
14.5Data management . . . . .320
14.5.1Data register and data alignment (ADC_DR, ALIGN) . . . . .320
14.5.2ADC overrun (OVR, OVRMOD) . . . . .320
14.5.3Managing a sequence of data converted without using the DMA . . . . .321
14.5.4Managing converted data without using the DMA without overrun . . . . .321
14.5.5Managing converted data using the DMA . . . . .321
DMA one shot mode (DMACFG = 0) . . . . .322
DMA circular mode (DMACFG = 1) . . . . .322
14.6Low-power features . . . . .323
14.6.1Wait mode conversion . . . . .323
14.6.2Auto-off mode (AUTOFF) . . . . .324
14.7Analog window watchdog (AWDEN, AWDSGL, AWDCH,
ADC_TR) . . . . .
325
14.7.1Description of the analog watchdog . . . . .325
14.7.2ADC_AWD1_OUT output signal generation . . . . .326
14.7.3Analog watchdog threshold control . . . . .328
14.8Oversampler . . . . .329
14.8.1ADC operating modes supported when oversampling . . . . .331
14.8.2Analog watchdog . . . . .331
14.8.3Triggered mode . . . . .331
14.9Temperature sensor and internal reference voltage . . . . .332
Main features . . . . .333
Reading the temperature . . . . .333
Calculating the actual V DDA voltage using the internal reference voltage . . . . .334
Converting a supply-relative ADC measurement to an absolute voltage value . . . . .334
14.10VLCD voltage monitoring . . . . .334
14.11ADC interrupts . . . . .335
14.12ADC registers . . . . .336
14.12.1ADC interrupt and status register (ADC_ISR) . . . . .336
14.12.2ADC interrupt enable register (ADC_IER) . . . . .337
14.12.3ADC control register (ADC_CR) . . . . .339
14.12.4ADC configuration register 1 (ADC_CFGR1) . . . . .341
14.12.5ADC configuration register 2 (ADC_CFGR2) . . . . .345
14.12.6ADC sampling time register (ADC_SMPR) . . . . .346
14.12.7ADC watchdog threshold register (ADC_TR) . . . . .347
14.12.8ADC channel selection register (ADC_CHSELR) . . . . .347
14.12.9ADC data register (ADC_DR) . . . . .348
14.12.10ADC Calibration factor (ADC_CALFACT) . . . . .348
15.10.1DAC control register (DAC_CR) . . . . .364
15.10.2DAC software trigger register (DAC_SWTRIGR) . . . . .368
15.10.3DAC channel1 12-bit right-aligned data holding register
(DAC_DHR12R1) . . . . .
368
15.10.4DAC channel1 12-bit left-aligned data holding register
(DAC_DHR12L1) . . . . .
369
15.10.5DAC channel1 8-bit right-aligned data holding register
(DAC_DHR8R1) . . . . .
369
15.10.6DAC channel2 12-bit right-aligned data holding register
(DAC_DHR12R2) . . . . .
369
15.10.7DAC channel2 12-bit left-aligned data holding register
(DAC_DHR12L2) . . . . .
370
15.10.8DAC channel2 8-bit right-aligned data holding register
(DAC_DHR8R2) . . . . .
370
15.10.9Dual DAC 12-bit right-aligned data holding register
(DAC_DHR12RD) . . . . .
371
15.10.10Dual DAC 12-bit left-aligned data holding register
(DAC_DHR12LD) . . . . .
371
15.10.11Dual DAC 8-bit right-aligned data holding register
(DAC_DHR8RD) . . . . .
371
15.10.12DAC channel1 data output register (DAC_DOR1) . . . . .372
15.10.13DAC channel2 data output register (DAC_DOR2) . . . . .372
15.10.14DAC status register (DAC_SR) . . . . .372
15.10.15DAC register map . . . . .374
16Comparator (COMP) . . . . .376
16.1Introduction . . . . .376
16.2COMP main features . . . . .376
16.3COMP functional description . . . . .377
16.3.1COMP block diagram . . . . .377
16.3.2COMP pins and internal signals . . . . .377
16.3.3COMP reset and clocks . . . . .378
16.3.4Comparator LOCK mechanism . . . . .378
16.3.5Power mode . . . . .378
16.4COMP interrupts . . . . .378
16.5COMP registers . . . . .378
16.5.1Comparator 1 control and status register (COMP1_CSR) . . . . .378
16.5.2Comparator 2 control and status register (COMP2_CSR) . . . . .380
16.5.3COMP register map . . . . .382
17Liquid crystal display controller (LCD) . . . . .383
17.1Introduction . . . . .383
Glossary . . . . .383
17.2LCD main features . . . . .384
17.3LCD implementation . . . . .385
17.4LCD functional description . . . . .385
17.4.1General description . . . . .385
17.4.2Frequency generator . . . . .386
17.4.3Common driver . . . . .387
COM signal bias . . . . .387
COM signal duty . . . . .388
8 to 1 Mux. . . . .390
17.4.4Segment driver . . . . .390
In the case of 1/4 or 1/8 duty . . . . .390
Blink . . . . .394
17.4.5Voltage generator and contrast control . . . . .394
LCD supply source . . . . .394
LCD intermediate voltages . . . . .395
LCD drive selection . . . . .395
External decoupling . . . . .397
Deadtime . . . . .397
17.4.6Double buffer memory . . . . .398
17.4.7COM and SEG multiplexing . . . . .398
Output pins versus duty modes . . . . .398
Remapping capability for small packages . . . . .398
Summary of COM and SEG functions versus duty and remap . . . . .399
17.4.8Flowchart . . . . .403
17.5LCD low-power modes . . . . .404
17.6LCD interrupts . . . . .404
Start of frame (SOF) . . . . .404
Update display done (UDD) . . . . .404
17.7LCD registers . . . . .405
17.7.1LCD control register (LCD_CR) . . . . .405
17.7.2LCD frame control register (LCD_FCR) . . . . .406
17.7.3LCD status register (LCD_SR) . . . . .408
17.7.4LCD clear register (LCD_CLR) . . . . .409
17.7.5LCD display memory (LCD_RAM) . . . . .410
17.7.6LCD register map . . . . .411
18Touch sensing controller (TSC) . . . . .413
18.1Introduction . . . . .413
18.2TSC main features . . . . .413
18.3TSC functional description . . . . .414
18.3.1TSC block diagram . . . . .414
18.3.2Surface charge transfer acquisition overview . . . . .414
18.3.3Reset and clocks . . . . .416
18.3.4Charge transfer acquisition sequence . . . . .417
18.3.5Spread spectrum feature . . . . .418
18.3.6Max count error . . . . .418
18.3.7Sampling capacitor I/O and channel I/O mode selection . . . . .419
18.3.8Acquisition mode . . . . .420
18.3.9I/O hysteresis and analog switch control . . . . .420
18.4TSC low-power modes . . . . .421
18.5TSC interrupts . . . . .421
18.6TSC registers . . . . .422
18.6.1TSC control register (TSC_CR) . . . . .422
18.6.2TSC interrupt enable register (TSC_IER) . . . . .424
18.6.3TSC interrupt clear register (TSC_ICR) . . . . .425
18.6.4TSC interrupt status register (TSC_ISR) . . . . .426
18.6.5TSC I/O hysteresis control register (TSC_IOHCR) . . . . .426
18.6.6TSC I/O analog switch control register
(TSC_IOASCR) . . . . .
427
18.6.7TSC I/O sampling control register (TSC_IOSCR) . . . . .427
18.6.8TSC I/O channel control register (TSC_IOCCR) . . . . .428
18.6.9TSC I/O group control status register (TSC_IOGCSR) . . . . .428
18.6.10TSC I/O group x counter register (TSC_IOGxCR) . . . . .429
18.6.11TSC register map . . . . .430
19AES hardware accelerator (AES) . . . . .432
19.1Introduction . . . . .432
19.2AES main features . . . . .432
19.3AES implementation . . . . .433
19.4AES functional description . . . . .433
19.4.1AES block diagram . . . . .433
19.4.2AES internal signals . . . . .433
19.7.1AES control register (AES_CR) . . . . .457
19.7.2AES status register (AES_SR) . . . . .459
19.7.3AES data input register (AES_DINR) . . . . .460
19.7.4AES data output register (AES_DOUTR) . . . . .460
19.7.5AES key register 0 (AES_KEYR0) . . . . .461
19.7.6AES key register 1 (AES_KEYR1) . . . . .462
19.7.7AES key register 2 (AES_KEYR2) . . . . .462
19.7.8AES key register 3 (AES_KEYR3) . . . . .462
19.7.9AES initialization vector register 0 (AES_IVR0) . . . . .463
19.7.10AES initialization vector register 1 (AES_IVR1) . . . . .463
19.7.11AES initialization vector register 2 (AES_IVR2) . . . . .464
19.7.12AES initialization vector register 3 (AES_IVR3) . . . . .464
19.7.13AES register map . . . . .464
20True random number generator (RNG) . . . . .466
20.1Introduction . . . . .466
20.2RNG main features . . . . .466
20.3RNG functional description . . . . .467
20.3.1RNG block diagram . . . . .467
20.3.2RNG internal signals . . . . .467
20.3.3Random number generation . . . . .468
Noise source . . . . .469
Post processing . . . . .469
Output buffer . . . . .469
Health checks . . . . .470
20.3.4RNG initialization . . . . .470
20.3.5RNG operation . . . . .470
Normal operations . . . . .470
Low-power operations . . . . .471
Software post-processing . . . . .471
20.3.6RNG clocking . . . . .471
20.3.7Error management . . . . .471
Clock error detection . . . . .471
Noise source error detection . . . . .472
20.3.8RNG low-power usage . . . . .472
20.4RNG interrupts . . . . .472
20.5RNG processing time . . . . .472
20.6RNG entropy source validation . . . . .473
20.6.1Introduction . . . . .473
20.6.2Validation conditions . . . . .473
20.6.3Data collection . . . . .473
20.7RNG registers . . . . .473
20.7.1RNG control register (RNG_CR) . . . . .473
20.7.2RNG status register (RNG_SR) . . . . .475
20.7.3RNG data register (RNG_DR) . . . . .476
20.7.4RNG register map . . . . .476
21General-purpose timers (TIM2/TIM3) . . . . .477
21.1TIM2/TIM3 introduction . . . . .477
21.2TIM2/TIM3 main features . . . . .477
21.3TIM2/TIM3 functional description . . . . .479
21.3.1Time-base unit . . . . .479
Prescaler description . . . . .479
21.3.2Counter modes . . . . .481
Upcounting mode . . . . .481
Downcounting mode . . . . .484
Center-aligned mode (up/down counting) . . . . .487
21.3.3Clock selection . . . . .491
Internal clock source (CK_INT) . . . . .491
External clock source mode 1 . . . . .492
External clock source mode 2 . . . . .494
21.3.4Capture/compare channels . . . . .495
21.3.5Input capture mode . . . . .497
21.3.6PWM input mode . . . . .499
21.3.7Forced output mode . . . . .500
21.3.8Output compare mode . . . . .500
21.3.9PWM mode . . . . .501
PWM edge-aligned mode . . . . .502
Downcounting configuration . . . . .503
PWM center-aligned mode . . . . .503
21.3.10One-pulse mode . . . . .505
Particular case: OCx fast enable: . . . . .506
21.3.11Clearing the OCxREF signal on an external event . . . . .506
21.3.12Encoder interface mode . . . . .507
21.3.13Timer input XOR function . . . . .509
21.3.14Timers and external trigger synchronization . . . . .510
Slave mode: Reset mode . . . . .510
Slave mode: Gated mode . . . . .511
Slave mode: Trigger mode . . . . .512
Slave mode: External Clock mode 2 + trigger mode . . . . .513
21.3.15Timer synchronization . . . . .514
Using one timer as prescaler for another timer . . . . .514
Using one timer to enable another timer . . . . .515
Using one timer to start another timer . . . . .517
Starting 2 timers synchronously in response to an external trigger . . . . .519
21.3.16Debug mode . . . . .520
21.4TIM2/TIM3 registers . . . . .521
21.4.1TIMx control register 1 (TIMx_CR1) . . . . .521
21.4.2TIMx control register 2 (TIMx_CR2) . . . . .523
21.4.3TIMx slave mode control register (TIMx_SMCR) . . . . .524
21.4.4TIMx DMA/Interrupt enable register (TIMx_DIER) . . . . .526
21.4.5TIMx status register (TIMx_SR) . . . . .527
21.4.6TIMx event generation register (TIMx_EGR) . . . . .529
21.4.7TIMx capture/compare mode register 1 (TIMx_CCMR1) . . . . .530
Output compare mode . . . . .530
Input capture mode. . . . .531
21.4.8TIMx capture/compare mode register 2 (TIMx_CCMR2) . . . . .533
Output compare mode . . . . .533
Input capture mode. . . . .534
21.4.9TIMx capture/compare enable register (TIMx_CCER) . . . . .534
21.4.10TIMx counter (TIMx_CNT) . . . . .536
21.4.11TIMx prescaler (TIMx_PSC) . . . . .536
21.4.12TIMx auto-reload register (TIMx_ARR) . . . . .536
21.4.13TIMx capture/compare register 1 (TIMx_CCR1) . . . . .537
21.4.14TIMx capture/compare register 2 (TIMx_CCR2) . . . . .537
21.4.15TIMx capture/compare register 3 (TIMx_CCR3) . . . . .538
21.4.16TIMx capture/compare register 4 (TIMx_CCR4) . . . . .538
21.4.17TIMx DMA control register (TIMx_DCR) . . . . .539
21.4.18TIMx DMA address for full transfer (TIMx_DMAR) . . . . .539
Example of how to use the DMA burst feature . . . . .540
21.4.19TIM2 option register (TIM2_OR) . . . . .541
21.4.20TIM3 option register (TIM3_OR) . . . . .542
21.5TIMx register map . . . . .543
22General-purpose timers (TIM21/22) . . . . .545
22.1Introduction . . . . .545
22.2TIM21/22 main features . . . . .545
22.2.1TIM21/22 main features . . . . .545
22.3TIM21/22 functional description . . . . .547
22.3.1Timebase unit . . . . .547
Prescaler description . . . . .547
22.3.2Counter modes . . . . .549
Upcounting mode . . . . .549
Downcounting mode . . . . .553
Center-aligned mode (up/down counting) . . . . .556
22.3.3Clock selection . . . . .560
Internal clock source (CK_INT) . . . . .560
External clock source mode 2 . . . . .562
22.3.4Capture/compare channels . . . . .563
22.3.5Input capture mode . . . . .565
22.3.6PWM input mode . . . . .567
22.3.7Forced output mode . . . . .568
22.3.8Output compare mode . . . . .568
22.3.9PWM mode . . . . .569
PWM center-aligned mode . . . . .571
Hints on using center-aligned mode . . . . .572
22.3.10Clearing the OCxREF signal on an external event . . . . .572
22.3.11One-pulse mode . . . . .573
Particular case: OCx fast enable . . . . .575
22.3.12Encoder interface mode . . . . .575
22.3.13TIM21/22 external trigger synchronization . . . . .577
Slave mode: Reset mode . . . . .577
Slave mode: Gated mode . . . . .578
Slave mode: Trigger mode . . . . .579
22.3.14Timer synchronization (TIM21/22) . . . . .580
22.3.15Debug mode . . . . .580
22.4TIM21/22 registers . . . . .581
22.4.1TIM21/22 control register 1 (TIMx_CR1) . . . . .581
22.4.2TIM21/22 control register 2 (TIMx_CR2) . . . . .583
22.4.3TIM21/22 slave mode control register (TIMx_SMCR) . . . . .584
22.4.4TIM21/22 Interrupt enable register (TIMx_DIER) . . . . .587
22.4.5TIM21/22 status register (TIMx_SR) . . . . .587
22.4.6TIM21/22 event generation register (TIMx_EGR) . . . . .589
22.4.7TIM21/22 capture/compare mode register 1 (TIMx_CCMR1) . . . . .590
Output compare mode . . . . .590
Input capture mode. . . . .592
22.4.8TIM21/22 capture/compare enable register (TIMx_CCER) . . . . .593
22.4.9TIM21/22 counter (TIMx_CNT) . . . . .594
22.4.10TIM21/22 prescaler (TIMx_PSC) . . . . .594
22.4.11TIM21/22 auto-reload register (TIMx_ARR) . . . . .594
22.4.12TIM21/22 capture/compare register 1 (TIMx_CCR1) . . . . .595
22.4.13TIM21/22 capture/compare register 2 (TIMx_CCR2) . . . . .595
22.4.14TIM21 option register (TIM21_OR) . . . . .596
22.4.15TIM22 option register (TIM22_OR) . . . . .597
22.4.16TIM21/22 register map . . . . .598
23Basic timers (TIM6/7) . . . . .600
23.1Introduction . . . . .600
23.2TIM6/7 main features . . . . .600
23.3TIM6/7 functional description . . . . .601
23.3.1Time-base unit . . . . .601
Prescaler description . . . . .601
23.3.2Counting mode . . . . .603
23.3.3Clock source . . . . .606
23.3.4Debug mode . . . . .607
23.4TIM6/7 registers . . . . .608
23.4.1TIM6/7 control register 1 (TIMx_CR1) . . . . .608
23.4.2TIM6/7 control register 2 (TIMx_CR2) . . . . .609
23.4.3TIM6/7 DMA/Interrupt enable register (TIMx_DIER) . . . . .609
23.4.4TIM6/7 status register (TIMx_SR) . . . . .610
23.4.5TIM6/7 event generation register (TIMx_EGR) . . . . .610
23.4.6TIM6/7 counter (TIMx_CNT) . . . . .610
23.4.7TIM6/7 prescaler (TIMx_PSC) . . . . .611
23.4.8TIM6/7 auto-reload register (TIMx_ARR) . . . . .611
23.4.9TIM6/7 register map . . . . .612
24Low-power timer (LPTIM) . . . . .613
24.1Introduction . . . . .613
24.2LPTIM main features . . . . .613

25.3.2Window option . . . . .635
Configuring the IWDG when the window option is enabled . . . . .635
Configuring the IWDG when the window option is disabled . . . . .635
25.3.3Hardware watchdog . . . . .636
25.3.4Register access protection . . . . .636
25.3.5Debug mode . . . . .636
25.4IWDG registers . . . . .637
25.4.1IWDG key register (IWDG_KR) . . . . .637
25.4.2IWDG prescaler register (IWDG_PR) . . . . .638
25.4.3IWDG reload register (IWDG_RLR) . . . . .639
25.4.4IWDG status register (IWDG_SR) . . . . .640
25.4.5IWDG window register (IWDG_WINR) . . . . .641
25.4.6IWDG register map . . . . .642
26System window watchdog (WWDG) . . . . .643
26.1Introduction . . . . .643
26.2WWDG main features . . . . .643
26.3WWDG functional description . . . . .643
26.3.1WWDG block diagram . . . . .644
26.3.2Enabling the watchdog . . . . .644
26.3.3Controlling the down-counter . . . . .644
26.3.4How to program the watchdog timeout . . . . .644
26.3.5Debug mode . . . . .646
26.4WWDG interrupts . . . . .646
26.5WWDG registers . . . . .646
26.5.1WWDG control register (WWDG_CR) . . . . .646
26.5.2WWDG configuration register (WWDG_CFR) . . . . .647
26.5.3WWDG status register (WWDG_SR) . . . . .647
26.5.4WWDG register map . . . . .648
27Real-time clock (RTC) . . . . .649
27.1Introduction . . . . .649
27.2RTC main features . . . . .650
27.3RTC implementation . . . . .650
27.4RTC functional description . . . . .651
27.4.1RTC block diagram . . . . .651
27.4.2GPIOs controlled by the RTC . . . . .652
27.4.3Clock and prescalers . . . . .653
27.4.4Real-time clock and calendar . . . . .654
27.4.5Programmable alarms . . . . .655
27.4.6Periodic auto-wakeup . . . . .655
27.4.7RTC initialization and configuration . . . . .656
RTC register access . . . . .656
RTC register write protection . . . . .656
Calendar initialization and configuration . . . . .656
Daylight saving time . . . . .657
Programming the alarm . . . . .657
Programming the wakeup timer . . . . .657
27.4.8Reading the calendar . . . . .657
When BYPSHAD control bit is cleared in the RTC_CR register. . . . .657
When the BYPSHAD control bit is set in the RTC_CR register (bypass shadow registers) . . . . .658
27.4.9Resetting the RTC . . . . .658
27.4.10RTC synchronization . . . . .659
27.4.11RTC reference clock detection . . . . .659
27.4.12RTC smooth digital calibration . . . . .660
Calibration when PREDIV_A<3 . . . . .661
Verifying the RTC calibration . . . . .661
Re-calibration on-the-fly . . . . .662
27.4.13Time-stamp function . . . . .662
27.4.14Tamper detection . . . . .663
RTC backup registers . . . . .663
Tamper detection initialization . . . . .663
Trigger output generation on tamper event . . . . .664
Timestamp on tamper event . . . . .664
Edge detection on tamper inputs . . . . .664
Level detection with filtering on RTC_TAMPx inputs . . . . .664
27.4.15Calibration clock output . . . . .665
27.4.16Alarm output . . . . .665
Alarm output . . . . .665
27.5RTC low-power modes . . . . .666
27.6RTC interrupts . . . . .666
27.7RTC registers . . . . .667
27.7.1RTC time register (RTC_TR) . . . . .667
27.7.2RTC date register (RTC_DR) . . . . .668
27.7.3RTC control register (RTC_CR) . . . . .669
27.7.4RTC initialization and status register (RTC_ISR) . . . . .672
27.7.5RTC prescaler register (RTC_PRER) . . . . .675
27.7.6RTC wakeup timer register (RTC_WUTR) . . . . .676
27.7.7RTC alarm A register (RTC_ALRMAR) . . . . .677
27.7.8RTC alarm B register (RTC_ALRMBR) . . . . .678
27.7.9RTC write protection register (RTC_WPR) . . . . .679
27.7.10RTC sub second register (RTC_SSR) . . . . .679
27.7.11RTC shift control register (RTC_SHIFTR) . . . . .680
27.7.12RTC timestamp time register (RTC_TSTR) . . . . .681
27.7.13RTC timestamp date register (RTC_TSDR) . . . . .682
27.7.14RTC time-stamp sub second register (RTC_TSSSR) . . . . .683
27.7.15RTC calibration register (RTC_CALR) . . . . .684
27.7.16RTC tamper configuration register (RTC_TAMPCR) . . . . .685
27.7.17RTC alarm A sub second register (RTC_ALRMASSR) . . . . .688
27.7.18RTC alarm B sub second register (RTC_ALRMBSSR) . . . . .689
27.7.19RTC option register (RTC_OR) . . . . .690
27.7.20RTC backup registers (RTC_BKPxR) . . . . .690
27.7.21RTC register map . . . . .691
28Inter-integrated circuit (I2C) interface . . . . .693
28.1Introduction . . . . .693
28.2I2C main features . . . . .693
28.3I2C implementation . . . . .694
28.4I2C functional description . . . . .694
28.4.1I2C1/3 block diagram . . . . .695
28.4.2I2C2 block diagram . . . . .696
28.4.3I2C pins and internal signals . . . . .697
28.4.4I2C clock requirements . . . . .697
28.4.5Mode selection . . . . .697
Communication flow . . . . .698
28.4.6I2C initialization . . . . .698
Enabling and disabling the peripheral . . . . .698
Noise filters . . . . .698
I2C timings . . . . .700
28.4.7Software reset . . . . .703
28.4.8Data transfer . . . . .704
Bus error (BERR) . . . . .741
Arbitration lost (ARLO) . . . . .742
Overrun/underrun error (OVR) . . . . .742
Packet error checking error (PECERR) . . . . .742
Timeout Error (TIMEOUT) . . . . .742
Alert (ALERT) . . . . .743
28.4.18 DMA requests . . . . .743
Transmission using DMA . . . . .743
Reception using DMA . . . . .744
28.4.19 Debug mode . . . . .744
28.5 I2C low-power modes . . . . .744
28.6 I2C interrupts . . . . .745
28.7 I2C registers . . . . .746
28.7.1 I2C control register 1 (I2C_CR1) . . . . .746
28.7.2 I2C control register 2 (I2C_CR2) . . . . .749
28.7.3 I2C own address 1 register (I2C_OAR1) . . . . .751
28.7.4 I2C own address 2 register (I2C_OAR2) . . . . .752
28.7.5 I2C timing register (I2C_TIMINGR) . . . . .753
28.7.6 I2C timeout register (I2C_TIMEOUTR) . . . . .754
28.7.7 I2C interrupt and status register (I2C_ISR) . . . . .755
28.7.8 I2C interrupt clear register (I2C_ICR) . . . . .757
28.7.9 I2C PEC register (I2C_PECR) . . . . .758
28.7.10 I2C receive data register (I2C_RXDR) . . . . .759
28.7.11 I2C transmit data register (I2C_TXDR) . . . . .759
28.7.12 I2C register map . . . . .760
29 Universal synchronous/asynchronous receiver transmitter (USART/UART) . . . . .762
29.1 Introduction . . . . .762
29.2 USART main features . . . . .762
29.3 USART extended features . . . . .763
29.4 USART implementation . . . . .764
29.5 USART functional description . . . . .764
29.5.1 USART character description . . . . .767
29.5.2 USART transmitter . . . . .769
Character transmission . . . . .769
Single byte communication . . . . .770
Break characters . . . . .771
Idle characters . . . . .771
29.5.3 USART receiver . . . . .772
Start bit detection . . . . .772
Character reception . . . . .773
Break character . . . . .773
Idle character . . . . .773
Overrun error . . . . .774
Selecting the proper oversampling method . . . . .774
Framing error . . . . .776
Configurable stop bits during reception . . . . .777
29.5.4 USART baud rate generation . . . . .777
How to derive USARTDIV from USART_BRR register values . . . . .778
29.5.5 Tolerance of the USART receiver to clock deviation . . . . .779
29.5.6 USART auto baud rate detection . . . . .781
29.5.7 Multiprocessor communication using USART . . . . .782
Idle line detection (WAKE=0) . . . . .783
4-bit/7-bit address mark detection (WAKE=1) . . . . .783
29.5.8 Modbus communication using USART . . . . .784
Modbus/RTU . . . . .784
Modbus/ASCII . . . . .784
29.5.9 USART parity control . . . . .785
Even parity . . . . .785
Odd parity . . . . .785
Parity checking in reception . . . . .785
Parity generation in transmission . . . . .785
29.5.10 USART LIN (local interconnection network) mode . . . . .786
LIN transmission . . . . .786
LIN reception . . . . .786
29.5.11 USART synchronous mode . . . . .788
29.5.12 USART Single-wire Half-duplex communication . . . . .791
29.5.13 USART Smartcard mode . . . . .791
Block mode (T=1) . . . . .794
Direct and inverse convention . . . . .795
29.5.14 USART IrDA SIR ENDEC block . . . . .796
IrDA low-power mode . . . . .797
29.5.15 USART continuous communication in DMA mode . . . . .798
Transmission using DMA . . . . .798
Reception using DMA . . . . .799
Error flagging and interrupt generation in multibuffer communication . . . . .800
29.5.16RS232 hardware flow control and RS485 driver enable using USART . . . . .800
RS232 RTS flow control . . . . .801
RS232 CTS flow control . . . . .801
RS485 Driver Enable . . . . .802
29.5.17Wakeup from Stop mode using USART . . . . .802
Using Mute mode with Stop mode . . . . .803
Determining the maximum USART baud rate allowing to wakeup correctly from Stop mode when the USART clock source is the HSI clock. . . . .803
29.6USART in low-power modes . . . . .804
29.7USART interrupts . . . . .804
29.8USART registers . . . . .806
29.8.1USART control register 1 (USART_CR1) . . . . .806
29.8.2USART control register 2 (USART_CR2) . . . . .809
29.8.3USART control register 3 (USART_CR3) . . . . .813
29.8.4USART baud rate register (USART_BRR) . . . . .817
29.8.5USART guard time and prescaler register (USART_GTPR) . . . . .817
29.8.6USART receiver timeout register (USART_RTOR) . . . . .818
29.8.7USART request register (USART_RQR) . . . . .819
29.8.8USART interrupt and status register (USART_ISR) . . . . .820
29.8.9USART interrupt flag clear register (USART_ICR) . . . . .825
29.8.10USART receive data register (USART_RDR) . . . . .826
29.8.11USART transmit data register (USART_TDR) . . . . .826
29.8.12USART register map . . . . .827
30Low-power universal asynchronous receiver transmitter (LPUART) . . . . .829
30.1Introduction . . . . .829
30.2LPUART main features . . . . .830
30.3LPUART implementation . . . . .830
30.4LPUART functional description . . . . .831
30.4.1LPUART character description . . . . .833
30.4.2LPUART transmitter . . . . .835
Character transmission. . . . .835
Single byte communication. . . . .836
Break characters . . . . .837
Idle characters . . . . .837
30.4.3LPUART receiver . . . . .837
Start bit detection . . . . .837
Character reception . . . . .838
Break character . . . . .838
Idle character . . . . .838
Overrun error . . . . .839
Selecting the clock source . . . . .839
Framing error . . . . .840
Configurable stop bits during reception . . . . .840
30.4.4 LPUART baud rate generation . . . . .840
30.4.5 Tolerance of the LPUART receiver to clock deviation . . . . .842
30.4.6 Multiprocessor communication using LPUART . . . . .843
Idle line detection (WAKE=0) . . . . .843
4-bit/7-bit address mark detection (WAKE=1) . . . . .844
30.4.7 LPUART parity control . . . . .845
Even parity . . . . .845
Odd parity . . . . .845
Parity checking in reception . . . . .846
Parity generation in transmission . . . . .846
30.4.8 Single-wire Half-duplex communication using LPUART . . . . .846
30.4.9 Continuous communication in DMA mode using LPUART . . . . .846
Transmission using DMA . . . . .847
Reception using DMA . . . . .848
Error flagging and interrupt generation in multibuffer communication . . . . .849
30.4.10 RS232 Hardware flow control and RS485 Driver Enable using LPUART . . . . .849
RS232 RTS flow control . . . . .850
RS232 CTS flow control . . . . .850
RS485 Driver Enable . . . . .851
30.4.11 Wakeup from Stop mode using LPUART . . . . .852
Using Mute mode with Stop mode . . . . .853
Determining the maximum LPUART baud rate allowing to wakeup correctly from Stop mode when the LPUART clock source is the HSI clock . . . . .853
30.5 LPUART in low-power mode . . . . .854
30.6 LPUART interrupts . . . . .854
30.7 LPUART registers . . . . .856
30.7.1 Control register 1 (LPUART_CR1) . . . . .856
30.7.2 Control register 2 (LPUART_CR2) . . . . .859
30.7.3 Control register 3 (LPUART_CR3) . . . . .861
30.7.4 Baud rate register (LPUART_BRR) . . . . .863
30.7.5 Request register (LPUART_RQR) . . . . .863
30.7.6Interrupt & status register (LPUART_ISR) . . . . .864
30.7.7Interrupt flag clear register (LPUART_ICR) . . . . .867
30.7.8Receive data register (LPUART_RDR) . . . . .868
30.7.9Transmit data register (LPUART_TDR) . . . . .868
30.7.10LPUART register map . . . . .870
31Serial peripheral interface/ inter-IC sound (SPI/I2S) . . . . .871
31.1Introduction . . . . .871
31.1.1SPI main features . . . . .871
31.1.2SPI extended features . . . . .872
31.1.3I2S features . . . . .872
31.2SPI/I2S implementation . . . . .872
31.3SPI functional description . . . . .873
31.3.1General description . . . . .873
31.3.2Communications between one master and one slave . . . . .874
Full-duplex communication . . . . .874
Half-duplex communication . . . . .874
Simplex communications . . . . .875
31.3.3Standard multi-slave communication . . . . .877
31.3.4Multi-master communication . . . . .878
31.3.5Slave select (NSS) pin management . . . . .878
31.3.6Communication formats . . . . .880
Clock phase and polarity controls . . . . .880
Data frame format . . . . .881
31.3.7SPI configuration . . . . .882
31.3.8Procedure for enabling SPI . . . . .882
31.3.9Data transmission and reception procedures . . . . .883
Rx and Tx buffers . . . . .883
Tx buffer handling . . . . .883
Rx buffer handling . . . . .883
Sequence handling . . . . .883
31.3.10Procedure for disabling the SPI . . . . .885
31.3.11Communication using DMA (direct memory addressing) . . . . .886
31.3.12SPI status flags . . . . .888
Tx buffer empty flag (TXE) . . . . .888
Rx buffer not empty (RXNE) . . . . .888
Busy flag (BSY) . . . . .888
31.3.13SPI error flags . . . . .889
Overrun flag (OVR) . . . . .889
Mode fault (MODF) . . . . .889
CRC error (CRCERR) . . . . .890
TI mode frame format error (FRE) . . . . .890
31.4 SPI special features . . . . .890
31.4.1 TI mode . . . . .890
TI protocol in master mode . . . . .890
31.4.2 CRC calculation . . . . .891
CRC principle . . . . .891
CRC transfer managed by CPU . . . . .891
CRC transfer managed by DMA . . . . .892
Resetting the SPIx_TXCRC and SPIx_RXCRC values . . . . .892
31.5 SPI interrupts . . . . .893
31.6 I 2 S functional description . . . . .894
31.6.1 I 2 S general description . . . . .894
31.6.2 I 2 S full-duplex . . . . .895
31.6.3 Supported audio protocols . . . . .896
I 2 S Philips standard . . . . .897
MSB justified standard . . . . .899
LSB justified standard . . . . .900
PCM standard . . . . .902
31.6.4 Clock generator . . . . .903
31.6.5 I 2 S master mode . . . . .905
Procedure . . . . .905
Transmission sequence . . . . .905
Reception sequence . . . . .906
31.6.6 I 2 S slave mode . . . . .907
Transmission sequence . . . . .907
Reception sequence . . . . .908
31.6.7 I 2 S status flags . . . . .908
Busy flag (BSY) . . . . .908
Tx buffer empty flag (TXE) . . . . .909
RX buffer not empty (RXNE) . . . . .909
Channel Side flag (CHSIDE) . . . . .909
31.6.8 I 2 S error flags . . . . .909
Underrun flag (UDR) . . . . .909
Overrun flag (OVR) . . . . .910
Frame error flag (FRE) . . . . .910
31.6.9 I 2 S interrupts . . . . .910
31.6.10 DMA features . . . . .910
31.7SPI and I 2 S registers . . . . .911
31.7.1SPI control register 1 (SPI_CR1) (not used in I 2 S mode) . . . . .911
31.7.2SPI control register 2 (SPI_CR2) . . . . .913
31.7.3SPI status register (SPI_SR) . . . . .914
31.7.4SPI data register (SPI_DR) . . . . .916
31.7.5SPI CRC polynomial register (SPI_CRCPR) (not used in I 2 S mode) . . . . .916
31.7.6SPI RX CRC register (SPI_RXCRCR) (not used in I 2 S mode) . . . . .917
31.7.7SPI TX CRC register (SPI_TXCRCR) (not used in I 2 S mode) . . . . .917
31.7.8SPI_I 2 S configuration register (SPI_I2SCFGR) . . . . .918
31.7.9SPI_I 2 S prescaler register (SPI_I2SPR) . . . . .919
31.7.10SPI register map . . . . .920
32Universal serial bus full-speed device interface (USB) . . . . .921
32.1Introduction . . . . .921
32.2USB main features . . . . .921
32.3USB implementation . . . . .921
32.4USB functional description . . . . .922
32.4.1Description of USB blocks . . . . .923
32.5Programming considerations . . . . .924
32.5.1Generic USB device programming . . . . .924
32.5.2System and power-on reset . . . . .925
USB reset (RESET interrupt) . . . . .925
Structure and usage of packet buffers . . . . .925
Endpoint initialization . . . . .927
IN packets (data transmission) . . . . .927
OUT and SETUP packets (data reception) . . . . .928
Control transfers . . . . .929
32.5.3Double-buffered endpoints . . . . .930
32.5.4Isochronous transfers . . . . .932
32.5.5Suspend/Resume events . . . . .933
32.6USB and USB SRAM registers . . . . .936
32.6.1Common registers . . . . .936
USB control register (USB_CNTR) . . . . .936
USB interrupt status register (USB_ISTR) . . . . .938
USB frame number register (USB_FNR) . . . . .941
USB device address (USB_DADDR) . . . . .941
Buffer table address (USB_BTABLE) . . . . .942
LPM control and status register (USB_LPMCSR) . . . . .942
Battery charging detector (USB_BCDR) . . . . .943
Endpoint-specific registers . . . . .944
USB endpoint n register (USB_EPNR), n=[0..7] . . . . .944
32.6.2 Buffer descriptor table . . . . .949
Transmission buffer address n (USB_ADDRn_TX) . . . . .949
Transmission byte count n (USB_COUNTn_TX) . . . . .949
Reception buffer address n (USB_ADDRn_RX) . . . . .950
Reception byte count n (USB_COUNTn_RX) . . . . .950
32.6.3 USB register map . . . . .952
33 Debug support (DBG) . . . . .954
33.1 Overview . . . . .954
33.2 Reference Arm® documentation . . . . .955
33.3 Pinout and debug port pins . . . . .955
33.3.1 SWD port pins . . . . .955
33.3.2 SW-DP pin assignment . . . . .955
33.3.3 Internal pull-up & pull-down on SWD pins . . . . .956
33.4 ID codes and locking mechanism . . . . .956
33.4.1 MCU device ID code . . . . .956
DBG_IDCODE . . . . .956
33.5 SWD port . . . . .957
33.5.1 SWD protocol introduction . . . . .957
33.5.2 SWD protocol sequence . . . . .957
33.5.3 SW-DP state machine (reset, idle states, ID code) . . . . .958
33.5.4 DP and AP read/write accesses . . . . .959
33.5.5 SW-DP registers . . . . .959
33.5.6 SW-AP registers . . . . .960
33.6 Core debug . . . . .961
33.7 BPU (Break Point Unit) . . . . .961
33.7.1 BPU functionality . . . . .961
33.8 DWT (Data Watchpoint) . . . . .962
33.8.1 DWT functionality . . . . .962
33.8.2 DWT Program Counter Sample Register . . . . .962
33.9 MCU debug component (DBG) . . . . .962
33.9.1 Debug support for low-power modes . . . . .962
33.9.2 Debug support for timers, watchdog and I 2 C . . . . .963
33.9.3Debug MCU configuration register (DBG_CR) . . . . .963
33.9.4Debug MCU APB1 freeze register (DBG_APB1_FZ) . . . . .965
33.9.5Debug MCU APB2 freeze register (DBG_APB2_FZ) . . . . .967
33.10DBG register map . . . . .968
34Device electronic signature . . . . .969
34.1Memory size register . . . . .969
34.1.1Flash size register . . . . .969
34.2Unique device ID registers (96 bits) . . . . .969
Appendix ACode examples. . . . .971
A.1Introduction . . . . .971
A.2NVM/RCC Operation code example . . . . .971
A.2.1Increasing the CPU frequency preparation sequence code . . . . .971
A.2.2Decreasing the CPU frequency preparation sequence code . . . . .971
A.2.3Switch from PLL to HSI16 sequence code . . . . .972
A.2.4Switch to PLL sequence code. . . . .972
A.3NVM Operation code example . . . . .973
A.3.1Unlocking the data EEPROM and FLASH_PECR register code example . . . . .973
A.3.2Locking data EEPROM and FLASH_PECR register code example . . . . .973
A.3.3Unlocking the NVM program memory code example . . . . .973
A.3.4Unlocking the option bytes area code example . . . . .974
A.3.5Write to data EEPROM code example . . . . .974
A.3.6Erase to data EEPROM code example . . . . .974
A.3.7Program Option byte code example . . . . .975
A.3.8Erase Option byte code example . . . . .975
A.3.9Program a single word to Flash program memory code example . . . . .976
A.3.10Program half-page to Flash program memory code example . . . . .977
A.3.11Erase a page in Flash program memory code example . . . . .978
A.3.12Mass erase code example . . . . .979
A.4Clock Controller. . . . .980
A.4.1HSE start sequence code example . . . . .980
A.4.2PLL configuration modification code example . . . . .981
A.4.3MCO selection code example. . . . .982
A.5GPIOs . . . . .982
A.5.1Locking mechanism code example. . . . .982
A.5.2Alternate function selection sequence code example . . . . .982
A.5.3Analog GPIO configuration code example . . . . .982
A.6DMA . . . . .983
A.6.1DMA Channel Configuration sequence code example . . . . .983
A.7Interrupts and event . . . . .983
A.7.1NVIC initialization example . . . . .983
A.7.2Extended interrupt selection code example . . . . .983
A.8ADC . . . . .984
A.8.1Calibration code example . . . . .984
A.8.2ADC enable sequence code example . . . . .984
A.8.3ADC disable sequence code example . . . . .985
A.8.4ADC clock selection code example . . . . .985
A.8.5Single conversion sequence code example - Software trigger . . . . .985
A.8.6Continuous conversion sequence code example - Software trigger . . . . .986
A.8.7Single conversion sequence code example - Hardware trigger . . . . .986
A.8.8Continuous conversion sequence code example - Hardware trigger . . . . .987
A.8.9DMA one shot mode sequence code example . . . . .987
A.8.10DMA circular mode sequence code example . . . . .988
A.8.11Wait mode sequence code example . . . . .988
A.8.12Auto off and no wait mode sequence code example . . . . .988
A.8.13Auto off and wait mode sequence code example . . . . .989
A.8.14Analog watchdog code example . . . . .989
A.8.15Oversampling code example . . . . .990
A.8.16Temperature configuration code example . . . . .990
A.8.17Temperature computation code example . . . . .990
A.9DAC . . . . .991
A.9.1Independent trigger without wave generation code example . . . . .991
A.9.2Independent trigger with single triangle generation code example . . . . .991
A.9.3DMA initialization code example . . . . .991
A.10TSC code example . . . . .992
A.10.1TSC configuration code example . . . . .992
A.10.2TSC interrupt code example . . . . .993
A.11Timers . . . . .993
A.11.1Upcounter on TI2 rising edge code example . . . . .993
A.11.2Up counter on each 2 ETR rising edges code example . . . . .993
A.11.3Input capture configuration code example . . . . .994
A.11.4Input capture data management code example . . . . .994
A.11.5PWM input configuration code example . . . . .995
A.11.6PWM input with DMA configuration code example . . . . .995
A.11.7Output compare configuration code example . . . . .996
A.11.8Edge-aligned PWM configuration example. . . . .996
A.11.9Center-aligned PWM configuration example . . . . .997
A.11.10ETR configuration to clear OCxREF code example . . . . .997
A.11.11Encoder interface code example . . . . .998
A.11.12Reset mode code example . . . . .998
A.11.13Gated mode code example. . . . .999
A.11.14Trigger mode code example . . . . .999
A.11.15External clock mode 2 + trigger mode code example. . . . .1000
A.11.16One-Pulse mode code example . . . . .1000
A.11.17Timer prescaling another timer code example . . . . .1001
A.11.18Timer enabling another timer code example. . . . .1001
A.11.19Master and slave synchronization code example . . . . .1002
A.11.20Two timers synchronized by an external trigger code example . . . . .1004
A.11.21DMA burst feature code example . . . . .1005
A.12Low-power timer (LPTIM) . . . . .1006
A.12.1Pulse counter configuration code example. . . . .1006
A.13IWDG code example . . . . .1006
A.13.1IWDG configuration code example . . . . .1006
A.13.2IWDG configuration with window code example. . . . .1006
A.14WWDG code example. . . . .1007
A.14.1WWDG configuration code example. . . . .1007
A.15RTC code example . . . . .1007
A.15.1RTC calendar configuration code example. . . . .1007
A.15.2RTC alarm configuration code example . . . . .1008
A.15.3RTC WUT configuration code example . . . . .1008
A.15.4RTC read calendar code example . . . . .1009
A.15.5RTC calibration code example . . . . .1009
A.15.6RTC tamper and time stamp configuration code example . . . . .1009
A.15.7RTC tamper and time stamp code example . . . . .1010
A.15.8RTC clock output code example . . . . .1010
A.16I2C code example . . . . .1010
A.16.1I2C configured in slave mode code example . . . . .1010

Revision history . . . . . 1019

List of tables

Table 1.STM32L0x3 memory density . . . . .54
Table 2.Overview of features per category . . . . .54
Table 3.STM32L0x3 peripheral register boundary addresses . . . . .60
Table 4.Boot modes . . . . .64
Table 5.NVM organization (category 3 devices) . . . . .67
Table 6.NVM organization for UFB = 0 (192 Kbyte category 5 devices) . . . . .68
Table 7.Flash memory and data EEPROM remapping
(192 Kbyte category 5 devices) . . . . .
69
Table 8.NVM organization for UFB = 0 (128 Kbyte category 5 devices) . . . . .69
Table 9.Flash memory and data EEPROM remapping (128 Kbyte category 5 devices) . . . . .70
Table 10.NVM organization for UFB = 0 (64 Kbyte category 5 devices) . . . . .70
Table 11.Boot pin and BFB2 bit configuration . . . . .71
Table 12.Link between master clock power range and frequencies . . . . .73
Table 13.Delays to memory access and number of wait states . . . . .73
Table 14.Internal buffer management . . . . .76
Table 15.Configurations for buffers and speculative reading . . . . .79
Table 16.Dhrystone performances in all memory interface configurations . . . . .80
Table 17.NVM write/erase timings . . . . .94
Table 18.NVM write/erase duration . . . . .94
Table 19.Protection level and content of RDP Option bytes . . . . .98
Table 20.Link between protection bits of FLASH_WRPROTx register
and protected address in Flash program memory . . . . .
99
Table 21.Memory access vs mode, protection and Flash program memory sectors . . . . .100
Table 22.Flash interrupt request . . . . .103
Table 23.Flash interface - register map and reset values . . . . .120
Table 24.Option byte format . . . . .121
Table 25.Option byte organization . . . . .121
Table 26.CRC internal input/output signals . . . . .124
Table 27.CRC register map and reset values . . . . .129
Table 28.Segment accesses according to the Firewall state . . . . .133
Table 29.Segment granularity and area ranges . . . . .134
Table 30.Firewall register map and reset values . . . . .141
Table 31.Performance versus VCORE ranges . . . . .146
Table 32.Summary of low-power modes . . . . .153
Table 33.Sleep-now . . . . .157
Table 34.Sleep-on-exit . . . . .158
Table 35.Sleep-now (Low-power sleep) . . . . .159
Table 36.Sleep-on-exit (Low-power sleep) . . . . .160
Table 37.Stop mode . . . . .162
Table 38.Standby mode . . . . .164
Table 39.PWR - register map and reset values . . . . .172
Table 40.HSE/LSE clock sources . . . . .178
Table 41.System clock source frequency . . . . .183
Table 42.RCC register map and reset values . . . . .223
Table 43.CRS features . . . . .226
Table 44.Effect of low-power modes on CRS . . . . .230
Table 45.Interrupt control bits . . . . .230
Table 46.CRS register map and reset values . . . . .235
Table 47.Port bit configuration table . . . . .239
Table 48.GPIO register map and reset values . . . . .252
Table 49.SYSCFG register map and reset values . . . . .262
Table 50.DMA implementation . . . . .265
Table 51.DMA requests for each channel . . . . .266
Table 52.Programmable data width and endian behavior (when PINC = MINC = 1) . . . . .274
Table 53.DMA interrupt requests . . . . .275
Table 54.DMA register map and reset values . . . . .285
Table 55.List of vectors . . . . .288
Table 56.EXTI lines connections . . . . .295
Table 57.Extended interrupt/event controller register map and reset values . . . . .300
Table 58.ADC input/output pins . . . . .303
Table 59.ADC internal input/output signals . . . . .304
Table 60.External triggers . . . . .304
Table 61.Latency between trigger and start of conversion . . . . .309
Table 62.Configuring the trigger polarity . . . . .315
Table 63.tSAR timings depending on resolution . . . . .317
Table 64.Analog watchdog comparison . . . . .326
Table 65.Analog watchdog channel selection . . . . .326
Table 66.Maximum output results vs N and M. Grayed values indicates truncation . . . . .330
Table 67.ADC interrupts . . . . .335
Table 68.ADC register map and reset values . . . . .350
Table 69.DAC pins . . . . .353
Table 70.External triggers . . . . .356
Table 71.DAC register map and reset values . . . . .374
Table 72.COMP register map and reset values . . . . .382
Table 73.Implementation . . . . .385
Table 74.Example of frame rate calculation . . . . .386
Table 75.Blink frequency . . . . .394
Table 76.VLCD rail connections to GPIO pins . . . . .397
Table 77.Remapping capability . . . . .399
Table 78.LCD behavior in low-power modes . . . . .404
Table 79.LCD interrupt requests . . . . .404
Table 80.LCD register map and reset values . . . . .411
Table 81.Acquisition sequence summary . . . . .416
Table 82.Spread spectrum deviation versus AHB clock frequency . . . . .418
Table 83.I/O state depending on its mode and IODEF bit value . . . . .419
Table 84.Effect of low-power modes on TSC . . . . .421
Table 85.Interrupt control bits . . . . .421
Table 86.TSC register map and reset values . . . . .430
Table 87.AES internal input/output signals . . . . .433
Table 88.CTR mode initialization vector definition . . . . .449
Table 89.Key endianness in AES_KEYRx registers . . . . .452
Table 90.DMA channel configuration for memory-to-AES data transfer . . . . .453
Table 91.DMA channel configuration for AES-to-memory data transfer . . . . .454
Table 92.AES interrupt requests . . . . .456
Table 93.Processing latency (in clock cycle) . . . . .456
Table 94.AES register map and reset values . . . . .464
Table 95.RNG internal input/output signals . . . . .467
Table 96.RNG interrupt requests . . . . .472
Table 97.RNG register map and reset map . . . . .476
Table 98.Counting direction versus encoder signals . . . . .508
Table 99.TIM2/TIM3 internal trigger connection . . . . .525
Table 100.Output control bit for standard OCx channels. . . . .535
Table 101.TIM2/3 register map and reset values . . . . .543
Table 102.Counting direction versus encoder signals. . . . .576
Table 103.TIMx Internal trigger connection . . . . .586
Table 104.Output control bit for standard OCx channels. . . . .594
Table 105.TIM21/22 register map and reset values . . . . .598
Table 106.TIM6/7 register map and reset values . . . . .612
Table 107.STM32L0x3 LPTIM features. . . . .614
Table 108.LPTIM1 external trigger connection . . . . .615
Table 109.Prescaler division ratios . . . . .616
Table 110.Encoder counting scenarios . . . . .622
Table 111.Effect of low-power modes on the LPTIM. . . . .623
Table 112.Interrupt events. . . . .624
Table 113.LPTIM register map and reset values. . . . .633
Table 114.IWDG register map and reset values . . . . .642
Table 115.WWDG register map and reset values . . . . .648
Table 116.RTC implementation. . . . .650
Table 117.RTC pin PC13 configuration. . . . .652
Table 118.RTC_OUT mapping . . . . .653
Table 119.Effect of low-power modes on RTC . . . . .666
Table 120.Interrupt control bits . . . . .666
Table 121.RTC register map and reset values . . . . .691
Table 122.STM32L0x3 I2C features . . . . .694
Table 123.I2C input/output pins. . . . .697
Table 124.I2C internal input/output signals . . . . .697
Table 125.Comparison of analog vs. digital filters. . . . .699
Table 126.I2C-SMBus specification data setup and hold times . . . . .702
Table 127.I2C configuration. . . . .706
Table 128.I2C-SMBus specification clock timings. . . . .717
Table 129.Examples of timing settings for f I2CCLK = 8 MHz . . . . .727
Table 130.Examples of timings settings for f I2CCLK = 16 MHz . . . . .727
Table 131.SMBus timeout specifications. . . . .729
Table 132.SMBus with PEC configuration. . . . .732
Table 133.Examples of TIMEOUTA settings for various I2CCLK frequencies
(max t TIMEOUT = 25 ms) . . . . .
733
Table 134.Examples of TIMEOUTB settings for various I2CCLK frequencies . . . . .733
Table 135.Examples of TIMEOUTA settings for various I2CCLK frequencies
(max t IDLE = 50 µs) . . . . .
733
Table 136.Effect of low-power modes on the I2C . . . . .744
Table 137.I2C Interrupt requests. . . . .745
Table 138.I2C register map and reset values . . . . .760
Table 139.STM32L0x3 USART/LPUART features . . . . .764
Table 140.Noise detection from sampled data . . . . .776
Table 141.Error calculation for programmed baud rates at f CK = 32 MHz in both cases of
oversampling by 16 or by 8. . . . .
779
Table 142.Tolerance of the USART receiver when BRR [3:0] = 0000. . . . .780
Table 143.Tolerance of the USART receiver when BRR [3:0] is different from 0000 . . . . .780
Table 144.Frame formats . . . . .785
Table 145.Effect of low-power modes on the USART. . . . .804
Table 146.USART interrupt requests. . . . .804
Table 147.USART register map and reset values . . . . .827
Table 148.STM32L0x3 USART/LPUART features . . . . .831
Table 149.Error calculation for programmed baud rates at fck = 32.768 kHz . . . . .841
Table 150.Error calculation for programmed baud rates at fck = 32 MHz . . . . .841
Table 151.Tolerance of the LPUART receiver . . . . .842
Table 152.Frame formats . . . . .845
Table 153.Effect of low-power modes on the LPUART . . . . .854
Table 154.LPUART interrupt requests . . . . .854
Table 155.LPUART register map and reset values . . . . .870
Table 156.STM32L0x3 SPI implementation . . . . .872
Table 157.SPI interrupt requests . . . . .893
Table 158.Audio-frequency precision using standard 8 MHz HSE . . . . .904
Table 159.I 2 S interrupt requests . . . . .910
Table 160.SPI register map and reset values . . . . .920
Table 161.STM32L0x3 USB implementation . . . . .921
Table 162.Double-buffering buffer flag definition . . . . .931
Table 163.Bulk double-buffering memory buffers usage . . . . .931
Table 164.Isochronous memory buffers usage . . . . .933
Table 165.Resume event detection . . . . .934
Table 166.Reception status encoding . . . . .947
Table 167.Endpoint type encoding . . . . .947
Table 168.Endpoint kind meaning . . . . .947
Table 169.Transmission status encoding . . . . .948
Table 170.Definition of allocated buffer memory . . . . .951
Table 171.USB register map and reset values . . . . .952
Table 172.SW debug port pins . . . . .955
Table 173.REV_ID values . . . . .957
Table 174.Packet request (8-bits) . . . . .957
Table 175.ACK response (3 bits) . . . . .958
Table 176.DATA transfer (33 bits) . . . . .958
Table 177.SW-DP registers . . . . .959
Table 178.32-bit debug port registers addressed through the shifted value A[3:2] . . . . .960
Table 179.Core debug registers . . . . .961
Table 180.DBG register map and reset values . . . . .968
Table 181.Document revision history . . . . .1019

List of figures

Figure 1.System architecture . . . . .56
Figure 2.Memory map . . . . .59
Figure 3.Structure of one internal buffer . . . . .75
Figure 4.Timing to fetch and execute instructions with prefetch disabled . . . . .77
Figure 5.Timing to fetch and execute instructions with prefetch enabled . . . . .79
Figure 6.RDP levels . . . . .98
Figure 7.CRC calculation unit block diagram . . . . .124
Figure 8.STM32L0x3 firewall connection schematics . . . . .131
Figure 9.Firewall functional states . . . . .135
Figure 10.Power supply overview . . . . .143
Figure 11.Performance versus VDD and VCORE range . . . . .146
Figure 12.Power supply supervisors . . . . .149
Figure 13.Power-on reset/power-down reset waveform . . . . .150
Figure 14.BOR thresholds . . . . .151
Figure 15.PVD thresholds . . . . .152
Figure 16.Simplified diagram of the reset circuit . . . . .174
Figure 17.Clock tree . . . . .177
Figure 18.Using TIM21 channel 1 input capture to measure frequencies . . . . .185
Figure 19.CRS block diagram . . . . .227
Figure 20.CRS counter behavior . . . . .228
Figure 21.Basic structure of an I/O port bit . . . . .238
Figure 22.Basic structure of a 5-Volt tolerant I/O port bit . . . . .238
Figure 23.Input floating / pull up / pull down configurations . . . . .243
Figure 24.Output configuration . . . . .244
Figure 25.Alternate function configuration . . . . .245
Figure 26.High impedance-analog configuration . . . . .245
Figure 27.DMA request mapping . . . . .266
Figure 28.DMA block diagram . . . . .268
Figure 29.Extended interrupts and events controller (EXTI) block diagram . . . . .292
Figure 30.Extended interrupt/event GPIO mapping . . . . .294
Figure 31.ADC block diagram . . . . .303
Figure 32.ADC calibration . . . . .306
Figure 33.Calibration factor forcing . . . . .307
Figure 34.Enabling/disabling the ADC . . . . .308
Figure 35.ADC clock scheme . . . . .308
Figure 36.ADC connectivity . . . . .310
Figure 37.Analog to digital conversion time . . . . .314
Figure 38.ADC conversion timings . . . . .314
Figure 39.Stopping an ongoing conversion . . . . .315
Figure 40.Single conversions of a sequence, software trigger . . . . .318
Figure 41.Continuous conversion of a sequence, software trigger . . . . .318
Figure 42.Single conversions of a sequence, hardware trigger . . . . .319
Figure 43.Continuous conversions of a sequence, hardware trigger . . . . .319
Figure 44.Data alignment and resolution (oversampling disabled: OVSE = 0) . . . . .320
Figure 45.Example of overrun (OVR) . . . . .321
Figure 46.Wait mode conversion (continuous mode, software trigger) . . . . .323
Figure 47.Behavior with WAIT = 0, AUTOFF = 1 . . . . .324
Figure 48.Behavior with WAIT = 1, AUTOFF = 1 . . . . .325
Figure 49.Analog watchdog guarded area . . . . .326
Figure 50.ADC_AWD1_OUT signal generation . . . . .327
Figure 51.ADC_AWD1_OUT signal generation (AWD flag not cleared by software) . . . . .328
Figure 52.ADC1_AWD_OUT signal generation (on a single channel) . . . . .328
Figure 53.Analog watchdog threshold update . . . . .329
Figure 54.20-bit to 16-bit result truncation . . . . .330
Figure 55.Numerical example with 5-bits shift and rounding . . . . .330
Figure 56.Triggered oversampling mode (TOVS bit = 1) . . . . .332
Figure 57.Temperature sensor and VREFINT channel block diagram . . . . .333
Figure 58.DAC block diagram . . . . .353
Figure 59.Data registers in single DAC channel mode . . . . .354
Figure 60.Timing diagram for conversion with trigger disabled TEN = 0 . . . . .355
Figure 61.Data registers in dual DAC channel mode . . . . .357
Figure 62.DAC LFSR register calculation algorithm . . . . .361
Figure 63.DAC conversion (SW trigger enabled) with LFSR wave generation . . . . .362
Figure 64.DAC triangle wave generation . . . . .362
Figure 65.DAC conversion (SW trigger enabled) with triangle wave generation . . . . .363
Figure 66.Comparator 1 and 2 block diagrams . . . . .377
Figure 67.LCD controller block diagram . . . . .385
Figure 68.1/3 bias, 1/4 duty . . . . .388
Figure 69.Static duty case 1 . . . . .389
Figure 70.Static duty case 2 . . . . .389
Figure 71.1/2 duty, 1/2 bias . . . . .390
Figure 72.1/3 duty, 1/3 bias . . . . .391
Figure 73.1/4 duty, 1/3 bias . . . . .392
Figure 74.1/8 duty, 1/4 bias . . . . .393
Figure 75.LCD voltage control . . . . .396
Figure 76.Deadtime . . . . .397
Figure 77.SEG/COM mux feature example . . . . .402
Figure 78.Flowchart example . . . . .403
Figure 79.TSC block diagram . . . . .414
Figure 80.Surface charge transfer analog I/O group structure . . . . .415
Figure 81.Sampling capacitor voltage variation . . . . .416
Figure 82.Charge transfer acquisition sequence . . . . .417
Figure 83.Spread spectrum variation principle . . . . .418
Figure 84.AES block diagram . . . . .433
Figure 85.ECB encryption and decryption principle . . . . .435
Figure 86.CBC encryption and decryption principle . . . . .436
Figure 87.CTR encryption and decryption principle . . . . .437
Figure 88.STM32 cryptolib AES flowchart example . . . . .438
Figure 89.Encryption key derivation for ECB/CBC decryption (Mode 2). . . . .441
Figure 90.Example of suspend mode management . . . . .442
Figure 91.ECB encryption . . . . .442
Figure 92.ECB decryption . . . . .443
Figure 93.CBC encryption . . . . .443
Figure 94.CBC decryption . . . . .444
Figure 95.ECB/CBC encryption (Mode 1) . . . . .445
Figure 96.ECB/CBC decryption (Mode 3) . . . . .446
Figure 97.Message construction in CTR mode . . . . .448
Figure 98.CTR encryption . . . . .448
Figure 99.CTR decryption . . . . .449
Figure 100. 128-bit block construction with respect to data swap . . . . .451
Figure 101. DMA transfer of a 128-bit data block during input phase . . . . .453
Figure 102. DMA transfer of a 128-bit data block during output phase . . . . .454
Figure 103. AES interrupt signal generation . . . . .456
Figure 104. RNG block diagram . . . . .467
Figure 105. Entropy source model . . . . .468
Figure 106. General-purpose timer block diagram . . . . .478
Figure 107. Counter timing diagram with prescaler division change from 1 to 2 . . . . .480
Figure 108. Counter timing diagram with prescaler division change from 1 to 4 . . . . .480
Figure 109. Counter timing diagram, internal clock divided by 1 . . . . .481
Figure 110. Counter timing diagram, internal clock divided by 2 . . . . .482
Figure 111. Counter timing diagram, internal clock divided by 4 . . . . .482
Figure 112. Counter timing diagram, internal clock divided by N . . . . .483
Figure 113. Counter timing diagram, Update event when ARPE=0 (TIMx_ARR not preloaded). . . . .483
Figure 114. Counter timing diagram, Update event when ARPE=1 (TIMx_ARR preloaded). . . . .484
Figure 115. Counter timing diagram, internal clock divided by 1 . . . . .485
Figure 116. Counter timing diagram, internal clock divided by 2 . . . . .485
Figure 117. Counter timing diagram, internal clock divided by 4 . . . . .486
Figure 118. Counter timing diagram, internal clock divided by N . . . . .486
Figure 119. Counter timing diagram, Update event when repetition counter
is not used . . . . .
487
Figure 120. Counter timing diagram, internal clock divided by 1, TIMx_ARR=0x6 . . . . .488
Figure 121. Counter timing diagram, internal clock divided by 2 . . . . .489
Figure 122. Counter timing diagram, internal clock divided by 4, TIMx_ARR=0x36 . . . . .489
Figure 123. Counter timing diagram, internal clock divided by N . . . . .490
Figure 124. Counter timing diagram, Update event with ARPE=1 (counter underflow). . . . .490
Figure 125. Counter timing diagram, Update event with ARPE=1 (counter overflow). . . . .491
Figure 126. Control circuit in normal mode, internal clock divided by 1 . . . . .492
Figure 127. TI2 external clock connection example. . . . .492
Figure 128. Control circuit in external clock mode 1 . . . . .493
Figure 129. External trigger input block . . . . .494
Figure 130. Control circuit in external clock mode 2 . . . . .495
Figure 131. Capture/compare channel (example: channel 1 input stage). . . . .496
Figure 132. Capture/compare channel 1 main circuit . . . . .496
Figure 133. Output stage of capture/compare channel (channel 1). . . . .497
Figure 134. PWM input mode timing . . . . .499
Figure 135. Output compare mode, toggle on OC1. . . . .501
Figure 136. Edge-aligned PWM waveforms (ARR=8). . . . .502
Figure 137. Center-aligned PWM waveforms (ARR=8). . . . .504
Figure 138. Example of one-pulse mode. . . . .505
Figure 139. Clearing TIMx_OCxREF . . . . .507
Figure 140. Example of counter operation in encoder interface mode . . . . .509
Figure 141. Example of encoder interface mode with TI1FP1 polarity inverted . . . . .509
Figure 142. Control circuit in reset mode . . . . .510
Figure 143. Control circuit in gated mode . . . . .511
Figure 144. Control circuit in trigger mode . . . . .512
Figure 145. Control circuit in external clock mode 2 + trigger mode . . . . .514
Figure 146. Master/Slave timer example . . . . .514
Figure 147. Gating timer y with OC1REF of timer x. . . . .516
Figure 148. Gating timer y with Enable of timer x . . . . .517
Figure 149. Triggering timer y with update of timer x. . . . .518
Figure 150. Triggering timer y with Enable of timer x . . . . .518
Figure 151. Triggering timer x and y with timer x TI1 input . . . . .519
Figure 152. General-purpose timer block diagram (TIM21/22) . . . . .546
Figure 153. Counter timing diagram with prescaler division change from 1 to 2 . . . . .548
Figure 154. Counter timing diagram with prescaler division change from 1 to 4 . . . . .549
Figure 155. Counter timing diagram, internal clock divided by 1 . . . . .550
Figure 156. Counter timing diagram, internal clock divided by 2 . . . . .551
Figure 157. Counter timing diagram, internal clock divided by 4 . . . . .551
Figure 158. Counter timing diagram, internal clock divided by N . . . . .552
Figure 159. Counter timing diagram, update event when ARPE=0 (TIMx_ARR not preloaded). . . . .552
Figure 160. Counter timing diagram, update event when ARPE=1 (TIMx_ARR preloaded). . . . .553
Figure 161. Counter timing diagram, internal clock divided by 1 . . . . .554
Figure 162. Counter timing diagram, internal clock divided by 2 . . . . .554
Figure 163. Counter timing diagram, internal clock divided by 4 . . . . .555
Figure 164. Counter timing diagram, internal clock divided by N . . . . .555
Figure 165. Counter timing diagram, internal clock divided by 1, TIMx_ARR=0x6 . . . . .557
Figure 166. Counter timing diagram, internal clock divided by 2 . . . . .557
Figure 167. Counter timing diagram, internal clock divided by 4, TIMx_ARR=0x36 . . . . .558
Figure 168. Counter timing diagram, internal clock divided by N . . . . .558
Figure 169. Counter timing diagram, Update event with ARPE=1 (counter underflow). . . . .559
Figure 170. Counter timing diagram, Update event with ARPE=1 (counter overflow). . . . .559
Figure 171. Control circuit in normal mode, internal clock divided by 1 . . . . .560
Figure 172. TI2 external clock connection example. . . . .561
Figure 173. Control circuit in external clock mode 1 . . . . .562
Figure 174. External trigger input block . . . . .562
Figure 175. Control circuit in external clock mode 2 . . . . .563
Figure 176. Capture/compare channel (example: channel 1 input stage). . . . .564
Figure 177. Capture/compare channel 1 main circuit . . . . .564
Figure 178. Output stage of capture/compare channel (channel 1 and 2). . . . .565
Figure 179. PWM input mode timing . . . . .567
Figure 180. Output compare mode, toggle on OC1 . . . . .569
Figure 181. Edge-aligned PWM waveforms (ARR=8). . . . .570
Figure 182. Center-aligned PWM waveforms (ARR=8). . . . .571
Figure 183. Clearing TIMx_OCxREF . . . . .573
Figure 184. Example of one pulse mode . . . . .574
Figure 185. Example of counter operation in encoder interface mode . . . . .576
Figure 186. Example of encoder interface mode with TI1FP1 polarity inverted . . . . .577
Figure 187. Control circuit in reset mode . . . . .578
Figure 188. Control circuit in gated mode . . . . .579
Figure 189. Control circuit in trigger mode . . . . .580
Figure 190. Basic timer block diagram . . . . .600
Figure 191. Counter timing diagram with prescaler division change from 1 to 2 . . . . .602
Figure 192. Counter timing diagram with prescaler division change from 1 to 4 . . . . .602
Figure 193. Counter timing diagram, internal clock divided by 1 . . . . .603
Figure 194. Counter timing diagram, internal clock divided by 2 . . . . .604
Figure 195. Counter timing diagram, internal clock divided by 4 . . . . .604
Figure 196. Counter timing diagram, internal clock divided by N . . . . .605
Figure 197. Counter timing diagram, update event when ARPE = 0 (TIMx_ARR not preloaded). . . . .605
Figure 198. Counter timing diagram, update event when ARPE=1 (TIMx_ARR preloaded). . . . .606
Figure 199. Control circuit in normal mode, internal clock divided by 1 . . . . .607
Figure 200. Low-power timer block diagram . . . . .614
Figure 201. Glitch filter timing diagram . . . . .616
Figure 202. LPTIM output waveform, single counting mode configuration . . . . .618
Figure 203. LPTIM output waveform, Single counting mode configuration
and Set-once mode activated (WAVE bit is set). . . . .
618
Figure 204. LPTIM output waveform, Continuous counting mode configuration . . . . .619
Figure 205. Waveform generation . . . . .620
Figure 206. Encoder mode counting sequence . . . . .623
Figure 207. Independent watchdog block diagram . . . . .634
Figure 208. Watchdog block diagram . . . . .644
Figure 209. Window watchdog timing diagram . . . . .645
Figure 210. RTC block diagram . . . . .651
Figure 211. I2C1/3 block diagram . . . . .695
Figure 212. I2C2 block diagram . . . . .696
Figure 213. I2C bus protocol . . . . .698
Figure 214. Setup and hold timings . . . . .700
Figure 215. I2C initialization flow . . . . .703
Figure 216. Data reception . . . . .704
Figure 217. Data transmission . . . . .705
Figure 218. Slave initialization flow . . . . .708
Figure 219. Transfer sequence flow for I2C slave transmitter, NOSTRETCH = 0 . . . . .710
Figure 220. Transfer sequence flow for I2C slave transmitter, NOSTRETCH = 1 . . . . .711
Figure 221. Transfer bus diagrams for I2C slave transmitter . . . . .712
Figure 222. Transfer sequence flow for slave receiver with NOSTRETCH = 0 . . . . .713
Figure 223. Transfer sequence flow for slave receiver with NOSTRETCH = 1 . . . . .714
Figure 224. Transfer bus diagrams for I2C slave receiver . . . . .714
Figure 225. Master clock generation . . . . .716
Figure 226. Master initialization flow . . . . .718
Figure 227. 10-bit address read access with HEAD10R = 0 . . . . .718
Figure 228. 10-bit address read access with HEAD10R = 1 . . . . .719
Figure 229. Transfer sequence flow for I2C master transmitter for N≤255 bytes . . . . .720
Figure 230. Transfer sequence flow for I2C master transmitter for N>255 bytes . . . . .721
Figure 231. Transfer bus diagrams for I2C master transmitter . . . . .722
Figure 232. Transfer sequence flow for I2C master receiver for N≤255 bytes . . . . .724
Figure 233. Transfer sequence flow for I2C master receiver for N >255 bytes . . . . .725
Figure 234. Transfer bus diagrams for I2C master receiver . . . . .726
Figure 235. Timeout intervals for \( t_{LOW:SEXT} \) , \( t_{LOW:MEXT} \) . . . . .730
Figure 236. Transfer sequence flow for SMBus slave transmitter N bytes + PEC . . . . .734
Figure 237. Transfer bus diagrams for SMBus slave transmitter (SBC=1) . . . . .735
Figure 238. Transfer sequence flow for SMBus slave receiver N Bytes + PEC . . . . .736
Figure 239. Bus transfer diagrams for SMBus slave receiver (SBC=1). . . . .737
Figure 240. Bus transfer diagrams for SMBus master transmitter . . . . .738
Figure 241. Bus transfer diagrams for SMBus master receiver . . . . .740
Figure 242. USART block diagram . . . . .766
Figure 243. Word length programming . . . . .768
Figure 244. Configurable stop bits . . . . .770
Figure 245. TC/TXE behavior when transmitting . . . . .771
Figure 246. Start bit detection when oversampling by 16 or 8 . . . . .772
Figure 247. Data sampling when oversampling by 16 . . . . .775
Figure 248. Data sampling when oversampling by 8 . . . . .776
Figure 249. Mute mode using Idle line detection . . . . .783
Figure 250. Mute mode using address mark detection . . . . .784
Figure 251. Break detection in LIN mode (11-bit break length - LBDL bit is set) . . . . .787
Figure 252. Break detection in LIN mode vs. Framing error detection. . . . .788
Figure 253. USART example of synchronous transmission. . . . .789
Figure 254. USART data clock timing diagram (M bits = 00) . . . . .789
Figure 255. USART data clock timing diagram (M bits = 01) . . . . .790
Figure 256. RX data setup/hold time . . . . .790
Figure 257. ISO 7816-3 asynchronous protocol . . . . .792
Figure 258. Parity error detection using the 1.5 stop bits . . . . .793
Figure 259. IrDA SIR ENDEC- block diagram . . . . .797
Figure 260. IrDA data modulation (3/16) -Normal Mode . . . . .798
Figure 261. Transmission using DMA . . . . .799
Figure 262. Reception using DMA . . . . .800
Figure 263. Hardware flow control between 2 USARTs . . . . .800
Figure 264. RS232 RTS flow control . . . . .801
Figure 265. RS232 CTS flow control . . . . .802
Figure 266. USART interrupt mapping diagram . . . . .805
Figure 267. LPUART block diagram . . . . .832
Figure 268. Word length programming . . . . .834
Figure 269. Configurable stop bits . . . . .835
Figure 270. TC/TXE behavior when transmitting . . . . .837
Figure 271. Mute mode using Idle line detection . . . . .844
Figure 272. Mute mode using address mark detection . . . . .845
Figure 273. Transmission using DMA . . . . .848
Figure 274. Reception using DMA . . . . .849
Figure 275. Hardware flow control between 2 LPUARTs . . . . .849
Figure 276. RS232 RTS flow control . . . . .850
Figure 277. RS232 CTS flow control . . . . .851
Figure 278. LPUART interrupt mapping diagram . . . . .855
Figure 279. SPI block diagram. . . . .873
Figure 280. Full-duplex single master/ single slave application. . . . .874
Figure 281. Half-duplex single master/ single slave application . . . . .875
Figure 282. Simplex single master/single slave application (master in transmit-only/
slave in receive-only mode) . . . . .
876
Figure 283. Master and three independent slaves. . . . .877
Figure 284. Multi-master application . . . . .878
Figure 285. Hardware/software slave select management . . . . .879
Figure 286. Data clock timing diagram . . . . .881
Figure 287. TXE/RXNE/BSY behavior in master / full-duplex mode (BIDIMODE=0,
RXONLY=0) in the case of continuous transfers . . . . .
884
Figure 288. TXE/RXNE/BSY behavior in slave / full-duplex mode (BIDIMODE=0,
RXONLY=0) in the case of continuous transfers . . . . .
885
Figure 289. Transmission using DMA . . . . .887
Figure 290. Reception using DMA . . . . .888
Figure 291. TI mode transfer . . . . .891
Figure 292. I 2 S block diagram . . . . .894
Figure 293. Full-duplex communication . . . . .896
Figure 294. I 2 S Philips protocol waveforms (16/32-bit full accuracy, CPOL = 0). . . . .897
Figure 295. I 2 S Philips standard waveforms (24-bit frame with CPOL = 0). . . . .897
Figure 296. Transmitting 0x8EAA33 . . . . .898
Figure 297. Receiving 0x8EAA33 . . . . .898
Figure 298. I 2 S Philips standard (16-bit extended to 32-bit packet frame with CPOL = 0) . . . . .898
Figure 299. Example of 16-bit data frame extended to 32-bit channel frame . . . . .899
Figure 300. MSB Justified 16-bit or 32-bit full-accuracy length with CPOL = 0 . . . . .899
Figure 301. MSB justified 24-bit frame length with CPOL = 0 . . . . .899
Figure 302. MSB justified 16-bit extended to 32-bit packet frame with CPOL = 0 . . . . .900
Figure 303. LSB justified 16-bit or 32-bit full-accuracy with CPOL = 0 . . . . .900
Figure 304. LSB justified 24-bit frame length with CPOL = 0 . . . . .900
Figure 305. Operations required to transmit 0x3478AE. . . . .901
Figure 306. Operations required to receive 0x3478AE . . . . .901
Figure 307. LSB justified 16-bit extended to 32-bit packet frame with CPOL = 0 . . . . .901
Figure 308. Example of 16-bit data frame extended to 32-bit channel frame . . . . .902
Figure 309. PCM standard waveforms (16-bit) . . . . .902
Figure 310. PCM standard waveforms (16-bit extended to 32-bit packet frame). . . . .902
Figure 311. Audio sampling frequency definition . . . . .903
Figure 312. I 2 S clock generator architecture . . . . .903
Figure 313. USB peripheral block diagram . . . . .922
Figure 314. Packet buffer areas with examples of buffer description table locations . . . . .926
Figure 315. Block diagram of STM32L0x3 MCU and Cortex ® -M0+-level debug support . . . . .954

Chapters