ST STM32F2 Series User manual

March 2017
DocID028236 Rev 2
1/1371
www.st.com
UM1940
User Manual
Description of STM32F2 HAL and Low Layer drivers
Introduction
STMCubeTM is STMicroelectronics's original initiative to ease developers' life by reducing development
efforts, time and cost. STM32Cube covers the STM32 portfolio.
STM32Cube Version 1.x includes:
The STM32CubeMX, a graphical software configuration tool that allows generating C initialization
code using graphical wizards.
A comprehensive embedded software platform, delivered per series (such asSTM32CubeF2
forSTM32F2 series)
The STM32Cube Hardware Abstraction Layer (HAL), an STM32 abstraction layer embedded
software, ensuring maximized portability across the STM32 portfolio
The Low Layer APIs (LL) offering a fast light-weight expert-oriented layer which is closer to the
hardware than the HAL. The LL APIs are available only for a set of peripherals.
A consistent set of middleware components such as RTOS, USB, TCP/IP, Graphics
All embedded software utilities coming with a full set of examples.
The HAL driver layer provides a generic multi instance simple set of APIs (application programming
interfaces) to interact with the upper layer (application, libraries and stacks).
The HAL driver APIs are split into two categories: generic APIs which provide common and generic
functions for all the STM32 series and extension APIs which include specific and customized functions
for a given line or part number. The HAL drivers include a complete set of ready-to-use APIs which
simplify the user application implementation. As an example, the communication peripherals contain
APIs to initialize and configure the peripheral, manage data transfers in polling mode, handle interrupts
or DMA, and manage communication errors.
The HAL drivers are feature-oriented instead of IP-oriented. As an example, the timer APIs are split into
several categories following the functions offered by the IP such as basic timer, capture, or pulse width
modulation (PWM). The HAL driver layer implements run-time failure detection by checking the input
values of all functions. Such dynamic checking contributes to enhance the firmware robustness. Run-
time detection is also suitable for user application development and debugging.
The LL drivers offer hardware services based on the available features of the STM32 peripherals. These
services reflect exactly the hardware capabilities and provide atomic operations that must be called
following the programming model described in the product line reference manual. As a result, the LL
services are not based on standalone processes and do not require any additional memory resources to
save their states, counter or data pointers: all operations are performed by changing the associated
peripheral registers content. Contrary to the HAL, the LL APIs are not provided for peripherals for which
optimized access is not a key feature, or for those requiring heavy software configuration and/or
complex upper level stack (such as FMC, USB, SDMMC).
The HAL and LL are complementary and cover a wide range of applications requirements:
The HAL offers high-level and feature-oriented APIs, with a high-portability level. They hide the
MCU and peripheral complexity to end-user.
The LL offers low-level APIs at registers level, with better optimization but less portability. They
require deep knowledge of the MCU and peripherals specifications.
The source code of HAL and LL drivers is developed in Strict ANSI-C which makes it independent from
the development tools. It is checked with CodeSonar™ static analysis tool. It is fully documented and is
MISRA-C 2004 compliant.

Contents
UM1940
2/1371
DocID028236 Rev 2
Contents
1Acronyms and definitions.............................................................26
2Overview of HAL drivers...............................................................28
2.1 HAL and user-application files.........................................................28
2.1.1 HAL driver files ................................................................................. 28
2.1.2 User-application files........................................................................ 30
2.2 HAL data structures ........................................................................31
2.2.1 Peripheral handle structures ............................................................ 31
2.2.2 Initialization and configuration structure........................................... 33
2.2.3 Specific process structures .............................................................. 33
2.3 API classification.............................................................................33
2.4 Devices supported by HAL drivers..................................................34
2.5 HAL driver rules ..............................................................................36
2.5.1 HAL API naming rules...................................................................... 36
2.5.2 HAL general naming rules................................................................ 37
2.5.3 HAL interrupt handler and callback functions................................... 38
2.6 HAL generic APIs............................................................................39
2.7 HAL extension APIs........................................................................40
2.7.1 HAL extension model overview........................................................ 40
2.7.2 HAL extension model cases............................................................. 41
2.8 File inclusion model.........................................................................43
2.9 HAL common resources..................................................................43
2.10 HAL configuration............................................................................44
2.11 HAL system peripheral handling .....................................................46
2.11.1 Clock................................................................................................. 46
2.11.2 GPIOs............................................................................................... 46
2.11.3 Cortex NVIC and SysTick timer........................................................ 48
2.11.4 PWR ................................................................................................. 48
2.11.5 EXTI.................................................................................................. 48
2.11.6 DMA.................................................................................................. 49
2.12 How to use HAL drivers ..................................................................51
2.12.1 HAL usage models........................................................................... 51
2.12.2 HAL initialization............................................................................... 52
2.12.3 HAL IO operation process................................................................ 54
2.12.4 Timeout and error management....................................................... 57
3Overview of Low Layer drivers.....................................................61

