1 /** 2 ****************************************************************************** 3 * @file stm32u0xx_hal_adc.h 4 * @author MCD Application Team 5 * @brief Header file of ADC HAL module. 6 ****************************************************************************** 7 * @attention 8 * 9 * Copyright (c) 2023 STMicroelectronics. 10 * All rights reserved. 11 * 12 * This software is licensed under terms that can be found in the LICENSE file 13 * in the root directory of this software component. 14 * If no LICENSE file comes with this software, it is provided AS-IS. 15 * 16 ****************************************************************************** 17 */ 18 19 /* Define to prevent recursive inclusion -------------------------------------*/ 20 #ifndef STM32U0xx_HAL_ADC_H 21 #define STM32U0xx_HAL_ADC_H 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 /* Includes ------------------------------------------------------------------*/ 28 #include "stm32u0xx_hal_def.h" 29 30 /* Include low level driver */ 31 #include "stm32u0xx_ll_adc.h" 32 33 /** @addtogroup STM32U0xx_HAL_Driver 34 * @{ 35 */ 36 37 /** @addtogroup ADC 38 * @{ 39 */ 40 41 /* Exported types ------------------------------------------------------------*/ 42 /** @defgroup ADC_Exported_Types ADC Exported Types 43 * @{ 44 */ 45 46 /** 47 * @brief ADC group regular oversampling structure definition 48 */ 49 typedef struct 50 { 51 uint32_t Ratio; /*!< Configures the oversampling ratio. 52 This parameter can be a value of @ref ADC_HAL_EC_OVS_RATIO */ 53 54 uint32_t RightBitShift; /*!< Configures the division coefficient for the Oversampler. 55 This parameter can be a value of @ref ADC_HAL_EC_OVS_SHIFT */ 56 57 uint32_t TriggeredMode; /*!< Selects the regular triggered oversampling mode. 58 This parameter can be a value of @ref ADC_HAL_EC_OVS_DISCONT_MODE */ 59 60 } ADC_OversamplingTypeDef; 61 62 /** 63 * @brief Structure definition of ADC instance and ADC group regular. 64 * @note Parameters of this structure are shared within 2 scopes: 65 * - Scope entire ADC (differentiation done for compatibility with some other STM32 series featuring ADC 66 * groups regular and injected): ClockPrescaler, Resolution, DataAlign, 67 * ScanConvMode, EOCSelection, LowPowerAutoWait. 68 * - Scope ADC group regular: ContinuousConvMode, NbrOfConversion, DiscontinuousConvMode, 69 * ExternalTrigConv, ExternalTrigConvEdge, DMAContinuousRequests, Overrun, OversamplingMode, Oversampling. 70 * @note The setting of these parameters by function HAL_ADC_Init() is conditioned to ADC state. 71 * ADC state can be either: 72 * - For all parameters: ADC disabled 73 * - For all parameters except 'ClockPrescaler' and 'Resolution': ADC enabled without conversion on going on 74 * group regular. 75 * If ADC is not in the appropriate state to modify some parameters, these parameters setting is bypassed 76 * without error reporting (as it can be the expected behavior in case of intended action to update another 77 * parameter (which fulfills the ADC state condition) on the fly). 78 */ 79 typedef struct 80 { 81 uint32_t ClockPrescaler; /*!< Select ADC clock source (synchronous clock derived from APB clock or asynchronous 82 clock derived from system clock or PLL (Refer to reference manual for list of 83 clocks available)) and clock prescaler. 84 This parameter can be a value of @ref ADC_HAL_EC_COMMON_CLOCK_SOURCE. 85 Note: The ADC clock configuration is common to all ADC instances. 86 Note: In case of synchronous clock mode based on HCLK/1, the configuration must 87 be enabled only if the system clock has a 50% duty clock cycle (APB 88 prescaler configured inside RCC must be bypassed and PCLK clock must have 89 50% duty cycle). Refer to reference manual for details. 90 Note: In case of usage of asynchronous clock, the selected clock must be 91 preliminarily enabled at RCC top level. 92 Note: This parameter can be modified only if all ADC instances are disabled. */ 93 94 uint32_t Resolution; /*!< Configure the ADC resolution. 95 This parameter can be a value of @ref ADC_HAL_EC_RESOLUTION */ 96 97 uint32_t DataAlign; /*!< Specify ADC data alignment in conversion data register (right or left). 98 Refer to reference manual for alignments formats versus resolutions. 99 This parameter can be a value of @ref ADC_HAL_EC_DATA_ALIGN */ 100 101 uint32_t ScanConvMode; /*!< Configure the sequencer of ADC group regular. 102 On this STM32 series, ADC group regular sequencer both modes "fully configurable" 103 or "not fully configurable" are available: 104 - sequencer configured to fully configurable: 105 sequencer length and each rank affectation to a channel are configurable. 106 - Sequence length: Set number of ranks in the scan sequence. 107 - Sequence direction: Unless specified in parameters, sequencer 108 scan direction is forward (from rank 1 to rank n). 109 - sequencer configured to not fully configurable: 110 sequencer length and each rank affectation to a channel are fixed by channel 111 HW number. 112 - Sequence length: Number of ranks in the scan sequence is 113 defined by number of channels set in the sequence, 114 rank of each channel is fixed by channel HW number. 115 (channel 0 fixed on rank 0, channel 1 fixed on rank1, ...). 116 - Sequence direction: Unless specified in parameters, sequencer 117 scan direction is forward (from lowest channel number to 118 highest channel number). 119 This parameter can be associated to parameter 'DiscontinuousConvMode' to have 120 main sequence subdivided in successive parts. Sequencer is automatically enabled 121 if several channels are set (sequencer cannot be disabled, as it can be the case 122 on other STM32 devices): 123 If only 1 channel is set: Conversion is performed in single mode. 124 If several channels are set: Conversions are performed in sequence mode. 125 This parameter can be a value of @ref ADC_Scan_mode */ 126 127 uint32_t EOCSelection; /*!< Specify which EOC (End Of Conversion) flag is used for conversion by polling and 128 interruption: end of unitary conversion or end of sequence conversions. 129 This parameter can be a value of @ref ADC_EOCSelection. */ 130 131 FunctionalState LowPowerAutoWait; /*!< Select the dynamic low power Auto Delay: new conversion start only when the 132 previous conversion (for ADC group regular) has been retrieved by user software, 133 using function HAL_ADC_GetValue(). 134 This feature automatically adapts the frequency of ADC conversions triggers to 135 the speed of the system that reads the data. Moreover, this avoids risk of 136 overrun for low frequency applications. 137 This parameter can be set to ENABLE or DISABLE. 138 Note: It is not recommended to use with interruption or DMA (HAL_ADC_Start_IT(), 139 HAL_ADC_Start_DMA()) since these modes have to clear immediately the EOC 140 flag (by CPU to free the IRQ pending event or by DMA). 141 Auto wait will work but fort a very short time, discarding its intended 142 benefit (except specific case of high load of CPU or DMA transfers which 143 can justify usage of auto wait). 144 Do use with polling: 1. Start conversion with HAL_ADC_Start(), 2. Later on, 145 when ADC conversion data is needed: 146 use HAL_ADC_PollForConversion() to ensure that conversion is completed and 147 HAL_ADC_GetValue() to retrieve conversion result and trig another 148 conversion start. */ 149 150 FunctionalState LowPowerAutoPowerOff; /*!< Select the auto-off mode: the ADC automatically powers-off after a 151 conversion and automatically wakes-up when a new conversion is triggered 152 (with startup time between trigger and start of sampling). 153 This feature can be combined with automatic wait mode 154 (parameter 'LowPowerAutoWait'). 155 This parameter can be set to ENABLE or DISABLE. */ 156 157 FunctionalState ContinuousConvMode; /*!< Specify whether the conversion is performed in single mode (one conversion) 158 or continuous mode for ADC group regular, after the first ADC conversion 159 start trigger occurred (software start or external trigger). This parameter 160 can be set to ENABLE or DISABLE. */ 161 162 uint32_t NbrOfConversion; /*!< Specify the number of ranks that will be converted within the regular group 163 sequencer. 164 This parameter is dependent on ScanConvMode: 165 - sequencer configured to fully configurable: 166 Number of ranks in the scan sequence is configurable using this parameter. 167 Note: After the first call of 'HAL_ADC_Init()', each rank corresponding to 168 parameter "NbrOfConversion" must be set using 'HAL_ADC_ConfigChannel()'. 169 Afterwards, when all needed sequencer ranks are set, parameter 170 'NbrOfConversion' can be updated without modifying configuration of 171 sequencer ranks (sequencer ranks above 'NbrOfConversion' are discarded). 172 - sequencer configured to not fully configurable: 173 Number of ranks in the scan sequence is defined by number of channels set in 174 the sequence. This parameter is discarded. 175 This parameter must be a number between Min_Data = 1 and Max_Data = 8. 176 Note: This parameter must be modified when no conversion is on going on regular 177 group (ADC disabled, or ADC enabled without continuous mode or external 178 trigger that could launch a conversion). */ 179 180 FunctionalState DiscontinuousConvMode; /*!< Specify whether the conversions sequence of ADC group regular is performed 181 in Complete-sequence/Discontinuous-sequence (main sequence subdivided in 182 successive parts). 183 Discontinuous mode is used only if sequencer is enabled (parameter 184 'ScanConvMode'). If sequencer is disabled, this parameter is discarded. 185 Discontinuous mode can be enabled only if continuous mode is disabled. 186 If continuous mode is enabled, this parameter setting is discarded. 187 This parameter can be set to ENABLE or DISABLE. 188 Note: On this STM32 series, ADC group regular number of discontinuous 189 ranks increment is fixed to one-by-one. */ 190 191 uint32_t ExternalTrigConv; /*!< Select the external event source used to trigger ADC group regular conversion 192 start. 193 If set to ADC_SOFTWARE_START, external triggers are disabled and software trigger 194 is used instead. 195 This parameter can be a value of @ref ADC_regular_external_trigger_source. 196 Caution: external trigger source is common to all ADC instances. */ 197 198 uint32_t ExternalTrigConvEdge; /*!< Select the external event edge used to trigger ADC group regular conversion start 199 If trigger source is set to ADC_SOFTWARE_START, this parameter is discarded. 200 This parameter can be a value of @ref ADC_regular_external_trigger_edge */ 201 202 FunctionalState DMAContinuousRequests; /*!< Specify whether the DMA requests are performed in one shot mode (DMA 203 transfer stops when number of conversions is reached) or in continuous 204 mode (DMA transfer unlimited, whatever number of conversions). 205 This parameter can be set to ENABLE or DISABLE. 206 Note: In continuous mode, DMA must be configured in circular mode. 207 Otherwise an overrun will be triggered when DMA buffer maximum 208 pointer is reached. */ 209 210 uint32_t Overrun; /*!< Select the behavior in case of overrun: data overwritten or preserved (default). 211 This parameter can be a value of @ref ADC_HAL_EC_REG_OVR_DATA_BEHAVIOR. 212 Note: In case of overrun set to data preserved and usage with programming model 213 with interruption (HAL_Start_IT()): ADC IRQ handler has to clear end of 214 conversion flags, this induces the release of the preserved data. If 215 needed, this data can be saved in function HAL_ADC_ConvCpltCallback(), 216 placed in user program code (called before end of conversion flags clear) 217 Note: Error reporting with respect to the conversion mode: 218 - Usage with ADC conversion by polling for event or interruption: Error is 219 reported only if overrun is set to data preserved. If overrun is set to 220 data overwritten, user can willingly not read all the converted data, 221 this is not considered as an erroneous case. 222 - Usage with ADC conversion by DMA: Error is reported whatever overrun 223 setting (DMA is expected to process all data from data register). */ 224 225 uint32_t SamplingTimeCommon1; /*!< Set sampling time common to a group of channels. 226 Unit: ADC clock cycles 227 Conversion time is the addition of sampling time and processing time 228 (12.5 ADC clock cycles at ADC resolution 12 bits, 229 10.5 cycles at 10 bits, 230 8.5 cycles at 8 bits, 231 6.5 cycles at 6 bits). 232 Note: On this STM32 family, two different sampling time settings are available, 233 each channel can use one of these two settings. On some other STM32 devices 234 this parameter in channel wise and is located into ADC channel 235 initialization structure. 236 This parameter can be a value of @ref ADC_HAL_EC_CHANNEL_SAMPLINGTIME 237 Note: In case of usage of internal measurement channels (VrefInt/Vbat/TempSensor) 238 sampling time constraints must be respected (sampling time can be adjusted 239 in function of ADC clock frequency and sampling time setting) 240 Refer to device datasheet for timings values, parameters TS_vrefint, 241 TS_vbat, TS_temp (values rough order: few tens of microseconds). */ 242 243 uint32_t SamplingTimeCommon2; /*!< Set sampling time common to a group of channels, second common setting possible. 244 Unit: ADC clock cycles 245 Conversion time is the addition of sampling time and processing time 246 (12.5 ADC clock cycles at ADC resolution 12 bits, 247 10.5 cycles at 10 bits, 248 8.5 cycles at 8 bits, 249 6.5 cycles at 6 bits). 250 Note: On this STM32 family, two different sampling time settings are available, 251 each channel can use one of these two settings. On some other STM32 devices 252 this parameter in channel wise and is located into ADC channel 253 initialization structure. 254 This parameter can be a value of @ref ADC_HAL_EC_CHANNEL_SAMPLINGTIME 255 Note: In case of usage of internal measurement channels (VrefInt/Vbat/TempSensor) 256 sampling time constraints must be respected (sampling time can be adjusted 257 in function of ADC clock frequency and sampling time setting) 258 Refer to device datasheet for timings values, parameters TS_vrefint, 259 TS_vbat, TS_temp (values rough order: few tens of microseconds). */ 260 261 FunctionalState OversamplingMode; /*!< Specify whether the oversampling feature is enabled or disabled. 262 This parameter can be set to ENABLE or DISABLE. 263 Note: This parameter can be modified only if there is no conversion is 264 ongoing on ADC group regular. */ 265 266 ADC_OversamplingTypeDef Oversampling; /*!< Specify the Oversampling parameters. 267 Caution: this setting overwrites the previous oversampling configuration 268 if oversampling is already enabled. */ 269 270 uint32_t TriggerFrequencyMode; /*!< Set ADC trigger frequency mode. 271 This parameter can be a value of @ref ADC_HAL_EC_REG_TRIGGER_FREQ. 272 Note: ADC trigger frequency mode must be set to low frequency when 273 a duration is exceeded before ADC conversion start trigger event 274 (between ADC enable and ADC conversion start trigger event 275 or between two ADC conversion start trigger event). 276 Duration value: Refer to device datasheet, parameter "tIdle". 277 Note: When ADC trigger frequency mode is set to low frequency, 278 some rearm cycles are inserted before performing ADC conversion 279 start, inducing a delay of 2 ADC clock cycles. */ 280 281 } ADC_InitTypeDef; 282 283 /** 284 * @brief Structure definition of ADC channel for regular group 285 * @note The setting of these parameters by function HAL_ADC_ConfigChannel() is conditioned to ADC state. 286 * ADC state can be either: 287 * - For all parameters: ADC disabled or enabled without conversion on going on regular group. 288 * If ADC is not in the appropriate state to modify some parameters, these parameters setting is bypassed 289 * without error reporting (as it can be the expected behavior in case of intended action to update another 290 * parameter (which fulfills the ADC state condition) on the fly). 291 */ 292 typedef struct 293 { 294 uint32_t Channel; /*!< Specify the channel to configure into ADC regular group. 295 This parameter can be a value of @ref ADC_HAL_EC_CHANNEL 296 Note: Depending on devices and ADC instances, some channels may not be available 297 on device package pins. Refer to device datasheet for channels 298 availability. */ 299 300 uint32_t Rank; /*!< Add or remove the channel from ADC regular group sequencer and specify its 301 conversion rank. 302 This parameter is dependent on ScanConvMode: 303 - sequencer configured to fully configurable: 304 Channels ordering into each rank of scan sequence: 305 whatever channel can be placed into whatever rank. 306 - sequencer configured to not fully configurable: 307 rank of each channel is fixed by channel HW number. 308 (channel 0 fixed on rank 0, channel 1 fixed on rank1, ...). 309 Despite the channel rank is fixed, this parameter allow an additional 310 possibility: to remove the selected rank (selected channel) from sequencer. 311 This parameter can be a value of @ref ADC_HAL_EC_REG_SEQ_RANKS */ 312 313 uint32_t SamplingTime; /*!< Sampling time value to be set for the selected channel. 314 Unit: ADC clock cycles 315 Conversion time is the addition of sampling time and processing time 316 (12.5 ADC clock cycles at ADC resolution 12 bits, 317 10.5 cycles at 10 bits, 318 8.5 cycles at 8 bits, 319 6.5 cycles at 6 bits). 320 This parameter can be a value of @ref ADC_HAL_EC_SAMPLINGTIME_COMMON 321 Note: On this STM32 family, two different sampling time settings are available 322 (refer to parameters "SamplingTimeCommon1" and "SamplingTimeCommon2"), 323 each channel can use one of these two settings. 324 325 Note: In case of usage of internal measurement channels (VrefInt/Vbat/ 326 TempSensor), sampling time constraints must be respected (sampling time 327 can be adjusted in function of ADC clock frequency and sampling time 328 setting) 329 Refer to device datasheet for timings values. */ 330 331 } ADC_ChannelConfTypeDef; 332 333 /** 334 * @brief Structure definition of ADC analog watchdog 335 * @note The setting of these parameters by function HAL_ADC_AnalogWDGConfig() is conditioned to ADC state. 336 * ADC state can be either: 337 * - For all parameters except 'HighThreshold', 'LowThreshold': ADC disabled or ADC enabled without conversion 338 on going on ADC groups regular. 339 * - For parameters 'HighThreshold', 'LowThreshold': ADC enabled with conversion on going on regular. 340 */ 341 typedef struct 342 { 343 uint32_t WatchdogNumber; /*!< Select which ADC analog watchdog is monitoring the selected channel. 344 For Analog Watchdog 1: Only 1 channel can be monitored (or overall group of channels 345 by setting parameter 'WatchdogMode') 346 For Analog Watchdog 2 and 3: Several channels can be monitored (by successive calls 347 of 'HAL_ADC_AnalogWDGConfig()' for each channel) 348 This parameter can be a value of @ref ADC_HAL_EC_AWD_NUMBER. */ 349 350 uint32_t WatchdogMode; /*!< Configure the ADC analog watchdog mode: single/all/none channels. 351 For Analog Watchdog 1: Configure the ADC analog watchdog mode: single channel or all 352 channels, ADC group regular. 353 For Analog Watchdog 2 and 3: Several channels can be monitored by applying 354 successively the AWD init structure. 355 This parameter can be a value of @ref ADC_analog_watchdog_mode. */ 356 357 uint32_t Channel; /*!< Select which ADC channel to monitor by analog watchdog. 358 For Analog Watchdog 1: this parameter has an effect only if parameter 'WatchdogMode' 359 is configured on single channel (only 1 channel can be 360 monitored). 361 For Analog Watchdog 2 and 3: Several channels can be monitored. To use this feature, 362 call successively the function HAL_ADC_AnalogWDGConfig() 363 for each channel to be added (or removed with value 364 'ADC_ANALOGWATCHDOG_NONE'). 365 This parameter can be a value of @ref ADC_HAL_EC_CHANNEL. */ 366 367 FunctionalState ITMode; /*!< Specify whether the analog watchdog is configured in interrupt or polling mode. 368 This parameter can be set to ENABLE or DISABLE */ 369 370 uint32_t HighThreshold; /*!< Configure the ADC analog watchdog High threshold value. 371 Depending of ADC resolution selected (12, 10, 8 or 6 bits), this parameter must be a 372 number between Min_Data = 0x000 and Max_Data = 0xFFF, 0x3FF, 0xFF or 0x3F 373 respectively. 374 Note: Analog watchdog 2 and 3 are limited to a resolution of 8 bits: if ADC 375 resolution is 12 bits the 4 LSB are ignored, if ADC resolution is 10 bits the 2 376 LSB are ignored. 377 Note: If ADC oversampling is enabled, ADC analog watchdog thresholds are 378 impacted: the comparison of analog watchdog thresholds is done on 379 oversampling final computation (after ratio and shift application): 380 ADC data register bitfield [15:4] (12 most significant bits). */ 381 382 uint32_t LowThreshold; /*!< Configures the ADC analog watchdog Low threshold value. 383 Depending of ADC resolution selected (12, 10, 8 or 6 bits), this parameter must be a 384 number between Min_Data = 0x000 and Max_Data = 0xFFF, 0x3FF, 0xFF or 0x3F 385 respectively. 386 Note: Analog watchdog 2 and 3 are limited to a resolution of 8 bits: if ADC 387 resolution is 12 bits the 4 LSB are ignored, if ADC resolution is 10 bits the 2 388 LSB are ignored. 389 Note: If ADC oversampling is enabled, ADC analog watchdog thresholds are 390 impacted: the comparison of analog watchdog thresholds is done on 391 oversampling final computation (after ratio and shift application): 392 ADC data register bitfield [15:4] (12 most significant bits).*/ 393 } ADC_AnalogWDGConfTypeDef; 394 395 /** @defgroup ADC_States ADC States 396 * @{ 397 */ 398 399 /** 400 * @brief HAL ADC state machine: ADC states definition (bitfields) 401 * @note ADC state machine is managed by bitfields, state must be compared 402 * with bit by bit. 403 * For example: 404 * " if ((HAL_ADC_GetState(hadc1) & HAL_ADC_STATE_REG_BUSY) != 0UL) " 405 * " if ((HAL_ADC_GetState(hadc1) & HAL_ADC_STATE_AWD1) != 0UL) " 406 */ 407 /* States of ADC global scope */ 408 #define HAL_ADC_STATE_RESET (0x00000000UL) /*!< ADC not yet initialized or disabled */ 409 #define HAL_ADC_STATE_READY (0x00000001UL) /*!< ADC peripheral ready for use */ 410 #define HAL_ADC_STATE_BUSY_INTERNAL (0x00000002UL) /*!< ADC is busy from internal process (ex : calibration, ...) */ 411 #define HAL_ADC_STATE_TIMEOUT (0x00000004UL) /*!< TimeOut occurrence */ 412 413 /* States of ADC errors */ 414 #define HAL_ADC_STATE_ERROR_INTERNAL (0x00000010UL) /*!< Internal error occurrence */ 415 #define HAL_ADC_STATE_ERROR_CONFIG (0x00000020UL) /*!< Configuration error occurrence */ 416 #define HAL_ADC_STATE_ERROR_DMA (0x00000040UL) /*!< DMA error occurrence */ 417 418 /* States of ADC group regular */ 419 #define HAL_ADC_STATE_REG_BUSY (0x00000100UL) /*!< A conversion on ADC group regular is ongoing or can occur 420 (either by continuous mode, external trigger, low power 421 auto power-on (if feature available), multimode ADC master 422 control (if feature available)) */ 423 #define HAL_ADC_STATE_REG_EOC (0x00000200UL) /*!< Conversion data available on group regular */ 424 #define HAL_ADC_STATE_REG_OVR (0x00000400UL) /*!< Overrun occurrence */ 425 #define HAL_ADC_STATE_REG_EOSMP (0x00000800UL) /*!< Not available on this STM32 series: End Of Sampling flag 426 raised */ 427 428 /* States of ADC group injected */ 429 #define HAL_ADC_STATE_INJ_BUSY (0x00001000UL) /*!< Not available on this STM32 series: A conversion on group 430 injected is ongoing or can occur (either by auto-injection 431 mode, external trigger, low power auto power-on (if feature 432 available), multimode ADC master control (if feature 433 available))*/ 434 #define HAL_ADC_STATE_INJ_EOC (0x00002000UL) /*!< Not available on this STM32 series: Conversion data 435 available on group injected */ 436 #define HAL_ADC_STATE_INJ_JQOVF (0x00004000UL) /*!< Not available on this STM32 series: Injected queue overflow 437 occurrence */ 438 439 /* States of ADC analog watchdogs */ 440 #define HAL_ADC_STATE_AWD1 (0x00010000UL) /*!< Out-of-window occurrence of ADC analog watchdog 1 */ 441 #define HAL_ADC_STATE_AWD2 (0x00020000UL) /*!< Out-of-window occurrence of ADC analog watchdog 2 */ 442 #define HAL_ADC_STATE_AWD3 (0x00040000UL) /*!< Out-of-window occurrence of ADC analog watchdog 3 */ 443 444 /* States of ADC multi-mode */ 445 #define HAL_ADC_STATE_MULTIMODE_SLAVE (0x00100000UL) /*!< Not available on this STM32 series: ADC in multimode slave 446 state, controlled by another ADC master (when feature 447 available) */ 448 449 450 /** 451 * @} 452 */ 453 454 /** 455 * @brief ADC handle Structure definition 456 */ 457 #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1) 458 typedef struct __ADC_HandleTypeDef 459 #else 460 typedef struct 461 #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */ 462 { 463 ADC_TypeDef *Instance; /*!< Register base address */ 464 ADC_InitTypeDef Init; /*!< ADC initialization parameters and regular conversions setting */ 465 DMA_HandleTypeDef *DMA_Handle; /*!< Pointer DMA Handler */ 466 HAL_LockTypeDef Lock; /*!< ADC locking object */ 467 __IO uint32_t State; /*!< ADC communication state (bitmap of ADC states) */ 468 __IO uint32_t ErrorCode; /*!< ADC Error code */ 469 470 uint32_t ADCGroupRegularSequencerRanks; /*!< ADC group regular sequencer memorization of ranks 471 setting, used in mode "fully configurable" (refer to 472 parameter 'ScanConvMode') */ 473 #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1) 474 void (* ConvCpltCallback)(struct __ADC_HandleTypeDef *hadc); /*!< ADC conversion complete callback */ 475 void (* ConvHalfCpltCallback)(struct __ADC_HandleTypeDef *hadc); /*!< ADC conversion DMA half-transfer 476 callback */ 477 void (* LevelOutOfWindowCallback)(struct __ADC_HandleTypeDef *hadc); /*!< ADC analog watchdog 1 callback */ 478 void (* ErrorCallback)(struct __ADC_HandleTypeDef *hadc); /*!< ADC error callback */ 479 void (* LevelOutOfWindow2Callback)(struct __ADC_HandleTypeDef *hadc); /*!< ADC analog watchdog 2 callback */ 480 void (* LevelOutOfWindow3Callback)(struct __ADC_HandleTypeDef *hadc); /*!< ADC analog watchdog 3 callback */ 481 void (* EndOfSamplingCallback)(struct __ADC_HandleTypeDef *hadc); /*!< ADC end of sampling callback */ 482 void (* CalibrationCpltCallback)(struct __ADC_HandleTypeDef *hadc); /*!< ADC end of calibration callback */ 483 void (* ADCReadyCallback)(struct __ADC_HandleTypeDef *hadc); /*!< ADC Ready callback */ 484 void (* ChannelConfigReadyCallback)(struct __ADC_HandleTypeDef *hadc); /*!< ADC Channel Configuration Ready callback */ 485 void (* MspInitCallback)(struct __ADC_HandleTypeDef *hadc); /*!< ADC Msp Init callback */ 486 void (* MspDeInitCallback)(struct __ADC_HandleTypeDef *hadc); /*!< ADC Msp DeInit callback */ 487 #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */ 488 } ADC_HandleTypeDef; 489 490 #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1) 491 /** 492 * @brief HAL ADC Callback ID enumeration definition 493 */ 494 typedef enum 495 { 496 HAL_ADC_CONVERSION_COMPLETE_CB_ID = 0x00U, /*!< ADC conversion complete callback ID */ 497 HAL_ADC_CONVERSION_HALF_CB_ID = 0x01U, /*!< ADC conversion DMA half-transfer callback ID */ 498 HAL_ADC_LEVEL_OUT_OF_WINDOW_1_CB_ID = 0x02U, /*!< ADC analog watchdog 1 callback ID */ 499 HAL_ADC_ERROR_CB_ID = 0x03U, /*!< ADC error callback ID */ 500 HAL_ADC_LEVEL_OUT_OF_WINDOW_2_CB_ID = 0x06U, /*!< ADC analog watchdog 2 callback ID */ 501 HAL_ADC_LEVEL_OUT_OF_WINDOW_3_CB_ID = 0x07U, /*!< ADC analog watchdog 3 callback ID */ 502 HAL_ADC_END_OF_SAMPLING_CB_ID = 0x08U, /*!< ADC end of sampling callback ID */ 503 HAL_ADC_MSPINIT_CB_ID = 0x09U, /*!< ADC Msp Init callback ID */ 504 HAL_ADC_MSPDEINIT_CB_ID = 0x0AU, /*!< ADC Msp DeInit callback ID */ 505 HAL_ADC_END_OF_CALIBRATION_CB_ID = 0x0BU, /*!< ADC end of calibration callback ID */ 506 HAL_ADC_ADC_READY_CB_ID = 0x0CU, /*!< ADC Ready callback ID */ 507 HAL_ADC_CONFIG_CHANNEL_ID = 0x0DU /*!< ADC config channel callback ID */ 508 } HAL_ADC_CallbackIDTypeDef; 509 510 /** 511 * @brief HAL ADC Callback pointer definition 512 */ 513 typedef void (*pADC_CallbackTypeDef)(ADC_HandleTypeDef *hadc); /*!< pointer to a ADC callback function */ 514 515 #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */ 516 517 /** 518 * @} 519 */ 520 521 522 /* Exported constants --------------------------------------------------------*/ 523 524 /** @defgroup ADC_Exported_Constants ADC Exported Constants 525 * @{ 526 */ 527 528 /** @defgroup ADC_Error_Code ADC Error Code 529 * @{ 530 */ 531 #define HAL_ADC_ERROR_NONE (0x00U) /*!< No error */ 532 #define HAL_ADC_ERROR_INTERNAL (0x01U) /*!< ADC peripheral internal error (problem of clocking, 533 enable/disable, erroneous state, ...) */ 534 #define HAL_ADC_ERROR_OVR (0x02U) /*!< Overrun error */ 535 #define HAL_ADC_ERROR_DMA (0x04U) /*!< DMA transfer error */ 536 #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1) 537 #define HAL_ADC_ERROR_INVALID_CALLBACK (0x10U) /*!< Invalid Callback error */ 538 #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */ 539 /** 540 * @} 541 */ 542 543 /** @defgroup ADC_HAL_EC_COMMON_CLOCK_SOURCE ADC common - Clock source 544 * @{ 545 */ 546 #define ADC_CLOCK_SYNC_PCLK_DIV1 (LL_ADC_CLOCK_SYNC_PCLK_DIV1) /*!< ADC synchronous clock from AHB clock 547 without prescaler. This configuration must be enabled only if PCLK has 548 a 50% duty clock cycle (APB prescaler configured inside the RCC must 549 be bypassed and the system clock must by 50% duty cycle) */ 550 #define ADC_CLOCK_SYNC_PCLK_DIV2 (LL_ADC_CLOCK_SYNC_PCLK_DIV2) /*!< ADC synchronous clock from AHB clock 551 with prescaler division by 2 */ 552 #define ADC_CLOCK_SYNC_PCLK_DIV4 (LL_ADC_CLOCK_SYNC_PCLK_DIV4) /*!< ADC synchronous clock from AHB clock 553 with prescaler division by 4 */ 554 555 #define ADC_CLOCK_ASYNC_DIV1 (LL_ADC_CLOCK_ASYNC_DIV1) /*!< ADC asynchronous clock without 556 prescaler */ 557 #define ADC_CLOCK_ASYNC_DIV2 (LL_ADC_CLOCK_ASYNC_DIV2) /*!< ADC asynchronous clock with prescaler 558 division by 2 */ 559 #define ADC_CLOCK_ASYNC_DIV4 (LL_ADC_CLOCK_ASYNC_DIV4) /*!< ADC asynchronous clock with prescaler 560 division by 4 */ 561 #define ADC_CLOCK_ASYNC_DIV6 (LL_ADC_CLOCK_ASYNC_DIV6) /*!< ADC asynchronous clock with prescaler 562 division by 6 */ 563 #define ADC_CLOCK_ASYNC_DIV8 (LL_ADC_CLOCK_ASYNC_DIV8) /*!< ADC asynchronous clock with prescaler 564 division by 8 */ 565 #define ADC_CLOCK_ASYNC_DIV10 (LL_ADC_CLOCK_ASYNC_DIV10) /*!< ADC asynchronous clock with prescaler 566 division by 10 */ 567 #define ADC_CLOCK_ASYNC_DIV12 (LL_ADC_CLOCK_ASYNC_DIV12) /*!< ADC asynchronous clock with prescaler 568 division by 12 */ 569 #define ADC_CLOCK_ASYNC_DIV16 (LL_ADC_CLOCK_ASYNC_DIV16) /*!< ADC asynchronous clock with prescaler 570 division by 16 */ 571 #define ADC_CLOCK_ASYNC_DIV32 (LL_ADC_CLOCK_ASYNC_DIV32) /*!< ADC asynchronous clock with prescaler 572 division by 32 */ 573 #define ADC_CLOCK_ASYNC_DIV64 (LL_ADC_CLOCK_ASYNC_DIV64) /*!< ADC asynchronous clock with prescaler 574 division by 64 */ 575 #define ADC_CLOCK_ASYNC_DIV128 (LL_ADC_CLOCK_ASYNC_DIV128) /*!< ADC asynchronous clock with prescaler 576 division by 128 */ 577 #define ADC_CLOCK_ASYNC_DIV256 (LL_ADC_CLOCK_ASYNC_DIV256) /*!< ADC asynchronous clock with prescaler 578 division by 256 */ 579 /** 580 * @} 581 */ 582 583 /** @defgroup ADC_HAL_EC_RESOLUTION ADC instance - Resolution 584 * @{ 585 */ 586 #define ADC_RESOLUTION_12B (LL_ADC_RESOLUTION_12B) /*!< ADC resolution 12 bits */ 587 #define ADC_RESOLUTION_10B (LL_ADC_RESOLUTION_10B) /*!< ADC resolution 10 bits */ 588 #define ADC_RESOLUTION_8B (LL_ADC_RESOLUTION_8B) /*!< ADC resolution 8 bits */ 589 #define ADC_RESOLUTION_6B (LL_ADC_RESOLUTION_6B) /*!< ADC resolution 6 bits */ 590 /** 591 * @} 592 */ 593 594 /** @defgroup ADC_HAL_EC_DATA_ALIGN ADC conversion data alignment 595 * @{ 596 */ 597 #define ADC_DATAALIGN_RIGHT (LL_ADC_DATA_ALIGN_RIGHT) /*!< ADC conversion data alignment: right aligned 598 (alignment on data register LSB bit 0)*/ 599 #define ADC_DATAALIGN_LEFT (LL_ADC_DATA_ALIGN_LEFT) /*!< ADC conversion data alignment: left aligned 600 (alignment on data register MSB bit 15)*/ 601 /** 602 * @} 603 */ 604 605 /** @defgroup ADC_Scan_mode ADC sequencer scan mode 606 * @{ 607 */ 608 /* Note: On this STM32 family, ADC group regular sequencer both modes */ 609 /* "fully configurable" or "not fully configurable" are */ 610 /* available. */ 611 /* Scan mode values must be compatible with other STM32 devices having */ 612 /* a configurable sequencer. */ 613 /* Scan direction setting values are defined by taking in account */ 614 /* already defined values for other STM32 devices: */ 615 /* ADC_SCAN_DISABLE (0x00000000UL) */ 616 /* ADC_SCAN_ENABLE (0x00000001UL) */ 617 /* Sequencer fully configurable with only rank 1 enabled is considered */ 618 /* as default setting equivalent to scan enable. */ 619 /* In case of migration from another STM32 device, the user will be */ 620 /* warned of change of setting choices with assert check. */ 621 /* Sequencer set to fully configurable */ 622 #define ADC_SCAN_DISABLE (0x00000000UL) /*!< Sequencer set to fully configurable: 623 only the rank 1 is enabled (no scan sequence on several ranks) */ 624 #define ADC_SCAN_ENABLE (ADC_CFGR1_CHSELRMOD) /*!< Sequencer set to fully configurable: 625 sequencer length and each rank affectation to a channel are configurable. */ 626 627 /* Sequencer set to not fully configurable */ 628 #define ADC_SCAN_SEQ_FIXED (ADC_SCAN_SEQ_FIXED_INT) /*!< Sequencer set to not fully configurable: 629 sequencer length and each rank affectation to a channel are fixed by 630 channel HW number (channel 0 fixed on rank 0, channel 1 fixed on rank1, ...). 631 Scan direction forward: from channel 0 to channel 18 */ 632 #define ADC_SCAN_SEQ_FIXED_BACKWARD (ADC_SCAN_SEQ_FIXED_INT \ 633 | ADC_CFGR1_SCANDIR) /*!< Sequencer set to not fully configurable: 634 sequencer length and each rank affectation to a channel are fixed by 635 channel HW number (channel 0 fixed on rank 0, channel 1 fixed on rank1, ...). 636 Scan direction backward: from channel 18 to channel 0 */ 637 638 #define ADC_SCAN_DIRECTION_FORWARD (ADC_SCAN_SEQ_FIXED) /* For compatibility with other STM32 series */ 639 #define ADC_SCAN_DIRECTION_BACKWARD (ADC_SCAN_SEQ_FIXED_BACKWARD) /* For compatibility with other STM32 series */ 640 /** 641 * @} 642 */ 643 644 /** @defgroup ADC_regular_external_trigger_source ADC group regular trigger source 645 * @{ 646 */ 647 /* ADC group regular trigger sources for all ADC instances */ 648 #define ADC_SOFTWARE_START (LL_ADC_REG_TRIG_SOFTWARE) /*!< ADC group regular conversion 649 trigger software start */ 650 #define ADC_EXTERNALTRIG_T1_TRGO2 (LL_ADC_REG_TRIG_EXT_TIM1_TRGO2) /*!< ADC group regular conversion 651 trigger from external peripheral: TIM1 TRGO. */ 652 #define ADC_EXTERNALTRIG_T1_CC4 (LL_ADC_REG_TRIG_EXT_TIM1_CH4) /*!< ADC group regular conversion 653 trigger from external peripheral: TIM1 channel 4 event (capture compare). */ 654 #define ADC_EXTERNALTRIG_T2_TRGO (LL_ADC_REG_TRIG_EXT_TIM2_TRGO) /*!< ADC group regular conversion 655 trigger from external peripheral: TIM2 TRGO. */ 656 #define ADC_EXTERNALTRIG_T3_TRGO (LL_ADC_REG_TRIG_EXT_TIM3_TRGO) /*!< ADC group regular conversion 657 trigger from external peripheral: TIM3 TRGO. */ 658 #define ADC_EXTERNALTRIG_T15_TRGO (LL_ADC_REG_TRIG_EXT_TIM15_TRGO) /*!< ADC group regular conversion 659 trigger from external peripheral: TIM15 TRGO. */ 660 #define ADC_EXTERNALTRIG_T6_TRGO (LL_ADC_REG_TRIG_EXT_TIM6_TRGO) /*!< ADC group regular conversion 661 trigger from external peripheral: TIM6 TRGO. */ 662 #define ADC_EXTERNALTRIG_EXT_IT11 (LL_ADC_REG_TRIG_EXT_EXTI_LINE11) /*!< ADC group regular conversion 663 trigger from external peripheral: external interrupt line 11. */ 664 /** 665 * @} 666 */ 667 668 /** @defgroup ADC_regular_external_trigger_edge ADC group regular trigger edge (when external trigger is selected) 669 * @{ 670 */ 671 #define ADC_EXTERNALTRIGCONVEDGE_NONE (0x00000000UL) /*!< ADC group regular trigger 672 disabled (SW start)*/ 673 #define ADC_EXTERNALTRIGCONVEDGE_RISING (LL_ADC_REG_TRIG_EXT_RISING) /*!< ADC group regular conversion 674 trigger polarity set to rising edge */ 675 #define ADC_EXTERNALTRIGCONVEDGE_FALLING (LL_ADC_REG_TRIG_EXT_FALLING) /*!< ADC group regular conversion 676 trigger polarity set to falling edge */ 677 #define ADC_EXTERNALTRIGCONVEDGE_RISINGFALLING (LL_ADC_REG_TRIG_EXT_RISINGFALLING) /*!< ADC group regular conversion 678 trigger polarity set to both rising and falling edges */ 679 /** 680 * @} 681 */ 682 683 /** @defgroup ADC_EOCSelection ADC sequencer end of unitary conversion or sequence conversions 684 * @{ 685 */ 686 #define ADC_EOC_SINGLE_CONV (ADC_ISR_EOC) /*!< End of unitary conversion flag */ 687 #define ADC_EOC_SEQ_CONV (ADC_ISR_EOS) /*!< End of sequence conversions flag */ 688 /** 689 * @} 690 */ 691 692 /** @defgroup ADC_HAL_EC_REG_OVR_DATA_BEHAVIOR ADC group regular - Overrun behavior on conversion data 693 * @{ 694 */ 695 #define ADC_OVR_DATA_PRESERVED (LL_ADC_REG_OVR_DATA_PRESERVED) /*!< ADC group regular behavior in case 696 of overrun: data preserved */ 697 #define ADC_OVR_DATA_OVERWRITTEN (LL_ADC_REG_OVR_DATA_OVERWRITTEN) /*!< ADC group regular behavior in case 698 of overrun: data overwritten */ 699 /** 700 * @} 701 */ 702 703 /** @defgroup ADC_HAL_EC_REG_SEQ_RANKS ADC group regular - Sequencer ranks 704 * @{ 705 */ 706 #define ADC_RANK_CHANNEL_NUMBER (0x00000001U) /*!< Enable the rank of the selected channels. Number of 707 ranks in the sequence is defined by number of channels enabled, rank of 708 each channel is defined by channel number (channel 0 fixed on rank 0, 709 channel 1 fixed on rank1, ...). 710 Setting relevant if parameter "ScanConvMode" is set to sequencer not fully 711 configurable. */ 712 #define ADC_RANK_NONE (0x00000002U) /*!< Disable the selected rank (selected channel) from 713 sequencer. 714 Setting relevant if parameter "ScanConvMode" is set to sequencer not fully 715 configurable. */ 716 717 #define ADC_REGULAR_RANK_1 (LL_ADC_REG_RANK_1) /*!< ADC group regular sequencer rank 1 */ 718 #define ADC_REGULAR_RANK_2 (LL_ADC_REG_RANK_2) /*!< ADC group regular sequencer rank 2 */ 719 #define ADC_REGULAR_RANK_3 (LL_ADC_REG_RANK_3) /*!< ADC group regular sequencer rank 3 */ 720 #define ADC_REGULAR_RANK_4 (LL_ADC_REG_RANK_4) /*!< ADC group regular sequencer rank 4 */ 721 #define ADC_REGULAR_RANK_5 (LL_ADC_REG_RANK_5) /*!< ADC group regular sequencer rank 5 */ 722 #define ADC_REGULAR_RANK_6 (LL_ADC_REG_RANK_6) /*!< ADC group regular sequencer rank 6 */ 723 #define ADC_REGULAR_RANK_7 (LL_ADC_REG_RANK_7) /*!< ADC group regular sequencer rank 7 */ 724 #define ADC_REGULAR_RANK_8 (LL_ADC_REG_RANK_8) /*!< ADC group regular sequencer rank 8 */ 725 /** 726 * @} 727 */ 728 729 /** @defgroup ADC_HAL_EC_SAMPLINGTIME_COMMON ADC instance - Sampling time common to a group of channels 730 * @{ 731 */ 732 #define ADC_SAMPLINGTIME_COMMON_1 (LL_ADC_SAMPLINGTIME_COMMON_1) /*!< Set sampling time common to a group of 733 channels: sampling time nb 1 */ 734 #define ADC_SAMPLINGTIME_COMMON_2 (LL_ADC_SAMPLINGTIME_COMMON_2) /*!< Set sampling time common to a group of 735 channels: sampling time nb 2 */ 736 /** 737 * @} 738 */ 739 740 /** @defgroup ADC_HAL_EC_CHANNEL_SAMPLINGTIME Channel - Sampling time 741 * @{ 742 */ 743 #define ADC_SAMPLETIME_1CYCLE_5 (LL_ADC_SAMPLINGTIME_1CYCLE_5) /*!< Sampling time 1.5 ADC clock cycle */ 744 #define ADC_SAMPLETIME_3CYCLES_5 (LL_ADC_SAMPLINGTIME_3CYCLES_5) /*!< Sampling time 3.5 ADC clock cycles */ 745 #define ADC_SAMPLETIME_7CYCLES_5 (LL_ADC_SAMPLINGTIME_7CYCLES_5) /*!< Sampling time 7.5 ADC clock cycles */ 746 #define ADC_SAMPLETIME_12CYCLES_5 (LL_ADC_SAMPLINGTIME_12CYCLES_5) /*!< Sampling time 12.5 ADC clock cycles */ 747 #define ADC_SAMPLETIME_19CYCLES_5 (LL_ADC_SAMPLINGTIME_19CYCLES_5) /*!< Sampling time 19.5 ADC clock cycles */ 748 #define ADC_SAMPLETIME_39CYCLES_5 (LL_ADC_SAMPLINGTIME_39CYCLES_5) /*!< Sampling time 39.5 ADC clock cycles */ 749 #define ADC_SAMPLETIME_79CYCLES_5 (LL_ADC_SAMPLINGTIME_79CYCLES_5) /*!< Sampling time 79.5 ADC clock cycles */ 750 #define ADC_SAMPLETIME_160CYCLES_5 (LL_ADC_SAMPLINGTIME_160CYCLES_5) /*!< Sampling time 160.5 ADC clock cycles */ 751 /** 752 * @} 753 */ 754 755 /** @defgroup ADC_HAL_EC_CHANNEL ADC instance - Channel number 756 * @{ 757 */ 758 #define ADC_CHANNEL_0 (LL_ADC_CHANNEL_0) /*!< External channel (GPIO pin) ADCx_IN0 */ 759 #define ADC_CHANNEL_1 (LL_ADC_CHANNEL_1) /*!< External channel (GPIO pin) ADCx_IN1 */ 760 #define ADC_CHANNEL_2 (LL_ADC_CHANNEL_2) /*!< External channel (GPIO pin) ADCx_IN2 */ 761 #define ADC_CHANNEL_3 (LL_ADC_CHANNEL_3) /*!< External channel (GPIO pin) ADCx_IN3 */ 762 #define ADC_CHANNEL_4 (LL_ADC_CHANNEL_4) /*!< External channel (GPIO pin) ADCx_IN4 */ 763 #define ADC_CHANNEL_5 (LL_ADC_CHANNEL_5) /*!< External channel (GPIO pin) ADCx_IN5 */ 764 #define ADC_CHANNEL_6 (LL_ADC_CHANNEL_6) /*!< External channel (GPIO pin) ADCx_IN6 */ 765 #define ADC_CHANNEL_7 (LL_ADC_CHANNEL_7) /*!< External channel (GPIO pin) ADCx_IN7 */ 766 #define ADC_CHANNEL_8 (LL_ADC_CHANNEL_8) /*!< External channel (GPIO pin) ADCx_IN8 */ 767 #define ADC_CHANNEL_9 (LL_ADC_CHANNEL_9) /*!< External channel (GPIO pin) ADCx_IN9 */ 768 #define ADC_CHANNEL_10 (LL_ADC_CHANNEL_10) /*!< External channel (GPIO pin) ADCx_IN10 */ 769 #define ADC_CHANNEL_11 (LL_ADC_CHANNEL_11) /*!< External channel (GPIO pin) ADCx_IN11 */ 770 #define ADC_CHANNEL_12 (LL_ADC_CHANNEL_12) /*!< External channel (GPIO pin) ADCx_IN12 */ 771 #define ADC_CHANNEL_13 (LL_ADC_CHANNEL_13) /*!< External channel (GPIO pin) ADCx_IN13 */ 772 #define ADC_CHANNEL_14 (LL_ADC_CHANNEL_14) /*!< External channel (GPIO pin) ADCx_IN14 */ 773 #define ADC_CHANNEL_15 (LL_ADC_CHANNEL_15) /*!< External channel (GPIO pin) ADCx_IN15 */ 774 #define ADC_CHANNEL_16 (LL_ADC_CHANNEL_16) /*!< External channel (GPIO pin) ADCx_IN16 */ 775 #define ADC_CHANNEL_17 (LL_ADC_CHANNEL_17) /*!< External channel (GPIO pin) ADCx_IN17 */ 776 #define ADC_CHANNEL_18 (LL_ADC_CHANNEL_18) /*!< External channel (GPIO pin) ADCx_IN18 */ 777 #define ADC_CHANNEL_19 (LL_ADC_CHANNEL_19) /*!< External channel (GPIO pin) ADCx_IN19 */ 778 #define ADC_CHANNEL_TEMPSENSOR (LL_ADC_CHANNEL_TEMPSENSOR) /*!< Internal channel Temperature sensor. */ 779 #define ADC_CHANNEL_VREFINT (LL_ADC_CHANNEL_VREFINT) /*!< Internal channel VrefInt: Internal 780 voltage reference. */ 781 #define ADC_CHANNEL_VBAT (LL_ADC_CHANNEL_VBAT) /*!< Internal channel Vbat/3: Vbat voltage 782 through a divider ladder of factor 1/3 to have channel voltage always below 783 Vdda. */ 784 #define ADC_CHANNEL_DACCH1 (LL_ADC_CHANNEL_DACCH1) /*!< Internal channel DAC channel 1. */ 785 /** 786 * @} 787 */ 788 789 /** @defgroup ADC_HAL_EC_AWD_NUMBER Analog watchdog - ADC analog watchdog (AWD) number 790 * @{ 791 */ 792 #define ADC_ANALOGWATCHDOG_1 (LL_ADC_AWD1) /*!< ADC analog watchdog number 1 */ 793 #define ADC_ANALOGWATCHDOG_2 (LL_ADC_AWD2) /*!< ADC analog watchdog number 2 */ 794 #define ADC_ANALOGWATCHDOG_3 (LL_ADC_AWD3) /*!< ADC analog watchdog number 3 */ 795 /** 796 * @} 797 */ 798 799 /** @defgroup ADC_analog_watchdog_mode ADC analog watchdog (AWD) mode 800 * @{ 801 */ 802 #define ADC_ANALOGWATCHDOG_NONE (0x00000000UL) /*!< ADC AWD not selected */ 803 #define ADC_ANALOGWATCHDOG_SINGLE_REG (ADC_CFGR1_AWD1SGL | ADC_CFGR1_AWD1EN) /*!< ADC AWD applied to a regular 804 group single channel */ 805 #define ADC_ANALOGWATCHDOG_ALL_REG (ADC_CFGR1_AWD1EN) /*!< ADC AWD applied to regular 806 group all channels */ 807 /** 808 * @} 809 */ 810 811 /** @defgroup ADC_HAL_EC_OVS_RATIO Oversampling - Ratio 812 * @{ 813 */ 814 /** 815 * @note The oversampling ratio is the number of ADC conversions performed, sum of these conversions data is computed 816 * to result as the ADC oversampling conversion data (before potential shift) 817 */ 818 #define ADC_OVERSAMPLING_RATIO_2 (LL_ADC_OVS_RATIO_2) /*!< ADC oversampling ratio 2 */ 819 #define ADC_OVERSAMPLING_RATIO_4 (LL_ADC_OVS_RATIO_4) /*!< ADC oversampling ratio 4 */ 820 #define ADC_OVERSAMPLING_RATIO_8 (LL_ADC_OVS_RATIO_8) /*!< ADC oversampling ratio 8 */ 821 #define ADC_OVERSAMPLING_RATIO_16 (LL_ADC_OVS_RATIO_16) /*!< ADC oversampling ratio 16 */ 822 #define ADC_OVERSAMPLING_RATIO_32 (LL_ADC_OVS_RATIO_32) /*!< ADC oversampling ratio 32 */ 823 #define ADC_OVERSAMPLING_RATIO_64 (LL_ADC_OVS_RATIO_64) /*!< ADC oversampling ratio 64 */ 824 #define ADC_OVERSAMPLING_RATIO_128 (LL_ADC_OVS_RATIO_128) /*!< ADC oversampling ratio 128 */ 825 #define ADC_OVERSAMPLING_RATIO_256 (LL_ADC_OVS_RATIO_256) /*!< ADC oversampling ratio 256 */ 826 /** 827 * @} 828 */ 829 830 /** @defgroup ADC_HAL_EC_OVS_SHIFT Oversampling - Data shift 831 * @{ 832 */ 833 /** 834 * @note The sum of the ADC conversions data is divided by "Rightbitshift" number to result as the ADC oversampling 835 * conversion data) 836 */ 837 #define ADC_RIGHTBITSHIFT_NONE (LL_ADC_OVS_SHIFT_NONE) /*!< ADC oversampling no shift */ 838 #define ADC_RIGHTBITSHIFT_1 (LL_ADC_OVS_SHIFT_RIGHT_1) /*!< ADC oversampling right shift of 1 ranks */ 839 #define ADC_RIGHTBITSHIFT_2 (LL_ADC_OVS_SHIFT_RIGHT_2) /*!< ADC oversampling right shift of 2 ranks */ 840 #define ADC_RIGHTBITSHIFT_3 (LL_ADC_OVS_SHIFT_RIGHT_3) /*!< ADC oversampling right shift of 3 ranks */ 841 #define ADC_RIGHTBITSHIFT_4 (LL_ADC_OVS_SHIFT_RIGHT_4) /*!< ADC oversampling right shift of 4 ranks */ 842 #define ADC_RIGHTBITSHIFT_5 (LL_ADC_OVS_SHIFT_RIGHT_5) /*!< ADC oversampling right shift of 5 ranks */ 843 #define ADC_RIGHTBITSHIFT_6 (LL_ADC_OVS_SHIFT_RIGHT_6) /*!< ADC oversampling right shift of 6 ranks */ 844 #define ADC_RIGHTBITSHIFT_7 (LL_ADC_OVS_SHIFT_RIGHT_7) /*!< ADC oversampling right shift of 7 ranks */ 845 #define ADC_RIGHTBITSHIFT_8 (LL_ADC_OVS_SHIFT_RIGHT_8) /*!< ADC oversampling right shift of 8 ranks */ 846 /** 847 * @} 848 */ 849 850 /** @defgroup ADC_HAL_EC_OVS_DISCONT_MODE Oversampling - Discontinuous mode 851 * @{ 852 */ 853 #define ADC_TRIGGEREDMODE_SINGLE_TRIGGER (LL_ADC_OVS_REG_CONT) /*!< ADC oversampling discontinuous mode: 854 continuous mode (all conversions of OVS ratio are done from 1 trigger) */ 855 #define ADC_TRIGGEREDMODE_MULTI_TRIGGER (LL_ADC_OVS_REG_DISCONT) /*!< ADC oversampling discontinuous mode: 856 discontinuous mode (each conversion of OVS ratio needs a trigger) */ 857 /** 858 * @} 859 */ 860 861 /** @defgroup ADC_HAL_EC_REG_TRIGGER_FREQ ADC group regular - Trigger frequency mode 862 * @{ 863 */ 864 865 /** 866 * @note ADC trigger frequency mode must be set to low frequency when a duration is exceeded before ADC conversion 867 * start trigger event (between ADC enable and ADC conversion start trigger event or between two ADC conversion 868 * start trigger event). 869 * Duration value: Refer to device datasheet, parameter "tIdle". 870 */ 871 #define ADC_TRIGGER_FREQ_HIGH (LL_ADC_TRIGGER_FREQ_HIGH) /*!< Trigger frequency mode set to high frequency. */ 872 #define ADC_TRIGGER_FREQ_LOW (LL_ADC_TRIGGER_FREQ_LOW) /*!< Trigger frequency mode set to low frequency. */ 873 /** 874 * @} 875 */ 876 877 /** @defgroup ADC_Event_type ADC Event type 878 * @{ 879 */ 880 /** 881 * @note Analog watchdog 1 is available on all stm32 series 882 * Analog watchdog 2 and 3 are not available on all series 883 */ 884 #define ADC_EOSMP_EVENT (ADC_FLAG_EOSMP) /*!< ADC End of Sampling event */ 885 #define ADC_AWD1_EVENT (ADC_FLAG_AWD1) /*!< ADC Analog watchdog 1 event (main analog watchdog) */ 886 #define ADC_AWD2_EVENT (ADC_FLAG_AWD2) /*!< ADC Analog watchdog 2 event (additional analog watchdog) */ 887 #define ADC_AWD3_EVENT (ADC_FLAG_AWD3) /*!< ADC Analog watchdog 3 event (additional analog watchdog) */ 888 #define ADC_OVR_EVENT (ADC_FLAG_OVR) /*!< ADC overrun event */ 889 /** 890 * @} 891 */ 892 #define ADC_AWD_EVENT ADC_AWD1_EVENT /*!< ADC Analog watchdog 1 event: Naming for compatibility 893 with other STM32 devices having only one analog watchdog */ 894 895 /** @defgroup ADC_interrupts_definition ADC interrupts definition 896 * @{ 897 */ 898 #define ADC_IT_RDY ADC_IER_ADRDYIE /*!< ADC Ready interrupt source */ 899 #define ADC_IT_CCRDY ADC_IER_CCRDYIE /*!< ADC channel configuration ready interrupt source */ 900 #define ADC_IT_EOSMP ADC_IER_EOSMPIE /*!< ADC End of sampling interrupt source */ 901 #define ADC_IT_EOC ADC_IER_EOCIE /*!< ADC End of regular conversion interrupt source */ 902 #define ADC_IT_EOS ADC_IER_EOSIE /*!< ADC End of regular sequence of conversions interrupt source */ 903 #define ADC_IT_OVR ADC_IER_OVRIE /*!< ADC overrun interrupt source */ 904 #define ADC_IT_AWD1 ADC_IER_AWD1IE /*!< ADC Analog watchdog 1 interrupt source (main analog watchdog) */ 905 #define ADC_IT_AWD2 ADC_IER_AWD2IE /*!< ADC Analog watchdog 2 interrupt source (additional analog 906 watchdog) */ 907 #define ADC_IT_AWD3 ADC_IER_AWD3IE /*!< ADC Analog watchdog 3 interrupt source (additional analog 908 watchdog) */ 909 #define ADC_IT_EOCAL ADC_IER_EOCALIE /*!< ADC End of Calibration interrupt source */ 910 /** 911 * @} 912 */ 913 914 /** @defgroup ADC_flags_definition ADC flags definition 915 * @{ 916 */ 917 #define ADC_FLAG_RDY ADC_ISR_ADRDY /*!< ADC Ready flag */ 918 #define ADC_FLAG_CCRDY ADC_ISR_CCRDY /*!< ADC channel configuration ready flag */ 919 #define ADC_FLAG_EOSMP ADC_ISR_EOSMP /*!< ADC End of Sampling flag */ 920 #define ADC_FLAG_EOC ADC_ISR_EOC /*!< ADC End of Regular Conversion flag */ 921 #define ADC_FLAG_EOS ADC_ISR_EOS /*!< ADC End of Regular sequence of Conversions flag */ 922 #define ADC_FLAG_OVR ADC_ISR_OVR /*!< ADC overrun flag */ 923 #define ADC_FLAG_AWD1 ADC_ISR_AWD1 /*!< ADC Analog watchdog 1 flag (main analog watchdog) */ 924 #define ADC_FLAG_AWD2 ADC_ISR_AWD2 /*!< ADC Analog watchdog 2 flag (additional analog watchdog) */ 925 #define ADC_FLAG_AWD3 ADC_ISR_AWD3 /*!< ADC Analog watchdog 3 flag (additional analog watchdog) */ 926 #define ADC_FLAG_EOCAL ADC_ISR_EOCAL /*!< ADC End of Calibration interrupt flag */ 927 /** 928 * @} 929 */ 930 931 /** 932 * @} 933 */ 934 935 /* Private macro -------------------------------------------------------------*/ 936 937 /** @defgroup ADC_Private_Macros ADC Private Macros 938 * @{ 939 */ 940 /* Macro reserved for internal HAL driver usage, not intended to be used in */ 941 /* code of final user. */ 942 943 /** 944 * @brief Test if conversion trigger of regular group is software start 945 * or external trigger. 946 * @param __HANDLE__ ADC handle 947 * @retval SET (software start) or RESET (external trigger) 948 */ 949 #define ADC_IS_SOFTWARE_START_REGULAR(__HANDLE__) \ 950 (((__HANDLE__)->Instance->CFGR1 & ADC_CFGR1_EXTEN) == 0UL) 951 952 /** 953 * @brief Return resolution bits in CFGR1 register RES[1:0] field. 954 * @param __HANDLE__ ADC handle 955 * @retval Value of bitfield RES in CFGR1 register. 956 */ 957 #define ADC_GET_RESOLUTION(__HANDLE__) \ 958 (LL_ADC_GetResolution((__HANDLE__)->Instance)) 959 960 /** 961 * @brief Clear ADC error code (set it to no error code "HAL_ADC_ERROR_NONE"). 962 * @param __HANDLE__ ADC handle 963 * @retval None 964 */ 965 #define ADC_CLEAR_ERRORCODE(__HANDLE__) ((__HANDLE__)->ErrorCode = HAL_ADC_ERROR_NONE) 966 967 /** 968 * @brief Simultaneously clear and set specific bits of the handle State. 969 * @note ADC_STATE_CLR_SET() macro is merely aliased to generic macro MODIFY_REG(), 970 * the first parameter is the ADC handle State, the second parameter is the 971 * bit field to clear, the third and last parameter is the bit field to set. 972 * @retval None 973 */ 974 #define ADC_STATE_CLR_SET MODIFY_REG 975 976 /** 977 * @brief Enable ADC discontinuous conversion mode for regular group 978 * @param _REG_DISCONTINUOUS_MODE_: Regular discontinuous mode. 979 * @retval None 980 */ 981 #define ADC_CFGR1_REG_DISCCONTINUOUS(_REG_DISCONTINUOUS_MODE_) \ 982 ((_REG_DISCONTINUOUS_MODE_) << 16U) 983 984 /** 985 * @brief Enable the ADC auto off mode. 986 * @param _AUTOOFF_ Auto off bit enable or disable. 987 * @retval None 988 */ 989 #define ADC_CFGR1_AUTOOFF(_AUTOOFF_) \ 990 ((_AUTOOFF_) << 15U) 991 992 /** 993 * @brief Enable the ADC auto delay mode. 994 * @param _AUTOWAIT_ Auto delay bit enable or disable. 995 * @retval None 996 */ 997 #define ADC_CFGR1_AUTOWAIT(_AUTOWAIT_) \ 998 ((_AUTOWAIT_) << 14U) 999 1000 /** 1001 * @brief Enable ADC continuous conversion mode. 1002 * @param _CONTINUOUS_MODE_ Continuous mode. 1003 * @retval None 1004 */ 1005 #define ADC_CFGR1_CONTINUOUS(_CONTINUOUS_MODE_) \ 1006 ((_CONTINUOUS_MODE_) << 13U) 1007 1008 /** 1009 * @brief Enable ADC overrun mode. 1010 * @param _OVERRUN_MODE_ Overrun mode. 1011 * @retval Overrun bit setting to be programmed into CFGR register 1012 */ 1013 /* Note: Bit ADC_CFGR1_OVRMOD not used directly in constant */ 1014 /* "ADC_OVR_DATA_OVERWRITTEN" to have this case defined to 0x00, to set it */ 1015 /* as the default case to be compliant with other STM32 devices. */ 1016 #define ADC_CFGR1_OVERRUN(_OVERRUN_MODE_) \ 1017 ( ( (_OVERRUN_MODE_) != (ADC_OVR_DATA_PRESERVED) \ 1018 )? (ADC_CFGR1_OVRMOD) : (0x00000000UL) \ 1019 ) 1020 1021 /** 1022 * @brief Set ADC scan mode with differentiation of sequencer setting 1023 * fixed or configurable 1024 * @param _SCAN_MODE_ Scan conversion mode. 1025 * @retval None 1026 */ 1027 /* Note: Scan mode set using this macro (instead of parameter direct set) */ 1028 /* due to different modes on other STM32 devices: */ 1029 /* if scan mode is disabled, sequencer is set to fully configurable */ 1030 /* with setting of only rank 1 enabled afterwards. */ 1031 #define ADC_SCAN_SEQ_MODE(_SCAN_MODE_) \ 1032 ( (((_SCAN_MODE_) & ADC_SCAN_SEQ_FIXED_INT) != 0UL \ 1033 )? \ 1034 ((_SCAN_MODE_) & (~ADC_SCAN_SEQ_FIXED_INT)) \ 1035 : \ 1036 (ADC_CFGR1_CHSELRMOD) \ 1037 ) 1038 1039 /** 1040 * @brief Enable the ADC DMA continuous request. 1041 * @param _DMACONTREQ_MODE_: DMA continuous request mode. 1042 * @retval None 1043 */ 1044 #define ADC_CFGR1_DMACONTREQ(_DMACONTREQ_MODE_) \ 1045 ((_DMACONTREQ_MODE_) << 1U) 1046 1047 /** 1048 * @brief Shift the AWD threshold in function of the selected ADC resolution. 1049 * Thresholds have to be left-aligned on bit 11, the LSB (right bits) are set to 0. 1050 * If resolution 12 bits, no shift. 1051 * If resolution 10 bits, shift of 2 ranks on the left. 1052 * If resolution 8 bits, shift of 4 ranks on the left. 1053 * If resolution 6 bits, shift of 6 ranks on the left. 1054 * therefore, shift = (12 - resolution) = 12 - (12- (((RES[1:0]) >> 3)*2)) 1055 * @param __HANDLE__ ADC handle 1056 * @param _Threshold_ Value to be shifted 1057 * @retval None 1058 */ 1059 #define ADC_AWD1THRESHOLD_SHIFT_RESOLUTION(__HANDLE__, _Threshold_) \ 1060 ((_Threshold_) << ((((__HANDLE__)->Instance->CFGR1 & ADC_CFGR1_RES) >> 3U)*2U)) 1061 1062 #define IS_ADC_CLOCKPRESCALER(ADC_CLOCK) (((ADC_CLOCK) == ADC_CLOCK_SYNC_PCLK_DIV1) ||\ 1063 ((ADC_CLOCK) == ADC_CLOCK_SYNC_PCLK_DIV2) ||\ 1064 ((ADC_CLOCK) == ADC_CLOCK_SYNC_PCLK_DIV4) ||\ 1065 ((ADC_CLOCK) == ADC_CLOCK_ASYNC_DIV1 ) ||\ 1066 ((ADC_CLOCK) == ADC_CLOCK_ASYNC_DIV2 ) ||\ 1067 ((ADC_CLOCK) == ADC_CLOCK_ASYNC_DIV4 ) ||\ 1068 ((ADC_CLOCK) == ADC_CLOCK_ASYNC_DIV6 ) ||\ 1069 ((ADC_CLOCK) == ADC_CLOCK_ASYNC_DIV8 ) ||\ 1070 ((ADC_CLOCK) == ADC_CLOCK_ASYNC_DIV10 ) ||\ 1071 ((ADC_CLOCK) == ADC_CLOCK_ASYNC_DIV12 ) ||\ 1072 ((ADC_CLOCK) == ADC_CLOCK_ASYNC_DIV16 ) ||\ 1073 ((ADC_CLOCK) == ADC_CLOCK_ASYNC_DIV32 ) ||\ 1074 ((ADC_CLOCK) == ADC_CLOCK_ASYNC_DIV64 ) ||\ 1075 ((ADC_CLOCK) == ADC_CLOCK_ASYNC_DIV128 ) ||\ 1076 ((ADC_CLOCK) == ADC_CLOCK_ASYNC_DIV256)) 1077 1078 #define IS_ADC_RESOLUTION(RESOLUTION) (((RESOLUTION) == ADC_RESOLUTION_12B) || \ 1079 ((RESOLUTION) == ADC_RESOLUTION_10B) || \ 1080 ((RESOLUTION) == ADC_RESOLUTION_8B) || \ 1081 ((RESOLUTION) == ADC_RESOLUTION_6B) ) 1082 1083 #define IS_ADC_DATA_ALIGN(ALIGN) (((ALIGN) == ADC_DATAALIGN_RIGHT) || \ 1084 ((ALIGN) == ADC_DATAALIGN_LEFT) ) 1085 1086 #define IS_ADC_SCAN_MODE(SCAN_MODE) (((SCAN_MODE) == ADC_SCAN_DISABLE) || \ 1087 ((SCAN_MODE) == ADC_SCAN_ENABLE) || \ 1088 ((SCAN_MODE) == ADC_SCAN_SEQ_FIXED) || \ 1089 ((SCAN_MODE) == ADC_SCAN_SEQ_FIXED_BACKWARD) ) 1090 1091 #define IS_ADC_EXTTRIG_EDGE(EDGE) (((EDGE) == ADC_EXTERNALTRIGCONVEDGE_NONE) || \ 1092 ((EDGE) == ADC_EXTERNALTRIGCONVEDGE_RISING) || \ 1093 ((EDGE) == ADC_EXTERNALTRIGCONVEDGE_FALLING) || \ 1094 ((EDGE) == ADC_EXTERNALTRIGCONVEDGE_RISINGFALLING) ) 1095 1096 #define IS_ADC_EXTTRIG(REGTRIG) (((REGTRIG) == ADC_EXTERNALTRIG_T1_TRGO2) || \ 1097 ((REGTRIG) == ADC_EXTERNALTRIG_T1_CC4) || \ 1098 ((REGTRIG) == ADC_EXTERNALTRIG_T2_TRGO) || \ 1099 ((REGTRIG) == ADC_EXTERNALTRIG_T3_TRGO) || \ 1100 ((REGTRIG) == ADC_EXTERNALTRIG_T15_TRGO) || \ 1101 ((REGTRIG) == ADC_EXTERNALTRIG_T6_TRGO) || \ 1102 ((REGTRIG) == ADC_EXTERNALTRIG_EXT_IT11) || \ 1103 ((REGTRIG) == ADC_SOFTWARE_START) ) 1104 1105 #define IS_ADC_EOC_SELECTION(EOC_SELECTION) (((EOC_SELECTION) == ADC_EOC_SINGLE_CONV) || \ 1106 ((EOC_SELECTION) == ADC_EOC_SEQ_CONV)) 1107 1108 #define IS_ADC_OVERRUN(OVR) (((OVR) == ADC_OVR_DATA_PRESERVED) || \ 1109 ((OVR) == ADC_OVR_DATA_OVERWRITTEN) ) 1110 1111 #define IS_ADC_REGULAR_RANK_SEQ_FIXED(RANK) (((RANK) == ADC_RANK_CHANNEL_NUMBER) || \ 1112 ((RANK) == ADC_RANK_NONE) ) 1113 1114 #define IS_ADC_REGULAR_RANK(RANK) (((RANK) == ADC_REGULAR_RANK_1 ) || \ 1115 ((RANK) == ADC_REGULAR_RANK_2 ) || \ 1116 ((RANK) == ADC_REGULAR_RANK_3 ) || \ 1117 ((RANK) == ADC_REGULAR_RANK_4 ) || \ 1118 ((RANK) == ADC_REGULAR_RANK_5 ) || \ 1119 ((RANK) == ADC_REGULAR_RANK_6 ) || \ 1120 ((RANK) == ADC_REGULAR_RANK_7 ) || \ 1121 ((RANK) == ADC_REGULAR_RANK_8 ) ) 1122 1123 #define IS_ADC_CHANNEL(CHANNEL) (((CHANNEL) == ADC_CHANNEL_0) || \ 1124 ((CHANNEL) == ADC_CHANNEL_1) || \ 1125 ((CHANNEL) == ADC_CHANNEL_2) || \ 1126 ((CHANNEL) == ADC_CHANNEL_3) || \ 1127 ((CHANNEL) == ADC_CHANNEL_4) || \ 1128 ((CHANNEL) == ADC_CHANNEL_5) || \ 1129 ((CHANNEL) == ADC_CHANNEL_6) || \ 1130 ((CHANNEL) == ADC_CHANNEL_7) || \ 1131 ((CHANNEL) == ADC_CHANNEL_8) || \ 1132 ((CHANNEL) == ADC_CHANNEL_9) || \ 1133 ((CHANNEL) == ADC_CHANNEL_10) || \ 1134 ((CHANNEL) == ADC_CHANNEL_11) || \ 1135 ((CHANNEL) == ADC_CHANNEL_12) || \ 1136 ((CHANNEL) == ADC_CHANNEL_13) || \ 1137 ((CHANNEL) == ADC_CHANNEL_14) || \ 1138 ((CHANNEL) == ADC_CHANNEL_15) || \ 1139 ((CHANNEL) == ADC_CHANNEL_16) || \ 1140 ((CHANNEL) == ADC_CHANNEL_17) || \ 1141 ((CHANNEL) == ADC_CHANNEL_18) || \ 1142 ((CHANNEL) == ADC_CHANNEL_19) || \ 1143 ((CHANNEL) == ADC_CHANNEL_TEMPSENSOR) || \ 1144 ((CHANNEL) == ADC_CHANNEL_VREFINT) || \ 1145 ((CHANNEL) == ADC_CHANNEL_VBAT) || \ 1146 ((CHANNEL) == ADC_CHANNEL_DACCH1) ) 1147 1148 #define IS_ADC_SAMPLING_TIME_COMMON(SAMPLING_TIME_COMMON) (((SAMPLING_TIME_COMMON) == ADC_SAMPLINGTIME_COMMON_1) || \ 1149 ((SAMPLING_TIME_COMMON) == ADC_SAMPLINGTIME_COMMON_2) ) 1150 1151 #define IS_ADC_SAMPLE_TIME(TIME) (((TIME) == ADC_SAMPLETIME_1CYCLE_5) || \ 1152 ((TIME) == ADC_SAMPLETIME_3CYCLES_5) || \ 1153 ((TIME) == ADC_SAMPLETIME_7CYCLES_5) || \ 1154 ((TIME) == ADC_SAMPLETIME_12CYCLES_5) || \ 1155 ((TIME) == ADC_SAMPLETIME_19CYCLES_5) || \ 1156 ((TIME) == ADC_SAMPLETIME_39CYCLES_5) || \ 1157 ((TIME) == ADC_SAMPLETIME_79CYCLES_5) || \ 1158 ((TIME) == ADC_SAMPLETIME_160CYCLES_5) ) 1159 1160 #define IS_ADC_ANALOG_WATCHDOG_NUMBER(WATCHDOG) (((WATCHDOG) == ADC_ANALOGWATCHDOG_1) || \ 1161 ((WATCHDOG) == ADC_ANALOGWATCHDOG_2) || \ 1162 ((WATCHDOG) == ADC_ANALOGWATCHDOG_3) ) 1163 1164 #define IS_ADC_ANALOG_WATCHDOG_MODE(WATCHDOG) (((WATCHDOG) == ADC_ANALOGWATCHDOG_NONE) || \ 1165 ((WATCHDOG) == ADC_ANALOGWATCHDOG_SINGLE_REG) || \ 1166 ((WATCHDOG) == ADC_ANALOGWATCHDOG_ALL_REG) ) 1167 1168 #define IS_ADC_TRIGGER_FREQ(TRIGGER_FREQ) (((TRIGGER_FREQ) == LL_ADC_TRIGGER_FREQ_HIGH) || \ 1169 ((TRIGGER_FREQ) == LL_ADC_TRIGGER_FREQ_LOW) ) 1170 1171 #define IS_ADC_EVENT_TYPE(EVENT) (((EVENT) == ADC_EOSMP_EVENT) || \ 1172 ((EVENT) == ADC_AWD1_EVENT) || \ 1173 ((EVENT) == ADC_AWD2_EVENT) || \ 1174 ((EVENT) == ADC_AWD3_EVENT) || \ 1175 ((EVENT) == ADC_OVR_EVENT) ) 1176 1177 /** 1178 * @brief Verify that a given value is aligned with the ADC resolution range. 1179 * @param __RESOLUTION__ ADC resolution (12, 10, 8 or 6 bits). 1180 * @param __ADC_VALUE__ value checked against the resolution. 1181 * @retval SET (__ADC_VALUE__ in line with __RESOLUTION__) or RESET (__ADC_VALUE__ not in line with __RESOLUTION__) 1182 */ 1183 #define IS_ADC_RANGE(__RESOLUTION__, __ADC_VALUE__) \ 1184 ((__ADC_VALUE__) <= __LL_ADC_DIGITAL_SCALE(__RESOLUTION__)) 1185 1186 /** @defgroup ADC_regular_nb_conv_verification ADC Regular Conversion Number Verification 1187 * @{ 1188 */ 1189 #define IS_ADC_REGULAR_NB_CONV(LENGTH) (((LENGTH) >= 1UL) && ((LENGTH) <= 8UL)) 1190 /** 1191 * @} 1192 */ 1193 1194 1195 /* Private constants ---------------------------------------------------------*/ 1196 1197 /** @defgroup ADC_Private_Constants ADC Private Constants 1198 * @{ 1199 */ 1200 1201 /* Combination of all post-conversion flags bits: EOC/EOS, OVR, AWD */ 1202 #define ADC_FLAG_POSTCONV_ALL (ADC_FLAG_AWD | ADC_FLAG_OVR | ADC_FLAG_EOS | ADC_FLAG_EOC) 1203 1204 /* Internal definition to differentiate sequencer setting fixed or configurable */ 1205 #define ADC_SCAN_SEQ_FIXED_INT 0x80000000U 1206 1207 /** 1208 * @} 1209 */ 1210 1211 /* Exported macro ------------------------------------------------------------*/ 1212 1213 /** @defgroup ADC_Exported_Macros ADC Exported Macros 1214 * @{ 1215 */ 1216 /* Macro for internal HAL driver usage, and possibly can be used into code of */ 1217 /* final user. */ 1218 1219 /** @defgroup ADC_HAL_EM_HANDLE_IT_FLAG HAL ADC macro to manage HAL ADC handle, IT and flags. 1220 * @{ 1221 */ 1222 1223 /** @brief Reset ADC handle state. 1224 * @param __HANDLE__ ADC handle 1225 * @retval None 1226 */ 1227 #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1) 1228 #define __HAL_ADC_RESET_HANDLE_STATE(__HANDLE__) \ 1229 do{ \ 1230 (__HANDLE__)->State = HAL_ADC_STATE_RESET; \ 1231 (__HANDLE__)->MspInitCallback = NULL; \ 1232 (__HANDLE__)->MspDeInitCallback = NULL; \ 1233 } while(0) 1234 #else 1235 #define __HAL_ADC_RESET_HANDLE_STATE(__HANDLE__) \ 1236 ((__HANDLE__)->State = HAL_ADC_STATE_RESET) 1237 #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */ 1238 1239 /** 1240 * @brief Enable ADC interrupt. 1241 * @param __HANDLE__ ADC handle 1242 * @param __INTERRUPT__ ADC Interrupt 1243 * This parameter can be one of the following values: 1244 * @arg @ref ADC_IT_RDY ADC Ready interrupt source 1245 * @arg @ref ADC_IT_CCRDY ADC channel configuration ready interrupt source 1246 * @arg @ref ADC_IT_EOSMP ADC End of Sampling interrupt source 1247 * @arg @ref ADC_IT_EOC ADC End of Regular Conversion interrupt source 1248 * @arg @ref ADC_IT_EOS ADC End of Regular sequence of Conversions interrupt source 1249 * @arg @ref ADC_IT_OVR ADC overrun interrupt source 1250 * @arg @ref ADC_IT_AWD1 ADC Analog watchdog 1 interrupt source (main analog watchdog) 1251 * @arg @ref ADC_IT_AWD2 ADC Analog watchdog 2 interrupt source (additional analog watchdog) 1252 * @arg @ref ADC_IT_AWD3 ADC Analog watchdog 3 interrupt source (additional analog watchdog) 1253 * @retval None 1254 */ 1255 #define __HAL_ADC_ENABLE_IT(__HANDLE__, __INTERRUPT__) \ 1256 (((__HANDLE__)->Instance->IER) |= (__INTERRUPT__)) 1257 1258 /** 1259 * @brief Disable ADC interrupt. 1260 * @param __HANDLE__ ADC handle 1261 * @param __INTERRUPT__ ADC Interrupt 1262 * This parameter can be one of the following values: 1263 * @arg @ref ADC_IT_RDY ADC Ready interrupt source 1264 * @arg @ref ADC_IT_CCRDY ADC channel configuration ready interrupt source 1265 * @arg @ref ADC_IT_EOSMP ADC End of Sampling interrupt source 1266 * @arg @ref ADC_IT_EOC ADC End of Regular Conversion interrupt source 1267 * @arg @ref ADC_IT_EOS ADC End of Regular sequence of Conversions interrupt source 1268 * @arg @ref ADC_IT_OVR ADC overrun interrupt source 1269 * @arg @ref ADC_IT_AWD1 ADC Analog watchdog 1 interrupt source (main analog watchdog) 1270 * @arg @ref ADC_IT_AWD2 ADC Analog watchdog 2 interrupt source (additional analog watchdog) 1271 * @arg @ref ADC_IT_AWD3 ADC Analog watchdog 3 interrupt source (additional analog watchdog) 1272 * @retval None 1273 */ 1274 #define __HAL_ADC_DISABLE_IT(__HANDLE__, __INTERRUPT__) \ 1275 (((__HANDLE__)->Instance->IER) &= ~(__INTERRUPT__)) 1276 1277 /** @brief Checks if the specified ADC interrupt source is enabled or disabled. 1278 * @param __HANDLE__ ADC handle 1279 * @param __INTERRUPT__ ADC interrupt source to check 1280 * This parameter can be one of the following values: 1281 * @arg @ref ADC_IT_RDY ADC Ready interrupt source 1282 * @arg @ref ADC_IT_CCRDY ADC channel configuration ready interrupt source 1283 * @arg @ref ADC_IT_EOSMP ADC End of Sampling interrupt source 1284 * @arg @ref ADC_IT_EOC ADC End of Regular Conversion interrupt source 1285 * @arg @ref ADC_IT_EOS ADC End of Regular sequence of Conversions interrupt source 1286 * @arg @ref ADC_IT_OVR ADC overrun interrupt source 1287 * @arg @ref ADC_IT_AWD1 ADC Analog watchdog 1 interrupt source (main analog watchdog) 1288 * @arg @ref ADC_IT_AWD2 ADC Analog watchdog 2 interrupt source (additional analog watchdog) 1289 * @arg @ref ADC_IT_AWD3 ADC Analog watchdog 3 interrupt source (additional analog watchdog) 1290 * @retval State of interruption (SET or RESET) 1291 */ 1292 #define __HAL_ADC_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) \ 1293 (((__HANDLE__)->Instance->IER & (__INTERRUPT__)) == (__INTERRUPT__)) 1294 1295 /** 1296 * @brief Check whether the specified ADC flag is set or not. 1297 * @param __HANDLE__ ADC handle 1298 * @param __FLAG__ ADC flag 1299 * This parameter can be one of the following values: 1300 * @arg @ref ADC_FLAG_RDY ADC Ready flag 1301 * @arg @ref ADC_FLAG_CCRDY ADC channel configuration ready flag 1302 * @arg @ref ADC_FLAG_EOSMP ADC End of Sampling flag 1303 * @arg @ref ADC_FLAG_EOC ADC End of Regular Conversion flag 1304 * @arg @ref ADC_FLAG_EOS ADC End of Regular sequence of Conversions flag 1305 * @arg @ref ADC_FLAG_OVR ADC overrun flag 1306 * @arg @ref ADC_FLAG_AWD1 ADC Analog watchdog 1 flag (main analog watchdog) 1307 * @arg @ref ADC_FLAG_AWD2 ADC Analog watchdog 2 flag (additional analog watchdog) 1308 * @arg @ref ADC_FLAG_AWD3 ADC Analog watchdog 3 flag (additional analog watchdog) 1309 * @retval State of flag (TRUE or FALSE). 1310 */ 1311 #define __HAL_ADC_GET_FLAG(__HANDLE__, __FLAG__) \ 1312 ((((__HANDLE__)->Instance->ISR) & (__FLAG__)) == (__FLAG__)) 1313 1314 /** 1315 * @brief Clear the specified ADC flag. 1316 * @param __HANDLE__ ADC handle 1317 * @param __FLAG__ ADC flag 1318 * This parameter can be one of the following values: 1319 * @arg @ref ADC_FLAG_RDY ADC Ready flag 1320 * @arg @ref ADC_FLAG_CCRDY ADC channel configuration ready flag 1321 * @arg @ref ADC_FLAG_EOSMP ADC End of Sampling flag 1322 * @arg @ref ADC_FLAG_EOC ADC End of Regular Conversion flag 1323 * @arg @ref ADC_FLAG_EOS ADC End of Regular sequence of Conversions flag 1324 * @arg @ref ADC_FLAG_OVR ADC overrun flag 1325 * @arg @ref ADC_FLAG_AWD1 ADC Analog watchdog 1 flag (main analog watchdog) 1326 * @arg @ref ADC_FLAG_AWD2 ADC Analog watchdog 2 flag (additional analog watchdog) 1327 * @arg @ref ADC_FLAG_AWD3 ADC Analog watchdog 3 flag (additional analog watchdog) 1328 * @retval None 1329 */ 1330 /* Note: bit cleared bit by writing 1 (writing 0 has no effect on any bit of register ISR) */ 1331 #define __HAL_ADC_CLEAR_FLAG(__HANDLE__, __FLAG__) \ 1332 (((__HANDLE__)->Instance->ISR) = (__FLAG__)) 1333 1334 /** 1335 * @} 1336 */ 1337 1338 /** @defgroup ADC_HAL_EM_HELPER_MACRO HAL ADC helper macro 1339 * @{ 1340 */ 1341 1342 /** 1343 * @brief Helper macro to get ADC channel number in decimal format 1344 * from literals ADC_CHANNEL_x. 1345 * @note Example: 1346 * __HAL_ADC_CHANNEL_TO_DECIMAL_NB(ADC_CHANNEL_4) 1347 * will return decimal number "4". 1348 * @note The input can be a value from functions where a channel 1349 * number is returned, either defined with number 1350 * or with bitfield (only one bit must be set). 1351 * @param __CHANNEL__ This parameter can be one of the following values: 1352 * @arg @ref ADC_CHANNEL_0 1353 * @arg @ref ADC_CHANNEL_1 1354 * @arg @ref ADC_CHANNEL_2 1355 * @arg @ref ADC_CHANNEL_3 1356 * @arg @ref ADC_CHANNEL_4 1357 * @arg @ref ADC_CHANNEL_5 1358 * @arg @ref ADC_CHANNEL_6 1359 * @arg @ref ADC_CHANNEL_7 1360 * @arg @ref ADC_CHANNEL_8 1361 * @arg @ref ADC_CHANNEL_9 1362 * @arg @ref ADC_CHANNEL_10 1363 * @arg @ref ADC_CHANNEL_11 1364 * @arg @ref ADC_CHANNEL_12 1365 * @arg @ref ADC_CHANNEL_13 1366 * @arg @ref ADC_CHANNEL_14 1367 * @arg @ref ADC_CHANNEL_15 1368 * @arg @ref ADC_CHANNEL_16 1369 * @arg @ref ADC_CHANNEL_17 1370 * @arg @ref ADC_CHANNEL_18 1371 * @arg @ref ADC_CHANNEL_19 1372 * @arg @ref ADC_CHANNEL_VREFINT 1373 * @arg @ref ADC_CHANNEL_TEMPSENSOR 1374 * @arg @ref ADC_CHANNEL_VBAT 1375 * @arg @ref ADC_CHANNEL_DACCH1 1376 * @retval Value between Min_Data=0 and Max_Data=18 1377 */ 1378 #define __HAL_ADC_CHANNEL_TO_DECIMAL_NB(__CHANNEL__) \ 1379 __LL_ADC_CHANNEL_TO_DECIMAL_NB((__CHANNEL__)) 1380 1381 /** 1382 * @brief Helper macro to get ADC channel in literal format ADC_CHANNEL_x 1383 * from number in decimal format. 1384 * @note Example: 1385 * __HAL_ADC_DECIMAL_NB_TO_CHANNEL(4) 1386 * will return a data equivalent to "ADC_CHANNEL_4". 1387 * @param __DECIMAL_NB__ Value between Min_Data=0 and Max_Data=18 1388 * @retval Returned value can be one of the following values: 1389 * @arg @ref ADC_CHANNEL_0 1390 * @arg @ref ADC_CHANNEL_1 1391 * @arg @ref ADC_CHANNEL_2 1392 * @arg @ref ADC_CHANNEL_3 1393 * @arg @ref ADC_CHANNEL_4 1394 * @arg @ref ADC_CHANNEL_5 1395 * @arg @ref ADC_CHANNEL_6 1396 * @arg @ref ADC_CHANNEL_7 1397 * @arg @ref ADC_CHANNEL_8 1398 * @arg @ref ADC_CHANNEL_9 1399 * @arg @ref ADC_CHANNEL_10 1400 * @arg @ref ADC_CHANNEL_11 1401 * @arg @ref ADC_CHANNEL_12 1402 * @arg @ref ADC_CHANNEL_13 1403 * @arg @ref ADC_CHANNEL_14 1404 * @arg @ref ADC_CHANNEL_15 1405 * @arg @ref ADC_CHANNEL_16 1406 * @arg @ref ADC_CHANNEL_17 1407 * @arg @ref ADC_CHANNEL_18 1408 * @arg @ref ADC_CHANNEL_19 1409 * @arg @ref ADC_CHANNEL_VREFINT 1410 * @arg @ref ADC_CHANNEL_TEMPSENSOR 1411 * @arg @ref ADC_CHANNEL_VBAT 1412 * @arg @ref ADC_CHANNEL_DACCH1 1413 */ 1414 #define __HAL_ADC_DECIMAL_NB_TO_CHANNEL(__DECIMAL_NB__) \ 1415 __LL_ADC_DECIMAL_NB_TO_CHANNEL((__DECIMAL_NB__)) 1416 1417 /** 1418 * @brief Helper macro to determine whether the selected channel 1419 * corresponds to literal definitions of driver. 1420 * @note The different literal definitions of ADC channels are: 1421 * - ADC internal channel: 1422 * ADC_CHANNEL_VREFINT, ADC_CHANNEL_TEMPSENSOR, ... 1423 * - ADC external channel (channel connected to a GPIO pin): 1424 * ADC_CHANNEL_1, ADC_CHANNEL_2, ... 1425 * @note The channel parameter must be a value defined from literal 1426 * definition of a ADC internal channel (ADC_CHANNEL_VREFINT, 1427 * ADC_CHANNEL_TEMPSENSOR, ...), 1428 * ADC external channel (ADC_CHANNEL_1, ADC_CHANNEL_2, ...), 1429 * must not be a value from functions where a channel number is 1430 * returned from ADC registers, 1431 * because internal and external channels share the same channel 1432 * number in ADC registers. The differentiation is made only with 1433 * parameters definitions of driver. 1434 * @param __CHANNEL__ This parameter can be one of the following values: 1435 * @arg @ref ADC_CHANNEL_0 1436 * @arg @ref ADC_CHANNEL_1 1437 * @arg @ref ADC_CHANNEL_2 1438 * @arg @ref ADC_CHANNEL_3 1439 * @arg @ref ADC_CHANNEL_4 1440 * @arg @ref ADC_CHANNEL_5 1441 * @arg @ref ADC_CHANNEL_6 1442 * @arg @ref ADC_CHANNEL_7 1443 * @arg @ref ADC_CHANNEL_8 1444 * @arg @ref ADC_CHANNEL_9 1445 * @arg @ref ADC_CHANNEL_10 1446 * @arg @ref ADC_CHANNEL_11 1447 * @arg @ref ADC_CHANNEL_12 1448 * @arg @ref ADC_CHANNEL_13 1449 * @arg @ref ADC_CHANNEL_14 1450 * @arg @ref ADC_CHANNEL_15 1451 * @arg @ref ADC_CHANNEL_16 1452 * @arg @ref ADC_CHANNEL_17 1453 * @arg @ref ADC_CHANNEL_18 1454 * @arg @ref ADC_CHANNEL_19 1455 * @arg @ref ADC_CHANNEL_VREFINT 1456 * @arg @ref ADC_CHANNEL_TEMPSENSOR 1457 * @arg @ref ADC_CHANNEL_VBAT 1458 * @arg @ref ADC_CHANNEL_DACCH1 1459 * @retval Value "0" if the channel corresponds to a parameter definition of a ADC external channel 1460 * (channel connected to a GPIO pin). 1461 * Value "1" if the channel corresponds to a parameter definition of a ADC internal channel. 1462 */ 1463 #define __HAL_ADC_IS_CHANNEL_INTERNAL(__CHANNEL__) \ 1464 __LL_ADC_IS_CHANNEL_INTERNAL((__CHANNEL__)) 1465 1466 /** 1467 * @brief Helper macro to convert a channel defined from parameter 1468 * definition of a ADC internal channel (ADC_CHANNEL_VREFINT, 1469 * ADC_CHANNEL_TEMPSENSOR, ...), 1470 * to its equivalent parameter definition of a ADC external channel 1471 * (ADC_CHANNEL_1, ADC_CHANNEL_2, ...). 1472 * @note The channel parameter can be, additionally to a value 1473 * defined from parameter definition of a ADC internal channel 1474 * (ADC_CHANNEL_VREFINT, ADC_CHANNEL_TEMPSENSOR, ...), 1475 * a value defined from parameter definition of 1476 * ADC external channel (ADC_CHANNEL_1, ADC_CHANNEL_2, ...) 1477 * or a value from functions where a channel number is returned 1478 * from ADC registers. 1479 * @param __CHANNEL__ This parameter can be one of the following values: 1480 * @arg @ref ADC_CHANNEL_0 1481 * @arg @ref ADC_CHANNEL_1 1482 * @arg @ref ADC_CHANNEL_2 1483 * @arg @ref ADC_CHANNEL_3 1484 * @arg @ref ADC_CHANNEL_4 1485 * @arg @ref ADC_CHANNEL_5 1486 * @arg @ref ADC_CHANNEL_6 1487 * @arg @ref ADC_CHANNEL_7 1488 * @arg @ref ADC_CHANNEL_8 1489 * @arg @ref ADC_CHANNEL_9 1490 * @arg @ref ADC_CHANNEL_10 1491 * @arg @ref ADC_CHANNEL_11 1492 * @arg @ref ADC_CHANNEL_12 1493 * @arg @ref ADC_CHANNEL_13 1494 * @arg @ref ADC_CHANNEL_14 1495 * @arg @ref ADC_CHANNEL_15 1496 * @arg @ref ADC_CHANNEL_16 1497 * @arg @ref ADC_CHANNEL_17 1498 * @arg @ref ADC_CHANNEL_18 1499 * @arg @ref ADC_CHANNEL_19 1500 * @arg @ref ADC_CHANNEL_VREFINT 1501 * @arg @ref ADC_CHANNEL_TEMPSENSOR 1502 * @arg @ref ADC_CHANNEL_VBAT 1503 * @arg @ref ADC_CHANNEL_DACCH1 1504 * @retval Returned value can be one of the following values: 1505 * @arg @ref ADC_CHANNEL_0 1506 * @arg @ref ADC_CHANNEL_1 1507 * @arg @ref ADC_CHANNEL_2 1508 * @arg @ref ADC_CHANNEL_3 1509 * @arg @ref ADC_CHANNEL_4 1510 * @arg @ref ADC_CHANNEL_5 1511 * @arg @ref ADC_CHANNEL_6 1512 * @arg @ref ADC_CHANNEL_7 1513 * @arg @ref ADC_CHANNEL_8 1514 * @arg @ref ADC_CHANNEL_9 1515 * @arg @ref ADC_CHANNEL_10 1516 * @arg @ref ADC_CHANNEL_11 1517 * @arg @ref ADC_CHANNEL_12 1518 * @arg @ref ADC_CHANNEL_13 1519 * @arg @ref ADC_CHANNEL_14 1520 * @arg @ref ADC_CHANNEL_15 1521 * @arg @ref ADC_CHANNEL_16 1522 * @arg @ref ADC_CHANNEL_17 1523 * @arg @ref ADC_CHANNEL_18 1524 * @arg @ref ADC_CHANNEL_19 1525 */ 1526 #define __HAL_ADC_CHANNEL_INTERNAL_TO_EXTERNAL(__CHANNEL__) \ 1527 __LL_ADC_CHANNEL_INTERNAL_TO_EXTERNAL((__CHANNEL__)) 1528 1529 /** 1530 * @brief Helper macro to determine whether the internal channel 1531 * selected is available on the ADC instance selected. 1532 * @note The channel parameter must be a value defined from parameter 1533 * definition of a ADC internal channel (ADC_CHANNEL_VREFINT, 1534 * ADC_CHANNEL_TEMPSENSOR, ...), 1535 * must not be a value defined from parameter definition of 1536 * ADC external channel (ADC_CHANNEL_1, ADC_CHANNEL_2, ...) 1537 * or a value from functions where a channel number is 1538 * returned from ADC registers, 1539 * because internal and external channels share the same channel 1540 * number in ADC registers. The differentiation is made only with 1541 * parameters definitions of driver. 1542 * @param __ADC_INSTANCE__ ADC instance 1543 * @param __CHANNEL__ This parameter can be one of the following values: 1544 * @arg @ref ADC_CHANNEL_VREFINT 1545 * @arg @ref ADC_CHANNEL_TEMPSENSOR 1546 * @arg @ref ADC_CHANNEL_VBAT 1547 * @arg @ref ADC_CHANNEL_DACCH1 1548 * @retval Value "0" if the internal channel selected is not available on the ADC instance selected. 1549 * Value "1" if the internal channel selected is available on the ADC instance selected. 1550 */ 1551 #define __HAL_ADC_IS_CHANNEL_INTERNAL_AVAILABLE(__ADC_INSTANCE__, __CHANNEL__) \ 1552 __LL_ADC_IS_CHANNEL_INTERNAL_AVAILABLE((__ADC_INSTANCE__), (__CHANNEL__)) 1553 1554 /** 1555 * @brief Helper macro to select the ADC common instance 1556 * to which is belonging the selected ADC instance. 1557 * @note ADC common register instance can be used for: 1558 * - Set parameters common to several ADC instances 1559 * - Multimode (for devices with several ADC instances) 1560 * Refer to functions having argument "ADCxy_COMMON" as parameter. 1561 * @param __ADCx__ ADC instance 1562 * @retval ADC common register instance 1563 */ 1564 #define __HAL_ADC_COMMON_INSTANCE(__ADCx__) \ 1565 __LL_ADC_COMMON_INSTANCE((__ADCx__)) 1566 1567 /** 1568 * @brief Helper macro to check if all ADC instances sharing the same 1569 * ADC common instance are disabled. 1570 * @note This check is required by functions with setting conditioned to 1571 * ADC state: 1572 * All ADC instances of the ADC common group must be disabled. 1573 * Refer to functions having argument "ADCxy_COMMON" as parameter. 1574 * @note On devices with only 1 ADC common instance, parameter of this macro 1575 * is useless and can be ignored (parameter kept for compatibility 1576 * with devices featuring several ADC common instances). 1577 * @param __ADCXY_COMMON__ ADC common instance 1578 * (can be set directly from CMSIS definition or by using helper macro @ref __LL_ADC_COMMON_INSTANCE() ) 1579 * @retval Value "0" if all ADC instances sharing the same ADC common instance 1580 * are disabled. 1581 * Value "1" if at least one ADC instance sharing the same ADC common instance 1582 * is enabled. 1583 */ 1584 #define __HAL_ADC_IS_ENABLED_ALL_COMMON_INSTANCE(__ADCXY_COMMON__) \ 1585 __LL_ADC_IS_ENABLED_ALL_COMMON_INSTANCE((__ADCXY_COMMON__)) 1586 1587 /** 1588 * @brief Helper macro to define the ADC conversion data full-scale digital 1589 * value corresponding to the selected ADC resolution. 1590 * @note ADC conversion data full-scale corresponds to voltage range 1591 * determined by analog voltage references Vref+ and Vref- 1592 * (refer to reference manual). 1593 * @param __ADC_RESOLUTION__ This parameter can be one of the following values: 1594 * @arg @ref ADC_RESOLUTION_12B 1595 * @arg @ref ADC_RESOLUTION_10B 1596 * @arg @ref ADC_RESOLUTION_8B 1597 * @arg @ref ADC_RESOLUTION_6B 1598 * @retval ADC conversion data full-scale digital value 1599 */ 1600 #define __HAL_ADC_DIGITAL_SCALE(__ADC_RESOLUTION__) \ 1601 __LL_ADC_DIGITAL_SCALE((__ADC_RESOLUTION__)) 1602 1603 /** 1604 * @brief Helper macro to convert the ADC conversion data from 1605 * a resolution to another resolution. 1606 * @param __DATA__ ADC conversion data to be converted 1607 * @param __ADC_RESOLUTION_CURRENT__ Resolution of to the data to be converted 1608 * This parameter can be one of the following values: 1609 * @arg @ref ADC_RESOLUTION_12B 1610 * @arg @ref ADC_RESOLUTION_10B 1611 * @arg @ref ADC_RESOLUTION_8B 1612 * @arg @ref ADC_RESOLUTION_6B 1613 * @param __ADC_RESOLUTION_TARGET__ Resolution of the data after conversion 1614 * This parameter can be one of the following values: 1615 * @arg @ref ADC_RESOLUTION_12B 1616 * @arg @ref ADC_RESOLUTION_10B 1617 * @arg @ref ADC_RESOLUTION_8B 1618 * @arg @ref ADC_RESOLUTION_6B 1619 * @retval ADC conversion data to the requested resolution 1620 */ 1621 #define __HAL_ADC_CONVERT_DATA_RESOLUTION(__DATA__,\ 1622 __ADC_RESOLUTION_CURRENT__,\ 1623 __ADC_RESOLUTION_TARGET__) \ 1624 __LL_ADC_CONVERT_DATA_RESOLUTION((__DATA__),\ 1625 (__ADC_RESOLUTION_CURRENT__),\ 1626 (__ADC_RESOLUTION_TARGET__)) 1627 1628 /** 1629 * @brief Helper macro to calculate the voltage (unit: mVolt) 1630 * corresponding to a ADC conversion data (unit: digital value). 1631 * @note Analog reference voltage (Vref+) must be either known from 1632 * user board environment or can be calculated using ADC measurement 1633 * and ADC helper macro @ref __LL_ADC_CALC_VREFANALOG_VOLTAGE(). 1634 * @param __VREFANALOG_VOLTAGE__ Analog reference voltage (unit: mV) 1635 * @param __ADC_DATA__ ADC conversion data (resolution 12 bits) 1636 * (unit: digital value). 1637 * @param __ADC_RESOLUTION__ This parameter can be one of the following values: 1638 * @arg @ref ADC_RESOLUTION_12B 1639 * @arg @ref ADC_RESOLUTION_10B 1640 * @arg @ref ADC_RESOLUTION_8B 1641 * @arg @ref ADC_RESOLUTION_6B 1642 * @retval ADC conversion data equivalent voltage value (unit: mVolt) 1643 */ 1644 #define __HAL_ADC_CALC_DATA_TO_VOLTAGE(__VREFANALOG_VOLTAGE__,\ 1645 __ADC_DATA__,\ 1646 __ADC_RESOLUTION__) \ 1647 __LL_ADC_CALC_DATA_TO_VOLTAGE((__VREFANALOG_VOLTAGE__),\ 1648 (__ADC_DATA__),\ 1649 (__ADC_RESOLUTION__)) 1650 1651 /** 1652 * @brief Helper macro to calculate analog reference voltage (Vref+) 1653 * (unit: mVolt) from ADC conversion data of internal voltage 1654 * reference VrefInt. 1655 * @note Computation is using VrefInt calibration value 1656 * stored in system memory for each device during production. 1657 * @note This voltage depends on user board environment: voltage level 1658 * connected to pin Vref+. 1659 * On devices with small package, the pin Vref+ is not present 1660 * and internally bonded to pin Vdda. 1661 * @note On this STM32 series, calibration data of internal voltage reference 1662 * VrefInt corresponds to a resolution of 12 bits, 1663 * this is the recommended ADC resolution to convert voltage of 1664 * internal voltage reference VrefInt. 1665 * Otherwise, this macro performs the processing to scale 1666 * ADC conversion data to 12 bits. 1667 * @param __VREFINT_ADC_DATA__ ADC conversion data (resolution 12 bits) 1668 * of internal voltage reference VrefInt (unit: digital value). 1669 * @param __ADC_RESOLUTION__ This parameter can be one of the following values: 1670 * @arg @ref ADC_RESOLUTION_12B 1671 * @arg @ref ADC_RESOLUTION_10B 1672 * @arg @ref ADC_RESOLUTION_8B 1673 * @arg @ref ADC_RESOLUTION_6B 1674 * @retval Analog reference voltage (unit: mV) 1675 */ 1676 #define __HAL_ADC_CALC_VREFANALOG_VOLTAGE(__VREFINT_ADC_DATA__,\ 1677 __ADC_RESOLUTION__) \ 1678 __LL_ADC_CALC_VREFANALOG_VOLTAGE((__VREFINT_ADC_DATA__),\ 1679 (__ADC_RESOLUTION__)) 1680 1681 /** 1682 * @brief Helper macro to calculate the temperature (unit: degree Celsius) 1683 * from ADC conversion data of internal temperature sensor. 1684 * @note Computation is using temperature sensor calibration values 1685 * stored in system memory for each device during production. 1686 * @note Calculation formula: 1687 * Temperature = ((TS_ADC_DATA - TS_CAL1) 1688 * * (TS_CAL2_TEMP - TS_CAL1_TEMP)) 1689 * / (TS_CAL2 - TS_CAL1) + TS_CAL1_TEMP 1690 * with TS_ADC_DATA = temperature sensor raw data measured by ADC 1691 * Avg_Slope = (TS_CAL2 - TS_CAL1) 1692 * / (TS_CAL2_TEMP - TS_CAL1_TEMP) 1693 * TS_CAL1 = equivalent TS_ADC_DATA at temperature 1694 * TEMP_DEGC_CAL1 (calibrated in factory) 1695 * TS_CAL2 = equivalent TS_ADC_DATA at temperature 1696 * TEMP_DEGC_CAL2 (calibrated in factory) 1697 * Caution: Calculation relevancy under reserve that calibration 1698 * parameters are correct (address and data). 1699 * To calculate temperature using temperature sensor 1700 * datasheet typical values (generic values less, therefore 1701 * less accurate than calibrated values), 1702 * use helper macro @ref __LL_ADC_CALC_TEMPERATURE_TYP_PARAMS(). 1703 * @note As calculation input, the analog reference voltage (Vref+) must be 1704 * defined as it impacts the ADC LSB equivalent voltage. 1705 * @note Analog reference voltage (Vref+) must be either known from 1706 * user board environment or can be calculated using ADC measurement 1707 * and ADC helper macro @ref __LL_ADC_CALC_VREFANALOG_VOLTAGE(). 1708 * @note On this STM32 series, calibration data of temperature sensor 1709 * corresponds to a resolution of 12 bits, 1710 * this is the recommended ADC resolution to convert voltage of 1711 * temperature sensor. 1712 * Otherwise, this macro performs the processing to scale 1713 * ADC conversion data to 12 bits. 1714 * @param __VREFANALOG_VOLTAGE__ Analog reference voltage (unit: mV) 1715 * @param __TEMPSENSOR_ADC_DATA__ ADC conversion data of internal 1716 * temperature sensor (unit: digital value). 1717 * @param __ADC_RESOLUTION__ ADC resolution at which internal temperature 1718 * sensor voltage has been measured. 1719 * This parameter can be one of the following values: 1720 * @arg @ref ADC_RESOLUTION_12B 1721 * @arg @ref ADC_RESOLUTION_10B 1722 * @arg @ref ADC_RESOLUTION_8B 1723 * @arg @ref ADC_RESOLUTION_6B 1724 * @retval Temperature (unit: degree Celsius) 1725 */ 1726 #define __HAL_ADC_CALC_TEMPERATURE(__VREFANALOG_VOLTAGE__,\ 1727 __TEMPSENSOR_ADC_DATA__,\ 1728 __ADC_RESOLUTION__) \ 1729 __LL_ADC_CALC_TEMPERATURE((__VREFANALOG_VOLTAGE__),\ 1730 (__TEMPSENSOR_ADC_DATA__),\ 1731 (__ADC_RESOLUTION__)) 1732 1733 /** 1734 * @brief Helper macro to calculate the temperature (unit: degree Celsius) 1735 * from ADC conversion data of internal temperature sensor. 1736 * @note Computation is using temperature sensor typical values 1737 * (refer to device datasheet). 1738 * @note Calculation formula: 1739 * Temperature = (TS_TYP_CALx_VOLT(uV) - TS_ADC_DATA * Conversion_uV) 1740 * / Avg_Slope + CALx_TEMP 1741 * with TS_ADC_DATA = temperature sensor raw data measured by ADC 1742 * (unit: digital value) 1743 * Avg_Slope = temperature sensor slope 1744 * (unit: uV/Degree Celsius) 1745 * TS_TYP_CALx_VOLT = temperature sensor digital value at 1746 * temperature CALx_TEMP (unit: mV) 1747 * Caution: Calculation relevancy under reserve the temperature sensor 1748 * of the current device has characteristics in line with 1749 * datasheet typical values. 1750 * If temperature sensor calibration values are available on 1751 * on this device (presence of macro __LL_ADC_CALC_TEMPERATURE()), 1752 * temperature calculation will be more accurate using 1753 * helper macro @ref __LL_ADC_CALC_TEMPERATURE(). 1754 * @note As calculation input, the analog reference voltage (Vref+) must be 1755 * defined as it impacts the ADC LSB equivalent voltage. 1756 * @note Analog reference voltage (Vref+) must be either known from 1757 * user board environment or can be calculated using ADC measurement 1758 * and ADC helper macro @ref __LL_ADC_CALC_VREFANALOG_VOLTAGE(). 1759 * @note ADC measurement data must correspond to a resolution of 12bits 1760 * (full scale digital value 4095). If not the case, the data must be 1761 * preliminarily rescaled to an equivalent resolution of 12 bits. 1762 * @param __TEMPSENSOR_TYP_AVGSLOPE__ Device datasheet data: Temperature sensor slope typical value 1763 (unit: uV/DegCelsius). 1764 * On this STM32 series, refer to device datasheet parameter "Avg_Slope". 1765 * @param __TEMPSENSOR_TYP_CALX_V__ Device datasheet data: Temperature sensor voltage typical value (at 1766 temperature and Vref+ defined in parameters below) (unit: mV). 1767 * On this STM32 series, refer to device datasheet parameter "V30" 1768 * (corresponding to TS_CAL1). 1769 * @param __TEMPSENSOR_CALX_TEMP__ Device datasheet data: Temperature at which temperature sensor voltage (see 1770 parameter above) is corresponding (unit: mV) 1771 * @param __VREFANALOG_VOLTAGE__ Analog voltage reference (Vref+) voltage (unit: mV) 1772 * @param __TEMPSENSOR_ADC_DATA__ ADC conversion data of internal temperature sensor (unit: digital value). 1773 * @param __ADC_RESOLUTION__ ADC resolution at which internal temperature sensor voltage has been measured. 1774 * This parameter can be one of the following values: 1775 * @arg @ref ADC_RESOLUTION_12B 1776 * @arg @ref ADC_RESOLUTION_10B 1777 * @arg @ref ADC_RESOLUTION_8B 1778 * @arg @ref ADC_RESOLUTION_6B 1779 * @retval Temperature (unit: degree Celsius) 1780 */ 1781 #define __HAL_ADC_CALC_TEMPERATURE_TYP_PARAMS(__TEMPSENSOR_TYP_AVGSLOPE__,\ 1782 __TEMPSENSOR_TYP_CALX_V__,\ 1783 __TEMPSENSOR_CALX_TEMP__,\ 1784 __VREFANALOG_VOLTAGE__,\ 1785 __TEMPSENSOR_ADC_DATA__,\ 1786 __ADC_RESOLUTION__) \ 1787 __LL_ADC_CALC_TEMPERATURE_TYP_PARAMS((__TEMPSENSOR_TYP_AVGSLOPE__),\ 1788 (__TEMPSENSOR_TYP_CALX_V__),\ 1789 (__TEMPSENSOR_CALX_TEMP__),\ 1790 (__VREFANALOG_VOLTAGE__),\ 1791 (__TEMPSENSOR_ADC_DATA__),\ 1792 (__ADC_RESOLUTION__)) 1793 1794 /** 1795 * @} 1796 */ 1797 1798 /** 1799 * @} 1800 */ 1801 1802 /* Include ADC HAL Extended module */ 1803 #include "stm32u0xx_hal_adc_ex.h" 1804 1805 /* Exported functions --------------------------------------------------------*/ 1806 /** @addtogroup ADC_Exported_Functions 1807 * @{ 1808 */ 1809 1810 /** @addtogroup ADC_Exported_Functions_Group1 1811 * @brief Initialization and Configuration functions 1812 * @{ 1813 */ 1814 /* Initialization and de-initialization functions ****************************/ 1815 HAL_StatusTypeDef HAL_ADC_Init(ADC_HandleTypeDef *hadc); 1816 HAL_StatusTypeDef HAL_ADC_DeInit(ADC_HandleTypeDef *hadc); 1817 void HAL_ADC_MspInit(ADC_HandleTypeDef *hadc); 1818 void HAL_ADC_MspDeInit(ADC_HandleTypeDef *hadc); 1819 1820 #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1) 1821 /* Callbacks Register/UnRegister functions ***********************************/ 1822 HAL_StatusTypeDef HAL_ADC_RegisterCallback(ADC_HandleTypeDef *hadc, HAL_ADC_CallbackIDTypeDef CallbackID, 1823 pADC_CallbackTypeDef pCallback); 1824 HAL_StatusTypeDef HAL_ADC_UnRegisterCallback(ADC_HandleTypeDef *hadc, HAL_ADC_CallbackIDTypeDef CallbackID); 1825 #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */ 1826 /** 1827 * @} 1828 */ 1829 1830 /** @addtogroup ADC_Exported_Functions_Group2 1831 * @brief IO operation functions 1832 * @{ 1833 */ 1834 /* IO operation functions *****************************************************/ 1835 1836 /* Blocking mode: Polling */ 1837 HAL_StatusTypeDef HAL_ADC_Start(ADC_HandleTypeDef *hadc); 1838 HAL_StatusTypeDef HAL_ADC_Stop(ADC_HandleTypeDef *hadc); 1839 HAL_StatusTypeDef HAL_ADC_PollForConversion(ADC_HandleTypeDef *hadc, uint32_t Timeout); 1840 HAL_StatusTypeDef HAL_ADC_PollForEvent(ADC_HandleTypeDef *hadc, uint32_t EventType, uint32_t Timeout); 1841 1842 /* Non-blocking mode: Interruption */ 1843 HAL_StatusTypeDef HAL_ADC_Start_IT(ADC_HandleTypeDef *hadc); 1844 HAL_StatusTypeDef HAL_ADC_Stop_IT(ADC_HandleTypeDef *hadc); 1845 1846 /* Non-blocking mode: DMA */ 1847 HAL_StatusTypeDef HAL_ADC_Start_DMA(ADC_HandleTypeDef *hadc, uint32_t *pData, uint32_t Length); 1848 HAL_StatusTypeDef HAL_ADC_Stop_DMA(ADC_HandleTypeDef *hadc); 1849 1850 /* ADC retrieve conversion value intended to be used with polling or interruption */ 1851 uint32_t HAL_ADC_GetValue(const ADC_HandleTypeDef *hadc); 1852 1853 /* ADC IRQHandler and Callbacks used in non-blocking modes (Interruption and DMA) */ 1854 void HAL_ADC_IRQHandler(ADC_HandleTypeDef *hadc); 1855 void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef *hadc); 1856 void HAL_ADC_ConvHalfCpltCallback(ADC_HandleTypeDef *hadc); 1857 void HAL_ADC_LevelOutOfWindowCallback(ADC_HandleTypeDef *hadc); 1858 void HAL_ADC_ErrorCallback(ADC_HandleTypeDef *hadc); 1859 void HAL_ADC_CalibrationCpltCallback(ADC_HandleTypeDef *hadc); 1860 void HAL_ADC_ADCReadyCallback(ADC_HandleTypeDef *hadc); 1861 /** 1862 * @} 1863 */ 1864 1865 /** @addtogroup ADC_Exported_Functions_Group3 Peripheral Control functions 1866 * @brief Peripheral Control functions 1867 * @{ 1868 */ 1869 /* Peripheral Control functions ***********************************************/ 1870 HAL_StatusTypeDef HAL_ADC_ConfigChannel(ADC_HandleTypeDef *hadc, const ADC_ChannelConfTypeDef *pConfig); 1871 HAL_StatusTypeDef HAL_ADC_AnalogWDGConfig(ADC_HandleTypeDef *hadc, 1872 const ADC_AnalogWDGConfTypeDef *pAnalogWDGConfig); 1873 1874 /** 1875 * @} 1876 */ 1877 1878 /* Peripheral State functions *************************************************/ 1879 /** @addtogroup ADC_Exported_Functions_Group4 1880 * @{ 1881 */ 1882 uint32_t HAL_ADC_GetState(const ADC_HandleTypeDef *hadc); 1883 uint32_t HAL_ADC_GetError(const ADC_HandleTypeDef *hadc); 1884 1885 /** 1886 * @} 1887 */ 1888 1889 /** 1890 * @} 1891 */ 1892 1893 /* Private functions ---------------------------------------------------------*/ 1894 HAL_StatusTypeDef ADC_ConversionStop(ADC_HandleTypeDef *hadc); 1895 HAL_StatusTypeDef ADC_Enable(ADC_HandleTypeDef *hadc); 1896 HAL_StatusTypeDef ADC_Disable(ADC_HandleTypeDef *hadc); 1897 1898 /** 1899 * @} 1900 */ 1901 1902 /** 1903 * @} 1904 */ 1905 1906 /** 1907 * @} 1908 */ 1909 1910 #ifdef __cplusplus 1911 } 1912 #endif 1913 1914 1915 #endif /* STM32U0xx_HAL_ADC_H */ 1916