Description of STM32F1 HAL and Low layer drivers

Transcript

1 UM1850 User manual Description of STM32F1 HAL and Low - layer drivers Introduction TM is an STMicroelectronics original initiative to make developers' lives easier by reducing STMCube development efforts, time and cost. STM32Cube covers the whole STM32 portfolio. STM32Cube Version 1.x includes: STM32CubeMX, a graphical software configuration tool that allows the generation of C initialization code using graphical wizards. A comprehensive embedded software platform, delivered per series (such as STM32CubeF1 for STM32F1 series) The STM32Cube HAL, STM32 abstraction layer embedded software ensuring maximized portability across the STM32 portfolio weight expert - Low Layer APIs (LL) offering a fast light oriented layer which is closer to the - hardware than the HAL. 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 delivered with a full set of examples. ogramming instance simple set of APIs (application pr The HAL driver layer provides a generic multi - 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 e specific and customized functions functions for all the STM32 series and extension APIs which includ for a given line or part number. The HAL drivers include a complete set of ready use APIs which - to - simplify the user application implementation. As an example, the communication peripherals contain configure the peripheral, manage data transfers in polling mode, handle interrupts APIs to initialize and or DMA, and manage communication errors. - oriented. As an example, the timer APIs are split into - The HAL drivers are feature oriented instead of IP several categories follo wing the IP functions: basic timer, capture, pulse width modulation (PWM), etc.. 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. - time detection is also Run 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 pro duct 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 eral registers content. Contrary to the HAL, the LL APIs are not provided for peripherals for which periph optimized access is not a key feature, or for those requiring heavy software configuration and/or complex upper level stack (such as FSMC, USB, SDMMC). HAL and LL are complementary and cover a wide range of applications requirements: The - The HAL offers high - - portability level. They hide the level and feature oriented APIs, with a high user. - MCU and peripheral complexity to end registers level, with better optimization but less portability. They - level APIs at The LL offers low require deep knowledge of the MCU and peripherals specifications. C which makes it independent from - The source code of HAL and LL drivers is developed in Strict ANSI the development too ls. It is checked with CodeSonar™ static analysis tool. It is fully documented and is MISRA C 2004 compliant. - 2 DocID027328 Rev April 2017 1 / 1166 www.st.com

2 Contents UM1850 Contents Acronyms and definitions ... ... 24 1 Overview of HAL drivers ... ... 2 26 - application files ... HAL and user 26 2.1 ... HAL driver files ... ... 2.1.1 26 ... 2.1.2 User - application files ... ... ... 27 ... 2.2 ... ... 29 HAL data structures 2.2.1 Peripheral handle struc tures ... ... 29 2.2.2 Initialization and configuration structure ... ... 30 2.2.3 ... ... 31 Specific process structures API classification ... ... ... 31 2.3 ... ivers ... Devices supported by HAL dr 32 2.4 ... HAL driver rules 38 ... ... 2.5 2.5.1 HAL API naming rules ... ... ... 38 2.5.2 HAL general naming rules ... ... 39 2.5.3 HAL interrupt handler and callback functions ... ... 40 2.6 HAL generic APIs ... ... ... 41 2.7 42 ... ... ... HAL extension APIs 2.7.1 ... ... 42 HAL extension model overview HAL extension model cases ... ... 42 2.7.2 ... del ... ... File inclusion mo 45 2.8 ... HAL common resources ... .. 46 2.9 2.10 HAL configuration ... ... ... 46 2.11 HAL system peripheral handling ... ... 47 ... 2.11.1 Clock ... ... . 47 2.11.2 GPIOs ... ... ... 48 2.11.3 50 Cortex NVIC and SysTick timer ... ... . 2.11.4 ... ... ... 50 PWR ... EXTI ... 2.11.5 ... .. 50 2.11.6 DMA ... ... ... .. 52 2.12 How to use HAL drivers ... ... .. 53 2.12.1 HAL usage models ... ... ... 53 HAL initialization ... ... ... 54 2.12.2 56 2.12.3 HAL IO operation process ... ... Timeout and error management 2.12.4 59 ... ... DocID027328 / 1166 2 Rev 2

3 UM1850 Contents 3 ... ... 63 Overview of Low Layer drivers Low Layer files ... ... ... 63 3.1 Overview of Low Layer APIs and naming rules ... 65 3.2 1 Peripheral initialization functions ... ... 65 3.2. 3.2.2 - level configuration functions ... 69 Peripheral register ... ... 71 4 Cohabiting of HAL and LL Low Layer driver used in standalone mode ... ... 4.1 71 4.2 Mixed use of Low Layer APIs and HAL drivers ... 71 72 5 HAL System Driver ... ... ... 5.1 HAL Firmware driver API description ... ... 72 5.1.1 How to use this driver ... ... ... 72 5.1.2 Initialization and de - initialization functions ... ... 72 HAL Control functions 5.1.3 ... ... ... 72 5.1.4 Detailed description of functions ... ... 73 5.2 HAL Firmware driver defines ... ... 77 ... 5.2.1 HAL ... ... ... 77 79 6 HAL ADC Generic Driver ... ... 79 ... ... ADC Firmware driver registers structures 6.1 6.1.1 ... ... ... 79 ADC_InitTypeDef ADC_ChannelConfTypeDef ... ... 80 6.1.2 ADC_AnalogWDGConfTy peDef ... ... 80 6.1.3 ADC_HandleTypeDef ... 6.1.4 ... 81 ... 6.2 ADC Firmware driver API description ... ... 81 6.2.1 ADC peripheral features ... ... ... 81 How to use this driver ... ... ... 82 6.2.2 6.2.3 Initialization and de - initialization functions ... ... 84 IO operation functions 6.2.4 85 ... ... ... 6.2.5 Peripheral Control functions ... ... 85 6.2.6 Peripheral State and Errors functions ... ... 85 6.2.7 Detailed description of functions ... ... 86 ... 6.3 ADC Firmw are driver defines ... 92 ... 6.3.1 ... ... ADC .. 92 7 HAL ADC Extension Driver ... ... 100 7.1 ADCEx Firmware driver registers structures ... . 100 100 7.1.1 A DC_InjectionConfTypeDef ... ... ... ... ADC_MultiModeTypeDef 7.1.2 101 2 DocID027328 Rev 1166 3 /

4 Contents UM1850 7.2 ADCEx Firmware driver API description ... ... 102 IO operation functions ... ... 7.2.1 102 ... 7.2.2 Peripheral Control functions ... 102 ... 7.2.3 Detailed description of functions ... ... 103 7.3 ADCEx Firmware driver defines ... ... 106 7.3.1 ADCEx ... ... ... 106 8 HAL CAN Generic Driver ... ... 110 110 8.1 CAN Firmware driver registers structures ... ... 8.1.1 CAN_InitTypeDef ... ... ... 110 8.1.2 CanTxMsgTypeDef ... ... ... 111 ... 8.1.3 CanRxMsgTypeDef ... ... 111 ... 8.1.4 CAN_HandleTypeDef 112 ... ... 8.2 CAN Firmware driver API description ... ... 112 8.2.1 How to use this driver ... ... ... 112 8.2.2 Initialization and de - initialization functions ... ... 113 114 8.2.3 IO operation functions ... ... ... ... ... Peripheral State and Error functions 8.2.4 114 8.2.5 ... ... 114 Detailed description of functions ... ... 118 8.3 CAN Firmware driver defines CAN ... ... ... 118 8.3.1 HAL CAN Extension Driver ... ... 127 9 9.1 CANEx Firmware driver registers structures ... . 127 9.1.1 CAN_FilterConfTypeDef ... ... . 127 10 HAL CEC Generic Driver ... ... 128 10.1 CEC Firmware driver registers structures ... ... 128 10.1.1 CEC_InitTypeDef ... ... ... 128 10.1.2 128 CEC_HandleTypeDef ... ... ... 10.2 CEC Firmware driver API description ... ... 129 10.2.1 How to use this driver ... ... ... 129 10.2.2 Initialization and Configuration functions ... ... 129 ... 10.2.3 IO operation functions 130 ... ... 10.2.4 Peripheral Control function ... ... 130 10.2.5 Detailed des cription of functions ... ... 131 10.3 CEC Firmware driver defines ... ... 133 133 10.3.1 CEC ... ... ... 11 139 ... ... HAL CORTEX Generic Driver DocID027328 / 1166 4 Rev 2

5 UM1850 Contents 11.1 ... 139 CORTEX Firmware driver registers structures MPU_Region_InitTypeDef ... ... 139 11.1.1 ... ... 140 11.2 CORTEX Firmware driver API description How to use this driver ... ... ... 140 11.2.1 11.2.2 - initialization functions ... ... 140 Initialization and de ... ... 141 11.2.3 Peripheral Control functions Detailed description of functions ... 11.2.4 141 ... 11.3 CORTEX Firmware driver defines ... ... 146 11.3.1 CORTEX 6 ... ... ... 14 12 ... ... 149 HAL CRC Generic Driver CRC Firmware driver registers structures ... ... 149 12.1 CRC_HandleTypeDef ... ... ... 149 12.1.1 12.2 CRC Firmware driver API description ... ... 149 12.2.1 How to use this driver ... ... ... 149 12.2.2 Initialization and de - initialization functions ... ... 149 12.2.3 Peripheral Control functions ... ... 149 150 12.2.4 Peripheral State functions ... ... 150 ... ... Detailed description of functions 12.2.5 12.3 ware driver defines ... ... 151 CRC Firm ... ... ... 151 12.3.1 CRC HAL DAC Generic Driver ... 13 153 ... 13.1 DAC Firmware driver registers structures ... ... 153 13.1.1 DAC_HandleTypeDef ... ... ... 153 13.1.2 DAC_ChannelConfTypeDef ... ... 153 13.2 DAC Firmware driver API description ... ... 153 13.2.1 DAC Peripheral features ... ... . 153 ... 13.2.2 How to use this driver ... ... 155 ... 13.2.3 initialization functions ... - 156 Initialization and de IO operation functions ... ... ... 156 13.2.4 Peripheral Control functions ... ... 157 13.2.5 ... Peripheral State and Errors functions 157 ... 13.2.6 13.2.7 Detailed description of functions ... ... 157 13.3 DAC Firmware driver defines ... ... 162 13.3.1 DAC ... ... ... 162 14 HAL DAC Extension Driver ... ... 164 ... ... r API description DACEx Firmware drive 14.1 164 2 DocID027328 Rev 1166 5 /

6 Contents UM1850 14.1.1 ... ... ... 164 How to use this driver Extended features functions ... ... 164 14.1.2 ... ... 164 14.1.3 Detailed description of functions DACEx Fi rmware driver defines ... ... 168 14.2 14.2.1 ... ... ... 168 DACEx ... ... 170 15 HAL DMA Generic Driver DMA Firmware driver registers structures ... ... 15.1 170 15.1.1 DMA_InitTypeDef ... ... 170 ... 170 15.1.2 __DMA_HandleTypeDef ... ... . 15.2 DMA Firmware driver AP I description ... ... 171 15.2.1 How to use this driver ... ... ... 171 ... 15.2.2 Initialization and de - initialization functions ... 172 IO operation functions 15.2.3 ... ... ... 172 15.2.4 Peripheral State and Errors functions ... ... 173 15.2.5 Detailed description of functions ... ... 173 15.3 DMA Firmware driver defines ... ... 176 176 15.3.1 DMA ... ... ... 181 ... ... HAL DMA Extension Driver 16 16.1 ... ... 181 DMAEx Firmware driver defines DMAEx ... ... 181 ... 16.1.1 HAL ETH Generic Driver ... ... 17 183 ETH Firmware driver registers structures ... ... 183 17.1 ETH_InitTypeDef ... ... ... 183 17.1.1 17.1.2 ... ... ... 183 ETH_MACInitTypeDef ... ... ... 186 17.1.3 ETH_DMAInitTypeDef ETH_DMADescTypeDef ... ... . 187 17.1.4 ETH_DMARxFrameInfos ... ... 17.1.5 187 17.1.6 ETH_HandleTypeDef ... ... ... 188 17.2 ... ... 188 ETH Firmware driver API description ... use this driver ... ... 17.2.1 188 How to ... - initialization functions Initialization and de ... 189 17.2.2 17.2.3 IO operation functions ... ... ... 189 17.2.4 Peripheral Control functions ... ... 190 17.2.5 Peripheral State functions ... ... 190 17.2.6 Detailed description of functions ... ... 190 195 17.3 ETH Firmware d river defines ... ... 195 . ... ... ... ETH 17.3.1 DocID027328 / 1166 6 Rev 2

7 UM1850 Contents 18 HAL FLASH Generic Driver ... ... 221 FLASH Firmware drive r registers structures 18.1 . 221 ... 18.1.1 FLASH_ProcessTypeDef ... ... 221 18.2 FLASH Firmware driver API description ... ... 221 18.2.1 FLASH peripheral features ... ... 221 18.2.2 How to use thi s driver ... ... ... 221 18.2.3 Peripheral Control functions ... ... 222 222 18.2.4 Peripheral Errors functions ... ... 18.2.5 ... ... 222 Detailed description of functions FLASH Firmware driver defines ... ... 225 18.3 FLASH ... ... ... 225 18.3.1 19 HAL FLASH Extension Driver ... ... 230 19.1 FLASHEx Firmware driver registers structures ... 230 19.1.1 FLASH_EraseInitTypeDef ... ... 230 19.1.2 FLASH_OBProgramI nitTypeDef ... ... 230 19.2 FLASHEx Firmware driver API description ... ... 231 231 19.2.1 FLASH Erasing Programming functions ... ... ... ... Option Bytes Programming functions 19.2.2 231 19.2.3 iled description of functions ... ... 231 Deta ... ... 233 19.3 FLASHEx Firmware driver defines FLASHEx ... 19.3.1 ... 233 ... 20 HAL GPIO Generic Driver ... ... 236 20.1 GPIO Firmware driver registers structures ... ... 236 20.1.1 GPIO_InitTypeDef ... ... ... 236 20.2 GPIO Firmware driver API description ... ... 236 20.2.1 GPIO Peripheral features ... ... 236 ... 20.2.2 How to use this driver ... ... 237 20.2.3 nd de - initialization functions ... ... 237 Initialization a ... 20.2.4 ... ... 237 IO operation functions Detailed description of functions ... ... 238 20.2.5 20.3 GPIO Firmware driver defines ... ... 240 20.3.1 GPIO ... ... ... 240 21 HAL GPIO Extension Driver ... ... 243 21.1 GPIOEx Firmware driver API description ... ... 243 GPIO Peripheral extension features ... ... 243 21.1.1 ... ... ... to use this driver How 21.1.2 243 2 DocID027328 Rev 1166 7 /

8 Contents UM1850 21.1.3 ... ... 243 Extended features functions Detailed description of functions ... ... 243 21.1.4 ... ... 244 21.2 GPIOEx Firmware driver defines GPIOEx ... ... ... 244 21.2.1 22 ... ... 259 HAL HCD Generic Driver ... ... 259 22.1 HCD Firmware driver registers structures HCD_HandleTypeDef ... ... 22.1.1 259 ... 22.2 HCD Firmware driver API description ... ... 259 22.2.1 How to 259 use this driver ... ... ... ... 22.2.2 - initialization functions Initialization and de ... 259 22.2.3 IO operation functions ... ... ... 260 22.2.4 Peripheral Control functions ... ... 260 22.2.5 Peripheral ... State functions ... 260 22.2.6 Detailed description of functions ... ... 260 22.3 HCD Firmware driver defines ... ... 265 22.3.1 HCD ... ... ... 265 266 23 HAL I2C Generic Driver ... ... ... ... I2C Firmware driver registers structures 23.1 266 23.1.1 ... ... ... 266 I2C_InitTypeDef ... ... ... 266 23.1.2 I2C_HandleTypeDef I2C Firmware driver API description ... ... 267 23.2 ... ... ... How to use this driver 267 23.2.1 23.2.2 Initialization and de - initialization functions ... ... 272 23.2.3 IO operation functions ... ... ... 272 23.2.4 Peripheral State, Mode and Error functions ... ... 274 23 .2.5 Detailed description of functions ... ... 274 23.3 I2C Firmware driver defines ... ... 286 23.3.1 286 I2C ... ... ... .. 24 HAL I2S Generic Driver ... ... 292 24.1 I2S Firmware driver registers structures ... ... 292 ... 24.1.1 I2S_InitTypeDef ... ... 292 ... 24.1.2 __I2S_HandleTypeDef ... ... 292 24.2 I2S Firmware driver API description ... ... 293 24.2.1 How to use this driver ... ... ... 293 24.2.2 Initialization a nd de - initialization functions ... ... 295 295 24.2.3 IO operation functions ... ... ... Peripheral State and Errors functions 24.2.4 296 ... ... DocID027328 / 1166 8 Rev 2

9 UM1850 Contents 24.2.5 ... ... 296 Detailed description of functions I2S Firm ... ... 302 24.3 ware driver defines .. ... ... ... 302 24.3.1 I2S HAL IRDA Generic Driver ... ... 307 25 25.1 ... ... 307 IRDA Firmware driver registers structures ... ... ... 307 25.1.1 IRDA_InitTypeDef IRDA_HandleTypeDef ... 25.1.2 ... 307 ... 25.2 IRDA Firmware driver API description ... ... 308 25.2.1 How to use this driver ... ... ... 308 25.2.2 ... ... 310 Initialization and Configuration functions .2.3 IO operation functions ... ... ... 311 25 Peripheral State and Errors functions ... ... 312 25.2.4 ... Detailed description of functions 312 ... 25.2.5 25.3 IRDA Firmware driver defines ... ... 320 25.3.1 IRDA ... ... ... 320 26 HAL IWDG Generic Driver ... ... 326 26.1 IWDG Firmware driver registers structures ... ... 326 ... ... ... IWDG_InitTypeDef 26.1.1 326 26.1.2 ... ... ... 326 IWDG_HandleTypeDef ... ... 26.2 326 IWDG Firmware driver API description 26.2.1 IWDG Generic features ... ... .. 326 26.2.2 How to use this driver ... ... ... 327 26.2.3 ... ... 327 Initialization and Start functions 26.2.4 IO operation functions ... ... ... 327 26.2.5 Detailed description of functions ... ... 327 26.3 IWDG Firmware driver defines ... ... 328 ... 26.3.1 IWDG ... ... 328 27 ... ... 330 HAL NAND Generic Driver ... ... 330 27.1 NAND Firmware driver registers structures NAND_IDTypeDef ... ... ... 330 27.1.1 NAND_AddressTypeDef ... ... 27.1.2 330 . 27.1.3 NAND_DeviceConfigTyp eDef ... ... 330 27.1.4 NAND_HandleTypeDef ... ... .. 331 NAND Firmware driver API description ... ... 3 31 27.2 27.2.1 How to use this driver ... ... ... 331 ... initialization functions - NAND Initialization and de 27.2.2 332 2 DocID027328 Rev 1166 9 /

10 Contents UM1850 27.2.3 ... ... 332 NAND Input and Output functions NAND Control functions . ... ... 333 27.2.4 NAND State functions ... ... ... 333 27.2.5 Detailed description of functions ... ... 333 27.2.6 27.3 mware driver defines ... ... 339 NAND Fir ... ... ... 339 27.3.1 NAND HAL NOR Generic Driver ... ... 28 340 28.1 NOR Firmware driver registers structures ... ... 340 28.1.1 NOR_IDTypeDef ... ... ... 340 28.1.2 ... ... ... 340 NOR_CFITypeDef ... ... ... 28.1.3 340 NOR_HandleTypeDef 28.2 NOR Firmware driver API description ... ... 341 28.2.1 How to use this driver ... ... ... 341 28.2.2 on and de_initialization functions ... 341 NOR Initializati 28.2.3 NOR Input and Output functions ... ... 342 28.2.4 NOR Control functions ... ... ... 342 28.2.5 NOR State functions ... ... ... 342 ... of functions Detailed description 28.2.6 342 ... 28.3 ... ... 346 NOR Firmware driver defines ... ... ... 346 28.3.1 NOR HAL PCCARD Generic Driver 29 ... 348 ... 29.1 PCCARD Firmware driver registers structures ... 348 29.1.1 PCCARD_HandleTypeDef ... ... 348 29.2 ... ... 348 PCCARD Firmware driver API description 29.2.1 How to use this driver ... ... ... 348 29.2.2 PCCARD Initialization and de - initialization functions ... 349 29.2.3 PCCARD Input Output and memory functions ... 349 29.2.4 PCCARD Peripheral State functions ... ... 349 29.2.5 ... ... 349 Detailed description of functions ... ... 353 29.3 PCCARD Firmware driver defines PCCARD ... ... 29.3.1 353 ... 30 HAL PCD Generic Driver ... ... 354 30.1 PCD Firmware driver registers structures ... ... 354 30.1.1 PCD_HandleTypeDef ... ... ... 354 30.2 PCD Firmware driver API description ... ... 354 30.2.1 How to use this driver ... ... ... 354 355 30.2.2 ... ... initialization functions - Initialization and de DocID027328 / 1166 10 Rev 2

11 UM1850 Contents 30.2.3 ... ... ... 355 IO operation functions Peripheral Control functions ... ... 355 30.2.4 ... ... 356 30.2.5 Peripheral State functions Detailed descr iption of functions ... ... 356 30.2.6 30.3 ... ... 362 PCD Firmware driver defines ... ... ... 362 30.3.1 PCD HAL PCD Extension Driver ... 31 364 ... 31.1 PCDEx Firmware driver API description ... ... 364 364 31.1.1 Extended Peripheral Control functions ... ... 31.1.2 Detailed description of functions ... ... 364 32 HAL PWR Ge neric Driver ... ... 365 32.1 PWR Firmware driver registers structures ... ... 365 ... 32.1.1 PWR_PVDTypeDef 365 ... ... 32.2 PWR Firmware driver API description ... ... 365 32.2.1 Initialization and de - initialization functions ... ... 365 32.2.2 Peripheral Control functions ... ... 365 367 32.2.3 Detailed description of fu nctions ... ... 32.3 371 ... ... PWR Firmware driver defines 32.3.1 ... ... ... 371 PWR HAL RCC Generic Driver ... ... 376 33 RCC Firmware driver registers structures ... ... 376 33.1 RCC_PLLInitTypeDef ... ... 33.1.1 376 ... 33.1.2 RCC_ClkInitTypeDef ... ... ... 376 33.2 RCC Firmware driver AP I description ... ... 377 RCC specific features ... ... ... 377 33.2.1 33.2.2 RCC Limitations ... ... ... 377 Initialization and de - 33.2.3 377 initialization functions ... ... 33.2.4 Peripheral Control functions ... ... 378 33.2.5 Detailed description of functions ... ... 378 ... 33.3 RCC Firm ware driver defines ... 383 ... 33.3.1 RCC 383 ... ... 34 HAL RCC Extension Driver ... ... 398 34.1 RCCEx Firmware drive r registers structures ... . 398 34.1.1 RCC_OscInitTypeDef ... ... ... 398 398 34.1.2 RCC_PeriphCLKInitTypeDef ... ... ... ... RCCEx Firmware driver API description 34.2 399 2 DocID027328 Rev 1166 11 /

12 Contents UM1850 34.2.1 nded Peripheral Control functions ... ... 399 Exte Detailed description of functions ... ... 399 34.2.2 ... ... 400 34.3 RCCEx Firmware driver defines RCCEx ... ... ... 400 34.3.1 35 ... ... 409 HAL RTC Generic Driver ... ... 409 35.1 RTC Firmware driver registers structures RTC_TimeTypeDef ... ... 35.1.1 409 ... 35.1.2 RTC_AlarmTypeDef ... ... 409 ... 409 RTC_InitTypeDef 35.1.3 ... ... ... ... 35.1.4 ... ... RTC_DateTypeDef 41 0 35.1.5 RTC_HandleTypeDef ... ... ... 410 35.2 RTC Firmware driver API description ... ... 410 ... 35.2.1 How to use this driver ... ... 410 ... 35.2.2 Restrictions WARNING: Drivers ... 411 35.2.3 Backup Domain Operating Condition ... ... 411 35.2.4 Backup Domain Reset ... ... ... 412 412 35.2.5 Backup Domain Access ... ... .. ... ... RTC and low power modes 35.2.6 412 ... 35.2.7 initialization functions ... - 412 Initialization and de RTC Time and Date functions ... ... 413 35.2.8 ... ... ... RTC Alarm functions 413 35.2.9 Peripheral State functions ... ... 413 35.2.10 35.2.11 Peripheral Control functions ... ... 413 35.2.12 Detailed description of functions ... ... 413 35.3 RTC Firmware driver defines ... ... 418 35.3.1 RTC ... ... ... 418 425 36 HAL RTC Extension Driver ... ... 36.1 ... . 425 RTCEx Firmware driver registers structures RTC_TamperTypeDef ... ... ... 425 36.1.1 RTCEx Firmware driver API description ... ... 425 36.2 36.2.1 RTC Tamper functions ... ... ... 425 RTC Second functio 36.2.2 ns ... ... ... 425 36.2.3 Extension Peripheral Control functions ... ... 425 36.2.4 Detailed description of functions ... ... 426 36.3 RTCEx Firmware driver defines ... ... 429 429 36.3.1 RTCEx ... ... ... 37 436 ... ... HAL SD Generic Driver DocID027328 / 1166 12 Rev 2

13 UM1850 Contents 37.1 ... ... 436 SD Firmware driver registers structures HAL_SD_CardInfoTypeDef ... ... 436 37.1.1 ... ... ... 436 37.1.2 SD_HandleTypeDef HAL_SD_CardCSDTypeDef ... ... 437 37.1.3 37.1.4 ... ... 439 HAL_SD_CardCIDTypeDef ... ... 440 37.1.5 HAL_SD_CardStatusTypeDef SD Firmware driver API description ... ... 37.2 441 37.2.1 How to use this driver ... ... 441 ... 37.2.2 444 Initialization and de - initialization functions ... ... 37.2.3 IO operation functions ... ... ... 444 37.2.4 Peripheral Control functions ... ... 444 ... 37.2.5 Detailed d escription of functions ... 445 37.3 SD Firmware driver defines ... ... 451 ... 37.3.1 ... ... SD ... 451 38 HAL SMARTCARD Generic Driver ... ... 459 38.1 SMARTCARD Firmware driver registers structures ... 459 459 38.1.1 SMARTCARD_InitTypeDef ... ... 38.1.2 460 ... ... SMARTCARD_HandleTypeDef 38.2 ... 461 SMARTCARD Firmware driver API description How to use this driver ... ... ... 461 38.2.1 Initialization a nd Configuration functions ... ... 463 38.2.2 ... ... ... IO operation functions 464 38.2.3 38.2.4 Peripheral State and Errors functions ... ... 465 38.2.5 Detailed description of functions ... ... 465 38.3 SMARTCAR D Firmware driver defines ... ... 472 38.3.1 SMARTCARD ... ... ... 472 39 HAL SPI Generic Driver ... ... 480 39.1 480 SPI Firmware driver registers structures ... ... 39.1.1 SPI_InitTypeDef ... ... ... 480 39.1.2 __SPI_HandleTypeDef ... ... ... 481 39.2 SPI Firmware driver API description ... ... 482 ... 39.2.1 How to use this driver 482 ... ... ... 39.2.2 - initialization functions Initialization and de ... 482 39.2.3 IO operation functions ... ... ... 483 39.2.4 Peripheral State and Errors functions ... ... 484 484 39.2.5 Detailed description of functions ... ... 491 ... ... SPI Firmware driver defines 39.3 2 DocID027328 Rev 1166 13 /

14 Contents UM1850 39.3.1 ... ... ... .. 491 SPI HAL SRAM Generic Driver ... ... 496 40 SRAM Firmware driver registers structures ... ... 496 40.1 SRAM_HandleTypeDef ... ... .. 496 40.1.1 40.2 SRAM Firmware driver API description ... ... 496 ... ... ... 496 40.2.1 How to use this driver ... 40.2.2 497 SRAM Initialization and de_initialization functions 40.2.3 SRAM Input and Output functions ... ... 497 40.2.4 SRAM Control functions ... ... . 497 40.2.5 ... ... ... 498 SRAM State functions iption of functions ... ... 498 40.2.6 Detailed descr SRAM Firmware driver defines ... ... 502 40.3 SRAM ... ... ... 502 40.3.1 41 HAL TIM Generic Driver ... ... 503 41.1 TIM Firmware driver registers structures ... ... 503 41.1.1 TIM_Base_InitTypeDef ... ... ... 503 41.1.2 TIM_OC_InitTypeDef ... ... ... 503 41.1.3 TIM_OnePulse_InitTyp eDef ... ... 504 505 ... ... ... TIM_IC_InitTypeDef 41.1.4 41.1.5 ... ... 505 TIM_Encoder_InitTypeDef ... ... 506 41.1.6 TIM_ClockConfigTypeDef TIM_ClearInputConfigTypeDef ... ... 506 41.1.7 TIM_SlaveConfigTypeDef ... 41.1.8 507 ... 41.1.9 TIM_HandleTypeDef ... ... ... 507 41.2 TIM Firmware driver API description ... ... 508 TIMER Generic features ... ... . 508 41.2.1 41.2.2 How to use this driver ... ... ... 508 509 41.2.3 Time Base functions ... ... ... 41.2.4 ... ... 509 Time Output Compare functions 41.2.5 Time PWM functions ... ... ... 510 41.2.6 Time Input Capture functions ... ... 510 41.2.7 Time One Pulse functions ... ... 511 41.2.8 Time Encoder functions ... ... .. 511 41.2.9 IRQ handler management ... ... 512 41.2.10 Peripheral Control functions ... ... 512 ... 41.2.11 TIM Callb acks functions ... . 512 512 41.2.12 Peripheral State functions ... ... 41.2.13 513 ... ... Detailed description of functions DocID027328 / 1166 14 Rev 2

15 UM1850 Contents 41.3 ... ... 537 TIM Firmware driver defines TIM .. ... ... ... 537 41.3.1 HAL TIM Extension Driver ... ... 556 42 TIMEx Firmware driver registers structures ... ... 556 42.1 42.1.1 ... ... 556 TIM_HallSensor_InitTypeDef ... ... 556 42.1.2 TIM_BreakDeadTimeConfigTypeDef TIM_Mast erConfigTypeDef ... 42.1.3 557 ... 42.2 TIMEx Firmware driver API description ... ... 557 557 42.2.1 TIMER Extended features ... ... 42.2.2 How to use this driver ... ... ... 557 42.2.3 Timer Hall Senso r functions ... ... 558 42.2.4 Timer Complementary Output Compare functions ... 558 Timer Complementary PWM functions 42.2.5 ... ... 559 42.2.6 Timer Complementary One Pulse functions ... ... 559 42.2.7 Peripheral Control functions ... ... 559 42.2.8 Extension Callbacks functions ... ... 560 560 42.2.9 Exte nsion Peripheral State functions ... ... ... ... Detailed description of functions 42.2.10 560 42.3 ... ... 570 TIMEx Firmware driver defines TIMEx ... ... ... 570 42.3.1 HAL UART Generic Driver ... ... 43 571 UART Firmware driver registers structures ... ... 571 43.1 UART_InitTypeDef ... ... ... 571 43.1.1 ... ... ... 571 UART_HandleTypeDef 43.1.2 UART Firmware driver API description ... ... 572 43.2 How to use this driver ... ... ... 572 43.2.1 43.2.2 Initialization and Configuration functions ... ... 574 43.2.3 ... ... ... 575 IO operation functions ... ... 43.2.4 576 Peripheral Control functions 43.2.5 Periph eral State and Errors functions ... ... 577 43.2.6 Detailed description of functions ... ... 577 43.3 UART Firmware driver defines ... ... 587 43.3.1 UART ... ... ... 587 44 HAL USART Generic Driver ... ... 596 596 44.1 USART Firmware driver registers structures ... . 44.1.1 596 ... ... ... USART_InitTypeDef 2 DocID027328 Rev 1166 15 /

16 Contents UM1850 44.1.2 ... ... 596 USART_HandleTypeDef USART Firmware driver API description ... ... 597 44.2 ... ... ... 597 44.2.1 How to use this driver Initialization and Configuration functions ... ... 599 44.2.2 44.2.3 ... ... ... 600 IO operation functions ... ... 601 44.2.4 Peripheral State and Errors functions Detailed description of functions ... 44.2.5 601 ... 44.3 USART Firmware driver defines ... ... 609 44.3.1 USART ... ... ... 609 45 ... ... 615 HAL WWDG Generic Driver WWDG Firmware driver registers structures ... . 615 45.1 ... ... ... WWDG_InitTypeDef 615 45.1.1 ... WWDG_HandleTypeDef ... 615 45.1.2 45.2 WWDG Firmware driver A PI description ... ... 615 45.2.1 WWDG specific features ... ... 615 45.2.2 How to use this driver ... ... ... 616 45.2.3 Initialization and Configuration functions ... ... 616 45.2.4 617 ... ... ... IO operation functions 45.2.5 ... ... 617 Detailed description of functions WWDG Firmware driver defines ... ... 618 45.3 WWDG ... ... ... 45.3.1 618 LL ADC Generic Driver ... ... 621 46 ADC Firmware driver regi sters structures ... ... 621 46.1 ... ... 621 LL_ADC_CommonInitTypeDef 46.1.1 LL_ADC_InitTypeDef ... ... ... 621 46.1.2 LL_ADC_REG_InitTypeDef ... ... 621 46.1.3 46.1.4 LL_ADC_INJ_InitT ypeDef ... ... 622 46.2 ... ... 623 ADC Firmware driver API description ... ... 46.2.1 623 Detailed description of functions 46.3 ADC Firmware driver defines ... ... 669 46.3.1 ADC ... ... ... 669 47 LL BUS Generic Driver ... ... 697 47.1 BUS Firmware driver API description ... ... 6 97 47.1.1 Detailed description of functions ... ... 697 709 47.2 BUS Firmware driver defines ... ... BUS 47.2.1 709 ... ... ... DocID027328 / 1166 16 Rev 2

17 UM1850 Contents 48 ... ... 712 LL CORTEX Generic Driver CORTEX Firmware driver API description ... ... 712 48.1 ... ... 712 48.1.1 Detailed description of functions CORTEX F irmware driver defines ... 48.2 719 ... 48.2.1 CORTEX ... ... ... 719 ... 49 ... 722 LL CRC Generic Driver 49.1 CRC Firmware driver API description ... ... 722 ... 49.1.1 Detail ed description of functions ... 722 49.2 ... ... 723 CRC Firmware driver defines CRC ... ... ... 723 49.2.1 LL DAC Generic Driver ... ... 725 50 ... DAC Firmware driver registers structures ... 725 50.1 50.1.1 LL_DAC_InitTypeDef ... ... ... 725 50.2 DAC Firmware driver API description ... ... 725 50.2.1 Detailed description of functions ... ... 725 50.3 DAC Firmware driver defines ... ... 739 50.3.1 739 ... ... ... DAC 51 ... ... 745 LL DMA Generic Driver DMA Firmware driver registers structures ... ... 745 51.1 ... ... ... LL_DMA_InitTypeDef 745 51.1.1 ... DMA Firmware driver AP I description ... 746 51.2 51.2.1 Detailed description of functions ... ... 746 51.3 DMA Firmware driver defines ... ... 779 51.3.1 DMA ... ... ... 779 52 LL EXTI Generic Driver ... ... 783 ... 52.1 EXTI Firmware driver registers structures 783 ... 52.1.1 LL_EXTI_InitTypeDef ... ... ... 783 52.2 EXTI Firmware driver API description ... ... 783 ... 52.2.1 Deta iled description of functions ... 783 52.3 EXTI Firmware driver defines 796 ... ... 52.3.1 EXTI ... ... ... 796 53 LL GPIO Generic Driver ... ... 798 53.1 GPIO Firmware driver registers structures ... ... 798 798 53.1.1 LL_GPIO_InitTypeDef ... ... ... GPIO Firmware driver API description 53.2 798 ... ... 2 DocID027328 Rev 1166 17 /

18 Contents UM1850 53.2.1 ... ... 798 Detailed description of functions GPIO Firmware driver defines ... ... 831 53.3 ... ... ... 831 53.3.1 GPIO LL I2C Generic Driver ... ... 54 835 .. 54.1 I2C Firmware driver registers structures ... ... 835 ... ... ... 54.1.1 835 LL_I2C_InitTypeDef 54.2 I2C Firmware driver AP I description ... ... 835 54.2.1 Detailed description of functions ... ... 835 54.3 ... ... 866 I2C Firmware driver defines .. ... ... ... 54.3.1 866 I2C LL I2S Generic Driver ... ... .. 871 55 55.1 I2S Firmware driver registers structures ... ... 871 55.1.1 ... ... ... 871 LL_I2S_InitTypeDef I2S Firmware driver API description ... ... 871 55.2 55.2.1 Detailed description of functions ... ... 871 55.3 I2S Firm ware driver defines ... ... 885 55.3.1 885 .. ... ... ... I2S 56 ... ... 887 LL IWDG Generic Driver ... ... 887 56.1 IWDG Firmware driver API description Detailed description of functions ... ... 887 56.1.1 IWDG Firmware driver defines ... 56.2 890 ... 56.2.1 IWDG ... ... ... 890 57 LL PWR Generic Driver ... ... 892 PWR Firmware driver API description ... ... 892 57.1 57.1.1 Detail ed description of functions ... ... 892 ... 57.2 PWR Firmware driver defines 897 ... 57.2.1 PWR ... ... ... 897 58 LL RCC Generic Driver ... ... 899 ... 58.1 RCC Firmware driver regi sters structures ... 899 58.1.1 LL_RCC_ClocksTypeDef 899 ... ... 58.2 RCC Firmware driver API description ... ... 899 58.2.1 Detailed description of functions ... ... 899 58.3 RCC Firm ware driver defines ... ... 921 921 58.3.1 RCC ... ... ... LL RTC Generic Driver 59 927 ... ... DocID027328 / 1166 18 Rev 2

19 UM1850 Contents 59.1 ... ... 927 RTC Firmware driver registers structures LL_RTC_InitTypeDef ... ... ... 927 59.1.1 LL_RTC_TimeTypeDef ... ... ... 927 59.1.2 LL_RTC_AlarmTypeDef ... 59.1.3 . 927 ... 59.2 RTC Firmware driver API description ... ... 928 ... ed description of functions 59.2.1 ... 928 Detail RTC Firmware driver defines ... ... 944 59.3 944 59.3.1 RTC ... ... ... 60 LL SPI Generic Driver ... ... .. 947 60.1 SPI Firmware driver registers structures ... ... 947 ... 60.1.1 LL_SPI_InitTypeDef ... ... 947 ... 60.2 SPI Firmware driver API description 94 ... 8 60.2.1 Detailed description of functions ... ... 948 60.3 SPI Firmware driver defines ... ... 965 ... 60.3.1 SPI ... ... .. 965 967 61 LL SYSTEM Generic Driver ... ... 967 ... ... SYSTEM Firmware driver API description 61.1 61.1.1 ... ... 967 Detailed description of functions SYSTEM F ... ... 975 irmware driver defines 61.2 SYSTEM ... ... ... 61.2.1 975 ... ... LL TIM Generic Driver 977 62 . TIM Firmware driver registers structures ... ... 977 62.1 ... ... ... 977 LL_TIM_InitTypeDef 62.1.1 LL_TIM_OC_InitTypeDef ... ... 977 62.1.2 . ... ... LL_TIM_IC_InitTypeDef 978 62.1.3 LL_TIM_ENCODER_InitTypeDef ... ... 62.1.4 979 62.1.5 ENSOR_InitTypeDef ... ... 980 LL_TIM_HALLS ... ... 62.1.6 980 LL_TIM_BDTR_InitTypeDef 62.2 TIM Firmware driver API description ... ... 981 62.2.1 Detailed description of functions ... ... 981 62.3 TIM Firmware driver defines ... ... 1043 62.3.1 TIM ... ... ... 1043 63 LL USART Generic Driver ... ... 1054 63.1 USART Firmware driver registers structures ... 1054 1054 63.1.1 LL_USART_InitTypeDef ... ... TypeDef LL_USART_ClockInit 63.1.2 1054 ... ... 2 DocID027328 Rev 1166 19 /

20 Contents UM1850 63.2 ... ... 1055 USART Firmware driver API description Detailed description of functions ... ... 1055 63.2.1 ... ... 1099 63.3 USART Firmware driver defines USART ... ... ... 1099 63.3.1 64 ... ... 1103 LL UTILS Generic Driver ... . 1103 64.1 UTILS Firmware driver registers structures LL_UTILS_PLLInitTypeDef ... 64.1.1 1103 ... 64.1.2 LL_UTILS_ClkInitTypeDef ... ... 1103 1103 64.2 UTILS Firmware dri ver API description ... ... 64.2.1 System Configuration functions ... ... 1103 64.2.2 Detailed description of functions ... ... 1104 64.3 UTILS Firmware driver defines ... ... 1106 ... 64.3.1 UTILS 1106 ... ... 65 LL WWDG Generic Driver ... ... 1108 65.1 WWDG Firmware driver API description ... ... 1108 65.1.1 Detailed description of functions ... ... 1108 1112 65.2 WWDG Fir mware driver defines ... ... ... ... ... WWDG 65.2.1 1112 66 - layer driver Correspondence between API registers and API low ... ... 1113 functions ... ADC ... ... ... 66.1 1113 66.2 BUS ... ... 1117 ... 66.3 CORTEX ... ... ... 1125 66.4 CRC ... ... ... 1126 66.5 DAC ... ... ... 1126 ... 66.6 DMA ... ... 1128 EXTI 66.7 ... ... ... 1131 66.8 ... ... ... 1131 GPIO I2C ... ... ... 1132 66.9 ... ... ... I2S 1136 66.10 66.11 IWDG ... ... ... 1137 66.12 PWR ... ... ... 1138 RCC ... ... ... 1138 66.13 66.14 RTC ... ... ... 1141 ... ... ... SPI 66.15 1142 DocID027328 / 1166 20 Rev 2

21 UM1850 Contents 66.16 SYSTEM ... ... ... 1144 66.17 TIM ... ... ... 1146 1155 ... ... ... USART 66.18 ... 66.19 WWDG ... ... 1160 67 1161 ... ... ... FAQs Revision history 68 ... ... 1165 ... 2 DocID027328 Rev 1166 21 /

22 List of tables UM1850 List of tables ... ... ... Table 1: Acronyms and definitions 24 ... ... ... ... ... Table 2: HAL driver files 26 Table 3: User application f iles ... - ... ... 27 ... Table 4: API classification ... ... ... ... 32 Table 5: List of devices supported by HAL drivers ... ... ... 33 Table 6: HAL API naming rules ... ... ... ... 38 Table 7: Macros handling interrupts and specific clock configurations ... ... 39 Table 8: Callback functions ... ... ... ... 40 1 4 Table 9: HAL generic APIs ... ... ... ... Table 10: HAL extension APIs ... ... 42 ... ... ... ... ... 47 Table 11: Define statements used for HAL configuration ... ... ... 49 Table 12: Description of GPIO_InitTypeDef structure Table 13: Description of EXTI configuration macros ... ... ... 51 Table 14: MSP functions ... ... ... ... 55 Table 15: Timeout values ... ... ... ... 59 Table 16: LL driver files ... ... ... 63 ... Table 17: Common peripheral initialization functions ... ... ... 66 Table 18: Optio nal peripheral initialization functions ... ... ... 67 Table 19: Specific Interrupt, DMA request and status flags management ... ... 69 ... 69 Table 20: Available function formats ... ... ... 69 ... ... Table 21: Peripheral clock activation/deactivation management Table 22: Peripheral activati on/deactivation management ... ... ... 70 ... ... ... 70 Table 23: Peripheral configuration management Table 24: Peripheral register management ... ... ... 70 Table 25: Correspondence between ADC registers and ADC low - layer driver functions ... 1113 ... Table 26: Correspondence between BUS registers and BUS low - layer driver functions 1117 Table 27: Corre - layer driver functions ... 1125 spondence between CORTEX registers and CORTEX low Table 28: Correspondence between CRC registers and CRC low - layer driver functions ... 1126 Table 29: Correspondence between DAC registers and DAC low layer driver functions ... 1126 - - layer driver functions ... 1128 Table 30: Correspondence between DMA registers and DMA low 1131 Table 31: Correspondence between EXTI registers and EXTI low - layer driver functions ... layer driver functions 1131 ... - Table 32: Correspondence between GPIO registers and GPIO low Table 33: Correspondence between I2C registers and I2C low - ... 1132 layer driver functions s and I2S low layer driver functions ... 1136 Table 34: Correspondence between I2S register - - layer driver functions ... 1137 Table 35: Correspondence between IWDG registers and IWDG low - layer driver functions ... 1138 Table 36: Correspondence between PWR registers and PWR low ... - layer driver functions 1138 Table 37: Correspondence between RCC registers and RCC low Table 38: Correspondence between RTC registers and RTC low - ... 1141 layer driver functions Table 39: Correspondence between SPI registers and SPI low layer driver functions ... 1142 - Table 40: Correspondence between SYSTEM registers and SYSTEM low - layer driver functions ... 1144 Table 41: Correspondence between TIM registers and TIM low - layer driver functions ... 1146 1155 Table 42: Correspondence between USART registers and USART low - layer driver functions ... ... layer driver functions - isters and WWDG low Table 43: Correspondence between WWDG reg 1160 1165 ... ... ... ... Table 44: Document revision history DocID027328 / 1166 22 Rev 2

23 UM1850 figures List of List of figures 29 Figure 1: Example of project template ... ... ... ... 43 Figure 2: Adding device - specific functions ... ... ... 43 Figure 3: Adding family - specific functions ... ... ... ... ... ... Figure 4: Adding new peripherals 44 ... ... 44 Figur e 5: Updating existing APIs ... ... ... ... ... ... ... Figure 6: File inclusion model 45 ... Figure 7: HAL driver model ... ... ... 53 64 ... ... Figure 8: Low Layer driver ... ... folders 65 ... ... ... ... Figure 9: Low Layer driver CMSIS files 2 DocID027328 Rev 1166 23 /

24 Acronyms and definitions UM1850 1 Acronyms and definitions Table 1: Acronyms and definitions Definition Acronym Analog ADC - to - digital converter American National Standards Institute ANSI API Application Programming Interface BSP Board Support Package CAN Controller area network Consumer electronic controller CEC Cortex Microcontroller Software Interface Standard CMSIS Central Processing Unit CPU CRC CRC calculation unit DAC Digital to analog converter Direct Memory Access DMA Ethernet controller ETH External interrupt/event controller EXTI Flash memory FLASH GPIO General purpose I/Os HAL Hardware abstraction layer HCD USB Host Controller Driver I2C Inter - integrated circuit I2S Inter - integrated sound IRDA InfraRed Data Association IWDG Independent watchdog LCD Liquid Crystal Display Controler MSP MCU Specific Package NAND NAND Flash memory NOR Nor Flash memory Nested Vectored Interrupt Controller NVIC PCD USB Peripheral Controller Driver PWR Power controller RCC Reset and clock controller time clock Real - RTC Secure Digital SD SRAM external memory SRAM Smartcard IC SMARTCARD Serial Peripheral interface SPI DocID027328 / 1166 24 Rev 2

25 UM1850 Acronyms and definitions Acronym Definition SysTick System tick timer purpose or basic timer - control, general - Advanced TIM UART Universal asynchronous receiver/transmitter USART Universal synchronous receiver/transmitter WWDG Window watchdog Universal Serial Bus USB STM32 peripheral or block PPP 2 DocID027328 Rev 1166 25 /

26 Overview of HAL UM1850 drivers Overview of HAL drivers 2 The HAL drivers were designed to offer a rich set of APIs and to interact easily with the application upper layers. sts of a set of functions covering the most common peripheral features. Each driver consi The development of each driver is driven by a common API which standardizes the driver structure, the functions and the parameter names. The HAL drivers include a set of driver module s, each module being linked to a standalone peripheral. However, in some cases, the module is linked to a peripheral functional mode. As an example, several modules exist for the USART peripheral: UART driver module, USART driver module, SMARTCARD driver m odule and IRDA driver module. The HAL main features are the following: family portable set of APIs covering the common peripheral features as well as Cross - extension APIs in case of specific peripheral features. Three API programming models: polling, interrupt and DMA. APIs are RTOS compliant: Fully reentrant APIs Systematic usage of timeouts in polling mode. Support of peripheral multi instance allowing concurrent API calls for multiple - instances of a given peripheral (USART1, USART2...) callback functions mechanism: - All HAL APIs implement user - callback functions to perform Peripheral Init/DeInit HAL APIs can call user peripheral system level Initialization/De - Initialization (clock, GPIOs, interrupt, DMA) Peripherals interrupt events Er ror events. Object locking mechanism: safe hardware access to prevent multiple spurious accesses to shared resources. Timeout used for all blocking processes: the timeout can be a simple counter or a timebase. HAL and user application files - 2.1 2.1.1 HAL driver files A HAL drivers are composed of the following set of files: Table 2: HAL driver files File Description Main peripheral/module driver file. stm32f1xx_hal_ppp.c It includes the APIs that are common to all STM32 devices. Example: stm32f1xx_hal_adc.c, stm32f1xx_hal_irda.c, ... Header file of the main driver C file It includes common data, handle and enumeration structures, stm32f1 xx_hal_ppp.h macros, as well as the exported generic define statements and APIs. xx_hal_adc.h, stm32f1 Example: xx_hal_irda.h, ... stm32f1 DocID027328 / 1166 26 Rev 2

27 UM1850 drivers Ove rview of HAL File Description Extension file of a peripheral/module driver. It includes the specific APIs for a given part number or family, as well as the newly defined APIs that overwrite the default generic APIs if the internal stm32f1 xx_hal_ppp_ex.c process is implemented in different way. stm32f1 Example: xx_hal_dma_ex.c, ... stm32f1 xx_hal_adc_ex.c, Header file of the extension C file. ic data and enumeration structures, define It includes the specif stm32f1 xx_hal_ppp_ex.h statements and macros, as well as the exported device part number specific APIs stm32f1 xx_hal_dma_ex.h, ... stm32f1 Example: xx_hal_adc_ex.h, GMCU, This file is used for HAL initialization and contains DB stm32f1 xx_hal.c ick APIs. Remap and Time Delay based on SysT stm32f1 xx_hal.h xx_hal.c header file Template file to be copied to the user application folder. xx_hal_msp_template.c stm32f1 It contains the MSP initialization and de initialization (main routine - and callbacks) of the peripheral used in the user application. Template file allowing to customize the drivers for a given stm32f1 xx_hal_conf_template.h application. Common HAL resources such as common define statements, stm32f1 xx_hal_d ef.h enumerations, structures and macros. 2.1.2 User - application files The minimum files required to build an application using the HAL are listed in the table below: application files - Tabl e 3: User File Description This file contains SystemInit() which is called at startup just after reset and before branching to the main program. It does not configure the system clock at startup (contrary to the standard library). This is to be done using system_stm32f1xx.c the HAL APIs in the user fi les. It allows to relocate the vector table in internal SRAM. Toolchain specific file that contains reset handler and exception vectors. startup_stm32f1xx.s For some toolchains, it allows adapting the stack/heap size to fit the application requirements. stm32f1xx_flash.icf Linker file for EWARM toolchain allowing mainly to adapt the stack/heap (optional) size to fit the application requirements. - initialization (main routine This file contains the MSP initialization and de stm32f1xx_hal_msp.c and callbac ks) of the peripheral used in the user application. This file allows the user to customize the HAL drivers for a specific application. stm32f1xx_hal_conf.h It is not mandatory to modify this configuration. The application can use the default configuration without any modification. 2 DocID027328 Rev 1166 27 /

28 Overview of HAL UM1850 drivers Description File This file contains the exceptions handler and peripherals interrupt service routine, and calls HAL_IncTick() at regular time intervals to increment a local variable (declared in stm32f1x ebase. By x_hal.c) used as HAL tim stm32f1xx_it.c/.h default, this function is called each 1ms in Systick ISR. . The PPP_IRQHandler() routine must call HAL_PPP_IRQHandler() if an interrupt based process is used within the application. This file contains the main program routine, mainly: the call to HAL_Init() assert_failed() implementation main.c/.h system clock configuration peripheral HAL initialization and user application code. to - use project templates, one for each - The STM32Cube package comes with ready supported board. Each project contain s the files listed above and a preconfigured project for the supported toolchains. Each project template provides empty main loop function and can be used as a starting e point to get familiar with project settings for STM32Cube. Their characteristics are th following: It contains the sources of HAL, CMSIS and BSP drivers which are the minimal components to develop a code on a given board. It contains the include paths for all the firmware components. It defines the STM32 device supported, and allows configuring the CMSIS and HAL drivers accordingly. It provides ready to use user files preconfigured as defined below: HAL is initialized SysTick ISR implemented for HAL_Delay() System clock configured with the maximum frequency of the device If an existing project is copied to another location, then include paths must be updated. DocID027328 / 1166 28 Rev 2

29 UM1850 drivers Overview of HAL : Example of project template 1 Figure 2.2 HAL data structures Each HAL driver can contain the following data structures: Peripheral handle structures Initialization and configuration structures Specific process structures. Peripheral handle structures 2.2.1 instance architecture that allows working with - The APIs have a modular generic multi several IP instances simultaneously. is the main structure that is implemented in the HAL PPP_HandleTypeDef *handle t handles the peripheral/module configuration and registers and embeds all the drivers. I structures and variables needed to follow the peripheral device flow. The peripheral handle is used for the following purposes: instance has its own handle. As a Multi instance support: each peripheral/module result instance resources are independent. Peripheral process intercommunication: the handle is used to manage shared data resources between the process routines. Example: global pointers, DMA handles, state machine. St orage : this handle is used also to manage global variables within a given HAL driver. An example of peripheral structure is shown below: typedef struct { USART_TypeDef *Instance; /* USART registers base address */ USART_InitTypeDef Init; /* Usart commun ication parameters */ uint8_t *pTxBuffPtr;/* Pointer to Usart Tx transfer Buffer */ uint16_t TxXferSize; /* Usart Tx Transfer size */ __IO uint16_t TxXferCount;/* Usart Tx Transfer Counter */ 2 DocID027328 Rev 1166 29 /

30 Overview of HAL UM1850 drivers uint8_t *pRxBuffPtr;/* Pointer to Usart Rx transfer Buffer */ ui nt16_t RxXferSize; /* Usart Rx Transfer size */ __IO uint16_t RxXferCount; /* Usart Rx Transfer Counter */ DMA_HandleTypeDef *hdmatx; /* Usart Tx DMA Handle parameters */ DMA_HandleTypeDef *hdmarx; /* Usart Rx DMA Handle parameters */ HAL_LockTypeDef Lock; /* Locking object */ __IO HAL_USART_StateTypeDef State; /* Usart communication state */ __IO HAL_USART_ErrorTypeDef ErrorCode;/* USART Error code */ }USART_HandleTypeDef; re 1) The multi - instance feature implies that all the APIs used in the application a re entrant and avoid using global variables because subroutines can fail to be re - - entrant if they rely on a global variable to remain unchanged but that variable is modified when the subroutine is recursively invoked. For this reason, the following rule s are respected: entrant code does not hold any static (or global) non - constant data: re - Re - entrant functions can work with global data. For example, a re entrant - interrupt service routine can grab a piece of hardware status to work with read buffer) which is not only global, but volatile. Still, typical (e.g. serial port use of static variables and global data is not advised, in the sense that only - modify - atomic read write instructions should be used in these variables. It should not be possible for an in terrupt or signal to occur during the execution of such an instruction. Reentrant code does not modify its own code. 2) When a peripheral can manage several processes simultaneously using the process is added in the DMA (full duplex case), the DMA interface handle for each PPP_HandleTypeDef. 3) For the shared and system peripherals, no handle or instance object is used. The peripherals concerned by this exception are the following: GPIO SYSTICK NVIC PWR RCC FLASH. configuration structure 2.2.2 Initialization and These structures are defined in the generic driver header file when it is common to all part numbers. When they can change from one part number to another, the structures are extension header file for each part number. defined in the typedef struct { This member configures the UART communication baudrate.*/ uint32_t BaudRate; /*!< uint32_t WordLength; /*!< Specifies the number of data bits transmitted or received in a frame.*/ its; /*!< Specifies the number of stop bits transmitted.*/ uint32_t StopB uint32_t Parity; /*!< Specifies the parity mode. */ uint32_t Mode; /*!< Specifies wether the Receive or Transmit mode is enabled or disabled.*/ e flow control mode is enabled uint32_t HwFlowCtl; /*!< Specifies wether the hardwar or disabled.*/ DocID027328 / 1166 30 Rev 2

31 UM1850 drivers Overview of HAL uint32_t OverSampling; /*!< Specifies wether the Over sampling 8 is enabled or disabled, to achieve higher speed (up to fPCLK/8).*/ }UART_InitTypeDef; es or sub modul - The config structure is used to initialize the sub instances. See - below example: HAL_ADC_ConfigChannel (ADC_HandleTypeDef* hadc, ADC_ChannelConfTypeDef* sConfig) 2.2.3 Specific process structures The specific process structures are used for specific process (common APIs). They are defined in the generic driver header file. Example: HAL_PPP_Process (PPP_HandleTypeDef* hadc,PPP_ProcessConfig* sConfig) 2.3 API classification The HAL APIs are classified into three categories: common generic APIs applying to all STM32 devices. These APIs are Generic APIs: consequently present in the generic HAL driver files of all STM32 microcontrollers. t(ADC_HandleTypeDef* hadc); HAL_StatusTypeDef HAL_ADC_Ini HAL_StatusTypeDef HAL_ADC_DeInit(ADC_HandleTypeDef *hadc); HAL_StatusTypeDef HAL_ADC_Start(ADC_HandleTypeDef* hadc); HAL_StatusTypeDef HAL_ADC_Stop(ADC_HandleTypeDef* hadc); hadc); HAL_StatusTypeDef HAL_ADC_Start_IT(ADC_HandleTypeDef* HAL_StatusTypeDef HAL_ADC_Stop_IT(ADC_HandleTypeDef* hadc); void HAL_ADC_IRQHandler(ADC_HandleTypeDef* hadc); categories : - This set of API is divided into two sub Extension APIs: : APIs applying to a given family. They are locate d in the Family specific APIs extension HAL driver file (see example below related to the ADC). HAL_StatusTypeDef HAL_ADCEx_Calibration_Start(ADC_HandleTypeDef* hadc, uint32_t SingleDiff); uint32_t HAL_ADCEx_Calibration_GetValue(ADC_HandleTypeDef* hadc, uint32_t SingleDiff); Device part number specific APIs: These APIs are implemented in the extension file and delimited by specific define statements relative to a given part number. #if defined (STM32F101xG) || defined (STM32F103x6)|| defined (STM32F103xB) || xC) || defined (STM32F107xC) || defined (STM32F103xE) || defined defined (STM32F105 (STM32F103xG) /* ADC multimode */ HAL_StatusTypeDef HAL_ADCEx_MultiModeStart_DMA(ADC_HandleTypeDef *hadc, uint32_t *pData, uint32_tLength); andleTypeDef *hadc); HAL_StatusTypeDef HAL_ADCEx_MultiModeStop_DMA(ADC_H #endif /* STM32F101xG || defined STM32F103x6 || defined STM32F103xB || defined STM32F105xC || defined STM32F107xC || defined STM32F103xE || defined STM32F103xG */ The data structure related to the specific APIs is delimited by the device part number define statement. It is located in the corresponding extension header C file. 2 DocID027328 Rev 1166 31 /

32 Overview of HAL UM1850 drivers he The following table summarizes the location of the different categories of HAL APIs in t driver files. Table 4: API classification Generic file Extension file (1) Common APIs X X Family specific APIs X Device specific APIs X Notes: (1) In some cases, the implementation for a specific device part number may change . In this case the generic API is declared as weak function in the extension file. The API is implemented again to overwrite the default function Family specific APIs are only related to a given family. This means that if a specific API is implemented in another family, and the arguments of this latter family are different, additional structures and arguments might need to be added. ndlers are used for common and family specific processes. The IRQ ha Devices supported by HAL drivers 2.4 DocID027328 / 1166 32 Rev 2

33 UM1850 Overview of HAL drivers Table 5: List of devices supported by HAL drivers VALUE ACCESS USB PERFORMANCE OTG Ethernet Files STM32F1 STM32F1 STM32F1 STM32F1 STM32F1 STM32F1 STM32F1 STM32F1 STM32F1 STM32F1 STM32F1 STM32F1 STM32F1 STM32F1 01xE 02x6 02xB 01xB 03x6 03xB 01x6 03xE 00xE 03xG 05xC 00xB 07xC 01xG Yes stm32f1xx_hal.h stm32f1xx_hal.c Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes stm32f1xx_hal_adc.c Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes stm32f1xx_hal_adc.h stm32f1xx_hal_adc_ex.c Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes stm32f1xx_hal_adc_ex.h stm32f1xx_hal_can.c Yes No No No No No No No No Yes Yes Yes Yes Yes stm32f1xx_hal_can.h stm32f1xx_hal_cec.c No Yes Yes No No No No No No No No No No No stm32f1xx_hal_cec.h stm32f1xx_hal_cortex.c Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes stm32f1xx_hal_cortex.h stm32f1xx_hal_crc.c Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes stm32f1xx_hal_crc.h stm32f1xx_hal_dac.c Yes Yes Yes No No Yes Yes No No No No Yes Yes Yes stm32f1xx_hal_dac.h stm32f1xx_hal_dac_ex.c Yes Yes Yes No No Yes Yes No No No No Yes Yes Yes stm32f1xx_hal_dac_ex.h stm32f1xx_hal_dma.c Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes stm32f1xx_hal_dma.h stm32f1xx_hal_dma_ex.h Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes stm32f1xx_hal_eth.c No Yes No No No No No No No No No No No No stm32f1xx_hal_eth.h stm32f1xx_hal_flash.c Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes stm32f1xx_hal_flash.h stm32f1xx_hal_flash_ex.c Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes stm32f1xx_hal_flash_ex.h 2 / 33 DocID027328 1166 Rev

34 Overview of HAL drivers UM1850 PERFORMANCE ACCESS USB VALUE OTG Ethernet Files STM32F1 STM32F1 STM32F1 STM32F1 STM32F1 STM32F1 STM32F1 STM32F1 STM32F1 STM32F1 STM32F1 STM32F1 STM32F1 STM32F1 03xB 01xE 02x6 02xB 01xB 03x6 01x6 03xE 00xE 03xG 05xC 00xB 07xC 01xG stm32f1xx_hal_gpio.c Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes stm32f1xx_hal_gpio.h stm32f1xx_hal_gpio_ex.c Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes stm32f1xx_hal_gpio_ex.h stm32f1xx_hal_hcd.c No No No No No No No No No No No No Yes Yes stm32f1xx_hal_hcd.h stm32f1xx_hal_i2c.c Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes stm32f1xx_hal_i2c.h stm32f1xx_hal_i2s.c Yes No No No No No No No No No No Yes Yes Yes stm32f1xx_hal_i2s.h stm32f1xx_hal_irda.c Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes stm32f1xx_hal_irda.h stm32f1xx_hal_iwdg.c Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes stm32f1xx_hal_iwdg.h stm32f1xx_hal_msp_template.c NA NA NA NA NA NA NA NA NA NA NA NA NA NA stm32f1xx_hal_nand.c No No No No Yes Yes No No No No No Yes Yes No stm32f1xx_hal_nand.h stm32f1xx_hal_nor.c Yes Yes No No No No No Yes No No Yes Yes No No stm32f1xx_hal_nor.h stm32f1xx_hal_pccard.c No No No No No Yes Yes No No No No Yes Yes No stm32f1xx_hal_pccard.h stm32f1xx_hal_pcd.c Yes Yes Yes Yes Yes Yes No No No No No No Yes Yes stm32f1xx_hal_pcd.h stm32f1xx_hal_pcd_ex.c Yes Yes Yes Yes Yes Yes No No No No No No Yes Yes stm32f1xx_hal_pcd_ex.h Yes Yes Yes Yes Yes Yes stm32f1xx_hal_pwr.c Yes Yes Yes Yes Yes Yes Yes Yes DocID027328 2 Rev 34 1166 /

35 UM1850 Overview of HAL drivers PERFORMANCE ACCESS USB VALUE OTG Ethernet Files STM32F1 STM32F1 STM32F1 STM32F1 STM32F1 STM32F1 STM32F1 STM32F1 STM32F1 STM32F1 STM32F1 STM32F1 STM32F1 STM32F1 03xB 01xE 02x6 02xB 01xB 03x6 01x6 03xE 00xE 03xG 05xC 00xB 07xC 01xG stm32f1xx_hal_rcc.c Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes stm32f1xx_hal_rcc.h stm32f1xx_hal_rcc_ex.c Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes stm32f1xx_hal_rcc_ex.h stm32f1xx_hal_rtc.c Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes stm32f1xx_hal_rtc.h stm32f1xx_hal_rtc_ex.c Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes stm32f1xx_hal_rtc_ex.h stm32f1xx_hal_sd.c No No No No No No No No No No No Yes Yes No stm32f1xx_hal_sd.h stm32f1xx_hal_smartcard.c Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes stm32f1xx_hal_smartcard.h stm32f1xx_hal_spi.c Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes stm32f1xx_hal_spi.h stm32f1xx_hal_spi_ex.c Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes stm32f1xx_hal_sram.c No Yes No No Yes Yes No No No No No Yes Yes No stm32f1xx_hal_sram.h stm32f1xx_hal_tim.c Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes stm32f1xx_hal_tim.h stm32f1xx_hal_tim_ex.c Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes stm32f1xx_hal_tim_ex.h stm32f1xx_hal_uart.c Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes stm32f1xx_hal_uart.h stm32f1xx_hal_usart.c Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes stm32f1xx_hal_usart.h stm32f1xx_hal_wwdg.c Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes stm32f1xx_hal_wwdg.h 2 / 35 DocID027328 1166 Rev

36 Overview of HAL drivers UM1850 ACCESS USB PERFORMANCE OTG Ethernet VALUE Files STM32F1 STM32F1 STM32F1 STM32F1 STM32F1 STM32F1 STM32F1 STM32F1 STM32F1 STM32F1 STM32F1 STM32F1 STM32F1 STM32F1 03xE 02x6 02xB 00xE 03x6 01xE 03xB 01xG 01xB 03xG 05xC 01x6 07xC 00xB stm32f1xx_ll_fsmc.c No Yes No No Yes Yes No No No No Yes Yes No No stm32f1xx_ll_fsmc.h stm32f1xx_ll_sdmmc.c No No No No No No No No No No Yes Yes No No stm32f1xx_ll_sdmmc.h stm32f1xx_ll_usb.c Yes No No No No No No Yes Yes Yes Yes Yes Yes Yes stm32f1xx_ll_usb.h stm32f1xx_ll_adc.h Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes stm32f1xx_ll_adc.c Yes Yes Yes Yes Yes Yes Yes stm32f1xx_ll_bus.h Yes Yes Yes Yes Yes Yes Yes stm32f1xx_ll_cortex.h Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes stm32f1xx_ll_crc.h Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes stm32f1xx_ll_crc.c stm32f1xx_ll_dac.h No Yes Yes No No Yes Yes No No No Yes Yes Yes Yes stm32f1xx_ll_dac.c stm32f1xx_ll_dma.h Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes stm32f1xx_ll_dma.c stm32f1xx_ll_exti.h Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes stm32f1xx_ll_exti.c stm32f1xx_ll_gpio.h Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes stm32f1xx_ll_gpio.c stm32f1xx_ll_i2c.h Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes stm32f1xx_ll_i2c.c Yes Yes Yes Yes Yes stm32f1xx_ll_iwdg.h Yes Yes Yes Yes Yes Yes Yes Yes Yes stm32f1xx_ll_pwr.h Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes stm32f1xx_ll_pwr.c stm32f1xx_ll_rcc.h Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes stm32f1xx_ll_rcc.c 36 / 1166 DocID027328 Rev 2

37 UM1850 Overview of HAL drivers ACCESS USB PERFORMANCE OTG Ethernet VALUE Files STM32F1 STM32F1 STM32F1 STM32F1 STM32F1 STM32F1 STM32F1 STM32F1 STM32F1 STM32F1 STM32F1 STM32F1 STM32F1 STM32F1 01x6 02x6 02xB 00xE 01xB 03x6 03xB 03xE 01xE 03xG 05xC 07xC 00xB 01xG stm32f1xx_ll_rtc.h Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes stm32f1xx_ll_rtc.c stm32f1xx_ll_spi.h Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes stm32f1xx_ll_spi.c Yes Yes Yes Yes Yes stm32f1xx_ll_system.h Yes Yes Yes Yes Yes Yes Yes Yes Yes stm32f1xx_ll_tim.h Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes stm32f1xx_ll_tim.c stm32f1xx_ll_usart.h Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes stm32f1xx_ll_usart.c stm32f1xx_ll_utils.h Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes stm32f1xx_ll_utils.c Yes Yes Yes Yes Yes Yes stm32f1xx_ll_wwdg.h Yes Yes Yes Yes Yes Yes Yes Yes 2 DocID027328 Rev 1166 37 /

38 O UM1850 of HAL drivers verview 2.5 HAL driver rules 2.5.1 HAL API naming rules The following naming rules are used in HAL drivers: Table 6: HAL API naming rules Device specific Family specific Generic File stm32f1xx_ hal_ppp_ex (c/h) stm32f1xx_hal_ppp_ex (c/h) stm32f1xx_hal_ppp (c/h) names Module HAL_PPP_ MODULE name HAL_PPPEx_Function HAL_PPPEx_Function HAL_PPP_Function Functio HAL_PPPEx_FeatureFunction_ HAL_PPP_FeatureFunction_ HAL_PPPEx_FeatureFunction_ n name MODE MODE MODE Handle NA PPP_HandleTypedef NA name Init structu PPP_InitTypeDef NA PPP_InitTypeDef re name Enum HAL_PPP_StructnameTypeD NA NA name ef prefix refers to the peripheral functional mode and not to the peripheral itself. PPP The For example, if the USART, PPP can be USART, IRDA, UART or SMARTCARD depending on the peripheral mode. The constants used in one file are defined within this file. A constant used in several files is defined in a header file. All constants are written in uppercase, except for peripheral driver function parameters. hould be suffixed with _TypeDef. typedef variable names s Registers are considered as constants. In most cases, their name is in uppercase and uses the same acronyms as in the STM32F1 reference manuals. Peripheral registers are declared in the PPP_TypeDef structure (e.g. ADC_TypeDef) stm32f1xxx.h corresponds to stm32f100xb.h, in stm32f1xxx.h header file. stm32f100xe.h, stm32f101x6.h, stm32f101xb.h, stm32f101xe.h, stm32f101xg.h, stm32f102x6.h, stm32f102xb. h, stm32f103x6.h, stm32f103xb.h, stm32f103xe.h, stm32f103xg.h, stm32f105xc.h and stm32f107xc.h. Peripheral function names are prefixed by HAL_, then the corresponding peripheral acronym in uppercase followed by an underscore. The first letter of each word is in uppercase (e.g. HAL_UART_Transmit()). Only one underscore is allowed in a function name to separate the peripheral acronym from the rest of the function name. The structure containing the PPP peripheral initialization parameters are named peDef (e.g. ADC_InitTypeDef). PPP_InitTy The structure containing the Specific configuration parameters for the PPP peripheral are named PPP_xxxxConfTypeDef (e.g. ADC_ChannelConfTypeDef). Peripheral handle structures are named PPP_HandleTypedef (e.g ef) DMA_HandleTypeD The functions used to initialize the PPP peripheral according to parameters specified in PPP_InitTypeDef are named HAL_PPP_Init (e.g. HAL_TIM_Init()). The functions used to reset the PPP peripheral registers to their default values are named PPP_DeIn it, e.g. TIM_DeInit. DocID027328 / 1166 38 Rev 2

39 UM1850 of HAL drivers Overview The MODE suffix refers to the process mode, which can be polling, interrupt or DMA. As an example, when the DMA is used in addition to the native resources, the function should be called: HAL_PPP_Function_DMA (). prefix sh Feature The ould refer to the new feature. Example: HAL_ADC_Start () refers to the injection mode HAL general naming rules 2.5.2 For the shared and system peripherals, no handle or instance object is used. This rule applies to the following peripherals: GPIO SYSTICK NVIC RCC FLASH. Example: The requires only the GPIO address and its configuration HAL_GPIO_Init() parameters. AL_StatusTypeDef HAL_GPIO_Init (GPIO_TypeDef* GPIOx, GPIO_InitTypeDef *Init) H { /*GPIO Initialization body */ } The macros that handle interrupts and specific clock configurations are defined in each peripheral/module driver. These macros are exported in th e peripheral driver header files so that they can be used by the extension file. The list of these macros is This list is not exhaustive and other macros related to peripheral defined below: cation. features can be added, so that they can be used in the user appli Table 7: Macros handling interrupts and specific clock configurations Macros Description Enables a specific peripheral __HAL_PPP_ENABLE_IT(__HANDLE__, __INTERRUPT__) interrupt Disables a specific peripheral __HAL_PPP_DISABLE_IT(__HANDLE__, __INTERRUPT__) interrupt Gets a specific peripheral interrupt __HAL_PPP_GET_IT (__HANDLE__, __ INTERRUPT __) status Clears a specific peripheral __HAL_PPP_CLEAR_IT (__HANDLE__, __ INTERRUPT __) interrupt status Gets a specific peripheral flag ANDLE__, __FLAG__) __HAL_PPP_GET_FLAG (__H status Clears a specific peripheral flag __HAL_PPP_CLEAR_FLAG (__HANDLE__, __FLAG__) status __HAL_PPP_ENABLE(__HANDLE__) Enables a peripheral __HAL_PPP_DISABLE(__HANDLE__) Disables a peripheral __HAL_PPP_XXXX (__HANDLE__, __PARAM__) Specific PPP HAL driver macro __HAL_PPP_GET_ IT_SOURCE (__HANDLE__, __ Checks the source of specified INTERRUPT __) interrupt NVIC and SYSTICK are two ARM Cortex core features. The APIs related to these are located in the stm32f1xx_hal_cortex.c file. features 2 DocID027328 Rev 1166 39 /

40 Overview of HAL drivers UM1850 When a status bit or a flag is read from registers, it is composed of shifted values depending on the number of read values and of their size. In this case, the returned status width is 32 bits. Example : ST ATUS = XX | (YY << 16) or STATUS = XX | (YY << 8) | (YY << 16) | (YY << 24)". The PPP handles are valid before using the HAL_PPP_Init() API. The init function e modifying the handle fields. performs a check befor HAL_PPP_Init(PPP_HandleTypeDef) if(hppp == NULL) { return HAL_ERROR; } The macros defined below are used: Conditional macro: - #define ABS(x) (((x) > 0) ? (x) : (x)) Pseudo code macro (multiple instructions macro): - #define __HAL_LINKDMA(__HANDLE__, __PPP_DMA_FIELD_, __DMA_HANDLE_) \ \ do{ \ >__PPP_DMA_FIELD_ = &(__DMA_HANDLE_); - (__HANDLE__) \ (__DMA_HANDLE_).Parent = (__HANDLE__); } while(0) HAL interrupt handler and callback functions 2.5.3 Besides the APIs, HAL peripheral drivers include: HAL_PPP_IRQHandler() peripheral interrupt handler that should be called from stm32f1xx_it.c User callback functions. The user callback functions are defined as empty functions with “weak” attribute. They have to be defined in the user code. There are th ree types of user callbacks functions: Initialization callbacks: HAL_PPP_MspInit() Peripheral system level initialization/ de - and HAL_PPP_MspDeInit Process complete callbacks : HAL_PPP_ProcessCpltCallback Error callback: HAL_PPP_ErrorCallback. Callback functions Table 8: Example Callback functions Ex: HAL_USART_MspInit() HAL_PPP_MspInit() / _DeInit() Called from HAL_PPP_Init() API function to perform peripheral system level initialization (GPIOs, clock, DMA, interrupt) Ex: HAL_USART_TxCpltCallback HAL_PPP_ProcessCpltCallback Called by peripheral or DMA interrupt handler when the process completes Ex: HAL_USART_ErrorCallback HAL_PPP_ErrorCallback Called by peripheral or DMA interrupt handler when an error occurs DocID027328 / 1166 40 Rev 2

41 UM1850 Overview of HAL drivers 2.6 HAL generic APIs The generic APIs provide common generic functions applying to all STM32 devices. They are composed of four APIs groups: Initialization and de HAL_PPP_Init(), HAL_PPP_DeInit() initialization functions: - : HAL_PPP_Read IO operation functions (), HAL_PPP_Write(),HAL_PPP_Transmit(), HAL_PPP_Receive() Control functions : HAL_PPP_Set (), HAL_PPP_Get (). State and Errors functions : HAL_PPP_GetState (), HAL_PPP_GetError (). For some peripheral/module drivers, these groups are modified depending on the peripheral/module implementation. Example: in the timer driver, the API grouping is based on timer features (PWM, OC, IC...). s allow initializing a peripheral and configuring initialization function The initialization and de - level resources, mainly clocks, GPIO, alternate functions (AF) and possibly DMA the low - and interrupts. The HAL_DeInit() function restores the peripheral default state, frees the level resources and remo ves any direct dependency with the hardware. - low The IO operation functions perform a row access to the peripheral payload data in write and read modes. The control functions are used to change dynamically the peripheral configuration and set ng mode. another operati The peripheral state and errors functions allow retrieving in runtime the peripheral and data flow states, and identifying the type of errors that occurred. The example below is based on the ADC peripheral. The list of generic APIs is not exhaust ive. It is only given as an example. Table 9: HAL generic APIs Function Common API name Description group This function initializes the peripheral and HAL_ADC_Init() - configures the low level resources (clocks, GPIO, AF..) Initialization group This function restores the peripheral default state, HAL_ADC_DeInit() level resources and removes any - frees the low direct dependency with the hardware. This function starts ADC conversions when the HAL_ADC_Start () polling method is used This function stops ADC conversions when the HAL_ADC_Stop () polling method is used This function allows waiting for the end of conversions when the polling method is used. In HAL_ADC_PollForConversion() IO operation this case, a timout value is specified by the user group according to the application. This function starts ADC conversions when the HAL_ADC_Start_IT() d is used interrupt metho This function stops ADC conversions when the HAL_ADC_Stop_IT() interrupt method is used HAL_ADC_IRQHandler() This function handles ADC interrupt requests 2 DocID027328 Rev 1166 41 /

42 Overview UM1850 of HAL drivers Function Common API name Description group Callback function called in the IT subroutine to HAL_ADC_ConvCpltCallback() e the end of the current process or when a indicat DMA transfer has completed Callback function called in the IT subroutine if a HAL_ADC_ErrorCallback() peripheral error or a DMA transfer error occurred This function configures the selected ADC regular HAL_ADC_ConfigChannel() channel, the corresponding rank in the sequencer and the sample time Control group This function configures the analog watchdog for HAL_ADC_AnalogWDGConfig the selected ADC This function allows getting in runtime the HAL_ADC_GetState() peripheral and the data flow states. State and Errors group This fuction allows getting in runtime the error HAL_ADC_GetError() that occurred during IT routine HAL extension APIs 2.7 2.7.1 model overview HAL extension The extension APIs provide specific functions or overwrite modified APIs for a specific family (series) or specific part number within the same family. The extension model consists of an additional file, stm32f1xx_hal_ppp_ex.c, that includes all the specific functions and define statements (stm32f1xx_hal_ppp_ex.h) for a given part number. Below an example based on the ADC peripheral: Table 10: HAL extension APIs Common API Name Function Group HAL_ADCEx_CalibrationStart() This function is used to start the automatic ADC calibration HAL extension model cases 2.7.2 The specific IP features can be handled by the HAL drivers in five different ways. They are ed below. describ specific function - Case 1: Adding a part number When a new feature specific to a given device is required, the new APIs are added in the stm32f1xx_hal_ppp_ex.c extension file. They are named HAL_PPPEx_Function(). DocID027328 / 1166 42 Rev 2

43 UM1850 of HAL drivers Overview specific functions - : Adding device 2 Figure Example: stm32f1xx_hal_adc_ex.c/h #if defined(STM32F101xG) || defined (STM32F103x6) || defined (STM32F103xB) || defined (STM32F105xC) || defined (STM32F107xC) || defined (STM32F103xE) || defined(STM32F103xG) /* ADC multimode */ HAL_StatusTypeDef HAL_ADCEx_MultiModeStart_DMA(ADC_HandleTypeDef *hadc, uint32_t *pData, uint32_t Length); HAL_StatusTypeDef HAL_ADCEx_MultiModeStop_DMA(ADC_HandleTypeDef *hadc); 3xB || defined #endif /* STM32F101xG || defined STM32F103x6 || defined STM32F10 STM32F105xC || defined STM32F107xC || defined STM32F103xE || defined STM32F103xG */ specific function Case 2: Adding a family - In this case, the API is added in the extension driver C file and named HAL_PPPEx_Function (). - : Adding family 3 Figure specific functions Case 3: Adding a new peripheral (specific to a device belonging to a given family) When a peripheral which is available only in a specific device is required, the APIs /module are added in stm32f1xx_hal_newppp.c. corresponding to this new peripheral However the inclusion of this file is selected in the stm32lxx_hal_conf.h using the macro: #define HAL_NEWPPP_MODULE_ENABLED 2 DocID027328 Rev 1166 43 /

44 Overview UM1850 of HAL drivers Figure : Adding new peripherals 4 cd.c/h Example: stm32f1xx_hal_l Case 4: Updating existing common APIs In this case, the routines are defined with the same names in the stm32f1xx_hal_ppp_ex.c extension file, while the generic API is defined as weak , so that the compiler will overwrite the original routine by the new defined function. : Updating existing APIs 5 Figure Case 5: Updating existing data structures The data structure for a specific device part number (e.g. PPP_InitTypeDef) can have cture is defined in the extension header file and different fields. In this case, the data stru delimited by the specific part number define statement. Example: #if defined (STM32F100xB) typedef struct { (...) }PPP_InitTypeDef; #endif /* STM32F100xB */ DocID027328 / 1166 44 Rev 2

45 UM1850 of HAL drivers Overview File inclusion model 2.8 The header of the common HAL driver file (stm32f1xx_hal.h) includes the common configurations for the whole HAL library. It is the only header file that is included in the user e able to use the HAL resources. sources and the HAL C sources files to b Figure : File inclusion model 6 A PPP driver is a standalone module which is used in a project. The user must enable the . corresponding USE_HAL_PPP_MODULE define statement in the configuration file /********************************************************************* * @file stm32f1xx_hal_conf.h * @author MCD Application Team * @version VX.Y.Z * @date dd yyyy - mm - * @brief This file contains the modules to be used ************************************ ********************************** (...) #define USE_HAL_USART_MODULE #define USE_HAL_IRDA_MODULE #define USE_HAL_DMA_MODULE #define USE_HAL_RCC_MODULE (...) 2 DocID027328 Rev 1166 45 /

46 Overview UM1850 of HAL drivers 2.9 HAL common resources The common HAL resources, such as common define enumerations, structures and stm32f1xx_hal_def.h. The main common define enumeration is macros, are defined in HAL_StatusTypeDef . The HAL status is used by almost all HAL APIs, except for boolean HAL Status e status of the current API operations. It has functions and IRQ handler. It returns th four possible values as described below: Typedef enum { HAL_OK = 0x00, HAL_ERROR = 0x01, HAL_BUSY = 0x02, HAL_TIMEOUT = 0x03 } HAL_StatusTypeDef; HAL Locked The HAL lock is used by all HAL APIs to prevent accessing by accident shared resources. typedef enum { HAL_UNLOCKED = 0x00, /*!__PPP_DMA_FIELD_ = &(__DMA_HANDLE_); (__HANDLE__) (__DMA_HANDLE_).Parent = (__HANDLE__); \ } while(0) 2.10 HAL configuration allows customizing the drivers for the user x_hal_conf.h, , stm32f1x The configuration file application. Modifying this configuration is not mandatory: the application can use the default configuration without any modification. e or modify some options by To configure these parameters, the user should enable, disabl uncommenting, commenting or modifying the values of the related define statements as described in the table below: DocID027328 / 1166 46 Rev 2

47 UM1850 of HAL drivers Overview Table 11: Define statements used for HAL configuration Configuration item Default Value Description Defines the value of the external oscillator 25 000 000 Hz on (HSE) expressed in Hz. The user must HSE_ VALUE EVAL, - STM3210C adjust this define statement when using a otherwise 8 000 000 Hz different crystal value. up, expressed in ms - 5000 Timeout for HSE start HSE_STARTUP_TIMEOUT Defines the value of the internal oscillator HSI_VALUE 8 000 000 Hz (HSI) expressed in Hz. Defines the value of the external oscillator (HSE) expressed in Hz. The user must LSE_VALUE 32768 Hz adjust this defi ne statement when using a different crystal value. LSE_STARTUP_TIMEOUT 5000 up, expressed in ms - Timeout for LSE start VDD_VALUE 3300 (mV) VDD value USE_RTOS Enables the use of RTOS FALSE (for future use) PREFETCH_ENABLE Enables prefetch feature TRUE The stm32f1xx_hal_conf_template.h file is located in the HAL drivers folder. It Inc should be copied to the user folder, renamed and modified as described above. al_conf_template.h file are the By default, the values defined in the stm32f1xx_h same as the ones used for the examples and demonstrations. All HAL include files are enabled so that they can be used in the user code without modifications. 2.11 HAL system peripheral handling This chapter gives an overview of how the system peripherals are handled by the HAL drivers. The full API list is provided within each peripheral driver description section. Clock 2.11.1 Two main functions can be used to configure the system clock: HAL_RCC_OscConfig (RCC_OscInitTypeDef *RCC_OscInitStruct). This function configures/enables multiple clock sources (HSE, HSI, LSE, LSI, PLL). HAL_RCC_ClockConfig (RCC_ClkInitTypeDef *RCC_C lkInitStruct, uint32_t FLatency). This function selects the system clock source configures AHB, APB1 and APB2 clock dividers configures the number od Flash memory wait states updates the SysTick configuration when HCLK clock changes. Some peripheral clocks are not derived from the system clock (RTC, USB...). In this case, the clock configuration is performed by an extended API defined in 2 DocID027328 Rev 1166 47 /

48 Overview UM1850 of HAL drivers HAL_RCCEx_PeriphCLKConfig(RCC_PeriphCLKInitTypeDef stm32f1xx_hal_rcc_ex.c: . *PeriphClkInit) ions are available: Additional RCC HAL driver funct HAL_RCC_DeInit() Clock de - init function that return clock configuration to reset state Get clock functions that allow retreiving various clock configurations (system clock, HCLK, PCLK1, PCLK2, ...) MCO and CSS configuration functions A s et of macros are defined in stm32f1xx_hal_rcc.h and stm32f1xx_hal_rcc_ex.h. They allow executing elementary operations on RCC block registers, such as peripherals clock gating/reset control: __PPP_CLK_ENABLE/__PPP_CLK_DISABLE to enable/disable the peripher al clock __PPP_FORCE_RESET/__PPP_RELEASE_RESET to force/release peripheral reset __PPP_CLK_SLEEP_ENABLE/__PPP_CLK_SLEEP_DISABLE to enable/disable the peripheral clock during low power (Sleep) mode. GPIOs 2.11.2 are the following: GPIO HAL APIs HAL_GPIO_Init() / HAL_GPIO_DeInit() HAL_GPIO_ReadPin() / HAL_GPIO_WritePin() HAL_GPIO_TogglePin (). In addition to standard GPIO modes (input, output, analog), the pin mode can be configured as EXTI with interrupt or event generation . When selecting EXTI mode with interrupt generation, the user must call HAL_GPIO_EXTI_IRQHandler() from stm32f1xx_it.c and implement HAL_GPIO_EXTI_Callback() The table below describes the GPIO_InitTypeDef structure field. DocID027328 / 1166 48 Rev 2

49 UM1850 Overview of HAL drivers GPIO_InitTypeDef structure Table 12: Description of Structure Description field Specifies the GPIO pins to be configured. Pin Possible values: GPIO_PIN_x or GPIO_PIN_All, where x[0..15] Specifies the operating mode for the selected pins: GPIO mode or EXTI mode. Possible values are: GPIO mode GPIO_MODE_INPUT : Input floating - GPIO_MODE_OUTPUT_PP : Output push pull GPIO_MODE_OUTPUT_OD : Output open drain pull - GPIO_MODE_AF_PP : Alternate function push GPIO_MODE_AF_OD : Alternate function open drain GPIO_MODE_ANALOG : Analog m ode Mode External Interrupt mode GPIO_MODE_IT_RISING : Rising edge trigger detection GPIO_MODE_IT_FALLING : Falling edge trigger detection GPIO_MODE_IT_RISING_FALLING : Rising/Falling edge trigger detection External Event mode GPIO_MODE_EVT_RISING : Rising edge trigger detection GPIO_MODE_EVT_FALLING : Falling edge trigger detection GPIO_MODE_EVT_RISING_FALLING: Rising/Falling edge trigger detection Specifies the Pull down activation for the selected pins. - - up or Pull Possible values are: GPIO_NOPULL Pull GPIO_PULLUP GPIO_PULLDOWN Specifies the speed for the selected pins Possible values are: Speed GPIO_SPEED_LOW GPIO_SPEED_MEDIUM GPIO_SPEED_HIGH Please find below typical GPIO configuration examples: - Configuring GPIOs as output push pull to drive external LEDs GPIO_InitStruct.Pin = GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_PULLUP; GPIO_InitStruct.Speed = GPIO_SPEED_MEDIUM; HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); Configuring PA0 as external interrupt with falling edge sensitivity: GPIO_InitStructure.Mode = GPIO_MODE_IT_FALLING; GPIO_InitStructure.Pull = GPIO_NOPULL; GPIO_InitStructure.Pin = GPIO_PIN_0; _GPIO_Init(GPIOA, &GPIO_InitStructure); HAL 2 DocID027328 Rev 1166 49 /

50 Overview UM1850 of HAL drivers 2.11.3 Cortex NVIC and SysTick timer The Cortex HAL driver, stm32f1xx_hal_cortex.c, provides APIs to handle NVIC and SysTick. The supported APIs include: NVIC_SetPriorityGrouping() HAL_NVIC_SetPriority()/ HAL_ HAL_NVIC_GetPriority() / HAL_NVIC_GetPriorityGrouping() HAL_NVIC_EnableIRQ()/HAL_NVIC_DisableIRQ() HAL_NVIC_SystemReset() HAL_SYSTICK_IRQHandler() HAL_NVIC_GetPendingIRQ() / HAL_NVIC_SetPendingIRQ () / HAL_NVIC_ClearPendingIRQ() HAL_NVIC_GetActive(IRQn) HAL_SYSTICK_Config() HAL_SYSTICK_CLKSourceConfig() HAL_SYSTICK_Callback() PWR 2.11.4 The PWR HAL driver handles power management. The features shared between all STM32 Series are listed below: PVD configu ration, enabling/disabling and interrupt handling HAL_PWR_ConfigPVD() HAL_PWR_EnablePVD() / HAL_PWR_DisablePVD() HAL_PWR_PVD_IRQHandler() HAL_PWR_PVDCallback() Wakeup pin configuration HAL_PWR_EnableWakeUpPin() / HAL_PWR_DisableWakeUpPin() power mode Low - entry HAL_PWR_EnterSLEEPMode() HAL_PWR_EnterSTOPMode() HAL_PWR_EnterSTANDBYMode() EXTI 2.11.5 The EXTI is not considered as a standalone peripheral but rather as a service used by other peripheral. As a result there are no EXTI APIs but each peripheral HAL driver implements the associated EXTI configuration and EXTI function are implemented as macros in its header file. The first 16 EXTI lines connected to the GPIOs are managed within the GPIO driver. The GPIO_InitTypeDef structu re allows configuring an I/O as external interrupt or external event. The EXTI lines connected internally to the PVD, RTC, USB, and Ethernet are configured within the HAL drivers of these peripheral through the macros given in the table below. The ernal connections depend on the targeted STM32 microcontroller (refer to the EXTI int product datasheet for more details): DocID027328 / 1166 50 Rev 2

51 UM1850 of HAL drivers Overview Table 13: Description of EXTI configuration macros Macros Description Enables a given EXTI line in terrupt __HAL_PPP_{SUBLOCK}__EXTI_ENABLE_IT() Example: __HAL_PWR_PVD_EXTI_ENABLE_IT() Disables a given EXTI line. __HAL_PPP_{SUBLOCK}__EXTI_DISABLE_IT() Example: __HAL_PWR_PVD_EXTI_DISABLE_IT() Gets a given EXTI line interrupt flag pending bit status. __HAL_ PPP_{SUBLOCK}__EXTI_GET_FLAG() Example: __HAL_PWR_PVD_EXTI_GET_FLAG() Clears a given EXTI line interrupt flag pending bit. __HAL_ PPP_{SUBLOCK}_EXTI_CLEAR_FLAG() Example; __HAL_PWR_PVD_EXTI_CLEAR_FLAG() en EXTI line. Generates a software interrupt for a giv __HAL_ Example: PPP_{SUBLOCK}_EXTI_GENERATE_SWIT() __HAL_PWR_PVD_EXTI_ GENERATE_SWIT () Enable a given EXTI line event __HAL_PPP_SUBBLOCK_EXTI_ENABLE_ EVENT() Example: __HAL_RTC_WAKEUP_EXTI_ENABLE_EVENT() Disable a given EXTI line event __HAL_PPP_SUBBLOCK_EXTI_DISABLE_ EVENT() Example: __HAL_RTC_WAKEUP_EXTI_DISABLE_EVENT() __HAL_ Configure an EXTI Interrupt or Event on rising edge PPP_SUBBLOCK_EXTI_ENABLE_RISING_ EDGE() __HAL_ Enable an EXTI Interrupt or Event on Falling edge PPP_SUBBLOCK_EXTI_DISABLE_FALLING_ EDGE() __HAL_ Disable an EXTI Interrupt or Event on rising edge PPP_SUBBLOCK_EXTI_DISABLE_RISING_ EDGE() __HAL_ Disable an EXTI Interrupt or Event on Falling edge PPP_SUBBLOCK_EXTI_DISABLE_FALLING_ EDGE() Enable an EXTI Interrupt or Event on Rising/Falling __HAL_ edge PPP_SUBBLOCK_EXTI_ENABLE_RISING_ FALLING_EDGE() Disable an EXTI Interrupt or Event on Rising/Falling __HAL_ edge PPP_SUBBLOCK_EXTI_DISABLE_RISING_ FALLING_EDGE() 2 DocID027328 Rev 1166 51 /

52 Overview of HAL drivers UM1850 If the EXTI interrupt mode is selected, the user application must call HAL_PPP_FUNCTION_IRQHandler() (for example HAL_PWR_PVD_IRQHandler()), from stm32f1xx_it.c file, and implement HAL_PPP_FUNCTIONCallback() callback function (for example HAL_PWR_PVDCallback(). 2.11.6 DMA nabling and configuring the peripheral to be connected to the The DMA HAL driver allows e DMA Channels (except for internal SRAM/FLASH memory which do not require any initialization). Refer to the product reference manual for details on the DMA request l. corresponding to each periphera For a given channel, HAL_DMA_Init() API allows programming the required configuration through the following parameters: Transfer Direction Source and Destination data formats Circular, Normal or peripheral flow control mode Channels Priority level Source and Destination Increment mode Two operating modes are available: Polling mode I/O operation a. Use HAL_DMA_Start() to start DMA transfer when the source and destination addresses and the Length of data to be transferred have been configured. MA_PollForTransfer() to poll for the end of current transfer. In this Use HAL_D b. case a fixed timeout can be configured depending on the user application. Interrupt mode I/O operation a. Configure the DMA interrupt priority using HAL_NVIC_SetPriority() b. RQ handler using HAL_NVIC_EnableIRQ() Enable the DMA I c. Use HAL_DMA_Start_IT() to start DMA transfer when the source and destination addresses and the length of data to be transferred have been confgured. In this case the DMA interrupt is configured. d. Use HAL_DMA_IRQHandle r() called under DMA_IRQHandler() Interrupt subroutine e. When data transfer is complete, HAL_DMA_IRQHandler() function is executed and a user function can be called by customizing XferCpltCallback and handle structure). XferErrorCallback function pointer (i.e. a member of DMA Additional functions and macros are available to ensure efficient DMA management: Use HAL_DMA_GetState() function to return the DMA state and HAL_DMA_GetError() in case of error detection. Use HAL_DMA_Abort() function to abort the curre nt transfer The most used DMA HAL driver macros are the following: __HAL_DMA_ENABLE: enables the specified DMA Channels. __HAL_DMA_DISABLE: disables the specified DMA Channels. __HAL_DMA_GET_FLAG: gets the DMA Channels pending flags. : clears the DMA Channels pending flags. __HAL_DMA_CLEAR_FLAG __HAL_DMA_ENABLE_IT: enables the specified DMA Channels interrupts. __HAL_DMA_DISABLE_IT: disables the specified DMA Channels interrupts. __HAL_DMA_GET_IT_SOURCE: checks whether the specified DMA stream interrupt s occurred or not. ha DocID027328 / 1166 52 Rev 2

53 Overview UM1850 of HAL drivers When a peripheral is used in DMA mode, the DMA initialization should be done in the HAL_PPP_MspInit() callback. In addition, the user application should associate the DMA handle to the PPP handle (refer to section “HAL IO operation functions”). DMA channel callbacks need to be initialized by the user application only in case - to - memory transfer. However when peripheral - to - of memory memory transfers are used, these callbacks are automatically initialized by calling a process API function that uses the DMA. How to use HAL drivers 2.12 HAL usage models 2.12.1 The following figure shows the typical use of the HAL driver and the interaction between and the interrupts. the application user, the HAL driver Figure : HAL driver model 7 The functions implemented in the HAL driver are shown in green, the functions called from interrupt handlers in dotted lines, and the msp functions implemented in the user dotted lines represent the interactions between application in red. Non - the user application functions. 53 DocID027328 1166 / 2 Rev

54 Overview UM1850 of HAL drivers Basically, the HAL driver APIs are called from user files and optionally from interrupt handlers file when the APIs based on the DMA or the PPP peripheral dedicated interrupts are used. ete callbacks are When DMA or PPP peripheral interrupts are used, the PPP process compl time event mode (interrupts). called to inform the user about the process completion in real - Note that the same process completion callbacks are used for DMA in interrupt mode. 2.12.2 HAL initialization obal initialization HAL gl 2.12.2.1 In addition to the peripheral initialization and de - initialization functions, a set of APIs are provided to initialize the HAL core implemented in file stm32f1xx_hal.c. must be called at application startup to HAL_Init(): this function - fetch queue initialize data/instruction cache and pre set SysTick timer to generate an interrupt each 1ms (based on HSI clock) with the lowest priority vel initializations call HAL_MspInit() user callback function to perform system le (Clock, GPIOs, DMA, interrupts). HAL_MspInit() is defined as “weak” empty function in the HAL drivers. HAL_DeInit() resets all peripherals calls function HAL_MspDeInit() which a is user callback function to do system - level De ions. Initalizat HAL_GetTick(): this function gets current SysTick counter value (incremented in SysTick interrupt) used by peripherals drivers to handle timeouts. HAL_Delay(). this function implements a delay (expressed in milliseconds) using the SysTick timer. e must be taken when using HAL_Delay() since this function provides an accurate Car delay (expressed in milliseconds) based on a variable incremented in SysTick ISR. This means that if HAL_Delay() is called from a peripheral ISR, then the SysTick t have highest priority (numerically lower) than the peripheral interrupt, interrupt mus otherwise the caller ISR will be blocked. System clock initialization 2.12.2.2 The clock configuration is done at the beginning of the user code. Howe ver the user can change the configuration of the clock in his own code. Please find below the typical Clock configuration sequence: void SystemClock_Config(void) { RCC_ClkInitTypeDef clkinitstruct = {0}; RCC_OscInitTypeDef oscinitstruct = {0}; */ ------------------------------------------------------ /* Conf igure PLLs /* PLL2 configuration: PLL2CLK=(HSE/HSEPrediv2Value)*PLL2MUL=(25/5)*8=40 MHz */ /* PREDIV1 configuration: PREDIV1CLK = PLL2CLK / HSEPredivValue = 40 / 5 = 8 MHz */ /* PLL configuration: PLLCLK = PREDIV1CLK * PLLMUL = 8 * 9 = 72 MHz */ /* Enable HSE Oscillator and activate PLL with HSE as source */ oscinitstruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; oscinitstruct.HSEState = RCC_HSE_ON; oscinitstruct.HSEPredivValue = RCC_HSE_PRED IV_DIV5; oscinitstruct.Prediv1Source = RCC_PREDIV1_SOURCE_PLL2; oscinitstruct.PLL.PLLState = RCC_PLL_ON; oscinitstruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; oscinitstruct.PLL.PLLMUL = RCC_PLL_MUL9; oscinitstruct.PLL2.PLL2State = RCC_PLL2_ON; ct.PLL2.PLL2MUL = RCC_PLL2_MUL8; oscinitstru oscinitstruct.PLL2.HSEPrediv2Value = RCC_HSE_PREDIV2_DIV5; if (HAL_RCC_OscConfig(&oscinitstruct)!= HAL_OK) DocID027328 / 1166 54 Rev 2

55 UM1850 Overview of HAL drivers { /* Initialization Error */ while(1); } /* Select PLL as system clock source and configure the HCLK, PCL K1 and PCLK2 clocks dividers */ clkinitstruct.ClockType = (RCC_CLOCKTYPE_SYSCLK I RCC_CLOCKTYPE_HCLK I RCC_CLOCKTYPE_PCLK1 I RCC_CLOCKTYPE_PCLK2); clkinitstruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; clkinitstruct.AHBCLKDivider = RCC_SYSCLK_DIV1; clkinitstruct.APB2CLKDivider = RCC_HCLK_DIV1; clkinitstruct.APB1CLKDivider = RCC_HCLK_DIV2; if (HAL_RCC_ClockConfig(&clkinitstruct, FLASH_LATENCY_2)!= HAL_OK) { /* Initialization Error */ while(1); } } HAL MSP initialization process 2.12.2.3 while the hardware resources The peripheral initialization is done through HAL_PPP_Init() initialization used by a peripheral (PPP) is performed during this initialization by calling HAL_PPP_MspInit(). MSP callback function nit callback performs the low level initialization related to the different additional The MspI hardware resources: RCC, GPIO, NVIC and DMA. - All the HAL drivers with handles include two MSP callbacks for initialization and de initialization: /** Initializes the PPP MSP. * @brief * @param hppp: PPP handle * @retval None */ void __weak HAL_PPP_MspInit(PPP_HandleTypeDef *hppp) { /* NOTE : This function Should not be modified, when the callback is needed, the HAL_PPP_MspInit could be implemented in the user fi le */ } /** * @brief DeInitializes PPP MSP. * @param hppp: PPP handle * @retval None */ void __weak HAL_PPP_MspDeInit(PPP_HandleTypeDef *hppp) { /* NOTE : This function Should not be modified, when the callback is needed, the HAL_PPP_MspDeInit could be imp lemented in the user file */ } The MSP callbacks are declared empty as weak functions in each peripheral driver. The user can use them to set the low level initialization code or omit them and use his own initialization routine. file in the user stm32f1xx_hal_msp.c The HAL MSP callback is im plemented inside the folders. An file template is located in the HAL folder and should be stm32f1xx_hal_msp.c copied to the user folder. It can be generated automatically by STM32CubeMX tool and further modified. Note t hat all the routines are declared as weak functions and could be overwritten or removed to use user low level initialization code. file contains the following functions: stm32f1xx_hal_msp.c Table 14: MSP functions Description Routine void HAL_MspInit() Global MSP initialization routine void HAL_MspDeInit() initialization routine - Global MSP de void HAL_PPP_MspInit() PPP MSP initialization routine 2 DocID027328 Rev 1166 55 /

56 Overview UM1850 of HAL drive rs Routine Description void HAL_PPP_MspDeInit() PPP MSP de - initialization routine initialized during the program execution, the By default, if no peripheral needs to be de - and MSP De Hal_MspInit() whole MSP initialization is done in Initialization in the - and In this case the HAL_PPP_MspInit() Hal_MspDeInit(). HAL_PPP_MspDeInit() are not implemented. initialized in run time and the low level When one or more peripherals needs to be de - resources of a given peripheral need to be released and used by another peripheral, rned HAL_PPP_MspDeInit() and HAL_PPP_MspInit() are implemented for the conce peripheral and other peripherals initialization and de - Initialization are kept in the global HAL_MspDeInit(). HAL_MspInit() and the and , the If there is nothing to be initialized by the global HAL_MspDeInit() HAL_MspInit() mitted. two routines can simply be o 2.12.3 HAL IO operation process The HAL functions with internal data processing like transmit, receive, write and read are generally provided with three data processing modes as follows: Polling mode Interrupt mo de DMA mode 2.12.3.1 Polling mode In Polling mode, the HAL functions return the process status when the data processing in blocking mode is complete. The operation is considered complete when the function returns the HAL_OK status , otherwise an error status is returned. The user can get more information through the HAL_PPP_GetState() function. The data processing is handled internally in a loop. A timeout (expressed in ms) is used to prevent process hanging. s the typical Polling mode processing sequence : The example below show HAL_StatusTypeDef HAL_PPP_Transmit ( PPP_HandleTypeDef * phandle, uint8_t pData, int16_tSize,uint32_tTimeout) { if((pData == NULL ) || (Size == 0)) { return HAL_ERROR; } (...) while (data processing is runni ng) { if( timeout reached ) { return HAL_TIMEOUT; } } (...) return HELIAC; } Interrupt mode 2.12.3.2 In Interrupt mode, the HAL function returns the process status after starting the data processing and enabling the appropriate interruption. The end of the operation is indicated o be informed by a callback declared as a weak function. It can be customized by the user t - in real time about the process completion. The user can also get the process status through the function. HAL_PPP_GetState() DocID027328 / 1166 56 Rev 2

57 UM1850 of HAL drivers Overview In Interrupt mode, four functions are declared in the driver: HAL_PPP_Process_IT() : launch the process Handler() HAL_PPP_IRQ : the global PPP peripheral interruption __weak HAL_PPP_ProcessCpltCallback () : the callback relative to the process completion. : the callback relative to the process Error. __weak HAL_PPP_ProcessErrorCallback() is called in the user file and To use a process in Interrupt mo de, HAL_PPP_Process_IT() stm32f1xx_it.c. HAL_PPP_IRQHandler in The function is declared as weak function in the driver. HAL_PPP_ProcessCpltCallback() This means that the user can declare it again in the application. The function in the driver is not modified. An example of use is illustrated below: file: main.c UART_HandleTypeDef UartHandle; main(void) int { /* Set User Parameters */ UartHandle.Init.BaudRate = 9600; UartHandle.Init.WordLength = UART_DATABITS_8; UartHandle.Init.StopBits = UART_STOPBITS_1; UartHandle.Init.Parity = UART_PARITY_NONE; UartHandle.Init.HwFlowCtl = UART_HWCONTROL_NONE; Ua rtHandle.Init.Mode = UART_MODE_TX_RX; UartHandle.Init.Instance = USART1; HAL_UART_Init(&UartHandle); HAL_UART_SendIT(&UartHandle, TxBuffer, sizeof(TxBuffer)); while (1); } void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart) { } void HAL_UART_ErrorCallb ack(UART_HandleTypeDef *huart) { } stm32f1xx_it.c file: extern UART_HandleTypeDef UartHandle; void USART1_IRQHandler(void) { HAL_UART_IRQHandler(&UartHandle); } 2.12.3.3 DMA mode In DMA mode, the HAL function returns the process statu s after starting the data processing through the DMA and after enabling the appropriate DMA interruption. The end of the operation is indicated by a callback declared as a weak function and can be - time about th e process completion. The user customized by the user to be informed in real can also get the process status through the HAL_PPP_GetState() function. For the DMA mode, three functions are declared in the driver: HAL_PPP_Process_DMA() : launch the process HAL_PPP_DMA_IRQHandler() used by the PPP peripheral : the DMA interruption : the callback relative to the process __weak HAL_PPP_ProcessCpltCallback() completion. : the callback relative to the process Error. __weak HAL_PPP_ErrorCpltCallback() 2 DocID027328 Rev 1166 57 /

58 Overview of HAL drivers UM1850 To use a process in DMA mode, HAL_PPP_Process_DMA() is cal led in the user file and is placed in the HAL_PPP_DMA_IRQHandler() . When DMA mode is stm32f1xx_it.c the used, the DMA initialization is done in the callback. The user should HAL_PPP_MspInit() also associate the DMA handle to the PPP handle. For this purpos e, the handles of all the peripheral drivers that use the DMA must be declared as follows: typedef struct { PPP_TypeDef *Instance; /* Register base address */ PPP_InitTypeDef Init; /* PPP communication parameters */ HAL_StateTypeDef State; /* PPP communic ation state */ (...) DMA_HandleTypeDef *hdma; /* associated DMA handle */ } PPP_HandleTypeDef; The initialization is done as follows (UART example): int main(void) { /* Set User Parameters */ UartHandle.Init.BaudRate = 9600; T_DATABITS_8; UartHandle.Init.WordLength = UAR UartHandle.Init.StopBits = UART_STOPBITS_1; UartHandle.Init.Parity = UART_PARITY_NONE; UartHandle.Init.HwFlowCtl = UART_HWCONTROL_NONE; UartHandle.Init.Mode = UART_MODE_TX_RX; UartHandle.Init.Instance = UART1; HAL_UART_Init(&UartHandle); (..) } void HAL_USART_MspInit (UART_HandleTypeDef * huart) { static DMA_HandleTypeDef hdma_tx; static DMA_HandleTypeDef hdma_rx; (...) __HAL_LINKDMA(UartHandle, DMA_Handle_tx, hdma_tx); __HAL_LINKDMA(UartHandle, DMA_Handle_rx, hdma_rx); (...) } The HAL_PPP_Process CpltCallback() function is declared as weak function in the driver that means, the user can declare it again in the application code. The function in the driver should not be modified. An example of use is illustrated below: file: main.c UART_HandleTypeDef UartHandle; int main(void) { /* Set User Paramaters */ UartHandle.Init.BaudRate = 9600; UartHandle.Init.WordLength = UART_DATABITS_8; UartHandle.Init.StopBits = UART_STOPBITS_1; UartHandle.Init.Parity = UART_PARITY_NONE; HwFlowCtl = UART_HWCONTROL_NONE; UartHandle.Init. UartHandle.Init.Mode = UART_MODE_TX_RX; UartHandle.Init.Instance = USART1; HAL_UART_Init(&UartHandle); HAL_UART_Send_DMA(&UartHandle, TxBuffer, sizeof(TxBuffer)); while (1); } void HAL_UART_TxCpltCallback(UART_HandleTypeDef *phuart) { } void HAL_UART_TxErrorCallback(UART_HandleTypeDef *phuart) { } stm32f1xx_it.c file: DocID027328 / 1166 58 Rev 2

59 UM1850 of HAL drivers Overview extern UART_HandleTypeDef UartHandle; void DMAx_IRQHandler(void) { HAL_DMA_IRQHandler(&UartHandle.DMA_Handle_tx); } should be linked in the rrorCallback() and HAL_USART_E HAL_USART_TxCpltCallback() HAL_PPP_Process_DMA() function to the DMA transfer complete callback and the DMA transfer Error callback by using the following statement: HAL_PPP_Process_DMA (PPP_HandleTypeDef *hppp, Params...) { (...) hppp - >DMA_Handl e >XferCpltCallback = HAL_UART_TxCpltCallback ; - >DMA_Handle hppp - - >XferErrorCallback = HAL_UART_ErrorCallback ; (...) } Timeout and error management 2.12.4 Timeout management 2.12.4.1 used for the APIs that operate in polling mode. It defines the delay The timeout is often during which a blocking process should wait till an error is returned. An example is provided below: HAL_StatusTypeDef HAL_DMA_PollForTransfer(DMA_HandleTypeDef *hdma, uint32_t CompleteL evel, uint32_t Timeout) The timeout possible value are the following: Table 15: Timeout values Description Timeout value 0 No poll : Immediate process check and exit (1) 1) - 1 ... (HAL_MAX_DELAY Timeout in ms HAL_MAX_DELAY Infinite poll till process is successful Notes: (1) HAL_MAX_DELAY is defined in the stm32f1xx_hal_def.h as 0xFFFFFFFF However, in some cases, a fixed timeout is used for system peripherals or internal HAL driver processes. In these cases , the timeout has the same meaning and is used in the same way, except when it is defined locally in the drivers and cannot be modified or introduced as an argument in the user application. Example of fixed timeout: #define LOCAL_PROCESS_TIMEOUT 100 HAL_ StatusTypeDef HAL_PPP_Process(PPP_HandleTypeDef) { (...) timeout = HAL_GetTick() + LOCAL_PROCESS_TIMEOUT; (...) while(ProcessOngoing) { (...) if(HAL_GetTick() >= timeout) { /* Process unlocked */ __HAL_UNLOCK(hppp); hppp >State= HAL_PPP_STATE_TIMEOUT; - _PPP_STATE_TIMEOUT; return HAL } 2 DocID027328 Rev 1166 59 /

60 Overview of HAL drivers UM1850 } (...) } The following example shows how to use the timeout inside the polling functions: HAL_PPP_StateTypeDef HAL_PPP_Poll (PPP_HandleTypeDef *hppp, uint32_t Timeout) { (...) timeout = HAL_GetTick() + Timeout; (...) while(ProcessOngoing) { (...) if(Timeout != HAL_MAX_DELAY) { if(HAL_GetTick() >= timeout) { /* Process unlocked */ __HAL_UNLOCK(hppp); hppp >State= HAL_PPP_STATE_TIMEOUT; - return hppp >State; - } } (...) } Error management 2.12.4.2 The HAL drivers implement a check for the following items: Valid parameters: for some process the used parameters should be valid and already defined, otherwise the system can crash or go into an undefined state. These critical parameters are checked befo re they are used (see example below). HAL_StatusTypeDef HAL_PPP_Process(PPP_HandleTypeDef* hppp, uint32_t *pdata, uint32 Size) { if ((pData == NULL ) || (Size == 0)) { return HAL_ERROR; } } ument since it keeps Valid handle: the PPP peripheral handle is the most important arg the PPP driver vital parameters. It is always checked in the beginning of the HAL_PPP_Init() function. HAL_StatusTypeDef HAL_PPP_Init(PPP_HandleTypeDef* hppp) { if (hppp == NULL) //the handle should be already allocated { RROR; return HAL_E } } Timeout error: the following statement is used when a timeout error occurs: while (Process ongoing) { timeout = HAL_GetTick() + Timeout; while (data processing is running) { if(timeout) { return HAL_TIMEOUT; } } HAL_PPP_Process () When an error occurs during a per returns with a ipheral process, HAL_PPP_GetError () status. The HAL PPP driver implements the to allow HAL_ERROR retrieving the origin of the error. DocID027328 / 1166 60 Rev 2

61 UM1850 of HAL drivers Overview HAL_PPP_ErrorTypeDef HAL_PPP_GetError (PPP_HandleTypeDef *hppp); HAL_PPP_ErrorTypeDef is defined and used to store the last les, a In all peripheral hand error code. typedef struct { PPP_TypeDef * Instance; /* PPP registers base address */ PPP_InitTypeDef Init; /* PPP initialization parameters */ / HAL_LockTypeDef Lock; /* PPP locking object * __IO HAL_PPP_StateTypeDef State; /* PPP state */ __IO HAL_PPP_ErrorTypeDef ErrorCode; /* PPP Error code */ (...) /* PPP specific parameters */ } PPP_HandleTypeDef; The error state and the peripheral global state are always updated before returning an : error PPP >State = HAL_PPP_READY; /* Set the peripheral ready */ - PP - >ErrorCode = HAL_ERRORCODE ; /* Set the error code */ _HAL_UNLOCK(PPP) ; /* Unlock the PPP resources */ return HAL_ERROR; /*return with HAL error */ HAL_PPP_GetError () errupt mode in the error callback: must be used in int void HAL_PPP_ProcessCpltCallback(PPP_HandleTypeDef *hspi) { ErrorCode = HAL_PPP_GetError (hppp); /* retreive error code */ } time checking - Run 2.12.4.3 The HAL implements run time failure detection by checking the input values of all HAL - - time checking is achieved by using an assert_param driver functions. The run macro. This macro is used in all the HAL driver functions which have an input parameter. It a llows verifying that the input value lies within the parameter allowed values. time checking, use the assert_param macro, and leave the define To enable the run - USE_FULL_ASSERT uncommented in stm32f1xx_hal_conf.h file. ef *huart) void HAL_UART_Init(UART_HandleTypeD { (..) /* Check the parameters */ assert_param(IS_UART_INSTANCE(huart >Instance)); - assert_param(IS_UART_BAUDRATE(huart - >Init.BaudRate)); >Init.WordLength)); - assert_param(IS_UART_WORD_LENGTH(huart assert_param(IS_UART_STOPBITS(huart - >Init.StopBit s)); >Init.Parity)); assert_param(IS_UART_PARITY(huart - - >Init.Mode)); assert_param(IS_UART_MODE(huart >Init.HwFlowCtl)); - assert_param(IS_UART_HARDWARE_FLOW_CONTROL(huart (..) /** @defgroup UART_Word_Length * @{ */ 00000) #define UART_WORDLENGTH_8B ((uint32_t)0x000 #define UART_WORDLENGTH_9B ((uint32_t)USART_CR1_M) #define IS_UART_WORD_LENGTH(LENGTH) (((LENGTH) == UART_WORDLENGTH_8B) || ((LENGTH) == UART_WORDLENGTH_9B)) \ function is assert_failed If the expression passed to the assert_param macro is false, the called and returns the name of the source file and the source line number of the call that failed. If the expression is true, no value is returned. 2 DocID027328 Rev 1166 61 /

62 of HAL drivers Overview UM1850 macro is implemented in stm32f1xx_hal_conf.h: assert_param The ------------------------------------------------------------ /* Exported macro */ #ifdef USE_FULL_ASSERT /** * @brief The assert_param macro is used for function's parameters check. * @param expr: If expr is false, it calls assert_failed function * which reports the name of the source file and the source * line number of the call that failed. * If expr is true, it returns no value. * @retval None */ #define assert_param(expr) ((expr)?(void)0:assert_failed((uint8_t *)__FILE__, __LINE__)) */ --------------------- ----------------- /* Exported functions void assert_failed(uint8_t* file, uint32_t line); #else #define assert_param(expr)((void)0) #endif /* USE_FULL_ASSERT */ assert_failed The function is implemented in the main.c file or in any other user C file: #ifdef USE_FULL_ASSE RT /** * @brief Reports the name of the source file and the source line number * where the assert_param error has occurred. * @param file: pointer to the source file name * @param line: assert_param error line source number * @retval None */ void assert_fa iled(uint8_t* file, uint32_t line) { /* User can add his own implementation to report the file name and line number, r \ ex: printf("Wrong parameters value: file %s on line %d n", file, line) */ \ /* Infinite loop */ while (1) { } } time checking introduces, it is recommended - run Because of the overhead to use it during application code development and debugging, and to remove it from the final application to improve code size and speed. DocID027328 / 1166 62 Rev 2

63 Overview UM1850 of Low Layer drivers 3 Overview of Low Layer drivers - weight expert - The Low Layer (LL) drivers are designed to offer a fast light oriented layer which is closer to the hardware than the HAL. Contrary to the HAL, LL APIs are not provided for peripherals where optimized access is not a key feature, or those re quiring level stack (such as FSMC, USB or - heavy software configuration and/or complex upper SDMMC). The LL drivers feature: A set of functions to initialize peripheral main features according to the parameters specified in data structures ons used to fill initialization data structures with the reset values of each A set of functi field - Functions to perform peripheral de initialization (peripheral registers restored to their default values) A set of inline functions for direct and atomic register access Full independence from HAL since LL drivers can be used either in standalone mode (without HAL drivers) or in mixed mode (with HAL drivers) Full coverage of the supported peripheral features. ilable features of the The Low Layer drivers provide hardware services based on the ava STM32 peripherals. These services reflect exactly the hardware capabilities and provide shot operations that must be called following the programming model described in the - one microcontroller line reference manual. As a result, the LL services do not implement any processing and do not require any additional memory resources to save their states, counter or data pointers: all the operations are performed by changing the associated peripheral registers content. 3.1 Low Layer files The Low Layer drivers are built around header/C files (one per each supported peripheral) plus five header files for some System and Cortex related features. Table 16: LL driver files Description File This is the h source file for core bus control and peripheral clock - activation and deactivation stm32f1xx_ll_bus.h Example: LL_AHB2_GRP1_EnableClock stm32f1xx_ll_ppp.c provides peripheral initialization functions such as it(), LL_PPP_DeInit(). All the other APIs LL_PPP_Init(), LL_PPP_StructIn are definined within stm32f1xx_ll_ppp.h file. stm32f1xx_ll_ppp.h/.c The Low Layer PPP driver is a standalone module. To use it, the application must include it in the xx_ll_ppp.h file. operation APIs including the Systick, Low Cortex - M related register stm32f1 xx_ll_cortex.h power (LL_SYSTICK_xxxxx, LL_LPM_xxxxx "Low Power Mode" ...) This file covers the generic APIs: Read of device unique ID and electronic signature xx_ll_utils.h/.c stm32f1 Timebase and delay management System clock configuration. System related operations (LL_SYSCFG_xxx, LL_DBGMCU_xxx, xx_ll_system.h stm32f1 LL_FLASH_xxx and LL_VREFBUF_xxx) 2 DocID027328 Rev 1166 63 /

64 Overview UM1850 of Low Layer drivers Description File Template file allowing to define the assert_param macro, that is used ing is enabled. time check - when run stm32_assert_template.h This file is required only when the LL drivers are used in standalone mode (without calling the HAL APIs). It should be copied to the application folder and renamed to stm32_assert.h. . There is no configuration file for the LL drivers The Low Layer files are located in the same HAL driver folder. : Low Layer driver folders 8 Figure In general, Low Layer drivers include only the STM32 CMSIS device file. #include "stm32yyxx.h" DocID027328 / 1166 64 Rev 2

65 UM1850 of Low Layer drivers Overview : Low Layer driver CMSIS files 9 Figure Application files have to include only the used Low Layer driver header files. 3.2 Overview of Low Layer APIs and naming rules 3.2.1 Peripheral initialization functions The LL drivers offer three set of initialization functions. They are defined in stm32f1xx_ll_ppp.c file: Functions to initialize peripheral main features according to the parameters specified in data structures ialization data structures with the reset values of each A set of functions used to fill init field initialization (peripheral registers restored to their default - Function for peripheral de values) The definition of these LL initialization functions and associated resources (structure, . To literals and prototypes) is conditioned by a compilation switch: USE_FULL_LL_DRIVER use these functions, this switch must be added in the toolchain compiler prepro cessor or to any generic header file which is processed before the LL drivers. The below table shows the list of the common functions provided for all the supported peripherals: 2 DocID027328 Rev 1166 65 /

66 Overview UM1850 of Low Layer drivers Table 17: Common peripheral initialization functions Return Functions Description Parameters Type Initializes the peripheral main features PPP_TypeDef* according to the parameters specified in PPPx PPP_InitStruct. LL_PPP_InitType ErrorStatus LL_PPP_Init Example: Def* LL_USART_Init(USART_TypeDef PPP_InitStruct itTypeDef *USARTx, LL_USART_In *USART_InitStruct) Fills each PPP_InitStruct member with its LL_PPP_InitType default value. LL_PPP_ Def* void Example. StructInit PPP_InitStruct LL_USART_StructInit(LL_USART_InitType Def *USART_InitStruct) initializes the peripheral registers, that - De is restore them to their default reset values. PPP_TypeDef* LL_PPP_ ErrorStatus Example. PPPx DeInit LL_USART_DeInit(USART_TypeDef *USARTx) : "Optional Table 18 Additional functions are available for some peripherals (refer to peripheral initialization functions" ) . DocID027328 / 1166 66 Rev 2

67 UM1850 of Low Layer drivers Overview Table 18: Optional peripheral initialization functions Return Parameters Examples Functions Type Initializes peripheral features according to the parameters specified in PPP_InitStruct. Example: LL_ADC_INJ_Init(ADC_Type Def *ADCx, LL_ADC_INJ_InitTypeDef *ADC_INJ_InitStruct) LL_RTC_TIME_Init(RTC_Typ eDef *RTCx, uint32_t RTC_Format, PPP_TypeDef* PPPx LL_RTC_Ti meTypeDef LL_PPP{_ *RTC_TimeStruct) CATEGORY}_Init Error LL_PPP{_CATEGORY} TypeDef* Status _Init PPP{_CATEGORY}_ LL_RTC_DATE_Init(RTC_Typ InitStruct eDef *RTCx, uint32_t RTC_Format, LL_RTC_DateTypeDef *RTC_DateStruct) LL_TIM_IC_Init(TIM_TypeDef * TIMx, uint32_t Channel, LL_TIM_IC_InitTypeDef* TIM_IC_InitStruct) LL_TIM_ENCODER_Init(TIM_ TypeDef* TIMx, LL_TIM_ENCODER_InitType Def* TIM_EncoderInitStruct) Fills each PPP{_CATEGORY}_InitStruct member with its default value. LL_PPP{_CATEGORY}_ InitTypeDef* LL_PPP{_CATEGORY} void PPP{_CATEGORY}_ _StructInit Example: InitStruct LL_ADC_INJ_StructInit(LL_A _InitTypeDef DC_INJ *ADC_INJ_InitStruct) Initializes the common features shared between different instances of the PPP_TypeDef* PPPx same peripheral. LL_PPP_CommonInit Error TypeDef* LL_PPP_CommonInit Example: Status PPP_CommonInit LL_ADC_CommonInit(ADC_C Struct ommon_TypeDef *ADCxy_COMMON, LL_ADC_CommonInitTypeDef *ADC_CommonInitStruct) 67 DocID027328 1166 / 2 Rev

68 of Low Layer drivers Overview UM1850 Return Parameters Functions Examples Type Fills each PPP_CommonInitStruct member with its default value LL_PPP_CommonInitType LL_PPP_Common Def* void StructInit Example: PPP_CommonInitStruct LL_ADC_CommonStructInit(L L_ADC_CommonInitTypeDef *ADC_CommonInitStruct) Initializes the peripheral clock configuration in synchronous mode. PPP_TypeDef* PPPx LL_PPP_ClockInit Error LL_PPP_ClockInit TypeDef* Example: Status PPP_ClockInitStruct ockInit(USART LL_USART_Cl _TypeDef *USARTx, LL_USART_ClockInitTypeDef *USART_ClockInitStruct) Fills each PPP_ClockInitStruct member with its default value LL_PPP_ClockInitTypeDef* void LL_PPP_ClockStructInit Example: PPP_ClockInitStruct LL_USART_ClockStructInit(LL _USART_ClockInitTypeDef *USART_ClockInitStruct) - 3.2.1.1 time checking Run time failure detection by Like HAL drivers, LL initialization functions implement run - Section river functions. For more details please refer to checking the input values of all LL d . 2.12.4.3: "Run - time checking" When using the LL drivers in standalone mode (without calling HAL functions), the ing: time check - following actions are required to use run 1. Copy stm32_assert_template.h to the application folder and rename it to - stm32_assert.h. This file defines the assert_param macro which is used when run time checking is enabled. Include stm32_assert.h file within the application main header file. 2. 3. the USE_FULL_ASSERT compilation switch in the toolchain compiler Add preprocessor or in any generic header file which is processed before the stm32_assert.h driver. time checking is not available for LL inline functions. - Run DocID027328 / 1166 68 Rev 2

69 UM1850 of Low Layer drivers Overview configuration functions level 3.2.2 Peripheral register - On top of the peripheral initialization functions, the LL drivers offer a set of inline functions for direct atomic register access. Their format is as follows: LL_PPP_Function (PPPx_TypeDef *PPPx, args) __STATIC_INLINE return_type The “Function” naming is defined depending to the action category: Specific Interrupt, DMA request and status flags management : Set/Get/Clear/Enable/Disable flags on interrupt and status registers Table 19: Speci fic Interrupt, DMA request and status flags management Name Examples LL_RCC_IsActiveFlag_LSIRDY LL_RCC_IsActiveFlag_FWRST() LL_PPP_{_CATEGORY}_ActionItem_BITNAME LL_ADC_ClearFlag_EOC(ADC1) LL_PPP{_CATEGORY}_IsItem_BITNAME_Action LL_DMA_ClearFlag_TCx(DMA_TypeDef* DMAx) Table 20: Available function formats Format Action Item LL_PPP_IsActiveFlag_BITNAME Get Flag LL_PPP_ClearFlag_BITNAME Clear LL_PPP_EnableIT_BITNAME Enable LL_PPP_DisableIT_BITNAME Disable Interrupts LL_PPP_IsEnabledIT_BITNAME Get LL_PPP_EnableDMAReq_BITNAME Enable LL_PPP_DisableDMAReq_BITNAME DMA Disable LL_PPP_IsEnabledDMAReq_BITNAME Get BITNAME refers to the peripheral register bit name as described in the product line reference manual. : Enable/Disable/Reset a Peripheral clock activation/deactivation management peripheral clock Table 21: Peripheral clock activation/deactivation management Examples Name LL_AHB2_GRP1_EnableClock (LL_AHB2_GRP1_PERIPH_GPIOA|LL_AHB2_GRP1_PERIPH_GP IOB) LL_BUS_GRPx_ActionClock{Mode} by LL_APB1_GRP1_EnableClockSleep (LL_APB1_GRP1_PERIPH_DAC1) 2 DocID027328 Rev 1166 69 /

70 Overview UM1850 of Low Layer drivers 'x' corresponds to the group index and refers to the index of the modified register on a given bus. Peripheral activation/deactivation management : Enable/disable a peripheral or activate/deactivate specific peripheral features Table 22: Peripheral activation/deactivation management Examples Name LL_ADC_Enable () LL_ADC_StartCalibration(); LL_PPP{_CATEGORY}_Action{Item} LL_ADC_IsCalibrationOnGoing; LL_PPP{_CATEGORY}_IsItemAction LL_RCC_HSI_Enable () LL_RCC_HSI_IsReady() : Set/get a peripheral configuration settings Peripheral configuration management Table 23: Peripheral configuration management Name Examples LL_USART_SetBaudRate (USART2, Clock, LL_PPP{_CATEGORY}_Set{ or LL_USART_BAUDRATE_9600) Get}ConfigItem : Write/read the content of a register/retrun DMA Peripheral register management relative register address Table 24: Peripheral register management Name LL_PPP_WriteReg(__INSTANCE__, __REG__, __VALUE__) LL_PPP_ReadReg(__INSTANCE__, __REG__) LL_PPP_DMA_GetRegAddr (PPP_TypeDef *PPPx,{Sub Instance if any ex: Channel} , {uint32_t Propriety}) The Propriety is a variable used to identify the DMA transfer direction or the data register type. DocID027328 / 1166 70 Rev 2

71 UM1850 of HAL and LL Cohabiting Cohabiting of HAL and LL 4 The Low Layer is designed to be used in standalone mode or combined with the HAL. It cannot be automatically used with the HAL for the same peripheral instance. If you use the LL APIs for a specific instance, you can still use the HAL APIs for other instan ces. Be careful that the Low Layer might overwrite some registers which content is mirrored in the HAL handles. Low Layer driver used in standalone mode 4.1 The Low Layer APIs can be used without calling the HAL driver services. This is done by simply including stm32f1xx_ll_ppp.h in the application files. The LL APIs for a given peripheral are called by executing the same sequence as the one recommended by the programming model in the corresponding product lin e reference manual. In this case the HAL drivers associated to the used peripheral can be removed from the workspace. However the STM32CubeF1 framework should be used in the same way as in the HAL CMSIS should always be used. drivers case which means that System file, startup file and When the BSP drivers are included, the used HAL drivers associated with the BSP functions drivers should be included in the workspace, even if they are not used by the application layer. HAL drivers Mixed use of Low Layer APIs and 4.2 In this case the Low Layer APIs are used in conjunction with the HAL drivers to achieve direct and register level based operations. into account: Mixed use is allowed, however some consideration should be taken It is recommended to avoid using simultaneously the HAL APIs and the combination of Low Layer APIs for a given peripheral instance. If this is the case, one or more private fields in the HAL PPP handle structure should be updated accordingly. For operations and processes that do not alter the handle fields including the initialization structure, the HAL driver APIs and the Low Layer services can be used together for the same peripheral instance. striction with all the HAL drivers that The Low Layer drivers can be used without any re are not based on handle objects (RCC, common HAL, flash and GPIO). Several examples showing how to use HAL and LL in the same application are provided within stm32f1 firmware package (refer to Examples_MIX projects). 1. When the HAL Init/DeInit APIs are not used and are replaced by the Low Layer macros, the InitMsp() functions are not called and the MSP initialization should be done in the user application. is 2. When process APIs are not used and the corresponding function performed through the Low Layer APIs, the callbacks are not called and post processing or error management should be done by the user application. 3. When the LL APIs is used for process operations, the IRQ handler HAL APIs ould be implemented by the user application. cannot be called and the IRQ sh Each LL driver implements the macros needed to read and clear the associated interrupt flags. 2 DocID027328 Rev 1166 71 /

72 System Driver HAL UM1850 HAL System Driver 5 HAL Firmware driver API description 5.1 5.1.1 How to use this driver The common HAL driver contains a set of generic and common APIs that can be used by the PPP peripheral drivers and the user to start using the HAL. contains two APIs' categories: The HAL Common HAL APIs Services HAL APIs 5.1.2 Initialization and de - initialization functions This section provides functions allowing to: Initializes the Flash interfac e, the NVIC allocation and initial clock configuration. It initializes the source of time base also when timeout is needed and the backup domain when enabled. de Initializes common part of the HAL. - a dedicated Tick interrupt Configure The time base source to have 1ms time base with priority. Systick timer is used by default as source of time base, but user can eventually implement his proper time base source (a general purpose timer for example or other time source), keeping in mind that Time base duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and handled in milliseconds basis. Time base configuration function (HAL_InitTick ()) is called automatically at the beginning of the program after reset by HAL_Init() or at any time when clock is co nfigured, by HAL_RCC_ClockConfig(). Source of time base is configured to generate interrupts at regular time intervals. Care must be taken if HAL_Delay() is called from a peripheral ISR process, the ly lower) than the Tick interrupt line must have higher priority (numerical peripheral interrupt. Otherwise the caller ISR process will be blocked. functions affecting time base configurations are declared as __weak to make override possible in case of other implementations in user file. This section contains t he following APIs: HAL_Init() HAL_DeInit() HAL_MspInit() HAL_MspDeInit() HAL_InitTick() HAL 5.1.3 Control functions This section provides functions allowing to: Provide a tick value in millisecond Provide a blocking delay in millisecond Suspend the time base source interrupt Resume the time base source interrupt Get the HAL API driver version Get the device identifier DocID027328 / 1166 72 Rev 2

73 UM1850 System Driver HAL Get the device revision identifier Enable/Disable Debug module during SLEEP mode Enable/Disable Debug module during STOP mode Enable/Disable Debug module during STANDBY mode ontains the following APIs: This section c HAL_IncTick() HAL_GetTick() HAL_Delay() HAL_SuspendTick() esumeTick() HAL_R HAL_GetHalVersion() HAL_GetREVID() HAL_GetDEVID() HAL_DBGMCU_EnableDBGSleepMode() HAL_DBGMCU_DisableDBGSleepMode() HAL_DBGMCU_EnableDBGStopMode() HAL_DBGMCU_DisableDBGStopMode() e() HAL_DBGMCU_EnableDBGStandbyMod HAL_DBGMCU_DisableDBGStandbyMode() HAL_GetUID() Detailed description of functions 5.1.4 HAL_Init HAL_StatusTypeDef HAL_Init (void ) Function name Function description This function is used to initialize the HAL Library; it must be the first instruction to be executed in the main program (before to call any other HAL function), it performs the following: Configure the Flash prefetch. Return values HAL: tus sta Notes SysTick is used as time base for the HAL_Delay() function, the application need to ensure that the SysTick time base is always set to 1 millisecond to have correct HAL operation. HAL_DeInit HAL_StatusTypeDef HAL_DeInit (void ) Function name - This function de nction description Fu Initializes common part of the HAL and stops the source of time base. Return values status HAL: Notes This function is optional. HAL_MspInit void HAL_MspInit (void ) Function name Function description Initializes the MSP. Return values None: 2 DocID027328 Rev 1166 73 /

74 HAL UM1850 System Driver HAL_MspDeInit void HAL_MspDeInit (void ) Function name Function description DeInitializes the MSP. Return values None: HAL_InitTick HAL_StatusTypeDef HAL_InitTick (uint32_t TickPriority) Function name This function configures the source of the time base. Function description Parameters Tick interrupt priority. TickPriority: Return values HAL: status Notes This function is called automatically at the beginning of program after reset by HAL_Init() or at any time when clock is reconfigured by HAL_RCC_ClockConfig(). In the default implementation, SysTick timer is the source of time base. It is used to generate interrupts at regular time intervals. Care must be taken if HAL_Delay() is called from a per ipheral ISR process, The the SysTick interrupt must have higher priority (numerically lower) than the peripheral interrupt. Otherwise the caller ISR process will be blocked. The function is declared as __weak to be overwritten in case on in user file. of other implementati HAL_IncTick void HAL_IncTick (void ) Function name This function is called to increment a global variable "uwTick" used Function description as application time base. Return values None: Notes able is incremented In the default implementation, this vari each 1ms in Systick ISR. This function is declared as __weak to be overwritten in case of other implementations in user file. HAL_Delay void HAL_Delay (__IO uint32_t Delay) Function name Function description This function provides minimum delay (in milliseconds) based on variable incremented. Parameters Delay: specifies the delay time length, in milliseconds. Return values None: Notes In the default implementation , SysTick timer is the source of se. It is used to generate interrupts at regular time time ba intervals where uwTick is incremented. This function is declared as __weak to be overwritten in case of other implementations in user file. DocID027328 / 1166 74 Rev 2

75 UM1850 HAL System Driver HAL_GetTick uint32_t HAL_GetTick (void ) Function name Provides a tick value in millisecond. Function description Return values tick: value Notes This function is declared as __weak to be overwritten in case of other implementations in user file. HAL_SuspendTick void HAL_SuspendTick (void ) Function name Suspend Tick increment. Function description Return values None: Notes In the default implementation , SysTick timer is the source of time base. It is used to generate interrupts at regular time intervals. Once HAL_SuspendTick() is called, the SysTick interrupt will be disabled and so Tick increment is suspended. This function is declared as __weak to be overwritten in case of other implementations in user file. HAL_ResumeTick void HAL_ResumeTick (void ) Function name increment. Function description Resume Tick Return values None: Notes In the default implementation , SysTick timer is the source of time base. It is used to generate interrupts at regular time intervals. Once HAL_ResumeTick() is called, the SysTick interrupt will be enabled and so T ick increment is resumed. This function is declared as __weak to be overwritten in case of other implementations in user file. HAL_GetHalVersion uint32_t HAL_GetHalVersion (void ) Function name Returns the HAL revision. Function description Return values version: : 0xXYZR (8bits for each decimal, R for RC) HAL_GetREVID uint32_t HAL_GetREVID (void ) Function name Function description Returns the device revision identifier. Return values Device: revision identifier HAL_GetDEVID nt32_t HAL_GetDEVID (void ) ui Function name Rev 2 1166 75 DocID027328 /

76 System Driver HAL UM1850 Returns the device identifier. Function description Return values identifier Device: HAL_DBGMCU_EnableDBGSleepMode void HAL_DBGMCU_EnableDBGSleepMode (void ) Function name Enable the Debug Module during SLEEP mode. Function description Return values None: HAL_DBGMCU_DisableDBGSleepMode void HAL_DBGMCU_DisableDBGSleepMode (void ) Function name Disable the Debug Module during SLEEP mode Note: On devices Function description STM32F10xx8 and STM32F10xxB, STM32F101xC/D/E and STM32F103xC/D/E, STM32F101xF/G and STM32F103xF/G STM32F10xx4 and STM32F10xx6 Debug registers DBGMCU_IDCODE and DBGMCU_CR are accessible only in ug mode (not accessible by the user software in normal mode). deb Return values None: HAL_DBGMCU_EnableDBGStopMode void HAL_DBGMCU_EnableDBGStopMode (void ) Function name Function description Enable the Debug Module during STOP mode Note: On devices F10xx8 and STM32F10xxB, STM32F101xC/D/E and STM32 STM32F103xC/D/E, STM32F101xF/G and STM32F103xF/G STM32F10xx4 and STM32F10xx6 Debug registers DBGMCU_IDCODE and DBGMCU_CR are accessible only in debug mode (not accessible by the user software in normal mode). eturn values R None: HAL_DBGMCU_DisableDBGStopMode void HAL_DBGMCU_DisableDBGStopMode (void ) Function name Function description Disable the Debug Module during STOP mode Note: On devices STM32F10xx8 and STM32F10xxB, STM32F101xC/D/E and STM32F103xC/D/E, STM32F101xF/G and STM32F103xF/G STM32F10xx4 and STM32F10xx6 Debug registers DBGMCU_IDCODE and DBGMCU_CR are accessible only in debu g mode (not accessible by the user software in normal mode). Return values None: HAL_DBGMCU_EnableDBGStandbyMode void HAL_DBGMCU_EnableDBGStandbyMode (void ) Function name Enable the Debug Module during STANDBY mode Note: On Function description es STM32F10xx8 and STM32F10xxB, STM32F101xC/D/E devic and STM32F103xC/D/E, STM32F101xF/G and STM32F103xF/G STM32F10xx4 and STM32F10xx6 Debug registers DocID027328 / 1166 76 Rev 2

77 System Driver UM1850 HAL DBGMCU_IDCODE and DBGMCU_CR are accessible only in debug mode (not accessible by the user software in normal mo de). Return values None: HAL_DBGMCU_DisableDBGStandbyMode void HAL_DBGMCU_DisableDBGStandbyMode (void ) Function name Function description Disable the Debug Module during STANDBY mode Note: On devices STM32F10xx8 and STM32F10xxB, STM32F101xC/D/E and STM32F103xC/D/E, STM32F101xF/G and STM32F103xF/G STM32F10xx4 and STM32F10xx6 Debug registers DBGMCU_IDCODE and DBGMCU_CR are accessible only in d ebug mode (not accessible by the user software in normal mode). Return values None: HAL_GetUID void HAL_GetUID (uint32_t * UID) Function name Return the unique device identifier (UID based on 96 bits) Function description Parameters UID: pointer to 3 words array. Return values Device: identifier 5.2 HAL Firmware driver defines HAL 5.2.1 Freeze Unfreeze Peripherals in Debug mode __HAL_DBGMCU_FREEZE_TIM2 __HAL_DBGMCU_UNFREEZE_TIM2 __HAL_DBGMCU_FREEZE_TIM3 __HAL_DBGMCU_UNFREEZE_TIM3 __HAL_DBGMCU_FREEZE_TIM4 __HAL_DBGMCU_UNFREEZE_TIM4 __HAL_DBGMCU_FREEZE_TIM5 __HAL_DBGMCU_UNFREEZE_TIM5 __HAL_DBGMCU_FREEZE_TIM6 __HAL_DBGMCU_UNFREEZE_TIM6 __HAL_DBGMCU_FREEZE_TIM7 __HAL_DBGMCU_UNFREEZE_TIM7 __HAL_DBGMCU_FREEZE_TIM12 __HAL_DBGMCU_UNFREEZE_TIM12 __HAL_DBGMCU_FREEZE_TIM13 2 DocID027328 Rev 1166 77 /

78 HAL UM1850 System Driver __HAL_DBGMCU_UNFREEZE_TIM13 __HAL_DBGMCU_FREEZE_TIM14 __HAL_DBGMCU_UNFREEZE_TIM14 __HAL_DBGMCU_FREEZE_WWDG __HAL_DBGMCU_UNFREEZE_WWDG __HAL_DBGMCU_FREEZE_IWDG __HAL_DBGMCU_UNFREEZE_IWDG __HAL_DBGMCU_FREEZE_I2C1_TIMEOUT __HAL_DBGMCU_UNFREEZE_I2C1_TIMEOUT __HAL_DBGMCU_FREEZE_I2C2_TIMEOUT __HAL_DBGMCU_UNFREEZE_I2C2_TIMEOUT __HAL_DBGMCU_FREEZE_CAN1 __HAL_DBGMCU_UNFREEZE_CAN1 __HAL_DBGMCU_FREEZE_TIM1 __HAL_DBGMCU_UNFREEZE_TIM1 __HAL_DBGMCU_FREEZE_TIM8 __HAL_DBGMCU_UNFREEZE_TIM8 __HAL_DBGMCU_FREEZE_TIM9 __HAL_DBGMCU_UNFREEZE_TIM9 __HAL_DBGMCU_FREEZE_TIM10 __HAL_DBGMCU_UNFREEZE_TIM10 __HAL_DBGMCU_FREEZE_TIM11 __HAL_DBGMCU_UNFREEZE_TIM11 DocID027328 / 1166 78 Rev 2

79 UM1850 ADC Generic Driver HAL 6 HAL ADC Generic Driver 6.1 ADC Firmware driver registers structures ADC_InitTypeDef 6.1.1 Data Fields uint32_t DataAlign uint32_t ScanConvMode uint32_t ContinuousConvMode uint32_t NbrOfConversion uint32_t DiscontinuousConvMode uint32_t NbrOfDiscConversion uint32_t ExternalTrigConv Field Documentation uint32_t ADC_InitTypeDef::DataAlign Specifies ADC data alignment to right (MSB on register bit 11 and LSB on register bit 0) (default setting) or to left (if regular group: MSB on register bit 15 and LSB on register bit 4, if injected group (MSB kept as signed value due to potential negative value after offset application): MSB on register bit 14 and LSB on register bit 3). This parameter can be a value of ADC_Data_align uint32_t ADC_InitTypeDef::ScanConvMode Configures the sequencer of regular and injected gr oups. This parameter can be associated to parameter 'DiscontinuousConvMode' to have main sequence subdivided in successive parts. If disabled: Conversion is performed in single mode (one channel converted, the one defined in rank 1). Parameters 'NbrOfConve rsion' and 'InjectedNbrOfConversion' are discarded (equivalent to set to 1). If enabled: Conversions are performed in sequence mode (multiple ranks defined by 'NbrOfConversion'/'InjectedNbrOfConversion' and each channel rank). Scan direction is upward: fro ADC_Scan_mode m rank1 to rank 'n'. This parameter can be a value of Note: For regular group, this parameter should be enabled in conversion either by polling (HAL_ADC_Start with Discontinuous mode and NbrOfDiscConversion=1) or by DMA (HAL_ADC_Start_DMA), but not by interruption (HAL_ADC_Start_IT): in scan mode, interruption is triggered only on the the last conversion of the sequence. All previous conversions would be overwritten by the last one. Injected group used with sca n mode has not this constraint: each rank has its own result register, no data is overwritten. uint32_t ADC_InitTypeDef::ContinuousConvMode Specifies whether the conversion is performed in single mode (one conversion) or after the selected trigger occurred (software start continuous mode for regular group, or external trigger). This parameter can be set to ENABLE or DISABLE. uint32_t ADC_InitTypeDef::NbrOfConversion Specifies the number of ranks that will be converted within the regular group o use regular group sequencer and convert several ranks, parameter sequencer. T 'ScanConvMode' must be enabled. This parameter must be a number between Min_Data = 1 and Max_Data = 16. uint32_t ADC_InitTypeDef::DiscontinuousConvMode Specifies whether the conversions se quence of regular group is performed in Complete sequence (main sequence subdivided in - sequence/Discontinuous - successive parts). Discontinuous mode is used only if sequencer is enabled (parameter 'ScanConvMode'). If sequencer is disabled, this parameter is discarded. 2 DocID027328 Rev 1166 79 /

80 HAL UM1850 ADC Generic Driver Discontinuous mode can be enabled only if continuous mode is disabled. If continuous mode is enabled, this parameter setting is discarded. This parameter can be set to ENABLE or DISABLE. uint32_t ADC_InitTypeDef::NbrOfDiscConversion Specifies the number of discontinuous conversions in which the main sequence of regular group (parameter NbrOfConversion) will be subdivided. If parameter 'DiscontinuousConvMode' is disabled, this parameter is discarded. This parameter ata = 1 and Max_Data = 8. must be a number between Min_D uint32_t ADC_InitTypeDef::ExternalTrigConv Selects the external event used to trigger the conversion start of regular group. If set to ADC_SOFTWARE_START, external triggers are disabled. If set to external trigger ing is on event rising edge. This parameter can be a value of source, trigger ADC_External_trigger_source_Regular ADC_ChannelConfTypeDef 6.1.2 Data Fields uint32_t Channel uint32_t Rank plingTime uint32_t Sam Field Documentation uint32_t ADC_ChannelConfTypeDef::Channel Specifies the channel to configure into ADC regular group. This parameter can be a value of Note: Depending on devices, some channels may not be ADC_channels available on package pins. Refer to device datasheet for channels availability. Note: On STM32F1 devices with several ADC: Only ADC1 can access internal measurement channels (VrefInt/TempSensor) Note: O n STM32F10xx8 and STM32F10xxB devices: A low - amplitude voltage glitch may be generated (on ADC input 0) on the PA0 pin, when the ADC is converting with injection trigger. It is advised to distribute the analog channels so that Channel 0 is configured as an injected channel. Refer to errata sheet of these devices for more details. uint32_t ADC_ChannelConfTypeDef::Rank Specifies the rank in the regular group sequencer This parameter can be a value of ADC_regular_rank Note: In case of need to disable a channel or change order of conversion sequencer, rank containing a previous channel setting can be overwritten by the new channel setting (or parameter number of conversions can be adjusted) lingTime uint32_t ADC_ChannelConfTypeDef::Samp Sampling time value to be set for the selected channel. Unit: ADC clock cycles Conversion time is the addition of sampling time and processing time (12.5 ADC clock cycles at ADC resolution 12 bits). This parameter can be a value of ADC_sampling_times Caution: This parameter updates the parameter property of the channel, that can be used into regular and/or injected groups. If this same channel will be updated has been previously configured in the other group (regular/injected), it to last setting. Note: In case of usage of internal measurement channels (VrefInt/TempSensor), sampling time constraints must be respected (sampling time can be adjusted in function of ADC clock frequency and sampling time setting) Refer device datasheet for timings values, parameters TS_vrefint, TS_temp (values rough to order: 5us to 17.1us min). ADC_AnalogWDGConfTypeDef 6.1.3 Data Fields uint32_t WatchdogMode uint32_t Channel DocID027328 / 1166 80 Rev 2

81 UM1850 HAL ADC Generic Driver uint32_t ITMode uint 32_t HighThreshold uint32_t LowThreshold uint32_t WatchdogNumber Field Documentation uint32_t ADC_AnalogWDGConfTypeDef::WatchdogMode Configures the ADC analog watchdog mode: single/all channels, regular/injected . group. This parameter can be a value of ADC_analog_watchdog_mode uint32_t ADC_AnalogWDGConfTypeDef::Channel Selects which ADC channel to monitor by analog watchdog. This parameter has an effect only if watchdog mode is configured on single channel (parameter ADC_channels WatchdogMode) This parameter can be a value of . DC_AnalogWDGConfTypeDef::ITMode uint32_t A Specifies whether the analog watchdog is configured in interrupt or polling mode. This parameter can be set to ENABLE or DISABLE uint32_t ADC_AnalogWDGConfTypeDef::HighThreshold Configures the ADC analog watchdog High thres hold value. This parameter must be a number between Min_Data = 0x000 and Max_Data = 0xFFF. uint32_t ADC_AnalogWDGConfTypeDef::LowThreshold Configures the ADC analog watchdog High threshold value. This parameter must be a d Max_Data = 0xFFF. number between Min_Data = 0x000 an uint32_t ADC_AnalogWDGConfTypeDef::WatchdogNumber Reserved for future use, can be set to 0 6.1.4 ADC_HandleTypeDef Data Fields ADC_TypeDef * Instance ADC_InitTypeDef Init DMA_HandleTypeDef * DMA_Han dle HAL_LockTypeDef Lock __IO uint32_t State __IO uint32_t ErrorCode Field Documentation ADC_TypeDef* ADC_HandleTypeDef::Instance Register base address ADC_InitTypeDef ADC_HandleTypeDef::Init ADC required parameters ADC_HandleTypeDef::DMA_Handle DMA_HandleTypeDef* Pointer DMA Handler HAL_LockTypeDef ADC_HandleTypeDef::Lock ADC locking object __IO uint32_t ADC_HandleTypeDef::State ADC communication state (bitmap of ADC states) __IO uint32_t ADC_HandleTypeDef::ErrorCode ADC Error code 6.2 ADC Firmware driver API description 6.2.1 ADC peripheral features - 12 bit resolution 2 DocID027328 Rev 1166 81 /

82 HAL UM1850 ADC Generic Driver Interrupt generation at the end of regular conversion, end of injected conversion, and in case of analog watchdog or overrun events. Single and continuous conversion modes. Scan mode for conversion of several channels sequentially. Data alignment with in - built data coherency. Programmable sampling time (channel wise) ADC conversion of regular group and injected group. External trigger (timer or EXTI) for both regular and injected groups. DMA request generation for transfer of conversions data of regular group. Multimode Dual mode (available on devices with 2 ADCs or more). Configurable DMA data storage in Multimode Dual mode (available on devices with 2 DCs or more). Configurable delay between conversions in Dual interleaved mode (available on devices with 2 DCs or more). ADC calibration V to 3.6 V at slower V at full speed and down to 1.8 ADC supply requirements: 2.4 speed. ADC input range: from Vref (connected to Vssa) to Vref+ (connected to Vdda or to an - external voltage reference). 6.2.2 How to use this driver Configur ation of top level parameters related to ADC 1. Enable the ADC interface As prerequisite, ADC clock must be configured at RCC top level. Caution: On STM32F1, ADC clock frequency max is 14MHz (refer to device datasheet). Therefore, ADC clock prescaler must be configured in function of ADC clock source frequency to remain below this maximum frequency. One clock setting is mandatory: ADC clock (core clock, also possibly conversion clock). Example: Into HAL_ADC_MspInit() (recommended code location) or with device clock parameters configuration: other RCC_PeriphCLKInitTypeDef PeriphClkInit; __ADC1_CLK_ENABLE(); PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC; PeriphClkInit.AdcClockSelection = RCC_ADCPCLK2_DIV2; HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit); ADC pins configuration 2. Enable the clock for the ADC GPIOs using macro __HAL_RCC_GPIOx_CLK_ENABLE() Configure these ADC pins in analog mode using function HAL_GPIO_Init() Optionally, in case of usage of ADC with interruptions: 3. using function HAL_NVIC_EnableIRQ(ADCx_IRQn) Configure the NVIC for ADC Insert the ADC interruption handler function HAL_ADC_IRQHandler() into the function of corresponding ADC interruption vector ADCx_IRQHandler(). 4. Optionally, in case of usage of DMA: el, mode normal or circular, ...) using function Configure the DMA (DMA chann HAL_DMA_Init(). Configure the NVIC for DMA using function HAL_NVIC_EnableIRQ(DMAx_Channelx_IRQn) DocID027328 / 1166 82 Rev 2

83 UM1850 HAL ADC Generic Driver Insert the ADC interruption handler function HAL_ADC_IRQHandler() into the function of corresponding DMA inter ruption vector DMAx_Channelx_IRQHandler(). Configuration of ADC, groups regular/injected, channels parameters Configure the ADC parameters (resolution, data alignment, ...) and regular group 1. parameters (conversion trigger, sequencer, ...) using function H AL_ADC_Init(). 2. Configure the channels for regular group parameters (channel number, channel rank into sequencer, ..., into regular group) using function HAL_ADC_ConfigChannel(). uencer, ..., Optionally, configure the injected group parameters (conversion trigger, seq 3. of injected group) and the channels for injected group parameters (channel number, channel rank into sequencer, ..., into injected group) using function HAL_ADCEx_InjectedConfigChannel(). channels monitored, Optionally, configure the analog watchdog parameters ( 4. thresholds, ...) using function HAL_ADC_AnalogWDGConfig(). Optionally, for devices with several ADC instances: configure the multimode 5. parameters using function HAL_ADCEx_MultiModeConfigChannel(). Execution of ADC conversions 1. ly, perform an automatic ADC calibration to improve the conversion accuracy Optional using function HAL_ADCEx_Calibration_Start(). 2. ADC driver can be used among three modes: polling, interruption, transfer by DMA. ADC conversion by polling: Activate the ADC perip heral and start conversions using function HAL_ADC_Start() Wait for ADC conversion completion using function HAL_ADC_PollForConversion() (or for injected group: HAL_ADCEx_InjectedPollForConversion() ) Retrieve conversion results using function HAL_ADC_GetV alue() (or for injected group: HAL_ADCEx_InjectedGetValue() ) Stop conversion and disable the ADC peripheral using function HAL_ADC_Stop() ADC conversion by interruption: Activate the ADC peripheral and start conversions using function HAL_ADC_Start_IT() Wait for ADC conversion completion by call of function HAL_ADC_ConvCpltCallback() (this function must be implemented in user program) (or for injected group: HAL_ADCEx_InjectedConvCpltCallback() ) e() (or for Retrieve conversion results using function HAL_ADC_GetValu injected group: HAL_ADCEx_InjectedGetValue() ) Stop conversion and disable the ADC peripheral using function HAL_ADC_Stop_IT() ADC conversion with transfer by DMA: Activate the ADC peripheral and start conversions using function _DMA() HAL_ADC_Start Wait for ADC conversion completion by call of function HAL_ADC_ConvCpltCallback() or HAL_ADC_ConvHalfCpltCallback() (these functions must be implemented in user program) Conversion results are automatically transferred by DMA into destination le address. variab Stop conversion and disable the ADC peripheral using function HAL_ADC_Stop_DMA() 2 DocID027328 Rev 1166 83 /

84 HAL UM1850 ADC Generic Driver For devices with several ADCs: ADC multimode conversion with transfer by DMA: Activate the ADC peripheral (slave) and start conversions using function HAL_ADC_St art() Activate the ADC peripheral (master) and start conversions using function HAL_ADCEx_MultiModeStart_DMA() Wait for ADC conversion completion by call of function HAL_ADC_ConvCpltCallback() or HAL_ADC_ConvHalfCpltCallback() (these emented in user program) functions must be impl Conversion results are automatically transferred by DMA into destination variable address. Stop conversion and disable the ADC peripheral (master) using function HAL_ADCEx_MultiModeStop_DMA() ipheral (slave) using function Stop conversion and disable the ADC per HAL_ADC_Stop_IT() Callback functions must be implemented in user program: HAL_ADC_ErrorCallback() HAL_ADC_LevelOutOfWindowCallback() (callback of analog watchdog) HAL_ADC_ConvCpltCallback() HAL_ADC_ConvHalfCpltCallback HAL_ADCEx_InjectedConvCpltCallback() Deinitialization of ADC 1. Disable the ADC interface ADC clock can be hard reset and disabled at RCC top level. Hard reset of ADC peripherals using macro __ADCx_FORCE_RESET(), __ADCx_RELEASE_RESET(). using the equivalent macro/functions as configuration step. ADC clock disable Example: Into HAL_ADC_MspDeInit() (recommended code location) or with other device clock parameters configuration: PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC ection = RCC_ADCPLLCLK2_OFF PeriphClkInit.AdcClockSel HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) 2. ADC pins configuration Disable the clock for the ADC GPIOs using macro __HAL_RCC_GPIOx_CLK_DISABLE() 3. Optionally, in case of usage of ADC with interruptions: Disable the NVIC for ADC using function HAL_NVIC_EnableIRQ(ADCx_IRQn) 4. Optionally, in case of usage of DMA: Deinitialize the DMA using function HAL_DMA_Init(). Disable the NVIC for DMA using function HAL_NVIC_EnableIRQ(DMAx_Channelx_IRQn) functions initialization - Initialization and de 6.2.3 This section provides functions allowing to: Initialize and configure the ADC. initialize the ADC. - De DocID027328 / 1166 84 Rev 2

85 UM1850 ADC Generic Driver HAL This section contains the following APIs: HAL_ADC_Init() HAL_ADC_DeInit() HAL_ADC_MspInit() HAL_ADC_MspDeInit() 6.2.4 IO operation functions ovides functions allowing to: This section pr Start conversion of regular group. Stop conversion of regular group. Poll for conversion complete on regular group. Poll for conversion event. Get result of regular channel conversion. able interruptions. Start conversion of regular group and en Stop conversion of regular group and disable interruptions. Handle ADC interrupt request Start conversion of regular group and enable DMA transfer. Stop conversion of regular group and disable ADC DMA transfer. This section contains the following APIs: HAL_ADC_Start() HAL_ADC_Stop() HAL_ADC_PollForConversion() HAL_ADC_PollForEvent() HAL_ADC_Start_IT() HAL_ADC_Stop_IT() HAL_ADC_Start_DMA() HAL_ADC_Stop_DMA() HAL_ADC_GetValue( ) HAL_ADC_IRQHandler() HAL_ADC_ConvCpltCallback() HAL_ADC_ConvHalfCpltCallback() HAL_ADC_LevelOutOfWindowCallback() HAL_ADC_ErrorCallback() 6.2.5 Peripheral Control functions This section provides functions allowing to: Configure channels on regular group Configure the analog watchdog This section contains the following APIs: HAL_ADC_ConfigChannel() HAL_ADC_AnalogWDGConfig() 6.2.6 Peripheral State and Errors functions - time the status of the peripheral. This subsection provides functions to get in run Check the ADC state Check the ADC error code This section contains the following APIs: 2 DocID027328 Rev 1166 85 /

86 HAL UM1850 ADC Generic Driver HAL_ADC_GetState() HAL_ADC_GetError() 6.2.7 Detailed description of functions HAL_ADC_Init HAL_StatusTypeDef HAL_ADC_Init (ADC_HandleTypeDef * Function name hadc) heral and regular group according to Initializes the ADC perip Function description parameters specified in structure "ADC_InitTypeDef". Parameters ADC handle hadc: Return values status HAL: Notes As prerequisite, ADC clock must be configured at RCC top ample code level (clock source APB2). See commented ex below that can be copied and uncommented into HAL_ADC_MspInit(). Possibility to update parameters on the fly: This function initializes the ADC MSP (HAL_ADC_MspInit()) only when coming from ADC state reset. Following calls to this function can b e used to reconfigure some parameters of ADC_InitTypeDef structure on the fly, without modifying MSP configuration. If ADC MSP has to be modified again, HAL_ADC_DeInit() must be called before HAL_ADC_Init(). The setting of these parameters is conditioned t o ADC state. For parameters constraints, see comments of structure "ADC_InitTypeDef". This function configures the ADC within 2 scopes: scope of entire ADC and scope of regular group. For parameters details, see comments of structure "ADC_InitTypeDef". HAL_ADC_DeInit HAL_StatusTypeDef HAL_ADC_DeInit (ADC_HandleTypeDef * Function name hadc) Deinitialize the ADC peripheral registers to their default reset Function description values, with deinitialization of the ADC MSP. Parameters ADC handle hadc: turn values Re HAL: status HAL_ADC_MspInit void HAL_ADC_MspInit (ADC_HandleTypeDef * hadc) Function name Function description Initializes the ADC MSP. Parameters hadc: ADC handle Return values None: DocID027328 / 1166 86 Rev 2

87 UM1850 ADC Generic Driver HAL HAL_ADC_MspDeInit HAL_ADC_MspDeInit (ADC_HandleTypeDef * hadc) void Function name DeInitializes the ADC MSP. Function description Parameters hadc: ADC handle Return values None: HAL_ADC_Start HAL_StatusTypeDef HAL_ADC_Start (ADC_HandleTypeDef * Function name hadc) Function description Enables ADC, starts conversion of regular group. Parameters ADC handle hadc: Return values status HAL: HAL_ADC_Stop HAL_StatusTypeDef HAL_ADC_Stop (ADC_HandleTypeDef * Function name hadc) Function description nd injected channels in Stop ADC conversion of regular group (a case of auto_injection mode), disable ADC peripheral. Parameters hadc: ADC handle Return values status. HAL: Notes : ADC peripheral disable is forcing stop of potential conversion on injected group. If injected group is under use, it should be preliminarily stopped using HAL_ADCEx_InjectedStop function. HAL_ADC_PollForConversion HAL_StatusTypeDef HAL_ADC_PollForConversion Function name (ADC_HandleTypeDef * hadc, uint32_t Timeout) nversion to be completed. Wait for regular group co Function description Parameters ADC handle hadc: Timeout value in millisecond. Timeout: Return values status HAL: Notes This function cannot be used in a particular setup: ADC configured in DMA mode. In this case, DMA resets the flag polling cannot be performed on each conversion. EOC and On STM32F1 devices, limitation in case of sequencer enabled (several ranks selected): polling cannot be done on each conversion inside the sequence. In this case, polling is rsion time. replaced by wait for maximum conve HAL_ADC_PollForEvent HAL_StatusTypeDef HAL_ADC_PollForEvent Function name Rev 2 87 / 1166 DocID027328

88 HAL UM1850 ADC Generic Driver (ADC_HandleTypeDef * hadc, uint32_t EventType, uint32_t Timeout) Function description Poll for conversion event. Parameters ADC handle hadc: t type. This parameter can be one the ADC even EventType: of the following values: ADC_AWD_EVENT: ADC Analog watchdog event. Timeout value in millisecond. Timeout: Return values status HAL: HAL_ADC_Start_IT HAL_StatusTypeDef HAL_ADC_Start_IT (ADC_HandleTypeDef Function name * hadc) Function description Enables ADC, starts conversion of regular group with interruption. HAL_ADC_Stop_IT HAL_StatusTypeDef HAL_ADC_Stop_IT (ADC_HandleTypeDef Function name * hadc) Stop ADC conversion of regular group (and injected group in case Function description of auto_injection mode), disable interrution of end - of - conversion, disable ADC peripheral. Parameters ADC handle hadc: Return values None: HAL_ADC_Start_DMA Def HAL_ADC_Start_DMA HAL_StatusType Function name (ADC_HandleTypeDef * hadc, uint32_t * pData, uint32_t Length) Enables ADC, starts conversion of regular group and transfers Function description result through DMA. HAL_ADC_Stop_DMA HAL_StatusTypeDef HAL_ADC_Stop_DMA Function name (ADC_HandleTypeDef * hadc) Function description Stop ADC conversion of regular group (and injected group in case of auto_injection mode), disable ADC DMA transfer, disable ADC peripheral. Parameters ADC handle hadc: Return values HAL: status. Notes : ADC peripheral disable is forcing stop of potential conversion on injected group. If injected group is under use, it should be preliminarily stopped using HAL_ADCEx_InjectedStop function. For devices with several ADCs: This function is for single - DocID027328 / 1166 88 Rev 2

89 UM1850 ADC Generic Driv er HAL e only. For multimode, use the dedicated ADC mod MultimodeStop function. On STM32F1 devices, only ADC1 and ADC3 (ADC availability depending on devices) have DMA capability. HAL_ADC_GetValue uint32_t HAL_ADC_GetValue (ADC_HandleTypeDef * hadc) Function name Funct ion description Get ADC regular group conversion result. Parameters hadc: ADC handle Return values group regular conversion data ADC: Notes Reading register DR automatically clears ADC flag EOC (ADC group regular end of unitary conversion). This function does not clear ADC flag EOS (ADC group regular end of sequence conversion). Occurrence of flag EOS rising: If sequencer is composed of 1 rank, flag EOS is equivalent to flag EOC.If sequencer is composed of several nce flag EOC only is raised, at ranks, during the scan seque the end of the scan sequence both flags EOC and EOS are raised. To clear this flag, either use function: in programming model IT: HAL_ADC_IRQHandler(), in programming model polling: HAL_ADC_PollForConversion() or __HAL_ADC_C LEAR_FLAG(&hadc, ADC_FLAG_EOS). HAL_ADC_IRQHandler void HAL_ADC_IRQHandler (ADC_HandleTypeDef * hadc) Function name Function description Handles ADC interrupt request. Parameters ADC handle hadc: Return values None: HAL_ADC_ConvCpltCallback void HAL_ADC_ConvCpltCallback (ADC_HandleTypeDef * Function name hadc) Conversion complete callback in non blocking mode. Function description Parameters hadc: ADC handle Return values None: HAL_ADC_ConvHalfCpltCallback nvHalfCpltCallback (ADC_HandleTypeDef * void HAL_ADC_Co Function name hadc) transfer callback in non blocking mode. - Function description Conversion DMA half Parameters ADC handle hadc: Return values None: 2 DocID027328 Rev 1166 89 /

90 HAL UM1850 ADC Generic Driver HAL_ADC_LevelOutOfWindowCallback HAL_ADC_LevelOutOfWindowCallback void Function name (ADC_HandleTypeDef * hadc) Function description Analog watchdog callback in non blocking mode. Parameters ADC handle hadc: Return values None: HAL_ADC_ErrorCallback (ADC_HandleTypeDef * hadc) void HAL_ADC_ErrorCallback Function name Function description ADC error callback in non blocking mode (ADC conversion with interruption or transfer by DMA) Parameters hadc: ADC handle Return values None: HAL_ADC_ConfigChannel DC_ConfigChannel HAL_StatusTypeDef HAL_A Function name (ADC_HandleTypeDef * hadc, ADC_ChannelConfTypeDef * sConfig) Configures the the selected channel to be linked to the regular Function description group. Parameters hadc: ADC handle Structure of ADC channel for regular group. sConfig: Return values status HAL: Notes In case of usage of internal measurement channels: Vbat/VrefInt/TempSensor. These internal paths can be be disabled using function HAL_ADC_DeInit(). Possibility to update parameters on the fly: This function hannel into regular group, following calls to this initializes c function can be used to reconfigure some parameters of structure "ADC_ChannelConfTypeDef" on the fly, without reseting the ADC. The setting of these parameters is conditioned to ADC state. For parameters c onstraints, see comments of structure "ADC_ChannelConfTypeDef". HAL_ADC_AnalogWDGConfig HAL_StatusTypeDef HAL_ADC_AnalogWDGConfig Function name (ADC_HandleTypeDef * hadc, ADC_AnalogWDGConfTypeDef * AnalogWDGConfig) Function description Configures the ana log watchdog. Parameters ADC handle hadc: Structure of ADC analog watchdog AnalogWDGConfig: configuration Return values status HAL: DocID027328 / 1166 90 Rev 2

91 UM1850 ADC Generic Driver HAL Notes Analog watchdog thresholds can be modified while ADC conversion is on going. In this case, some constraints must be taken into account: the programmed threshold values are effective from the next ADC EOC (end of unitary conversion). Considering that registers write delay may happen due to bus activity, this might cause an uncertainty on the effective timing he new programmed threshold values. of t HAL_ADC_GetState uint32_t HAL_ADC_GetState (ADC_HandleTypeDef * hadc) Function name Function description return the ADC state Parameters ADC handle hadc: Return values HAL: state HAL_ADC_GetError uint32_t HAL_ADC_GetError (ADC_HandleTypeDef * hadc) Function name Return the ADC error code. Function description Parameters hadc: ADC handle Return values Error Code ADC: ADC_Enable HAL_StatusTypeDef ADC_Enable (ADC_HandleTypeDef * Function name hadc) Function description Enable the selected ADC. Parameters hadc: ADC handle Return values HAL: status. Notes Prerequisite condition to use this function: ADC must be disabled and voltage regulator must be enabled (done into HAL_ADC_Init()). ADC_ConversionStop _Disable HAL_StatusTypeDef ADC_ConversionStop_Disable Function name (ADC_HandleTypeDef * hadc) Stop ADC conversion and disable the selected ADC. Function description Parameters ADC handle hadc: Return values status. HAL: Notes Prerequisite condition to use this function: ADC conversions must be stopped to disable the ADC. ADC_StabilizationTime void ADC_StabilizationTime (uint32_t DelayUs) Function name Rev 2 1166 91 / DocID027328

92 HAL UM1850 ADC Generic Driver Function description ADC_DMAConvCplt void ADC_DMAConvCplt (DMA_HandleTypeDef * hdma) Function name Function description DMA transfer complete callback. Parameters hdma: pointer to DMA handle. Return values None: ADC_DMAHalfConvCplt void ADC_DMAHalfConvCplt (DMA_HandleTypeDef * hdma) Function name Function description DMA half transfer complete callback. Parameters hdma: pointer to DMA handle. Return values None: ADC_DMAError void ADC_DMAError (DMA_HandleTypeDef * hdma) Function name DMA error callback. Function description Parameters pointer to DMA handle. hdma: Return values None: 6.3 ADC Firmware driver defines 6.3.1 ADC ADC analog watchdog mode ADC_ANALOGWATCHDOG_NONE ADC_ANALOGWATCHDOG_SINGLE_REG ADC_ANALOGWATCHDOG_SINGLE_INJEC ADC_ANALOGWATCHDOG_SINGLE_REGINJEC ADC_ANALOGWATCHDOG_ALL_REG ADC_ANALOGWATCHDOG_ALL_INJEC ADC_ANALOGWATCHDOG_ALL_REGINJEC ADC channels ADC_CHANNEL_0 ADC_CHANNEL_1 ADC_CHANNEL_2 ADC_CHANNEL_3 ADC_CHANNEL_4 ADC_CHANNEL_5 DocID027328 / 1166 92 Rev 2

93 UM1850 ADC Generic Driver HAL ADC_CHANNEL_6 ADC_CHANNEL_7 ADC_CHANNEL_8 ADC_CHANNEL_9 ADC_CHANNEL_10 ADC_CHANNEL_11 ADC_CHANNEL_12 ADC_CHANNEL_13 ADC_CHANNEL_14 ADC_CHANNEL_15 ADC_CHANNEL_16 ADC_CHANNEL_17 ADC_CHANNEL_TEMPSENSOR ADC_CHANNEL_VREFINT ADC conversion cycles ADC_CONVERSIONCLOCKCYCLES_SAMPLETIME_1CYCLE5 ADC_CONVERSIONCLOCKCYCLES_SAMPLETIME_7CYCLES5 ADC_CONVERSIONCLOCKCYCLES_SAMPLETIME_13CYCLES5 ADC_CONVERSIONCLOCKCYCLES_SAMPLETIME_28CYCLES5 ADC_CONVERSIONCLOCKCYCLES_SAMPLETIME_41CYCLES5 ADC_CONVERSIONCLOCKCYCLES_SAMPLETIME_55CYCLES5 ADC_CONVERSIONCLOCKCYCLES_SAMPLETIME_71CYCLES5 ADC_CONVERSIONCLOCKCYCLES_SAMPLETIME_239CYCLES5 ADC conversion group ADC_REGULAR_GROUP ADC_INJECTED_GROUP ADC_REGULAR_INJECTED_GROUP ADC data alignment ADC_DATAALIGN_RIGHT ADC_DATAALIGN_LEFT ADC Error Code No error HAL_ADC_ERROR_NONE HAL_ADC_ERROR_INTERNAL ADC IP internal error: if problem of clocking, enable/disable, erroneous state Overrun error HAL_ADC_ERROR_OVR DMA transfer error HAL_ADC_ERROR_DMA ADC Event type 2 DocID027328 Rev 1166 93 /

94 HAL UM1850 ADC Generic Driver ADC Analog watchdog event ADC_AWD_EVENT ADC_AWD1_EVENT ADC Analog watchdog 1 event: Alternate naming for compatibility with other STM32 devices having several analog watchdogs ADC Exported Macros Description: __HAL_ADC_ENABLE Enable the ADC peripheral. Parameters: __HANDLE__: ADC handle Return value: None Notes: ADC enable requires a delay for ADC stabilization time (refer to device datasheet, parameter tSTAB) On STM32F1, if ADC is already enabled this macro trigs a conversion SW start on regular group. Description: __HAL_ADC_DISABLE peripheral. Disable the ADC Parameters: __HANDLE__: ADC handle Return value: None Description: __HAL_ADC_ENABLE_IT Enable the ADC end of conversion interrupt. Parameters: __HANDLE__: ADC handle __INTERRUPT__: ADC Interrupt This parameter can be any combination of the fol lowing values: ADC_IT_EOC: ADC End of Regular Conversion interrupt source ADC_IT_JEOC: ADC End of Injected Conversion interrupt source ADC_IT_AWD: ADC Analog watchdog interrupt source Return value: None Description: __HAL_ADC_DISABLE_IT Disable the ADC end of conversion interrupt. DocID027328 / 1166 94 Rev 2

95 UM1850 ADC Generic Driver HAL Parameters: __HANDLE__: ADC handle __INTERRUPT__: ADC Interrupt This parameter can be any combination of the following values: ADC_IT_EOC: ADC End of Regular Conversion interrupt source ADC_IT_JEOC: ADC End of Injected ion interrupt source Convers ADC_IT_AWD: ADC Analog watchdog interrupt source Return value: None Description: __HAL_ADC_GET_IT_SOURCE Checks if the specified ADC interrupt source is enabled or disabled. Parameters: __HANDLE__: ADC handle __INTERRUPT__: ADC interrupt source to check This parameter can be any combination of the following values: ADC_IT_EOC: ADC End of Regular Conversion interrupt source ADC_IT_JEOC: ADC End of Injected Conversion interrupt source ADC_IT_AWD: ADC Analog watchdog interrupt source Return value: None Description: __HAL_ADC_GET_FLAG Get the selected ADC's flag status. Parameters: __HANDLE__: ADC handle __FLAG__: ADC flag This parameter can be any combination of the following values: ar ADC_FLAG_STRT: ADC Regul group start flag ADC_FLAG_JSTRT: ADC Injected group start flag ADC_FLAG_EOC: ADC End of Regular conversion flag ADC_FLAG_JEOC: ADC End of Injected conversion flag ADC_FLAG_AWD: ADC Analog watchdog flag Return value: 2 DocID027328 Rev 1166 95 /

96 HAL UM1850 ADC Generic Driver None Description: __HAL_ADC_CLEAR_FLAG Clear the ADC's pending flags. Parameters: __HANDLE__: ADC handle __FLAG__: ADC flag This parameter can be any combination of the following values: ADC_FLAG_STRT: ADC Regular group start flag ADC_FLAG_JSTRT: ADC Injected group start flag FLAG_EOC: ADC End of ADC_ Regular conversion flag ADC_FLAG_JEOC: ADC End of Injected conversion flag ADC_FLAG_AWD: ADC Analog watchdog flag Return value: None Description: __HAL_ADC_RESET_HANDLE_STATE Reset ADC handle state. Parameters: __HANDLE__: ADC handle Return value: None ADC Exported Types ADC not yet initialized or disabled HAL_ADC_STATE_RESET ADC peripheral ready for use HAL_ADC_STATE_READY ADC is busy to internal process (initialization, HAL_ADC_STATE_BUSY_INTERNAL calibration) HAL_ADC_STATE_TIMEOUT TimeOut occurrence HAL_ADC_STATE_ERROR_INTERNAL Internal error occurrence HAL_ADC_STATE_ERROR_CONFIG Configuration error occurrence HAL_ADC_STATE_ERROR_DMA DMA error occurrence A conversion on group regular is ongoing or HAL_ADC_STATE_REG_BUSY can occur (either by continuous mode, - on, external trigger, low power auto power multimode ADC master control) HAL_ADC_STATE_REG_EOC Conversion data available on group regular HAL_ADC_STATE_REG_OVR ble on STM32F1 device: Overrun Not availa occurrence HAL_ADC_STATE_REG_EOSMP Not available on STM32F1 device: End Of DocID027328 / 1166 96 Rev 2

97 UM1850 HAL ADC Generic Driver Sampling flag raised HAL_ADC_STATE_INJ_BUSY A conversion on group injected is ongoing or injection mode, can occur (either by auto - on, external trigger, low power auto power - multimode ADC master control) Conversion data available on group injected HAL_ADC_STATE_INJ_EOC HAL_ADC_STATE_INJ_JQOVF No t available on STM32F1 device: Injected queue overflow occurrence - Out window occurrence of analog HAL_ADC_STATE_AWD1 - of watchdog 1 HAL_ADC_STATE_AWD2 Not available on STM32F1 device: Out - of - window occurrence of analog watchdog 2 t available on STM32F1 device: Out - of - No HAL_ADC_STATE_AWD3 window occurrence of analog watchdog 3 HAL_ADC_STATE_MULTIMODE_SLAVE ADC in multimode slave state, controlled by another ADC master ( ADC external trigger enable for regular group ADC_EXTERNALTRIGCONVEDGE_NONE ADC_EXTERNALTRIGCONVEDGE_RISING ADC External trigger selection for regular group ADC_EXTERNALTRIGCONV_T1_CC1 < List of external triggers with generic trigger name, independently of ADC_EXTERNALTRIGCONV_T1_CC2 ADC_EXTERNALTRIGCONV_T2_CC2 ADC_EXTERNALTRIGCONV_T3_TRGO ADC_EXTERNALTRIGCONV_T4_CC4 External triggers of regular group for ADC3 ADC_EXTERNALTRIGCONV_EXT_IT11 only ADC_EXTERNALTRIGCONV_T2_CC3 ADC_EXTERNALTRIGCONV_T3_CC1 ADC_EXTERNALTRIGCONV_T5_CC1 ADC_EXTERNALTRIGCONV_T5_CC3 ADC_EXTERNALTRIGCONV_T8_CC1 < External triggers of regular group for all ADC ADC_EXTERNALTRIGCONV_T1_CC3 instances Note: TIM8_TRGO is available on density and - ADC1 and ADC2 only in high ADC_EXTERNALTRIGCONV_T8_TRGO ADC_SOFTWARE_START ADC flags definition ADC Regular group start flag ADC_FLAG_STRT 2 DocID027328 Rev 1166 97 /

98 ADC Generic Driver HAL UM1850 ADC_FLAG_JSTRT ADC Injected group start flag ADC End of Regular conversion flag ADC_FLAG_EOC ADC_FLAG_JEOC ADC End of Injected conversion flag ADC Analog watchdog flag ADC_FLAG_AWD ADC interrupts definition ADC End of Regular Conversion interrupt source ADC_IT_EOC ADC End of Injected Conversion interrupt source ADC_IT_JEOC ADC_IT_AWD ADC Analog watchdog interrupt source ADC range verification IS_ADC_RANGE ADC regular discontinuous mode number verification IS_ADC_REGULAR_DISCONT_NUMBER ADC regular nb conv verification IS_ADC_REGULAR_NB_CONV ADC rank into regular group ADC_REGULAR_RANK_1 ADC_REGULAR_RANK_2 ADC_REGULAR_RANK_3 ADC_REGULAR_RANK_4 ADC_REGULAR_RANK_5 ADC_REGULAR_RANK_6 ADC_REGULAR_RANK_7 ADC_REGULAR_RANK_8 ADC_REGULAR_RANK_9 ADC_REGULAR_RANK_10 ADC_REGULAR_RANK_11 ADC_REGULAR_RANK_12 ADC_REGULAR_RANK_13 ADC_REGULAR_RANK_14 ADC_REGULAR_RANK_15 ADC_REGULAR_RANK_16 ADC sampling times ADC_SAMPLETIME_1CYCLE_5 Sampling time 1.5 ADC clock cycle Sampling time 7.5 ADC clock cycles ADC_SAMPLETIME_7CYCLES_5 Sampling time 13.5 ADC clock cycles ADC_SAMPLETIME_13CYCLES_5 ADC_SAMPLETIME_28CYCLES_5 Sampling time 28.5 ADC clock cycles DocID027328 / 1166 98 Rev 2

99 UM1850 ADC Generic Driver HAL Sampling time 41.5 ADC clock cycles ADC_SAMPLETIME_41CYCLES_5 Sampling time 55.5 ADC clock cycles ADC_SAMPLETIME_55CYCLES_5 Sampling time 71.5 ADC clock cycles ADC_SAMPLETIME_71CYCLES_5 ADC_SAMPLETIME_239CYCLES_5 Sampling time 239.5 ADC clock cycles ADC sampling times all channels ADC_SAMPLETIME_ALLCHANNELS_SMPR2BIT2 ADC_SAMPLETIME_ALLCHANNELS_SMPR1BIT2 ADC_SAMPLETIME_ALLCHANNELS_SMPR2BIT1 ADC_SAMPLETIME_ALLCHANNELS_SMPR1BIT1 ADC_SAMPLETIME_ALLCHANNELS_SMPR2BIT0 ADC_SAMPLETIME_ALLCHANNELS_SMPR1BIT0 ADC_SAMPLETIME_1CYCLE5_SMPR2ALLCHANNELS ADC_SAMPLETIME_7CYCLES5_SMPR2ALLCHANNELS ADC_SAMPLETIME_13CYCLES5_SMPR2ALLCHANNELS ADC_SAMPLETIME_28CYCLES5_SMPR2ALLCHANNELS ADC_SAMPLETIME_41CYCLES5_SMPR2ALLCHANNELS ADC_SAMPLETIME_55CYCLES5_SMPR2ALLCHANNELS ADC_SAMPLETIME_71CYCLES5_SMPR2ALLCHANNELS ADC_SAMPLETIME_239CYCLES5_SMPR2ALLCHANNELS ADC_SAMPLETIME_1CYCLE5_SMPR1ALLCHANNELS ADC_SAMPLETIME_7CYCLES5_SMPR1ALLCHANN ELS ADC_SAMPLETIME_13CYCLES5_SMPR1ALLCHANNELS ADC_SAMPLETIME_28CYCLES5_SMPR1ALLCHANNELS ADC_SAMPLETIME_41CYCLES5_SMPR1ALLCHANNELS ADC_SAMPLETIME_55CYCLES5_SMPR1ALLCHANNELS ADC_SAMPLETIME_71CYCLES5_SMPR1ALLCHANNELS ADC_SAMPLETIME_239CYCLES5_SMPR1ALLCHANNELS ADC scan mode ADC_SCAN_DISABLE ADC_SCAN_ENABLE 2 DocID027328 Rev 1166 99 /

100 HAL UM1850 ADC Extension Driver HAL ADC Extension Driver 7 7.1 ADCEx Firmware driver registers structures ADC_InjectionConfTypeDef 7.1.1 Data Fields uint32_t InjectedChannel uint32_t InjectedRank uint32_t InjectedSamplingTime uint32_t InjectedOffset uint32_t InjectedNbrOfConversion uint32_t InjectedDiscontinuousConvMode uint32_t AutoInjectedConv uint32_t ExternalTrigInjecConv Field Documentation uint32_t ADC_InjectionConfTypeDef::InjectedChannel Selection of ADC channel to configure This parameter can be a value of Note: Depending on devices, some channels may not be available on ADC_channels package pins. Refer to device datasheet for channels availability. Note: On STM32F1 devices with several ADC: Only ADC1 can access internal measur ement channels - (VrefInt/TempSensor) Note: On STM32F10xx8 and STM32F10xxB devices: A low amplitude voltage glitch may be generated (on ADC input 0) on the PA0 pin, when the ADC is converting with injection trigger. It is advised to distribute the analog cha nnels so that Channel 0 is configured as an injected channel. Refer to errata sheet of these devices for more details. uint32_t ADC_InjectionConfTypeDef::InjectedRank Rank in the injected group sequencer This parameter must be a value of Note: In case of need to disable a channel or change order of ADCEx_injected_rank conversion sequencer, rank containing a previous channel setting can be overwritten sted) by the new channel setting (or parameter number of conversions can be adju uint32_t ADC_InjectionConfTypeDef::InjectedSamplingTime Sampling time value to be set for the selected channel. Unit: ADC clock cycles Conversion time is the addition of sampling time and processing time (12.5 ADC clock its). This parameter can be a value of cycles at ADC resolution 12 b Caution: This parameter updates the parameter property of ADC_sampling_times the channel, that can be used into regular and/or injected groups. If this same channel configured in the other group (regular/injected), it will be updated has been previously to last setting. Note: In case of usage of internal measurement channels (VrefInt/TempSensor), sampling time constraints must be respected (sampling time DC clock frequency and sampling time setting) Refer can be adjusted in function of A to device datasheet for timings values, parameters TS_vrefint, TS_temp (values rough order: 5us to 17.1us min). uint32_t ADC_InjectionConfTypeDef::InjectedOffset the raw converted data (for channels set on Defines the offset to be subtracted from injected group only). Offset value must be a positive number. Depending of ADC resolution selected (12, 10, 8 or 6 bits), this parameter must be a number between Min_Data = 0x000 and Max_Data = 0xFFF, 0x3FF, 0xFF or 0x3F respectively. uint32_t ADC_InjectionConfTypeDef::InjectedNbrOfConversion Specifies the number of ranks that will be converted within the injected group DocID027328 / 11 66 100 Rev 2

101 UM1850 ADC Extension Driver HAL sequencer. To use the injected group sequencer and convert several ranks, ode' must be enabled. This parameter must be a number parameter 'ScanConvM between Min_Data = 1 and Max_Data = 4. Caution: this setting impacts the entire HAL_ADCEx_InjectedConfigChannel() injected group. Therefore, call of to configure he configuration of other channels previously a channel on injected group can impact t set. uint32_t ADC_InjectionConfTypeDef::InjectedDiscontinuousConvMode Specifies whether the conversions sequence of injected group is performed in Complete sequence/Discontinuous ided in sequence (main sequence subdiv - - successive parts). Discontinuous mode is used only if sequencer is enabled (parameter 'ScanConvMode'). If sequencer is disabled, this parameter is discarded. Discontinuous mode can be enabled only if continuous mode is disabled. If continuous is enabled, this parameter setting is discarded. This parameter can be set to mode ENABLE or DISABLE. Note: For injected group, number of discontinuous ranks increment is fixed to one - by one. Caution: this setting impacts the entire injected - group. Therefore, c all of to configure a HAL_ADCEx_InjectedConfigChannel() channel on injected group can impact the configuration of other channels previously set. uint32_t ADC_InjectionConfTypeDef::AutoInjectedConv oup conversion after Enables or disables the selected ADC automatic injected gr regular one This parameter can be set to ENABLE or DISABLE. Note: To use Automatic injected conversion, discontinuous mode must be disabled ('DiscontinuousConvMode' and 'InjectedDiscontinuousConvMode' set to DISABLE) Note: To use Autom atic injected conversion, injected group external triggers must be disabled ('ExternalTrigInjecConv' set to ADC_SOFTWARE_START) Note: In case of DMA used with regular group: if DMA configured in normal mode (single shot) JAUTO will be stopped upon DMA tran sfer complete. To maintain JAUTO always enabled, DMA must be configured in circular mode. Caution: this setting impacts the entire injected group. Therefore, call of HAL_ADCEx_InjectedConfigChannel() to configure a channel on injected group can impact the configuration of other channels previously set. uint32_t ADC_InjectionConfTypeDef::ExternalTrigInjecConv Selects the external event used to trigger the conversion start of injected group. If set ed. If set to to ADC_INJECTED_SOFTWARE_START, external triggers are disabl external trigger source, triggering is on event rising edge. This parameter can be a value of Note: This parameter must be ADCEx_External_trigger_source_Injected modified when ADC is disabled (before ADC start conversion or after ADC stop conversion). If ADC is enabled, this parameter setting is bypassed without error reporting (as it can be the expected behaviour in case of another parameter update on group. Therefore, call of the fly) Caution: this setting impacts the entire injected HAL_ADCEx_InjectedConfigChannel() to configure a channel on injected group can impact the configuration of other channels previously set. ADC_MultiModeTypeDef 7.1.2 Data Fields uint32_t Mode Field Documentation uint32_t ADC_MultiModeTypeDef::Mode Configures the ADC to operate in independent or multi mode. This parameter can be a Note: In dual mode, a change of channel ADCEx_Common_mode value of configuration generates a restart that can produce a loss of synchronization. It is recommended to disable dual mode before any configuration change. Note: In case of g time should be configured for simultaneous mode used: Exactly the same samplin 2 DocID027328 Rev 1166 101 /

102 HAL ADC Extension Driver UM1850 the 2 channels that will be sampled simultaneously by ACD1 and ADC2. Note: In case of interleaved mode used: To avoid overlap between conversions, maximum sampling and 14 ADC clock cycles time allowed is 7 ADC clock cycles for fast interleaved mode for slow interleaved mode. Note: Some multimode parameters are fixed on STM32F1 and can be configured on other STM32 devices with several ADC (multimode configuration structure can have additional parameters). The equivalences are: Parameter 'DMAAccessMode': On STM32F1, this parameter is fixed to 1 DMA channel (one DMA channel for both ADC, DMA of ADC master). On other STM32 devices with several ADC, this is equivalent to parameter 'ADC_DMAACCESSMODE_12_10_BITS'.Parameter 'TwoSamplin gDelay': On STM32F1, this parameter is fixed to 7 or 14 ADC clock cycles depending on fast or slow interleaved mode selected. On other STM32 devices with several ADC, this is equivalent to parameter 'ADC_TWOSAMPLINGDELAY_7CYCLES' (for fast interleaved mode ). 7.2 ADCEx Firmware driver API description IO operation functions 7.2.1 This section provides functions allowing to: Start conversion of injected group. injected group. Stop conversion of Poll for conversion complete on injected group. Get result of injected channel conversion. Start conversion of injected group and enable interruptions. Stop conversion of injected group and disable interruptions. Start multimode and enabl e DMA transfer. Stop multimode and disable ADC DMA transfer. Get result of multimode conversion. - calibration for single or differential ending. Perform the ADC self Get calibration factors for single or differential ending. Set calibration factors for single or differential ending. This section contains the following APIs: HAL_ADCEx_Calibration_Start() HAL_ADCEx_InjectedStart() HAL_ADCEx_InjectedStop() HAL_ADCEx_InjectedPollForConversion() HAL_ADCEx_InjectedStart_IT() HAL_ADCEx_InjectedStop_IT() HAL _ADCEx_MultiModeStart_DMA() HAL_ADCEx_MultiModeStop_DMA() HAL_ADCEx_InjectedGetValue() HAL_ADCEx_MultiModeGetValue() HAL_ADCEx_InjectedConvCpltCallback() Peripheral Control functions 7.2.2 This section provides functions allowing to: Configure channels on injected group Configure multimode wing APIs: This section contains the follo DocID027328 / 1166 102 Rev 2

103 UM1850 ADC Extension Driver HAL HAL_ADCEx_InjectedConfigChannel() HAL_ADCEx_MultiModeConfigChannel() Detailed description of functions 7.2.3 HAL_ADCEx_Calibration_Start HAL_StatusTypeDef HAL_ADCEx_Calibration_Start Function name (ADC_HandleTypeDef * hadc) Perform an ADC automatic self Function description calibration Calibration prerequisite: - ADC must be disabled (execute this function before _ADC_Stop() ). HAL_ADC_Start() or after HAL Parameters hadc: ADC handle Return values status HAL: HAL_ADCEx_InjectedStart HAL_StatusTypeDef HAL_ADCEx_InjectedStart Function name (ADC_HandleTypeDef * hadc) Enables ADC, starts conversion of injected group. Function description Parameters hadc: ADC handle Return values status HAL: HAL_ADCEx_InjectedStop HAL_StatusTypeDef HAL_ADCEx_InjectedStop Function name (ADC_HandleTypeDef * hadc) Function description Stop conversion of injected channels. Parameters hadc: ADC handle Return values None: Notes If ADC must be disabled and if conversion is on going on regular group, function HAL_ADC_Stop must be used to stop both injected and regular groups, and disable the ADC. If injected group mode auto injection is enabled, function - HAL_ADC_Stop must be used. - In case of auto injection mode, HAL_ADC_Stop must be used. HAL_ADCEx_InjectedPollForConversion HAL_StatusTypeDef HAL_ADCEx_InjectedPollForConversion Function name (ADC_HandleTypeDef * hadc, uint32_t Timeout) Function descripti on Wait for injected group conversion to be completed. Parameters hadc: ADC handle Timeout: Timeout value in millisecond. Return values HAL: status 2 DocID027328 Rev 1166 103 /

104 HAL ADC Extension Driver UM1850 HAL_ADCEx_InjectedStart_IT HAL_StatusTypeDef HAL_ADCEx_InjectedStart_IT Function name (ADC_HandleType Def * hadc) Function description Enables ADC, starts conversion of injected group with interruption. HAL_ADCEx_InjectedStop_IT HAL_StatusTypeDef HAL_ADCEx_InjectedStop_IT Function name (ADC_HandleTypeDef * hadc) Stop conversion of injected channels, disable interruption of end Function description - conversion. of - Parameters ADC handle hadc: Return values None: Notes If ADC must be disabled and if conversion is on going on regular group, function HAL_ADC_Stop must be used to stop both injected and regular groups, and disable the ADC. If injected group mode auto injection is enabled, function - HAL_ADC_Stop must be used. HAL_ADCEx_MultiModeStart_DMA HAL_StatusTypeDef HAL_ADCEx_MultiModeStart_DMA Function name (ADC_HandleTypeDef * hadc, uint32_t * pData, uint32_t Length) Enables ADC, starts conversion of regular group and transfers Function description result through DMA. HAL_ADCEx_MultiModeStop_DMA HAL_StatusTypeDef HAL_ADCEx_MultiModeStop_DMA Function name (ADC_HandleTypeDef * hadc) Function description Stop ADC conversion of regular group (and injected channels in case of auto_injection mode), disable ADC DMA transfer, disable ADC peripheral. Parameters hadc: ADC handle of ADC master (handle of ADC slave must not be used) Return values None: Notes Multimode is kept enabled after this function. To disable multimode (set with HAL_ADCEx_MultiModeConfigChannel(), ADC must be reinitialized using HAL_ADC_Init() or HAL_ADC_ReInit(). function In case of DMA configured in circular mode, HAL_ADC_Stop_DMA must be called after this function with handle of ADC slave, to properly disable the DMA channel. HAL_ADCEx_InjectedGetValue uint32_t HAL_ADCEx_InjectedGetValue (ADC_HandleTypeDef Function name 1166 DocID027328 / Rev 2 104

105 UM1850 ADC Extension Driver HAL * hadc, uint32_t InjectedRank) Get ADC injected group conversion result. Fun ction description Parameters ADC handle hadc: InjectedRank: the converted ADC injected rank. This parameter can be one of the following values: ADC_INJECTED_RANK_1: Injected Channel1 selected ADC_INJECTED_RANK _2: Injected Channel2 selected ADC_INJECTED_RANK_3: Injected Channel3 selected ADC_INJECTED_RANK_4: Injected Channel4 selected Return values group injected conversion data ADC: Notes Reading register JDRx automatically clears ADC flag JEOC injected end of unitary conversion). (ADC group This function does not clear ADC flag JEOS (ADC group injected end of sequence conversion) Occurrence of flag JEOS rising: If sequencer is composed of 1 rank, flag JEOS is d of several equivalent to flag JEOC.If sequencer is compose ranks, during the scan sequence flag JEOC only is raised, at the end of the scan sequence both flags JEOC and EOS are raised. Flag JEOS must not be cleared by this function because it would not be compliant with low power features (feature low power auto - wait, not available on all STM32 families). To clear this flag, either use function: in programming model IT: HAL_ADC_IRQHandler(), in programming model polling: HAL_ADCEx_InjectedPollForConversion() or __HAL_ADC_CLEAR_FLAG(&hadc, ADC_FLAG_JEOS ). HAL_ADCEx_MultiModeGetValue uint32_t HAL_ADCEx_MultiModeGetValue Function name (ADC_HandleTypeDef * hadc) Function description Returns the last ADC Master&Slave regular conversions results data in the selected multi mode. Parameters ADC hand hadc: le of ADC master (handle of ADC slave must not be used) Return values converted data value. The: HAL_ADCEx_InjectedConvCpltCallback void HAL_ADCEx_InjectedConvCpltCallback Function name (ADC_HandleTypeDef * hadc) Injected conversion complete callback in non blocking mode. Function description Parameters ADC handle hadc: Return values None: HAL_ADCEx_InjectedConfigChannel HAL_StatusTypeDef HAL_ADCEx_InjectedConfigChannel Function name (ADC_HandleTypeDef * hadc, ADC_InjectionConfTy peDef * 2 DocID027328 Rev 1166 105 /

106 HAL UM1850 ADC Extension Driver sConfigInjected) Function description Configures the ADC injected group and the selected channel to be linked to the injected group. Parameters ADC handle hadc: sConfigInjected: Structure of ADC injected group and ADC channel for injected group. Return values None: Notes Possibility to update parameters on the fly: This function initializes injected group, following calls to this function can be ters of structure used to reconfigure some parame "ADC_InjectionConfTypeDef" on the fly, without reseting the ADC. The setting of these parameters is conditioned to ADC state: this function must be called when ADC is not under conversion. HAL_ADCEx_MultiModeConfigChannel AL_StatusTypeDef HAL_ADCEx_MultiModeConfigChannel H Function name (ADC_HandleTypeDef * hadc, ADC_MultiModeTypeDef * multimode) Function description Enable ADC multimode and configure multimode parameters. Parameters hadc: ADC handle Structure of ADC multimode configuration multimode: Return values status HAL: Notes Possibility to update parameters on the fly: This function initializes multimode parameters, following calls to this function can be used to reconfigure some parameters of re "ADC_MultiModeTypeDef" on the fly, without structu reseting the ADCs (both ADCs of the common group). The setting of these parameters is conditioned to ADC state. For parameters constraints, see comments of structure "ADC_MultiModeTypeDef". guration from multimode to single mode, To change back confi ADC must be reset (using function HAL_ADC_Init() ). 7.3 ADCEx Firmware driver defines 7.3.1 ADCEx ADC Extended Dual ADC Mode ADC dual mode disabled (ADC DENT ADC_MODE_INDEPEN independent mode) ADC_DUALMODE_REGSIMULT_INJECSIMU ADC dual mode enabled: Combined LT regular simultaneous + injected simultaneous mode, on groups regular and injected ADC_DUALMODE_REGSIMULT_ALTERTRIG ADC dual mode enabled: Combined regular simultaneous + alternate trigger DocID027328 / 1166 106 Rev 2

107 UM1850 ADC Extensio n Driver HAL mode, on groups regular and injected ADC dual mode enabled: Combined ADC_DUALMODE_INJECSIMULT_INTERLFA injected simultaneous + fast interleaved ST d mode, on groups regular and injecte (delay between ADC sampling phases: 7 ADC clock cycles (equivalent to parameter "TwoSamplingDelay" set to "ADC_TWOSAMPLINGDELAY_7CYCL ES" on other STM32 devices)) ADC dual mode enabled: Combined ADC_DUALMODE_INJECSIMULT_INTERLSL injected simultaneous OW + slow Interleaved mode, on groups regular and injected (delay between ADC sampling phases: 14 ADC clock cycles (equivalent to parameter "TwoSamplingDelay" set to "ADC_TWOSAMPLINGDELAY_7CYCL ES" on other STM32 devices)) ode enabled: Injected ADC_DUALMODE_INJECSIMULT ADC dual m simultaneous mode, on group injected ADC dual mode enabled: Regular ADC_DUALMODE_REGSIMULT simultaneous mode, on group regular ADC dual mode enabled: Fast ADC_DUALMODE_INTERLFAST interleaved mode, on group regular (delay between A DC sampling phases: 7 ADC clock cycles (equivalent to parameter "TwoSamplingDelay" set to "ADC_TWOSAMPLINGDELAY_7CYCL ES" on other STM32 devices)) ADC dual mode enabled: Slow ADC_DUALMODE_INTERLSLOW interleaved mode, on group regular (delay between ADC sampling phases: 14 ADC clock cycles (equivalent to parameter "TwoSamplingDelay" set to "ADC_TWOSAMPLINGDELAY_7CYCL ES" on other STM32 devices)) ADC_DUALMODE_ALTERTRIG ADC dual mode enabled: Alternate trigger mode, on group injected ADCEx external trigger enable for injected group ADC_EXTERNALTRIGINJECCONV_EDGE_NONE ADC_EXTERNALTRIGINJECCONV_EDGE_RISING ADCEx External trigger selection for injected group ALTRIGINJECCONV_T2_TRGO < List of external triggers with generic ADC_EXTERN trigger name, independently of ADC_EXTERNALTRIGINJECCONV_T2_CC1 ADC_EXTERNALTRIGINJECCONV_T3_CC4 ADC_EXTERNALTRIGINJECCONV_T4_TRGO ADC_EXTERNALTRIGINJECCONV_EXT_IT15 External triggers of injected group for 2 DocID027328 Rev 1166 107 /

108 HAL ADC Extension Driver UM1850 ADC3 only ADC_EXTERNALTRIGINJECCONV_T4_CC3 ADC_EXTERNALTRIGINJECCONV_T8_CC2 ADC_EXTERNALTRIGINJECCONV_T5_TRGO ADC_EXTERNALTRIGINJECCONV_T5_CC4 ADC_EXTERNALTRIGINJECCONV_T1_CC4 < External triggers of injected group for all ADC instances ADC_EXTERNALTRIGINJECCONV_T1_TRGO Note: TIM8_CC4 is available on ADC1 and ADC2 only in high - density and ADC_EXTERNALTRIGINJECCONV_T8_CC4 ADC_INJECTED_SOFTWARE_START erification ADCEx injected nb conv v IS_ADC_INJECTED_NB_CONV ADCEx rank into injected group ADC_INJECTED_RANK_1 ADC_INJECTED_RANK_2 ADC_INJECTED_RANK_3 ADC_INJECTED_RANK_4 ADC Extended Internal HAL driver trigger selection for injected group ADC1_2_EXTERNALTRIGINJEC_T2_TRGO ADC1_2_EXTERNALTRIGINJEC_T2_CC1 ADC1_2_EXTERNALTRIGINJEC_T3_CC4 ADC1_2_EXTERNALTRIGINJEC_T4_TRGO ADC1_2_EXTERNALTRIGINJEC_EXT_IT15 ADC1_2_EXTERNALTRIGINJEC_T8_CC4 ADC3_EXTERNALTRIGINJEC_T4_CC3 ADC3_EXTERNALTRIGINJEC_T8_CC2 ADC3_EXTERNALTRIGINJEC_T8_CC4 ADC3_EXTERNALTRIGINJEC_T5_TRGO ADC3_EXTERNALTRIGINJEC_T5_CC4 ADC1_2_3_EXTERNALTRIGINJEC_T1_TRGO ADC1_2_3_EXTERNALTRIGINJEC_T1_CC4 ADC1_2_3_JSWSTART trigger selection for regular group ADC Extended Internal HAL driver ADC1_2_EXTERNALTRIG_T1_CC1 ADC1_2_EXTERNALTRIG_T1_CC2 ADC1_2_EXTERNALTRIG_T2_CC2 DocID027328 / 1166 108 Rev 2

109 UM1850 ADC Extension Driver HAL ADC1_2_EXTERNALTRIG_T3_TRGO ADC1_2_EXTERNALTRIG_T4_CC4 ADC1_2_EXTERNALTRIG_EXT_IT11 ADC1_2_EXTERNALTRIG_T8_TRGO ADC3_EXTERNALTRIG_T3_CC1 ADC3_EXTERNALTRIG_T2_CC3 ADC3_EXTERNALTRIG_T8_CC1 ADC3_EXTERNALTRIG_T8_TRGO ADC3_EXTERNALTRIG_T5_CC1 ADC3_EXTERNALTRIG_T5_CC3 ADC1_2_3_EXTERNALTRIG_T1_CC3 ADC1_2_3_SWSTART 2 DocID027328 Rev 1166 109 /

110 UM1850 HAL CAN Generic Driver 8 HAL CAN Generic Driver 8.1 CAN Firmware driver registers structures 8.1.1 CAN_InitTypeDef Data Fields uint32_t Prescaler uint32_t Mode uint32_t SJW uint32_t BS1 uint32_t BS2 uint32_t TTCM uint32_t ABOM uint32_t AWUM uint32_t NART uint32_t RFLM uint32_t TXFP Field Documentation uint32_t CAN_InitTypeDef::Prescaler Specifies the length of a time quantum. This parameter must be a number between Min_Data = 1 and Max_Data = 1024 uint32_t CAN_InitTypeDef::Mode Specifies the CAN operating mode. This parameter can be a value of CAN_operating_mode uint32_t CAN_InitTypeDef::SJW Specifies the maximum number of time quanta the CAN hardware is allowed to lengthen or shorten a bit to perform resynchronization. This parameter can be a value of CAN_synchronisation_jump_width uint32_t CAN_InitTypeDef::BS1 be a value Specifies the number of time quanta in Bit Segment 1. This parameter can of CAN_time_quantum_in_bit_segment_1 uint32_t CAN_InitTypeDef::BS2 Specifies the number of time quanta in Bit Segment 2. This parameter can be a value CAN_time_quantum_in_bit_segment_2 of uint32_t CAN_InitTypeDef::TTCM Enable or disable the time triggered communication mode. This parameter can be set to ENABLE or DISABLE. uint32_t CAN_InitTypeDef::ABOM Enable or disable the automatic bus is parameter can be set to off management. Th - ENABLE or DISABLE uint32_t CAN_InitTypeDef::AWUM - up mode. This parameter can be set to Enable or disable the automatic wake ENABLE or DISABLE uint32_t CAN_InitTypeDef::NART - e. This parameter can be set automatic retransmission mod Enable or disable the non to ENABLE or DISABLE uint32_t CAN_InitTypeDef::RFLM Enable or disable the receive FIFO Locked mode. This parameter can be set to ENABLE or DISABLE DocID027328 / 1166 110 Rev 2

111 UM1850 HAL CAN Generic Driver uint32_t CAN_InitTypeDef::TXFP Enable or disable the transmit FIFO priority. This parameter can be set to ENABLE or DISABLE CanTxMsgTypeDef 8.1.2 Data Fields uint32_t StdId uint32_t ExtId uint32_t IDE uint32_t RTR uint32_t DLC uint8_t Data ntation Field Docume uint32_t CanTxMsgTypeDef::StdId Specifies the standard identifier. This parameter must be a number between Min_Data = 0 and Max_Data = 0x7FF uint32_t CanTxMsgTypeDef::ExtId Specifies the extended identifier. This parameter must be a number between Min_Data = 0 and Max_Data = 0x1FFFFFFF uint32_t CanTxMsgTypeDef::IDE Specifies the type of identifier for the message that will be transmitted. This parameter can be a value of CAN_Identifier_Type uint32_t CanTxMsgTypeDef ::RTR Specifies the type of frame for the message that will be transmitted. This parameter can be a value of CAN_remote_transmission_request uint32_t CanTxMsgTypeDef::DLC mitted. This parameter must be a Specifies the length of the frame that will be trans number between Min_Data = 0 and Max_Data = 8 uint8_t CanTxMsgTypeDef::Data[8] Contains the data to be transmitted. This parameter must be a number between Min_Data = 0 and Max_Data = 0xFF 8.1.3 CanRxMsgTypeDef Data Fields uint32_t StdId uint32_t ExtId uint32_t IDE uint32_t RTR uint32_t DLC uint8_t Data uint32_t FMI uint32_t FIFONumber Field Documentation uint32_t CanRxMsgTypeDef::StdId Specifies the standard identifier. This parameter must be a number between Min_Data = 0 and Max_Data = 0x7FF uint32_t CanRxMsgTypeDef::ExtId Specifies the extended identifier. This parameter must be a number between Min_Data = 0 and Max_Data = 0x1FFFFFFF 2 DocID027328 Rev 1166 111 /

112 UM1850 HAL CAN Generic Driver uint32_t CanRxMsgTypeDef::IDE Specifies the type of identifier for the message that will be received. This parameter can be a value of CAN_Identifier_Type uint32_t CanRxMsgTypeDef::RTR eceived message. This parameter can be a value Specifies the type of frame for the r of CAN_remote_transmission_request uint32_t CanRxMsgTypeDef::DLC Specifies the length of the frame that will be received. This parameter must be a number between Min_Data = 0 a nd Max_Data = 8 uint8_t CanRxMsgTypeDef::Data[8] Contains the data to be received. This parameter must be a number between Min_Data = 0 and Max_Data = 0xFF uint32_t CanRxMsgTypeDef::FMI Specifies the index of the filter the message stored in the mailbox passes through. This parameter must be a number between Min_Data = 0 and Max_Data = 0xFF uint32_t CanRxMsgTypeDef::FIFONumber Specifies the receive FIFO number. This parameter can be CAN_FIFO0 or CAN_FIFO1 8.1.4 CAN_HandleTypeDef Data Fields CAN_TypeDef * Instance CAN_InitTypeDef Init CanTxMsgTypeDef * pTxMsg CanRxMsgTypeDef * pRxMsg __IO HAL_CAN_StateTypeDef State HAL_LockTypeDef Lock __IO uint32_t ErrorCode Field Documentation CAN_TypeDef* CAN_HandleTypeDef::Instance Register base address CAN_InitTypeDef CAN_HandleTypeDef::Init CAN required parameters CanTxMsgTypeDef* CAN_HandleTypeDef::pTxMsg Pointer to transmit structure CanRxMsgTypeDef* CAN_HandleTypeDef::pRxMsg Pointer to reception structure __IO HAL_CAN_StateT ypeDef CAN_HandleTypeDef::State CAN communication state HAL_LockTypeDef CAN_HandleTypeDef::Lock CAN locking object __IO uint32_t CAN_HandleTypeDef::ErrorCode CAN Error code 8.2 CAN Firmware driver API description to use this driver How 8.2.1 1. Enable the CAN controller interface clock using __HAL_RCC_CAN1_CLK_ENABLE() In case you are using for CAN1 and __HAL_RCC_CAN2_CLK_ENABLE() for CAN2 . CAN2 only, you have to enable the CAN1 clock 2. CAN pins configuration DocID027328 / 1166 112 Rev 2

113 UM1850 CAN Generic Driver HAL Enable the clock for the CAN GPIOs using the following function: __HAL_RCC_GPIOx_CLK_ENABLE(); Connect and configure the involved CAN pins using the following function HAL_GPIO_Init(); Initialize and configure the CAN using HAL _CAN_Init() function. 3. Transmit the desired CAN frame using HAL_CAN_Transmit() function. 4. 5. Or transmit the desired CAN frame using HAL_CAN_Transmit_IT() function. 6. Receive a CAN frame using HAL_CAN_Receive() function. eceive_IT() function. Or receive a CAN frame using HAL_CAN_R 7. Polling mode IO operation Start the CAN peripheral transmission and wait the end of this operation using HAL_CAN_Transmit(), at this stage user can specify the value of timeout according to his end application l reception and wait the end of this operation using Start the CAN periphera HAL_CAN_Receive(), at this stage user can specify the value of timeout according to his end application Interrupt mode IO operation Start the CAN peripheral transmission using HAL_CAN_Transmit_IT() t the CAN peripheral reception using HAL_CAN_Receive_IT() Star Use HAL_CAN_IRQHandler() called under the used CAN Interrupt subroutine At CAN end of transmission HAL_CAN_TxCpltCallback() function is executed and nction pointer user can add his own code by customization of fu HAL_CAN_TxCpltCallback In case of CAN Error, HAL_CAN_ErrorCallback() function is executed and user can add his own code by customization of function pointer HAL_CAN_ErrorCallback CAN HAL driver macros list Below the list of most used macr os in CAN HAL driver. __HAL_CAN_ENABLE_IT: Enable the specified CAN interrupts __HAL_CAN_DISABLE_IT: Disable the specified CAN interrupts __HAL_CAN_GET_IT_SOURCE: Check if the specified CAN interrupt source is enabled or disabled __HAL_CAN_CLEAR_FLAG: Clear the CAN's pending flags __HAL_CAN_GET_FLAG: Get the selected CAN's flag status You can refer to the CAN HAL driver header file for more useful macros 8.2.2 initialization functions - Initialization and de This section provides functions allowing to: Initialize and configure the CAN. initialize the CAN. - De This section contains the following APIs: HAL_CAN_Init() HAL_CAN_ConfigFilter() 2 DocID027328 Rev 1166 113 /

114 HAL UM1850 CAN Generi c Driver HAL_CAN_DeInit() HAL_CAN_MspInit() HAL_CAN_MspDeInit() 8.2.3 IO operation functions This section provides functions allowing to: Transmit a CAN frame message. Receive a CAN frame message. Enter CAN peripheral in sleep mode. Wake up the CAN peripheral from sleep mode. This section contains the following APIs: HAL_CAN_Transmit() HAL_CAN_Transmit_IT() HAL_CAN_Receive() HAL_CAN_Receive_IT() HAL_CAN_Sleep() HAL_CAN_WakeUp() HAL_CAN_IRQHandler() HAL_CAN_TxCpltCallback() HAL_CAN_RxCpltCallback() HAL_CAN_ErrorCallback() P eripheral State and Error functions 8.2.4 This subsection provides functions allowing to : Check the CAN state. Check CAN Errors detected during interrupt process This section contains the following APIs: HAL_CAN_GetState() HAL_CAN_GetError() 8.2.5 Detailed description of functions HAL_CAN_Init HAL_StatusTypeDef HAL_CAN_Init (CAN_HandleTypeDef * Function name hcan) Initializes the CAN peripheral according to the specified Function description parameters in the CAN_InitStruct. Parameters pointer to a CAN_HandleTypeDef structure that hcan: contains the configuration information for the sp ecified CAN. Return values status HAL: HAL_CAN_ConfigFilter HAL_StatusTypeDef HAL_CAN_ConfigFilter Function name (CAN_HandleTypeDef * hcan, CAN_FilterConfTypeDef * sFilterConfig) DocID027328 / 1166 114 Rev 2

115 UM1850 CAN Generic Driver HAL Function description Configures the CAN reception filter according to the specified parameters in the CAN_FilterInitStruct. Parameters pointer to a CAN_HandleTypeDef structure that hcan: contains the configuration information for the specified CAN. sFilterConfig: pointer to a CAN_FilterConfTypeDef structure that contains the filter configuration information. Return values None: HAL_CAN_DeInit HAL_StatusTypeDef HAL_CAN_DeInit (CAN_HandleTypeDef * Function name hcan) Deinitializes the CANx p Function description eripheral registers to their default reset values. Parameters pointer to a CAN_HandleTypeDef structure that hcan: contains the configuration information for the specified CAN. Return values HAL: status HAL_CAN_MspInit HAL_CAN_MspInit (CAN_HandleTypeDef * hcan) void Function name Initializes the CAN MSP. Function description Parameters hcan: pointer to a CAN_HandleTypeDef structure that contains the configuration information for the specified CAN. Return values None: HAL_CAN_MspDeInit void HAL_CAN_MspDeInit (CAN_HandleTypeDef * hcan) Function name DeInitializes the CAN MSP. Function description Parameters hcan: pointer to a CAN_HandleTypeDef structure that contains the configuration information for the specified CAN. Return values None: HAL_CAN_Transmit HAL_StatusTypeDef HAL_CAN_Transmit Function name (CAN_HandleTypeDef * hcan, uint32_t Timeout) Function des Initiates and transmits a CAN frame message. cription Parameters hcan: pointer to a CAN_HandleTypeDef structure that contains the configuration information for the specified CAN. Specify Timeout value Timeout: Return values status HAL: 2 DocID027328 Rev 1166 115 /

116 HAL UM1850 CAN Generic Driver HAL_CAN_Transmit_IT HAL_StatusTypeDef HAL_CAN_Transmit_IT Function name (CAN_HandleTypeDef * hcan) Function description Initiates and transmits a CAN frame message. Parameters hcan: pointer to a CAN_HandleTypeDef structure that contains the configurati on information for the specified CAN. Return values HAL: status HAL_CAN_Receive HAL_StatusTypeDef HAL_CAN_Receive (CAN_HandleTypeDef Function name * hcan, uint8_t FIFONumber, uint32_t Timeout) Receives a correct CAN frame. Function description Parameters hcan: pointer to a CAN_HandleTypeDef structure that contains the configuration information for the specified CAN. FIFO Number value FIFONumber: Timeout: Specify Timeout value Return values HAL: status HAL_CAN_Receive_IT HAL_StatusTypeDef HAL_CAN_Receive_IT Function name (CAN_HandleTypeDef * hcan, uint8_t FIFONumber) Receives a correct CAN frame. Function description Parameters hcan: pointer to a CAN_HandleTypeDef structure that ed CAN. contains the configuration information for the specifi Specify the FIFO number FIFONumber: Return values HAL: status HAL_CAN_Sleep HAL_StatusTypeDef HAL_CAN_Sleep (CAN_HandleTypeDef * Function name hcan) Enters the Sleep (low power) mode. Function description Parameters hcan: pointer to a CAN_HandleTypeDef structure that contains the configuration information for the specified CAN. Return values status. HAL: HAL_CAN_WakeUp HAL_StatusTypeDef HAL_CAN_WakeUp Function name (CAN_HandleTypeDef * hcan) Wakes up the CAN peripheral from sleep mode, after that the CAN Function description peripheral is in the normal mode. Parameters hcan: pointer to a CAN_HandleTypeDef structure that contains the configuration information for the specified CAN. DocID027328 / 1166 116 Rev 2

117 UM1850 HAL CAN Generic Driver Return values HAL: status. HAL_CAN_IRQHandler void HAL_CAN_IRQHandler (CAN_HandleTypeDef * hcan) Function name Handles CAN interrupt request. Function description Parameters hcan: pointer to a CAN_HandleTypeDef structure that ied CAN. contains the configuration information for the specif Return values None: HAL_CAN_TxCpltCallback void HAL_CAN_TxCpltCallback (CAN_HandleTypeDef * hcan) Function name Transmission complete callback in non blocking mode. Function description Parameters hcan: pointer to a CAN_HandleTypeDef structure that contains the configuration information for the specified CAN. Return values None: HAL_CAN_RxCpltCallback void HAL_CAN_RxCpltCallback (CAN_HandleTypeDef * hcan) Function name on complete callback in non blocking mode. Function description Transmissi Parameters hcan: pointer to a CAN_HandleTypeDef structure that contains the configuration information for the specified CAN. Return values None: HAL_CAN_ErrorCallback (CAN_HandleTypeDef * hcan) void HAL_CAN_ErrorCallback Function name Function description Error CAN callback. Parameters pointer to a CAN_HandleTypeDef structure that hcan: contains the configuration information for the specified CAN. Return values None: HAL_CAN_GetError uint32_t HAL_CAN_GetError (CAN_HandleTypeDef * hcan) Function name Return the CAN error code. Function description Parameters pointer to a CAN_HandleTypeDef structure that hcan: contains the configuration information for the specified CAN. Return values CAN: Code Error HAL_CAN_GetState HAL_CAN_StateTypeDef HAL_CAN_GetState Function name Rev 2 117 / 1166 DocID027328

118 HAL UM1850 CAN Generic Driver (CAN_HandleTypeDef * hcan) Function description return the CAN state Parameters hcan: pointer to a CAN_HandleTypeDef structure that contains the configuration information for the specified CAN. Return values state HAL: 8.3 CAN Firmware driver defines 8.3.1 CAN CAN Error Code No error HAL_CAN_ERROR_NONE EWG error HAL_CAN_ERROR_EWG HAL_CAN_ERROR_EPV EPV error BOF error HAL_CAN_ERROR_BOF Stuff error HAL_CAN_ERROR_STF Form error HAL_CAN_ERROR_FOR HAL_CAN_ERROR_ACK Acknowledgment error Bit recessive HAL_CAN_ERROR_BR HAL_CAN_ERROR_BD LEC dominant LEC transfer error HAL_CAN_ERROR_CRC FIFO0 overrun error HAL_CAN_ERROR_FOV0 HAL_CAN_ERROR_FOV1 FIFO1 overrun error CAN Exported Macros Description: __HAL_CAN_RESET_HANDLE_STATE Reset CAN handle state. Parameters: __HANDLE__: CAN handle. Return value: None Description: __HAL_CAN_ENABLE_IT Enable the specified CAN interrupts. Parameters: __HANDLE__: CAN handle. __INTERRUPT__: CAN Interrupt. This parameter can be one of the following values: Transmit mailbox CAN_IT_TME: empty interrupt enable CAN_IT_FMP0: FIFO 0 message pending interrupt DocID027328 / 1166 118 Rev 2

119 UM1850 HAL CAN Generic Driver CAN_IT_FF0 : FIFO 0 full interrupt CAN_IT_FOV0: FIFO 0 overrun interrupt CAN_IT_FMP1: FIFO 1 message pending interrupt CAN_IT_FF1 : FIFO 1 full interrupt CAN_IT_FOV1: FIFO 1 overrun interrupt up interrupt - CAN_IT_WKU : Wake CAN_IT_SLK : Sleep acknowledge interrupt CAN_IT_EWG : Error warning interrupt CAN_IT_EPV : Error passive interrupt off interrupt CAN_IT_BOF : Bus - CAN_IT_LEC : Last error code interrupt Error Interrupt CAN_IT_ERR : Return value: None. Description: __HAL_CAN_DISABLE_IT Disable the specified CAN interrupts. Parameters: __HANDLE__: CAN handle. __INTERRUPT__: CAN Interrupt. This parameter can be one of the following values: CAN_IT_TME: Transmit mailbox empty interrupt enable CAN_IT_FMP0: FIFO 0 message pending interrupt CAN_IT_FF0 : FIFO 0 full interrupt CAN_IT_FOV0: FIFO 0 overrun interrupt CAN_IT_FMP1: FIFO 1 message pending interrupt CAN_IT_FF1 : FIFO 1 full interrupt CAN_IT_FOV1: FIFO 1 overrun interrupt up interrupt CAN_IT_WKU : Wake - CAN_IT_SLK : Sleep acknowledge interrupt CAN_IT_EWG : Error warning interrupt CAN_IT_EPV : Error passive interrupt off interrupt CAN_IT_BOF : Bus - CAN_IT_LEC : Last error code interrupt CAN_IT_ERR : Error Interrupt 2 DocID027328 Rev 1166 119 /

120 HAL UM1850 CAN Generic Driver eturn value: R None. Description: __HAL_CAN_MSG_PENDING Return the number of pending received messages. Parameters: __HANDLE__: CAN handle. __FIFONUMBER__: Receive FIFO number, CAN_FIFO0 or CAN_FIFO1. Return value: The: number of pending message. Description: __HAL_CAN_GET_FLAG Check whether the specified CAN flag is set or not. Parameters: __HANDLE__: specifies the CAN Handle. __FLAG__: specifies the flag to check. This parameter can be one of the following values: CAN_TSR_RQCP0: Request MailBox0 Flag CAN_TSR_RQCP1: Request MailBox1 Flag CAN_TSR_RQCP2: Request MailBox2 Flag CAN_FLAG_TXOK0: Transmission OK MailBox0 Flag CAN_FLAG_TXOK1: Transmission OK MailBox1 Flag CAN_FLAG_TXOK2: Transmission OK MailBox2 Flag CAN_FLAG_TME0: Transmit mailbox 0 empty Flag CAN_FLAG_TME1: Transmit mailbox 1 empty Flag CAN_FLAG_TME2: Transmit mailbox 2 empty Flag CAN_FLAG_FMP0: FIFO 0 Message Pending Flag CAN_FLAG_FF0: FIFO 0 Full Flag CAN_FLAG_FOV0: FIFO 0 Overrun Flag CAN_FLAG_FMP1: FIFO 1 Message Pending Flag CAN_FLAG_FF1: FIFO 1 Full Flag CAN_FLAG_FOV1: FIFO 1 Overrun Flag CAN_FLAG_WKU: Wake up Flag DocID027328 / 1166 120 Rev 2

121 UM1850 CAN Generic Driver HAL CAN_FLAG_SLAK: Sleep acknowledge Flag CAN_FLAG_SLAKI: Sleep acknowledge Flag CAN_FLAG_EWG: Error Warning Flag CAN_FLAG_EPV: Error Passive Flag Of f Flag - CAN_FLAG_BOF: Bus Return value: The: new state of __FLAG__ (TRUE or FALSE). Description: __HAL_CAN_CLEAR_FLAG Clear the specified CAN pending flag. Parameters: __HANDLE__: specifies the CAN Handle. __FLAG__: specifies the flag to check. This parameter can be one of the following values: CAN_TSR_RQCP0: Request MailBox0 Flag CAN_TSR_RQCP1: Request MailBox1 Flag CAN_TSR_RQCP2: Request MailBox2 Flag CAN_FLAG_TXOK0: Transmission OK MailBox0 Flag _TXOK1: Transmission CAN_FLAG OK MailBox1 Flag CAN_FLAG_TXOK2: Transmission OK MailBox2 Flag CAN_FLAG_TME0: Transmit mailbox 0 empty Flag CAN_FLAG_TME1: Transmit mailbox 1 empty Flag CAN_FLAG_TME2: Transmit mailbox 2 empty Flag CAN_FLAG_FMP0: FIFO 0 Message Flag Pending CAN_FLAG_FF0: FIFO 0 Full Flag CAN_FLAG_FOV0: FIFO 0 Overrun Flag CAN_FLAG_FMP1: FIFO 1 Message Pending Flag CAN_FLAG_FF1: FIFO 1 Full Flag CAN_FLAG_FOV1: FIFO 1 Overrun Flag CAN_FLAG_WKU: Wake up Flag CAN_FLAG_SLAKI: Sleep acknowledge Flag lue: Return va 2 DocID027328 Rev 1166 121 /

122 HAL UM1850 CAN Generic Driver The: new state of __FLAG__ (TRUE or FALSE). Description: __HAL_CAN_GET_IT_SOURCE Check if the specified CAN interrupt source is enabled or disabled. Parameters: __HANDLE__: specifies the CAN Handle. __INTERRUPT__: specifies the CAN interrupt source to check. This parameter can be one of the following values: CAN_IT_TME: Transmit mailbox empty interrupt enable CAN_IT_FMP0: FIFO 0 message pending interrupt CAN_IT_FF0 : FIFO 0 full interrupt CAN_IT_FOV0 : FIFO 0 overrun interrupt CAN_IT_FMP1: FIFO 1 message pending interrupt CAN_IT_FF1 : FIFO 1 full interrupt CAN_IT_FOV1: FIFO 1 overrun interrupt CAN_IT_WKU : Wake - up interrupt CAN_IT_SLK : Sleep acknowledge interrupt CAN_IT_EWG : Error warning interrupt AN_IT_EPV : Error passive interrupt C CAN_IT_BOF : Bus off interrupt - CAN_IT_LEC : Last error code interrupt CAN_IT_ERR : Error Interrupt Return value: The: new state of __IT__ (TRUE or FALSE). Description: __HAL_CAN_TRANSMIT_STATUS Check the transmission status of a CAN Frame. Parameters: __HANDLE__: specifies the CAN Handle. __TRANSMITMAILBOX__: the number of the mailbox that is used for transmission. Return value: The: new status of transmission (TRUE or FALSE). Description: __HAL_CAN_FIFO_RELEASE 122 DocID027328 / Rev 2 1166

123 UM1850 CAN Generic Driver HAL se the specified receive FIFO. Relea Parameters: __HANDLE__: CAN handle. __FIFONUMBER__: Receive FIFO number, CAN_FIFO0 or CAN_FIFO1. Return value: None. Description: __HAL_CAN_CANCEL_TRANSMIT Cancel a transmit request. Parameters: Handle. __HANDLE__: specifies the CAN __TRANSMITMAILBOX__: the number of the mailbox that is used for transmission. Return value: None. Description: __HAL_CAN_DBG_FREEZE Enable or disables the DBG Freeze for CAN. Parameters: __HANDLE__: specifies the CAN Handle. __NEWSTATE__: new state of the CAN peripheral. This parameter can be: ENABLE (CAN reception/transmission is frozen during debug. Reception FIFOs can still be accessed/controlled normally) or DISABLE (CAN is working during debug). Return value: None CAN Filter FIFO Filter FIFO 0 assignment for filter x CAN_FILT ER_FIFO0 Filter FIFO 1 assignment for filter x CAN_FILTER_FIFO1 CAN Filter Mode CAN_FILTERMODE_IDMASK Identifier mask mode CAN_FILTERMODE_IDLIST Identifier list mode CAN Filter Scale bit filters CAN_FILTERSCALE_16BIT Two 16 - CAN_FILTERSCALE_32BIT bit filter - One 32 CAN Flags Request MailBox0 flag CAN_FLAG_RQCP0 CAN_FLAG_RQCP1 Request MailBox1 flag 2 DocID027328 Rev 1166 123 /

124 HAL UM1850 CAN Generic Driver Request MailBox2 flag CAN_FLAG_RQCP2 CAN_FLAG_TXOK0 Transmission OK MailBox0 flag CAN_FLAG_TXOK1 Transmission OK MailBox1 flag Transmission OK MailBox2 flag CAN_FLAG_TXOK2 Transmit mailbox 0 empty flag CAN_FLAG_TME0 Transmit mailbox 0 empty flag CAN_FLAG_TME1 CAN_FLAG_TME2 Transmit mailbox 0 empty flag CAN_FLAG_FF0 FIFO 0 Full flag CAN_FLAG_FOV0 FIFO 0 Overrun flag CAN_FLAG_FF1 FIFO 1 Full flag CAN_FLAG_FOV1 FIFO 1 Overrun flag CAN_FLAG_WKU Wake up flag CAN_FLAG_SLAK Sleep acknowledge flag Sleep acknowledge flag CAN_FLAG_SLAKI Error warning flag CAN_FLAG_EWG Error passive flag CAN_FLAG_EPV CAN_FLAG_BOF Bus - Off flag CAN Identifier Type CAN_ID_STD Standard Id CAN_ID_EXT Extended Id CAN initialization Status CAN_INITSTATUS_FAILED CAN initialization failed CAN_INITSTATUS_SUCCESS CAN initialization OK CAN Interrupts Transmit mailbox empty interrupt CAN_IT_TME CAN_IT_FMP0 FIFO 0 message pending interrupt CAN_IT_FF0 FIFO 0 full interrupt FIFO 0 overrun interrupt CAN_IT_FOV0 FIFO 1 message pending interrupt CAN_IT_FMP1 FIFO 1 full interrupt CAN_IT_FF1 CAN_IT_FOV1 FIFO 1 overrun interrupt CAN_IT_WKU Wake - up interrupt Sleep acknowledge interrupt CAN_IT_SLK CAN_IT_EWG Error warning interrupt Error passive interrupt CAN_IT_EPV off interrupt - Bus CAN_IT_BOF DocID027328 / 1166 124 Rev 2

125 UM1850 CAN Generic Driver HAL Last error code interrupt CAN_IT_LEC CAN_IT_ERR Error Interrupt CAN Operating Mode Normal mode CAN_MODE_NORMAL CAN_MODE_LOOPBACK Loopback mode CAN_MODE_SILENT Silent mode CAN_MODE_SILENT_LOOPBACK Loopback combined with silent mode CAN Receive FIFO Number CAN_FIFO0 CAN FIFO 0 used to receive CAN_FIFO1 CAN FIFO 1 used to receive CAN Remote Transmission Request CAN_RTR_DATA Data frame Remote frame CAN_RTR_REMOTE CAN Synchronization Jump Width 1 time quantum CAN_SJW_1TQ 2 time quantum CAN_SJW_2TQ 3 time quantum CAN_SJW_3TQ 4 time quantum CAN_SJW_4TQ CAN Time Quantum in Bit Segment 1 CAN_BS1_1TQ 1 time quantum CAN_BS1_2TQ 2 time quantum CAN_BS1_3TQ 3 time quantum 4 time quantum CAN_BS1_4TQ CAN_BS1_5TQ 5 time quantum 6 time quantum CAN_BS1_6TQ 7 time quantum CAN_BS1_7TQ CAN_BS1_8TQ 8 time quantum CAN_BS1_9TQ 9 time quantum CAN_BS1_10TQ 10 time quantum CAN_BS1_11TQ 11 time quantum CAN_BS1_12TQ 12 time quantum CAN_BS1_13TQ 13 time quantum 14 time quantum CAN_BS1_14TQ 15 time quantum CAN_BS1_15TQ 16 time quantum CAN_BS1_16TQ CAN Time Quantum in bit segment 2 2 DocID027328 Rev 1166 125 /

126 HAL UM1850 CAN Generic Driver CAN_BS2_1TQ 1 time quantum CAN_BS2_2TQ 2 time quantum 3 time quantum CAN_BS2_3TQ 4 time quantum CAN_BS2_4TQ CAN_BS2_5TQ 5 time quantum CAN_BS2_6TQ 6 time quantum 7 time quantum CAN_BS2_7TQ 8 time quantum CAN_BS2_8TQ CAN Transmit Constants CAN cell did not provide CAN_TxStatus_NoMailBox CAN_TXSTATUS_NOMAILBOX DocID027328 / 1166 126 Rev 2

127 UM1850 CAN Extension Driver HAL HAL CAN Extension Driver 9 9.1 CANEx Firmware driver registers structures 9.1.1 CAN_FilterConfTypeDef Data Fields uint32_t FilterIdHigh uint32_t FilterIdLow uint32_t FilterMaskIdHigh uint32_t FilterMaskIdLow uint32_t FilterFIFOAssignment uint32_t FilterNumber uint32_t FilterMode uint32_t FilterScale uint32_t FilterActivation uint32_t BankNumber Field Documentation uint32_t CAN_FilterConfTypeDef::FilterIdHigh - bit configuration, first one for a Specifies the filter identification number (MSBs for a 32 bit configuration). This parameter must be a number between Min_Data = 0x0000 - 16 and Max_Data = 0xFFFF. uint32_t CAN_FilterConfTypeDef::FilterIdLow Specifies the filter identification number (LSBs for a 32 - bit configuration, second one bit configuration). This parameter must be a number between Min_Data = for a 16 - 0x0000 and Max_Data = 0xFFFF. uint32_t CAN_FilterConfTypeDef::FilterMaskIdHigh Specifies the filter m ask number or identification number, according to the mode - bit configuration, first one for a 16 bit configuration). This parameter (MSBs for a 32 - must be a number between Min_Data = 0x0000 and Max_Data = 0xFFFF. uint32_t CAN_FilterConfTypeDef::FilterMask IdLow Specifies the filter mask number or identification number, according to the mode bit configuration). This parameter - bit configuration, second one for a 16 - (LSBs for a 32 must be a number between Min_Data = 0x0000 and Max_Data = 0xFFFF. uint32_t CAN_ FilterConfTypeDef::FilterFIFOAssignment Specifies the FIFO (0 or 1) which will be assigned to the filter. This parameter can be CAN_filter_FIFO a value of uint32_t CAN_FilterConfTypeDef::FilterNumber ich will be initialized. This parameter must be a number between Specifies the filter wh Min_Data = 0 and Max_Data = 13. uint32_t CAN_FilterConfTypeDef::FilterMode Specifies the filter mode to be initialized. This parameter can be a value of filter_mode CAN_ uint32_t CAN_FilterConfTypeDef::FilterScale CAN_filter_scale Specifies the filter scale. This parameter can be a value of uint32_t CAN_FilterConfTypeDef::FilterActivation Enable or disable the filter. This param eter can be set to ENABLE or DISABLE. uint32_t CAN_FilterConfTypeDef::BankNumber Select the start slave bank filter This parameter must be a number between Min_Data = 0 and Max_Data = 28. 2 DocID027328 Rev 1166 127 /

128 CEC Generic Driver HAL UM1850 10 HAL CEC Generic Driver Firmware driver registers structures 10.1 CEC CEC_InitTypeDef 10.1.1 Data Fields uint32_t TimingErrorFree uint32_t PeriodErrorFree uint16_t OwnAddress uint8_t * RxBuffer Field Documentation uint32_t CEC_InitTypeDef::TimingErrorFree Configures the CEC Bit Timing Error Mode. This parameter can be a value of CEC_BitTimingErrorMode uint32_t CEC_InitTypeDef::PeriodErrorFree Configures the CEC Bit Period Error Mode. This parameter can be a value of CEC_BitPeriodErrorMode uint16_t CEC_InitTypeDef::OwnAddress Own addresses configuration This parameter can be a value of CEC_OWN_ADDRESS peDef::RxBuffer uint8_t* CEC_InitTy CEC Rx buffer pointeur 10.1.2 CEC_HandleTypeDef Data Fields CEC_TypeDef * Instance CEC_InitTypeDef Init uint8_t * pTxBuffPtr uint16_t TxXferCount uint16_t RxXferSize HAL_LockTypeDef Lock HAL_CEC_StateTypeDef gState HAL_CEC_StateTypeDef RxState uint32_t ErrorCode Field Documentation CEC_TypeDef* CEC_HandleTypeDef::Instance CEC registers base address CEC_InitTypeDef CEC_HandleTypeDef::Init CEC communication parameters peDef::pTxBuffPtr uint8_t* CEC_HandleTy Pointer to CEC Tx transfer Buffer uint16_t CEC_HandleTypeDef::TxXferCount CEC Tx Transfer Counter uint16_t CEC_HandleTypeDef::RxXferSize CEC Rx Transfer size, 0: header received only HAL_LockTypeDef CEC_HandleTypeDef::Lock Locking obje ct DocID027328 28 / 1166 1 Rev 2

129 UM1850 HAL CEC Generic Driver HAL_CEC_StateTypeDef CEC_HandleTypeDef::gState CEC state information related to global Handle management and also related to Tx operations. This parameter can be a value of HAL_CEC_StateTypeDef HAL_CEC_StateTypeDef CEC_HandleTypeDef::RxState CEC state information related to Rx operations. This parameter can be a value of HAL_CEC_StateTypeDef uint32_t CEC_HandleTypeDef::ErrorCode For errors handling purposes, copy of ISR register in case error is reported 10.2 CEC Firmware driver API description How to use this driver 10.2.1 The CEC HAL driver can be used as follow: 1. Declare a CEC_HandleTypeDef handle structure. Initialize the CEC low level resources by implementing the HAL_CEC_MspInit ()API: 2. a. Enable the CEC interface clock. b. CEC pins configuration: Enable the clock for the CEC GPIOs. up. - Configure these CEC pins as alternate function pull NVIC configuration if yo c. u need to use interrupt process (HAL_CEC_Transmit_IT() and HAL_CEC_Receive_IT() APIs): Configure the CEC interrupt priority. Enable the NVIC CEC IRQ handle. The specific CEC interrupts (Transmission complete interrupt, RXNE will be managed using the macros interrupt and Error Interrupts) __HAL_CEC_ENABLE_IT() and __HAL_CEC_DISABLE_IT() inside the transmit and receive process. Program the Bit Timing Error Mode and the Bit Period Error Mode in the hcec Init 3. structure. 4. Initialize the CEC registers by callin g the HAL_CEC_Init() API. This API (HAL_CEC_Init()) configures also the low level Hardware (GPIO, CLOCK, CORTEX...etc) by calling the customed HAL_CEC_MspInit() API. Initialization and Configuration functions 10.2.2 This subsection provides a set of functions allowing to initialize the CEC The following parameters need to be configured: TimingErrorFree PeriodErrorFree InitiatorAddress This section contains the following APIs: HAL_CEC_Init() HAL_CEC_DeInit() HAL_CEC_SetDeviceAddress() HAL_CEC_MspInit() HAL_CEC_MspDeInit() 2 DocID027328 Rev 1166 129 /

130 CEC Generic Driver HAL UM1850 IO operation functions 10.2.3 This subsection provides a set of functions allowing to manage the CEC data transfers. 1. The CEC handle must contain the initiator (TX side) and the destination (RX si de) logical addresses (4 bit long addresses, 0xF for broadcast messages destination) - 2. The communication is performed using Interrupts. These API's return the HAL status. The end of the data processing will be indicated through the dedicated CEC IRQ when ing Interrupt mode. The HAL_CEC_TxCpltCallback(), HAL_CEC_RxCpltCallback() us user callbacks will be executed respectively at the end of the transmit or Receive process The HAL_CEC_ErrorCallback() user callback will be executed when a etected communication error is d API's with Interrupt are : (+) HAL_CEC_Transmit_IT() (+) HAL_CEC_IRQHandler() 3. 4. A set of User Callbacks are provided: (+) HAL_CEC_TxCpltCallback() (+) HAL_CEC_RxCpltCallback() (+) HAL_CEC_ErrorCallback() This subsection provides a set of function s allowing to manage the CEC data transfers. (#) The CEC handle must contain the initiator (TX side) and the destination (RX side) logical addresses (4 bit long addresses, 0xF for broadcast messages destination) (#) The - communication is performed using Int errupts. These API's return the HAL status. The end of the data processing will be indicated through the dedicated CEC IRQ when using Interrupt mode. The HAL_CEC_TxCpltCallback(), HAL_CEC_RxCpltCallback() user end of the transmit or Receive process The callbacks will be executed respectively at the HAL_CEC_ErrorCallback() user callback will be executed when a communication error is detected (#) API's with Interrupt are : HAL_CEC_Transmit_IT() HAL_CEC_IRQHandler() (#) A set of User Callbacks are provided: H AL_CEC_TxCpltCallback() HAL_CEC_RxCpltCallback() HAL_CEC_ErrorCallback() This section contains the following APIs: HAL_CEC_Transmit_IT() HAL_CEC_GetLastReceivedFrameSize() HAL_CEC_ChangeRxBuffer() HAL_CEC_IRQHandler() HAL_CEC_TxCpltCallback() HAL_CEC_RxCpltCallback() HAL_CEC_ErrorCallback() Peripheral Control function 10.2.4 This subsection provides a set of functions allowing to control the CEC. - HAL_CEC_GetState() API can be helpful to check in run CEC time the state of the peripheral. - HAL_CEC_GetError() API can be helpful to check in run time the error of the CEC peripheral. This section contains the following APIs: HAL_CEC_GetState() HAL_CEC_GetError() DocID027328 / 1166 130 Rev 2

131 HAL UM1850 CEC Generic Driver Detailed description of functions 10.2.5 HAL_CEC_Init HAL_StatusTypeDef HAL_CEC_Init (CEC_HandleTypeDef * Function name hcec) Function description Initializes the CEC mode according to the specified parameters in the CEC_InitTypeDef and creates the associated handle . Parameters hcec: CEC handle Return values HAL: status HAL_CEC_DeInit ypeDef * HAL_StatusTypeDef HAL_CEC_DeInit (CEC_HandleT Function name hcec) Function description DeInitializes the CEC peripheral. Parameters hcec: CEC handle Return values status HAL: HAL_CEC_SetDeviceAddress HAL_StatusTypeDef HAL_CEC_SetDeviceAddress Function name (CEC_HandleTypeDef * hcec, uint16_t CEC_OwnAddress) Function description Initializes the Own Address of the CEC device. Parameters CEC handle hcec: The CEC own address. CEC_OwnAddress: Return values HAL: status HAL_CEC_MspInit void HAL_CEC_MspInit (CEC_HandleTypeDef * h cec) Function name Function description CEC MSP Init. Parameters hcec: CEC handle Return values None: HAL_CEC_MspDeInit void HAL_CEC_MspDeInit (CEC_HandleTypeDef * hcec) Function name Function description CEC MSP DeInit. Parameters CEC handle hcec: values Return None: HAL_CEC_Transmit_IT HAL_StatusTypeDef HAL_CEC_Transmit_IT Function name (CEC_HandleTypeDef * hcec, uint8_t InitiatorAddress, uint8_t 2 DocID027328 Rev 1166 131 /

132 HAL UM1850 CEC Generic Driver DestinationAddress, uint8_t * pData, uint32_t Size) Function description Send data in interrupt mode. Parameters hcec: CEC handle InitiatorAddress: Initiator address DestinationAddress: destination logical address pData: pointer to input byte data buffer Size: amount of data to be sent in bytes (without counting the header). 0 means only the header is sent (ping operation). Maximum TX size is 15 bytes (1 opcode and up to 14 operands). Return values HAL: status HAL_CEC_GetLastReceivedFrameSize uint32_t HAL_CEC_GetLastReceivedFrameSize Function name (CEC_HandleTypeDef * hcec) Get size of the received frame. Function description Parameters hcec: CEC handle Return values size Frame: HAL_CEC_ChangeRxBuffer void HAL_CEC_ChangeRxBuffer (CEC_HandleTypeDef * hcec, Function name uint8_t * Rxbuffer) Function description Change Rx Buffer. Parameters hcec: CEC handle Rxbuffer: Rx Buffer Return values size Frame: Notes This function can be called only inside the HAL_CEC_RxCpltCallback() HAL_CEC_IRQHandler void HAL_CEC_IRQHandler (CEC_HandleTypeDef * hcec) Function name Function description This function handles CEC interrupt requests. Parameters CEC handle hcec: Return values None: HAL_CEC_TxCpltCallback void HAL_CEC_TxCpltCallback (CEC_HandleTypeDef * hcec) Function name Tx Transfer completed callback. Function description Parameters hcec: CEC handle Return values None: DocID027328 / 1166 132 Rev 2

133 UM1850 CEC Generic Driver HAL HAL_CEC_RxCpltCallback void HAL_CEC_RxCpltCallback (CEC_HandleTypeDef * hcec, Function name uint32_t RxFrameSize) Rx Transfer completed callback. Function description Parameters CEC handle hcec: RxFrameSize: Size of frame Return values None: HAL_CEC_ErrorCallback void HAL_CEC_ErrorCallback (CEC_HandleTypeDef * hcec) Function name CEC error callbacks. Function description Parameters CEC handle hcec: Return values None: HAL_CEC_GetState HAL_CEC_StateTypeDef HAL_CEC_GetState Function name (CEC_HandleTypeDef * hcec) return the CEC state Function description Parameters hcec: pointer to a CEC_HandleTypeDef structure that contains the configuration information for the specified CEC module. Return values HAL: state HAL_CEC_GetError uint32_t HAL_CEC_GetError (CEC_HandleTypeDef * hcec) Function name Return the CEC error code. Function description Parameters : pointer to a CEC_HandleTypeDef structure that hcec: contains the configuration information for the specified CEC. Return values Error Code CEC: CEC Firmware driver defines 10.3 10.3.1 CEC t Period Error Mode Bi Bit period error Standard Mode CEC_BIT_PERIOD_ERROR_MODE_STANDARD Bit period error Flexible Mode CEC_BIT_PERIOD_ERROR_MODE_FLEXIBLE Bit Timing Error Mode Bit timing error Standard Mode CEC_BIT_TIMING_ERROR_MODE_STANDARD Bit timing error Free Mode CEC_BIT_TIMING_ERROR_MODE_ERRORFREE CEC Error Code 2 DocID027328 Rev 1166 133 /

134 HAL UM1850 CEC Generic Driver no error HAL_CEC_ERROR_NONE HAL_CEC_ERROR_BTE Bit Timing Error Bit Period Error HAL_CEC_ERROR_BPE HAL_CEC_ERROR_RBTFE Rx Block Transfer Finished Error HAL_CEC_ERROR_SBE Start Bit Error HAL_CEC_ERROR_ACKE Block Acknowledge Error HAL_CEC_ERROR_LINE Line Error HAL_CEC_ERROR_TBTFE Tx Block Transfer Finished Error CEC Exported Macros Description: __HAL_CEC_RESET_HANDLE_STATE Reset CEC handle gstate & RxState. Parameters: __HANDLE__: CEC handle. Return value: None Description: __HAL_CEC_GET_FLAG Checks whether or not the specified CEC interrupt flag is set. Parameters: __HANDLE__: specifies the CEC Handle. __FLAG__: specifies the flag to check. CEC_FLAG_TERR: Tx Error CEC_FLAG_TBTRF:Tx Block Transfer Finished CEC_FLAG_RERR: Rx Error CEC_FLAG_RBTF: Rx Block Transfer Finished Return value: ITStatus Description: __HAL_CEC_CLEAR_FLAG Clears the CEC's pending flags. Parameters: __HANDLE__: specifies the CEC Handle. __FLAG__: specifies the flag to clear. This parameter can be DocID027328 / 1166 134 Rev 2

135 HAL UM1850 CEC Generic Driver any combination of the following values: CEC_CSR_TERR: Tx Error CEC_FLAG_TBTRF: Tx Block Transfer Finished CEC_CSR_RERR: Rx Error CEC_CSR_RBTF: Rx Block Transfer Finished Return value: none Description: __ HAL_CEC_ENABLE_IT Enables the specified CEC interrupt. Parameters: __HANDLE__: specifies the CEC Handle. __INTERRUPT__: specifies the CEC interrupt to enable. This parameter can be: CEC_IT_IE : Interrupt Enable. Return value: none Description: __HAL_CEC_DISABLE_IT Disables the specified CEC interrupt. Parameters: __HANDLE__: specifies the CEC Handle. __INTERRUPT__: specifies the CEC interrupt to disable. This parameter can be: CEC_IT_IE : Interrupt Enable Return value: none Description: __HAL_CEC_GET_IT_SOURCE Checks whether or not the specified CEC interrupt is enabled. Parameters: __HANDLE__: specifies the CEC Handle. DocID027328 Rev 2 66 135 / 11

136 HAL UM1850 CEC Generic Driver __INTERRUPT__: specifies the CEC interrupt to check. This parameter can be: CEC_IT_IE : Interrupt Enable R eturn value: FlagStatus Description: __HAL_CEC_ENABLE Enables the CEC device. Parameters: __HANDLE__: specifies the CEC Handle. Return value: none Description: __HAL_CEC_DISABLE Disables the CEC device. Parameters: __HANDLE__: specifies the CEC Handle. Return value: none Description: __HAL_CEC_FIRST_BYTE_TX_SET Set Transmission Start flag. Parameters: __HANDLE__: specifies the CEC Handle. Return value: none Description: __HAL_CEC_LAST_BYTE_TX_SET Set Transmission End flag. Parameters: specifies the __HANDLE__: CEC Handle. Return value: none Description: __HAL_CEC_GET_TRANSMISSION_START_FLA G Get Transmission Start flag. Parameters: __HANDLE__: specifies the DocID027328 / 1166 136 Rev 2

137 UM1850 CEC Generic Driver HAL CEC Handle. Return value: FlagStatus Description: __HAL_CEC_GET_TRANSMISSION_END_FLAG Get Transmission End flag. Parameters: __HANDLE__: specifies the CEC Handle. Return value: FlagStatus Description: __HAL_CEC_CLEAR_OAR Clear OAR register. Parameters: __HANDLE__: specifies the CEC Handle. Return value: none Description: __HAL_CEC_SET_OAR OAR register. Set Parameters: __HANDLE__: specifies the CEC Handle. __ADDRESS__: Own Address value. Return value: none Flags definition CEC_FLAG_TSOM CEC_FLAG_TEOM CEC_FLAG_TERR CEC_FLAG_TBTRF CEC_FLAG_RSOM CEC_FLAG_REOM CEC_FLAG_RERR CEC_FLAG_RBTF CEC Initiator logical address position in message header CEC_INITIATOR_LSB_POS Interrupts definition 2 DocID027328 Rev 1166 137 /

138 HAL UM1850 CEC Generic Driver CEC_IT_IE CEC Own Address CEC_OWN_ADDRESS_NONE CEC_OWN_ADDRESS_0 CEC_OWN_ADDRESS_1 CEC_OWN_ADDRESS_2 CEC_OWN_ADDRESS_3 CEC_OWN_ADDRESS_4 CEC_OWN_ADDRESS_5 CEC_OWN_ADDRESS_6 CEC_OWN_ADDRESS_7 CEC_OWN_ADDRESS_8 CEC_OWN_ADDRESS_9 CEC_OWN_ADDRESS_10 CEC_OWN_ADDRESS_11 CEC_OWN_ADDRESS_12 CEC_OWN_ADDRESS_13 CEC_OWN_ADDRESS_14 CEC_OWN_ADDRESS_15 DocID027328 / 1166 138 Rev 2

139 UM1850 CORTEX Generic Driver HAL Generic Driver HAL CORTEX 11 11.1 CORTEX Firmware driver registers structures 11.1.1 MPU_Region_InitTypeDef Data Fields uint8_t Enable uint8_t Number uint32_t BaseAddress uint8_t Size uint8_t SubRegionDisable uint8_t TypeExtField uint8_t AccessPermission uint8_t DisableExec uint8_t IsShareable uint8_t IsCacheable uint8_t IsBufferable Field Documentation uint8_t MPU_Region_InitTypeDef::Enable Specifies the status of the region. This parameter can be a value of CORTEX_MPU_Region_Enable uint8_t MPU_Region_InitTypeDef::Number Specifies the number of the region to protect. This parameter can be a value of CORTEX_MPU_Region_Number uint32_t MPU_Region_InitTypeDef::BaseAddress Specifies the base address of the region to protect. uint8_t MPU_Region_InitTypeDef::Size Specifies the size of the region to protect. This parameter can be a val ue of CORTEX_MPU_Region_Size uint8_t MPU_Region_InitTypeDef::SubRegionDisable Specifies the number of the subregion protection to disable. This parameter must be a number between Min_Data = 0x00 and Max_Data = 0xFF uint8_t MPU_Region_InitTypeDef::TypeExtField Specifies the TEX field level. This parameter can be a value of CORTEX_MPU_TEX_Levels uint8_t MPU_Region_InitTypeDef::AccessPermission Specifies the region access permission type. This parameter can be a value of CORTEX_MPU_Region_Permission_Attributes uint8_t MPU_Region_InitTypeDef::DisableExec Specifies the instruction access status. This parameter can be a value of EX_MPU_Instruction_Access CORT uint8_t MPU_Region_InitTypeDef::IsShareable Specifies the shareability status of the protected region. This parameter can be a value of CORTEX_MPU_Access_Shareable sCacheable uint8_t MPU_Region_InitTypeDef::I Specifies the cacheable status of the region protected. This parameter can be a value CORTEX_MPU_Access_Cacheable of 2 DocID027328 Rev 1166 139 /

140 HAL CORTEX Generic Driver UM1850 uint8_t MPU_Region_InitTypeDef::IsBufferable Specifies the bufferable status of the protected r egion. This parameter can be a value of CORTEX_MPU_Access_Bufferable 11.2 CORTEX Firmware driver API description How to use this driver 11.2.1 Ho w to configure Interrupts using CORTEX HAL driver This section provides functions allowing to configure the NVIC interrupts (IRQ). The - M3 exceptions are managed by CMSIS functions. Cortex uping() function 1. Configure the NVIC Priority Grouping using HAL_NVIC_SetPriorityGro according to the following table. 2. Configure the priority of the selected IRQ Channels using HAL_NVIC_SetPriority(). Enable the selected IRQ Channels using HAL_NVIC_EnableIRQ(). 3. When the 4. igure priority. please refer to programming manual for details in how to conf NVIC_PRIORITYGROUP_0 is selected, IRQ preemption is no more possible. The pending IRQ priority will be managed only by the sub priority. IRQ priority order sub Lowest preemption priorityLowest (sorted by highest to lowest priority): priorityLowest hardware priority (IRQ number) How to configure Systick using CORTEX HAL driver Setup SysTick Timer for time base. The HAL_SYSTICK_Config()function calls the SysTick_Config() function which is a CMSIS function that: Configures the SysTick Reload register with value passed as function parameter. Configures the SysTick IRQ priority to the lowest value 0x0F. Resets the SysTick Counter register. Configures the SysTick Counter clock source to be Core Clock Source (HCLK). ick Interrupt. Enables the SysT Starts the SysTick Counter. You can change the SysTick Clock source to be HCLK_Div8 by calling the macro __HAL_CORTEX_SYSTICKCLK_CONFIG(SYSTICK_CLKSOURCE_HCLK_DIV8) just after the HAL_SYSTICK_Config() function call. The CLK_CONFIG() macro is defined inside the __HAL_CORTEX_SYSTICK stm32f1xx_hal_cortex.h file. You can change the SysTick IRQ priority by calling the HAL_NVIC_SetPriority(SysTick_IRQn,...) function just after the HAL_SYSTICK_Config() function call. The HAL_NVIC_SetPriority() call the NVIC_SetPriority() function which is a CMSIS function. To adjust the SysTick time base, use the following formula: Reload Value = SysTick Counter Clock (Hz) x Desired Time base (s) function Reload Value is the parameter to be passed for HAL_SYSTICK_Config() Reload Value should not exceed 0xFFFFFF Initialization and de 11.2.2 initialization functions - This section provides the CORTEX HAL driver functions allowing to configure Interrupts Systick functionalities DocID027328 / 1166 140 Rev 2

141 UM1850 HAL CORTEX Generic Driver This section contains the following APIs: HAL_NVIC_SetPriorityGrouping() HAL_NVIC_SetPriority() HAL_NVIC_EnableIRQ() HAL_NVIC_DisableIRQ() HAL_NVIC_SystemReset() HAL_SYSTICK_Config() Peripheral Control functions 11.2.3 ides a set of functions allowing to control the CORTEX (NVIC, This subsection prov SYSTICK, MPU) functionalities. This section contains the following APIs: HAL_MPU_Disable() HAL_MPU_Enable() HAL_MPU_ConfigRegion() HAL_NVIC_GetPriorityGrouping() HAL_NVIC_GetPriority() HAL_NVIC_SetPendingIRQ() HAL_NVIC_GetPendingIRQ() HAL_NVIC_ClearPendingIRQ() HAL_NVIC_GetActive() HAL_SYSTICK_CLKSourceConfig() HAL_SYSTICK_IRQHandler() HAL_SYSTICK_Callback() 11.2.4 Detailed description of functions HAL_NVIC_SetPriorityGrouping up) void HAL_NVIC_SetPriorityGrouping (uint32_t PriorityGro Function name Function description Sets the priority grouping field (preemption priority and subpriority) using the required unlock sequence. Parameters The priority grouping bits length. This PriorityGroup: parameter can be one of the following values: NVIC_PRIORITYGROUP_0: 0 bits for preemption priority 4 bits for subpriority NVIC_PRIORITYGROUP_1: 1 bits for preemption priority 3 bits for subpriority NVIC_PRIORITYGROUP_2: 2 bits for preemption priority 2 bits for subpriority for preemption NVIC_PRIORITYGROUP_3: 3 bits priority 1 bits for subpriority NVIC_PRIORITYGROUP_4: 4 bits for preemption priority 0 bits for subpriority Return values None: Notes When the NVIC_PriorityGroup_0 is selected, IRQ preemption will be is no more possible. The pending IRQ priority managed only by the subpriority. 2 DocID027328 Rev 1166 141 /

142 iver HAL UM1850 CORTEX Generic Dr HAL_NVIC_SetPriority void HAL_NVIC_SetPriority (IRQn_Type IRQn, uint32_t Function name PreemptPriority, uint32_t SubPriority) Function description Sets the priority of an interrupt. Parameters IRQn: External interrupt number. This parameter can be an enumerator of IRQn_Type enumeration (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32f10xx.h)) IRQn The preemption priority for the PreemptPriority: channel. This parameter can be a value between 0 and 15 A lower priority value indicates a higher priority the subpriority level for the IRQ channel. This SubPriority: parameter can be a value between 0 and 15 A lower priority value indicates a highe r priority. Return values None: HAL_NVIC_EnableIRQ void HAL_NVIC_EnableIRQ (IRQn_Type IRQn) Function name Enables a device specific interrupt in the NVIC interrupt controller. Function description Parameters IRQn: External interrupt number. This parameter can be an enumerator of IRQn_Type enumeration (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32f10xxx.h)) Return values None: Notes To configure interrupts priority correctly, the NVIC_PriorityGroupConfig() function should be called before. HAL_NVIC_DisableIRQ void HAL_NVIC_DisableIRQ (IRQn_Type IRQn) Function name ntroller. Disables a device specific interrupt in the NVIC interrupt co Function description Parameters External interrupt number. This parameter can be an IRQn: enumerator of IRQn_Type enumeration (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32f10xxx.h)) Return values None: HAL_NVIC_SystemReset void HAL_NVIC_SystemReset (void ) Function name Initiates a system reset request to reset the MCU. Function description Return values None: HAL_SYSTICK_Config uint32_t HAL_SYSTICK_Config (uint32_t TicksNumb) Function name 142 DocID027328 / Rev 2 1166

143 UM1850 CORTEX Generic Driver HAL Function description Initializes the System Timer and its interrupt, and starts the System Tick Timer. Parameters TicksNumb: Specifies the ticks Number of ticks between two interrupts. Return values 0 Function succeeded. - status: 1 Function failed. HAL_NVIC_GetPriorityGrouping uint32_t HAL_NVIC_GetPriorityGrouping (void ) Function name Function description Gets the priority grouping field from the NVIC Interrupt Controller. Return values - >AIRCR [10:8] PRIGROUP grouping field (SCB Priority: field) HAL_NVIC_GetPriority void HAL_NVIC_GetPriority (IRQn_Type IRQn, uint32_t Function name PriorityGroup, uint32_t * pPreemptPriority, uint32_t * pSubPriority) Gets the priority of an interrupt. Function description Parameters External interrupt number. This parameter can be an IRQn: enumerator of IRQn_Type enumeration (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32f10xxx.h)) the priority grouping bits length PriorityGroup: . This parameter can be one of the following values: NVIC_PRIORITYGROUP_0: 0 bits for preemption priority 4 bits for subpriority NVIC_PRIORITYGROUP_1: 1 bits for preemption priority 3 bits for subpriority NVIC_PRIORITYGROUP_2: 2 bits for preemption priori ty 2 bits for subpriority NVIC_PRIORITYGROUP_3: 3 bits for preemption priority 1 bits for subpriority NVIC_PRIORITYGROUP_4: 4 bits for preemption priority 0 bits for subpriority Pointer on the Preemptive priority value pPreemptPriority: (starting from 0). Pointer on the Subpriority value (starting from pSubPriority: 0). Return values None: HAL_NVIC_GetPendingIRQ uint32_t HAL_NVIC_GetPendingIRQ (IRQn_Type IRQn) Function name Gets Pending Interrupt (reads the pending register in the NVIC Function description and returns the pending bit for the specified interrupt). Parameters IRQn: External interrupt number. This parameter can be an enumerator of IRQn_Type enumeration (For the complete 2 DocID027328 Rev 1166 143 /

144 HAL UM1850 CORTEX Generic Driver STM32 Dev ices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32f10xxx.h)) Return values status: - 0 Interrupt status is not pending. 1 Interrupt status is pending. HAL_NVIC_SetPendingIRQ ype IRQn) void HAL_NVIC_SetPendingIRQ (IRQn_T Function name Sets Pending bit of an external interrupt. Function description Parameters IRQn: External interrupt number This parameter can be an enumerator of IRQn_Type enumeration (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32f10xxx.h)) Return values None: HAL_NVIC_ClearPendingIRQ void HAL_NVIC_ClearPendingIRQ (IRQn_Type IRQn) Fu nction name Function description Clears the pending bit of an external interrupt. Parameters External interrupt number. This parameter can be an IRQn: enumerator of IRQn_Type enumeration (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32f10xxx.h)) Return values None: HAL_NVIC_GetActive uint32_t HAL_NVIC_GetActive (IRQn_Type IRQn) Function name Function description Gets active interrupt ( reads the active register in NVIC and returns the active bit). Parameters IRQn: External interrupt number This parameter can be an enumerator of IRQn_Type enumeration (For the complete r to the STM32 Devices IRQ Channels list, please refe appropriate CMSIS device file (stm32f10xxx.h)) Return values 0 Interrupt status is not pending. status: - 1 Interrupt status is pending. HAL_SYSTICK_CLKSourceConfig void HAL_SYSTICK_CLKSourceConfig (uint32_t CLKSource) Function name Configures the SysTick clock source. Function description Parameters specifies the SysTick clock source. This CLKSource: parameter can be one of the following values: SYSTICK_CLKSOURCE_HCLK_DIV8: AHB clock divided by 8 selected as SysTick clock source. SYSTICK_ CLKSOURCE_HCLK: AHB clock selected as SysTick clock source. DocID027328 / 1166 144 Rev 2

145 UM1850 CORTEX Generic Driver HAL Return values None: HAL_SYSTICK_IRQHandler void HAL_SYSTICK_IRQHandler (void ) Function name Function description This function handles SYSTICK interrupt request. Return values None: HAL_SYSTICK_Callback void HAL_SYSTICK_Callback (void ) Function name SYSTICK callback. Function description Return values None: HAL_MPU_Enable void HAL_MPU_Enable (uint32_t MPU_Control) Function name Function description Enable the MPU. Parameters Specifies the control mode of the MPU during MPU_Control: hard fault, NMI, FAULTMASK and privileged access to the default memory This parameter can be one of the following values: MPU_HFNMI_PRIVDEF_NONE MPU_HARDFAULT_NMI MPU_PRIVILEGED_DEFAULT PRIVDEF MPU_HFNMI_ Return values None: HAL_MPU_Disable void HAL_MPU_Disable (void ) Function name Function description Disables the MPU. Return values None: HAL_MPU_ConfigRegion void HAL_MPU_ConfigRegion (MPU_Region_InitTypeDef * Function name MPU_Init) Initializes and configures the Region and the memory to be Function description protected. Parameters Pointer to a MPU_Region_InitTypeDef structure MPU_Init: that contains the initialization and configuration information. Return values None: 2 DocID027328 Rev 1166 145 /

146 HAL UM1850 CORTEX Generic Driver CORTEX F 11.3 irmware driver defines 11.3.1 CORTEX CORTEX MPU Instruction Access Bufferable MPU_ACCESS_BUFFERABLE MPU_ACCESS_NOT_BUFFERABLE CORTEX MPU Instruction Access Cacheable MPU_ACCESS_CACHEABLE MPU_ACCESS_NOT_CACHEABLE CORTEX MPU Instruction Access Shareable MPU_ACCESS_SHAREABLE MPU_ACCESS_NOT_SHAREABLE MPU HFNMI and PRIVILEGED Access control MPU_HFNMI_PRIVDEF_NONE MPU_HARDFAULT_NMI MPU_PRIVILEGED_DEFAULT MPU_HFNMI_PRIVDEF CORTEX MPU Instruction Access MPU_INSTRUCTION_ACCESS_ENABLE MPU_INSTRUCTION_ACCESS_DISABLE CORTEX MPU Region Enable MPU_REGION_ENABLE MPU_REGION_DISABLE CORTEX MPU Region Number MPU_REGION_NUMBER0 MPU_REGION_NUMBER1 MPU_REGION_NUMBER2 MPU_REGION_NUMBER3 MPU_REGION_NUMBER4 MPU_REGION_NUMBER5 MPU_REGION_NUMBER6 MPU_REGION_NUMBER7 CORTEX MPU Region Permission Attributes MPU_REGION_NO_ACCESS MPU_REGION_PRIV_RW MPU_REGION_PRIV_RW_URO MPU_REGION_FULL_ACCESS DocID027328 / 1166 146 Rev 2

147 UM1850 CORTEX Generic Driver HAL MPU_REGION_PRIV_RO MPU_REGION_PRIV_RO_URO CORTEX MPU Region Size MPU_REGION_SIZE_32B MPU_REGION_SIZE_64B MPU_REGION_SIZE_128B MPU_REGION_SIZE_256B MPU_REGION_SIZE_512B MPU_REGION_SIZE_1KB MPU_REGION_SIZE_2KB MPU_REGION_SIZE_4KB MPU_REGION_SIZE_8KB MPU_REGION_SIZE_16KB MPU_REGION_SIZE_32KB MPU_REGION_SIZE_64KB MPU_REGION_SIZE_128KB MPU_REGION_SIZE_256KB MPU_REGION_SIZE_512KB MPU_REGION_SIZE_1MB MPU_REGION_SIZE_2MB MPU_REGION_SIZE_4MB MPU_REGION_SIZE_8MB MPU_REGION_SIZE_16MB MPU_REGION_SIZE_32MB MPU_REGION_SIZE_64MB MPU_REGION_SIZE_128MB MPU_REGION_SIZE_256MB MPU_REGION_SIZE_512MB MPU_REGION_SIZE_1GB MPU_REGION_SIZE_2GB MPU_REGION_SIZE_4GB MPU TEX Levels MPU_TEX_LEVEL0 MPU_TEX_LEVEL1 MPU_TEX_LEVEL2 CORTEX Preemption Priority Group 2 DocID027328 Rev 1166 147 /

148 HAL UM1850 CORTEX Generic Driver emption priority 4 bits for subpriority - 0 bits for pre NVIC_PRIORITYGROUP_0 emption priority 3 bits for subpriority - 1 bits for pre NVIC_PRIORITYGROUP_1 emption priority 2 bits for subpriority NVIC_PRIORITYGROUP_2 2 bits for pre - NVIC_PRIORITYGROUP_3 3 bits for pre emption priority 1 bits for subpriority - - emption priority 0 bits for subpriority NVIC_PRIORITYGROUP_4 4 bits for pre CORTEX _SysTick clock source SYSTICK_CLKSOURCE_HCLK_DIV8 SYSTICK_CLKSOURCE_HCLK DocID027328 / 1166 148 Rev 2

149 HAL UM1850 CRC Generic Driver 12 HAL CRC Generic Driver 12.1 CRC Firmware driver registers structures 12.1.1 CRC_HandleTypeDef Data Fields CRC_TypeDef * Instance HAL_LockTypeDef Lock __IO HAL_CRC_StateTypeDef State Field Documentation CRC_TypeDef* CRC_HandleTypeDef::Instance Register base address HAL_LockTypeDef CRC_HandleTypeDef::Lock CR C locking object __IO HAL_CRC_StateTypeDef CRC_HandleTypeDef::State CRC communication state CRC Firmware driver API description 12.2 How to use this driver 12.2.1 The CRC HAL driver can be used as follows: Enable CRC AHB clock using __HAL_RCC_CRC_CLK_ENABLE(); 1. 2. Use HAL_CRC_Accumulate() function to compute the CRC value of a 32 - bit data buffer using combination of the previous CRC value and the new one. on to compute the CRC Value of a new 32 - bit data 3. Use HAL_CRC_Calculate() functi buffer. This function resets the CRC computation unit before starting the computation to avoid getting wrong CRC values. 12.2.2 - initialization functions Initialization and de This section provides functions allowing to: Initialize the CRC according to the specified parameters in the CRC_InitTypeDef and create the associated handle DeInitialize the CRC peripheral Initialize the CRC MSP DeInitialize CRC MSP This section contains the following APIs: HAL_CRC_Init() HAL_CRC_DeInit() HAL_CRC_MspInit() HAL_CRC_MspDeInit() Peripheral Control functions 12.2.3 This section provides functions allowing to: 2 DocID027328 Rev 1166 149 /

150 HAL CRC Generic Driver UM1850 - bit CRC value of 32 Compute the 32 - bit data buffer, using combination of the previous CRC value and the new o ne. - bit CRC value of 32 - bit data buffer, independently of the previous Compute the 32 CRC value. This section contains the following APIs: HAL_CRC_Accumulate() HAL_CRC_Calculate() l State functions 12.2.4 Periphera time the status of the peripheral. - This subsection permits to get in run This section contains the following APIs: HAL_CRC_GetState() Detailed descriptio 12.2.5 n of functions HAL_CRC_Init HAL_StatusTypeDef HAL_CRC_Init (CRC_HandleTypeDef * Function name hcrc) Initializes the CRC according to the specified parameters in the Function description CRC_InitTypeDef and creates the associated handle. Parameters hcrc: pointer to a CRC_HandleTypeDef structure that contains the configuration information for CRC Return values HAL: status HAL_CRC_DeInit HAL_StatusTypeDef HAL_CRC_DeInit (CRC_HandleTypeDef * Function name hcrc) Function description DeInitializes the CRC peripheral. Parameters hcrc: pointer to a CRC_HandleTypeDef structure that contains the configuration information for CRC Return values status HAL: HAL_CRC_MspInit void HAL_CRC_MspInit (CRC_HandleTypeDef * hcrc) Function name Function description Initializes the CRC MSP. Parameters hcrc: pointer to a CRC_HandleTypeDef structure that contains the configuration information for CRC Return values None: HAL_CRC_MspDeInit void HAL_CRC_MspDeInit (CRC_HandleTypeDef * hcrc) Function name DeInitializes the CRC MSP. Function description DocID027328 / 1166 150 Rev 2

151 UM1850 HAL CRC Generic Driver Parameters hcrc: pointer to a CRC_HandleTypeDef structure that contains the configuration information for CRC Return values None: HAL_CRC_Accumulate uint32_t HAL_CRC_Accumulate (CRC_HandleTypeDef * hcrc, Function name 2_t pBuffer, uint32_t BufferLength) uint3 Computes the 32 bit data buffer using combination Function description - - bit CRC of 32 of the previous CRC value and the new one. Parameters hcrc: pointer to a CRC_HandleTypeDef structure that contains the configuratio n information for CRC pointer to the buffer containing the data to be pBuffer: computed length of the buffer to be computed (defined BufferLength: in word, 4 bytes) Return values 32 CRC bit: - HAL_CRC_Calculate (CRC_HandleTypeDef * hcrc, uint32_t HAL_CRC_Calculate Function name uint32_t pBuffer, uint32_t BufferLength) Computes the 32 - bit CRC of 32 - bit data buffer independently of Function description the previous CRC value. Parameters hcrc: pointer to a CRC_HandleTypeDef structure that contains the configuration information for CRC pBuffer: Pointer to the buffer containing the data to be computed Length of the buffer to be computed (defined BufferLength: in word, 4 bytes) Return values 32 CRC bit: - HAL_CRC_GetState HAL_CRC_StateTypeDef HAL_CRC_GetState Function name (CRC_HandleTypeDef * hcrc) Function description Returns the CRC state. Parameters pointer to a CRC_HandleTypeDef structure that hcrc: contains the configuration information for CRC Return values HAL: state CRC Firmware driver defines 12.3 CRC 12.3.1 CRC Exported Macros Description: __HA L_CRC_RESET_HANDLE_STATE 151 Rev 2 1166 / DocID027328

152 HAL UM1850 CRC Generic Driver Reset CRC handle state. Parameters: __HANDLE__: CRC handle Return value: None Description: __HAL_CRC_DR_RESET Resets CRC Data Register. Parameters: __HANDLE__: CRC handle Return value: None Description: __HAL_CRC_SET_IDR bit data in the Independent Stores a 8 - Data(ID) register. Parameters: __HANDLE__: CRC handle bit value to be stored in the __VALUE__: 8 - ID register Return value: None Description: __HAL_CRC_GET_IDR - bit data stored in the Returns the 8 Independent Data(ID) register. Parameters: __HANDLE__: CRC handle Return value: 8 bit: value of the ID register - DocID027328 / 1166 152 Rev 2

153 HAL UM1850 DAC Generic Driver 13 HAL DAC Generic Driver DAC Firmware driver registers structures 13.1 13.1.1 AC_HandleTypeDef D Data Fields DAC_TypeDef * Instance __IO HAL_DAC_StateTypeDef State HAL_LockTypeDef Lock DMA_HandleTypeDef * DMA_Handle1 DMA_HandleTypeDef * DMA_Handle2 __IO uint32_t ErrorCode Field Documentation DAC_TypeDef* DAC_HandleTypeDef::Instance Register base address __IO HAL_DAC_StateTypeDef DAC_HandleTypeDef::State DAC communication state HAL_LockTypeDef DAC_HandleTypeDef::Lock DAC locking object DMA_HandleTypeDef* DAC_HandleTypeDef::DMA_Handle1 Pointe r DMA handler for channel 1 DMA_HandleTypeDef* DAC_HandleTypeDef::DMA_Handle2 Pointer DMA handler for channel 2 __IO uint32_t DAC_HandleTypeDef::ErrorCode DAC Error code 13.1.2 DAC_ChannelConfTypeDef Data Fields int32_t DAC_Trigger u uint32_t DAC_OutputBuffer Field Documentation uint32_t DAC_ChannelConfTypeDef::DAC_Trigger Specifies the external trigger for the selected DAC channel. This parameter can be a - Note: For STM32F100x high ction DACEx_trigger_sele density value line value of devices, additional trigger sources are available. uint32_t DAC_ChannelConfTypeDef::DAC_OutputBuffer Specifies whether the DAC channel output buffer is enabled or disabled. This DAC_output_buffer parameter can be a value o f 13.2 DAC Firmware driver API description DAC Peripheral features 13.2.1 2 DocID027328 Rev 1166 153 /

154 HAL UM1850 DAC Generic Driver DAC Channels bit Digital Analog Converters that can be used independently - The device integrates two 12 or simultaneously (dual mode): DAC channel1 with DAC_OUT1 (PA4) as output 1. 2. DAC channel2 with DAC_OUT2 (PA5) as output DAC Triggers triggered using DAC_TRIGGER_NONE and - Digital to Analog conversion can be non DAC_OUT1/DAC_OUT2 is available once writing to DHRx register. Digital to Analog conversion can be triggered by: External event: EXTI Line 9 (any GPIOx_PIN_9) using DAC_TRIGGER 1. _EXT_IT9. The used pin (GPIOx_PIN_9) must be configured in input mode. 2. Timers TRGO: TIM2, TIM4, TIM6, TIM7 For STM32F10x connectivity line devices and - density devices: - density and XL STM32F100x devices: TIM3 For STM32F10x high sity value line devices: TIM15 as replacement of den - TIM8 For STM32F100x high TIM5. (DAC_TRIGGER_T2_TRGO, DAC_TRIGGER_T4_TRGO...) Software using DAC_TRIGGER_SOFTWARE 3. DAC Buffer mode feature Each DAC channel integrates an output buffer that can be used to reduce the output impedance , and to drive external loads directly without having to add an external operational amplifier. To enable, the output buffer use sConfig.DAC_OutputBuffer = DAC_OUTPUTBUFFER_ENABLE; Refer to the device datasheet for more details about output impedance value with and without output buffer. DAC connect feature Each DAC channel can be connected internally. To connect, use sConfig.DAC_ConnectOnChipPeripheral = DAC_CHIPCONNECT_ENABLE; GPIO configurations guidelines When a DAC channel is used (ex channe l1 on PA4) and the other is not (ex channel1 on PA5 is configured in Analog and disabled). Channel1 may disturb channel2 as coupling effect. Note that there is no coupling on channel2 as soon as channel2 is turned on. Coupling on adjacent channel could be avoided as follows: when unused PA5 is configured as INPUT PULL - UP or DOWN. PA5 is configured in ANALOG just before it is turned on. DAC wave generation feature Both DAC channels can be used to generate Noise wave using HAL_DACEx_NoiseWaveGenerate() 1. Triangle wave using HAL_DACEx_TriangleWaveGenerate() 2. DAC data format The DAC data format can be: 8 1. bit right alignment using DAC_ALIGN_8B_R - DocID027328 / 1166 154 Rev 2

155 UM1850 DAC Generic Driver HAL - 12 bit left alignment using DAC_ALIGN_12B_L 2. 3. 12 bit right alignment using DAC_ALIGN_12B_R - ge correspondance DAC data value to volta The analog output voltage on each DAC channel pin is determined by the following equation: DAC_OUTx = VREF+ * DOR / 4095 with DOR is the Data Output Register VEF+ is the input voltage reference (refer to the device datasheet) To set DAC_OUT1 to 0.7V, use e.g. Assuming that VREF+ = 3.3V, DAC_OUT1 = (3.3 * 868) / 4095 = 0.7V DMA requests A DMA1 request can be generated when an external trigger (but not a software trigger) ) occurs if DMA1 requests are enabled using HAL_DAC_Start_DMA( DMA requests are mapped as following: 1. density with - density, high - density, medium - DAC channel1 : For STM32F100x low DAC DMA remap: mapped on DMA1 channel3 which must be already configured For - density without DAC DMA remap and other STM3 2F1 devices: STM32F100x high mapped on DMA2 channel3 which must be already configured 2. - DAC channel2 : For STM32F100x low density, medium - density, high - density with DAC DMA remap: mapped on DMA1 channel4 which must be already configured For AC DMA remap and other STM32F1 devices: density without D STM32F100x high - mapped on DMA2 channel4 which must be already configured 13.2.2 How to use this driver DAC APB clock must be enabled to get write access to DAC registers using HAL_DAC_Init() Configure DAC_OUTx (DAC_OUT1: PA4, DAC_OUT2: PA5) in analog mode. Configure the DAC channel using HAL_DAC_ConfigChannel() function. Enable the DAC channel using HAL_DAC_Start() or HAL_DAC_Start_DMA functions Polling mode IO operation Start the DAC peripheral using HAL_DAC_Start() To read the DAC last data output value, use the HAL_DAC_GetValue() function. Stop the DAC peripheral using HAL_DAC_Stop() DMA mode IO operation ge the user specify Start the DAC peripheral using HAL_DAC_Start_DMA(), at this sta the length of data to be transferred at each end of conversion At the middle of data transfer HAL_DACEx_ConvHalfCpltCallbackCh1()or HAL_DACEx_ConvHalfCpltCallbackCh2() function is executed and user can add his own code by customization of function pointer HAL_DAC_ConvHalfCpltCallbackCh1 or HAL_DAC_ConvHalfCpltCallbackCh2 At The end of data transfer HAL_DAC_ConvCpltCallbackCh1()or HAL_DAC_ConvCpltCallbackCh2() function is executed and user can add his own code by customization of function pointer HAL_DAC_ConvCpltCallbackCh1 or HAL_DAC_ConvCpltCallbackCh2 2 DocID027328 Rev 1166 155 /

156 HAL UM1850 DAC Generic Driver In case of transfer Error, HAL_DAC_ErrorCallbackCh1() or HAL_DACEx_ErrorCallbackCh2() function is executed and user can add his own code allbackCh1 or by customization of function pointer HAL_DAC_ErrorC HAL_DACEx_ErrorCallbackCh2 For STM32F100x devices with specific feature: DMA underrun. In case of DMA underrun, DAC interruption triggers and execute internal function HAL_DAC_IRQHandler. HAL_DAC_DMAUnderrunCallbackCh1()or unCallbackCh2() function is executed and user can add his HAL_DACEx_DMAUnderr own code by customization of function pointer HAL_DAC_DMAUnderrunCallbackCh1 or HAL_DACEx_DMAUnderrunCallbackCh2 add his own code by customization of function pointer HAL_DAC_ErrorCallbackCh1 he DAC peripheral using HAL_DAC_Stop_DMA() Stop t DAC HAL driver macros list Below the list of most used macros in DAC HAL driver. __HAL_DAC_ENABLE : Enable the DAC peripheral (For STM32F100x devices with specific feature: DMA underrun) __HAL_DAC_DISABLE : Dis able the DAC peripheral (For STM32F100x devices with specific feature: DMA underrun) __HAL_DAC_CLEAR_FLAG: Clear the DAC's pending flags (For STM32F100x devices with specific feature: DMA underrun) r STM32F100x __HAL_DAC_GET_FLAG: Get the selected DAC's flag status (Fo devices with specific feature: DMA underrun) You can refer to the DAC HAL driver header file for more useful macros - 13.2.3 Initialization and de initialization functions This section provides functions allowing to: Initialize and configure the DAC. initialize the DAC. - De This section contains the following APIs: HAL_DAC_Init() HAL_DAC_DeInit() HAL_DAC_MspInit() HAL_DAC_MspDeInit() IO operation functions 13.2.4 This section provides functions allowing to: Start conversion. Stop conversion. conversion and enable DMA transfer. Start Stop conversion and disable DMA transfer. Get result of conversion. This section contains the following APIs: HAL_DAC_Start() DocID027328 / 1166 156 Rev 2

157 UM1850 HAL DAC Generic Driver HAL_DAC_Stop() HAL_DAC_Start_DMA() HAL_DAC_Stop_DMA() HAL_DAC_GetValue() HAL_DAC_ConvCpltCallbackCh1() HAL_DAC_ConvHal fCpltCallbackCh1() HAL_DAC_ErrorCallbackCh1() HAL_DAC_SetValue() Peripheral Control functions 13.2.5 This section provides functions allowing to: Configure channels. Set the specified data holding register value for DAC channel. This section contains the following APIs: HAL_DAC_ConfigChannel() HAL_DAC_SetValue() 13.2.6 Peripheral State and Errors functions This subsection provides functions allowing to Check the DAC state. Check the DAC Errors. This section contains the following APIs: HAL_DAC_GetState() HAL_DAC_GetError() HAL_DAC_ConvCpltCallbackCh1() HAL_DAC_ConvHalfCpltCallbackCh1() HAL_DAC_ErrorCallbackCh1() Detailed description of functions 13.2.7 HAL_DAC_Init HAL_StatusTypeDef HAL_DAC_Init (DAC_HandleTypeDef * Function name hdac) Function description Initializes the DAC peripheral according to the specified parameters in the DAC_InitStruct. Parameters hdac: pointer to a DAC_HandleTypeDef structure that contains the configuration information for the specified DAC. Return values status HAL: _DeInit HAL_DAC HAL_StatusTypeDef HAL_DAC_DeInit (DAC_HandleTypeDef * Function name hdac) Function description Deinitializes the DAC peripheral registers to their default reset values. Parameters hdac: pointer to a DAC_HandleTypeDef structure that 2 DocID027328 Rev 1166 157 /

158 HAL UM1850 DAC Generic Driver configuration information for the specified DAC. contains the Return values status HAL: HAL_DAC_MspInit void HAL_DAC_MspInit (DAC_HandleTypeDef * hdac) Function name Function description Initializes the DAC MSP. Parameters pointer to a DAC_HandleTypeDef structure that hdac: contains the configuration information for the specified DAC. Return values None: HAL_DAC_MspDeInit void HAL_DAC_MspDeInit (DAC_HandleTypeDef * hdac) Function name DeInitializes the DAC MSP. Function description Parameters pointer to a DAC_HandleTypeDef structure that hdac: contains the configuration information for the specified DAC. Return values None: HAL_DAC_Start * HAL_StatusTypeDef HAL_DAC_Start (DAC_HandleTypeDef Function name hdac, uint32_t Channel) Enables DAC and starts conversion of channel. Function description Parameters hdac: pointer to a DAC_HandleTypeDef structure that contains the configuration information for the specified DAC. The selected DAC channe l. This parameter can be Channel: one of the following values: DAC_CHANNEL_1: DAC Channel1 selected DAC_CHANNEL_2: DAC Channel2 selected Return values HAL: status HAL_DAC_Stop HAL_StatusTypeDef HAL_DAC_Stop (DAC_HandleTypeDef * Function name hdac, uint32_t Channel) Disables DAC and stop conversion of channel. Function description Parameters hdac: pointer to a DAC_HandleTypeDef structure that contains the configuration information for the specified DAC. The selected DAC channel. This parameter c an be Channel: one of the following values: DAC_CHANNEL_1: DAC Channel1 selected DAC_CHANNEL_2: DAC Channel2 selected Return values HAL: status DocID027328 / 1166 158 Rev 2

159 UM1850 DAC Generic Driver HAL HAL_DAC_Start_DMA HAL_StatusTypeDef HAL_DAC_Start_DMA Function name uint32_t * (DAC_HandleTypeDef * hdac, uint32_t Channel, pData, uint32_t Length, uint32_t Alignment) Function description Enables DAC and starts conversion of channel. Parameters hdac: pointer to a DAC_HandleTypeDef structure that contains the configuration information for the specified DAC. el: Chann The selected DAC channel. This parameter can be one of the following values: DAC_CHANNEL_1: DAC Channel1 selected DAC_CHANNEL_2: DAC Channel2 selected pData: The Source memory Buffer address. The length of data to be transferred from memory to Length: DAC peripheral Alignment: Specifies the data alignment for DAC channel. This parameter can be one of the following values: DAC_ALIGN_8B_R: 8bit right data alignment selected DAC_ALIGN_12B_L: 12bit left data alignment selected DAC_ALIGN_12B_R: 12bit right data alignment selected Return values status HAL: HAL_DAC_Stop_DMA HAL_StatusTypeDef HAL_DAC_Stop_DMA Function name (DAC_HandleTypeDef * hdac, uint32_t Channel) Disables DAC and stop conversion of channel. Function description Parameters pointer to a DAC_HandleTypeDef structure that hdac: contains the configuration information for the specified DAC. Channel: The selected DAC channel. This parameter can be one of the following values: DAC_CHANNEL_1: DAC Channel1 selected DAC_CHANNEL_2: DAC Channel2 selected Return values HAL: status HAL_DAC_SetValue HAL_StatusTypeDef HAL_DAC_SetValue Function name (DAC_HandleTypeDef * hdac, uint32_t Channel, uint32_t Alignment, uint32_t Data) Set the specified data holding register value for DAC channel. on description Functi Parameters hdac: pointer to a DAC_HandleTypeDef structure that contains the configuration information for the specified DAC. Channel: can be The selected DAC channel. This parameter one of the following values: DAC_CHANNEL_1: DAC Channel1 selected DAC_CHANNEL_2: DAC Channel2 selected Specifies the data alignment. This parameter Alignment: can be one of the following values: DAC_ALIGN_8B_R: 8bit right data alignment selected 2 DocID027328 Rev 1166 159 /

160 HAL DAC Generic Driver UM1850 DAC_ALIGN_12B_L: 12bit left data alignment selected DAC_ALIGN_12B_R: 12bit right data alignment selected Data: Data to be loaded in the selected data holding register. Return values HAL: status HAL_DAC_GetValue uint32_t HAL_DAC_GetValue (DAC_HandleTypeDef * hdac, Function name uint32_t Channel) Returns the last data output value of the selected DAC channel. Function description Parameters hdac: pointer to a DAC_HandleTypeDef structure that contains the configuration information for the specified DA C. Channel: The selected DAC channel. This parameter can be one of the following values: DAC_CHANNEL_1: DAC Channel1 selected DAC_CHANNEL_2: DAC Channel2 selected Return values selected DAC channel data output value. The: HAL_DAC_ConfigChannel HAL_StatusTypeDef HAL_DAC_ConfigChannel Function name (DAC_HandleTypeDef * hdac, DAC_ChannelConfTypeDef * sConfig, uint32_t Channel) Function description Configures the selected DAC channel. Parameters hdac: pointer to a DAC_HandleTypeDef structure tha t contains the configuration information for the specified DAC. sConfig: DAC configuration structure. Channel: The selected DAC channel. This parameter can be one of the following values: DAC_CHANNEL_1: DAC Channel1 selected selected DAC_CHANNEL_2: DAC Channel2 Return values status HAL: HAL_DAC_GetState HAL_DAC_StateTypeDef HAL_DAC_GetState Function name (DAC_HandleTypeDef * hdac) return the DAC state Function description Parameters pointer to a DAC_HandleTypeDef structure that hdac: contains the configuration information for the specified DAC. Return values state HAL: HAL_DAC_GetError uint32_t HAL_DAC_GetError (DAC_HandleTypeDef * hdac) Function name Function description Return the DAC error code. Parameters pointer to a DAC_HandleTypeDef structure that hdac: DocID027328 / 1166 160 Rev 2

161 HAL UM1850 DAC Generic Driver contains the configuration information for the specified DAC. Return values Error Code DAC: HAL_DAC_ConvCpltCallbackCh1 void HAL_DAC_ConvCpltCallbackCh1 (DAC_HandleTypeDef * Function name hdac) Function description Conversion complete callback in non blocking mode for Channel1. Parameters hdac: pointer to a DAC_HandleTypeDef structure that contains the configuration information for the specified DAC. Return values None: HAL_DAC_ConvHalfCpltCallbackCh1 void HAL_DAC_ConvHalfCpltCallbackCh1 Function name (DAC_HandleTypeDef * hdac) Conversion half DMA transfer callback in non blocking mode for Function description Channel1. Parameters structure that pointer to a DAC_HandleTypeDef hdac: contains the configuration information for the specified DAC. Return values None: HAL_DAC_ErrorCallbackCh1 void HAL_DAC_ErrorCallbackCh1 (DAC_HandleTypeDef * Function name hdac) Function description Error DAC callback for Channel1. Parameters pointer to a DAC_HandleTypeDef structure that hdac: contains the configuration information for the specified DAC. Return values None: DAC_DMAConvCpltCh1 void DAC_DMAConvCpltCh1 (DMA_HandleTypeDef * hdma) Function name Function description D MA conversion complete callback. Parameters hdma: pointer to a DMA_HandleTypeDef structure that contains the configuration information for the specified DMA module. Return values None: DAC_DMAHalfConvCpltCh1 void DAC_DMAHalfConvCpltCh1 (DMA_HandleTypeDef * Function name hdma) DMA half transfer complete callback. Function description Parameters pointer to a DMA_HandleTypeDef structure that hdma: 2 DocID027328 Rev 1166 161 /

162 HAL UM1850 DAC Generic Driver contains the configuration information for the specified DMA module. Return values None: DAC_DMAErrorCh1 void DAC_DMAErrorCh1 (DMA_HandleTypeDef * hdma) Function name Function description DMA error callback. Parameters pointer to a DMA_HandleTypeDef structure that hdma: contains the configuration information for the specified DMA module. Return values None: DAC Firmware driver defines 13.3 DAC 13.3.1 DAC Channel selection DAC_CHANNEL_1 DAC_CHANNEL_2 DAC data alignement DAC_ALIGN_12B_R DAC_ALIGN_12B_L DAC_ALIGN_8B_R DAC Error Code No error HAL_DAC_ERROR_NONE DAC channel1 DMA underrun error HAL_DAC_ERROR_DMAUNDERRUNCH1 DAC channel2 DMA underrun error HAL_DAC_ERROR_DMAUNDERRUNCH2 HAL_DAC_ERROR_DMA DMA error DAC Exported Macros Description: __HAL_DAC_RESET_HANDLE_STATE Reset DAC handle state. Parameters: __HANDLE__: specifies the DAC handle. Return value: None Description: __HAL_DAC_ENABLE Enable the DAC channel. Parameters: __HANDLE__: specifies the DAC handle. __DAC_Channel__: specifies the DAC DocID027328 / 1166 162 Rev 2

163 UM1850 DA C Generic Driver HAL channel Return value: None Description: __HAL_DAC_DISABLE Disable the DAC channel. Parameters: __HANDLE__: specifies the DAC handle __DAC_Channel__: specifies the DAC channel. Return value: None DAC output buffer DAC_OUTPUTBUFFER_ENABLE DAC_OUTPUTBUFFER_DISABLE 2 DocID027328 Rev 1166 163 /

164 DAC Extension Driver HAL UM1850 14 HAL DAC Extension Driver 14.1 DACEx Firmware driver API description 14.1.1 How to use this driver de is enabled (i.e DAC Channel1 and Channel2 are used When Dual mo simultaneously) : Use HAL_DACEx_DualGetValue() to get digital data to be converted and use HAL_DACEx_DualSetValue() to set digital value to converted simultaneously in Channel 1 and Channel 2. Use HAL_ DACEx_TriangleWaveGenerate() to generate Triangle signal. Use HAL_DACEx_NoiseWaveGenerate() to generate Noise signal. 14.1.2 Extended features functions This section provides functions allowing to: Start con version. Stop conversion. Start conversion and enable DMA transfer. Stop conversion and disable DMA transfer. Get result of conversion. Get result of dual mode conversion. This section contains the following APIs: HAL_DACEx_DualGetValue() HAL_DACEx_TriangleWaveGenerate() HAL_DACEx_NoiseWaveGenerate() HAL_DACEx_DualSetValue() HAL_DACEx_ConvCpltCallbackCh2() HAL_DACEx_ConvHalfCpltCallbackCh2() HAL_DACEx_ErrorCallbackCh2() 14.1.3 Detailed description of functions HAL_DACEx_DualGe tValue uint32_t HAL_DACEx_DualGetValue (DAC_HandleTypeDef * Function name hdac) Returns the last data output value of the selected DAC channel. Function description Parameters hdac: pointer to a DAC_HandleTypeDef structure that contains the configuration information for the specified DAC. Return values selected DAC channel data output value. The: HAL_DACEx_TriangleWaveGenerate Generate HAL_StatusTypeDef HAL_DACEx_TriangleWave Function name (DAC_HandleTypeDef * hdac, uint32_t Channel, uint32_t Amplitude) Function description Enables or disables the selected DAC channel wave generation. DocID027328 / 1166 164 Rev 2

165 UM1850 HAL DAC Extension Driver Parameters hdac: pointer to a DAC_HandleTypeDef structure that mation for the specified DAC. contains the configuration infor The selected DAC channel. This parameter can be Channel: one of the following values: DAC_CHANNEL_1 / DAC_CHANNEL_2 Select max triangle amplitude. This parameter Amplitude: can be one of the following values: PLITUDE_1: Select max triangle DAC_TRIANGLEAM amplitude of 1 DAC_TRIANGLEAMPLITUDE_3: Select max triangle amplitude of 3 DAC_TRIANGLEAMPLITUDE_7: Select max triangle amplitude of 7 DAC_TRIANGLEAMPLITUDE_15: Select max triangle amplitude of 15 Select max triangle DAC_TRIANGLEAMPLITUDE_31: amplitude of 31 DAC_TRIANGLEAMPLITUDE_63: Select max triangle amplitude of 63 DAC_TRIANGLEAMPLITUDE_127: Select max triangle amplitude of 127 DAC_TRIANGLEAMPLITUDE_255: Select max triangle amplitude of 255 ect max triangle DAC_TRIANGLEAMPLITUDE_511: Sel amplitude of 511 DAC_TRIANGLEAMPLITUDE_1023: Select max triangle amplitude of 1023 DAC_TRIANGLEAMPLITUDE_2047: Select max triangle amplitude of 2047 DAC_TRIANGLEAMPLITUDE_4095: Select max triangle amplitude of 4095 Return values sta HAL: tus HAL_DACEx_NoiseWaveGenerate HAL_StatusTypeDef HAL_DACEx_NoiseWaveGenerate Function name (DAC_HandleTypeDef * hdac, uint32_t Channel, uint32_t Amplitude) Function description Enables or disables the selected DAC channel wave generation. Parameters pointer to a DAC_HandleTypeDef structure that hdac: contains the configuration information for the specified DAC. The selected DAC channel. This parameter can be Channel: one of the following values: DAC_CHANNEL_1 / DAC_CHANNEL_2 hannel LFSR for noise wave Unmask DAC c Amplitude: generation. This parameter can be one of the following values: DAC_LFSRUNMASK_BIT0: Unmask DAC channel LFSR bit0 for noise wave generation DAC_LFSRUNMASK_BITS1_0: Unmask DAC channel LFSR bit[1:0] for noise wave generation DAC_LF SRUNMASK_BITS2_0: Unmask DAC channel 2 DocID027328 Rev 1166 165 /

166 DAC Extension Driver HAL UM1850 LFSR bit[2:0] for noise wave generation DAC_LFSRUNMASK_BITS3_0: Unmask DAC channel LFSR bit[3:0] for noise wave generation DAC_LFSRUNMASK_BITS4_0: Unmask DAC channel LFSR bit[4:0] for noise wave generation DAC_LFSRUNMAS K_BITS5_0: Unmask DAC channel LFSR bit[5:0] for noise wave generation DAC_LFSRUNMASK_BITS6_0: Unmask DAC channel LFSR bit[6:0] for noise wave generation DAC_LFSRUNMASK_BITS7_0: Unmask DAC channel LFSR bit[7:0] for noise wave generation _0: Unmask DAC channel DAC_LFSRUNMASK_BITS8 LFSR bit[8:0] for noise wave generation DAC_LFSRUNMASK_BITS9_0: Unmask DAC channel LFSR bit[9:0] for noise wave generation DAC_LFSRUNMASK_BITS10_0: Unmask DAC channel LFSR bit[10:0] for noise wave generation Unmask DAC channel DAC_LFSRUNMASK_BITS11_0: LFSR bit[11:0] for noise wave generation Return values HAL: status HAL_DACEx_DualSetValue HAL_StatusTypeDef HAL_DACEx_DualSetValue Function name (DAC_HandleTypeDef * hdac, uint32_t Alignment, uint32_t Data1, uint32_t Data2) Set the specified data holding register value for dual DAC channel. description Function Parameters hdac: pointer to a DAC_HandleTypeDef structure that contains the configuration information for the specified DAC. Specifies the data alignment for dua l channel Alignment: DAC. This parameter can be one of the following values: DAC_ALIGN_8B_R: 8bit right data alignment selected DAC_ALIGN_12B_L: 12bit left data alignment selected DAC_ALIGN_12B_R: 12bit right data alignment selected e loaded in the selected Data1: Data for DAC Channel2 to b data holding register. Data2: Data for DAC Channel1 to be loaded in the selected data holding register. Return values status HAL: Notes In dual mode, a unique register access is required to write in same time. both DAC channels at the HAL_DACEx_ConvCpltCallbackCh2 void HAL_DACEx_ConvCpltCallbackCh2 Function name (DAC_HandleTypeDef * hdac) Conversion complete callback in non blocking mode for Channel2. Function description Parameters hdac: pointer to a DAC_HandleTypeDef structure that contains the configuration information for the specified DAC. DocID027328 / 1166 166 Rev 2

167 UM1850 HAL DAC Extension Driver Return values None: HAL_DACEx_ConvHalfCpltCallbackCh2 void HAL_DACEx_ConvHalfCpltCallbackCh2 Function name (DAC_HandleTypeDef * hdac) Conversion half DMA transfer callback in non blocking mode for description Function Channel2. Parameters pointer to a DAC_HandleTypeDef structure that hdac: contains the configuration information for the specified DAC. Return values None: ackCh2 HAL_DACEx_ErrorCallb void HAL_DACEx_ErrorCallbackCh2 (DAC_HandleTypeDef * Function name hdac) Error DAC callback for Channel2. Function description Parameters hdac: pointer to a DAC_HandleTypeDef structure that contains the configuration information for the specified DAC. Return values None: DAC_DMAConvCpltCh2 void DAC_DMAConvCpltCh2 (DMA_HandleTypeDef * hdma) Function name Function description plete callback. DMA conversion com Parameters hdma: pointer to a DMA_HandleTypeDef structure that contains the configuration information for the specified DMA module. Return values None: DAC_DMAHalfConvCpltCh2 void DAC_DMAHalfConvCpltCh2 (DMA_HandleTypeDef * Function name hdma) Function description DMA half transfer complete callback. Parameters pointer to a DMA_HandleTypeDef structure that hdma: contains the configuration information for the specified DMA module. Return values None: Ch2 DAC_DMAError void DAC_DMAErrorCh2 (DMA_HandleTypeDef * hdma) Function name DMA error callback. Function description Parameters pointer to a DMA_HandleTypeDef structure that hdma: contains the configuration information for the specified DMA 2 DocID027328 Rev 1166 167 /

168 HAL UM1850 DAC Extension Driver module. Return values None: 14.2 DACEx Firmware driver defines DACEx 14.2.1 DACEx lfsrunmask triangleamplitude DAC_LFSRUNMASK_BIT0 Unmask DAC channel LFSR bit0 for noise wave generation DAC_LFSRU NMASK_BITS1_0 Unmask DAC channel LFSR bit[1:0] for noise wave generation Unmask DAC channel LFSR bit[2:0] for noise wave DAC_LFSRUNMASK_BITS2_0 generation DAC_LFSRUNMASK_BITS3_0 Unmask DAC channel LFSR bit[3:0] for noise wave generation Unmask DAC channel LFSR bit[4:0] for noise wave DAC_LFSRUNMASK_BITS4_0 generation Unmask DAC channel LFSR bit[5:0] for noise wave DAC_LFSRUNMASK_BITS5_0 generation DAC_LFSRUNMASK_BITS6_0 Unmask DAC channel LFSR bit[6:0] for noise wave generation DAC_ LFSRUNMASK_BITS7_0 Unmask DAC channel LFSR bit[7:0] for noise wave generation DAC_LFSRUNMASK_BITS8_0 Unmask DAC channel LFSR bit[8:0] for noise wave generation DAC_LFSRUNMASK_BITS9_0 Unmask DAC channel LFSR bit[9:0] for noise wave generation DAC_LFSRUNMASK_BITS10_0 Unmask DAC channel LFSR bit[10:0] for noise wave generation Unmask DAC channel LFSR bit[11:0] for noise DAC_LFSRUNMASK_BITS11_0 wave generation DAC_TRIANGLEAMPLITUDE_1 Select max triangle amplitude of 1 DAC_TRIANGLEAMPLITUDE_3 Select max triangle amplitude of 3 DAC_TRIANGLEAMPLITUDE_7 Select max triangle amplitude of 7 DAC_TRIANGLEAMPLITUDE_15 Select max triangle amplitude of 15 DAC_TRIANGLEAMPLITUDE_31 Select max triangle amplitude of 31 DAC_TRIANGLEAMPLITUDE_63 Select max triangle amplitude of 63 Select max triangle amplitude of 127 DAC_TRIANGLEAMPLITUDE_127 Select max triangle amplitude of 255 DAC_TRIANGLEAMPLITUDE_255 Select max triangle amplitude of 511 DAC_TRIANGLEAMPLITUDE_511 DAC_TRIANGLEAMPLITUDE_1023 Select max triangle amplitude of 1023 DocID027328 / 1166 168 Rev 2

169 UM1850 DAC Extension Driver HAL DAC_TRIANGLEAMPLITUDE_2047 Select max triangle amplitude of 2047 DAC_TRIANGLEAMPLITUDE_4095 Select max triangle amplitude of 4095 DAC trigger selection DAC_TRIGGER_NONE Conversion is automatic once the DAC1_DHRxxxx register has been loaded, and not by external trigger DAC_TRIGGER_T6_TRGO TIM6 TRGO selected as external conversion trigger for DAC channel ger for TIM7 TRGO selected as external conversion trig DAC_TRIGGER_T7_TRGO DAC channel DAC_TRIGGER_T2_TRGO TIM2 TRGO selected as external conversion trigger for DAC channel TIM4 TRGO selected as external conversion trigger for DAC_TRIGGER_T4_TRGO DAC channel conversion trigger EXTI Line9 event selected as external DAC_TRIGGER_EXT_IT9 for DAC channel Conversion started by software trigger for DAC channel DAC_TRIGGER_SOFTWARE TIM8 TRGO selected as external conversion trigger for DAC_TRIGGER_T8_TRGO DAC channel DAC_TRIGGER_T5_TRGO TIM5 TRGO selected as external conversion trigger for DAC channel 2 DocID027328 Rev 1166 169 /

170 UM1850 HAL DMA Generic Driver 15 HAL DMA Generic Driver 15.1 DMA Firmware driver registers structures 15.1.1 DMA_InitTypeDef Data Fields uint32_t Direction uint32_t PeriphInc uint32_t MemInc uint32_t PeriphDataAlignment uint32_t MemDataAlignment uint32_t Mode uint32_t Priority Field Documentation uint32_t DMA_InitTypeDef::Direction Specifies if the data will be transferred from memory to peripheral, from memory to memory or from peripheral to memory. This parameter can be a value of DMA_Data_transfer_direction uint32_t DMA_InitTypeDef::PeriphInc fies whether the Peripheral address register should be incremented or not. This Speci DMA_Peripheral_incremented_mode parameter can be a value of uint32_t DMA_InitTypeDef::MemInc Specifies whether the memory address register shou ld be incremented or not. This parameter can be a value of DMA_Memory_incremented_mode uint32_t DMA_InitTypeDef::PeriphDataAlignment Specifies the Peripheral data width. This parameter can be a value of DMA_Peripheral_data_size uint32_t DMA_InitTypeDef::MemDataAlignment Specifies the Memory data width. This parameter can be a value of DMA_Memory_data_size uint32_t DMA_InitTypeDef::Mode Specifies the operation mode of the DMAy Channelx. This parameter can be a value of DMA_mode Note: - memory data transfer to - The circular buffer mode cannot be used if the memory is configured on the selected Channel y uint32_t DMA_InitTypeDef::Priorit Specifies the software priority for the DMAy Channelx. This parameter can be a value of DMA_Priority_level __DMA_HandleTypeDef 15.1.2 Data Fields DMA_Channel_TypeDef * Instance TypeDef Init DMA_Init HAL_LockTypeDef Lock HAL_DMA_StateTypeDef State void * Parent void(* XferCpltCallback void(* XferHalfCpltCallback DocID027328 / 1166 170 Rev 2

171 UM1850 DMA Generic Driver HAL void(* XferErrorCallback void(* XferAbortCallback __IO uint32_t ErrorCode DMA_TypeDef * DmaBaseAddress uint32_t ChannelIndex Fiel d Documentation DMA_Channel_TypeDef* __DMA_HandleTypeDef::Instance Register base address DMA_InitTypeDef __DMA_HandleTypeDef::Init DMA communication parameters HAL_LockTypeDef __DMA_HandleTypeDef::Lock DMA locking object __DMA_HandleTypeDef::State HAL_DMA_StateTypeDef DMA transfer state void* __DMA_HandleTypeDef::Parent Parent object state void(* __DMA_HandleTypeDef::XferCpltCallback)(struct __DMA_HandleTypeDef *hdma) DMA transfer complete callback __DMA_HandleTypeDef::XferHalfCpltCallback)(struct void(* __DMA_HandleTypeDef *hdma) DMA Half transfer complete callback void(* __DMA_HandleTypeDef::XferErrorCallback)(struct __DMA_HandleTypeDef *hdma) DMA transfer error callback AbortCallback)(struct void(* __DMA_HandleTypeDef::Xfer __DMA_HandleTypeDef *hdma) DMA transfer abort callback __IO uint32_t __DMA_HandleTypeDef::ErrorCode DMA Error code DMA_TypeDef* __DMA_HandleTypeDef::DmaBaseAddress DMA Channel Base Address uint32_t __DMA_HandleTypeDef::ChannelIndex DMA Channel Index 15.2 DMA Firmware driver API description How to use this driver 15.2.1 1. Enable and configure the peripheral to be connected to the DMA Channel (except for AM / FLASH memories: no initialization is necessary). Please refer to the internal SR Reference manual for connection between peripherals and DMA requests. For a given Channel, program the required configuration through the following 2. sfer Direction, Source and Destination data parameters: Channel request, Tran formats, Circular or Normal mode, Channel Priority level, Source and Destination Increment mode using HAL_DMA_Init() function. 3. Use HAL_DMA_GetState() function to return the DMA state and se of error detection. HAL_DMA_GetError() in ca Use HAL_DMA_Abort() function to abort the current transfer 4. - to - Memory In Memory transfer mode, Circular mode is not allowed. 2 DocID027328 Rev 1166 171 /

172 HAL DMA Generic Driver UM1850 Polling mode IO operation Use HAL_DMA_Start() to start DMA transfer after the configuration of Source addre ss and destination address and the Length of data to be transferred Use HAL_DMA_PollForTransfer() to poll for the end of current transfer, in this case a fixed Timeout can be configured by User depending from his application. Interrupt mode IO operation C onfigure the DMA interrupt priority using HAL_NVIC_SetPriority() Enable the DMA IRQ handler using HAL_NVIC_EnableIRQ() Use HAL_DMA_Start_IT() to start DMA transfer after the configuration of Source address and destination address and the Length of data to be transferred. In this case the DMA interrupt is configured Use HAL_DMA_IRQHandler() called under DMA_IRQHandler() Interrupt subroutine At the end of data transfer HAL_DMA_IRQHandler() function is executed and user can n of function pointer XferCpltCallback and add his own function by customizatio XferErrorCallback (i.e. a member of DMA handle structure). DMA HAL driver macros list Below the list of most used macros in DMA HAL driver. __HAL_DMA_ENABLE: Enable the specified DMA Channel. __HAL_DMA_DISABLE: Disable the specified DMA Channel. __HAL_DMA_GET_FLAG: Get the DMA Channel pending flags. __HAL_DMA_CLEAR_FLAG: Clear the DMA Channel pending flags. __HAL_DMA_ENABLE_IT: Enable the specified DMA Channel interrupts. __HAL_DMA_DISABLE_IT: Disable the specif ied DMA Channel interrupts. __HAL_DMA_GET_IT_SOURCE: Check whether the specified DMA Channel interrupt has occurred or not. You can refer to the DMA HAL driver header file for more useful macros 15.2.2 initialization functions - Initialization and de This section provides functions allowing to initialize the DMA Channel source and destination addresses, incrementation and data sizes, transfer direction, circular/normal - to , memory memory mode selection and Channel priority value. - mode selection The HAL_DMA_Init() function follows the DMA configuration procedures as described in reference manual. This section contains the following APIs: ) HAL_DMA_Init( HAL_DMA_DeInit() 15.2.3 IO operation functions This section provides functions allowing to: Configure the source, destination address and data length and Start DMA transfer Configure the source, destination address and data length and Start DMA transfer with interrupt DocID027328 / 1166 172 Rev 2

173 UM1850 HAL DMA Generic Driver Abort DMA transfer Poll for transfer complete Handle DMA interrupt request This section contains the following APIs: tart() HAL_DMA_S HAL_DMA_Start_IT() HAL_DMA_Abort() HAL_DMA_Abort_IT() HAL_DMA_PollForTransfer() DMA_IRQHandler() HAL_ HAL_DMA_RegisterCallback() HAL_DMA_UnRegisterCallback() Peripheral State and Errors functions 15.2.4 This subsection provides functions allowing to Check the DMA state Get error code This section contains the following APIs: HAL_DMA_GetState() HAL_DMA_GetError() 15.2.5 Detailed description of f unctions HAL_DMA_Init HAL_StatusTypeDef HAL_DMA_Init (DMA_HandleTypeDef * Function name hdma) Initialize the DMA according to the specified parameters in the Function description DMA_InitTypeDef and initialize the associated handle. Parameters hdma: Pointer to a DMA_HandleTypeDef structure that contains the configuration information for the specified DMA Channel. R eturn values HAL: status HAL_DMA_DeInit HAL_StatusTypeDef HAL_DMA_DeInit (DMA_HandleTypeDef * Function name hdma) Function description DeInitialize the DMA peripheral. Parameters pointer to a DMA_HandleTypeDef structure that hdma: contains the configuration information for the specified DMA Channel. Return values HAL: status HAL_DMA_Start HAL_StatusTypeDef HAL_DMA_Start (DMA_HandleTypeDef * Function name nt32_t DstAddress, uint32_t hdma, uint32_t SrcAddress, ui 2 DocID027328 Rev 1166 173 /

174 HAL UM1850 DMA Generic Driver DataLength) Function description Start the DMA Transfer. Parameters hdma: pointer to a DMA_HandleTypeDef structure that contains the configuration information for the specified DMA Channel. SrcAddress: fer address The source memory Buf DstAddress: The destination memory Buffer address The length of data to be transferred from DataLength: source to destination Return values status HAL: HAL_DMA_Start_IT HAL_StatusTypeDef HAL_DMA_Start_IT Function name (DMA_HandleTypeDef * hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength) Function description Start the DMA Transfer with interrupt enabled. Parameters pointer to a DMA_HandleTypeDef structure that hdma: fied DMA contains the configuration information for the speci Channel. The source memory Buffer address SrcAddress: DstAddress: The destination memory Buffer address DataLength: The length of data to be transferred from source to destination Return values HAL: status HAL_DMA_Abort tusTypeDef HAL_DMA_Abort (DMA_HandleTypeDef * HAL_Sta Function name hdma) Function description Abort the DMA Transfer. Parameters pointer to a DMA_HandleTypeDef structure that hdma: contains the configuration information for the specified DMA Channel. Return values HAL: status HAL_DMA_Abort_IT HAL_StatusTypeDef HAL_DMA_Abort_IT Function name (DMA_HandleTypeDef * hdma) Aborts the DMA Transfer in Interrupt mode. Function description Parameters : pointer to a DMA_HandleTypeDef structure that hdma: contains the configur ation information for the specified DMA Channel. Return values HAL: status DocID027328 / 1166 174 Rev 2

175 DMA Generic Driver UM1850 HAL HAL_DMA_PollForTransfer HAL_StatusTypeDef HAL_DMA_PollForTransfer Function name (DMA_HandleTypeDef * hdma, uint32_t CompleteLevel, uint32_t Timeout) Function description Polling for transfer complete. Parameters hdma: pointer to a DMA_HandleTypeDef structure that contains the configuration information for the specified DMA Channel. Specifies the DMA level complete. CompleteLevel: Timeout duration. Timeout: values Return HAL: status HAL_DMA_IRQHandler void HAL_DMA_IRQHandler (DMA_HandleTypeDef * hdma) Function name Function description Handles DMA interrupt request. Parameters pointer to a DMA_HandleTypeDef structure that hdma: contains the configuration information for the specified DMA Channel. Return values None: HAL_DMA_RegisterCallback HAL_StatusTypeDef HAL_DMA_RegisterCallback Function name (DMA_HandleTypeDef * hdma, HAL_DMA _CallbackIDTypeDef CallbackID, void(*)(DMA_HandleTypeDef *_hdma) pCallback) Function description Register callbacks. Parameters pointer to a DMA_HandleTypeDef structure that hdma: contains the configuration information for the specified DMA Channel. User Callback identifer a CallbackID: HAL_DMA_CallbackIDTypeDef ENUM as parameter. pCallback: pointer to private callbacsk function which has pointer to a DMA_HandleTypeDef structure as parameter. Return values HAL: status HAL_DMA_UnRegisterCallback HAL_StatusTypeDef HAL_DMA_UnRegisterCallback F unction name (DMA_HandleTypeDef * hdma, HAL_DMA_CallbackIDTypeDef CallbackID) UnRegister callbacks. Function description Parameters pointer to a DMA_HandleTypeDef structure that hdma: ion information for the specified DMA contains the configurat Channel. CallbackID: User Callback identifer a HAL_DMA_CallbackIDTypeDef ENUM as parameter. 2 DocID027328 Rev 1166 175 /

176 HAL UM1850 DMA Generic Driver Return values HAL: status HAL_DMA_GetState HAL_DMA_StateTypeDef HAL_DMA_GetState Function name (DMA_HandleTypeDef * hdma) Function description Return the DMA hande state. Parameters pointer to a DMA_HandleTypeDef structure that hdma: contains the configuration information for the specified DMA Channel. Return values state HAL: HAL_DMA_GetError HAL_DMA_GetError (DMA_HandleTypeDef * hdma) uint32_t Function name Function description Return the DMA error code. Parameters : pointer to a DMA_HandleTypeDef structure that hdma: contains the configuration information for the specified DMA Channel. Return values DMA: Error Code 15.3 DMA Firmware driver defines 15.3.1 DMA DMA Data transfer direction DMA_PERIPH_TO_MEMORY Peripheral to memory direction Memory to peripheral direction DMA_MEMORY_TO_PERIPH Memory to memory direction DMA_MEMORY_TO_MEMORY DMA Error Code HAL_DMA_ERROR_NONE No error HAL_DMA_ERROR_TE Transfer error HAL_DMA_ERROR_NO_XFER no ongoing transfer Timeout error HAL_DMA_ERROR_TIMEOUT Not supported mode HAL_DMA_ERROR_NOT_SUPPORTED DMA Exported Macros Description: __HAL_DMA_RESET_HANDLE_STATE Reset DMA handle state. Parameters: __HANDLE__: DMA handle Return value: None DocID027328 / 1166 176 Rev 2

177 UM1850 DMA Generic Driver HAL Description: __HAL_DMA_ENABLE Enable the specified DMA Channel. Parameters: __HANDLE__: DMA handle Return value: None Description: __HAL_DMA_DISABLE Disable the specified DMA Channel. Parameters: __HANDLE__: DMA handle Return value: None Description: __HAL_DMA_ENABLE_IT Enables the specified DMA Channel interrupts. Parameters: __HANDLE__: DMA handle __INTERRUPT__: specifies the DMA interrupt sources to be enabled or disabled. This parameter can be any combination of the following values: DMA_IT_TC: Transfer complete interrupt mask DMA_IT_HT: Half transfer complete interrupt mask DMA_IT_TE: Transfer error interrupt mask Return value: None Description: __HAL_DMA_DISABLE_IT Disable the specified DMA Channel interrupts. Parameters: __HANDLE__: DMA handle __INTERRUPT__: specifies the DMA or interrupt sources to be enabled disabled. This parameter can be any combination of the following values: DMA_IT_TC: Transfer complete interrupt mask DMA_IT_HT: Half transfer complete interrupt mask DMA_IT_TE: Transfer error interrupt 2 DocID027328 Rev 1166 177 /

178 DMA Generic Driver HAL UM1850 mask Return value: None Description: __HAL_DMA_GET_IT_SOURCE Check whether the specified DMA Channel interrupt is enabled or not. Parameters: __HANDLE__: DMA handle __INTERRUPT__: specifies the DMA interrupt source to check. This parameter can be one of the following values: DMA_IT_TC: Transfer complet e interrupt mask DMA_IT_HT: Half transfer complete interrupt mask DMA_IT_TE: Transfer error interrupt mask Return value: The: state of DMA_IT (SET or RESET). Description: __HAL_DMA_GET_COUNTER Return the number of remaining data units in the current DMA C hannel transfer. Parameters: __HANDLE__: DMA handle Return value: The: number of remaining data units in the current DMA Channel transfer. DMA flag definitions DMA_FLAG_GL1 DMA_FLAG_TC1 DMA_FLAG_HT1 DMA_FLAG_TE1 DMA_FLAG_GL2 DMA_FLAG_TC2 DMA_FLAG_HT2 DMA_FLAG_TE2 DMA_FLAG_GL3 DMA_FLAG_TC3 DMA_FLAG_HT3 DMA_FLAG_TE3 DocID027328 / 1166 178 Rev 2

179 UM1850 DMA Generic Driver HAL DMA_FLAG_GL4 DMA_FLAG_TC4 DMA_FLAG_HT4 DMA_FLAG_TE4 DMA_FLAG_GL5 DMA_FLAG_TC5 DMA_FLAG_HT5 DMA_FLAG_TE5 DMA_FLAG_GL6 DMA_FLAG_TC6 DMA_FLAG_HT6 DMA_FLAG_TE6 DMA_FLAG_GL7 DMA_FLAG_TC7 DMA_FLAG_HT7 DMA_FLAG_TE7 DMA interrupt enable definitions DMA_IT_TC DMA_IT_HT DMA_IT_TE DMA Memory data size DMA_MDATAALIGN_BYTE Memory data alignment: Byte DMA_MDATAALIGN_HALFWORD Memory data alignment: HalfWord Memory data alignment: Word DMA_MDATAALIGN_WORD DMA Memory incremented mode Memory increment mode Enable DMA_MINC_ENABLE DMA_MINC_DISABLE Memory increment mode Disable DMA mode Normal mode DMA_NORMAL DMA_CIRCULAR Circular mode DMA Peripheral data size Peripheral data alignment: Byte DMA_PDATAALIGN_BYTE DMA_PDATAALIGN_HALFWORD Peripheral data alignment: HalfWord DMA_PDATAALIGN_WORD Peripheral data alignment: Word DMA Peripheral incremented mode LE DMA_PINC_ENAB Peripheral increment mode Enable 2 DocID027328 Rev 1166 179 /

180 HAL DMA Generic Driver UM1850 Peripheral increment mode Disable DMA_PINC_DISABLE DMA Priority level Priority level : Low DMA_PRIORITY_LOW Priority level : Medium DMA_PRIORITY_MEDIUM DMA_PRIORITY_HIGH Priority level : High Priority level : Very_High DMA_PRIORITY_VERY_HIGH DocID027328 / 1166 180 Rev 2

181 UM1850 DMA Extension Driver HAL HAL DMA Extension Driver 16 DMAEx Firmware driver defines 16.1 DMAEx 16.1.1 density and XL density product devices DMAEx High Description: __HAL_DMA_GET_TC_FLAG_INDEX Returns the current DMA Channel transfer complete flag. Parameters: __HANDLE__: DMA handle Return value: The: specified transfer complete flag index. Description: EX __HAL_DMA_GET_HT_FLAG_IND Returns the current DMA Channel half transfer complete flag. Parameters: __HANDLE__: DMA handle Return value: The: specified half transfer complete flag index. Description: __HAL_DMA_GET_TE_FLAG_INDEX Returns the current DMA Channel transfer error flag. Parameters: __HANDLE__: DMA handle Return value: The: specified transfer error flag index. Description: __HAL_DMA_GET_GI_FLAG_INDEX Return the current DMA Channel Global interrupt flag. Parameters: __HANDLE__: DMA handle Return value: The: specified transfer error flag index. Description: __HAL_DMA_GET_FLAG Get the DMA Channel pending flags. 2 DocID027328 Rev 1166 181 /

182 HAL DMA Extension Driver UM1850 Parameters: __HANDLE__: DMA handle __FLAG__: Get the specified flag. This parameter can be any combination of the following values: DMA_FLAG_TCx: Transfer complete flag DMA_FLAG_HTx: Half transfer complete flag DMA_FLAG_TEx: Transfer error flag Where x can be 1_7 or 1_5 (depending on DMA1 or DMA2) to select the DMA Channel flag. Return value: The: state of FLAG (SET or RESET). Description: __HAL_D MA_CLEAR_FLAG Clears the DMA Channel pending flags. Parameters: __HANDLE__: DMA handle __FLAG__: specifies the flag to clear. This parameter can be any combination of the following values: DMA_FLAG_TCx: Transfer complete flag Half transfer DMA_FLAG_HTx: complete flag DMA_FLAG_TEx: Transfer error flag Where x can be 1_7 or 1_5 (depending on DMA1 or DMA2) to select the DMA Channel flag. Return value: None DocID027328 / 1166 182 Rev 2

183 UM1850 ETH Generic Driver HAL HAL ETH Generic Driver 17 ers structures 17.1 ETH Firmware driver regist ETH_InitTypeDef 17.1.1 Data Fields uint32_t AutoNegotiation uint32_t Speed uint32_t DuplexMode uint16_t PhyAddress uint8_t * MACAddr uint32_t RxMode uint32_t ChecksumMode uint32_t MediaInterface Field Documentation uint32_t ETH_InitTypeDef::AutoNegotiation Selects or not the AutoNegotiation mode for the external PHY The AutoNegotiation allows an automatic setting of the Speed (10/100Mbps) and the mode (half/ful l - duplex). This parameter can be a value of ETH_AutoNegotiation uint32_t ETH_InitTypeDef::Speed ETH_Speed Sets the Ethernet speed: 10/100 Mbps. This parameter can be a value of uint32_t ETH_ InitTypeDef::DuplexMode Selects the MAC duplex mode: Half - Duplex or Full - Duplex mode This parameter can ETH_Duplex_Mode be a value of uint16_t ETH_InitTypeDef::PhyAddress r between Min_Data = 0 and Ethernet PHY address. This parameter must be a numbe Max_Data = 32 uint8_t* ETH_InitTypeDef::MACAddr MAC Address of used Hardware: must be pointer on an array of 6 bytes uint32_t ETH_InitTypeDef::RxMode Selects the Ethernet Rx mode: Polling mode, Interrupt mode. This parameter ca n be a value of ETH_Rx_Mode uint32_t ETH_InitTypeDef::ChecksumMode Selects if the checksum is check by hardware or by software. This parameter can be a value of ETH_Checksum_Mode uint32_t ET H_InitTypeDef::MediaInterface independent interface or the reduced media Selects the media independent interface. - - This parameter can be a value of ETH_Media_Interface 17.1.2 ETH_MACInitTypeDef Data Fields uint32_t Watchdog uint32_t Jabber uint32_t InterFrameGap uint32_t CarrierSense uint32_t ReceiveOwn uint32_t LoopbackMode uint32_t ChecksumOffload 2 DocID027328 Rev 1166 183 /

184 HAL UM1850 ETH Generic Driver uint32_t RetryTransmission uint32_t AutomaticPadCRCStrip uint32_t BackOffLimit uint32_t DeferralCheck uint32_t ReceiveAll uint32_t SourceAddrFilter uint32_t PassControlFrames uint32_t BroadcastFramesReception uint32_t DestinationAddrFilter uint32_t PromiscuousMode uint32_t MulticastFramesFilter uint32_t UnicastFramesFilter HashTableHigh uint32_t uint32_t HashTableLow uint32_t PauseTime uint32_t ZeroQuantaPause uint32_t PauseLowThreshold uint32_t UnicastPauseFrameDetect uint32_t ReceiveFlowControl uint32_t TransmitFlowControl uint32_t VLANTagComparison uint32_t VLANTagIdentifier Field Documentation uint32_t ETH_MACInitTypeDef::Watchdog Selects or not the Watchdog timer When enabled, the MAC allows no more then 2048 bytes to be received. When disabled, the MAC can receive up to 16384 bytes. This ETH_Watchdog parameter can be a value of uint32_t ETH_MACInitTypeDef::Jabber Selects or not Jabber timer When enabled, the MAC allows no more then 2048 bytes to be sent. When disabled, the MAC can send up to 16384 bytes. This parameter can be a value of ETH_Jabber uint32_t ETH_MACInitTypeDef::InterFrameGap Selects the minimum IFG between frames during transmission. This parameter can be a value of ETH_Inter_Frame_Gap uint32_t ETH_MACInitTypeDef::Carr ierSense Selects or not the Carrier Sense. This parameter can be a value of ETH_Carrier_Sense uint32_t ETH_MACInitTypeDef::ReceiveOwn Selects or not the ReceiveOwn, ReceiveOwn allows the reception of frames when the TX_EN s Duplex mode. This parameter can be a value of - ignal is asserted in Half ETH_Receive_Own uint32_t ETH_MACInitTypeDef::LoopbackMode Selects or not the internal MAC MII Loopback mode. This parameter can be a value of ETH_Loop_Back_Mode uint32_t ETH_MACInitTypeDef::ChecksumOffload Selects or not the IPv4 checksum checking for received frame payloads' ETH_Checksum_Offload TCP/UDP/ICMP headers. This parameter can be a value of uint32_t ETH_MACInitTypeDef::RetryTransmission Selects or not the MAC attempt retries transmission, based on the settings of BL, - when a collision occurs (Half Duplex mode). This parameter can be a value of ETH_Retry_Transmission DocID027328 / 1166 184 Rev 2

185 ETH Generic Driver UM1850 HAL uint32_t ETH_MACInitTypeDef::AutomaticPadCRCStrip Selects or not the Automatic MAC Pad/CRC Stripping. This parameter can be a value of ETH_Automatic_Pad_CRC_Strip ETH_MACInitTypeDef::BackOffLimit uint32_t Selects the BackOff limit value. This parameter can be a value of ETH_Back_Off_Limit uint32_t ETH_MACInitTypeDef::DeferralCheck Selects or not the deferral check function (Half This parameter can be - Duplex mode). a value of ETH_Deferral_Check uint32_t ETH_MACInitTypeDef::ReceiveAll Selects or not all frames reception by the MAC (No filtering). This parameter can be a TH_Receive_All value of E uint32_t ETH_MACInitTypeDef::SourceAddrFilter Selects the Source Address Filter mode. This parameter can be a value of ETH_Source_Addr_Filter uint32_t ETH_MACInitTypeDef::PassControlFrames Sets the forwarding mode of the control frames (including unicast and multicast PAUSE frames) This parameter can be a value of ETH_Pass_Control_Frames uint32_t ETH_MACInitTypeDef::BroadcastFramesReception cast Frames. This parameter can be a value of Selects or not the reception of Broad ETH_Broadcast_Frames_Reception uint32_t ETH_MACInitTypeDef::DestinationAddrFilter Sets the destination filter mode for both unicast and multicast frames. This parameter can be a value of ETH_Destination_Addr_Filter uint32_t ETH_MACInitTypeDef::PromiscuousMode Selects or not the Promiscuous Mode This parameter can be a value of ETH_Promiscuous_Mode uint32_t ETH_MACI nitTypeDef::MulticastFramesFilter Selects the Multicast Frames filter mode: None/HashTableFilter/PerfectFilter/PerfectHashTableFilter. This parameter can be a value of ETH_Multicast_Frames_Filter ::UnicastFramesFilter uint32_t ETH_MACInitTypeDef Selects the Unicast Frames filter mode: HashTableFilter/PerfectFilter/PerfectHashTableFilter. This parameter can be a value of ETH_Unicast_Frames_Filter uint32_t ETH_MACInitTypeDef::HashTableHigh This field holds the higher 32 bits of Hash table. This parameter must be a number between Min_Data = 0x0 and Max_Data = 0xFFFFFFFFU uint32_t ETH_MACInitTypeDef::HashTableLow This field holds the lower 32 bits of Hash table. This parameter must be a numbe r between Min_Data = 0x0 and Max_Data = 0xFFFFFFFFU uint32_t ETH_MACInitTypeDef::PauseTime This field holds the value to be used in the Pause Time field in the transmit control frame. This parameter must be a number between Min_Data = 0x0 and Max_Data = xFFFFU 0 uint32_t ETH_MACInitTypeDef::ZeroQuantaPause - Quanta Pause Control frames. This Selects or not the automatic generation of Zero ETH_Zero_Quanta_Pause parameter can be a value of hreshold uint32_t ETH_MACInitTypeDef::PauseLowT This field configures the threshold of the PAUSE to be checked for automatic retransmission of PAUSE Frame. This parameter can be a value of ETH_Pause_Low_Threshold ect uint32_t ETH_MACInitTypeDef::UnicastPauseFrameDet Selects or not the MAC detection of the Pause frames (with MAC Address0 unicast 2 DocID027328 Rev 1166 185 /

186 HAL UM1850 ETH Generic Driver address and unique multicast address). This parameter can be a value of ETH_Unicast_Pause_Frame_Detect uint32_t ETH_MACInitTypeDef::Receive FlowControl Enables or disables the MAC to decode the received Pause frame and disable its transmitter for a specified time (Pause Time) This parameter can be a value of ETH_Receive_Flow_Control :TransmitFlowControl uint32_t ETH_MACInitTypeDef: - Duplex mode) or the Enables or disables the MAC to transmit Pause frames (Full - MAC back Duplex mode) This parameter can be a value of - pressure operation (Half ETH_Transmit_Flow_Control uint32_t ETH_MACI nitTypeDef::VLANTagComparison - bit VLAN identifier or the complete 16 - bit VLAN tag for comparison and Selects the 12 ETH_VLAN_Tag_Comparison filtering. This parameter can be a value of uint32_t ETH_MACInitTypeDef::VLANTagIde ntifier Holds the VLAN tag identifier for receive frames 17.1.3 ETH_DMAInitTypeDef Data Fields uint32_t DropTCPIPChecksumErrorFrame uint32_t ReceiveStoreForward uint32_t FlushReceivedFrame uint32_t TransmitStoreForward uint32_t TransmitThresholdControl uint32_t ForwardErrorFrames uint32_t ForwardUndersizedGoodFrames uint32_t ReceiveThresholdControl uint32_t SecondFrameOperate uint32_t AddressAlignedBeats uint32_t FixedBurst uint32_t RxDMABurstLength TxDMABurstLength uint32_t uint32_t DescriptorSkipLength uint32_t DMAArbitration Field Documentation uint32_t ETH_DMAInitTypeDef::DropTCPIPChecksumErrorFrame Selects or not the Dropping of TCP/IP Checksum Error Frames. This parameter can be a value of ETH_Drop_TCP_IP_Checksum_Error_Frame uint32_t ETH_DMAInitTypeDef::ReceiveStoreForward Enables or disables the Receive store and forward mode. This parameter can be a value of ETH_Receive_Store _Forward uint32_t ETH_DMAInitTypeDef::FlushReceivedFrame Enables or disables the flushing of received frames. This parameter can be a value of ETH_Flush_Received_Frame uint32_t ETH_DMAInitTypeDef::TransmitStoreForward es or disables Transmit store and forward mode. This parameter can be a value Enabl of ETH_Transmit_Store_Forward uint32_t ETH_DMAInitTypeDef::TransmitThresholdControl can be a value of Selects or not the Transmit Threshold Control. This parameter ETH_Transmit_Threshold_Control uint32_t ETH_DMAInitTypeDef::ForwardErrorFrames Selects or not the forward to the DMA of erroneous frames. This parameter can be a ETH_Forward_Error_Frames value of DocID027328 / 1166 186 Rev 2

187 ETH Generic Driver UM1850 HAL uint32_t ETH_DMAInitTypeDef::ForwardUndersizedGoodFrames Enables or disables the Rx FIFO to forward Undersized frames (frames with no Error and length less than 64 bytes) including pad bytes and CRC) This parameter can be a - value o ETH_Forward_Undersized_Good_Frames f uint32_t ETH_DMAInitTypeDef::ReceiveThresholdControl Selects the threshold level of the Receive FIFO. This parameter can be a value of old_Control ETH_Receive_Thresh uint32_t ETH_DMAInitTypeDef::SecondFrameOperate Selects or not the Operate on second frame mode, which allows the DMA to process a second frame of Transmit data even before obtaining the status for the first frame. ETH_Second_Frame_Operate of This parameter can be a value uint32_t ETH_DMAInitTypeDef::AddressAlignedBeats Enables or disables the Address Aligned Beats. This parameter can be a value of ETH_Address_Aligned_Beats uint32 _t ETH_DMAInitTypeDef::FixedBurst Enables or disables the AHB Master interface fixed burst transfers. This parameter can be a value of ETH_Fixed_Burst uint32_t ETH_DMAInitTypeDef::RxDMABurstLength er of beats to be transferred in one Rx DMA transaction. Indicates the maximum numb This parameter can be a value of ETH_Rx_DMA_Burst_Length uint32_t ETH_DMAInitTypeDef::TxDMABurstLength Indicates the maximum number of beats to be transferred in one Tx DMA transaction. ETH_Tx_DMA_Burst_Length This parameter can be a value of uint32_t ETH_DMAInitTypeDef::DescriptorSkipLength Specifies the number of word to s kip between two unchained descriptors (Ring mode) This parameter must be a number between Min_Data = 0 and Max_Data = 32 uint32_t ETH_DMAInitTypeDef::DMAArbitration Selects the DMA Tx/Rx arbitration. This parameter can be a value of ETH_DMA_Arbitration 17.1.4 ETH_DMADescTypeDef Data Fields __IO uint32_t Status uint32_t ControlBufferSize uint32_t Buffer1Addr uint32_t Buffer2NextDescAddr Field Documentation __IO uint32_t ETH_DMADescTypeDef::Status Status uint32_t ETH_DMADescTypeDef::ControlBufferSize Control and Buffer1, Buffer2 lengths uint32_t ETH_DMADescTypeDef::Buffer1Addr Buffer1 address pointer uint32_t ETH_DMADescTypeDef::Buffer2NextDescAddr iptor address pointer Buffer2 or next descr 17.1.5 ETH_DMARxFrameInfos Data Fields ETH_DMADescTypeDef * FSRxDesc ETH_DMADescTypeDef * LSRxDesc uint32_t SegCount 2 DocID027328 Rev 1166 187 /

188 HAL UM1850 ETH Generic Driver uint32_t length uint32_t buffer Field Documentation ETH_DMADescTypeDef* ETH_DMA RxFrameInfos::FSRxDesc First Segment Rx Desc ETH_DMADescTypeDef* ETH_DMARxFrameInfos::LSRxDesc Last Segment Rx Desc uint32_t ETH_DMARxFrameInfos::SegCount Segment count uint32_t ETH_DMARxFrameInfos::length Frame length uint32_t ETH_DMARxFrameInfos::buf fer Frame buffer ETH_HandleTypeDef 17.1.6 Data Fields ETH_TypeDef * Instance ETH_InitTypeDef Init uint32_t LinkStatus ETH_DMADescTypeDef * RxDesc ETH_DMADescTypeDef * TxDesc ETH_DMARxFrameInfos RxFrameInfos HAL_ETH_StateTypeDef State __IO HAL_LockTypeDef Lock Field Documentation ETH_TypeDef* ETH_HandleTypeDef::Instance Register base address ETH_InitTypeDef ETH_HandleTypeDef::Init Ethernet Init Configuration uint32_t ETH_HandleTypeDef::LinkStatus Ethernet link st atus ETH_DMADescTypeDef* ETH_HandleTypeDef::RxDesc Rx descriptor to Get ETH_DMADescTypeDef* ETH_HandleTypeDef::TxDesc Tx descriptor to Set ETH_DMARxFrameInfos ETH_HandleTypeDef::RxFrameInfos last Rx frame infos ef::State __IO HAL_ETH_StateTypeDef ETH_HandleTypeD ETH communication state HAL_LockTypeDef ETH_HandleTypeDef::Lock ETH Lock 17.2 ETH Firmware driver API description 17.2.1 How to use this driver andle structure, for example: ETH_HandleTypeDef Declare a ETH_HandleTypeDef h 1. heth; Fill parameters of Init structure in heth handle 2. Call HAL_ETH_Init() API to initialize the Ethernet peripheral (MAC, DMA, ...) 3. 4. : Initialize the ETH low level resources through the HAL_ETH_MspInit() API DocID027328 / 1166 188 Rev 2

189 HAL UM1850 ETH Generic Driver a. Enable the Ethernet interface clock using __HAL_RCC_ETHMAC_CLK_ENABLE(); __HAL_RCC_ETHMACTX_CLK_ENABLE(); __HAL_RCC_ETHMACRX_CLK_ENABLE(); b. Initialize the related GPIO clocks - out c. Configure Ethernet pin d. Configure Ethernet NVIC interrupt (IT mode) 5. Initialize Ethernet DMA Descriptors in chain mode and point to allocated buffers: a. HAL_ETH_DMATxDescListInit(); for Transmission process HAL_ETH_DMARxDescListInit(); for Reception process b. 6. Enable MAC and DMA transmission and reception: a. HAL_ETH_Start(); 7. P repare ETH DMA TX Descriptors and give the hand to ETH DMA to transfer the frame to MAC TX FIFO: a. HAL_ETH_TransmitFrame(); Poll for a received frame in ETH RX DMA Descriptors and get received frame 8. parameters HAL_ETH_GetReceivedFrame(); (should be called into an infinite loop) a. Get a received frame when an ETH RX interrupt occurs: 9. a. HAL_ETH_GetReceivedFrame_IT(); (called in IT mode only) 10. Communicate with external PHY device: a. Read a specific register from the P HY HAL_ETH_ReadPHYRegister(); Write data to a specific RHY register: HAL_ETH_WritePHYRegister(); b. 11. Configure the Ethernet MAC after ETH peripheral initialization HAL_ETH_ConfigMAC(); all MAC parameters should be filled. 12. Configure the Ethernet DMA after ETH peripheral initialization HAL_ETH_ConfigDMA(); all DMA parameters should be filled. The PTP protocol and the DMA descriptors ring mode are not supported in this driver initialization functions 17.2.2 Initialization and de - This section provides functions allowing to: Initialize and configure the Ethernet peripheral - De initialize the Ethernet peripheral This section contains the following APIs: HAL_ETH_Init() HAL_ETH_DeInit() HAL_ETH_DMATxDescListInit() HAL_ETH_DMARxDescListInit() HAL_ETH_MspInit() AL_ETH_MspDeInit() H 17.2.3 IO operation functions This section provides functions allowing to: Transmit a frame HAL_ETH_TransmitFrame(); Receive a frame HAL_ETH_GetReceivedFrame(); HAL_ETH_GetReceivedFrame_IT(); Read from an External PHY register HAL_ETH_ReadPHYRegister(); Write to an External PHY register HAL_ETH_WritePHYRegister(); This section contains the following APIs: HAL_ETH_TransmitFrame() 2 DocID027328 Rev 1166 189 /

190 HAL ETH Generic Driver UM1850 HAL_ ETH_GetReceivedFrame() HAL_ETH_GetReceivedFrame_IT() HAL_ETH_IRQHandler() HAL_ETH_TxCpltCallback() HAL_ETH_RxCpltCallback() HAL_ETH_ErrorCallback() HAL_ETH_ReadPHYRegister() HAL_ETH_WritePHYRegister() Peripheral Control functions 17.2.4 This section provides functions allowing to: Enable MAC and DMA transmission and reception. HAL_ETH_Start(); Disable MAC and DMA transmission and reception. HAL_ETH_Stop(); Set the MAC configuration in runtime mode HAL_ETH_ConfigMAC(); Set the DMA configuration in runtime mode HAL_ETH_ConfigDMA(); This section contains the following APIs: HAL_ETH_Start() HAL_ETH_Stop() HAL_ETH_ConfigMAC() HAL_ETH_ConfigDMA() 17.2.5 Peripheral State functions This subsection permits to get in run - time the status of the peripheral and the data flow. Get the ETH handle state: HAL_ETH _GetState(); This section contains the following APIs: HAL_ETH_GetState() 17.2.6 Detailed description of functions HAL_ETH_Init (ETH_HandleTypeDef * HAL_StatusTypeDef HAL_ETH_Init Function name heth) Function description Initializes the Ethernet MAC and DMA according to default parameters. Parameters heth: pointer to a ETH_HandleTypeDef structure that contains the configuration information for ETHERNET module Return values status HAL: HAL_ETH_DeInit HAL_StatusTypeDef HAL_ETH_DeInit (ETH_HandleTypeDef * Function name heth) Initializes the ETH peripheral. De Function description - Parameters heth: pointer to a ETH_HandleTypeDef structure that ion information for ETHERNET module contains the configurat DocID027328 / 1166 190 Rev 2

191 UM1850 ETH Generic Driver HAL Return values HAL: status HAL_ETH_MspInit void HAL_ETH_MspInit (ETH_HandleTypeDef * heth) Function name Function description Initializes the ETH MSP. Parameters pointer to a ETH_HandleTypeDef structure that heth: contains the configuration information for ETHERNET module Return values None: HAL_ETH_MspDeInit void HAL_ETH_MspDeInit (ETH_HandleTypeDef * heth) Function name Function description DeInitializes ETH MSP. Parameters pointer to a ETH_HandleTypeDef structure that heth: contains the configuration information for ETHERNET module Return values None: HAL_ETH_DMATxDescListInit HAL_StatusTypeDef HAL_ETH_DMATxDescListInit Function name h, ETH_DMADescTypeDef * (ETH_HandleTypeDef * het DMATxDescTab, uint8_t * TxBuff, uint32_t TxBuffCount) Function description Initializes the DMA Tx descriptors in chain mode. Parameters heth: pointer to a ETH_HandleTypeDef structure that contains the configuration information f or ETHERNET module DMATxDescTab: Pointer to the first Tx desc list TxBuff: Pointer to the first TxBuffer list TxBuffCount: Number of the used Tx desc in the list Return values status HAL: HAL_ETH_DMARxDescListInit HAL_ETH_DMARxDescListInit HAL_StatusTypeDef Function name (ETH_HandleTypeDef * heth, ETH_DMADescTypeDef * DMARxDescTab, uint8_t * RxBuff, uint32_t RxBuffCount) Function description Initializes the DMA Rx descriptors in chain mode. Parameters heth: ture that pointer to a ETH_HandleTypeDef struc contains the configuration information for ETHERNET module Pointer to the first Rx desc list DMARxDescTab: Pointer to the first RxBuffer list RxBuff: RxBuffCount: Number of the used Rx desc in the list Return values status HAL: HAL_ETH_TransmitFrame HAL_StatusTypeDef HAL_ETH_TransmitFrame Function name Rev 2 191 / 1166 DocID027328

192 HAL ETH Generic Driver UM1850 (ETH_HandleTypeDef * heth, uint32_t FrameLength) Sends an Ethernet frame. Function description Parameters pointer to a ETH_HandleTypeDef structure that heth: contains the confi guration information for ETHERNET module Amount of data to be sent FrameLength: Return values status HAL: HAL_ETH_GetReceivedFrame HAL_StatusTypeDef HAL_ETH_GetReceivedFrame Function name (ETH_HandleTypeDef * heth) Function description Checks for received frames. Parameters pointer to a ETH_HandleTypeDef structure that heth: contains the configuration information for ETHERNET module Return values HAL: status HAL_ETH_ReadPHYRegister ister HAL_StatusTypeDef HAL_ETH_ReadPHYReg Function name (ETH_HandleTypeDef * heth, uint16_t PHYReg, uint32_t * RegValue) Function description Reads a PHY register. Parameters pointer to a ETH_HandleTypeDef structure that heth: contains the configuration information for ETHERNET module PHYReg: PHY register address, is the index of one of the 32 PHY register. This parameter can be one of the following values: PHY_BCR: Transceiver Basic Control Register, PHY_BSR: Transceiver Basic Status Register. More PHY register could be read depending on the used PHY RegValue: PHY register value Return values status HAL: HAL_ETH_WritePHYRegister HAL_StatusTypeDef HAL_ETH_WritePHYRegister Function name (ETH_HandleTypeDef * heth, uint16_t PHYReg, uint32_t RegValue) Function description Writes to a PHY register. Parameters pointer to a ETH_HandleTypeDef structure that heth: contains the configuration information for ETHERNET module PHYReg: PHY register address, is the index of one of the 32 PHY register. This parameter can be one of t he following values: PHY_BCR: Transceiver Control Register. More PHY register could be written depending on the used PHY the value to write RegValue: Return values status HAL: DocID027328 / 1166 192 Rev 2

193 UM1850 HAL ETH Generic Driver HAL_ETH_GetReceivedFrame_IT HAL_ETH_GetReceivedFrame_IT HAL_StatusTypeDef Function name (ETH_HandleTypeDef * heth) Function description Gets the Received frame in interrupt mode. Parameters heth: pointer to a ETH_HandleTypeDef structure that contains the configuration information for ETHERNET module Return val ues status HAL: HAL_ETH_IRQHandler void HAL_ETH_IRQHandler (ETH_HandleTypeDef * heth) Function name This function handles ETH interrupt request. Function description Parameters pointer to a ETH_HandleTypeDef structure that heth: ation information for ETHERNET module contains the configur Return values HAL: status HAL_ETH_TxCpltCallback void HAL_ETH_TxCpltCallback (ETH_HandleTypeDef * heth) Function name Tx Transfer completed callbacks. Function description Parameters heth: pointer to a ETH_HandleTypeDef structure that contains the configuration information for ETHERNET module Return values None: HAL_ETH_RxCpltCallback void HAL_ETH_RxCpltCallback (ETH_HandleTypeDef * heth) Function name Rx Transfer completed callbacks. Function description Parameters heth: pointer to a ETH_HandleTypeDef structure that contains the configuration information for ETHERNET module Return values None: HAL_ETH_ErrorCallback void HAL_ETH_ErrorCallback (ETH_HandleT ypeDef * heth) Function name Function description Ethernet transfer error callbacks. Parameters heth: pointer to a ETH_HandleTypeDef structure that contains the configuration information for ETHERNET module Return values None: HAL_ETH_Start HAL_StatusTypeDef HAL_ETH_Start (ETH_HandleTypeDef * Function name heth) 2 DocID027328 Rev 1166 193 /

194 HAL UM1850 ETH Generic Driver Enables Ethernet MAC and DMA reception/transmission. Function description Parameters pointer to a ETH_HandleTypeDef structure that heth: le contains the configuration information for ETHERNET modu Return values status HAL: HAL_ETH_Stop HAL_StatusTypeDef HAL_ETH_Stop (ETH_HandleTypeDef * Function name heth) Function description Stop Ethernet MAC and DMA reception/transmission. Parameters pointer to a ETH_HandleTypeDef structure that heth: contains the configuration information for ETHERNET module Return values HAL: status HAL_ETH_ConfigMAC HAL_StatusTypeDef HAL_ETH_ConfigMAC Function name nf) (ETH_HandleTypeDef * heth, ETH_MACInitTypeDef * macco Set ETH MAC Configuration. Function description Parameters heth: pointer to a ETH_HandleTypeDef structure that contains the configuration information for ETHERNET module macconf: MAC Configuration structure Return values HAL: status HAL_ETH_ConfigDMA HAL_StatusTypeDef HAL_ETH_ConfigDMA Function name (ETH_HandleTypeDef * heth, ETH_DMAInitTypeDef * dmaconf) Sets ETH DMA Configuration. Function description Parameters heth: pointer to a ETH_HandleTypeDef structure that nfiguration information for ETHERNET module contains the co dmaconf: DMA Configuration structure Return values HAL: status HAL_ETH_GetState HAL_ETH_StateTypeDef HAL_ETH_GetState Function name (ETH_HandleTypeDef * heth) Return the ETH HAL state. Function description Parameters heth: pointer to a ETH_HandleTypeDef structure that contains the configuration information for ETHERNET module Return values state HAL: DocID027328 / 1166 194 Rev 2

195 UM1850 ETH Generic Driver HAL ETH Firmware driver defines 17.3 17.3.1 ETH ETH Address Aligned Beats ETH_ADDRESSALIGNEDBEATS_ENABLE ETH_ADDRESSALIGNEDBEATS_DISABLE ETH Automatic Pad CRC Strip ETH_AUTOMATICPADCRCSTRIP_ENABLE ETH_AUTOMATICPADCRCSTRIP_DISABLE ETH AutoNegotiation ETH_AUTONEGOTIATION_ENABLE ETH_AUTONEGOTIATION_DISABLE ETH Back Off Limit ETH_BACKOFFLIMIT_10 ETH_BACKOFFLIMIT_8 ETH_BACKOFFLIMIT_4 ETH_BACKOFFLIMIT_1 ETH Broadcast Frames Reception ETH_BROADCASTFRAMESRECEPTION_ENABLE ETH_BROADCASTFRAMESRECEPTION_DISABLE ETH Buffers setting ETH_MAX_PACKET_SIZE ETH_HEADER + ETH_EXTRA + ETH_VLAN_TAG + ETH_MAX_ETH_PAYLOAD + ETH_CRC ETH_HEADER 6 byte Dest addr, 6 byte Src addr, 2 byte length/type Ethernet CRC ETH_CRC Extra bytes in some cases ETH_EXTRA optional 802.1q VLAN Tag ETH_VLAN_TAG Minimum Ethernet payload size ETH_MIN_ETH_PAYLOAD ETH_MAX_ETH_PAYLOAD Maximum Ethernet payload size ETH_JUMBO_FRAME_PAYLOAD Jumbo frame payload size ETH_RX_BUF_SIZE ETH_RXBUFNB ETH_TX_BUF_SIZE ETH_TXBUFNB Carrier Sense ETH ETH_CARRIERSENCE_ENABLE ETH_CARRIERSENCE_DISABLE 2 DocID027328 Rev 1166 195 /

196 HAL UM1850 ETH Generic Driver ETH Checksum Mode ETH_CHECKSUM_BY_HARDWARE ETH_CHECKSUM_BY_SOFTWARE ETH Checksum Offload ETH_CHECKSUMOFFLAOD_ENABLE ETH_CHECKSUMOFFLAOD_DISABLE ETH Deferral Check ETH_DEFFERRALCHECK_ENABLE ETH_DEFFERRALCHECK_DISABLE ETH Destination Addr Filter ETH_DESTINATIONADDRFILTER_NORMAL ETH_DESTINATIONADDRFILTER_INVERSE ETH DMA Arbitration ETH_DMAARBITRATION_ROUNDROBIN_RXTX_1_1 ETH_DMAARBITRATION_ROUNDROBIN_RXTX_2_1 ETH_DMAARBITRATION_ROUNDROBIN_RXTX_3_1 ETH_DMAARBITRATION_ROUNDROBIN_RXTX_4_1 ETH_DMAARBITRATION_RXPRIORTX ETH DMA Flags ETH_DMA_FLAG_TST stamp trigger interrupt (on DMA) - Time PMT interrupt (on DMA) ETH_DMA_FLAG_PMT MMC interrupt (on DMA) ETH_DMA_FLAG_MMC Error bits 0 - - Rx DMA, 1 ETH_DMA_FLAG_DATATRANSFERERROR Tx DMA ETH_DMA_FLAG_READWRITEERROR Error bits 0 - write transfer, 1 - read transfer desc. access ETH_DMA_FLAG_ACCESSERROR Error bits 0 - data buffer, 1 - Normal i ETH_DMA_FLAG_NIS nterrupt summary flag ETH_DMA_FLAG_AIS Abnormal interrupt summary flag ETH_DMA_FLAG_ER Early receive flag Fatal bus error flag ETH_DMA_FLAG_FBE ETH_DMA_FLAG_ET Early transmit flag ETH_DMA_FLAG_RWT Receive watchdog timeout flag ETH_DMA_FLAG_RPS Receive process stopped flag Receive buffer unavailable flag ETH_DMA_FLAG_RBU Receive flag ETH_DMA_FLAG_R Underflow flag ETH_DMA_FLAG_TU Overflow flag ETH_DMA_FLAG_RO DocID027328 / 1166 196 Rev 2

197 HAL UM1850 ETH Generic Driver ETH_DMA_FLAG_TJT Transmit jabber timeout flag ETH_DMA_FLAG_TBU Transmit buffer unavailable flag ETH_DMA_FLAG_TPS Transmit process stopped flag ETH_DMA_FLAG_T Transmit flag ETH DMA Interrupts stamp trigger interrupt (on DMA) - Time ETH_DMA_IT_TST PMT interrupt (on DMA) ETH_DMA_IT_PMT ETH_DMA_IT_MMC MMC interrupt (on DMA) ETH_DMA_IT_NIS Normal interrupt summary ETH_DMA_IT_AIS Abnormal interrupt summary ETH_DMA_IT_ER Early receive interrupt ETH_DMA_IT_FBE Fatal bus error interrupt ETH_DMA_IT_ET Early transmit interrupt ETH_DMA_IT_RWT Receive watchdog timeout interrupt Receive process stopped interrupt ETH_DMA_IT_RPS Receive buffer unavailable interrupt ETH_DMA_IT_RBU Receive interrupt ETH_DMA_IT_R ETH_DMA_IT_TU Underflow interrupt ETH_DMA_IT_RO Overflow interrupt _TJT Transmit jabber timeout interrupt ETH_DMA_IT ETH_DMA_IT_TBU Transmit buffer unavailable interrupt ETH_DMA_IT_TPS Transmit process stopped interrupt Transmit interrupt ETH_DMA_IT_T ETH DMA overflow ETH_DMA_OVERFLOW_RXFIFOCOUNTER Overflow bit for FIFO overflow counter Overflow bit for missed frame ETH_DMA_OVERFLOW_MISSEDFRAMECOUNTER counter ETH DMA receive process state ETH_DMA_RECEIVEPROCESS_STOPPED Stopped - Reset or Stop Rx Command issued fetching the Rx descriptor ETH_DMA_RECEIVEPROCESS_FETCHING Running - waiting for packet ETH_DMA_RECEIVEPROCESS_WAITING Running - Rx Descriptor unavailable ETH_DMA_RECEIVEPROCESS_SUSPENDED Suspended - closing descriptor - Running ETH_DMA_RECEIVEPROCESS_CLOSING queuing the receive frame - Running ETH_DMA_RECEIVEPROCESS_QUEUING into host memory ETH DMA RX Descriptor 2 DocID027328 Rev 1166 197 /

198 HAL UM1850 ETH Gene ric Driver OWN bit: descriptor is owned by DMA engine ETH_DMARXDESC_OWN DA Filter Fail for the rx frame ETH_DMARXDESC_AFM Receive descriptor frame length ETH_DMARXDESC_FL Error summary: OR of the following bits: DE || OE || IPC ETH_DMARXDESC_ES || LC || RWT || RE || CE Descriptor error: no more descriptors for receive frame ETH_DMARXDESC_DE ETH_DMARXDESC_SAF SA Filter Fail for the recei ved frame ETH_DMARXDESC_LE Frame size not matching with length field Overflow Error: Frame was damaged due to buffer ETH_DMARXDESC_OE overflow ETH_DMARXDESC_VLAN VLAN Tag: received frame is a VLAN frame ETH_DMARXDESC_FS First descriptor of the frame ETH_DMARXDESC_LS Last descriptor of the frame ETH_DMARXDESC_IPV4HCE IPC Checksum Error: Rx Ipv4 header checksum error Late collision occurred during reception ETH_DMARXDESC_LC herwise 802.3 Ethernet, ot - Frame type ETH_DMARXDESC_FT Receive Watchdog Timeout: watchdog timer expired ETH_DMARXDESC_RWT during reception Receive error: error reported by MII interface ETH_DMARXDESC_RE Dribble bit error: frame contains non int multiple of 8 bits ETH_DMARXDESC_DBE CRC error ETH_DMARXDESC_CE Rx MAC Address/Payload Checksum Error: Rx MAC ETH_DMARXDESC_MAMPCE address matched/ Rx Payload Checksum Error ETH_DMARXDESC_DIC Disable Interrupt on Completion ETH_DMARXDESC_RBS2 Receive Buffer2 Size ETH_DMARXDESC_RER Receive End of Ring Second Address Chained ETH_DMARXDESC_RCH Receive Buffer1 Size ETH_DMARXDESC_RBS1 ETH_DMARXDESC_B1AP Buffer1 Address Pointer ETH_DMARXDESC_B2AP Buffer2 Address Pointer ETH DMA Rx descriptor buffers ETH_DMARXDESC_BUFFER1 DMA Rx Desc Buffer1 ETH_DMARXDESC_BUFFER2 DMA Rx Desc Buffer2 ETH DMA transmit process state ETH_DMA_TRANSMITPROCESS_STOPPED Stopped - Reset or Stop Tx Command issued - fetching the Tx descriptor ETH_DMA_TRANSMITPROCESS_FETCHING Running - Running ETH_DMA_TRANSMITPROCESS_WAITING waiting for status DocID027328 / 1166 198 Rev 2

199 UM1850 HAL ETH Generic Driver - Running ETH_DMA_TRANSMITPROCESS_READING reading the data from host memory ETH_DMA_TRANSMITPROCESS_SUSPENDED - Tx Descriptor Suspended unavailable ETH_DMA_TRANSMITPROCESS_CLOSING Running - closing Rx descriptor ETH DMA TX Descriptor ETH_DMATXDESC_OWN OWN bit: descriptor is owned by DMA engine ETH_DMATXDESC_IC Interrupt on Completion ETH_DMATXDESC_LS Last Segment ETH_DMATXDESC_FS First Segment Disable CRC ETH_DMATXDESC_DC Disable Padding ETH_DMATXDESC_DP Transmit Time Stamp Enable ETH_DMATXDESC_TTSE Checksum Insertion Control: 4 ETH_DMATXDESC_CIC cases ETH_DMATXDESC_CIC_BYPASS Do Nothing: Checksum Engine is bypassed ETH_DMATXDESC_CIC_IPV4HEADER IPV4 header Checksum Insertion ETH_DMATXDESC_CIC_TCPUDPICMP_SEGMENT TCP/UDP/ICMP Checksum Insertion calculated over segment only ETH_DMATXDESC_CIC_TCPUDPICMP_FULL TCP/UDP/ICMP Checksum Insertion fully calculated Transmit End of Ring ETH_DMATXDESC_TER Second Address Chained ETH_DMATXDESC_TCH Tx Time Stamp Status ETH_DMATXDESC_TTSS ETH_DMATXDESC_IHE IP Header Error Error summary: OR of the ETH_DMATXDESC_ES following bits: UE || ED || EC || LCO || NC || LCA || FF || JT ETH_DMATXDESC_JT Jabber Timeout Frame Flushed: DMA/MTL flushed ETH_DMATXDESC_FF the frame due to SW flush Payload Checksum Error ETH_DMATXDESC_PCE ETH_DMATXDESC_LCA Loss of Carrier: carrier lost during transmission ETH_DMATXDESC_NC m No Carrier: no carrier signal fro the transceiver Late Collision: transmission ETH_DMATXDESC_LCO aborted due to collision 2 DocID027328 Rev 1166 199 /

200 HAL UM1850 ETH Generic Driver ETH_DMATXDESC_EC Excessive Collision: transmission aborted after 16 collisions ETH_DMATXDESC_VF VLAN Frame Collision Count ETH_DMATXDESC_CC ETH_DMATXDESC_ED Excessive Deferral Underflow Error: late data arrival ETH_DMATXDESC_UF from the memory Deferred Bit ETH_DMATXDESC_DB Transmit Buffer2 Size ETH_DMATXDESC_TBS2 ETH_DMATXDESC_TBS1 Transmit Buffer1 Size ETH_DMATXDESC_B1AP Buffer1 Address Pointer ETH_DMATXDESC_B2AP Buffer2 Address Pointer ETH DMA Tx descriptor Checksum Insertion Control Checksum engine bypass ETH_DMATXDESC_CHECKSUMBYPASS ETH_DMATXDESC_CHECKSUMIPV4HEADER IPv4 header checksum insertion ETH_DMATXDESC_CHECKSUMTCPUDPICMPSEGMENT TCP/UDP/ICMP checksum insertion. Pseudo header checksum is assumed to be present ETH_DMATXDESC_CHECKSUMTCPUDPICMPFULL TCP/UDP/ICMP checksum fully in hardware including pseudo header ETH DMA Tx descriptor segment Last Segment ETH_DMATXDESC_LASTSEGMENTS ETH_DMATXDESC_FIRSTSEGMENT First Segment ETH Drop TCP IP Checksum Error Frame ETH_DROPTCPIPCHECKSUMERRORFRAME_ENABLE ETH_DROPTCPIPCHECKSUMERRORFRAME_DISABLE ETH Duplex Mode ETH_MODE_FULLDUPLEX ETH_MODE_HALFDUPLEX ETH Exported Macros Description: __HAL_ETH_RESET_HANDLE_STATE Reset ETH handle state. Parameters: __HANDLE__: specifies the ETH handle. Return value: DocID027328 / 1166 200 Rev 2

201 UM1850 ETH Generic Driver HAL None Description: __HAL_ETH_DMATXDESC_GET_FLAG Checks whether the specified ETHERNET DMA Tx Desc flag is set or not. Parameters: __HANDLE__: ETH Handle __FLAG__: specifies the flag of TDES0 to check. Return value: the: ETH_DMATxDescFlag (SET or RESET). Description: __HAL_ETH_DMARXDESC_GET_FLAG Checks whether the specified ETHERNET DMA Rx Desc flag is set or not. ers: Paramet __HANDLE__: ETH Handle __FLAG__: specifies the flag of RDES0 to check. Return value: the: ETH_DMATxDescFlag (SET or RESET). Description: __HAL_ETH_DMARXDESC_ENABLE_IT Enables the specified DMA Rx Desc receive interrupt. Parameters: Handle __HANDLE__: ETH Return value: None Description: __HAL_ETH_DMARXDESC_DISABLE_IT Disables the specified DMA Rx Desc receive interrupt. Parameters: __HANDLE__: ETH Handle Return value: None Description: __HAL_ETH_DMARXDESC_SET_OWN_ BIT Own bit. Set the specified DMA Rx Desc Parameters: 2 DocID027328 Rev 1166 201 /

202 ETH Generic Driver HAL UM1850 __HANDLE__: ETH Handle Return value: None Description: __HAL_ETH_DMATXDESC_GET_COLLI SION_COUNT Returns the specified ETHERNET DMA Tx Desc collision count. Parameters: __HANDLE__: ETH Handle Return value: The: Transmit descriptor colli sion counter value. Description: __HAL_ETH_DMATXDESC_SET_OWN_ BIT Set the specified DMA Tx Desc Own bit. Parameters: __HANDLE__: ETH Handle Return value: None Description: __HAL_ETH_DMATXDESC_ENABLE_IT Enables the specified DMA Tx Desc Transmit interrupt. Parameters: __HANDLE__: ETH Handle Return value: None Description: __HAL_ETH_DMATXDESC_DISABLE_IT Disables the specified DMA Tx Desc Transmit interrupt. Parameters: __HANDLE__: ETH Handle Return value: None Description: __HAL_ETH_DMATXDESC_CHECKSUM _INSERTION Selects the specified ETHERNET DMA Tx Desc Checksum Insertion. Parameters: __HANDLE__: ETH Handle __CHECKSUM__: specifies is the DMA Tx desc checksum insertion. This parameter can be one of the following DocID027328 / 1166 202 Rev 2

203 UM1850 ETH Generic Driver HAL values: ETH_DMATXDESC_CHECKSUMB YPASS : Checksum bypass ETH_DMATXDESC_CHECKSUMI PV4HEADER : IPv4 header checksum ETH_DMATXDESC_CHECKSUMT CPUDPICMPSEGMENT : TCP/UDP/ICMP checksum. Pseudo header checksum is assumed to be present ETH_DMATXDESC_CHECKSUMT CPUDPICMPFULL : TCP/UDP/ICMP checksum fully in hardware including pseudo header Return value: None Description: __HAL_ETH_DMATXDESC_CRC_ENABL E Enables the DMA Tx Desc CRC. Parameters: __HANDLE__: ETH Handle Return value: None Description: __HAL_ETH_DMATXDESC_CRC_DISAB LE Disables the DMA Tx Desc CRC. Parameters: __HANDLE__: ETH Handle Return value: None Description: __HAL_ETH_DMATXDESC_SHORT_FRA ME_PADDING_ENABLE Enables the DMA Tx Desc padding for frame shorter than 64 bytes. Parameters: __HANDLE__: ETH Handle Return value: None Description: __HAL_ETH_DMATXDESC_S HORT_FRA ME_PADDING_DISABLE Disables the DMA Tx Desc padding for frame shorter than 64 bytes. Parameters: __HANDLE__: ETH Handle 2 DocID027328 Rev 1166 203 /

204 ETH Generic Driver HAL UM1850 Return value: None Description: __HAL_ETH_MAC_ENABLE_IT Enables the specified ETHERNET MAC interrupts. Parameters: __HANDLE__: : ETH Handle __INTERRUPT__: specifies the ETHERNET MAC interrupt sources to be enabled or disabled. This parameter can be any combination of the following values: ETH_MAC_IT_TST : Time stamp trigger interrupt ETH_MAC_IT_PMT : PMT interrupt Return value: None Description: __HAL_ETH_MAC_DISABLE_IT Disables the specified ETHERNET MAC interrupts. Parameters: __HANDLE__: : ETH Handle __INTERRUPT__: specifies the ETHERNET MAC interrupt sources to be enabled or disabled. This parameter can be any combination of the following values: ETH_MAC_IT_TST : Time stamp trigger interrupt ETH_MAC_IT_PMT : PMT interrupt Return value: None Description: __HAL_ET H_INITIATE_PAUSE_CONTRO L_FRAME Initiate a Pause Control Frame (Full - duplex only). Parameters: __HANDLE__: ETH Handle Return value: None Description: __HAL_ETH_GET_FLOW_CONTROL_BU SY_STATUS Checks whether the ETHERNET flow control busy bit is set or not. DocID027328 / 1166 204 Rev 2

205 UM1850 ETH Generic Driv er HAL Parameters: __HANDLE__: ETH Handle Return value: The: new state of flow control busy status bit (SET or RESET). Description: __HAL_ETH_BACK_PRESSURE_ACTIVA TION_ENABLE Enables the MAC Back Pressure operation activation (Half - duplex only). Param eters: __HANDLE__: ETH Handle Return value: None Description: __HAL_ETH_BACK_PRESSURE_ACTIVA TION_DISABLE Disables the MAC BackPressure duplex only). - operation activation (Half Parameters: __HANDLE__: ETH Handle Return value: None Description: __HAL_ETH_MAC_GET_FLAG Checks whether the specified ETHERNET MAC flag is set or not. Parameters: __HANDLE__: ETH Handle __FLAG__: specifies the flag to check. This parameter can be one of the following values: ETH_MAC_FLAG_TST : Time stamp trigger flag ETH_MAC_FLAG_MMCT : MMC transmit flag ETH_MAC_FLAG_MMCR : MMC receive flag ETH_MAC_FLAG_MMC : MMC flag ETH_MAC_FLAG_PMT : PMT flag Return value: The: state of ETHERNET MAC flag. Description: __HAL_ETH_DMA_ENABLE_IT Enables the specified ETHERNET DMA interrupts. 2 DocID027328 Rev 1166 205 /

206 HAL UM1850 ETH Generic Driver Parameters: __HANDLE__: : ETH Handle __INTERRUPT__: specifies the ETHERNET DMA interrupt sources to be enabled Return value: None Description: __HAL_ETH_DMA_DISABLE_IT Disables the specified ETHERNET DMA interrupts. Parameters: TH Handle __HANDLE__: : E __INTERRUPT__: specifies the ETHERNET DMA interrupt sources to be disabled. Return value: None Description: __HAL_ETH_DMA_CLEAR_IT Clears the ETHERNET DMA IT pending bit. Parameters: __HANDLE__: : ETH Handle interrupt __INTERRUPT__: specifies the pending bit to clear. Return value: None Description: __HAL_ETH_DMA_GET_FLAG Checks whether the specified ETHERNET DMA flag is set or not. Parameters: __HANDLE__: ETH Handle __FLAG__: specifies the flag to check. Return value: The: new state of ETH_DMA_FLAG (SET or RESET). Description: __HAL_ETH_DMA_CLEAR_FLAG Checks whether the specified ETHERNET DMA flag is set or not. Parameters: __HANDLE__: ETH Handle __FLAG__: specifies the flag to clear. DocID027328 / 1166 206 Rev 2

207 HAL UM1850 ETH Generic Driver Return value: The: new state of ETH_DMA_FLAG (SET or RESET). Description: __HAL_ETH_GET_DMA_OVERFLOW_ST ATUS Checks whether the specified ETHERNET DMA overflow flag is set or not. Parameters: __HANDLE__: ETH Handle __OVERFLOW__: specifies the DMA overflow flag to check. This parameter can be one of the foll owing values: ETH_DMA_OVERFLOW_RXFIFO COUNTER : Overflow for FIFO Overflows Counter ETH_DMA_OVERFLOW_MISSED FRAMECOUNTER : Overflow for Buffer Unavailable Missed Frame Counter Return value: The: state of ETHERNET DMA overflow Flag (SET or RESET). Description: __HAL_ETH _SET_RECEIVE_WATCHDO G_TIMER Set the DMA Receive status watchdog timer register value. Parameters: __HANDLE__: ETH Handle __VALUE__: DMA Receive status watchdog timer register value Return value: None Description: __HAL_ETH_GLOBAL_UNICAST_WAKE UP_ENABLE Enables any unicast packet filtered by the MAC address recognition to be a - wake up frame. Parameters: __HANDLE__: ETH Handle. Return value: None Description: __HAL_ETH_GLOBAL_UNICAST_WAKE UP_DISABLE Disables any unicast packet filtered by the MAC address recognition to be a up frame. - wake 2 DocID027328 Rev 1166 207 /

208 HAL UM1850 ETH Generic Driver Parameters: __HANDLE__: ETH Handle. Return value: None Description: __HAL_ETH_WAKEUP_FRAME_DETECT ION_ENABLE - Up Frame Enables the MAC Wake Detection. Parameters: __HANDLE__: ETH Handle. Return value: None Description: __HAL_ETH_WAKEUP_FRAME_DETECT ION_DISABLE Up Frame - Disables the MAC Wake Detection. Parameters: __HANDLE__: ETH Handle. Return value: None Description: __HAL_ETH_MAGIC_PACKET_DETECTI ON_ENABLE Enables the MAC Magic Packet Detection. Parameters: __HANDLE__: ETH Handle. Return value: None Description: __HAL_ETH_MAGIC_PACKET_DETECTI ON_DISABLE Disables the MAC Magic Packet Detection. Parameters: __HANDLE__: ETH Handle. Return value: None Description: __HAL_ETH_POWER_DOWN_ENABLE er Down. Enables the MAC Pow Parameters: __HANDLE__: ETH Handle Return value: DocID027328 / 1166 208 Rev 2

209 UM1850 ETH Generic Driver HAL None Description: __HAL_ETH_POWER_DOWN_DISABLE Disables the MAC Power Down. Parameters: __HANDLE__: ETH Handle Return value: None Description: __HAL_ETH_GET_PMT_FLAG_STATUS Checks whether the specified ETHERNET PMT flag is set or not. Parameters: __HANDLE__: ETH Handle. __FLAG__: specifies the flag to check. This parameter can be one of the following values: ETH_PMT_FLAG_WUFFRPR : Wake Up Frame Filter Register - Pointer Reset Wake ETH_PMT_FLAG_WUFR : - Up Frame Received ETH_PMT_FLAG_MPR : Magic Packet Received Return value: The: new state of ETHERNET PMT Flag (SET or RESET). Description: __HAL_ETH_MMC_COUNTER_FULL_PR ESET Preset and Initialize the MMC counters to almost - (full - full value: 0xFFFF_FFF0 16) Parameters: __HANDLE__: ETH Handle. Return value: None Description: __HAL_ETH_MMC_COUNTER_HALF_PR ESET Preset and Initialize the MMC counters half value: 0x7FFF_FFF0 (half to almost - 16) - Parameters: __HANDLE__: ETH Handle. Return value: None 2 DocID027328 Rev 1166 209 /

210 HAL UM1850 ETH Generic Driver Description: __HAL_ETH_MMC_COUNTER_FREEZE_ ENABLE Enables the MMC Counter Freeze. Parameters: __HANDLE__: ETH Handle. Return value: None Description: __HAL_ETH_MMC_COUNTER_FREEZE_ DISABLE Disables the MMC Counter Freeze. Parameters: __HANDLE__: ETH Handle. Return value: None Description: __HAL_ETH_ETH_MMC_RESET_ONREA D_ENABLE Enables the MMC Reset On Read. Parameters: __HANDLE__: ETH Handle. Return value: None Description: __HAL_ETH_ETH_MMC_RESET_ONREA D_DISABLE Disables the MMC Reset On Read. Parameters: __HANDLE__: ETH Handle. Return value: None Description: __HAL_ETH_ETH_MMC_COUNTER_RO LLOVER_ENABLE Enables the MMC Counter Stop Rollover. Parameters: __HANDLE__: ETH Handle. Return value: None Description: __HAL_ETH_ETH_MMC_COUNTER_RO LLOVER_DISABLE Disables the MMC Counter Stop Rollover. Parameters: __HANDLE__: ETH Handle. DocID027328 / 1166 210 Rev 2

211 HAL UM1850 ETH Generic Driver Return value: None Description: __HAL_ETH_MMC_COUNTERS_RESET Resets the MMC Counters. Parameters: __HANDLE__: ETH Handle. Return value: None Description: __HAL_ETH_MMC_RX_IT_ENABLE Enables the specified ETHERNET MMC Rx interrupts. Parameters: __HANDLE__: ETH Handle. __INTERRUPT__: specifies the ETHERNET MMC interrupt sources to be enabled or disabled. This parameter can be one of the following values: When Rx ETH_MMC_IT_RGUF : good unicast frames counter reaches half the maximum value ETH_MMC_IT_RFAE : When Rx alignment error counter reaches half the maximum value ETH_MMC_IT_RFCE : When Rx crc error counter reaches half the maximum value Return value: None Description: __HAL_ETH_MMC _RX_IT_DISABLE Disables the specified ETHERNET MMC Rx interrupts. Parameters: __HANDLE__: ETH Handle. __INTERRUPT__: specifies the ETHERNET MMC interrupt sources to be enabled or disabled. This parameter can be one of the following values: H_MMC_IT_RGUF : When Rx ET good unicast frames counter reaches half the maximum value ETH_MMC_IT_RFAE : When Rx alignment error counter reaches half the maximum value ETH_MMC_IT_RFCE : When Rx crc error counter reaches half the 2 DocID027328 Rev 1166 211 /

212 HAL UM1850 ETH Generic Driver maximum value Return value: None Description: __HAL_ETH_MMC_TX_IT_ENABLE Enables the specified ETHERNET MMC Tx interrupts. Parameters: __HANDLE__: ETH Handle. __INTERRUPT__: specifies the ETHERNET MMC interrupt sources to be enabled or disabled. This parameter can be one of the foll owing values: ETH_MMC_IT_TGF : When Tx good frame counter reaches half the maximum value ETH_MMC_IT_TGFMSC: When Tx good multi col counter reaches half the maximum value ETH_MMC_IT_TGFSC : When Tx good single col counter reaches half the maximum value urn value: Ret None Description: __HAL_ETH_MMC_TX_IT_DISABLE Disables the specified ETHERNET MMC Tx interrupts. Parameters: __HANDLE__: ETH Handle. __INTERRUPT__: specifies the ETHERNET MMC interrupt sources to be enabled or disabled. This parameter can be one of the following values: ETH_MMC_IT_TGF : When Tx good frame counter reaches half the maximum value ETH_MMC_IT_TGFMSC: When Tx counter reaches half good multi col the maximum value ETH_MMC_IT_TGFSC : When Tx good single col counter reaches half the maximum value Return value: None Description: __HAL_ETH_WAKEUP_EXTI_ENABLE_I T Enables the ETH External interrupt line. DocID027328 / 1166 212 Rev 2

213 HAL UM1850 ETH Generic Driver Return value: None Description: __HAL_ETH _WAKEUP_EXTI_DISABLE_I T Disables the ETH External interrupt line. Return value: None Description: __HAL_ETH_WAKEUP_EXTI_ENABLE_E VENT Enable event on ETH External event line. Return value: None. Description: __HAL_ETH_WAKEUP_EXTI_DISABLE_ EVENT Disable event on ETH External event line. Return value: None. Description: __HAL_ETH_WAKEUP_EXTI_GET_FLAG Get flag of the ETH External interrupt line. Return value: None Description: __HAL_ETH_WAKEUP_EXTI_CLEAR_FL AG External interrupt Clear flag of the ETH line. Return value: None Description: __HAL_ETH_WAKEUP_EXTI_ENABLE_R ISING_EDGE_TRIGGER Enables rising edge trigger to the ETH External interrupt line. Return value: None Description: __HAL_ETH_WAKEUP_EXTI_DISABLE_ RISING_EDGE_TRIGGER sables the rising edge trigger to the Di ETH External interrupt line. Return value: None Description: __HAL_ETH_WAKEUP_EXTI_ENABLE_F ALLING_EDGE_TRIGGER Enables falling edge trigger to the ETH 2 DocID027328 Rev 1166 213 /

214 ETH Generic Driver HAL UM1850 External interrupt line. Return value: None Description: __HAL_ETH_WAKEUP_EXTI_DISABLE_ FALLING_EDGE_TRIGGER Disables falling edge trigger to the ETH External interrupt line. Return value: None Description: __HAL_ETH_WAKEUP_EXTI_ENABLE_F ALLINGRISING_TRIGGER Enables rising/falling edge trigger to the ETH External interrupt line. Return value: None Description: __HAL_ETH_WAKEUP_EXTI_DISABLE_ FALLINGRISING_TRIGGER Disables rising/falling edge trigger to the ETH External interrupt line. Return value: None Description: __HAL_ETH_WAKEUP_EXTI_GENERAT E_SWIT Generate a Software interrupt on selected EXTI line. Return value: None. ETH EXTI LINE WAKEUP External interrupt line 19 Connected to the ETH EXTI Line ETH_EXTI_LINE_WAKEUP ETH Fixed Burst ETH_FIXEDBURST_ENABLE ETH_FIXEDBURST_DISABLE Received Frame ETH Flush ETH_FLUSHRECEIVEDFRAME_ENABLE ETH_FLUSHRECEIVEDFRAME_DISABLE ETH Forward Error Frames ETH_FORWARDERRORFRAMES_ENABLE ETH_FORWARDERRORFRAMES_DISABLE ETH Forward Undersized Good Frames ETH_FORWARDUNDERSIZEDGOODFRAMES_ENABLE ETH_FORWARDUNDERSIZEDGOODFRAMES_DISABLE ETH Inter Frame Gap DocID027328 / 1166 214 Rev 2

215 UM1850 ETH Generic Driver HAL minimum IFG between frames during transmission is ETH_INTERFRAMEGAP_96BIT 96Bit ETH_INTERFRAMEGAP_88BIT minimum IFG between frames during transmission is 88Bit ETH_INTERFRAMEGAP_80BIT minimum IFG between frames during transmission is 80Bit minimum IFG between frames during transmission is ETH_INTERFRAMEGAP_72BIT 72Bit minimum IFG between frames during transmission is ETH_INTERFRAMEGAP_64BIT 64Bit minimum IFG between frames during transmission is ETH_INTERFRAMEGAP_56BIT 56Bit minimum IFG between frames during transmission is ETH_INTERFRAMEGAP_48BIT 48Bit ETH_INTERFRAMEGAP_40BIT minimum IFG between frames during transmission is 40Bit ETH Jabber ETH_JABBER_ENABLE ETH_JABBER_DISABLE ETH Loop Back Mode ETH_LOOPBACKMODE_ENABLE ETH_LOOPBACKMODE_DISABLE ETH MAC addresses ETH_MAC_ADDRESS0 ETH_MAC_ADDRESS1 ETH_MAC_ADDRESS2 ETH_MAC_ADDRESS3 ETH MAC addresses filter Mask bytes ETH_MAC_ADDRESSMASK_BYTE6 Mask MAC Address high reg bits [15:8] ETH_MAC_ADDRESSMASK_BYTE5 Mask MAC Address high reg bits [7:0] Mask MAC Address low reg bits [31:24] ETH_MAC_ADDRESSMASK_BYTE4 ETH_MAC_ADDRESSMASK_BYTE3 Mask MAC Address low reg bits [23:16] ETH_MAC_ADDRESSMASK_BYTE2 Mask MAC Address low reg bits [15:8] Mask MAC Address low reg bits [70] ETH_MAC_ADDRESSMASK_BYTE1 ETH MAC addresses filter SA DA ETH_MAC_ADDRESSFILTER_SA ETH_MAC_ADDRESSFILTER_DA ETH MAC Flags Time stamp trigger flag (on MAC) ETH_MAC_FLAG_TST 2 DocID027328 Rev 1166 215 /

216 HAL UM1850 ETH Generic Driver MMC transmit flag ETH_MAC_FLAG_MMCT ETH_MAC_FLAG_MMCR MMC receive flag MMC flag (on MAC) ETH_MAC_FLAG_MMC ETH_MAC_FLAG_PMT PMT flag (on MAC) ETH MAC Interrupts Time stamp trigger interrupt (on MAC) ETH_MAC_IT_TST MMC transmit interrupt ETH_MAC_IT_MMCT MMC receive interrupt ETH_MAC_IT_MMCR ETH_MAC_IT_MMC MMC interrupt (on MAC) PMT interrupt (on MAC) ETH_MAC_IT_PMT ETH Media Interface ETH_MEDIA_INTERFACE_MII ETH_MEDIA_INTERFACE_RMII Interrupts ETH MMC Rx When Rx good unicast frames counter reaches half the maximum ETH_MMC_IT_RGUF value When Rx alignment error counter reaches half the maximum value ETH_MMC_IT_RFAE ETH_MMC_IT_RFCE When Rx crc error counter reaches half the maximum value MMC Tx Interrupts ETH ETH_MMC_IT_TGF When Tx good frame counter reaches half the maximum value ETH_MMC_IT_TGFMSC When Tx good multi col counter reaches half the maximum value When Tx good single col counter reaches half the maximum ETH_MMC_IT_TGFSC value ETH Multicast Frames Filter ETH_MULTICASTFRAMESFILTER_PERFECTHASHTABLE ETH_MULTICASTFRAMESFILTER_HASHTABLE ETH_MULTICASTFRAMESFILTER_PERFECT ETH_MULTICASTFRAMESFILTER_NONE ETH Pass Control Frames MAC filters all ETH_PASSCONTROLFRAMES_BLOCKALL control frames from reaching the application MAC forwards all ETH_PASSCONTROLFRAMES_FORWARDALL control frames to application even if they fail the Address Filter MAC forwards ETH_PASSCONTROLFRAMES_FORWARDPASSEDADDRFILTER DocID027328 / 1166 216 Rev 2

217 UM1850 ETH Generic Driver HAL that control frames pass the Address Filter. ETH Pause Low Threshold ETH_PAUSELOWTHRESHOLD_MINUS4 Pause time minus 4 slot times ETH_PAUSELOWTHRESHOLD_MINUS28 Pause time minus 28 slot times Pause time minus 144 slot times ETH_PAUSELOWTHRESHOLD_MINUS144 Pause time minus 256 slot times ETH_PAUSELOWTHRESHOLD_MINUS256 ETH PMT Flags - Up Frame Filter Register Pointer Reset ETH_PMT_FLAG_WUFFRPR Wake ETH_PMT_FLAG_WUFR Up Frame Received Wake - Magic Packet Received ETH_PMT_FLAG_MPR ETH Promiscuous Mode ETH_PROMISCUOUS_MODE_ENABLE ETH_PROMISCUOUS_MODE_DISABLE ETH Receive All ETH_RECEIVEALL_ENABLE ETH_RECEIVEAll_DISABLE ETH Receive Flow Control ETH_RECEIVEFLOWCONTROL_ENABLE ETH_RECEIVEFLOWCONTROL_DISABLE ETH Receive Own ETH_RECEIVEOWN_ENABLE ETH_RECEIVEOWN_DISABLE ETH Receive Store Forward ETH_RECEIVESTOREFORWARD_ENABLE ETH_RECEIVESTOREFORWARD_DISABLE ETH Receive Threshold Control ETH_RECEIVEDTHRESHOLDCONTROL_64BYTES threshold level of the MTL Receive FIFO is 64 Bytes ETH_RECEIVEDTHRESHOLDCONTROL_32BYTES threshold level of the MTL Receive FIFO is 32 Bytes threshold level of the MTL ETH_RECEIVEDTHRESHOLDCONTROL_96BYTES Receive FIFO is 96 Bytes threshold level of the MTL ETH_RECEIVEDTHRESHOLDCONTROL_128BYTES IFO is 128 Bytes Receive F ETH Retry Transmission ETH_RETRYTRANSMISSION_ENABLE 2 DocID027328 Rev 1166 217 /

218 ETH Generic Driver HAL UM1850 ETH_RETRYTRANSMISSION_DISABLE ETH Rx DMA Burst Length ETH_RXDMABURSTLENGTH_1BEAT maximum number of beats to be transferred in one RxDMA transaction is 1 ETH_RXDMABURSTLENGTH_2BEAT maximum number of beats to be transferred in one RxDMA transaction is 2 maximum number of beats to be ETH_RXDMABURSTLENGTH_4BEAT transferred in one RxDMA transaction is 4 maximum number of beats to be ETH_RXDMABURSTLENGTH_8BEAT transferred in one RxDMA transaction is 8 maximum number of beats to be ETH_RXDMABURSTLENGTH_16BEAT transferred in one RxDMA transaction is 16 maximum number of beats to be ETH_RXDMABURSTLENGTH_32BEAT DMA transaction transferred in one Rx is 32 maximum number of beats to be ETH_RXDMABURSTLENGTH_4XPBL_4BEAT transferred in one RxDMA transaction is 4 maximum number of beats to be ETH_RXDMABURSTLENGTH_4XPBL_8BEAT transferred in one RxDMA transaction is 8 ETH_RXDMABURSTLENGTH_4XPBL_16BEAT maximum number of beats to be transferred in one RxDMA transaction is 16 maximum number of beats to be ETH_RXDMABURSTLENGTH_4XPBL_32BEAT transferred in one RxDMA transaction is 32 mum number of beats to be maxi ETH_RXDMABURSTLENGTH_4XPBL_64BEAT transferred in one RxDMA transaction is 64 maximum number of beats to be ETH_RXDMABURSTLENGTH_4XPBL_128BEAT transferred in one RxDMA transaction is 128 ETH Rx Mode ETH_RXPOLLING_MODE ETH_RXINTERRUPT_MODE ETH Second Frame Operate ETH_SECONDFRAMEOPERARTE_ENABLE ETH_SECONDFRAMEOPERARTE_DISABLE ETH Source Addr Filter DocID027328 / 1166 218 Rev 2

219 UM1850 ETH Generic Driver HAL ETH_SOURCEADDRFILTER_NORMAL_ENABLE ETH_SOURCEADDRFILTER_INVERSE_ENABLE ETH_SOURCEADDRFILTER_DISABLE ETH Speed ETH_SPEED_10M ETH_SPEED_100M ETH Transmit Flow Control ETH_TRANSMITFLOWCONTROL_ENABLE ETH_TRANSMITFLOWCONTROL_DISABLE ETH Transmit Store Forward ETH_TRANSMITSTOREFORWARD_ENABLE ETH_TRANSMITSTOREFORWARD_DISABLE ETH Transmit Threshold Control threshold level of the MTL ETH_TRANSMITTHRESHOLDCONTROL_64BYTES Transmit FIFO is 64 Bytes ETH_TRANSMITTHRESHOLDCONTROL_128BYTES threshold level of the MTL Transmit FIFO is 128 Bytes threshold level of the MTL ETH_TRANSMITTHRESHOLDCONTROL_192BYTES Transmit FIFO is 192 Bytes ETH_TRANSMITTHRESHOLDCONTROL_256BYTES threshold level of the MTL Transmit FIFO is 256 Bytes threshold level of the MTL ETH_TRANSMITTHRESHOLDCONTROL_40BYTES Transmit FIFO is 40 Bytes ETH_TRANSMITTHRESHOLDCONTROL_32BYTES threshold level of the MTL Transmit FIFO is 32 Bytes threshold level of the MTL ETH_TRANSMITTHRESHOLDCONTROL_24BYTES Transmit FIFO is 24 Bytes threshold level of the MTL ETH_TRANSMITTHRESHOLDCONTROL_16BYTES Transmit FIFO is 16 Bytes ETH Tx DMA Burst Length maximum number of beats to be ETH_TXDMABURSTLENGTH_1BEAT transferred in one TxDMA (or both) transaction is 1 maximum number of beats to be ETH_TXDMABURSTLENGTH_2BEAT transferred in one TxDMA (or both) transaction is 2 maximum number of beats to be ETH_TXDMABURSTLENGTH_4BEAT transferred in one TxDMA (or both) transaction is 4 maximum number of beats to be ETH_TXDMABURSTLENGTH_8BEAT transferred in one TxDMA (or both) transaction is 8 2 DocID027328 Rev 1166 219 /

220 ETH Generic Driver HAL UM1850 maximum number of beats to be ETH_TXDMABURSTLENGTH_16BEAT nsferred in one TxDMA (or both) tra transaction is 16 maximum number of beats to be ETH_TXDMABURSTLENGTH_32BEAT transferred in one TxDMA (or both) transaction is 32 ETH_TXDMABURSTLENGTH_4XPBL_4BEAT maximum number of beats to be both) transferred in one TxDMA (or transaction is 4 maximum number of beats to be ETH_TXDMABURSTLENGTH_4XPBL_8BEAT transferred in one TxDMA (or both) transaction is 8 maximum number of beats to be ETH_TXDMABURSTLENGTH_4XPBL_16BEAT transferred in one TxDMA (or both) transaction is 16 maximum number of beats to be ETH_TXDMABURSTLENGTH_4XPBL_32BEAT transferred in one TxDMA (or both) transaction is 32 maximum number of beats to be ETH_TXDMABURSTLENGTH_4XPBL_64BEAT transferred in one TxDMA (or both) transaction is 64 ETH_TXDMABURSTLENGTH_4XPBL_128BEAT maximum number of beats to be transferred in one TxDMA (or both) transaction is 128 ETH Unicast Frames Filter ETH_UNICASTFRAMESFILTER_PERFECTHASHTABLE ETH_UNICASTFRAMESFILTER_HASHTABLE ETH_UNICASTFRAMESFILTER_PERFECT ETH Unicast Pause Frame Detect ETH_UNICASTPAUSEFRAMEDETECT_ENABLE ETH_UNICASTPAUSEFRAMEDETECT_DISABLE ETH VLAN Tag Comparison ETH_VLANTAGCOMPARISON_12BIT ETH_VLANTAGCOMPARISON_16BIT ETH Watchdog ETH_WATCHDOG_ENABLE ETH_WATCHDOG_DISABLE ETH Zero Quanta Pause ETH_ZEROQUANTAPAUSE_ENABLE ETH_ZEROQUANTAPAUSE_DISABLE DocID027328 / 1166 220 Rev 2

221 HAL UM1850 FLASH Generic Driver 18 HAL FLASH Generic Driver registers structures FLASH Firmware driver 18.1 FLASH_ProcessTypeDef 18.1.1 Data Fields __IO FLASH_ProcedureTypeDef ProcedureOnGoing __IO uint32_t DataRemaining __IO uint32_t Address __IO uint64_t Data AL_LockTypeDef Lock H __IO uint32_t ErrorCode Field Documentation __IO FLASH_ProcedureTypeDef FLASH_ProcessTypeDef::ProcedureOnGoing Internal variable to indicate which procedure is ongoing or not in IT context ing __IO uint32_t FLASH_ProcessTypeDef::DataRemain word to program in IT - Internal variable to save the remaining pages to erase or half context __IO uint32_t FLASH_ProcessTypeDef::Address Internal variable to save address selected for program or erase __IO uint64_t FLASH_ProcessTypeDef::Data Internal variable to save data to be programmed HAL_LockTypeDef FLASH_ProcessTypeDef::Lock FLASH locking object __IO uint32_t FLASH_ProcessTypeDef::ErrorCode FLASH error code This parameter can be a value of FLASH_Error_C odes 18.2 FLASH Firmware driver API description FLASH peripheral features 18.2.1 - - The Flash memory interface manages CPU AHB I Code and D Code accesses to the Flash memory. It implements the erase and program Flash memory operations and the read and write protection mechanisms. The Flash memory interface accelerates code execution with a system of instruction prefetch. The FLASH main features are: Flash memory read operation s Flash memory program/erase operations Read / write protections Prefetch on I Code - Option Bytes programming How to use this driver 18.2.2 memory of This driver provides functions and macros to configure and program the FLASH all STM32F1xx devices. 2 DocID027328 Rev 1166 221 /

222 HAL FLASH Generic Driver UM1850 FLASH Memory I/O Programming functions: this group includes all needed functions 1. to erase and program the main memory: Lock and Unlock the FLASH interface Erase function: Erase page, erase all pages Program functions: half word, word and doubleword FLASH Option Bytes Programming functions: this group includes all needed functions 2. to manage the Option Bytes: Lock and Unlock the Option Bytes Set/Reset the write protection Set the Read protection Level Option Bytes Program the user Launch the Option Bytes loader Erase Option Bytes Program the data Option Bytes Get the Write protection. Get the user option bytes. Interrupts and flags management functions : this group includes all needed functions 3. to: upts Handle FLASH interr Wait for last FLASH operation according to its status Get error flag status In addition to these function, this driver includes a set of macros allowing to handle the following operations: Set/Get the latency Enable/Disable the prefetch buffer e/Disable the half cycle access Enabl Enable/Disable the FLASH interrupts Monitor the FLASH flags status Peripheral Control functions 18.2.3 This subsection provides a set of functions allowing to control the FLAS H memory operations. This section contains the following APIs: HAL_FLASH_Unlock() HAL_FLASH_Lock() HAL_FLASH_OB_Unlock() HA L_FLASH_OB_Lock() HAL_FLASH_OB_Launch() 18.2.4 Peripheral Errors functions time errors of the FLASH peripheral. - This subsection permit to get in run following APIs: This section contains the HAL_FLASH_GetError() Detailed description of functions 18.2.5 HAL_FLASH_Program HAL_StatusTypeDef HAL_FLASH_Program (uint32_t Function name 1166 DocID027328 / Rev 2 222

223 UM1850 FLASH Generic Driver HAL uint64_t Data) TypeProgram, uint32_t Address, Program halfword, word or double word at a specified address. Function description Parameters Indicate the way to program at a specified TypeProgram: address. This parameter can be a value of FLASH Type Program dress to be programmed. Address: Specifies the ad Data: Specifies the data to be programmed Return values HAL Status HAL_StatusTypeDef: Notes The function HAL_FLASH_Unlock() should be called before to unlock the FLASH interface The function after to lock the FLASH HAL_FLASH_Lock() should be called interface If an erase and a program operations are requested simultaneously, the erase operation is performed before the program one. FLASH should be previously erased before new is programmation (only exception to this is when 0x0000 programmed) HAL_FLASH_Program_IT HAL_StatusTypeDef HAL_FLASH_Program_IT (uint32_t Function name TypeProgram, uint32_t Address, uint64_t Data) Function description Program halfword, word or double word at a specified address with interrupt enabled. P arameters TypeProgram: Indicate the way to program at a specified address. This parameter can be a value of FLASH Type Program Specifies the address to be programmed. Address: Data: Specifies the data to be programmed Return values HAL Status HAL_StatusTypeDef: Notes The function HAL_FLASH_Unlock() should be called before to unlock the FLASH interface The function HAL_FLASH_Lock() should be called after to lock the FLASH interface If an erase and a program operations are requested erase operation is performed before the simultaneously, the program one. HAL_FLASH_IRQHandler void HAL_FLASH_IRQHandler (void ) Function name This function handles FLASH interrupt request. Function description Return values None: HAL_FLASH_EndOfOperationCallback void HAL_FLASH_EndOfOperationCallback (uint32_t Functi on name 223 Rev 2 / 1166 DocID027328

224 HAL FLASH Generic Driver UM1850 ReturnValue) FLASH end of operation interrupt callback. Function description Parameters The value saved in this parameter depends on ReturnValue: the ongoing procedure Mass Erase: No return value expected Pages Erase: Address of the page which has been erased (if 0xFFFFFFFF, it means that all the selected pages have been erased) Program: Address which was selected for data program Return values none: HAL_FLASH_OperationErrorCallback void HAL_FLASH_OperationErrorCallback (uint32_t e Function nam ReturnValue) FLASH operation error interrupt callback. Function description Parameters The value saved in this parameter depends on ReturnValue: the ongoing procedure expected Mass Erase: No return value Pages Erase: Address of the page which returned an error Program: Address which was selected for data program Return values none: HAL_FLASH_Unlock HAL_StatusTypeDef HAL_FLASH_Unlock (void ) Function name Function description Unlock the FLASH c ontrol register access. Return values HAL: Status HAL_FLASH_Lock HAL_StatusTypeDef HAL_FLASH_Lock (void ) Function name Function description Locks the FLASH control register access. Return values Status HAL: HAL_FLASH_OB_Unlock HAL_StatusTypeDef HAL_FLASH_OB_Unlock (void ) Function name Unlock the FLASH Option Control Registers access. Function description Return values HAL: Status HAL_FLASH_OB_Lock HAL_StatusTypeDef HAL_FLASH_OB_Lock (void ) Function name Function description Lock the FLASH Option Control Registers access. DocID027328 / 1166 224 Rev 2

225 UM1850 FLASH Generic Driver HAL Return values HAL: Status HAL_FLASH_OB_Launch HAL_StatusTypeDef HAL_FLASH_OB_Launch (void ) Function name Function description Launch the option byte loading. Return values HAL: Status Notes function will reset automatically the MCU. This HAL_FLASH_GetError uint32_t HAL_FLASH_GetError (void ) Function name Function description Get the specific FLASH error flag. Return values FLASH_ErrorCode: The returned value can be: FLASH Error Codes WaitForLastOperation FLASH_ HAL_StatusTypeDef FLASH_WaitForLastOperation (uint32_t Function name Timeout) Wait for a FLASH operation to complete. Function description Parameters Timeout: maximum flash operation timeout Return values Status HAL: FLASH_WaitForLastOperationBank2 HAL_StatusTypeDef FLASH_WaitForLastOperationBank2 Function name (uint32_t Timeout) Wait for a FLASH BANK2 operation to complete. Function description Parameters maximum flash operation timeout Timeout: Return values HAL_StatusTypeDef: HAL Status 18.3 FLASH Firmware driver defines FLASH 18.3.1 FLASH Error Codes No error HAL_FLASH_ERROR_NONE HAL_FLASH_ERROR_PROG Programming error Write protection error HAL_FLASH_ERROR_WRP HAL_FLASH_ERROR_OPTV Option validity error Flag definition FLASH Bank1 Busy flag FLASH_FLAG_BSY FLASH_FLAG_PGERR FLASH Bank1 Programming error flag 2 DocID027328 Rev 1166 225 /

226 HAL UM1850 FLASH Generic Driv er FLASH Bank1 Write protected error flag FLASH_FLAG_WRPERR FLASH_FLAG_EOP FLASH Bank1 End of Operation flag FLASH Bank1 Busy flag FLASH_FLAG_BSY_BANK1 FLASH_FLAG_PGERR_BANK1 FLASH Bank1 Programming error flag FLASH Bank1 Write protected error flag FLASH_FLAG_WRPERR_BANK1 FLASH_FLAG_EOP_BANK1 FLASH Bank1 End of Operation flag FLASH_FLAG_BSY_BANK2 FLASH Bank2 Busy flag FLASH_FLAG_PGERR_BANK2 FLASH Bank2 Programming error flag FLASH Bank2 Write protected error flag FLASH_FLAG_WRPERR_BANK2 FLASH_FLAG_EOP_BANK2 FLASH Bank2 End of Operation flag FLASH_FLAG_OPTVERR Option Byte Error FLASH Half Cycle Description: __HAL_FLASH_HALF_CYCLE_ACCESS_ENABLE Enable the FLASH half cycle access. Return value: None Notes: half cycle access can only be - used with a low freque ncy clock of less than 8 MHz that can be obtained with the use of HSI or HSE but not of PLL. Description: __HAL_FLASH_HALF_CYCLE_ACCESS_DISABLE Disable the FLASH half cycle access. Return value: None Notes: half cycle access can only be - low used with a frequency clock of less than 8 MHz that can be obtained with the use of HSI or HSE but not of PLL. Interrupt Description: __HAL_FLASH_ENABLE_IT Enable the specified FLASH interrupt. Parameters: __INTERRUPT__: FLASH interrupt This parameter combination of the following values: can be any DocID027328 / 1166 226 Rev 2

227 UM1850 FLASH Generic Driver HAL FLASH_IT_EOP_BANK1 End of FLASH Operation Interrupt on bank1 FLASH_IT_ERR_BANK1 Error Interrupt on bank1 FLASH_IT_EOP_BANK2 End of FLASH Operation Interrupt on bank2 FLASH_IT_ERR_BANK2 Error Interrupt on bank2 Return v alue: none Description: __HAL_FLASH_DISABLE_IT Disable the specified FLASH interrupt. Parameters: __INTERRUPT__: FLASH interrupt This parameter can be any combination of the following values: FLASH_IT_EOP_BANK1 End of FLASH Operation Interrupt on bank1 FLASH_IT_ERR_BANK1 Error Interrupt on bank1 FLASH_IT_EOP_BANK2 End of FLASH Operation Interrupt on bank2 FLASH_IT_ERR_BANK2 Error Interrupt on bank2 Return value: none Description: __HAL_FLASH_GET_FLAG Get the specified FLASH flag status. Parameters: __FLAG__: specifies the FLASH flag to check. This parameter can be one of the following values: FLASH_FLAG_EOP_BANK1 FLASH End of Operation flag on bank1 FLASH_FLAG_WRPERR_BANK1 FLASH Write protected error flag on bank1 FLASH_FLAG_PGERR_BANK1 FLASH Progra mming error flag on bank1 FLASH_FLAG_BSY_BANK1 FLASH Busy flag on bank1 FLASH_FLAG_EOP_BANK2 FLASH End of Operation flag on bank2 FLASH_FLAG_WRPERR_BANK2 FLASH Write protected error flag on bank2 FLASH_FLAG_PGERR_BANK2 FLASH Programming error flag on bank2 FLASH_FLAG_BSY_BANK2 FLASH Busy flag on bank2 FLASH_FLAG_OPTVERR Loaded OB and its 2 DocID027328 Rev 1166 227 /

228 FLASH Generic Driver HAL UM1850 complement do not match Return value: The: new state of __FLAG__ (SET or RESET). Description: __HAL_FLASH_CLEAR_FLAG Clear the specified FLASH flag. Parameters: __FLAG__: specifies the FLASH flags to clear. This parameter can be any combination of the following values: FLASH_FLAG_EOP_BANK1 FLASH End of Operation flag on bank1 FLASH_FLAG_WRPERR_BANK1 FLASH Write protected error flag on bank1 FLASH_FLAG_PGERR_BANK1 FLASH Programming error flag on bank1 FLASH_FLAG_BSY_BANK1 FLASH Busy flag on bank1 FLASH_FLAG_EOP_BANK2 FLASH End of Operation flag on bank2 FLASH_FLAG_WRPERR_BANK2 FLASH Write protected error flag on bank2 FLASH_FLAG_PGERR_BANK2 FLASH Programming error flag on bank2 FLASH_FLAG_BSY_BANK2 FLASH Busy flag on bank2 FLASH_FLAG_OPTVERR Loaded OB and its complement do not match Return value: none Interrupt definition FLASH_IT_EOP End of FLASH Operation Interrupt source Bank1 FLASH_IT_ERR Error Interrupt source Bank1 End of FLASH Operation Interrupt source Bank1 FLASH_IT_EOP_BANK1 FLASH_IT_ERR_BANK1 Error Interrupt source Bank1 FLASH_IT_EOP_BANK2 End of FLASH Operation Interrupt source Bank2 Bank2 Error Interrupt source FLASH_IT_ERR_BANK2 FLASH Latency FLASH Zero Latency cycle FLASH_LATENCY_0 FLASH_LATENCY_1 FLASH One Latency cycle FLASH Two Latency cycles FLASH_LATENCY_2 FLASH Prefetch Description: __HAL_FLASH_PREFETCH_BUFFER_ENABLE Enable the FLASH prefetch DocID027328 / 1166 228 Rev 2

229 UM1850 FLASH Generic Driver HAL buffer. value: Return None Description: __HAL_FLASH_PREFETCH_BUFFER_DISABLE Disable the FLASH prefetch buffer. Return value: None FLASH Type Program FLASH_TYPEPROGRAM_HALFWORD Program a half bit) at a specified - word (16 - address. Program a word (32 - bit) at a specified FLASH_TYPEPROGRAM_WORD address. FLASH_TYPEPROGRAM_DOUBLEWORD bit) at a - Program a double word (64 specified address 2 DocID027328 Rev 1166 229 /

230 FLASH Extension Driver HAL UM1850 HAL FLASH Extension Driver 19 FLASHEx Firmware driver registers structures 19.1 19.1.1 FLASH_EraseInitTypeDef Data Fields uint32_t TypeErase uint32_t Banks uint32_t PageAddress uint32_t NbPages Field Documentation uint32_t FLASH_EraseInitTypeDef::TypeE rase TypeErase: Mass erase or page erase. This parameter can be a value of FLASHEx_Type_Erase uint32_t FLASH_EraseInitTypeDef::Banks Select banks to erase when Mass erase is enabled. This parameter must be a value FLASHEx_Banks of uint32_t FLASH_EraseInitTypeDef::PageAddress PageAdress: Initial FLASH page address to erase when mass erase is disabled This parameter must be a number between Min_Data = 0x08000000 and Max_Data = FLASH_BANKx_END ( x = 1 or 2 depending on devices) uint32_t FLASH_EraseInitTypeDef::NbPages NbPages: Number of pagess to be erased. This parameter must be a value between Min_Data = 1 and Max_Data = (max number of pages - value of initial page) 19.1.2 FLASH_OBProgramInitTypeDef Data Fields uint32_t OptionType uint32_t WRPState uint32_t WRPPage uint32_t Banks uint8_t RDPLevel uint8_t USERConfig uint32_t DATAAddress uint8_t DATAData Field Documentation uint32_t FLASH_OBProgramInitTypeDef::OptionType OptionType: Option byte to be configured. This parameter can be a value of FLASHEx_OB_Type uint32_t FLASH_OBProgramInitTypeDef::WRPState WRPState: Write protection activation or deactivation. This parameter can be a value of FLASHEx_OB_WRP_State uint32_t FLASH_OBProgramInitTypeDef::WRPPage WRPPage: specifies the page(s) to be write protected This parameter c an be a value of FLASHEx_OB_Write_Protection DocID027328 / 1166 230 Rev 2

231 HAL UM1850 FLASH Extension Driver uint32_t FLASH_OBProgramInitTypeDef::Banks Select banks for WRP activation/deactivation of all sectors. This parameter must be a value of _Banks FLASHEx uint8_t FLASH_OBProgramInitTypeDef::RDPLevel RDPLevel: Set the read protection level.. This parameter can be a value of FLASHEx_OB_Read_Protection uint8_t FLASH_OBProgramInitTypeDef::USERConfig USERConfig: Program th e FLASH User Option Byte: IWDG / STOP / STDBY / BOOT1 This parameter can be a combination of FLASHEx_OB_IWatchdog , FLASHEx_OB_nRST_STOP , , Y FLASHEx_OB_nRST_STDB FLASHEx_OB_BOOT1 uint32_t FLASH_OBProgramInitTypeDef::DATAAddress DATAAddress: Address of the option byte DATA to be programmed This parameter can be a value of FLASHEx_OB_Data_Address nt8_t FLASH_OBProgramInitTypeDef::DATAData ui DATAData: Data to be stored in the option byte DATA This parameter must be a number between Min_Data = 0x00 and Max_Data = 0xFF FLASHEx Firmware driver API description 19.2 19.2.1 FLASH Erasing Programming functions The FLASH Memory Erasing functions, includes the following functions: @ref HAL_FLASHEx_Erase: return only when erase has been done @ref HAL_FLASHEx_Erase_IT : end of erase is done when @ref HAL_FLASH_EndOfOperationCallback is called with parameter 0xFFFFFFFF Any operation of erase should follow these steps: 1. Call the @ref HAL_FLASH_Unlock() function to enable the flash control register and ss. program memory acce Call the desired function to erase page. 2. Call the @ref HAL_FLASH_Lock() to disable the flash program memory access 3. (recommended to protect the FLASH memory against possible unwanted operation). This section contains the following APIs: HAL_FLASHEx_Erase() HAL_FLASHEx_Erase_IT() 19.2.2 Option Bytes Programming functions This subsection provides a set of functions allowing to control the FLASH option bytes operations. This section contains the following APIs: HAL_FLASHEx_OBErase() HAL_FLASHEx_OBProgram() HAL_FLASHEx_OBGetConfig() HAL_FLASHEx_OBGetUserData() Detailed description of functions 19.2.3 HAL_FLASHEx_Erase HEx_Erase HAL_StatusTypeDef HAL_FLAS Function name Rev 2 1166 231 / DocID027328

232 HAL UM1850 FLASH Extension Driver (FLASH_EraseInitTypeDef * pEraseInit, uint32_t * PageError) Function description Perform a mass erase or erase the specified FLASH memory pages. Parameters pEraseInit: pointer to an FLASH_EraseInitTypeDef structure tion information for the erasing. that contains the configura pointer to variable that contains the configuration PageError: information on faulty page in case of error (0xFFFFFFFF means that all the pages have been correctly erased) Return values HAL Status HAL_StatusTypeDef: Notes To correctly run this function, the HAL_FLASH_Unlock() function must be called before. Call the HAL_FLASH_Lock() to disable the flash memory access (recommended to protect the FLASH memory against possible unwanted operation) HAL_FLASHEx_Erase_IT HAL_StatusTypeDef HAL_FLASHEx_Erase_IT Fu nction name (FLASH_EraseInitTypeDef * pEraseInit) Perform a mass erase or erase the specified FLASH memory Function description pages with interrupt enabled. Parameters pEraseInit: eDef structure pointer to an FLASH_EraseInitTyp that contains the configuration information for the erasing. Return values HAL_StatusTypeDef: HAL Status Notes To correctly run this function, the HAL_FLASH_Unlock() function must be called before. Call the HAL_FLASH_Lock() to disable the flash memory access (recommended to protect the FLASH memory against possible unwanted operation) HAL_FLASHEx_OBErase HAL_StatusTypeDef HAL_FLASHEx_OBErase (void ) Function name Erases the FLASH option bytes. Function description Return values HAL: status Notes This functions erases all option bytes except the Read protection (RDP). The function HAL_FLASH_Unlock() should be called before to unlock the FLASH interface The function HAL_FLASH_OB_Unlock() should be called before to unlock ytes The function HAL_FLASH_OB_Launch() the options b should be called after to force the reload of the options bytes (system reset will occur) HAL_FLASHEx_OBProgram HAL_StatusTypeDef HAL_FLASHEx_OBProgram Function name (FLASH_OBProgramInitTypeDef * pOBInit) Function Program option bytes. description Parameters pOBInit: pointer to an FLASH_OBInitStruct structure that DocID027328 / 1166 232 Rev 2

233 HAL UM1850 FLASH Extension Driver contains the configuration information for the programming. Return values HAL_StatusTypeDef: HAL Status Notes be called before The function HAL_FLASH_Unlock() should to unlock the FLASH interface The function HAL_FLASH_OB_Unlock() should be called before to unlock the options bytes The function HAL_FLASH_OB_Launch() should be called after to force the reload of the options bytes (system reset will occ ur) HAL_FLASHEx_OBGetConfig void HAL_FLASHEx_OBGetConfig Function name (FLASH_OBProgramInitTypeDef * pOBInit) Get the Option byte configuration. Function description Parameters pointer to an FLASH_OBInitStruct structure that pOBInit: iguration information for the programming. contains the conf Return values None: HAL_FLASHEx_OBGetUserData uint32_t HAL_FLASHEx_OBGetUserData (uint32_t Function name DATAAdress) Function description Get the Option byte user data. Parameters Address of the option byte DATA This DATAAdress: parameter can be one of the following values: OB_DATA_ADDRESS_DATA0 OB_DATA_ADDRESS_DATA1 Return values programmed in USER data Value: FLASHEx Firmware driver defines 19.3 19.3.1 FLASHEx Banks Bank 1 FLASH_BANK_1 Bank 2 FLASH_BANK_2 Bank1 and Bank2 FLASH_BANK_BOTH Option Byte BOOT1 BOOT1 Reset OB_BOOT1_RESET BOOT1 Set OB_BOOT1_SET Option Byte Data Address OB_DATA_ADDRESS_DATA0 OB_DATA_ADDRESS_DATA1 Option Byte IWatchdog 2 DocID027328 Rev 1166 233 /

234 HAL UM1850 FLASH Extension Driver Software IWDG selected OB_IWDG_SW OB_IWDG_HW Hardware IWDG selected Option Byte nRST STDBY No reset generated when entering in STANDBY OB_STDBY_NO_RST OB_STDBY_RST Reset generated when entering in STANDBY Option Byte nRST STOP OB_STOP_NO_RST No reset generated when entering in STOP OB_STOP_RST Reset generated when entering in STOP Option Byte Read Protection OB_RDP_LEVEL_0 OB_RDP_LEVEL_1 Option Bytes Type WRP option byte configuration OPTIONBYTE_WRP OPTIONBYTE_RDP RDP option byte configuration OPTIONBYTE_USER USER option byte configuration OPTIONBYTE_DATA DATA option byte configuration Option Bytes Write Protection Write protection of page 0 TO 1 OB_WRP_PAGES0TO1 OB_WRP_PAGES2TO3 Write protection of page 2 TO 3 OB_WRP_PAGES4TO5 Write protection of page 4 TO 5 OB_WRP_PAGES6TO7 Write protection of page 6 TO 7 OB_WRP_PAGES8TO9 Write protection of page 8 TO 9 OB_WRP_PAGES10TO11 Write protection of page 10 TO 11 OB_WRP_PAGES12TO13 Write protection of page 12 TO 13 Write protection of page 14 TO 15 OB_WRP_PAGES14TO15 OB_WRP_PAGES16TO17 Write protection of page 16 TO 17 OB_WRP_PAGES18TO19 Write protection of page 18 TO 19 OB_WRP_PAGES20TO21 Write protection of page 20 TO 21 OB_WRP_PAGES22TO23 Write protection of page 22 TO 23 OB_WRP_PAGES24TO25 Write protection of page 24 TO 25 OB_WRP_PAGES26TO27 Write protection of page 26 TO 27 OB_WRP_PAGES28TO29 Write protection of page 28 TO 29 Write protection of page 30 TO 31 OB_WRP_PAGES30TO31 Write protection of page 32 TO 33 OB_WRP_PAGES32TO33 Write protection of page 34 TO 35 OB_WRP_PAGES34TO35 OB_WRP_PAGES36TO37 Write protection of page 36 TO 37 DocID027328 / 1166 234 Rev 2

235 HAL UM1850 FLASH Extension Driver OB_WRP_PAGES38TO39 Write protection of page 38 TO 39 Write protection of page 40 TO 41 OB_WRP_PAGES40TO41 Write protection of page 42 TO 43 OB_WRP_PAGES42TO43 OB_WRP_PAGES44TO45 Write protection of page 44 TO 45 Write protection of page 46 TO 47 OB_WRP_PAGES46TO47 Write protection of page 48 TO 49 OB_WRP_PAGES48TO49 Write protection of page 50 TO 51 OB_WRP_PAGES50TO51 Write protection of page 52 TO 53 OB_WRP_PAGES52TO53 Write protection of page 54 TO 55 OB_WRP_PAGES54TO55 Write protection of page 56 TO 57 OB_WRP_PAGES56TO57 Write protection of page 58 TO 59 OB_WRP_PAGES58TO59 Write protection of page 60 TO 61 OB_WRP_PAGES60TO61 OB_WRP_PAGES62TO127 Write protection of page 62 TO 127 OB_WRP_PAGES62TO255 Write protecti on of page 62 TO 255 OB_WRP_PAGES62TO511 Write protection of page 62 TO 511 Write protection of all Pages OB_WRP_ALLPAGES OB_WRP_PAGES0TO15MASK OB_WRP_PAGES16TO31MASK OB_WRP_PAGES32TO47MASK OB_WRP_PAGES48TO511MASK Option Byte WRP State OB_WRPSTATE_DISABLE Disable the write protection of the desired pages Enable the write protection of the desired pagess OB_WRPSTATE_ENABLE Page Size FLASH_PAGE_SIZE Type Erase Pages erase only FLASH_TYPEERASE_PAGES Flash mass erase activation FLASH_TYPEERASE_MASSERASE 2 DocID027328 Rev 1166 235 /

236 GPI HAL UM1850 O Generic Driver 20 HAL GPIO Generic Driver GPIO Firmware driver registers structures 20.1 20.1.1 GPIO_InitTypeDef Data Fields uint32_t Pin uint32_t Mode uint32_t Pull uint32_t Speed Field Documentation uint32_t GPIO_InitTypeDef::Pin Specifies the GPIO pins to be configured. This parameter can be any value of GPIO_pins_define uint32_t GPIO_InitTypeDef::Mode Specifies the operating mode for the selected pins. This parameter can be a value of GPIO_mode_define uint32_t GPIO_InitTypeDef::Pull Specifies the Pull Down activation for the selected pins. This parameter can - up or Pull - be a value of GPIO_pull_define uint32_t GPIO_InitTypeDef::Speed Specifies the speed for the selected pins. This parameter can be a value of GPIO_speed_define GPIO Firmware driver API descrip 20.2 tion GPIO Peripheral features 20.2.1 Subject to the specific hardware characteristics of each I/O port listed in the datasheet, each port bit of the General Purpose IO (GPIO ) Ports, can be individually configured by software in several modes: Input mode Analog mode Output mode Alternate function mode External interrupt/event lines During and just after reset, the alternate functions and external interrupt lines are not ac tive and the I/O ports are configured in input floating mode. - up and pull down resistors, which can be activated All GPIO pins have weak internal pull - or not. - In Output or Alternate mode, each IO can be configured on open pull type - drain or push and th e IO speed can be selected depending on the VDD value. All ports have external interrupt/event capability. To use external interrupt lines, the port must be configured in input mode. All available GPIO pins are connected to the 16 external t lines from EXTI0 to EXTI15. interrupt/even DocID027328 / 1166 236 Rev 2

237 UM1850 GPIO Generic Driver HAL The external interrupt/event controller consists of up to 20 edge detectors in connectivity line devices, or 19 edge detectors in other devices for generating event/interrupt requests. Each input line can be independently co nfigured to select the type (event or interrupt) and the corresponding trigger event (rising or falling or both). Each line can also masked independently. A pending register maintains the status line of the interrupt requests 20.2.2 How to use this driver Enable the GPIO APB2 clock using the following function : 1. __HAL_RCC_GPIOx_CLK_ENABLE(). Configure the GPIO pin(s) using HAL_GPIO_Init(). 2. Configure the IO mode using "Mode" member from GPIO_InitTypeDef structur e down resistor using "Pull" member from GPIO_InitTypeDef - Activate Pull - up, Pull structure. In case of Output or alternate function mode selection: the speed is configured through "Speed" member from GPIO_InitTypeDef structure Analog mode is required when a pin is to be used as ADC channel or DAC output. In case of external interrupt/event selection the "Mode" member from GPIO_InitTypeDef structure select the type (interrupt or event) and the corresponding trigger event (rising or falling or both). of external interrupt/event mode selection, configure NVIC IRQ priority In case 3. mapped to the EXTI line using HAL_NVIC_SetPriority() and enable it using HAL_NVIC_EnableIRQ(). 4. To get the level of a pin configured in input mode use HAL_GPIO_ReadPin(). 5. To set/rese t the level of a pin configured in output mode use HAL_GPIO_WritePin()/HAL_GPIO_TogglePin(). 6. To lock pin configuration until next reset use HAL_GPIO_LockPin(). 7. During and just after reset, the alternate functions are not active and the GPIO pins igured in input floating mode (except JTAG pins). are conf The LSE oscillator pins OSC32_IN and OSC32_OUT can be used as general purpose 8. (PC14 and PC15, respectively) when the LSE oscillator is off. The LSE has priority over the GPIO function. The HSE oscillator pins OSC_IN/OSC_OUT can be used as general purpose PD0 and 9. PD1, respectively, when the HSE oscillator is off. The HSE has priority over the GPIO function. Initialization and de 20.2.3 - initialization functions This section provides functions allowing to initialize and de - initialize the GPIOs to be ready for use. This section contains the following APIs: HAL_GPIO_Init() HAL_GPIO_DeInit() IO operation functions 20.2.4 This subsection provides a set of functions allowing to manage the GPIOs. This section contains the following APIs: O_ReadPin() HAL_GPI HAL_GPIO_WritePin() HAL_GPIO_TogglePin() HAL_GPIO_LockPin() HAL_GPIO_EXTI_IRQHandler() 2 DocID027328 Rev 1166 237 /

238 HAL UM1850 GPIO Generic Driver HAL_GPIO_EXTI_Callback() Detailed description of functions 20.2.5 HAL_GPIO_Init void HAL_GPIO_Init (GPIO_TypeDef * GPIOx, Function name GPIO_InitTypeDef * GPIO_Init) tializes the GPIOx peripheral according to the specified Ini Function description parameters in the GPIO_Init. Parameters GPIOx: where x can be (A..G depending on device used) to select the GPIO peripheral pointer to a GPIO_InitTypeDef structure that GPIO_Init: contains the co nfiguration information for the specified GPIO peripheral. Return values None: HAL_GPIO_DeInit void HAL_GPIO_DeInit (GPIO_TypeDef * GPIOx, uint32_t Function name GPIO_Pin) De initializes the GPIOx peripheral registers to their default reset - Function description values. Parameters GPIOx: where x can be (A..G depending on device used) to select the GPIO peripheral GPIO_Pin: specifies the port bit to be written. This parameter O_PIN_x where x can be (0..15). can be one of GPI Return values None: HAL_GPIO_ReadPin GPIO_PinState HAL_GPIO_ReadPin (GPIO_TypeDef * GPIOx, Function name uint16_t GPIO_Pin) Function description Reads the specified input port pin. Parameters where x can be (A..G depending on device used) to GPIOx: select the GPIO peripheral GPIO_Pin: specifies the port bit to read. This parameter can be GPIO_PIN_x where x can be (0..15). Return values input port pin value. The: HAL_GPIO_WritePin id HAL_GPIO_WritePin (GPIO_TypeDef * GPIOx, uint16_t vo Function name GPIO_Pin, GPIO_PinState PinState) Function description Sets or clears the selected data port bit. Parameters where x can be (A..G depending on device used) to GPIOx: select the GPIO peripheral in: GPIO_P specifies the port bit to be written. This parameter can be one of GPIO_PIN_x where x can be (0..15). DocID027328 / 1166 238 Rev 2

239 UM1850 HAL GPIO Generic Driver specifies the value to be written to the selected bit. PinState: This parameter can be one of the GPIO_PinState enum values: clear the port pin GPIO_BIT_RESET: to GPIO_BIT_SET: to set the port pin Return values None: Notes This function uses GPIOx_BSRR register to allow atomic read/modify accesses. In this way, there is no risk of an IRQ occurring between the read and the modify access. HAL_GP IO_TogglePin void HAL_GPIO_TogglePin (GPIO_TypeDef * GPIOx, uint16_t Function name GPIO_Pin) Toggles the specified GPIO pin. Function description Parameters where x can be (A..G depending on device used) to GPIOx: select the GPIO peripheral Specifies the pins to be toggled. GPIO_Pin: Return values None: HAL_GPIO_LockPin HAL_StatusTypeDef HAL_GPIO_LockPin (GPIO_TypeDef * Function name GPIOx, uint16_t GPIO_Pin) Locks GPIO Pins configuration registers. Function description Parameters GPIOx: where x can be (A..G depending on device used) to select the GPIO peripheral specifies the port bit to be locked. This parameter GPIO_Pin: can be any combination of GPIO_Pin_x where x can be (0..15). Return values None: Notes The locking mechanism allows the IO configuration to be frozen. When the LOCK sequence has been applied on a port bit, it is no longer possible to modify the value of the port bit until the next reset. HAL_GPIO_EXTI_IRQHandler 6_t GPIO_Pin) void HAL_GPIO_EXTI_IRQHandler (uint1 Function name This function handles EXTI interrupt request. Function description Parameters Specifies the pins connected EXTI line GPIO_Pin: Return values None: HAL_GPIO_EXTI_Callback void HAL_GPIO_EXTI_Callback (uint16_t GPIO_Pin) Function name EXTI line detection callbacks. Function description 2 DocID027328 Rev 1166 239 /

240 HAL UM1850 GPIO Generic Driver Parameters Specifies the pins connected EXTI line GPIO_Pin: Return values None: GPIO Firmware driver defines 20.3 20.3.1 GPIO Exported Macros GPIO Description: __HAL_GPIO_EXTI_GET_FLAG Checks whether the specified EXTI line flag is set or not. Parameters: __EXTI_LINE__: specifies the EXTI line flag to check. This parameter can be GPIO_PIN_x where x can be(0..15) Return value: new state of __EXTI_LINE__ (SET or The: RESET). Description: __HAL_GPIO_EXTI_CLEAR_FLAG Clears the EXTI's line pending flags. Parameters: __EXTI_LINE__: specifies the EXTI lines flags to clear. This parameter can be any combination of GPIO_PIN_x where x can be (0..15) Return value: None Description: __HAL_GPIO_EXTI_GET_IT Checks whether the specified EXTI line is asserted or not. Parameters: __EXTI_LINE__: specifies the EXTI line to check. This parameter can be GPIO_PIN_x where x can be(0..15) Return value: e: new state of __EXTI_LINE__ (SET or Th RESET). Description: __HAL_GPIO_EXTI_CLEAR_IT Clears the EXTI's line pending bits. Parameters: __EXTI_LINE__: specifies the EXTI lines to clear. This parameter can be any DocID027328 / 1166 240 Rev 2

241 UM1850 GPIO Generic Driver HAL combination of GPIO_PIN_x where x can be (0..15) Return value: None Description: __HAL_GPIO_EXTI_GENERATE_SWIT Generates a Software interrupt on selected EXTI line. Parameters: __EXTI_LINE__: specifies the EXTI line to check. This parameter can be GPIO_PIN_x where x can be(0..15) Return value: one N GPIO mode define Input Floating Mode GPIO_MODE_INPUT Output Push Pull Mode GPIO_MODE_OUTPUT_PP Output Open Drain Mode GPIO_MODE_OUTPUT_OD Alternate Function Push Pull Mode GPIO_MODE_AF_PP GPIO_MODE_AF_OD Alternate Function Open Drain Mode Alternate Function Input Mode GPIO_MODE_AF_INPUT GPIO_MODE_ANALOG Analog Mode External Interrupt Mode with Rising edge trigger GPIO_MODE_IT_RISING detection External Interrupt Mode with Falling edge trigger GPIO_MODE_IT_FALLING detection External Interrupt Mode with Rising/Falling edge GPIO_MODE_IT_RISING_FALLING trigger detection GPIO_MODE_EVT_RISING External Event Mode with Rising edge trigger detection External Event Mode with Falling edge trigger GPIO_MODE_EVT_FALLING detection PIO_MODE_EVT_RISING_FALLING External Event Mode with Rising/Falling edge G trigger detection GPIO pins define GPIO_PIN_0 GPIO_PIN_1 GPIO_PIN_2 GPIO_PIN_3 GPIO_PIN_4 GPIO_PIN_5 2 DocID027328 Rev 1166 241 /

242 HAL UM1850 GPIO Generic Driver GPIO_PIN_6 GPIO_PIN_7 GPIO_PIN_8 GPIO_PIN_9 GPIO_PIN_10 GPIO_PIN_11 GPIO_PIN_12 GPIO_PIN_13 GPIO_PIN_14 GPIO_PIN_15 GPIO_PIN_All GPIO_PIN_MASK GPIO pull define up or Pull - - No Pull down activation GPIO_NOPULL Pull up activation - GPIO_PULLUP down activation GPIO_PULLDOWN Pull - GPIO speed define Low speed GPIO_SPEED_FREQ_LOW Medium speed GPIO_SPEED_FREQ_MEDIUM High speed GPIO_SPEED_FREQ_HIGH DocID027328 / 1166 242 Rev 2

243 UM1850 GPIO Extension Driver HAL HAL GPIO Extension Driver 21 21.1 GPIOEx Firmware driver API description GPIO Peripheral extension features 21.1.1 GPIO module on STM32F1 family, manage also the AFIO register: Possibility to use the EVENTOUT Cortex feature How to use this driver 21.1.2 This driver provides functions to use EVENTOUT Cortex feature Configure EVENTOUT Cortex feature using the function 1. HAL_GPIOEx_ConfigEventout() tout() Activate EVENTOUT Cortex feature using the HAL_GPIOEx_EnableEven 2. Deactivate EVENTOUT Cortex feature using the HAL_GPIOEx_DisableEventout() 3. Extended features functions 21.1.3 This section provides functions allowing to: Configure EVENTOUT Cortex feature using the function HAL_GPIOEx_ConfigEventout() Activate EVENTOUT Cortex feature using the HAL_GPIOEx_EnableEventout() Deactivate EVENTOUT Cortex feature using the HAL_GPIOEx_DisableEventout() This section contains the following APIs: HAL_GPIOEx_ConfigEventout() HAL_GPIOEx_EnableEventout() HAL_GPIOEx_DisableEventout() 21.1.4 Detailed description of functions HAL_GPIOEx_ConfigEventout void HAL_GPIOEx_ConfigEventout (uint32_t Function name GPIO_PortSource, uint32_t GPIO_PinSource) Configures the port and pin on which the EVENTOUT Cortex Function description signal will be connected. Parameters Select the port used to output the Cortex GPIO_PortSource: EVENTOUT signal. This parameter can be a value of EVENTOUT Port. Select the pin used to output the Cortex GPIO_PinSource: EVENTOUT signal. This parameter can be a value of EVENTOUT Pin. Return values None: _GPIOEx_EnableEventout HAL void HAL_GPIOEx_EnableEventout (void ) Function name Rev 2 1166 243 / DocID027328

244 GPIO Extension Driver HAL UM1850 Enables the Event Output. Function description Return values None: HAL_GPIOEx_DisableEventout void HAL_GPIOEx_DisableEventout (void ) Function name Disables the Event Output. Function description Return values None: 21.2 GPIOEx Firmware driver defines 21.2.1 GPIOEx Alternate Function Remapping Description: __HAL_AFIO_REMAP_SPI1_ENABLE Enable the remapping of SPI1 alternate function NSS, SCK, MISO and MOSI. Return value: None Notes: ENABLE: Remap (NSS/PA15, SCK/PB3, MISO/PB4, MOSI/PB5) Description: __HAL_AFIO_REMAP_SPI1_DISABLE Disable the remapping of SPI1 alternate function NSS, SCK, MOSI. MISO and Return value: None Notes: DISABLE: No remap (NSS/PA4, SCK/PA5, MISO/PA6, MOSI/PA7) Description: __HAL_AFIO_REMAP_I2C1_ENABLE Enable the remapping of I2C1 alternate function SCL and SDA. Return value: None Notes: ENABLE: Remap (SCL/PB8, SDA/PB9) DocID027328 / 1166 244 Rev 2

245 HAL UM1850 GPIO Extension Driver Description: AL_AFIO_REMAP_I2C1_DISABLE __H Disable the remapping of I2C1 alternate function SCL and SDA. Return value: None Notes: DISABLE: No remap (SCL/PB6, SDA/PB7) Description: __HAL_AFIO_REMAP_USART1_ENABLE Enable the remapping of USART1 alternate function TX and RX. Return value: None Notes: ENABLE: Remap (TX/PB6, RX/PB7) Description: __HAL_AFIO_REMAP_USART1_DISABLE Disable the remapping of USART1 alternate function TX and RX. Return value: None Notes: DISABLE: No remap (TX/PA9, RX/PA10) Description: __HAL_AFIO_REMAP_USART2_ENABLE Enable the remapping of USART2 alternate function CTS, RTS, CK, TX and RX. Return value: None Notes: ENABLE: Remap (CTS/PD3, RTS/PD4, TX/PD5, RX/PD6, CK/PD7) Description: __HAL_AFIO_REMAP_USART2_DISABLE the remapping of Disable USART2 alternate function CTS, RTS, CK, TX and RX. 2 DocID027328 Rev 1166 245 /

246 GPIO Extension Dr HAL UM1850 iver Return value: None Notes: DISABLE: No remap (CTS/PA0, RTS/PA1, TX/PA2, RX/PA3, CK/PA4) Description: __HAL_AFIO_REMAP_USART3_ENABLE Enable the remapping of USART3 alternate function CTS, R TS, CK, TX and RX. Return value: None Notes: ENABLE: Full remap (TX/PD8, RX/PD9, CK/PD10, CTS/PD11, RTS/PD12) Description: __HAL_AFIO_REMAP_USART3_PARTIAL Enable the remapping of USART3 alternate function CTS, RTS, CK, TX and RX. Return value: None Notes: PARTIAL: Partial remap (TX/PC10, RX/PC11, CK/PC12, CTS/PB13, RTS/PB14) Description: __HAL_AFIO_REMAP_USART3_DISABLE Disable the remapping of USART3 alternate function CTS, RTS, CK, TX and RX. Return value: None Notes: DISABLE: No remap (TX/PB10, RX/PB11, CK/PB12, CTS/PB13, RTS/PB14) Description: __HAL_AFIO_REMAP_TIM1_ENABLE Enable the remapping of TIM1 alternate function channels 1 to 4, 1N to 3N, external trigger DocID027328 / 1166 246 Rev 2

247 UM1850 GPIO Extension Driver HAL (ETR) and Break input (BKIN) Return value: None Notes: ENABLE: Full remap CH1/PE9, (ETR/PE7, CH2/PE11, CH3/PE13, CH4/PE14, BKIN/PE15, CH1N/PE8, CH2N/PE10, CH3N/PE12) Description: __HAL_AFIO_REMAP_TIM1_PARTIAL Enable the remapping of TIM1 alternate function channels 1 to 4, 1N to 3N, external trigger (ETR) and Break input (BKIN) lue: Return va None Notes: PARTIAL: Partial remap (ETR/PA12, CH1/PA8, CH2/PA9, CH3/PA10, CH4/PA11, BKIN/PA6, CH1N/PA7, CH2N/PB0, CH3N/PB1) Description: __HAL_AFIO_REMAP_TIM1_DISABLE Disable the remapping of TIM1 alternate function channels 1 to 4, 1N to 3N, l trigger (ETR) and externa Break input (BKIN) Return value: None Notes: DISABLE: No remap (ETR/PA12, CH1/PA8, CH2/PA9, CH3/PA10, CH4/PA11, BKIN/PB12, CH1N/PB13, CH2N/PB14, CH3N/PB15) Description: __HAL_AFIO_REMAP_TIM2_ENABLE Enable the remapping of TIM2 alternate function channels 1 to 4 and external trigger (ETR) Return value: 2 DocID027328 Rev 1166 247 /

248 GPIO Extension Driver HAL UM1850 None Notes: ENABLE: Full remap (CH1/ETR/PA15, CH2/PB3, CH3/PB10, CH4/PB11) Description: __HAL_AFIO_REMAP_TIM2_PARTIAL_2 Enable the remapping of TIM2 alternate function channels 1 to 4 and external trigger (ETR) Return value: None Notes: PARTIAL_2: Partial remap (CH1/ETR/PA0, CH2/PA1, CH3/PB10, CH4/PB11) Description: __HAL_AFIO_REMAP_TIM2_PARTIAL_1 Enable the remapping of TIM2 alternate function channels 1 (ETR) to 4 and external trigger Return value: None Notes: PARTIAL_1: Partial remap (CH1/ETR/PA15, CH2/PB3, CH3/PA2, CH4/PA3) Description: __HAL_AFIO_REMAP_TIM2_DISABLE Disable the remapping of TIM2 alternate function channels 1 to 4 and external trigger (ETR) Return value: None Notes: DISABLE: No remap (CH1/ETR/PA0, CH2/PA1, CH3/PA2, CH4/PA3) Description: __HAL_AFIO_REMAP_TIM3_ENABLE Enable the remapping of TIM3 alternate function channels 1 to 4. Return value: None DocID027328 / 1166 248 Rev 2

249 UM1850 GPIO Extension Driver HAL Notes: ENABLE: Full remap (CH1/PC6, CH2/PC7, CH3/PC8, CH4/PC9) TIM3_ETR on PE0 is not re - mapped. Description: __HAL_AFIO_REMAP_TIM3_PARTIAL Enable the remapping of TIM3 alternate function channels 1 to 4. Return value: None Notes: PARTIAL: Partial remap (CH1/PB4, CH2/PB5, CH3/PB0, CH4/PB1) - TIM3_ETR on PE0 is not re apped. m Description: __HAL_AFIO_REMAP_TIM3_DISABLE Disable the remapping of TIM3 alternate function channels 1 to 4. Return value: None Notes: DISABLE: No remap (CH1/PA6, CH2/PA7, CH3/PB0, CH4/PB1) TIM3_ETR on PE0 is not re - mapped. Description: __HAL_AFIO_REMAP_TIM4_ENABLE Enable the remapping of TIM4 alternate function channels 1 to 4. Return value: None Notes: ENABLE: Full remap (TIM4_CH1/PD12, TIM4_CH2/PD13, TIM4_CH3/PD14, TIM4_CH4/PD15) TIM4_ETR mapped. - on PE0 is not re Description: __HAL_AF IO_REMAP_TIM4_DISABLE 249 Rev 2 1166 / DocID027328

250 HAL UM1850 GPIO Extension Driver Disable the remapping of TIM4 alternate function channels 1 to 4. Return value: None Notes: DISABLE: No remap (TIM4_CH1/PB6, TIM4_CH2/PB7, TIM4_CH3/PB8, TIM4_CH4/PB9) TIM4_ETR mapped. on PE0 is not re - Description: N1_1 __HAL_AFIO_REMAP_CA Enable or disable the remapping of CAN alternate function CAN_RX and CAN_TX in devices with a single CAN interface. Return value: None Notes: CASE 1: CAN_RX mapped to PA11, CAN_TX mapped to PA12 Description: __HAL_AFIO_REMAP_CAN1_2 Enable or disable the remapping of CAN alternate function CAN_RX and CAN_TX in devices with a single CAN interface. Return value: None Notes: CASE 2: CAN_RX mapped to PB8, CAN_TX mapped to PB9 (not available on 36 - pin package) ription: Desc __HAL_AFIO_REMAP_CAN1_3 Enable or disable the remapping of CAN alternate function CAN_RX and CAN_TX in devices with a single CAN interface. Return value: DocID027328 / 1166 250 Rev 2

251 HAL UM1850 GPIO Extension Driver None Notes: CASE 3: CAN_RX mapped to PD0, CAN_TX mapped to PD1 Description: __HAL_AFIO_REMAP_PD01_ENABLE Enable the remapping of PD0 and PD1. Return value: None Notes: ENABLE: PD0 remapped on OSC_IN, PD1 remapped on OSC_OUT. Description: __HAL_AFIO_REMAP_PD01_DISABLE Disable the remapping of PD0 and PD1. Return value: None Notes: DISABLE: No remapping of PD0 and PD1 Description: _ _HAL_AFIO_REMAP_TIM5CH4_ENABLE Enable the remapping of TIM5CH4. Return value: None Notes: ENABLE: LSI internal clock is connected to TIM5_CH4 input for calibration purpose. This function is available only in high density value line devices. Description: __HAL_AFIO_REMAP_TIM5CH4_DISABLE Disable the remapping of TIM5CH4. Return value: None Notes: DISABLE: TIM5_CH4 is 2 DocID027328 Rev 1166 251 /

252 HAL UM1850 GPIO Extension Driver connected to PA3 This function is available only in high density value line devices. ption: Descri __HAL_AFIO_REMAP_ADC1_ETRGINJ_ENABLE Enable the remapping of ADC1_ETRGINJ (ADC 1 External trigger injected conversion). Return value: None Notes: ENABLE: ADC1 External Event injected conversion is connected to TIM8 Channel4. Description: __HAL_AFIO_REMAP_ADC1_ETRGINJ_DISABLE the remapping of Disable ADC1_ETRGINJ (ADC 1 External trigger injected conversion). Return value: None Notes: DISABLE: ADC1 External trigger injected conversion is connected to EXTI15 Description: __HAL_AFIO_REMAP_ADC1_ETRGREG_ENABLE Enable the remapping of ETRGREG (ADC 1 ADC1_ External trigger regular conversion). Return value: None Notes: ENABLE: ADC1 External Event regular conversion is connected to TIM8 TRG0. Description: __HAL_AFIO_REMAP_ADC1_ETRGREG_DISABLE Disable the remapping of ADC1_ETRGREG (ADC 1 al trigger regular Extern conversion). Return value: DocID027328 / 1166 252 Rev 2

253 UM1850 GPIO Extension Driver HAL None Notes: DISABLE: ADC1 External trigger regular conversion is connected to EXTI11 Description: __HAL_AFIO_REMAP_ADC2_ETRGINJ_ENABLE Enable the remapping of ADC2_ETRGREG (ADC 2 External trigger injected conversion). Return value: None Notes: ENABLE: ADC2 External Event injected conversion is connected to TIM8 Channel4. Description: __HAL_AFIO_REMAP_ADC2_ETRGINJ_DISABLE Disable the remapping of ADC2_ETRGREG (ADC 2 External trigger injected conversion). turn value: Re None Notes: DISABLE: ADC2 External trigger injected conversion is connected to EXTI15 Description: __HAL_AFIO_REMAP_ADC2_ETRGREG_ENABLE Enable the remapping of ADC2_ETRGREG (ADC 2 External trigger regular conversion). Return value: None Notes: ENABLE: ADC2 External Event regular conversion is connected to TIM8 TRG0. Description: __HAL_AFIO_REMAP_ADC2_ETRGREG_DISABLE Disable the remapping of ADC2_ETRGREG (ADC 2 External trigger regular conversion). 2 DocID027328 Rev 1166 253 /

254 HAL UM1850 GPIO Extension Driver Return value: None Notes: External DISABLE: ADC2 trigger regular conversion is connected to EXTI11 Description: __HAL_AFIO_REMAP_SWJ_ENABLE Enable the Serial wire JTAG configuration. Return value: None Notes: DP - ENABLE: Full SWJ (JTAG DP): Reset State - + SW Description: __HAL_AFIO_REMAP_SWJ_NONJTRST Enable the Serial wire JTAG configuration. Return value: None Notes: NONJTRST: Full SWJ (JTAG - DP + SW - DP) but without NJTRST Description: __HAL_AFIO_REMAP_SWJ_NOJTAG Enable the Serial wire JTAG configuration. Return value: None Notes: DP Disabled - JTAG NOJTAG: - DP Enabled and SW Description: __HAL_AFIO_REMAP_SWJ_DISABLE Disable the Serial wire JTAG configuration. Return value: None Notes: DP Disabled - DISABLE: JTAG DP Disabled - and SW Description: __HAL_AFIO_REMAP_TIM9_ENABLE 254 DocID027328 / Rev 2 1166

255 UM1850 GPIO Extension Driver HAL Enable the remapping of TIM9_CH1 and TIM9_CH2. Return value: None Notes: ENABLE: Remap (TIM9_CH1 on PE5 and TIM9_CH2 on PE6). Description: __HAL_AFIO_REMAP_TIM9_DISABLE Disable the remapping of TIM9_CH1 and TIM9_CH2. Return value: None Notes: DISABLE: No remap (TIM9_CH1 on PA2 and TIM9_CH2 on PA3). Description: __HAL_AFIO_REMAP_TIM10_ENABLE Enable the remapping of TIM10_CH1. Return value: None Notes: ENABLE: Remap (TIM10_CH1 on PF6). Description: __HAL_AFIO_REMAP_TIM10_DISABLE Disable the remapping of TIM10_CH1. Return value: None Notes: DISABLE: No remap (TIM10_CH1 on PB8). Description: __HAL_AFIO_REMAP_TIM11_ENABLE Enable the remapping of TIM11_CH1. Return value: None Notes: ENABLE: Remap 2 DocID027328 Rev 1166 255 /

256 HAL Extension Driver UM1850 GPIO (TIM11_CH1 on PF7). Description: __HAL_AFIO_REMAP_TIM11_DISABLE Disable the remapping of TIM11_CH1. Return value: None Notes: DISABLE: No remap (TIM11_CH1 on PB9). Description: __HAL_AFIO_REMAP_TIM13_ENABLE Enable the remapping of TIM13_CH1. Return value: None Notes: ENABLE: Remap STM32F100:(TIM13_CH1 on PF8). Others:(TIM13_CH1 on PB0). Description: __HAL_AFIO_REMAP_TIM13_DISABLE Disable the remapping of TIM13_CH1. Return value: None Notes: DISABLE: No remap STM32F100:(TIM13_CH1 on PA6). Others:(TIM13_CH1 on PC8). n: Descriptio __HAL_AFIO_REMAP_TIM14_ENABLE Enable the remapping of TIM14_CH1. Return value: None Notes: ENABLE: Remap STM32F100:(TIM14_CH1 on PB1). Others:(TIM14_CH1 on PF9). Description: __HAL_AFIO_REMAP_TIM14_DISABLE Disable the remapping of DocID027328 / 1166 256 Rev 2

257 UM1850 GPIO Extension Driver HAL TIM14_CH1. Return value: None Notes: DISABLE: No remap STM32F100:(TIM14_CH1 on PC9). Others:(TIM14_CH1 on PA7). Description: __HAL_AFIO_FSMCNADV_DISCONNECTED Controls the use of the optional FSMC_NADV signal. Return value: None Notes: DISCONNECTED: The NADV signal is not connected. The I/O pin can be us ed by another peripheral. Description: __HAL_AFIO_FSMCNADV_CONNECTED Controls the use of the optional FSMC_NADV signal. Return value: None Notes: CONNECTED: The NADV signal is connected to the output (default). EVENTOUT Pin AFIO_EVENTOUT_PIN_0 EVENTOUT on pin 0 EVENTOUT on pin 1 AFIO_EVENTOUT_PIN_1 AFIO_EVENTOUT_PIN_2 EVENTOUT on pin 2 AFIO_EVENTOUT_PIN_3 EVENTOUT on pin 3 EVENTOUT on pin 4 AFIO_EVENTOUT_PIN_4 AFIO_EVENTOUT_PIN_5 EVENTOUT on pin 5 AFIO_EVENTOUT_PIN_6 EVENTOUT on pin 6 EVENTOUT on pin 7 AFIO_EVENTOUT_PIN_7 AFIO_EVENTOUT_PIN_8 EVENTOUT on pin 8 EVENTOUT on pin 9 AFIO_EVENTOUT_PIN_9 AFIO_EVENTOUT_PIN_10 EVENTOUT on pin 10 2 DocID027328 Rev 1166 257 /

258 HAL UM1850 GPIO Extension Driver EVENTOUT on pin 11 AFIO_EVENTOUT_PIN_11 EVENTOUT on pin 12 AFIO_EVENTOUT_PIN_12 AFIO_EVENTOUT_PIN_13 EVENTOUT on pin 13 EVENTOUT on pin 14 AFIO_EVENTOUT_PIN_14 AFIO_EVENTOUT_PIN_15 EVENTOUT on pin 15 IS_AFIO_EVENTOUT_PIN EVENTOUT Port EVENTOUT on port A AFIO_EVENTOUT_PORT_A AFIO_EVENTOUT_PORT_B EVENTOUT on port B AFIO_EVENTOUT_PORT_C EVENTOUT on port C AFIO_EVENTOUT_PORT_D EVENTOUT on port D EVENTOUT on port E AFIO_EVENTOUT_PORT_E IS_AFIO_EVENTOUT_PORT DocID027328 / 1166 258 Rev 2

259 HAL UM1850 HCD Generic Driver 22 HAL HCD Generic Driver isters structures HCD Firmware driver reg 22.1 22.1.1 HCD_HandleTypeDef Data Fields HCD_TypeDef * Instance HCD_InitTypeDef Init HCD_HCTypeDef hc HAL_LockTypeDef Lock __IO HCD_StateTypeDef State void * pData Field Documentation HCD_TypeDef* HCD_HandleTypeDef::Instance Register base address HCD_InitTypeDef HCD_HandleTypeDef::Init HCD required parameters HCD_HCTypeDef HCD_HandleTypeDef::hc[15U] Host channels parameters HAL_LockTypeDef HCD_HandleTypeDef::Lock HCD peripheral status __IO HCD_StateTypeDef HCD_HandleTypeDef::State HCD communication state void* HCD_HandleTypeDef::pData Pointer Stack Handler 22.2 HCD Firmware driver API description How to use this driver 22.2.1 1. Declare a HCD_HandleTypeDef handle structure, for example: HCD_HandleTypeDef hhcd; 2. Fill parameters of Init structure in HCD handle Call HAL_HCD_Init() API to initialize the HCD peripheral (Core, Host core, ...) 3. Initialize the HCD low level resources through the HAL_HCD_MspInit() API: 4. a. Enable the HCD/USB Low Level interface clock using the following macro __HAL_RCC_USB_OTG_FS_CLK_ENABLE() b. Initialize the related GPIO clocks - c. out Configure HCD pin Configure HCD NVIC interrupt d. Associate the Upper USB Host stack to the HAL HCD Driver: 5. hhcd.pData = phost; a. 6. Enable HCD transmission and reception: a. HAL_HCD_Start(); initialization functions - Initialization and de 22.2.2 This section provides functions allowing to: This section contains the following APIs: DocID027328 Rev 2 66 259 / 11

260 HAL HCD Generic Driver UM1850 HAL_HCD_Init() HAL_HCD_HC_Init() HAL_HCD _HC_Halt() HAL_HCD_DeInit() HAL_HCD_MspInit() HAL_HCD_MspDeInit() 22.2.3 IO operation functions the following APIs: This section contains HAL_HCD_HC_SubmitRequest() HAL_HCD_IRQHandler() HAL_HCD_SOF_Callback() HAL_HCD_Connect_Callback() HAL_HCD_Disconnect_Callback() HAL_HCD_HC_NotifyURBChange_Callback() Peripheral Control functions 22.2.4 This subsection provides a set of functions allowing to control the HCD data transfers. This section contains the following APIs: HAL_HCD_Start() HAL_HCD_Stop() HAL_HCD_ResetPort() 22.2.5 Peripheral State functions This subsection permits to get in run - time the status of the peripheral and the data flow. This section contains the following APIs: HAL_HCD_GetState() HAL_HCD_HC_GetURBState() HAL_HCD_HC_GetXferCount() HAL_HCD_HC_GetState() HAL_HCD_GetCurren tFrame() HAL_HCD_GetCurrentSpeed() 22.2.6 Detailed description of functions HAL_HCD_Init HAL_StatusTypeDef HAL_HCD_Init (HCD_HandleTypeDef * Function name hhcd) Function description Initialize the host driver. Parameters HCD handle hhcd: Return values HAL: status HAL_HCD_DeInit HAL_StatusTypeDef HAL_HCD_DeInit (HCD_HandleTypeDef * Function name hhcd) DocID027328 / 1166 260 Rev 2

261 UM1850 HCD Generic Driver HAL DeInitialize the host driver. Function description Parameters hhcd: HCD handle Return values HAL: status HAL_HCD_HC_Init HAL_StatusTypeDef HAL_HCD_HC_Init (HCD_HandleTypeDef Function name * hhcd, uint8_t ch_num, uint8_t epnum, uint8_t dev_address, uint8_t speed, uint8_t ep_type, uint16_t mps) Function description Initialize a host channel. Parameters HCD handle hhcd: ch_num: Channel number. This parameter can be a value from 1 to 15 epnum: Endpoint number. This parameter can be a value from 1 to 15 dev_address: : Current device address This parameter can value from 0 to 255 be a speed: Current device speed. This parameter can be one of these values: HCD_SPEED_FULL: Full speed mode, HCD_SPEED_LOW: Low speed mode Endpoint Type. This parameter can be one of these ep_type: values: EP_TYPE_CTRL: Control type, EP_ TYPE_ISOC: Isochronous type, EP_TYPE_BULK: Bulk type, EP_TYPE_INTR: Interrupt type Max Packet Size. This parameter can be a value from mps: 0 to32K Return values HAL: status HAL_HCD_HC_Halt HAL_StatusTypeDef HAL_HCD_HC_Halt Function name (HCD_HandleTypeDef * hhcd, uint8_t ch_num) Function description Halt a host channel. Parameters HCD handle hhcd: ch_num: Channel number. This parameter can be a value from 1 to 15 Return values status HAL: HAL_HCD_MspInit void HAL_HCD_MspInit (HCD_HandleTypeDef * hhcd) Function name Function description Initializes the HCD MSP. Parameters HCD handle hhcd: Return values None: HAL_HCD_MspDeInit void HAL_HCD_MspDeInit (HCD_HandleTypeDef * hhcd) Function name Rev 2 1166 261 / DocID027328

262 HAL UM1850 HCD Generic Driver DeInitializes HCD MSP. Function description Parameters hhcd: HCD handle Return values None: HAL_HCD_HC_SubmitRequest HAL_StatusTypeDef HAL_HCD_HC_SubmitRequest Function name (HCD_HandleTypeDef * hhcd, uint8_t ch_num, uint8_t direction, uint8_t ep_type, uint8_t token, uint8_t * pbuff, uint16_t length, uint8_t do_ping) Function description Submit a new URB for processing. Parameters HCD handle hhcd: Channel number. This parameter can be a value ch_num: from 1 to 15 ne of Channel number. This parameter can be o direction: these values: 0 : Output / 1 : Input Endpoint Type. This parameter can be one of these ep_type: values: EP_TYPE_CTRL: Control type/ EP_TYPE_ISOC: Isochronous type/ EP_TYPE_BULK: Bulk type/ EP_TYPE_INTR: Interrupt type/ token: rameter can be one of these Endpoint Type. This pa values: 0: HC_PID_SETUP / 1: HC_PID_DATA1 pbuff: pointer to URB data Length of URB data length: do_ping: activate do ping protocol (for high speed only). This parameter can be one of these values: 0 : do ping inactive / 1 : d o ping active Return values status HAL: HAL_HCD_IRQHandler void HAL_HCD_IRQHandler (HCD_HandleTypeDef * hhcd) Function name Function description handle HCD interrupt request. Parameters HCD handle hhcd: Return values None: HAL_HCD_SOF_Callback void HAL_HCD_SOF_Callback (HCD_HandleTypeDef * hhcd) Function name SOF callback. Function description Parameters HCD handle hhcd: Return values None: HAL_HCD_Connect_Callback void HAL_HCD_Connect_Callback (HCD_HandleTypeDef * Function name hhcd) DocID027328 / 1166 262 Rev 2

263 UM1850 HCD Generic Driver HA L Connexion Event callback. Function description Parameters HCD handle hhcd: Return values None: HAL_HCD_Disconnect_Callback void HAL_HCD_Disconnect_Callback (HCD_HandleTypeDef * Function name hhcd) Function description Disonnection Event callback. Parameters hhcd: HCD handle Return values None: HAL_HCD_HC_NotifyURBChange_Callback void HAL_HCD_HC_NotifyURBChange_Callback Function name (HCD_HandleTypeDef * hhcd, uint8_t chnum, HCD_URBStateTypeDef urb_state) hange callback. Notify URB state c Function description Parameters HCD handle hhcd: chnum: Channel number. This parameter can be a value from 1 to 15 urb_state: This parameter can be one of these values: URB_IDLE/ URB_DONE/ URB_NOTREADY/ URB_NYET/ URB_ERROR/ URB_STALL/ Return values None: HAL_HCD_ResetPort HAL_StatusTypeDef HAL_HCD_ResetPort Function name (HCD_HandleTypeDef * hhcd) Function description Reset the host port. Parameters hhcd: HCD handle Return values status HAL: HAL_HCD_Start HAL_HCD_Start (HCD_HandleTypeDef * HAL_StatusTypeDef Function name hhcd) Function description Start the host driver. Parameters HCD handle hhcd: Return values HAL: status HAL_HCD_Stop HAL_StatusTypeDef HAL_HCD_Stop (HCD_HandleTypeDef * Function name hhcd) 2 DocID027328 Rev 1166 263 /

264 HAL UM1850 HCD Generic Driver Stop the host driver. Function description Parameters hhcd: HCD handle Return values HAL: status HAL_HCD_GetState HCD_StateTypeDef HAL_HCD_GetState (HCD_HandleTypeDef Function name * hhcd) Function description Return the HCD handle state. Parameters HCD handle hhcd: Return values HAL: state HAL_HCD_HC_GetURBState HCD_URBStateTypeDef HAL_HCD_HC_GetURBState Function name (HCD_HandleTypeDef * hhcd, uint8_t chnum) Function description Return URB state for a channel. Parameters HCD handle hhcd: chnum: Channel number. This parameter can be a value from 1 to 15 Return values URB: state. This parameter can be one of these values: URB_IDLE/ URB_DONE/ URB_NOTREADY/ URB_NYET/ URB_ERROR/ URB_STALL/ HAL_HCD_HC_GetXferCount uint32_t HAL_HCD_HC_GetXferCount (HCD_HandleTypeDef * Function name hhcd, uint8_t chnum) Return the last host transfer size. Function description Parameters HCD handle hhcd: chnum: Channel number. This parameter can be a value from 1 to 15 Return values transfer size in byte last: HAL_HCD_HC_GetState HCD_HCStateTypeDef HAL_HCD_HC_GetState Function name (HCD_HandleTypeDef * hhcd, uint8_t chnum) Function description Return the Host Channel state. Parameters HCD handle hhcd: Channel number. This para chnum: meter can be a value from 1 to 15 Return values channel state This parameter can be one of the these Host: values: HC_IDLE/ HC_XFRC/ HC_HALTED/ HC_NYET/ HC_NAK/ HC_STALL/ HC_XACTERR/ HC_BBLERR/ HC_DATATGLERR/ DocID027328 / 1166 264 Rev 2

265 UM1850 HCD Generic Driver HAL HAL_HCD_GetCurrentFrame uint32_t HAL_HCD_GetCurrentFrame (HCD_HandleTypeDef * Function name hhcd) Function description Return the current Host frame number. Parameters HCD handle hhcd: Return values Current: Host frame number HAL_HCD_GetCurrentSpeed rentSpeed (HCD_HandleTypeDef * uint32_t HAL_HCD_GetCur Function name hhcd) Return the Host enumeration speed. Function description Parameters HCD handle hhcd: Return values Enumeration: speed 22.3 HCD Firmware driver defines HCD 22.3.1 HCD Exported Macros __HAL_HCD_ENABLE __HAL_HCD_DISABLE __HAL_HCD_GET_FLAG __HAL_HCD_CLEAR_FLAG __HAL_HCD_IS_INVALID_INTERRUPT __HAL_HCD_CLEAR_HC_INT __HAL_HCD_MASK_HALT_HC_INT __HAL_HCD_UNMASK_HALT_HC_INT __HAL_HCD_MASK_ACK_HC_INT __HAL_HCD_UNMASK_ACK_HC_INT HCD Instance definition IS_HCD_ALL_INSTANCE HCD Speed HCD_SPEED_LOW HCD_SPEED_FULL 2 DocID027328 Rev 1166 265 /

266 HAL UM1850 I2C Generic Driver 23 HAL I2C Generic Driver driver registers structures 23.1 I2C Firmware I2C_InitTypeDef 23.1.1 Data Fields uint32_t ClockSpeed uint32_t DutyCycle uint32_t OwnAddress1 uint32_t AddressingMode uint32_t DualAddressMode Address2 uint32_t Own uint32_t GeneralCallMode uint32_t NoStretchMode Field Documentation uint32_t I2C_InitTypeDef::ClockSpeed Specifies the clock frequency. This parameter must be set to a value lower than 400kHz uint32_t I2C_InitTypeDef::DutyCycle Specifies the I2C fast mode duty cycle. This parameter can be a value of I2C_duty_cycle_in_fast_mode uint32_t I2C_InitTypeDef::OwnAddress1 bit Specifies the first device own address. This parameter can be a 7 - bit or 10 - addr ess. uint32_t I2C_InitTypeDef::AddressingMode bit addressing mode is selected. This parameter can be a value - - bit or 10 Specifies if 7 I2C_addressing_mode of uint32_t I2C_InitTypeDef::DualAddressMode Specifies if dual addre ssing mode is selected. This parameter can be a value of I2C_dual_addressing_mode uint32_t I2C_InitTypeDef::OwnAddress2 Specifies the second device own address if dual addressing mode is selected This parameter can be a 7 - bit address. uint32_t I2C_InitTypeDef::GeneralCallMode Specifies if general call mode is selected. This parameter can be a value of I2C_general_call_addressing_mode uint32_t I2C_InitTypeDef::NoStretchMode Specifies if nostretch mode is selected. This parameter can be a value of I2C_nostretch_mode I2C_HandleTypeDef 23.1.2 Data Fields I2C_TypeDef * Instance I2C_InitTypeDef Init uint8_t * pBuffPtr uint16_t XferSize __IO uint16_t XferCount __IO uint32_t XferOptions DocID027328 / 1166 266 Rev 2

267 UM1850 I2C Generic Driver HAL __IO uint32_t PreviousState DMA_HandleTypeDef * hdmatx DMA_HandleTypeDef * hdmarx HAL_LockTypeDef Lock __IO HAL_I2C_StateTypeDef State __IO HAL_I2C_ModeTypeDef Mode __IO uint32_t ErrorCode __IO uint32_t Devaddress __IO uint32_t Memaddress __IO uint32_t MemaddSize __IO uint32_t EventCount Field Documentation I2C_TypeDef* I2C_HandleTypeDef::Instance I2C registers base address I2C_InitTypeDef I2C_HandleTypeDef::Init I2C communication parameters uint8_t* I2C_HandleTypeDef::pBuffPtr Pointer to I2C transfer buffer uint16_t I2C_HandleTypeDef::XferSize I2C transfer size XferCount __IO uint16_t I2C_HandleTypeDef:: I2C transfer counter __IO uint32_t I2C_HandleTypeDef::XferOptions I2C transfer options __IO uint32_t I2C_HandleTypeDef::PreviousState I2C communication Previous state and mode context for internal usage DMA_HandleTypeDef* I2C_HandleTypeDef::hd matx I2C Tx DMA handle parameters DMA_HandleTypeDef* I2C_HandleTypeDef::hdmarx I2C Rx DMA handle parameters HAL_LockTypeDef I2C_HandleTypeDef::Lock I2C locking object __IO HAL_I2C_StateTypeDef I2C_HandleTypeDef::State I2C communication state HAL_I2C_ModeTypeDef I2C_HandleTypeDef::Mode __IO I2C communication mode __IO uint32_t I2C_HandleTypeDef::ErrorCode I2C Error code __IO uint32_t I2C_HandleTypeDef::Devaddress I2C Target device address __IO uint32_t I2C_HandleTypeDef::Memaddress ory address I2C Target mem __IO uint32_t I2C_HandleTypeDef::MemaddSize I2C Target memory address size __IO uint32_t I2C_HandleTypeDef::EventCount I2C Event counter I2C Firmware driver API description 23.2 How to use this driver 23.2.1 The I2C HAL driver can be used as follows: 2 DocID027328 Rev 1166 267 /

268 HAL UM1850 I2C Generic Driver Declare a I2C_HandleTypeDef handle structure, for example: I2C_HandleTypeDef 1. hi2c; 2. Initialize the I2C low level resources by implementing the HAL_I2C_MspInit() API: the I2Cx interface clock a. Enable b. I2C pins configuration Enable the clock for the I2C GPIOs Configure I2C pins as alternate function open - drain c. NVIC configuration if you need to use interrupt process Configure the I2Cx interrupt priority Enable the NVIC I2C IRQ Channel d. DMA Configuration if you need to use DMA process Declare a DMA_HandleTypeDef handle structure for the transmit or receive channel Enable the DMAx interface clock using Configure the DMA handle parameters Configure the DMA Tx or Rx channel e the initialized DMA handle to the hi2c DMA Tx or Rx handle Associat Configure the priority and enable the NVIC for the transfer complete interrupt on the DMA Tx or Rx channel 3. Configure the Communication Speed, Duty cycle, Addressing mode, Own Address1, Dual Addr essing mode, Own Address2, General call and Nostretch mode in the hi2c Init structure. Initialize the I2C registers by calling the HAL_I2C_Init(), configures also the low level 4. Hardware (GPIO, CLOCK, NVIC...etc) by calling the customized HAL_I2C_MspInit(& hi2c) API. 5. To check if target device is ready for communication, use the function HAL_I2C_IsDeviceReady() For I2C IO and IO MEM operations, three operation modes are available within this 6. driver : Polling mode IO operation Transmit in master mode an amo unt of data in blocking mode using HAL_I2C_Master_Transmit() Receive in master mode an amount of data in blocking mode using HAL_I2C_Master_Receive() Transmit in slave mode an amount of data in blocking mode using HAL_I2C_Slave_Transmit() Receive in slave mode an amount of data in blocking mode using HAL_I2C_Slave_Receive() Polling mode IO MEM operation Write an amount of data in blocking mode to a specific memory address using HAL_I2C_Mem_Write() ory address using Read an amount of data in blocking mode from a specific mem HAL_I2C_Mem_Read() Interrupt mode IO operation Transmit in master mode an amount of data in non blocking mode using HAL_I2C_Master_Transmit_IT() At transmission end of transfer HAL_I2C_MasterTxCpltCallback is executed and user his own code by customization of function pointer can add HAL_I2C_MasterTxCpltCallback DocID027328 / 1166 268 Rev 2

269 UM1850 I2C Generic Driver HAL Receive in master mode an amount of data in non blocking mode using HAL_I2C_Master_Receive_IT() At reception end of transfer HAL_I2C_MasterRxCpltCallback is executed and user ca n add his own code by customization of function pointer HAL_I2C_MasterRxCpltCallback Transmit in slave mode an amount of data in non blocking mode using HAL_I2C_Slave_Transmit_IT() user At transmission end of transfer HAL_I2C_SlaveTxCpltCallback is executed and can add his own code by customization of function pointer HAL_I2C_SlaveTxCpltCallback Receive in slave mode an amount of data in non blocking mode using HAL_I2C_Slave_Receive_IT() At reception end of transfer HAL_I2C_SlaveRxCpltCallback is executed a nd user can add his own code by customization of function pointer HAL_I2C_SlaveRxCpltCallback In case of transfer Error, HAL_I2C_ErrorCallback() function is executed and user can add his own code by customization of function pointer HAL_I2C_ErrorCallback bort a master I2C process communication with Interrupt using A HAL_I2C_Master_Abort_IT() End of abort process, HAL_I2C_AbortCpltCallback() is executed and user can add his own code by customization of function pointer HAL_I2C_AbortCpltCallback() ode IO sequential operation Interrupt m These interfaces allow to manage a sequential transfer with a repeated start condition when a direction change during transfer A specific option field manage the different steps of a sequential transfer Option field value s are defined through @ref I2C_XFEROPTIONS and are listed below: I2C_FIRST_AND_LAST_FRAME: No sequential usage, functionnal is same as associated interfaces in no sequential mode I2C_FIRST_FRAME: Sequential usage, this option allow to manage a sequence with start condition, address and data to transfer without a final stop condition I2C_NEXT_FRAME: Sequential usage, this option allow to manage a sequence with a restart condition, address and with new data to transfer if the direction y the new data to transfer if no direction change and change or manage onl without a final stop condition in both cases I2C_LAST_FRAME: Sequential usage, this option allow to manage a sequance with a restart condition, address and with new data to transfer if the direction cha nge or manage only the new data to transfer if no direction change and with a final stop condition in both cases Differents sequential I2C interfaces are listed below: - Sequential transmit in master I2C mode an amount of data in non blocking mode L_I2C_Master_Sequential_Transmit_IT() using HA At transmission end of current frame transfer, HAL_I2C_MasterTxCpltCallback() is executed and user can add his own code by customization of function pointer HAL_I2C_MasterTxCpltCallback() I2C mode an amount of data in non blocking mode - Sequential receive in master using HAL_I2C_Master_Sequential_Receive_IT() At reception end of current frame transfer, HAL_I2C_MasterRxCpltCallback() is executed and user can add his own MasterRxCpltCallback() code by customization of function pointer HAL_I2C_ 2 DocID027328 Rev 1166 269 /

270 I2C Generic Driver HAL UM1850 Abort a master I2C process communication with Interrupt using HAL_I2C_Master_Abort_IT() End of abort process, HAL_I2C_AbortCpltCallback() is executed and user can add his own code by customization of function pointer HAL_I2C_AbortCp ltCallback() Enable/disable the Address listen mode in slave I2C mode using HAL_I2C_EnableListen_IT() HAL_I2C_DisableListen_IT() When address slave I2C match, HAL_I2C_AddrCallback() is executed and and the user can add his own code to check the Address Match Code transmission direction request by master (Write/Read). At Listen mode end HAL_I2C_ListenCpltCallback() is executed and user can add his own code by customization of function pointer HAL_I2C_ListenCpltCallback() e an amount of data in non Sequential transmit in slave I2C mod blocking mode - using HAL_I2C_Slave_Sequential_Transmit_IT() At transmission end of current frame transfer, HAL_I2C_SlaveTxCpltCallback() is executed and user can add his own TxCpltCallback() code by customization of function pointer HAL_I2C_Slave Sequential receive in slave I2C mode an amount of data in non blocking mode - using HAL_I2C_Slave_Sequential_Receive_IT() At reception end of current frame transfer, HAL_I2C_SlaveRxCpltCallback() is executed and user can add his own code by customization of function pointer HAL_I2C_SlaveRxCpltCallback() In case of transfer Error, HAL_I2C_ErrorCallback() function is executed and user can add his own code by customization of function pointer HAL_I2C_ErrorCallback() Interrupt mode IO MEM opera tion - blocking mode with Interrupt to a specific memory Write an amount of data in no address using HAL_I2C_Mem_Write_IT() At MEM end of write transfer HAL_I2C_MemTxCpltCallback is executed and user can add his own code by customization of function pointer HAL_I2C_MemTxCpltCallback blocking mode with Interrupt from a specific memory - Read an amount of data in no address using HAL_I2C_Mem_Read_IT() At MEM end of read transfer HAL_I2C_MemRxCpltCallback is executed and user can of function pointer HAL_I2C_MemRxCpltCallback add his own code by customization In case of transfer Error, HAL_I2C_ErrorCallback() function is executed and user can add his own code by customization of function pointer HAL_I2C_ErrorCallback DMA mode IO operation amount of data in non blocking mode (DMA) using Transmit in master mode an HAL_I2C_Master_Transmit_DMA() At transmission end of transfer HAL_I2C_MasterTxCpltCallback is executed and user can add his own code by customization of function pointer HAL_I2C_MasterTxCpltCallback Receive in master mode an amount of data in non blocking mode (DMA) using HAL_I2C_Master_Receive_DMA() At reception end of transfer HAL_I2C_MasterRxCpltCallback is executed and user can add his own code by customization of function pointer back HAL_I2C_MasterRxCpltCall Transmit in slave mode an amount of data in non blocking mode (DMA) using HAL_I2C_Slave_Transmit_DMA() DocID027328 / 1166 270 Rev 2

271 UM1850 I2C Generic Driver HAL At transmission end of transfer HAL_I2C_SlaveTxCpltCallback is executed and user can add his own code by customization of function pointer laveTxCpltCallback HAL_I2C_S Receive in slave mode an amount of data in non blocking mode (DMA) using HAL_I2C_Slave_Receive_DMA() At reception end of transfer HAL_I2C_SlaveRxCpltCallback is executed and user can add his own code by customization of function pointer HAL_I2C_SlaveRxCpltCallback In case of transfer Error, HAL_I2C_ErrorCallback() function is executed and user can add his own code by customization of function pointer HAL_I2C_ErrorCallback Abort a master I2C process communication with Interrupt using HAL_I 2C_Master_Abort_IT() End of abort process, HAL_I2C_AbortCpltCallback() is executed and user can add his own code by customization of function pointer HAL_I2C_AbortCpltCallback() DMA mode IO MEM operation - Write an amount of data in no A to a specific memory address blocking mode with DM using HAL_I2C_Mem_Write_DMA() At MEM end of write transfer HAL_I2C_MemTxCpltCallback is executed and user can add his own code by customization of function pointer HAL_I2C_MemTxCpltCallback blocki - Read an amount of data in no ng mode with DMA from a specific memory address using HAL_I2C_Mem_Read_DMA() At MEM end of read transfer HAL_I2C_MemRxCpltCallback is executed and user can add his own code by customization of function pointer HAL_I2C_MemRxCpltCallback In case of transfer Error, HAL_I2C_ErrorCallback() function is executed and user can add his own code by customization of function pointer HAL_I2C_ErrorCallback I2C HAL driver macros list Below the list of most used macros in I2C HAL driver. C peripheral __HAL_I2C_ENABLE: Enable the I2 __HAL_I2C_DISABLE: Disable the I2C peripheral __HAL_I2C_GET_FLAG : Checks whether the specified I2C flag is set or not __HAL_I2C_CLEAR_FLAG : Clear the specified I2C pending flag __HAL_I2C_ENABLE_IT: Enable the specified I2C interrupt C_DISABLE_IT: Disable the specified I2C interrupt __HAL_I2 You can refer to the I2C HAL driver header file for more useful macros I2C Workarounds linked to Silicon Limitation See ErrataSheet to know full silicon limitation list of your product. (#) Workarounds Implemented inside I2C HAL Driver (##) Wrong data read into data register (Polling and Interrupt mode) (##) Start cannot be generated after a ftware events must be managed before the current misplaced Stop (##) Some so byte is being transferred: Workaround: Use DMA in general, except when the Master is receiving a single byte. For Interupt mode, I2C should have the highest "Setup time for a repeated Start priority in the application. (##) Mismatch on the condition" timing parameter: Workaround: Reduce the frequency down to 88 kHz or use the I2C Fast mode if supported by the slave. (##) Data valid time - 2 DocID027328 Rev 1166 271 /

272 HAL UM1850 I2C Generic Driver (tVD;DAT) violated without the OVR flag being set: Workaround: If the sla ve device allows it, use the clock stretching mechanism by programming NoStretchMode = I2C_NOSTRETCH_DISABLE in HAL_I2C_Init. initialization functions - Initialization and de 23.2.2 tion provides a set of functions allowing to initialize and de - initialize the I2Cx This subsec peripheral: User must Implement HAL_I2C_MspInit() function in which he configures all related peripherals resources (CLOCK, GPIO, DMA, IT and NVIC). Call the function HAL_ I2C_Init() to configure the selected device with the selected configuration: Communication Speed Duty cycle Addressing mode Own Address 1 Dual Addressing mode Own Address 2 General call mode Nostretch mode Call the function HAL_I2C_DeInit() to restore the default configuration of the selected I2Cx peripheral. This section contains the following APIs: HAL_I2C_Init() HAL_I2C_DeInit() HAL_I2C_MspInit() HAL_I2C_MspDeInit() 23.2.3 IO operation functions This subsection provides a set of functions allowing to manage the I2C data transfers. 1. Ther e are two modes of transfer: Blocking mode : The communication is performed in the polling mode. The status of all data processing is returned by the same function after finishing transfer. Blocking mode : The communication is performed using Interrupt No - s or DMA. These functions return the status of the transfer startup. The end of the data processing will be indicated through the dedicated I2C IRQ when using Interrupt mode or the DMA IRQ when using DMA mode. Blocking mode functions are : 2. HAL_I2C_Master _Transmit() HAL_I2C_Master_Receive() HAL_I2C_Slave_Transmit() HAL_I2C_Slave_Receive() HAL_I2C_Mem_Write() HAL_I2C_Mem_Read() HAL_I2C_IsDeviceReady() Blocking mode functions with Interrupt are : - 3. No HAL_I2C_Master_Transmit_IT() HAL_I2C_Master_Receive_IT() HAL_I2C_Slave_Transmit_IT() HAL_I2C_Slave_Receive_IT() DocID027328 / 1166 272 Rev 2

273 UM1850 I2C Generic Driver HAL HAL_I2C_Master_Sequential_Transmit_IT() HAL_I2C_Master_Sequential_Receive_IT() HAL_I2C_Slave_Sequential_Transmit_IT() HAL_I2C_Slave_Sequential_Receive_IT() HAL_I2C_Mem_Write_IT() HAL_I2C_Mem_Read_IT() Blocking mode functions with DMA are : - No 4. HAL_I2C_Master_Transmit_DMA() HAL_I2C_Master_Receive_DMA() HAL_I2C_Slave_Transmit_DMA() HAL_I2C_Slave_Receive_DMA() HAL_I2C_Mem_Write_DMA() HAL_I2C_Mem_Read_DMA() d in non Blocking mode: A set of Transfer Complete Callbacks are provide 5. HAL_I2C_MemTxCpltCallback() HAL_I2C_MemRxCpltCallback() HAL_I2C_MasterTxCpltCallback() HAL_I2C_MasterRxCpltCallback() HAL_I2C_SlaveTxCpltCallback() HAL_I2C_SlaveRxCpltCallback() HAL_I2C_ErrorCallback() HAL_I2C_AbortCpltCallback() This section contains the following APIs: HAL_I2C_Master_Transmit() HAL_I2C_Master_Receive() HAL_I2C_Slave_Transmit() HAL_I2C_Slave_Receive() HAL_I2C_Master_Transmit_IT() HAL_I2C_Master_Receive_IT() HAL_I2C_Master_Sequential_Transmit_IT() HAL _I2C_Master_Sequential_Receive_IT() HAL_I2C_Slave_Transmit_IT() HAL_I2C_Slave_Receive_IT() HAL_I2C_Slave_Sequential_Transmit_IT() HAL_I2C_Slave_Sequential_Receive_IT() HAL_I2C_EnableListen_IT() HAL_I2C_DisableListen_IT() HAL_I2C_Master_Transmit_DMA() HAL_I2C_Master_Receive_DMA() HAL_I2C_Master_Abort_IT() HAL_I2C_Slave_Transmit_DMA() HAL_I2C_Slave_Receive_DMA() HAL_I2C_Mem_Write() HAL_I2C_Mem_Read() HAL_I2C_Mem_Write_IT() HAL_I2C_Mem_Read_IT() () HAL_I2C_Mem_Write_DMA HAL_I2C_Mem_Read_DMA() HAL_I2C_IsDeviceReady() HAL_I2C_EV_IRQHandler() HAL_I2C_ER_IRQHandler() 2 DocID027328 Rev 1166 273 /

274 HAL I2C Generic Driver UM1850 HAL_I2C_MasterTxCpltCallback() HAL_I2C_MasterRxCpltCallback() HAL_I2C_SlaveTxCpltCallback() HAL_I2C_SlaveRxCpltCallback() HAL_I2C_AddrCallback() HAL_I2C_ListenCpltCallback() HAL_I2C_MemTxCpltCallback() HAL_I2C_MemRxCpltCallback() HAL_I2C_ErrorCallback() HAL_I2C_AbortCpltCallback() 23.2.4 Peripheral State, Mode and Error functions time the status of the peripheral and the data flow. run This subsection permits to get in - This section contains the following APIs: HAL_I2C_GetState() HAL_I2C_GetMode() HAL_I2C_GetError() etailed description of functions D 23.2.5 HAL_I2C_Init HAL_StatusTypeDef HAL_I2C_Init (I2C_HandleTypeDef * hi2c) Function name Function description Initializes the I2C according to the specified parameters in the I2C_InitTypeDef and create the associated handle. Parameters pointer to a I2C_HandleTypeDef structure that contains hi2c: the configuration information for I2C module Return values status HAL: HAL_I2C_DeInit HAL_StatusTypeDef HAL_I2C_DeInit (I2C_HandleTypeDef * Function name hi2c) DeInitializes the I2C peripheral. Function description Parameters pointer to a I2C_HandleTypeDef structure that contains hi2c: n for I2C module the configuration informatio Return values HAL: status HAL_I2C_MspInit void HAL_I2C_MspInit (I2C_HandleTypeDef * hi2c) Function name Function description I2C MSP Init. Parameters hi2c: pointer to a I2C_HandleTypeDef structure that contains the configuration information for I2C module Return values None: DocID027328 / 1166 274 Rev 2

275 HAL UM1850 I2C Generic Driver HAL_I2C_MspDeInit void HAL_I2C_MspDeInit (I2C_HandleTypeDef * hi2c) Function name Function description I2C MSP DeInit. Parameters pointer to a I2C_HandleTypeDef structure that contains hi2c: the configuration information for I2C module Return values None: HAL_I2C_Master_Transmit HAL_StatusTypeDef HAL_I2C_Master_Transmit Function name (I2C_HandleTypeDef * hi2c, uint16_t DevAddres s, uint8_t * pData, uint16_t Size, uint32_t Timeout) Function description Transmits in master mode an amount of data in blocking mode. Parameters hi2c: Pointer to a I2C_HandleTypeDef structure that contains the configuration information for the specifi ed I2C. Target device address: The device 7 bits DevAddress: address value in datasheet must be shift at right before call interface pData: Pointer to data buffer Amount of data to be sent Size: Timeout: Timeout duration Return values HAL: status HAL_I2C_Master_Receive HAL_StatusTypeDef HAL_I2C_Master_Receive Function name (I2C_HandleTypeDef * hi2c, uint16_t DevAddress, uint8_t * pData, uint16_t Size, uint32_t Timeout) Function description Receives in master mode an amount of data in blocking mode . Parameters hi2c: Pointer to a I2C_HandleTypeDef structure that contains the configuration information for the specified I2C. DevAddress: Target device address: The device 7 bits address value in datasheet must be shift at right before call interface Pointer to data buffer pData: Size: Amount of data to be sent Timeout: Timeout duration Return values status HAL: HAL_I2C_Slave_Transmit HAL_StatusTypeDef HAL_I2C_Slave_Transmit Function name (I2C_HandleTypeDef * hi2c, uint8_t * pData, uint16_t Size, uint32_t Timeout) Function description Transmits in slave mode an amount of data in blocking mode. Parameters Pointer to a I2C_HandleTypeDef structure that contains hi2c: the configuration information for the specified I2C. fer Pointer to data buf pData: 2 DocID027328 Rev 1166 275 /

276 HAL UM1850 I2C Generic Driver Amount of data to be sent Size: Timeout duration Timeout: Return values status HAL: HAL_I2C_Slave_Receive HAL_StatusTypeDef HAL_I2C_Slave_Receive Function name (I2C_HandleTypeDef * hi2c, uint8_t * pData, uint16_t Size, uint32_t Timeout) Function Receive in slave mode an amount of data in blocking mode. description Parameters hi2c: Pointer to a I2C_HandleTypeDef structure that contains the configuration information for the specified I2C. Pointer to data buffer pData: Amount of data to be sent Size: Timeout: Timeout duration Return values status HAL: HAL_I2C_Mem_Write HAL_StatusTypeDef HAL_I2C_Mem_Write Function name (I2C_HandleTypeDef * hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t * pData, uint16_t 32_t Timeout) Size, uint Write an amount of data in blocking mode to a specific memory Function description address. Parameters hi2c: Pointer to a I2C_HandleTypeDef structure that contains the configuration information for the specified I2C. DevAddress: Target device address MemAddress: Internal memory address MemAddSize: Size of internal memory address pData: Pointer to data buffer Amount of data to be sent Size: Timeout: Timeout duration Return values HAL: status HAL_I2C_Mem_Read HAL_StatusTypeDef HAL_I2C_Mem_Read Function name (I2C_HandleTypeDef * hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t * pData, uint16_t Size, uint32_t Timeout) Function description Read an amount of data in blocking mode from a specific mem ory address. Parameters hi2c: Pointer to a I2C_HandleTypeDef structure that contains the configuration information for the specified I2C. Target device address DevAddress: Internal memory address MemAddress: MemAddSize: Size of internal memory address Pointer to data buffer pData: DocID027328 / 1166 276 Rev 2

277 UM1850 ric Driver HAL I2C Gene Size: Amount of data to be sent Timeout: Timeout duration Return values status HAL: HAL_I2C_IsDeviceReady HAL_StatusTypeDef HAL_I2C_IsDeviceReady Function name (I2C_HandleTypeDef * hi2c, uint16_t DevAddress, uint32_t Trials, uint32_t Timeout) Function description Checks if target device is ready for communication. Parameters hi2c: Pointer to a I2C_HandleTypeDef structure that contains the configuration information for the specified I2C . DevAddress: Target device address Trials: Number of trials Timeout duration Timeout: Return values HAL: status Notes This function is used with Memory devices HAL_I2C_Master_Transmit_IT HAL_StatusTypeDef HAL_I2C_Master_Transmit_IT Function name (I2C_HandleTypeDef * hi2c, uint16_t DevAddress, uint8_t * pData, uint16_t Size) Function description Transmit in master mode an amount of data in non - blocking mode with Interrupt. Parameters Pointer to a I2C_HandleTypeDef structure that contains hi2c: the configuration information for the specified I2C. DevAddress: Target device address: The device 7 bits address value in datasheet must be shift at right before call interface pData: Pointer to data buffer Size: Amount of data to be sent Return values status HAL: HAL_I2C_Master_Receive_IT HAL_StatusTypeDef HAL_I2C_Master_Receive_IT Function name (I2C_HandleTypeDef * hi2c, uint16_t DevAddress, uint8_t * pData, uint16_t Size) Funct blocking mode - Receive in master mode an amount of data in non ion description with Interrupt. Parameters hi2c: Pointer to a I2C_HandleTypeDef structure that contains the configuration information for the specified I2C. : The device 7 bits Target device address DevAddress: address value in datasheet must be shift at right before call interface pData: Pointer to data buffer Size: Amount of data to be sent 2 DocID027328 Rev 1166 277 /

278 HAL UM1850 I2C Generic Driver Return values HAL: status HAL_I2C_Slave_Transmit_IT HAL_StatusTypeDef HAL_I2C_Slave_Transmit_IT Function name (I2C_HandleTypeDef * hi2c, uint8_t * pData, uint16_t Size) Transmit in slave mode an amount of data in non blocking mode Function description - with Interrupt. Parameters hi2c: Pointer to a I2C_HandleTypeDef structure that conta ins the configuration information for the specified I2C. pData: Pointer to data buffer Size: Amount of data to be sent Return values HAL: status HAL_I2C_Slave_Receive_IT HAL_StatusTypeDef HAL_I2C_Slave_Receive_IT Function name (I2C_HandleTypeDef * hi2 c, uint8_t * pData, uint16_t Size) - blocking mode Function description Receive in slave mode an amount of data in non with Interrupt. Parameters hi2c: Pointer to a I2C_HandleTypeDef structure that contains the configuration information for the specified I2C. pData: Pointer to data buffer Size: Amount of data to be sent Return values HAL: status HAL_I2C_Mem_Write_IT HAL_StatusTypeDef HAL_I2C_Mem_Write_IT Function name (I2C_HandleTypeDef * hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t * pData, uint16_t Size) Function description Write an amount of data in non - blocking mode with Interrupt to a specific memory address. Parameters hi2c: Pointer to a I2C_HandleTypeDef structure that contains the configuration information for the specified I2C. DevAddress: Target device address MemAddress: Internal memory address MemAddSize: Size of internal memory address pData: Pointer to data buffer Size: Amount of data to be sent Return values status HAL: HAL_I2C_Mem_Read_IT HAL_StatusTypeDef HAL_I2C_Mem_Read_IT Function name (I2C_HandleTypeDef * hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t * pData, uint16_t Size) DocID027328 / 1166 278 Rev 2

279 UM1850 I2C Generic Driver HAL Function description Read an amount of data in non - blocking mode with Interrupt from a specific memory address. Parameters Pointer to a I2C_HandleTypeDef structure that contains hi2c: the configuration information for the specif ied I2C. Target device address DevAddress: Internal memory address MemAddress: Size of internal memory address MemAddSize: pData: Pointer to data buffer Size: Amount of data to be sent Return values status HAL: HAL_I2C_Master_Sequential_Transmit_IT HAL_StatusTypeDef Function name HAL_I2C_Master_Sequential_Transmit_IT (I2C_HandleTypeDef * hi2c, uint16_t DevAddress, uint8_t * pData, uint16_t Size, uint32_t XferOptions) Sequential transmit in master mode an amount of data in non - Function description locking mode with Interrupt. b Parameters Pointer to a I2C_HandleTypeDef structure that contains hi2c: the configuration information for the specified I2C. Target device address: The device 7 bits DevAddress: address value in datasheet must be shift at r ight before call interface pData: Pointer to data buffer Amount of data to be sent Size: XferOptions: Options of Transfer, value of I2C XferOptions definition Return values status HAL: Notes This interface allow to manage repeated start condition when a direction change during transfer HAL_I2C_Master_Sequential_Receive_IT HAL_StatusTypeDef HAL_I2C_Master_Sequential_Receive_IT Function name (I2C_HandleTypeDef * hi2c, uint16_t DevAddress, uint8_t * pData, uint16_t Size, uint32_t XferOptions) Functi on description Sequential receive in master mode an amount of data in non - blocking mode with Interrupt. Parameters Pointer to a I2C_HandleTypeDef structure that contains hi2c: the configuration information for the specified I2C. ce address: The device 7 bits DevAddress: Target devi address value in datasheet must be shift at right before call interface pData: Pointer to data buffer Amount of data to be sent Size: Options of Transfer, value of I2C XferOptions XferOptions: definition Return values HAL: status 2 DocID027328 Rev 1166 279 /

280 HAL I2C Generic Driver UM1850 Notes This interface allow to manage repeated start condition when a direction change during transfer HAL_I2C_Slave_Sequential_Transmit_IT HAL_StatusTypeDef HAL_I2C_Slave_Sequential_Transmit_IT Function name (I2C_HandleTypeDef * hi2c, uint8_ t * pData, uint16_t Size, uint32_t XferOptions) Function description - Sequential transmit in slave mode an amount of data in no blocking mode with Interrupt. Parameters hi2c: Pointer to a I2C_HandleTypeDef structure that contains the configuration infor mation for I2C module Pointer to data buffer pData: Amount of data to be sent Size: Options of Transfer, value of I2C XferOptions XferOptions: definition Return values HAL: status Notes This interface allow to manage repeated start condition when direction change during transfer a HAL_I2C_Slave_Sequential_Receive_IT HAL_StatusTypeDef HAL_I2C_Slave_Sequential_Receive_IT Function name (I2C_HandleTypeDef * hi2c, uint8_t * pData, uint16_t Size, uint32_t XferOptions) Sequential rece ive in slave mode an amount of data in non - Function description blocking mode with Interrupt. Parameters hi2c: Pointer to a I2C_HandleTypeDef structure that contains the configuration information for the specified I2C. pData: Pointer to data buffer Amount of data to be sent Size: Options of Transfer, value of I2C XferOptions XferOptions: definition Return values status HAL: Notes This interface allow to manage repeated start condition when a direction change during transfer HAL_I2C_Master_Abort_IT HAL_StatusTypeDef HAL_I2C_Master_Abort_IT Function name (I2C_HandleTypeDef * hi2c, uint16_t DevAddress) Function description Abort a master I2C process communication with Interrupt. Parameters s Pointer to a I2C_HandleTypeDef structure that contain hi2c: the configuration information for the specified I2C. Target device address: The device 7 bits DevAddress: address value in datasheet must be shift at right before call interface Return values HAL: status DocID027328 / 1166 280 Rev 2

281 UM1850 HAL I2C Generic Driver Notes is ready This abort can be called only if state HAL_I2C_EnableListen_IT HAL_StatusTypeDef HAL_I2C_EnableListen_IT Function name (I2C_HandleTypeDef * hi2c) Function description Enable the Address listen mode with Interrupt. Parameters hi2c: Pointer to a I2C_HandleTypeDef structure that cont ains the configuration information for the specified I2C. Return values status HAL: HAL_I2C_DisableListen_IT HAL_StatusTypeDef HAL_I2C_DisableListen_IT Function name (I2C_HandleTypeDef * hi2c) Function description Disable the Address listen mode with Interrupt. Parameters hi2c: Pointer to a I2C_HandleTypeDef structure that contains the configuration information for the specified I2C. Return values status HAL: HAL_I2C_Master_Transmit_DMA HAL_StatusTypeDef HAL_I2C_Master_Transmit_DMA Function name (I2C_HandleTypeDef * hi2c, uint16_t DevAddress, uint8_t * pData, uint16_t Size) Function description Transmit in master mode an amount of data in non - blocking mode with DMA. Parameters hi2c: Pointer to a I2 C_HandleTypeDef structure that contains the configuration information for the specified I2C. DevAddress: Target device address: The device 7 bits address value in datasheet must be shift at right before call interface Pointer to data buffer pData: Amount of data to be sent Size: Return values status HAL: HAL_I2C_Master_Receive_DMA HAL_StatusTypeDef HAL_I2C_Master_Receive_DMA Function name (I2C_HandleTypeDef * hi2c, uint16_t DevAddress, uint8_t * pData, uint16_t Size) aster mode an amount of data in non blocking mode Receive in m - Function description with DMA. Parameters Pointer to a I2C_HandleTypeDef structure that contains hi2c: the configuration information for the specified I2C. Target device address: The device 7 bits DevAddress: address value in datasheet must be shift at right before call interface 2 DocID027328 Rev 1166 281 /

282 HAL UM1850 I2C Generic Driver Pointer to data buffer pData: Size: Amount of data to be sent Return values HAL: status HAL_I2C_Slave_Transmit_DMA HAL_StatusTypeDef HAL_I2C_Slave_Transmit_DMA Function name * hi2c, uint8_t * pData, uint16_t Size) (I2C_HandleTypeDef Transmit in slave mode an amount of data in non Function description - blocking mode with DMA. Parameters Pointer to a I2C_HandleTypeDef structure that contains hi2c: I2C. the configuration information for the specified pData: Pointer to data buffer Amount of data to be sent Size: Return values status HAL: HAL_I2C_Slave_Receive_DMA HAL_StatusTypeDef HAL_I2C_Slave_Receive_DMA Function name (I2C_HandleTypeDef * hi2c, uint8_t * pData, uint16_t Size) blocking mode - Receive in slave mode an amount of data in non description Function with DMA. Parameters hi2c: Pointer to a I2C_HandleTypeDef structure that contains the configuration information for the specified I2C. pData: Pointer to data buffer Size: Amount of data to be sent Return values HAL: status HAL_I2C_Mem_Write_DMA HAL_StatusTypeDef HAL_I2C_Mem_Write_DMA Function name (I2C_HandleTypeDef * hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t * pData, uint16_t Size) unction description F - blocking mode with DMA to a Write an amount of data in non specific memory address. Parameters hi2c: Pointer to a I2C_HandleTypeDef structure that contains the configuration information for the specified I2C. DevAddress: Target device address Internal memory address MemAddress: MemAddSize: Size of internal memory address Pointer to data buffer pData: Amount of data to be sent Size: Return values status HAL: HAL_I2C_Mem_Read_DMA HAL_StatusTypeDef HAL_I 2C_Mem_Read_DMA Function name 282 DocID027328 / Rev 2 1166

283 UM1850 HAL I2C Generic Driver (I2C_HandleTypeDef * hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t * pData, uint16_t Size) Function description - blocking mode with DMA from a Reads an amount of data in non specific memory address. Paramete rs hi2c: Pointer to a I2C_HandleTypeDef structure that contains the configuration information for the specified I2C. DevAddress: Target device address Internal memory address MemAddress: Size of internal memory address MemAddSize: Pointer to data buffer pData: Amount of data to be read Size: Return values status HAL: HAL_I2C_EV_IRQHandler void HAL_I2C_EV_IRQHandler (I2C_HandleTypeDef * hi2c) Function name This function handles I2C event interrupt request. Function description Parameters hi2c: Pointer to a I2C_HandleTypeDef structure that contains the configuration information for the specified I2C. Return values None: HAL_I2C_ER_IRQHandler void HAL_I2C_ER_IRQHandler (I2C_HandleTypeDef * hi2c) Function name This function handles I2C error interrupt request. Function description Parameters Pointer to a I2C_HandleTypeDef structure that contains hi2c: the configuration information for the specified I2C. Return values None: HAL_I2C_MasterTxCpltCallback void HAL_I2C_MasterTxCpltCallback (I2C_HandleTypeDef * Function name hi2c) Function description Master Tx Transfer completed callback. Parameters hi2c: Pointer to a I2C_HandleTypeDef structure that contains the configuration information for the specified I2C. Return values None: HAL_I2C_MasterRxCpltCallback void HAL_I2C_MasterRxCpltCallback (I2C_HandleTypeDef * Function name hi2c) Master Rx Transfer completed callback. Function description Parameters Pointer to a I2C_HandleTypeDef structure that con hi2c: tains the configuration information for the specified I2C. 2 DocID027328 Rev 1166 283 /

284 HAL UM1850 I2C Generic Driv er Return values None: HAL_I2C_SlaveTxCpltCallback void HAL_I2C_SlaveTxCpltCallback (I2C_HandleTypeDef * Function name hi2c) Function description Slave Tx Transfer completed callback. Parameters Pointer to a I2C_HandleTypeDef structure that contains hi2c: the configuration information for the specified I2C. Return values None: HAL_I2C_SlaveRxCpltCallback void HAL_I2C_SlaveRxCpltCallback (I2C_HandleTypeDef * Function name hi2c) Slave Rx Transfer completed callback. iption Function descr Parameters Pointer to a I2C_HandleTypeDef structure that contains hi2c: the configuration information for the specified I2C. Return values None: HAL_I2C_AddrCallback void HAL_I2C_AddrCallback (I2C_HandleTypeDef * hi2c, Function name uint8_t TransferDirection, uint16_t AddrMatchCode) Function description Slave Address Match callback. Parameters hi2c: Pointer to a I2C_HandleTypeDef structure that contains the configuration information for the specified I2 C. TransferDirection: Master request Transfer Direction (Write/Read), value of I2C XferOptions definition AddrMatchCode: Address Match Code Return values None: HAL_I2C_ListenCpltCallback void HAL_I2C_ListenCpltCallback (I2C_HandleTypeDef * hi2c) Function name Listen Complete callback. Function description Parameters Pointer to a I2C_HandleTypeDef structure that contains hi2c: the configuration information for the specified I2C. Return values None: HAL_I2C_MemTxCpltCallback _I2C_MemTxCpltCallback (I2C_HandleTypeDef * void HAL Function name hi2c) Memory Tx Transfer completed callback. Function description Parameters Pointer to a I2C_HandleTypeDef structure that contains hi2c: DocID027328 / 1166 284 Rev 2

285 UM1850 HAL I2C Generic Driver the configuration information for the specified I2C. Return values None: HAL_I2C_MemRxCpltCallback void HAL_I2C_MemRxCpltCallback (I2C_HandleTypeDef * Function name hi2c) Function description Memory Rx Transfer completed callback. Parameters Pointer to a I2C_HandleTypeDef structure that contains hi2c: ion information for the specified I2C. the configurat Return values None: HAL_I2C_ErrorCallback void HAL_I2C_ErrorCallback (I2C_HandleTypeDef * hi2c) Function name Function description I2C error callback. Parameters Pointer to a I2C_HandleTypeDef structure that contains hi2c: the configuration information for the specified I2C. Return values None: HAL_I2C_AbortCpltCallback void HAL_I2C_AbortCpltCallback (I2C_HandleTypeDef * hi2c) Function name Function description I2C abort callback. Parameters hi2c: Pointer to a I2C_HandleTypeDef structure that contains the configuration information for the specified I2C. Return values None: HAL_I2C_GetState HAL_I2C_StateTypeDef HAL_I2C_GetState Function name (I2C_HandleTypeDef * hi2c) Function description Return the I2C handle state. Parameters hi2c: Pointer to a I2C_HandleTypeDef structure that contains the configuration information for the specified I2C. Return values HAL: state HAL_I2C_GetMode HAL_I2C_ModeTypeDef HAL_I2C_GetMode Function name (I2C_HandleTypeDef * hi2c) Return the I2C Master, Slave, Memory or no mode. Function description Parameters hi2c: Pointer to a I2C_HandleTypeDef structure that contains the configuration information for I2C module eturn values R HAL: mode 2 DocID027328 Rev 1166 285 /

286 HAL I2C Generic Driver UM1850 HAL_I2C_GetError uint32_t HAL_I2C_GetError (I2C_HandleTypeDef * hi2c) Function name Return the I2C error code. Function description Parameters Pointer to a I2C_HandleTypeDef structure that contains hi2c: the configuration infor mation for the specified I2C. Return values Error Code I2C: 23.3 I2C Firmware driver defines 23.3.1 I2C I2C addressing mode I2C_ADDRESSINGMODE_7BIT I2C_ADDRESSINGMODE_10BIT addressing mode I2C dual I2C_DUALADDRESS_DISABLE I2C_DUALADDRESS_ENABLE I2C duty cycle in fast mode I2C_DUTYCYCLE_2 I2C_DUTYCYCLE_16_9 I2C Error Code HAL_I2C_ERROR_NONE No error BERR error HAL_I2C_ERROR_BERR HAL_I2C_ERROR_ARLO ARLO error HAL_I2C_ERROR_AF AF error OVR error HAL_I2C_ERROR_OVR HAL_I2C_ERROR_DMA DMA transfer error HAL_I2C_ERROR_TIMEOUT Timeout Error I2C Exported Macros Description: __HAL_I2C_RESET_HANDLE_STATE Reset I2C handle state. Parameters: __HANDLE__: specifies the I2C Handle. This parameter can be I2C where x: 1, 2, or 3 to select the I2C peripheral. Return value: None Description: __HAL_I2C_ENABLE_IT Enable or disable the specified I2C DocID027328 / 1166 286 Rev 2

287 UM1850 I2C Generic Driver HAL interrupts. Parameters: __HANDLE__: specifies the I2C Handle. This parameter can be I2C where x: 1, 2, or 3 to select the I2C peripheral. __INTERRUPT__: specifies the interrupt source to enable or disable. This parameter can be one of the following values: I2C_IT_BUF: Buffer interrupt enable nable I2C_IT_EVT: Event interrupt e I2C_IT_ERR: Error interrupt enable Return value: None __HAL_I2C_DISABLE_IT Description: __HAL_I2C_GET_IT_SOURCE Checks if the specified I2C interrupt source is enabled or disabled. Parameters: __HANDLE__: specifies the I2C Handle. can be I2C where x: 1, 2, or This parameter 3 to select the I2C peripheral. __INTERRUPT__: specifies the I2C interrupt source to check. This parameter can be one of the following values: I2C_IT_BUF: Buffer interrupt enable I2C_IT_EVT: Event interrupt enable I2C_IT_ERR: Error interrupt enable Return value: The: new state of __INTERRUPT__ (TRUE or FALSE). Description: __HAL_I2C_GET_FLAG Checks whether the specified I2C flag is set or not. Parameters: __HANDLE__: specifies the I2C Handle. 1, 2, or This parameter can be I2C where x: 3 to select the I2C peripheral. __FLAG__: specifies the flag to check. This parameter can be one of the following values: I2C_FLAG_SMBALERT: SMBus Alert flag I2C_FLAG_TIMEOUT: Timeout or Tlow error flag I2C_FLAG_PECERR: PEC error in reception flag 2 DocID027328 Rev 1166 287 /

288 I2C Generic Driver HAL UM1850 I2C_FLAG_OVR: Overrun/Underrun flag I2C_FLAG_AF: Acknowledge failure flag I2C_FLAG_ARLO: Arbitration lost flag I2C_FLAG_BERR: Bus error flag I2C_FLAG_TXE: Data register empty flag I2C_FLAG_RXNE: Data register not empty flag I2C_FLAG_STOPF: Stop detect ion flag bit header sent - I2C_FLAG_ADD10: 10 flag I2C_FLAG_BTF: Byte transfer finished flag I2C_FLAG_ADDR: Address sent flag Address matched flag I2C_FLAG_SB: Start bit flag I2C_FLAG_DUALF: Dual flag I2C_FLAG_SMBHOST: SMBus host header SMBus I2C_FLAG_SMBDEFAULT: default header I2C_FLAG_GENCALL: General call header flag I2C_FLAG_TRA: Transmitter/Receiver flag I2C_FLAG_BUSY: Bus busy flag I2C_FLAG_MSL: Master/Slave flag Return value: The: new state of __FLAG__ (TRUE or FALSE). Description: __HAL_I2C_CLEAR_FLAG Clears the I2C pending flags which are cleared by writing 0 in a specific bit. Parameters: __HANDLE__: specifies the I2C Handle. This parameter can be I2C where x: 1, 2, or 3 to select the I2C peripheral. __FLAG__: specifies the flag to clear. This parameter can be any combination of the following values: I2C_FLAG_SMBALERT: SMBus Alert flag I2C_FLAG_TIMEOUT: Timeout or Tlow error flag I2C_FLAG_PECERR: PEC error in reception flag run I2C_FLAG_OVR: Overrun/Under flag (Slave mode) I2C_FLAG_AF: Acknowledge failure DocID027328 / 1166 288 Rev 2

289 HAL UM1850 I2C Generic Driver flag I2C_FLAG_ARLO: Arbitration lost flag (Master mode) I2C_FLAG_BERR: Bus error flag Return value: None Description: __HAL_I2C_CLEAR_ADDRFLAG Clears the I2C ADDR pending flag. Parameters: __HANDLE__: specifies the I2C Handle. This parameter can be I2C where x: 1, 2, or 3 to select the I2C peripheral. Return value: None Description: __HAL_I2C_CLEAR_STOPFLAG Clears the I2C STOPF pending flag. Parameters: __HANDLE__: specifies the I2C Handle. This param eter can be I2C where x: 1, 2, or 3 to select the I2C peripheral. Return value: None Description: __HAL_I2C_ENABLE Enable the I2C peripheral. Parameters: __HANDLE__: specifies the I2C Handle. This parameter can be I2Cx where x: 1 or 2 to select the I2C pe ripheral. Return value: None Description: __HAL_I2C_DISABLE Disable the I2C peripheral. Parameters: __HANDLE__: specifies the I2C Handle. This parameter can be I2Cx where x: 1 or 2 to select the I2C peripheral. Return value: None I2C Flag definition 2 DocID027328 Rev 1166 289 /

290 HAL UM1850 I2C Generic Driver I2C_FLAG_SMBALERT I2C_FLAG_TIMEOUT I2C_FLAG_PECERR I2C_FLAG_OVR I2C_FLAG_AF I2C_FLAG_ARLO I2C_FLAG_BERR I2C_FLAG_TXE I2C_FLAG_RXNE I2C_FLAG_STOPF I2C_FLAG_ADD10 I2C_FLAG_BTF I2C_FLAG_ADDR I2C_FLAG_SB I2C_FLAG_DUALF I2C_FLAG_SMBHOST I2C_FLAG_SMBDEFAULT I2C_FLAG_GENCALL I2C_FLAG_TRA I2C_FLAG_BUSY I2C_FLAG_MSL I2C general call addressing mode I2C_GENERALCALL_DISABLE I2C_GENERALCALL_ENABLE I2C Interrupt configuration definition I2C_IT_BUF I2C_IT_EVT I2C_IT_ERR I2C Private macros to check input parameters IS_I2C_DUTY_CYCLE IS_I2C_ADDRESSING_MODE IS_I2C_DUAL_ADDRESS IS_I2C_GENERAL_CALL IS_I2C_NO_STRETCH IS_I2C_MEMADD_SIZE IS_I2C_CLOCK_SPEED DocID027328 / 1166 290 Rev 2

291 UM1850 I2C Generic Driver HAL IS_I2C_OWN_ADDRESS1 IS_I2C_OWN_ADDRESS2 IS_I2C_TRANSFER_OPTIONS_REQUEST I2C Memory Address Size I2C_MEMADD_SIZE_8BIT I2C_MEMADD_SIZE_16BIT I2C nostretch mode I2C_NOSTRETCH_DISABLE I2C_NOSTRETCH_ENABLE I2C XferDirection definition I2C_DIRECTION_RECEIVE I2C_DIRECTION_TRANSMIT XferOptions definition I2C I2C_FIRST_FRAME I2C_NEXT_FRAME I2C_FIRST_AND_LAST_FRAME I2C_LAST_FRAME 2 DocID027328 Rev 1166 291 /

292 I2S Generic Driver HAL UM1850 HAL I2S Generic Driver 24 I2S Firmware driver registers structures 24.1 24.1.1 I2S_InitTypeDef Data Fields uint32_t Mode uint32_t Standard uint32_t DataFormat uint32_t MCLKOutput uint32_t AudioFreq uint32_t CPOL Field Documentation uint32_t I2S_InitTypeDef::Mode I2S_Mode Specifies the I2S operating mode. This parameter can be a value of uint32_t I2S_InitTypeDef::Standard Specifies the standard used for the I2S communication. This parameter can be a I2S_Standard value of uint32_t I2S_InitTypeDef::DataFormat Specifies the data format for the I2S communication. This parameter can be a value of I2S_Data_Format uint32_t I2S_InitTypeDef::MCLKOutput Specifies whether the I2S MCLK output is enabled or not. This parameter can be a value of I2S_MCLK_Output uint32_t I2S_InitTypeDef::AudioFreq Specifies the frequency selected for the I2S communication. This parameter can be a value of I2S_Audio_Frequency uint32_t I2S_InitTypeDef::CPOL Specifies the idle state of the I2S clock. This parameter can be a value of I2S_Clock_Polarity __I2S_HandleTypeDef 24.1.2 Data Fields SPI_TypeDef * Instance I2S_InitTypeDef Init uint16_t * pTxBuffPtr __IO uint16_t TxXferSize __IO uint16_t TxXferCount uint16_t * pRxBuffPtr __IO uint16_t RxXferSize __IO uint16_t RxXferCount void(* IrqHandlerISR DMA_HandleTypeDef * hdmatx DMA_HandleTypeDef * hdmarx __IO HAL_LockTypeDef Lock __IO HAL_I2S_StateTypeDef State __IO uint32_t ErrorCode DocID027328 / 1166 292 Rev 2

293 UM1850 HAL I2S Generic Driver Field Documentation SPI_TypeDef* __I2S_HandleTypeDef::Instance I2S registers base address I2S_InitTypeDef __I2S_HandleTypeDef::Init I2S communication parameters uint16_t* __I2S_HandleTypeDef::pTxBuffPtr Pointer to I2S Tx transfer buffer __IO uint16_t __I2S_HandleTypeDef::TxXferSize I2S Tx transfer size __IO uint16_t __I2S_HandleTypeDef::TxXferCount I2S Tx transfer Counter uint16_t* __I2S_HandleTypeDef::pRxBuffPtr Pointer to I2S Rx transfer buffer __IO uint16_t __I2S_HandleTypeDef::RxXferSize I2S Rx transfer size __IO uint16_t __I2S_HandleTypeDef::RxXferCount ransfer size at I2S Rx transfer counter (This field is initialized at the same value as t the beginning of the transfer and decremented when a sample is received RxBufferCount) NbSamplesReceived = RxBufferSize - void(* __I2S_HandleTypeDef::IrqHandlerISR)(struct __I2S_HandleTypeDef *hi2s) I2S function pointer on IrqHandler DMA_Ha ndleTypeDef* __I2S_HandleTypeDef::hdmatx I2S Tx DMA handle parameters DMA_HandleTypeDef* __I2S_HandleTypeDef::hdmarx I2S Rx DMA handle parameters __IO HAL_LockTypeDef __I2S_HandleTypeDef::Lock I2S locking object __IO HAL_I2S_StateTypeDef __I2S_HandleTyp eDef::State I2S communication state __IO uint32_t __I2S_HandleTypeDef::ErrorCode I2S Error code This parameter can be a value of I2S_ErrorCode 24.2 I2S Firmware driver API description How 24.2.1 to use this driver The I2S HAL driver can be used as follow: 1. Declare a I2S_HandleTypeDef handle structure. Initialize the I2S low level resources by implement the HAL_I2S_MspInit() API: 2. a. Enable the SPIx interfa ce clock. I2S pins configuration: b. Enable the clock for the I2S GPIOs. Configure these I2S pins as alternate function. NVIC configuration if you need to use interrupt process (HAL_I2S_Transmit_IT() c. and HAL_I2S_Receive_IT() APIs). interrupt priority. Configure the I2Sx Enable the NVIC I2S IRQ handle. d. DMA Configuration if you need to use DMA process (HAL_I2S_Transmit_DMA() and HAL_I2S_Receive_DMA() APIs: Declare a DMA handle structure for the Tx/Rx Channel. Enable the DMAx interface clock. Configure t he declared DMA handle structure with the required Tx/Rx parameters. 2 DocID027328 Rev 1166 293 /

294 HAL I2S Generic Driver UM1850 Configure the DMA Tx/Rx Channel. Associate the initialized DMA handle to the I2S DMA Tx/Rx handle. Configure the priority and enable the NVIC for the transfer complete interrupt MA Tx/Rx Channel. on the D 3. Program the Mode, Standard, Data Format, MCLK Output, Audio frequency and Polarity using HAL_I2S_Init() function. The specific I2S interrupts (Transmission he complete interrupt, RXNE interrupt and Error Interrupts) will be managed using t macros __HAL_I2S_ENABLE_IT() and __HAL_I2S_DISABLE_IT() inside the transmit and receive process. The I2SxCLK source is the system clock (provided by the HSI, the HSE or the PLL, and sourcing the AHB clock). For connectivity line devices, the rce can be either SYSCLK or the PLL3 VCO (2 x PLL3CLK) clock in I2SxCLK sou External clock source order to achieve the maximum accuracy. Make sure that either: is configured after setting correctly the define constant HSE_VALUE in the stm32f1xx_hal_conf.h file. 4. operation modes are available within this driver : Three Polling mode IO operation Send an amount of data in blocking mode using HAL_I2S_Transmit() Receive an amount of data in blocking mode using HAL_I2S_Receive() Interrupt mode IO operation f data in non blocking mode using HAL_I2S_Transmit_IT() Send an amount o At transmission end of half transfer HAL_I2S_TxHalfCpltCallback is executed and user can add his own code by customization of function pointer HAL_I2S_TxHalfCpltCallback r HAL_I2S_TxCpltCallback is executed and user can At transmission end of transfe add his own code by customization of function pointer HAL_I2S_TxCpltCallback Receive an amount of data in non blocking mode using HAL_I2S_Receive_IT() lback is executed and user At reception end of half transfer HAL_I2S_RxHalfCpltCal can add his own code by customization of function pointer HAL_I2S_RxHalfCpltCallback At reception end of transfer HAL_I2S_RxCpltCallback is executed and user can add his own code by customization of function pointer HAL_I2S_RxCpl tCallback In case of transfer Error, HAL_I2S_ErrorCallback() function is executed and user can add his own code by customization of function pointer HAL_I2S_ErrorCallback DMA mode IO operation Send an amount of data in non blocking mode (DMA) using HAL_I2 S_Transmit_DMA() At transmission end of half transfer HAL_I2S_TxHalfCpltCallback is executed and user can add his own code by customization of function pointer HAL_I2S_TxHalfCpltCallback At transmission end of transfer HAL_I2S_TxCpltCallback is executed and user can add his own code by customization of function pointer HAL_I2S_TxCpltCallback Receive an amount of data in non blocking mode (DMA) using HAL_I2S_Receive_DMA() At reception end of half transfer HAL_I2S_RxHalfCpltCallback is executed and user can add his own code by customization of function pointer HAL_I2S_RxHalfCpltCallback At reception end of transfer HAL_I2S_RxCpltCallback is executed and user can add his own code by customization of function pointer HAL_I2S_RxCpltCallback DocID027328 / 1166 294 Rev 2

295 UM1850 I2S Generic Driver HAL In case of transfer Error, HAL_I2S_ErrorCallback() function is executed and user can add his own code by customization of function pointer HAL_I2S_ErrorCallback Pause the DMA Transfer using HAL_I2S_DMAPause() Resume the DMA Transfer using HAL_I2S_DMAResume() sfer using HAL_I2S_DMAStop() Stop the DMA Tran I2S HAL driver macros list Below the list of most used macros in I2S HAL driver. __HAL_I2S_ENABLE: Enable the specified SPI peripheral (in I2S mode) __HAL_I2S_DISABLE: Disable the specified SPI peripheral (in I2S mode) __HAL _I2S_ENABLE_IT : Enable the specified I2S interrupts __HAL_I2S_DISABLE_IT : Disable the specified I2S interrupts __HAL_I2S_GET_FLAG: Check whether the specified I2S flag is set or not You can refer to the I2S HAL driver header file for more useful macros I2C Workarounds linked to Silicon Limitation - Only the 16 bit mode with no data extension can be used when the I2S is in Master and used the PCM long synchronization mode. - initialization functions 24.2.2 Initialization and de This subsection provides a set of functions allowing to initialize and de - initialize the I2Sx peripheral in simplex mode: nt HAL_I2S_MspInit() function in which he configures all related User must Impleme peripherals resources (CLOCK, GPIO, DMA, IT and NVIC ). Call the function HAL_I2S_Init() to configure the selected device with the selected configuration: Mode Standard Data Format put MCLK Out Audio frequency Polarity Call the function HAL_I2S_DeInit() to restore the default configuration of the selected I2Sx peripheral. This section contains the following APIs: HAL_I2S_Init() HAL_I2S_DeInit() HAL_I2S_MspInit() HAL_I2S_MspDeInit() IO operation functions 24.2.3 This subsection provides a set of functions allowing to manage the I2S data transfers. 2 DocID027328 Rev 1166 295 /

296 HAL UM1850 I2S Generic Driver There are two modes of transfer: 1. Blocking mode : The communication is performed in the polling mode. The status n after finishing transfer. of all data processing is returned by the same functio Blocking mode : The communication is performed using Interrupts or DMA. - No These functions return the status of the transfer startup. The end of the data rrupt processing will be indicated through the dedicated I2S IRQ when using Inte mode or the DMA IRQ when using DMA mode. 2. Blocking mode functions are : HAL_I2S_Transmit() HAL_I2S_Receive() Blocking mode functions with Interrupt are : - 3. No HAL_I2S_Transmit_IT() HAL_I2S_Receive_IT() Blocking mode functions with DMA are : 4. No - HAL_I2S_Transmit_DMA() HAL_I2S_Receive_DMA() 5. A set of Transfer Complete Callbacks are provided in non Blocking mode: HAL_I2S_TxCpltCallback() HAL_I2S_RxCpltCallback() HAL_I2S_ErrorCallback() This section contains the following APIs: HAL_I2S_Transmit() HAL_I2S_Receive() HAL_I2S_Transmit_IT() HAL_I2S_Receive_IT() HAL_I2S_Transmit_DMA() HAL_I2S_Receive_DMA() HAL_I2S_DMAPause() HAL_I2S_DMAResume() HAL_I2S_DMAStop() HAL_I2S_IRQHan dler() HAL_I2S_TxHalfCpltCallback() HAL_I2S_TxCpltCallback() HAL_I2S_RxHalfCpltCallback() HAL_I2S_RxCpltCallback() HAL_I2S_ErrorCallback() 24.2.4 Peripheral State and Errors functions - This subsection permits to get in run time the status of the peripheral and the data flow. contains the following APIs: This section HAL_I2S_GetState() HAL_I2S_GetError() Detailed description of functions 24.2.5 HAL_I2S_Init I2S_Init (I2S_HandleTypeDef * hi2s) HAL_StatusTypeDef HAL_ Function name Function description Initializes the I2S according to the specified parameters in the I2S_InitTypeDef and create the associated handle. DocID027328 / 1166 296 Rev 2

297 UM1850 HAL I2S Generic Driver Parameters pointer to a I2S_HandleTypeDef structure that contains hi2s: the configuration information for I2S module Return values HAL: status HAL_I2S_DeInit HAL_StatusTypeDef HAL_I2S_DeInit (I2S_HandleTypeDef * Function name hi2s) he I2S peripheral. Function description DeInitializes t Parameters pointer to a I2S_HandleTypeDef structure that contains hi2s: the configuration information for I2S module Return values HAL: status HAL_I2S_MspInit void HAL_I2S_MspInit (I2S_HandleTypeDef * hi2s) Function name Function I2S MSP Init. description Parameters pointer to a I2S_HandleTypeDef structure that contains hi2s: the configuration information for I2S module Return values None: HAL_I2S_MspDeInit void HAL_I2S_MspDeInit (I2S_HandleTypeDef * hi2s) Function name I2S MSP DeInit. Function description Parameters hi2s: pointer to a I2S_HandleTypeDef structure that contains the configuration information for I2S module Return values None: HAL_I2S_Transmit HAL_StatusTypeDef HAL_I2S_Transmit (I2S_HandleTypeDef * Function name hi2s, uint16_t * pData, uint16_t Size, uint32_t Timeout) Function description Transmit an amount of data in blocking mode. Parameters pointer to a I2S_HandleTypeDef structure that contains hi2s: the configuration information for I2 S module - pData: a 16 bit pointer to data buffer. Size: number of data sample to be sent: Timeout: Timeout duration Return values HAL: status Notes When a 16 bit data frame extended is - bit data frame or a 16 - selected during the I2S configuration phase, the Size bit data length in the - parameter means the number of 16 bit data - transaction and when a 24 - bit data frame or a 32 frame is selected the Size parameter means the number of bit data length. - 16 The I2S is kept enabled at the end of transaction to avoid the 2 DocID027328 Rev 1166 297 /

298 HAL UM1850 I2S Generic Driver synchronization between Master and Slave(example: - clock de audio streaming). HAL_I2S_Receive HAL_StatusTypeDef HAL_I2S_Receive (I2S_HandleTypeDef * Function name hi2s, uint16_t * pData, uint16_t Size, uint32_t Timeout) Receive an amount of data in blocking mode. Function description Parameters pointer to a I2S_HandleTypeDef structure that contains hi2s: the configuration information for I2S module bit pointer to data buffer pData: a 16 - Size: number of data sample to be sent: Timeout duration Timeout: Return values HAL: status Notes - bit data frame extended is - bit data frame or a 16 When a 16 selected during the I2S configuration phase, the Size parameter means the number of 16 bit data length in the - - bit data - a frame or a 32 bit dat transaction and when a 24 frame is selected the Size parameter means the number of 16 bit data length. - The I2S is kept enabled at the end of transaction to avoid the - synchronization between Master and Slave(example: clock de audio streaming) In I2S Master R eceiver mode, just after enabling the peripheral the clock will be generate in continuous way and as the I2S is not disabled at the end of the I2S transaction HAL_I2S_Transmit_IT HAL_StatusTypeDef HAL_I2S_Transmit_IT Function name (I2S_HandleTypeDef * hi2 s, uint16_t * pData, uint16_t Size) Function description Transmit an amount of data in non - blocking mode with Interrupt. Parameters pointer to a I2S_HandleTypeDef structure that contains hi2s: the configuration information for I2S module bit pointer to data buffer. - a 16 pData: Size: number of data sample to be sent: Return values HAL: status Notes - bit data frame or a 16 When a 16 - bit data frame extended is selected during the I2S configuration phase, the Size bit data length in the parameter means the number of 16 - - bit data - bit data frame or a 32 transaction and when a 24 frame is selected the Size parameter means the number of bit data length. 16 - The I2S is kept enabled at the end of transaction to avoid the synchronization between - clock de Master and Slave(example: audio streaming). DocID027328 / 1166 298 Rev 2

299 UM1850 I2S Generic Driver HAL HAL_I2S_Receive_IT HAL_StatusTypeDef HAL_I2S_Receive_IT Function name (I2S_HandleTypeDef * hi2s, uint16_t * pData, uint16_t Size) upt. Function description Receive an amount of data in non - blocking mode with Interr Parameters pointer to a I2S_HandleTypeDef structure that contains hi2s: the configuration information for I2S module bit pointer to the Receive data buffer. - a 16 pData: Size: number of data sample to be sent: Return values HAL: status Notes bit data frame extended is - bit data frame or a 16 - When a 16 selected during the I2S configuration phase, the Size parameter means the number of 16 - bit data length in the bit data - bit data frame or a 32 - transaction and when a 24 frame is selected the Size p arameter means the number of 16 bit data length. - The I2S is kept enabled at the end of transaction to avoid the synchronization between Master and Slave(example: clock de - audio streaming). It is recommended to use DMA for the I2S receiver to avoid ronisation between Master and Slave otherwise the synch - de I2S interrupt should be optimized. HAL_I2S_IRQHandler void HAL_I2S_IRQHandler (I2S_HandleTypeDef * hi2s) Function name This function handles I2S interrupt request. Function description Parameters hi2s: pointer to a I2S_HandleTypeDef structure that contains the configuration information for I2S module Return values None: HAL_I2S_Transmit_DMA HAL_StatusTypeDef HAL_I2S_Transmit_DMA Function name (I2S_HandleTypeDef * hi2s, uint16_t * pData, uint16_t Size) - blocking mode with DMA. Function description Transmit an amount of data in non Parameters hi2s: pointer to a I2S_HandleTypeDef structure that contains the configuration information for I2S module bit pointer to the Transmit data buff pData: a 16 - er. Size: number of data sample to be sent: Return values HAL: status Notes When a 16 - bit data frame or a 16 - bit data frame extended is selected during the I2S configuration phase, the Size - bit data length in the parameter means the number of 16 - transaction and when a 24 bit data - bit data frame or a 32 frame is selected the Size parameter means the number of bit data length. - 16 The I2S is kept enabled at the end of transaction to avoid the synchronization between Master and Slave(example: - clock de 2 DocID027328 Rev 1166 299 /

300 HAL UM1850 I2S Generic Driver audio streaming). HAL_I2S_Receive_DMA HAL_StatusTypeDef HAL_I2S_Receive_DMA Function name (I2S_HandleTypeDef * hi2s, uint16_t * pData, uint16_t Size) Receive an amount of data in non - Function description blocking mode with DMA. Parameters hi2s: pointer to a I2S_HandleTypeDef structure that contains the configuration information for I2S module pData: a 16 - bit pointer to the Receive data buffer. number of data sample to be sent: Size: Return values HAL: status Notes bit data frame extended is r a 16 - - When a 16 bit data frame o selected during the I2S configuration phase, the Size bit data length in the - parameter means the number of 16 - bit data - bit data frame or a 32 transaction and when a 24 of frame is selected the Size parameter means the number - 16 bit data length. The I2S is kept enabled at the end of transaction to avoid the clock de - synchronization between Master and Slave(example: audio streaming). HAL_I2S_DMAPause HAL_StatusTypeDef HAL_I2S_DMAPause Function name (I2S_HandleTypeDef * hi2s) Pauses the audio channel playing from the Media. Function description Parameters hi2s: pointer to a I2S_HandleTypeDef structure that contains the configuration information for I2S module Return values status HAL: HAL_I2S_DMAResume _StatusTypeDef HAL_I2S_DMAResume HAL Function name (I2S_HandleTypeDef * hi2s) Function description Resumes the audio channel playing from the Media. Parameters hi2s: pointer to a I2S_HandleTypeDef structure that contains the configuration information for I2S module Return values status HAL: HAL_I2S_DMAStop HAL_StatusTypeDef HAL_I2S_DMAStop (I2S_HandleTypeDef Function name * hi2s) Resumes the audio channel playing from the Media. Function description Parameters hi2s: pointer to a I2S_HandleTypeDef structure that contains the configuration information for I2S module DocID027328 / 1166 300 Rev 2

301 UM1850 HAL I2S Generic Driver Return values HAL: status HAL_I2S_TxHalfCpltCallback void HAL_I2S_TxHalfCpltCallback (I2S_HandleTypeDef * hi2s) Function name Tx Transfer Half completed callbacks. Function description Parameters pointer to a I2S_HandleTypeDef structure that contains hi2s: the configuration information for I2S module Return values None: HAL_I2S_TxCpltCallback eTypeDef * hi2s) void HAL_I2S_TxCpltCallback (I2S_Handl Function name Tx Transfer completed callbacks. Function description Parameters pointer to a I2S_HandleTypeDef structure that contains hi2s: the configuration information for I2S module Return values None: HAL_I2S_RxHalfCpltCallback void HAL_I2S_RxHalfCpltCallback (I2S_HandleTypeDef * hi2s) Function name Function description Rx Transfer half completed callbacks. Parameters hi2s: pointer to a I2S_HandleTypeDef structure that contains the configuration information for I2S module Return values ne: No HAL_I2S_RxCpltCallback void HAL_I2S_RxCpltCallback (I2S_HandleTypeDef * hi2s) Function name Function description Rx Transfer completed callbacks. Parameters pointer to a I2S_HandleTypeDef structure that contains hi2s: the configuration information for I2S module Return values None: HAL_I2S_ErrorCallback void HAL_I2S_ErrorCallback (I2S_HandleTypeDef * hi2s) Function name I2S error callbacks. Function description Parameters pointer to a I2S_HandleTypeDef structure that contains hi2s: the configuration information for I2S module Return values None: HAL_I2S_GetState HAL_I2S_StateTypeDef HAL_I2S_GetState Function name Rev 2 301 / 1166 DocID027328

302 HAL I2S Generic Driver UM1850 (I2S_HandleTypeDef * hi2s) Function description Return the I2S state. Parameters hi2s: pointer to a I2S_HandleTypeDef structure that contains the configuration information for I2S module Return values state HAL: HAL_I2S_GetError uint32_t HAL_I2S_GetError ( I2S_HandleTypeDef * hi2s) Function name Function description Return the I2S error code. Parameters pointer to a I2S_HandleTypeDef structure that contains hi2s: the configuration information for I2S module Return values Error Code I2S: I2S Firmware driver defines 24.3 24.3.1 I2S I2S Audio Frequency I2S_AUDIOFREQ_192K I2S_AUDIOFREQ_96K I2S_AUDIOFREQ_48K I2S_AUDIOFREQ_44K I2S_AUDIOFREQ_32K I2S_AUDIOFREQ_22K I2S_AUDIOFREQ_16K I2S_AUDIOFREQ_11K I2S_AUDIOFREQ_8K I2S_AUDIOFREQ_DEFAULT I2S Clock Polarity I2S_CPOL_LOW I2S_CPOL_HIGH I2S Data Format I2S_DATAFORMAT_16B I2S_DATAFORMAT_16B_EXTENDED I2S_DATAFORMAT_24B I2S_DATAFORMAT_32B I2S Error Code No error HAL_I2S_ERROR_NONE HAL_I2S_ERROR_TIMEOUT Timeout error DocID027328 / 1166 302 Rev 2

303 UM1850 I2S Generic Driver HAL OVR error HAL_I2S_ERROR_OVR HAL_I2S_ERROR_UDR UDR error DMA transfer error HAL_I2S_ERROR_DMA HAL_I2S_ERROR_PRESCALER Prescaler Calculation error I2S Exported Macros Description: __HAL_I2S_RESET_HANDLE_STATE Reset I2S handle state. Parameters: __HANDLE__: specifies the I2S Handle. Return value: None Description: __HAL_I2S_ENABLE Enable the specified SPI peripheral (in I2S mode). Parameters: __HANDLE__: specifies the I2S Handle. Return value: None Description: __HAL_I2S_DISABLE Disable the specified SPI peripheral (in I2S mode). Parameters: __HANDLE__: specifies the I2S Handle. Return value: None Description: __HAL_I2S_ENABLE_IT Enable the specified I2S interrupts. Parameters: specifies the I2S Handle. __HANDLE__: __INTERRUPT__: specifies the interrupt source to enable or disable. This parameter can be one of the following values: I2S_IT_TXE: Tx buffer empty interrupt enable I2S_IT_RXNE: RX buffer not empty interrupt enable Error interrupt enable I2S_IT_ERR: Return value: None 2 DocID027328 Rev 1166 303 /

304 HAL UM1850 I2S Generic Driver Description: __HAL_I2S_DISABLE_IT Disable the specified I2S interrupts. Parameters: __HANDLE__: specifies the I2S Handle. __INTERRUPT__: specifies the interrupt source to enable or disable. This parameter can be o ne of the following values: I2S_IT_TXE: Tx buffer empty interrupt enable I2S_IT_RXNE: RX buffer not empty interrupt enable I2S_IT_ERR: Error interrupt enable Return value: None Description: __HAL_I2S_GET_IT_SOURCE source Checks if the specified I2S interrupt is enabled or disabled. Parameters: __HANDLE__: specifies the I2S Handle. This parameter can be I2S where x: 1, 2, or 3 to select the I2S peripheral. __INTERRUPT__: specifies the I2S interrupt source to check. This parameter can be one of the follow ing values: I2S_IT_TXE: Tx buffer empty interrupt enable I2S_IT_RXNE: RX buffer not empty interrupt enable I2S_IT_ERR: Error interrupt enable Return value: The: new state of __IT__ (TRUE or FALSE). Description: __HAL_I2S_GET_FLAG fied I2S flag is set Checks whether the speci or not. Parameters: __HANDLE__: specifies the I2S Handle. __FLAG__: specifies the flag to check. This parameter can be one of the following values: I2S_FLAG_RXNE: Receive buffer not empty flag I2S_FLAG_TXE: Transmit buffer empty flag I2S_FLAG_UDR: Underrun flag I2S_FLAG_OVR: Overrun flag I2S_FLAG_FRE: Frame error flag DocID027328 / 1166 304 Rev 2

305 UM1850 I2S Generic Driver HAL I2S_FLAG_CHSIDE: Channel Side flag I2S_FLAG_BSY: Busy flag Return value: The: new state of __FLAG__ (TRUE or FALSE). Description: __HAL_I2S_CLEAR_OVRFLAG OVR pending flag. Clears the I2S Parameters: __HANDLE__: specifies the I2S Handle. Return value: None Description: __HAL_I2S_CLEAR_UDRFLAG Clears the I2S UDR pending flag. Parameters: __HANDLE__: specifies the I2S Handle. Return value: None I2S Flags Definition I2S_FLAG_TXE I2S_FLAG_RXNE I2S_FLAG_UDR I2S_FLAG_OVR I2S_FLAG_FRE I2S_FLAG_CHSIDE I2S_FLAG_BSY I2S Interrupts Definition I2S_IT_TXE I2S_IT_RXNE I2S_IT_ERR I2S Mclk Output I2S_MCLKOUTPUT_ENABLE I2S_MCLKOUTPUT_DISABLE I2S Mode I2S_MODE_SLAVE_TX I2S_MODE_SLAVE_RX I2S_MODE_MASTER_TX I2S_MODE_MASTER_RX 2 DocID027328 Rev 1166 305 /

306 HAL UM1850 I2S Generic Driver I2S Standard I2S_STANDARD_PHILIPS I2S_STANDARD_MSB I2S_STANDARD_LSB I2S_STANDARD_PCM_SHORT I2S_STANDARD_PCM_LONG DocID027328 2 Rev 1166 / 306

307 IRDA Generic Driver UM1850 HAL 25 HAL IRDA Generic Driver 25.1 IRDA Firmware driver registers structures 25.1.1 IRDA_InitTypeDef Data Fields uint32_t BaudRate uint32_t WordLength uint32_t Parity uint32_t M ode uint8_t Prescaler uint32_t IrDAMode Field Documentation uint32_t IRDA_InitTypeDef::BaudRate This member configures the IRDA communication baud rate. The baud rate is computed using the following formula:IntegerDivider = ((PCLKx) / (16 * (hirda - ((uint32_t) IntegerDivider)) * 16) - Init.BaudRate)))FractionalDivider = ((IntegerDivider > + 0.5 uint32_t IRDA_InitTypeDef::WordLength Specifies the number of data bits transmitted or received in a frame. This parameter IRDA_Word_Length can be a value of uint32_t IRDA_InitTypeDef::Parity IRDA_Parity Specifies the parity mode. This parameter can be a value of Note: When parity is enabled, the computed parity is inserted at the MSB position of t he transmitted data (9th bit when the word length is set to 9 data bits; 8th bit when the word length is set to 8 data bits). uint32_t IRDA_InitTypeDef::Mode Specifies whether the Receive or Transmit mode is enabled or disabled. This parameter can be a val ue of IRDA_Transfer_Mode uint8_t IRDA_InitTypeDef::Prescaler Specifies the Prescaler value prescaler value to be programmed in the IrDA low - power Baud Register, for defining pulse width on which burst acceptance/rejection w ill be decided. This value is used as divisor of system clock to achieve required pulse width. uint32_t IRDA_InitTypeDef::IrDAMode Specifies the IrDA mode This parameter can be a value of IRDA_Low_Power 25.1.2 IRDA_HandleTypeDef Data Fields USART_TypeDef * Instance IRDA_InitTypeDef Init uint8_t * pTxBuffPtr uint16_t TxXferSize __IO uint16_t TxXferCount uint8_t * pRxBuffPtr uint16_t RxXferSize __IO uint16_t RxXferCount hdmatx DMA_HandleTypeDef * DMA_HandleTypeDef * hdmarx 2 DocID027328 Rev 1166 307 /

308 HAL UM1850 IRDA Generic Driver HAL_LockTypeDef Lock __IO HAL_IRDA_StateTypeDef gState __IO HAL_IRDA_StateTypeDef RxState __IO uint32_t ErrorCode Field Documentation USART_TypeDef* IRDA_HandleTypeDef::Instance USART registers base address IRDA_InitTypeDef IRDA_HandleTypeDef::Init IRDA communication parameters uint8_t* IRDA_HandleTypeDef::pTxBuffPtr Pointer to IRDA Tx transfer Buffer uint16_t IRDA_HandleTypeDef::TxXferSize IRDA Tx Transfer size __IO uint16_t IRDA_HandleTypeDef::TxXferCount IRDA Tx Transfer Counter uint8_t* IRDA_HandleTypeDef::pRxBuffPtr Pointer to IRDA Rx transfer Buffer uint16_t IRDA_HandleTypeDef::RxXferSize IRDA Rx Transfer size __IO uint16_t IRDA_HandleTypeDef::RxXferCount fer Counter IRDA Rx Trans DMA_HandleTypeDef* IRDA_HandleTypeDef::hdmatx IRDA Tx DMA Handle parameters DMA_HandleTypeDef* IRDA_HandleTypeDef::hdmarx IRDA Rx DMA Handle parameters HAL_LockTypeDef IRDA_HandleTypeDef::Lock Locking object HandleTypeDef::gState __IO HAL_IRDA_StateTypeDef IRDA_ IRDA state information related to global Handle management and also related to Tx operations. This parameter can be a value of HAL_IRDA_StateTypeDef __IO HAL_IRDA_StateTypeDef IRDA_HandleTypeDef::RxState to Rx operations. This parameter can be a value of IRDA state information related HAL_IRDA_StateTypeDef __IO uint32_t IRDA_HandleTypeDef::ErrorCode IRDA Error code 25.2 IRDA Firmware driver API description 25.2.1 How to use this driver The IRDA HAL driver can be used as follows: 1. Declare a IRDA_HandleTypeDef handle structure. Initialize the IRDA low level resources by implementing the HAL_IRDA_MspInit() API: 2. Enable the USARTx interface clock. a. b. IRDA pins configura tion: Enable the clock for the IRDA GPIOs. - Configure the IRDA pins as alternate function pull up. c. NVIC configuration if you need to use interrupt process (HAL_IRDA_Transmit_IT() and HAL_IRDA_Receive_IT() APIs): Configure the USARTx interrupt priority. Enable the NVIC USART IRQ handle. d. DMA Configuration if you need to use DMA process (HAL_IRDA_Transmit_DMA() and HAL_IRDA_Receive_DMA() APIs): DocID027328 / 1166 308 Rev 2

309 HAL UM1850 IRD A Generic Driver Declare a DMA handle structure for the Tx/Rx channel. Enable the DMAx interface clock. Configure the declared DMA handle structure with the required Tx/Rx parameters. Configure the DMA Tx/Rx channel. Associate the initialized DMA handle to the IRDA DMA Tx/Rx handle. Configure the priority and enable the NVIC for the transfer complete interrupt on the DMA Tx/Rx channe l. Configure the IRDAx interrupt priority and enable the NVIC USART IRQ handle (used for last byte sending completion detection in DMA non circular mode) 3. Program the Baud Rate, Word Length, Parity, IrDA Mode, Prescaler and e hirda Init structure. Mode(Receiver/Transmitter) in th 4. Initialize the IRDA registers by calling the HAL_IRDA_Init() API: This API configures also the low level Hardware GPIO, CLOCK, CORTEX...etc) by calling the customized HAL_IRDA_MspInit() API. The specific IRDA interrupts (Transmission complete interrupt, RXNE interrupt and Error Interrupts) will be managed using the macros __HAL_IRDA_ENABLE_IT() and __HAL_IRDA_DISABLE_IT() inside the transmit and receive process. available within this driver : Three operation modes are Polling mode IO operation Send an amount of data in blocking mode using HAL_IRDA_Transmit() Receive an amount of data in blocking mode using HAL_IRDA_Receive() Interrupt mode IO operation Send an amount of data in non blocking mode using HAL_IRDA_Transmit_IT() At transmission end of transfer HAL_IRDA_TxCpltCallback is executed and user can add his own code by customization of function pointer HAL_IRDA_TxCpltCallback ta in non blocking mode using HAL_IRDA_Receive_IT() Receive an amount of da At reception end of transfer HAL_IRDA_RxCpltCallback is executed and user can add his own code by customization of function pointer HAL_IRDA_RxCpltCallback In case of transfer Error, HAL_IRDA_ErrorCallb ack() function is executed and user can add his own code by customization of function pointer HAL_IRDA_ErrorCallback DMA mode IO operation Send an amount of data in non blocking mode (DMA) using HAL_IRDA_Transmit_DMA() At transmission end of half transfe r HAL_IRDA_TxHalfCpltCallback is executed and user can add his own code by customization of function pointer HAL_IRDA_TxHalfCpltCallback At transmission end of transfer HAL_IRDA_TxCpltCallback is executed and user can function pointer HAL_IRDA_TxCpltCallback add his own code by customization of Receive an amount of data in non blocking mode (DMA) using HAL_IRDA_Receive_DMA() At reception end of half transfer HAL_IRDA_RxHalfCpltCallback is executed and user can add his own code by customization of function pointer HAL_IRDA_RxHalfCpltCallback 2 DocID027328 Rev 1166 309 /

310 IRDA Generic Driver HAL UM1850 At reception end of transfer HAL_IRDA_RxCpltCallback is executed and user can add his own code by customization of function pointer HAL_IRDA_RxCpltCallback s executed and user In case of transfer Error, HAL_IRDA_ErrorCallback() function i can add his own code by customization of function pointer HAL_IRDA_ErrorCallback Pause the DMA Transfer using HAL_IRDA_DMAPause() Resume the DMA Transfer using HAL_IRDA_DMAResume() Stop the DMA Transfer using HAL_IRDA_DMAStop() L driver macros list IRDA HA Below the list of most used macros in IRDA HAL driver. __HAL_IRDA_ENABLE: Enable the IRDA peripheral __HAL_IRDA_DISABLE: Disable the IRDA peripheral __HAL_IRDA_GET_FLAG : Check whether the specified IRDA flag is set or not __HAL_IRD A_CLEAR_FLAG : Clear the specified IRDA pending flag __HAL_IRDA_ENABLE_IT: Enable the specified IRDA interrupt __HAL_IRDA_DISABLE_IT: Disable the specified IRDA interrupt __HAL_IRDA_GET_IT_SOURCE: Check whether the specified IRDA interrupt has occurred or not You can refer to the IRDA HAL driver header file for more useful macros remark: If the parity is enabled, then the MSB bit of the data written i Additional n the data register is transmitted but is changed by the parity bit. T he IRDA frame bits). Refer to - depend on the frame length defined by the M bit (8 bits or 9 - formats the product reference manual for details. 25.2.2 Initialization and Configuration functions This subsection provides a set of functions allowing to initialize the USARTx or the UARTy in IrDA mode. For the asynchronous mode only these parameters can be configured: BaudRate ength WordL Parity: If the parity is enabled, then the MSB bit of the data written in the data register is transmitted but is changed by the parity bit. Depending on the frame bits), please refer to Reference manual for - bits or 9 - length defined by the M bit (8 possible IRDA frame formats. Prescaler: A pulse of width less than two and greater than one PSC period(s) may or may not be rejected. The receiver set up time should be managed by software. The IrDA physical layer specification specifies a minimum of 10 ms delay between transmission and reception (IrDA is a half duplex protocol). Mode: Receiver/transmitter modes IrDAMode: the IrDA can operate in the Normal mode or in the Low power mode. The HAL_IRDA_Init() API follows IRDA configuration procedures (details for the procedures are available in reference manual). This section contains the following APIs: DocID027328 / 1166 310 Rev 2

311 UM1850 IRDA Generic Driver HAL HAL_IRDA_Init() IRDA_DeInit() HAL_ HAL_IRDA_MspInit() HAL_IRDA_MspDeInit() IO operation functions 25.2.3 e IRDA data transfers. This subsection provides a set of functions allowing to manage th IrDA is a half duplex communication protocol. If the Transmitter is busy, any data on the IrDA receive line will be ignored by the IrDA decoder and if the Receiver is busy, data on the TX from the USART to IrDA will not be encoded by IrDA. While receiving data, transmission should be avoided as the data to be transmitted could be corrupted. There are two modes of transfer: 1. Blocking mode: The communication is performed in polling mode. The HAL status of all data processing is returne d by the same function after finishing transfer. - Blocking mode: The communication is performed using Interrupts or DMA, No these APIs return the HAL status. The end of the data processing will be pt mode or the indicated through the dedicated IRDA IRQ when using Interru DMA IRQ when using DMA mode. The HAL_IRDA_TxCpltCallback(), HAL_IRDA_RxCpltCallback() user callbacks will be executed respectively at the end of the transmit or Receive process The HAL_IRDA_ErrorCallback() user callback will be executed when a communication error is detected 2. Blocking mode APIs are: HAL_IRDA_Transmit() HAL_IRDA_Receive() Non Blocking mode APIs with Interrupt are: 3. HAL_IRDA_Transmit_IT() HAL_IRDA_Receive_IT() HAL_IRDA_IRQHandler() Non Blocking mode functions with DMA are: 4. HAL_IRDA_Transmit_DMA() HAL_IRDA_Receive_DMA() HAL_IRDA_DMAPause() HAL_IRDA_DMAResume() HAL_IRDA_DMAStop() 5. A set of Transfer Complete Callbacks are provided in non Blocking mode: HAL_IRDA_TxHalfCpltCallback() HAL_IRDA_TxCpltCallback() HAL_IRDA_RxHalfCpltCallback() HAL_IRDA_RxCpltCallback() HAL_IRDA_ErrorCallback() This section contains the following APIs: HAL_IRDA_Transmit() HAL_IRDA_Receive() HAL_IRDA_Transmit_IT() HAL_IRDA_Receive_IT() HAL_IRDA_Transmit_DMA() HAL_IRDA_Receive_DMA() H AL_IRDA_DMAPause() HAL_IRDA_DMAResume() HAL_IRDA_DMAStop() 2 DocID027328 Rev 1166 311 /

312 HAL UM1850 IRDA Generic Driver HAL_IRDA_Abort() HAL_IRDA_AbortTransmit() HAL_IRDA_AbortReceive() HAL_IRDA_Abort_IT() HAL_IRDA_AbortTransmit_IT() HAL_IRDA_AbortReceive_IT() HAL_IRDA_IRQHan dler() HAL_IRDA_TxCpltCallback() HAL_IRDA_TxHalfCpltCallback() HAL_IRDA_RxCpltCallback() HAL_IRDA_RxHalfCpltCallback() HAL_IRDA_ErrorCallback() HAL_IRDA_AbortCpltCallback() HAL_IRDA_AbortTransmitCpltCallback() HAL_IRDA_AbortReceiveCpltCallback() 25.2.4 Peripheral State and Errors functions This subsection provides a set of functions allowing to return the State of IrDA munication communication process and also return Peripheral Errors occurred during com process time the state of the IrDA - HAL_IRDA_GetState() API can be helpful to check in run peripheral. HAL_IRDA_GetError() check in run - time errors that could be occurred during communication. This section contains the following APIs: HAL_IRDA_GetState() HAL_IRDA_GetError() 25.2.5 Detailed description of functions HAL_IRDA_Init HAL_StatusTypeDef HAL_IRDA_Init (IRDA_HandleTypeDef * Function name rda) hi Initializes the IRDA mode according to the specified parameters in Function description the IRDA_InitTypeDef and create the associated handle. Parameters Pointer to a IRDA_HandleTypeDef structure that hirda: contains the configuration information for the specified IRDA module. Return values status HAL: HAL_IRDA_DeInit HAL_StatusTypeDef HAL_IRDA_DeInit (IRDA_HandleTypeDef Function name * hirda) ption Function descri DeInitializes the IRDA peripheral. Parameters Pointer to a IRDA_HandleTypeDef structure that hirda: contains the configuration information for the specified IRDA module. DocID027328 / 1166 312 Rev 2

313 UM1850 HAL IRDA Generic Driver Return values status HAL: HAL_IRDA_MspInit void HAL_IRDA_MspInit (IRDA_HandleTypeDef * hirda) Function name Function description IRDA MSP Init. Parameters hirda: Pointer to a IRDA_HandleTypeDef structure that contains the configuration information for the specified IRDA module. Return values None: DeInit HAL_IRDA_Msp void HAL_IRDA_MspDeInit (IRDA_HandleTypeDef * hirda) Function name IRDA MSP DeInit. Function description Parameters Pointer to a IRDA_HandleTypeDef structure that hirda: contains the configuration information for the specified IRDA module. Return values None: HAL_IRDA_Transmit HAL_StatusTypeDef HAL_IRDA_Transmit Function name (IRDA_HandleTypeDef * hirda, uint8_t * pData, uint16_t Size, uint32_t Timeout) Function description Sends an amount of data in blocking mode. Parameters hirda: Po inter to a IRDA_HandleTypeDef structure that contains the configuration information for the specified IRDA module. pData: Pointer to data buffer Size: Amount of data to be sent Timeout: Specify timeout value Return values HAL: status HAL_IRDA_Receive HAL_StatusTypeDef HAL_IRDA_Receive Function name (IRDA_HandleTypeDef * hirda, uint8_t * pData, uint16_t Size, uint32_t Timeout) Function description Receive an amount of data in blocking mode. Parameters e that Pointer to a IRDA_HandleTypeDef structur hirda: contains the configuration information for the specified IRDA module. pData: Pointer to data buffer Amount of data to be received Size: Timeout: Specify timeout value Return values status HAL: 2 DocID027328 Rev 1166 313 /

314 HAL UM1850 IRDA Generic Driver HAL_IRDA_Transmit_IT HAL_StatusTypeDef HAL_IRDA_Transmit_IT Function name (IRDA_HandleTypeDef * hirda, uint8_t * pData, uint16_t Size) Function description Sends an amount of data in non blocking mode. Parameters hirda: Pointer to a IRDA_HandleTypeDef structure that contains the configu ration information for the specified IRDA module. Pointer to data buffer pData: Amount of data to be sent Size: Return values status HAL: HAL_IRDA_Receive_IT HAL_StatusTypeDef HAL_IRDA_Receive_IT Function name (IRDA_HandleTypeDef * hirda, uint8_t * pD ata, uint16_t Size) Receives an amount of data in non blocking mode. Function description Parameters Pointer to a IRDA_HandleTypeDef structure that hirda: contains the configuration information for the specified IRDA module. Pointer to data buffer pData: Amount of data to be received Size: Return values HAL: status HAL_IRDA_Transmit_DMA HAL_StatusTypeDef HAL_IRDA_Transmit_DMA Function name (IRDA_HandleTypeDef * hirda, uint8_t * pData, uint16_t Size) Function description Sends a n amount of data in non blocking mode. Parameters hirda: Pointer to a IRDA_HandleTypeDef structure that contains the configuration information for the specified IRDA module. pData: Pointer to data buffer Amount of data to be sent Size: Return values HAL: status HAL_IRDA_Receive_DMA HAL_StatusTypeDef HAL_IRDA_Receive_DMA Function name (IRDA_HandleTypeDef * hirda, uint8_t * pData, uint16_t Size) Function description Receives an amount of data in non blocking mode. Parameters hirda: Pointer to a IRDA_HandleTypeDef structure that contains the configuration information for the specified IRDA module. pData: Pointer to data buffer Amount of data to be received Size: Return values status HAL: DocID027328 / 1166 314 Rev 2

315 UM1850 HAL IRDA Generic Driver Notes (PCE = 1) the data received When the IRDA parity is enabled contain the parity bit. HAL_IRDA_DMAPause HAL_StatusTypeDef HAL_IRDA_DMAPause Function name (IRDA_HandleTypeDef * hirda) Function description Pauses the DMA Transfer. Parameters ure that Pointer to a IRDA_HandleTypeDef struct hirda: contains the configuration information for the specified IRDA module. Return values status HAL: HAL_IRDA_DMAResume HAL_StatusTypeDef HAL_IRDA_DMAResume Function name (IRDA_HandleTypeDef * hirda) Function description Resumes the DMA Transfer. Parameters Pointer to a IRDA_HandleTypeDef structure that hirda: contains the configuration information for the specified IRDA module. Return values HAL: status HAL_IRDA_DMAStop HAL_StatusTypeDef HAL_IRDA_DMAStop Function name rda) (IRDA_HandleTypeDef * hi Function description Stops the DMA Transfer. Parameters hirda: Pointer to a IRDA_HandleTypeDef structure that contains the configuration information for the specified IRDA module. Return values status HAL: HAL_IRDA_Abort HAL_StatusTypeDef HAL_IRDA_Abort (IRDA_HandleTypeDef Function name * hirda) Function description Abort ongoing transfers (blocking mode). Parameters IRDA handle. hirda: Return values status HAL: Notes This procedure could be used for aborting any ongoing transfer started in Interrupt or DMA mode. This procedure performs following operations : Disable PPP InterruptsDisable the DMA transfer in the peripheral register (if enabled)Abort ing HAL_DMA_Abort (in case of transfer DMA transfer by call in DMA mode)Set handle State to READY This procedure is executed in blocking mode : when exiting 2 DocID027328 Rev 1166 315 /

316 UM1850 HAL IRDA Generic Driver function, Abort is considered as completed. HAL_IRDA_AbortTransmit HAL_StatusTypeDef HAL_IRDA_AbortTransmit Function name (IRDA_HandleTypeDef * hirda) Abort ongoing Transmit transfer (blocking mode). Function description Parameters hirda: IRDA handle. Return values HAL: status Notes This procedure could be used for aborting any ongoing tarted in Interrupt or DMA mode. This procedure transfer s performs following operations : Disable PPP InterruptsDisable the DMA transfer in the peripheral register (if enabled)Abort DMA transfer by calling HAL_DMA_Abort (in case of transfer in DMA mode)Set handle St ate to READY This procedure is executed in blocking mode : when exiting function, Abort is considered as completed. HAL_IRDA_AbortReceive HAL_StatusTypeDef HAL_IRDA_AbortReceive Function name (IRDA_HandleTypeDef * hirda) Function description Abort ongoing Receive transfer (blocking mode). Parameters IRDA handle. hirda: Return values HAL: status Notes This procedure could be used for aborting any ongoing transfer started in Interrupt or DMA mode. This procedure ns : Disable PPP InterruptsDisable performs following operatio the DMA transfer in the peripheral register (if enabled)Abort DMA transfer by calling HAL_DMA_Abort (in case of transfer in DMA mode)Set handle State to READY This procedure is executed in blocking mode : when exiting fu nction, Abort is considered as completed. HAL_IRDA_Abort_IT HAL_StatusTypeDef HAL_IRDA_Abort_IT Function name (IRDA_HandleTypeDef * hirda) Abort ongoing transfers (Interrupt mode). Function description Parameters IRDA handle. hirda: Return values status HAL: Notes This procedure could be used for aborting any ongoing transfer started in Interrupt or DMA mode. This procedure performs following operations : Disable PPP InterruptsDisable the DMA transfer in the peripheral register (if enabled)Abort ing HAL_DMA_Abort_IT (in case of DMA transfer by call transfer in DMA mode)Set handle State to READYAt abort completion, call user abort complete callback DocID027328 / 1166 316 Rev 2

317 UM1850 IRDA Generic Driver HAL This procedure is executed in Interrupt mode, meaning that abort procedure could be considered as completed only when r abort complete callback is executed (not when exiting use function). HAL_IRDA_AbortTransmit_IT HAL_StatusTypeDef HAL_IRDA_AbortTransmit_IT Function name (IRDA_HandleTypeDef * hirda) Abort ongoing Transmit transfer (Interrupt mode). Function description arameters P IRDA handle. hirda: Return values status HAL: Notes This procedure could be used for aborting any ongoing transfer started in Interrupt or DMA mode. This procedure performs following operations : Disable PPP InterruptsDisable the DMA transfer in the peripheral register (if enabled)Abort DMA transfer by call ing HAL_DMA_Abort_IT (in case of transfer in DMA mode)Set handle State to READYAt abort completion, call user abort complete callback This procedure is executed in Interrupt mode, meaning that abort procedure could be considered as completed only when r abort complete callback is executed (not when exiting use function). HAL_IRDA_AbortReceive_IT HAL_StatusTypeDef HAL_IRDA_AbortReceive_IT Function name (IRDA_HandleTypeDef * hirda) Function description Abort ongoing Receive transfer (Interrupt mode). Para meters IRDA handle. hirda: Return values HAL: status Notes This procedure could be used for aborting any ongoing transfer started in Interrupt or DMA mode. This procedure performs following operations : Disable PPP InterruptsDisable the DMA transfer in the peripheral register (if enabled)Abort ing HAL_DMA_Abort_IT (in case of DMA transfer by call transfer in DMA mode)Set handle State to READYAt abort completion, call user abort complete callback This procedure is executed in Interrupt mode, meaning that abort procedure could be considered as completed only when r abort complete callback is executed (not when exiting use function). HAL_IRDA_IRQHandler void HAL_IRDA_IRQHandler (IRDA_HandleTypeDef * hirda) Function name This function handles IRDA interrupt request. Function description Parameters Pointer to hirda: a IRDA_HandleTypeDef structure that contains the configuration information for the specified IRDA 2 DocID027328 Rev 1166 317 /

318 IRDA Generic Driver HAL UM1850 module. Return values None: HAL_IRDA_TxCpltCallback void HAL_IRDA_TxCpltCallback (IRDA_HandleTypeDef * Function name hirda) Function description Tx Transfer complete callbacks. Parameters pointer to a IRDA_HandleTypeDef structure that hirda: contains the configuration information for the specified IRDA module. Return values None: HAL_IRDA_RxCpltCallback void HAL_IRDA_RxCpltCallback (IRDA_HandleTypeDef * Function name hirda) Function description Rx Transfer complete callbacks. Parameters hirda: Pointer to a IRDA_HandleTypeDef structure that contains the configuration information for the specified IRDA module. Return val ues None: HAL_IRDA_TxHalfCpltCallback void HAL_IRDA_TxHalfCpltCallback (IRDA_HandleTypeDef * Function name hirda) Tx Half Transfer completed callbacks. Function description Parameters Pointer to a IRDA_HandleTypeDef structure that hirda: contains the configuration information for the specified USART module. Return values None: HAL_IRDA_RxHalfCpltCallback void HAL_IRDA_RxHalfCpltCallback (IRDA_HandleTypeDef * Function name hirda) Rx Half Transfer complete callbacks. description Function Parameters hirda: Pointer to a IRDA_HandleTypeDef structure that contains the configuration information for the specified IRDA module. Return values None: HAL_IRDA_ErrorCallback HAL_IRDA_ErrorCallback (IRDA_HandleTypeDef * hirda) void Function name 318 DocID027328 / Rev 1166 2

319 UM1850 IRDA Generic Driver HAL IRDA error callbacks. Function description Parameters hirda: Pointer to a IRDA_HandleTypeDef structure that contains the configuration information for the specified IRDA module. Return values None: HAL_IRDA_AbortCpltCallback void HAL_IRDA_AbortCpltCallback (IRDA_HandleTypeDef * Function name hirda) Function description IRDA Abort Complete callback. Parameters IRDA handle. hirda: Return values None: HAL_IRDA_AbortTransmitCpltCallback void HAL_IRDA_AbortTransmitCpltCallback name Function (IRDA_HandleTypeDef * hirda) IRDA Abort Transmit Complete callback. Function description Parameters IRDA handle. hirda: Return values None: HAL_IRDA_AbortReceiveCpltCallback HAL_IRDA_AbortReceiveCpltCallback void Function name (IRDA_HandleTypeDef * hirda) Function description IRDA Abort ReceiveComplete callback. Parameters hirda: IRDA handle. Return values None: HAL_IRDA_GetState HAL_IRDA_StateTypeDef HAL_IRDA_GetState Function name (IRDA_HandleTypeDef * hirda) Returns the IRDA state. Function description Parameters hirda: Pointer to a IRDA_HandleTypeDef structure that contains the configuration information for the specified IRDA module. Return values state HAL: or HAL_IRDA_GetErr uint32_t HAL_IRDA_GetError (IRDA_HandleTypeDef * hirda) Function name Return the IRDA error code. Function description Parameters hirda: Pointer to a IRDA_HandleTypeDef structure that contains the configuration information for the specified IRDA 2 DocID027328 Rev 1166 319 /

320 IRDA Generic Driver HAL UM1850 module. Return values IRDA: Error Code IRDA Firmware driver defines 25.3 25.3.1 IRDA IRDA Error Code No error HAL_IRDA_ERROR_NONE HAL_IRDA_ERROR_PE Parity error HAL_IRDA_ERROR_NE Noise error Frame error HAL_IRDA_ERROR_FE Overrun error HAL_IRDA_ERROR_ORE HAL_IRDA_ERROR_DMA DMA transfer error IRDA Exported Macros Description: __HAL_IRDA_RESET_HANDLE_STATE Reset IRDA handle gstate & RxState. Parameters: __HANDLE__: specifies the IRDA Handle. IRDA Handle selects the USARTx or UARTy peripheral (USART,UART availability and x,y values depending on device). Description: __HAL_IRDA_FLUSH_DRREGISTER Flush the IRDA DR register. Parameters: __HANDLE__: specifies the USART Handle. IRDA Handle selects the USARTx or UARTy peripheral (USART,UART availability and x,y values depending on device). escription: D __HAL_IRDA_GET_FLAG Check whether the specified IRDA flag is set or not. Parameters: __HANDLE__: specifies the IRDA Handle. IRDA Handle selects the USARTx or UARTy peripheral (USART,UART availability and x,y values depending on device). g to check. __FLAG__: specifies the fla This parameter can be one of the following values: IRDA_FLAG_TXE: Transmit data DocID027328 / 1166 320 Rev 2

321 UM1850 IRDA Generic Driver HAL register empty flag IRDA_FLAG_TC: Transmission Complete flag IRDA_FLAG_RXNE: Receive data register not empty flag IRDA_FLAG_IDLE: Idle Line detection flag IRDA_FLAG_ORE: OverRun Error flag IRDA_FLAG_NE: Noise Error flag IRDA_FLAG_FE: Framing Error flag IRDA_FLAG_PE: Parity Error flag Return value: The: new state of __FLAG__ (TRUE or FALSE). Description: __HAL_IRDA_CLEAR_FLAG Clear the specified IRDA pending flag. Parameters: __HANDLE__: specifies the IRDA Handle. IRDA Handle selects the USARTx or UARTy peripheral (USART,UART availability and x,y values depending on device). __FLAG__: specifies the flag to check. This parameter can be any combination of the following values: IRDA_FLAG_TC: Transmission Complete flag. IRDA_FLAG_RXNE: Receive data register not empty flag. Notes: PE (Parity error), FE (Framing error), NE (Noise e rror), ORE (OverRun error) and IDLE (Idle line detected) flags are cleared by software sequence: a read operation to USART_SR register followed by a read operation to USART_DR register. RXNE flag can be also cleared by a read to the USART_DR register. TC f lag can be also cleared by software sequence: a read operation to USART_SR register followed by a write operation to USART_DR register. TXE flag is cleared only by a write to the USART_DR register. Description: __HAL_IRDA_CLEAR_PEFLAG pending flag. Clear the IRDA PE Parameters: __HANDLE__: specifies the IRDA Handle. 2 DocID027328 Rev 1166 321 /

322 HAL UM1850 IRDA Generic Driver IRDA Handle selects the USARTx or UARTy peripheral (USART,UART availability and x,y values depending on device). Description: __HAL_IRDA_CLEAR_FEFLAG Clear the IRDA FE pending flag. Paramete rs: __HANDLE__: specifies the IRDA Handle. IRDA Handle selects the USARTx or UARTy peripheral (USART,UART availability and x,y values depending on device). Description: __HAL_IRDA_CLEAR_NEFLAG Clear the IRDA NE pending flag. Parameters: __HANDLE__: specif ies the IRDA Handle. IRDA Handle selects the USARTx or UARTy peripheral (USART,UART availability and x,y values depending on device). Description: __HAL_IRDA_CLEAR_OREFLAG Clear the IRDA ORE pending flag. Parameters: __HANDLE__: specifies the IRDA Handle. IRDA Handle selects the USARTx or UARTy peripheral (USART,UART availability and x,y values depending on device). Description: __HAL_IRDA_CLEAR_IDLEFLAG Clear the IRDA IDLE pending flag. Parameters: __HANDLE__: specifies the IRDA Handle. ts the USARTx or IRDA Handle selec UARTy peripheral (USART,UART availability and x,y values depending on device). Description: __HAL_IRDA_ENABLE_IT Enable the specified IRDA interrupt. Parameters: __HANDLE__: specifies the IRDA Handle. IRDA Handle selects the USARTx or Ty peripheral (USART,UART UAR availability and x,y values depending on device). DocID027328 / 1166 322 Rev 2

323 UM1850 IRDA Generic Driver HAL __INTERRUPT__: specifies the IRDA interrupt source to enable. This parameter can be one of the following values: IRDA_IT_TXE: Transmit Data Register empty interrupt IRDA_IT_TC: Tr ansmission complete interrupt IRDA_IT_RXNE: Receive Data register not empty interrupt IRDA_IT_IDLE: Idle line detection interrupt IRDA_IT_PE: Parity Error interrupt IRDA_IT_ERR: Error interrupt(Frame error, noise error, overrun error) Description: __HAL_IRDA_DISABLE_IT Disable the specified IRDA interrupt. Parameters: __HANDLE__: specifies the IRDA Handle. IRDA Handle selects the USARTx or UARTy peripheral (USART,UART availability and x,y values depending on device). __INTERRUPT__: specifies the IRDA interrupt source to disable. This parameter can be one of the following values: IRDA_IT_TXE: Transmit Data Register empty interrupt IRDA_IT_TC: Transmission complete interrupt IRDA_IT_RXNE: Receive Data register not empty interrupt IRDA_IT_IDLE: Idle line detection interrupt IRDA_IT_PE: Parity Error interrupt IRDA_IT_ERR: Error interrupt(Frame error, noise error, overrun error) Description: __HAL_IRDA_GET_IT_SOURCE Check whether the specified IRDA interrupt has occurred or not. Parameters: __HANDLE__: specifies the IRDA Handle. IRDA Handle selects the USARTx or UARTy peripheral (USART,UART availability and x,y values depending on device). __IT__: specifies the IRDA interrupt source to check. This parameter can be he following values: one of t IRDA_IT_TXE: Transmit Data Register empty interrupt 2 DocID027328 Rev 1166 323 /

324 IRDA Generic Driver HAL UM1850 IRDA_IT_TC: Transmission complete interrupt IRDA_IT_RXNE: Receive Data register not empty interrupt IRDA_IT_IDLE: Idle line detection interrupt IRDA_IT_ERR: Error interrupt E: Parity Error interrupt IRDA_IT_P Return value: The: new state of __IT__ (TRUE or FALSE). Description: __HAL_IRDA_ENABLE Enable UART/USART associated to IRDA Handle. Parameters: __HANDLE__: specifies the IRDA Handle. IRDA Handle selects the USARTx or peripheral (USART,UART UARTy availability and x,y values depending on device). Description: __HAL_IRDA_DISABLE Disable UART/USART associated to IRDA Handle. Parameters: __HANDLE__: specifies the IRDA Handle. IRDA Handle selects the USARTx or SART,UART UARTy peripheral (U availability and x,y values depending on device). IRDA Flags IRDA_FLAG_TXE IRDA_FLAG_TC IRDA_FLAG_RXNE IRDA_FLAG_IDLE IRDA_FLAG_ORE IRDA_FLAG_NE IRDA_FLAG_FE IRDA_FLAG_PE IRDA Interrupt Definitions IRDA_IT_PE IRDA_IT_TXE IRDA_IT_TC DocID027328 / 1166 324 Rev 2

325 UM1850 IRDA Generic Driver HAL IRDA_IT_RXNE IRDA_IT_IDLE IRDA_IT_LBD IRDA_IT_CTS IRDA_IT_ERR IRDA Low Power IRDA_POWERMODE_LOWPOWER IRDA_POWERMODE_NORMAL IRDA Parity IRDA_PARITY_NONE IRDA_PARITY_EVEN IRDA_PARITY_ODD IRDA Transfer Mode IRDA_MODE_RX IRDA_MODE_TX IRDA_MODE_TX_RX IRDA Word Length IRDA_WORDLENGTH_8B IRDA_WORDLENGTH_9B 2 DocID027328 Rev 1166 325 /

326 IWDG Generic Driver HAL UM1850 26 HAL IWDG Generic Driver IWDG Firmware driver registers structures 26.1 IWDG_InitTypeDef 26.1.1 Data Fields uint32_t Prescaler uint32_t Reload Field Documentation uint32_t IWDG_InitTypeDef::Prescaler IWDG_Presca Select the prescaler of the IWDG. This parameter can be a value of ler uint32_t IWDG_InitTypeDef::Reload counter reload value. This parameter must be a number - Specifies the IWDG down between Min_Data = 0 and Max_Data = 0x0FFF 26.1.2 IWDG_HandleTypeDef Data Fields e IWDG_TypeDef * Instanc IWDG_InitTypeDef Init Field Documentation IWDG_TypeDef* IWDG_HandleTypeDef::Instance Register base address IWDG_InitTypeDef IWDG_HandleTypeDef::Init IWDG required parameters 26.2 IWDG Firmware driver API description IWDG Generic features 26.2.1 The IWDG can be started by either software or hardware (configurable through option byte). Speed clock (LSI) and thus stays active even if the main - The IWDG is clocked by Low clock fails. Once the IWDG is started, the LSI is forced ON and both can not be disabled. The counter starts counting down from the reset value (0xFFF). When it reaches the end of count value (0x000) a reset signal is generated (IWDG reset). Whenever the key value 0x0000 AAAA is written in the IWDG_KR register, the IWDG_RLR value is reloaded in the counter and the watchdog reset is prevented. The IWDG is implemented in the VDD voltage domain that is still functional in STOP up from STANDBY). IWDGRST flag in IWDG reset can wake and STANDBY mode ( - RCC_CSR register can be used to inform when an IWDG reset occurs. Debug mode : When the microcontroller enters debug mode (core halted), the IWDG ending on DBG_IWDG_STOP counter either continues to work normally or stops, dep configuration bit in DBG module, accessible through __HAL_DBGMCU_FREEZE_IWDG() and __HAL_DBGMCU_UNFREEZE_IWDG() macros DocID027328 / 1166 326 Rev 2

327 HAL UM1850 IWDG Generic Driver max timeout value @32KHz (LSI): ~125us / ~32.7s The IWDG timeout may vary due - Min to LSI frequency dispersion. STM32F1xx devices provide the capability to measure the LSI frequency (LSI clock connected internally to TIM5 CH4 input capture). The measured value can be used to have an IWDG timeout with an acceptable accuracy. How to use this driver 26.2.2 Use IWDG using HAL_IWDG_Init() function to : 1. Enable instance by writing Start keyword in IWDG_KEY register. LSI clock is forced ON and IWDG counter starts downcounting. Enable write access to configuration register: IWDG_PR & IW DG_RLR. Configure the IWDG prescaler and counter reload value. This reload value will be loaded in the IWDG counter each time the watchdog is reloaded, then the IWDG will start counting down from this value. wait for status flags to be reset" Then the app lication program must refresh the IWDG counter at regular intervals 2. during normal operation to prevent an MCU reset, using HAL_IWDG_Refresh() function. IWDG HAL driver macros list Below the list of most used macros in IWDG HAL driver: Enable the IWDG peripheral __HAL_IWDG_START: __HAL_IWDG_RELOAD_COUNTER: Reloads IWDG counter with value defined in the reload register Initialization and Start functions 26.2.3 This section provides functions allowing to: Initialize the IWDG according to the specified parameters in the IWDG_InitTypeDef of associated handle. Once initialization is performed in HAL_IWDG_Init function, Watchdog is reloaded in order to exit function with correct time base. ns the following APIs: This section contai HAL_IWDG_Init() 26.2.4 IO operation functions This section provides functions allowing to: Refresh the IWDG. This section contains the following APIs: HAL_IWDG_Refresh() Detailed description of functions 26.2.5 HAL_IWDG_Init HAL_StatusTypeDef HAL_IWDG_Init (IWDG_HandleTypeDef * Function name hiwdg) Function description Initialize the IWDG according to the specified parameters in the IWDG_InitTypeDef and start watchdog. 2 DocID027328 Rev 1166 327 /

328 HAL UM1850 IWDG Generic Driver Parameters hiwdg: pointer to a IWDG_HandleTypeDef structure that contains the configuration information for the specified IWDG module. Return values status AL: H HAL_IWDG_Refresh HAL_StatusTypeDef HAL_IWDG_Refresh Function name (IWDG_HandleTypeDef * hiwdg) Function description Refresh the IWDG. Parameters hiwdg: pointer to a IWDG_HandleTypeDef structure that contains the configuration information for the specified IWDG module. Return values status HAL: IWDG Firmware driver defines 26.3 IWDG 26.3.1 IWDG Exported Macros Description: __HAL_IWDG_START Enable the IWDG peripheral. Parameters: __HANDLE__: IWDG handle Return value: None Description: __HAL_IWDG_RELOAD_COUNTER Reload IWDG counter with value defined in to IWDG_PR the reload register (write access & IWDG_RLR registers disabled). Parameters: __HANDLE__: IWDG handle Return value: None IWDG Prescaler IWDG_PRESCALER_4 IWDG prescaler set to 4 IWDG_PRESCALER_8 IWDG prescaler set to 8 IWDG prescaler set to 16 IWDG_PRESCALER_16 IWDG prescaler set to 32 IWDG_PRESCALER_32 IWDG prescaler set to 64 IWDG_PRESCALER_64 IWDG prescaler set to 128 IWDG_PRESCALER_128 DocID027328 / 1166 328 Rev 2

329 UM1850 HAL IWDG Generic Driver IWDG prescaler set to 256 IWDG_PRESCALER_256 Rev 329 / 1166 DocID027328 2

330 NAND Generic Driver HAL UM1850 27 HAL NAND Generic Driver 27.1 NAND Firmware driver registers structures NAND_IDTypeDef 27.1.1 Data Fields uint8_t Maker_Id uint8_t Device_Id uint8_t Third_Id uint8_t Fourth_Id Field Documentation NAND_IDTypeDef::Maker_Id uint8_t uint8_t NAND_IDTypeDef::Device_Id uint8_t NAND_IDTypeDef::Third_Id uint8_t NAND_IDTypeDef::Fourth_Id NAND_AddressTypeDef 27.1.2 Data Fields uint16_t Page uint16_t Plane uint16_t Block Field Docu mentation uint16_t NAND_AddressTypeDef::Page NAND memory Page address uint16_t NAND_AddressTypeDef::Plane NAND memory Plane address uint16_t NAND_AddressTypeDef::Block NAND memory Block address 27.1.3 NAND_DeviceConfigTypeDef Data Fields uint32_t PageSize uint32_t SpareAreaSize uint32_t BlockSize uint32_t BlockNbr uint32_t PlaneNbr uint32_t PlaneSize FunctionalState ExtraCommandEnable Field Documentation uint32_t NAND_DeviceConfigTypeDef::PageSize NAND memory page (without spare area) size measured in bytes for 8 bits adressing or words for 16 bits addressing uint32_t NAND_DeviceConfigTypeDef::SpareAreaSize NAND memory spare area size measured in bytes for 8 bits adressing or words for 16 bits addr essing DocID027328 / 1166 330 Rev 2

331 UM1850 NAND Generic Driver HAL uint32_t NAND_DeviceConfigTypeDef::BlockSize NAND memory block size measured in number of pages uint32_t NAND_DeviceConfigTypeDef::BlockNbr NAND memory number of total blocks uint32_t NAND_DeviceConfigTypeDef::PlaneNbr NAND memory number of plane s uint32_t NAND_DeviceConfigTypeDef::PlaneSize NAND memory plane size measured in number of blocks FunctionalState NAND_DeviceConfigTypeDef::ExtraCommandEnable NAND extra command needed for Page reading mode. This parameter is mandatory ts after the read command (NAND_CMD_AREA_TRUE1) and for some NAND par before DATA reading sequence. Example: Toshiba THTH58BYG3S0HBAI6. This parameter could be ENABLE or DISABLE Please check the Read Mode sequnece in the NAND device datasheet NAND_HandleTypeDef 27.1.4 Data Fields FSMC_NAND_TypeDef * Instance FSMC_NAND_InitTypeDef Init HAL_LockTypeDef Lock __IO HAL_NAND_StateTypeDef State NAND_DeviceConfigTypeDef Config Field Documentation FSMC_NAND_TypeDef* NAND_HandleTypeDef::Instance gister base address Re FSMC_NAND_InitTypeDef NAND_HandleTypeDef::Init NAND device control configuration parameters HAL_LockTypeDef NAND_HandleTypeDef::Lock NAND locking object __IO HAL_NAND_StateTypeDef NAND_HandleTypeDef::State NAND device access state AND_DeviceConfigTypeDef NAND_HandleTypeDef::Config N NAND phusical characteristic information structure 27.2 NAND Firmware driver API description How to use this driver 27.2.1 This driver is a generic layered driver which contains a set of APIs used to control NAND flash memories. It uses the FSMC layer functions to interface with NAND devices. This driver is used as follows: function HAL_NAND_Init() with NAND flash memory configuration sequence using the control and timing parameters for both common and attribute spaces. Read NAND flash memory maker and device IDs using the function HAL_NAND_Read_ID(). The read information is stored in the NAND_ID_TypeDef structure declared b y the function caller. Access NAND flash memory by read/write operations using the functions HAL_NAND_Read_Page_8b()/HAL_NAND_Read_SpareArea_8b(), HAL_NAND_Write_Page_8b()/HAL_NAND_Write_SpareArea_8b(), (), HAL_NAND_Read_Page_16b()/HAL_NAND_Read_SpareArea_16b HAL_NAND_Write_Page_16b()/HAL_NAND_Write_SpareArea_16b() to read/write page(s)/spare area(s). These functions use specific device information (Block, page 2 DocID027328 Rev 1166 331 /

332 HAL NAND Generic Driver UM1850 size..) predefined by the user in the NAND_DeviceConfigTypeDef structure. The information is contained by the Nand_Address_Typedef structure read/write address passed as parameter. Perform NAND flash Reset chip operation using the function HAL_NAND_Reset(). Perform NAND flash erase block operation using the function block address information is contained in the HAL_NAND_Erase_Block(). The erase Nand_Address_Typedef structure passed as parameter. Read the NAND flash status operation using the function HAL_NAND_Read_Status(). You can also control the NAND device by calling the control APIs HAL_NAND_E CC_Enable()/ HAL_NAND_ECC_Disable() to respectively enable/disable the ECC code correction feature or the function HAL_NAND_GetECC() to get the ECC correction code. You can monitor the NAND device HAL state by calling the function HAL_NAND_GetState() This driver is a set of generic APIs which handle standard NAND flash operations. If a NAND flash device contains different operations and/or implementations, it should be implemented separately. NAND Initialization and de - initialization functions 27.2.2 initialize the NAND memory - This section provides functions allowing to initialize/de This section contains the following APIs: HAL_NAND_Init() HAL_NAND_DeInit() HAL_NAND_MspInit() HAL_NAND_MspDeInit() HAL_NAND_IRQHandler() HAL_NAND_ITCa llback() HAL_NAND_ConfigDevice() HAL_NAND_Read_ID() NAND Input and Output functions 27.2.3 control the NAND memory This section provides functions allowing to use and This section contains the following APIs: HAL_NAND_Read_ID() HAL_NAND_Reset() HAL_NAND_ConfigDevice() HAL_NAND_Read_Page_8b() HAL_NAND_Read_Page_16b() HAL_NAND_Write_Page_8b() HAL_NAND_Write_Page_16b() HAL_NAND_Read_SpareArea_8b() HAL_NAND_Read_SpareArea_16b() HAL_NAND_Write_SpareArea_8b() HAL_NAND_Write_SpareArea_16b() HAL_ NAND_Erase_Block() HAL_NAND_Read_Status() HAL_NAND_Address_Inc() DocID027328 / 1166 332 Rev 2

333 UM1850 iver HAL NAND Generic Dr 27.2.4 NAND Control functions This subsection provides a set of functions allowing to control dynamically the NAND interface. This section contains the following APIs: HAL_NAND_ECC_Enable() HAL_NAND_ECC_Disable() HAL_NAND_GetECC() NAND State functions 27.2.5 This subsection permits to get in run time the status of the NAND controller and the data - flow. This section contains the following APIs: HAL_NAND_GetState() HAL_NAND_Read_Status() 27.2.6 Detailed description of functions HAL_NAND_Init (NAND_HandleTypeDef * HAL_StatusTypeDef HAL_NAND_Init Function name hnand, FSMC_NAND_PCC_TimingTypeDef * ComSpace_Timing, FSMC_NAND_PCC_TimingTypeDef * AttSpace_Timing) Function description Perform NAND memory Initialization sequence. Parameters hnand: pointer to a NAND_HandleTypeDef structure that contains the configuration information for NAND module. ComSpace_Timing: pointer to Common space timing structure AttSpace_Timing: pointer to Attribute space timing structure Return values HAL: status L_NAND_DeInit HA HAL_StatusTypeDef HAL_NAND_DeInit Function name (NAND_HandleTypeDef * hnand) Function description Perform NAND memory De - Initialization sequence. Parameters hnand: pointer to a NAND_HandleTypeDef structure that contains the configuration information for NAND module. Return values status HAL: HAL_NAND_ConfigDevice HAL_StatusTypeDef HAL_NAND_ConfigDevice Function name (NAND_HandleTypeDef * hnand, NAND_DeviceConfigTypeDef * pDeviceConfig) Configure the device: Enter the physical parameters of the device. Function description Parameters pointer to a NAND_HandleTypeDef structure that hnand: 2 DocID027328 Rev 1166 333 /

334 HAL UM1850 NAND Generic Driver contains the configuration information for NAND module. pDeviceConfig: : pointer to NAND_DeviceConfigTypeDef structure Return values status HAL: HAL_NAND_Read_ID HAL_StatusTypeDef HAL_NAND_Read_ID Function name (NAND_HandleTypeDef * hnand, NAND_IDTypeDef * pNAND_ID) Function description Read the NAND memory electronic signature. Parameters hnand: pointer to a NAND_HandleTypeDef structure that contains the configuration information for NAND module. pNAND_ID: NAND ID structure Return values HAL: status HAL_NAND_MspInit void HAL_NAND_MspInit (NAND_HandleTypeDef * hnand) Function name description NAND MSP Init. Function Parameters pointer to a NAND_HandleTypeDef structure that hnand: contains the configuration information for NAND module. Return values None: HAL_NAND_MspDeInit hnand) void HAL_NAND_MspDeInit (NAND_HandleTypeDef * Function name Function description NAND MSP DeInit. Parameters pointer to a NAND_HandleTypeDef structure that hnand: contains the configuration information for NAND module. Return values None: HAL_NAND_IRQHandler void HAL_NAND_IRQHandler (NAN D_HandleTypeDef * hnand) Function name Function description This function handles NAND device interrupt request. Parameters hnand: pointer to a NAND_HandleTypeDef structure that contains the configuration information for NAND module. Return values status HAL: HAL_NAND_ITCallback void HAL_NAND_ITCallback (NAND_HandleTypeDef * hnand) Function name Function description NAND interrupt feature callback. Parameters hnand: pointer to a NAND_HandleTypeDef structure that ND module. contains the configuration information for NA DocID027328 / 1166 334 Rev 2

335 UM1850 NAND Generic Driver HAL Return values None: HAL_NAND_Reset HAL_StatusTypeDef HAL_NAND_Reset Function name (NAND_HandleTypeDef * hnand) NAND memory reset. Function description Parameters pointer to a NAND_HandleTypeDef structure that hnand: contains the configuration information for NAND module. Return values HAL: status HAL_NAND_Read_Page_8b HAL_StatusTypeDef HAL_NAND_Read_Page_8b Function name NAND_AddressTypeDef * (NAND_HandleTypeDef * hnand, pAddress, uint8_t * pBuffer, uint32_t NumPageToRead) Read Page(s) from NAND memory block (8 - bits addressing) Function description Parameters hnand: pointer to a NAND_HandleTypeDef structure that contains the configuration information for NAND module. : pointer to NAND address structure pAddress: : pointer to destination read buffer pBuffer: : number of pages to read from block NumPageToRead: rn values Retu status HAL: HAL_NAND_Write_Page_8b HAL_StatusTypeDef HAL_NAND_Write_Page_8b Function name (NAND_HandleTypeDef * hnand, NAND_AddressTypeDef * pAddress, uint8_t * pBuffer, uint32_t NumPageToWrite) Function description Write Page(s) to NAND memor y block (8 - bits addressing) Parameters hnand: pointer to a NAND_HandleTypeDef structure that contains the configuration information for NAND module. : pointer to NAND address structure pAddress: pBuffer: : pointer to source buffer to write NumPageToWrite: : number of pages to write to block Return values status HAL: HAL_NAND_Read_SpareArea_8b HAL_StatusTypeDef HAL_NAND_Read_SpareArea_8b Function name (NAND_HandleTypeDef * hnand, NAND_AddressTypeDef * NumSpareAreaToRead) pAddress, uint8_t * pBuffer, uint32_t bits addressing) Function description Read Spare area(s) from NAND memory (8 - Parameters hnand: pointer to a NAND_HandleTypeDef structure that contains the configuration information for NAND module. ess structure : pointer to NAND addr pAddress: pointer to source buffer to write pBuffer: 2 DocID027328 Rev 1166 335 /

336 HAL UM1850 NAND Generic Driver Number of spare area to read NumSpareAreaToRead: Return values HAL: status HAL_NAND_Write_SpareArea_8b HAL_StatusTypeDef HAL_NAND_Write_SpareArea_8b Function name (NAND_HandleTypeDef * hnand, NAND_AddressTypeDef * pAddress, uint8_t * pBuffer, uint32_t NumSpareAreaTowrite) bits addressing) - Write Spare area(s) to NAND memory (8 Function description Parameters hnand: pointer to a NAND_HandleTypeDef structure that contains the configuration inf ormation for NAND module. pAddress: : pointer to NAND address structure : pointer to source buffer to write pBuffer: NumSpareAreaTowrite: : number of spare areas to write to block Return values HAL: status HAL_NAND_Read_Page_16b HAL_StatusTypeDef HAL_NAND_Read_Page_16b Function name (NAND_HandleTypeDef * hnand, NAND_AddressTypeDef * pAddress, uint16_t * pBuffer, uint32_t NumPageToRead) bits addressing) - Read Page(s) from NAND memory block (16 Function description Parameters a NAND_HandleTypeDef structure that hnand: pointer to contains the configuration information for NAND module. pAddress: : pointer to NAND address structure : pointer to destination read buffer. pBuffer should pBuffer: be 16bits aligned o read from block : number of pages t NumPageToRead: Return values HAL: status HAL_NAND_Write_Page_16b HAL_StatusTypeDef HAL_NAND_Write_Page_16b Function name (NAND_HandleTypeDef * hnand, NAND_AddressTypeDef * pAddress, uint16_t * pBuffer, uint32_t NumPageToWrite) Function description bits addressing) W rite Page(s) to NAND memory block (16 - Parameters pointer to a NAND_HandleTypeDef structure that hnand: contains the configuration information for NAND module. pAddress: : pointer to NAND address structure pBuffer: : pointer to source buffer to write. pBuffer should be 16bits aligned : number of pages to write to block NumPageToWrite: Return values HAL: status HAL_NAND_Read_SpareArea_16b HAL_StatusTypeDef HAL_NAND_Read_SpareArea_16b Function name eDef * hnand, NAND_AddressTypeDef * (NAND_HandleTyp DocID027328 / 1166 336 Rev 2

337 UM1850 NAND Generic Driver HAL pAddress, uint16_t * pBuffer, uint32_t NumSpareAreaToRead) - Function description Read Spare area(s) from NAND memory (16 bits addressing) Parameters hnand: pointer to a NAND_HandleTypeDef structure that contains the configuration information for NAND module. : pointer to NAND address structure pAddress: pBuffer: pointer to source buffer to write. pBuffer should be 16bits aligned. NumSpareAreaToRead: Number of spare area to read Return values HAL: status HAL_NAND_Write_SpareArea_16b HAL_StatusTypeDef HAL_NAND_Write_SpareArea_16b Function name (NAND_HandleTypeDef * hnand, NAND_AddressTypeDef * pAddress, uint16_t * pBuffer, uint32_t NumSpareAreaTowri te) Write Spare area(s) to NAND memory (16 bits addressing) - Function description Parameters hnand: pointer to a NAND_HandleTypeDef structure that contains the configuration information for NAND module. pAddress: : pointer to NAND address structure pBu : pointer to source buffer to write. pBuffer should be ffer: 16bits aligned. NumSpareAreaTowrite: : number of spare areas to write to block Return values HAL: status HAL_NAND_Erase_Block HAL_StatusTypeDef HAL_NAND_Erase_Block Function name (NAND_HandleTypeDef * hnand, NAND_AddressTypeDef * pAddress) NAND memory Block erase. Function description Parameters pointer to a NAND_HandleTypeDef structure that hnand: contains the configuration information for NAND module. pAddress: : pointer to NAND address structure Return values HAL: status HAL_NAND_Read_Status uint32_t HAL_NAND_Read_Status (NAND_HandleTypeDef * Function name hnand) NAND memory read status. Function description Parameters hnand: pointer to a NAND_HandleTypeDef structure that contains the configuration information for NAND module. Return values NAND: status 2 DocID027328 Rev 1166 337 /

338 HAL NAND Generic Driver UM1850 HAL_NAND_Address_Inc uint32_t HAL_NAND_Address_Inc (NAND_HandleTypeDef * Function name hnand, NAND_AddressTypeDef * pAddress) Function description Increment the NAND memory address. Parameters hnand: pointer to a NAND_HandleTypeDef structure that contains the configuration information for NAND module. pAddress: pointer to NAND address structure Return values new status of the increment address operation. It can The: be: NAND_VALID_ADDRESS: When the new address is valid address NAND_INVALID_ADDRESS: When the new address is invalid address HAL_NAND_ECC_Enable HAL_StatusTypeDef HAL_NAND_ECC_Enable Function name D_HandleTypeDef * hnand) (NAN Enables dynamically NAND ECC feature. Function description Parameters pointer to a NAND_HandleTypeDef structure that hnand: contains the configuration information for NAND module. Return values HAL: status HAL_NAND_ECC_Disable HAL_StatusTypeDef HAL_NAND_ECC_Disable Function name (NAND_HandleTypeDef * hnand) Function description Disables dynamically FSMC_NAND ECC feature. Parameters pointer to a NAND_HandleTypeDef structure that hnand: contains the config uration information for NAND module. Return values HAL: status HAL_NAND_GetECC HAL_StatusTypeDef HAL_NAND_GetECC Function name (NAND_HandleTypeDef * hnand, uint32_t * ECCval, uint32_t Timeout) Function description Disables dynamically NAND ECC feature. Parameters pointer to a NAND_HandleTypeDef structure that hnand: contains the configuration information for NAND module. ECCval: pointer to ECC value Timeout: maximum timeout to wait Return values status HAL: HAL_NAND_GetState HAL_NAND_StateTypeDef HAL_NAND_GetState Function name 1166 DocID027328 / Rev 2 338

339 UM1850 NAND Generic Driver HAL (NAND_HandleTypeDef * hnand) return the NAND state Function description Parameters hnand: pointer to a NAND_HandleTypeDef structure that contains the configuration information for NAND module. Return values state HAL: NAND Firmware driver defines 27.3 NAND 27.3.1 NAND Exported Macros Description: __HAL_NAND_RESET_HANDLE_STATE Reset NAND handle state. Parameters: __HANDLE__: specifies the NAND handle. Return value: None 2 DocID027328 Rev 1166 339 /

340 NOR Generi HAL UM1850 c Driver 28 HAL NOR Generic Driver 28.1 NOR Firmware driver registers structures 28.1.1 NOR_IDTypeDef Data Fields uint16_t Manufacturer_Code uint16_t Device_Code1 uint16_t Device_Code2 uint16_t Device_Code3 Field Documentation uint16_t NOR_IDTypeDef::Manufacturer_Code Defines the device's manufacturer code used to identify the memory uint16_t NOR_IDTypeDef::Device_Code1 6_t NOR_IDTypeDef::Device_Code2 uint1 uint16_t NOR_IDTypeDef::Device_Code3 Defines the device's codes used to identify the memory. These codes can be accessed by performing read operations with specific control signals and addresses set.They can also be accessed by issuing an Auto Select command 28.1.2 NOR_CFITypeDef Data Fields uint16_t CFI_1 uint16_t CFI_2 uint16_t CFI_3 uint16_t CFI_4 Field Documentation uint16_t NOR_CFITypeDef::CFI_1 < Defines the information stored in the memory's Common flash interface which contains a description of various electrical and timing parameters, density information and functions supported by the memory uint16_t NOR_CFITypeDef::CFI_2 ef::CFI_3 uint16_t NOR_CFITypeD uint16_t NOR_CFITypeDef::CFI_4 28.1.3 NOR_HandleTypeDef Data Fields FSMC_NORSRAM_TypeDef * Instance FSMC_NORSRAM_EXTENDED_TypeDef * Extended FSMC_NORSRAM_InitTypeDef Init HAL_LockTypeDef Lock HAL_NOR_StateTypeDef State __IO Field Documentation FSMC_NORSRAM_TypeDef* NOR_HandleTypeDef::Instance Register base address DocID027328 / 1166 340 Rev 2

341 UM1850 NOR Generic Driver HAL FSMC_NORSRAM_EXTENDED_TypeDef* NOR_HandleTypeDef::Extended Extended mode register base address FSMC_NORSRAM_InitTypeDef NOR_HandleTypeD ef::Init NOR device control configuration parameters HAL_LockTypeDef NOR_HandleTypeDef::Lock NOR locking object __IO HAL_NOR_StateTypeDef NOR_HandleTypeDef::State NOR device access state NOR Firmware driver API description 28.2 How to use this driver 28.2.1 This driver is a generic layered driver which contains a set of APIs used to control NOR flash memories. It uses the FSMC layer functions to interface with NOR devices. This r is used as follows: drive NOR flash memory configuration sequence using the function HAL_NOR_Init() with control and timing parameters for both normal and extended mode. Read NOR flash memory manufacturer code and device IDs using the function D(). The read information is stored in the NOR_ID_TypeDef HAL_NOR_Read_I structure declared by the function caller. Access NOR flash memory by read/write data unit operations using the functions HAL_NOR_Read(), HAL_NOR_Program(). ations using the functions Perform NOR flash erase block/chip oper HAL_NOR_Erase_Block() and HAL_NOR_Erase_Chip(). Read the NOR flash CFI (common flash interface) IDs using the function HAL_NOR_Read_CFI(). The read information is stored in the NOR_CFI_TypeDef structure declared by the function caller. You can also control the NOR device by calling the control APIs HAL_NOR_WriteOperation_Enable()/ HAL_NOR_WriteOperation_Disable() to respectively enable/disable the NOR write operation You can monitor the NOR device HAL state by calling the funct ion HAL_NOR_GetState() This driver is a set of generic APIs which handle standard NOR flash operations. If a NOR flash device contains different operations and/or implementations, it should be implemented separately. NOR HAL driver macros list Below the list of most used macros in NOR HAL driver. NOR_WRITE : NOR memory write data to specified address 28.2.2 NOR Initialization and de_initialization functions This section provide initialize the NOR memory - s functions allowing to initialize/de This section contains the following APIs: HAL_NOR_Init() HAL_NOR_DeInit() HAL_NOR_MspInit() HAL_NOR_MspDeInit() HAL_NOR_MspWait() 2 DocID027328 Rev 1166 341 /

342 HAL UM1850 NOR Generic Driver NOR Input and Output functions 28.2.3 memory This section provides functions allowing to use and control the NOR This section contains the following APIs: HAL_NOR_Read_ID() HAL_NOR_ReturnToReadMode() HAL_NOR_Read() HAL_NOR_Program() HAL_NOR_ReadBuffer() HAL_NOR_ProgramBuffer() HAL_NOR_Erase_Block() HAL_NOR_Erase_Chip() HAL_NOR_Read_CFI() NOR Control functions 28.2.4 This subsection provides a set of functions allowing to control dynamically the NOR interface. This section contains the following APIs: HAL_NOR_WriteOperation_Enable() HAL_NOR_WriteOperation_Disable() NOR State functions 28.2.5 This subsection permits to get in run time the status of the NO R controller and the data - flow. This section contains the following APIs: HAL_NOR_GetState() HAL_NOR_GetStatus() 28.2.6 Detailed description of functions HA L_NOR_Init HAL_StatusTypeDef HAL_NOR_Init (NOR_HandleTypeDef * Function name hnor, FSMC_NORSRAM_TimingTypeDef * Timing, FSMC_NORSRAM_TimingTypeDef * ExtTiming) Function description Perform the NOR memory Initialization sequence. Parameters hnor: pointer to a NOR_HandleTypeDef structure that contains the configuration information for NOR module. pointer to NOR control timing structure Timing: ExtTiming: pointer to NOR extended mode timing structure Return values status HAL: HAL_NOR_DeInit HAL_StatusTypeDef HAL_NOR_DeInit (NOR_HandleTypeDef * Fun ction name hnor) Function description Initialization sequence. - Perform NOR memory De DocID027328 / 1166 342 Rev 2

343 UM1850 NOR Generic Driver HAL Parameters hnor: pointer to a NOR_HandleTypeDef structure that contains the configuration information for NOR module. Return values status HAL: HAL_NOR_MspInit void HAL_NOR_MspInit (NOR_HandleTypeDef * hnor) Function name Function description NOR MSP Init. Parameters hnor: pointer to a NOR_HandleTypeDef structure that contains the configuration information for NOR module. Return values None: HAL_NOR_MspDeInit void HAL_NOR_MspDeInit (NOR_HandleTypeDef * hnor) Function name NOR MSP DeInit. Function description Parameters hnor: pointer to a NOR_HandleTypeDef structure that contains the configuration information for NOR module. Return values None: HAL_NOR_MspWait void HAL_NOR_MspWait (NOR_HandleTypeDef * hnor, Function name uint32_t Timeout) Function description NOR MSP Wait fro Ready/Busy signal. Parameters hnor: pointer to a NOR_HandleTypeDef structure that contains the configuration information for NOR module. Timeout: Maximum timeout value Return values None: HAL_NOR_Read_ID HAL_StatusTypeDef HAL_NOR_Read_ID Function name (NOR_HandleTypeDef * hnor, NOR_IDTypeDef * pNOR_ID) Function description Read NOR flash IDs. Parameters pointer to a NOR_HandleTypeDef structure that hnor: odule. contains the configuration information for NOR m : pointer to NOR ID structure pNOR_ID: Return values HAL: status HAL_NOR_ReturnToReadMode HAL_StatusTypeDef HAL_NOR_ReturnToReadMode Function name (NOR_HandleTypeDef * hnor) Returns the NOR memory to Read mode. Function description Parameters hnor: pointer to a NOR_HandleTypeDef structure that 2 DocID027328 Rev 1166 343 /

344 HAL UM1850 NOR Generic Driver contains the configuration information for NOR module. Return values HAL: status HAL_NOR_Read HAL_StatusTypeDef HAL_NOR_Read (NOR_HandleTypeDef * Function name pData) hnor, uint32_t * pAddress, uint16_t * Read data from NOR memory. Function description Parameters hnor: pointer to a NOR_HandleTypeDef structure that contains the configuration information for NOR module. pAddress: pointer to Device address : pointer to read data pData: Return values status HAL: HAL_NOR_Program HAL_StatusTypeDef HAL_NOR_Program Function name (NOR_HandleTypeDef * hnor, uint32_t * pAddress, uint16_t * pData) Function description Program data to NOR memory. Parameters cture that pointer to a NOR_HandleTypeDef stru hnor: contains the configuration information for NOR module. Device address pAddress: : pointer to the data to write pData: Return values HAL: status HAL_NOR_ReadBuffer HAL_StatusTypeDef HAL_NOR_ReadBuffer Function name (NOR_HandleTypeDef * hnor, uint32_t uwAddress, uint16_t * pData, uint32_t uwBufferSize) Function description Reads a block of data from the FSMC NOR memory. Parameters pointer to a NOR_HandleTypeDef structure that hnor: contains the configuration information for NOR module. uwA ddress: NOR memory internal address to read from. pData: pointer to the buffer that receives the data read from the NOR memory. uwBufferSize: : number of Half word to read. Return values HAL: status HAL_NOR_ProgramBuffer HAL_StatusTypeDef HAL_NOR_ProgramBuffer Function name (NOR_HandleTypeDef * hnor, uint32_t uwAddress, uint16_t * pData, uint32_t uwBufferSize) Function description - word buffer to the FSMC NOR memory. Writes a half Parameters hnor: pointer to a NOR_HandleTypeDef structure that contains the configuration information for NOR module. DocID027328 / 1166 344 Rev 2

345 HAL UM1850 NOR Generic Driver uwAddress: NOR memory internal address from which the data pData: pointer to source data buffer. uwBufferSize: number of Half words to write. Return v alues status HAL: Notes Some NOR memory need Address aligned to xx bytes (can be aligned to 64 bytes boundary for example). The maximum buffer size allowed is NOR memory dependent (can be 64 Bytes max for example). HAL_NOR_Erase_Block HAL_StatusTypeDef HAL_NOR_Erase_Block Function name (NOR_HandleTypeDef * hnor, uint32_t BlockAddress, uint32_t Address) Erase the specified block of the NOR memory. Function description Parameters hnor: pointer to a NOR_HandleTypeDef structure that contains the conf iguration information for NOR module. : Block to erase address BlockAddress: Device address Address: Return values HAL: status HAL_NOR_Erase_Chip HAL_StatusTypeDef HAL_NOR_Erase_Chip Function name (NOR_HandleTypeDef * hnor, uint32_t Address) Function description Erase the entire NOR chip. Parameters hnor: pointer to a NOR_HandleTypeDef structure that contains the configuration information for NOR module. : Device address Address: Return values HAL: status HAL_NOR_Read_CFI HAL_StatusTypeDef HAL_NOR_Read_CFI Function name (NOR_HandleTypeDef * hnor, NOR_CFITypeDef * pNOR_CFI) Function description Read NOR flash CFI IDs. Parameters hnor: pointer to a NOR_HandleTypeDef structure that contains the configuration information for NOR module. : pointer to NOR CFI IDs structure pNOR_CFI: Return values status HAL: HAL_NOR_WriteOperation_Enable HAL_StatusTypeDef HAL_NOR_WriteOperation_Enable Function name (NOR_HandleTypeDef * hnor) Enables dynamically NOR write operation. Function description 2 DocID027328 Rev 1166 345 /

346 HAL UM1850 NOR Generic Driver Parameters pointer to a NOR_HandleTypeDef structure that hnor: contains the configuration information for NOR module. Return values HAL: status HAL_NOR_WriteOperation_Disable L_NOR_WriteOperation_Disable HAL_StatusTypeDef HA Function name (NOR_HandleTypeDef * hnor) Function description Disables dynamically NOR write operation. Parameters pointer to a NOR_HandleTypeDef structure that hnor: contains the configuration information for NOR module. Return values status HAL: HAL_NOR_GetState HAL_NOR_StateTypeDef HAL_NOR_GetState Function name (NOR_HandleTypeDef * hnor) Function description return the NOR controller state Parameters pointer to a NOR_HandleTypeDef structure that hnor: contains the configuration information for NOR module. Return values NOR: controller state HAL_NOR_GetStatus HAL_NOR_StatusTypeDef HAL_NOR_GetStatus Function name (NOR_HandleTypeDef * hnor, uint32_t Address, uint32_t Timeout) Function description Returns the NOR operation status. Parameters hnor: pointer to a NOR_HandleTypeDef structure that contains the configuration information for NOR module. Device address Address: Timeout: NOR progamming Timeout Return values NOR_Status: lue can be: The returned va HAL_NOR_STATUS_SUCCESS, HAL_NOR_STATUS_ERROR or HAL_NOR_STATUS_TIMEOUT NOR Firmware driver defines 28.3 28.3.1 NOR NOR Exported Macros Description: __HAL_NOR_RESET_HANDLE_STATE Reset NOR handle state. Parameters: __HANDLE__: NOR handle DocID027328 / 1166 346 Rev 2

347 UM1850 HAL NOR Generic Driver Return value: None 2 / 1166 347 Rev DocID027328

348 PCCARD Generic Driver HAL UM1850 29 HAL PCCARD Generic Driver PCCARD Firmware driver registers structures 29.1 PCCARD_HandleTypeDef 29.1.1 Data Fields FSMC_PCCARD_TypeDef * Instance FSMC_PCCARD_InitTypeDef Init __IO HAL_PCCARD_StateTypeDef State HAL_LockTypeDef Lock Field Documentation FSMC_PCCARD_TypeDef* PCCARD_HandleTypeDef::Instance Register base address for PCCARD device FSMC_PCCARD_InitTypeDef PCCARD_HandleTypeDef::Init PCCARD device control configuration parameters __IO HAL_PCCARD_StateTypeDef PCCARD_HandleTypeDef::State PCCARD device access state peDef::Lock HAL_LockTypeDef PCCARD_HandleTy PCCARD Lock 29.2 PCCARD Firmware driver API description How to use this driver 29.2.1 ntrol This driver is a generic layered driver which contains a set of APIs used to co PCCARD/compact flash memories. It uses the FSMC/FSMC layer functions to interface with PCCARD devices. This driver is used for: PCCARD/compact flash memory configuration sequence using the function s for both common and HAL_PCCARD_Init() with control and timing parameter attribute spaces. Read PCCARD/compact flash memory maker and device IDs using the function HAL_PCCARD_Read_ID(). The read information is stored in the CompactFlash_ID structure declared by the function caller. flash memory by read/write operations using the functions Access PCCARD/compact HAL_PCCARD_Read_Sector()/HAL_PCCARD_Write_Sector(), to read/write sector. Perform PCCARD/compact flash Reset chip operation using the function HAL_PCCARD_Reset(). Perform PCCARD/compact flash eras e sector operation using the function HAL_PCCARD_Erase_Sector(). Read the PCCARD/compact flash status operation using the function HAL_PCCARD_ReadStatus(). You can monitor the PCCARD/compact flash device HAL state by calling the function HAL_PCCARD_GetSt ate() This driver is a set of generic APIs which handle standard PCCARD/compact flash operations. If a PCCARD/compact flash device contains different operations and/or implementations, it should be implemented separately. DocID027328 / 1166 348 Rev 2

349 UM1850 PCCARD Generic Driver HAL 29.2.2 PCCARD Initialization and de - initialization functions - This section provides functions allowing to initialize/de initialize the PCCARD memory This section contains the following APIs: HAL_PCCARD_Init() HAL_PCCARD_DeInit() HAL_PCCARD_MspInit() HAL_PCCARD_MspDeInit() PCCARD Input Output and memory functions 29.2.3 This section provides functions allowing to use and control the PCCARD memory This section contains the following APIs: HAL_PCCARD_Read_ID() _PCCARD_Read_Sector() HAL HAL_PCCARD_Write_Sector() HAL_PCCARD_Erase_Sector() HAL_PCCARD_Reset() HAL_PCCARD_IRQHandler() HAL_PCCARD_ITCallback() PCCARD Peripheral State functions 29.2.4 This subsection permits to get in run - time the status of the PCCARD controller and the data flow. This section contains the following APIs: HAL_PCCARD_GetState() HAL_PCCARD_GetStatus() HAL_PCCARD_ReadStatus() Detailed description of functions 29.2.5 HAL_PCCARD_Init HAL_StatusTypeDef HAL_PCCARD_Init Function name (PCCARD_HandleTypeDef * hpccard, FSMC_NAND_PCC_TimingTypeDef * ComSpaceTiming, FSMC_NAND_PCC_TimingTypeDef * AttSpaceTiming, FSMC_NAND_PCC_TimingTypeDef * IOSpaceTiming) ction description Fun Perform the PCCARD memory Initialization sequence. Parameters pointer to a PCCARD_HandleTypeDef structure hpccard: that contains the configuration information for PCCARD module. ComSpaceTiming: Common space timing structure Attribute space timing structure AttSpaceTi ming: IOSpaceTiming: IO space timing structure Return values HAL: status 2 DocID027328 Rev 1166 349 /

350 HAL PCCARD Generic Driver UM1850 HAL_PCCARD_DeInit HAL_StatusTypeDef HAL_PCCARD_DeInit Function name (PCCARD_HandleTypeDef * hpccard) initialization sequence. Perform the PCCARD memory De Function description - Parameters pointer to a PCCARD_HandleTypeDef structure hpccard: that contains the configuration information for PCCARD module. Return values HAL: status HAL_PCCARD_MspInit CCARD_MspInit (PCCARD_HandleTypeDef * void HAL_P Function name hpccard) PCCARD MSP Init. Function description Parameters pointer to a PCCARD_HandleTypeDef structure hpccard: that contains the configuration information for PCCARD module. Return values None: HAL_PCCARD_MspDeInit void HAL_PCCARD_MspDeInit (PCCARD_HandleTypeDef * Function name hpccard) Function description PCCARD MSP DeInit. Parameters pointer to a PCCARD_HandleTypeDef structure hpccard: that contains the configuration information for PCCARD module. Return values None: HAL_PCCARD_Read_ID HAL_StatusTypeDef HAL_PCCARD_Read_ID Function name (PCCARD_HandleTypeDef * hpccard, uint8_t CompactFlash_ID, uint8_t * pStatus) Function description Read Compact Flash's ID. Parameters hpccard: pointer to a PCCARD_HandleTypeDef structure that contains the configuration information for PCCARD module. CompactFlash_ID: Compact flash ID structure. pointer to compact flash status pStatus: Return values HAL: status HAL_PCCARD_Write_Sector HAL_StatusTypeDef HAL_PCCARD_Write_Sector n name Functio (PCCARD_HandleTypeDef * hpccard, uint16_t * pBuffer, uint16_t SectorAddress, uint8_t * pStatus) DocID027328 / 1166 350 Rev 2

351 HAL UM1850 PCCARD Generic Driver Function description Write sector to PCCARD memory. Parameters hpccard: pointer to a PCCARD_HandleTypeDef structure that contains the configuration information for PCCARD module. pBuffer: pointer to source write buffer SectorAddress: Sector address to write pStatus: pointer to CF status Return values status HAL: HAL_PCC ARD_Read_Sector HAL_StatusTypeDef HAL_PCCARD_Read_Sector Function name (PCCARD_HandleTypeDef * hpccard, uint16_t * pBuffer, uint16_t SectorAddress, uint8_t * pStatus) Read sector from PCCARD memory. Function description Parameters pointer to a PCCARD_HandleTypeDef structure hpccard: that contains the configuration information for PCCARD module. pointer to destination read buffer pBuffer: SectorAddress: Sector address to read pointer to CF status pStatus: Return values HAL: status HAL_PCCARD_Erase_Sector HAL_StatusTypeDef HAL_PCCARD_Erase_Sector Function name (PCCARD_HandleTypeDef * hpccard, uint16_t SectorAddress, uint8_t * pStatus) Function description Erase sector from PCCARD memory. Parameters pointer to a PCCARD_Ha ndleTypeDef structure hpccard: that contains the configuration information for PCCARD module. Sector address to erase SectorAddress: pStatus: pointer to CF status Return values HAL: status HAL_PCCARD_Reset HAL_StatusTypeDef HAL_PCCARD_Reset Function name (PCCARD_HandleTypeDef * hpccard) Reset the PCCARD memory. Function description Parameters hpccard: pointer to a PCCARD_HandleTypeDef structure that contains the configuration information for PCCARD module. Return values HAL: status 2 DocID027328 Rev 1166 351 /

352 HAL PCCARD Generic Driver UM1850 HAL_PCCARD_IRQHan dler void HAL_PCCARD_IRQHandler (PCCARD_HandleTypeDef * Function name hpccard) Function description This function handles PCCARD device interrupt request. Parameters hpccard: pointer to a PCCARD_HandleTypeDef structure that contains the configuration information for PCCARD module. Return values HAL: status HAL_PCCARD_ITCallback void HAL_PCCARD_ITCallback (PCCARD_HandleTypeDef * Function name hpccard) CCARD interrupt feature callback. P Function description Parameters pointer to a PCCARD_HandleTypeDef structure hpccard: that contains the configuration information for PCCARD module. Return values None: HAL_PCCARD_GetState HAL_PCCARD_StateTypeDef HAL_PCCARD_GetState Function name (PCCARD_HandleTypeDef * hpccard) Function description return the PCCARD controller state Parameters hpccard: pointer to a PCCARD_HandleTypeDef structure that contains the configuration information for PCCARD module. Return values AL: state H HAL_PCCARD_GetStatus HAL_PCCARD_StatusTypeDef HAL_PCCARD_GetStatus Function name (PCCARD_HandleTypeDef * hpccard) Function description Get the compact flash memory status. Parameters hpccard: pointer to a PCCARD_HandleTypeDef structure that contains the configuration information for PCCARD module. Return values status of the CF operation. This parameter can be: New: CompactFlash_TIMEOUT_ERROR: when the previous operation generate a Timeout e rror CompactFlash_READY: when memory is ready for the next operation HAL_PCCARD_ReadStatus HAL_PCCARD_StatusTypeDef HAL_PCCARD_ReadStatus Function name (PCCARD_HandleTypeDef * hpccard) DocID027328 / 1166 352 Rev 2

353 UM1850 PCCARD Generic Driver HAL Reads the Compact Flash memory status using the Function description Read status command. Parameters hpccard: pointer to a PCCARD_HandleTypeDef structure that contains the configuration information for PCCARD module. Return values The: status of the Compact Flash memory. This parameter can be: memory is busy CompactFlash_BUSY: when CompactFlash_READY: when memory is ready for the next operation CompactFlash_ERROR: when the previous operation gererates error 29.3 PCCARD Firmware driver defines PCCARD 29.3.1 PCCARD Exported Macros Description: __HAL_PCCARD_RESET_HANDLE_STATE Reset PCCARD handle state. Parameters: __HANDLE__: specifies the PCCARD handle. Return value: None 2 DocID027328 Rev 1166 353 /

354 HAL UM1850 PCD Generic Driver HAL PCD Generic Driver 30 30.1 PCD Firmware driver registers structures PCD_HandleTypeDef 30.1.1 Data Fields PCD_TypeDef * Instance PCD_InitTypeDef Init __IO uint8_t USB_Address PCD_EPTypeDef IN_ep PCD_EPTypeDef OUT_ep HAL_LockTypeDef Lock __IO PCD_StateTypeDef State uint32_t Setup void * pData Field Documentation PCD_TypeDef* PCD_HandleTypeDef::Instance Register base address PCD_InitTypeDef PCD_HandleTypeDef::Init PCD required parameters __IO uint8_t PCD_HandleTypeDef ::USB_Address USB Address: not used by USB OTG FS PCD_EPTypeDef PCD_HandleTypeDef::IN_ep[15U] IN endpoint parameters PCD_EPTypeDef PCD_HandleTypeDef::OUT_ep[15U] OUT endpoint parameters HAL_LockTypeDef PCD_HandleTypeDef::Lock PCD peripheral status PCD_StateTypeDef PCD_HandleTypeDef::State __IO PCD communication state uint32_t PCD_HandleTypeDef::Setup[12U] Setup packet buffer void* PCD_HandleTypeDef::pData Pointer to upper stack Handler 30.2 PCD Firmware driver API description How to use this driver 30.2.1 The PCD HAL driver can be used as follows: Declare a PCD_HandleTypeDef handle structure, for example: PCD_HandleTypeDef 1. hpcd; Fill parameters of Init structure in HCD handle 2. all HAL_PCD_Init() API to initialize the HCD peripheral (Core, Device core, ...) C 3. Initialize the PCD low level resources through the HAL_PCD_MspInit() API: 4. Enable the PCD/USB Low Level interface clock using the following macro a. __HAL_RCC_USB_CLK_ENABLE(); For USB Device FS peripheral available on STM32F102xx and STM32F103xx devices DocID027328 / 1166 354 Rev 2

355 UM1850 PCD Generic Driver HAL __HAL_RCC_USB_OTG_FS_CLK_ENABLE(); For USB OTG FS peripheral available on STM32F105xx and STM32F107xx devices b. Initialize the related GPIO clocks - Configure PCD pin out c. d. Configure PCD NVIC interrupt 5. Associate the Upper USB device stack to the HAL PCD Driver: hpcd.pData = pdev; a. 6. Enable HCD transmission and reception: a. HAL_PCD_Start(); 30.2.2 initialization functions - Initialization and de This section provides functions allowing to: This section contains the following APIs: HAL_PCD_Init() HAL_PCD_DeInit() HAL_PCD_MspInit() HAL_PCD_MspDeInit() 30.2.3 IO operation functions ers. This subsection provides a set of functions allowing to manage the PCD data transf This section contains the following APIs: HAL_PCD_Start() HAL_PCD_Stop() HAL_PCD_IRQHandler() back() HAL_PCD_DataOutStageCall HAL_PCD_DataInStageCallback() HAL_PCD_SetupStageCallback() HAL_PCD_SOFCallback() HAL_PCD_ResetCallback() HAL_PCD_SuspendCallback() HAL_PCD_ResumeCallback() HAL_PCD_ISOOUTIncompleteCallback() HAL_PCD_ISOINIncompleteCallback() HAL_PCD_ConnectCallback() HAL_PCD_DisconnectCallback() Peripheral Control functions 30.2.4 This subsection provides a set of functions allowing to control the PCD data transfers. This section contains the following APIs: HAL_PCD_DevConnect() HAL_PCD_DevDisconnect() HAL_PCD_SetAddress() HAL_PCD_EP_Open() HAL_PCD_EP_Close() HAL_PCD_EP_Receive() HAL_PCD_EP_GetRxCount() HAL_PCD_EP_Transmit() HAL_PCD_EP_SetStall() HAL_PCD_EP_ClrStall() 2 DocID027328 Rev 1166 355 /

356 HAL PCD Generic Driver UM1850 HAL_PCD_EP_Flush() HAL_PCD_ActivateRemoteWakeup() HAL_PCD_DeActivateRemoteWakeup() Peripheral State functions 30.2.5 This subsection permits to get in run time the status of the peripheral and the data flow. - This section contains the following APIs: HAL_PCD_GetState() Detailed description of functions 30.2.6 HAL_PCD_Init HAL_StatusTypeDef HAL_PCD_Init (PCD_HandleTypeDef * Function name hpcd) ding to the specified parameters in the Initializes the PCD accor Function description PCD_InitTypeDef and create the associated handle. Parameters PCD handle hpcd: Return values status HAL: HAL_PCD_DeInit HAL_StatusTypeDef HAL_PCD_DeInit (PCD_HandleTypeDef * Function name hpcd) Function description DeInitializes the PCD peripheral. Parameters PCD handle hpcd: Return values status HAL: HAL_PCD_MspInit void HAL_PCD_MspInit (PCD_HandleTypeDef * hpcd) Function name Function description Initializes the PCD MSP. Parameters PCD handle hpcd: Return values None: HAL_PCD_MspDeInit void HAL_PCD_MspDeInit (PCD_HandleTypeDef * hpcd) Function name DeInitializes PCD MSP. Function description Parameters PCD handle hpcd: Return values None: HAL_PCD_Start HAL_StatusTypeDef HAL_PCD_Start (PCD_HandleTypeDef * Function name hpcd) DocID027328 / 1166 356 Rev 2

357 UM1850 PCD Generic Driver HAL Start The USB Device. Function description Parameters hpcd: PCD handle Return values HAL: status HAL_PCD_Stop HAL_StatusTypeDef HAL_PCD_Stop (PCD_HandleTypeDef * Function name hpcd) Functio n description Stop The USB Device. Parameters hpcd: PCD handle Return values HAL: status HAL_PCD_IRQHandler void HAL_PCD_IRQHandler (PCD_HandleTypeDef * hpcd) Function name This function handles PCD interrupt request. Function description Parameters hpcd: PCD handle Return values HAL: status HAL_PCD_DataOutStageCallback void HAL_PCD_DataOutStageCallback (PCD_HandleTypeDef * Function name hpcd, uint8_t epnum) Function description Data out stage callbacks. Parameters hpcd: PCD handle endpoint number epnum: Return values None: HAL_PCD_DataInStageCallback void HAL_PCD_DataInStageCallback (PCD_HandleTypeDef * Function name hpcd, uint8_t epnum) Data IN stage callbacks. Function description Parameters PCD handle hpcd: endpoint number epnum: Return values None: HAL_PCD_SetupStageCallback void HAL_PCD_SetupStageCallback (PCD_HandleTypeDef * Function name hpcd) Function description Setup stage callback. Parameters PCD handle hpcd: Return values None: DocID027328 Rev 2 66 357 / 11

358 HAL UM1850 PCD Generic Driver HAL_PCD_SOFCallbac k void HAL_PCD_SOFCallback (PCD_HandleTypeDef * hpcd) Function name Function description USB Start Of Frame callbacks. Parameters hpcd: PCD handle Return values None: HAL_PCD_ResetCallback void HAL_PCD_ResetCallback (PCD_HandleTypeDef * hpcd) Function name USB Reset callbacks. Function description Parameters PCD handle hpcd: Return values None: HAL_PCD_SuspendCallback void HAL_PCD_SuspendCallback (PCD_HandleTypeDef * Function name hpcd) Suspend event callbacks. Function description Parameters PCD handle hpcd: Return values None: HAL_PCD_ResumeCallback void HAL_PCD_ResumeCallback (PCD_HandleTypeDef * Function name hpcd) Function description Resume event callbacks. Parameters hpcd: PCD handle Return values None: HAL_PCD_ISOOUTIncompleteCallback void HAL_PCD_ISOOUTIncompleteCallback Function name (PCD_HandleTypeDef * hpcd, uint8_t epnum) Function description Incomplete ISO OUT callbacks. Parameters hpcd: PCD handle endpoint number epnum: Return values None: HAL_PCD_ISOINIncompleteCallback void HAL_PCD_ISOINIncompleteCallback Function name (PCD_HandleTypeDef * hpcd, uint8_t epnum) Function description Incomplete ISO IN callbacks. Parameters hpcd: PCD handle DocID027328 / 1166 358 Rev 2

359 UM1850 PCD Generic Driver HAL endpoint number epnum: Return values None: AL_PCD_ConnectCallback H void HAL_PCD_ConnectCallback (PCD_HandleTypeDef * Function name hpcd) Function description Connection event callbacks. Parameters hpcd: PCD handle Return values None: HAL_PCD_DisconnectCallback void HAL_PCD_DisconnectCallback (PCD_HandleTypeDef * Function name hpcd) Disconnection event callbacks. Function description Parameters hpcd: PCD handle Return values None: HAL_PCD_DevConnect HAL_StatusTypeDef HAL_PCD_DevConnect Function name (PCD_HandleTypeDef * hpcd) Function description Connect the USB device. Parameters PCD handle hpcd: Return values HAL: status HAL_PCD_DevDisconnect HAL_StatusTypeDef HAL_PCD_DevDisconnect Function name (PCD_HandleTypeDef * hpcd) Function description Disconnect the USB device. Parameters hpcd: PCD handle Return values status HAL: HAL_PCD_SetAddress HAL_StatusTypeDef HAL_PCD_SetAddress Function name (PCD_HandleTypeDef * hpcd, uint8_t address) Function description Set the USB Device address. Par ameters PCD handle hpcd: new device address address: Return values status HAL: 2 DocID027328 Rev 1166 359 /

360 HAL UM1850 PCD Generic Driver HAL_PCD_EP_Open HAL_StatusTypeDef HAL_PCD_EP_Open Function name (PCD_HandleTypeDef * hpcd, uint8_t ep_addr, uint16_t ep_mps, uint8_t ep_type) Function description Open and configure an endpoint. Parameters hpcd: PCD handle endpoint address ep_addr: ep_mps: endpoint max packet size ep_type: endpoint type Return values status HAL: HAL_PCD_EP_Close HAL_StatusTypeDef HAL_PCD_EP_Close Function name (PCD_HandleTypeDef * hpcd, uint8_t ep_addr) Function description Deactivate an endpoint. Parameters PCD handle hpcd: ep_addr: endpoint address Return values status HAL: HAL_PCD_EP_Receive HAL_StatusTypeDef HAL_PCD_EP_Receive Function name (PCD_Hand leTypeDef * hpcd, uint8_t ep_addr, uint8_t * pBuf, uint32_t len) Function description Receive an amount of data. Parameters hpcd: PCD handle ep_addr: endpoint address pBuf: pointer to the reception buffer amount of data to be received len: values Return status HAL: HAL_PCD_EP_Transmit HAL_StatusTypeDef HAL_PCD_EP_Transmit Function name (PCD_HandleTypeDef * hpcd, uint8_t ep_addr, uint8_t * pBuf, uint32_t len) Send an amount of data. Function description Parameters PCD handle hpcd: ep_addr: en dpoint address pointer to the transmission buffer pBuf: len: amount of data to be sent Return values status HAL: DocID027328 / 1166 360 Rev 2

361 UM1850 PCD Generic Driver HAL HAL_PCD_EP_GetRxCount uint16_t HAL_PCD_EP_GetRxCount (PCD_HandleTypeDef * Function name hpcd, uint8_t ep_addr) Function description Get Received Data Size. Parameters hpcd: PCD handle ep_addr: endpoint address Return values Size Data: HAL_PCD_EP_SetStall HAL_StatusTypeDef HAL_PCD_EP_SetStall Function name (PCD_HandleTypeDef * hpcd, uint8_t ep_addr) Function description Set a STALL condition over an endpoint. Parameters hpcd: PCD handle endpoint address ep_addr: Return values status HAL: HAL_PCD_EP_ClrStall HAL_StatusTypeDef HAL_PCD_EP_ClrStall Function name (PCD_HandleTypeDef * hpcd, uint8_t ep_addr) cription Clear a STALL condition over in an endpoint. Function des Parameters hpcd: PCD handle ep_addr: endpoint address Return values HAL: status HAL_PCD_EP_Flush HAL_StatusTypeDef HAL_PCD_EP_Flush Function name (PCD_HandleTypeDef * hpcd, uint8_t ep_addr) Function description Flush an endpoint. Parameters hpcd: PCD handle ep_addr: endpoint address Return values HAL: status HAL_PCD_ActivateRemoteWakeup HAL_StatusTypeDef HAL_PCD_ActivateRemoteWakeup Function name (PCD_HandleTypeDef * hpcd) Function description HAL_PCD_ActivateRemoteWakeup : active remote wakeup signalling. Parameters hpcd: PCD handle Return values status HAL: 2 DocID027328 Rev 1166 361 /

362 HAL PCD Generic Driver UM1850 HAL_PCD_DeActivateRemoteWakeup HAL_StatusTypeDef HAL_PCD_DeActivateRemoteWakeup Function name (PCD_HandleTypeDef * hpcd) HAL_PCD_DeActivateRemoteWakeup : de Function description active remote wakeup - signalling. Parameters hpcd: PCD handle Return values status HAL: HAL_PCD_GetState PCD_StateTypeDef HAL_PCD_GetState (PCD_HandleTypeDef Function name * hpcd) Return the PCD state. Function description Parameters PCD handle hpcd: Return values state HAL: PCD Firmware driver defines 30.3 30.3.1 PCD PCD ENDP PCD_ENDP0 PCD_ENDP1 PCD_ENDP2 PCD_ENDP3 PCD_ENDP4 PCD_ENDP5 PCD_ENDP6 PCD_ENDP7 PCD Endpoint Kind PCD_SNG_BUF PCD_DBL_BUF PCD EP0 MPS PCD_EP0MPS_64 PCD_EP0MPS_32 PCD_EP0MPS_16 PCD_EP0MPS_08 PCD Exported Macros __HAL_PCD_ENABLE __HAL_PCD_DISABLE DocID027328 / 1166 362 Rev 2

363 UM1850 PCD Generic Driver HAL __HAL_PCD_GET_FLAG __HAL_PCD_CLEAR_FLAG __HAL_USB_WAKEUP_EXTI_ENABLE_IT __HAL_USB_WAKEUP_EXTI_DISABLE_IT __HAL_USB_WAKEUP_EXTI_GET_FLAG __HAL_USB_WAKEUP_EXTI_CLEAR_FLAG __HAL_USB_WAKEUP_EXTI_ENABLE_RISING_EDGE __HAL_USB_WAKEUP_EXTI_ENABLE_FALLING_EDGE __HAL_USB_WAKEUP_EXTI_ENABLE_RISING_FALLING_EDGE PCD Instance definition IS_PCD_ALL_INSTANCE PCD PHY Module PCD_PHY_EMBEDDED PCD Speed PCD_SPEED_HIGH PCD_SPEED_HIGH_IN_FULL PCD_SPEED_FULL Timeout Value Turnaround USBD_FS_TRDT_VALUE 2 DocID027328 Rev 1166 363 /

364 HAL UM1850 PCD Extension Driver HAL PCD Extension Driver 31 31.1 PCDEx Firmware driver API description 31.1.1 Extended Peripheral Control functions This section provides functions allowing to: Update FIFO (USB_OTG_FS) Update PMA configuration (USB) This section contains the following APIs: HAL_PCDEx_PMAConfig() Detailed description of functions 31.1.2 HAL_PCDEx_PMAConfig HAL_StatusTypeDef HAL_PCDEx_PMAConfig Function name (PCD_HandleTypeDef * hpcd, uint16_t ep_addr, uint16_t ep_kind, uint32_t pmaadress) Function description Configure PMA for EP. Parameters : Device instance hpcd: endpoint address ep_addr: endpoint Kind USB_SNG_BUF: Single Buffer used ep_kind: USB_DBL_BUF: Double Buffer used pmaadress: EP address in The PMA: In case of single buffer endpoint this parameter is 16 - bit value provi ding the address in PMA allocated to endpoint. In case of double buffer - endpoint this parameter is a 32 bit value providing the endpoint buffer 0 address in the LSB part of 32 bit value and - endpoint buffer 1 address in the MSB part of 32 bit value. - values Return HAL: status HAL_PCDEx_SetConnectionState void HAL_PCDEx_SetConnectionState (PCD_HandleTypeDef * Function name hpcd, uint8_t state) Function description Software Device Connection, this function is not required by USB OTG FS peripheral, it is use d only by USB Device FS peripheral. Parameters PCD handle hpcd: connection state (0 : disconnected / 1: connected) state: Return values None: DocID027328 / 1166 364 Rev 2

365 UM1850 HAL PWR Generic Driver 32 HAL PWR Generic Driver 32.1 PWR Firmware driver registers structures 32.1.1 PWR_PVDTypeDef Data Fields uint32_t PVDLevel uint32_t Mode Field Documentation uint32_t PWR_PVDTypeDef::PVDLevel PVDLevel: Specifies the PVD detection level. This parameter can b e a value of PWR_PVD_detection_level uint32_t PWR_PVDTypeDef::Mode Mode: Specifies the operating mode for the selected pins. This parameter can be a value of PWR_PVD_Mode PWR Firmware driver API description 32.2 initialization functions - Initialization and de 32.2.1 After reset, the backup domain (RTC registers, RTC backup data registers) is protec ted against possible unwanted write accesses. To enable access to the RTC Domain and RTC registers, proceed as follows: Enable the Power Controller (PWR) APB1 interface clock using the __HAL_RCC_PWR_CLK_ENABLE() macro. Enable access to RTC domain using the HAL_PWR_EnableBkUpAccess() function. This section contains the following APIs: HAL_PWR_DeInit() HAL_PWR_EnableBkUpAccess() HAL_PWR_DisableBkUpAccess() Peripheral Control functions 32.2.2 PVD configuration The PVD is used to monitor the VDD power supply by comparing it to a threshold he PWR_CR). selected by the PVD Level (PLS[2:0] bits in t A PVDO flag is available to indicate if VDD/VDDA is higher or lower than the PVD threshold. This event is internally connected to the EXTI line16 and can generate an interrupt if enabled. This is done through __HAL_PVD_EXTI_ENABLE_IT() macro. The PVD is stopped in Standby mode. WakeUp pin configuration WakeUp pin is used to wake up the system from Standby mode. This pin is forced in down configuration and is active on rising edges. - input pull There is one WakeUp pin: WakeUp Pin 1 on PA.00. 2 DocID027328 Rev 1166 365 /

366 HAL PWR Generic Driver UM1850 Low Power modes configuration - The device features 3 low power modes: Sleep mode: CPU clock off, all peripherals including Cortex M3 core peripherals like - NVIC, SysTick, etc. are kept running Stop mode: All clocks are stopped Standby mode: 1.8V domain pow ered off Sleep mode Entry: The Sleep mode is entered by using the HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFx) functions with PWR_SLEEPENTRY_WFI: enter SLEEP mode with WFI instruction PWR_SLEEPENTRY_WFE: enter SLEEP mode with WFE inst ruction Exit: WFI entry mode, Any peripheral interrupt acknowledged by the nested vectored interrupt controller (NVIC) can wake up the device from Sleep mode. WFE entry mode, Any wakeup event can wake up the device from Sleep mode. upt w/o NVIC configuration & SEVONPEND bit set in Any peripheral interr the Cortex (HAL_PWR_EnableSEVOnPend) Any EXTI Line (Internal or External) configured in Event mode Stop mode The Stop mode is based on the Cortex - M3 deepsleep mode combined with peripheral he voltage regulator can be configured either in normal or low - power mode. clock gating. T In Stop mode, all clocks in the 1.8 V domain are stopped, the PLL, the HSI and the HSE RC oscillators are disabled. SRAM and register contents are preserved. In Stop mode, all I/O p ins keep the same state as in Run mode. Entry: The Stop mode is entered using the HAL_PWR_EnterSTOPMode(PWR_REGULATOR_VALUE, PWR_SLEEPENTRY_WFx ) function with: PWR_REGULATOR_VALUE= PWR_MAINREGULATOR_ON: Main regulator ON. PWR_REGULATOR_VALUE= PWR_LOWPOW ERREGULATOR_ON: Low Power regulator ON. PWR_SLEEPENTRY_WFx= PWR_SLEEPENTRY_WFI: enter STOP mode with WFI instruction PWR_SLEEPENTRY_WFx= PWR_SLEEPENTRY_WFE: enter STOP mode with WFE instruction Exit: WFI entry mode, Any EXTI Line (Internal or External) configured in Interrupt mode with NVIC configured WFE entry mode, Any EXTI Line (Internal or External) configured in Event mode. Standby mode The Standby mode allows to achieve the lowest power consumption. It is based on the M3 deepsleep mode, wi th the voltage regulator disabled. The 1.8 V domain is Cortex - consequently powered off. The PLL, the HSI oscillator and the HSE oscillator are also switched off. SRAM and register contents are lost except for registers in the Backup domain and Standby circuitry Entry: DocID027328 / 1166 366 Rev 2

367 PWR Generic Driver UM1850 HAL The Standby mode is entered using the HAL_PWR_EnterSTANDBYMode() function. Exit: WKUP pin rising edge, RTC alarm event rising edge, external Reset in NRSTpin, IWDG Reset Auto power mode - wakeup (AWU) from low - The MCU can be woken up from low - power mode by an RTC Alarm event, without depending on an external interrupt (Auto - wakeup mode). RTC auto - wakeup (AWU) from the Stop and Standby modes To wake up from the Stop mode with an RTC alarm event, it is necessary to configure the RTC to generate the RTC alarm using the HAL_RTC_SetAlarm_IT() function. PWR Workarounds linked to Silicon Limitation Below the list of all silicon limitations known on STM32F1xx prouct. Workarounds Implemented inside PWR HAL Driver 1. overloaded the WFE by an internal - bugging Stop mode with WFE entry De a. function This section contains the following APIs: HAL_PWR_ConfigPVD() HAL_PWR_EnablePVD() HAL_PWR_DisablePVD() HAL_PWR_EnableWakeUpPin() HAL_PWR_DisableWakeUpPin() HAL_PWR_EnterSLEEPMode() HAL_PWR_EnterSTOPMode () HAL_PWR_EnterSTANDBYMode() HAL_PWR_EnableSleepOnExit() HAL_PWR_DisableSleepOnExit() HAL_PWR_EnableSEVOnPend() HAL_PWR_DisableSEVOnPend() HAL_PWR_PVD_IRQHandler() HAL_PWR_PVDCallback() Detailed description of functions 32.2.3 HAL_PWR_DeInit void HAL_PWR_DeInit (void ) Function name Deinitializes the PWR peripheral registers to their default reset Function description values. Return values None: HAL_PWR_EnableBkUpAccess void HAL_PWR_EnableBkUpAccess (void ) Function name Function description Enables access to the backup domain (RTC registers, RTC backup data registers ). 2 DocID027328 Rev 1166 367 /

368 HAL PWR Generic Driver UM1850 Return values None: Notes If the HSE divided by 128 is used as the RTC clock, the Backup Domain Access should be kept enabled. ess HAL_PWR_DisableBkUpAcc void HAL_PWR_DisableBkUpAccess (void ) Function name Function description Disables access to the backup domain (RTC registers, RTC backup data registers). Return values None: Notes If the HSE divided by 128 is used as the RTC clock, the Domain Access should be kept enabled. Backup HAL_PWR_ConfigPVD void HAL_PWR_ConfigPVD (PWR_PVDTypeDef * sConfigPVD) Function name Function description Configures the voltage threshold detected by the Power Voltage Detector(PVD). Parameters r to an PWR_PVDTypeDef structure that pointe sConfigPVD: contains the configuration information for the PVD. Return values None: Notes Refer to the electrical characteristics of your device datasheet for more details about the voltage threshold corresponding to each detec tion level. HAL_PWR_EnablePVD void HAL_PWR_EnablePVD (void ) Function name Enables the Power Voltage Detector(PVD). Function description Return values None: HAL_PWR_DisablePVD void HAL_PWR_DisablePVD (void ) Function name Function description Disables the Power Voltage Detector(PVD). Return values None: HAL_PWR_EnableWakeUpPin void HAL_PWR_EnableWakeUpPin (uint32_t WakeUpPinx) Function name Function description Enables the WakeUp PINx functionality. Parameters Up pin to enable. WakeUpPinx: - Specifies the Power Wake This parameter can be one of the following values: PWR_WAKEUP_PIN1 Return values None: DocID027328 / 1166 368 Rev 2

369 UM1850 PWR Generic Driver HAL HAL_PWR_DisableWakeUpPin void HAL_PWR_DisableWakeUpPin (uint32_t WakeUpPinx) Function name Function description Disables the WakeUp PINx functionality. Parameters Up pin to disable. - Specifies the Power Wake WakeUpPinx: This parameter can be one of the following values: PWR_WAKEUP_PIN1 Return values None: HAL_PWR_EnterSTOPMode void HAL_PWR_EnterS TOPMode (uint32_t Regulator, uint8_t Function name STOPEntry) Enters Stop mode. Function description Parameters Specifies the regulator state in Stop mode. This Regulator: parameter can be one of the following values: PWR_MAINREGULATOR_ON: Stop mode with ON regulator PWR_LOWPOWERREGULATOR_ON: Stop mode with low power regulator ON STOPEntry: Specifies if Stop mode in entered with WFI or WFE instruction. This parameter can be one of the following values: PWR_STOPENTRY_WFI: Enter Stop mode with WFI instruction OPENTRY_WFE: Enter Stop mode with WFE PWR_ST instruction Return values None: Notes In Stop mode, all I/O pins keep the same state as in Run mode. When exiting Stop mode by using an interrupt or a wakeup event, HSI RC oscillator is selected as system clock. When the voltage regulator operates in low power mode, an additional startup delay is incurred when waking up from Stop mode. By keeping the internal regulator ON during Stop mode, the consumption is higher although the startup time is reduced. HAL_PWR_En terSLEEPMode void HAL_PWR_EnterSLEEPMode (uint32_t Regulator, uint8_t Function name SLEEPEntry) Enters Sleep mode. Function description Parameters - Regulator state as no effect in SLEEP mode Regulator: allows to support portability from legacy software Specifies if SLEEP mode is entered with WFI SLEEPEntry: or WFE instruction. When WFI entry is used, tick interrupt nterrupt wake up have to be disabled if not desired as the i source. This parameter can be one of the following values: PWR_SLEEPENTRY_WFI: enter SLEEP mode with WFI 2 DocID027328 Rev 1166 369 /

370 HAL UM1850 PWR Generic Driver instruction PWR_SLEEPENTRY_WFE: enter SLEEP mode with WFE instruction Return values None: Notes he same state as in Run In Sleep mode, all I/O pins keep t mode. HAL_PWR_EnterSTANDBYMode void HAL_PWR_EnterSTANDBYMode (void ) Function name Function description Enters Standby mode. Return values None: Notes In Standby mode, all I/O pins are high impedance except for: Reset pad (still available)TAMPER pin if configured for tamper or calibration out.WKUP pin (PA0) if enabled. HAL_PWR_EnableSleepOnExit void HAL_PWR_EnableSleepOnExit (void ) Function name tion description Func Exit when returning from Handler mode to - On - Indicates Sleep Thread mode. Return values None: Notes Set SLEEPONEXIT bit of SCR register. When this bit is set, the processor re - enters SLEEP mode when an interruption handling is over. Setting this bit is useful when the processor is expected to run only on interruptions handling. HAL_PWR_DisableSleepOnExit void HAL_PWR_DisableSleepOnExit (void ) Function name On - Disables Sleep Function description Exit feature when returning from Hand ler mode - to Thread mode. Return values None: Notes Clears SLEEPONEXIT bit of SCR register. When this bit is - set, the processor re enters SLEEP mode when an interruption handling is over. HAL_PWR_EnableSEVOnPend void HAL_PWR_EnableSEVOnPend (void ) Function name Enables CORTEX M3 SEVONPEND bit. Function description Return values None: Notes Sets SEVONPEND bit of SCR register. When this bit is set, this causes WFE to wake up when an interrupt moves from inactive to pended. DocID027328 / 1166 370 Rev 2

371 UM1850 HAL PWR Generic Driver HAL_PWR_DisableSEVOnPend void HAL_PWR_DisableSEVOnPend (void ) Function name Function description Disables CORTEX M3 SEVONPEND bit. Return values None: Notes Clears SEVONPEND bit of SCR register. When this bit is set, an interrupt moves from this causes WFE to wake up when inactive to pended. HAL_PWR_PVD_IRQHandler void HAL_PWR_PVD_IRQHandler (void ) Function name This function handles the PWR PVD interrupt request. Function description Return values None: Notes he PVD_IRQHandler(). This API should be called under t HAL_PWR_PVDCallback void HAL_PWR_PVDCallback (void ) Function name Function description PWR PVD interrupt callback. Return values None: PWR Firmware driver defines 32.3 32.3.1 PWR PWR CR Register alias address LPSDSR_BIT_NUMBER CR_LPSDSR_BB DBP_BIT_NUMBER CR_DBP_BB PVDE_BIT_NUMBER CR_PVDE_BB PWR CSR Register alias address CSR_EWUP_BB PWR Exported Macros Description: __HAL_PWR_GET_FLAG Check PWR flag is set or not. Parameters: __FLAG__: specifies the flag to check. This parameter can be one of the following values: 2 DocID027328 Rev 1166 371 /

372 HAL UM1850 PWR Generic Driver PWR_FLAG_WU: Wake Up flag. This flag indicates that a wakeup event was received from the WKUP pin or from RTC alarm An the additional wakeup event is detected if the WKUP pin is enabled (by setting the EWUP bit) when the WKUP pin level is already high. PWR_FLAG_SB: StandBy flag. This flag indicates that the system was resumed from StandBy mode. PWR_FLAG_PVDO: PVD Output. This flag is valid only if PVD is enabled by the HAL_PWR_EnableP VD() function. The PVD is stopped by Standby mode For this reason, this bit is equal to 0 after Standby or reset until the PVDE bit is set. Return value: The: new state of __FLAG__ (TR UE or FALSE). Description: __HAL_PWR_CLEAR_FLAG Clear the PWR's pending flags. Parameters: __FLAG__: specifies the flag to clear. This parameter can be one of the following values: PWR_FLAG_WU: Wake Up flag PWR_FLAG_SB: StandBy flag Description: __HAL_PWR_PVD_EXTI_ENABLE_IT Enable interrupt on PVD Exti Line 16. DocID027328 / 1166 372 Rev 2

373 HAL UM1850 PWR Generic Driver Return value: None. Description: __HAL_PWR_PVD_EXTI_DISABLE_IT Disable interrupt on PVD Exti Line 16. Return value: None. Description: __HAL_PWR_PVD_EXTI_ENABLE_EVENT event on PVD Exti Enable Line 16. Return value: None. Description: __HAL_PWR_PVD_EXTI_DISABLE_EVENT Disable event on PVD Exti Line 16. Return value: None. Description: __HAL_PWR_PVD_EXTI_ENABLE_FALLING_EDGE PVD EXTI line configuration: set falling edge trigger. Return value: None. Description: __HAL_PWR_PVD_EXTI_DISABLE_FALLING_EDGE Disable the PVD Extended Interrupt Falling Trigger. Return value: None. Description: __HAL_PWR_PVD_EXTI_ENABLE_RISING_EDGE PVD EXTI line configuration: set rising edge trigger. Return value: None. Description: __HAL_PWR_PVD_EXTI_DISABLE_RISING_EDGE Disable the PVD Extended Interrupt Rising Trigger. Return value: None. 2 DocID027328 Rev 1166 373 /

374 HAL UM1850 PWR Generic Driver Description: __HAL_PWR_PVD_EXTI_ENABLE_RISING_FALLING_ EDGE PVD EXTI line configuration: set rising & falling edge trigger. Return value: None. Description: __HAL_PWR_PVD_EXTI_DISABLE_RISING_FALLING _EDGE Disable the PVD Extended Interrupt Rising & Falling Trigger. Return value: None. Description: __HAL_PWR_PVD_EXTI_GET_FLAG Check whether the specified PVD EXTI nterrupt flag is set or not. i Return value: EXTI: PVD Line Status. Description: __HAL_PWR_PVD_EXTI_CLEAR_FLAG Clear the PVD EXTI flag. Return value: None. Description: __HAL_PWR_PVD_EXTI_GENERATE_SWIT Generate a Software interrupt on selected EXTI line. Return value: None. PWR Flag PWR_FLAG_WU PWR_FLAG_SB PWR_FLAG_PVDO PWR PVD detection level PWR_PVDLEVEL_0 PWR_PVDLEVEL_1 PWR_PVDLEVEL_2 PWR_PVDLEVEL_3 PWR_PVDLEVEL_4 PWR_PVDLEVEL_5 DocID027328 / 1166 374 Rev 2

375 HAL UM1850 PWR Gene ric Driver PWR_PVDLEVEL_6 PWR_PVDLEVEL_7 PWR PVD Mode basic mode is used PWR_PVD_MODE_NORMAL PWR_PVD_MODE_IT_RISING External Interrupt Mode with Rising edge trigger detection External Interrupt Mode with Falling PWR_PVD_MODE_IT_FALLING edge trigger detection External Interrupt Mode with PWR_PVD_MODE_IT_RISING_FALLING Rising/Falling edge trigger detection PWR_PVD_MODE_EVENT_RISING Event Mode with Rising edge trigger detection Event Mode with Falling edge trigger PWR_PVD_MODE_EVENT_FALLING detection nt Mode with Rising/Falling edge Eve PWR_PVD_MODE_EVENT_RISING_FALLING trigger detection PWR PVD Mode Mask PVD_MODE_IT PVD_MODE_EVT PVD_RISING_EDGE PVD_FALLING_EDGE PWR Register alias address PWR_OFFSET PWR_CR_OFFSET PWR_CSR_OFFSET PWR_CR_OFFSET_BB PWR_CSR_OFFSET_BB Regulator state in SLEEP/STOP mode PWR PWR_MAINREGULATOR_ON PWR_LOWPOWERREGULATOR_ON PWR SLEEP mode entry PWR_SLEEPENTRY_WFI PWR_SLEEPENTRY_WFE PWR STOP mode entry PWR_STOPENTRY_WFI PWR_STOPENTRY_WFE PWR WakeUp Pins PWR_WAKEUP_PIN1 2 DocID027328 Rev 1166 375 /

376 HAL UM1850 RCC Generic Driver 33 HAL RCC Generic Driver 33.1 RCC Firmware driver registers structures RCC_PLLInitTypeDef 33.1.1 Data Fields uint32_t PLLState uint32_t PLLSource uint32_t PLLMUL Field Documentation uint32_t RCC_PLLInitTypeDef::PLLState PLLState: The new state of the PLL. This parameter can be a value of RCC_PLL_Config uint32_t RCC_PLLInitTypeDef::PLLSource This parameter must be a value of PLLSource: PLL entry clock source. RCC_PLL_Clock_Source uint32_t RCC_PLLInitTypeDef::PLLMUL PLLMUL: Multiplication factor for PLL VCO input clock This parameter must be a ultiplication_Factor RCCEx_PLL_M value of RCC_ClkInitTypeDef 33.1.2 Data Fields uint32_t ClockType uint32_t SYSCLKSource uint32_t AHBCLKDivider uint32_t APB1CLKDivider uint32_t APB2CLKDivider Field Documentation RCC_ClkInitTypeDef::ClockType uint32_t The clock to be configured. This parameter can be a value of RCC_System_Clock_Type uint32_t RCC_ClkInitTypeDef::SYSCLKSource be a value of The clock source (SYSCLKS) used as system clock. This parameter can RCC_System_Clock_Source uint32_t RCC_ClkInitTypeDef::AHBCLKDivider The AHB clock (HCLK) divider. This clock is derived from the system clock (SYSCLK). RCC_AHB_Clock_Source This parameter can be a value of uint32_t RCC_ClkInitTypeDef::APB1CLKDivider The APB1 clock (PCLK1) divider. This clock is derived from the AHB clock (HCLK). This parameter can be a value of RCC_APB1_APB2_Clock_Source RCC_ClkInitTypeDef::APB2CLKDivider uint32_t The APB2 clock (PCLK2) divider. This clock is derived from the AHB clock (HCLK). RCC_APB1_APB2_Clock_Source This parameter can be a value of DocID027328 / 1166 376 Rev 2

377 UM1850 HAL RCC Generic Driver RCC Firmware driver API description 33.2 33.2.1 RCC specific features After reset the device is running from Internal High Speed oscillator (HSI 8MHz) with Flash 0 wait state, Flash prefetch buffer is enabled, and all p eripherals are off except internal SRAM, Flash and JTAG. There is no prescaler on High speed (AHB) and Low speed (APB) buses; all peripherals mapped on these buses are running at HSI speed. The clock for all peripherals is switched off, except the SRAM an d FLASH. All GPIOs are in input floating state, except the JTAG pins which are assigned to be used for debug purpose. Once the device started from reset, the user application has to: Configure the clock source to be used to drive the System clock (if the application needs higher frequency/performance) Configure the System clock frequency and Flash settings Configure the AHB and APB buses prescalers Enable the clock for the peripheral(s) to be used Configure the clock source(s) for peripherals whose clocks are not derived from the System clock (I2S, RTC, ADC, USB OTG FS) RCC Limitations 33.2.2 A delay between an RCC peripheral clock enable and the effective peripheral enabling e the peripheral read/write from/to registers. should be taken into account in order to manag This delay depends on the peripheral mapping. AHB & APB peripherals, 1 dummy read is necessary Workarounds: For AHB & APB peripherals, a dummy read to the peripheral register has been 1. inserted in each __HAL_RCC_PPP_CLK_ENABLE() macro. 33.2.3 Initialization and de - initialization functions This section provide s functions allowing to configure the internal/external oscillators (HSE, HSI, LSE, LSI, PLL, CSS and MCO) and the System buses clocks (SYSCLK, AHB, APB1 and APB2). Internal/external clock and PLL configuration HSI (high - immed RC used directly or through the PLL tr - speed internal), 8 MHz factory 1. as System clock source. 2. LSI (low - speed internal), ~40 KHz low consumption RC used as IWDG and/or RTC clock source. - 3. speed external), 4 to 24 MHz (STM32F100xx) or 4 to 16 MHz HSE (high (STM32F101x/STM32F102x/STM32F1 03x) or 3 to 25 MHz (STM32F105x/STM32F107x) crystal oscillator used directly or through the PLL as System clock source. Can be used also as RTC clock source. - speed external), 32 KHz oscillator used as RTC clock source. 4. LSE (low PLL (clocked by HSI or HSE 5. ), featuring different output clocks: The first output is used to generate the high speed system clock (up to 72 MHz for STM32F10xxx or up to 24 MHz for STM32F100xx) The second output is used to generate the clock for the USB OTG FS (48 MHz) 2 DocID027328 Rev 1166 377 /

378 RCC Generic Driver HAL UM1850 ecurity system), once enable using the macro CSS (Clock s 6. __HAL_RCC_CSS_ENABLE() and if a HSE clock failure occurs(HSE used directly or through PLL as System clock source), the System clocks automatically switched to HSI and an interrupt is generated if enabled. The in terrupt is linked to the Cortex M3 - - NMI (Non Maskable Interrupt) exception vector. 7. MCO1 (microcontroller clock output), used to output SYSCLK, HSI, HSE or PLL clock (divided by 2) on PA8 pin + PLL2CLK, PLL3CLK/2, PLL3CLK and XTI for STM32F105x/STM32F107x System, AHB and APB buses clocks configuration Several clock sources can be used to drive the System clock (SYSCLK): HSI, HSE 1. and PLL. The AHB clock (HCLK) is derived from System clock through configurable prescaler and used to clock the CPU, memory and p eripherals mapped on AHB bus (DMA, GPIO...). APB1 (PCLK1) and APB2 (PCLK2) clocks are derived from AHB clock through configurable prescalers and used to clock the peripherals mapped on these buses. You can use "@ref HAL_RCC_GetSysClockFreq()" function to r etrieve the frequencies of these clocks. All the peripheral clocks are derived from the System clock (SYSCLK) except: RTC: RTC clock can be derived either from the LSI, LSE or HSE clock divided by 128. USB OTG FS and RTC: USB OTG FS require a frequency eq ual to 48 MHz to work correctly. This clock is derived of the main PLL through PLL Multiplier.I2S interface on STM32F105x/STM32F107x can be derived from PLL3CLKIWDG clock which is always the LSI clock. and HCLK/PCLK2 is 72 For STM32F10xxx, the maximum frequency of the SYSCLK 2. MHz, PCLK1 36 MHz. For STM32F100xx, the maximum frequency of the SYSCLK and HCLK/PCLK1/PCLK2 is 24 MHz. Depending on the SYSCLK frequency, the flash latency should be adapted accordingly. This section contains the following APIs: HAL_RCC_DeInit() HAL_RCC_OscConfig() HAL_RCC_ClockConfig() 33.2.4 Peripheral Control functions This subsection provides a set of functions allowing to control the RCC Clocks frequencies. This section contains the following APIs: HAL_RCC_MCOConfig() HAL_RCC_EnableCSS() HAL_RCC_DisableCSS() HAL_RCC_GetSysClockFreq() HAL_RCC_GetHCLKFreq() HAL_RCC_GetPCLK1Freq() HAL_RCC_GetPC LK2Freq() HAL_RCC_GetOscConfig() HAL_RCC_GetClockConfig() HAL_RCC_NMI_IRQHandler() HAL_RCC_CSSCallback() n of functions Detailed descriptio 33.2.5 HAL_RCC_DeInit void HAL_RCC_DeInit (void ) Function name 378 DocID027328 / Rev 2 1166

379 UM1850 HAL RCC Generic Driver Function description Resets the RCC clock configuration to the default reset state. Return values None: Notes The default reset state of the clock configuration is given below: HSI ON and used as system clock sourceHSE and PLL OFFAHB, APB1 and APB2 prescaler set to 1.CSS and MCO1 OFFAll interrupts disabled This function does not modify the configuration of the ripheral clocksLSI, LSE and RTC clocks Pe HAL_RCC_OscConfig HAL_StatusTypeDef HAL_RCC_OscConfig Function name (RCC_OscInitTypeDef * RCC_OscInitStruct) Initializes the RCC Oscillators according to the specified Function description parameters in the RCC_OscInitTypeDef. Parameters pointer to an RCC_OscInitTypeDef RCC_OscInitStruct: structure that contains the configuration information for the RCC Oscillators. Return values status HAL: Notes The PLL is not disabled when used as system clock. The PLL is not disabled when USB OTG FS clock is enabled (specific to devices with USB FS) Transitions LSE Bypass to LSE On and LSE On to LSE Bypass are not supported by this macro. User should request a transition to LSE Off first and then LSE On or LSE Bypass. Transition HSE Bypass to HSE On and HSE On to HSE Bypass are not supported by this macro. User should request a transition to HSE Off first and then HSE On or HSE Bypass. _RCC_ClockConfig HAL HAL_StatusTypeDef HAL_RCC_ClockConfig Function name (RCC_ClkInitTypeDef * RCC_ClkInitStruct, uint32_t FLatency) Function description Initializes the CPU, AHB and APB buses clocks according to the specified parameters in the RCC_ClkInitStr uct. Parameters RCC_ClkInitStruct: pointer to an RCC_OscInitTypeDef structure that contains the configuration information for the RCC peripheral. FLatency: FLASH Latency The value of this parameter depend on device used within the same series alues Return v status HAL: Notes The SystemCoreClock CMSIS variable is used to store System Clock Frequency and updated by HAL_RCC_GetHCLKFreq() function called within this function The HSI is used (enabled by hardware) as system clock - up from STOP and - Reset, wake up from source after start STANDBY mode, or in case of failure of the HSE used directly or indirectly as system clock (if the Clock Security System CSS is enabled). 2 DocID027328 Rev 1166 379 /

380 HAL UM1850 RCC Generic Driver A switch from one clock source to another occurs only if the up delay target clock source is ready - (clock stable after start or PLL locked). If a clock source which is not yet ready is selected, the switch will occur when the clock source will be ready. You can use HAL_RCC_GetClockConfig() function to know which clock is currently used as syst em clock source. HAL_RCC_MCOConfig void HAL_RCC_MCOConfig (uint32_t RCC_MCOx, uint32_t Function name RCC_MCOSource, uint32_t RCC_MCODiv) Selects the clock source to output on MCO pin. Function description Parameters RCC_MCOx: ction for the clock specifies the output dire source. This parameter can be one of the following values: RCC_MCO1 Clock source to output on MCO1 pin(PA8). RCC_MCOSource: specifies the clock source to output. This parameter can be one of the following values: RCC_MCO1SOURCE_NOCLO CK No clock selected as MCO clock RCC_MCO1SOURCE_SYSCLK System clock selected as MCO clock RCC_MCO1SOURCE_HSI HSI selected as MCO clock RCC_MCO1SOURCE_HSE HSE selected as MCO clock specifies the MCO DIV. This parameter can RCC_MCODiv: be one of the following values: RCC_MCODIV_1 no division applied to MCO clock Return values None: Notes MCO pin should be configured in alternate function mode. HAL_RCC_EnableCSS ableCSS (void ) void HAL_RCC_En Function name Function description Enables the Clock Security System. Return values None: Notes If a failure is detected on the HSE oscillator clock, this oscillator is automatically disabled and an interrupt is about the failure (Clock generated to inform the software Security System Interrupt, CSSI), allowing the MCU to perform rescue operations. The CSSI is linked to the Cortex - Maskable Interrupt) exception vector. M3 NMI (Non - HAL_RCC_DisableCSS void HAL_RCC_DisableCSS (void ) Function name Function description Disables the Clock Security System. Return values None: DocID027328 / 1166 380 Rev 2

381 UM1850 HAL RCC Generic Driver HAL_RCC_GetSysClockFreq uint32_t HAL_RCC_GetSysClockFreq (void ) Function name Returns the SYSCLK frequency. Function description Return values SYSCLK: frequency Notes The system frequency computed by this function is not the real frequency in the chip. It is calculated based on the predefined constant and the selected clock source: If SYSCLK source is HSI, function returns values based on HSI_VALUE(*) s HSE, function returns a value based on If SYSCLK source i HSE_VALUE divided by PREDIV factor(**) If SYSCLK source is PLL, function returns a value based on HSE_VALUE divided by PREDIV factor(**) or HSI_VALUE(*) multiplied by the PLL factor. (*) HSI_VALUE is a constant defi ned in stm32f1xx_hal_conf.h file (default value 8 MHz) but the real value may vary depending on the variations in voltage and temperature. (**) HSE_VALUE is a constant defined in stm32f1xx_hal_conf.h file (default value 8 MHz), user has to VALUE is same as the real frequency of the ensure that HSE_ crystal used. Otherwise, this function may have wrong result. The result of this function could be not correct when using fractional value for HSE crystal. This function can be used by the user application to comp ute the baud - rate for the communication peripherals or configure other parameters. Each time SYSCLK changes, this function must be called to update the right SYSCLK value. Otherwise, any configuration based on this function will be incorrect. HAL_RCC_GetH CLKFreq uint32_t HAL_RCC_GetHCLKFreq (void ) Function name Returns the HCLK frequency. Function description Return values frequency HCLK: Notes Each time HCLK changes, this function must be called to configuration update the right HCLK value. Otherwise, any based on this function will be incorrect. The SystemCoreClock CMSIS variable is used to store System Clock Frequency and updated within this function HAL_RCC_GetPCLK1Freq uint32_t HAL_RCC_GetPCLK1Freq (void ) Function name Returns the PCLK1 frequency. ion Function descript Return values frequency PCLK1: Notes Each time PCLK1 changes, this function must be called to update the right PCLK1 value. Otherwise, any configuration 2 DocID027328 Rev 1166 381 /

382 HAL UM1850 RCC Generic Driv er based on this function will be incorrect. HAL_RCC_GetPCLK2Freq uint32_t HAL_RCC_GetPCLK2Freq (void ) Function name Function description Returns the PCLK2 frequency. Return values PCLK2: frequency Notes Each time PCLK2 changes, this function must be called to update the right PCLK2 value. Otherwise, any configurat ion based on this function will be incorrect. HAL_RCC_GetOscConfig void HAL_RCC_GetOscConfig (RCC_OscInitTypeDef * Function name RCC_OscInitStruct) Configures the RCC_OscInitStruct according to the internal RCC Function description configuration registers. Parameters RCC_OscInitStruct: pointer to an RCC_OscInitTypeDef structure that will be configured. Return values None: HAL_RCC_GetClockConfig L_RCC_GetClockConfig (RCC_ClkInitTypeDef * void HA Function name RCC_ClkInitStruct, uint32_t * pFLatency) Get the RCC_ClkInitStruct according to the internal RCC Function description configuration registers. Parameters RCC_ClkInitStruct: pointer to an RCC_ClkInitTypeDef str ucture that contains the current clock configuration. pFLatency: Pointer on the Flash Latency. Return values None: HAL_RCC_NMI_IRQHandler void HAL_RCC_NMI_IRQHandler (void ) Function name Function description This function handles the RCC CSS interrupt request. Return values None: Notes This API should be called under the NMI_Handler(). HAL_RCC_CSSCallback void HAL_RCC_CSSCallback (void ) Function name Function description RCC Clock Security System interrupt callback. Return values none: DocID027328 / 1166 382 Rev 2

383 HAL UM1850 RCC Generic Driver 33.3 RCC Firmware driver defines 33.3.1 RCC AHB Clock Source RCC_SYSCLK_DIV1 SYSCLK not divided RCC_SYSCLK_DIV2 SYSCLK divided by 2 RCC_SYSCLK_DIV4 SYSCLK divided by 4 RCC_SYSCLK_DIV8 SYSCLK divided by 8 SYSCLK divided by 16 RCC_SYSCLK_DIV16 SYSCLK divided by 64 RCC_SYSCLK_DIV64 RCC_SYSCLK_DIV128 SYSCLK divided by 128 256 RCC_SYSCLK_DIV256 SYSCLK divided by SYSCLK divided by 512 RCC_SYSCLK_DIV512 AHB Peripheral Clock Enable Disable Status __HAL_RCC_DMA1_IS_CLK_ENABLED __HAL_RCC_DMA1_IS_CLK_DISABLED __HAL_RCC_SRAM_IS_CLK_ENABLED __HAL_RCC_SRAM_IS_CLK_DISABLED __HAL_RCC_FLITF_IS_CLK_ENABLED __HAL_RCC_FLITF_IS_CLK_DISABLED __HAL_RCC_CRC_IS_CLK_ENABLED __HAL_RCC_CRC_IS_CLK_DISABLED Alias define maintained for legacy __HAL_RCC_SYSCFG_CLK_DISABLE __HAL_RCC_SYSCFG_CLK_ENABLE __HAL_RCC_SYSCFG_FORCE_RESET __HAL_RCC_SYSCFG_RELEASE_RESET APB1 APB2 Clock Source RCC_HCLK_DIV1 HCLK not divided HCLK divided by 2 RCC_HCLK_DIV2 HCLK divided by 4 RCC_HCLK_DIV4 HCLK divided by 8 RCC_HCLK_DIV8 RCC_HCLK_DIV16 HCLK divided by 16 APB1 Clock Enable Disable __HAL_RCC_TIM2_CLK_ENABLE __HAL_RCC_TIM3_CLK_ENABLE __HAL_RCC_WWDG_CLK_ENABLE 2 DocID027328 Rev 1166 383 /

384 HAL UM1850 RCC Generic Driver __HAL_RCC_USART2_CLK_ENABLE __HAL_RCC_I2C1_CLK_ENABLE __HAL_RCC_BKP_CLK_ENABLE __HAL_RCC_PWR_CLK_ENABLE __HAL_RCC_TIM2_CLK_DISABLE __HAL_RCC_TIM3_CLK_DISABLE __HAL_RCC_WWDG_CLK_DISABLE __HAL_RCC_USART2_CLK_DISABLE __HAL_RCC_I2C1_CLK_DISABLE __HAL_RCC_BKP_CLK_DISABLE __HAL_RCC_PWR_CLK_DISABLE APB1 Force Release Reset __HAL_RCC_APB1_FORCE_RESET __HAL_RCC_TIM2_FORCE_RESET __HAL_RCC_TIM3_FORCE_RESET __HAL_RCC_WWDG_FORCE_RESET __HAL_RCC_USART2_FORCE_RESET __HAL_RCC_I2C1_FORCE_RESET __HAL_RCC_BKP_FORCE_RESET __HAL_RCC_PWR_FORCE_RESET __HAL_RCC_APB1_RELEASE_RESET __HAL_RCC_TIM2_RELEASE_RESET __HAL_RCC_TIM3_RELEASE_RESET __HAL_RCC_WWDG_RELEASE_RESET __HAL_RCC_USART2_RELEASE_RESET __HAL_RCC_I2C1_RELEASE_RESET __HAL_RCC_BKP_RELEASE_RESET __HAL_RCC_PWR_RELEASE_RESET APB1 Peripheral Clock Enable Disable Status __HAL_RCC_TIM2_IS_CLK_ENABLED __HAL_RCC_TIM2_IS_CLK_DISABLED __HAL_RCC_TIM3_IS_CLK_ENABLED __HAL_RCC_TIM3_IS_CLK_DISABLED __HAL_RCC_WWDG_IS_CLK_ENABLED __HAL_RCC_WWDG_IS_CLK_DISABLED __HAL_RCC_USART2_IS_CLK_ENABLED DocID027328 / 1166 384 Rev 2

385 UM1850 RCC Generic Driver HAL __HAL_RCC_USART2_IS_CLK_DISABLED __HAL_RCC_I2C1_IS_CLK_ENABLED __HAL_RCC_I2C1_IS_CLK_DISABLED __HAL_RCC_BKP_IS_CLK_ENABLED __HAL_RCC_BKP_IS_CLK_DISABLED __HAL_RCC_PWR_IS_CLK_ENABLED __HAL_RCC_PWR_IS_CLK_DISABLED APB2 Clock Enable Disable __HAL_RCC_AFIO_CLK_ENABLE __HAL_RCC_GPIOA_CLK_ENABLE __HAL_RCC_GPIOB_CLK_ENABLE __HAL_RCC_GPIOC_CLK_ENABLE __HAL_RCC_GPIOD_CLK_ENABLE __HAL_RCC_ADC1_CLK_ENABLE __HAL_RCC_TIM1_CLK_ENABLE __HAL_RCC_SPI1_CLK_ENABLE __HAL_RCC_USART1_CLK_ENABLE __HAL_RCC_AFIO_CLK_DISABLE __HAL_RCC_GPIOA_CLK_DISABLE __HAL_RCC_GPIOB_CLK_DISABLE __HAL_RCC_GPIOC_CLK_DISABLE __HAL_RCC_GPIOD_CLK_DISABLE __HAL_RCC_ADC1_CLK_DISABLE __HAL_RCC_TIM1_CLK_DISABLE __HAL_RCC_SPI1_CLK_DISABLE __HAL_RCC_USART1_CLK_DISABLE Reset APB2 Force Release __HAL_RCC_APB2_FORCE_RESET __HAL_RCC_AFIO_FORCE_RESET __HAL_RCC_GPIOA_FORCE_RESET __HAL_RCC_GPIOB_FORCE_RESET __HAL_RCC_GPIOC_FORCE_RESET __HAL_RCC_GPIOD_FORCE_RESET __HAL_RCC_ADC1_FORCE_RESET __HAL_RCC_TIM1_FORCE_RESET __HAL_RCC_SPI1_FORCE_RESET 2 DocID027328 Rev 1166 385 /

386 HAL UM1850 RCC Generic Driver __HAL_RCC_USART1_FORCE_RESET __HAL_RCC_APB2_RELEASE_RESET __HAL_RCC_AFIO_RELEASE_RESET __HAL_RCC_GPIOA_RELEASE_RESET __HAL_RCC_GPIOB_RELEASE_RESET __HAL_RCC_GPIOC_RELEASE_RESET __HAL_RCC_GPIOD_RELEASE_RESET __HAL_RCC_ADC1_RELEASE_RESET __HAL_RCC_TIM1_RELEASE_RESET __HAL_RCC_SPI1_RELEASE_RESET __HAL_RCC_USART1_RELEASE_RESET APB2 Peripheral Clock Enable Disable Status __HAL_RCC_AFIO_IS_CLK_ENABLED __HAL_RCC_AFIO_IS_CLK_DISABLED __HAL_RCC_GPIOA_IS_CLK_ENABLED __HAL_RCC_GPIOA_IS_CLK_DISABLED __HAL_RCC_GPIOB_IS_CLK_ENABLED __HAL_RCC_GPIOB_IS_CLK_DISABLED __HAL_RCC_GPIOC_IS_CLK_ENABLED __HAL_RCC_GPIOC_IS_CLK_DISABLED __HAL_RCC_GPIOD_IS_CLK_ENABLED __HAL_RCC_GPIOD_IS_CLK_DISABLED __HAL_RCC_ADC1_IS_CLK_ENABLED __HAL_RCC_ADC1_IS_CLK_DISABLED __HAL_RCC_TIM1_IS_CLK_ENABLED __HAL_RCC_TIM1_IS_CLK_DISABLED __HAL_RCC_SPI1_IS_CLK_ENABLED __HAL_RCC_SPI1_IS_CLK_DISABLED __HAL_RCC_USART1_IS_CLK_ENABLED __HAL_RCC_USART1_IS_CLK_DISABLED BitAddress AliasRegion RCC_CR_OFFSET_BB RCC_CFGR_OFFSET_BB RCC_CIR_OFFSET_BB RCC_BDCR_OFFSET_BB RCC_CSR_OFFSET_BB DocID027328 / 1166 386 Rev 2

387 UM1850 HAL RCC Generic Driver RCC_HSION_BIT_NUMBER RCC_CR_HSION_BB RCC_HSEON_BIT_NUMBER RCC_CR_HSEON_BB RCC_CSSON_BIT_NUMBER RCC_CR_CSSON_BB RCC_PLLON_BIT_NUMBER RCC_CR_PLLON_BB RCC_LSION_BIT_NUMBER RCC_CSR_LSION_BB RCC_RMVF_BIT_NUMBER RCC_CSR_RMVF_BB RCC_LSEON_BIT_NUMBER RCC_BDCR_LSEON_BB RCC_LSEBYP_BIT_NUMBER RCC_BDCR_LSEBYP_BB RCC_RTCEN_BIT_NUMBER RCC_BDCR_RTCEN_BB RCC_BDRST_BIT_NUMBER RCC_BDCR_BDRST_BB Flags RCC_FLAG_HSIRDY Internal High Speed clock ready flag RCC_FLAG_HSERDY External High Speed clock ready flag PLL clock ready flag RCC_FLAG_PLLRDY RCC_FLAG_LSIRDY Internal Low Speed oscillator Ready RCC_FLAG_PINRST PIN reset flag RCC_FLAG_PORRST POR/PDR reset flag Software Reset flag RCC_FLAG_SFTRST RCC_FLAG_IWDGRST Independent Watchdog reset flag RCC_FLAG_WWDGRST Window watchdog reset flag Power reset flag - RCC_FLAG_LPWRRST Low External Low Speed oscillator Ready RCC_FLAG_LSERDY Flags Interrupts Management Description: __HAL_RCC_ENABLE_IT Enable RCC interrupt. Parameters: __INTERRUPT__: specifies the RCC 2 DocID027328 Rev 1166 387 /

388 HAL UM1850 RCC Generic Driver interrupt sources to be enabled. This parameter can be any combination of the following values: RCC_IT_LSIRDY LSI ready interrupt RCC_IT_LSERDY LSE ready interrupt RCC_IT_HSIRDY HSI ready interrupt RCC_IT_HSERDY HSE ready interrupt RCC_IT_PLLRDY main PLL ready interrupt Description: __HAL_RCC_DISABLE_IT Disable RCC interrupt. Parameters: __INTERRUPT__: specifies the RCC interrupt sources to be disabled. This parameter can be any combination of the following values: RCC_IT_LSIRDY LSI ready interrupt RCC_IT_LSERDY LSE ready interrupt RCC_IT_HSIRDY HSI ready interrupt RCC_IT_HSERDY HSE ready interrupt RCC_IT_PLLRDY main PLL ready interrupt Description: __HAL_RCC_CLEAR_IT Clear the RCC's interrupt pending bits. Parameters: __INTERRUPT__: specifies the interrupt pending bit to clear. This parameter can be any combination of the following values: RCC_IT_LSIRDY LSI ready interrupt. RCC_IT_LSERDY LSE ready interrupt. RCC_IT_HSIRDY HSI ready interrupt. RCC_IT_HSERDY HSE ready interrupt. RCC_IT_PLLRDY Main PLL ready interrupt. RCC_IT_CSS Clock Security System interrupt Description: __HAL_RCC_GET_IT Check the RCC's interrupt has occurred or not. Parameters: __INTERRUPT__: specifies the RCC interrupt source to check. This parameter can be one of the following values: RCC_IT_LSIRDY LSI ready interrupt. RCC_IT_LSERDY LSE ready interrupt. RCC_IT_HSIRDY HSI ready interrupt. RCC_IT_HSERDY HSE ready DocID027328 / 1166 388 Rev 2

389 UM1850 RCC Generic Driver HAL interrupt. IT_PLLRDY Main PLL ready RCC_ interrupt. RCC_IT_CSS Clock Security System interrupt Return value: The: new state of __INTERRUPT__ (TRUE or FALSE). __HAL_RCC_CLEAR_RESET_FLAGS The reset flags are RCC_FLAG_PINRST, RCC_FLAG_PORRST, RCC_FLAG_SFTRST, ST, RCC_FLAG_IWDGR RCC_FLAG_WWDGRST, RCC_FLAG_LPWRRST Description: __HAL_RCC_GET_FLAG Check RCC flag is set or not. Parameters: __FLAG__: specifies the flag to check. This parameter can be one of the following values: RCC_FLAG_HSIRDY HSI oscillator clock ready. RCC_FLAG_HSERDY HSE oscillator clock ready. RCC_FLAG_PLLRDY Main PLL clock ready. RCC_FLAG_LSERDY LSE oscillator clock ready. RCC_FLAG_LSIRDY LSI oscillator clock ready. RCC_FLAG_PINRST Pin reset. RCC_FLAG_PORRST POR/PDR reset. et. RCC_FLAG_SFTRST Software res RCC_FLAG_IWDGRST Independent Watchdog reset. RCC_FLAG_WWDGRST Window Watchdog reset. RCC_FLAG_LPWRRST Low Power reset. Return value: The: new state of __FLAG__ (TRUE or FALSE). Get Clock source Description: __HAL_RCC_SYSCLK_CONFIG the system clock source. Macro to configure Parameters: __SYSCLKSOURCE__: specifies the system 2 DocID027328 Rev 1166 389 /

390 HAL UM1850 RCC Generic Driver clock source. This parameter can be one of the following values: RCC_SYSCLKSOURCE_HSI HSI oscillator is used as system clock source. RCC_SYSCLKSOURCE_HSE HSE system clock source. oscillator is used as RCC_SYSCLKSOURCE_PLLCLK PLL output is used as system clock source. Description: __HAL_RCC_GET_SYSCLK_SOU RCE Macro to get the clock source used as system clock. Return value: The: clock source used as system clock. The returned value can be one of the following: RCC_SYSCLKSOURCE_STATUS_HSI HSI used as system clock RCC_SYSCLKSOURCE_STATUS_HSE HSE used as system clock RCC_SYSCLKSOURCE_STATUS_PLLCL K PLL used as system clock HSE Config RCC_HSE_OFF HSE clock deactivation HSE clock activation RCC_HSE_ON RCC_HSE_BYPASS External clock source for HSE clock HSE Configuration Description: __HAL_RCC_HSE_CONFIG Macro to configure the External High Speed oscillator (HSE). Parameters: __STATE__: specifies the new state of the HSE. This ameter can be one of the following values: par RCC_HSE_OFF turn OFF the HSE oscillator, HSERDY flag goes low after 6 HSE oscillator clock cycles. RCC_HSE_ON turn ON the HSE oscillator RCC_HSE_BYPASS HSE oscillator bypassed with external clock Notes: Transition HSE Bypass to HSE On and HSE On to HSE Bypass are not supported by this macro. User should request a transition to HSE Off first and then HSE On or HSE Bypass. After enabling the HSE (RCC_HSE_ON or RCC_HSE_Bypass), the d wait on HSERDY flag to application software shoul be set indicating that HSE clock is stable and can be used to clock the PLL and/or system clock. HSE state can not be changed if it is used directly or through the DocID027328 / 1166 390 Rev 2

391 UM1850 RCC Generic Driver HAL PLL as system clock. In this case, you have to select e of the system clock then change the another sourc HSE state (ex. disable it). The HSE is stopped by hardware when entering STOP and STANDBY modes. This function reset the CSSON bit, so if the clock security system(CSS) was previously enabled you have to enable it agai n after calling this function. HSI Config HSI clock deactivation RCC_HSI_OFF RCC_HSI_ON HSI clock activation RCC_HSICALIBRATION_DEFAULT HSI Configuration Notes: __HAL_RCC_HSI_ENABLE The HSI is stopped by hardware when entering STOP and modes. HSI can not STANDBY be stopped if it is used as system clock source. In this case, you have to select another source of the system clock then stop the HSI. After enabling the HSI, the application software should wait on HSIRDY flag to HSI clock be set indicating that is stable and can be used as system clock source. When the HSI is stopped, HSIRDY flag goes low after 6 HSI oscillator clock cycles. __HAL_RCC_HSI_DISABLE Description: __HAL_RCC_HSI_CALIBRATIONVALUE_ADJUS T Macro to adjust the Internal High S peed oscillator (HSI) calibration value. Parameters: _HSICALIBRATIONVALUE_: specifies the calibration trimming value. (default is RCC_HSICALIBRATION_DEFA ULT). This parameter must be a number between 0 and 0x1F. Notes: The calibration is used to for the variations in compensate voltage and temperature that influence the frequency of the 2 DocID027328 Rev 1166 391 /

392 RCC Generic Driver HAL UM1850 internal HSI RC. Interrupts LSI Ready Interrupt flag RCC_IT_LSIRDY LSE Ready Interrupt flag RCC_IT_LSERDY RCC_IT_HSIRDY HSI Ready Interrupt flag HSE Ready Interrupt flag RCC_IT_HSERDY RCC_IT_PLLRDY PLL Ready Interrupt flag RCC_IT_CSS Clock Security System Interrupt flag LSE Config RCC_LSE_OFF LSE clock deactivation LSE clock activation RCC_LSE_ON External clock source for LSE clock RCC_LSE_BYPASS LSE Configuration Description: __HAL_RCC_LSE_CONFIG Macro to configure the External Low Speed oscillator (LSE). Parameters: __STATE__: specifies the new state of the LSE. This parameter can be one of the following values: RCC_LSE_OFF turn OFF the LSE oscilla tor, LSERDY flag goes low after 6 LSE oscillator clock cycles. RCC_LSE_ON turn ON the LSE oscillator. RCC_LSE_BYPASS LSE oscillator bypassed with external clock. Notes: Transitions LSE Bypass to LSE On and LSE On to ro. As the LSE Bypass are not supported by this mac LSE is in the Backup domain and write access is denied to this domain after reset, you have to enable write access using HAL_PWR_EnableBkUpAccess() function before to configure the LSE (to be done once SE_ON or after reset). After enabling the LSE (RCC_L RCC_LSE_BYPASS), the application software should wait on LSERDY flag to be set indicating that LSE clock is stable and can be used to clock the RTC. LSI Config RCC_LSI_OFF LSI clock deactivation RCC_LSI_ON LSI clock activation Configuration LSI Notes: __HAL_RCC_LSI_ENABLE After enabling the LSI, the application software should wait on LSIRDY flag to be set indicating that LSI clock DocID027328 / 1166 392 Rev 2

393 UM1850 RCC Generic Driver HAL is stable and can be used to clock the IWDG and/or the RTC. Notes: __HAL_RCC_LSI_DISABLE be disabled if the IWDG is running. When LSI can not the LSI is stopped, LSIRDY flag goes low after 6 LSI oscillator clock cycles. MCO Clock Prescaler RCC_MCODIV_1 MCO Index RCC_MCO1 RCC_MCO MCO1 to be compliant with other families with 2 MCOs Oscillator Type RCC_OSCILLATORTYPE_NONE RCC_OSCILLATORTYPE_HSE RCC_OSCILLATORTYPE_HSI RCC_OSCILLATORTYPE_LSE RCC_OSCILLATORTYPE_LSI Peripheral Clock Enable Disable __HAL_RCC_DMA1_CLK_ENABLE __HAL_RCC_SRAM_CLK_ENABLE __HAL_RCC_FLITF_CLK_ENABLE __HAL_RCC_CRC_CLK_ENABLE __HAL_RCC_DMA1_CLK_DISABLE __HAL_RCC_SRAM_CLK_DISABLE __HAL_RCC_FLITF_CLK_DISABLE __HAL_RCC_CRC_CLK_DISABLE PLL Clock Source HSI clock divided by 2 selected as PLL entry clock RCC_PLLSOURCE_HSI_DIV2 source HSE clock selected as PLL entry clock source RCC_PLLSOURCE_HSE PLL Config PLL is not configured RCC_PLL_NONE PLL deactivation RCC_PLL_OFF PLL activation RCC_PLL_ON PLL Configuration Notes: __HAL_RCC_PLL_ENABLE Rev 2 1166 393 / DocID027328

394 HAL UM1850 RCC Generic Driver After enabling the main PLL, the application software should wait on PLLRDY flag to be set indicating that PLL clock is stable and can be used as system clock source. The main PLL is disabled by hardware when entering STOP and STANDBY modes. Notes: __HAL_RCC_PLL_DISABLE The main PLL can not be disabled if it is used as system clock source Description: __HAL_RCC_PLL_CONFIG Macro to configure the main PLL clock source and multiplication factors. Parameters: __RCC_PLLSOURCE__: specifies the PLL entry clock source. This parameter can be e of the following values: on RCC_PLLSOURCE_HSI_DIV2 HSI oscillator clock selected as PLL clock entry RCC_PLLSOURCE_HSE HSE oscillator clock selected as PLL clock entry __PLLMUL__: specifies the multiplication factor for PLL VCO output clock This parameter c an be one of the following values: RCC_PLL_MUL4 PLLVCO = PLL clock entry x 4 RCC_PLL_MUL6 PLLVCO = PLL clock entry x 6 RCC_PLL_MUL2 PLLVCO = PLL clock entry x 2 RCC_PLL_MUL3 PLLVCO = PLL clock entry x 3 RCC_PLL_MUL10 PLLVCO = PLL clock entry x 10 RCC_PLL_MUL11 PLLVCO = PLL clock entry x 11 RCC_PLL_MUL12 PLLVCO = PLL clock entry x 12 RCC_PLL_MUL13 PLLVCO = PLL clock entry x 13 RCC_PLL_MUL14 PLLVCO = PLL clock entry x 14 RCC_PLL_MUL15 PLLVCO = PLL clock entry x 15 RCC_PLL_MUL16 PLLVCO = PLL clock ent ry x 16 DocID027328 / 1166 394 Rev 2

395 HAL UM1850 RCC Generic Driver RCC_PLL_MUL8 PLLVCO = PLL clock entry x 8 RCC_PLL_MUL9 PLLVCO = PLL clock entry x 9 Notes: This function must be used only when the main PLL is disabled. Description: __HAL_RCC_GET_PLL_OSCSOURCE Get oscillator clock selected as PLL input clock. turn value: Re The: clock source used for PLL entry. The returned value can be one of the following: RCC_PLLSOURCE_HSI_DIV2 HSI oscillator clock selected as PLL input clock RCC_PLLSOURCE_HSE HSE oscillator clock selected as PLL input clock Register offsets RCC_OFFSET RCC_CR_OFFSET RCC_CFGR_OFFSET RCC_CIR_OFFSET RCC_BDCR_OFFSET RCC_CSR_OFFSET RCC RTC Clock Configuration Description: __HAL_RCC_RTC_CONFIG Macro to configure the RTC clock (RTCCLK). Parameters: __RTC_CLKSOURCE__: specifies the RTC clock source. This parameter can be one of the following values: RCC_RTCCLKSOURCE_NO_CLK No clock selected as RTC clock RCC_RTCCLKSOURCE_LSE LSE selected as RTC clock RCC_RTCCLKSOURCE_LSI LSI selected as RTC clock RTCCLKSOURCE_HSE_DIV128 RCC_ HSE divided by 128 selected as RTC clock Notes: 2 DocID027328 Rev 1166 395 /

396 HAL UM1850 RCC Generic Driver As the RTC clock configuration bits are in the Backup domain and write access is denied to this domain after reset, you have to enable write access using the Power before to configure Backup Access macro the RTC clock source (to be done once after reset). Once the RTC clock is configured it can't be changed unless the Backup domain is reset using __HAL_RCC_BACKUPRESET_FORCE() macro, or by a Power On Reset (POR). d as RTC clock If the LSE or LSI is use source, the RTC continues to work in STOP and STANDBY modes, and can be used as wakeup source. However, when the HSE clock is used as RTC clock source, the RTC cannot be used in STOP and STANDBY modes. The maximum input clock frequency for R TC is 1MHz (when using HSE as RTC clock source). Description: __HAL_RCC_GET_RTC_SOURCE Macro to get the RTC clock source. Return value: The: clock source can be one of the following values: RCC_RTCCLKSOURCE_NO_CLK No clock selected as RTC clock RCC_RTCCLKSOURCE_LSE LSE selected as RTC clock RCC_RTCCLKSOURCE_LSI LSI selected as RTC clock RCC_RTCCLKSOURCE_HSE_DIV128 HSE divided by 128 selected as RTC clock Notes: __HAL_RCC_RTC_ENABLE These macros must be used only after the lected. RTC clock source was se Notes: __HAL_RCC_RTC_DISABLE These macros must be used only after the RTC clock source was selected. Notes: __HAL_RCC_BACKUPRESET_FORC E This function resets the RTC peripheral (including the backup registers) and the in RCC_BDCR RTC clock source selection register. DocID027328 / 1166 396 Rev 2

397 HAL UM1850 RCC Generic Driver __HAL_RCC_BACKUPRESET_RELE ASE RTC Clock Source RCC_RTCCLKSOURCE_NO_CLK No clock RCC_RTCCLKSOURCE_LSE LSE oscillator clock used as RTC clock RCC_RTCCLKSOURCE_LSI LSI oscillator clock used as RTC clock HSE oscillator clock divided by 128 used as RTC RCC_RTCCLKSOURCE_HSE_DIV128 clock System Clock Source RCC_SYSCLKSOURCE_HSI HSI selected as system clock RCC_SYSCLKSOURCE_HSE HSE selected as system clock PLL selected as system clock RCC_SYSCLKSOURCE_PLLCLK System Clock Source Status RCC_SYSCLKSOURCE_STATUS_HSI HSI used as system clock RCC_SYSCLKSOURCE_STATUS_HSE HSE used as system clock PLL used as system clock RCC_SYSCLKSOURCE_STATUS_PLLCLK System Clock Type SYSCLK to configure RCC_CLOCKTYPE_SYSCLK HCLK to configure RCC_CLOCKTYPE_HCLK PCLK1 to configure RCC_CLOCKTYPE_PCLK1 RCC_CLOCKTYPE_PCLK2 PCLK2 to configure RCC Timeout RCC_DBP_TIMEOUT_VALUE RCC_LSE_TIMEOUT_VALUE CLOCKSWITCH_TIMEOUT_VALUE HSE_TIMEOUT_VALUE HSI_TIMEOUT_VALUE LSI_TIMEOUT_VALUE PLL_TIMEOUT_VALUE 2 DocID027328 Rev 1166 397 /

398 UM1850 HAL RCC Extension Driver 34 HAL RCC Extension Driver 34.1 RCCEx Firmware driver registers structures 34.1.1 RCC_OscInitTypeDef Data Fields uint32_t OscillatorType uint32_t HSEState uint32_t HSEPredivValue uint32_t LSEState uint32_t HSIState uint32_t HSICalibrationValue uint32_t LSIState RCC_PLLInitTypeDef PLL Field Documentation RCC_OscInitTypeDef::OscillatorType uint32_t The oscillators to be configured. This parameter can be a value of RCC_Oscillator_Type uint32_t RCC_OscInitTypeDef::HSEState RCC_HSE_Config The new state of the HSE. This parameter can be a value of uint32_t RCC_OscInitTypeDef::HSEPredivValue The Prediv1 factor value (named PREDIV1 or PLLXTPRE in RM) This parameter can be a value of RCCEx_Prediv1_Factor TypeDef::LSEState uint32_t RCC_OscInit RCC_LSE_Config The new state of the LSE. This parameter can be a value of uint32_t RCC_OscInitTypeDef::HSIState The new state of the HSI. This parameter can be a value of R CC_HSI_Config uint32_t RCC_OscInitTypeDef::HSICalibrationValue The HSI calibration trimming value (default is RCC_HSICALIBRATION_DEFAULT). This parameter must be a number between Min_Data = 0x00 and Max_Data = 0x1F uint32_t RCC_OscInitTypeDef::LSIState e new state of the LSI. This parameter can be a value of Th RCC_LSI_Config RCC_PLLInitTypeDef RCC_OscInitTypeDef::PLL PLL structure parameters RCC_PeriphCLKInitTypeDef 34.1.2 lds Data Fie uint32_t PeriphClockSelection uint32_t RTCClockSelection uint32_t AdcClockSelection uint32_t I2s2ClockSelection uint32_t I2s3ClockSelection uint32_t UsbClockSelection Field Documentation uint32_t RCC_PeriphCLKInitTypeDef::PeriphClockSelection The Extended Clock to be configured. This parameter can be a value of RCCEx_Periph_Clock_Selection DocID027328 / 1166 398 Rev 2

399 UM1850 RCC Extension Driver HAL uint32_t RCC_PeriphCLKInitTypeDef::RTCClockSelection specifies the RTC clock source. This parameter can be a value of RCC_RTC_Clock_Source uint32_t RCC_PeriphCLKInitTypeDef::AdcClockSelection RCCEx_ADC_Prescaler ADC clock source This parameter can be a value of n uint32_t RCC_PeriphCLKInitTypeDef::I2s2ClockSelectio RCCEx_I2S2_Clock_Source I2S2 clock source This parameter can be a value of uint32_t RCC_PeriphCLKInitTypeDef::I2s3ClockSelection I2S3 clock source This parameter can be a value of RCCEx_I2S3_Clock_Source uint32_t RCC_PeriphCLKInitTypeDef::UsbClockSelection USB clock source This parameter can be a value of RCCEx_USB_Prescaler 34.2 RCCEx Firmware driver API description Extended Peripheral Control functions 34.2.1 This subsection provides a set of functions allowing to control the RCC Clocks frequencies. iphCLKConfig() is Important note: Care must be taken when HAL_RCCEx_Per used to select the RTC clock source; in this case the Backup domain will be reset in order to modify the RTC Clock source, as consequence RTC registers (including the backup registers) are set to their reset values. This section contai ns the following APIs: HAL_RCCEx_PeriphCLKConfig() HAL_RCCEx_GetPeriphCLKConfig() HAL_RCCEx_GetPeriphCLKFreq() Detailed description of functions 34.2.2 HAL_RCCEx_PeriphCLKConfig HAL_StatusTypeDef HAL_RCCEx_PeriphCLKConfig Function name (RCC_PeriphCLKInitTypeDef * PeriphClkInit) Function description Initializes the RCC extended peripherals clocks according to the specified parameters in the RCC_PeriphCLKInitTypeDef. Parameters pointer to an RCC_PeriphCLKInitTypeDef PeriphClkInit: structure that contains the configuration information for the Extended Peripherals clocks(RTC clock). Return values status HAL: tes No Care must be taken when HAL_RCCEx_PeriphCLKConfig() is used to select the RTC clock source; in this case the Backup domain will be reset in order to modify the RTC Clock source, as consequence RTC registers (including the backup heir reset values. registers) are set to t In case of STM32F105xC or STM32F107xC devices, PLLI2S will be enabled if requested on one of 2 I2S interfaces. When PLLI2S is enabled, you need to call HAL_RCCEx_DisablePLLI2S to manually disable it. 2 DocID027328 Rev 1166 399 /

400 HAL UM1850 RCC Extension Driver HAL_RCCEx_GetPeriphCLKConfig void HAL_RCCEx_GetPeriphCLKConfig Function name (RCC_PeriphCLKInitTypeDef * PeriphClkInit) Function description Get the PeriphClkInit according to the internal RCC configuration registers. Parameters PeriphClkInit: pointer to an RCC_PeriphCLKInitTypeDef structure that returns the configuration information for the Extended Peripherals clocks(RTC, I2S, ADC clocks). Return values None: HAL_RCCEx_GetPeriphCLKFreq t32_t PeriphClk) uint32_t HAL_RCCEx_GetPeriphCLKFreq (uin Function name Function description Returns the peripheral clock frequency. Parameters PeriphClk: Peripheral clock identifier This parameter can be one of the following values: RCC_PERIPHCLK_RTC RTC peripheral clock clock RCC_PERIPHCLK_ADC ADC peripheral RCC_PERIPHCLK_I2S2 I2S2 peripheral clock RCC_PERIPHCLK_I2S3 I2S3 peripheral clock RCC_PERIPHCLK_I2S3 I2S3 peripheral clock RCC_PERIPHCLK_I2S2 I2S2 peripheral clock Return values Frequency: in Hz (0: means that no available frequency for ral) the periphe Notes Returns 0 if peripheral clock is unknown RCCEx Firmware driver defines 34.3 RCCEx 34.3.1 ADC Prescaler RCC_ADCPCLK2_DIV2 RCC_ADCPCLK2_DIV4 RCC_ADCPCLK2_DIV6 RCC_ADCPCLK2_DIV8 AHB1 Peripheral Clock Enable Disable Status __HAL_RCC_DMA2_IS_CLK_ENABLED __HAL_RCC_DMA2_IS_CLK_DISABLED __HAL_RCC_FSMC_IS_CLK_ENABLED __HAL_RCC_FSMC_IS_CLK_DISABLED __HAL_RCC_SDIO_IS_CLK_ENABLED __HAL_RCC_SDIO_IS_CLK_DISABLED APB1 Clock Enable Disable DocID027328 / 1166 400 Rev 2

401 UM1850 RCC Extension Driver HAL __HAL_RCC_CAN1_CLK_ENABLE __HAL_RCC_CAN1_CLK_DISABLE __HAL_RCC_TIM4_CLK_ENABLE __HAL_RCC_SPI2_CLK_ENABLE __HAL_RCC_USART3_CLK_ENABLE __HAL_RCC_I2C2_CLK_ENABLE __HAL_RCC_TIM4_CLK_DISABLE __HAL_RCC_SPI2_CLK_DISABLE __HAL_RCC_USART3_CLK_DISABLE __HAL_RCC_I2C2_CLK_DISABLE __HAL_RCC_USB_CLK_ENABLE __HAL_RCC_USB_CLK_DISABLE __HAL_RCC_TIM5_CLK_ENABLE __HAL_RCC_TIM6_CLK_ENABLE __HAL_RCC_TIM7_CLK_ENABLE __HAL_RCC_SPI3_CLK_ENABLE __HAL_RCC_UART4_CLK_ENABLE __HAL_RCC_UART5_CLK_ENABLE __HAL_RCC_DAC_CLK_ENABLE __HAL_RCC_TIM5_CLK_DISABLE __HAL_RCC_TIM6_CLK_DISABLE __HAL_RCC_TIM7_CLK_DISABLE __HAL_RCC_SPI3_CLK_DISABLE __HAL_RCC_UART4_CLK_DISABLE __HAL_RCC_UART5_CLK_DISABLE __HAL_RCC_DAC_CLK_DISABLE __HAL_RCC_TIM12_CLK_ENABLE __HAL_RCC_TIM13_CLK_ENABLE __HAL_RCC_TIM14_CLK_ENABLE __HAL_RCC_TIM12_CLK_DISABLE __HAL_RCC_TIM13_CLK_DISABLE __HAL_RCC_TIM14_CLK_DISABLE APB1 Force Release Reset __HAL_RCC_CAN1_FORCE_RESET __HAL_RCC_CAN1_RELEASE_RESET __HAL_RCC_TIM4_FORCE_RESET 2 DocID027328 Rev 1166 401 /

402 HAL UM1850 RCC Extension Driver __HAL_RCC_SPI2_FORCE_RESET __HAL_RCC_USART3_FORCE_RESET __HAL_RCC_I2C2_FORCE_RESET __HAL_RCC_TIM4_RELEASE_RESET __HAL_RCC_SPI2_RELEASE_RESET __HAL_RCC_USART3_RELEASE_RESET __HAL_RCC_I2C2_RELEASE_RESET __HAL_RCC_USB_FORCE_RESET __HAL_RCC_USB_RELEASE_RESET __HAL_RCC_TIM5_FORCE_RESET __HAL_RCC_TIM6_FORCE_RESET __HAL_RCC_TIM7_FORCE_RESET __HAL_RCC_SPI3_FORCE_RESET __HAL_RCC_UART4_FORCE_RESET __HAL_RCC_UART5_FORCE_RESET __HAL_RCC_DAC_FORCE_RESET __HAL_RCC_TIM5_RELEASE_RESET __HAL_RCC_TIM6_RELEASE_RESET __HAL_RCC_TIM7_RELEASE_RESET __HAL_RCC_SPI3_RELEASE_RESET __HAL_RCC_UART4_RELEASE_RESET __HAL_RCC_UART5_RELEASE_RESET __HAL_RCC_DAC_RELEASE_RESET __HAL_RCC_TIM12_FORCE_RESET __HAL_RCC_TIM13_FORCE_RESET __HAL_RCC_TIM14_FORCE_RESET __HAL_RCC_TIM12_RELEASE_RESET __HAL_RCC_TIM13_RELEASE_RESET __HAL_RCC_TIM14_RELEASE_RESET APB1 Peripheral Clock Enable Disable Status __HAL_RCC_CAN1_IS_CLK_ENABLED __HAL_RCC_CAN1_IS_CLK_DISABLED __HAL_RCC_TIM4_IS_CLK_ENABLED __HAL_RCC_TIM4_IS_CLK_DISABLED __HAL_RCC_SPI2_IS_CLK_ENABLED __HAL_RCC_SPI2_IS_CLK_DISABLED DocID027328 / 1166 402 Rev 2

403 UM1850 er RCC Extension Driv HAL __HAL_RCC_USART3_IS_CLK_ENABLED __HAL_RCC_USART3_IS_CLK_DISABLED __HAL_RCC_I2C2_IS_CLK_ENABLED __HAL_RCC_I2C2_IS_CLK_DISABLED __HAL_RCC_USB_IS_CLK_ENABLED __HAL_RCC_USB_IS_CLK_DISABLED __HAL_RCC_TIM5_IS_CLK_ENABLED __HAL_RCC_TIM5_IS_CLK_DISABLED __HAL_RCC_TIM6_IS_CLK_ENABLED __HAL_RCC_TIM6_IS_CLK_DISABLED __HAL_RCC_TIM7_IS_CLK_ENABLED __HAL_RCC_TIM7_IS_CLK_DISABLED __HAL_RCC_SPI3_IS_CLK_ENABLED __HAL_RCC_SPI3_IS_CLK_DISABLED __HAL_RCC_UART4_IS_CLK_ENABLED __HAL_RCC_UART4_IS_CLK_DISABLED __HAL_RCC_UART5_IS_CLK_ENABLED __HAL_RCC_UART5_IS_CLK_DISABLED __HAL_RCC_DAC_IS_CLK_ENABLED __HAL_RCC_DAC_IS_CLK_DISABLED __HAL_RCC_TIM13_IS_CLK_ENABLED __HAL_RCC_TIM13_IS_CLK_DISABLED __HAL_RCC_TIM14_IS_CLK_ENABLED __HAL_RCC_TIM14_IS_CLK_DISABLED APB2 Clock Enable Disable __HAL_RCC_ADC2_CLK_ENABLE __HAL_RCC_ADC2_CLK_DISABLE __HAL_RCC_GPIOE_CLK_ENABLE __HAL_RCC_GPIOE_CLK_DISABLE __HAL_RCC_GPIOF_CLK_ENABLE __HAL_RCC_GPIOG_CLK_ENABLE __HAL_RCC_GPIOF_CLK_DISABLE __HAL_RCC_GPIOG_CLK_DISABLE __HAL_RCC_TIM8_CLK_ENABLE __HAL_RCC_ADC3_CLK_ENABLE __HAL_RCC_TIM8_CLK_DISABLE 2 DocID027328 Rev 1166 403 /

404 HAL UM1850 RCC Extension Driver __HAL_RCC_ADC3_CLK_DISABLE __HAL_RCC_TIM9_CLK_ENABLE __HAL_RCC_TIM10_CLK_ENABLE __HAL_RCC_TIM11_CLK_ENABLE __HAL_RCC_TIM9_CLK_DISABLE __HAL_RCC_TIM10_CLK_DISABLE __HAL_RCC_TIM11_CLK_DISABLE APB2 Force Release Reset __HAL_RCC_ADC2_FORCE_RESET __HAL_RCC_ADC2_RELEASE_RESET __HAL_RCC_GPIOE_FORCE_RESET __HAL_RCC_GPIOE_RELEASE_RESET __HAL_RCC_GPIOF_FORCE_RESET __HAL_RCC_GPIOG_FORCE_RESET __HAL_RCC_GPIOF_RELEASE_RESET __HAL_RCC_GPIOG_RELEASE_RESET __HAL_RCC_TIM8_FORCE_RESET __HAL_RCC_ADC3_FORCE_RESET __HAL_RCC_TIM8_RELEASE_RESET __HAL_RCC_ADC3_RELEASE_RESET __HAL_RCC_TIM9_FORCE_RESET __HAL_RCC_TIM10_FORCE_RESET __HAL_RCC_TIM11_FORCE_RESET __HAL_RCC_TIM9_RELEASE_RESET __HAL_RCC_TIM10_RELEASE_RESET __HAL_RCC_TIM11_RELEASE_RESET Peripheral Clock Enable Disable Status APB2 __HAL_RCC_ADC2_IS_CLK_ENABLED __HAL_RCC_ADC2_IS_CLK_DISABLED __HAL_RCC_GPIOE_IS_CLK_ENABLED __HAL_RCC_GPIOE_IS_CLK_DISABLED __HAL_RCC_GPIOF_IS_CLK_ENABLED __HAL_RCC_GPIOF_IS_CLK_DISABLED __HAL_RCC_GPIOG_IS_CLK_ENABLED __HAL_RCC_GPIOG_IS_CLK_DISABLED __HAL_RCC_TIM8_IS_CLK_ENABLED DocID027328 / 1166 404 Rev 2

405 HAL UM1850 RCC Extension Driver __HAL_RCC_TIM8_IS_CLK_DISABLED __HAL_RCC_ADC3_IS_CLK_ENABLED __HAL_RCC_ADC3_IS_CLK_DISABLED __HAL_RCC_TIM9_IS_CLK_ENABLED __HAL_RCC_TIM9_IS_CLK_DISABLED __HAL_RCC_TIM10_IS_CLK_ENABLED __HAL_RCC_TIM10_IS_CLK_DISABLED __HAL_RCC_TIM11_IS_CLK_ENABLED __HAL_RCC_TIM11_IS_CLK_DISABLED HSE Configuration Description: __HAL_RCC_HSE_PREDIV_CONFIG External High Speed Macro to configure the oscillator (HSE) Predivision factor for PLL. Parameters: __HSE_PREDIV_VALUE__: specifies the division value applied to HSE. This parameter must be a number between RCC_HSE_PREDIV_DIV1 and RCC_HSE_PREDIV_DIV2. Notes: Predivision factor c an not be changed if PLL is used as system clock In this case, you have to select another source of the system clock, disable the PLL and then change the HSE predivision factor. __HAL_RCC_HSE_GET_PREDIV I2S2 Clock Source RCC_I2S2CLKSOURCE_SYSCLK I2S3 Clock Source RCC_I2S3CLKSOURCE_SYSCLK MCO1 Clock Source RCC_MCO1SOURCE_NOCLOCK RCC_MCO1SOURCE_SYSCLK RCC_MCO1SOURCE_HSI RCC_MCO1SOURCE_HSE RCC_MCO1SOURCE_PLLCLK RCC Extended MCOx Clock Config Description: __HAL_RCC_MCO1_CONFIG configure the MCO clock. Macro to 2 DocID027328 Rev 1166 405 /

406 HAL UM1850 RCC Extension Driver Parameters: __MCOCLKSOURCE__: specifies the MCO clock source. This parameter can be one of the following values: RCC_MCO1SOURCE_NOCLOCK No clock selected as MCO clock RCC_MCO1SOURCE_SYSCLK System clock clock (SYSCLK) selected as MCO RCC_MCO1SOURCE_HSI HSI selected as MCO clock RCC_MCO1SOURCE_HSE HSE selected as MCO clock RCC_MCO1SOURCE_PLLCLK PLL clock divided by 2 selected as MCO clock __MCODIV__: specifies the MCO clock prescaler. This parameter can be one of the following val ues: RCC_MCODIV_1 No division applied on MCO clock source Peripheral Clock Enable Disable __HAL_RCC_DMA2_CLK_ENABLE __HAL_RCC_DMA2_CLK_DISABLE __HAL_RCC_FSMC_CLK_ENABLE __HAL_RCC_FSMC_CLK_DISABLE __HAL_RCC_SDIO_CLK_ENABLE __HAL_RCC_SDIO_CLK_DISABLE Peripheral Configuration Description: __HAL_RCC_USB_CONFIG Macro to configure the USB clock. Parameters: __USBCLKSOURCE__: specifies the USB clock source. This parameter can be one of the following values: RCC_USBCLKSOURCE_PLL PLL clock divided by 1 selected as USB clock RCC_USBCLKSOURCE_PLL_DIV1_5 PLL clock divided by 1.5 selected as USB clock Description: __HAL_RCC_GET_USB_SOURC E Macro to get the USB clock (USBCLK). Return value: The: clock source can be one of the following values: RCC_USBCLKSOURCE_PLL PLL clock divided by 1 selected as USB clock RCC_USBCLKSOURCE_PLL_DIV1_5 PLL clock divided by 1.5 selected as USB DocID027328 / 1166 406 Rev 2

407 UM1850 RCC Extension Driver HAL clock Description: __HAL_RCC_ADC_CONFIG Macro to configure the ADCx clock (x=1 to 3 depending on devices). ameters: Par __ADCCLKSOURCE__: specifies the ADC clock source. This parameter can be one of the following values: RCC_ADCPCLK2_DIV2 PCLK2 clock divided by 2 selected as ADC clock RCC_ADCPCLK2_DIV4 PCLK2 clock divided by 4 selected as ADC clock RCC_ADCPCLK2_DIV6 PCLK2 clock divided by 6 selected as ADC clock RCC_ADCPCLK2_DIV8 PCLK2 clock divided by 8 selected as ADC clock Description: __HAL_RCC_GET_ADC_SOURC E Macro to get the ADC clock (ADCxCLK, x=1 to 3 depending on devices). Return value: clock source can be one of the following The: values: RCC_ADCPCLK2_DIV2 PCLK2 clock divided by 2 selected as ADC clock RCC_ADCPCLK2_DIV4 PCLK2 clock divided by 4 selected as ADC clock RCC_ADCPCLK2_DIV6 PCLK2 clock divided by 6 selected as ADC clock RCC_ADCPCL K2_DIV8 PCLK2 clock divided by 8 selected as ADC clock Periph Clock Selection RCC_PERIPHCLK_RTC RCC_PERIPHCLK_ADC RCC_PERIPHCLK_I2S2 RCC_PERIPHCLK_I2S3 RCC_PERIPHCLK_USB PLL Multiplication Factor RCC_PLL_MUL2 RCC_PLL_MUL3 RCC_PLL_MUL4 RCC_PLL_MUL5 RCC_PLL_MUL6 RCC_PLL_MUL7 2 DocID027328 Rev 1166 407 /

408 HAL UM1850 RCC Extension Driver RCC_PLL_MUL8 RCC_PLL_MUL9 RCC_PLL_MUL10 RCC_PLL_MUL11 RCC_PLL_MUL12 RCC_PLL_MUL13 RCC_PLL_MUL14 RCC_PLL_MUL15 RCC_PLL_MUL16 HSE Prediv1 Factor RCC_HSE_PREDIV_DIV1 RCC_HSE_PREDIV_DIV2 Prescaler USB RCC_USBCLKSOURCE_PLL RCC_USBCLKSOURCE_PLL_DIV1_5 DocID027328 / 1166 408 Rev 2

409 UM1850 RTC Generic Driver HAL HAL RTC Generic Driver 35 35.1 RTC Firmware driver registers structures RTC_TimeTypeDef 35.1.1 Data Fields uint8_t Hours uint8_t Minutes uint8_t Seconds Field Documentation uint8_t RTC_TimeTypeDef::Hours Specifies the RTC Time Hour. This parameter must be a number between Min_Data = 0 and Max_Data = 23 uint8_ t RTC_TimeTypeDef::Minutes Specifies the RTC Time Minutes. This parameter must be a number between Min_Data = 0 and Max_Data = 59 uint8_t RTC_TimeTypeDef::Seconds Specifies the RTC Time Seconds. This parameter must be a number between _Data = 59 Min_Data = 0 and Max 35.1.2 RTC_AlarmTypeDef Data Fields RTC_TimeTypeDef AlarmTime uint32_t Alarm Field Documentation RTC_TimeTypeDef RTC_AlarmTypeDef::AlarmTime Specifies the RTC Alarm Time members m uint32_t RTC_AlarmTypeDef::Alar Specifies the alarm ID (only 1 alarm ID for STM32F1). This parameter can be a value RTC_Alarms_Definitions of RTC_InitTypeDef 35.1.3 Data Fields uint32_t AsynchPrediv uint32_t OutPut Documentation Field uint32_t RTC_InitTypeDef::AsynchPrediv Specifies the RTC Asynchronous Predivider value. This parameter must be a number between Min_Data = 0x00 and Max_Data = 0xFFFFF or RTC_AUTO_1_SECOND If RTC_AUTO_1_SECOND is selected, AsynchPrediv will b e set automatically to get 1sec timebase uint32_t RTC_InitTypeDef::OutPut Specifies which signal will be routed to the RTC Tamper pin. This parameter can be a RTC_output_source_to_output_on_the_Tamper_pin value of 2 DocID027328 Rev 1166 409 /

410 HAL UM1850 RTC Generic Driver RTC_Date TypeDef 35.1.4 Data Fields uint8_t WeekDay uint8_t Month uint8_t Date uint8_t Year Field Documentation uint8_t RTC_DateTypeDef::WeekDay Specifies the RTC Date WeekDay (not necessary for HAL_RTC_SetDate). This RTC_WeekDay_Definitions parameter can be a value of uint8_t RTC_DateTypeDef::Month Specifies the RTC Date Month (in BCD format). This parameter can be a value of RTC_Month_Date_Definitions uint8_t RTC_DateTypeDef::Date Specifies the RTC Date. This parameter must be a number between Min_Data = 1 and Max_Data = 31 uint8_t RTC_DateTypeDef::Year This parameter must be a number between Min_Data = Specifies the RTC Date Year. 0 and Max_Data = 99 RTC_HandleTypeDef 35.1.5 Data Fields RTC_TypeDef * Instance RTC_InitTypeDef Init RTC_DateTypeDef DateToUpdate HAL_LockTypeDef Lock TypeDef State __IO HAL_RTCState Field Documentation RTC_TypeDef* RTC_HandleTypeDef::Instance Register base address RTC_InitTypeDef RTC_HandleTypeDef::Init RTC required parameters RTC_DateTypeDef RTC_HandleTypeDef::DateToUpdate cally Current date set by user and updated automati HAL_LockTypeDef RTC_HandleTypeDef::Lock RTC locking object __IO HAL_RTCStateTypeDef RTC_HandleTypeDef::State Time communication state RTC Firmware driver API description 35.2 How to use this driver 35.2.1 Enable the RTC domain access (see description in the section above). Configure the RTC Prescaler (Asynchronous prescaler to generate RTC 1Hz time base) using the HAL_RTC_Init() function. DocID027328 / 1166 410 Rev 2

411 UM1850 HAL RTC Generic Driver Time and Date configuration To configure the RTC Calendar (Time and Date) use the HAL_RTC_SetTime() and HAL_RTC_SetDate() functions. To read the RTC Calendar, use the HAL_RTC_GetTime() and HAL_RTC_GetDate() functions. Alarm configuration To configure the RTC Alarm use the HAL_RTC_SetAlarm() function. You can also configure the RTC Alarm with interrupt mode using the HAL_RTC_SetAlarm_IT() function. To read the RTC Alarm, use the HAL_RTC_GetAlarm() function. Tamper configuration mper Level using the Enable the RTC Tamper and configure the Ta HAL_RTCEx_SetTamper() function. You can configure RTC Tamper with interrupt mode using HAL_RTCEx_SetTamper_IT() function. The TAMPER1 alternate function can be mapped to PC13 Backup Data Registers configuration To write to the RTC Bac kup Data registers, use the HAL_RTCEx_BKUPWrite() function. To read the RTC Backup Data registers, use the HAL_RTCEx_BKUPRead() function. 35.2.2 WARNING: Drivers Restrictions RTC version used on STM32F1 famil ies is version V1. All the features supported by V2 (other families) will be not supported on F1. As on V2, main RTC features are managed by HW. But on F1, date feature is completely managed by SW. Then, there are some restrictions compared to other fam ilies: Only format 24 hours supported in HAL (format 12 hours not supported) Date is saved in SRAM. Then, when MCU is in STOP or STANDBY mode, date will be lost. User should implement a way to save date before entering in low power mode (an example is pro vided with firmware package based on backup registers) Date is automatically updated each time a HAL_RTC_GetTime or HAL_RTC_GetDate is called. Alarm detection is limited to 1 day. It will expire only 1 time (no alarm repetition, need to program a new alarm ) Backup Domain Operating Condition 35.2.3 The real - time clock (RTC) and the RTC backup registers can be powered from the VBAT RTC backup voltage when the main VDD supply is powered off. To retain the content of the registers and supply the RTC when VDD is turned off, VBAT pin can be connected to an optional standby voltage supplied by a battery or by another source. To allow the RTC operating even when the main digital supply (VDD) is turned off, the VBAT pin powers the following blocks: The RTC The LSE oscillator PC13 I/O 2 DocID027328 Rev 1166 411 /

412 HAL RTC Generic Driver UM1850 When the backup domain is supplied by VDD (analog switch connected to VDD), the following pins are available: PC13 can be used as a Tamper pin When the backup domain is supplied by VBAT (analog switch connected to VBAT because VDD is not present), the following pins are available: PC13 can be used as the Tamper pin Backup Domain Reset 35.2.4 The backup domai n reset sets all RTC registers and the RCC_BDCR register to their reset values. A backup domain reset is generated when one of the following events occurs: 1. Software reset, triggered by setting the BDRST bit in the RCC Backup domain control register (RCC_ BDCR). 2. VDD or VBAT power on, if both supplies have previously been powered off. Tamper detection event resets all data backup registers. 3. Backup Domain Access 35.2.5 After reset, the backup domain (RTC registers, RTC backup data registers and backup SRAM) is protected against possible unwanted write accesses. To enable access to the RTC Domain and RTC registers, proceed as follows: CLKConfig in using RCC_PERIPHCLK_RTC for Call the function HAL_RCCEx_Periph PeriphClockSelection and select RTCClockSelection (LSE, LSI or HSE) Enable the BKP clock in using __HAL_RCC_BKP_CLK_ENABLE() 35.2.6 RTC and low power modes The MCU can be woke n up from a low power mode by an RTC alternate function. The RTC alternate functions are the RTC alarms (Alarm A), and RTC tamper event detection. These RTC alternate functions can wake up the system from the Stop and Standby low power modes. The syste m can also wake up from low power modes without depending on an external - interrupt (Auto wakeup mode), by using the RTC alarm. initialization functions - Initialization and de 35.2.7 This section provides functions allowing to initialize and configure the RTC Prescaler (Asynchronous), disable RTC registers Write protection, enter and exit the RTC initialization mode, RTC registers synchronization check and reference clock detection ena ble. The RTC Prescaler should be programmed to generate the RTC 1Hz time base. 1. 2. All RTC registers are Write protected. Writing to the RTC registers is enabled by setting the CNF bit in the RTC_CRL register. 3. modes (Standby or Stop) the To read the calendar after wakeup from low power software must first wait for the RSF bit (Register Synchronized Flag) in the RTC_CRL register to be set by hardware. The HAL_RTC_WaitForSynchro() function implements the above software sequence (RSF clear and RSF check). section contains the following APIs: This HAL_RTC_Init() HAL_RTC_DeInit() DocID027328 / 1166 412 Rev 2

413 UM1850 RTC Generic Driver HAL HAL_RTC_MspInit() HAL_RTC_MspDeInit() functions 35.2.8 RTC Time and Date This section provides functions allowing to configure Time and Date features This section contains the following APIs: HAL_RTC_SetTime() HAL_RTC_GetTime() HAL_RTC_SetDate() HAL_RTC_GetDate() RTC Alarm functions 35.2.9 This section provides functions allowing to configure Alarm fea ture This section contains the following APIs: HAL_RTC_SetAlarm() HAL_RTC_SetAlarm_IT() HAL_RTC_GetAlarm() HAL_RTC_DeactivateAlarm() HAL_RTC_AlarmIRQHandler() HAL_RTC_AlarmAEventCallback() HAL_RTC_PollForAlarmAEvent() 35.2.10 Peripheral State functions This subsection provides functions allowing to Get RTC state This section contains the following APIs: HAL_RTC_GetState() Peripheral Control functions 35.2.11 This subsection provides functions allowing to Wait for RTC Time and Date Synchronization This section contains the following APIs: HAL_RTC_WaitForSynchro() ons Detailed description of functi 35.2.12 HAL_RTC_Init HAL_StatusTypeDef HAL_RTC_Init (RTC_HandleTypeDef * Function name hrtc) Initializes the RTC peripheral. Function description Parameters pointer to a RTC_HandleTypeDef structure that hrtc: contains the configuration information for RTC. Return values status HAL: 2 DocID027328 Rev 1166 413 /

414 HAL UM1850 RTC Generic Driver HAL_RTC_DeInit HAL_StatusTypeDef HAL_RTC_DeInit (RTC_HandleTypeDef * Function name hrtc) Function description DeInitializes the RTC peripheral. Parameters hrtc: pointer to a RTC_HandleTypeDef structure that contains the configuration information for RTC. Return values HAL: status Notes This function does not reset the RTC Backup Data registers. HAL_RTC_MspInit void HAL_RTC_MspInit (RTC_HandleTypeDef * hrtc) Function name Function description Initializes the RTC MSP. Parameters hrtc: pointer to a RTC_HandleTypeDef structure that contains the configuration information for RTC. Return values No ne: HAL_RTC_MspDeInit void HAL_RTC_MspDeInit (RTC_HandleTypeDef * hrtc) Function name DeInitializes the RTC MSP. Function description Parameters hrtc: pointer to a RTC_HandleTypeDef structure that contains the configuration information for RTC. Return values None: HAL_RTC_SetTime HAL_StatusTypeDef HAL_RTC_SetTime (RTC_HandleTypeDef Function name * hrtc, RTC_TimeTypeDef * sTime, uint32_t Format) Sets RTC current time. Function description Parameters ture that hrtc: pointer to a RTC_HandleTypeDef struc contains the configuration information for RTC. Pointer to Time structure sTime: Specifies the format of the entered parameters. This Format: parameter can be one of the following values: RTC_FORMAT_BIN: Binary data format RTC_FORMAT_BCD: BCD data format Return values status HAL: HAL_RTC_GetTime HAL_StatusTypeDef HAL_RTC_GetTime (RTC_HandleTypeDef Function name * hrtc, RTC_TimeTypeDef * sTime, uint32_t Format) Gets RTC current time. Function description Parameters hrtc: pointer to a RTC_HandleTypeDef structure that DocID027328 / 1166 414 Rev 2

415 UM1850 RTC Generic Driver HAL contains the configuration information for RTC. sTime: Pointer to Time structure Specifies the format of the entered parameters. This Format: parameter can be one of the following values: RTC_FORMAT_BIN: Bi nary data format RTC_FORMAT_BCD: BCD data format Return values HAL: status HAL_RTC_SetDate HAL_StatusTypeDef HAL_RTC_SetDate (RTC_HandleTypeDef Function name * hrtc, RTC_DateTypeDef * sDate, uint32_t Format) Function description Sets RTC current date. Parameters pointer to a RTC_HandleTypeDef structure that hrtc: contains the configuration information for RTC. sDate: Pointer to date structure specifies the format of the entered parameters. This Format: parameter can be one of the following values: RTC_FORMAT_BIN: Binary data format RTC_FORMAT_BCD: BCD data format Return values status HAL: HAL_RTC_GetDate HAL_StatusTypeDef HAL_RTC_GetDate (RTC_HandleTypeDef Function name * hrtc, RTC_DateTypeDef * sDate, uint32_t Format) Function description Gets RTC current date. Parameters hrtc: pointer to a RTC_HandleTypeDef structure that contains the configuration information for RTC. Pointer to Date structure sDate: Specifies the format of the entered parameters. This Format: parameter can be one of the following values: RTC_FORMAT_BIN: Binary data format RTC_FORMAT_BCD: BCD data format Return values HAL: status HAL_RTC_SetAlarm HAL_StatusTypeDef HAL_RTC_SetAlarm Function name (RTC_HandleTypeDef * hrtc, RTC_AlarmTypeDef * sAlarm, uint32_t Format) Function description Sets the specified RTC Alarm. Parameters hrtc: pointer to a RTC_HandleTypeDef structure that contains the configuration information for RTC. Pointer to Alarm structure sAlarm: Format: rs. This Specifies the format of the entered paramete parameter can be one of the following values: RTC_FORMAT_BIN: Binary data format 2 DocID027328 Rev 1166 415 /

416 HAL UM1850 RTC Generic Driver RTC_FORMAT_BCD: BCD data format Return values HAL: status HAL_RTC_SetAlarm_IT HAL_StatusTypeDef HAL_RTC_SetAlarm_IT Function name RTC_AlarmTypeDef * sAlarm, (RTC_HandleTypeDef * hrtc, uint32_t Format) Function description Sets the specified RTC Alarm with Interrupt. Parameters hrtc: pointer to a RTC_HandleTypeDef structure that contains the configuration information for RTC. sAlarm: Pointer to Alarm struc ture Format: Specifies the format of the entered parameters. This parameter can be one of the following values: RTC_FORMAT_BIN: Binary data format RTC_FORMAT_BCD: BCD data format Return values HAL: status Notes before enabling the The HAL_RTC_SetTime() must be called Alarm feature. HAL_RTC_DeactivateAlarm HAL_StatusTypeDef HAL_RTC_DeactivateAlarm Function name (RTC_HandleTypeDef * hrtc, uint32_t Alarm) Function description Deactive the specified RTC Alarm. Parameters leTypeDef structure that pointer to a RTC_Hand hrtc: contains the configuration information for RTC. Specifies the Alarm. This parameter can be one of Alarm: the following values: RTC_ALARM_A: AlarmA Return values HAL: status HAL_RTC_GetAlarm HAL_StatusTypeDef HAL_RTC_GetAlarm Function name (RTC_HandleTypeDef * hrtc, RTC_AlarmTypeDef * sAlarm, uint32_t Alarm, uint32_t Format) Function description Gets the RTC Alarm value and masks. Parameters pointer to a RTC_HandleTypeDef structure that hrtc: contains the configuration information for RTC. Pointer to Date structure sAlarm: Specifies the Alarm. This parameter can be one of Alarm: the following values: RTC_ALARM_A: Alarm mat of the entered parameters. This Specifies the for Format: parameter can be one of the following values: RTC_FORMAT_BIN: Binary data format RTC_FORMAT_BCD: BCD data format DocID027328 / 1166 416 Rev 2

417 UM1850 Generic Driver HAL RTC Return values status HAL: HAL_RTC_AlarmIRQHandler void HAL_RTC_AlarmIRQHandler (RTC_HandleTypeDef * hrtc) Function name Function description This function handles Alarm interrupt request. Parameters hrtc: pointer to a RTC_HandleTypeDef structure that contains the configuration information for RTC. Return values None: ent HAL_RTC_PollForAlarmAEv HAL_StatusTypeDef HAL_RTC_PollForAlarmAEvent Function name (RTC_HandleTypeDef * hrtc, uint32_t Timeout) Function description This function handles AlarmA Polling request. Parameters pointer to a RTC_HandleTypeDef structure that hrtc: contains the configuration information for RTC. Timeout duration Timeout: Return values HAL: status HAL_RTC_AlarmAEventCallback void HAL_RTC_AlarmAEventCallback (RTC_HandleTypeDef * Function name hrtc) Fu nction description Alarm A callback. Parameters hrtc: pointer to a RTC_HandleTypeDef structure that contains the configuration information for RTC. Return values None: HAL_RTC_GetState HAL_RTCStateTypeDef HAL_RTC_GetState Function name (RTC_HandleTypeDef * hrtc) Function description Returns the RTC state. Parameters hrtc: pointer to a RTC_HandleTypeDef structure that contains the configuration information for RTC. Return values state HAL: HAL_RTC_WaitForSynchro HAL_StatusTypeDef HAL_RTC_WaitForSynchro Function name (RTC_HandleTypeDef * hrtc) Function description Waits until the RTC registers (RTC_CNT, RTC_ALR and RTC_PRL) are synchronized with RTC APB clock. Parameters hrtc: pointer to a RTC_HandleTypeDef structure that contains the configuration information for RTC. 2 DocID027328 Rev 1166 417 /

418 HAL UM1850 RTC Generic Driver Return values HAL: status Notes This function must be called before any read operation after an APB reset or an APB clock stop. 35.3 RTC Firmware driver defines 35.3.1 RTC Alarms Definitions Specify alarm ID (mainly for legacy purposes) RTC_ALARM_A Automatic calculation of prediv for 1sec timebase RTC_AUTO_1_SECOND RTC Exported Macros Description: __HAL_RTC_RESET_HANDLE_STATE Reset RTC handle state. Parameters: __HANDLE__: RTC handle. Return value: None Description: __HAL_RTC_WRITEPROTECTION_DISABLE Disable the write protection for RTC registers. Parameters: __HANDLE__: specifies RTC handle. the Return value: None Description: __HAL_RTC_WRITEPROTECTION_ENABLE Enable the write protection for RTC registers. Parameters: __HANDLE__: specifies the RTC handle. Return value: None Description: __HAL_RTC_ALARM_ENABLE_IT Enable the RTC Alarm interrupt. DocID027328 / 1166 418 Rev 2

419 UM1850 RTC Generic Driver HAL Parameters: __HANDLE__: specifies the RTC handle. __INTERRUPT__: specifies the RTC Alarm interrupt sources to be enabled or disabled. This parameter can be any combination of the following values: RTC_IT_ALRA: Alarm A interrupt Return value: None Description: __HAL_RTC_ALARM_DISABLE_IT Disable the RTC Alarm interrupt. Parameters: __HANDLE__: specifies the RTC handle. __INTERRUPT__: specifies the RTC Alarm interrupt sources to be enabled or disabled. This parameter can be any e combination of th following values: RTC_IT_ALRA: Alarm A interrupt Return value: None Description: __HAL_RTC_ALARM_GET_IT_SOURCE Check whether the specified RTC Alarm interrupt has been enabled or not. Parameters: __HANDLE__: specifies the RTC handle. __INTERRUPT__: specifies the RTC Alarm interrupt sources to be checked This parameter can be: RTC_IT_ALRA: Alarm A interrupt Return value: 2 DocID027328 Rev 1166 419 /

420 HAL UM1850 RTC Generic Driver None Description: __HAL_RTC_ALARM_GET_FLAG Get the selected RTC Alarm's flag status. Parameters: ies __HANDLE__: specif the RTC handle. __FLAG__: specifies the RTC Alarm Flag sources to be enabled or disabled. This parameter can be: RTC_FLAG_ALRAF Return value: None Description: __HAL_RTC_ALARM_GET_IT Check whether the specified RTC Alarm interrupt has occurred or not. Parameters: __HANDLE__: specifies the RTC handle. __INTERRUPT__: specifies the RTC Alarm interrupt sources to check. This parameter can be: RTC_IT_ALRA: Alarm A interrupt Return value: None Description: __HAL_RTC_ALARM_CLEAR_FLAG Alarm's Clear the RTC pending flags. Parameters: __HANDLE__: specifies the RTC handle. __FLAG__: specifies the RTC Alarm Flag sources to be enabled or disabled. This parameter can be: RTC_FLAG_ALRAF Return value: DocID027328 / 1166 420 Rev 2

421 UM1850 RTC Generic Driver HAL None Description: __HAL_RTC_ALARM_EXTI_ENABLE_IT interrupt on Enable ALARM Exti Line 17. Return value: None. Description: __HAL_RTC_ALARM_EXTI_DISABLE_IT Disable interrupt on ALARM Exti Line 17. Return value: None. Description: __HAL_RTC_ALARM_EXTI_ENABLE_EVENT Enable event on ALARM Exti Line 17. e: Return valu None. Description: __HAL_RTC_ALARM_EXTI_DISABLE_EVENT Disable event on ALARM Exti Line 17. Return value: None. Description: __HAL_RTC_ALARM_EXTI_ENABLE_FALLING_EDGE ALARM EXTI line configuration: set falling edge trigger. Return value: None. Description: __HAL_RTC_ALARM_EXTI_DISABLE_FALLING_EDGE Disable the ALARM Extended Interrupt Falling Trigger. Return value: None. Description: __HAL_RTC_ALARM_EXTI_ENABLE_RISING_EDGE ALARM EXTI line configuration: set rising edge trigger. Return value: None. 2 DocID027328 Rev 1166 421 /

422 HAL UM1850 RTC Generic Driver Description: __HAL_RTC_ALARM_EXTI_DISABLE_RISING_EDGE Disable the ALARM Extended Interrupt Rising Trigger. Return value: None. Description: __HAL_RTC_ALARM_EXTI_ENABLE_RISING_FALLING _EDGE ALARM EXTI line configuration: set rising & trigger. falling edge Return value: None. Description: __HAL_RTC_ALARM_EXTI_DISABLE_RISING_FALLIN G_EDGE Disable the ALARM Extended Interrupt Rising & Falling Trigger. Return value: None. Description: __HAL_RTC_ALARM_EXTI_GET_FLAG Check whether the EXTI specified ALARM interrupt flag is set or not. Return value: EXTI: ALARM Line Status. Description: __HAL_RTC_ALARM_EXTI_CLEAR_FLAG Clear the ALARM EXTI flag. Return value: None. Description: __HAL_RTC_ALARM_EXTI_GENERATE_SWIT Generate a Software d interrupt on selecte EXTI line. Return value: None. RTC EXTI Line event External interrupt line 17 Connected to the RTC RTC_EXTI_LINE_ALARM_EVENT Alarm event Flags Definitions DocID027328 / 1166 422 Rev 2

423 UM1850 HAL RTC Generic Driver RTC_FLAG_RTOFF RTC Operation OFF flag RTC_FLAG_RSF Registers Synchronized flag RTC_FLAG_OW Overflow flag Alarm flag RTC_FLAG_ALRAF RTC_FLAG_SEC Second flag Tamper Interrupt Flag RTC_FLAG_TAMP1F Input Parameter Format RTC_FORMAT_BIN RTC_FORMAT_BCD Interrupts Definitions Overflow interrupt RTC_IT_OW Alarm interrupt RTC_IT_ALRA Second interrupt RTC_IT_SEC RTC_IT_TAMP1 TAMPER Pin interrupt enable Month Definitions RTC_MONTH_JANUARY RTC_MONTH_FEBRUARY RTC_MONTH_MARCH RTC_MONTH_APRIL RTC_MONTH_MAY RTC_MONTH_JUNE RTC_MONTH_JULY RTC_MONTH_AUGUST RTC_MONTH_SEPTEMBER RTC_MONTH_OCTOBER RTC_MONTH_NOVEMBER RTC_MONTH_DECEMBER Output source to output on the Tamper pin No output on the TAMPER pin RTC_OUTPUTSOURCE_NONE RTC clock with a frequency divided by 64 on the RTC_OUTPUTSOURCE_CALIBCLOCK TAMPER pin Alarm pulse signal on the TAMPER pin RTC_OUTPUTSOURCE_ALARM Second pulse signal on the TAMPER pin RTC_OUTPUTSOURCE_SECOND Default Timeout Value RTC_TIMEOUT_VALUE WeekDay Definitions RTC_WEEKDAY_MONDAY 2 DocID027328 Rev 1166 423 /

424 HAL UM1850 Driver RTC Generic RTC_WEEKDAY_TUESDAY RTC_WEEKDAY_WEDNESDAY RTC_WEEKDAY_THURSDAY RTC_WEEKDAY_FRIDAY RTC_WEEKDAY_SATURDAY RTC_WEEKDAY_SUNDAY DocID027328 2 Rev 1166 / 424

425 UM1850 RTC Extension Driver HAL HAL RTC Extension Driver 36 36.1 RTCEx Firmware driver registers structures RTC_TamperTypeDef 36.1.1 Data Fields uint32_t Tamper uint32_t Trigger Field Documentation uint32_t RTC_TamperTypeDef::Tamper Specifies the Tamper Pin. This parameter can be a value of x_Tamper_Pins_Definitions RTCE uint32_t RTC_TamperTypeDef::Trigger Specifies the Tamper Trigger. This parameter can be a value of RTCEx_Tamper_Trigger_Definitions RTCEx Firmware driver API description 36.2 RTC Tamper functions 36.2.1 This section provides functions allowing to configure Tamper feature This section contains the following APIs: HAL_RTCEx_SetTamper() HAL_RTCEx_SetTamper_IT() HAL_RTCEx_DeactivateTamper() HAL_RTCEx_TamperIRQHandler() HAL_RTCEx_Tamper1Ev entCallback() HAL_RTCEx_PollForTamper1Event() RTC Second functions 36.2.2 This section provides functions implementing second interupt handlers PIs: This section contains the following A HAL_RTCEx_SetSecond_IT() HAL_RTCEx_DeactivateSecond() HAL_RTCEx_RTCIRQHandler() HAL_RTCEx_RTCEventCallback() HAL_RTCEx_RTCEventErrorCallback() 36.2.3 Extension Peripheral Control functions This subsection provides functions allowing to data register Writes a data in a specified RTC Backup Read a data in a specified RTC Backup data register Sets the Smooth calibration parameters. This section contains the following APIs: 2 DocID027328 Rev 1166 425 /

426 HAL UM1850 RTC Extension Driver HAL_RTCEx_BKUPWrite() HAL_RTCEx_BKUPRead() HAL_RTCEx_SetSmoothCalib() Detailed description of functions 36.2.4 HAL_RTCEx_SetTamper HAL_StatusTypeDef HAL_RTCEx_SetTamper Function name (RTC_HandleTypeDef * hrtc, RTC_TamperTypeDef * sTamper) Function description Sets Tamper. Parameters pointer to a RTC_HandleTypeDef structure that hrtc: contains the configuration information for RTC. sTamper: Pointer to Tamper Structure. Return values HAL: status Notes By calling this API we disable the tamper interrupt for all tampers. Tamper can be enabled only if ASOE and CCO bit are reset HAL_RTCEx_SetTamper_IT HAL_StatusTypeDef HAL_RTCEx_SetTamper_IT Function name ) (RTC_HandleTypeDef * hrtc, RTC_TamperTypeDef * sTamper Function description Sets Tamper with interrupt. Parameters pointer to a RTC_HandleTypeDef structure that hrtc: contains the configuration information for RTC. sTamper: Pointer to RTC Tamper. Return values status HAL: Notes By calling this API we force the tamper interrupt for all tampers. Tamper can be enabled only if ASOE and CCO bit are reset HAL_RTCEx_DeactivateTamper HAL_StatusTypeDef HAL_RTCEx_DeactivateTamper Function name (RTC_HandleTypeDef * hrtc, uint32_t Tamper) Function description eactivates Tamper. D Parameters hrtc: pointer to a RTC_HandleTypeDef structure that contains the configuration information for RTC. Tamper: Selected tamper pin. This parameter can be a value of Tamper Pins Definitions Return values status HAL: Ex_TamperIRQHandler HAL_RTC void HAL_RTCEx_TamperIRQHandler (RTC_HandleTypeDef * Function name hrtc) DocID027328 / 1166 426 Rev 2

427 UM1850 RTC Extension Driver HAL This function handles Tamper interrupt request. Function description Parameters pointer to a RTC_HandleTypeDef structure that hrtc: contains the configuration information for RTC. Return values None: HAL_RTCEx_Tamper1EventCallback void HAL_RTCEx_Tamper1EventCallback Function name (RTC_HandleTypeDef * hrtc) callback. Tamper 1 Function description Parameters hrtc: pointer to a RTC_HandleTypeDef structure that contains the configuration information for RTC. Return values None: HAL_RTCEx_PollForTamper1Event HAL_StatusTypeDef HAL_RTCEx_PollForTamper1Event Function name (RTC_HandleTypeDef * hrtc, uint32_t Timeout) Function description This function handles Tamper1 Polling. Parameters pointer to a RTC_HandleTypeDef structure that hrtc: contains the configuration information for RTC. Timeout: Timeout duration values Return status HAL: HAL_RTCEx_SetSecond_IT HAL_StatusTypeDef HAL_RTCEx_SetSecond_IT Function name (RTC_HandleTypeDef * hrtc) Function description Sets Interrupt for second. Parameters pointer to a RTC_HandleTypeDef structure that hrtc: contains the configuration information for RTC. Return values HAL: status HAL_RTCEx_DeactivateSecond HAL_StatusTypeDef HAL_RTCEx_DeactivateSecond Function name (RTC_HandleTypeDef * hrtc) on Function descripti Deactivates Second. Parameters pointer to a RTC_HandleTypeDef structure that hrtc: contains the configuration information for RTC. Return values status HAL: HAL_RTCEx_RTCIRQHandler void HAL_RTCEx_RTCIRQHandler (RTC_HandleTypeDef * Function name hrtc) 2 DocID027328 Rev 1166 427 /

428 HAL UM1850 RTC Extension Driver This function handles second interrupt request. Function description Parameters pointer to a RTC_HandleTypeDef structure that hrtc: contains the configuration information for RTC. Return values None: HAL_RTCEx_RTCEventCallback vo id HAL_RTCEx_RTCEventCallback (RTC_HandleTypeDef * Function name hrtc) Second event callback. Function description Parameters hrtc: pointer to a RTC_HandleTypeDef structure that contains the configuration information for RTC. Return values None: HAL_RTCEx_RTCEventErrorCallback void HAL_RTCEx_RTCEventErrorCallback Function name (RTC_HandleTypeDef * hrtc) Function description Second event error callback. Parameters pointer to a RTC_HandleTypeDef structure that hrtc: contains the configuration information for RTC. Return values None: HAL_RTCEx_BKUPWrite void HAL_RTCEx_BKUPWrite (RTC_HandleTypeDef * hrtc, Function name uint32_t BackupRegister, uint32_t Data) Writes a data in a specified RTC Backup data register. Function description Parameters hrtc: pointer to a RTC_HandleTypeDef structure that contains the configuration information for RTC. RTC Backup data Register number. This BackupRegister: parameter can be: RT C_BKP_DRx where x can be from 1 to 10 (or 42) to specify the register (depending devices). Data: Data to be written in the specified RTC Backup data register. Return values None: HAL_RTCEx_BKUPRead uint32_t HAL_RTCEx_BKUPRead (RTC_HandleTypeDef * hrtc, Function name uint32_t BackupRegister) Function description Reads data from the specified RTC Backup data Register. Parameters pointer to a RTC_HandleTypeDef structure that hrtc: contains the configuration information for RTC. RTC Backup data Register number. This er: BackupRegist parameter can be: RTC_BKP_DRx where x can be from 1 to 10 (or 42) to specify the register (depending devices). DocID027328 / 1166 428 Rev 2

429 UM1850 RTC Extension Driver HAL Return values Read: value HAL_RTCEx_SetSmoothCalib othCalib HAL_StatusTypeDef HAL_RTCEx_SetSmo Function name (RTC_HandleTypeDef * hrtc, uint32_t SmoothCalibPeriod, uint32_t SmoothCalibPlusPulses, uint32_t SmouthCalibMinusPulsesValue) Function description Sets the Smooth calibration parameters. Parameters RTC handle hrtc: SmoothCalibPeriod: Not used (only present for compatibility with another families) Not used (only present for SmoothCalibPlusPulses: compatibility with another families) SmouthCalibMinusPulsesValue: specifies the RTC Clock r between Calibration value. This parameter must be a numbe 0 and 0x7F. Return values status HAL: RTCEx Firmware driver defines 36.3 36.3.1 RTCEx Alias define maintained for legacy HAL_RTCEx_TamperTimeStampIRQHandler Backup Registers Definitions RTC_BKP_DR1 RTC_BKP_DR2 RTC_BKP_DR3 RTC_BKP_DR4 RTC_BKP_DR5 RTC_BKP_DR6 RTC_BKP_DR7 RTC_BKP_DR8 RTC_BKP_DR9 RTC_BKP_DR10 RTC_BKP_DR11 RTC_BKP_DR12 RTC_BKP_DR13 RTC_BKP_DR14 RTC_BKP_DR15 RTC_BKP_DR16 2 DocID027328 Rev 1166 429 /

430 HAL UM1850 RTC Extension Driver RTC_BKP_DR17 RTC_BKP_DR18 RTC_BKP_DR19 RTC_BKP_DR20 RTC_BKP_DR21 RTC_BKP_DR22 RTC_BKP_DR23 RTC_BKP_DR24 RTC_BKP_DR25 RTC_BKP_DR26 RTC_BKP_DR27 RTC_BKP_DR28 RTC_BKP_DR29 RTC_BKP_DR30 RTC_BKP_DR31 RTC_BKP_DR32 RTC_BKP_DR33 RTC_BKP_DR34 RTC_BKP_DR35 RTC_BKP_DR36 RTC_BKP_DR37 RTC_BKP_DR38 RTC_BKP_DR39 RTC_BKP_DR40 RTC_BKP_DR41 RTC_BKP_DR42 RTCEx Exported Macros Description: __HAL_RTC_TAMPER_ENABLE_IT Enable the RTC Tamper interrupt. Parameters: specifies the RTC __HANDLE__: handle. __INTERRUPT__: specifies the RTC Tamper interrupt sources to be enabled This parameter can be any combination of the following values: RTC_IT_TAMP1: Tamper A interrupt Return value: DocID027328 / 1166 430 Rev 2

431 UM1850 RTC Extension Driver HAL None Description: __HAL_RTC_TAMPER_DISABLE_IT Disable the RTC Tamper interrupt. Parameters: __HANDLE__: specifies the RTC handle. __INTERRUPT__: specifies the RTC Tamper interrupt sources to be disabled. This parameter can be any combination of the following values: RTC_IT_TAMP1: Tamper A interrupt R eturn value: None Description: __HAL_RTC_TAMPER_GET_IT_SOURCE Check whether the specified RTC Tamper interrupt has been enabled or not. Parameters: __HANDLE__: specifies the RTC handle. __INTERRUPT__: specifies the RTC Tamper interrupt sources to be checked. This parameter can be: RTC_IT_TAMP1 Return value: None Description: __HAL_RTC_TAMPER_GET_FLAG Get the selected RTC Tamper's flag status. Parameters: __HANDLE__: specifies the RTC ndle. ha __FLAG__: specifies the RTC Tamper Flag sources to be enabled or disabled. This parameter can be: RTC_FLAG_TAMP1F Return value: None Description: __HAL_RTC_TAMPER_GET_IT Get the selected RTC Tamper's flag status. Parameters: 2 DocID027328 Rev 1166 431 /

432 HAL UM1850 RTC Extension Driver __HANDLE__: specifies the RTC handle. __INTERRUPT__: specifies the RTC Tamper interrupt sources to be checked. This parameter can be: RTC_IT_TAMP1 Return value: None Description: __HAL_RTC_TAMPER_CLEAR_FLAG Clear the RTC Tamper's pending flags. Parameters: specifies the RTC __HANDLE__: handle. __FLAG__: specifies the RTC Tamper Flag sources to be enabled or disabled. This parameter can be: RTC_FLAG_TAMP1F Return value: None Description: __HAL_RTC_SECOND_ENABLE_IT Enable the RTC Second interrupt. Parameters: __HANDLE__: specifies the RTC handle. __INTERRUPT__: specifies the RTC Second interrupt sources to be enabled This parameter can be any combination of the following values: RTC_IT_SEC: Second A interrupt Return value: None cription: Des __HAL_RTC_SECOND_DISABLE_IT Disable the RTC Second interrupt. Parameters: __HANDLE__: specifies the RTC handle. __INTERRUPT__: specifies the RTC Second interrupt sources to be disabled. This parameter can be any combination of the following values: RTC_IT_SEC: Second A interrupt DocID027328 / 1166 432 Rev 2

433 UM1850 RTC Extension Driver HAL Return value: None Description: __HAL_RTC_SECOND_GET_IT_SOURCE Check whether the specified RTC Second interrupt has occurred or not. Parameters: __HANDLE__: specifies the RTC handle. __INTERRUPT__: specifies the RTC Second interrupt sources to b e enabled or disabled. This parameter can be: RTC_IT_SEC: Second A interrupt Return value: None Description: __HAL_RTC_SECOND_GET_FLAG Get the selected RTC Second's flag status. Parameters: __HANDLE__: specifies the RTC handle. __FLAG__: specifies the RTC Second Flag sources to be enabled or disabled. This parameter can be: RTC_FLAG_SEC Return value: None Description: __HAL_RTC_SECOND_CLEAR_FLAG Clear the RTC Second's pending flags. Parameters: __HANDLE__: specifies the RTC handle. __FLAG__: specifies the RTC Second Flag sources to be enabled or disabled. This parameter can be: RTC_FLAG_SEC Return value: None Description: __HAL_RTC_OVERFLOW_ENABLE_IT Enable the RTC Overflow interrupt. 2 DocID027328 Rev 1166 433 /

434 RTC Extension Driver HAL UM1850 Parameters: RTC __HANDLE__: specifies the handle. __INTERRUPT__: specifies the RTC Overflow interrupt sources to be enabled This parameter can be any combination of the following values: RTC_IT_OW: Overflow A interrupt Return value: None Description: __HAL_RTC_OVERFLOW_DISABLE_IT RTC Overflow interrupt. Disable the Parameters: __HANDLE__: specifies the RTC handle. __INTERRUPT__: specifies the RTC Overflow interrupt sources to be disabled. This parameter can be any combination of the following values: RTC_IT_OW: Overflow A interrupt Return va lue: None Description: __HAL_RTC_OVERFLOW_GET_IT_SOURCE Check whether the specified RTC Overflow interrupt has occurred or not. Parameters: __HANDLE__: specifies the RTC handle. __INTERRUPT__: specifies the RTC Overflow interrupt sources to be enabled or disabled. This parameter can be: RTC_IT_OW: Overflow A interrupt Return value: None Description: __HAL_RTC_OVERFLOW_GET_FLAG Get the selected RTC Overflow's flag status. ers: Paramet DocID027328 / 1166 434 Rev 2

435 UM1850 RTC Extension Driver HAL __HANDLE__: specifies the RTC handle. __FLAG__: specifies the RTC Overflow Flag sources to be enabled or disabled. This parameter can be: RTC_FLAG_OW Return value: None Description: __HAL_RTC_OVERFLOW_CLEAR_FLAG Clear the RTC Overflow's pending flags. Parameters: __HANDLE__: specifies the RTC handle. __FLAG__: specifies the RTC Overflow Flag sources to be enabled or disabled. This parameter can be: RTC_FLAG_OW Return value: None Private macros to check input parameters IS_RTC_TAMPER IS_RTC_TAMPER_TRIGGER IS_RTC_BKP IS_RTC_SMOOTH_CALIB_MINUS Tamper Pins Definitions Select tamper to be enabled (mainly for legacy purposes) RTC_TAMPER_1 Tamper Trigger Definitions data A high level on the TAMPER pin resets all RTC_TAMPERTRIGGER_LOWLEVEL backup registers (if TPE bit is set) A low level on the TAMPER pin resets all data RTC_TAMPERTRIGGER_HIGHLEVEL backup registers (if TPE bit is set) 2 DocID027328 Rev 1166 435 /

436 SD Generic Driver HAL UM1850 37 HAL SD Generic Driver structures SD Firmware driver registers 37.1 37.1.1 HAL_SD_CardInfoTypeDef Data Fields uint32_t CardType uint32_t CardVersion uint32_t Class uint32_t RelCardAdd uint32_t BlockNbr uint32_t BlockSize ockNbr uint32_t LogBl uint32_t LogBlockSize Field Documentation uint32_t HAL_SD_CardInfoTypeDef::CardType Specifies the card Type uint32_t HAL_SD_CardInfoTypeDef::CardVersion Specifies the card version uint32_t HAL_SD_CardInfoTypeDef::Class Specifies the class of the card class uint32_t HAL_SD_CardInfoTypeDef::RelCardAdd Specifies the Relative Card Address uint32_t HAL_SD_CardInfoTypeDef::BlockNbr Specifies the Card Capacity in blocks uint32_t HAL_SD_CardInfoTypeDef::BlockSize Specifies on e block size in bytes uint32_t HAL_SD_CardInfoTypeDef::LogBlockNbr Specifies the Card logical Capacity in blocks uint32_t HAL_SD_CardInfoTypeDef::LogBlockSize Specifies logical block size in bytes SD_HandleTypeDef 37.1.2 Data Fields SD_TypeDef * Instance SD_InitTypeDef Init HAL_LockTypeDef Lock uint32_t * pTxBuffPtr uint32_t TxXferSize uint32_t * pRxBuffPtr uint32_t RxXferSize __IO uint32_t Context __IO HAL_SD_StateTypeDef State O uint32_t ErrorCode __I DMA_HandleTypeDef * hdmarx DMA_HandleTypeDef * hdmatx HAL_SD_CardInfoTypeDef SdCard DocID027328 / 1166 436 Rev 2

437 UM1850 SD Generic Driver HAL uint32_t CSD uint32_t CID Field Documentation SD_TypeDef* SD_HandleTypeDef::Instance SD registers base address SD_InitTypeDef SD_HandleTypeDef::Init SD required parameters HAL_LockTypeDef SD_HandleTypeDef::Lock SD locking object uint32_t* SD_HandleTypeDef::pTxBuffPtr Pointer to SD Tx transfer Buffer uint32_t SD_HandleTypeDef::TxXferSize SD Tx Transfer size uint32_t* SD_HandleTypeDef::pRxBuffPtr Poi nter to SD Rx transfer Buffer uint32_t SD_HandleTypeDef::RxXferSize SD Rx Transfer size __IO uint32_t SD_HandleTypeDef::Context SD transfer context __IO HAL_SD_StateTypeDef SD_HandleTypeDef::State SD card State __IO uint32_t SD_HandleTypeDef::ErrorCode SD Card Error codes DMA_HandleTypeDef* SD_HandleTypeDef::hdmarx SD Rx DMA handle parameters DMA_HandleTypeDef* SD_HandleTypeDef::hdmatx SD Tx DMA handle parameters HAL_SD_CardInfoTypeDef SD_HandleTypeDef::SdCard SD Card information uint32_t SD_HandleT ypeDef::CSD[4] SD card specific data table uint32_t SD_HandleTypeDef::CID[4] SD card identification number table 37.1.3 HAL_SD_CardCSDTypeDef Data Fields __IO uint8_t CSDStruct __IO uint8_t SysSpecVersion __IO uint8_t Reserved1 __IO uint8_t TAAC __IO uint8_t NSAC __IO uint8_t MaxBusClkFrec __IO uint16_t CardComdClasses __IO uint8_t RdBlockLen __IO uint8_t PartBlockRead __IO uint8_t WrBlockMisalign __IO uint8_t RdBlockMisalign __IO uint8_t DSRImpl Reserved2 __IO uint8_t __IO uint32_t DeviceSize __IO uint8_t MaxRdCurrentVDDMin 2 DocID027328 Rev 1166 437 /

438 HAL UM1850 SD Generic Driver __IO uint8_t MaxRdCurrentVDDMax __IO uint8_t MaxWrCurrentVDDMin __IO uint8_t MaxWrCurrentVDDMax __IO uint8_t DeviceSizeMul __IO uint8_t EraseGrSize __IO uint8_t EraseGrMul __IO uint8_t WrPr otectGrSize __IO uint8_t WrProtectGrEnable __IO uint8_t ManDeflECC __IO uint8_t WrSpeedFact __IO uint8_t MaxWrBlockLen __IO uint8_t WriteBlockPaPartial __IO uint8_t Reserved3 __IO uint8_t ContentProtectAppli __IO uint8_t FileFormatGrouop lag __IO uint8_t CopyF __IO uint8_t PermWrProtect __IO uint8_t TempWrProtect __IO uint8_t FileFormat __IO uint8_t ECC __IO uint8_t CSD_CRC __IO uint8_t Reserved4 Field Documentation __IO uint8_t HAL_SD_CardCSDTypeDef::CSDStruct CSD structure __IO uint8_t HAL_SD_CardCSDTypeDef::SysSpecVersion System specification version __IO uint8_t HAL_SD_CardCSDTypeDef::Reserved1 Reserved __IO uint8_t HAL_SD_CardCSDTypeDef::TAAC Data read access time 1 __IO uint8_t HAL_SD_CardCSDTypeDef::NSAC n CLK cycles Data read access time 2 i __IO uint8_t HAL_SD_CardCSDTypeDef::MaxBusClkFrec Max. bus clock frequency __IO uint16_t HAL_SD_CardCSDTypeDef::CardComdClasses Card command classes __IO uint8_t HAL_SD_CardCSDTypeDef::RdBlockLen Max. read data block length __IO uint8_t HAL_SD_CardCSDTypeDef::PartBlockRead Partial blocks for read allowed __IO uint8_t HAL_SD_CardCSDTypeDef::WrBlockMisalign Write block misalignment __IO uint8_t HAL_SD_CardCSDTypeDef::RdBlockMisalign Read block misalignment Def::DSRImpl __IO uint8_t HAL_SD_CardCSDType DSR implemented __IO uint8_t HAL_SD_CardCSDTypeDef::Reserved2 Reserved __IO uint32_t HAL_SD_CardCSDTypeDef::DeviceSize Device Size DocID027328 / 1166 438 Rev 2

439 UM1850 SD Generic Driver HAL __IO uint8_t HAL_SD_CardCSDTypeDef::MaxRdCurrentVDDMin Max. read current @ VDD min __IO uint8_t HAL_SD_CardC SDTypeDef::MaxRdCurrentVDDMax Max. read current @ VDD max __IO uint8_t HAL_SD_CardCSDTypeDef::MaxWrCurrentVDDMin Max. write current @ VDD min __IO uint8_t HAL_SD_CardCSDTypeDef::MaxWrCurrentVDDMax Max. write current @ VDD max __IO uint8_t HAL_SD_CardCSD TypeDef::DeviceSizeMul Device size multiplier __IO uint8_t HAL_SD_CardCSDTypeDef::EraseGrSize Erase group size __IO uint8_t HAL_SD_CardCSDTypeDef::EraseGrMul Erase group size multiplier __IO uint8_t HAL_SD_CardCSDTypeDef::WrProtectGrSize roup size Write protect g __IO uint8_t HAL_SD_CardCSDTypeDef::WrProtectGrEnable Write protect group enable __IO uint8_t HAL_SD_CardCSDTypeDef::ManDeflECC Manufacturer default ECC __IO uint8_t HAL_SD_CardCSDTypeDef::WrSpeedFact Write speed factor __IO uint8_t HAL_SD_Ca rdCSDTypeDef::MaxWrBlockLen Max. write data block length __IO uint8_t HAL_SD_CardCSDTypeDef::WriteBlockPaPartial Partial blocks for write allowed __IO uint8_t HAL_SD_CardCSDTypeDef::Reserved3 Reserved __IO uint8_t HAL_SD_CardCSDTypeDef::ContentProtectAp pli Content protection application __IO uint8_t HAL_SD_CardCSDTypeDef::FileFormatGrouop File format group __IO uint8_t HAL_SD_CardCSDTypeDef::CopyFlag Copy flag (OTP) __IO uint8_t HAL_SD_CardCSDTypeDef::PermWrProtect Permanent write protection uint8_t HAL_SD_CardCSDTypeDef::TempWrProtect __IO Temporary write protection __IO uint8_t HAL_SD_CardCSDTypeDef::FileFormat File format __IO uint8_t HAL_SD_CardCSDTypeDef::ECC ECC code __IO uint8_t HAL_SD_CardCSDTypeDef::CSD_CRC CSD CRC __IO uint8_t HAL_SD_ CardCSDTypeDef::Reserved4 Always 1 HAL_SD_CardCIDTypeDef 37.1.4 Data Fields __IO uint8_t ManufacturerID __IO uint16_t OEM_AppliID __IO uint32_t ProdName1 __IO uint8_t ProdName2 2 DocID027328 Rev 1166 439 /

440 HAL UM1850 SD Generic Driver __IO uint8_t ProdRev ProdSN __IO uint32_t __IO uint8_t Reserved1 __IO uint16_t ManufactDate __IO uint8_t CID_CRC __IO uint8_t Reserved2 Field Documentation __IO uint8_t HAL_SD_CardCIDTypeDef::ManufacturerID Manufacturer ID __IO uint16_t HAL_SD_CardCIDTypeDef::OEM_AppliID OEM/Application ID __IO uint32_t HAL_SD_CardCIDTypeDef::ProdName1 Product Name part1 __IO uint8_t HAL_SD_CardCIDTypeDef::ProdName2 Product Name part2 __IO uint8_t HAL_SD_CardCIDTypeDef::ProdRev Product Revision __IO uint32_t HAL_SD_CardCIDTypeDef::ProdSN Number Product Serial __IO uint8_t HAL_SD_CardCIDTypeDef::Reserved1 Reserved1 __IO uint16_t HAL_SD_CardCIDTypeDef::ManufactDate Manufacturing Date __IO uint8_t HAL_SD_CardCIDTypeDef::CID_CRC CID CRC __IO uint8_t HAL_SD_CardCIDTypeDef::Reserved2 Always 1 HAL_SD_CardStatusTypeDef 37.1.5 Data Fields __IO uint8_t DataBusWidth __IO uint8_t SecuredMode __IO uint16_t CardType __IO uint32_t ProtectedAreaSize __IO uint8_t SpeedClass __IO uint8_t PerformanceMove t AllocationUnitSize __IO uint8_ __IO uint16_t EraseSize __IO uint8_t EraseTimeout __IO uint8_t EraseOffset Field Documentation __IO uint8_t HAL_SD_CardStatusTypeDef::DataBusWidth Shows the currently defined data bus width edMode __IO uint8_t HAL_SD_CardStatusTypeDef::Secur Card is in secured mode of operation __IO uint16_t HAL_SD_CardStatusTypeDef::CardType Carries information about card type __IO uint32_t HAL_SD_CardStatusTypeDef::ProtectedAreaSize Carries information about the capacity of protected area DocID027328 / 1166 440 Rev 2

441 UM1850 HAL SD Generic Driver __IO uint8_t HAL_SD_CardStatusTypeDef::SpeedClass Carries information about the speed class of the card __IO uint8_t HAL_SD_CardStatusTypeDef::PerformanceMove Carries information about the card's performance move __IO uint8_t HAL_SD_CardStatusTypeDef::Allocat ionUnitSize Carries information about the card's allocation unit size __IO uint16_t HAL_SD_CardStatusTypeDef::EraseSize Determines the number of AUs to be erased in one operation __IO uint8_t HAL_SD_CardStatusTypeDef::EraseTimeout for any number of AU erase Determines the timeout __IO uint8_t HAL_SD_CardStatusTypeDef::EraseOffset Carries information about the erase offset SD Firmware driver API description 37.2 37.2.1 How to use this driver This driver implements a high level communication layer for read and write from/to this memory. The needed STM32 hardware resources (SDIO and GPIO) are performed by the user in HAL_SD_MspInit() function (MSP laye r). Basically, the MSP layer configuration should be the same as we provide in the examples. You can easily tailor this configuration according to hardware resources. r This driver is a generic layered driver for SDIO memories which uses the HAL SDIO drive functions to interface with SD and uSD cards devices. It is used as follows: 1. Initialize the SDIO low level resources by implement the HAL_SD_MspInit() API: a. Enable the SDIO interface clock using __HAL_RCC_SDIO_CLK_ENABLE(); SDIO pins configuration for SD card b. Enable the clock for the SDIO GPIOs using the functions __HAL_RCC_GPIOx_CLK_ENABLE(); up using - Configure these SDIO pins as alternate function pull HAL_GPIO_Init() and according to your pin assignment; DMA Configuration if you need to use DMA pro cess c. (HAL_SD_ReadBlocks_DMA() and HAL_SD_WriteBlocks_DMA() APIs). Enable the DMAx interface clock using __HAL_RCC_DMAx_CLK_ENABLE(); Configure the DMA using the function HAL_DMA_Init() with predeclared and filled. d. NVIC configuration if you need to use i nterrupt process when using DMA transfer. Configure the SDIO and DMA interrupt priorities using functions HAL_NVIC_SetPriority(); DMA priority is superior to SDIO's priority Enable the NVIC DMA and SDIO IRQs using function HAL_NVIC_EnableIRQ() upts are managed using the macros __HAL_SD_ENABLE_IT() SDIO interr and __HAL_SD_DISABLE_IT() inside the communication process. SDIO interrupts pending bits are managed using the macros __HAL_SD_GET_IT() and __HAL_SD_CLEAR_IT() errupt process NVIC configuration if you need to use int e. (HAL_SD_ReadBlocks_IT() and HAL_SD_WriteBlocks_IT() APIs). Configure the SDIO interrupt priorities using function HAL_NVIC_SetPriority(); Enable the NVIC SDIO IRQs using function HAL_NVIC_EnableIRQ() SDIO interrupts are managed using the ma cros __HAL_SD_ENABLE_IT() and __HAL_SD_DISABLE_IT() inside the communication process. 2 DocID027328 Rev 1166 441 /

442 HAL UM1850 SD Generic Driver SDIO interrupts pending bits are managed using the macros __HAL_SD_GET_IT() and __HAL_SD_CLEAR_IT() 2. At this stage, you can perform SD read/write/erase operations after SD card initialization SD Card Initialization and configuration To initialize the SD Card, use the HAL_SD_Init() function. It Initializes SDIO IP(STM32 side) and the SD Card, and put it into StandBy State (Ready for data transfer). This function provide the following operations: 1. ce with defaullt configuration. The initialization Initialize the SDIO peripheral interfa process is done at 400KHz. You can change or adapt this frequency by adjusting the "ClockDiv" field. The SD Card frequency (SDIO_CK) is computed as follows: SDIO_CK = SDIOCLK / (ClockDiv + 2) In initializa tion mode and according to the SD Card standard, make sure that the SDIO_CK frequency doesn't exceed 400KHz. This phase of initialization is done through SDIO_Init() and SDIO_PowerState_ON() SDIO low level APIs. _SD_InitCard(). This phase allows the card 2. Initialize the SD card. The API used is HAL initialization and identification and check the SD Card type (Standard Capacity or High Capacity) The initialization flow is compatible with SD standard. This API off - lize the card in case of plug (HAL_SD_InitCard()) could be used also to reinitia in. - plug Configure the SD Card Data transfer frequency. By Default, the card transfer 3. frequency is set to 24MHz. You can change or adapt this frequency by adjusting the the SD Card standard, make sure "ClockDiv" field. In transfer mode and according to that the SDIO_CK frequency doesn't exceed 25MHz and 50MHz in High - speed mode switch. To be able to use a frequency higher than 24MHz, you should use the SDIO peripheral in bypass mode. Refer to the corresponding reference ma nual for more details. 4. Select the corresponding SD Card according to the address read with the step 2. 5. Configure the SD Card in wide bus mode: 4 bits data. - SD Card Read operation You can read from SD card in polling mode by using function HAL_SD_ReadBlo cks(). This function allows the read of 512 bytes blocks. You can choose either one block read operation or multiple block read operation by adjusting the "NumberOfBlocks" heck parameter. After this, you have to ensure that the transfer is done correctly. The c is done through HAL_SD_GetCardState() function for SD card state. You can read from SD card in DMA mode by using function HAL_SD_ReadBlocks_DMA(). This function allows the read of 512 bytes blocks. You ltiple block read operation by can choose either one block read operation or mu adjusting the "NumberOfBlocks" parameter. After this, you have to ensure that the transfer is done correctly. The check is done through HAL_SD_GetCardState() function for SD card state. You could also check the DMA transfer p rocess through the SD Rx interrupt event. You can read from SD card in Interrupt mode by using function HAL_SD_ReadBlocks_IT(). This function allows the read of 512 bytes blocks. You can ion by adjusting choose either one block read operation or multiple block read operat the "NumberOfBlocks" parameter. After this, you have to ensure that the transfer is done correctly. The check is done through HAL_SD_GetCardState() function for SD card state. You could also check the IT transfer process through the SD Rx interrupt event. DocID027328 / 1166 442 Rev 2

443 HAL UM1850 SD Generic Driver SD Card Write operation You can write to SD card in polling mode by using function HAL_SD_WriteBlocks(). This function allows the read of 512 bytes blocks. You can choose either one block read operation or multiple block read operation by adjusting the "NumberOfBlocks" parameter. After this, you have to ensure that the transfer is done correctly. The check is done through HAL_SD_GetCardState() function for SD card state. You can write to SD card in DMA mode by using function HAL_SD_WriteBlocks_DMA(). This function allows the read of 512 bytes blocks. You can choose either one block read operation or multiple block read operation by adjusting the "NumberOfBlocks" parameter. After this, you have to ensure that the transfer is done correctly. The check is done through HAL_SD_GetCardState() function for SD card state. You could also check the DMA transfer process through the SD Tx interrupt event. You can write to SD card in I nterrupt mode by using function HAL_SD_WriteBlocks_IT(). This function allows the read of 512 bytes blocks. You can choose either one block read operation or multiple block read operation by adjusting ensure that the transfer is the "NumberOfBlocks" parameter. After this, you have to done correctly. The check is done through HAL_SD_GetCardState() function for SD card state. You could also check the IT transfer process through the SD Tx interrupt event. SD card status are related to the SD Memory Card proprietary The SD Status contains status bits that features. To get SD card status use the HAL_SD_GetCardStatus(). SD card information To get SD card information, you can use the function HAL_SD_GetCardInfo(). It uch as block size, card type, block returns useful information about the SD card s number ... SD card CSD register The HAL_SD_GetCardCSD() API allows to get the parameters of the CSD register. Some of the CSD parameters are useful for card initialization and identification. SD card CID register AL_SD_GetCardCID() API allows to get the parameters of the CID register. The H Some of the CSD parameters are useful for card initialization and identification. SD HAL driver macros list Below the list of most used macros in SD HAL driver. __HAL_SD_ENABLE : E nable the SD device __HAL_SD_DISABLE : Disable the SD device __HAL_SD_DMA_ENABLE: Enable the SDIO DMA transfer __HAL_SD_DMA_DISABLE: Disable the SDIO DMA transfer __HAL_SD_ENABLE_IT: Enable the SD device interrupt __HAL_SD_DISABLE_IT: Disable the SD device interrupt __HAL_SD_GET_FLAG:Check whether the specified SD flag is set or not __HAL_SD_CLEAR_FLAG: Clear the SD's pending flags 2 DocID027328 Rev 1166 443 /

444 HAL UM1850 SD Generic Driver You can refer to the SD HAL driver header file for more useful macros initialization functions Initialization and de 37.2.2 - initialize the SD card device to be - This section provides functions allowing to initialize/de ready for use. This section contains the following APIs: SD_Init() HAL_ HAL_SD_InitCard() HAL_SD_DeInit() HAL_SD_MspInit() HAL_SD_MspDeInit() IO operation functions 37.2.3 This subsection provides a set of functions allowing to manage the data transfer from/to SD card. This section contains the following APIs: HAL_SD_ReadBlocks() HAL_SD_WriteBlocks() HAL_SD_ReadBlocks_IT() HAL_SD_WriteBlocks_IT() HAL_SD_ReadBlocks_DMA() cks_DMA() HAL_SD_WriteBlo HAL_SD_Erase() HAL_SD_IRQHandler() HAL_SD_GetState() HAL_SD_GetError() pltCallback() HAL_SD_TxC HAL_SD_RxCpltCallback() HAL_SD_ErrorCallback() HAL_SD_AbortCallback() Peripheral Control functions 37.2.4 This subsection provides a set of functions allowing to control the SD card operations and get the related information This section contains the following APIs: HAL_SD_GetCardCID() HAL_SD_GetCardCSD() HAL_SD_GetCardStatus() HAL_SD_GetCardInfo() HAL_SD_ConfigWideBusOperation() HAL_SD_GetCardState() HAL_SD_Abort() HAL_SD_Abort_IT() DocID027328 / 1166 444 Rev 2

445 UM1850 SD Generic Driver HAL 37.2.5 Detailed description of functions HAL_SD_Init HAL_StatusTypeDef HAL_SD_Init (SD_HandleTypeDef * hsd) Function name Function description Initializes the SD according to the specified parameters in the SD_HandleTypeDef and create the associated handle. Parameters hsd: Pointer to the SD handle Return values HAL: status HAL_SD_InitCard HAL_StatusTypeDef HAL_SD_InitCard (SD_HandleTypeDef * Function name hsd) Initializes the SD Card. Function description Parameters hsd: Pointer to SD handle Return values HAL: status Notes This function initializes the SD card. It could be used when a needed. initialization is - card re HAL_SD_DeInit HAL_StatusTypeDef HAL_SD_DeInit (SD_HandleTypeDef * Function name hsd) De - Initializes the SD card. Function description Parameters hsd: Pointer to SD handle Return values HAL: status HAL_SD_MspInit void HAL_SD_MspInit (SD_HandleTypeDef * hsd) Function name Initializes the SD MSP. Function description Parameters hsd: Pointer to SD handle Return values None: HAL_SD_MspDeInit void HAL_SD_MspDeInit (SD_HandleTypeDef * hsd) Function name Function description - Initialize SD MSP. De Parameters Pointer to SD handle hsd: Return values None: HAL_SD_ReadBlocks HAL_StatusTypeDef HAL_SD_ReadBlocks Function name (SD_HandleTypeDef * hsd, uint8_t * pData, uint32_t BlockAdd, 2 DocID027328 Rev 1166 445 /

446 HAL UM1850 SD Generic Driver uint32_t NumberOfBlocks, uint32_t Timeout) Function description Reads block(s) from a specified address in a card. Parameters hsd: Pointer to SD handle pData: pointer to the buffer that will contain the received data BlockAdd: Block Address from where data is to be read NumberOfBlocks: Number of SD blocks to read Specify timeout value Timeout: Return values HAL: status Notes This API should be followed by a check on the card state through HAL_SD_GetCardState(). HAL_SD_WriteBlocks HAL_StatusTypeDef HAL_SD_WriteBlocks Function name ( SD_HandleTypeDef * hsd, uint8_t * pData, uint32_t BlockAdd, uint32_t NumberOfBlocks, uint32_t Timeout) Function description Allows to write block(s) to a specified address in a card. Parameters hsd: Pointer to SD handle pData: pointer to the buffer that will contain the data to transmit BlockAdd: Block Address where data will be written Number of SD blocks to write NumberOfBlocks: Timeout: Specify timeout value Return values HAL: status Notes This API should be followed b y a check on the card state through HAL_SD_GetCardState(). HAL_SD_Erase HAL_StatusTypeDef HAL_SD_Erase (SD_HandleTypeDef * Function name hsd, uint32_t BlockStartAdd, uint32_t BlockEndAdd) SD card. Function description Erases the specified memory area of the given Parameters Pointer to SD handle hsd: BlockStartAdd: Start Block address BlockEndAdd: End Block address Return values status HAL: Notes This API should be followed by a check on the card state through HAL_SD_GetCardState(). HAL_SD_ReadBlocks_IT HAL_StatusTypeDef HAL_SD_ReadBlocks_IT Function name (SD_HandleTypeDef * hsd, uint8_t * pData, uint32_t BlockAdd, uint32_t NumberOfBlocks) Reads block(s) from a specified address in a card. Function description Parameters Poin hsd: ter to SD handle DocID027328 / 1166 446 Rev 2

447 HAL UM1850 SD Generic Driver Pointer to the buffer that will contain the received pData: data BlockAdd: Block Address from where data is to be read NumberOfBlocks: Number of blocks to read. Return values status HAL: Notes This API should be followed by a check on the card state through HAL_SD_GetCardState(). You could also check the IT transfer process through the SD Rx interrupt event. HAL_SD_WriteBlocks_IT HAL_StatusTypeDef HAL_SD_WriteBlocks_IT Function name BlockAdd, (SD_HandleTypeDef * hsd, uint8_t * pData, uint32_t uint32_t NumberOfBlocks) Function description Writes block(s) to a specified address in a card. Parameters hsd: Pointer to SD handle pData: Pointer to the buffer that will contain the data to transmit Block Address where data will be written BlockAdd: Number of blocks to write NumberOfBlocks: Return values HAL: status Notes This API should be followed by a check on the card state through HAL_SD_GetCardState(). You could also check the IT transfer process thr ough the SD Tx interrupt event. HAL_SD_ReadBlocks_DMA HAL_StatusTypeDef HAL_SD_ReadBlocks_DMA Function name (SD_HandleTypeDef * hsd, uint8_t * pData, uint32_t BlockAdd, uint32_t NumberOfBlocks) Reads block(s) from a specified address in a card. Function description Parameters hsd: Pointer SD handle Pointer to the buffer that will contain the received pData: data BlockAdd: Block Address from where data is to be read Number of blocks to read. NumberOfBlocks: Return values status HAL: Notes should be followed by a check on the card state This API through HAL_SD_GetCardState(). You could also check the DMA transfer process through the SD Rx interrupt event. HAL_SD_WriteBlocks_DMA HAL_StatusTypeDef HAL_SD_WriteBlocks_DMA Function name f * hsd, uint8_t * pData, uint32_t BlockAdd, (SD_HandleTypeDe 2 DocID027328 Rev 1166 447 /

448 HAL UM1850 SD Generic Driver uint32_t NumberOfBlocks) Function description Writes block(s) to a specified address in a card. Parameters hsd: Pointer to SD handle pData: Pointer to the buffer that will contain the data to transmit Block Address where data will be written BlockAdd: NumberOfBlocks: Number of blocks to write Return values HAL: status Notes This API should be followed by a check on the card state through HAL_SD_GetCardState(). process through the You could also check the DMA transfer SD Tx interrupt event. HAL_SD_IRQHandler void HAL_SD_IRQHandler (SD_HandleTypeDef * hsd) Function name This function handles SD card interrupt request. Function description Parameters Pointer to SD handle hsd: Return values None: HAL_SD_TxCpltCallback void HAL_SD_TxCpltCallback (SD_HandleTypeDef * hsd) Function name Tx Transfer completed callbacks. Function description Parameters hsd: Pointer to SD handle Return values None: HAL_SD_RxCpltCallback void HAL_SD_ RxCpltCallback (SD_HandleTypeDef * hsd) Function name Rx Transfer completed callbacks. Function description Parameters hsd: Pointer SD handle Return values None: HAL_SD_ErrorCallback void HAL_SD_ErrorCallback (SD_HandleTypeDef * hsd) Function name SD error callbacks. description Function Parameters Pointer SD handle hsd: Return values None: HAL_SD_AbortCallback void HAL_SD_AbortCallback (SD_HandleTypeDef * hsd) Function name 448 DocID027328 / Rev 2 1166

449 UM1850 SD Generic Driver HAL SD Abort callbacks. Function description Parameters Pointer SD handle hsd: Return values None: HAL_SD_ConfigWideBusOperation HAL_StatusTypeDef HAL_SD_ConfigWideBusOperation Function name (SD_HandleTypeDef * hsd, uint32_t WideMode) Function description Enables wide bus operation for the requested card if supported by card. Parameters Pointer to SD handle hsd: WideMode: Specifies the SD card wide bus mode This parameter can be one of the following values: SDIO_BUS_WIDE_8B: 8 - bit data transfer bit data transfer SDIO_BUS_WIDE_4B: 4 - bit data transfer - SDIO_BUS_WIDE_1B: 1 rn values Retu status HAL: HAL_SD_SendSDStatus HAL_StatusTypeDef HAL_SD_SendSDStatus Function name (SD_HandleTypeDef * hsd, uint32_t * pSDstatus) Function description HAL_SD_GetCardState HAL_SD_CardStateTypeDef HAL_SD_GetCardState Function name (SD_HandleTypeDef * hsd) Function description Gets the current sd card data state. Parameters pointer to SD handle hsd: Return values Card: state HAL_SD_GetCardCID HAL_StatusTypeDef HAL_SD_GetCardCID Function name (SD_HandleTypeDef * hsd, HAL_SD_Car dCIDTypeDef * pCID) Returns information the information of the card which are stored Function description on the CID register. Parameters hsd: Pointer to SD handle Pointer to a HAL_SD_CIDTypeDef structure that pCID: contains all CID register parameters Return values status HAL: HAL_SD_GetCardCSD HAL_StatusTypeDef HAL_SD_GetCardCSD Function name (SD_HandleTypeDef * hsd, HAL_SD_CardCSDTypeDef * 2 DocID027328 Rev 1166 449 /

450 HAL SD Generic Driver UM1850 pCSD) Returns information the information of the card which are stored description Function on the CSD register. Parameters hsd: Pointer to SD handle pCSD: Pointer to a HAL_SD_CardCSDTypeDef structure that contains all CSD register parameters Return values status HAL: HAL_SD_GetCardStatus HAL_StatusTypeDef HAL_SD_GetCardStatus Function name (SD_HandleTypeDef * hsd, HAL_SD_CardStatusTypeDef * pStatus) Function description Gets the SD status info. Parameters hsd: Pointer to SD handle pStatus: HAL_SD_CardStatusTypeDef Pointer to the structure that will contain the SD card status information Return values status HAL: HAL_SD_GetCardInfo HAL_StatusTypeDef HAL_SD_GetCardInfo Function name (SD_HandleTypeDef * hsd, HAL_SD_CardInfoTypeDef * pCardInfo) description Function Gets the SD card info. Parameters Pointer to SD handle hsd: pCardInfo: Pointer to the HAL_SD_CardInfoTypeDef structure that will contain the SD card status information Return values status HAL: HAL_SD_GetState ypeDef HAL_SD_GetState HAL_SD_StateT Function name (SD_HandleTypeDef * hsd) Function description return the SD state Parameters hsd: Pointer to sd handle Return values state HAL: HAL_SD_GetError uint32_t HAL_SD_GetError (SD_HandleTypeDef * hsd) Function name description Function Return the SD error code. Parameters : Pointer to a SD_HandleTypeDef structure that hsd: contains the configuration information. Return values Error Code SD: DocID027328 / 1166 450 Rev 2

451 UM1850 SD Generic Driver HAL HAL_SD_Abort HAL_StatusTypeDef HAL_SD_Abort (SD_HandleTypeDef * Function name hsd) Function description Abort the current transfer and disable the SD. Parameters hsd: pointer to a SD_HandleTypeDef structure that contains the configuration information for SD module. Return values status HAL: HAL_SD_Abort_IT HAL_StatusTypeDef HAL_SD_Abort_IT (SD_HandleTypeDef * Function name hsd) Abort the current transfer and disable the SD (IT mode). Function description Parameters hsd: pointer to a SD_HandleTypeDef structure that contains the configuration information for SD module. Return values status HAL: SD Firmware driver defines 37.3 37.3.1 SD SD Error status enumeration Structure definition No error HAL_SD_ERROR_NONE Command response received (but HAL_SD_ERROR_CMD_CRC_FAIL CRC check failed) HAL_SD_ERROR_DATA_CRC_FAIL Data block sent/received (CRC check failed) HAL_SD_ERROR_CMD_RSP_TIMEOUT Command response timeout HAL_SD_ERROR_DATA_TIMEOUT Data timeout HAL_SD_ERROR_TX_UNDERRUN Transmit FIFO underrun Receive FIFO overrun HAL_SD_ERROR_RX_OVERRUN HAL_SD_ERROR_ADDR_MISALIGNED Misaligned address HAL_SD_ERROR_BLOCK_LEN_ERR Transferred block length is not allowed for the card or the number of transferred bytes does not match the block length HAL_SD_ERROR_ERASE_SEQ_ERR An error in the sequence of erase command occurs HAL_SD_ERROR_BAD_ERASE_PARAM An invalid selection for erase groups Attempt to program a write protect HAL_SD_ERROR_WRITE_PROT_VIOLATION block Sequence or password error has HAL_SD_ERROR_LOCK_UNLOCK_FAILED been detected in unlock command or if there was an attempt to access a 2 DocID027328 Rev 1166 451 /

452 HAL UM1850 SD Generic Driver d card locke HAL_SD_ERROR_COM_CRC_FAILED CRC check of the previous command failed HAL_SD_ERROR_ILLEGAL_CMD Command is not legal for the card state HAL_SD_ERROR_CARD_ECC_FAILED Card internal ECC was applied but failed to correct the data Internal card controller error RR HAL_SD_ERROR_CC_E HAL_SD_ERROR_GENERAL_UNKNOWN_ERR General or unknown error The card could not sustain data HAL_SD_ERROR_STREAM_READ_UNDERRUN reading in stream rmode The card could not sustain data HAL_SD_ERROR_STREAM_WRITE_OVERRUN programming in stream mode HAL_SD_ERROR_CID_CSD_OVERWRITE CID/CSD overwrite error HAL_SD_ERROR_WP_ERASE_SKIP Only partial address space was erased HAL_SD_ERROR_CARD_ECC_DISABLED Command has been executed internal ECC without using Erase sequence was cleared before HAL_SD_ERROR_ERASE_RESET executing because an out of erase sequence command was received HAL_SD_ERROR_AKE_SEQ_ERR Error in sequence of authentication HAL_SD_ERROR_INVALID_VOLTRANGE Error in case of invalid voltage range Error when addressed block is out of HAL_SD_ERROR_ADDR_OUT_OF_RANGE range HAL_SD_ERROR_REQUEST_NOT_APPLICABLE Error when command request is not applicable HAL_SD_ERROR_PARAM the used parameter is not valid Error when feature is not insupported HAL _SD_ERROR_UNSUPPORTED_FEATURE Error when transfer process is busy HAL_SD_ERROR_BUSY HAL_SD_ERROR_DMA Error while DMA transfer HAL_SD_ERROR_TIMEOUT Timeout error SD context enumeration SD_CONTEXT_NONE None Read single block operation SD_CONTEXT_READ_SINGLE_BLOCK Read multiple blocks operation SD_CONTEXT_READ_MULTIPLE_BLOCK Write single block operation SD_CONTEXT_WRITE_SINGLE_BLOCK SD_CONTEXT_WRITE_MULTIPLE_BLOCK Write multiple blocks operation Process in Interrupt mode TEXT_IT SD_CON SD_CONTEXT_DMA Process in DMA mode DocID027328 / 1166 452 Rev 2

453 UM1850 SD Generic Driver HAL SD Supported Memory Cards CARD_SDSC CARD_SDHC_SDXC CARD_SECURED SD Supported Version CARD_V1_X CARD_V2_X Exported Constants BLOCKSIZE Block size is 512 bytes Macros SD Exported Description: __HAL_SD_ENABLE Enable the SD device. Return value: None Description: __HAL_SD_DISABLE Disable the SD device. Return value: None Description: __HAL_SD_DMA_ENABLE Enable the SDMMC DMA transfer. Return value: None Description: __HAL_SD_DMA_DISABLE Disable the SDMMC DMA transfer. Return value: None Description: __HAL_SD_ENABLE_IT Enable the SD device interrupt. Parameters: __HANDLE__: SD Handle __INTERRUPT__: specifies the SDMMC interrupt sources to be enabled. This parameter can be one or a combination of the following values: SDIO_IT_CCRCFAIL: Command response received (CRC check failed) interrupt SDIO_IT_DCRCFAIL: Data block sent/received C check failed) interrupt (CR SDIO_IT_CTIMEOUT: Command response timeout interrupt 2 DocID027328 Rev 1166 453 /

454 HAL SD Generic Driver UM1850 SDIO_IT_DTIMEOUT: Data timeout interrupt SDIO_IT_TXUNDERR: Transmit FIFO underrun error interrupt SDIO_IT_RXOVERR: Received FIFO overrun error interrupt response SDIO_IT_CMDREND: Command received (CRC check passed) interrupt SDIO_IT_CMDSENT: Command sent (no response required) interrupt SDIO_IT_DATAEND: Data end (data counter, SDIDCOUNT, is zero) interrupt SDIO_IT_DBCKEND: Data block sent/received (CRC check passed) interrupt SDIO_IT_CMDACT: Command transfer in progress interrupt SDIO_IT_TXACT: Data transmit in progress interrupt SDIO_IT_RXACT: Data receive in progress interrupt SDIO_IT_TXFIFOHE: Transmit FIFO Half Empty interrupt SDIO_IT_RXFIFOHF: Receive FIFO Half Full interr upt SDIO_IT_TXFIFOF: Transmit FIFO full interrupt SDIO_IT_RXFIFOF: Receive FIFO full interrupt SDIO_IT_TXFIFOE: Transmit FIFO empty interrupt SDIO_IT_RXFIFOE: Receive FIFO empty interrupt SDIO_IT_TXDAVL: Data available in transmit FIFO interrupt SDIO_IT_RX DAVL: Data available in receive FIFO interrupt SDIO_IT_SDIOIT: SD I/O interrupt received interrupt Return value: None Description: __HAL_SD_DISABLE_IT Disable the SD device interrupt. Parameters: __HANDLE__: SD Handle __INTERRUPT__: specifies the SDMMC interrupt sources to be disabled. This parameter can be one or a combination of the following values: SDIO_IT_CCRCFAIL: Command response received (CRC check failed) interrupt SDIO_IT_DCRCFAIL: Data block sent/received RC check failed) interrupt (C SDIO_IT_CTIMEOUT: Command response timeout interrupt SDIO_IT_DTIMEOUT: Data timeout interrupt SDIO_IT_TXUNDERR: Transmit FIFO underrun DocID027328 / 1166 454 Rev 2

455 HAL UM1850 SD Generic Driver error interrupt SDIO_IT_RXOVERR: Received FIFO overrun error interrupt SDIO_IT_CMDREND: Comman d response received (CRC check passed) interrupt SDIO_IT_CMDSENT: Command sent (no response required) interrupt SDIO_IT_DATAEND: Data end (data counter, SDIDCOUNT, is zero) interrupt SDIO_IT_DBCKEND: Data block sent/received (CRC check passed) interrupt SDIO_IT_CMDACT: Command transfer in progress interrupt SDIO_IT_TXACT: Data transmit in progress interrupt SDIO_IT_RXACT: Data receive in progress interrupt SDIO_IT_TXFIFOHE: Transmit FIFO Half Empty interrupt SDIO_IT_RXFIFOHF: Receive FIFO Half Full upt interr SDIO_IT_TXFIFOF: Transmit FIFO full interrupt SDIO_IT_RXFIFOF: Receive FIFO full interrupt SDIO_IT_TXFIFOE: Transmit FIFO empty interrupt SDIO_IT_RXFIFOE: Receive FIFO empty interrupt SDIO_IT_TXDAVL: Data available in transmit FIFO interrupt SDIO_IT_RXDAVL: Data available in receive FIFO interrupt SDIO_IT_SDIOIT: SD I/O interrupt received interrupt Return value: None Description: __HAL_SD_GET_FLAG Check whether the specified SD flag is set or not. Parameters: __HANDLE__: SD Handle pecifies the flag to check. This parameter __FLAG__: s can be one of the following values: SDIO_FLAG_CCRCFAIL: Command response received (CRC check failed) SDIO_FLAG_DCRCFAIL: Data block sent/received (CRC check failed) SDIO_FLAG_CTIMEOUT: Command response timeout SD IO_FLAG_DTIMEOUT: Data timeout SDIO_FLAG_TXUNDERR: Transmit FIFO underrun error SDIO_FLAG_RXOVERR: Received FIFO overrun error 2 DocID027328 Rev 1166 455 /

456 SD Generi HAL UM1850 c Driver SDIO_FLAG_CMDREND: Command response received (CRC check passed) SDIO_FLAG_CMDSENT: Command sent (no response required) SDIO_FLAG_DATAEND: Data end (data counter, SDIDCOUNT, is zero) SDIO_FLAG_DBCKEND: Data block sent/received (CRC check passed) SDIO_FLAG_CMDACT: Command transfer in progress SDIO_FLAG_TXACT: Data transmit in progress s SDIO_FLAG_RXACT: Data receive in progres SDIO_FLAG_TXFIFOHE: Transmit FIFO Half Empty SDIO_FLAG_RXFIFOHF: Receive FIFO Half Full SDIO_FLAG_TXFIFOF: Transmit FIFO full SDIO_FLAG_RXFIFOF: Receive FIFO full SDIO_FLAG_TXFIFOE: Transmit FIFO empty SDIO_FLAG_RXFIFOE: Receive FIFO empty VL: Data available in transmit SDIO_FLAG_TXDA FIFO SDIO_FLAG_RXDAVL: Data available in receive FIFO SDIO_FLAG_SDIOIT: SD I/O interrupt received Return value: The: new state of SD FLAG (SET or RESET). Description: __HAL_SD_CLEAR_FLAG Clear the SD's pending flags. Parameters: __HANDLE__: SD Handle __FLAG__: specifies the flag to clear. This parameter can be one or a combination of the following values: SDIO_FLAG_CCRCFAIL: Command response received (CRC check failed) SDIO_FLAG_DCRCFAIL: Data block check failed) sent/received (CRC SDIO_FLAG_CTIMEOUT: Command response timeout SDIO_FLAG_DTIMEOUT: Data timeout SDIO_FLAG_TXUNDERR: Transmit FIFO underrun error SDIO_FLAG_RXOVERR: Received FIFO overrun error SDIO_FLAG_CMDREND: Command response received (CRC check passed) O_FLAG_CMDSENT: Command sent (no SDI response required) SDIO_FLAG_DATAEND: Data end (data counter, SDIDCOUNT, is zero) SDIO_FLAG_DBCKEND: Data block sent/received (CRC check passed) DocID027328 / 1166 456 Rev 2

457 UM1850 SD Generic Driver HAL SDIO_FLAG_SDIOIT: SD I/O interrupt received Return value: None Description: __HAL_SD_GET_IT Check whether the specified SD interrupt has occurred or not. Parameters: __HANDLE__: SD Handle __INTERRUPT__: specifies the SDMMC interrupt source to check. This parameter can be one of the following values: Command response SDIO_IT_CCRCFAIL: received (CRC check failed) interrupt SDIO_IT_DCRCFAIL: Data block sent/received (CRC check failed) interrupt SDIO_IT_CTIMEOUT: Command response timeout interrupt SDIO_IT_DTIMEOUT: Data timeout interrupt derrun SDIO_IT_TXUNDERR: Transmit FIFO un error interrupt SDIO_IT_RXOVERR: Received FIFO overrun error interrupt SDIO_IT_CMDREND: Command response received (CRC check passed) interrupt SDIO_IT_CMDSENT: Command sent (no response required) interrupt SDIO_IT_DATAEND: Data end (data counter, SD IDCOUNT, is zero) interrupt SDIO_IT_DBCKEND: Data block sent/received (CRC check passed) interrupt SDIO_IT_CMDACT: Command transfer in progress interrupt SDIO_IT_TXACT: Data transmit in progress interrupt SDIO_IT_RXACT: Data receive in progress interrupt SDIO_IT_TXFIFOHE: Transmit FIFO Half Empty interrupt SDIO_IT_RXFIFOHF: Receive FIFO Half Full interrupt SDIO_IT_TXFIFOF: Transmit FIFO full interrupt SDIO_IT_RXFIFOF: Receive FIFO full interrupt SDIO_IT_TXFIFOE: Transmit FIFO empty interrupt E: Receive FIFO empty interrupt SDIO_IT_RXFIFO SDIO_IT_TXDAVL: Data available in transmit FIFO interrupt SDIO_IT_RXDAVL: Data available in receive FIFO interrupt SDIO_IT_SDIOIT: SD I/O interrupt received 2 DocID027328 Rev 1166 457 /

458 HAL UM1850 SD Generic Driver interrupt Return value: The: new state of SD IT (SET or RESET). Description: __HAL_SD_CLEAR_IT Clear the SD's interrupt pending bits. Parameters: __HANDLE__: SD Handle __INTERRUPT__: specifies the interrupt pending bit to clear. This parameter can be one or a combination of the following values: Command response SDIO_IT_CCRCFAIL: received (CRC check failed) interrupt SDIO_IT_DCRCFAIL: Data block sent/received (CRC check failed) interrupt SDIO_IT_CTIMEOUT: Command response timeout interrupt SDIO_IT_DTIMEOUT: Data timeout interrupt errun SDIO_IT_TXUNDERR: Transmit FIFO und error interrupt SDIO_IT_RXOVERR: Received FIFO overrun error interrupt SDIO_IT_CMDREND: Command response received (CRC check passed) interrupt SDIO_IT_CMDSENT: Command sent (no response required) interrupt SDIO_IT_DATAEND: Data end (data counter, MC_DCOUNT, is zero) interrupt SDM SDIO_IT_SDIOIT: SD I/O interrupt received interrupt Return value: None SD Handle Structure definition SD_InitTypeDef SD_TypeDef DocID027328 / 1166 458 Rev 2

459 HAL UM1850 SMARTCARD Generic Driver 38 HAL SMARTCARD Generic Driver driver registers structures 38.1 SMARTCARD Firmware SMARTCARD_InitTypeDef 38.1.1 Data Fields uint32_t BaudRate uint32_t WordLength uint32_t StopBits uint32_t Parity uint32_t Mode ity uint32_t CLKPolar uint32_t CLKPhase uint32_t CLKLastBit uint32_t Prescaler uint32_t GuardTime uint32_t NACKState Field Documentation uint32_t SMARTCARD_InitTypeDef::BaudRate This member configures the SmartCard communication baud rate. The baud rate is computed using the following formula:IntegerDivider = ((PCLKx) / (16 * (hsmartcard - - ((uint32_t) IntegerDivider)) * 16) >Init.BaudRate)))FractionalDivider = ((IntegerDivider + 0 .5 uint32_t SMARTCARD_InitTypeDef::WordLength Specifies the number of data bits transmitted or received in a frame. This parameter can be a value of SMARTCARD_Word_Length uint32_t SMARTCARD_InitTypeDef::StopBits Specifies the number of stop bits transmitted. This parameter can be a value of SMARTCARD_Stop_Bits uint32_t SMARTCARD_InitTypeDef::Parity SMARTCARD_Parity Specifies the parity mode. This parameter can be a value of Note: When parity is enabled, the computed parity is inserted at the MSB position of the transmitted data (9th bit when the word length is set to 9 data bits; 8th bit when the word length is set to 8 data bits). InitTypeDef::Mode uint32_t SMARTCARD_ Specifies whether the Receive or Transmit mode is enabled or disabled. This parameter can be a value of SMARTCARD_Mode uint32_t SMARTCARD_InitTypeDef::CLKPolarity lock. This parameter can be a value of Specifies the steady state of the serial c SMARTCARD_Clock_Polarity uint32_t SMARTCARD_InitTypeDef::CLKPhase Specifies the clock transition on which the bit capture is made. This parameter can be SMARTCARD_Clock_Phase a value of uint32_t SMARTCARD_InitTypeDef::CLKLastBit Specifies whether the clock pulse corresponding to the last transmitted data bit (MSB) has to be output on the SCLK pin in synchronous mode. This parameter can be a SMARTCARD_Last_Bit value of uint32_t SMARTCARD_InitTypeDef::Prescaler Specifies the SmartCard Prescaler value used for dividing the system clock to provide 2 DocID027328 Rev 1166 459 /

460 HAL SMARTCARD Generic Driver UM1850 the smartcard clock. The value given in the register (5 significant bits) is mul tiplied by 2 to give the division factor of the source clock frequency. This parameter can be a SMARTCARD_Prescaler value of uint32_t SMARTCARD_InitTypeDef::GuardTime ber of baud clocks Specifies the SmartCard Guard Time value in terms of num uint32_t SMARTCARD_InitTypeDef::NACKState Specifies the SmartCard NACK Transmission state This parameter can be a value of SMARTCARD_NACK_State 38.1.2 SMARTCARD_HandleTypeDef Data Fields USART_TypeDef * Instance SMARTCARD_InitTypeDef Init uint8_t * pTxBuffPtr uint16_t TxXferSize __IO uint16_t TxXferCount uint8_t * pRxBuffPtr uint16_t RxXferSize __IO uint16_t RxXferCount DMA_HandleTypeDef * hdmatx * hdmarx DMA_HandleTypeDef HAL_LockTypeDef Lock __IO HAL_SMARTCARD_StateTypeDef gState __IO HAL_SMARTCARD_StateTypeDef RxState __IO uint32_t ErrorCode Field Documentation USART_TypeDef* SMARTCARD_HandleTypeDef::Instance USART registers base address SMARTCARD_InitTypeDef SM ARTCARD_HandleTypeDef::Init SmartCard communication parameters uint8_t* SMARTCARD_HandleTypeDef::pTxBuffPtr Pointer to SmartCard Tx transfer Buffer uint16_t SMARTCARD_HandleTypeDef::TxXferSize SmartCard Tx Transfer size eDef::TxXferCount __IO uint16_t SMARTCARD_HandleTyp SmartCard Tx Transfer Counter uint8_t* SMARTCARD_HandleTypeDef::pRxBuffPtr Pointer to SmartCard Rx transfer Buffer uint16_t SMARTCARD_HandleTypeDef::RxXferSize SmartCard Rx Transfer size __IO uint16_t SMARTCARD_HandleTypeDef::RxXferCou nt SmartCard Rx Transfer Counter DMA_HandleTypeDef* SMARTCARD_HandleTypeDef::hdmatx SmartCard Tx DMA Handle parameters DMA_HandleTypeDef* SMARTCARD_HandleTypeDef::hdmarx SmartCard Rx DMA Handle parameters HAL_LockTypeDef SMARTCARD_HandleTypeDef::Lock cking object Lo __IO HAL_SMARTCARD_StateTypeDef SMARTCARD_HandleTypeDef::gState SmartCard state information related to global Handle management and also related to HAL_SMARTCARD_StateTypeDef Tx operations. This parameter can be a value of DocID027328 / 1166 460 Rev 2

461 UM1850 SMARTCARD Generic Driver HAL StateTypeDef SMARTCARD_HandleTypeDef::RxState __IO HAL_SMARTCARD_ SmartCard state information related to Rx operations. This parameter can be a value of HAL_SMARTCARD_StateTypeDef __IO uint32_t SMARTCARD_HandleTypeDef::ErrorCode SmartCard Error code API description SMARTCARD Firmware driver 38.2 38.2.1 How to use this driver The SMARTCARD HAL driver can be used as follows: 1. Declare a SMARTCARD_HandleTypeDef handle structure. 2. Initialize the SMARTCARD low level resources by implementing the HAL_SMARTCARD_MspInit() API: a. Enable the USARTx interface clock. SMARTCARD pins configuration: b. Enable the clock for the SMARTCARD GPIOs. Configure the SMARTCARD pins as alternate function pu up. - ll NVIC configuration if you need to use interrupt process c. (HAL_SMARTCARD_Transmit_IT() and HAL_SMARTCARD_Receive_IT() APIs): Configure the USARTx interrupt priority. Enable the NVIC USART IRQ handle. DMA Configuration if you need to use DMA process d. ( HAL_SMARTCARD_Transmit_DMA() and HAL_SMARTCARD_Receive_DMA() APIs): Declare a DMA handle structure for the Tx/Rx channel. Enable the DMAx interface clock. Configure the declared DMA handle structure with the required Tx/Rx parameters. Configure the DMA Tx/Rx channel. Associate the initialized DMA handle to the SMARTCARD DMA Tx/Rx handle. Configure the priority and enable the NVIC for the transfer complete interrupt on the DMA Tx/Rx channel. T IRQ Configure the USARTx interrupt priority and enable the NVIC USAR handle (used for last byte sending completion detection in DMA non circular mode) 3. Program the Baud Rate, Word Length, Stop Bit, Parity, Hardware flow control and Mode(Receiver/Transmitter) in the SMARTCARD Init structure. egisters by calling the HAL_SMARTCARD_Init() API: Initialize the SMARTCARD r 4. These APIs configure also the low level Hardware GPIO, CLOCK, CORTEX...etc) by calling the customized HAL_SMARTCARD_MspInit() API. NE The specific SMARTCARD interrupts (Transmission complete interrupt, RX interrupt and Error Interrupts) will be managed using the macros __HAL_SMARTCARD_ENABLE_IT() and __HAL_SMARTCARD_DISABLE_IT() inside the transmit and receive process. Three operation modes are available within this driver: Polling mode IO operation Send an amount of data in blocking mode using HAL_SMARTCARD_Transmit() 2 DocID027328 Rev 1166 461 /

462 SMARTCARD Generic Driver HAL UM1850 Receive an amount of data in blocking mode using HAL_SMARTCARD_Receive() Interrupt mode IO operation Send an amount of data in non blocking mode using HAL_SMARTCARD_Transmit_IT() ansmission end of transfer HAL_SMARTCARD_TxCpltCallback is executed and At tr user can add his own code by customization of function pointer HAL_SMARTCARD_TxCpltCallback Receive an amount of data in non blocking mode using HAL_SMARTCARD_Receive_IT() At reception end of transfer HAL_SMARTCARD_RxCpltCallback is executed and user can add his own code by customization of function pointer HAL_SMARTCARD_RxCpltCallback In case of transfer Error, HAL_SMARTCARD_ErrorCallback() function is executed and user can add his own code by customization of function pointer HAL_SMARTCARD_ErrorCallback DMA mode IO operation Send an amount of data in non blocking mode (DMA) using HAL_SMARTCARD_Transmit_DMA() At transmission end of transfer HAL_SMARTCARD_TxCpltCallback is executed and user can add his own code by customization of function pointer HAL_SMARTCARD_TxCpltCallback Receive an amount of data in non blocking mode (DMA) using HAL_SMARTCARD_Receive_DMA() r At reception end of transfer HAL_SMARTCARD_RxCpltCallback is executed and use can add his own code by customization of function pointer HAL_SMARTCARD_RxCpltCallback In case of transfer Error, HAL_SMARTCARD_ErrorCallback() function is executed and user can add his own code by customization of function pointer HAL_SMARTCARD_ErrorCal lback SMARTCARD HAL driver macros list Below the list of most used macros in SMARTCARD HAL driver. __HAL_SMARTCARD_ENABLE: Enable the SMARTCARD peripheral __HAL_SMARTCARD_DISABLE: Disable the SMARTCARD peripheral the specified SMARTCARD flag __HAL_SMARTCARD_GET_FLAG : Check whether is set or not __HAL_SMARTCARD_CLEAR_FLAG : Clear the specified SMARTCARD pending flag __HAL_SMARTCARD_ENABLE_IT: Enable the specified SMARTCARD interrupt __HAL_SMARTCARD_DISABLE_IT: Disable the specified SMARTCARD interrupt You can refer to the SMARTCARD HAL driver header file for more useful macros DocID027328 / 1166 462 Rev 2

463 UM1850 SMARTCARD Generic Driver HAL Additional remark: If the parity is enabled, then the MSB bit of the data written in . T the data register is transmitted but is changed by the parity bit he SMARTCARD - bits or 9 - fra m bits). e formats depend on the frame length defined by the M bit (8 Refer to the product reference manual for details. 38.2.2 Initialization and Configuration functions This subsection provides a set of functions allowing to initialize the USART in Smartcard mode. The Smartcard interface is designed to support asynchronous protocol Smartcards as 3 standard. - defined in the ISO 7816 The USART can provide a clock to the smartcard through the SCLK output. In smartcard mode, SCLK is not associated to the communication but is simply derived from the internal bit prescaler. - peripheral input clock through a 5 For the Smartcard mode only these parameters can be configured: Baud Rate Word Length => Should be 9 bits (8 bits + parity) Stop Bit Parity: => Should be enabled USART polarity USART phase USART LastBit Receiver/transmitter modes Prescaler GuardTime NACKState: The Smartcard NACK state onfiguration to get the Answer to Reset from the Recommended SmartCard interface c Card: Word Length = 9 Bits 1.5 Stop Bit Even parity BaudRate = 12096 baud Tx and Rx enabled Please refer to the ISO 7816 3 specification for more details. - It is also possible to choose 0.5 stop bit fo r receiving but it is recommended to use 1.5 stop bits for both transmitting and receiving to avoid switching between the two configurations. The HAL_SMARTCARD_Init() function follows the USART SmartCard configuration procedure (details for the procedure are available in reference manual (RM0329)). This section contains the following APIs: HAL_SMARTCARD_Init() HAL_SMARTCARD_DeInit() HAL_SMARTCARD_MspInit() HAL_SMARTCARD_MspDeInit() HAL_SMARTCARD_ReInit() 2 DocID027328 Rev 1166 463 /

464 HAL UM1850 SMARTCARD Generic Driver IO operation functions 38.2.3 This subsection provides a set of functions allowing to manage the SMARTCARD data transfers. 1. Smartcard is a single wire half duplex communication protocol. The Smartcard interface is designed to support asynchronous protocol Smartcards as defined in the 3 standard. - ISO 7816 2. The USART should be configured as: 8 bits plus parity: where M=1 and PCE=1 in the USART_CR1 register 1.5 stop bits when transmitting and receiving: where STOP=11 in the USART_CR2 re gister. 3. There are two modes of transfer: Blocking mode: The communication is performed in polling mode. The HAL status of all data processing is returned by the same function after finishing transfer. Non Blocking mode: The communication is performed us ing Interrupts or DMA, These APIs return the HAL status. The end of the data processing will be indicated through the dedicated SMARTCARD IRQ when using Interrupt mode or the DMA IRQ when using DMA mode. The HAL_SMARTCARD_TxCpltCallback(), HAL_SMARTCARD_Rx CpltCallback() user callbacks will be executed respectively at the end of the Transmit or Receive process The HAL_SMARTCARD_ErrorCallback() user callback will be executed when a communication error is detected Blocking mode APIs are : 4. HAL_SMARTCARD_Trans mit() HAL_SMARTCARD_Receive() 5. Non Blocking mode APIs with Interrupt are : HAL_SMARTCARD_Transmit_IT() HAL_SMARTCARD_Receive_IT() HAL_SMARTCARD_IRQHandler() Non Blocking mode functions with DMA are : 6. HAL_SMARTCARD_Transmit_DMA() HAL_SMARTCARD_Receive_DMA() A set of Transfer Complete Callbacks are provided in non Blocking mode: 7. HAL_SMARTCARD_TxCpltCallback() HAL_SMARTCARD_RxCpltCallback() HAL_SMARTCARD_ErrorCallback() This section contains the following APIs: HAL_SMARTCARD_Transmit() HAL_SMARTCARD_Receive() HAL_SMARTCARD_Transmit_IT() HAL_SMARTCARD_Receive_IT() HAL_SM ARTCARD_Transmit_DMA() HAL_SMARTCARD_Receive_DMA() HAL_SMARTCARD_Abort() HAL_SMARTCARD_AbortTransmit() HAL_SMARTCARD_AbortReceive() HAL_SMARTCARD_Abort_IT() HAL_SMARTCARD_AbortTransmit_IT() HAL_SMARTCARD_AbortReceive_IT() MARTCARD_IRQHandler() HAL_S HAL_SMARTCARD_TxCpltCallback() DocID027328 / 1166 464 Rev 2

465 UM1850 SMARTCARD Generic Driver HAL HAL_SMARTCARD_RxCpltCallback() HAL_SMARTCARD_ErrorCallback() HAL_SMARTCARD_AbortCpltCallback() HAL_SMARTCARD_AbortTransmitCpltCallback() HAL_SMARTCARD_AbortReceiveCpltCallback() Peripheral State and Errors functions 38.2.4 This subsection provides a set of functions allowing to control the SmartCard. time the state of HAL_SMARTCARD_GetState() API can be helpful to check in run - the SmartCard peripheral. e errors that could be occurred during tim - HAL_SMARTCARD_GetError() check in run communication. This section contains the following APIs: HAL_SMARTCARD_GetState() HAL_SMARTCARD_GetError() Detailed description of functions 38.2.5 HAL_SMARTCARD_Init HAL_StatusTypeDef HAL_SMARTCARD_Init Function name (SMARTCARD_HandleTypeDef * hsc) Function description Initializes the SmartCard mode according to the specified parameters in the SMARTCARD_InitTypeDef and create the associated handle. Parameters hsc: pointer to a SMARTCARD_HandleTypeDef structure that contains the configuration information for SMARTCARD module. Return values status HAL: HAL_SMARTCARD_ReInit HAL_StatusTypeDef HAL_SMARTCARD_ReInit Function name (SMARTCARD_HandleTypeDef * hsc) Function description HAL_SMARTCARD_DeInit HAL_StatusTypeDef HAL_SMARTCARD_DeInit Function name (SMARTCARD_Hand leTypeDef * hsc) DeInitializes the USART SmartCard peripheral. Function description Parameters hsc: pointer to a SMARTCARD_HandleTypeDef structure that contains the configuration information for SMARTCARD module. Return values status HAL: 2 DocID027328 Rev 1166 465 /

466 HAL UM1850 SMARTCARD Generic Driver HAL_SMARTCARD_MspInit void HAL_SMARTCARD_MspInit Function name (SMARTCARD_HandleTypeDef * hsc) Function description SMARTCARD MSP Init. Parameters hsc: pointer to a SMARTCARD_HandleTypeDef structure CARD that contains the configuration information for SMART module. Return values None: HAL_SMARTCARD_MspDeInit void HAL_SMARTCARD_MspDeInit Function name (SMARTCARD_HandleTypeDef * hsc) Function description SMARTCARD MSP DeInit. Parameters pointer to a SMARTCARD_HandleTypeDef structure hsc: that contains the configuration information for SMARTCARD module. Return values None: HAL_SMARTCARD_Transmit HAL_StatusTypeDef HAL_SMARTCARD_Transmit Function name pData, uint16_t (SMARTCARD_HandleTypeDef * hsc, uint8_t * Size, uint32_t Timeout) Send an amount of data in blocking mode. Function description Parameters hsc: pointer to a SMARTCARD_HandleTypeDef structure that contains the configuration information for SMARTCARD module. pData: pointer to data buffer amount of data to be sent Size: Timeout: Timeout duration Return values HAL: status HAL_SMARTCARD_Receive HAL_StatusTypeDef HAL_SMARTCARD_Receive Function name (SMARTCARD_HandleTypeDef * hsc, uint8_t * pData, uint16_t Size, uin t32_t Timeout) Function description Receive an amount of data in blocking mode. Parameters pointer to a SMARTCARD_HandleTypeDef structure hsc: that contains the configuration information for SMARTCARD module. pData: pointer to data buffer amount of data to be received Size: Timeout duration Timeout: Return values status HAL: DocID027328 / 1166 466 Rev 2

467 UM1850 SMARTCARD Generic Driver HAL HAL_SMARTCARD_Transmit_IT HAL_StatusTypeDef HAL_SMARTCARD_Transmit_IT Function name (SMARTCARD_HandleTypeDef * hsc, uint8_t * pData, uint16_t Size) Function description Send an amount of data in non blocking mode. Parameters pointer to a SMARTCARD_HandleTypeDef structure hsc: that contains the configuration information for SMARTCARD module. pData: pointer to data buffer Size: amount of data to be sent Return values status HAL: HAL_SMARTCARD_Receive_IT HAL_StatusTypeDef HAL_SMARTCARD_Receive_IT Function name (SMARTCARD_HandleTypeDef * hsc, uint8_t * pData, uint16_t Size) Receive an amount of data in non blocking mode. Function description Parameters hsc: pointer to a SMARTCARD_HandleTypeDef structure that contains the configuration information for SMARTCARD module. pointer to data buffer pData: amount of data to be received Size: Return values HAL: status HAL_SMARTCARD_Transmit_DMA HAL_StatusTypeDef HAL_SMARTCARD_Transmit_DMA Function name (SMARTCARD_HandleTypeDef * hsc, uint8_t * pData, uint16_t Size) Function description Send an amount of data in non blocking mode. Parameters hsc: pointer to a SMARTCARD_HandleTypeDef structure that contains the configuration information for SMARTCARD module. pointer to data buffer pData: Size: amount of data to be sent Return values status HAL: HAL_SMARTCARD_Receive_DMA sTypeDef HAL_SMARTCARD_Receive_DMA HAL_Statu Function name (SMARTCARD_HandleTypeDef * hsc, uint8_t * pData, uint16_t Size) Receive an amount of data in non blocking mode. Function description Parameters hsc: pointer to a SMARTCARD_HandleTypeDef structure figuration information for SMARTCARD that contains the con module. pData: pointer to data buffer 2 DocID027328 Rev 1166 467 /

468 HAL SMARTCARD Generic Driver UM1850 amount of data to be received Size: Return values HAL: status Notes When the SMARTCARD parity is enabled (PCE = 1) the data received contain the parity bit.s HAL_SMARTCARD_Abort HAL_StatusTypeDef HAL_SMARTCARD_Abort Function name (SMARTCARD_HandleTypeDef * hsc) Abort ongoing transfers (blocking mode). Function description Parameters SMARTCARD handle. hsc: Return values status HAL: Notes This procedure could be used for aborting any ongoing transfer started in Interrupt or DMA mode. This procedure performs following operations : Disable PPP InterruptsDisable the DMA transfer in the peripheral register (if enabled)Abort ing HAL_DMA_Abort (in case of transfer DMA transfer by call in DMA mode)Set handle State to READY This procedure is executed in blocking mode : when exiting function, Abort is considered as completed. HAL_SMARTCARD_AbortTransmit AbortTransmit HAL_StatusTypeDef HAL_SMARTCARD_ Function name (SMARTCARD_HandleTypeDef * hsc) Abort ongoing Transmit transfer (blocking mode). Function description Parameters SMARTCARD handle. hsc: Return values status HAL: Notes This procedure could be used for aborting any ongoing transfer started in Interrupt or DMA mode. This procedure performs following operations : Disable PPP InterruptsDisable the DMA transfer in the peripheral register (if enabled)Abort ing HAL_DMA_Abort (in case of transfer DMA transfer by call in DMA mode)Set handle State to READY This procedure is executed in blocking mode : when exiting function, Abort is considered as completed. HAL_SMARTCARD_AbortReceive bortReceive HAL_StatusTypeDef HAL_SMARTCARD_A Function name (SMARTCARD_HandleTypeDef * hsc) Function description Abort ongoing Receive transfer (blocking mode). Parameters SMARTCARD handle. hsc: Return values status HAL: Notes This procedure could be used for aborting any ongoing transfer started in Interrupt or DMA mode. This procedure performs following operations : Disable PPP InterruptsDisable DocID027328 / 1166 468 Rev 2

469 UM1850 SMARTCARD Generic Driver HAL the DMA transfer in the peripheral register (if enabled)Abort DMA transfer by calling HAL_DMA_Abort (in case of transfer in DMA mode)Set handle State to READY This procedure is executed in blocking mode : when exiting function, Abort is considered as completed. HAL_SMARTCARD_Abort_IT HAL_StatusTypeDef HAL_SMARTCARD_Abort_IT Function name (SMARTCARD_HandleTypeDef * hsc) Abort ongoing transfers (Interrupt mode). Function description Parameters SMARTCARD handle. hsc: Return values HAL: status Notes This procedure could be used for aborting any ongoing transfer started in Interrupt or DMA mode. This procedure : Disable PPP InterruptsDisable performs following operations the DMA transfer in the peripheral register (if enabled)Abort DMA transfer by calling HAL_DMA_Abort_IT (in case of transfer in DMA mode)Set handle State to READYAt abort completion, call user abort complete callback ocedure is executed in Interrupt mode, meaning that This pr abort procedure could be considered as completed only when user abort complete callback is executed (not when exiting function). HAL_SMARTCARD_AbortTransmit_IT RD_AbortTransmit_IT HAL_StatusTypeDef HAL_SMARTCA Function name (SMARTCARD_HandleTypeDef * hsc) Function description Abort ongoing Transmit transfer (Interrupt mode). Parameters SMARTCARD handle. hsc: Return values HAL: status Notes This procedure could be used for aborting any ongoing transfer started in Interrupt or DMA mode. This procedure performs following operations : Disable PPP InterruptsDisable the DMA transfer in the peripheral register (if enabled)Abort DMA transfer by call ing HAL_DMA_Abort_IT (in case of transfer in DMA mode)Set handle State to READYAt abort completion, call user abort complete callback This procedure is executed in Interrupt mode, meaning that abort procedure could be considered as completed only when user abort complete callback is executed (not when exiting function). HAL_SMARTCARD_AbortReceive_IT HAL_StatusTypeDef HAL_SMARTCARD_AbortReceive_IT Function name (SMARTCARD_HandleTypeDef * hsc) Abort ongoing Receive transfer (Interru Function description pt mode). 2 DocID027328 Rev 1166 469 /

470 HAL UM1850 SMARTCARD Generic Driver Parameters SMARTCARD handle. hsc: Return values status HAL: Notes This procedure could be used for aborting any ongoing transfer started in Interrupt or DMA mode. This procedure performs following operations : Disable PPP InterruptsDisable the DMA transfer in the peripheral register (if enabled)Abort ing HAL_DMA_Abort_IT (in case of DMA transfer by call transfer in DMA mode)Set handle State to READYAt abort completion, call user abort complete callback This procedure is executed in Interrupt mode, meaning that abort procedure could be considered as completed only when r abort complete callback is executed (not when exiting use function). HAL_SMARTCARD_IRQHandler void HAL_SMARTCARD_IRQHandler Function name (SMARTCARD_HandleTypeDef * hsc) This function handles SMARTCARD interrupt request. Function description Parameters pointer to a SMARTCARD_HandleTypeDef structure sc: h that contains the configuration information for SMARTCARD module. Return values None: HAL_SMARTCARD_TxCpltCallback void HAL_SMARTCARD_TxCpltCallback Function name (SMARTCARD_HandleTypeDef * hsc) Tx Transfer completed callbacks. Function description Parameters hsc: pointer to a SMARTCARD_HandleTypeDef structure that contains the configuration information for SMARTCARD module. Return values None: HAL_SMARTCARD_RxCpltCallback void HAL_SMARTCARD_RxCpltCallback Function name (SMARTCARD_HandleTypeDef * hsc) Function description Rx Transfer completed callbacks. Parameters pointer to a SMARTCARD_HandleTypeDef structure hsc: that contains the configuration information for SMARTCARD module. Return values None: HAL_SMARTCARD_ErrorCallback void HAL_SMARTCARD_ErrorCallback Function name (SMARTCARD_HandleTypeDef * hsc) DocID027328 / 1166 470 Rev 2

471 HAL UM1850 SMARTCARD Generic Driver SMARTCARD error callbacks. Function description Parameters hsc: pointer to a SMARTCARD_HandleTypeDef structure that contains the configuration information for SMARTCARD module. Return values None: HAL_SMARTCARD_AbortCpltCallback void HAL_SMARTCARD_AbortCpltCallback Function name (SMARTCARD_HandleTypeDef * hsc) SMARTCARD Abort Complete callback. Function description Parameters SMARTCARD handle. hsc: Return values None: HAL_SMARTCARD_AbortTransmitCpltCallback void HAL_SMARTCARD_AbortTransmitCpltCallback Function name (SMARTCARD_HandleTypeDef * hsc) SMARTCARD Abort Transmit Complete callback. description Function Parameters SMARTCARD handle. hsc: Return values None: HAL_SMARTCARD_AbortReceiveCpltCallback void HAL_SMARTCARD_AbortReceiveCpltCallback Function name (SMARTCARD_HandleTypeDef * hsc) Function description SMARTCARD Abort ReceiveComplete callback. Parameters SMARTCARD handle. hsc: Return values None: HAL_SMARTCARD_GetState HAL_SMARTCARD_StateTypeDef Function name HAL_SMARTCARD_GetState (SMARTCARD_HandleTypeDef * hsc) return the SMARTCARD state Function description Parameters hsc: pointer to a SMARTCARD_HandleTypeDef structure that contains the configuration information for SMARTCARD module. Return values HAL: state HAL_SMARTCARD_GetError uint32_t HAL_SMARTCARD_GetError Function name (SMARTCARD_HandleTypeDef * hsc) Return the SMARTCARD error code. Function description 2 DocID027328 Rev 1166 471 /

472 HAL SMARTCARD Generic Driver UM1850 Parameters hsc: : pointer to a SMARTCARD_HandleTypeDef structure that contains the configuration information for the specified SMARTCARD. Return values Error Code SMARTCARD: 38.3 SMARTCARD Firmware driver defines 38.3.1 SMARTCARD SMARTCARD Clock Phase SMARTCARD_PHASE_1EDGE SMARTCARD_PHASE_2EDGE SMARTCARD Clock Polarity SMARTCARD_POLARITY_LOW SMARTCARD_POLARITY_HIGH SMARTCARD DMA requests SMARTCARD_DMAREQ_TX SMARTCARD_DMAREQ_RX SMARTCARD Error Code HAL_SMARTCARD_ERROR_NONE No error HAL_SMARTCARD_ERROR_PE Parity error HAL_SMARTCARD_ERROR_NE Noise error HAL_SMARTCARD_ERROR_FE Frame error HAL_SMARTCARD_ERROR_ORE OverRun error DMA transfer error HAL_SMARTCARD_ERROR_DMA SMARTCARD Exported Macros Description: __HAL_SMARTCARD_RESET_HANDLE_STA TE Reset SMARTCARD handle gstate & RxState. Parameters: __HANDLE__: specifies the SMARTCARD Handle. SMARTCARD Handle selects the USARTx peripheral (USART availability and x value depending on device). Description: __HAL_SMARTCARD_FLUSH_DRREGISTER Flush the Smartcard DR register. Parameters: specifies the __HANDLE__: SMARTCARD Handle. SMARTCARD Handle selects the DocID027328 / 1166 472 Rev 2

473 UM1850 SMARTCARD Generic Driver HAL USARTx peripheral (USART availability and x value depending on device). Description: __HAL_SMARTCARD_GET_FLAG Check whether the specified Smartcard flag is set or not. Parameters: specifies the __HANDLE__: SMARTCARD Handle. SMARTCARD Handle selects the USARTx peripheral (USART availability and x value depending on device). __FLAG__: specifies the flag to check. This parameter can be one of the following values: SMARTCARD_FLAG_TXE: a register empty Transmit dat flag SMARTCARD_FLAG_TC: Transmission Complete flag SMARTCARD_FLAG_RXNE: Receive data register not empty flag SMARTCARD_FLAG_IDLE: Idle Line detection flag SMARTCARD_FLAG_ORE: OverRun Error flag SMARTCARD_FLAG_NE: Noise Error flag _FLAG_FE: SMARTCARD Framing Error flag SMARTCARD_FLAG_PE: Parity Error flag Return value: The: new state of __FLAG__ (TRUE or FALSE). Description: __HAL_SMARTCARD_CLEAR_FLAG Clear the specified Smartcard pending flags. Parameters: __HANDLE__: specifies the SMARTCARD Handle. SMARTCARD Handle selects the USARTx peripheral (USART availability and x value depending on device). __FLAG__: specifies the flag to check. This parameter can be any 2 DocID027328 Rev 1166 473 /

474 HAL UM1850 SMARTCARD Generic Driver combination of the following values: SMARTCARD_FLAG_TC: mplete flag. Transmission Co SMARTCARD_FLAG_RXNE: Receive data register not empty flag. Notes: PE (Parity error), FE (Framing error), NE (Noise error) and ORE (OverRun error) flags are cleared by software sequence: a read operation to USART_SR register followed by a read operation to USART_DR register. RXNE flag can be also cleared by a read to the USART_DR register. TC flag can be also cleared by software sequence: a read operation to USART_SR register followed by a write operation to USART_DR register. d only by a write to TXE flag is cleare the USART_DR register. Description: __HAL_SMARTCARD_CLEAR_PEFLAG Clear the SMARTCARD PE pending flag. Parameters: __HANDLE__: specifies the USART Handle. SMARTCARD Handle selects the USARTx peripheral (USART availability and x value depending on device). Description: __HAL_SMARTCARD_CLEAR_FEFLAG Clear the SMARTCARD FE pending flag. Parameters: __HANDLE__: specifies the USART Handle. SMARTCARD Handle selects the USARTx peripheral (USART availability and x value depending on device). Description: __HAL_SMARTCARD_CLEAR_NEFLAG Clear the SMARTCARD NE pending flag. Parameters: __HANDLE__: specifies the USART Handle. SMARTCARD Handle selects the USARTx peripheral (USART availability and x value DocID027328 / 1166 474 Rev 2

475 UM1850 SMARTCARD Generic Driver HAL depending on device). Description: __HAL_SMARTCARD_CLEAR_O REFLAG Clear the SMARTCARD ORE pending flag. Parameters: __HANDLE__: specifies the USART Handle. SMARTCARD Handle selects the USARTx peripheral (USART availability and x value depending on device). Description: __HAL_SMARTCARD_CLEAR_IDLEFLAG Clear the SMARTCARD IDLE pending flag. Parameters: __HANDLE__: specifies the USART Handle. SMARTCARD Handle selects the USARTx peripheral (USART availability and x value depending on device). Description: __HAL_SMARTCARD_ENABLE_IT Enable the specified SmartCard interrupt. Parameters: __HANDLE__: specifies the SMARTCARD Handle. SMARTCARD Handle selects the USARTx peripheral (USART availability and x value depending on device). __INTERRUPT__: specifies the SMARTCARD interrupt to enable. be one of the This parameter can following values: SMARTCARD_IT_TXE: Transmit Data Register empty interrupt SMARTCARD_IT_TC: Transmission complete interrupt SMARTCARD_IT_RXNE: Receive Data register not empty interrupt SMARTCARD_IT_IDLE: Idle line detection interrupt ARD_IT_PE: Parity SMARTC Error interrupt SMARTCARD_IT_ERR: Error interrupt(Frame error, noise 2 DocID027328 Rev 1166 475 /

476 HAL UM1850 SMARTCARD Generic Driver error, overRun error) Description: __HAL_SMARTCARD_DISABLE_IT Disable the specified SmartCard interrupt. Parameters: __HANDLE__: specifies the SMARTCARD Handle. SMARTCARD Handle selects the USARTx peripheral (USART availability and x value depending on device). __INTERRUPT__: specifies the SMARTCARD interrupt to disable. This parameter can be one of the following values: SMARTCARD_IT_TXE: mpty Transmit Data Register e interrupt SMARTCARD_IT_TC: Transmission complete interrupt SMARTCARD_IT_RXNE: Receive Data register not empty interrupt SMARTCARD_IT_IDLE: Idle line detection interrupt SMARTCARD_IT_PE: Parity Error interrupt SMARTCARD_IT_ERR: Error interrupt(Frame er ror, noise error, overRun error) Description: __HAL_SMARTCARD_GET_IT_SOURCE Checks whether the specified SmartCard interrupt has occurred or not. Parameters: __HANDLE__: specifies the SmartCard Handle. __IT__: specifies the SMARTCARD interrupt source to check. This parameter can be one of the following values: SMARTCARD_IT_TXE: Transmit Data Register empty interrupt SMARTCARD_IT_TC: Transmission complete interrupt SMARTCARD_IT_RXNE: Receive Data registe r not DocID027328 / 1166 476 Rev 2

477 UM1850 SMARTCARD Generic Driver HAL empty interrupt SMARTCARD_IT_IDLE: Idle line detection interrupt SMARTCARD_IT_ERR: Error interrupt SMARTCARD_IT_PE: Parity Error interrupt Return value: The: new state of __IT__ (TRUE or FALSE). Description: __HAL_SMARTCARD_ENABLE ssociated to Enable the USART a the SMARTCARD Handle. Parameters: __HANDLE__: specifies the SMARTCARD Handle. SMARTCARD Handle selects the USARTx peripheral (USART availability and x value depending on device). Description: __HAL_SMARTCARD_DISABLE associated to Disable the USART the SMARTCARD Handle. Parameters: __HANDLE__: specifies the SMARTCARD Handle. SMARTCARD Handle selects the USARTx peripheral (USART availability and x value depending on device). Description: __HAL_SMARTCARD_DMA_REQUEST_ENA BLE le the SmartCard Macros to enab DMA request. Parameters: __HANDLE__: specifies the SmartCard Handle. __REQUEST__: specifies the SmartCard DMA request. This parameter can be one of the following values: SMARTCARD_DMAREQ_TX: SmartCard DMA transmit request _RX: SMARTCARD_DMAREQ SmartCard DMA receive request 2 DocID027328 Rev 1166 477 /

478 HAL UM1850 SMARTCARD Generic Driver Description: __HAL_SMARTCARD_DMA_REQUEST_DISA BLE Macros to disable the SmartCard DMA request. Parameters: __HANDLE__: specifies the SmartCard Handle. __REQUEST__: specifies the SmartCard DMA request. This parameter can be one of the following values: SMARTCARD_DMAREQ_TX: SmartCard DMA transmit request SMARTCARD_DMAREQ_RX: SmartCard DMA receive request SMARTCARD Last Bit SMARTCARD_LASTBIT_DISABLE RTCARD_LASTBIT_ENABLE SMA SMARTCARD Mode SMARTCARD_MODE_RX SMARTCARD_MODE_TX SMARTCARD_MODE_TX_RX SMARTCARD NACK State SMARTCARD_NACK_ENABLE SMARTCARD_NACK_DISABLE SMARTCARD Parity SMARTCARD_PARITY_EVEN SMARTCARD_PARITY_ODD SMARTCARD Prescaler SYSCLK divided by 2 SMARTCARD_PRESCALER_SYSCLK_DIV2 SMARTCARD_PRESCALER_SYSCLK_DIV4 SYSCLK divided by 4 SMARTCARD_PRESCALER_SYSCLK_DIV6 SYSCLK divided by 6 SYSCLK divided by 8 SMARTCARD_PRESCALER_SYSCLK_DIV8 SMARTCARD_PRESCALER_SYSCLK_DIV10 SYSCLK divided by 10 SMARTCARD_PRESCALER_SYSCLK_DIV12 SYSCLK divided by 12 SYSCLK divided by 14 SMARTCARD_PRESCALER_SYSCLK_DIV14 SMARTCARD_PRESCALER_SYSCLK_DIV16 SYSCLK divided by 16 SYSCLK divided by 18 SMARTCARD_PRESCALER_SYSCLK_DIV18 SYSCLK divided by 20 SMARTCARD_PRESCALER_SYSCLK_DIV20 DocID027328 / 1166 478 Rev 2

479 HAL UM1850 SMARTCARD Generic Driver SMARTCARD_PRESCALER_SYSCLK_DIV22 SYSCLK divided by 22 SYSCLK divided by 24 SMARTCARD_PRESCALER_SYSCLK_DIV24 SYSCLK divided by 26 SMARTCARD_PRESCALER_SYSCLK_DIV26 SMARTCARD_PRESCALER_SYSCLK_DIV28 SYSCLK divided by 28 SMARTCARD_PRESCALER_SYSCLK_DIV30 SYSCLK divided by 30 SMARTCARD_PRESCALER_SYSCLK_DIV32 SYSCLK divided by 32 SMARTCARD_PRESCALER_SYSCLK_DIV34 SYSCLK divided by 34 SMARTCARD_PRESCALER_SYSCLK_DIV36 SYSCLK divided by 36 SYSCLK divided by 38 D_PRESCALER_SYSCLK_DIV38 SMARTCAR SYSCLK divided by 40 SMARTCARD_PRESCALER_SYSCLK_DIV40 SYSCLK divided by 42 SMARTCARD_PRESCALER_SYSCLK_DIV42 SMARTCARD_PRESCALER_SYSCLK_DIV44 SYSCLK divided by 44 SMARTCARD_PRESCALER_SYSCLK_DIV46 SYSCLK divided by 46 SYSCLK divided by 48 SMARTCARD_PRESCALER_SYSCLK_DIV48 SYSCLK divided by 50 SMARTCARD_PRESCALER_SYSCLK_DIV50 SMARTCARD_PRESCALER_SYSCLK_DIV52 SYSCLK divided by 52 SYSCLK divided by 54 SMARTCARD_PRESCALER_SYSCLK_DIV54 SMARTCARD_PRESCALER_SYSCLK_DIV56 SYSCLK divided by 56 SMARTCARD_PRESCALER_SYSCLK_DIV58 SYSCLK divided by 58 SMARTCARD_PRESCALER_SYSCLK_DIV60 SYSCLK divided by 60 SMARTCARD_PRESCALER_SYSCLK_DIV62 SYSCLK divided by 62 SMARTCARD Number of Stop Bits SMARTCARD_STOPBITS_0_5 SMARTCARD_STOPBITS_1_5 SMARTCARD Word Length SMARTCARD_WORDLENGTH_9B 2 DocID027328 Rev 1166 479 /

480 SPI Generic Driver HAL UM1850 HAL SPI Generic Driver 39 SPI Firmware driver registers structures 39.1 39.1.1 SPI_InitTypeDef Data Fields uint32_t Mode uint32_t Direction uint32_t DataSize uint32_t CLKPolarity uint32_t CLKPhase uint32_t NSS uint32_t BaudRatePrescaler uint32_t FirstBit uint32_t TIMode uint32_t CRCCalculation CRCPolynomial uint32_t Field Documentation uint32_t SPI_InitTypeDef::Mode Specifies the SPI operating mode. This parameter can be a value of SPI_Mode uint32_t SPI_InitTypeDef::Direction parameter can be a value of Specifies the SPI Directional mode state. This SPI_Direction uint32_t SPI_InitTypeDef::DataSize Specifies the SPI data size. This parameter can be a value of SPI_Data_Size y uint32_t SPI_InitTypeDef::CLKPolarit Specifies the serial clock steady state. This parameter can be a value of SPI_Clock_Polarity uint32_t SPI_InitTypeDef::CLKPhase Specifies the clock active edge for the bit capture. This parameter can be a value of SPI_Clock_Phase uint32_t SPI_InitTypeDef::NSS Specifies whether the NSS signal is managed by hardware (NSS pin) or by software SPI_Slave_Select_management using the SSI bit. This parameter can be a value of uint32_t SPI_InitTypeDef::BaudRatePrescaler Specifies the Baud Rate prescaler value which will be used to configure the transmit SPI_BaudRa and receive SCK clock. This parameter can be a value of te_Prescaler The communication clock is derived from the master clock. The slave clock does Note: not need to be set. uint32_t SPI_InitTypeDef::FirstBit Specifies whether data transfers start from MSB or LSB bit. This parameter can be a SPI_MSB_LSB_transmission value of uint32_t SPI_InitTypeDef::TIMode Specifies if the TI mode is enabled or not. This parameter can be a value of SPI_TI_mode uint32_t SPI_InitTypeDef::CRCCalculation Specifies if the CRC calculation is enabled or not. This parameter can be a value of SPI_CRC_Calculation DocID027328 / 1166 480 Rev 2

481 UM1850 SPI Generic Driver HAL uint32_t SPI_InitTypeDef::CRCPolynomial Specifies the polynomial used for the CRC calculation. This parameter must be a number betw een Min_Data = 0 and Max_Data = 65535 __SPI_HandleTypeDef 39.1.2 Data Fields SPI_TypeDef * Instance SPI_InitTypeDef Init uint8_t * pTxBuffPtr uint16_t TxXferSize __IO uint16_t TxXferCount uint8_t * pRxBuffPtr RxXferSize uint16_t __IO uint16_t RxXferCount void(* RxISR void(* TxISR DMA_HandleTypeDef * hdmatx DMA_HandleTypeDef * hdmarx HAL_LockTypeDef Lock __IO HAL_SPI_StateTypeDef State __IO uint32_t ErrorCode Field Documentation SPI_TypeDef* __SPI_HandleTypeDef::Instance SPI registers base address SPI_InitTypeDef __SPI_HandleTypeDef::Init SPI communication parameters uint8_t* __SPI_HandleTypeDef::pTxBuffPtr Pointer to SPI Tx transfer Buffer uint16_t __SPI_HandleTypeDef::TxXferSize SPI Tx Transfer size __SPI_HandleTypeDef::TxXferCount __IO uint16_t SPI Tx Transfer Counter uint8_t* __SPI_HandleTypeDef::pRxBuffPtr Pointer to SPI Rx transfer Buffer uint16_t __SPI_HandleTypeDef::RxXferSize SPI Rx Transfer size __IO uint16_t __SPI_HandleTypeDef::RxXferCount fer Counter SPI Rx Trans void(* __SPI_HandleTypeDef::RxISR)(struct __SPI_HandleTypeDef *hspi) function pointer on Rx ISR void(* __SPI_HandleTypeDef::TxISR)(struct __SPI_HandleTypeDef *hspi) function pointer on Tx ISR DMA_HandleTypeDef* __SPI_HandleTypeDef::hdmatx I Tx DMA Handle parameters SP DMA_HandleTypeDef* __SPI_HandleTypeDef::hdmarx SPI Rx DMA Handle parameters HAL_LockTypeDef __SPI_HandleTypeDef::Lock Locking object __IO HAL_SPI_StateTypeDef __SPI_HandleTypeDef::State SPI communication state 2 DocID027328 Rev 1166 481 /

482 HAL UM1850 SPI Generic Driver __SPI_HandleTypeDef::ErrorCode __IO uint32_t SPI Error code 39.2 SPI Firmware driver API description How to use this driver 39.2.1 The SPI HAL driver can be used as follows: peDef handle structure, for example: SPI_HandleTypeDef Declare a SPI_HandleTy 1. hspi; Initialize the SPI low level resources by implementing the HAL_SPI_MspInit() API: 2. a. Enable the SPIx interface clock b. SPI pins configuration Enable the clock for the SPI GPIOs pull Configure these SPI pins as alternate function push - c. NVIC configuration if you need to use interrupt process Configure the SPIx interrupt priority Enable the NVIC SPI IRQ handle d. DMA Configuration if you need to use DMA process Declare a DMA_HandleTypeDef handle structur e for the transmit or receive Channel Enable the DMAx clock Configure the DMA handle parameters Configure the DMA Tx or Rx Channel Associate the initilalized hdma_tx(or _rx) handle to the hspi DMA Tx (or Rx) handle Configure the priority and enable the NV IC for the transfer complete interrupt on the DMA Tx or Rx Channel 3. Program the Mode, BidirectionalMode , Data size, Baudrate Prescaler, NSS management, Clock polarity and phase, FirstBit and CRC configuration in the hspi Init structure. 4. Initialize the SP I registers by calling the HAL_SPI_Init() API: This API configures also the low level Hardware GPIO, CLOCK, CORTEX...etc) by calling the customized HAL_SPI_MspInit() API. Circular mode restriction: 1. The DMA circular mode cannot be used when the SPI is configured in these modes: Master 2Lines RxOnly a. b. Master 1Line Rx 2. The CRC feature is not managed when the DMA circular mode is enabled ing APIs the When the SPI DMA Pause/Stop features are used, we must use the follow 3. HAL_SPI_DMAPause()/ HAL_SPI_DMAStop() only under the SPI callbacks Master Receive mode restriction: only mode (MSTR =1, BIDIMODE=0, RXONLY=0) or - 1. In Master unidirectional receive bidirectional receive mode (MSTR=1, BIDIMODE=1, BIDIOE=0), to ensure that the SPI does not initiate a new transfer the following procedure has to be respected: a. HAL_SPI_DeInit() HAL_SPI_Init() b. Initialization and de 39.2.2 initialization functions - - This subsection provides a set of functions allowing to initialize and de initialize the SPIx peripheral: DocID027328 / 1166 482 Rev 2

483 UM1850 HAL SPI Generic Driver User must impleme nt HAL_SPI_MspInit() function in which he configures all related peripherals resources (CLOCK, GPIO, DMA, IT and NVIC ). Call the function HAL_SPI_Init() to configure the selected device with the selected configuration: Mode Direction Data Size Clock Pol arity and Phase NSS Management BaudRate Prescaler FirstBit TIMode CRC Calculation CRC Polynomial if CRC enabled Call the function HAL_SPI_DeInit() to restore the default configuration of the selected SPIx peripheral. APIs: This section contains the following HAL_SPI_Init() HAL_SPI_DeInit() HAL_SPI_MspInit() HAL_SPI_MspDeInit() 39.2.3 IO operation functions This subsection provides a set of functions allowing to manage the SPI data transfers. The SPI supports master and slave mode : 1. There are two modes of transfer: Blocking mode: The communication is performed in polling mode. The HAL status of all data processing is returned by the same function after finishing transfer. No Blocking mode: The communication is performed using Interrupts or DMA, - These APIs return the HAL status. The end of the data processing will be indicated through t he dedicated SPI IRQ when using Interrupt mode or the DMA IRQ when using DMA mode. The HAL_SPI_TxCpltCallback(), HAL_SPI_RxCpltCallback() and HAL_SPI_TxRxCpltCallback() user callbacks will ess The be executed respectively at the end of the transmit or Receive proc HAL_SPI_ErrorCallback()user callback will be executed when a communication error is detected 2. APIs provided for these 2 transfer modes (Blocking mode or Non blocking mode using either Interrupt or DMA) exist for 1Line (simplex) and 2Lines (full dup lex) modes. This section contains the following APIs: HAL_SPI_Transmit() HAL_SPI_Receive() HAL_SPI_TransmitReceive() HAL_SPI_Transmit_IT() HAL_SPI_Receive_IT() HAL_SPI_TransmitReceive_IT() HAL_SPI_Transmit_DMA() HAL_SPI_Receive_DMA() HAL_SPI_TransmitReceive_DMA() HAL_SPI_Abort() 2 DocID027328 Rev 1166 483 /

484 HAL UM1850 SPI Generic Driver HAL_SPI_Abort_IT() HAL_SPI_DMAPause() HAL_SPI_D MAResume() HAL_SPI_DMAStop() HAL_SPI_IRQHandler() HAL_SPI_TxCpltCallback() HAL_SPI_RxCpltCallback() HAL_SPI_TxRxCpltCallback() HAL_SPI_TxHalfCpltCallback() HAL_SPI_RxHalfCpltCallback() HAL_SPI_TxRxHalfCpltCallback() HAL_SPI_ErrorCallback() HAL_SPI_AbortCpltCallback() Peripheral State and Errors functions 39.2.4 This subsection provides a set of functions allowing to control the SPI. HAL_SPI_GetState() API can be helpful to check in run time the state of the SPI - peripheral time Errors occurring during communication - HAL_SPI_GetError() check in run This section contains the following APIs: HAL_SPI_GetSt ate() HAL_SPI_GetError() 39.2.5 Detailed description of functions HAL_SPI_Init HAL_StatusTypeDef HAL_SPI_Init (SPI_HandleTypeDef * hspi) Function name Function description Initialize the SPI according to the specified parameters in the SPI_InitTypeDef and initialize the associated handle. Parameters pointer to a SPI_HandleTypeDef structure that contains hspi: the configuration information for SPI module. Return values HA L: status HAL_SPI_DeInit HAL_StatusTypeDef HAL_SPI_DeInit (SPI_HandleTypeDef * Function name hspi) Function description De Initialize the SPI peripheral. Parameters hspi: pointer to a SPI_HandleTypeDef structure that contains the configuration information for SPI module. Return values HAL: status HAL_SPI_MspInit void HAL_SPI_MspInit (SPI_HandleTypeDef * hspi) Function name Function description Initialize the SPI MSP. DocID027328 / 1166 484 Rev 2

485 UM1850 SPI Generic Driver HAL Parameters hspi: pointer to a SPI_HandleTypeDef structure that contains the configuration information for SPI module. Return values None: HAL_SPI_MspDeInit void HAL_SPI_MspDeInit (SPI_HandleTypeDef * hspi) Function name Initialize the SPI MSP. - De Function description Parameters hspi: pointer to a SPI_HandleTypeDef structure that contains the configuration information for SPI module. Return values None: HAL_SPI_Transmit * HAL_StatusTypeDef HAL_SPI_Transmit (SPI_HandleTypeDef Function name hspi, uint8_t * pData, uint16_t Size, uint32_t Timeout) Function description Transmit an amount of data in blocking mode. Parameters pointer to a SPI_HandleTypeDef structure that contains hspi: the configuration information for SPI module. pData: pointer to data buffer amount of data to be sent Size: Timeout: Timeout duration Return values HAL: status HAL_SPI_Receive HAL_StatusTypeDef HAL_SPI_Receive (SPI_HandleTypeDef * Function name hspi, uint8_t * pData, uint16_t Size, uint32_t Timeout) unction description Receive an amount of data in blocking mode. F Parameters hspi: pointer to a SPI_HandleTypeDef structure that contains the configuration information for SPI module. pData: pointer to data buffer Size: amount of data to be received Timeout duration Tim eout: Return values status HAL: HAL_SPI_TransmitReceive HAL_StatusTypeDef HAL_SPI_TransmitReceive Function name (SPI_HandleTypeDef * hspi, uint8_t * pTxData, uint8_t * pRxData, uint16_t Size, uint32_t Timeout) Function description Transmit and Receive an amount of data in blocking mode. Parameters pointer to a SPI_HandleTypeDef structure that contains hspi: the configuration information for SPI module. pTxData: pointer to transmission data buffer pointer to reception data buffer pRxData: amount of data to be sent and received Size: 2 DocID027328 Rev 1166 485 /

486 HAL UM1850 SPI Generic Driver Timeout duration Timeout: Return values HAL: status HAL_SPI_Transmit_IT HAL_StatusTypeDef HAL_SPI_Transmit_IT Function name (SPI_HandleTypeDef * hspi, uint8_t * pData, uint16_t Size) - Transmit an amount of data in non blocking mode with Interrupt. Function description Parameters hspi: pointer to a SPI_HandleTypeDef structure that contains the configuration information for SPI module. pData: pointer to data buffer e: amount of data to be sent Siz Return values HAL: status HAL_SPI_Receive_IT HAL_StatusTypeDef HAL_SPI_Receive_IT Function name (SPI_HandleTypeDef * hspi, uint8_t * pData, uint16_t Size) - blocking mode with Interrupt. Receive an amount of data in non Function description Parameters hspi: pointer to a SPI_HandleTypeDef structure that contains the configuration information for SPI module. pData: pointer to data buffer amount of data to be sent Size: Return values HAL: status HAL_SPI_TransmitReceive_IT HAL_StatusTypeDef HAL_SPI_TransmitReceive_IT Function name (SPI_HandleTypeDef * hspi, uint8_t * pTxData, uint8_t * pRxData, uint16_t Size) Function description Transmit and Receive an amount of data in non - b locking mode with Interrupt. Parameters pointer to a SPI_HandleTypeDef structure that contains hspi: the configuration information for SPI module. pointer to transmission data buffer pTxData: pRxData: pointer to reception data buffer Size: amount of data to be sent and received Return values status HAL: HAL_SPI_Transmit_DMA HAL_StatusTypeDef HAL_SPI_Transmit_DMA Function name (SPI_HandleTypeDef * hspi, uint8_t * pData, uint16_t Size) n - blocking mode with DMA. Function description Transmit an amount of data in no Parameters pointer to a SPI_HandleTypeDef structure that contains hspi: the configuration information for SPI module. pointer to data buffer pData: DocID027328 / 1166 486 Rev 2

487 UM1850 SPI Generic Driver HAL amount of data to be sent Size: Return values HAL: status HAL_SPI_Receive_DMA HAL_StatusTypeDef HAL_SPI_Receive_DMA Function name (SPI_HandleTypeDef * hspi, uint8_t * pData, uint16_t Size) blocking mode with DMA. - Receive an amount of data in non Function description Parameters hspi: pointer to a SPI_HandleTyp eDef structure that contains the configuration information for SPI module. pData: pointer to data buffer amount of data to be sent Size: Return values HAL: status Notes When the CRC feature is enabled the pData Length must be Size + 1. itReceive_DMA HAL_SPI_Transm HAL_StatusTypeDef HAL_SPI_TransmitReceive_DMA Function name (SPI_HandleTypeDef * hspi, uint8_t * pTxData, uint8_t * pRxData, uint16_t Size) Function description Transmit and Receive an amount of data in non - blocking mode with DMA. Parameters hspi: pointer to a SPI_HandleTypeDef structure that contains the configuration information for SPI module. pTxData: pointer to transmission data buffer pRxData: pointer to reception data buffer Size: amount of data to be sent Return values status HAL: Notes When the CRC feature is enabled the pRxData Length must be Size + 1 HAL_SPI_DMAPause HAL_StatusTypeDef HAL_SPI_DMAPause Function name (SPI_HandleTypeDef * hspi) Function description Pause the DMA Transfer. Parameters hspi: pointer to a SPI_HandleTypeDef structure that contains the configuration information for the specified SPI module. Return values status HAL: HAL_SPI_DMAResume HAL_StatusTypeDef HAL_SPI_DMAResume Function name (SPI_HandleTypeDef * hspi) Resume the DMA Transfer. ption Function descri 2 DocID027328 Rev 1166 487 /

488 HAL UM1850 SPI Gene ric Driver Parameters hspi: pointer to a SPI_HandleTypeDef structure that contains the configuration information for the specified SPI module. Return values status HAL: HAL_SPI_DMAStop HAL_StatusTypeDef HAL_SPI_DMAStop (SPI_HandleTypeDef Function name * hspi) Function description Stop the DMA Transfer. Parameters pointer to a SPI_HandleTypeDef structure that contains hspi: the configuration information for the specified SPI module. Return values status HAL: HAL_ SPI_Abort HAL_StatusTypeDef HAL_SPI_Abort (SPI_HandleTypeDef * Function name hspi) Abort ongoing transfer (blocking mode). Function description Parameters hspi: SPI handle. Return values status HAL: Notes This procedure could be used for aborting any ongoing transfer (Tx and Rx), started in Interrupt or DMA mode. This procedure performs following operations : Disable SPI Interrupts (depending of transfer direction)Disable the DMA transfer in the peripheral register (if enabled)Abort DMA transfer by calling HAL_DMA_Abort (in case of transfer in DMA mode)Set handle State to READY This procedure is executed in blocking mode : when exiting function, Abort is considered as completed. e Once transfer is aborted, th __HAL_SPI_CLEAR_OVRFLAG() macro must be called in user application before starting new SPI receive process. HAL_SPI_Abort_IT HAL_StatusTypeDef HAL_SPI_Abort_IT (SPI_HandleTypeDef * Function name hspi) Abort ongoing transfer (Interrupt mode). Function description Parameters hspi: SPI handle. Return values status HAL: Notes This procedure could be used for aborting any ongoing transfer (Tx and Rx), started in Interrupt or DMA mode. This procedure performs following oper ations : Disable SPI Interrupts (depending of transfer direction)Disable the DMA transfer in the peripheral register (if enabled)Abort DMA transfer by calling HAL_DMA_Abort_IT (in case of transfer in DMA mode)Set handle State to READYAt abort completion, all user abort complete callback c DocID027328 / 1166 488 Rev 2

489 HAL UM1850 SPI Generic Driver This procedure is executed in Interrupt mode, meaning that abort procedure could be considered as completed only when user abort complete callback is executed (not when exiting function). Once transfer is aborted, the L_SPI_CLEAR_OVRFLAG() macro must be called in __HA user application before starting new SPI receive process. HAL_SPI_IRQHandler void HAL_SPI_IRQHandler (SPI_HandleTypeDef * hspi) Function name Function description Handle SPI interrupt request. Parameters pointer to a SPI_HandleTypeDef structure that contains hspi: the configuration information for the specified SPI module. Return values None: HAL_SPI_TxCpltCallback void HAL_SPI_TxCpltCallback (SPI_HandleTypeDef * hspi) Function name on Function descripti Tx Transfer completed callback. Parameters pointer to a SPI_HandleTypeDef structure that contains hspi: the configuration information for SPI module. Return values None: HAL_SPI_RxCpltCallback void HAL_SPI_RxCpltCallback (SPI_HandleTypeDef * hspi) Function name Function description Rx Transfer completed callback. Parameters hspi: pointer to a SPI_HandleTypeDef structure that contains the configuration information for SPI module. Return values None: HAL_SPI_TxRxCpltCallback void HAL_SPI_TxRxCpltCallback (SPI_HandleTypeDef * hspi) Functi on name Function description Tx and Rx Transfer completed callback. Parameters hspi: pointer to a SPI_HandleTypeDef structure that contains the configuration information for SPI module. values Return None: HAL_SPI_TxHalfCpltCallback void HAL_SPI_TxHalfCpltCallback (SPI_HandleTypeDef * hspi) Function name Tx Half Transfer completed callback. Function description Parameters hspi: pointer to a SPI_HandleTypeDef structure that contains figuration information for SPI module. the con 2 DocID027328 Rev 1166 489 /

490 HAL SPI Generic Driver UM1850 Return values None: HAL_SPI_RxHalfCpltCallback void HAL_SPI_RxHalfCpltCallback (SPI_HandleTypeDef * Function name hspi) Rx Half Transfer completed callback. Function description Parameters hspi: pointer to a SPI_HandleTypeDef structure that contains the configuration information for SPI module. Return values None: HAL_SPI_TxRxHalfCpltCallback void HAL_SPI_TxRxHalfCpltCallback (SPI_HandleTypeDef * Function name hspi) d Rx Half Transfer callback. Function description Tx an Parameters pointer to a SPI_HandleTypeDef structure that contains hspi: the configuration information for SPI module. Return values None: HAL_SPI_ErrorCallback void HAL_SPI_ErrorCallback (SPI_HandleTypeDef * hspi) Function name Function description SPI error callback. Parameters hspi: pointer to a SPI_HandleTypeDef structure that contains the configuration information for SPI module. Return values None: HAL_SPI_AbortCpltCallback allback (SPI_HandleTypeDef * hspi) void HAL_SPI_AbortCpltC Function name SPI Abort Complete callback. Function description Parameters hspi: SPI handle. Return values None: HAL_SPI_GetState HAL_SPI_StateTypeDef HAL_SPI_GetState Function name (SPI_HandleTypeDef * hspi) Return the SPI handle state. Function description Parameters hspi: pointer to a SPI_HandleTypeDef structure that contains the configuration information for SPI module. Return values SPI: state DocID027328 / 1166 490 Rev 2

491 UM1850 HAL SPI Generic Driver HAL_SPI_GetError (SPI_HandleTypeDef * hspi) uint32_t HAL_SPI_GetError Function name Function description Return the SPI error code. Parameters hspi: pointer to a SPI_HandleTypeDef structure that contains the configuration information for SPI module. Return values error code in bitmap format SPI: SPI_ISCRC ErrorValid uint8_t SPI_ISCRCErrorValid (SPI_HandleTypeDef * hspi) Function name Checks if encountered CRC error could be corresponding to Function description wrongly detected errors according to SPI instance, Device type, and revision ID. Parameters pointer to a SPI_HandleTypeDef structure that contains hspi: the configuration information for SPI module. Return values CRC: error validity (SPI_INVALID_CRC_ERROR or SPI_VALID_CRC_ERROR). 39.3 SPI Firmware driver defines 39.3.1 SPI SPI BaudRate Prescaler SPI_BAUDRATEPRESCALER_2 SPI_BAUDRATEPRESCALER_4 SPI_BAUDRATEPRESCALER_8 SPI_BAUDRATEPRESCALER_16 SPI_BAUDRATEPRESCALER_32 SPI_BAUDRATEPRESCALER_64 SPI_BAUDRATEPRESCALER_128 SPI_BAUDRATEPRESCALER_256 SPI Clock Phase SPI_PHASE_1EDGE SPI_PHASE_2EDGE SPI Clock Polarity SPI_POLARITY_LOW SPI_POLARITY_HIGH SPI CRC Calculation SPI_CRCCALCULATION_DISABLE SPI_CRCCALCULATION_ENABLE SPI Data Size 2 DocID027328 Rev 1166 491 /

492 HAL SPI Generic Driver UM1850 SPI_DATASIZE_8BIT SPI_DATASIZE_16BIT SPI Direction Mode SPI_DIRECTION_2LINES SPI_DIRECTION_2LINES_RXONLY SPI_DIRECTION_1LINE SPI Error Code HAL_SPI_ERROR_NONE No error MODF error HAL_SPI_ERROR_MODF CRC error HAL_SPI_ERROR_CRC OVR error HAL_SPI_ERROR_OVR FRE error HAL_SPI_ERROR_FRE DMA transfer error HAL_SPI_ERROR_DMA HAL_SPI_ERROR_FLAG Flag: RXNE,TXE, BSY SPI Exported Macros Description: __HAL_SPI_RESET_HANDLE_STATE Reset SPI handle state. Parameters: __HANDLE__: specifies the SPI Handle. This param eter can be SPI where x: 1, 2, or 3 to select the SPI peripheral. Return value: None Description: __HAL_SPI_ENABLE_IT Enable the specified SPI interrupts. Parameters: __HANDLE__: specifies the SPI handle. This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral. __INTERRUPT__: specifies the interrupt source to enable. This parameter can be one of the following values: SPI_IT_TXE: Tx buffer empty interrupt enable SPI_IT_RXNE: RX buffer not empty interrupt enable SPI_IT_ERR: Error interrupt enable Return value: None Description: __HAL_SPI_DISABLE_IT 492 DocID027328 / Rev 2 1166

493 UM1850 SPI Generic Driver HAL Disable the specified SPI interrupts. Parameters: __HANDLE__: specifies the SPI handle. This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral. __INTERRUPT__: specifies the interrupt source to disable. This parameter can be one of the following values: SPI_IT_TXE: Tx buffer empty interrupt enable SPI_IT_RXNE: RX buffer not empty interrupt enable SPI_IT_ERR: Error interrupt enable Return value: No ne Description: __HAL_SPI_GET_IT_SOURCE Check whether the specified SPI interrupt source is enabled or not. Parameters: __HANDLE__: specifies the SPI Handle. This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral. ies the SPI __INTERRUPT__: specif interrupt source to check. This parameter can be one of the following values: SPI_IT_TXE: Tx buffer empty interrupt enable SPI_IT_RXNE: RX buffer not empty interrupt enable SPI_IT_ERR: Error interrupt enable Return value: The: new state of __I T__ (TRUE or FALSE). Description: __HAL_SPI_GET_FLAG Check whether the specified SPI flag is set or not. Parameters: __HANDLE__: specifies the SPI Handle. This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral. __FLAG__: specifies the flag to check. This parameter can be one of the following values: SPI_FLAG_RXNE: Receive buffer not empty flag SPI_FLAG_TXE: Transmit buffer empty flag SPI_FLAG_CRCERR: CRC error flag 2 DocID027328 Rev 1166 493 /

494 HAL UM1850 SPI Generic Driver SPI_FLAG_MODF: Mode fault flag errun flag SPI_FLAG_OVR: Ov SPI_FLAG_BSY: Busy flag Return value: The: new state of __FLAG__ (TRUE or FALSE). Description: __HAL_SPI_CLEAR_CRCERRFLAG Clear the SPI CRCERR pending flag. Parameters: __HANDLE__: specifies the SPI Handle. 2, or This parameter can be SPI where x: 1, 3 to select the SPI peripheral. Return value: None Description: __HAL_SPI_CLEAR_MODFFLAG Clear the SPI MODF pending flag. Parameters: __HANDLE__: specifies the SPI Handle. This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral. Return value: None Description: __HAL_SPI_CLEAR_OVRFLAG Clear the SPI OVR pending flag. Parameters: __HANDLE__: specifies the SPI Handle. This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral. Return value: None Description: __HAL_SPI_ENABLE Enable the SPI peripheral. Parameters: __HANDLE__: specifies the SPI Handle. This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral. Return value: None Description: __HAL_SPI_DISABLE 494 DocID027328 / Rev 2 1166

495 UM1850 SPI Generic Driv er HAL Disable the SPI peripheral. Parameters: __HANDLE__: specifies the SPI Handle. This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral. Return value: None SPI Flags Definition SPI_FLAG_RXNE SPI_FLAG_TXE SPI_FLAG_BSY SPI_FLAG_CRCERR SPI_FLAG_MODF SPI_FLAG_OVR SPI Interrupt Definition SPI_IT_TXE SPI_IT_RXNE SPI_IT_ERR SPI Mode SPI_MODE_SLAVE SPI_MODE_MASTER SPI MSB LSB Transmission SPI_FIRSTBIT_MSB SPI_FIRSTBIT_LSB SPI Slave Select Management SPI_NSS_SOFT SPI_NSS_HARD_INPUT SPI_NSS_HARD_OUTPUT SPI TI Mode SPI_TIMODE_DISABLE 2 DocID027328 Rev 1166 495 /

496 SRAM Generic Driver HAL UM1850 HAL SRAM Generic Driver 40 SRAM Firmware driver registers structures 40.1 40.1.1 SRAM_HandleTypeDef Data Fields FSMC_NORSRAM_TypeDef * Instance FSMC_NORSRAM_EXTENDED_TypeDef * Extended FSMC_NORSRAM_InitTypeDef Init HAL_LockTypeDef Lock __IO HAL_SRAM_StateTypeDef State DMA_HandleTypeDef * hdma Field Documentation FSMC_NORSRAM_TypeDef* SRAM_HandleTypeDef::Instance ister base address Reg FSMC_NORSRAM_EXTENDED_TypeDef* SRAM_HandleTypeDef::Extended Extended mode register base address FSMC_NORSRAM_InitTypeDef SRAM_HandleTypeDef::Init SRAM device control configuration parameters HAL_LockTypeDef SRAM_HandleTypeDef::Lock AM locking object SR __IO HAL_SRAM_StateTypeDef SRAM_HandleTypeDef::State SRAM device access state DMA_HandleTypeDef* SRAM_HandleTypeDef::hdma Pointer DMA handler 40.2 SRAM Firmware driver API description 40.2.1 driver How to use this This driver is a generic layered driver which contains a set of APIs used to control SRAM memories. It uses the FSMC layer functions to interface with SRAM devices. The following wed to configure the FSMC to interface with SRAM/PSRAM sequence should be follo memories: 1. Declare a SRAM_HandleTypeDef handle structure, for example: SRAM_HandleTypeDef hsram; and: Fill the SRAM_HandleTypeDef handle "Init" field with the allowed values of the structure member. Fill the SRAM_HandleTypeDef handle "Instance" field with a predefined base register instance for NOR or SRAM device Fill the SRAM_HandleTypeDef handle "Extended" field with a predefined base register instance for NOR or SRAM extended mode Declare two FSM 2. C_NORSRAM_TimingTypeDef structures, for both normal and extended mode timings; for example: FSMC_NORSRAM_TimingTypeDef Timing and FSMC_NORSRAM_TimingTypeDef ExTiming; and fill its fields with the allowed values of the structure member. 3. Controller by calling the function HAL_SRAM_Init(). This function Initialize the SRAM performs the following sequence: MSP hardware layer configuration using the function HAL_SRAM_MspInit() a. DocID027328 / 1166 496 Rev 2

497 UM1850 SRAM Generic Driver HAL b. Control register configuration using the FSMC NORSRAM interface function FSMC_NORSRAM_Init() c. Timing register configuration using the FSMC NORSRAM interface function FSMC_NORSRAM_Timing_Init() d. Extended mode Timing register configuration using the FSMC NORSRAM interface function FSMC_NORSRAM_Extended_Timing_Init() Enable the SRAM e. device using the macro __FSMC_NORSRAM_ENABLE() 4. At this stage you can perform read/write accesses from/to the memory connected to the NOR/SRAM Bank. You can perform either polling or DMA transfer using the following APIs: HAL_SRAM_Read()/HAL_SRAM_Write() for polling read/write access HAL_SRAM_Read_DMA()/HAL_SRAM_Write_DMA() for DMA read/write transfer 5. You can also control the SRAM device by calling the control APIs HAL_SRAM_WriteOperation_Enable()/ HAL_SRAM_WriteOperation_Disable() to respectively enable /disable the SRAM write operation 6. You can continuously monitor the SRAM device HAL state by calling the function HAL_SRAM_GetState() SRAM Initialization and de_initialization functions 40.2.2 initialize the SRAM memory - This section provides functions allowing to initialize/de This section contains the following APIs: HAL_SRAM_Init() HAL_SRAM_DeInit() HAL_SRAM_MspInit() HAL_SRAM_MspDeInit() HAL_SRAM_DMA_XferCpltCallback() HAL_SRAM_DMA_XferErrorCallback() 40.2.3 functions SRAM Input and Output This section provides functions allowing to use and control the SRAM memory This section contains the following APIs: HAL_SRAM_Read_8b() HAL_SRAM_Write_8b() HAL_SRAM_Read_16b() HAL_SRAM_Write_16b() HAL_SRAM_Read_32b() HAL_SRAM_Write_32b() HAL_SRAM_Read_DMA() HAL_SRAM_Write_DMA() SRAM Control functions 40.2.4 SRAM This subsection provides a set of functions allowing to control dynamically the interface. This section contains the following APIs: HAL_SRAM_WriteOperation_Enable() HAL_SRAM_WriteOperation_Disable() 2 DocID027328 Rev 1166 497 /

498 UM1850 HAL SRAM Generic Driver 40.2.5 SRAM State functions This subsection permits to get in run time the status of the SRAM controller and the data - flow. This section contains the following APIs: HAL_SRAM_GetState() 40.2.6 Detailed description of functions HAL_SRAM_Init HAL_StatusTypeDef HAL_SRAM_Init (SRAM_HandleTypeDef * Function name hsram, FSMC_NORSRAM_TimingTypeDef * Timing, FSMC_NORSRAM_TimingTypeDef * ExtTiming) itialization sequence. Function description Performs the SRAM device in Parameters pointer to a SRAM_HandleTypeDef structure that hsram: contains the configuration information for SRAM module. Pointer to SRAM control timing structure Timing: Pointer to SRAM extended mode timing structure ExtTiming: Return values status HAL: HAL_SRAM_DeInit HAL_StatusTypeDef HAL_SRAM_DeInit Function name (SRAM_HandleTypeDef * hsram) initialization sequence. Function description Performs the SRAM device De - Parameters hsram: pointer to a SRAM_HandleTypeDef structure that contains the configuration information for SRAM module. Return values status HAL: HAL_SRAM_MspInit void HAL_SRAM_MspInit (SRAM_HandleTypeDef * hsram) Function name Function description SRAM MSP Init. rameters Pa pointer to a SRAM_HandleTypeDef structure that hsram: contains the configuration information for SRAM module. Return values None: HAL_SRAM_MspDeInit void HAL_SRAM_MspDeInit (SRAM_HandleTypeDef * hsram) Function name Function description SRAM MSP DeInit. Parameters pointer to a SRAM_HandleTypeDef structure that hsram: contains the configuration information for SRAM module. Return values None: DocID027328 / 1166 498 Rev 2

499 UM1850 SRAM Generic Driver HAL HAL_SRAM_DMA_XferCpltCallback void HAL_SRAM_DMA_XferCpltCallback Function name (DMA_HandleTy peDef * hdma) Function description DMA transfer complete callback. Parameters hdma: pointer to a SRAM_HandleTypeDef structure that contains the configuration information for SRAM module. Return values None: HAL_SRAM_DMA_XferErrorCallback void HAL_SRAM_DMA_XferErrorCallback Function name (DMA_HandleTypeDef * hdma) Function description DMA transfer complete error callback. Parameters hdma: pointer to a SRAM_HandleTypeDef structure that contains the configuration information for SRAM module. rn values Retu None: HAL_SRAM_Read_8b HAL_StatusTypeDef HAL_SRAM_Read_8b Function name (SRAM_HandleTypeDef * hsram, uint32_t * pAddress, uint8_t * pDstBuffer, uint32_t BufferSize) Function description bit buffer from SRAM memory. - Reads 8 Parameters pointer to a SRAM_HandleTypeDef structure that hsram: contains the configuration information for SRAM module. Pointer to read start address pAddress: pDstBuffer: Pointer to destination buffer Size of the buffer to read from memory BufferSize: Return values H AL: status HAL_SRAM_Write_8b HAL_StatusTypeDef HAL_SRAM_Write_8b Function name (SRAM_HandleTypeDef * hsram, uint32_t * pAddress, uint8_t * pSrcBuffer, uint32_t BufferSize) Writes 8 - Function description bit buffer to SRAM memory. Parameters pointer to a SRAM_HandleTypeDef structure that hsram: contains the configuration information for SRAM module. Pointer to write start address pAddress: Pointer to source buffer to write pSrcBuffer: Size of the buffer to write to memory BufferSize: es Return valu status HAL: HAL_SRAM_Read_16b HAL_StatusTypeDef HAL_SRAM_Read_16b Function name (SRAM_HandleTypeDef * hsram, uint32_t * pAddress, uint16_t 2 DocID027328 Rev 1166 499 /

500 HAL UM1850 SRAM Generic Driver * pDstBuffer, uint32_t BufferSize) Function description Reads 16 - bit buffer from SRAM memory. Parameters pointer to a SRAM_HandleTypeDef structure that hsram: contains the configuration information for SRAM module. pAddress: Pointer to read start address pDstBuffer: Pointer to destination buffer Size of the buffer to read from memory BufferSize: Return v alues HAL: status HAL_SRAM_Write_16b HAL_StatusTypeDef HAL_SRAM_Write_16b Function name (SRAM_HandleTypeDef * hsram, uint32_t * pAddress, uint16_t * pSrcBuffer, uint32_t BufferSize) Writes 16 Function description bit buffer to SRAM memory. - Parameters pointer to a SRAM_HandleTypeDef structure that hsram: contains the configuration information for SRAM module. pAddress: Pointer to write start address Pointer to source buffer to write pSrcBuffer: Size of the buffer to write to memory BufferSize: Return values HAL: status HAL_SRAM_Read_32b HAL_StatusTypeDef HAL_SRAM_Read_32b Function name (SRAM_HandleTypeDef * hsram, uint32_t * pAddress, uint32_t * pDstBuffer, uint32_t BufferSize) Function description Reads 32 - bit buffer from SRAM memory. meters Para pointer to a SRAM_HandleTypeDef structure that hsram: contains the configuration information for SRAM module. pAddress: Pointer to read start address pDstBuffer: Pointer to destination buffer Size of the buffer to read from memory BufferSize: eturn values R status HAL: HAL_SRAM_Write_32b HAL_StatusTypeDef HAL_SRAM_Write_32b Function name (SRAM_HandleTypeDef * hsram, uint32_t * pAddress, uint32_t * pSrcBuffer, uint32_t BufferSize) bit buffer to SRAM memory. - Function description Writes 32 Parameters hsram: pointer to a SRAM_HandleTypeDef structure that contains the configuration information for SRAM module. pAddress: Pointer to write start address pSrcBuffer: Pointer to source buffer to write emory Size of the buffer to write to m BufferSize: Return values status HAL: DocID027328 / 1166 500 Rev 2

501 UM1850 SRAM Generic Driver HAL HAL_SRAM_Read_DMA HAL_StatusTypeDef HAL_SRAM_Read_DMA Function name (SRAM_HandleTypeDef * hsram, uint32_t * pAddress, uint32_t * pDstBuffer, uint32_t BufferSize) Function description Reads a Words data from the SRAM memory using DMA transfer. Parameters hsram: pointer to a SRAM_HandleTypeDef structure that contains the configuration information for SRAM module. Pointer to read start address pAddress: Pointer to destina tion buffer pDstBuffer: BufferSize: Size of the buffer to read from memory Return values status HAL: HAL_SRAM_Write_DMA HAL_StatusTypeDef HAL_SRAM_Write_DMA Function name (SRAM_HandleTypeDef * hsram, uint32_t * pAddress, uint32_t * pSrcBuffer, uint32_t BufferSize) Writes a Words data buffer to SRAM memory using DMA transfer. Function description Parameters hsram: pointer to a SRAM_HandleTypeDef structure that contains the configuration information for SRAM module. pAddress: Pointer to write start address Pointer to source buffer to write pSrcBuffer: BufferSize: Size of the buffer to write to memory Return values HAL: status HAL_SRAM_WriteOperation_Enable HAL_StatusTypeDef HAL_SRAM_WriteOperation_Enable Function name (SRAM_HandleTypeDef * hsram) Funct Enables dynamically SRAM write operation. ion description Parameters hsram: pointer to a SRAM_HandleTypeDef structure that contains the configuration information for SRAM module. Return values status HAL: HAL_SRAM_WriteOperation_Disable HAL_StatusTypeDef HAL_SRAM_WriteOperation_Disable Function name (SRAM_HandleTypeDef * hsram) Function description Disables dynamically SRAM write operation. Parameters pointer to a SRAM_HandleTypeDef structure that hsram: SRAM module. contains the configuration information for Return values HAL: status HAL_SRAM_GetState HAL_SRAM_StateTypeDef HAL_SRAM_GetState Function name (SRAM_HandleTypeDef * hsram) 2 DocID027328 Rev 1166 501 /

502 HAL UM1850 c Driver SRAM Generi Returns the SRAM controller state. Function description Parameters hsram: pointer to a SRAM_HandleTypeDef structure that contains the configuration information for SRAM module. Return values state HAL: 40.3 SRAM Firmware driver defines 40.3.1 SRAM Exported Macros SRAM Description: __HAL_SRAM_RESET_HANDLE_STATE Reset SRAM handle state. Parameters: __HANDLE__: SRAM handle Return value: None DocID027328 / 1166 502 Rev 2

503 TIM Generic Driver UM1850 HAL 41 HAL TIM Generic Driver 41.1 TIM Firmware driver registers structures 41.1.1 TIM_Base_InitTypeDef Data Fields uint32_t Prescaler uint32_t CounterMode uint32_t Period uint32_t ClockDivision uint32_t RepetitionCounter uint32_t AutoReloadPreload Field Documentation uint32_t TIM_Base_InitTypeDef::Prescaler Specifies the prescaler value used to divide the TIM clock. This parameter can be a number between Min_Data = 0x0000 and Max_Data = 0xFFFF uint32_t TIM_Base_InitTypeDef::CounterMode Specifies the coun TIM_Counter_Mode ter mode. This parameter can be a value of uint32_t TIM_Base_InitTypeDef::Period Reload Register at the - Specifies the period value to be loaded into the active Auto next update event. This parameter can be a number between Min_Data = 0x0000 and Max_Data = 0xFFFF. uint32_t TIM_Base_InitTypeDef::ClockDivision Specifies the clock division. This parameter can be a value of TIM_ClockDivision uint32_t TIM_Base_InitTypeDef::RepetitionCounter Specifies the repetition counter value. Each time the RCR downcounter reaches zero, an update event is generated and counting restarts from the RCR value (N). This er of PWM periods in edge - means in PWM mode that (N+1) corresponds to:the numb aligned mode This parameter - aligned modethe number of half PWM period in center must be a number between Min_Data = 0x00 and Max_Data = 0xFF. Note: This parameter is valid only for TIM1 and TIM8. oReloadPreload uint32_t TIM_Base_InitTypeDef::Aut Specifies the auto - reload preload. This parameter can be a value of TIM_AutoReloadPreload TIM_OC_InitTypeDef 41.1.2 Data Fields uint32_t OCMode uint32_t Pulse OCPolarity uint32_t uint32_t OCNPolarity uint32_t OCFastMode uint32_t OCIdleState uint32_t OCNIdleState Field Documentation 2 DocID027328 Rev 1166 503 /

504 TIM Generic Driver HAL UM1850 uint32_t TIM_OC_InitTypeDef::OCMode Specifies the TIM mode. This parameter can be a value of TIM_Output_Comp are_and_PWM_modes uint32_t TIM_OC_InitTypeDef::Pulse Specifies the pulse value to be loaded into the Capture Compare Register. This parameter can be a number between Min_Data = 0x0000 and Max_Data = 0xFFFF uint32_t TIM_OC_InitTypeDef::OCPolarity the output polarity. This parameter can be a value of Specifies TIM_Output_Compare_Polarity uint32_t TIM_OC_InitTypeDef::OCNPolarity Specifies the complementary output polarity. This parameter can be a value of TIM_Output_Compare_N_Polarity This parameter is valid only for TIM1 and TIM8. Note: uint32_t TIM_OC_InitTypeDef::OCFastMode Specifies the Fast mode state. This parameter can be a value of TIM_Output_Fast_State No This parameter is valid only in PWM1 and PWM2 mode. te: uint32_t TIM_OC_InitTypeDef::OCIdleState Specifies the TIM Output Compare pin state during Idle state. This parameter can be a TIM_Output_Compare_Idle_State value of This parameter is valid only for TIM1 and TIM8. te: No uint32_t TIM_OC_InitTypeDef::OCNIdleState Specifies the TIM Output Compare pin state during Idle state. This parameter can be a TIM_Output_Compare_N_Idle_State value of Not e: This parameter is valid only for TIM1 and TIM8. 41.1.3 TIM_OnePulse_InitTypeDef Data Fields uint32_t OCMode uint32_t Pulse uint32_t OCPolarity uint32_t OCNPolarity uint32_t OCIdleState uint32_t OCNIdleState uint32_t ICPolarity uint32_t ICSelection uint32_t ICFilter Field Documentation uint32_t TIM_OnePulse_InitTypeDef::OCMode Specifies the TIM mode. This parameter can be a value of TIM_Output_Compare_and_PWM_modes _OnePulse_InitTypeDef::Pulse uint32_t TIM Specifies the pulse value to be loaded into the Capture Compare Register. This parameter can be a number between Min_Data = 0x0000 and Max_Data = 0xFFFF uint32_t TIM_OnePulse_InitTypeDef::OCPolarity ty. This parameter can be a value of Specifies the output polari TIM_Output_Compare_Polarity uint32_t TIM_OnePulse_InitTypeDef::OCNPolarity Specifies the complementary output polarity. This parameter can be a value of TIM_Output_Compare_N_Polarity This parameter is valid only for TIM1 and TIM8. Note: DocID027328 / 1166 504 Rev 2

505 TIM Generic Driver UM1850 HAL uint32_t TIM_OnePulse_InitTypeDef::OCIdleState Specifies the TIM Output Compare pin state during Idle state. This parameter can be a value of TIM_Output_Compare_Idle_State Note: This parameter is valid only for TIM1 and TIM8. uint32_t TIM_OnePulse_InitTypeDef::OCNIdleState Specifies the TIM Output Compare pin state during Idle state. This parameter can be a value of TIM_Output_Compare_N_Idle_State Note: This parameter is valid only for TIM1 and TIM8. uint32_t TIM_OnePulse_InitTypeDef::ICPolarity Specifies the active edge of the input signal. This parameter can be a value of TIM_Inp ut_Capture_Polarity uint32_t TIM_OnePulse_InitTypeDef::ICSelection Specifies the input. This parameter can be a value of TIM_Input_Capture_Selection uint32_t TIM_OnePulse_InitTypeDef::ICFilter Specifies the input capture fi lter. This parameter can be a number between Min_Data = 0x0 and Max_Data = 0xF 41.1.4 TIM_IC_InitTypeDef Data Fields uint32_t ICPolarity uint32_t ICSelection uint32_t ICPrescaler uint32_t ICFilter Field Documentation uint32_t TIM_IC_InitTypeDef::ICPolarity Specifies the active edge of the input signal. This parameter can be a value of TIM_Input_Capture_Polarity uint32_t TIM_IC_InitTypeDef::ICSelection can be a value of Specifies the input. This parameter TIM_Input_Capture_Selection uint32_t TIM_IC_InitTypeDef::ICPrescaler Specifies the Input Capture Prescaler. This parameter can be a value of TIM_Input_Capture_Prescaler nt32_t TIM_IC_InitTypeDef::ICFilter ui Specifies the input capture filter. This parameter can be a number between Min_Data = 0x0 and Max_Data = 0xF 41.1.5 TIM_Encoder_InitTypeDef Data Fields uint32_t EncoderMode uint32_t IC1Polarity uint32_t IC1Selection uint32_t IC1Prescaler uint32_t IC1Filter uint32_t IC2Polarity uint32_t IC2Selection uint32_t IC2Prescaler uint32_t IC2Filter Field Documentation 2 DocID027328 Rev 1166 505 /

506 HAL TIM Generic Driver UM1850 uint32_t TIM_Encoder_InitTypeDef::EncoderMode dge of the input signal. This parameter can be a value of Specifies the active e TIM_Encoder_Mode uint32_t TIM_Encoder_InitTypeDef::IC1Polarity Specifies the active edge of the input signal. This parameter can be a value of TIM_Input_Capture_Polarity uint32_t TIM_Encoder_InitTypeDef::IC1Selection Specifies the input. This parameter can be a value of TIM_Input_Capture_Selection uint32_t TIM_Encoder_InitTypeDef::IC1Prescaler Specifies the Input Capture Prescaler. This parameter can be a value of TIM_Input_Capture_Prescaler uint32_t TIM_Encoder_InitTypeDef::IC1Filter Specifies the input capture filter. This parameter can be a number between Min_Data 0 and Max_Data = 0xF = 0x uint32_t TIM_Encoder_InitTypeDef::IC2Polarity Specifies the active edge of the input signal. This parameter can be a value of TIM_Input_Capture_Polarity uint32_t TIM_Encoder_InitTypeDef::IC2Selection TIM_Input_Capture_Selection Specifies the input. This parameter can be a value of uint32_t TIM_Encoder_InitTypeDef::IC2Prescaler Specifies the Input Capture Prescaler. This parameter can be a value of TIM_Input_Capture_Prescaler uint32_t TIM_Encoder_InitTypeDef::IC2Filter Specifies the input capture filter. This parameter can be a number between Min_Data = 0x0 and Max_Data = 0xF 41.1.6 TIM_ClockConfigTypeDef Data Fields uint32_t ClockSource uint32_t ClockPolarity uint32_t ClockPrescaler uint32_t ClockFilter Field Documentation uint32_t TIM_ClockConfigTypeDef::ClockSource TIM clock sources This parameter can be a value of TIM_Clock_Source uint32_t TIM_ClockConfigTypeDef::ClockPolarity TIM clock polarity This parameter can be a value of TIM_Clock_Polarity uint32_t TIM_ClockConfigTypeDef::ClockPrescaler TIM clock prescaler This parameter can TIM_Clock_Prescaler be a value of uint32_t TIM_ClockConfigTypeDef::ClockFilter TIM clock filter This parameter can be a number between Min_Data = 0x0 and Max_Data = 0xF 41.1.7 TIM_ClearInputConfigTypeDef Data Fields uint32_t ClearInputState uint32_t ClearInputSource uint32_t ClearInputPolarity uint32_t ClearInputPrescaler uint32_t ClearInputFilter DocID027328 / 1166 506 Rev 2

507 UM1850 HAL TIM Generic Driver Field Documentation uint32_t TIM_ClearInputConfigTypeDef::ClearInputState Input state This parameter can be ENABLE or DISABLE TIM clear uint32_t TIM_ClearInputConfigTypeDef::ClearInputSource TIM clear Input sources This parameter can be a value of TIM_ClearInput_Source TIM_ClearInputConfigTypeDef::ClearInputPolarity uint32_t TIM Clear Input polarity This parameter can be a value of TIM_ClearInput_Polarity uint32_t TIM_ClearInputConfigTypeDef::ClearInputPrescaler TIM Clear Input prescaler This para meter can be a value of TIM_ClearInput_Prescaler uint32_t TIM_ClearInputConfigTypeDef::ClearInputFilter TIM Clear Input filter This parameter can be a number between Min_Data = 0x0 and Max_Data = 0xF 41.1.8 TIM_SlaveConfigTypeDef Data Fields uint32_t SlaveMode uint32_t InputTrigger uint32_t TriggerPolarity uint32_t TriggerPrescaler uint32_t TriggerFilter Field Documentation uint32_t TIM_SlaveConfigTypeDef::SlaveMode Slave mode selecti on This parameter can be a value of TIM_Slave_Mode uint32_t TIM_SlaveConfigTypeDef::InputTrigger Input Trigger source This parameter can be a value of TIM_Trigger_Selection uint32_t TIM_SlaveConfigTypeDef::TriggerPolarity Input Trigger polarity This parameter can be a value of TIM_Trigger_Polarity uint32_t TIM_SlaveConfigTypeDef::TriggerPrescaler Input trigger prescaler This parameter can be a value of TIM_Trigger_Prescaler uint32_t TIM_SlaveConfigTypeDef::TriggerFilter Input trigger filter This parameter can be a number between Min_Data = 0x0 and Max_Data = 0xF 41.1.9 TIM_HandleTypeDef Data Fields TIM_TypeDef * Instance TIM_Base_InitTypeDef Init HAL_TIM_ActiveChannel Channel DMA_HandleTypeDef * hdma HAL_LockTypeDef Lock __IO HAL_TIM_StateTypeDef State Field Documentation TIM_TypeDef* TIM_HandleTypeDef::Instance Register base address TIM_Base_InitTypeDef TIM_HandleTypeDef::Init TIM Time Base required parameters HAL_TIM_ActiveChannel TIM_HandleTypeDef::Channel Active channel 2 DocID027328 Rev 1166 507 /

508 HAL UM1850 TIM Generic Driver DMA_HandleTypeDef* TIM_HandleTypeDef::hdma[7U] TIM_DMA_Handle_index DMA Handlers array This array is accessed by a HAL_LockTypeDef TIM_HandleTypeDef::Lock Locking object __IO HAL_TIM_StateTypeDef TIM_HandleTypeDef::State TIM operation state TIM Firmware driver API description 41.2 atures TIMER Generic fe 41.2.1 The Timer features include: 16 1. - bit up, down, up/down auto - reload counter. - 16 bit programmable prescaler allowing dividing (also on the fly) the counter clock 2. 65536. frequency either by any factor between 1 and 3. Up to 4 independent channels for: Input Capture Output Compare aligned Mode) - PWM generation (Edge and Center - pulse mode output One How to use this driver 41.2.2 enting the following functions Initialize the TIM low level resources by implem 1. depending from feature used : Time Base : HAL_TIM_Base_MspInit() Input Capture : HAL_TIM_IC_MspInit() Output Compare : HAL_TIM_OC_MspInit() PWM generation : HAL_TIM_PWM_MspInit() One - pulse mode output : HAL_TIM_OnePulse_MspI nit() Encoder mode output : HAL_TIM_Encoder_MspInit() 2. Initialize the TIM low level resources : a. Enable the TIM interface clock using __HAL_RCC_TIMx_CLK_ENABLE(); b. TIM pins configuration Enable the clock for the TIM GPIOs using the following function: __HA L_RCC_GPIOx_CLK_ENABLE(); Configure these TIM pins in Alternate function mode using HAL_GPIO_Init(); 3. The external Clock can be configured, if needed (the default clock is the internal clock from the APBx), using the following function: HAL_TIM_ConfigClock Source, the clock configuration should be done before any start function. 4. Configure the TIM in the desired functioning mode using one of the Initialization function of this driver: HAL_TIM_Base_Init: to use the Timer to generate a simple time base M_OC_Init and HAL_TIM_OC_ConfigChannel: to use the Timer to HAL_TI generate an Output Compare signal. HAL_TIM_PWM_Init and HAL_TIM_PWM_ConfigChannel: to use the Timer to generate a PWM signal. measure HAL_TIM_IC_Init and HAL_TIM_IC_ConfigChannel: to use the Timer to an external signal. HAL_TIM_OnePulse_Init and HAL_TIM_OnePulse_ConfigChannel: to use the Timer in One Pulse Mode. HAL_TIM_Encoder_Init: to use the Timer Encoder Interface. 5. Activate the TIM peripheral using one of the start functions depending from the feature used: DocID027328 / 1166 508 Rev 2

509 UM1850 TIM Generic Driver HAL Time Base : HAL_TIM_Base_Start(), HAL_TIM_Base_Start_DMA(), HAL_TIM_Base_Start_IT() Input Capture : HAL_TIM_IC_Start(), HAL_TIM_IC_Start_DMA(), HAL_TIM_IC_Start_ IT() Output Compare : HAL_TIM_OC_Start(), HAL_TIM_OC_Start_DMA(), HAL_TIM_OC_Start_IT() PWM generation : HAL_TIM_PWM_Start(), HAL_TIM_PWM_Start_DMA(), HAL_TIM_PWM_Start_IT() - One pulse mode output : HAL_TIM_OnePulse_Start(), HAL_TIM_OnePulse_Start_IT() der mode output : HAL_TIM_Encoder_Start(), Enco HAL_TIM_Encoder_Start_DMA(), HAL_TIM_Encoder_Start_IT(). The DMA Burst is managed with the two following functions: 6. HAL_TIM_DMABurst_WriteStart() HAL_TIM_DMABurst_ReadStart() 41.2.3 Time Base functions This section provides functions allowing to: Initialize and configure the TIM base. - initialize the TIM base. De Start the Time Base. Stop the Time Base. Start the Time Base and enable interrupt. nterrupt. Stop the Time Base and disable i Start the Time Base and enable DMA transfer. Stop the Time Base and disable DMA transfer. This section contains the following APIs: HAL_TIM_Base_Init() HAL_TIM_Base_DeInit() HAL_TIM_Base_MspInit() HAL_TIM_Base_MspDeInit() HAL_TIM_Base_Start() HAL_TIM_Base_Stop() TIM_Base_Start_IT() HAL_ HAL_TIM_Base_Stop_IT() HAL_TIM_Base_Start_DMA() HAL_TIM_Base_Stop_DMA() 41.2.4 Time Output Compare functions This section provides functions allowing to: Initialize and configure the TIM Output Compare. initialize the TIM Output Compare. De - Start the Time Output Compare. Stop the Time Output Compare. Time Output Compare and enable interrupt. Start the Stop the Time Output Compare and disable interrupt. Start the Time Output Compare and enable DMA transfer. Stop the Time Output Compare and disable DMA transfer. This section contains the following APIs: HAL_TIM_OC_Init() 2 DocID027328 Rev 1166 509 /

510 HAL UM1850 TIM Generic Driver HAL_TIM_OC_DeInit() HAL_TIM_OC_MspInit() HAL_TIM_OC_MspDeInit() ) HAL_TIM_OC_Start( HAL_TIM_OC_Stop() HAL_TIM_OC_Start_IT() HAL_TIM_OC_Stop_IT() HAL_TIM_OC_Start_DMA() HAL_TIM_OC_Stop_DMA() 41.2.5 Time PWM functions This section provides functions allowing to: Initialize and configure the TIM PWM. initialize the TIM PWM. De - Start the Time PWM. Stop the Time PWM. Start the Time PWM and enable interrupt. Stop the Time PWM and disable interrupt. Start the Time PWM and enable DMA transfer. Stop the Time PWM and disable DMA transfer. This section contains the following APIs: HAL_TIM_PWM_Init() HAL_TIM_PWM_DeInit() HAL_TIM_PWM_MspInit() HAL_TIM_PWM_MspDeInit() HAL_TIM_PWM_Start() HAL_TI M_PWM_Stop() HAL_TIM_PWM_Start_IT() HAL_TIM_PWM_Stop_IT() HAL_TIM_PWM_Start_DMA() HAL_TIM_PWM_Stop_DMA() 41.2.6 Time Input Capture functions This section provides functions allowing to: Initialize and configure the TIM Input Capture. - initialize the TIM Input Capture. De Start the Time Input Capture. Stop the Time Input Capture. Start the Time Input Capture and enable interrupt. Stop the Time Input Capture and disable interrupt. Start the Time Input Capture and enable DMA transfer. Stop the Time Input Capture and disable DMA transfer. This section contains the following APIs: HAL_TIM_IC_Init() HAL_TIM_IC_DeInit() HAL_TIM_IC_MspInit() HAL_TIM_IC_MspDeInit() HAL_TIM_IC_Start() HAL_TIM_IC_Stop() DocID027328 / 1166 510 Rev 2

511 UM1850 HAL TIM Generic Driver HAL_TIM_IC_Start_IT() HAL_TIM_IC_Stop_IT() HAL_TIM_IC_Start_DMA() HAL_TIM_IC_Stop_DMA() 41.2.7 Time One Pulse functions This section provides functions allowing to: Initialize and configure the TIM One Pulse. initialize the TIM One Pulse. De - Start the Time One Pulse. Stop the Time One Pulse. Start the Time One Pulse and enable interrupt. Stop the Time One Pulse and disable interrupt. Start the Time One Pulse and enable DMA transfer. Stop the Time One Pulse and disable DMA transfer. APIs: This section contains the following HAL_TIM_OnePulse_Init() HAL_TIM_OnePulse_DeInit() HAL_TIM_OnePulse_MspInit() HAL_TIM_OnePulse_MspDeInit() HAL_TIM_OnePulse_Start() HAL_TIM_OnePulse_Stop() HAL_TIM_OnePulse_Start_IT() HAL_TIM_OnePulse_Stop_IT() 41.2.8 Time Encoder functions This section provides functions allowing to: Initialize and configure the TIM Encoder. initialize the TIM Encoder. De - Start the Time Encoder. Stop the Time Encoder. Start the Time Encoder and enable interrupt . Stop the Time Encoder and disable interrupt. Start the Time Encoder and enable DMA transfer. Stop the Time Encoder and disable DMA transfer. This section contains the following APIs: HAL_TIM_Encoder_Init() HAL_TIM_Encoder_DeInit() HAL_TIM_Encoder_MspInit() HAL_TIM_Encoder_MspDeInit() HAL_TIM_Encoder_Start() L_TIM_Encoder_Stop() HA HAL_TIM_Encoder_Start_IT() HAL_TIM_Encoder_Stop_IT() HAL_TIM_Encoder_Start_DMA() HAL_TIM_Encoder_Stop_DMA() 2 DocID027328 Rev 1166 511 /

512 HAL UM1850 TIM Generic Driver IRQ handler management 41.2.9 This section provides Timer IRQ handler function. This section contains the following APIs: HAL_TIM_IRQHandler() Control functions Peripheral 41.2.10 This section provides functions allowing to: Configure The Input Output channels for OC, PWM, IC or One Pulse mode. Configure External Clock source. reak features and dead time. Configure Complementary channels, b Configure Master and the Slave synchronization. Configure the DMA Burst Mode. This section contains the following APIs: HAL_TIM_OC_ConfigChannel() nfigChannel() HAL_TIM_IC_Co HAL_TIM_PWM_ConfigChannel() HAL_TIM_OnePulse_ConfigChannel() HAL_TIM_DMABurst_WriteStart() iteStop() HAL_TIM_DMABurst_Wr HAL_TIM_DMABurst_ReadStart() HAL_TIM_DMABurst_ReadStop() HAL_TIM_GenerateEvent() HAL_TIM_ConfigOCrefClear() HAL_TIM_ConfigClockSource() HAL_TIM_ConfigTI1Input() HAL_TIM_SlaveConfigSynchronization() HAL_TIM_SlaveConfigSynchronization_I T() HAL_TIM_ReadCapturedValue() TIM Callbacks functions 41.2.11 This section provides TIM callback functions: Timer Period elapsed callback Timer Output Compare callback Timer Input capture callback Timer Trigger callback Timer Error callback This section contains the following APIs: HAL_TIM_PeriodElapsedCallback() HAL_TIM_OC_DelayElapsedCallback() HAL_TIM_IC_CaptureCallback() HAL_TIM_PWM_PulseFinishedCallback() HAL_TIM_TriggerCallback() HAL_TIM_ErrorCallback() Peripheral State functions 41.2.12 time the status of the peripheral and the data flow. - This subsection permit to get in run DocID027328 / 1166 512 Rev 2

513 UM1850 TIM Generic Driver HAL This section contains the following APIs: HAL_TIM_Base_GetState() HAL_TIM_OC_GetState() HAL_TIM_PWM_GetState() HAL_TIM_IC_GetState() HAL_TIM_OnePulse_GetState() HAL_TIM_Encoder_GetState() Detailed description of functions 41.2.13 TIM_Base_SetConfig void TIM_Base_SetConfig (TIM_TypeDef * TIMx, Function name TIM_Base_InitTypeDef * Structure) Time Base configuration. Function description Parameters : TIM periheral TIMx: : TIM Base configuration structure Structure: Return values None: TIM_TI1_SetConfig void TIM_TI1_SetConfig (TIM_TypeDef * TIMx, uint32_t Function name TIM_ICPolarity, uint32_t TIM_ICSelection, uint32_t TIM_ICFilter) Configure the TI1 as Input. Function description Parameters TIMx: to select the TIM peripheral. : The Input Polarity. This parameter can be TIM_ICPolarity: one of the following values: TIM_ICPOLARITY_RISING TIM _ICPOLARITY_FALLING : specifies the input to be used. This TIM_ICSelection: parameter can be one of the following values: TIM_ICSELECTION_DIRECTTI: TIM Input 1 is selected to be connected to IC1. TIM_ICSELECTION_INDIRECTTI: TIM Input 1 is selected to be connected to IC2. TIM_ICSELECTION_TRC: TIM Input 1 is selected to be connected to TRC. TIM_ICFilter: : Specifies the Input Capture Filter. This parameter must be a value between 0x00 and 0x0F. Return values None: Notes are not used in INDIRECT TIM_ICFilter and TIM_ICPolarity mode as TI2FP1 (on channel2 path) is used as the input - signal. Therefore CCMR1 must be protected against un initialized filter and polarity values. TIM_OC2_SetConfig void TIM_OC2_SetConfig (TIM_TypeDef * TIMx, Function name Rev 2 513 / 1166 DocID027328

514 HAL UM1850 TIM Generic Driver _InitTypeDef * OC_Config) TIM_OC Time Ouput Compare 2 configuration. Function description Parameters TIMx: to select the TIM peripheral OC_Config: : The ouput configuration structure Return values None: TIM_DMADelayPulseCplt TIM_DMADelayPulseCplt (DMA_HandleTypeDef * hdma) void Function name Function description TIM DMA Delay Pulse complete callback. Parameters hdma: : pointer to DMA handle. Return values None: TIM_DMAError void TIM_DMAError (DMA_HandleTypeDef * hdma) Function name TIM DMA error callback. Function description Parameters : pointer to DMA handle. hdma: Return values None: TIM_DMACaptureCplt void TIM_DMACaptureCplt (DMA_HandleTypeDef * hdma) Function name TIM DMA Capture complete callback. Function description Parameters : pointer to DMA handle. hdma: Return values None: TIM_CCxChannelCmd void TIM_CCxChannelCmd (TIM_TypeDef * TIMx, uint32_t Function name Channel, uint32_t ChannelState) Function description Enables or disables the TIM Capture Compare Channel x. Parameters to select the TIM peripheral TIMx: Channel: : specifies the TIM Channel This parameter can be one of the following values: TIM_CHANNEL_1: TIM Channel 1 TIM_CHANNEL_2: TIM Channel 2 TIM_ CHANNEL_3: TIM Channel 3 TIM_CHANNEL_4: TIM Channel 4 ChannelState: : specifies the TIM Channel CCxE bit new state. This parameter can be: TIM_CCx_ENABLE or TIM_CCx_Disable. Return values None: DocID027328 / 1166 514 Rev 2

515 UM1850 HAL TIM Generic Driver HAL_TIM_Base_Init HAL_StatusTypeDef HAL_TIM_Base_Init (TIM_HandleTypeDef Function name * htim) Function description Initializes the TIM Time base Unit according to the specified parameters in the TIM_HandleTypeDef and create the associated handle. Parameters htim: : TIM Base handle Return values HAL: status HAL_TIM_Base_DeInit HAL_StatusTypeDef HAL_TIM_Base_DeInit Function name (TIM_HandleTypeDef * htim) Function description DeInitializes the TIM Base peripheral. Parameters : TIM Base handle htim: Return values status HAL: HAL_TIM_Base_MspInit void HAL_TIM_Base_MspInit (TIM_HandleTypeDef * htim) Function name Initializes the TIM Base MSP. Function description Parameters htim: : TIM handle Return values None: HAL_TIM_Base_MspDeInit void HAL_TIM_Base_MspDeInit (TIM_HandleTypeDef * htim) Function name DeInitializes TIM Base MSP. Function description Parameters : TIM handle htim: Return values None: HAL_TIM_Base_Start HAL_StatusTypeDef HAL_TIM_Base_Start Function name (TIM_HandleTypeDef * htim) Fu Starts the TIM Base generation. nction description Parameters htim: : TIM handle Return values status HAL: HAL_TIM_Base_Stop HAL_StatusTypeDef HAL_TIM_Base_Stop Function name (TIM_HandleTypeDef * htim) Stops the TIM Base generation. Function description 2 DocID027328 Rev 1166 515 /

516 HAL UM1850 TIM Generic Driver Parameters htim: : TIM handle Return values status HAL: HAL_TIM_Base_Start_IT HAL_StatusTypeDef HAL_TIM_Base_Start_IT Function name (TIM_HandleTypeDef * htim) Starts the TIM Base generation in interrupt mode. Function description Parameters htim: : TIM handle Return values HAL: status HAL_TIM_Base_Stop_IT HAL_StatusTypeDef HAL_TIM_Base_Stop_IT Function name (TIM_HandleTypeDef * htim) neration in interrupt mode. Function description Stops the TIM Base ge Parameters htim: : TIM handle Return values status HAL: HAL_TIM_Base_Start_DMA HAL_StatusTypeDef HAL_TIM_Base_Start_DMA Function name (TIM_HandleTypeDef * htim, uint32_t * pData, uint16_t Length) Function description Starts the TIM Base generation in DMA mode. Parameters htim: : TIM handle pData: : The source Buffer address. Length: : The length of data to be transferred from memory to peripheral. Return values HAL: status HAL_TIM_Base_Stop_DMA HAL_StatusTypeDef HAL_TIM_Base_Stop_DMA Function name (TIM_HandleTypeDef * htim) Function description Stops the TIM Base generation in DMA mode. Parameters htim: : TIM handle Return values status HAL: HAL_TIM_OC_Init HAL_StatusTypeDef HAL_TIM_OC_Init (TIM_HandleTypeDef * Function name htim) Initializes the TIM Output Compare according to the specified Function description parameters in the TIM_HandleTypeDef and create the associated handle. DocID027328 / 1166 516 Rev 2

517 UM1850 HAL TIM Generic Driver Parameters : TIM Output Compare handle htim: values Return HAL: status HAL_TIM_OC_DeInit HAL_StatusTypeDef HAL_TIM_OC_DeInit Function name (TIM_HandleTypeDef * htim) Function description DeInitializes the TIM peripheral. Parameters htim: : TIM Output Compare handle Return values status HAL: _OC_MspInit HAL_TIM void HAL_TIM_OC_MspInit (TIM_HandleTypeDef * htim) Function name Function description Initializes the TIM Output Compare MSP. Parameters : TIM handle htim: Return values None: HAL_TIM_OC_MspDeInit (TIM_HandleTypeDef * htim) void HAL_TIM_OC_MspDeInit Function name Function description DeInitializes TIM Output Compare MSP. Parameters htim: : TIM handle Return values None: HAL_TIM_OC_Start HAL_StatusTypeDef HAL_TIM_OC_Start (TIM_HandleTypeDef Function name * htim, uint32_t Channel) Function description Starts the TIM Output Compare signal generation. Parameters : TIM Output Compare handle htim: : TIM Channel to be enabled This parameter can Channel: be one of the following values: TIM_CHANNEL_1: TIM Channel 1 selected TIM_CHANNEL_2: TIM Channel 2 selected TIM_CHANNEL_3: TIM Channel 3 selected TIM_CHANNEL_4: TIM Channel 4 selected Return values HAL: status HAL_TIM_OC_Stop HAL_StatusTypeDef HAL_TIM_OC_Stop (TIM_HandleTypeDef Function name * htim, uint32_t Channel) Function description Stops the TIM Output Compare signal generation. Parameters : TIM handle htim: : TIM Channel to be disabled This parameter can Channel: 2 DocID027328 Rev 1166 517 /

518 HAL UM1850 TIM Generic Driver be one of the following values: TIM_CHANNEL_1: TIM Channel 1 selected TIM_CHANNEL_2: TIM Channe l 2 selected TIM_CHANNEL_3: TIM Channel 3 selected TIM_CHANNEL_4: TIM Channel 4 selected Return values HAL: status HAL_TIM_OC_Start_IT HAL_StatusTypeDef HAL_TIM_OC_Start_IT Function name (TIM_HandleTypeDef * htim, uint32_t Channel) Function description Starts the TIM Output Compare signal generation in interrupt mode. Parameters : TIM OC handle htim: Channel: : TIM Channel to be enabled This parameter can be one of the following values: TIM_CHANNEL_1: TIM Channel 1 selected el 2 selected TIM_CHANNEL_2: TIM Chann TIM_CHANNEL_3: TIM Channel 3 selected TIM_CHANNEL_4: TIM Channel 4 selected Return values HAL: status HAL_TIM_OC_Stop_IT HAL_StatusTypeDef HAL_TIM_OC_Stop_IT Function name (TIM_HandleTypeDef * htim, uint32_t Channel) Function description Stops the TIM Output Compare signal generation in interrupt mode. Parameters htim: : TIM Output Compare handle : TIM Channel to be disabled This parameter can Channel: be one of the following values: TIM_CHANNEL_1: TIM Channel 1 selected TIM_CHANNEL_2: TIM Channel 2 selected TIM_CHANNEL_3: TIM Channel 3 selected TIM_CHANNEL_4: TIM Channel 4 selected Return values status HAL: HAL_TIM_OC_Start_DMA HAL_StatusTypeDef HAL_TIM_OC_Start_DMA Function name Channel, uint32_t * (TIM_HandleTypeDef * htim, uint32_t pData, uint16_t Length) Function description Starts the TIM Output Compare signal generation in DMA mode. Parameters : TIM Output Compare handle htim: : TIM Channel to be enabled This parameter can Channel: values: be one of the following TIM_CHANNEL_1: TIM Channel 1 selected TIM_CHANNEL_2: TIM Channel 2 selected TIM_CHANNEL_3: TIM Channel 3 selected DocID027328 / 1166 518 Rev 2

519 UM1850 TIM Generic Driver HAL TIM_CHANNEL_4: TIM Channel 4 selected pData: : The source Buffer address. Length: : The length of data to be transferred from memory to TIM peripheral Return values status HAL: HAL_TIM_OC_Stop_DMA HAL_StatusTypeDef HAL_TIM_OC_Stop_DMA Function name (TIM_HandleTypeDef * htim, uint32_t Channel) ut Compare signal generation in DMA mode. Function description Stops the TIM Outp Parameters htim: : TIM Output Compare handle Channel: : TIM Channel to be disabled This parameter can be one of the following values: TIM_CHANNEL_1: TIM Channel 1 selected TIM_CHANNEL_2: TIM Channel 2 selected TIM_CHANNEL_3: TIM Channel 3 selected TIM_CHANNEL_4: TIM Channel 4 selected Return values status HAL: HAL_TIM_PWM_Init HAL_StatusTypeDef HAL_TIM_PWM_Init (TIM_HandleTypeDef Function name * htim) Function description Initializes the TIM PWM Time Base according to the specified parameters in the TIM_HandleTypeDef and create the associated handle. Parameters htim: : TIM handle Return values status HAL: HAL_TIM_PWM_DeInit HAL_TIM_PWM_DeInit HAL_StatusTypeDef Function name (TIM_HandleTypeDef * htim) Function description DeInitializes the TIM peripheral. Parameters htim: : TIM handle Return values HAL: status HAL_TIM_PWM_MspInit void HAL_TIM_PWM_MspInit (TIM_HandleTypeDef * htim) Function name Initializes the TIM PWM MSP. ion description Funct Parameters htim: : TIM handle Return values None: 2 DocID027328 Rev 1166 519 /

520 TIM Generic Driver HAL UM1850 HAL_TIM_PWM_MspDeInit void HAL_TIM_PWM_MspDeInit (TIM_HandleTypeDef * htim) Function name Function description DeInitializes TIM PWM MSP. Parameters htim: : TIM handle Return values None: HAL_TIM_PWM_Start HAL_StatusTypeDef HAL_TIM_PWM_Start Function name (TIM_HandleTypeDef * htim, uint32_t Channel) Function description Starts the PWM signal generation. Parameters : TIM handle htim: Channel: : TIM Channels to be enabled This parameter can be one of the following values: TIM_CHANNEL_1: TIM Channel 1 selected TIM_CHANNEL_2: TIM Channel 2 selected TIM_CHANNEL_3: TIM Channel 3 selected TIM_CHANNEL_4: TIM Channel 4 selected Return values status HAL: HAL_TIM_PWM_Stop HAL_StatusTypeDef HAL_TIM_PWM_Stop Function name (TIM_HandleTypeDef * htim, uint32_t Channel) Function description Stops the PWM signal generation. Parameters : TIM handle htim: Channel: : TIM Channels to be disabled This parameter can be one of the following values: TIM_CHANNEL_1: TIM Channel 1 selected TIM_CHANNEL_2: TIM Channel 2 selected TIM_CHANNEL_3: TIM Channel 3 selected TIM_CHANNEL_4: TIM Channel 4 selected Return values status HAL: HAL_TIM_PWM_Start_IT HAL_StatusTypeDef HAL_TIM_PWM_Start_IT Function name (TIM_HandleTypeDef * htim, uint32_t Channel) Starts the PWM signal generation in interrupt mode. Function description Parameters : TIM handle htim: : TIM Channel to be enabled This parameter can Channel: be one of the following values: TIM_CHANNEL_1: TIM Channel 1 selected TIM_CHANNEL_2: TIM Channel 2 selected TIM_CHANNEL_3: TIM Channel 3 selected TIM_CHANNEL_4: TIM Channel 4 selected DocID027328 / 1166 520 Rev 2

521 UM1850 TIM Generic Driver HAL Return values HAL: st atus HAL_TIM_PWM_Stop_IT HAL_StatusTypeDef HAL_TIM_PWM_Stop_IT Function name (TIM_HandleTypeDef * htim, uint32_t Channel) Function description Stops the PWM signal generation in interrupt mode. Parameters : TIM handle htim: Channel: : TIM Channels to be disabled This parameter can be one of the following values: TIM_CHANNEL_1: TIM Channel 1 selected TIM_CHANNEL_2: TIM Channel 2 selected TIM_CHANNEL_3: TIM Channel 3 selected TIM_CHANNEL_4: TIM Channel 4 selected Return values status HAL: HAL_TIM_PWM_Start_DMA HAL_StatusTypeDef HAL_TIM_PWM_Start_DMA Function name (TIM_HandleTypeDef * htim, uint32_t Channel, uint32_t * pData, uint16_t Length) Starts the TIM PWM signal generation in DMA mode. Function description Parameters : TIM handle htim: : TIM Channels to be enabled This parameter can Channel: be one of the following values: TIM_CHANNEL_1: TIM Channel 1 selected TIM_CHANNEL_2: TIM Channel 2 selected TIM_CHANNEL_3: TIM Channel 3 selected TIM_CHANNEL_4: TIM Channel 4 selected pData: : The source Buffer address. Length: : The length of data to be transferred from memory to TIM peripheral Return values HAL: status HAL_TIM_PWM_Stop_DMA HAL_StatusTypeDef HAL_TIM_PWM_Stop_DMA Function name (TIM_HandleTypeDef * htim, uint32_t Channel) Function description Stops the TIM PWM signal generation in DMA mode. Parameters : TIM handle htim: : TIM Channels to be disabled This parameter can Channel: be one of the following values: TIM_CHANNEL_1: TIM Channel 1 selected : TIM Channel 2 selected TIM_CHANNEL_2 TIM_CHANNEL_3: TIM Channel 3 selected TIM_CHANNEL_4: TIM Channel 4 selected Return values status HAL: 2 DocID027328 Rev 1166 521 /

522 HAL UM1850 TIM Generic Driver HAL_TIM_IC_Init HAL_StatusTypeDef HAL_TIM_IC_Init (TIM_HandleTypeDef * Function name htim) Function description Initializes the TIM Input Capture Time base according to the specified parameters in the TIM_HandleTypeDef and create the associated handle. Parameters : TIM Input Capture handle htim: Return values status HAL: HAL_TIM_IC_DeInit HAL_StatusTypeDef HAL_TIM_IC_DeInit (TIM_HandleTypeDef Function name * htim) Function description DeInitializes the TIM peripheral. Parameters : TIM Input Capture handle htim: Return values status HAL: HAL_TIM_IC_MspInit (TIM_HandleTypeDef * htim) void HAL_TIM_IC_MspInit Function name Function description Initializes the TIM Input Capture MSP. Parameters : TIM handle htim: Return values None: HAL_TIM_IC_MspDeInit void HAL_TIM_IC_MspDeInit (TIM_HandleTypeDef * htim) Function name Function description DeInitializes TIM Input Capture MSP. Parameters : TIM handle htim: Return values None: HAL_TIM_IC_Start HAL_StatusTypeDef HAL_TIM_IC_Start (TIM_HandleTypeDef * Function name htim, uint32_t Channel) Function description Starts the TIM Input Capture m easurement. Parameters htim: : TIM Input Capture handle Channel: : TIM Channels to be enabled This parameter can be one of the following values: TIM_CHANNEL_1: TIM Channel 1 selected TIM_CHANNEL_2: TIM Channel 2 selected selected TIM_CHANNEL_3: TIM Channel 3 TIM_CHANNEL_4: TIM Channel 4 selected Return values HAL: status DocID027328 / 1166 522 Rev 2

523 UM1850 TIM Generic Driver HAL HAL_TIM_IC_Stop HAL_StatusTypeDef HAL_TIM_IC_Stop (TIM_HandleTypeDef * Function name htim, uint32_t Channel) Function description Stops the TIM Input Capture measurement. Parameters : TIM handle htim: Channel: : TIM Channels to be disabled This parameter can be one of the following values: TIM_CHANNEL_1: TIM Channel 1 selected TIM_CHANNEL_2: TIM Channel 2 selected TIM_CHANNEL_3: TIM Channel 3 selected Channel 4 selected TIM_CHANNEL_4: TIM Return values HAL: status HAL_TIM_IC_Start_IT HAL_StatusTypeDef HAL_TIM_IC_Start_IT Function name (TIM_HandleTypeDef * htim, uint32_t Channel) Starts the TIM Input Capture measurement in interrupt mode. Function description Parameters : TIM Input Capture handle htim: Channel: : TIM Channels to be enabled This parameter can be one of the following values: TIM_CHANNEL_1: TIM Channel 1 selected TIM_CHANNEL_2: TIM Channel 2 selected TIM_CHANNEL_3: TIM Channel 3 selected TIM_CH ANNEL_4: TIM Channel 4 selected Return values HAL: status HAL_TIM_IC_Stop_IT HAL_StatusTypeDef HAL_TIM_IC_Stop_IT Function name (TIM_HandleTypeDef * htim, uint32_t Channel) Function description Stops the TIM Input Capture measurement in interrupt mode. Parameters : TIM handle htim: : TIM Channels to be disabled This parameter can Channel: be one of the following values: TIM_CHANNEL_1: TIM Channel 1 selected TIM_CHANNEL_2: TIM Channel 2 selected TIM_CHANNEL_3: TIM Channel 3 selected TIM Channel 4 selected TIM_CHANNEL_4: Return values status HAL: HAL_TIM_IC_Start_DMA HAL_StatusTypeDef HAL_TIM_IC_Start_DMA Function name (TIM_HandleTypeDef * htim, uint32_t Channel, uint32_t * pData, uint16_t Length) Function description Starts the TIM Input Capture measurement in DMA mode. 2 DocID027328 Rev 1166 523 /

524 HAL UM1850 TIM Generic Driver Parameters htim: : TIM Input Capture handle : TIM Channels to be enabled This parameter can Channel: be one of the following values: TIM_CHANNEL_1: TIM Channel 1 selected 2 selected TIM_CHANNEL_2: TIM Channel TIM_CHANNEL_3: TIM Channel 3 selected TIM_CHANNEL_4: TIM Channel 4 selected pData: : The destination Buffer address. : The length of data to be transferred from TIM Length: peripheral to memory. Return values HAL: status HAL_TIM_IC_Stop_DM A HAL_StatusTypeDef HAL_TIM_IC_Stop_DMA Function name (TIM_HandleTypeDef * htim, uint32_t Channel) Stops the TIM Input Capture measurement in DMA mode. Function description Parameters : TIM Input Capture handle htim: : TIM Channels to be disabled This parameter can Channel: be one of the following values: TIM_CHANNEL_1: TIM Channel 1 selected TIM_CHANNEL_2: TIM Channel 2 selected TIM_CHANNEL_3: TIM Channel 3 selected TIM_CHANNEL_4: TIM Channel 4 selected Return values HAL: status HAL_TIM_OnePulse_Init HAL_StatusTypeDef HAL_TIM_OnePulse_Init Function name (TIM_HandleTypeDef * htim, uint32_t OnePulseMode) Function description Initializes the TIM One Pulse Time Base according to the specified parameters in the TIM_HandleTypeDef and create the associated handle. Parameters htim: : TIM OnePulse handle OnePulseMode: : Select the One pulse mode. This following values: parameter can be one of the TIM_OPMODE_SINGLE: Only one pulse will be generated. TIM_OPMODE_REPETITIVE: Repetitive pulses wil be generated. Return values status HAL: HAL_TIM_OnePulse_DeInit HAL_StatusTypeDef HAL_TIM_OnePulse_DeInit Function name (TIM_HandleTypeDef * htim) DeInitializes the TIM One Pulse. Function description Parameters : TIM One Pulse handle htim: DocID027328 / 1166 524 Rev 2

525 UM1850 TIM Generic Driver HAL Return values HAL: status HAL_TIM_OnePulse_MspInit void HAL_TIM_OnePulse_MspInit (TIM_HandleTypeDef * htim) Function name Function description Initializes the TIM One Pulse MSP. Parameters : TIM handle htim: Return values None: HAL_TIM_OnePulse_MspDeInit void HAL_TIM_OnePulse_MspDeInit (TIM_HandleTypeDef * Function name htim) Function description DeInitializes TIM One Pulse MSP. Parameters : TIM handle htim: Return values None: HAL_TIM_OnePulse_Start HAL_StatusTypeDef HAL_TIM_OnePulse_Start Function name (TIM_HandleTypeDef * htim, uint32_t OutputChannel) Function description ne Pulse signal generation. Starts the TIM O Parameters htim: : TIM One Pulse handle OutputChannel: : TIM Channels to be enabled This parameter can be one of the following values: TIM_CHANNEL_1: TIM Channel 1 selected TIM_CHANNEL_2: TIM Channel 2 selected Return values HAL: status HAL_TIM_OnePulse_Stop HAL_StatusTypeDef HAL_TIM_OnePulse_Stop Function name (TIM_HandleTypeDef * htim, uint32_t OutputChannel) Stops the TIM One Pulse signal generation. Function description Parameters htim: : TIM One Pulse handle : TIM Channels to be disable This OutputChannel: parameter can be one of the following values: TIM_CHANNEL_1: TIM Channel 1 selected TIM_CHANNEL_2: TIM Channel 2 selected Return values status HAL: HAL_TIM_OnePulse_Start_IT HAL_StatusTypeDef HAL_TIM_OnePulse_Start_IT Function name (TIM_HandleTypeDef * htim, uint32_t OutputChannel) Function description Starts the TIM One Pulse signal generation in interrupt mode. 2 DocID027328 Rev 1166 525 /

526 HAL UM1850 TIM Generic Driver Parameters htim: : TIM One Pulse handle OutputChannel: : TIM Channels to be enabled This parameter can be one of the following values: TIM_CHANNEL_1: TIM Channel 1 selected TIM_CHANNEL_2: TIM Channel 2 selected Return values HAL: status HAL_TIM_OnePulse_Stop_IT HAL_StatusTypeDef HAL_TIM_OnePulse_Stop_IT Function name (TIM_HandleTypeDef * htim, uint32_t OutputChannel) Stops the TIM One Pulse signal generation in interrupt mode. Function description Parameters htim: : TIM One Pulse handle : TIM Channels to be enabled This OutputChannel: ollowing values: parameter can be one of the f TIM_CHANNEL_1: TIM Channel 1 selected TIM_CHANNEL_2: TIM Channel 2 selected Return values status HAL: HAL_TIM_Encoder_Init HAL_StatusTypeDef HAL_TIM_Encoder_Init Function name (TIM_HandleTypeDef * htim, TIM_Encoder_InitTypeDef * sConfig) Initializes the TIM Encoder Interface and create the associated Function description handle. Parameters : TIM Encoder Interface handle htim: : TIM Encoder Interface configuration structure sConfig: Return values status HAL: HAL_TIM_Encoder _DeInit HAL_StatusTypeDef HAL_TIM_Encoder_DeInit Function name (TIM_HandleTypeDef * htim) Function description DeInitializes the TIM Encoder interface. Parameters htim: : TIM Encoder handle Return values HAL: status HAL_TIM_Encoder_MspInit void HAL_TIM_Encoder_MspInit (TIM_HandleTypeDef * htim) Function name Function description Initializes the TIM Encoder Interface MSP. Parameters : TIM handle htim: Return values None: DocID027328 / 1166 526 Rev 2

527 UM1850 TI M Generic Driver HAL HAL_TIM_Encoder_MspDeInit void HAL_TIM_Encoder_MspDeInit (TIM_HandleTypeDef * Function name htim) Function description DeInitializes TIM Encoder Interface MSP. Parameters htim: : TIM handle Return values None: HAL_TIM_Encoder_Start HAL_StatusTypeDef HAL_TIM_Encoder_Start Function name (TIM_HandleTypeDef * htim, uint32_ t Channel) Starts the TIM Encoder Interface. Function description Parameters htim: : TIM Encoder Interface handle : TIM Channels to be enabled This parameter can Channel: be one of the following values: TIM_CHANNEL_1: TIM Channel 1 selected TIM_CHANNEL_2: TIM Channel 2 selected TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected Return values status HAL: HAL_TIM_Encoder_Stop HAL_StatusTypeDef HAL_TIM_Encoder_Stop Function name (TIM_HandleTypeDef * htim, uint32_t Channel) n description Stops the TIM Encoder Interface. Functio Parameters htim: : TIM Encoder Interface handle Channel: : TIM Channels to be disabled This parameter can be one of the following values: TIM_CHANNEL_1: TIM Channel 1 selected TIM_CHANNEL_2: TIM Channel 2 selected TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected Return values status HAL: HAL_TIM_Encoder_Start_IT HAL_StatusTypeDef HAL_TIM_Encoder_Start_IT Function name (TIM_HandleTypeDef * htim, uint32_t Channel) Function description Starts the TIM Encoder Interface in interrupt mode. Parameters : TIM Encoder Interface handle htim: : TIM Channels to be enabled This parameter can Channel: be one of the following values: TIM_CHANNEL_1: TIM Channel 1 selected selected TIM_CHANNEL_2: TIM Channel 2 TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected 2 DocID027328 Rev 1166 527 /

528 HAL UM1850 TIM Generic Driver Return values HAL: status HAL_TIM_Encoder_Stop_IT HAL_StatusTypeDef HAL_TIM_Encoder_Stop_IT Function name (TIM_HandleTypeDef * htim, uint32_t Channel) Function description Stops the TIM Encoder Interface in interrupt mode. Parameters htim: : TIM Encoder Interface handle Channel: : TIM Channels to be disabled This parameter can be one of the following values: TIM_CHANNEL_1: TIM Channel 1 selected TIM_CHANNEL_2: TIM Channel 2 selected TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected Return values HAL: status HAL_TIM_Encoder_Start_DMA HAL_StatusTypeDef HAL_TIM_Encoder_Start_DMA Function name (TIM_HandleTypeDef * htim, uint32_t Channel, uint32_t * * pData2, uint16_t Length) pData1, uint32_t Starts the TIM Encoder Interface in DMA mode. Function description Parameters htim: : TIM Encoder Interface handle : TIM Channels to be enabled This parameter can Channel: be one of the following values: TIM_CHANNEL_1: TIM Channel 1 selected TIM_CHANNEL_2: TIM Channel 2 selected TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected : The destination Buffer address for IC1. pData1: pData2: : The destination Buffer address for IC2. Length: : The length of data to b e transferred from TIM peripheral to memory. Return values status HAL: HAL_TIM_Encoder_Stop_DMA HAL_StatusTypeDef HAL_TIM_Encoder_Stop_DMA Function name (TIM_HandleTypeDef * htim, uint32_t Channel) n DMA mode. Function description Stops the TIM Encoder Interface i Parameters htim: : TIM Encoder Interface handle Channel: : TIM Channels to be enabled This parameter can be one of the following values: TIM_CHANNEL_1: TIM Channel 1 selected TIM_CHANNEL_2: TIM Channel 2 selected TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected Return values status HAL: DocID027328 / 1166 528 Rev 2

529 UM1850 TIM Generic Driver HAL HAL_TIM_IRQHandler void HAL_TIM_IRQHandler (TIM_HandleTypeDef * htim) Function name Function description This function handles TIM interrupts requests. Parameters : TIM handle htim: Return values None: HAL_TIM_OC_ConfigChannel HAL_StatusTypeDef HAL_TIM_OC_ConfigChannel Function name (TIM_HandleTypeDef * htim, TIM_OC_InitTypeDef * sConfig, uint32_t Channel) Function description to the Initializes the TIM Output Compare Channels according specified parameters in the TIM_OC_InitTypeDef. Parameters : TIM Output Compare handle htim: : TIM Output Compare configuration structure sConfig: Channel: : TIM Channels to be enabled This parameter can be one of the following values: NNEL_1: TIM Channel 1 selected TIM_CHA TIM_CHANNEL_2: TIM Channel 2 selected TIM_CHANNEL_3: TIM Channel 3 selected TIM_CHANNEL_4: TIM Channel 4 selected Return values HAL: status HAL_TIM_PWM_ConfigChannel HAL_TIM_PWM_ConfigChannel HAL_StatusTypeDef Function name (TIM_HandleTypeDef * htim, TIM_OC_InitTypeDef * sConfig, uint32_t Channel) Function description Initializes the TIM PWM channels according to the specified parameters in the TIM_OC_InitTypeDef. Parameters : TIM handle htim: sC : TIM PWM configuration structure onfig: Channel: : TIM Channels to be enabled This parameter can be one of the following values: TIM_CHANNEL_1: TIM Channel 1 selected TIM_CHANNEL_2: TIM Channel 2 selected TIM_CHANNEL_3: TIM Channel 3 selected TIM_CHANNEL_4: TIM Channel 4 selected Return values status HAL: HAL_TIM_IC_ConfigChannel HAL_StatusTypeDef HAL_TIM_IC_ConfigChannel Function name (TIM_HandleTypeDef * htim, TIM_IC_InitTypeDef * sConfig, uint32_t Channel) Initialize Function description s the TIM Input Capture Channels according to the specified parameters in the TIM_IC_InitTypeDef. 2 DocID027328 Rev 1166 529 /

530 HAL UM1850 TIM Generic Driver Parameters htim: : TIM IC handle sConfig: : TIM Input Capture configuration structure Channel: : TIM Channels to be enabled This parameter can be one of the following values: TIM_CHANNEL_1: TIM Channel 1 selected TIM_CHANNEL_2: TIM Channel 2 selected TIM_CHANNEL_3: TIM Channel 3 selected TIM_CHANNEL_4: TIM Channel 4 selected Return values HAL: status HAL_TIM_OnePulse_ConfigChannel HAL_StatusTypeDef HAL_TIM_OnePulse_ConfigChannel Function name (TIM_HandleTypeDef * htim, TIM_OnePulse_InitTypeDef * sConfig, uint32_t OutputChannel, uint32_t InputChannel) Function description Initializes the TIM One Pulse Channels according to the specified parameter s in the TIM_OnePulse_InitTypeDef. Parameters htim: : TIM One Pulse handle : TIM One Pulse configuration structure sConfig: : TIM Channels to be enabled This OutputChannel: parameter can be one of the following values: TIM_CHANNEL_1: TIM Channel 1 selected TIM_CHANNEL_2: TIM Channel 2 selected InputChannel: : TIM Channels to be enabled This parameter can be one of the following values: TIM_CHANNEL_1: TIM Channel 1 selected TIM_CHANNEL_2: TIM Channel 2 selected Return values status HAL: ConfigOCrefClear HAL_TIM_ HAL_StatusTypeDef HAL_TIM_ConfigOCrefClear Function name (TIM_HandleTypeDef * htim, TIM_ClearInputConfigTypeDef * sClearInputConfig, uint32_t Channel) Configures the OCRef clear feature. Function description Parameters htim: : TIM handle sClearInputConfig: : pointer to a TIM_ClearInputConfigTypeDef structure that contains the OCREF clear feature and parameters for the TIM peripheral. Channel: : specifies the TIM Channel This parameter can be one of the following values: M_CHANNEL_1: TIM Channel 1 TI TIM_CHANNEL_2: TIM Channel 2 TIM_CHANNEL_3: TIM Channel 3 TIM_CHANNEL_4: TIM Channel 4 Return values status HAL: DocID027328 / 1166 530 Rev 2

531 UM1850 TIM Generic Driver HAL HAL_TIM_ConfigClockSource HAL_StatusTypeDef HAL_TIM_ConfigClockSource Function name (TIM_HandleTypeDef * htim, TI M_ClockConfigTypeDef * sClockSourceConfig) Function description Configures the clock source to be used. Parameters : TIM handle htim: sClockSourceConfig: : pointer to a TIM_ClockConfigTypeDef structure that contains the clock source information for the TIM peripheral. Return values status HAL: HAL_TIM_ConfigTI1Input HAL_StatusTypeDef HAL_TIM_ConfigTI1Input Function name (TIM_HandleTypeDef * htim, uint32 _t TI1_Selection) Function description Selects the signal connected to the TI1 input: direct from CH1_input or a XOR combination between CH1_input, CH2_input & CH3_input. Parameters : TIM handle. htim: TI1_Selection: : Indicate whether or not channel 1 is connected to the output of a XOR gate. This parameter can be one of the following values: TIM_TI1SELECTION_CH1: The TIMx_CH1 pin is connected to TI1 input TIM_TI1SELECTION_XORCOMBINATION: The pins are connected to the TI1 TIMx_CH1, CH2 and CH3 input (XOR combination) Return values status HAL: HAL_TIM_SlaveConfigSynchronization HAL_StatusTypeDef HAL_TIM_SlaveConfigSynchronization Function name (TIM_HandleTypeDef * htim, TIM_SlaveConfigTypeDef * sSlaveConfig) Func tion description Configures the TIM in Slave mode. Parameters htim: : TIM handle. sSlaveConfig: : pointer to a TIM_SlaveConfigTypeDef structure that contains the selected trigger (internal trigger and the ) input, filtered timer input or external trigger input) and the Slave mode (Disable, Reset, Gated, Trigger, External clock mode 1). Return values status HAL: HAL_TIM_SlaveConfigSynchronization_IT HAL_StatusTypeDef Function name HAL_TIM_SlaveConfigSynchronization_IT TIM_SlaveConfigTypeDef * (TIM_HandleTypeDef * htim, 2 DocID027328 Rev 1166 531 /

532 HAL UM1850 TIM Generic Driver sSlaveConfig) Function description Configures the TIM in Slave mode in interrupt mode. Parameters htim: TIM handle. sSlaveConfig: pointer to a TIM_SlaveConfigTypeDef structure that contains the selected trigger (internal trigg er input, filtered timer input or external trigger input) and the ) and the Slave mode (Disable, Reset, Gated, Trigger, External clock mode 1). Return values status HAL: HAL_TIM_DMABurst_WriteStart tart HAL_StatusTypeDef HAL_TIM_DMABurst_WriteS Function name (TIM_HandleTypeDef * htim, uint32_t BurstBaseAddress, uint32_t BurstRequestSrc, uint32_t * BurstBuffer, uint32_t BurstLength) Function description Configure the DMA Burst to transfer Data from the memory to the TIM peripheral. Parameters : TIM handle htim: BurstBaseAddress: : TIM Base address from where the DMA will start the Data write This parameter can be one of the following values: TIM_DMABASE_CR1 TIM_DMABASE_CR2 TIM_DMABASE_SMCR TIM_DMABASE_DIER TIM_DMABASE_SR TIM_DMABASE_EGR TIM_DMABAS E_CCMR1 TIM_DMABASE_CCMR2 TIM_DMABASE_CCER TIM_DMABASE_CNT TIM_DMABASE_PSC TIM_DMABASE_ARR TIM_DMABASE_RCR TIM_DMABASE_CCR1 TIM_DMABASE_CCR2 TIM_DMABASE_CCR3 TIM_DMABASE_CCR4 TIM_DMABASE_BDTR TIM_DMABASE_DCR : TIM DMA Request sources This BurstRequestSrc: parameter can be one of the following values: TIM_DMA_UPDATE: TIM update Interrupt source TIM_DMA_CC1: TIM Capture Compare 1 DMA source TIM_DMA_CC2: TIM Capture Compare 2 DMA source urce TIM_DMA_CC3: TIM Capture Compare 3 DMA so TIM_DMA_CC4: TIM Capture Compare 4 DMA source TIM_DMA_COM: TIM Commutation DMA source TIM_DMA_TRIGGER: TIM Trigger DMA source : The Buffer address. BurstBuffer: DocID027328 / 1166 532 Rev 2

533 UM1850 TIM Generic Driver HAL : DMA Burst length. This parameter can be BurstLength: one value between: TIM_DMABURSTLE NGTH_1TRANSFER and TIM_DMABURSTLENGTH_18TRANSFERS. Return values status HAL: HAL_TIM_DMABurst_WriteStop HAL_StatusTypeDef HAL_TIM_DMABurst_WriteStop Function name (TIM_HandleTypeDef * htim, uint32_t BurstRequestSrc) Stops the TIM DMA Burst mode. Function description Parameters htim: : TIM handle BurstRequestSrc: : TIM DMA Request sources to disable Return values HAL: status HAL_TIM_DMABurst_ReadStart HAL_StatusTypeDef HAL_TIM_DMABurst_ReadStart Function name im, uint32_t BurstBaseAddress, (TIM_HandleTypeDef * ht uint32_t BurstRequestSrc, uint32_t * BurstBuffer, uint32_t BurstLength) Configure the DMA Burst to transfer Data from the TIM peripheral Function description to the memory. Parameters htim: : TIM handle BurstBaseAddress: : TIM Base address from where the DMA will starts the Data read This parameter can be one of the following values: TIM_DMABASE_CR1 TIM_DMABASE_CR2 TIM_DMABASE_SMCR TIM_DMABASE_DIER TIM_DMABASE_SR TIM_DMABASE_EGR TIM_DMABASE_CCMR1 TIM_DMABASE_CCMR2 TIM_DMABASE_CCER TIM_DMABASE_CNT TIM_DMABASE_PSC TIM_DMABASE_ARR TIM_DMABASE_RCR TIM_DMABASE_CCR1 TIM_DMABASE_CCR2 TIM_DMABASE_CCR3 TIM_DMABASE_CCR4 TIM_DMABASE_BDTR TIM_DMABASE_DCR BurstRequestSrc: : TIM DMA Request sources This parameter can be one of the following values: TIM_DMA_UPDATE: TIM update Interrupt source TIM_DMA_CC1: TIM Capture Compare 1 DMA source TIM_DMA_CC2: TIM Capture Compare 2 DMA source 2 DocID027328 Rev 1166 533 /

534 HAL UM1850 TIM Generi c Driver urce TIM_DMA_CC3: TIM Capture Compare 3 DMA so TIM_DMA_CC4: TIM Capture Compare 4 DMA source TIM_DMA_COM: TIM Commutation DMA source TIM_DMA_TRIGGER: TIM Trigger DMA source : The Buffer address. BurstBuffer: BurstLength: : DMA Burst length. This parameter can be one value between: TIM_DMABURSTLE NGTH_1TRANSFER and TIM_DMABURSTLENGTH_18TRANSFERS. Return values status HAL: HAL_TIM_DMABurst_ReadStop HAL_StatusTypeDef HAL_TIM_DMABurst_ReadStop Function name (TIM_HandleTypeDef * htim, uint32_t BurstRequestSrc) Function description Stop the DMA burst reading. Parameters : TIM handle htim: : TIM DMA Request sources to disable. BurstRequestSrc: Return values HAL: status HAL_TIM_GenerateEvent HAL_StatusTypeDef HAL_TIM_GenerateEvent Function name t EventSource) (TIM_HandleTypeDef * htim, uint32_ Function description Generate a software event. Parameters htim: : TIM handle EventSource: : specifies the event source. This parameter can be one of the following values: TIM_EVENTSOURCE_UPDATE: Timer update Event source TIM_EVENTSOURCE_CC1: Timer Capture Compare 1 Event source TIM_EVENTSOURCE_CC2: Timer Capture Compare 2 Event source TIM_EVENTSOURCE_CC3: Timer Capture Compare 3 Event source TIM_EVENTSOURCE_CC4: Timer Capture Compare 4 Event source TIM_EVENTSOURCE_COM: Tim er COM event source TIM_EVENTSOURCE_TRIGGER: Timer Trigger Event source TIM_EVENTSOURCE_BREAK: Timer Break event source Return values status HAL: Notes TIM6 and TIM7 can only generate an update event. TIM_EVENTSOURCE_COM and TIM_EVENTSOURCE_BREAK are used only with TIM1, TIM15, TIM16 and TIM17. DocID027328 / 1166 534 Rev 2

535 UM1850 TIM Generic Driver HAL HAL_TIM_ReadCapturedValue uint32_t HAL_TIM_ReadCapturedValue (TIM_HandleTypeDef * Function name htim, uint32_t Channel) Read the captured value from Capture Compare unit. Function description Parameters : TIM handle. htim : : TIM Channels to be enabled This parameter can Channel: be one of the following values: TIM_CHANNEL_1 : TIM Channel 1 selected TIM_CHANNEL_2 : TIM Channel 2 selected TIM_CHANNEL_3 : TIM Channel 3 selected selected TIM_CHANNEL_4 : TIM Channel 4 Return values value Captured: HAL_TIM_PeriodElapsedCallback void HAL_TIM_PeriodElapsedCallback (TIM_HandleTypeDef * Function name htim) Period elapsed callback in non blocking mode. Function description Parameters htim: : TIM handle Return values None: HAL_TIM_OC_DelayElapsedCallback void HAL_TIM_OC_DelayElapsedCallback Function name (TIM_HandleTypeDef * htim) Function description Output Compare callback in non blocking mode. Parameters htim: : TIM OC handle Return values None: HAL_TIM_IC_CaptureCallback void HAL_TIM_IC_CaptureCallback (TIM_HandleTypeDef * Function name htim) Function description Input Capture callback in non blocking mode. Parameters : TIM IC handle htim: Return values None: HAL_TIM_PWM_PulseFinishedCallback void HAL_TIM_PWM_PulseFinishedCallback Function name (TIM_HandleTypeDef * htim) PWM Pulse finished callback in non blocking mode. Function description Parameters : TIM handle htim: Return values None: 2 DocID027328 Rev 1166 535 /

536 HAL UM1850 TIM Generic Driver HAL_TIM_Trigge rCallback void HAL_TIM_TriggerCallback (TIM_HandleTypeDef * htim) Function name Function description Hall Trigger detection callback in non blocking mode. Parameters htim: : TIM handle Return values None: HAL_TIM_ErrorCallback void HAL_TIM_ErrorCallback (TIM_HandleTypeDef * htim) Function name Timer error callback in non blocking mode. Function description Parameters : TIM handle htim: Return values None: HAL_TIM_Base_GetState HAL_TIM_StateTypeDef HAL_TIM_Base_GetState Function name (TIM_HandleTypeDef * htim) Return the TIM Base state. Function description Parameters : TIM Base handle htim: Return values HAL: state HAL_TIM_OC_GetState HAL_TIM_StateTypeDef HAL_TIM_OC_GetState Function name (TIM_HandleTypeDef * htim) Function description Return the TIM OC state. Parameters htim: : TIM Ouput Compare handle Return values state HAL: HAL_TIM_PWM_GetState HAL_TIM_StateTypeDef HAL_TIM_PWM_GetState Function name (TIM_HandleTypeDef * htim) Function description Return the TIM PWM state. Parameters : TIM handle htim: Return values state HAL: HAL_TIM_IC_GetState HAL_TIM_StateTypeDef HAL_TIM_IC_GetState Function name (TIM_HandleTypeDef * htim) Function description Return the TIM Input Capture state. Parameters htim: : TIM IC handle DocID027328 / 1166 536 Rev 2

537 UM1850 TIM Generic Driver HAL Return values HAL: state HAL_TIM_OnePulse_GetState HAL_TIM_StateTypeDef HAL_TIM_OnePulse_GetState Function name (TIM_HandleTypeDef * htim) Function description Return the TIM One Pulse Mode state. Parameters : TIM OPM handle htim: Return values state HAL: HAL_TIM_Encoder_GetState HAL_TIM_StateTypeDef HAL_TIM_Encoder_GetState Function name (TIM_HandleTypeDef * htim) Function description Return the TIM Encoder Mode state. Parameters : TIM Encoder handle htim: Return values HAL: state 41.3 TIM Firmware driver defines 41.3.1 TIM TIM Automatic Output Enable TIM_AUTOMATICOUTPUT_ENABLE TIM_AUTOMATICOUTPUT_DISABLE Reload Preload TIM Auto - TIMx_ARR register is not buffered TIM_AUTORELOAD_PRELOAD_DISABLE TIM_AUTORELOAD_PRELOAD_ENABLE TIMx_ARR register is buffered TIM Break Input Enable Disable TIM_BREAK_ENABLE TIM_BREAK_DISABLE TIM Break Input Polarity TIM_BREAKPOLARITY_LOW TIM_BREAKPOLARITY_HIGH TIM Channel TIM_CHANNEL_1 TIM_CHANNEL_2 TIM_CHANNEL_3 TIM_CHANNEL_4 TIM_CHANNEL_ALL TIM Capture/Compare Channel State 2 DocID027328 Rev 1166 537 /

538 HAL UM1850 TIM Generic Driver TIM_CCx_ENABLE TIM_CCx_DISABLE TIM_CCxN_ENABLE TIM_CCxN_DISABLE TIM Clear Input Polarity Polarity for ETRx pin TIM_CLEARINPUTPOLARITY_INVERTED TIM_CLEARINPUTPOLARITY_NONINVERTED Polarity for ETRx pin TIM Clear Input Prescaler No prescaler is used TIM_CLEARINPUTPRESCALER_DIV1 Prescaler for External ETR pin: Capture TIM_CLEARINPUTPRESCALER_DIV2 performed once every 2 events. TIM_CLEARINPUTPRESCALER_DIV4 Prescaler for External ETR pin: Capture performed once every 4 events. TIM_CLEARINPUTPRESCALER_DIV8 Prescaler for External ETR pin: Capture performed once every 8 events. TIM ClearInput Source TIM_CLEARINPUTSOURCE_ETR TIM_CLEARINPUTSOURCE_NONE TIM ClockDivision TIM_CLOCKDIVISION_DIV1 TIM_CLOCKDIVISION_DIV2 TIM_CLOCKDIVISION_DIV4 TIM Clock Polarity Polarity for ETRx clock sources TIM_CLOCKPOLARITY_INVERTED TIM_CLOCKPOLARITY_NONINVERTED Polarity for ETRx clock sources Polarity for TIx clock sources TIM_CLOCKPOLARITY_RISING TIM_CLOCKPOLARITY_FALLING Polarity for TIx clock sources Polarity for TIx clock sources TIM_CLOCKPOLARITY_BOTHEDGE TIM Clock Prescaler TIM_CLOCKPRESCALER_DIV1 No prescaler is used Prescaler for External ETR Clock: Capture performed TIM_CLOCKPRESCALER_DIV2 once every 2 events. ler for External ETR Clock: Capture performed Presca TIM_CLOCKPRESCALER_DIV4 once every 4 events. Prescaler for External ETR Clock: Capture performed TIM_CLOCKPRESCALER_DIV8 once every 8 events. TIM Clock Source TIM_CLOCKSOURCE_ETRMODE2 DocID027328 / 1166 538 Rev 2

539 UM1850 TIM Generic Driver HAL TIM_CLOCKSOURCE_INTERNAL TIM_CLOCKSOURCE_ITR0 TIM_CLOCKSOURCE_ITR1 TIM_CLOCKSOURCE_ITR2 TIM_CLOCKSOURCE_ITR3 TIM_CLOCKSOURCE_TI1ED TIM_CLOCKSOURCE_TI1 TIM_CLOCKSOURCE_TI2 TIM_CLOCKSOURCE_ETRMODE1 TIM Commutation Source TIM_COMMUTATION_TRGI TIM_COMMUTATION_SOFTWARE TIM Counter Mode TIM_COUNTERMODE_UP TIM_COUNTERMODE_DOWN TIM_COUNTERMODE_CENTERALIGNED1 TIM_COUNTERMODE_CENTERALIGNED2 TIM_COUNTERMODE_CENTERALIGNED3 TIM DMA Base Address TIM_DMABASE_CR1 TIM_DMABASE_CR2 TIM_DMABASE_SMCR TIM_DMABASE_DIER TIM_DMABASE_SR TIM_DMABASE_EGR TIM_DMABASE_CCMR1 TIM_DMABASE_CCMR2 TIM_DMABASE_CCER TIM_DMABASE_CNT TIM_DMABASE_PSC TIM_DMABASE_ARR TIM_DMABASE_RCR TIM_DMABASE_CCR1 TIM_DMABASE_CCR2 TIM_DMABASE_CCR3 TIM_DMABASE_CCR4 2 DocID027328 Rev 1166 539 /

540 HAL UM1850 TIM Generic Driver TIM_DMABASE_BDTR TIM_DMABASE_DCR TIM DMA Burst Length TIM_DMABURSTLENGTH_1TRANSFER TIM_DMABURSTLENGTH_2TRANSFERS TIM_DMABURSTLENGTH_3TRANSFERS TIM_DMABURSTLENGTH_4TRANSFERS TIM_DMABURSTLENGTH_5TRANSFERS TIM_DMABURSTLENGTH_6TRANSFERS TIM_DMABURSTLENGTH_7TRANSFERS TIM_DMABURSTLENGTH_8TRANSFERS TIM_DMABURSTLENGTH_9TRANSFERS TIM_DMABURSTLENGTH_10TRANSFERS TIM_DMABURSTLENGTH_11TRANSFERS TIM_DMABURSTLENGTH_12TRANSFERS TIM_DMABURSTLENGTH_13TRANSFERS TIM_DMABURSTLENGTH_14TRANSFERS TIM_DMABURSTLENGTH_15TRANSFERS TIM_DMABURSTLENGTH_16TRANSFERS TIM_DMABURSTLENGTH_17TRANSFERS TIM_DMABURSTLENGTH_18TRANSFERS TIM DMA Handle Index TIM_DMA_ID_UPDATE Index of the DMA handle used for Update DMA requests Index of the DMA handle used for Capture/Compare 1 TIM_DMA_ID_CC1 DMA requests TIM_DMA_ID_CC2 Index of the DMA handle used for Capture/Compare 2 DMA requests Index of the DMA handle used for Capture/Compare 3 TIM_DMA_ID_CC3 DMA requests TIM_DMA_ID_CC4 Index of the DMA handle used for Capture/Compare 4 DMA requests Index of the DMA handle used for Commutation DMA TIM_DMA_ID_COMMUTATION requests TIM_DMA_ID_TRIGGER f the DMA handle used for Trigger DMA requests Index o TIM DMA Sources TIM_DMA_UPDATE TIM_DMA_CC1 TIM_DMA_CC2 DocID027328 / 1166 540 Rev 2

541 UM1850 TIM Generic Driver HAL TIM_DMA_CC3 TIM_DMA_CC4 TIM_DMA_COM TIM_DMA_TRIGGER TIM Encoder Mode TIM_ENCODERMODE_TI1 TIM_ENCODERMODE_TI2 TIM_ENCODERMODE_TI12 TIM ETR Polarity TIM_ETRPOLARITY_INVERTED Polarity for ETR source Polarity for ETR source TIM_ETRPOLARITY_NONINVERTED TIM ETR Prescaler No prescaler is used TIM_ETRPRESCALER_DIV1 ETR input source is divided by 2 TIM_ETRPRESCALER_DIV2 TIM_ETRPRESCALER_DIV4 ETR input source is divided by 4 ETR input source is divided by 8 TIM_ETRPRESCALER_DIV8 TIM Event Source TIM_EVENTSOURCE_UPDATE TIM_EVENTSOURCE_CC1 TIM_EVENTSOURCE_CC2 TIM_EVENTSOURCE_CC3 TIM_EVENTSOURCE_CC4 TIM_EVENTSOURCE_COM TIM_EVENTSOURCE_TRIGGER TIM_EVENTSOURCE_BREAK TIM Exported Macros Description: __HAL_TIM_RESET_HANDLE_STATE Reset TIM handle state. Parameters: __HANDLE__: TIM handle. Return value: None Description: __HAL_TIM_ENABLE TIM peripheral. Enable the Parameters: __HANDLE__: TIM handle 2 DocID027328 Rev 1166 541 /

542 TIM Generic Driver HAL UM1850 Return value: None Description: __HAL_TIM_MOE_ENABLE Enable the TIM main Output. Parameters: __HANDLE__: TIM handle Return value: None Description: __HAL_TIM_DISABLE Disable the TIM peripheral. Parameters: __HANDLE__: TIM handle Return value: None Description: __HAL_TIM_MOE_DISABLE Disable the TIM main Output. Parameters: __HANDLE__: TIM handle Return value: None Notes: The Main Output Enable of a timer instance nd CCxN is disabled only if all the CCx a channels have been disabled Description: __HAL_TIM_MOE_DISABLE_UNCON DITIONALLY Disable the TIM main Output. Parameters: __HANDLE__: TIM handle Return value: None Notes: The Main Output Enable of a timer instance is disabled unconditionally Description: __HAL_TIM_ENABLE_IT Enables the specified TIM interrupt. Parameters: __HANDLE__: specifies the TIM Handle. DocID027328 / 1166 542 Rev 2

543 UM1850 TIM Generic Driver HAL __INTERRUPT__: specifies the TIM interrupt source to enable. This parameter can be one of the following values: TIM_IT_UPDATE: Update i nterrupt TIM_IT_CC1: Capture/Compare 1 interrupt TIM_IT_CC2: Capture/Compare 2 interrupt TIM_IT_CC3: Capture/Compare 3 interrupt TIM_IT_CC4: Capture/Compare 4 interrupt TIM_IT_COM: Commutation interrupt TIM_IT_TRIGGER: Trigger interrupt TIM_IT_BREAK: Break interrupt Return value: None Description: __HAL_TIM_DISABLE_IT Disables the specified TIM interrupt. Parameters: __HANDLE__: specifies the TIM Handle. __INTERRUPT__: specifies the TIM interrupt source to disable. This parameter can be one of the followin g values: TIM_IT_UPDATE: Update interrupt TIM_IT_CC1: Capture/Compare 1 interrupt TIM_IT_CC2: Capture/Compare 2 interrupt TIM_IT_CC3: Capture/Compare 3 interrupt TIM_IT_CC4: Capture/Compare 4 interrupt TIM_IT_COM: Commutation interrupt Trigger interrupt TIM_IT_TRIGGER: TIM_IT_BREAK: Break interrupt Return value: None Description: __HAL_TIM_ENABLE_DMA Enables the specified DMA request. Parameters: __HANDLE__: specifies the TIM Handle. __DMA__: specifies the TIM DMA request be one of the to enable. This parameter can following values: TIM_DMA_UPDATE: Update DMA request TIM_DMA_CC1: Capture/Compare 1 2 DocID027328 Rev 1166 543 /

544 HAL UM1850 TIM Generic Driver DMA request TIM_DMA_CC2: Capture/Compare 2 DMA request TIM_DMA_CC3: Capture/Compare 3 DMA request TIM_DMA_CC4: Capture/Compare 4 DMA request Commutation DMA TIM_DMA_COM: request TIM_DMA_TRIGGER: Trigger DMA request Return value: None Description: __HAL_TIM_DISABLE_DMA Disables the specified DMA request. Parameters: __HANDLE__: specifies the TIM Handle. __DMA__: specifies the TIM DMA request s parameter can be one of to disable. Thi the following values: TIM_DMA_UPDATE: Update DMA request TIM_DMA_CC1: Capture/Compare 1 DMA request TIM_DMA_CC2: Capture/Compare 2 DMA request TIM_DMA_CC3: Capture/Compare 3 DMA request TIM_DMA_CC4: Capture/Compare 4 DMA request TIM_DMA_COM: Commutation DMA request TIM_DMA_TRIGGER: Trigger DMA request Return value: None Description: __HAL_TIM_GET_FLAG Checks whether the specified TIM interrupt flag is set or not. Parameters: __HANDLE__: specifies the TIM Handle. __FLAG__: specifies the TIM interrupt flag to check. This parameter can be one of the following values: TIM_FLAG_UPDATE: Update interrupt flag TIM_FLAG_CC1: Capture/Compare 1 interrupt flag DocID027328 / 1166 544 Rev 2

545 UM1850 TIM Generic Driver HAL TIM_FLAG_CC2: Capture/Compare 2 interrupt flag ure/Compare 3 TIM_FLAG_CC3: Capt interrupt flag TIM_FLAG_CC4: Capture/Compare 4 interrupt flag TIM_FLAG_COM: Commutation interrupt flag TIM_FLAG_TRIGGER: Trigger interrupt flag TIM_FLAG_BREAK: Break interrupt flag TIM_FLAG_CC1OF: Capture/Compare 1 overcapture flag TIM_FLAG_CC2OF: Capture/Compare 2 overcapture flag TIM_FLAG_CC3OF: Capture/Compare 3 overcapture flag TIM_FLAG_CC4OF: Capture/Compare 4 overcapture flag Return value: The: new state of __FLAG__ (TRUE or FALSE). Description: __HAL_TIM_CLEAR_FLAG Clears the specified TIM interrupt flag. Parameters: __HANDLE__: specifies the TIM Handle. __FLAG__: specifies the TIM interrupt flag to clear. This parameter can be one of the following values: TIM_FLAG_UPDATE: Update interrupt flag TIM_FLAG_CC1: Capture/Compare 1 interrupt flag TIM_FLAG_CC2: Capture/Compare 2 interrupt flag TIM_FLAG_CC3: Capture/Compare 3 interrupt flag TIM_FLAG_CC4: Capture/Compare 4 interrupt flag TIM_FLAG_COM: Commutation interrupt flag TIM_FLAG_TRIGGER: Trigger interrupt flag TIM_FLAG_BREAK: Break interrupt flag TIM_FLAG_CC1OF: Capture/Compare 1 overcapture flag TIM_FLAG_CC2OF: Capture/Compare 2 overcapture flag TIM_FLAG_CC3OF: 2 DocID027328 Rev 1166 545 /

546 HAL UM1850 TIM Generic Driver Capture/Compare 3 overcapture flag TIM_FLAG_CC4OF: Capture/Compare 4 overcapture flag Return value: __FLAG__ (TRUE or The: new state of FALSE). Description: __HAL_TIM_GET_IT_SOURCE Checks whether the specified TIM interrupt has occurred or not. Parameters: __HANDLE__: TIM handle __INTERRUPT__: specifies the TIM interrupt source to check. Return value: The: state of TIM_ IT (SET or RESET). Description: __HAL_TIM_CLEAR_IT Clear the TIM interrupt pending bits. Parameters: __HANDLE__: TIM handle __INTERRUPT__: specifies the interrupt pending bit to clear. Return value: None Description: __HAL_TIM_IS_TIM_COUNTING_DO WN Indicates whether or not the TIM Counter is used as downcounter. Parameters: __HANDLE__: TIM handle. Return value: False: (Counter used as upcounter) or True (Counter used as downcounter) Notes: This macro is particularly usefull to get the counting mode w hen the timer operates in Center - aligned mode or Encoder mode. Description: __HAL_TIM_SET_PRESCALER Sets the TIM active prescaler register value on update event. Parameters: __HANDLE__: TIM handle. __PRESC__: specifies the active prescaler DocID027328 / 1166 546 Rev 2

547 HAL UM1850 TIM Generic Driver value. register new Return value: None Description: __HAL_TIM_SET_COMPARE Sets the TIM Capture Compare Register value on runtime without calling another time ConfigChannel function. Parameters: __HANDLE__: TIM handle. __CHANNEL__: : TIM Channels to be configured. This parameter can be one of the following values: TIM_CHANNEL_1: TIM Channel 1 selected TIM_CHANNEL_2: TIM Channel 2 selected TIM_CHANNEL_3: TIM Channel 3 selected TIM_CHANNEL_4: TIM Channel 4 selected __COMPARE__: specifies the Capture Compare register new value. Return value: None Description: __HAL_TIM_GET_COMPARE Gets the TIM Capture Compare Register value on runtime. Parameters: __HANDLE__: TIM handle. __CHANNEL__: : TIM Channel associated capture compare register This with the parameter can be one of the following values: TIM_CHANNEL_1: get capture/compare 1 register value TIM_CHANNEL_2: get capture/compare 2 register value TIM_CHANNEL_3: get capture/compare 3 register value TIM_CHANNEL_4: get ture/compare 4 register value cap Return value: bit value of the bit: or 32 16 - - capture/compare register (TIMx_CCRy) Description: __HAL_TIM_SET_COUNTER Sets the TIM Counter Register value on 2 DocID027328 Rev 1166 547 /

548 HAL UM1850 TIM Generic Driver runtime. Parameters: __HANDLE__: TIM handle. __COUNTER__: specifies the Counter register new value. Return value: None Description: __HAL_TIM_GET_COUNTER Gets the TIM Counter Register value on runtime. Parameters: __HANDLE__: TIM handle. Return value: bit value of the timer counter - bit: or 32 - 16 register (TIMx_CNT) Description: __HAL _TIM_SET_AUTORELOAD Sets the TIM Autoreload Register value on runtime without calling another time any Init function. Parameters: __HANDLE__: TIM handle. __AUTORELOAD__: specifies the Counter register new value. Return value: None Description: __HAL_TIM_GET_AUTORELOAD Gets the TIM Autoreload Register value on runtime. Parameters: __HANDLE__: TIM handle. Return value: bit value of the timer - bit or 32 - @retval: 16 auto reload register(TIMx_ARR) - Description: __HAL_TIM_SET_CLOCKDIVISION Sets the TIM Clock Division value on runtime without calling another time any Init function. Parameters: __HANDLE__: TIM handle. __CKD__: specifies the clock division value. This parameter can be one of the DocID027328 / 1166 548 Rev 2

549 UM1850 TIM Generic Driver HAL following value: TIM_CLOCKDIVISION_DIV1: tDTS=tCK_INT TIM_CLOCKDIVISION_DIV2: tDTS=2*tCK_INT TIM_CLOCKDIVISION_DIV4: tDTS=4*tCK_INT Return value: None Description: __HAL_TIM_GET_CLOCKDIVISION Gets the TIM Clock Division value on runtime. Parameters: __HANDLE__: TIM handle. Return value: The: clo ck division can be one of the following values: TIM_CLOCKDIVISION_DIV1: tDTS=tCK_INT TIM_CLOCKDIVISION_DIV2: tDTS=2*tCK_INT TIM_CLOCKDIVISION_DIV4: tDTS=4*tCK_INT Description: __HAL_TIM_SET_ICPRESCALER Sets the TIM Input Capture prescaler on without calling another time runtime Parameters: __HANDLE__: TIM handle. __CHANNEL__: : TIM Channels to be configured. This parameter can be one of the following values: TIM_CHANNEL_1: TIM Channel 1 selected TIM_CHANNEL_2: TIM Channel 2 selected TIM_CHANNEL_3: TI M Channel 3 selected TIM_CHANNEL_4: TIM Channel 4 selected __ICPSC__: specifies the Input Capture4 prescaler new value. This parameter can be one of the following values: TIM_ICPSC_DIV1: no prescaler TIM_ICPSC_DIV2: capture is done once every 2 events _ICPSC_DIV4: capture is done TIM once every 4 events TIM_ICPSC_DIV8: capture is done 2 DocID027328 Rev 1166 549 /

550 TIM Generic Driver HAL UM1850 once every 8 events Return value: None Description: __HAL_TIM_GET_ICPRESCALER Gets the TIM Input Capture prescaler on runtime. Parameters: __HANDLE__: TIM handle. __CHANNEL__: TIM Channels to be configured. This parameter can be one of the following values: TIM_CHANNEL_1: get input capture 1 prescaler value TIM_CHANNEL_2: get input capture 2 prescaler value TIM_CHANNEL_3: get input capture 3 prescaler value TIM_CHA NNEL_4: get input capture 4 prescaler value Return value: The: input capture prescaler can be one of the following values: TIM_ICPSC_DIV1: no prescaler TIM_ICPSC_DIV2: capture is done once every 2 events TIM_ICPSC_DIV4: capture is done once every 4 events TIM_ICPSC_DIV8: capture is done once every 8 events Description: __HAL_TIM_URS_ENABLE Set the Update Request Source (URS) bit of the TIMx_CR1 register. Parameters: __HANDLE__: TIM handle. Return value: None Notes: When the USR bit of the TIMx_CR1 register is set, only counter overflow/underflow generates an update interrupt or DMA request (if enabled) Description: __HAL_TIM_URS_DISABLE Reset the Update Request Source (URS) bit of the TIMx_CR1 register. DocID027328 / 1166 550 Rev 2

551 HAL UM1850 TIM Generic Driver Parameters: __HANDLE__: TIM handle. Return va lue: None Notes: When the USR bit of the TIMx_CR1 register is reset, any of the following events generate an update interrupt or DMA request (if enabled): (+) Counter overflow/underflow (+) Setting the UG bit (+) Update generation through the slave ntroller mode co Description: __HAL_TIM_SET_CAPTUREPOLARIT Y Sets the TIM Capture x input polarity on runtime. Parameters: __HANDLE__: TIM handle. __CHANNEL__: TIM Channels to be configured. This parameter can be one of the following values: TIM_CHANNEL_1: TIM Channel 1 selected TIM_CHANNEL_2: TIM Channel 2 selected TIM_CHANNEL_3: TIM Channel 3 selected TIM_CHANNEL_4: TIM Channel 4 selected __POLARITY__: Polarity for TIx source TIM_INPUTCHANNELPOLARITY_RIS ING: Rising Edge TIM_INPUTCHANNELPOLARITY_FA ng Edge LLING: Falli TIM_INPUTCHANNELPOLARITY_BO THEDGE: Rising and Falling Edge Return value: None Notes: The polarity TIM_INPUTCHANNELPOLARITY_BOTHE DGE is not authorized for TIM Channel 4. TIM Flag Definition TIM_FLAG_UPDATE TIM_FLAG_CC1 TIM_FLAG_CC2 2 DocID027328 Rev 1166 551 /

552 HAL TIM Generic Driver UM1850 TIM_FLAG_CC3 TIM_FLAG_CC4 TIM_FLAG_COM TIM_FLAG_TRIGGER TIM_FLAG_BREAK TIM_FLAG_CC1OF TIM_FLAG_CC2OF TIM_FLAG_CC3OF TIM_FLAG_CC4OF TIM Input Capture Polarity TIM_ICPOLARITY_RISING TIM_ICPOLARITY_FALLING TIM Input Capture Prescaler TIM_ICPSC_DIV1 Capture performed each time an edge is detected on the capture input Capture performed once every 2 events TIM_ICPSC_DIV2 TIM_ICPSC_DIV4 Capture performed once every 4 events Capture performed once every 8 events TIM_ICPSC_DIV8 TIM I nput Capture Selection TIM_ICSELECTION_DIRECTTI TIM Input 1, 2, 3 or 4 is selected to be connected to IC1, IC2, IC3 or IC4, respectively TIM_ICSELECTION_INDIRECTTI TIM Input 1, 2, 3 or 4 is selected to be connected to IC2, IC1, IC4 or IC3, respectively TIM_ICSELECTION_TRC TIM Input 1, 2, 3 or 4 is selected to be connected to TRC TIM Input Channel Polarity TIM_INPUTCHANNELPOLARITY_RISING Polarity for TIx source TIM_INPUTCHANNELPOLARITY_FALLING Polarity for TIx source GE Polarity for TIx source TIM_INPUTCHANNELPOLARITY_BOTHED TIM Interrupt Definition TIM_IT_UPDATE TIM_IT_CC1 TIM_IT_CC2 TIM_IT_CC3 TIM_IT_CC4 TIM_IT_COM TIM_IT_TRIGGER TIM_IT_BREAK DocID027328 / 1166 552 Rev 2

553 UM1850 TIM Generic Driver HAL TIM Lock level TIM_LOCKLEVEL_OFF TIM_LOCKLEVEL_1 TIM_LOCKLEVEL_2 TIM_LOCKLEVEL_3 TIM Master Mode Selection TIM_TRGO_RESET TIM_TRGO_ENABLE TIM_TRGO_UPDATE TIM_TRGO_OC1 TIM_TRGO_OC1REF TIM_TRGO_OC2REF TIM_TRGO_OC3REF TIM_TRGO_OC4REF TIM Master Slave Mode TIM_MASTERSLAVEMODE_ENABLE TIM_MASTERSLAVEMODE_DISABLE Pulse Mode TIM One TIM_OPMODE_SINGLE TIM_OPMODE_REPETITIVE TIM OSSI Off State Selection for Idle mode state TIM_OSSI_ENABLE TIM_OSSI_DISABLE TIM OSSR Off State Selection for Run mode state TIM_OSSR_ENABLE TIM_OSSR_DISABLE TIM Output Compare and PWM modes TIM_OCMODE_TIMING TIM_OCMODE_ACTIVE TIM_OCMODE_INACTIVE TIM_OCMODE_TOGGLE TIM_OCMODE_PWM1 TIM_OCMODE_PWM2 TIM_OCMODE_FORCED_ACTIVE TIM_OCMODE_FORCED_INACTIVE TIM Output Compare Idle State 2 DocID027328 Rev 1166 553 /

554 HAL UM1850 TIM Generic Driver TIM_OCIDLESTATE_SET TIM_OCIDLESTATE_RESET TIM Complementary Output Compare Idle State TIM_OCNIDLESTATE_SET TIM_OCNIDLESTATE_RESET TIM Complementary Output Compare Polarity TIM_OCNPOLARITY_HIGH TIM_OCNPOLARITY_LOW TIM Complementary Output Compare State TIM_OUTPUTNSTATE_DISABLE TIM_OUTPUTNSTATE_ENABLE TIM Output Compare Polarity TIM_OCPOLARITY_HIGH TIM_OCPOLARITY_LOW TIM Output Compare State TIM_OUTPUTSTATE_DISABLE TIM_OUTPUTSTATE_ENABLE TIM Output Fast State TIM_OCFAST_DISABLE TIM_OCFAST_ENABLE TIM Slave Mode TIM_SLAVEMODE_DISABLE TIM_SLAVEMODE_RESET TIM_SLAVEMODE_GATED TIM_SLAVEMODE_TRIGGER TIM_SLAVEMODE_EXTERNAL1 TIM TI1 Input Selection TIM_TI1SELECTION_CH1 TIM_TI1SELECTION_XORCOMBINATION TIM Trigger Polarity Polarity for ETRx trigger sources TIM_TRIGGERPOLARITY_INVERTED Polarity for ETRx trigger sources TIM_TRIGGERPOLARITY_NONINVERTED TIM_TRIGGERPOLARITY_RISING Polarity for TIxFPx or TI1_ED trigger sources Polarity for TIxFPx or TI1_ED trigger TIM_TRIGGERPOLARITY_FALLING sources TIM_TRIGGERPOLARITY_BOTHEDGE Polarity for TIxFPx or TI1_ED trigger DocID027328 / 1166 554 Rev 2

555 UM1850 TIM Generic Driver HAL sources TIM Trigger Prescaler TIM_TRIGGERPRESCALER_DIV1 No prescaler is used TIM_TRIGGERPRESCALER_DIV2 Prescaler for External ETR Trigger: Capture performed once every 2 events. TIM_TRIGGERPRESCALER_DIV4 Prescaler for External ETR Trigger: Capture performed once every 4 events. TIM_TRIGGERPRESCALER_DIV8 Prescaler for External ETR Trigger: Capture performed once every 8 events. TIM Trigger Selection TIM_TS_ITR0 TIM_TS_ITR1 TIM_TS_ITR2 TIM_TS_ITR3 TIM_TS_TI1F_ED TIM_TS_TI1FP1 TIM_TS_TI2FP2 TIM_TS_ETRF TIM_TS_NONE 2 DocID027328 Rev 1166 555 /

556 TIM Extension Driver HAL UM1850 42 HAL TIM Extension Driver 42.1 TIMEx Firmware driver registers structures 42.1.1 TIM_HallSensor_InitTypeDef Data Fields uint32_t IC1Polarity uint32_t IC1Prescaler uint32_t IC1Filter uint32_t Commutation_Delay Field Documentation uint32_t TIM_HallSensor_InitTypeDef::IC1Polarity es the active edge of the input signal. This parameter can be a value of Specifi TIM_Input_Capture_Polarity uint32_t TIM_HallSensor_InitTypeDef::IC1Prescaler Specifies the Input Capture Prescaler. This parameter can be a value of TIM_Input_Capture_Prescaler uint32_t TIM_HallSensor_InitTypeDef::IC1Filter Specifies the input capture filter. This parameter can be a number between Min_Data = 0x0 and Max_Data = 0xF mmutation_Delay uint32_t TIM_HallSensor_InitTypeDef::Co Specifies the pulse value to be loaded into the Capture Compare Register. This parameter can be a number between Min_Data = 0x0000 and Max_Data = 0xFFFF 42.1.2 TIM_BreakDeadTimeConfigTypeDef Data Fields uint32_t OffStateRunMode uint32_t OffStateIDLEMode uint32_t LockLevel uint32_t DeadTime uint32_t BreakState uint32_t BreakPolarity uint32_t AutomaticOutput Field Documentation uint32_t TIM_BreakDeadTimeConfigTypeDef::OffStateRunMode TIM off sta te in run mode This parameter can be a value of TIM_OSSR_Off_State_Selection_for_Run_mode_state uint32_t TIM_BreakDeadTimeConfigTypeDef::OffStateIDLEMode TIM off state in IDLE mode This parameter can be a value of TIM_OSSI_Off_State_Selection_for_Idle_mode_state uint32_t TIM_BreakDeadTimeConfigTypeDef::LockLevel TIM Lock level This parameter can be a value of TIM_Lock_level TIM_BreakDeadTimeConfigTypeDef::DeadTime uint32_t TIM dead Time This parameter can be a number between Min_Data = 0x00 and Max_Data = 0xFF uint32_t TIM_BreakDeadTimeConfigTypeDef::BreakState TIM_Break_Input_enable_disable TIM Break State This parameter can be a value of DocID027328 / 1166 556 Rev 2

557 UM1850 TIM Extension Driver HAL uint32_t TIM_BreakDeadTimeConfigTypeDef::BreakPolarity TIM_Break_Polarity TIM Break input polarity This parameter can be a value of uint32_t TIM_BreakDeadTimeConfigTypeDef::AutomaticO utput TIM Automatic Output Enable state This parameter can be a value of TIM_AOE_Bit_Set_Reset 42.1.3 TIM_MasterConfigTypeDef Data Fields uint32_t MasterOutputTrigger uint32_t Master SlaveMode Field Documentation uint32_t TIM_MasterConfigTypeDef::MasterOutputTrigger Trigger output (TRGO) selection This parameter can be a value of TIM_Master_Mode_Selection e uint32_t TIM_MasterConfigTypeDef::MasterSlaveMod Master/slave mode selection This parameter can be a value of TIM_Master_Slave_Mode TIMEx Firmware driver API description 42.2 42.2.1 TIMER Extended features The Timer Extended features include: 1. - time for : Complementary outputs with programmable dead Output Compare aligned Mode) - PWM generation (Edge and Center One - pulse mode output 2. Synchronization circuit to control the timer with external si gnals and to interconnect several timers together. 3. Break input to put the timer output signals in reset state or in a known state. - sensor circuitry for positioning 4. Supports incremental (quadrature) encoder and hall purposes 42.2.2 How to use this driver 1. Initialize the TIM low level resources by implementing the following functions depending from feature used : Complementary Output Compare : HAL_TIM_OC_MspInit() Complementary PWM generation : HAL_TIM_PWM_MspI nit() pulse mode output : HAL_TIM_OnePulse_MspInit() - Complementary One Hall Sensor output : HAL_TIMEx_HallSensor_MspInit() Initialize the TIM low level resources : 2. a. Enable the TIM interface clock using __HAL_RCC_TIMx_CLK_ENABLE(); b. TIM pins configuration Enable the clock for the TIM GPIOs using the following function: __HAL_RCC_GPIOx_CLK_ENABLE(); Configure these TIM pins in Alternate function mode using HAL_GPIO_Init(); The external Clock can be configured, if needed (the default clock is the internal cl ock 3. from the APBx), using the following function: HAL_TIM_ConfigClockSource, the clock configuration should be done before any start function. 4. Configure the TIM in the desired functioning mode using one of the initialization function of this driver: 2 DocID027328 Rev 1166 557 /

558 HAL UM1850 TIM Extension Driver TIMEx_HallSensor_Init and HAL_TIMEx_ConfigCommutationEvent: to use HAL_ the Timer Hall Sensor Interface and the commutation event with the corresponding Interrupt and DMA request if needed (Note that One Timer is used to interface with the Hall sensor Interface and another Timer should be used to use the commutation event). Activate the TIM peripheral using one of the start functions: 5. Complementary Output Compare : HAL_TIMEx_OCN_Start(), HAL_TIMEx_OCN_Start_DMA(), HAL_TIMEx_OCN_Start_IT() eration : HAL_TIMEx_PWMN_Start(), Complementary PWM gen HAL_TIMEx_PWMN_Start_DMA(), HAL_TIMEx_PWMN_Start_IT() Complementary One - pulse mode output : HAL_TIMEx_OnePulseN_Start(), HAL_TIMEx_OnePulseN_Start_IT() Hall Sensor output : HAL_TIMEx_HallSensor_Start(), r_Start_DMA(), HAL_TIMEx_HallSensor_Start_IT(). HAL_TIMEx_HallSenso Timer Hall Sensor functions 42.2.3 This section provides functions allowing to: Initialize and configure TIM HAL Sensor. initialize TIM HAL Sensor. - De the Hall Sensor Interface. Start Stop the Hall Sensor Interface. Start the Hall Sensor Interface and enable interrupts. Stop the Hall Sensor Interface and disable interrupts. Start the Hall Sensor Interface and enable DMA transfers. e and disable DMA transfers. Stop the Hall Sensor Interfac This section contains the following APIs: HAL_TIMEx_HallSensor_Init() HAL_TIMEx_HallSensor_DeInit() HAL_TIMEx_HallSensor_MspIni t() HAL_TIMEx_HallSensor_MspDeInit() HAL_TIMEx_HallSensor_Start() HAL_TIMEx_HallSensor_Stop() HAL_TIMEx_HallSensor_Start_IT() HAL_TIMEx_HallSensor_Stop_IT() HAL_TIMEx_HallSensor_Start_DMA() HAL_TIMEx_HallSensor_Stop_DMA() mpare functions Timer Complementary Output Co 42.2.4 This section provides functions allowing to: Start the Complementary Output Compare/PWM. Stop the Complementary Output Compare/PWM. e/PWM and enable interrupts. Start the Complementary Output Compar Stop the Complementary Output Compare/PWM and disable interrupts. Start the Complementary Output Compare/PWM and enable DMA transfers. Stop the Complementary Output Compare/PWM and disable DMA transfers. the following APIs: This section contains HAL_TIMEx_OCN_Start() HAL_TIMEx_OCN_Stop() HAL_TIMEx_OCN_Start_IT() DocID027328 / 1166 558 Rev 2

559 UM1850 TIM Extension Driver HAL HAL_TIMEx_OCN_Stop_IT() HAL_TIMEx_OCN_Start_DMA() HAL_TIMEx_OCN_Stop_DMA() 42.2.5 Timer Complementary PWM functions This section provides functions allowing to: tart the Complementary PWM. S Stop the Complementary PWM. Start the Complementary PWM and enable interrupts. Stop the Complementary PWM and disable interrupts. Start the Complementary PWM and enable DMA transfers. Stop the Complementary PWM and disable DMA t ransfers. Start the Complementary Input Capture measurement. Stop the Complementary Input Capture. Start the Complementary Input Capture and enable interrupts. Stop the Complementary Input Capture and disable interrupts. Capture and enable DMA transfers. Start the Complementary Input Stop the Complementary Input Capture and disable DMA transfers. Start the Complementary One Pulse generation. Stop the Complementary One Pulse. Start the Complementary One Pulse and enable interrupts. Stop the Complementar y One Pulse and disable interrupts. This section contains the following APIs: HAL_TIMEx_PWMN_Start() HAL_TIMEx_PWMN_Stop() HAL_TIMEx_PWMN_Start_IT() HAL_TIMEx_PWMN_Stop_IT() HAL_TIMEx_PWMN_Start_DMA() HAL_TIMEx_PWMN_Stop_DMA() 42.2.6 Timer Complementary One Pulse functions This section provides functions allowing to: Start the Complementary One Pulse generation. Stop the Complementary One Pulse. Start the Complementary One Pulse and enable interrupts. Stop the Complementary One Pulse and disable inte rrupts. This section contains the following APIs: HAL_TIMEx_OnePulseN_Start() HAL_TIMEx_OnePulseN_Stop() HAL_TIMEx_OnePulseN_Start_IT() HAL_TIMEx_OnePulseN_Stop_IT() Peripheral Control functions 42.2.7 This section provides functions allowing to: Configure the commutation event in case of use of the Hall sensor interface. gure Complementary channels, break features and dead time. Confi Configure Master synchronization. 2 DocID027328 Rev 1166 559 /

560 HAL TIM Extension Driver UM1850 This section contains the following APIs: HAL_TIMEx_ConfigCommutationEvent() HAL_TIMEx_ConfigCommutationEvent_IT() HAL_TIMEx_ConfigCommutationEvent_DMA() HAL_TIMEx_ConfigBreakDeadTime() HAL_TIMEx_MasterConfigSynchronization() 42.2.8 Extensio n Callbacks functions This section provides Extension TIM callback functions: Timer Commutation callback Timer Break callback This section contains the following APIs: HAL_TIMEx_CommutationCallback() HAL_TIMEx_BreakCallback() TIMEx_DMACommutationCplt() 42.2.9 Extension Peripheral State functions time the status of the peripheral and the data flow. - This subsection permit to get in run This section contains the following APIs: HAL_TIMEx_HallSensor_GetState() Detailed description of function s 42.2.10 HAL_TIMEx_HallSensor_Init HAL_StatusTypeDef HAL_TIMEx_HallSensor_Init Function name (TIM_HandleTypeDef * htim, TIM_HallSensor_InitTypeDef * sConfig) Function description Initializes the TIM Hall Sensor Interfac e and create the associated handle. Parameters : TIM Encoder Interface handle htim: : TIM Hall Sensor configuration structure sConfig: Return values HAL: status HAL_TIMEx_HallSensor_DeInit HAL_StatusTypeDef HAL_TIMEx_HallSensor_DeInit Function name (TIM_HandleTypeDef * htim) Function description DeInitializes the TIM Hall Sensor interface. Parameters : TIM Hall Sensor handle htim: Return values status HAL: HAL_TIMEx_HallSensor_MspInit void HAL_TIMEx_HallSensor_MspInit (TIM_HandleTypeDef * Function name htim) DocID027328 / 1166 560 Rev 2

561 UM1850 TIM Extension Driver HAL Initializes the TIM Hall Sensor MSP. Function description Parameters : TIM handle htim: Return values None: HAL_TIMEx_HallSensor_MspDeInit void HAL_TIMEx_HallSensor_MspDeInit (TIM_HandleTypeDef Function name * htim) ion description Funct DeInitializes TIM Hall Sensor MSP. Parameters : TIM handle htim: Return values None: HAL_TIMEx_HallSensor_Start HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start Function name (TIM_HandleTypeDef * htim) Starts the TIM Hall Sensor Interface. Function description Parameters htim: : TIM Hall Sensor handle Return values status HAL: HAL_TIMEx_HallSensor_Stop HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop Function name (TIM_HandleTypeDef * htim) Function description Stops the TIM Hall sensor Interface. Parameters htim: : TIM Hall Sensor handle Return values HAL: status HAL_TIMEx_HallSensor_Start_IT HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start_IT Function name (TIM_HandleTypeDef * htim) ts the TIM Hall Sensor Interface in interrupt mode. Star Function description Parameters htim: : TIM Hall Sensor handle Return values HAL: status HAL_TIMEx_HallSensor_Stop_IT HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_IT Function name (TIM_HandleTypeDef * htim) Function description Stops the TIM Hall Sensor Interface in interrupt mode. Parameters htim: : TIM handle Return values status HAL: 2 DocID027328 Rev 1166 561 /

562 Driver HAL UM1850 TIM Extension HAL_TIMEx_HallSensor_Start_DMA HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start_DMA Function name (TIM_HandleTypeDef * htim, uint32_t * pData, uint16_t Length) Function description Starts the TIM Hall Sensor Interface in DMA mode. Parameters : TIM Hall Sensor handle htim: pData: : The destination Buffer address. Length: : The length of data to be transferred from TIM perip heral to memory. Return values status HAL: HAL_TIMEx_HallSensor_Stop_DMA HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_DMA Function name (TIM_HandleTypeDef * htim) Stops the TIM Hall Sensor Interface in DMA mode. Function description Parameters htim: : TIM handle Return values status HAL: HAL_TIMEx_OCN_Start HAL_StatusTypeDef HAL_TIMEx_OCN_Start Function name (TIM_HandleTypeDef * htim, uint32_t Channel) Function description Starts the TIM Output Compare signal generation on the complementary output. Parameters htim: : TIM Output Compare handle : TIM Channel to be enabled This parameter can Channel: be one of the following values: TIM_CHANNEL_1: TIM Channel 1 selected TIM_CHANNEL_2: TIM Channel 2 selected TIM_CHANNEL_3: TIM Channel 3 selected TIM_CHANNEL_4: TIM Channel 4 selected Return values HAL: status HAL_TIMEx_OCN_Stop HAL_StatusTypeDef HAL_TIMEx_OCN_Stop Function name (TIM_HandleTypeDef * htim, uint32_t Channel ) Stops the TIM Output Compare signal generation on the Function description complementary output. Parameters : TIM handle htim: : TIM Channel to be disabled This parameter can Channel: be one of the following values: ected TIM_CHANNEL_1: TIM Channel 1 sel TIM_CHANNEL_2: TIM Channel 2 selected TIM_CHANNEL_3: TIM Channel 3 selected TIM_CHANNEL_4: TIM Channel 4 selected DocID027328 / 1166 562 Rev 2

563 UM1850 HAL TIM Extension Driver Return values status HAL: HAL_TIMEx_OCN_Start_IT HAL_StatusTypeDef HAL_TIMEx_OCN_Start_IT Function name (TIM_HandleTypeDef * htim, uint32_t Channel) Function description Starts the TIM Output Compare signal generation in interrupt mode on the complementary output. Parameters htim: : TIM OC handle : TIM Channel to be enabled This parameter can Channel: be one of the following valu es: TIM_CHANNEL_1: TIM Channel 1 selected TIM_CHANNEL_2: TIM Channel 2 selected TIM_CHANNEL_3: TIM Channel 3 selected TIM_CHANNEL_4: TIM Channel 4 selected Return values status HAL: HAL_TIMEx_OCN_Stop_IT HAL_StatusTypeDef HAL_TIMEx_OCN_Stop_IT Function name (TIM_HandleTypeDef * htim, uint32_t Channel) Stops the TIM Output Compare signal generation in interrupt mode Function description on the complementary output. Parameters htim: : TIM Output Compare handle Channel: o be disabled This parameter can : TIM Channel t be one of the following values: TIM_CHANNEL_1: TIM Channel 1 selected TIM_CHANNEL_2: TIM Channel 2 selected TIM_CHANNEL_3: TIM Channel 3 selected TIM_CHANNEL_4: TIM Channel 4 selected Return values HAL: status HAL_TIMEx_OCN_Start_DMA HAL_StatusTypeDef HAL_TIMEx_OCN_Start_DMA Function name (TIM_HandleTypeDef * htim, uint32_t Channel, uint32_t * pData, uint16_t Length) Function description Starts the TIM Output Compare signal generation in DMA mode on the complem entary output. Parameters : TIM Output Compare handle htim: Channel: : TIM Channel to be enabled This parameter can be one of the following values: TIM_CHANNEL_1: TIM Channel 1 selected TIM_CHANNEL_2: TIM Channel 2 selected 3 selected TIM_CHANNEL_3: TIM Channel TIM_CHANNEL_4: TIM Channel 4 selected : The source Buffer address. pData: : The length of data to be transferred from memory Length: to TIM peripheral 2 DocID027328 Rev 1166 563 /

564 HAL TIM Extension Driver UM1850 Return values status HAL: HAL_TIMEx_OCN_Stop_DMA x_OCN_Stop_DMA HAL_StatusTypeDef HAL_TIME Function name (TIM_HandleTypeDef * htim, uint32_t Channel) Function description Stops the TIM Output Compare signal generation in DMA mode on the complementary output. Parameters htim: : TIM Output Compare handle : TIM Channel to be disabled This parameter can Channel: be one of the following values: TIM_CHANNEL_1: TIM Channel 1 selected TIM_CHANNEL_2: TIM Channel 2 selected TIM_CHANNEL_3: TIM Channel 3 selected TIM_CHANNEL_4: TIM Channel 4 selected Return values status HAL: HAL_TIMEx_PWMN_Start HAL_StatusTypeDef HAL_TIMEx_PWMN_Start Function name (TIM_HandleTypeDef * htim, uint32_t Channel) Starts the PWM signal generation on the complementary output. Function description Parameters : TIM handle htim: : TIM Channel to be enabled This parameter can Channel: be one of the following values: TIM_CHANNEL_1: TIM Channel 1 selected TIM_CHANNEL_2: TIM Channel 2 selected TIM_CHANNEL_3: TIM Channel 3 selected TIM_CHANNEL_4: TIM Channel 4 selected Return values atus HAL: st HAL_TIMEx_PWMN_Stop HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop Function name (TIM_HandleTypeDef * htim, uint32_t Channel) Function description Stops the PWM signal generation on the complementary output. Parameters : TIM handle htim: : TIM Channel to be disabled This parameter can Channel: be one of the following values: TIM_CHANNEL_1: TIM Channel 1 selected TIM_CHANNEL_2: TIM Channel 2 selected TIM_CHANNEL_3: TIM Channel 3 selected TIM_CHANNEL_4: TIM Channel 4 selected Return values tatus s HAL: HAL_TIMEx_PWMN_Start_IT HAL_StatusTypeDef HAL_TIMEx_PWMN_Start_IT Function name 1166 DocID027328 / Rev 2 564

565 UM1850 TIM Extension Driver HAL (TIM_HandleTypeDef * htim, uint32_t Channel) Function description Starts the PWM signal generation in interrupt mode on the complementary output. Parameters : htim: TIM handle : TIM Channel to be disabled This parameter can Channel: be one of the following values: TIM_CHANNEL_1: TIM Channel 1 selected TIM_CHANNEL_2: TIM Channel 2 selected TIM_CHANNEL_3: TIM Channel 3 selected TIM_CHANNEL_4: TIM Channel 4 selected Return values status HAL: HAL_TIMEx_PWMN_Stop_IT HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop_IT Function name (TIM_HandleTypeDef * htim, uint32_t Channel) Stops the PWM signal generation in interrupt mode on the Function description complementary output. rameters Pa : TIM handle htim: : TIM Channel to be disabled This parameter can Channel: be one of the following values: TIM_CHANNEL_1: TIM Channel 1 selected TIM_CHANNEL_2: TIM Channel 2 selected TIM_CHANNEL_3: TIM Channel 3 selected TIM_CHANNEL_4: TIM Channel 4 selected Return values HAL: status HAL_TIMEx_PWMN_Start_DMA HAL_StatusTypeDef HAL_TIMEx_PWMN_Start_DMA Function name (TIM_HandleTypeDef * htim, uint32_t Channel, uint32_t * pData, uint16_t Length) l generation in DMA mode on the Function description Starts the TIM PWM signa complementary output. Parameters htim: : TIM handle Channel: : TIM Channel to be enabled This parameter can be one of the following values: TIM_CHANNEL_1: TIM Channel 1 selected TIM_CHANNEL_2: TIM Channel 2 selected TIM_CHANNEL_3: TIM Channel 3 selected TIM_CHANNEL_4: TIM Channel 4 selected : The source Buffer address. pData: : The length of data to be transferred from memory Length: to TIM peripheral Return values HAL: status 2 DocID027328 Rev 1166 565 /

566 HAL UM1850 TIM Extension Driver HAL_TIMEx_PWMN_Stop_DMA HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop_DMA Function nam e (TIM_HandleTypeDef * htim, uint32_t Channel) Function description Stops the TIM PWM signal generation in DMA mode on the complementary output. Parameters : TIM handle htim: : TIM Channel to be disabled This parameter can Channel: be one of the following values: TIM_CHANNEL_1: TIM Channel 1 selected TIM_CHANNEL_2: TIM Channel 2 selected TIM_CHANNEL_3: TIM Channel 3 selected TIM_CHANNEL_4: TIM Channel 4 selected Return values HAL: status HAL_TIMEx_OnePulseN_Start HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Start Function name (TIM_HandleTypeDef * htim, uint32_t OutputChannel) Starts the TIM One Pulse signal generation on the complemetary Function description output. Parameters : TIM One Pulse handle htim: OutputChannel: : TIM Channel to be enabled This parameter can be one of the following values: TIM_CHANNEL_1: TIM Channel 1 selected TIM_CHANNEL_2: TIM Channel 2 selected Return values status HAL: HAL_TIMEx_OnePulseN_Stop HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Stop Functi on name (TIM_HandleTypeDef * htim, uint32_t OutputChannel) Function description Stops the TIM One Pulse signal generation on the complementary output. Parameters htim: : TIM One Pulse handle OutputChannel: : TIM Channel to be disabled This parameter can be one of the following values: TIM_CHANNEL_1: TIM Channel 1 selected TIM_CHANNEL_2: TIM Channel 2 selected Return values status HAL: HAL_TIMEx_OnePulseN_Start_IT x_OnePulseN_Start_IT HAL_StatusTypeDef HAL_TIME Function name (TIM_HandleTypeDef * htim, uint32_t OutputChannel) Starts the TIM One Pulse signal generation in interrupt mode on Function description the complementary channel. Parameters htim: : TIM One Pulse handle DocID027328 / 1166 566 Rev 2

567 UM1850 TIM Extension Driver HAL l to be enabled This : TIM Channe OutputChannel: parameter can be one of the following values: TIM_CHANNEL_1: TIM Channel 1 selected TIM_CHANNEL_2: TIM Channel 2 selected Return values status HAL: HAL_TIMEx_OnePulseN_Stop_IT HAL_TIMEx_OnePulseN_Stop_IT HAL_StatusTypeDef Function name (TIM_HandleTypeDef * htim, uint32_t OutputChannel) Stops the TIM One Pulse signal generation in interrupt mode on Function description the complementary channel. Parameters : TIM One Pulse handle htim: : TIM Channel to be disabled This OutputChannel: parameter can be one of the following values: TIM_CHANNEL_1: TIM Channel 1 selected TIM_CHANNEL_2: TIM Channel 2 selected Return values status HAL: HAL_TIMEx_ConfigCommutationEvent HAL_StatusTypeDef HAL_TIMEx_ConfigCommutationEvent Function name (TIM_HandleTypeDef * htim, uint32_t InputTrigger, uint32_t CommutationSource) Configure the TIM commutation event sequence. Function description Parameters htim: : TIM handle : the Internal trigger corres ponding to the InputTrigger: Timer Interfacing with the Hall sensor This parameter can be one of the following values: TIM_TS_ITR0: Internal trigger 0 selected TIM_TS_ITR1: Internal trigger 1 selected TIM_TS_ITR2: Internal trigger 2 selected er 3 selected TIM_TS_ITR3: Internal trigg TIM_TS_NONE: No trigger is needed : the Commutation Event source This CommutationSource: parameter can be one of the following values: TIM_COMMUTATION_TRGI: Commutation source is the TRGI of the Interface Timer Commutation TIM_COMMUTATION_SOFTWARE: source is set by software using the COMG bit Return values status HAL: Notes : this function is mandatory to use the commutation event in order to update the configuration at each commutation detection on the TRGI input of the Timer, the typ ical use of this feature is with the use of another Timer(interface Timer) configured in Hall sensor interface, this interface Timer will generate the commutation at its TRGO output (connected to Timer used in this function) each time the TI1 of the Interf ace Timer detect a commutation at its input TI1. 2 DocID027328 Rev 1166 567 /

568 HAL TIM Extension Driver UM1850 HAL_TIMEx_ConfigCommutationEvent_IT HAL_StatusTypeDef Function name HAL_TIMEx_ConfigCommutationEvent_IT (TIM_HandleTypeDef * htim, uint32_t InputTrigger, uint32_t CommutationSource) Function description Co nfigure the TIM commutation event sequence with interrupt. Parameters htim: : TIM handle : the Internal trigger corresponding to the InputTrigger: Timer Interfacing with the Hall sensor This parameter can be one of the following values: Internal trigger 0 selected TIM_TS_ITR0: TIM_TS_ITR1: Internal trigger 1 selected TIM_TS_ITR2: Internal trigger 2 selected TIM_TS_ITR3: Internal trigger 3 selected TIM_TS_NONE: No trigger is needed : the Commutation Event source This CommutationSource: parameter can be one of the following values: TIM_COMMUTATION_TRGI: Commutation source is the TRGI of the Interface Timer TIM_COMMUTATION_SOFTWARE: Commutation source is set by software using the COMG bit Return value s HAL: status Notes : this function is mandatory to use the commutation event in order to update the configuration at each commutation detection on the TRGI input of the Timer, the typical use of mer) this feature is with the use of another Timer(interface Ti configured in Hall sensor interface, this interface Timer will generate the commutation at its TRGO output (connected to Timer used in this function) each time the TI1 of the Interface Timer detect a commutation at its input TI1. utationEvent_DMA HAL_TIMEx_ConfigComm HAL_StatusTypeDef Function name HAL_TIMEx_ConfigCommutationEvent_DMA (TIM_HandleTypeDef * htim, uint32_t InputTrigger, uint32_t CommutationSource) Configure the TIM commutation event sequence with DMA. Function description Parameters : TIM handle htim: InputTrigger: : the Internal trigger corresponding to the Timer Interfacing with the Hall sensor This parameter can be one of the following values: TIM_TS_ITR0: Internal trigger 0 selected TIM_TS_ITR1: Internal trigger 1 selected TS_ITR2: Internal trigger 2 selected TIM_ TIM_TS_ITR3: Internal trigger 3 selected TIM_TS_NONE: No trigger is needed : the Commutation Event source This CommutationSource: parameter can be one of the following values: TIM_COMMUTATION_TRGI: Commutation source is the DocID027328 / 1166 568 Rev 2

569 UM1850 HAL TIM Extension Driver TRGI of the Interface Timer TIM_COMMUTATION_SOFTWARE: Commutation source is set by software using the COMG bit Return values status HAL: Notes : this function is mandatory to use the commutation event in order to update the configuration at each commutation detection on the TRGI input of the Timer, the typical use of this feature is with the use of another Timer(interface Timer) configured in Hall sensor interface, this interface Timer will generate the commutation at its TRGO output (connected to Timer used in this function) each time the TI1 of the Interface Timer detect a commutation at its input TI1. : The user should configure the DMA in his own software, in This function only the COMDE bit is set HAL_TIMEx_ConfigBreakDeadTime AL_StatusTypeDef HAL_TIMEx_ConfigBreakDeadTime H Function name (TIM_HandleTypeDef * htim, TIM_BreakDeadTimeConfigTypeDef * sBreakDeadTimeConfig) Configures the Break feature, dead time, Lock level, OSSI/OSSR Function description State and the AOE(automatic output enable) . Parameters htim: : TIM handle sBreakDeadTimeConfig: : pointer to a TIM_ConfigBreakDeadConfigTypeDef structure that contains the BDTR Register configuration information for the TIM peripheral. Return values status HAL: HAL_TIMEx_MasterConfigSynchronization HAL_StatusTypeDef Function name HAL_TIMEx_MasterConfigSynchronization (TIM_HandleTypeDef * htim, TIM_MasterConfigTypeDef * sMasterConfig) Function description Configures the TIM in master mode. Parameters htim: : TIM handle. : pointer to a TIM_MasterConfigTypeDef sMasterConfig: structure that contains the selected trigger output (TRGO) and the Master/Slave mode. Return values status HAL: HAL_TIMEx_CommutationCallback void HAL_TIMEx_CommutationC allback (TIM_HandleTypeDef Function name * htim) Function description Hall commutation changed callback in non blocking mode. Parameters htim: : TIM handle 2 DocID027328 Rev 1166 569 /

570 HAL UM1850 TIM Extension Driver Return values None: HAL_TIMEx_BreakCallback htim) void HAL_TIMEx_BreakCallback (TIM_HandleTypeDef * Function name Hall Break detection callback in non blocking mode. Function description Parameters htim: : TIM handle Return values None: HAL_TIMEx_HallSensor_GetState HAL_TIM_StateTypeDef HAL_TIMEx_HallSensor_GetState Function name htim) (TIM_HandleTypeDef * Return the TIM Hall Sensor interface state. Function description Parameters htim: : TIM Hall Sensor handle Return values state HAL: TIMEx_DMACommutationCplt void TIMEx_DMACommutationCplt (DMA_HandleTypeDef * Function name hdma) Function descr iption TIM DMA Commutation callback. Parameters hdma: : pointer to DMA handle. Return values None: 42.3 TIMEx Firmware driver defines TIMEx 42.3.1 TIMEx Clock Filter IS_TIM_DEADTIME BreakDead Time DocID027328 / 1166 570 Rev 2

571 HAL UM1850 UART Generic Driver HAL UART Generic Driver 43 UART Firmware driver registers structures 43.1 43.1.1 UART_InitTypeDef Data Fields uint32_t BaudRate uint32_t WordLength uint32_t StopBits uint32_t Parity uint32_t Mode uint32_t HwFlowCtl uint32_t OverSampling Field Documentation uint32_t UART_InitTypeDef::BaudRate This member configures the UART communication baud rate. The baud rate is - computed using the following formula:IntegerDivider = ((PCLKx) / (16 * (huart ((uint32_t) IntegerDivider)) * 16) - >Init.BaudRate)))FractionalDivider = ((IntegerDivider + 0.5 uint32_t UART_InitTypeDef::WordLength Specifies the number of data bits transmi tted or received in a frame. This parameter can be a value of UART_Word_Length uint32_t UART_InitTypeDef::StopBits Specifies the number of stop bits transmitted. This parameter can be a value of UART_Stop_Bits uint32_t UART_InitTypeDef::Parity Specifies the parity mode. This parameter can be a value of UART_Parity When parity is enabled, the computed parity is inserted at the MSB position of Note: ed data (9th bit when the word length is set to 9 data bits; 8th bit when the the transmitt word length is set to 8 data bits). uint32_t UART_InitTypeDef::Mode Specifies whether the Receive or Transmit mode is enabled or disabled. This parameter can be a value of UART_Mode uint32_t UART_InitTypeDef::HwFlowCtl Specifies whether the hardware flow control mode is enabled or disabled. This UART_Hardware_Flow_Control parameter can be a value of uint32_t UART_InitTypeDef::OverSampling Specifies whether the Over sampling 8 is enabled or disabled, to achieve higher speed (up to fPCLK/8). This parameter can be a value of . UART_Over_Sampling M32F100xx family, so OverSampling parameter This feature is only available on ST should always be set to 16. 43.1.2 UART_HandleTypeDef Data Fields USART_TypeDef * Instance UART_InitTypeDef Init uint8_t * pTxBuffPtr uint16_t TxXferSize 2 DocID027328 Rev 1166 571 /

572 UM1850 HAL UART Generic Driver __IO uint16_t TxXferC ount uint8_t * pRxBuffPtr uint16_t RxXferSize __IO uint16_t RxXferCount DMA_HandleTypeDef * hdmatx DMA_HandleTypeDef * hdmarx HAL_LockTypeDef Lock __IO HAL_UART_StateTypeDef gState __IO HAL_UART_StateTypeDef RxState __IO uint32_t ErrorCode Documentation Field USART_TypeDef* UART_HandleTypeDef::Instance UART registers base address UART_InitTypeDef UART_HandleTypeDef::Init UART communication parameters uint8_t* UART_HandleTypeDef::pTxBuffPtr Pointer to UART Tx transfer Buffer uint16_t UART_Handle TypeDef::TxXferSize UART Tx Transfer size __IO uint16_t UART_HandleTypeDef::TxXferCount UART Tx Transfer Counter uint8_t* UART_HandleTypeDef::pRxBuffPtr Pointer to UART Rx transfer Buffer uint16_t UART_HandleTypeDef::RxXferSize UART Rx Transfer size IO uint16_t UART_HandleTypeDef::RxXferCount __ UART Rx Transfer Counter DMA_HandleTypeDef* UART_HandleTypeDef::hdmatx UART Tx DMA Handle parameters DMA_HandleTypeDef* UART_HandleTypeDef::hdmarx UART Rx DMA Handle parameters ef::Lock HAL_LockTypeDef UART_HandleTypeD Locking object __IO HAL_UART_StateTypeDef UART_HandleTypeDef::gState UART state information related to global Handle management and also related to Tx operations. This parameter can be a value of HAL_UART_StateTypeDef __IO HAL_UART_StateTypeDef U ART_HandleTypeDef::RxState UART state information related to Rx operations. This parameter can be a value of HAL_UART_StateTypeDef __IO uint32_t UART_HandleTypeDef::ErrorCode UART Error code UART Firmware driver API description 43.2 43.2.1 How to use this driver The UART HAL driver can be used as follows: Declare a UART_HandleTypeDef handle structure. 1. Initialize the UART low level resources by implementing the HAL_UART_MspInit() 2. API: Enable the USARTx interface clock. a. b. UART pins configuration: DocID027328 / 1166 572 Rev 2

573 UM1850 UART Generic Driver HAL Enable the clock for the UART GPIOs. Configure the UART pins (TX as alternate function pull e up, RX as alternat - function Input). c. NVIC configuration if you need to use interrupt process (HAL_UART_Transmit_IT() and HAL_UART_Receive_IT() APIs): Configure the USARTx interrupt priority. Enable the NVIC USART IRQ handle. d. DMA Configuration if you need to use DMA process (HAL_UART_Transmit_DMA() and HAL_UART_Receive_DMA() APIs): Declare a DMA handle structure for the Tx/Rx channel. Enable the DMAx interface clock. Configure the declared DMA handle structure with the required Tx/Rx parameters. nnel. Configure the DMA Tx/Rx cha Associate the initialized DMA handle to the UART DMA Tx/Rx handle. Configure the priority and enable the NVIC for the transfer complete interrupt on the DMA Tx/Rx channel. Configure the USARTx interrupt priority and enable the NVIC USART IRQ used for last byte sending completion detection in DMA non circular handle ( mode) Program the Baud Rate, Word Length, Stop Bit, Parity, Hardware flow control and 3. Mode(Receiver/Transmitter) in the huart Init structure. 4. For the UART asynchronous mode, initialize t he UART registers by calling the HAL_UART_Init() API. 5. For the UART Half duplex mode, initialize the UART registers by calling the HAL_HalfDuplex_Init() API. 6. For the LIN mode, initialize the UART registers by calling the HAL_LIN_Init() API. Processor mode, initialize the UART registers by calling the - For the Multi 7. HAL_MultiProcessor_Init() API. The specific UART interrupts (Transmission complete interrupt, RXNE interrupt and Error Interrupts) will be managed using the macros __HAL_UART_ENABLE_IT() an d __HAL_UART_DISABLE_IT() inside the transmit and receive process. These APIs (HAL_UART_Init() and HAL_HalfDuplex_Init()) configure also the low level Hardware GPIO, CLOCK, CORTEX...etc) by calling the customized HAL_UART_MspInit() API. Three operation modes are available within this driver: Polling mode IO operation Send an amount of data in blocking mode using HAL_UART_Transmit() Receive an amount of data in blocking mode using HAL_UART_Receive() Interrupt mode IO operation mount of data in non blocking mode using HAL_UART_Transmit_IT() Send an a At transmission end of transfer HAL_UART_TxCpltCallback is executed and user can add his own code by customization of function pointer HAL_UART_TxCpltCallback blocking mode using HAL_UART_Receive_IT() Receive an amount of data in non 2 DocID027328 Rev 1166 573 /

574 UART Generic Driver HAL UM1850 At reception end of transfer HAL_UART_RxCpltCallback is executed and user can add his own code by customization of function pointer HAL_UART_RxCpltCallback tion is executed and user In case of transfer Error, HAL_UART_ErrorCallback() func can add his own code by customization of function pointer HAL_UART_ErrorCallback DMA mode IO operation Send an amount of data in non blocking mode (DMA) using HAL_UART_Transmit_DMA() At transmission end of half transfer HAL_UART_TxHalfCpltCallback is executed and user can add his own code by customization of function pointer HAL_UART_TxHalfCpltCallback At transmission end of transfer HAL_UART_TxCpltCallback is executed and user can d his own code by customization of function pointer HAL_UART_TxCpltCallback ad Receive an amount of data in non blocking mode (DMA) using HAL_UART_Receive_DMA() At reception end of half transfer HAL_UART_RxHalfCpltCallback is executed and user can add his own code by customization of function pointer HAL_UART_RxHalfCpltCallback At reception end of transfer HAL_UART_RxCpltCallback is executed and user can own code by customization of function pointer HAL_UART_RxCpltCallback add his In case of transfer Error, HAL_UART_ErrorCallback() function is executed and user can add his own code by customization of function pointer HAL_UART_ErrorCallback using HAL_UART_DMAPause() Pause the DMA Transfer Resume the DMA Transfer using HAL_UART_DMAResume() Stop the DMA Transfer using HAL_UART_DMAStop() UART HAL driver macros list Below the list of most used macros in UART HAL driver. __HAL_UART_ENABLE: Enable the UART peripheral __HAL_UART_DISABLE: Disable the UART peripheral __HAL_UART_GET_FLAG : Check whether the specified UART flag is set or not __HAL_UART_CLEAR_FLAG : Clear the specified UART pending flag __HAL_UART_ENABLE_IT: Enable the specified UART interrupt __HAL_UART_DI SABLE_IT: Disable the specified UART interrupt __HAL_UART_GET_IT_SOURCE: Check whether the specified UART interrupt has occurred or not You can refer to the UART HAL driver header file for more useful macros Additional remark: If the parity is enabled, then the MSB bit of the data written in the data register is transmitted but is changed by the parity bit. The UART frame bits). Refer to - - bits or 9 formats depend on the frame length defined by the M bit (8 product reference manual for details. the 43.2.2 Initialization and Configuration functions This subsection provides a set of functions allowing to initialize the USARTx or the UARTy s mode. in asynchronou DocID027328 / 1166 574 Rev 2

575 UM1850 UART Generic Driver HAL For the asynchronous mode only these parameters can be configured: Baud Rate Word Length Stop Bit Parity: If the parity is enabled, then the MSB bit of the data written in the data register is transmitted but is changed by the parity bit. Depend ing on the frame - bits or 9 - length defined by the M bit (8 bits), please refer to Reference manual for possible UART frame formats. Hardware flow control Receiver/transmitter modes Over Sampling Method it() and The HAL_UART_Init(), HAL_HalfDuplex_Init(), HAL_LIN_In HAL_MultiProcessor_Init() APIs follow respectively the UART asynchronous, UART Half Processor configuration procedures (details for the procedures are - duplex, LIN and Multi available in reference manuals (RM0008 for STM32F10Xxx MCUs and RM0041 for STM32F100xx MCUs)). This section contains the following APIs: HAL_UART_Init() HAL_HalfDuplex_Init() HAL_LIN_Init() HAL_MultiProcessor_Init() HAL_UART_DeInit() HAL_UART_MspInit() HAL_UART_MspDeInit() IO operation functions 43.2.3 This subsection provides a set of functions allowing to manage the UART asynchronous and Half duplex data transfers. 1. There are two modes of transfer: Blocking mode: The communication is performed in polling mode. The HAL status of all data processing is returned by the same function after finishing transfer. Non blocking mode: The communication is performed using Interrupts or DMA, these APIs return the HAL status. The end of the data processing will be indicated through the dedicated UART IRQ when usin g Interrupt mode or the DMA IRQ when using DMA mode. The HAL_UART_TxCpltCallback(), HAL_UART_RxCpltCallback() user callbacks will be executed respectively at the end of the transmit or receive process. The HAL_UART_ErrorCallback() user cuted when a communication error is detected. callback will be exe 2. Blocking mode APIs are: HAL_UART_Transmit() HAL_UART_Receive() Non Blocking mode APIs with Interrupt are: 3. HAL_UART_Transmit_IT() HAL_UART_Receive_IT() HAL_UART_IRQHandler() DMA are: 4. Non Blocking mode functions with HAL_UART_Transmit_DMA() HAL_UART_Receive_DMA() HAL_UART_DMAPause() HAL_UART_DMAResume() 2 DocID027328 Rev 1166 575 /

576 HAL UM1850 UART Generic Driver HAL_UART_DMAStop() 5. A set of Transfer Complete Callbacks are provided in non blocking mode: HAL_UART_TxHalfCpltCallback() HAL_UART_TxCpltCallback() HAL_UART _RxHalfCpltCallback() HAL_UART_RxCpltCallback() HAL_UART_ErrorCallback() In the Half duplex communication, it is forbidden to run the transmit and receive process in parallel, the UART state HAL_UART_STATE_BUSY_TX_RX can't be useful. This section contains the following APIs: HAL_UART_Transmit() HAL_UART_Receive() HAL_UART_Transmit_IT() HAL_UART_Receive_IT() HAL_UART_Transmit_DMA() HAL_UART_Receive_DMA() HAL_UART_DMAPause() HAL_UART_DMAResume() HAL_UART_DMASt op() HAL_UART_Abort() HAL_UART_AbortTransmit() HAL_UART_AbortReceive() HAL_UART_Abort_IT() HAL_UART_AbortTransmit_IT() HAL_UART_AbortReceive_IT() HAL_UART_IRQHandler() HAL_UART_TxCpltCallback() HAL_UART_TxHalfCpltCallback() HAL_UART_RxCpltCallback() HAL_UART_RxHalfCpltCallback() HAL_UART_ErrorCallback() HAL_UART_Abor tCpltCallback() HAL_UART_AbortTransmitCpltCallback() HAL_UART_AbortReceiveCpltCallback() Peripheral Control functions 43.2.4 ovides a set of functions allowing to control the UART: This subsection pr HAL_LIN_SendBreak() API can be helpful to transmit the break character. HAL_MultiProcessor_EnterMuteMode() API can be helpful to enter the UART in mute mode. HAL_MultiProcessor_ExitMuteMode() API ca n be helpful to exit the UART mute mode by software. HAL_HalfDuplex_EnableTransmitter() API to enable the UART transmitter and disables the UART receiver in Half Duplex mode HAL_HalfDuplex_EnableReceiver() API to enable the UART receiver and disables the ART transmitter in Half Duplex mode U This section contains the following APIs: DocID027328 / 1166 576 Rev 2

577 UM1850 UART Generic Driver HAL HAL_LIN_SendBreak() HAL_MultiProcessor_EnterMuteMode() HAL_MultiProcessor_Exit MuteMode() HAL_HalfDuplex_EnableTransmitter() HAL_HalfDuplex_EnableReceiver() Peripheral State and Errors functions 43.2.5 on provides a set of functions allowing to return the State of UART This subsecti communication process, return Peripheral Errors occurred during communication process time the state of the UART - HAL_UART_GetState() API can be helpful to check in run peripheral. time errors that could be occurred during HAL_UART_GetError() check in run - communication. This section contains the following APIs: HAL_UART_GetState() HAL_UART_GetError() ion of functions Detailed descript 43.2.6 HAL_UART_Init HAL_StatusTypeDef HAL_UART_Init (UART_HandleTypeDef * Function name huart) Function description Initializes the UART mode according to the specified parameters in and create the associated handle. the UART_InitTypeDef Parameters pointer to a UART_HandleTypeDef structure that huart: contains the configuration information for the specified UART module. Return values HAL: status HAL_HalfDuplex_Init HAL_StatusTypeDef HAL_HalfDuplex_Init Function name (UART_HandleTypeDef * huart) - duplex mode according to the specified Initializes the half Function description parameters in the UART_InitTypeDef and create the associated handle. Parameters ucture that pointer to a UART_HandleTypeDef str huart: contains the configuration information for the specified UART module. Return values status HAL: HAL_LIN_Init HAL_StatusTypeDef HAL_LIN_Init (UART_HandleTypeDef * Function name huart, uint32_t BreakDetectLength) Initiali Function description zes the LIN mode according to the specified parameters in the UART_InitTypeDef and create the associated handle. 2 DocID027328 Rev 1166 577 /

578 HAL UM1850 UART Generic Driver Parameters huart: pointer to a UART_HandleTypeDef structure that contains the configuration information for the specified UART module. Specifies the LIN break detection BreakDetectLength: length. This parameter can be one of the following values: UART_LINBREAKDETECTLENGTH_10B: 10 bit break - detection UART_LINBREAKDETECTLENGTH_11B: 11 - bit break detection Return values HAL: status HAL_M ultiProcessor_Init HAL_StatusTypeDef HAL_MultiProcessor_Init Function name (UART_HandleTypeDef * huart, uint8_t Address, uint32_t WakeUpMethod) Function description Initializes the Multi - Processor mode according to the specified parameters in the UART_InitTypeDef and create the associated handle. Parameters huart: pointer to a UART_HandleTypeDef structure that contains the configuration information for the specified UART module. USART address Address: - up method. specifies the USART wake WakeUpMethod: This parameter can be one of the following values: up by an - METHOD_IDLELINE: Wake UART_WAKEUP idle line detection - up UART_WAKEUPMETHOD_ADDRESSMARK: Wake by an address mark Return values HAL: status HAL_UART_DeInit HAL_StatusTypeDef HAL_UART_DeInit Function name (UART_HandleTypeDef * huart) nitializes the UART peripheral. Function description DeI Parameters huart: pointer to a UART_HandleTypeDef structure that contains the configuration information for the specified UART module. Return values status HAL: HAL_UART_MspInit (UART_HandleTypeDef * huart) void HAL_UART_MspInit Function name Function description UART MSP Init. Parameters pointer to a UART_HandleTypeDef structure that huart: contains the configuration information for the specified UART module. DocID027328 / 1166 578 Rev 2

579 UM1850 UART Generic Driver HAL Return values None: HAL_UART_MspDeInit void HAL_UART_MspDeInit (UART_HandleTypeDef * huart) Function n ame UART MSP DeInit. Function description Parameters huart: pointer to a UART_HandleTypeDef structure that contains the configuration information for the specified UART module. Return values None: HAL_UART_Transmit HAL_StatusTypeDef HAL_UART_Transmit Function name (UART_HandleTypeDef * huart, uint8_t * pData, uint16_t Size, uint32_t Timeout) Function description Sends an amount of data in blocking mode. Parameters huart: pointer to a UART_HandleTypeDef structure that contains the configuration information for the specified UART module. pData: Pointer to data buffer Amount of data to be sent Size: Timeout duration Timeout: Return values HAL: status HAL_UART_Receive HAL_StatusTypeDef HAL_UART_Receive Function name (UART_HandleTypeDef * huart, uint8_t * pData, uint16_t Size, uint32_t Timeout) Function description Receive an amount of data in blocking mode. Parameters huart: pointer to a UART_HandleTypeDef structure that contains the configuration information for the specified UART module. pData: Pointer to data buffer Size: Amount of data to be received Timeout: Timeout duration Return values HAL: status HAL_UART_Transmit_IT HAL_UART_Transmit_IT HAL_StatusTypeDef Function name (UART_HandleTypeDef * huart, uint8_t * pData, uint16_t Size) Sends an amount of data in non blocking mode. Function description Parameters pointer to a UART_HandleTypeDef structure that huart: for the specified UART contains the configuration information module. Pointer to data buffer pData: 2 DocID027328 Rev 1166 579 /

580 HAL UM1850 UART Generic Driver Amount of data to be sent Size: Return values HAL: status HAL_UART_Receive_IT HAL_StatusTypeDef HAL_UART_Receive_IT Function name ) (UART_HandleTypeDef * huart, uint8_t * pData, uint16_t Size Receives an amount of data in non blocking mode. Function description Parameters huart: pointer to a UART_HandleTypeDef structure that contains the configuration information for the specified UART module. pData: Pointer to data buffer Amount of data to be received Size: Return values HAL: status HAL_UART_Transmit_DMA HAL_StatusTypeDef HAL_UART_Transmit_DMA Function name (UART_HandleTypeDef * huart, uint8_t * pData, uint16_t Size) ng mode. Sends an amount of data in non blocki Function description Parameters pointer to a UART_HandleTypeDef structure that huart: contains the configuration information for the specified UART module. pData: Pointer to data buffer Size: Amount of data to be sent Return values status HAL: HAL_UART_Receive_DMA HAL_StatusTypeDef HAL_UART_Receive_DMA Function name (UART_HandleTypeDef * huart, uint8_t * pData, uint16_t Size) Receives an amount of data in non blocking mode. Function description Parameters pointer to a UART_HandleTypeD huart: ef structure that contains the configuration information for the specified UART module. pData: Pointer to data buffer Amount of data to be received Size: Return values status HAL: Notes When the UART parity is enabled (PCE = 1) the data received contain the parity bit. HAL_UART_DMAPause HAL_StatusTypeDef HAL_UART_DMAPause Function name (UART_HandleTypeDef * huart) Pauses the DMA Transfer. Function description Parameters huart: pointer to a UART_HandleTypeDef structure that DocID027328 / 1166 580 Rev 2

581 UM1850 HAL UART Generic Driver contains the config uration information for the specified UART module. Return values HAL: status HAL_UART_DMAResume HAL_StatusTypeDef HAL_UART_DMAResume Function name (UART_HandleTypeDef * huart) Function description Resumes the DMA Transfer. Parameters huart: pointer to a UART_HandleTypeDef structure that contains the configuration information for the specified UART module. Return values status HAL: HAL_UART_DMAStop HAL_StatusTypeDef HAL_UART_DMAStop Function name (UART_HandleTypeDef * huart) ription Stops the DMA Transfer. Function desc Parameters pointer to a UART_HandleTypeDef structure that huart: contains the configuration information for the specified UART module. Return values HAL: status HAL_UART_Abort HAL_StatusTypeDef HAL_UART_Abort Function name (UART_HandleTypeDef * huart) Function description Abort ongoing transfers (blocking mode). Parameters huart: UART handle. Return values HAL: status Notes This procedure could be used for aborting any ongoing upt or DMA mode. This procedure transfer started in Interr performs following operations : Disable PPP InterruptsDisable the DMA transfer in the peripheral register (if enabled)Abort DMA transfer by calling HAL_DMA_Abort (in case of transfer in DMA mode)Set handle State to READY Th is procedure is executed in blocking mode : when exiting function, Abort is considered as completed. HAL_UART_AbortTransmit HAL_StatusTypeDef HAL_UART_AbortTransmit Function name (UART_HandleTypeDef * huart) Function description Abort ongoing Transmit transfer (blocking mode). Parameters UART handle. huart: 2 DocID027328 Rev 1166 581 /

582 HAL UM1850 UART Generic Driver Return values HAL: status Notes This procedure could be used for aborting any ongoing transfer started in Interrupt or DMA mode. This procedure performs following operati ons : Disable PPP InterruptsDisable the DMA transfer in the peripheral register (if enabled)Abort DMA transfer by calling HAL_DMA_Abort (in case of transfer in DMA mode)Set handle State to READY This procedure is executed in blocking mode : when exiting f unction, Abort is considered as completed. HAL_UART_AbortReceive HAL_StatusTypeDef HAL_UART_AbortReceive Function name (UART_HandleTypeDef * huart) Abort ongoing Receive transfer (blocking mode). Function description Parameters UART handle. huart: Return values status HAL: Notes This procedure could be used for aborting any ongoing transfer started in Interrupt or DMA mode. This procedure performs following operations : Disable PPP InterruptsDisable the DMA transfer in the peripheral register (if enabled)Abort DMA transfer by calling HAL_DMA_Abort (in case of transfer in DMA mode)Set handle State to READY This procedure is executed in blocking mode : when exiting function, Abort is considered as completed. HAL_UART_Abort_IT HAL_Stat usTypeDef HAL_UART_Abort_IT Function name (UART_HandleTypeDef * huart) Function description Abort ongoing transfers (Interrupt mode). Parameters UART handle. huart: Return values HAL: status Notes This procedure could be used for aborting any ongoing transfer started in Interrupt or DMA mode. This procedure performs following operations : Disable PPP InterruptsDisable the DMA transfer in the peripheral register (if enabled)Abort ing HAL_DMA_Abort_IT (in case of DMA transfer by call transfer in DMA mode)Set handle State to READYAt abort completion, call user abort complete callback This procedure is executed in Interrupt mode, meaning that abort procedure could be considered as completed only when r abort complete callback is executed (not when exiting use function). HAL_UART_AbortTransmit_IT HAL_StatusTypeDef HAL_UART_AbortTransmit_IT Function name (UART_HandleTypeDef * huart) DocID027328 / 1166 582 Rev 2

583 HAL UM1850 UART Generic Driver Abort ongoing Transmit transfer (Interrupt mode). Function description P arameters huart: UART handle. Return values status HAL: Notes This procedure could be used for aborting any ongoing transfer started in Interrupt or DMA mode. This procedure performs following operations : Disable PPP InterruptsDisable the DMA transfer in the peripheral register (if enabled)Abort ing HAL_DMA_Abort_IT (in case of DMA transfer by call transfer in DMA mode)Set handle State to READYAt abort completion, call user abort complete callback This procedure is executed in Interrupt mode, meaning that abort procedure could be considered as completed only when r abort complete callback is executed (not when exiting use function). HAL_UART_AbortReceive_IT HAL_StatusTypeDef HAL_UART_AbortReceive_IT Function name (UART_HandleTypeDef * huart) Abort ongoing Receive transfer (Interrupt mode). Function description meters Para huart: UART handle. Return values HAL: status Notes This procedure could be used for aborting any ongoing transfer started in Interrupt or DMA mode. This procedure performs following operations : Disable PPP InterruptsDisable the DMA transfer in the peripheral register (if enabled)Abort DMA transfer by call ing HAL_DMA_Abort_IT (in case of transfer in DMA mode)Set handle State to READYAt abort completion, call user abort complete callback This procedure is executed in Interrupt mode, meaning that abort procedure could be considered as completed only when r abort complete callback is executed (not when exiting use function). HAL_UART_IRQHandler void HAL_UART_IRQHandler (UART_HandleTypeDef * huart) Function name Function description This function handles UART interrupt request. Parameters huart: pointer to a UART_HandleTypeDef structure that contains the configuration information for the specified UART module. Return values None: HAL_UART_TxCpltCallback void HAL_UART_TxCpltCallback (UART_HandleTypeDef * Function name huart) Tx Transfer completed callbacks. description Function 2 DocID027328 Rev 1166 583 /

584 HAL UART Generic Driver UM1850 Parameters huart: pointer to a UART_HandleTypeDef structure that contains the configuration information for the specified UART module. Return values None: HAL_UART_TxHalfCpltCallback void HAL _UART_TxHalfCpltCallback (UART_HandleTypeDef * Function name huart) Tx Half Transfer completed callbacks. Function description Parameters pointer to a UART_HandleTypeDef structure that huart: contains the configuration information for the specified UART module. Return values None: HAL_UART_RxCpltCallback void HAL_UART_RxCpltCallback (UART_HandleTypeDef * Function name huart) Function description Rx Transfer completed callbacks. Parameters huart: pointer to a UART_HandleTypeDef structure that contains the co nfiguration information for the specified UART module. Return values None: HAL_UART_RxHalfCpltCallback void HAL_UART_RxHalfCpltCallback (UART_HandleTypeDef * Function name huart) Function description Rx Half Transfer completed callbacks. Parameters huart: pointer to a UART_HandleTypeDef structure that contains the configuration information for the specified UART module. Return values None: HAL_UART_ErrorCallback void HAL_UART_ErrorCallback (UART_HandleTypeDef * Function name huart) Function UART error callbacks. description Parameters pointer to a UART_HandleTypeDef structure that huart: contains the configuration information for the specified UART module. Return values None: DocID027328 / 1166 584 Rev 2

585 UM1850 UART Generic Driver HAL HAL_UART_AbortCpltCallback void HAL_UART_AbortCpltCallback (UART_HandleTypeDef * Function name huart) Function description UART Abort Complete callback. Parameters UART handle. huart: Return values None: HAL_UART_AbortTransmitCpltCallback void HAL_UART_AbortTransmitCpltCallback Function name ART_HandleTypeDef * huart) (U UART Abort Complete callback. Function description Parameters huart: UART handle. Return values None: HAL_UART_AbortReceiveCpltCallback void HAL_UART_AbortReceiveCpltCallback Function name (UART_HandleTypeDef * huart) Function description UART Abort Receive Complete callback. Parameters huart: UART handle. Return values None: HAL_LIN_SendBreak HAL_StatusTypeDef HAL_LIN_SendBreak Function name (UART_HandleTypeDef * huart) Transmits break characters. Function description Parameters pointer to a UART_HandleTypeDef structure that huart: contains the configuration information for the specified UART module. Return values HAL: status HAL_MultiProcessor_EnterMuteMode HAL_StatusTypeDef HAL_MultiProcessor_EnterMuteMode Function name (UART_HandleTypeDef * huart) Enters the UART in mute mode. Function description Parameters huart: pointer to a UART_HandleTypeDef structure that contains the configuration information for the specified UART module. Return values status HAL: 2 DocID027328 Rev 1166 585 /

586 HAL UM1850 UART Generic Driver HAL_MultiProcessor_ExitMuteMode HAL_StatusTypeDef HAL_MultiProcessor_ExitMuteMode Function name ypeDef * huart) (UART_HandleT Exits the UART mute mode: wake up software. Function description Parameters huart: pointer to a UART_HandleTypeDef structure that contains the configuration information for the specified UART module. Return values HAL: status HAL_HalfDuplex_EnableTransmitter HAL_StatusTypeDef HAL_HalfDuplex_EnableTransmitter Function name (UART_HandleTypeDef * huart) Enables the UART transmitter and disables the UART receiver. Function description Parameters huart: ypeDef structure that pointer to a UART_HandleT contains the configuration information for the specified UART module. Return values status HAL: HAL_HalfDuplex_EnableReceiver HAL_StatusTypeDef HAL_HalfDuplex_EnableReceiver Function name (UART_HandleTypeDef * huart) Function desc ription Enables the UART receiver and disables the UART transmitter. Parameters pointer to a UART_HandleTypeDef structure that huart: contains the configuration information for the specified UART module. Return values status HAL: HAL_UART_GetState HAL_UART_StateTypeDef HAL_UART_GetState Function name (UART_HandleTypeDef * huart) Function description Returns the UART state. Parameters pointer to a UART_HandleTypeDef structure that huart: contains the configuration information for the specified UART module. Return values state HAL: HAL_UART_GetError uint32_t HAL_UART_GetError (UART_HandleTypeDef * huart) Function name Return the UART error code. Function description Parameters huart: : pointer to a UART_HandleTypeDef structure that contains the configuration information for the specified UART. DocID027328 / 1166 586 Rev 2

587 UM1850 UART Generic Driver HAL Return values UART: Error Code 43.3 UART Firmware driver defines 43.3.1 UART UART Error Code No error HAL_UART_ERROR_NONE Parity error HAL_UART_ERROR_PE HAL_UART_ERROR_NE Noise error HAL_UART_ERROR_FE Frame error HAL_UART_ERROR_ORE Overrun error DMA transfer error HAL_UART_ERROR_DMA UART Exported Macros Description: __HAL_UART_RESET_HANDLE_STATE Reset UART handle gstate & RxState. Parameters: __HANDLE__: specifies the UART Handle. UART Handle selects the USARTx or UARTy peripheral (USART,UART availability and x,y values depending on device). Description: __HAL_UART_FLUSH_DRREGISTER Flushs the UART DR register. Parameters: __HANDLE__: specifies the UART Handle. UART Handle selects the USARTx or UARTy peripheral (USART,UART availability and x,y values depending on d evice). Description: __HAL_UART_GET_FLAG Checks whether the specified UART flag is set or not. Parameters: __HANDLE__: specifies the UART Handle. This parameter can be UARTx where x: 1, 2, 3, 4 or 5 to select the USART or UART peripheral. __FLAG__: specifies the flag to check. This parameter can be one of the following values: UART_FLAG_CTS: CTS Change flag (not available for 2 DocID027328 Rev 1166 587 /

588 UART Generic Driver HAL UM1850 UART4 and UART5) UART_FLAG_LBD: LIN Break detection flag UART_FLAG_TXE: Transmit data register empty flag UART_FLAG_TC: Transmission Complete flag UART_FLAG_RXNE: Receive data register not empty flag UART_FLAG_IDLE: Idle Line detection flag UART_FLAG_ORE: OverRun Error flag UART_FLAG_NE: Noise Error flag UART_FLAG_FE: Framing Error flag ror UART_FLAG_PE: Parity Er flag Return value: The: new state of __FLAG__ (TRUE or FALSE). Description: __HAL_UART_CLEAR_FLAG Clears the specified UART pending flag. Parameters: __HANDLE__: specifies the UART Handle. UART Handle selects the USARTx or UARTy peripheral availability and x,y (USART,UART values depending on device). __FLAG__: specifies the flag to check. This parameter can be any combination of the following values: UART_FLAG_CTS: CTS Change flag (not available for UART4 and UART5). UART_FLAG_LBD: LIN Break flag. detection UART_FLAG_TC: Transmission Complete flag. UART_FLAG_RXNE: Receive data register not empty flag. Notes: PE (Parity error), FE (Framing error), NE (Noise error), ORE (OverRun error) and IDLE (Idle line detected) flags are cleared by software sequence: a read operation to USART_SR register followed by a DocID027328 / 1166 588 Rev 2

589 HAL UM1850 UART Generic Driver read operation to USART_DR register. RXNE flag can be also cleared by a read to the USART_DR register. TC flag can be also cleared by software sequence: a read operation to USART_SR register a write operation to followed by USART_DR register. TXE flag is cleared only by a write to the USART_DR register. Description: __HAL_UART_CLEAR_PEFLAG Clears the UART PE pending flag. Parameters: __HANDLE__: specifies the UART Handle. UART Handle selects the USARTx o r UARTy peripheral (USART,UART availability and x,y values depending on device). Description: __HAL_UART_CLEAR_FEFLAG Clears the UART FE pending flag. Parameters: __HANDLE__: specifies the UART Handle. UART Handle selects the USARTx or UARTy peripheral SART,UART availability and x,y (U values depending on device). Description: __HAL_UART_CLEAR_NEFLAG Clears the UART NE pending flag. Parameters: __HANDLE__: specifies the UART Handle. UART Handle selects the USARTx or UARTy peripheral availability and x,y (USART,UART values depending on device). Description: __HAL_UART_CLEAR_OREFLAG Clears the UART ORE pending flag. Parameters: __HANDLE__: specifies the UART Handle. UART Handle selects the USARTx or UARTy peripheral (USART,UART availability and x,y values depending on device). Description: __HAL_UART_CLEAR_IDLEFLAG Clears the UART IDLE pending flag. Parameters: 2 DocID027328 Rev 1166 589 /

590 UART Generic Driver HAL UM1850 __HANDLE__: specifies the UART Handle. UART Handle selects the USARTx or UARTy peripheral (USART,UART availability and x,y values depend ing on device). Description: __HAL_UART_ENABLE_IT Enable the specified UART interrupt. Parameters: __HANDLE__: specifies the UART Handle. UART Handle selects the USARTx or UARTy peripheral (USART,UART availability and x,y values depending on device). __INTERRUPT__: specifies the UART interrupt source to enable. This parameter can be one of the following values: UART_IT_CTS: CTS change interrupt UART_IT_LBD: LIN Break detection interrupt UART_IT_TXE: Transmit Data Register empty interrupt ransmission UART_IT_TC: T complete interrupt UART_IT_RXNE: Receive Data register not empty interrupt UART_IT_IDLE: Idle line detection interrupt UART_IT_PE: Parity Error interrupt UART_IT_ERR: Error interrupt(Frame error, noise error, overrun error) Description: __HAL_UART_DISABLE_ IT Disable the specified UART interrupt. Parameters: __HANDLE__: specifies the UART Handle. UART Handle selects the USARTx or UARTy peripheral (USART,UART availability and x,y values depending on device). __INTERRUPT__: specifies the UART interrupt source to disable. This parameter can be one of the following values: UART_IT_CTS: CTS change interrupt UART_IT_LBD: LIN Break DocID027328 / 1166 590 Rev 2

591 HAL UM1850 UART Generic Driver detection interrupt UART_IT_TXE: Transmit Data Register empty interrupt Transmission UART_IT_TC: complete interrupt UART_IT_RXNE: Receive Data register not empty interrupt UART_IT_IDLE: Idle line detection interrupt UART_IT_PE: Parity Error interrupt UART_IT_ERR: Error interrupt(Frame error, noise error, overrun error) Description: SOURCE __HAL_UART_GET_IT_ Checks whether the specified UART interrupt has occurred or not. Parameters: __HANDLE__: specifies the UART Handle. UART Handle selects the USARTx or UARTy peripheral (USART,UART availability and x,y values depending on device). __IT__: specifies the UART interrupt source to check. This parameter can be one of the following values: UART_IT_CTS: CTS change interrupt (not available for UART4 and UART5) UART_IT_LBD: LIN Break detection interrupt UART_IT_TXE: Transmit Data interrupt Register empty UART_IT_TC: Transmission complete interrupt UART_IT_RXNE: Receive Data register not empty interrupt UART_IT_IDLE: Idle line detection interrupt UART_IT_ERR: Error interrupt Return value: The: new state of __IT__ (TRUE or FALSE). Description: __HAL_UART_HWCONTROL_CTS_ENABLE Enable CTS flow control This macro allows to enable CTS hardware flow control for a given UART instance, without need to call Parameters: 2 DocID027328 Rev 1166 591 /

592 HAL UART Generic Driver UM1850 __HANDLE__: specifies the UART Handle. The Handle Instance can be RTx (supporting the HW any USA Flow control feature). It is used to select the USART peripheral (USART availability and x value depending on device). Notes: As macro is expected to be used for modifying CTS Hw flow control feature activation, without need for T instance Deinit/Init, following USAR conditions for macro call should be fulfilled : UART instance should have already been initialised (through call of HAL_UART_Init() )macro could only be called when corresponding UART instance is disabled (i.e __HAL_UART_D ISABLE(__HANDL E__)) and should be followed by an Enable macro (i.e __HAL_UART_ENABLE(__HANDLE __)). Description: __HAL_UART_HWCONTROL_CTS_DISABLE Disable CTS flow control This macro allows to disable CTS hardware flow control for a given UART instance, without need to call Parameters: __HANDLE__: specifies the UART Handle. The Handle Instance can be any USARTx (supporting the HW Flow control feature). It is used to select the USART peripheral (USART availability and x value depending on device). Notes: A s macro is expected to be used for modifying CTS Hw flow control feature activation, without need for USART instance Deinit/Init, following conditions for macro call should be fulfilled : UART instance should have already been initialised (through call HAL_UART_Init() )macro could of only be called when corresponding UART instance is disabled (i.e __HAL_UART_DISABLE(__HANDL E__)) and should be followed by an Enable macro (i.e __HAL_UART_ENABLE(__HANDLE DocID027328 / 1166 592 Rev 2

593 UM1850 UART Ge neric Driver HAL __)). Description: __HAL_UART_HWCONTROL_RTS_ENABLE le RTS flow control This macro Enab allows to enable RTS hardware flow control for a given UART instance, without need to call Parameters: __HANDLE__: specifies the UART Handle. The Handle Instance can be any USARTx (supporting the HW Flow control feature). It is used to select the USART peripheral (USART availability and x value depending on device). Notes: As macro is expected to be used for modifying RTS Hw flow control feature activation, without need for USART instance Deinit/Init, following macro call should be conditions for fulfilled : UART instance should have already been initialised (through call of HAL_UART_Init() )macro could only be called when corresponding UART instance is disabled (i.e __HAL_UART_DISABLE(__HANDL E__)) and should be followed by an Enable macro (i.e __HAL_UART_ENABLE(__HANDLE __)). Description: __HAL_UART_HWCONTROL_RTS_DISABLE Disable RTS flow control This macro allows to disable RTS hardware flow control for a given UART instance, without need to call Parameters: __HANDLE__: specif ies the UART Handle. The Handle Instance can be any USARTx (supporting the HW Flow control feature). It is used to select the USART peripheral (USART availability and x value depending on device). Notes: As macro is expected to be used for modifying RTS Hw flow control feature activation, without need for USART instance Deinit/Init, following conditions for macro call should be 2 DocID027328 Rev 1166 593 /

594 UART Generic Driver HAL UM1850 fulfilled : UART instance should have already been initialised (through call HAL_UART_Init() )macro could of only be called when corresponding UART instance is disabled (i.e __HAL_UART_DISABLE(__HANDL E__)) and should be followed by an Enable macro (i.e __HAL_UART_ENABLE(__HANDLE __)). Description: __HAL_UART_ENABLE Enable UART. Para meters: __HANDLE__: specifies the UART Handle. Description: __HAL_UART_DISABLE Disable UART. Parameters: __HANDLE__: specifies the UART Handle. UART FLags UART_FLAG_CTS UART_FLAG_LBD UART_FLAG_TXE UART_FLAG_TC UART_FLAG_RXNE UART_FLAG_IDLE UART_FLAG_ORE UART_FLAG_NE UART_FLAG_FE UART_FLAG_PE UART Hardware Flow Control UART_HWCONTROL_NONE UART_HWCONTROL_RTS UART_HWCONTROL_CTS UART_HWCONTROL_RTS_CTS UART Interrupt Definitions UART_IT_PE UART_IT_TXE UART_IT_TC DocID027328 / 1166 594 Rev 2

595 UM1850 UART Generic Driver HAL UART_IT_RXNE UART_IT_IDLE UART_IT_LBD UART_IT_CTS UART_IT_ERR UART LIN Break Detection Length UART_LINBREAKDETECTLENGTH_10B UART_LINBREAKDETECTLENGTH_11B UART Transfer Mode UART_MODE_RX UART_MODE_TX UART_MODE_TX_RX UART Over Sampling UART_OVERSAMPLING_16 UART Parity UART_PARITY_NONE UART_PARITY_EVEN UART_PARITY_ODD UART State UART_STATE_DISABLE UART_STATE_ENABLE UART Number of Stop Bits UART_STOPBITS_1 UART_STOPBITS_2 UART Wakeup Functions UART_WAKEUPMETHOD_IDLELINE UART_WAKEUPMETHOD_ADDRESSMARK UART Word Length UART_WORDLENGTH_8B UART_WORDLENGTH_9B 2 DocID027328 Rev 1166 595 /

596 HAL UM1850 USART Generic Driver HAL USART Generic Driver 44 44.1 USART Firmware driver registers structures 44.1.1 USART_InitTypeDef Data Fields uint32_t BaudRate uint32_t WordLength uint32_t StopBits uint32_t Parity uint32_t Mode uint32_t CLKPolarity uint32_t CLKPhase uint32_t CLKLastBit Field Documentation USART_InitTypeDef::BaudRate uint32_t This member configures the Usart communication baud rate. The baud rate is - computed using the following formula:IntegerDivider = ((PCLKx) / (16 * (husart - >Init.BaudRate)))FractionalDivider = ((IntegerDivider rDivider)) * 16) ((uint32_t) Intege + 0.5 uint32_t USART_InitTypeDef::WordLength Specifies the number of data bits transmitted or received in a frame. This parameter can be a value of USART_Word_Length uint32_t USART_InitTypeDef::StopBits Sp ecifies the number of stop bits transmitted. This parameter can be a value of USART_Stop_Bits uint32_t USART_InitTypeDef::Parity U Specifies the parity mode. This parameter can be a value of SART_Parity Note: When parity is enabled, the computed parity is inserted at the MSB position of the transmitted data (9th bit when the word length is set to 9 data bits; 8th bit when the word length is set to 8 data bits). uint32_t USART_InitTypeDef::Mode Specifies whether the Receive or Transmit mode is enabled or disabled. This parameter can be a value of USART_Mode uint32_t USART_InitTypeDef::CLKPolarity e a value of Specifies the steady state of the serial clock. This parameter can b USART_Clock_Polarity uint32_t USART_InitTypeDef::CLKPhase Specifies the clock transition on which the bit capture is made. This parameter can be a value of USART_Clock_Phase t32_t USART_InitTypeDef::CLKLastBit uin Specifies whether the clock pulse corresponding to the last transmitted data bit (MSB) has to be output on the SCLK pin in synchronous mode. This parameter can be a USART_Last_Bit value of USART_HandleTypeDef 44.1.2 Data Fields USART_TypeDef * Instance DocID027328 / 1166 596 Rev 2

597 UM1850 USART Generic Driver HAL USART_InitTypeDef Init uint8_t * pTxBuffPtr uint16_t TxXferSize __IO uint16_t TxXferCount uint8_t * pRxBuffPtr uint16_t RxXferSize __IO uint 16_t RxXferCount DMA_HandleTypeDef * hdmatx DMA_HandleTypeDef * hdmarx HAL_LockTypeDef Lock __IO HAL_USART_StateTypeDef State __IO uint32_t ErrorCode Field Documentation USART_TypeDef* USART_HandleTypeDef::Instance USART registers base address ypeDef USART_HandleTypeDef::Init USART_InitT Usart communication parameters uint8_t* USART_HandleTypeDef::pTxBuffPtr Pointer to Usart Tx transfer Buffer uint16_t USART_HandleTypeDef::TxXferSize Usart Tx Transfer size __IO uint16_t USART_HandleTypeDef::TxXferCount Usart Tx Transfer Counter uint8_t* USART_HandleTypeDef::pRxBuffPtr Pointer to Usart Rx transfer Buffer uint16_t USART_HandleTypeDef::RxXferSize Usart Rx Transfer size __IO uint16_t USART_HandleTypeDef::RxXferCount Usart Rx Transfer Counter DMA_HandleTy peDef* USART_HandleTypeDef::hdmatx Usart Tx DMA Handle parameters DMA_HandleTypeDef* USART_HandleTypeDef::hdmarx Usart Rx DMA Handle parameters HAL_LockTypeDef USART_HandleTypeDef::Lock Locking object te __IO HAL_USART_StateTypeDef USART_HandleTypeDef::Sta Usart communication state __IO uint32_t USART_HandleTypeDef::ErrorCode USART Error code 44.2 USART Firmware driver API description How to use this driver 44.2.1 The USART HAL driver can be used as follows: 1. Declare a USART_HandleTypeDef handle structure. Initialize the USART low level resources by implementing the HAL_USART_MspInit () 2. API: a. Enable the USARTx interface clock. USART pins configuration: b. USART GPIOs. Enable the clock for the 2 DocID027328 Rev 1166 597 /

598 HAL UM1850 USART Generic Driver Configure the USART pins (TX as alternate function pull - up, RX as alternate function Input). c. NVIC configuration if you need to use interrupt process (HAL_USART_Transmit_IT(), HAL_USART_Receive_IT() and HAL_USART_TransmitReceive_IT() APIs): Co nfigure the USARTx interrupt priority. Enable the NVIC USART IRQ handle. DMA Configuration if you need to use DMA process d. (HAL_USART_Transmit_DMA() HAL_USART_Receive_DMA() and HAL_USART_TransmitReceive_DMA() APIs): Declare a DMA handle structure for the Tx/Rx channel. Enable the DMAx interface clock. Configure the declared DMA handle structure with the required Tx/Rx parameters. Configure the DMA Tx/Rx channel. Associate the initialized DMA handle to the USART DMA Tx/Rx handle. enable the NVIC for the transfer complete interrupt Configure the priority and on the DMA Tx/Rx channel. Configure the priority and enable the NVIC for the transfer complete interrupt on the DMA Tx/Rx channel. Configure the USARTx interrupt priority and enable the NVIC USART IRQ dle (used for last byte sending completion detection in DMA non circular han mode) 3. Program the Baud Rate, Word Length, Stop Bit, Parity, Hardware flow control and Mode(Receiver/Transmitter) in the husart Init structure. Initialize the USART registers by call ing the HAL_USART_Init() API: 4. These APIs configures also the low level Hardware GPIO, CLOCK, CORTEX...etc) by calling the customized HAL_USART_MspInit(&husart) API. The specific USART interrupts (Transmission complete interrupt, RXNE interrupt Interrupts) will be managed using the macros and Error __HAL_USART_ENABLE_IT() and __HAL_USART_DISABLE_IT() inside the transmit and receive process. 5. Three operation modes are available within this driver : Polling mode IO operation Send an amount of data in blocki ng mode using HAL_USART_Transmit() Receive an amount of data in blocking mode using HAL_USART_Receive() Interrupt mode IO operation Send an amount of data in non blocking mode using HAL_USART_Transmit_IT() At transmission end of transfer HAL_USART_TxHalfC pltCallback is executed and user can add his own code by customization of function pointer HAL_USART_TxCpltCallback Receive an amount of data in non blocking mode using HAL_USART_Receive_IT() d and user can At reception end of transfer HAL_USART_RxCpltCallback is execute add his own code by customization of function pointer HAL_USART_RxCpltCallback In case of transfer Error, HAL_USART_ErrorCallback() function is executed and user can add his own code by customization of function pointer HAL_USART_ErrorCallba ck DocID027328 / 1166 598 Rev 2

599 UM1850 USART Generic Driver HAL DMA mode IO operation Send an amount of data in non blocking mode (DMA) using HAL_USART_Transmit_DMA() At transmission end of half transfer HAL_USART_TxHalfCpltCallback is executed and user can add his own code by customization of function pointer USART_TxHalfCpltCallback HAL_ At transmission end of transfer HAL_USART_TxCpltCallback is executed and user can add his own code by customization of function pointer HAL_USART_TxCpltCallback Receive an amount of data in non blocking mode (DMA) using HAL_USART_Receive_DMA() At reception end of half transfer HAL_USART_RxHalfCpltCallback is executed and user can add his own code by customization of function pointer HAL_USART_RxHalfCpltCallback uted and user can At reception end of transfer HAL_USART_RxCpltCallback is exec add his own code by customization of function pointer HAL_USART_RxCpltCallback In case of transfer Error, HAL_USART_ErrorCallback() function is executed and user can add his own code by customization of function pointer lback HAL_USART_ErrorCal Pause the DMA Transfer using HAL_USART_DMAPause() Resume the DMA Transfer using HAL_USART_DMAResume() Stop the DMA Transfer using HAL_USART_DMAStop() USART HAL driver macros list Below the list of most used macros in USART HAL driver. __HAL_USART_ ENABLE: Enable the USART peripheral __HAL_USART_DISABLE: Disable the USART peripheral __HAL_USART_GET_FLAG : Check whether the specified USART flag is set or not __HAL_USART_CLEAR_FLAG : Clear the specified USART pending flag the specified USART interrupt __HAL_USART_ENABLE_IT: Enable __HAL_USART_DISABLE_IT: Disable the specified USART interrupt You can refer to the USART HAL driver header file for more useful macros Additio nal remark: If the parity is enabled, then the MSB bit of the data written in the data register is transmitted but is changed by the parity bit. The USART frame - formats depend on the frame length defined by the M bit (8 bits or 9 - bits). Refer to t reference manual for details.” the produc 44.2.2 Initialization and Configuration functions This subsection provides a set of functions allowing to initialize the USART in nous modes. asynchronous and in synchro For the asynchronous mode only these parameters can be configured: Baud Rate Word Length 2 DocID027328 Rev 1166 599 /

600 HAL USART Generic Driver UM1850 Stop Bit Parity: If the parity is enabled, then the MSB bit of the data written in the data ending on the frame register is transmitted but is changed by the parity bit. Dep length defined by the M bit (8 bits or 9 - bits), please refer to Reference manual for - possible USART frame formats. USART polarity USART phase USART LastBit Receiver/transmitter modes chronous configuration procedure The HAL_USART_Init() function follows the USART syn (details for the procedure are available in reference manuals (RM0008 for STM32F10Xxx MCUs and RM0041 for STM32F100xx MCUs)). This section contains the following APIs: HAL_USART_Init() HAL_USART_DeInit() HAL_USART_MspInit() HAL_USART_MspDeInit() 44.2.3 IO operation functions set of functions allowing to manage the USART synchronous This subsection provides a data transfers. The USART supports master mode only: it cannot receive or send data related to an input clock (SCLK is always an output). 1. There are two modes of transfer: Blocking mode: The com munication is performed in polling mode. The HAL status of all data processing is returned by the same function after finishing transfer. No Blocking mode: The communication is performed using Interrupts or DMA, - These API's return the HAL status. The end of the data processing will be indicated through the dedicated USART IRQ when using Interrupt mode or the DMA IRQ when using DMA mode. The HAL_USART_TxCpltCallback(), HAL_USART_RxCpltCallback() and HAL_USART_TxRxCpltCallback() user callbacks will be executed respectively at the end of the transmit or Receive process The HAL_USART_ErrorCallback() user callback will be executed when a communica tion error is detected Blocking mode APIs are : 2. HAL_USART_Transmit() in simplex mode HAL_USART_Receive() in full duplex receive only HAL_USART_TransmitReceive() in full duplex mode 3. Non Blocking mode APIs with Interrupt are : HAL_USART_Transmit_IT()in s implex mode HAL_USART_Receive_IT() in full duplex receive only HAL_USART_TransmitReceive_IT() in full duplex mode HAL_USART_IRQHandler() Non Blocking mode functions with DMA are : 4. HAL_USART_Transmit_DMA()in simplex mode plex receive only HAL_USART_Receive_DMA() in full du HAL_USART_TransmitReceive_DMA() in full duplex mode HAL_USART_DMAPause() HAL_USART_DMAResume() HAL_USART_DMAStop() DocID027328 / 1166 600 Rev 2

601 USART Generic Driver UM1850 HAL 5. A set of Transfer Complete Callbacks are provided in non Blocking mode: HAL_USART_TxHalfCpltCallback() HAL_USART_TxCpltCallback() HAL_USART_RxHalfCpltCallback() HAL_USART_RxCpltCallback() HAL_USART_ErrorCallback() HAL_USART_TxRxCpltCallback() This section contains the following APIs: HAL_USART_Transmit() HAL_USART_Receive() HAL_USART_TransmitReceive() HAL_USART_Transmit_IT() HAL_USART_Receive_IT() mitReceive_IT() HAL_USART_Trans HAL_USART_Transmit_DMA() HAL_USART_Receive_DMA() HAL_USART_TransmitReceive_DMA() HAL_USART_DMAPause() HAL_USART_DMAResume() HAL_USART_DMAStop() HAL_USART_Abort() HAL_USART_Abort_IT() HAL_USART_IR QHandler() HAL_USART_TxCpltCallback() HAL_USART_TxHalfCpltCallback() HAL_USART_RxCpltCallback() HAL_USART_RxHalfCpltCallback() HAL_USART_TxRxCpltCallback() HAL_USART_ErrorCallback() HAL_USART_AbortCpltCallback() 44.2.4 Peripheral State and Errors functions This subsection provides a set of functions allowing to return the State of USART communication process, return Peripheral Errors occurred during communication process - time the state of the be helpful to check in run HAL_USART_GetState() API can USART peripheral. - HAL_USART_GetError() check in run time errors that could be occurred during communication. This section contains the following APIs: HAL_USART_GetState() HAL_USART_GetError() Detailed description of functions 44.2.5 HAL_USART_Init HAL_StatusTypeDef HAL_USART_Init Function name (USART_HandleTypeDef * husart) Function description Initializes the USART mode according to the specified parameters in the USART_InitTypeDef and create the associated handle. 2 DocID027328 Rev 1166 601 /

602 HAL USART Generic Driver UM1850 Parameters husart: pointer to a USART_HandleTypeDef structure that contains the configuration information for the specified USART module. Return values HAL: status HAL_USART_DeInit HAL_StatusTypeDef HAL_USART_DeInit Function name (USART_HandleTypeDef * husart) DeInitializes the USART peripheral. description Function Parameters husart: pointer to a USART_HandleTypeDef structure that contains the configuration information for the specified USART module. Return values status HAL: HAL_USART_MspInit HAL_USART_MspInit (USART_HandleTypeDef * husart) void Function name Function description USART MSP Init. Parameters pointer to a USART_HandleTypeDef structure that husart: contains the configuration information for the specified USART module. Return values None: HAL_U SART_MspDeInit void HAL_USART_MspDeInit (USART_HandleTypeDef * Function name husart) Function description USART MSP DeInit. Parameters pointer to a USART_HandleTypeDef structure that husart: contains the configuration information for the specified USART module. Return values None: HAL_USART_Transmit HAL_StatusTypeDef HAL_USART_Transmit Function name (USART_HandleTypeDef * husart, uint8_t * pT xData, uint16_t Size, uint32_t Timeout) Function description Simplex Send an amount of data in blocking mode. Parameters husart: pointer to a USART_HandleTypeDef structure that contains the configuration information for the specified USART module. pTxD ata: Pointer to data buffer Size: Amount of data to be sent Timeout: Timeout duration Return values HAL: status DocID027328 / 1166 602 Rev 2

603 UM1850 USART Generic Driver HAL HAL_USART_Receive HAL_StatusTypeDef HAL_USART_Receive Function name (USART_HandleTypeDef * husart, uint8_t * pRxData, uint16_t Size, uint32_t Timeout) Duplex Receive an amount of data in blocking mode. - Function description Full Parameters husart: pointer to a USART_HandleTypeDef structure that contains the configuration information for the specified USART module. pRxData: Pointer t o data buffer Size: Amount of data to be received Timeout duration Timeout: Return values HAL: status HAL_USART_TransmitReceive HAL_StatusTypeDef HAL_USART_TransmitReceive Function name (USART_HandleTypeDef * husart, uint8_t * pTxData, uint8_t * pRxData, uint16_t Size, uint32_t Timeout) Function description - Duplex Send receive an amount of data in full duplex mode Full - (blocking mode). Parameters husart: pointer to a USART_HandleTypeDef structure that contains the configuration information for the specified USART module. pTxData: Pointer to data transmitted buffer Pointer to data received buffer pRxData: Size: Amount of data to be sent Timeout: Timeout duration Return values status HAL: HAL_USART_Transmit_IT ef HAL_USART_Transmit_IT HAL_StatusTypeD Function name (USART_HandleTypeDef * husart, uint8_t * pTxData, uint16_t Size) Simplex Send an amount of data in non blocking mode. - Function description Parameters husart: pointer to a USART_HandleTypeDef structure that contains the configuration information for the specified USART module. pTxData: Pointer to data buffer Size: Amount of data to be sent Return values HAL: status Notes The USART errors are not managed to avoid the overrun error. HAL_USART_Receive_IT HAL_StatusTypeDef HAL_USART_Receive_IT Function name (USART_HandleTypeDef * husart, uint8_t * pRxData, uint16_t 2 DocID027328 Rev 1166 603 /

604 HAL UM1850 USART Generic Driver Size) Function description Simplex Receive an amount of data in non - blocking mode. Parameters husart: pointer to a USART_HandleTypeDef structure that contains the configuration information for the specified USART module. pRxData: Pointer to data buffer Size: Amount of data to be received Return values HAL: status HAL_USART_TransmitReceive_IT HAL_StatusTypeDef HAL_USART_TransmitReceive_IT Function name (USART_HandleTypeDef * husart, uint8_t * pTxData, uint8_t * pRxData, uint16_t Size) - Duplex Send receive an amount of data in full Function description Full duplex mode - blocking). (non - ers Paramet pointer to a USART_HandleTypeDef structure that husart: contains the configuration information for the specified USART module. Pointer to data transmitted buffer pTxData: pRxData: Pointer to data received buffer Amount of data to be received Size: Return values HAL: status HAL_USART_Transmit_DMA HAL_StatusTypeDef HAL_USART_Transmit_DMA Function name (USART_HandleTypeDef * husart, uint8_t * pTxData, uint16_t Size) Function description Simplex Send an amount of data in non - blocking mode. Paramet ers husart: pointer to a USART_HandleTypeDef structure that contains the configuration information for the specified USART module. Pointer to data buffer pTxData: Size: Amount of data to be sent Return values status HAL: HAL_USART_Receive_DMA HAL_StatusTypeDef HAL_USART_Receive_DMA Function name (USART_HandleTypeDef * husart, uint8_t * pRxData, uint16_t Size) - Function description Full Duplex Receive an amount of data in non - blocking mode. Parameters structure that pointer to a USART_HandleTypeDef husart: contains the configuration information for the specified USART module. Pointer to data buffer pRxData: Size: Amount of data to be received DocID027328 / 1166 604 Rev 2

605 UM1850 USART Generic Driver HAL Return values HAL: status Notes The USART DMA transmit channel must be configured in order to gen erate the clock for the slave. When the USART parity is enabled (PCE = 1) the data received contain the parity bit. HAL_USART_TransmitReceive_DMA HAL_StatusTypeDef HAL_USART_TransmitReceive_DMA Function name (USART_HandleTypeDef * husart, uint8_t * pTxData, uint8_t * pRxData, uint16_t Size) Duplex Transmit Receive an amount of data in non - Function description Full - blocking mode. Parameters husart: pointer to a USART_HandleTypeDef structure that contains the configuration information for the speci fied USART module. pTxData: Pointer to data transmitted buffer Pointer to data received buffer pRxData: Amount of data to be received Size: Return values HAL: status Notes When the USART parity is enabled (PCE = 1) the data received contain the parit y bit. HAL_USART_DMAPause HAL_StatusTypeDef HAL_USART_DMAPause Function name (USART_HandleTypeDef * husart) Pauses the DMA Transfer. Function description Parameters pointer to a USART_HandleTypeDef structure that husart: contains the configuration information for the specified USART module. Return values HAL: status HAL_USART_DMAResume HAL_StatusTypeDef HAL_USART_DMAResume Function name (USART_HandleTypeDef * husart) Fun ction description Resumes the DMA Transfer. Parameters pointer to a USART_HandleTypeDef structure that husart: contains the configuration information for the specified USART module. Return values HAL: status HAL_USART_DMAStop HAL_StatusTypeDef HAL_USART_DMAStop Function name (USART_HandleTypeDef * husart) 2 DocID027328 Rev 1166 605 /

606 HAL UM1850 USART Generic Driver Function description Stops the DMA Transfer. Parameters husart: pointer to a USART_HandleTypeDef structure that contains the configuration information for the specified USART module. eturn values R HAL: status HAL_USART_Abort HAL_StatusTypeDef HAL_USART_Abort Function name (USART_HandleTypeDef * husart) Function description Abort ongoing transfer (blocking mode). Parameters husart: USART handle. Return values status HAL: Notes This procedure could be used for aborting any ongoing transfer (either Tx or Rx, as described by TransferType parameter) started in Interrupt or DMA mode. This procedure performs following operations : Disable PPP Interrupts (depending of transfer directio n)Disable the DMA transfer in the peripheral register (if enabled)Abort DMA transfer by calling HAL_DMA_Abort (in case of transfer in DMA mode)Set handle State to READY This procedure is executed in blocking mode : when exiting function, Abort is consider ed as completed. HAL_USART_Abort_IT HAL_StatusTypeDef HAL_USART_Abort_IT Function name (USART_HandleTypeDef * husart) Function description Abort ongoing transfer (Interrupt mode). Parameters USART handle. husart: Return values status HAL: Notes This procedure could be used for aborting any ongoing transfer (either Tx or Rx, as described by TransferType parameter) started in Interrupt or DMA mode. This procedure performs following operations : Disable PPP Interrupts n)Disable the DMA transfer in (depending of transfer directio the peripheral register (if enabled)Abort DMA transfer by calling HAL_DMA_Abort_IT (in case of transfer in DMA mode)Set handle State to READYAt abort completion, call user abort complete callback Interrupt mode, meaning that This procedure is executed in abort procedure could be considered as completed only when user abort complete callback is executed (not when exiting function). HAL_USART_IRQHandler void HAL_USART_IRQHandler (USART_HandleTypeDef * Function name husart) DocID027328 / 1166 606 Rev 2

607 UM1850 HAL USART Generic Driver This function handles USART interrupt request. Fun ction description Parameters husart: pointer to a USART_HandleTypeDef structure that contains the configuration information for the specified USART module. Return values None: HAL_USART_TxCpltCallback void HAL_USART_TxCpltCallback (USART_HandleTypeDef * Function name husart) Tx Transfer completed callbacks. Function description Parameters pointer to a USART_HandleTypeDef structure that husart: contains the configuration information for the specified USART module. Return values None: HAL_USART_TxHalfCpltCallback void HAL_USART_TxHalfCpltCallback Function name (USART_HandleTypeDef * husart) Tx Half Transfer completed callbacks. Function description Parameters husart: pointer to a USART_HandleTypeDef structure that contains the configuration information for the specified USART module. Return values None: HAL_USART_RxCpltCallback void HAL_USART_RxCpltCallback (USART_HandleTypeDef * Function name husart) Rx Transfer completed callbacks. Function des cription Parameters husart: pointer to a USART_HandleTypeDef structure that contains the configuration information for the specified USART module. Return values None: HAL_USART_RxHalfCpltCallback void HAL_USART_RxHalfCpltCallback Function name (USART_HandleTypeDef * husart) Function description Rx Half Transfer completed callbacks. Parameters husart: pointer to a USART_HandleTypeDef structure that contains the configuration information for the specified ule. USART mod Return values None: 2 DocID027328 Rev 1166 607 /

608 HAL USART Generic Driver UM1850 HAL_USART_TxRxCpltCallback void HAL_USART_TxRxCpltCallback (USART_HandleTypeDef Function name * husart) Function description - blocking process. Tx/Rx Transfers completed callback for the non Parameters husart: pointer to a USART_HandleTypeDef structure that contains the configuration information for the specified USART module. Return values None: HAL_USART_ErrorCallback void HAL_USART_ErrorCallback (USART_HandleTypeDef * Function name husart) iption USART error callbacks. Function descr Parameters husart: pointer to a USART_HandleTypeDef structure that contains the configuration information for the specified USART module. Return values None: HAL_USART_AbortCpltCallback void HAL_USART_AbortCpltCallback (USART_HandleTypeDef Function name * husart) Function description USART Abort Complete callback. Parameters USART handle. husart: Return values None: HAL_USART_GetState HAL_USART_StateTypeDef HAL_USART_GetState Function name (USART_Han dleTypeDef * husart) Returns the USART state. Function description Parameters husart: pointer to a USART_HandleTypeDef structure that contains the configuration information for the specified USART module. Return values HAL: state HAL_USART_GetError uint32_t HAL_USART_GetError (USART_HandleTypeDef * Function name husart) Function description Return the USART error code. Parameters : pointer to a USART_HandleTypeDef structure that husart: contains the configuration information for the specified RT. USA DocID027328 / 1166 608 Rev 2

609 UM1850 USART Generic Driver HAL Return values USART: Error Code 44.3 USART Firmware driver defines 44.3.1 USART USART Clock USART_CLOCK_DISABLE USART_CLOCK_ENABLE USART Clock Phase USART_PHASE_1EDGE USART_PHASE_2EDGE USART Clock Polarity USART_POLARITY_LOW USART_POLARITY_HIGH USART Error Code No error HAL_USART_ERROR_NONE HAL_USART_ERROR_PE Parity error HAL_USART_ERROR_NE Noise error Frame error HAL_USART_ERROR_FE Overrun error HAL_USART_ERROR_ORE HAL_USART_ERROR_DMA DMA transfer error USART Exported Macros Description: __HAL_USART_RESET_HANDLE_STATE Reset USART handle state. Parameters: __HANDLE__: specifies the USART Handle. USART Handle selects the USARTx peripheral (USART availability and x value depending on device). Description: __HAL_USART_GET_FLAG Checks whether the specified USART flag is set or not. Parameters: __HANDLE__: specifies the USART Handle. USART Handle selects the USARTx peripheral (USART availability x value depending on device). and __FLAG__: specifies the flag to check. This parameter can be one of the following values: USART_FLAG_TXE: Transmit data 2 DocID027328 Rev 1166 609 /

610 HAL UM1850 USART Generic Driver register empty flag USART_FLAG_TC: Transmission Complete flag USART_FLAG_RXNE: Receive empty flag data register not USART_FLAG_IDLE: Idle Line detection flag USART_FLAG_ORE: OverRun Error flag USART_FLAG_NE: Noise Error flag USART_FLAG_FE: Framing Error flag USART_FLAG_PE: Parity Error flag Return value: The: new state of __FLAG__ (TRUE or FALSE). Description: __HAL_USART_CLEAR_FLAG Clears the specified USART pending flags. Parameters: __HANDLE__: specifies the USART Handle. USART Handle selects the USARTx peripheral (USART availability and x value depending on device). to check. __FLAG__: specifies the flag This parameter can be any combination of the following values: USART_FLAG_TC: Transmission Complete flag. USART_FLAG_RXNE: Receive data register not empty flag. Notes: PE (Parity error), FE (Framing error), NE (Noise error), ORE (OverRun error) and IDLE (Idle line detected) flags are cleared by software sequence: a read operation to USART_SR register followed by a read operation to USART_DR register. RXNE flag can be also cleared by a read to the USART_DR register. TC flag can be software sequence: a also cleared by read operation to USART_SR register followed by a write operation to USART_DR register TXE flag is cleared only by a write to the USART_DR register DocID027328 / 1166 610 Rev 2

611 UM1850 USART Generic Driver HAL Description: __HAL_USART_CLEAR_PEFLAG Clear the USART PE pending flag. Parameters: ANDLE__: specifies the USART __H Handle. USART Handle selects the USARTx peripheral (USART availability and x value depending on device). Description: __HAL_USART_CLEAR_FEFLAG Clear the USART FE pending flag. Parameters: __HANDLE__: specifies the USART Handle. USART Handle selects the USARTx peripheral (USART availability and x value depending on device). Description: __HAL_USART_CLEAR_NEFLAG Clear the USART NE pending flag. Parameters: __HANDLE__: specifies the USART Handle. USART Handle selects the ARTx peripheral (USART availability US and x value depending on device). Description: __HAL_USART_CLEAR_OREFLAG Clear the USART ORE pending flag. Parameters: __HANDLE__: specifies the USART Handle. USART Handle selects the ty USARTx peripheral (USART availabili and x value depending on device). Description: __HAL_USART_CLEAR_IDLEFLAG Clear the USART IDLE pending flag. Parameters: __HANDLE__: specifies the USART Handle. USART Handle selects the USARTx peripheral (USART availability and x value depending on device). Description: __HAL_USART_ENABLE_IT Enable the specified USART interrupts. Parameters: __HANDLE__: specifies the USART Handle. USART Handle selects the USARTx peripheral (USART availability and x value depending on device). s the USART __INTERRUPT__: specifie 2 DocID027328 Rev 1166 611 /

612 USART Generic Driver HAL UM1850 interrupt source to enable. This parameter can be one of the following values: USART_IT_TXE: Transmit Data Register empty interrupt USART_IT_TC: Transmission complete interrupt USART_IT_RXNE: Receive Data register not empty interrupt IDLE: Idle line USART_IT_ detection interrupt USART_IT_PE: Parity Error interrupt USART_IT_ERR: Error interrupt(Frame error, noise error, overrun error) This parameter can be: ENABLE or DISABLE. Description: __HAL_USART_DISABLE_IT interrupts. Disable the specified USART Parameters: __HANDLE__: specifies the USART Handle. USART Handle selects the USARTx peripheral (USART availability and x value depending on device). __INTERRUPT__: specifies the USART interrupt source to disable. This parameter can be one of th e following values: USART_IT_TXE: Transmit Data Register empty interrupt USART_IT_TC: Transmission complete interrupt USART_IT_RXNE: Receive Data register not empty interrupt USART_IT_IDLE: Idle line detection interrupt USART_IT_PE: Parity Error interrupt USART_IT_ERR: Error interrupt(Frame error, noise error, overrun error) This parameter can be: ENABLE or DISABLE. Description: __HAL_USART_GET_IT_SOURCE Checks whether the specified USART interrupt has occurred or not. Parameters: e USART __HANDLE__: specifies th Handle. USART Handle selects the USARTx peripheral (USART availability and x value depending on device). DocID027328 / 1166 612 Rev 2

613 HAL UM1850 USART Generic Driver __IT__: specifies the USART interrupt source to check. This parameter can be one of the following values: USART_IT_TXE: Transmit Data Register empty interrupt USART_IT_TC: Transmission complete interrupt USART_IT_RXNE: Receive Data register not empty interrupt USART_IT_IDLE: Idle line detection interrupt USART_IT_ERR: Error interrupt USART_IT_PE: Parity Error interrupt Return value: te of __IT__ (TRUE or The: new sta FALSE). Description: __HAL_USART_ENABLE Enable USART. Parameters: __HANDLE__: specifies the USART Handle. USART Handle selects the USARTx peripheral (USART availability and x value depending on device). on: Descripti __HAL_USART_DISABLE Disable USART. Parameters: __HANDLE__: specifies the USART Handle. USART Handle selects the USARTx peripheral (USART availability and x value depending on device). USART Flags USART_FLAG_TXE USART_FLAG_TC USART_FLAG_RXNE USART_FLAG_IDLE USART_FLAG_ORE USART_FLAG_NE USART_FLAG_FE USART_FLAG_PE USART Interrupts Definition USART_IT_PE USART_IT_TXE 2 DocID027328 Rev 1166 613 /

614 HAL UM1850 USART Generic Driver USART_IT_TC USART_IT_RXNE USART_IT_IDLE USART_IT_LBD USART_IT_CTS USART_IT_ERR USART Last Bit USART_LASTBIT_DISABLE USART_LASTBIT_ENABLE USART Mode USART_MODE_RX USART_MODE_TX USART_MODE_TX_RX USART NACK State USART_NACK_ENABLE USART_NACK_DISABLE USART Parity USART_PARITY_NONE USART_PARITY_EVEN USART_PARITY_ODD USART Number of Stop Bits USART_STOPBITS_1 USART_STOPBITS_0_5 USART_STOPBITS_2 USART_STOPBITS_1_5 USART Word Length USART_WORDLENGTH_8B USART_WORDLENGTH_9B DocID027328 / 1166 614 Rev 2

615 UM1850 WWDG Generic Driver HAL HAL WWDG Generic Driver 45 45.1 WWDG Firmware driver registers structures WWDG_InitTypeDef 45.1.1 Data Fields uint32_t Prescaler uint32_t Window uint32_t Counter uint32_t EWIMode Field Documentation uint32_t WWDG_InitTypeDef::Prescaler Specifies the prescaler value of the WWDG. This parameter can be a value of WWDG_Prescaler uint32_t WWDG_InitTypeDef::Window Specifies the WWDG window value to be compared to the downcounter. This parameter must be a number Min_Data = 0x40 and Max_Data = 0x7F uint32_t WWDG_InitTypeDef::Counter running downcounter value. This parameter must be a - Specifies the WWDG free number between Min_Data = 0x40 and Max_Data = 0x7F uint32_t WWDG_InitTypeDef::EWIMode Specifies if WWDG Ea rly Wakeup Interupt is enable or not. This parameter can be a value of WWDG_EWI_Mode 45.1.2 WWDG_HandleTypeDef Data Fields WWDG_TypeDef * Instance WWDG_InitTypeDef Init Field Documentation WWDG_TypeDef* WWDG_HandleTypeDef::Instance Register base address WWDG_InitTypeDef WWDG_HandleTypeDef::Init WWDG required parameters WWDG Firmware driver API description 45.2 WWDG specific features 45.2.1 Once enabled the WWDG generates a system reset on expiry of a programmed time period, unless the program refreshes the counter (downcounter) before reaching 0x3F e rolls over from 0x40 to 0x3F). value (i.e. a reset is generated when the counter valu An MCU reset is also generated if the counter value is refreshed before the counter has reached the refresh window value. This implies that the counter must be refreshed in a limited window. disabled except by a system reset. Once enabled the WWDG cannot be WWDGRST flag in RCC_CSR register can be used to inform when a WWDG reset occurs. 2 DocID027328 Rev 1166 615 /

616 HAL UM1850 WWDG Generic Driver The WWDG counter input clock is derived from the APB clock divided by a programmable prescaler. WWDG clock (Hz) = PCLK1 / (4096 * Prescale r) WWDG timeout (mS) = 1000 * Counter / WWDG clock WWDG Counter refresh is allowed between the following limits : min time (mS) = 1000 * (Counter _ Window) / WWDG clock max time (mS) = 1000 * (Counter _ 0x40) / WWDG clock PCLK1): 910 us / 58.25 ms max timeout value at 36 MHz( - Min The Early Wakeup Interrupt (EWI) can be used if specific safety operations or data logging must be performed before the actual reset is generated. When the downcounter reaches the value 0x40, an EWI interrupt is generated and the corresponding interrupt service routine (ISR) can be used to trigger specific actions (such as communications or data logging), before resetting the device. In some applications, the EWI interrupt can be used to manage a software system check m recovery/graceful degradation, without generating a WWDG reset. In and/or syste this case, the corresponding interrupt service routine (ISR) should reload the WWDG counter to avoid the WWDG reset, then trigger the required actions. Note:When the be served, e.g. due to a system lock in a higher priority task, the EWI interrupt cannot WWDG reset will eventually be generated. Debug mode : When the microcontroller enters debug mode (core halted), the WWDG counter either continues to work normally or stops, depending on D BG_WWDG_STOP configuration bit in DBG module, accessible through __HAL_DBGMCU_FREEZE_WWDG() and __HAL_DBGMCU_UNFREEZE_WWDG() macros How to use this driver 45.2.2 Enable WWDG APB1 clock using __HAL_RCC_WWDG_CLK_ENABLE(). Set the WWDG prescaler, refresh window, counter value and Early Wakeup Interrupt mode using using HAL_WWDG_Init() function. This enables WWDG peripheral and given counter value. Init function can be the downcounter starts downcounting from called again to modify all watchdog parameters, however if EWI mode has been set once, it can't be clear until next reset. The application program must refresh the WWDG counter at regular intervals during operation to prevent an MCU reset using HAL_WWDG_Refresh() function. normal This operation must occur only when the counter is lower than the window value already programmed. if Early Wakeup Interrupt mode is enable an interrupt is generated when the counter rea ches 0x40. User can add his own code in weak function HAL_WWDG_EarlyWakeupCallback(). WWDG HAL driver macros list Below the list of most used macros in WWDG HAL driver. __HAL_WWDG_GET_IT_SOURCE: Check the selected WWDG's interrupt source. __HAL_WWDG_GET_FLAG: Get the selected WWDG's flag status. __HAL_WWDG_CLEAR_FLAG: Clear the WWDG's pending flags. 45.2.3 Initialization and Configuration functions allowing to: This section provides functions Initialize and start the WWDG according to the specified parameters in the WWDG_InitTypeDef of associated handle. Initialize the WWDG MSP. DocID027328 / 1166 616 Rev 2

617 UM1850 WWDG Generic Driver HAL This section contains the following APIs: HAL_WWDG_Init() HAL_WWDG_MspInit() IO operation functions 45.2.4 This section provides functions allowing to: Refresh the WWDG. Handle WWDG interrupt request and associated function callback. This section co ntains the following APIs: HAL_WWDG_Refresh() HAL_WWDG_IRQHandler() HAL_WWDG_EarlyWakeupCallback() Detailed description of functions 45.2.5 HAL_WWDG_Init HAL_StatusTypeDef HAL_WWDG_Init Function name (WWDG_HandleTypeDef * hwwdg) Initialize the WWDG according to the specified. Function description Parameters ucture that pointer to a WWDG_HandleTypeDef str hwwdg: contains the configuration information for the specified WWDG module. Return values HAL: status HAL_WWDG_MspInit void HAL_WWDG_MspInit (WWDG_HandleTypeDef * hwwdg) Function name Function description Initialize the WWDG MSP. Parameters hwwdg: pointer to a WWDG_HandleTypeDef structure that contains the configuration information for the specified WWDG module. Return values None: Notes When rewriting this function in user file, mechanism may be added to avoid multiple initialize when HA L_WWDG_Init function is called again to change parameters. HAL_WWDG_Refresh HAL_StatusTypeDef HAL_WWDG_Refresh Function name (WWDG_HandleTypeDef * hwwdg) Function description Refresh the WWDG. Parameters e that pointer to a WWDG_HandleTypeDef structur hwwdg: contains the configuration information for the specified WWDG module. Return values status HAL: 2 DocID027328 Rev 1166 617 /

618 HAL UM1850 WWDG Generic Driver HAL_WWDG_IRQHandler void HAL_WWDG_IRQHandler (WWDG_HandleTypeDef * Function name hwwdg) Function description Handle WWDG interrupt request. Parameters pointer to a WWDG_HandleTypeDef structure that hwwdg: contains the configuration information for the specified WWDG module. Return values None: Notes The Early Wakeup Interrupt (EWI) can be used if specific safety operations or data logging must be performed before the actual reset is generated. The EWI interrupt is enabled by calling HAL_WWDG_Init function with EWIMode set to WWDG_EWI_ENABLE. When the downcounter reaches the value 0x40, and EWI interrupt is generated and the terrupt Service Routine (ISR) can be used to corresponding In trigger specific actions (such as communications or data logging), before resetting the device. HAL_WWDG_EarlyWakeupCallback void HAL_WWDG_EarlyWakeupCallback Function name (WWDG_HandleTypeDef * hwwdg) WWDG Early Wakeup callback. Function description Parameters hwwdg: : pointer to a WWDG_HandleTypeDef structure that contains the configuration information for the specified WWDG module. Return values None: WWDG Firmware driver defines 45.3 WWDG 45.3.1 WWDG Early Wakeup Interrupt Mode EWI Disable WWDG_EWI_DISABLE WWDG_EWI_ENABLE EWI Enable WWDG Exported Macros Description: __HAL_WWDG_ENABLE Enables the WWDG peripheral. Parameters: __HANDLE__: WWDG handle Return value: None Description: __HAL_WWDG_ENABLE_IT Enables the WWDG early wakeup interrupt. DocID027328 / 1166 618 Rev 2

619 UM1850 WWDG Generic Driver HAL Parameters: __HANDLE__: WWDG handle __INTERRUPT__: specifies the interrupt to enable. This parameter can be one of the following values: WWDG_IT_EWI: Early wakeup interrupt Return value: None Notes: Once enabled this interrupt cannot be disabled except by a system reset. Description: __HAL_WWDG_GET_IT Checks whether the selected WWDG interrupt has occurred or not. Parameters: WWDG handle __HANDLE__: __INTERRUPT__: specifies the it to check. This parameter can be one of the following values: WWDG_FLAG_EWIF: Early wakeup interrupt IT Return value: The: new state of WWDG_FLAG (SET or RESET). Description: __HAL_WWDG_CLEAR_IT Clear the WWDG's interrupt pending bits bits to clear the selected interrupt pending bits. Parameters: __HANDLE__: WWDG handle __INTERRUPT__: specifies the interrupt pending bit to clear. This parameter can be one of the following values: WWDG_FLAG_EWIF: Early wakeup int errupt flag Description: __HAL_WWDG_GET_FLAG Check whether the specified WWDG flag is set or not. Parameters: __HANDLE__: WWDG handle __FLAG__: specifies the flag to check. This parameter can be one of the following values: WWDG_FLAG_EWIF: Early wakeup nterrupt flag i Return value: 2 DocID027328 Rev 1166 619 /

620 HAL Generic Driver UM1850 WWDG The: new state of WWDG_FLAG (SET or RESET). Description: __HAL_WWDG_CLEAR_FLAG Clears the WWDG's pending flags. Parameters: __HANDLE__: WWDG handle __FLAG__: specifies the flag to clear. This parameter can be one of the following values: WWDG_FLAG_EWIF: Early wakeup interrupt flag Return value: None Description: __HAL_WWDG_GET_IT_SOURCE Checks if the specified WWDG interrupt source is enabled or dis abled. Parameters: __HANDLE__: WWDG Handle. __INTERRUPT__: specifies the WWDG interrupt source to check. This parameter can be one of the following values: WWDG_IT_EWI: Early Wakeup Interrupt Return value: state: of __INTERRUPT__ (TRUE or FALSE). WWDG Flag definition Early wakeup interrupt flag WWDG_FLAG_EWIF WWDG Interrupt definition WWDG_IT_EWI Early wakeup interrupt WWDG Prescaler WWDG counter clock = (PCLK1/4096)/1 WWDG_PRESCALER_1 WWDG counter clock = (PCLK1/4096)/2 WWDG_PRESCALER_2 WWDG counter clock = (PCLK1/4096)/4 WWDG_PRESCALER_4 WWDG_PRESCALER_8 WWDG counter clock = (PCLK1/4096)/8 DocID027328 / 1166 620 Rev 2

621 LL UM1850 ADC Generic Driver 46 LL ADC Generic Driver ADC Firmware driver registers structures 46.1 46.1.1 CommonInitTypeDef LL_ADC_ Data Fields uint32_t Multimode Field Documentation uint32_t LL_ADC_CommonInitTypeDef::Multimode Set ADC multimode configuration to operate in independent mode or multimode (for devices with several ADC instances). This parameter can be a value of ADC_LL_EC_MULTI_MODE This feature can be modified afterwards using unitary . function LL_ADC_SetMultimode() LL_ADC_InitTypeDef 46.1.2 Data Fields uint32_t DataAlignment uint32_t SequencersScanMode Field Documentation Def::DataAlignment uint32_t LL_ADC_InitType Set ADC conversion data alignment. This parameter can be a value of ADC_LL_EC_DATA_ALIGN This feature can be modified afterwards using unitary . function LL_ADC_SetDataAlignment() uint32_t LL_ADC_InitTypeD ef::SequencersScanMode Set ADC scan selection. This parameter can be a value of This feature can be modified afterwards using ADC_LL_EC_SCAN_SELECTION . LL_ADC_SetSequencersScanMode() unitary function 46.1.3 LL_ADC_REG_InitTypeDef Data Fields uint32_t TriggerSource uint32_t SequencerLength uint32_t SequencerDiscont uint32_t ContinuousMode uint32_t DMATransfer Field Documentation uint32_t LL_ADC_REG_InitTypeDef::TriggerSource up regular conversion trigger source: internal (SW start) or from external Set ADC gro IP (timer event, external interrupt line). This parameter can be a value of ADC_LL_EC_REG_TRIGGER_SOURCE is set with trigger polarity: rising edge (only On this STM32 serie, external trigger Note: trigger polarity available on this STM32 serie). This feature can be modified afterwards using unitary function . LL_ADC_REG_SetTriggerSource() uint32_t LL_ADC_REG_InitTypeDef::SequencerLength Set ADC group r egular sequencer length. This parameter can be a value of 2 DocID027328 Rev 1166 621 /

622 UM1850 LL ADC Generic Driver ADC_LL_EC_REG_SEQ_SCAN_LENGTH Note: This parameter is discarded if scan mode is disabled (refer to parameter 'ADC_SequencersScanMode'). This feature can be modified a fterwards using unitary . LL_ADC_REG_SetSequencerLength() function uint32_t LL_ADC_REG_InitTypeDef::SequencerDiscont Set ADC group regular sequencer discontinuous mode: sequence subdivided and is parameter can be scan conversions interrupted every selected number of ranks. Th a value of ADC_LL_EC_REG_SEQ_DISCONT_MODE Note: This parameter has an effect only if group regular sequencer is enabled (scan length of 2 ranks or more). This feature can be modified afterwards using unit ary . LL_ADC_REG_SetSequencerDiscont() function uint32_t LL_ADC_REG_InitTypeDef::ContinuousMode Set ADC continuous conversion mode on ADC group regular, whether ADC conversions are performed in single mode (one conversion per trigger) or in continuous mode (after the first trigger, following conversions launched successively meter can be a value of automatically). This para Note: It is not possible to enable both ADC_LL_EC_REG_CONTINUOUS_MODE ADC group regular continuous mode and discontinuous mode.This feature can be modified afterwards using unitary function . G_SetContinuousMode() LL_ADC_RE uint32_t LL_ADC_REG_InitTypeDef::DMATransfer Set ADC group regular conversion data transfer: no transfer or transfer by DMA, and DMA requests mode. This parameter can be a value of This feature can be modified afterwards using TRANSFER ADC_LL_EC_REG_DMA_ . LL_ADC_REG_SetDMATransfer() unitary function LL_ADC_INJ_InitTypeDef 46.1.4 Data Fields uint32_t TriggerSource uint32_t SequencerLength uint32_t SequencerDiscont uint32_t TrigAuto Field Documentation uint32_t LL_ADC_INJ_InitTypeDef::TriggerSource Set ADC group injected conversion trigger source: internal (SW start) or from external IP (timer event, external interrupt line). This parameter can be a value of ADC_LL_EC_INJ_TRIGGER_SOURCE Note: On this STM32 serie, external trigger is set with trigger polarity: rising edge (only trigger polarity available on this STM32 serie). This feature can be modified afterwards . using unitary functio n LL_ADC_INJ_SetTriggerSource() uint32_t LL_ADC_INJ_InitTypeDef::SequencerLength Set ADC group injected sequencer length. This parameter can be a value of ADC_LL_EC_INJ_SEQ_SCAN_LENGTH scan mode is disabled (refer to parameter Note: This parameter is discarded if 'ADC_SequencersScanMode'). This feature can be modified afterwards using unitary LL_ADC_INJ_SetSequencerLength() function . uint32_t LL_ADC_INJ_InitTypeDef::SequencerDiscont Set ADC group injected sequencer discont inuous mode: sequence subdivided and scan conversions interrupted every selected number of ranks. This parameter can be a value of ADC_LL_EC_INJ_SEQ_DISCONT_MODE encer is enabled (scan This parameter has an effect only if group injected sequ Note: length of 2 ranks or more). This feature can be modified afterwards using unitary . LL_ADC_INJ_SetSequencerDiscont() function DocID027328 / 1166 622 Rev 2

623 UM1850 ADC Generic Driver LL uint32_t LL_ADC_INJ_InitTypeDef::TrigAuto Set ADC group injected conversion trigger: independent or from AD C group regular. This parameter can be a value of Note: This ADC_LL_EC_INJ_TRIG_AUTO parameter must be set to set to independent trigger if injected trigger source is set to an external trigger.This feature can be modified afterwards using unitary function . LL_ADC_INJ_SetTrigAuto() 46.2 ADC Firmware driver API description Detailed description of functions 46.2.1 LL_ADC_DMA_GetRegAddr __STATIC_INLINE uint32_t LL_ADC_DMA_GetRegAddr Function name (ADC_TypeDef * ADCx, uint32_t Register) Function to help to configure DMA transfer from ADC: retrieve the Function description ADC register address from ADC instance and a list of ADC registers intended to be used (most commonly) with DMA transfer. Parameters ADC instance ADCx: Register: This parameter can be one of the following values: (1) Available on devices with several ADC instances. LL_ADC_DMA_REG_REGULAR_DATA LL_ADC_DMA_REG_REGULAR_DATA_MULTI (1) Return values ADC: register address Notes These ADC registers are data registers: when ADC conversion data is available in ADC data registers, ADC generates a DMA transfer request. This macro is intended to be used with LL DMA driver, refer to function "LL_DMA_ConfigAddresses()". Example: LL_DMA_ConfigAddresses(DMA1, LL_DMA_CHANNEL_1, LL_ADC_DMA_GetRegAddr(ADC1, LL_ADC_DMA_REG_REGULAR_DATA), (uint32_t)&< array or variable >, LL_DMA_DIRECTION_PERIPH_TO_MEMORY); some devices For devices with several ADC: in multimode, use a different data register outside of ADC instance scope (common data register). This macro manages this register difference, only ADC instance has to be set as parameter. On STM32F1, only ADC instances ADC1 and ADC3 have DMA transfer capa bility, not ADC2 (ADC2 and ADC3 instances not available on all devices). On STM32F1, multimode can be used only with ADC1 and ADC2, not ADC3. Therefore, the corresponding parameter of data transfer for multimode can be used only with ADC1 and nd ADC3 instances not available on all ADC2. (ADC2 a devices). Reference Manual to DR DATA LL_ADC_DMA_GetRegAddr LL API cross reference: 623 Rev 2 1166 DocID027328 /

624 LL UM1850 ADC Generic Driver LL_ADC_SetCommonPathInternalCh __STATIC_INLINE void LL_ADC_SetCommonPathInternalCh Function name ADCxy_COMMON, uint32_t (ADC_Common_TypeDef * PathInternal) Set parameter common to several ADC: measurement path to Function description internal channels (VrefInt, temperature sensor, ...). Parameters ADC common instance (can be set ADCxy_COMMON: tion or by using helper macro directly from CMSIS defini __LL_ADC_COMMON_INSTANCE() ) This parameter can be a combination of the PathInternal: following values: LL_ADC_PATH_INTERNAL_NONE LL_ADC_PATH_INTERNAL_VREFINT LL_ADC_PATH_INTERNAL_TEMPSENSOR Return values None: Notes or several values can be selected. Example: One (LL_ADC_PATH_INTERNAL_VREFINT | LL_ADC_PATH_INTERNAL_TEMPSENSOR) Stabilization time of measurement path to internal channel: After enabling internal paths, before starting ADC conversion, a delay is required for internal voltage reference and temperature sensor stabilization time. Refer to device datasheet. Refer to literal LL_ADC_DELAY_TEMPSENSOR_STAB_US. ADC internal channel sampling time constraint: For ADC conversion of internal channels, a sampling time minim um value is required. Refer to device datasheet. Reference Manual to CR2 TSVREFE LL_ADC_SetCommonPathInternalCh LL API cross reference: LL_ADC_GetCommonPathInternalCh __STATIC_INLINE uint32_t Function name LL_ADC_GetCommonPathInternalCh ef * ADCxy_COMMON) (ADC_Common_TypeD Function description Get parameter common to several ADC: measurement path to internal channels (VrefInt, temperature sensor, ...). Parameters ADCxy_COMMON: ADC common instance (can be set directly from CMSIS definition or by using helper macro __LL_ADC_COMMON_INSTANCE() ) Return values Returned: value can be a combination of the following values: LL_ADC_PATH_INTERNAL_NONE LL_ADC_PATH_INTERNAL_VREFINT LL_ADC_PATH_INTERNAL_TEMPSENSOR Notes One or several values can be selected. Example: (LL_ADC_PATH_INTERNAL_VREFINT | LL_ADC_PATH_INTERNAL_TEMPSENSOR) DocID027328 / 1166 624 Rev 2

625 UM1850 LL ADC Generic Driver Reference Manual to CR2 TSVREFE LL_ADC_GetCommonPathInternalCh LL API cross reference: LL_ADC_SetDataA lignment __STATIC_INLINE void LL_ADC_SetDataAlignment Function name (ADC_TypeDef * ADCx, uint32_t DataAlignment) Function description Set ADC conversion data alignment. Parameters ADC instance ADCx: DataAlignment: This parameter can be one of the following values: LL_ADC_DATA_ALIGN_RIGHT LL_ADC_DATA_ALIGN_LEFT Return values None: Notes Refer to reference manual for alignments formats dependencies to ADC resolutions. Reference Manual to CR2 ALIGN LL_ADC_SetDataAlignment LL API cross reference: LL_ADC_GetDataAlignment __STATIC_INLINE uint32_t LL_ADC_GetDataAlignment Function name (ADC_TypeDef * ADCx) Function description Get ADC conversion data alignment. Parameters ADC instance ADCx: Return values value can be one of the following values: Returned: LL_ADC_DATA_ALIGN_RIGHT LL_ADC_DATA_ALIGN_LEFT Notes Refer to reference manual for alignments formats dependencies to ADC resolutions. Reference Manual to ataAlignment CR2 ALIGN LL_ADC_SetD LL API cross reference: LL_ADC_SetSequencersScanMode __STATIC_INLINE void LL_ADC_SetSequencersScanMode Function name (ADC_TypeDef * ADCx, uint32_t ScanMode) Set ADC sequencers scan mode, for all ADC groups (group Function description regular, group injected). Parameters ADCx: ADC instance ScanMode: This parameter can be one of the following values: LL_ADC_SEQ_SCAN_DISABLE LL_ADC_SEQ_SCAN_ENABLE 2 DocID027328 Rev 1166 625 /

626 LL ADC Generic Driver UM1850 Return values None: Notes According to sequencers scan mode : If disabled: ADC y conversion mode (one conversion is performed in unitar channel converted, that defined in rank 1). Configuration of sequencers of all ADC groups (sequencer scan length, ...) is discarded: equivalent to scan length of 1 rank.If enabled: ADC conversions are performed in sequence conversion s mode, according to configuration of sequencers of each ADC group (sequencer scan length, ...). Refer to function LL_ADC_REG_SetSequencerLength() and to function LL_ADC_INJ_SetSequencerLength(). Reference Manual to LL_ADC_SetSequencersScanMode CR1 SCAN LL API cross reference: LL_ADC_GetSequencersScanMode __STATIC_INLINE uint32_t Function name LL_ADC_GetSequencersScanMode (ADC_TypeDef * ADCx) Get ADC sequencers scan mode, for all ADC groups (group Function description regular, group injected). rameters Pa ADC instance ADCx: Return values Returned: value can be one of the following values: LL_ADC_SEQ_SCAN_DISABLE LL_ADC_SEQ_SCAN_ENABLE Notes According to sequencers scan mode : If disabled: ADC conversion is performed in unitary conversion mode (one channel converted, that defined in rank 1). Configuration of sequencers of all ADC groups (sequencer scan length, ...) is discarded: equivalent to scan length of 1 rank.If enabled: ADC conversions are performed in sequence conversions mode, according to configuration of sequencers of each ADC group (sequencer scan length, ...). Refer to function LL_ADC_REG_SetSequencerLength() and to function LL_ADC_ INJ_SetSequencerLength(). Reference Manual to CR1 SCAN LL_ADC_GetSequencersScanMode LL API cross reference: LL_ADC_REG_SetTriggerSource __STATIC_INLINE void LL_ADC_REG_SetTriggerSource Function name (ADC_TypeDef * ADCx, uint32_t TriggerSource) description Function Set ADC group regular conversion trigger source: internal (SW start) or from external IP (timer event, external interrupt line). Parameters ADC instance ADCx: This parameter can be one of the following TriggerSource: 1, parameter available on all ADC values: (1) On STM32F instances: ADC1, ADC2, ADC3 (for ADC instances ADCx available on the selected device). DocID027328 / 1166 626 Rev 2

627 UM1850 ADC Generic Driver LL LL_ADC_REG_TRIG_SOFTWARE LL_ADC_REG_TRIG_EXT_TIM1_CH3 (1) LL_ADC_REG_TRIG_EXT_TIM1_CH1 (2) LL_ADC_REG_TRIG_EXT_TIM1_CH2 (2) LL_ADC_REG_TRIG_EXT_TIM2_CH2 (2) LL_ADC_REG_TRIG_EXT_TIM3_TRGO (2) LL_ADC_REG_TRIG_EXT_TIM4_CH4 (2) LL_ADC_REG_TRIG_EXT_EXTI_LINE11 (2) LL_ADC_REG_TRIG_EXT_TIM8_TRGO (2)(4) LL_ADC_REG_TRIG_EXT_TIM8_TRGO_ADC3 (3) LL_ADC_REG_TRIG_EXT_TIM3_CH1 (3) LL_ADC_REG_TRIG_EXT_TIM2_CH3 (3) LL_ADC_REG_TRIG_EXT_TIM8_CH1 (3) LL_ADC_REG_TRIG_EXT_TIM8_TRGO (3) LL_ADC_REG_TRIG_EXT_TIM5_CH1 (3) LL_ADC_REG_TRIG_EXT_TIM5_CH3 (3) (2) On STM32F1, parameter available only on ADC instances: ADC1, ADC2 (for ADC instances ADCx available on the selected device). (3) On STM32F1, parameter available only on ADC instances: ADC3 (for ADC instances ADCx available on the selected device). - (4) On STM32F1, parameter available only on high density and XL - density devices. A remap of trigger must be done at top level (refer to AFIO peripheral). Return values None: Notes On this STM32 serie, external trigger is set with trigger polarity: rising edge (only trigger polarity available on this STM32 serie). Availability of parameters of trigger sources from timer depends on timers availability on the selected device. Reference Manual to CR2 EXTSEL LL_ADC_REG_SetTriggerSource LL API cross reference: LL_ADC_REG_GetTriggerSource __STATIC_INLINE uint32_t LL_ADC_REG_GetTrigger Source Function name (ADC_TypeDef * ADCx) Get ADC group regular conversion trigger source: internal (SW Function description start) or from external IP (timer event, external interrupt line). Parameters ADCx: ADC instance Return values value can be one of the following values: (1) On Returned: STM32F1, parameter available on all ADC instances: ADC1, ADC2, ADC3 (for ADC instances ADCx available on the selected device). LL_ADC_REG_TRIG_SOFTWARE LL_ADC_REG_TRIG_EXT_TIM1_CH3 (1) TIM1_CH1 (2) LL_ADC_REG_TRIG_EXT_ LL_ADC_REG_TRIG_EXT_TIM1_CH2 (2) 2 DocID027328 Rev 1166 627 /

628 LL UM1850 ADC Generic Driver LL_ADC_REG_TRIG_EXT_TIM2_CH2 (2) LL_ADC_REG_TRIG_EXT_TIM3_TRGO (2) LL_ADC_REG_TRIG_EXT_TIM4_CH4 (2) LL_ADC_REG_TRIG_EXT_EXTI_LINE11 (2) LL_ADC_REG_TRIG_EXT_TIM8_TRGO (2)(4) ) LL_ADC_REG_TRIG_EXT_TIM8_TRGO_ADC3 (3 LL_ADC_REG_TRIG_EXT_TIM3_CH1 (3) LL_ADC_REG_TRIG_EXT_TIM2_CH3 (3) LL_ADC_REG_TRIG_EXT_TIM8_CH1 (3) LL_ADC_REG_TRIG_EXT_TIM8_TRGO (3) LL_ADC_REG_TRIG_EXT_TIM5_CH1 (3) LL_ADC_REG_TRIG_EXT_TIM5_CH3 (3) (2) On STM32F1, parameter available only on ADC instan ces: ADC1, ADC2 (for ADC instances ADCx available on the selected device). (3) On STM32F1, parameter available only on ADC instances: ADC3 (for ADC instances ADCx available on the selected device). density - (4) On STM32F1, parameter available only on high - and XL density devices. A remap of trigger must be done at top level (refer to AFIO peripheral). Notes To determine whether group regular trigger source is internal detail of which peripheral is (SW start) or external, without selected as external trigger, (equivalent to "if(LL_ADC_REG_GetTriggerSource(ADC1) == LL_ADC_REG_TRIG_SOFTWARE)") use function LL_ADC_REG_IsTriggerSourceSWStart. Availability of parameters of trigger sources from timer on timers availability on the selected device. depends Reference Manual to CR2 EXTSEL LL_ADC_REG_GetTriggerSource LL API cross reference: LL_ADC_REG_IsTriggerSourceSWStart __STATIC_INLINE uint32_t Function name LL_ADC_REG_IsTriggerSourceSWStart (ADC_TypeDef * A DCx) Get ADC group regular conversion trigger source internal (SW Function description start) or external. Parameters ADC instance ADCx: Return values "0" if trigger source external trigger Value "1" if trigger Value: source SW start. Notes of group regular trigger source set to external trigger, In case to determine which peripheral is selected as external trigger, use function LL_ADC_REG_GetTriggerSource(). Reference Manual to CR2 EXTSEL LL_ADC_REG_IsTriggerSourceSWStart LL API cross reference: 628 DocID027328 / Rev 1166 2

629 UM1850 ADC Generic Driver LL L_ADC_REG_SetSequencerLength L __STATIC_INLINE void LL_ADC_REG_SetSequencerLength Function name (ADC_TypeDef * ADCx, uint32_t SequencerNbRanks) Function description Set ADC group regular sequencer length and scan direction. Parameters ADCx: ADC instance SequencerNbRanks: This parameter can be one of the following values: LL_ADC_REG_SEQ_SCAN_DISABLE LL_ADC_REG_SEQ_SCAN_ENABLE_2RANKS LL_ADC_REG_SEQ_SCAN_ENABLE_3RANKS LL_ADC_REG_SEQ_SCAN_ENABLE_4RANKS LL_ADC_REG_SEQ_SCAN_ENABLE_5RANKS LL_ADC_REG_SEQ_SCAN_ENABLE_6RANKS LL_ADC_REG_SEQ_SCAN_ENABLE_7RANKS LL_ADC_REG_SEQ_SCAN_ENABLE_8RANKS LL_ADC_REG_SEQ_SCAN_ENABLE_9RANKS LL_ADC_REG_SEQ_SCAN_ENABLE_10RANKS LL_ADC_REG_SEQ_SCAN_ENABLE_11RANKS LL_ADC_REG_SEQ_SCAN_ENABLE_12RANKS SCAN_ENABLE_13RANKS LL_ADC_REG_SEQ_ LL_ADC_REG_SEQ_SCAN_ENABLE_14RANKS LL_ADC_REG_SEQ_SCAN_ENABLE_15RANKS LL_ADC_REG_SEQ_SCAN_ENABLE_16RANKS Return values None: Notes Description of ADC group regular sequencer features: For devices with sequencer fully configurable (function "LL_ADC_REG_SetSequencerRanks()" available): sequencer length and each rank affectation to a channel are guration of: configurable. This function performs confi Sequence length: Number of ranks in the scan sequence.Sequence direction: Unless specified in parameters, sequencer scan direction is forward (from rank 1 to rank n). Sequencer ranks are selected using function . For devices with "LL_ADC_REG_SetSequencerRanks()" sequencer not fully configurable (function "LL_ADC_REG_SetSequencerChannels()" available): sequencer length and each rank affectation to a channel are defined by channel number. This function performs configuration of: Sequence length: N umber of ranks in the scan sequence is defined by number of channels set in the sequence, rank of each channel is fixed by channel HW number. (channel 0 fixed on rank 0, channel 1 fixed on rank1, ...).Sequence direction: Unless specified in parameters, uencer scan direction is forward (from lowest channel seq number to highest channel number). Sequencer ranks are selected using function "LL_ADC_REG_SetSequencerChannels()". On this STM32 serie, group regular sequencer configuration ance sequencer mode. If ADC is conditioned to ADC inst instance sequencer mode is disabled, sequencers of all groups (group regular, group injected) can be configured but their execution is disabled (limited to rank 1). Refer to function 2 DocID027328 Rev 1166 629 /

630 LL UM1850 ADC Generic Driver LL_ADC_SetSequencersScanMode(). abled is equivalent to sequencer of 1 rank: Sequencer dis ADC conversion on only 1 channel. Reference Manual to SQR1 L LL_ADC_REG_SetSequencerLength LL API cross reference: LL_ADC_REG_GetSequencerLength __STATIC_INLINE uint32_t Function name LL_ADC_REG_GetSequencerLen gth (ADC_TypeDef * ADCx) Function description Get ADC group regular sequencer length and scan direction. Parameters ADC instance ADCx: Return values value can be one of the following values: Returned: LL_ADC_REG_SEQ_SCAN_DISABLE LL_ADC_REG_SEQ_SCAN_ENABLE_2RANKS LL_ADC_REG_SEQ_SCAN_ENABLE_3RANKS LL_ADC_REG_SEQ_SCAN_ENABLE_4RANKS LL_ADC_REG_SEQ_SCAN_ENABLE_5RANKS LL_ADC_REG_SEQ_SCAN_ENABLE_6RANKS LL_ADC_REG_SEQ_SCAN_ENABLE_7RANKS LL_ADC_REG_SEQ_SCAN_ENABLE_8RANKS LL_ADC_REG_SEQ_SCA N_ENABLE_9RANKS LL_ADC_REG_SEQ_SCAN_ENABLE_10RANKS LL_ADC_REG_SEQ_SCAN_ENABLE_11RANKS LL_ADC_REG_SEQ_SCAN_ENABLE_12RANKS LL_ADC_REG_SEQ_SCAN_ENABLE_13RANKS LL_ADC_REG_SEQ_SCAN_ENABLE_14RANKS LL_ADC_REG_SEQ_SCAN_ENABLE_15RANKS ANKS LL_ADC_REG_SEQ_SCAN_ENABLE_16R Notes Description of ADC group regular sequencer features: For devices with sequencer fully configurable (function "LL_ADC_REG_SetSequencerRanks()" available): sequencer length and each rank affectation to a channel are uence length: configurable. This function retrieves: Seq Number of ranks in the scan sequence.Sequence direction: Unless specified in parameters, sequencer scan direction is forward (from rank 1 to rank n). Sequencer ranks are selected using function