UM1940
Contents
DocID028236 Rev 2
3/1371
3.1 Low Layer files................................................................................61
3.2 Overview of Low Layer APIs and naming rules...............................63
3.2.1 Peripheral initialization functions...................................................... 63
3.2.2 Peripheral register-level configuration functions .............................. 67
4Cohabiting of HAL and LL ............................................................69
4.1 Low Layer driver used in standalone mode.....................................69
4.2 Mixed use of Low Layer APIs and HAL drivers...............................69
5HAL System Driver........................................................................70
5.1 HAL Firmware driver API description..............................................70
5.1.1 How to use this driver....................................................................... 70
5.1.2 Initialization and de-initialization functions ....................................... 70
5.1.3 HAL Control functions....................................................................... 70
5.1.4 Detailed description of functions ...................................................... 71
5.2 HAL Firmware driver defines...........................................................75
5.2.1 HAL................................................................................................... 75
6HAL ADC Generic Driver...............................................................77
6.1 ADC Firmware driver registers structures .......................................77
6.1.1 ADC_InitTypeDef.............................................................................. 77
6.1.2 ADC_ChannelConfTypeDef ............................................................. 78
6.1.3 ADC_AnalogWDGConfTypeDef....................................................... 79
6.1.4 ADC_HandleTypeDef....................................................................... 80
6.2 ADC Firmware driver API description..............................................80
6.2.1 ADC Peripheral features................................................................... 80
6.2.2 How to use this driver....................................................................... 81
6.2.3 Initialization and de-initialization functions ....................................... 83
6.2.4 IO operation functions ...................................................................... 83
6.2.5 Peripheral Control functions............................................................. 83
6.2.6 Peripheral State and errors functions............................................... 84
6.2.7 Detailed description of functions ...................................................... 84
6.3 ADC Firmware driver defines..........................................................89
6.3.1 ADC.................................................................................................. 89
7HAL ADC Extension Driver...........................................................96
7.1 ADCEx Firmware driver registers structures...................................96
7.1.1 ADC_InjectionConfTypeDef ............................................................. 96
7.1.2 ADC_MultiModeTypeDef.................................................................. 97
7.2 ADCEx Firmware driver API description .........................................98

Contents
UM1940
4/1371
DocID028236 Rev 2
7.2.1 How to use this driver....................................................................... 98
7.2.2 Extended features functions............................................................. 99
7.2.3 Detailed description of functions .................................................... 100
7.3 ADCEx Firmware driver defines....................................................103
7.3.1 ADCEx............................................................................................ 103
8HAL CAN Generic Driver.............................................................105
8.1 CAN Firmware driver registers structures .....................................105
8.1.1 CAN_InitTypeDef............................................................................ 105
8.1.2 CAN_FilterConfTypeDef................................................................. 106
8.1.3 CanTxMsgTypeDef......................................................................... 107
8.1.4 CanRxMsgTypeDef........................................................................ 107
8.1.5 CAN_HandleTypeDef..................................................................... 108
8.2 CAN Firmware driver API description............................................108
8.2.1 How to use this driver..................................................................... 108
8.2.2 Initialization and de-initialization functions ..................................... 109
8.2.3 IO operation functions .................................................................... 110
8.2.4 Peripheral State and Error functions .............................................. 110
8.2.5 Detailed description of functions .................................................... 110
8.3 CAN Firmware driver defines........................................................114
8.3.1 CAN................................................................................................ 114
9HAL CORTEX Generic Driver......................................................122
9.1 CORTEX Firmware driver registers structures..............................122
9.1.1 MPU_Region_InitTypeDef.............................................................. 122
9.2 CORTEX Firmware driver API description ....................................123
9.2.1 How to use this driver..................................................................... 123
9.2.2 Initialization and de-initialization functions ..................................... 123
9.2.3 Peripheral Control functions........................................................... 124
9.2.4 Detailed description of functions .................................................... 124
9.3 CORTEX Firmware driver defines.................................................129
9.3.1 CORTEX......................................................................................... 129
10 HAL CRC Generic Driver.............................................................132
10.1 CRC Firmware driver registers structures.....................................132
10.1.1 CRC_HandleTypeDef..................................................................... 132
10.2 CRC Firmware driver API description ...........................................132
10.2.1 How to use this driver..................................................................... 132
10.2.2 Initialization and de-initialization functions ..................................... 132
10.2.3 Peripheral Control functions........................................................... 133

UM1940
Contents
DocID028236 Rev 2
5/1371
10.2.4 Peripheral State functions .............................................................. 133
10.2.5 Detailed description of functions .................................................... 133
10.3 CRC Firmware driver defines........................................................135
10.3.1 CRC................................................................................................ 135
11 HAL CRYP Generic Driver...........................................................136
11.1 CRYP Firmware driver registers structures...................................136
11.1.1 CRYP_InitTypeDef......................................................................... 136
11.1.2 CRYP_HandleTypeDef................................................................... 136
11.2 CRYP Firmware driver API description .........................................137
11.2.1 How to use this driver..................................................................... 137
11.2.2 Initialization and de-initialization functions ..................................... 138
11.2.3 AES processing functions .............................................................. 138
11.2.4 DES processing functions .............................................................. 139
11.2.5 TDES processing functions............................................................ 139
11.2.6 DMA callback functions.................................................................. 140
11.2.7 CRYP IRQ handler management................................................... 140
11.2.8 Peripheral State functions .............................................................. 140
11.2.9 Detailed description of functions .................................................... 140
11.3 CRYP Firmware driver defines......................................................155
11.3.1 CRYP.............................................................................................. 155
12 HAL DAC Generic Driver.............................................................159
12.1 DAC Firmware driver registers structures .....................................159
12.1.1 DAC_HandleTypeDef..................................................................... 159
12.1.2 DAC_ChannelConfTypeDef ........................................................... 159
12.2 DAC Firmware driver API description............................................160
12.2.1 DAC Peripheral features................................................................. 160
12.2.2 How to use this driver..................................................................... 161
12.2.3 Initialization and de-initialization functions ..................................... 162
12.2.4 IO operation functions .................................................................... 162
12.2.5 Peripheral Control functions........................................................... 162
12.2.6 Peripheral State and Errors functions ............................................ 162
12.2.7 Detailed description of functions .................................................... 163
12.3 DAC Firmware driver defines........................................................167
12.3.1 DAC................................................................................................ 167
13 HAL DAC Extension Driver.........................................................171
13.1 DACEx Firmware driver API description .......................................171

Contents
UM1940
6/1371
DocID028236 Rev 2
13.1.1 How to use this driver..................................................................... 171
13.1.2 Extended features functions........................................................... 171
13.1.3 Detailed description of functions .................................................... 171
13.2 DACEx Firmware driver defines....................................................175
13.2.1 DACEx............................................................................................ 175
14 HAL DCMI Generic Driver ...........................................................177
14.1 DCMI Firmware driver registers structures....................................177
14.1.1 DCMI_CodesInitTypeDef................................................................ 177
14.1.2 DCMI_InitTypeDef.......................................................................... 177
14.1.3 DCMI_HandleTypeDef ................................................................... 178
14.2 DCMI Firmware driver API description..........................................178
14.2.1 How to use this driver..................................................................... 178
14.2.2 Initialization and Configuration functions........................................ 179
14.2.3 IO operation functions .................................................................... 179
14.2.4 Peripheral Control functions........................................................... 180
14.2.5 Peripheral State and Errors functions ............................................ 180
14.2.6 Detailed description of functions .................................................... 180
14.3 DCMI Firmware driver defines.......................................................184
14.3.1 DCMI............................................................................................... 184
15 HAL DMA Generic Driver ............................................................190
15.1 DMA Firmware driver registers structures.....................................190
15.1.1 DMA_InitTypeDef........................................................................... 190
15.1.2 __DMA_HandleTypeDef................................................................. 191
15.2 DMA Firmware driver API description ...........................................192
15.2.1 How to use this driver..................................................................... 192
15.2.2 Initialization and de-initialization functions ..................................... 193
15.2.3 IO operation functions .................................................................... 193
15.2.4 State and Errors functions.............................................................. 194
15.2.5 Detailed description of functions .................................................... 194
15.3 DMA Firmware driver defines........................................................197
15.3.1 DMA................................................................................................ 197
16 HAL DMA Extension Driver.........................................................201
16.1 DMAEx Firmware driver API description.......................................201
16.1.1 How to use this driver..................................................................... 201
16.1.2 Extended features functions........................................................... 201
16.1.3 Detailed description of functions .................................................... 201
17 HAL ETH Generic Driver .............................................................203

UM1940
Contents
DocID028236 Rev 2
7/1371
17.1 ETH Firmware driver registers structures......................................203
17.1.1 ETH_InitTypeDef............................................................................ 203
17.1.2 ETH_MACInitTypeDef.................................................................... 203
17.1.3 ETH_DMAInitTypeDef.................................................................... 206
17.1.4 ETH_DMADescTypeDef................................................................. 207
17.1.5 ETH_DMARxFrameInfos................................................................ 208
17.1.6 ETH_HandleTypeDef ..................................................................... 208
17.2 ETH Firmware driver API description............................................209
17.2.1 How to use this driver..................................................................... 209
17.2.2 Initialization and de-initialization functions ..................................... 209
17.2.3 IO operation functions .................................................................... 210
17.2.4 Peripheral Control functions........................................................... 210
17.2.5 Peripheral State functions .............................................................. 210
17.2.6 Detailed description of functions .................................................... 211
17.3 ETH Firmware driver defines.........................................................215
17.3.1 ETH................................................................................................. 215
18 HAL FLASH Generic Driver.........................................................243
18.1 FLASH Firmware driver registers structures .................................243
18.1.1 FLASH_ProcessTypeDef ............................................................... 243
18.2 FLASH Firmware driver API description........................................243
18.2.1 FLASH peripheral features............................................................. 243
18.2.2 How to use this driver..................................................................... 243
18.2.3 Programming operation functions .................................................. 244
18.2.4 Peripheral Control functions........................................................... 244
18.2.5 Peripheral Errors functions............................................................. 244
18.2.6 Detailed description of functions .................................................... 245
18.3 FLASH Firmware driver defines....................................................247
18.3.1 FLASH............................................................................................ 247
19 HAL FLASH Extension Driver.....................................................253
19.1 FLASHEx Firmware driver registers structures.............................253
19.1.1 FLASH_EraseInitTypeDef.............................................................. 253
19.1.2 FLASH_OBProgramInitTypeDef .................................................... 253
19.2 FLASHEx Firmware driver API description....................................254
19.2.1 Flash Extension features................................................................ 254
19.2.2 How to use this driver..................................................................... 254
19.2.3 Extended programming operation functions .................................. 254
19.2.4 Detailed description of functions .................................................... 254

Contents
UM1940
8/1371
DocID028236 Rev 2
19.3 FLASHEx Firmware driver defines................................................256
19.3.1 FLASHEx........................................................................................ 256
20 HAL GPIO Generic Driver............................................................259
20.1 GPIO Firmware driver registers structures....................................259
20.1.1 GPIO_InitTypeDef.......................................................................... 259
20.2 GPIO Firmware driver API description ..........................................259
20.2.1 GPIO Peripheral features............................................................... 259
20.2.2 How to use this driver..................................................................... 260
20.2.3 Initialization and de-initialization functions ..................................... 260
20.2.4 IO operation functions .................................................................... 260
20.2.5 Detailed description of functions .................................................... 261
20.3 GPIO Firmware driver defines.......................................................263
20.3.1 GPIO............................................................................................... 263
21 HAL GPIO Extension Driver........................................................267
21.1 GPIOEx Firmware driver defines...................................................267
21.1.1 GPIOEx .......................................................................................... 267
22 HAL HASH Generic Driver ..........................................................268
22.1 HASH Firmware driver registers structures...................................268
22.1.1 HASH_InitTypeDef......................................................................... 268
22.1.2 HASH_HandleTypeDef................................................................... 268
22.2 HASH Firmware driver API description .........................................269
22.2.1 How to use this driver..................................................................... 269
22.2.2 HASH processing using polling mode functions ............................ 270
22.2.3 HASH processing using interrupt mode functions.......................... 270
22.2.4 HASH processing using DMA mode functions............................... 270
22.2.5 HMAC processing using polling mode functions............................ 270
22.2.6 HMAC processing using DMA mode functions .............................. 271
22.2.7 Peripheral State functions .............................................................. 271
22.2.8 Initialization and de-initialization functions ..................................... 271
22.2.9 Detailed description of functions .................................................... 271
22.3 HASH Firmware driver defines......................................................278
22.3.1 HASH.............................................................................................. 278
23 HAL HCD Generic Driver.............................................................280
23.1 HCD Firmware driver registers structures.....................................280
23.1.1 HCD_HandleTypeDef..................................................................... 280
23.2 HCD Firmware driver API description ...........................................280

UM1940
Contents
DocID028236 Rev 2
9/1371
23.2.1 How to use this driver..................................................................... 280
23.2.2 Initialization and de-initialization functions ..................................... 281
23.2.3 IO operation functions .................................................................... 281
23.2.4 Peripheral Control functions........................................................... 281
23.2.5 Peripheral State functions .............................................................. 281
23.2.6 Detailed description of functions .................................................... 281
23.3 HCD Firmware driver defines........................................................286
23.3.1 HCD................................................................................................ 286
24 HAL I2C Generic Driver...............................................................288
24.1 I2C Firmware driver registers structures .......................................288
24.1.1 I2C_InitTypeDef.............................................................................. 288
24.1.2 I2C_HandleTypeDef....................................................................... 288
24.2 I2C Firmware driver API description..............................................289
24.2.1 How to use this driver..................................................................... 289
24.2.2 Initialization and de-initialization functions ..................................... 293
24.2.3 IO operation functions .................................................................... 294
24.2.4 Peripheral State, Mode and Error functions................................... 296
24.2.5 Detailed description of functions .................................................... 296
24.3 I2C Firmware driver defines..........................................................308
24.3.1 I2C.................................................................................................. 308
25 HAL I2S Generic Driver...............................................................314
25.1 I2S Firmware driver registers structures .......................................314
25.1.1 I2S_InitTypeDef.............................................................................. 314
25.1.2 I2S_HandleTypeDef....................................................................... 314
25.2 I2S Firmware driver API description..............................................315
25.2.1 How to use this driver..................................................................... 315
25.2.2 Initialization and de-initialization functions ..................................... 317
25.2.3 IO operation functions .................................................................... 317
25.2.4 Peripheral State and Errors functions ............................................ 318
25.2.5 Detailed description of functions .................................................... 318
25.3 I2S Firmware driver defines ..........................................................323
25.3.1 I2S .................................................................................................. 323
26 HAL IRDA Generic Driver............................................................328
26.1 IRDA Firmware driver registers structures ....................................328
26.1.1 IRDA_InitTypeDef........................................................................... 328
26.1.2 IRDA_HandleTypeDef.................................................................... 328

Contents
UM1940
10/1371
DocID028236 Rev 2
26.2 IRDA Firmware driver API description...........................................329
26.2.1 How to use this driver..................................................................... 329
26.2.2 Initialization and Configuration functions........................................ 330
26.2.3 IO operation functions .................................................................... 331
26.2.4 Peripheral State and Errors functions ............................................ 332
26.2.5 Detailed description of functions .................................................... 332
26.3 IRDA Firmware driver defines.......................................................340
26.3.1 IRDA............................................................................................... 340
27 HAL IWDG Generic Driver...........................................................347
27.1 IWDG Firmware driver registers structures...................................347
27.1.1 IWDG_InitTypeDef ......................................................................... 347
27.1.2 IWDG_HandleTypeDef................................................................... 347
27.2 IWDG Firmware driver API description .........................................347
27.2.1 IWDG Generic features.................................................................. 347
27.2.2 How to use this driver..................................................................... 348
27.2.3 Initialization and Start functions...................................................... 348
27.2.4 IO operation functions .................................................................... 348
27.2.5 Detailed description of functions .................................................... 349
27.3 IWDG Firmware driver defines......................................................349
27.3.1 IWDG.............................................................................................. 349
28 HAL MMC Generic Driver............................................................351
28.1 MMC Firmware driver registers structures ....................................351
28.1.1 HAL_MMC_CardInfoTypeDef ........................................................ 351
28.1.2 MMC_HandleTypeDef.................................................................... 351
28.1.3 HAL_MMC_CardCSDTypeDef....................................................... 352
28.1.4 HAL_MMC_CardCIDTypeDef ........................................................ 354
28.1.5 HAL_MMC_CardStatusTypeDef.................................................... 355
28.2 MMC Firmware driver API description...........................................356
28.2.1 How to use this driver..................................................................... 356
28.2.2 Detailed description of functions .................................................... 359
28.3 MMC Firmware driver defines.......................................................362
28.3.1 MMC............................................................................................... 362
29 HAL NAND Generic Driver..........................................................370
29.1 NAND Firmware driver registers structures...................................370
29.1.1 NAND_IDTypeDef.......................................................................... 370
29.1.2 NAND_AddressTypeDef................................................................. 370
29.1.3 NAND_DeviceConfigTypeDef ........................................................ 370

UM1940
Contents
DocID028236 Rev 2
11/1371
29.1.4 NAND_HandleTypeDef .................................................................. 371
29.2 NAND Firmware driver API description.........................................371
29.2.1 How to use this driver..................................................................... 371
29.2.2 NAND Initialization and de-initialization functions.......................... 372
29.2.3 NAND Input and Output functions.................................................. 372
29.2.4 NAND Control functions ................................................................. 373
29.2.5 NAND State functions..................................................................... 373
29.2.6 Detailed description of functions .................................................... 373
29.3 NAND Firmware driver defines......................................................379
29.3.1 NAND.............................................................................................. 379
30 HAL NOR Generic Driver.............................................................380
30.1 NOR Firmware driver registers structures.....................................380
30.1.1 NOR_IDTypeDef ............................................................................ 380
30.1.2 NOR_CFITypeDef.......................................................................... 380
30.1.3 NOR_HandleTypeDef..................................................................... 380
30.2 NOR Firmware driver API description ...........................................381
30.2.1 How to use this driver..................................................................... 381
30.2.2 NOR Initialization and de_initialization functions ........................... 381
30.2.3 NOR Input and Output functions .................................................... 382
30.2.4 NOR Control functions.................................................................... 382
30.2.5 NOR State functions....................................................................... 382
30.2.6 Detailed description of functions .................................................... 382
30.3 NOR Firmware driver defines........................................................386
30.3.1 NOR................................................................................................ 386
31 HAL PCCARD Generic Driver .....................................................387
31.1 PCCARD Firmware driver registers structures..............................387
31.1.1 PCCARD_HandleTypeDef ............................................................. 387
31.2 PCCARD Firmware driver API description....................................387
31.2.1 How to use this driver..................................................................... 387
31.2.2 PCCARD Initialization and de-initialization functions..................... 388
31.2.3 PCCARD Input and Output functions............................................. 388
31.2.4 PCCARD State functions................................................................ 388
31.2.5 Detailed description of functions .................................................... 388
31.3 PCCARD Firmware driver defines.................................................392
31.3.1 PCCARD ........................................................................................ 392
32 HAL PCD Generic Driver.............................................................393

Contents
UM1940
12/1371
DocID028236 Rev 2
32.1 PCD Firmware driver registers structures .....................................393
32.1.1 PCD_HandleTypeDef..................................................................... 393
32.2 PCD Firmware driver API description............................................393
32.2.1 How to use this driver..................................................................... 393
32.2.2 Initialization and de-initialization functions ..................................... 394
32.2.3 IO operation functions .................................................................... 394
32.2.4 Peripheral Control functions........................................................... 394
32.2.5 Peripheral State functions .............................................................. 395
32.2.6 Detailed description of functions .................................................... 395
32.3 PCD Firmware driver defines........................................................401
32.3.1 PCD................................................................................................ 401
33 HAL PCD Extension Driver.........................................................403
33.1 PCDEx Firmware driver API description .......................................403
33.1.1 Extended features functions........................................................... 403
33.1.2 Detailed description of functions .................................................... 403
34 HAL PWR Generic Driver............................................................404
34.1 PWR Firmware driver registers structures ....................................404
34.1.1 PWR_PVDTypeDef........................................................................ 404
34.2 PWR Firmware driver API description...........................................404
34.2.1 Initialization and de-initialization functions ..................................... 404
34.2.2 Peripheral Control functions........................................................... 404
34.2.3 Detailed description of functions .................................................... 406
34.3 PWR Firmware driver defines .......................................................410
34.3.1 PWR ............................................................................................... 410
35 HAL PWR Extension Driver ........................................................415
35.1 PWREx Firmware driver API description.......................................415
35.1.1 Peripheral extended features functions.......................................... 415
35.1.2 Detailed description of functions .................................................... 415
35.2 PWREx Firmware driver defines...................................................416
35.2.1 PWREx........................................................................................... 416
36 HAL RCC Generic Driver.............................................................417
36.1 RCC Firmware driver registers structures.....................................417
36.1.1 RCC_PLLInitTypeDef..................................................................... 417
36.1.2 RCC_OscInitTypeDef..................................................................... 417
36.1.3 RCC_ClkInitTypeDef...................................................................... 418
36.2 RCC Firmware driver API description ...........................................418

UM1940
Contents
DocID028236 Rev 2
13/1371
36.2.1 RCC specific features..................................................................... 418
36.2.2 RCC Limitations.............................................................................. 419
36.2.3 Initialization and de-initialization functions ..................................... 419
36.2.4 Peripheral Control functions........................................................... 420
36.2.5 Detailed description of functions .................................................... 420
36.3 RCC Firmware driver defines........................................................425
36.3.1 RCC................................................................................................ 425
37 HAL RCC Extension Driver.........................................................453
37.1 RCCEx Firmware driver registers structures.................................453
37.1.1 RCC_PLLI2SInitTypeDef................................................................ 453
37.1.2 RCC_PeriphCLKInitTypeDef.......................................................... 453
37.2 RCCEx Firmware driver API description .......................................453
37.2.1 Extended Peripheral Control functions........................................... 453
37.2.2 Detailed description of functions .................................................... 454
37.3 RCCEx Firmware driver defines....................................................454
37.3.1 RCCEx............................................................................................ 454
38 HAL RNG Generic Driver.............................................................458
38.1 RNG Firmware driver registers structures.....................................458
38.1.1 RNG_HandleTypeDef..................................................................... 458
38.2 RNG Firmware driver API description ...........................................458
38.2.1 How to use this driver..................................................................... 458
38.2.2 Initialization and de-initialization functions ..................................... 458
38.2.3 Peripheral Control functions........................................................... 459
38.2.4 Peripheral State functions .............................................................. 459
38.2.5 Detailed description of functions .................................................... 459
38.3 RNG Firmware driver defines........................................................462
38.3.1 RNG................................................................................................ 462
39 HAL RTC Generic Driver.............................................................465
39.1 RTC Firmware driver registers structures .....................................465
39.1.1 RTC_InitTypeDef............................................................................ 465
39.1.2 RTC_TimeTypeDef......................................................................... 465
39.1.3 RTC_DateTypeDef......................................................................... 466
39.1.4 RTC_AlarmTypeDef....................................................................... 466
39.1.5 RTC_HandleTypeDef..................................................................... 467
39.2 RTC Firmware driver API description............................................467
39.2.1 Backup Domain Operating Condition............................................. 467

Contents
UM1940
14/1371
DocID028236 Rev 2
39.2.2 Backup Domain Reset.................................................................... 468
39.2.3 Backup Domain Access.................................................................. 468
39.2.4 How to use this driver..................................................................... 468
39.2.5 RTC and low power modes............................................................ 468
39.2.6 Initialization and de-initialization functions ..................................... 469
39.2.7 RTC Time and Date functions........................................................ 469
39.2.8 RTC Alarm functions ...................................................................... 469
39.2.9 Peripheral Control functions........................................................... 470
39.2.10 Peripheral State functions .............................................................. 470
39.2.11 Detailed description of functions .................................................... 470
39.3 RTC Firmware driver defines ........................................................475
39.3.1 RTC ................................................................................................ 475
40 HAL RTC Extension Driver .........................................................485
40.1 RTCEx Firmware driver registers structures .................................485
40.1.1 RTC_TamperTypeDef.................................................................... 485
40.2 RTCEx Firmware driver API description........................................485
40.2.1 How to use this driver..................................................................... 485
40.2.2 RTC TimeStamp and Tamper functions......................................... 486
40.2.3 RTC Wake-up functions ................................................................. 486
40.2.4 Extension Peripheral Control functions .......................................... 486
40.2.5 Extended features functions........................................................... 487
40.2.6 Detailed description of functions .................................................... 487
40.3 RTCEx Firmware driver defines....................................................494
40.3.1 RTCEx............................................................................................ 494
41 HAL SD Generic Driver ...............................................................508
41.1 SD Firmware driver registers structures........................................508
41.1.1 HAL_SD_CardInfoTypeDef............................................................ 508
41.1.2 SD_HandleTypeDef........................................................................ 508
41.1.3 HAL_SD_CardCSDTypeDef .......................................................... 509
41.1.4 HAL_SD_CardCIDTypeDef............................................................ 511
41.1.5 HAL_SD_CardStatusTypeDef........................................................ 512
41.2 SD Firmware driver API description..............................................513
41.2.1 How to use this driver..................................................................... 513
41.2.2 Initialization and de-initialization functions ..................................... 516
41.2.3 IO operation functions .................................................................... 516
41.2.4 Peripheral Control functions........................................................... 516
41.2.5 Detailed description of functions .................................................... 517

UM1940
Contents
DocID028236 Rev 2
15/1371
41.3 SD Firmware driver defines...........................................................523
41.3.1 SD................................................................................................... 523
42 HAL SMARTCARD Generic Driver..............................................531
42.1 SMARTCARD Firmware driver registers structures......................531
42.1.1 SMARTCARD_InitTypeDef ............................................................ 531
42.1.2 SMARTCARD_HandleTypeDef...................................................... 532
42.2 SMARTCARD Firmware driver API description.............................532
42.2.1 How to use this driver..................................................................... 532
42.2.2 Initialization and Configuration functions........................................ 534
42.2.3 IO operation functions .................................................................... 535
42.2.4 Peripheral State and Errors functions ............................................ 536
42.2.5 Detailed description of functions .................................................... 536
42.3 SMARTCARD Firmware driver defines.........................................543
42.3.1 SMARTCARD................................................................................. 543
43 HAL SPI Generic Driver...............................................................551
43.1 SPI Firmware driver registers structures.......................................551
43.1.1 SPI_InitTypeDef ............................................................................. 551
43.1.2 __SPI_HandleTypeDef................................................................... 552
43.2 SPI Firmware driver API description .............................................552
43.2.1 How to use this driver..................................................................... 552
43.2.2 Initialization and de-initialization functions ..................................... 553
43.2.3 IO operation functions .................................................................... 554
43.2.4 Peripheral State and Errors functions ............................................ 555
43.2.5 Detailed description of functions .................................................... 555
43.3 SPI Firmware driver defines..........................................................560
43.3.1 SPI.................................................................................................. 560
44 HAL SRAM Generic Driver..........................................................566
44.1 SRAM Firmware driver registers structures...................................566
44.1.1 SRAM_HandleTypeDef.................................................................. 566
44.2 SRAM Firmware driver API description.........................................566
44.2.1 How to use this driver..................................................................... 566
44.2.2 SRAM Initialization and de_initialization functions......................... 567
44.2.3 SRAM Input and Output functions.................................................. 567
44.2.4 SRAM Control functions................................................................. 567
44.2.5 SRAM State functions .................................................................... 568
44.2.6 Detailed description of functions .................................................... 568

Contents
UM1940
16/1371
DocID028236 Rev 2
44.3 SRAM Firmware driver defines .....................................................572
44.3.1 SRAM ............................................................................................. 572
45 HAL TIM Generic Driver ..............................................................573
45.1 TIM Firmware driver registers structures.......................................573
45.1.1 TIM_Base_InitTypeDef................................................................... 573
45.1.2 TIM_OC_InitTypeDef...................................................................... 573
45.1.3 TIM_OnePulse_InitTypeDef........................................................... 574
45.1.4 TIM_IC_InitTypeDef ....................................................................... 575
45.1.5 TIM_Encoder_InitTypeDef ............................................................. 575
45.1.6 TIM_ClockConfigTypeDef .............................................................. 576
45.1.7 TIM_ClearInputConfigTypeDef....................................................... 576
45.1.8 TIM_SlaveConfigTypeDef .............................................................. 577
45.1.9 TIM_HandleTypeDef ...................................................................... 577
45.2 TIM Firmware driver API description.............................................578
45.2.1 TIMER Generic features................................................................. 578
45.2.2 How to use this driver..................................................................... 578
45.2.3 Time Base functions....................................................................... 579
45.2.4 Time Output Compare functions .................................................... 579
45.2.5 Time PWM functions ...................................................................... 580
45.2.6 Time Input Capture functions ......................................................... 580
45.2.7 Time One Pulse functions .............................................................. 581
45.2.8 Time Encoder functions.................................................................. 581
45.2.9 IRQ handler management.............................................................. 582
45.2.10 Peripheral Control functions........................................................... 582
45.2.11 TIM Callbacks functions ................................................................. 582
45.2.12 Peripheral State functions .............................................................. 582
45.2.13 Detailed description of functions .................................................... 583
45.3 TIM Firmware driver defines..........................................................608
45.3.1 TIM.................................................................................................. 608
46 HAL TIM Extension Driver...........................................................629
46.1 TIMEx Firmware driver registers structures...................................629
46.1.1 TIM_HallSensor_InitTypeDef ......................................................... 629
46.1.2 TIM_MasterConfigTypeDef ............................................................ 629
46.1.3 TIM_BreakDeadTimeConfigTypeDef............................................. 629
46.2 TIMEx Firmware driver API description.........................................630
46.2.1 TIMER Extended features.............................................................. 630
46.2.2 How to use this driver..................................................................... 630

UM1940
Contents
DocID028236 Rev 2
17/1371
46.2.3 Timer Hall Sensor functions ........................................................... 631
46.2.4 Timer Complementary Output Compare functions......................... 631
46.2.5 Timer Complementary PWM functions........................................... 632
46.2.6 Timer Complementary One Pulse functions................................... 632
46.2.7 Peripheral Control functions........................................................... 632
46.2.8 Extension Callbacks functions........................................................ 633
46.2.9 Extension Peripheral State functions ............................................. 633
46.2.10 Detailed description of functions .................................................... 633
46.3 TIMEx Firmware driver defines .....................................................644
46.3.1 TIMEx ............................................................................................. 644
47 HAL UART Generic Driver...........................................................646
47.1 UART Firmware driver registers structures...................................646
47.1.1 UART_InitTypeDef ......................................................................... 646
47.1.2 UART_HandleTypeDef................................................................... 646
47.2 UART Firmware driver API description .........................................647
47.2.1 How to use this driver..................................................................... 647
47.2.2 Initialization and Configuration functions........................................ 649
47.2.3 IO operation functions .................................................................... 650
47.2.4 Peripheral Control functions........................................................... 651
47.2.5 Peripheral State and Errors functions ............................................ 651
47.2.6 Detailed description of functions .................................................... 652
47.3 UART Firmware driver defines......................................................661
47.3.1 UART.............................................................................................. 661
48 HAL USART Generic Driver ........................................................672
48.1 USART Firmware driver registers structures.................................672
48.1.1 USART_InitTypeDef....................................................................... 672
48.1.2 USART_HandleTypeDef ................................................................ 672
48.2 USART Firmware driver API description.......................................673
48.2.1 How to use this driver..................................................................... 673
48.2.2 Initialization and Configuration functions........................................ 675
48.2.3 IO operation functions .................................................................... 675
48.2.4 Peripheral State and Errors functions ............................................ 677
48.2.5 Detailed description of functions .................................................... 677
48.3 USART Firmware driver defines....................................................684
48.3.1 USART............................................................................................ 684
49 HAL WWDG Generic Driver ........................................................691

Contents
UM1940
18/1371
DocID028236 Rev 2
49.1 WWDG Firmware driver registers structures.................................691
49.1.1 WWDG_InitTypeDef....................................................................... 691
49.1.2 WWDG_HandleTypeDef ................................................................ 691
49.2 WWDG Firmware driver API description.......................................691
49.2.1 WWDG specific features ................................................................ 691
49.2.2 How to use this driver..................................................................... 692
49.2.3 Initialization and Configuration functions........................................ 692
49.2.4 IO operation functions .................................................................... 693
49.2.5 Detailed description of functions .................................................... 693
49.3 WWDG Firmware driver defines....................................................694
49.3.1 WWDG............................................................................................ 694
50 LL ADC Generic Driver................................................................697
50.1 ADC Firmware driver registers structures .....................................697
50.1.1 LL_ADC_CommonInitTypeDef....................................................... 697
50.1.2 LL_ADC_InitTypeDef...................................................................... 697
50.1.3 LL_ADC_REG_InitTypeDef............................................................ 698
50.1.4 LL_ADC_INJ_InitTypeDef.............................................................. 698
50.2 ADC Firmware driver API description............................................699
50.2.1 Detailed description of functions .................................................... 699
50.3 ADC Firmware driver defines........................................................757
50.3.1 ADC................................................................................................ 757
51 LL BUS Generic Driver................................................................790
51.1 BUS Firmware driver API description............................................790
51.1.1 Detailed description of functions .................................................... 790
51.2 BUS Firmware driver defines ........................................................816
51.2.1 BUS ................................................................................................ 816
52 LL CORTEX Generic Driver.........................................................819
52.1 CORTEX Firmware driver API description ....................................819
52.1.1 Detailed description of functions .................................................... 819
52.2 CORTEX Firmware driver defines.................................................826
52.2.1 CORTEX......................................................................................... 826
53 LL CRC Generic Driver................................................................829
53.1 CRC Firmware driver API description ...........................................829
53.1.1 Detailed description of functions .................................................... 829
53.2 CRC Firmware driver defines........................................................830
53.2.1 CRC................................................................................................ 830

UM1940
Contents
DocID028236 Rev 2
19/1371
54 LL DAC Generic Driver................................................................832
54.1 DAC Firmware driver registers structures.....................................832
54.1.1 LL_DAC_InitTypeDef...................................................................... 832
54.2 DAC Firmware driver API description............................................832
54.2.1 Detailed description of functions .................................................... 832
54.3 DAC Firmware driver defines........................................................848
54.3.1 DAC................................................................................................ 848
55 LL DMA Generic Driver ...............................................................854
55.1 DMA Firmware driver registers structures.....................................854
55.1.1 LL_DMA_InitTypeDef..................................................................... 854
55.2 DMA Firmware driver API description ...........................................856
55.2.1 Detailed description of functions .................................................... 856
55.3 DMA Firmware driver defines........................................................907
55.3.1 DMA................................................................................................ 907
56 LL EXTI Generic Driver ...............................................................911
56.1 EXTI Firmware driver registers structures.....................................911
56.1.1 LL_EXTI_InitTypeDef..................................................................... 911
56.2 EXTI Firmware driver API description ...........................................911
56.2.1 Detailed description of functions .................................................... 911
56.3 EXTI Firmware driver defines........................................................924
56.3.1 EXTI................................................................................................ 924
57 LL GPIO Generic Driver ..............................................................927
57.1 GPIO Firmware driver registers structures....................................927
57.1.1 LL_GPIO_InitTypeDef.................................................................... 927
57.2 GPIO Firmware driver API description ..........................................927
57.2.1 Detailed description of functions .................................................... 927
57.3 GPIO Firmware driver defines.......................................................942
57.3.1 GPIO............................................................................................... 942
58 LL I2C Generic Driver..................................................................945
58.1 I2C Firmware driver registers structures .......................................945
58.1.1 LL_I2C_InitTypeDef........................................................................ 945
58.2 I2C Firmware driver API description..............................................945
58.2.1 Detailed description of functions .................................................... 945
58.3 I2C Firmware driver defines..........................................................976
58.3.1 I2C.................................................................................................. 976

Contents
UM1940
20/1371
DocID028236 Rev 2
59 LL I2S Generic Driver..................................................................981
59.1 I2S Firmware driver registers structures .......................................981
59.1.1 LL_I2S_InitTypeDef........................................................................ 981
59.2 I2S Firmware driver API description..............................................981
59.2.1 Detailed description of functions .................................................... 981
59.3 I2S Firmware driver defines ..........................................................995
59.3.1 I2S .................................................................................................. 995
60 LL IWDG Generic Driver..............................................................997
60.1 IWDG Firmware driver API description .........................................997
60.1.1 Detailed description of functions .................................................... 997
60.2 IWDG Firmware driver defines....................................................1000
60.2.1 IWDG............................................................................................ 1000
61 LL PWR Generic Driver.............................................................1002
61.1 PWR Firmware driver API description.........................................1002
61.1.1 Detailed description of functions .................................................. 1002
61.2 PWR Firmware driver defines .....................................................1008
61.2.1 PWR ............................................................................................. 1008
62 LL RCC Generic Driver..............................................................1011
62.1 RCC Firmware driver registers structures...................................1011
62.1.1 LL_RCC_ClocksTypeDef ............................................................. 1011
62.2 RCC Firmware driver API description .........................................1011
62.2.1 Detailed description of functions .................................................. 1011
62.3 RCC Firmware driver defines......................................................1043
62.3.1 RCC.............................................................................................. 1043
63 LL RNG Generic Driver .............................................................1056
63.1 RNG Firmware driver API description .........................................1056
63.1.1 Detailed description of functions .................................................. 1056
63.2 RNG Firmware driver defines......................................................1059
63.2.1 RNG.............................................................................................. 1059
64 LL RTC Generic Driver..............................................................1061
64.1 RTC Firmware driver registers structures ...................................1061
64.1.1 LL_RTC_InitTypeDef.................................................................... 1061
64.1.2 LL_RTC_TimeTypeDef................................................................. 1061
64.1.3 LL_RTC_DateTypeDef................................................................. 1062
64.1.4 LL_RTC_AlarmTypeDef............................................................... 1062
Other manuals for STM32F2 Series
2
Table of contents
Other ST Microcontroller manuals

ST
ST STM32 Nucleo Installation and operating instructions

ST
ST STM32F4 Series User manual

ST
ST STM32MP135F-DK User manual

ST
ST STEVAL-BFA001V1B User manual

ST
ST UM2135 User manual

ST
ST STM32 Nucleo-64-P Series User manual

ST
ST P-NUCLEO-WB55 User manual

ST
ST STM32 Nucleo User manual

ST
ST STM32 Nucleo User manual

ST
ST ST25R3911B User manual