You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

1677 lines
104 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32wbxx_hal_adc.h
  4. * @author MCD Application Team
  5. * @brief Header file of ADC HAL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by ST under BSD 3-Clause license,
  13. * the "License"; You may not use this file except in compliance with the
  14. * License. You may obtain a copy of the License at:
  15. * opensource.org/licenses/BSD-3-Clause
  16. *
  17. ******************************************************************************
  18. */
  19. /* Define to prevent recursive inclusion -------------------------------------*/
  20. #ifndef STM32WBxx_HAL_ADC_H
  21. #define STM32WBxx_HAL_ADC_H
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. /* Includes ------------------------------------------------------------------*/
  26. #include "stm32wbxx_hal_def.h"
  27. /* Include low level driver */
  28. #include "stm32wbxx_ll_adc.h"
  29. /** @addtogroup STM32WBxx_HAL_Driver
  30. * @{
  31. */
  32. /** @addtogroup ADC
  33. * @{
  34. */
  35. /* Exported types ------------------------------------------------------------*/
  36. /** @defgroup ADC_Exported_Types ADC Exported Types
  37. * @{
  38. */
  39. /**
  40. * @brief ADC group regular oversampling structure definition
  41. */
  42. typedef struct
  43. {
  44. uint32_t Ratio; /*!< Configures the oversampling ratio.
  45. This parameter can be a value of @ref ADC_HAL_EC_OVS_RATIO */
  46. uint32_t RightBitShift; /*!< Configures the division coefficient for the Oversampler.
  47. This parameter can be a value of @ref ADC_HAL_EC_OVS_SHIFT */
  48. uint32_t TriggeredMode; /*!< Selects the regular triggered oversampling mode.
  49. This parameter can be a value of @ref ADC_HAL_EC_OVS_DISCONT_MODE */
  50. uint32_t OversamplingStopReset; /*!< Selects the regular oversampling mode.
  51. The oversampling is either temporary stopped or reset upon an injected
  52. sequence interruption.
  53. If oversampling is enabled on both regular and injected groups, this parameter
  54. is discarded and forced to setting "ADC_REGOVERSAMPLING_RESUMED_MODE"
  55. (the oversampling buffer is zeroed during injection sequence).
  56. This parameter can be a value of @ref ADC_HAL_EC_OVS_SCOPE_REG */
  57. } ADC_OversamplingTypeDef;
  58. /**
  59. * @brief Structure definition of ADC instance and ADC group regular.
  60. * @note Parameters of this structure are shared within 2 scopes:
  61. * - Scope entire ADC (affects ADC groups regular and injected): ClockPrescaler, Resolution, DataAlign,
  62. * ScanConvMode, EOCSelection, LowPowerAutoWait.
  63. * - Scope ADC group regular: ContinuousConvMode, NbrOfConversion, DiscontinuousConvMode, NbrOfDiscConversion,
  64. * ExternalTrigConv, ExternalTrigConvEdge, DMAContinuousRequests, Overrun, OversamplingMode, Oversampling.
  65. * @note The setting of these parameters by function HAL_ADC_Init() is conditioned to ADC state.
  66. * ADC state can be either:
  67. * - For all parameters: ADC disabled
  68. * - For all parameters except 'LowPowerAutoWait', 'DMAContinuousRequests' and 'Oversampling': ADC enabled without conversion on going on group regular.
  69. * - For parameters 'LowPowerAutoWait' and 'DMAContinuousRequests': ADC enabled without conversion on going on groups regular and injected.
  70. * If ADC is not in the appropriate state to modify some parameters, these parameters setting is bypassed
  71. * without error reporting (as it can be the expected behavior in case of intended action to update another parameter
  72. * (which fulfills the ADC state condition) on the fly).
  73. */
  74. typedef struct
  75. {
  76. uint32_t ClockPrescaler; /*!< Select ADC clock source (synchronous clock derived from APB clock or asynchronous clock derived from system clock or PLL (Refer to reference manual for list of clocks available)) and clock prescaler.
  77. This parameter can be a value of @ref ADC_HAL_EC_COMMON_CLOCK_SOURCE.
  78. Note: The ADC clock configuration is common to all ADC instances.
  79. Note: ADC clock source and prescaler must be selected in function of system clock to not exceed ADC maximum frequency, depending on devices.
  80. Example: STM32WB55xx ADC maximum frequency is 64MHz (corresponding to 4.27Msmp/s maximum)
  81. Example: STM32WB50xx ADC maximum frequency is 32MHz (corresponding to 2.13Msmp/s maximum)
  82. For ADC maximum frequency, refer to datasheet of the selected device.
  83. Note: In case of usage of channels on injected group, ADC frequency should be lower than AHB clock frequency /4 for resolution 12 or 10 bits,
  84. AHB clock frequency /3 for resolution 8 bits, AHB clock frequency /2 for resolution 6 bits.
  85. Note: In case of synchronous clock mode based on HCLK/1, the configuration must be enabled only
  86. if the system clock has a 50% duty clock cycle (APB prescaler configured inside RCC
  87. must be bypassed and PCLK clock must have 50% duty cycle). Refer to reference manual for details.
  88. Note: In case of usage of asynchronous clock, the selected clock must be preliminarily enabled at RCC top level.
  89. Note: This parameter can be modified only if all ADC instances are disabled. */
  90. uint32_t Resolution; /*!< Configure the ADC resolution.
  91. This parameter can be a value of @ref ADC_HAL_EC_RESOLUTION */
  92. uint32_t DataAlign; /*!< Specify ADC data alignment in conversion data register (right or left).
  93. Refer to reference manual for alignments formats versus resolutions.
  94. This parameter can be a value of @ref ADC_HAL_EC_DATA_ALIGN */
  95. uint32_t ScanConvMode; /*!< Configure the sequencer of ADC groups regular and injected.
  96. This parameter can be associated to parameter 'DiscontinuousConvMode' to have main sequence subdivided in successive parts.
  97. If disabled: Conversion is performed in single mode (one channel converted, the one defined in rank 1).
  98. Parameters 'NbrOfConversion' and 'InjectedNbrOfConversion' are discarded (equivalent to set to 1).
  99. If enabled: Conversions are performed in sequence mode (multiple ranks defined by 'NbrOfConversion' or 'InjectedNbrOfConversion' and rank of each channel in sequencer).
  100. Scan direction is upward: from rank 1 to rank 'n'.
  101. This parameter can be a value of @ref ADC_Scan_mode */
  102. uint32_t EOCSelection; /*!< Specify which EOC (End Of Conversion) flag is used for conversion by polling and interruption: end of unitary conversion or end of sequence conversions.
  103. This parameter can be a value of @ref ADC_EOCSelection. */
  104. FunctionalState LowPowerAutoWait; /*!< Select the dynamic low power Auto Delay: new conversion start only when the previous
  105. conversion (for ADC group regular) or previous sequence (for ADC group injected) has been retrieved by user software,
  106. using function HAL_ADC_GetValue() or HAL_ADCEx_InjectedGetValue().
  107. This feature automatically adapts the frequency of ADC conversions triggers to the speed of the system that reads the data. Moreover, this avoids risk of overrun
  108. for low frequency applications.
  109. This parameter can be set to ENABLE or DISABLE.
  110. Note: It is not recommended to use with interruption or DMA (HAL_ADC_Start_IT(), HAL_ADC_Start_DMA()) since these modes have to clear immediately the EOC flag (by CPU to free the IRQ pending event or by DMA).
  111. Auto wait will work but fort a very short time, discarding its intended benefit (except specific case of high load of CPU or DMA transfers which can justify usage of auto wait).
  112. Do use with polling: 1. Start conversion with HAL_ADC_Start(), 2. Later on, when ADC conversion data is needed:
  113. use HAL_ADC_PollForConversion() to ensure that conversion is completed and HAL_ADC_GetValue() to retrieve conversion result and trig another conversion start.
  114. (in case of usage of ADC group injected, use the equivalent functions HAL_ADCExInjected_Start(), HAL_ADCEx_InjectedGetValue(), ...). */
  115. FunctionalState ContinuousConvMode; /*!< Specify whether the conversion is performed in single mode (one conversion) or continuous mode for ADC group regular,
  116. after the first ADC conversion start trigger occurred (software start or external trigger).
  117. This parameter can be set to ENABLE or DISABLE. */
  118. uint32_t NbrOfConversion; /*!< Specify the number of ranks that will be converted within the regular group sequencer.
  119. To use the regular group sequencer and convert several ranks, parameter 'ScanConvMode' must be enabled.
  120. This parameter must be a number between Min_Data = 1 and Max_Data = 16.
  121. Note: This parameter must be modified when no conversion is on going on regular group (ADC disabled, or ADC enabled without
  122. continuous mode or external trigger that could launch a conversion). */
  123. FunctionalState DiscontinuousConvMode; /*!< Specify whether the conversions sequence of ADC group regular is performed in Complete-sequence/Discontinuous-sequence
  124. (main sequence subdivided in successive parts).
  125. Discontinuous mode is used only if sequencer is enabled (parameter 'ScanConvMode'). If sequencer is disabled, this parameter is discarded.
  126. Discontinuous mode can be enabled only if continuous mode is disabled. If continuous mode is enabled, this parameter setting is discarded.
  127. This parameter can be set to ENABLE or DISABLE. */
  128. uint32_t NbrOfDiscConversion; /*!< Specifies the number of discontinuous conversions in which the main sequence of ADC group regular (parameter NbrOfConversion) will be subdivided.
  129. If parameter 'DiscontinuousConvMode' is disabled, this parameter is discarded.
  130. This parameter must be a number between Min_Data = 1 and Max_Data = 8. */
  131. uint32_t ExternalTrigConv; /*!< Select the external event source used to trigger ADC group regular conversion start.
  132. If set to ADC_SOFTWARE_START, external triggers are disabled and software trigger is used instead.
  133. This parameter can be a value of @ref ADC_regular_external_trigger_source.
  134. Caution: external trigger source is common to all ADC instances. */
  135. uint32_t ExternalTrigConvEdge; /*!< Select the external event edge used to trigger ADC group regular conversion start.
  136. If trigger source is set to ADC_SOFTWARE_START, this parameter is discarded.
  137. This parameter can be a value of @ref ADC_regular_external_trigger_edge */
  138. FunctionalState DMAContinuousRequests; /*!< Specify whether the DMA requests are performed in one shot mode (DMA transfer stops when number of conversions is reached)
  139. or in continuous mode (DMA transfer unlimited, whatever number of conversions).
  140. This parameter can be set to ENABLE or DISABLE.
  141. Note: In continuous mode, DMA must be configured in circular mode. Otherwise an overrun will be triggered when DMA buffer maximum pointer is reached. */
  142. uint32_t Overrun; /*!< Select the behavior in case of overrun: data overwritten or preserved (default).
  143. This parameter applies to ADC group regular only.
  144. This parameter can be a value of @ref ADC_HAL_EC_REG_OVR_DATA_BEHAVIOR.
  145. Note: In case of overrun set to data preserved and usage with programming model with interruption (HAL_Start_IT()): ADC IRQ handler has to clear
  146. end of conversion flags, this induces the release of the preserved data. If needed, this data can be saved in function
  147. HAL_ADC_ConvCpltCallback(), placed in user program code (called before end of conversion flags clear).
  148. Note: Error reporting with respect to the conversion mode:
  149. - Usage with ADC conversion by polling for event or interruption: Error is reported only if overrun is set to data preserved. If overrun is set to data
  150. overwritten, user can willingly not read all the converted data, this is not considered as an erroneous case.
  151. - Usage with ADC conversion by DMA: Error is reported whatever overrun setting (DMA is expected to process all data from data register). */
  152. FunctionalState OversamplingMode; /*!< Specify whether the oversampling feature is enabled or disabled.
  153. This parameter can be set to ENABLE or DISABLE.
  154. Note: This parameter can be modified only if there is no conversion is ongoing on ADC groups regular and injected */
  155. ADC_OversamplingTypeDef Oversampling; /*!< Specify the Oversampling parameters.
  156. Caution: this setting overwrites the previous oversampling configuration if oversampling is already enabled. */
  157. } ADC_InitTypeDef;
  158. /**
  159. * @brief Structure definition of ADC channel for regular group
  160. * @note The setting of these parameters by function HAL_ADC_ConfigChannel() is conditioned to ADC state.
  161. * ADC state can be either:
  162. * - For all parameters: ADC disabled (this is the only possible ADC state to modify parameter 'SingleDiff')
  163. * - For all except parameters 'SamplingTime', 'Offset', 'OffsetNumber': ADC enabled without conversion on going on regular group.
  164. * - For parameters 'SamplingTime', 'Offset', 'OffsetNumber': ADC enabled without conversion on going on regular and injected groups.
  165. * If ADC is not in the appropriate state to modify some parameters, these parameters setting is bypassed
  166. * without error reporting (as it can be the expected behavior in case of intended action to update another parameter (which fulfills the ADC state condition)
  167. * on the fly).
  168. */
  169. typedef struct
  170. {
  171. uint32_t Channel; /*!< Specify the channel to configure into ADC regular group.
  172. This parameter can be a value of @ref ADC_HAL_EC_CHANNEL
  173. Note: Depending on devices and ADC instances, some channels may not be available on device package pins. Refer to device datasheet for channels availability. */
  174. uint32_t Rank; /*!< Specify the rank in the regular group sequencer.
  175. This parameter can be a value of @ref ADC_HAL_EC_REG_SEQ_RANKS
  176. Note: to disable a channel or change order of conversion sequencer, rank containing a previous channel setting can be overwritten by
  177. the new channel setting (or parameter number of conversions adjusted) */
  178. uint32_t SamplingTime; /*!< Sampling time value to be set for the selected channel.
  179. Unit: ADC clock cycles
  180. Conversion time is the addition of sampling time and processing time
  181. (12.5 ADC clock cycles at ADC resolution 12 bits, 10.5 cycles at 10 bits, 8.5 cycles at 8 bits, 6.5 cycles at 6 bits).
  182. This parameter can be a value of @ref ADC_HAL_EC_CHANNEL_SAMPLINGTIME
  183. Caution: This parameter applies to a channel that can be used into regular and/or injected group.
  184. It overwrites the last setting.
  185. Note: In case of usage of internal measurement channels (VrefInt/Vbat/TempSensor),
  186. sampling time constraints must be respected (sampling time can be adjusted in function of ADC clock frequency and sampling time setting)
  187. Refer to device datasheet for timings values. */
  188. uint32_t SingleDiff; /*!< Select single-ended or differential input.
  189. In differential mode: Differential measurement is carried out between the selected channel 'i' (positive input) and channel 'i+1' (negative input).
  190. Only channel 'i' has to be configured, channel 'i+1' is configured automatically.
  191. This parameter must be a value of @ref ADC_HAL_EC_CHANNEL_SINGLE_DIFF_ENDING
  192. Caution: This parameter applies to a channel that can be used in a regular and/or injected group.
  193. It overwrites the last setting.
  194. Note: Refer to Reference Manual to ensure the selected channel is available in differential mode.
  195. Note: When configuring a channel 'i' in differential mode, the channel 'i+1' is not usable separately.
  196. Note: This parameter must be modified when ADC is disabled (before ADC start conversion or after ADC stop conversion).
  197. If ADC is enabled, this parameter setting is bypassed without error reporting (as it can be the expected behavior in case
  198. of another parameter update on the fly) */
  199. uint32_t OffsetNumber; /*!< Select the offset number
  200. This parameter can be a value of @ref ADC_HAL_EC_OFFSET_NB
  201. Caution: Only one offset is allowed per channel. This parameter overwrites the last setting. */
  202. uint32_t Offset; /*!< Define the offset to be subtracted from the raw converted data.
  203. Offset value must be a positive number.
  204. Depending of ADC resolution selected (12, 10, 8 or 6 bits), this parameter must be a number between Min_Data = 0x000 and Max_Data = 0xFFF,
  205. 0x3FF, 0xFF or 0x3F respectively.
  206. Note: This parameter must be modified when no conversion is on going on both regular and injected groups (ADC disabled, or ADC enabled
  207. without continuous mode or external trigger that could launch a conversion). */
  208. } ADC_ChannelConfTypeDef;
  209. /**
  210. * @brief Structure definition of ADC analog watchdog
  211. * @note The setting of these parameters by function HAL_ADC_AnalogWDGConfig() is conditioned to ADC state.
  212. * ADC state can be either:
  213. * - For all parameters: ADC disabled or ADC enabled without conversion on going on ADC groups regular and injected.
  214. */
  215. typedef struct
  216. {
  217. uint32_t WatchdogNumber; /*!< Select which ADC analog watchdog is monitoring the selected channel.
  218. For Analog Watchdog 1: Only 1 channel can be monitored (or overall group of channels by setting parameter 'WatchdogMode')
  219. For Analog Watchdog 2 and 3: Several channels can be monitored (by successive calls of 'HAL_ADC_AnalogWDGConfig()' for each channel)
  220. This parameter can be a value of @ref ADC_HAL_EC_AWD_NUMBER. */
  221. uint32_t WatchdogMode; /*!< Configure the ADC analog watchdog mode: single/all/none channels.
  222. For Analog Watchdog 1: Configure the ADC analog watchdog mode: single channel or all channels, ADC groups regular and-or injected.
  223. For Analog Watchdog 2 and 3: Several channels can be monitored by applying successively the AWD init structure. Channels on ADC group regular and injected are not differentiated: Set value 'ADC_ANALOGWATCHDOG_SINGLE_xxx' to monitor 1 channel, value 'ADC_ANALOGWATCHDOG_ALL_xxx' to monitor all channels, 'ADC_ANALOGWATCHDOG_NONE' to monitor no channel.
  224. This parameter can be a value of @ref ADC_analog_watchdog_mode. */
  225. uint32_t Channel; /*!< Select which ADC channel to monitor by analog watchdog.
  226. For Analog Watchdog 1: this parameter has an effect only if parameter 'WatchdogMode' is configured on single channel (only 1 channel can be monitored).
  227. For Analog Watchdog 2 and 3: Several channels can be monitored. To use this feature, call successively the function HAL_ADC_AnalogWDGConfig() for each channel to be added (or removed with value 'ADC_ANALOGWATCHDOG_NONE').
  228. This parameter can be a value of @ref ADC_HAL_EC_CHANNEL. */
  229. FunctionalState ITMode; /*!< Specify whether the analog watchdog is configured in interrupt or polling mode.
  230. This parameter can be set to ENABLE or DISABLE */
  231. uint32_t HighThreshold; /*!< Configure the ADC analog watchdog High threshold value.
  232. Depending of ADC resolution selected (12, 10, 8 or 6 bits), this parameter must be a number
  233. between Min_Data = 0x000 and Max_Data = 0xFFF, 0x3FF, 0xFF or 0x3F respectively.
  234. Note: Analog watchdog 2 and 3 are limited to a resolution of 8 bits: if ADC resolution is 12 bits
  235. the 4 LSB are ignored, if ADC resolution is 10 bits the 2 LSB are ignored.
  236. Note: If ADC oversampling is enabled, ADC analog watchdog thresholds are
  237. impacted: the comparison of analog watchdog thresholds is done on
  238. oversampling final computation (after ratio and shift application):
  239. ADC data register bitfield [15:4] (12 most significant bits). */
  240. uint32_t LowThreshold; /*!< Configures the ADC analog watchdog Low threshold value.
  241. Depending of ADC resolution selected (12, 10, 8 or 6 bits), this parameter must be a number
  242. between Min_Data = 0x000 and Max_Data = 0xFFF, 0x3FF, 0xFF or 0x3F respectively.
  243. Note: Analog watchdog 2 and 3 are limited to a resolution of 8 bits: if ADC resolution is 12 bits
  244. the 4 LSB are ignored, if ADC resolution is 10 bits the 2 LSB are ignored.
  245. Note: If ADC oversampling is enabled, ADC analog watchdog thresholds are
  246. impacted: the comparison of analog watchdog thresholds is done on
  247. oversampling final computation (after ratio and shift application):
  248. ADC data register bitfield [15:4] (12 most significant bits). */
  249. } ADC_AnalogWDGConfTypeDef;
  250. /**
  251. * @brief ADC group injected contexts queue configuration
  252. * @note Structure intended to be used only through structure "ADC_HandleTypeDef"
  253. */
  254. typedef struct
  255. {
  256. uint32_t ContextQueue; /*!< Injected channel configuration context: build-up over each
  257. HAL_ADCEx_InjectedConfigChannel() call to finally initialize
  258. JSQR register at HAL_ADCEx_InjectedConfigChannel() last call */
  259. uint32_t ChannelCount; /*!< Number of channels in the injected sequence */
  260. } ADC_InjectionConfigTypeDef;
  261. /** @defgroup ADC_States ADC States
  262. * @{
  263. */
  264. /**
  265. * @brief HAL ADC state machine: ADC states definition (bitfields)
  266. * @note ADC state machine is managed by bitfields, state must be compared
  267. * with bit by bit.
  268. * For example:
  269. * " if ((HAL_ADC_GetState(hadc1) & HAL_ADC_STATE_REG_BUSY) != 0UL) "
  270. * " if ((HAL_ADC_GetState(hadc1) & HAL_ADC_STATE_AWD1) != 0UL) "
  271. */
  272. /* States of ADC global scope */
  273. #define HAL_ADC_STATE_RESET (0x00000000UL) /*!< ADC not yet initialized or disabled */
  274. #define HAL_ADC_STATE_READY (0x00000001UL) /*!< ADC peripheral ready for use */
  275. #define HAL_ADC_STATE_BUSY_INTERNAL (0x00000002UL) /*!< ADC is busy due to an internal process (initialization, calibration) */
  276. #define HAL_ADC_STATE_TIMEOUT (0x00000004UL) /*!< TimeOut occurrence */
  277. /* States of ADC errors */
  278. #define HAL_ADC_STATE_ERROR_INTERNAL (0x00000010UL) /*!< Internal error occurrence */
  279. #define HAL_ADC_STATE_ERROR_CONFIG (0x00000020UL) /*!< Configuration error occurrence */
  280. #define HAL_ADC_STATE_ERROR_DMA (0x00000040UL) /*!< DMA error occurrence */
  281. /* States of ADC group regular */
  282. #define HAL_ADC_STATE_REG_BUSY (0x00000100UL) /*!< A conversion on ADC group regular is ongoing or can occur (either by continuous mode,
  283. external trigger, low power auto power-on (if feature available), multimode ADC master control (if feature available)) */
  284. #define HAL_ADC_STATE_REG_EOC (0x00000200UL) /*!< Conversion data available on group regular */
  285. #define HAL_ADC_STATE_REG_OVR (0x00000400UL) /*!< Overrun occurrence */
  286. #define HAL_ADC_STATE_REG_EOSMP (0x00000800UL) /*!< Not available on this STM32 serie: End Of Sampling flag raised */
  287. /* States of ADC group injected */
  288. #define HAL_ADC_STATE_INJ_BUSY (0x00001000UL) /*!< A conversion on ADC group injected is ongoing or can occur (either by auto-injection mode,
  289. external trigger, low power auto power-on (if feature available), multimode ADC master control (if feature available)) */
  290. #define HAL_ADC_STATE_INJ_EOC (0x00002000UL) /*!< Conversion data available on group injected */
  291. #define HAL_ADC_STATE_INJ_JQOVF (0x00004000UL) /*!< Injected queue overflow occurrence */
  292. /* States of ADC analog watchdogs */
  293. #define HAL_ADC_STATE_AWD1 (0x00010000UL) /*!< Out-of-window occurrence of ADC analog watchdog 1 */
  294. #define HAL_ADC_STATE_AWD2 (0x00020000UL) /*!< Out-of-window occurrence of ADC analog watchdog 2 */
  295. #define HAL_ADC_STATE_AWD3 (0x00040000UL) /*!< Out-of-window occurrence of ADC analog watchdog 3 */
  296. /* States of ADC multi-mode */
  297. #define HAL_ADC_STATE_MULTIMODE_SLAVE (0x00100000UL) /*!< Not available on this STM32 serie: ADC in multimode slave state, controlled by another ADC master (when feature available) */
  298. /**
  299. * @}
  300. */
  301. /**
  302. * @brief ADC handle Structure definition
  303. */
  304. #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1)
  305. typedef struct __ADC_HandleTypeDef
  306. #else
  307. typedef struct
  308. #endif
  309. {
  310. ADC_TypeDef *Instance; /*!< Register base address */
  311. ADC_InitTypeDef Init; /*!< ADC initialization parameters and regular conversions setting */
  312. DMA_HandleTypeDef *DMA_Handle; /*!< Pointer DMA Handler */
  313. HAL_LockTypeDef Lock; /*!< ADC locking object */
  314. __IO uint32_t State; /*!< ADC communication state (bitmap of ADC states) */
  315. __IO uint32_t ErrorCode; /*!< ADC Error code */
  316. ADC_InjectionConfigTypeDef InjectionConfig ; /*!< ADC injected channel configuration build-up structure */
  317. #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1)
  318. void (* ConvCpltCallback)(struct __ADC_HandleTypeDef *hadc); /*!< ADC conversion complete callback */
  319. void (* ConvHalfCpltCallback)(struct __ADC_HandleTypeDef *hadc); /*!< ADC conversion DMA half-transfer callback */
  320. void (* LevelOutOfWindowCallback)(struct __ADC_HandleTypeDef *hadc); /*!< ADC analog watchdog 1 callback */
  321. void (* ErrorCallback)(struct __ADC_HandleTypeDef *hadc); /*!< ADC error callback */
  322. void (* InjectedConvCpltCallback)(struct __ADC_HandleTypeDef *hadc); /*!< ADC group injected conversion complete callback */
  323. void (* InjectedQueueOverflowCallback)(struct __ADC_HandleTypeDef *hadc); /*!< ADC group injected context queue overflow callback */
  324. void (* LevelOutOfWindow2Callback)(struct __ADC_HandleTypeDef *hadc); /*!< ADC analog watchdog 2 callback */
  325. void (* LevelOutOfWindow3Callback)(struct __ADC_HandleTypeDef *hadc); /*!< ADC analog watchdog 3 callback */
  326. void (* EndOfSamplingCallback)(struct __ADC_HandleTypeDef *hadc); /*!< ADC end of sampling callback */
  327. void (* MspInitCallback)(struct __ADC_HandleTypeDef *hadc); /*!< ADC Msp Init callback */
  328. void (* MspDeInitCallback)(struct __ADC_HandleTypeDef *hadc); /*!< ADC Msp DeInit callback */
  329. #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */
  330. } ADC_HandleTypeDef;
  331. #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1)
  332. /**
  333. * @brief HAL ADC Callback ID enumeration definition
  334. */
  335. typedef enum
  336. {
  337. HAL_ADC_CONVERSION_COMPLETE_CB_ID = 0x00U, /*!< ADC conversion complete callback ID */
  338. HAL_ADC_CONVERSION_HALF_CB_ID = 0x01U, /*!< ADC conversion DMA half-transfer callback ID */
  339. HAL_ADC_LEVEL_OUT_OF_WINDOW_1_CB_ID = 0x02U, /*!< ADC analog watchdog 1 callback ID */
  340. HAL_ADC_ERROR_CB_ID = 0x03U, /*!< ADC error callback ID */
  341. HAL_ADC_INJ_CONVERSION_COMPLETE_CB_ID = 0x04U, /*!< ADC group injected conversion complete callback ID */
  342. HAL_ADC_INJ_QUEUE_OVEFLOW_CB_ID = 0x05U, /*!< ADC group injected context queue overflow callback ID */
  343. HAL_ADC_LEVEL_OUT_OF_WINDOW_2_CB_ID = 0x06U, /*!< ADC analog watchdog 2 callback ID */
  344. HAL_ADC_LEVEL_OUT_OF_WINDOW_3_CB_ID = 0x07U, /*!< ADC analog watchdog 3 callback ID */
  345. HAL_ADC_END_OF_SAMPLING_CB_ID = 0x08U, /*!< ADC end of sampling callback ID */
  346. HAL_ADC_MSPINIT_CB_ID = 0x09U, /*!< ADC Msp Init callback ID */
  347. HAL_ADC_MSPDEINIT_CB_ID = 0x0AU /*!< ADC Msp DeInit callback ID */
  348. } HAL_ADC_CallbackIDTypeDef;
  349. /**
  350. * @brief HAL ADC Callback pointer definition
  351. */
  352. typedef void (*pADC_CallbackTypeDef)(ADC_HandleTypeDef *hadc); /*!< pointer to a ADC callback function */
  353. #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */
  354. /**
  355. * @}
  356. */
  357. /* Exported constants --------------------------------------------------------*/
  358. /** @defgroup ADC_Exported_Constants ADC Exported Constants
  359. * @{
  360. */
  361. /** @defgroup ADC_Error_Code ADC Error Code
  362. * @{
  363. */
  364. #define HAL_ADC_ERROR_NONE (0x00U) /*!< No error */
  365. #define HAL_ADC_ERROR_INTERNAL (0x01U) /*!< ADC peripheral internal error (problem of clocking,
  366. enable/disable, erroneous state, ...) */
  367. #define HAL_ADC_ERROR_OVR (0x02U) /*!< Overrun error */
  368. #define HAL_ADC_ERROR_DMA (0x04U) /*!< DMA transfer error */
  369. #define HAL_ADC_ERROR_JQOVF (0x08U) /*!< Injected context queue overflow error */
  370. #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1)
  371. #define HAL_ADC_ERROR_INVALID_CALLBACK (0x10U) /*!< Invalid Callback error */
  372. #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */
  373. /**
  374. * @}
  375. */
  376. /** @defgroup ADC_HAL_EC_COMMON_CLOCK_SOURCE ADC common - Clock source
  377. * @{
  378. */
  379. #define ADC_CLOCK_SYNC_PCLK_DIV1 (LL_ADC_CLOCK_SYNC_PCLK_DIV1) /*!< ADC synchronous clock derived from AHB clock without prescaler */
  380. #define ADC_CLOCK_SYNC_PCLK_DIV2 (LL_ADC_CLOCK_SYNC_PCLK_DIV2) /*!< ADC synchronous clock derived from AHB clock with prescaler division by 2 */
  381. #define ADC_CLOCK_SYNC_PCLK_DIV4 (LL_ADC_CLOCK_SYNC_PCLK_DIV4) /*!< ADC synchronous clock derived from AHB clock with prescaler division by 4 */
  382. #define ADC_CLOCK_ASYNC_DIV1 (LL_ADC_CLOCK_ASYNC_DIV1) /*!< ADC asynchronous clock without prescaler */
  383. #define ADC_CLOCK_ASYNC_DIV2 (LL_ADC_CLOCK_ASYNC_DIV2) /*!< ADC asynchronous clock with prescaler division by 2 */
  384. #define ADC_CLOCK_ASYNC_DIV4 (LL_ADC_CLOCK_ASYNC_DIV4) /*!< ADC asynchronous clock with prescaler division by 4 */
  385. #define ADC_CLOCK_ASYNC_DIV6 (LL_ADC_CLOCK_ASYNC_DIV6) /*!< ADC asynchronous clock with prescaler division by 6 */
  386. #define ADC_CLOCK_ASYNC_DIV8 (LL_ADC_CLOCK_ASYNC_DIV8) /*!< ADC asynchronous clock with prescaler division by 8 */
  387. #define ADC_CLOCK_ASYNC_DIV10 (LL_ADC_CLOCK_ASYNC_DIV10) /*!< ADC asynchronous clock with prescaler division by 10 */
  388. #define ADC_CLOCK_ASYNC_DIV12 (LL_ADC_CLOCK_ASYNC_DIV12) /*!< ADC asynchronous clock with prescaler division by 12 */
  389. #define ADC_CLOCK_ASYNC_DIV16 (LL_ADC_CLOCK_ASYNC_DIV16) /*!< ADC asynchronous clock with prescaler division by 16 */
  390. #define ADC_CLOCK_ASYNC_DIV32 (LL_ADC_CLOCK_ASYNC_DIV32) /*!< ADC asynchronous clock with prescaler division by 32 */
  391. #define ADC_CLOCK_ASYNC_DIV64 (LL_ADC_CLOCK_ASYNC_DIV64) /*!< ADC asynchronous clock with prescaler division by 64 */
  392. #define ADC_CLOCK_ASYNC_DIV128 (LL_ADC_CLOCK_ASYNC_DIV128) /*!< ADC asynchronous clock with prescaler division by 128 */
  393. #define ADC_CLOCK_ASYNC_DIV256 (LL_ADC_CLOCK_ASYNC_DIV256) /*!< ADC asynchronous clock with prescaler division by 256 */
  394. /**
  395. * @}
  396. */
  397. /** @defgroup ADC_HAL_EC_RESOLUTION ADC instance - Resolution
  398. * @{
  399. */
  400. #define ADC_RESOLUTION_12B (LL_ADC_RESOLUTION_12B) /*!< ADC resolution 12 bits */
  401. #define ADC_RESOLUTION_10B (LL_ADC_RESOLUTION_10B) /*!< ADC resolution 10 bits */
  402. #define ADC_RESOLUTION_8B (LL_ADC_RESOLUTION_8B) /*!< ADC resolution 8 bits */
  403. #define ADC_RESOLUTION_6B (LL_ADC_RESOLUTION_6B) /*!< ADC resolution 6 bits */
  404. /**
  405. * @}
  406. */
  407. /** @defgroup ADC_HAL_EC_DATA_ALIGN ADC conversion data alignment
  408. * @{
  409. */
  410. #define ADC_DATAALIGN_RIGHT (LL_ADC_DATA_ALIGN_RIGHT)/*!< ADC conversion data alignment: right aligned (alignment on data register LSB bit 0)*/
  411. #define ADC_DATAALIGN_LEFT (LL_ADC_DATA_ALIGN_LEFT) /*!< ADC conversion data alignment: left aligned (aligment on data register MSB bit 15)*/
  412. /**
  413. * @}
  414. */
  415. /** @defgroup ADC_Scan_mode ADC sequencer scan mode
  416. * @{
  417. */
  418. #define ADC_SCAN_DISABLE (0x00000000UL) /*!< Scan mode disabled */
  419. #define ADC_SCAN_ENABLE (0x00000001UL) /*!< Scan mode enabled */
  420. /**
  421. * @}
  422. */
  423. /** @defgroup ADC_regular_external_trigger_source ADC group regular trigger source
  424. * @{
  425. */
  426. /* ADC group regular trigger sources for all ADC instances */
  427. #define ADC_SOFTWARE_START (LL_ADC_REG_TRIG_SOFTWARE) /*!< ADC group regular conversion trigger internal: SW start. */
  428. #define ADC_EXTERNALTRIG_T1_TRGO (LL_ADC_REG_TRIG_EXT_TIM1_TRGO) /*!< ADC group regular conversion trigger from external peripheral: TIM1 TRGO. Trigger edge set to rising edge (default setting). */
  429. #define ADC_EXTERNALTRIG_T1_TRGO2 (LL_ADC_REG_TRIG_EXT_TIM1_TRGO2) /*!< ADC group regular conversion trigger from external peripheral: TIM1 TRGO2. Trigger edge set to rising edge (default setting). */
  430. #define ADC_EXTERNALTRIG_T1_CC1 (LL_ADC_REG_TRIG_EXT_TIM1_CH1) /*!< ADC group regular conversion trigger from external peripheral: TIM1 channel 1 event (capture compare: input capture or output capture). Trigger edge set to rising edge (default setting). */
  431. #define ADC_EXTERNALTRIG_T1_CC2 (LL_ADC_REG_TRIG_EXT_TIM1_CH2) /*!< ADC group regular conversion trigger from external peripheral: TIM1 channel 2 event (capture compare: input capture or output capture). Trigger edge set to rising edge (default setting). */
  432. #define ADC_EXTERNALTRIG_T1_CC3 (LL_ADC_REG_TRIG_EXT_TIM1_CH3) /*!< ADC group regular conversion trigger from external peripheral: TIM1 channel 3 event (capture compare: input capture or output capture). Trigger edge set to rising edge (default setting). */
  433. #define ADC_EXTERNALTRIG_T2_TRGO (LL_ADC_REG_TRIG_EXT_TIM2_TRGO) /*!< ADC group regular conversion trigger from external peripheral: TIM2 TRGO. Trigger edge set to rising edge (default setting). */
  434. #define ADC_EXTERNALTRIG_T2_CC2 (LL_ADC_REG_TRIG_EXT_TIM2_CH2) /*!< ADC group regular conversion trigger from external peripheral: TIM2 channel 2 event (capture compare: input capture or output capture). Trigger edge set to rising edge (default setting). */
  435. #define ADC_EXTERNALTRIG_EXT_IT11 (LL_ADC_REG_TRIG_EXT_EXTI_LINE11) /*!< ADC group regular conversion trigger from external peripheral: external interrupt line 11. Trigger edge set to rising edge (default setting). */
  436. /**
  437. * @}
  438. */
  439. /** @defgroup ADC_regular_external_trigger_edge ADC group regular trigger edge (when external trigger is selected)
  440. * @{
  441. */
  442. #define ADC_EXTERNALTRIGCONVEDGE_NONE (0x00000000UL) /*!< Regular conversions hardware trigger detection disabled */
  443. #define ADC_EXTERNALTRIGCONVEDGE_RISING (LL_ADC_REG_TRIG_EXT_RISING) /*!< ADC group regular conversion trigger polarity set to rising edge */
  444. #define ADC_EXTERNALTRIGCONVEDGE_FALLING (LL_ADC_REG_TRIG_EXT_FALLING) /*!< ADC group regular conversion trigger polarity set to falling edge */
  445. #define ADC_EXTERNALTRIGCONVEDGE_RISINGFALLING (LL_ADC_REG_TRIG_EXT_RISINGFALLING) /*!< ADC group regular conversion trigger polarity set to both rising and falling edges */
  446. /**
  447. * @}
  448. */
  449. /** @defgroup ADC_EOCSelection ADC sequencer end of unitary conversion or sequence conversions
  450. * @{
  451. */
  452. #define ADC_EOC_SINGLE_CONV (ADC_ISR_EOC) /*!< End of unitary conversion flag */
  453. #define ADC_EOC_SEQ_CONV (ADC_ISR_EOS) /*!< End of sequence conversions flag */
  454. /**
  455. * @}
  456. */
  457. /** @defgroup ADC_HAL_EC_REG_OVR_DATA_BEHAVIOR ADC group regular - Overrun behavior on conversion data
  458. * @{
  459. */
  460. #define ADC_OVR_DATA_PRESERVED (LL_ADC_REG_OVR_DATA_PRESERVED) /*!< ADC group regular behavior in case of overrun: data preserved */
  461. #define ADC_OVR_DATA_OVERWRITTEN (LL_ADC_REG_OVR_DATA_OVERWRITTEN) /*!< ADC group regular behavior in case of overrun: data overwritten */
  462. /**
  463. * @}
  464. */
  465. /** @defgroup ADC_HAL_EC_REG_SEQ_RANKS ADC group regular - Sequencer ranks
  466. * @{
  467. */
  468. #define ADC_REGULAR_RANK_1 (LL_ADC_REG_RANK_1) /*!< ADC group regular sequencer rank 1 */
  469. #define ADC_REGULAR_RANK_2 (LL_ADC_REG_RANK_2) /*!< ADC group regular sequencer rank 2 */
  470. #define ADC_REGULAR_RANK_3 (LL_ADC_REG_RANK_3) /*!< ADC group regular sequencer rank 3 */
  471. #define ADC_REGULAR_RANK_4 (LL_ADC_REG_RANK_4) /*!< ADC group regular sequencer rank 4 */
  472. #define ADC_REGULAR_RANK_5 (LL_ADC_REG_RANK_5) /*!< ADC group regular sequencer rank 5 */
  473. #define ADC_REGULAR_RANK_6 (LL_ADC_REG_RANK_6) /*!< ADC group regular sequencer rank 6 */
  474. #define ADC_REGULAR_RANK_7 (LL_ADC_REG_RANK_7) /*!< ADC group regular sequencer rank 7 */
  475. #define ADC_REGULAR_RANK_8 (LL_ADC_REG_RANK_8) /*!< ADC group regular sequencer rank 8 */
  476. #define ADC_REGULAR_RANK_9 (LL_ADC_REG_RANK_9) /*!< ADC group regular sequencer rank 9 */
  477. #define ADC_REGULAR_RANK_10 (LL_ADC_REG_RANK_10) /*!< ADC group regular sequencer rank 10 */
  478. #define ADC_REGULAR_RANK_11 (LL_ADC_REG_RANK_11) /*!< ADC group regular sequencer rank 11 */
  479. #define ADC_REGULAR_RANK_12 (LL_ADC_REG_RANK_12) /*!< ADC group regular sequencer rank 12 */
  480. #define ADC_REGULAR_RANK_13 (LL_ADC_REG_RANK_13) /*!< ADC group regular sequencer rank 13 */
  481. #define ADC_REGULAR_RANK_14 (LL_ADC_REG_RANK_14) /*!< ADC group regular sequencer rank 14 */
  482. #define ADC_REGULAR_RANK_15 (LL_ADC_REG_RANK_15) /*!< ADC group regular sequencer rank 15 */
  483. #define ADC_REGULAR_RANK_16 (LL_ADC_REG_RANK_16) /*!< ADC group regular sequencer rank 16 */
  484. /**
  485. * @}
  486. */
  487. /** @defgroup ADC_HAL_EC_CHANNEL_SAMPLINGTIME Channel - Sampling time
  488. * @{
  489. */
  490. #define ADC_SAMPLETIME_2CYCLES_5 (LL_ADC_SAMPLINGTIME_2CYCLES_5) /*!< Sampling time 2.5 ADC clock cycles */
  491. #define ADC_SAMPLETIME_6CYCLES_5 (LL_ADC_SAMPLINGTIME_6CYCLES_5) /*!< Sampling time 6.5 ADC clock cycles */
  492. #define ADC_SAMPLETIME_12CYCLES_5 (LL_ADC_SAMPLINGTIME_12CYCLES_5) /*!< Sampling time 12.5 ADC clock cycles */
  493. #define ADC_SAMPLETIME_24CYCLES_5 (LL_ADC_SAMPLINGTIME_24CYCLES_5) /*!< Sampling time 24.5 ADC clock cycles */
  494. #define ADC_SAMPLETIME_47CYCLES_5 (LL_ADC_SAMPLINGTIME_47CYCLES_5) /*!< Sampling time 47.5 ADC clock cycles */
  495. #define ADC_SAMPLETIME_92CYCLES_5 (LL_ADC_SAMPLINGTIME_92CYCLES_5) /*!< Sampling time 92.5 ADC clock cycles */
  496. #define ADC_SAMPLETIME_247CYCLES_5 (LL_ADC_SAMPLINGTIME_247CYCLES_5) /*!< Sampling time 247.5 ADC clock cycles */
  497. #define ADC_SAMPLETIME_640CYCLES_5 (LL_ADC_SAMPLINGTIME_640CYCLES_5) /*!< Sampling time 640.5 ADC clock cycles */
  498. /**
  499. * @}
  500. */
  501. /** @defgroup ADC_HAL_EC_CHANNEL ADC instance - Channel number
  502. * @{
  503. */
  504. /* Note: VrefInt, TempSensor and Vbat internal channels are not available on */
  505. /* all ADC instances (refer to Reference Manual). */
  506. #define ADC_CHANNEL_0 (LL_ADC_CHANNEL_0) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN0 */
  507. #define ADC_CHANNEL_1 (LL_ADC_CHANNEL_1) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN1 */
  508. #define ADC_CHANNEL_2 (LL_ADC_CHANNEL_2) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN2 */
  509. #define ADC_CHANNEL_3 (LL_ADC_CHANNEL_3) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN3 */
  510. #define ADC_CHANNEL_4 (LL_ADC_CHANNEL_4) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN4 */
  511. #define ADC_CHANNEL_5 (LL_ADC_CHANNEL_5) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN5 */
  512. #define ADC_CHANNEL_6 (LL_ADC_CHANNEL_6) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN6 */
  513. #define ADC_CHANNEL_7 (LL_ADC_CHANNEL_7) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN7 */
  514. #define ADC_CHANNEL_8 (LL_ADC_CHANNEL_8) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN8 */
  515. #define ADC_CHANNEL_9 (LL_ADC_CHANNEL_9) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN9 */
  516. #define ADC_CHANNEL_10 (LL_ADC_CHANNEL_10) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN10 */
  517. #define ADC_CHANNEL_11 (LL_ADC_CHANNEL_11) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN11 */
  518. #define ADC_CHANNEL_12 (LL_ADC_CHANNEL_12) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN12 */
  519. #define ADC_CHANNEL_13 (LL_ADC_CHANNEL_13) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN13 */
  520. #define ADC_CHANNEL_14 (LL_ADC_CHANNEL_14) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN14 */
  521. #define ADC_CHANNEL_15 (LL_ADC_CHANNEL_15) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN15 */
  522. #define ADC_CHANNEL_16 (LL_ADC_CHANNEL_16) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN16 */
  523. #define ADC_CHANNEL_17 (LL_ADC_CHANNEL_17) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN17 */
  524. #define ADC_CHANNEL_18 (LL_ADC_CHANNEL_18) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN18 */
  525. #define ADC_CHANNEL_VREFINT (LL_ADC_CHANNEL_VREFINT) /*!< ADC internal channel connected to VrefInt: Internal voltage reference. */
  526. #define ADC_CHANNEL_TEMPSENSOR (LL_ADC_CHANNEL_TEMPSENSOR) /*!< ADC internal channel connected to Temperature sensor. */
  527. #define ADC_CHANNEL_VBAT (LL_ADC_CHANNEL_VBAT) /*!< ADC internal channel connected to Vbat/3: Vbat voltage through a divider ladder of factor 1/3 to have Vbat always below Vdda. */
  528. /**
  529. * @}
  530. */
  531. /** @defgroup ADC_HAL_EC_AWD_NUMBER Analog watchdog - Analog watchdog number
  532. * @{
  533. */
  534. #define ADC_ANALOGWATCHDOG_1 (LL_ADC_AWD1) /*!< ADC analog watchdog number 1 */
  535. #define ADC_ANALOGWATCHDOG_2 (LL_ADC_AWD2) /*!< ADC analog watchdog number 2 */
  536. #define ADC_ANALOGWATCHDOG_3 (LL_ADC_AWD3) /*!< ADC analog watchdog number 3 */
  537. /**
  538. * @}
  539. */
  540. /** @defgroup ADC_analog_watchdog_mode ADC Analog Watchdog Mode
  541. * @{
  542. */
  543. #define ADC_ANALOGWATCHDOG_NONE (0x00000000UL) /*!< No analog watchdog selected */
  544. #define ADC_ANALOGWATCHDOG_SINGLE_REG (ADC_CFGR_AWD1SGL | ADC_CFGR_AWD1EN) /*!< Analog watchdog applied to a regular group single channel */
  545. #define ADC_ANALOGWATCHDOG_SINGLE_INJEC (ADC_CFGR_AWD1SGL | ADC_CFGR_JAWD1EN) /*!< Analog watchdog applied to an injected group single channel */
  546. #define ADC_ANALOGWATCHDOG_SINGLE_REGINJEC (ADC_CFGR_AWD1SGL | ADC_CFGR_AWD1EN | ADC_CFGR_JAWD1EN) /*!< Analog watchdog applied to a regular and injected groups single channel */
  547. #define ADC_ANALOGWATCHDOG_ALL_REG (ADC_CFGR_AWD1EN) /*!< Analog watchdog applied to regular group all channels */
  548. #define ADC_ANALOGWATCHDOG_ALL_INJEC (ADC_CFGR_JAWD1EN) /*!< Analog watchdog applied to injected group all channels */
  549. #define ADC_ANALOGWATCHDOG_ALL_REGINJEC (ADC_CFGR_AWD1EN | ADC_CFGR_JAWD1EN) /*!< Analog watchdog applied to regular and injected groups all channels */
  550. /**
  551. * @}
  552. */
  553. /** @defgroup ADC_HAL_EC_OVS_RATIO Oversampling - Ratio
  554. * @{
  555. */
  556. #define ADC_OVERSAMPLING_RATIO_2 (LL_ADC_OVS_RATIO_2) /*!< ADC oversampling ratio of 2 (2 ADC conversions are performed, sum of these conversions data is computed to result as the ADC oversampling conversion data (before potential shift) */
  557. #define ADC_OVERSAMPLING_RATIO_4 (LL_ADC_OVS_RATIO_4) /*!< ADC oversampling ratio of 4 (4 ADC conversions are performed, sum of these conversions data is computed to result as the ADC oversampling conversion data (before potential shift) */
  558. #define ADC_OVERSAMPLING_RATIO_8 (LL_ADC_OVS_RATIO_8) /*!< ADC oversampling ratio of 8 (8 ADC conversions are performed, sum of these conversions data is computed to result as the ADC oversampling conversion data (before potential shift) */
  559. #define ADC_OVERSAMPLING_RATIO_16 (LL_ADC_OVS_RATIO_16) /*!< ADC oversampling ratio of 16 (16 ADC conversions are performed, sum of these conversions data is computed to result as the ADC oversampling conversion data (before potential shift) */
  560. #define ADC_OVERSAMPLING_RATIO_32 (LL_ADC_OVS_RATIO_32) /*!< ADC oversampling ratio of 32 (32 ADC conversions are performed, sum of these conversions data is computed to result as the ADC oversampling conversion data (before potential shift) */
  561. #define ADC_OVERSAMPLING_RATIO_64 (LL_ADC_OVS_RATIO_64) /*!< ADC oversampling ratio of 64 (64 ADC conversions are performed, sum of these conversions data is computed to result as the ADC oversampling conversion data (before potential shift) */
  562. #define ADC_OVERSAMPLING_RATIO_128 (LL_ADC_OVS_RATIO_128) /*!< ADC oversampling ratio of 128 (128 ADC conversions are performed, sum of these conversions data is computed to result as the ADC oversampling conversion data (before potential shift) */
  563. #define ADC_OVERSAMPLING_RATIO_256 (LL_ADC_OVS_RATIO_256) /*!< ADC oversampling ratio of 256 (256 ADC conversions are performed, sum of these conversions data is computed to result as the ADC oversampling conversion data (before potential shift) */
  564. /**
  565. * @}
  566. */
  567. /** @defgroup ADC_HAL_EC_OVS_SHIFT Oversampling - Data shift
  568. * @{
  569. */
  570. #define ADC_RIGHTBITSHIFT_NONE (LL_ADC_OVS_SHIFT_NONE) /*!< ADC oversampling no shift (sum of the ADC conversions data is not divided to result as the ADC oversampling conversion data) */
  571. #define ADC_RIGHTBITSHIFT_1 (LL_ADC_OVS_SHIFT_RIGHT_1) /*!< ADC oversampling shift of 1 (sum of the ADC conversions data is divided by 2 to result as the ADC oversampling conversion data) */
  572. #define ADC_RIGHTBITSHIFT_2 (LL_ADC_OVS_SHIFT_RIGHT_2) /*!< ADC oversampling shift of 2 (sum of the ADC conversions data is divided by 4 to result as the ADC oversampling conversion data) */
  573. #define ADC_RIGHTBITSHIFT_3 (LL_ADC_OVS_SHIFT_RIGHT_3) /*!< ADC oversampling shift of 3 (sum of the ADC conversions data is divided by 8 to result as the ADC oversampling conversion data) */
  574. #define ADC_RIGHTBITSHIFT_4 (LL_ADC_OVS_SHIFT_RIGHT_4) /*!< ADC oversampling shift of 4 (sum of the ADC conversions data is divided by 16 to result as the ADC oversampling conversion data) */
  575. #define ADC_RIGHTBITSHIFT_5 (LL_ADC_OVS_SHIFT_RIGHT_5) /*!< ADC oversampling shift of 5 (sum of the ADC conversions data is divided by 32 to result as the ADC oversampling conversion data) */
  576. #define ADC_RIGHTBITSHIFT_6 (LL_ADC_OVS_SHIFT_RIGHT_6) /*!< ADC oversampling shift of 6 (sum of the ADC conversions data is divided by 64 to result as the ADC oversampling conversion data) */
  577. #define ADC_RIGHTBITSHIFT_7 (LL_ADC_OVS_SHIFT_RIGHT_7) /*!< ADC oversampling shift of 7 (sum of the ADC conversions data is divided by 128 to result as the ADC oversampling conversion data) */
  578. #define ADC_RIGHTBITSHIFT_8 (LL_ADC_OVS_SHIFT_RIGHT_8) /*!< ADC oversampling shift of 8 (sum of the ADC conversions data is divided by 256 to result as the ADC oversampling conversion data) */
  579. /**
  580. * @}
  581. */
  582. /** @defgroup ADC_HAL_EC_OVS_DISCONT_MODE Oversampling - Discontinuous mode
  583. * @{
  584. */
  585. #define ADC_TRIGGEREDMODE_SINGLE_TRIGGER (LL_ADC_OVS_REG_CONT) /*!< ADC oversampling discontinuous mode: continuous mode (all conversions of oversampling ratio are done from 1 trigger) */
  586. #define ADC_TRIGGEREDMODE_MULTI_TRIGGER (LL_ADC_OVS_REG_DISCONT) /*!< ADC oversampling discontinuous mode: discontinuous mode (each conversion of oversampling ratio needs a trigger) */
  587. /**
  588. * @}
  589. */
  590. /** @defgroup ADC_HAL_EC_OVS_SCOPE_REG Oversampling - Oversampling scope for ADC group regular
  591. * @{
  592. */
  593. #define ADC_REGOVERSAMPLING_CONTINUED_MODE (LL_ADC_OVS_GRP_REGULAR_CONTINUED) /*!< Oversampling buffer maintained during injection sequence */
  594. #define ADC_REGOVERSAMPLING_RESUMED_MODE (LL_ADC_OVS_GRP_REGULAR_RESUMED) /*!< Oversampling buffer zeroed during injection sequence */
  595. /**
  596. * @}
  597. */
  598. /** @defgroup ADC_Event_type ADC Event type
  599. * @{
  600. */
  601. #define ADC_EOSMP_EVENT (ADC_FLAG_EOSMP) /*!< ADC End of Sampling event */
  602. #define ADC_AWD1_EVENT (ADC_FLAG_AWD1) /*!< ADC Analog watchdog 1 event (main analog watchdog, present on all STM32 series) */
  603. #define ADC_AWD2_EVENT (ADC_FLAG_AWD2) /*!< ADC Analog watchdog 2 event (additional analog watchdog, not present on all STM32 series) */
  604. #define ADC_AWD3_EVENT (ADC_FLAG_AWD3) /*!< ADC Analog watchdog 3 event (additional analog watchdog, not present on all STM32 series) */
  605. #define ADC_OVR_EVENT (ADC_FLAG_OVR) /*!< ADC overrun event */
  606. #define ADC_JQOVF_EVENT (ADC_FLAG_JQOVF) /*!< ADC Injected Context Queue Overflow event */
  607. /**
  608. * @}
  609. */
  610. #define ADC_AWD_EVENT ADC_AWD1_EVENT /*!< ADC Analog watchdog 1 event: Naming for compatibility with other STM32 devices having only one analog watchdog */
  611. /** @defgroup ADC_interrupts_definition ADC interrupts definition
  612. * @{
  613. */
  614. #define ADC_IT_RDY ADC_IER_ADRDYIE /*!< ADC Ready interrupt source */
  615. #define ADC_IT_EOSMP ADC_IER_EOSMPIE /*!< ADC End of sampling interrupt source */
  616. #define ADC_IT_EOC ADC_IER_EOCIE /*!< ADC End of regular conversion interrupt source */
  617. #define ADC_IT_EOS ADC_IER_EOSIE /*!< ADC End of regular sequence of conversions interrupt source */
  618. #define ADC_IT_OVR ADC_IER_OVRIE /*!< ADC overrun interrupt source */
  619. #define ADC_IT_JEOC ADC_IER_JEOCIE /*!< ADC End of injected conversion interrupt source */
  620. #define ADC_IT_JEOS ADC_IER_JEOSIE /*!< ADC End of injected sequence of conversions interrupt source */
  621. #define ADC_IT_AWD1 ADC_IER_AWD1IE /*!< ADC Analog watchdog 1 interrupt source (main analog watchdog) */
  622. #define ADC_IT_AWD2 ADC_IER_AWD2IE /*!< ADC Analog watchdog 2 interrupt source (additional analog watchdog) */
  623. #define ADC_IT_AWD3 ADC_IER_AWD3IE /*!< ADC Analog watchdog 3 interrupt source (additional analog watchdog) */
  624. #define ADC_IT_JQOVF ADC_IER_JQOVFIE /*!< ADC Injected Context Queue Overflow interrupt source */
  625. #define ADC_IT_AWD ADC_IT_AWD1 /*!< ADC Analog watchdog 1 interrupt source: naming for compatibility with other STM32 devices having only one analog watchdog */
  626. /**
  627. * @}
  628. */
  629. /** @defgroup ADC_flags_definition ADC flags definition
  630. * @{
  631. */
  632. #define ADC_FLAG_RDY ADC_ISR_ADRDY /*!< ADC Ready flag */
  633. #define ADC_FLAG_EOSMP ADC_ISR_EOSMP /*!< ADC End of Sampling flag */
  634. #define ADC_FLAG_EOC ADC_ISR_EOC /*!< ADC End of Regular Conversion flag */
  635. #define ADC_FLAG_EOS ADC_ISR_EOS /*!< ADC End of Regular sequence of Conversions flag */
  636. #define ADC_FLAG_OVR ADC_ISR_OVR /*!< ADC overrun flag */
  637. #define ADC_FLAG_JEOC ADC_ISR_JEOC /*!< ADC End of Injected Conversion flag */
  638. #define ADC_FLAG_JEOS ADC_ISR_JEOS /*!< ADC End of Injected sequence of Conversions flag */
  639. #define ADC_FLAG_AWD1 ADC_ISR_AWD1 /*!< ADC Analog watchdog 1 flag (main analog watchdog) */
  640. #define ADC_FLAG_AWD2 ADC_ISR_AWD2 /*!< ADC Analog watchdog 2 flag (additional analog watchdog) */
  641. #define ADC_FLAG_AWD3 ADC_ISR_AWD3 /*!< ADC Analog watchdog 3 flag (additional analog watchdog) */
  642. #define ADC_FLAG_JQOVF ADC_ISR_JQOVF /*!< ADC Injected Context Queue Overflow flag */
  643. /**
  644. * @}
  645. */
  646. /**
  647. * @}
  648. */
  649. /* Private macro -------------------------------------------------------------*/
  650. /** @defgroup ADC_Private_Macros ADC Private Macros
  651. * @{
  652. */
  653. /* Macro reserved for internal HAL driver usage, not intended to be used in */
  654. /* code of final user. */
  655. /**
  656. * @brief Return resolution bits in CFGR register RES[1:0] field.
  657. * @param __HANDLE__ ADC handle
  658. * @retval Value of bitfield RES in CFGR register.
  659. */
  660. #define ADC_GET_RESOLUTION(__HANDLE__) \
  661. (LL_ADC_GetResolution((__HANDLE__)->Instance))
  662. /**
  663. * @brief Clear ADC error code (set it to no error code "HAL_ADC_ERROR_NONE").
  664. * @param __HANDLE__ ADC handle
  665. * @retval None
  666. */
  667. #define ADC_CLEAR_ERRORCODE(__HANDLE__) ((__HANDLE__)->ErrorCode = HAL_ADC_ERROR_NONE)
  668. /**
  669. * @brief Simultaneously clear and set specific bits of the handle State.
  670. * @note ADC_STATE_CLR_SET() macro is merely aliased to generic macro MODIFY_REG(),
  671. * the first parameter is the ADC handle State, the second parameter is the
  672. * bit field to clear, the third and last parameter is the bit field to set.
  673. * @retval None
  674. */
  675. #define ADC_STATE_CLR_SET MODIFY_REG
  676. /**
  677. * @brief Verify that a given value is aligned with the ADC resolution range.
  678. * @param __RESOLUTION__ ADC resolution (12, 10, 8 or 6 bits).
  679. * @param __ADC_VALUE__ value checked against the resolution.
  680. * @retval SET (__ADC_VALUE__ in line with __RESOLUTION__) or RESET (__ADC_VALUE__ not in line with __RESOLUTION__)
  681. */
  682. #define IS_ADC_RANGE(__RESOLUTION__, __ADC_VALUE__) \
  683. ((__ADC_VALUE__) <= __LL_ADC_DIGITAL_SCALE(__RESOLUTION__))
  684. /**
  685. * @brief Verify the length of the scheduled regular conversions group.
  686. * @param __LENGTH__ number of programmed conversions.
  687. * @retval SET (__LENGTH__ is within the maximum number of possible programmable regular conversions) or RESET (__LENGTH__ is null or too large)
  688. */
  689. #define IS_ADC_REGULAR_NB_CONV(__LENGTH__) (((__LENGTH__) >= (1UL)) && ((__LENGTH__) <= (16UL)))
  690. /**
  691. * @brief Verify the number of scheduled regular conversions in discontinuous mode.
  692. * @param NUMBER number of scheduled regular conversions in discontinuous mode.
  693. * @retval SET (NUMBER is within the maximum number of regular conversions in discontinuous mode) or RESET (NUMBER is null or too large)
  694. */
  695. #define IS_ADC_REGULAR_DISCONT_NUMBER(NUMBER) (((NUMBER) >= (1UL)) && ((NUMBER) <= (8UL)))
  696. /**
  697. * @brief Verify the ADC clock setting.
  698. * @param __ADC_CLOCK__ programmed ADC clock.
  699. * @retval SET (__ADC_CLOCK__ is a valid value) or RESET (__ADC_CLOCK__ is invalid)
  700. */
  701. #define IS_ADC_CLOCKPRESCALER(__ADC_CLOCK__) (((__ADC_CLOCK__) == ADC_CLOCK_SYNC_PCLK_DIV1) || \
  702. ((__ADC_CLOCK__) == ADC_CLOCK_SYNC_PCLK_DIV2) || \
  703. ((__ADC_CLOCK__) == ADC_CLOCK_SYNC_PCLK_DIV4) || \
  704. ((__ADC_CLOCK__) == ADC_CLOCK_ASYNC_DIV1) || \
  705. ((__ADC_CLOCK__) == ADC_CLOCK_ASYNC_DIV2) || \
  706. ((__ADC_CLOCK__) == ADC_CLOCK_ASYNC_DIV4) || \
  707. ((__ADC_CLOCK__) == ADC_CLOCK_ASYNC_DIV6) || \
  708. ((__ADC_CLOCK__) == ADC_CLOCK_ASYNC_DIV8) || \
  709. ((__ADC_CLOCK__) == ADC_CLOCK_ASYNC_DIV10) || \
  710. ((__ADC_CLOCK__) == ADC_CLOCK_ASYNC_DIV12) || \
  711. ((__ADC_CLOCK__) == ADC_CLOCK_ASYNC_DIV16) || \
  712. ((__ADC_CLOCK__) == ADC_CLOCK_ASYNC_DIV32) || \
  713. ((__ADC_CLOCK__) == ADC_CLOCK_ASYNC_DIV64) || \
  714. ((__ADC_CLOCK__) == ADC_CLOCK_ASYNC_DIV128) || \
  715. ((__ADC_CLOCK__) == ADC_CLOCK_ASYNC_DIV256) )
  716. /**
  717. * @brief Verify the ADC resolution setting.
  718. * @param __RESOLUTION__ programmed ADC resolution.
  719. * @retval SET (__RESOLUTION__ is a valid value) or RESET (__RESOLUTION__ is invalid)
  720. */
  721. #define IS_ADC_RESOLUTION(__RESOLUTION__) (((__RESOLUTION__) == ADC_RESOLUTION_12B) || \
  722. ((__RESOLUTION__) == ADC_RESOLUTION_10B) || \
  723. ((__RESOLUTION__) == ADC_RESOLUTION_8B) || \
  724. ((__RESOLUTION__) == ADC_RESOLUTION_6B) )
  725. /**
  726. * @brief Verify the ADC resolution setting when limited to 6 or 8 bits.
  727. * @param __RESOLUTION__ programmed ADC resolution when limited to 6 or 8 bits.
  728. * @retval SET (__RESOLUTION__ is a valid value) or RESET (__RESOLUTION__ is invalid)
  729. */
  730. #define IS_ADC_RESOLUTION_8_6_BITS(__RESOLUTION__) (((__RESOLUTION__) == ADC_RESOLUTION_8B) || \
  731. ((__RESOLUTION__) == ADC_RESOLUTION_6B) )
  732. /**
  733. * @brief Verify the ADC converted data alignment.
  734. * @param __ALIGN__ programmed ADC converted data alignment.
  735. * @retval SET (__ALIGN__ is a valid value) or RESET (__ALIGN__ is invalid)
  736. */
  737. #define IS_ADC_DATA_ALIGN(__ALIGN__) (((__ALIGN__) == ADC_DATAALIGN_RIGHT) || \
  738. ((__ALIGN__) == ADC_DATAALIGN_LEFT) )
  739. /**
  740. * @brief Verify the ADC scan mode.
  741. * @param __SCAN_MODE__ programmed ADC scan mode.
  742. * @retval SET (__SCAN_MODE__ is valid) or RESET (__SCAN_MODE__ is invalid)
  743. */
  744. #define IS_ADC_SCAN_MODE(__SCAN_MODE__) (((__SCAN_MODE__) == ADC_SCAN_DISABLE) || \
  745. ((__SCAN_MODE__) == ADC_SCAN_ENABLE) )
  746. /**
  747. * @brief Verify the ADC edge trigger setting for regular group.
  748. * @param __EDGE__ programmed ADC edge trigger setting.
  749. * @retval SET (__EDGE__ is a valid value) or RESET (__EDGE__ is invalid)
  750. */
  751. #define IS_ADC_EXTTRIG_EDGE(__EDGE__) (((__EDGE__) == ADC_EXTERNALTRIGCONVEDGE_NONE) || \
  752. ((__EDGE__) == ADC_EXTERNALTRIGCONVEDGE_RISING) || \
  753. ((__EDGE__) == ADC_EXTERNALTRIGCONVEDGE_FALLING) || \
  754. ((__EDGE__) == ADC_EXTERNALTRIGCONVEDGE_RISINGFALLING) )
  755. /**
  756. * @brief Verify the ADC regular conversions external trigger.
  757. * @param __HANDLE__ ADC handle
  758. * @param __REGTRIG__ programmed ADC regular conversions external trigger.
  759. * @retval SET (__REGTRIG__ is a valid value) or RESET (__REGTRIG__ is invalid)
  760. */
  761. #define IS_ADC_EXTTRIG(__HANDLE__, __REGTRIG__) (((__REGTRIG__) == ADC_EXTERNALTRIG_T1_CC1) || \
  762. ((__REGTRIG__) == ADC_EXTERNALTRIG_T1_CC2) || \
  763. ((__REGTRIG__) == ADC_EXTERNALTRIG_T1_CC3) || \
  764. ((__REGTRIG__) == ADC_EXTERNALTRIG_T2_CC2) || \
  765. ((__REGTRIG__) == ADC_EXTERNALTRIG_EXT_IT11) || \
  766. ((__REGTRIG__) == ADC_EXTERNALTRIG_T1_TRGO) || \
  767. ((__REGTRIG__) == ADC_EXTERNALTRIG_T1_TRGO2) || \
  768. ((__REGTRIG__) == ADC_EXTERNALTRIG_T2_TRGO) || \
  769. ((__REGTRIG__) == ADC_SOFTWARE_START) )
  770. /**
  771. * @brief Verify the ADC regular conversions check for converted data availability.
  772. * @param __EOC_SELECTION__ converted data availability check.
  773. * @retval SET (__EOC_SELECTION__ is a valid value) or RESET (__EOC_SELECTION__ is invalid)
  774. */
  775. #define IS_ADC_EOC_SELECTION(__EOC_SELECTION__) (((__EOC_SELECTION__) == ADC_EOC_SINGLE_CONV) || \
  776. ((__EOC_SELECTION__) == ADC_EOC_SEQ_CONV) )
  777. /**
  778. * @brief Verify the ADC regular conversions overrun handling.
  779. * @param __OVR__ ADC regular conversions overrun handling.
  780. * @retval SET (__OVR__ is a valid value) or RESET (__OVR__ is invalid)
  781. */
  782. #define IS_ADC_OVERRUN(__OVR__) (((__OVR__) == ADC_OVR_DATA_PRESERVED) || \
  783. ((__OVR__) == ADC_OVR_DATA_OVERWRITTEN) )
  784. /**
  785. * @brief Verify the ADC conversions sampling time.
  786. * @param __TIME__ ADC conversions sampling time.
  787. * @retval SET (__TIME__ is a valid value) or RESET (__TIME__ is invalid)
  788. */
  789. #define IS_ADC_SAMPLE_TIME(__TIME__) (((__TIME__) == ADC_SAMPLETIME_2CYCLES_5) || \
  790. ((__TIME__) == ADC_SAMPLETIME_6CYCLES_5) || \
  791. ((__TIME__) == ADC_SAMPLETIME_12CYCLES_5) || \
  792. ((__TIME__) == ADC_SAMPLETIME_24CYCLES_5) || \
  793. ((__TIME__) == ADC_SAMPLETIME_47CYCLES_5) || \
  794. ((__TIME__) == ADC_SAMPLETIME_92CYCLES_5) || \
  795. ((__TIME__) == ADC_SAMPLETIME_247CYCLES_5) || \
  796. ((__TIME__) == ADC_SAMPLETIME_640CYCLES_5) )
  797. /**
  798. * @brief Verify the ADC regular channel setting.
  799. * @param __CHANNEL__ programmed ADC regular channel.
  800. * @retval SET (__CHANNEL__ is valid) or RESET (__CHANNEL__ is invalid)
  801. */
  802. #define IS_ADC_REGULAR_RANK(__CHANNEL__) (((__CHANNEL__) == ADC_REGULAR_RANK_1 ) || \
  803. ((__CHANNEL__) == ADC_REGULAR_RANK_2 ) || \
  804. ((__CHANNEL__) == ADC_REGULAR_RANK_3 ) || \
  805. ((__CHANNEL__) == ADC_REGULAR_RANK_4 ) || \
  806. ((__CHANNEL__) == ADC_REGULAR_RANK_5 ) || \
  807. ((__CHANNEL__) == ADC_REGULAR_RANK_6 ) || \
  808. ((__CHANNEL__) == ADC_REGULAR_RANK_7 ) || \
  809. ((__CHANNEL__) == ADC_REGULAR_RANK_8 ) || \
  810. ((__CHANNEL__) == ADC_REGULAR_RANK_9 ) || \
  811. ((__CHANNEL__) == ADC_REGULAR_RANK_10) || \
  812. ((__CHANNEL__) == ADC_REGULAR_RANK_11) || \
  813. ((__CHANNEL__) == ADC_REGULAR_RANK_12) || \
  814. ((__CHANNEL__) == ADC_REGULAR_RANK_13) || \
  815. ((__CHANNEL__) == ADC_REGULAR_RANK_14) || \
  816. ((__CHANNEL__) == ADC_REGULAR_RANK_15) || \
  817. ((__CHANNEL__) == ADC_REGULAR_RANK_16) )
  818. /**
  819. * @}
  820. */
  821. /* Private constants ---------------------------------------------------------*/
  822. /** @defgroup ADC_Private_Constants ADC Private Constants
  823. * @{
  824. */
  825. /* Fixed timeout values for ADC conversion (including sampling time) */
  826. /* Maximum sampling time is 640.5 ADC clock cycle (SMPx[2:0] = 0b111 */
  827. /* Maximum conversion time is 12.5 + Maximum sampling time */
  828. /* or 12.5 + 640.5 = 653 ADC clock cycles */
  829. /* Minimum ADC Clock frequency is 0.14 MHz */
  830. /* Maximum conversion time is */
  831. /* 653 / 0.14 MHz = 4.66 ms */
  832. #define ADC_STOP_CONVERSION_TIMEOUT ( 5UL) /*!< ADC stop time-out value */
  833. /* Delay for temperature sensor stabilization time. */
  834. /* Maximum delay is 120us (refer device datasheet, parameter tSTART). */
  835. /* Unit: us */
  836. #define ADC_TEMPSENSOR_DELAY_US (LL_ADC_DELAY_TEMPSENSOR_STAB_US)
  837. /**
  838. * @}
  839. */
  840. /* Exported macro ------------------------------------------------------------*/
  841. /** @defgroup ADC_Exported_Macros ADC Exported Macros
  842. * @{
  843. */
  844. /* Macro for internal HAL driver usage, and possibly can be used into code of */
  845. /* final user. */
  846. /** @defgroup ADC_HAL_EM_HANDLE_IT_FLAG HAL ADC macro to manage HAL ADC handle, IT and flags.
  847. * @{
  848. */
  849. /** @brief Reset ADC handle state.
  850. * @param __HANDLE__ ADC handle
  851. * @retval None
  852. */
  853. #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1)
  854. #define __HAL_ADC_RESET_HANDLE_STATE(__HANDLE__) \
  855. do{ \
  856. (__HANDLE__)->State = HAL_ADC_STATE_RESET; \
  857. (__HANDLE__)->MspInitCallback = NULL; \
  858. (__HANDLE__)->MspDeInitCallback = NULL; \
  859. } while(0)
  860. #else
  861. #define __HAL_ADC_RESET_HANDLE_STATE(__HANDLE__) \
  862. ((__HANDLE__)->State = HAL_ADC_STATE_RESET)
  863. #endif
  864. /**
  865. * @brief Enable ADC interrupt.
  866. * @param __HANDLE__ ADC handle
  867. * @param __INTERRUPT__ ADC Interrupt
  868. * This parameter can be one of the following values:
  869. * @arg @ref ADC_IT_RDY ADC Ready interrupt source
  870. * @arg @ref ADC_IT_EOSMP ADC End of Sampling interrupt source
  871. * @arg @ref ADC_IT_EOC ADC End of Regular Conversion interrupt source
  872. * @arg @ref ADC_IT_EOS ADC End of Regular sequence of Conversions interrupt source
  873. * @arg @ref ADC_IT_OVR ADC overrun interrupt source
  874. * @arg @ref ADC_IT_JEOC ADC End of Injected Conversion interrupt source
  875. * @arg @ref ADC_IT_JEOS ADC End of Injected sequence of Conversions interrupt source
  876. * @arg @ref ADC_IT_AWD1 ADC Analog watchdog 1 interrupt source (main analog watchdog)
  877. * @arg @ref ADC_IT_AWD2 ADC Analog watchdog 2 interrupt source (additional analog watchdog)
  878. * @arg @ref ADC_IT_AWD3 ADC Analog watchdog 3 interrupt source (additional analog watchdog)
  879. * @arg @ref ADC_IT_JQOVF ADC Injected Context Queue Overflow interrupt source.
  880. * @retval None
  881. */
  882. #define __HAL_ADC_ENABLE_IT(__HANDLE__, __INTERRUPT__) \
  883. (((__HANDLE__)->Instance->IER) |= (__INTERRUPT__))
  884. /**
  885. * @brief Disable ADC interrupt.
  886. * @param __HANDLE__ ADC handle
  887. * @param __INTERRUPT__ ADC Interrupt
  888. * This parameter can be one of the following values:
  889. * @arg @ref ADC_IT_RDY ADC Ready interrupt source
  890. * @arg @ref ADC_IT_EOSMP ADC End of Sampling interrupt source
  891. * @arg @ref ADC_IT_EOC ADC End of Regular Conversion interrupt source
  892. * @arg @ref ADC_IT_EOS ADC End of Regular sequence of Conversions interrupt source
  893. * @arg @ref ADC_IT_OVR ADC overrun interrupt source
  894. * @arg @ref ADC_IT_JEOC ADC End of Injected Conversion interrupt source
  895. * @arg @ref ADC_IT_JEOS ADC End of Injected sequence of Conversions interrupt source
  896. * @arg @ref ADC_IT_AWD1 ADC Analog watchdog 1 interrupt source (main analog watchdog)
  897. * @arg @ref ADC_IT_AWD2 ADC Analog watchdog 2 interrupt source (additional analog watchdog)
  898. * @arg @ref ADC_IT_AWD3 ADC Analog watchdog 3 interrupt source (additional analog watchdog)
  899. * @arg @ref ADC_IT_JQOVF ADC Injected Context Queue Overflow interrupt source.
  900. * @retval None
  901. */
  902. #define __HAL_ADC_DISABLE_IT(__HANDLE__, __INTERRUPT__) \
  903. (((__HANDLE__)->Instance->IER) &= ~(__INTERRUPT__))
  904. /** @brief Checks if the specified ADC interrupt source is enabled or disabled.
  905. * @param __HANDLE__ ADC handle
  906. * @param __INTERRUPT__ ADC interrupt source to check
  907. * This parameter can be one of the following values:
  908. * @arg @ref ADC_IT_RDY ADC Ready interrupt source
  909. * @arg @ref ADC_IT_EOSMP ADC End of Sampling interrupt source
  910. * @arg @ref ADC_IT_EOC ADC End of Regular Conversion interrupt source
  911. * @arg @ref ADC_IT_EOS ADC End of Regular sequence of Conversions interrupt source
  912. * @arg @ref ADC_IT_OVR ADC overrun interrupt source
  913. * @arg @ref ADC_IT_JEOC ADC End of Injected Conversion interrupt source
  914. * @arg @ref ADC_IT_JEOS ADC End of Injected sequence of Conversions interrupt source
  915. * @arg @ref ADC_IT_AWD1 ADC Analog watchdog 1 interrupt source (main analog watchdog)
  916. * @arg @ref ADC_IT_AWD2 ADC Analog watchdog 2 interrupt source (additional analog watchdog)
  917. * @arg @ref ADC_IT_AWD3 ADC Analog watchdog 3 interrupt source (additional analog watchdog)
  918. * @arg @ref ADC_IT_JQOVF ADC Injected Context Queue Overflow interrupt source.
  919. * @retval State of interruption (SET or RESET)
  920. */
  921. #define __HAL_ADC_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) \
  922. (((__HANDLE__)->Instance->IER & (__INTERRUPT__)) == (__INTERRUPT__))
  923. /**
  924. * @brief Check whether the specified ADC flag is set or not.
  925. * @param __HANDLE__ ADC handle
  926. * @param __FLAG__ ADC flag
  927. * This parameter can be one of the following values:
  928. * @arg @ref ADC_FLAG_RDY ADC Ready flag
  929. * @arg @ref ADC_FLAG_EOSMP ADC End of Sampling flag
  930. * @arg @ref ADC_FLAG_EOC ADC End of Regular Conversion flag
  931. * @arg @ref ADC_FLAG_EOS ADC End of Regular sequence of Conversions flag
  932. * @arg @ref ADC_FLAG_OVR ADC overrun flag
  933. * @arg @ref ADC_FLAG_JEOC ADC End of Injected Conversion flag
  934. * @arg @ref ADC_FLAG_JEOS ADC End of Injected sequence of Conversions flag
  935. * @arg @ref ADC_FLAG_AWD1 ADC Analog watchdog 1 flag (main analog watchdog)
  936. * @arg @ref ADC_FLAG_AWD2 ADC Analog watchdog 2 flag (additional analog watchdog)
  937. * @arg @ref ADC_FLAG_AWD3 ADC Analog watchdog 3 flag (additional analog watchdog)
  938. * @arg @ref ADC_FLAG_JQOVF ADC Injected Context Queue Overflow flag.
  939. * @retval State of flag (TRUE or FALSE).
  940. */
  941. #define __HAL_ADC_GET_FLAG(__HANDLE__, __FLAG__) \
  942. ((((__HANDLE__)->Instance->ISR) & (__FLAG__)) == (__FLAG__))
  943. /**
  944. * @brief Clear the specified ADC flag.
  945. * @param __HANDLE__ ADC handle
  946. * @param __FLAG__ ADC flag
  947. * This parameter can be one of the following values:
  948. * @arg @ref ADC_FLAG_RDY ADC Ready flag
  949. * @arg @ref ADC_FLAG_EOSMP ADC End of Sampling flag
  950. * @arg @ref ADC_FLAG_EOC ADC End of Regular Conversion flag
  951. * @arg @ref ADC_FLAG_EOS ADC End of Regular sequence of Conversions flag
  952. * @arg @ref ADC_FLAG_OVR ADC overrun flag
  953. * @arg @ref ADC_FLAG_JEOC ADC End of Injected Conversion flag
  954. * @arg @ref ADC_FLAG_JEOS ADC End of Injected sequence of Conversions flag
  955. * @arg @ref ADC_FLAG_AWD1 ADC Analog watchdog 1 flag (main analog watchdog)
  956. * @arg @ref ADC_FLAG_AWD2 ADC Analog watchdog 2 flag (additional analog watchdog)
  957. * @arg @ref ADC_FLAG_AWD3 ADC Analog watchdog 3 flag (additional analog watchdog)
  958. * @arg @ref ADC_FLAG_JQOVF ADC Injected Context Queue Overflow flag.
  959. * @retval None
  960. */
  961. /* Note: bit cleared bit by writing 1 (writing 0 has no effect on any bit of register ISR) */
  962. #define __HAL_ADC_CLEAR_FLAG(__HANDLE__, __FLAG__) \
  963. (((__HANDLE__)->Instance->ISR) = (__FLAG__))
  964. /**
  965. * @}
  966. */
  967. /** @defgroup ADC_HAL_EM_HELPER_MACRO HAL ADC helper macro
  968. * @{
  969. */
  970. /**
  971. * @brief Helper macro to get ADC channel number in decimal format
  972. * from literals ADC_CHANNEL_x.
  973. * @note Example:
  974. * __HAL_ADC_CHANNEL_TO_DECIMAL_NB(ADC_CHANNEL_4)
  975. * will return decimal number "4".
  976. * @note The input can be a value from functions where a channel
  977. * number is returned, either defined with number
  978. * or with bitfield (only one bit must be set).
  979. * @param __CHANNEL__ This parameter can be one of the following values:
  980. * @arg @ref ADC_CHANNEL_0
  981. * @arg @ref ADC_CHANNEL_1 (7)
  982. * @arg @ref ADC_CHANNEL_2 (7)
  983. * @arg @ref ADC_CHANNEL_3 (7)
  984. * @arg @ref ADC_CHANNEL_4 (7)
  985. * @arg @ref ADC_CHANNEL_5 (7)
  986. * @arg @ref ADC_CHANNEL_6
  987. * @arg @ref ADC_CHANNEL_7
  988. * @arg @ref ADC_CHANNEL_8
  989. * @arg @ref ADC_CHANNEL_9
  990. * @arg @ref ADC_CHANNEL_10
  991. * @arg @ref ADC_CHANNEL_11
  992. * @arg @ref ADC_CHANNEL_12
  993. * @arg @ref ADC_CHANNEL_13
  994. * @arg @ref ADC_CHANNEL_14
  995. * @arg @ref ADC_CHANNEL_15
  996. * @arg @ref ADC_CHANNEL_16
  997. * @arg @ref ADC_CHANNEL_17
  998. * @arg @ref ADC_CHANNEL_18
  999. * @arg @ref ADC_CHANNEL_VREFINT
  1000. * @arg @ref ADC_CHANNEL_TEMPSENSOR
  1001. * @arg @ref ADC_CHANNEL_VBAT
  1002. *
  1003. * (7) On STM32WB, fast channel (0.188 us for 12-bit resolution (ADC conversion rate up to 5.33 Ms/s)).
  1004. * Other channels are slow channels (0.238 us for 12-bit resolution (ADC conversion rate up to 4.21 Ms/s)).
  1005. * @retval Value between Min_Data=0 and Max_Data=18
  1006. */
  1007. #define __HAL_ADC_CHANNEL_TO_DECIMAL_NB(__CHANNEL__) \
  1008. __LL_ADC_CHANNEL_TO_DECIMAL_NB((__CHANNEL__))
  1009. /**
  1010. * @brief Helper macro to get ADC channel in literal format ADC_CHANNEL_x
  1011. * from number in decimal format.
  1012. * @note Example:
  1013. * __HAL_ADC_DECIMAL_NB_TO_CHANNEL(4)
  1014. * will return a data equivalent to "ADC_CHANNEL_4".
  1015. * @param __DECIMAL_NB__ Value between Min_Data=0 and Max_Data=18
  1016. * @retval Returned value can be one of the following values:
  1017. * @arg @ref ADC_CHANNEL_0
  1018. * @arg @ref ADC_CHANNEL_1 (7)
  1019. * @arg @ref ADC_CHANNEL_2 (7)
  1020. * @arg @ref ADC_CHANNEL_3 (7)
  1021. * @arg @ref ADC_CHANNEL_4 (7)
  1022. * @arg @ref ADC_CHANNEL_5 (7)
  1023. * @arg @ref ADC_CHANNEL_6
  1024. * @arg @ref ADC_CHANNEL_7
  1025. * @arg @ref ADC_CHANNEL_8
  1026. * @arg @ref ADC_CHANNEL_9
  1027. * @arg @ref ADC_CHANNEL_10
  1028. * @arg @ref ADC_CHANNEL_11
  1029. * @arg @ref ADC_CHANNEL_12
  1030. * @arg @ref ADC_CHANNEL_13
  1031. * @arg @ref ADC_CHANNEL_14
  1032. * @arg @ref ADC_CHANNEL_15
  1033. * @arg @ref ADC_CHANNEL_16
  1034. * @arg @ref ADC_CHANNEL_17
  1035. * @arg @ref ADC_CHANNEL_18
  1036. * @arg @ref ADC_CHANNEL_VREFINT (1)
  1037. * @arg @ref ADC_CHANNEL_TEMPSENSOR (4)
  1038. * @arg @ref ADC_CHANNEL_VBAT (4)
  1039. *
  1040. * (7) On STM32WB, fast channel (0.188 us for 12-bit resolution (ADC conversion rate up to 5.33 Ms/s)).
  1041. * Other channels are slow channels (0.238 us for 12-bit resolution (ADC conversion rate up to 4.21 Ms/s)).\n
  1042. * (4) For ADC channel read back from ADC register,
  1043. * comparison with internal channel parameter to be done
  1044. * using helper macro @ref __LL_ADC_CHANNEL_INTERNAL_TO_EXTERNAL().
  1045. */
  1046. #define __HAL_ADC_DECIMAL_NB_TO_CHANNEL(__DECIMAL_NB__) \
  1047. __LL_ADC_DECIMAL_NB_TO_CHANNEL((__DECIMAL_NB__))
  1048. /**
  1049. * @brief Helper macro to determine whether the selected channel
  1050. * corresponds to literal definitions of driver.
  1051. * @note The different literal definitions of ADC channels are:
  1052. * - ADC internal channel:
  1053. * ADC_CHANNEL_VREFINT, ADC_CHANNEL_TEMPSENSOR, ...
  1054. * - ADC external channel (channel connected to a GPIO pin):
  1055. * ADC_CHANNEL_1, ADC_CHANNEL_2, ...
  1056. * @note The channel parameter must be a value defined from literal
  1057. * definition of a ADC internal channel (ADC_CHANNEL_VREFINT,
  1058. * ADC_CHANNEL_TEMPSENSOR, ...),
  1059. * ADC external channel (ADC_CHANNEL_1, ADC_CHANNEL_2, ...),
  1060. * must not be a value from functions where a channel number is
  1061. * returned from ADC registers,
  1062. * because internal and external channels share the same channel
  1063. * number in ADC registers. The differentiation is made only with
  1064. * parameters definitions of driver.
  1065. * @param __CHANNEL__ This parameter can be one of the following values:
  1066. * @arg @ref ADC_CHANNEL_0
  1067. * @arg @ref ADC_CHANNEL_1 (7)
  1068. * @arg @ref ADC_CHANNEL_2 (7)
  1069. * @arg @ref ADC_CHANNEL_3 (7)
  1070. * @arg @ref ADC_CHANNEL_4 (7)
  1071. * @arg @ref ADC_CHANNEL_5 (7)
  1072. * @arg @ref ADC_CHANNEL_6
  1073. * @arg @ref ADC_CHANNEL_7
  1074. * @arg @ref ADC_CHANNEL_8
  1075. * @arg @ref ADC_CHANNEL_9
  1076. * @arg @ref ADC_CHANNEL_10
  1077. * @arg @ref ADC_CHANNEL_11
  1078. * @arg @ref ADC_CHANNEL_12
  1079. * @arg @ref ADC_CHANNEL_13
  1080. * @arg @ref ADC_CHANNEL_14
  1081. * @arg @ref ADC_CHANNEL_15
  1082. * @arg @ref ADC_CHANNEL_16
  1083. * @arg @ref ADC_CHANNEL_17
  1084. * @arg @ref ADC_CHANNEL_18
  1085. * @arg @ref ADC_CHANNEL_VREFINT
  1086. * @arg @ref ADC_CHANNEL_TEMPSENSOR
  1087. * @arg @ref ADC_CHANNEL_VBAT
  1088. *
  1089. * (7) On STM32WB, fast channel (0.188 us for 12-bit resolution (ADC conversion rate up to 5.33 Ms/s)).
  1090. * Other channels are slow channels (0.238 us for 12-bit resolution (ADC conversion rate up to 4.21 Ms/s)).
  1091. * @retval Value "0" if the channel corresponds to a parameter definition of a ADC external channel (channel connected to a GPIO pin).
  1092. * Value "1" if the channel corresponds to a parameter definition of a ADC internal channel.
  1093. */
  1094. #define __HAL_ADC_IS_CHANNEL_INTERNAL(__CHANNEL__) \
  1095. __LL_ADC_IS_CHANNEL_INTERNAL((__CHANNEL__))
  1096. /**
  1097. * @brief Helper macro to convert a channel defined from parameter
  1098. * definition of a ADC internal channel (ADC_CHANNEL_VREFINT,
  1099. * ADC_CHANNEL_TEMPSENSOR, ...),
  1100. * to its equivalent parameter definition of a ADC external channel
  1101. * (ADC_CHANNEL_1, ADC_CHANNEL_2, ...).
  1102. * @note The channel parameter can be, additionally to a value
  1103. * defined from parameter definition of a ADC internal channel
  1104. * (ADC_CHANNEL_VREFINT, ADC_CHANNEL_TEMPSENSOR, ...),
  1105. * a value defined from parameter definition of
  1106. * ADC external channel (ADC_CHANNEL_1, ADC_CHANNEL_2, ...)
  1107. * or a value from functions where a channel number is returned
  1108. * from ADC registers.
  1109. * @param __CHANNEL__ This parameter can be one of the following values:
  1110. * @arg @ref ADC_CHANNEL_0
  1111. * @arg @ref ADC_CHANNEL_1 (7)
  1112. * @arg @ref ADC_CHANNEL_2 (7)
  1113. * @arg @ref ADC_CHANNEL_3 (7)
  1114. * @arg @ref ADC_CHANNEL_4 (7)
  1115. * @arg @ref ADC_CHANNEL_5 (7)
  1116. * @arg @ref ADC_CHANNEL_6
  1117. * @arg @ref ADC_CHANNEL_7
  1118. * @arg @ref ADC_CHANNEL_8
  1119. * @arg @ref ADC_CHANNEL_9
  1120. * @arg @ref ADC_CHANNEL_10
  1121. * @arg @ref ADC_CHANNEL_11
  1122. * @arg @ref ADC_CHANNEL_12
  1123. * @arg @ref ADC_CHANNEL_13
  1124. * @arg @ref ADC_CHANNEL_14
  1125. * @arg @ref ADC_CHANNEL_15
  1126. * @arg @ref ADC_CHANNEL_16
  1127. * @arg @ref ADC_CHANNEL_17
  1128. * @arg @ref ADC_CHANNEL_18
  1129. * @arg @ref ADC_CHANNEL_VREFINT
  1130. * @arg @ref ADC_CHANNEL_TEMPSENSOR
  1131. * @arg @ref ADC_CHANNEL_VBAT
  1132. *
  1133. * (7) On STM32WB, fast channel (0.188 us for 12-bit resolution (ADC conversion rate up to 5.33 Ms/s)).
  1134. * Other channels are slow channels (0.238 us for 12-bit resolution (ADC conversion rate up to 4.21 Ms/s)).
  1135. * @retval Returned value can be one of the following values:
  1136. * @arg @ref ADC_CHANNEL_0
  1137. * @arg @ref ADC_CHANNEL_1
  1138. * @arg @ref ADC_CHANNEL_2
  1139. * @arg @ref ADC_CHANNEL_3
  1140. * @arg @ref ADC_CHANNEL_4
  1141. * @arg @ref ADC_CHANNEL_5
  1142. * @arg @ref ADC_CHANNEL_6
  1143. * @arg @ref ADC_CHANNEL_7
  1144. * @arg @ref ADC_CHANNEL_8
  1145. * @arg @ref ADC_CHANNEL_9
  1146. * @arg @ref ADC_CHANNEL_10
  1147. * @arg @ref ADC_CHANNEL_11
  1148. * @arg @ref ADC_CHANNEL_12
  1149. * @arg @ref ADC_CHANNEL_13
  1150. * @arg @ref ADC_CHANNEL_14
  1151. * @arg @ref ADC_CHANNEL_15
  1152. * @arg @ref ADC_CHANNEL_16
  1153. * @arg @ref ADC_CHANNEL_17
  1154. * @arg @ref ADC_CHANNEL_18
  1155. */
  1156. #define __HAL_ADC_CHANNEL_INTERNAL_TO_EXTERNAL(__CHANNEL__) \
  1157. __LL_ADC_CHANNEL_INTERNAL_TO_EXTERNAL((__CHANNEL__))
  1158. /**
  1159. * @brief Helper macro to determine whether the internal channel
  1160. * selected is available on the ADC instance selected.
  1161. * @note The channel parameter must be a value defined from parameter
  1162. * definition of a ADC internal channel (ADC_CHANNEL_VREFINT,
  1163. * ADC_CHANNEL_TEMPSENSOR, ...),
  1164. * must not be a value defined from parameter definition of
  1165. * ADC external channel (ADC_CHANNEL_1, ADC_CHANNEL_2, ...)
  1166. * or a value from functions where a channel number is
  1167. * returned from ADC registers,
  1168. * because internal and external channels share the same channel
  1169. * number in ADC registers. The differentiation is made only with
  1170. * parameters definitions of driver.
  1171. * @param __ADC_INSTANCE__ ADC instance
  1172. * @param __CHANNEL__ This parameter can be one of the following values:
  1173. * @arg @ref ADC_CHANNEL_VREFINT
  1174. * @arg @ref ADC_CHANNEL_TEMPSENSOR
  1175. * @arg @ref ADC_CHANNEL_VBAT
  1176. * @retval Value "0" if the internal channel selected is not available on the ADC instance selected.
  1177. * Value "1" if the internal channel selected is available on the ADC instance selected.
  1178. */
  1179. #define __HAL_ADC_IS_CHANNEL_INTERNAL_AVAILABLE(__ADC_INSTANCE__, __CHANNEL__) \
  1180. __LL_ADC_IS_CHANNEL_INTERNAL_AVAILABLE((__ADC_INSTANCE__), (__CHANNEL__))
  1181. /**
  1182. * @brief Helper macro to select the ADC common instance
  1183. * to which is belonging the selected ADC instance.
  1184. * @note ADC common register instance can be used for:
  1185. * - Set parameters common to several ADC instances
  1186. * - Multimode (for devices with several ADC instances)
  1187. * Refer to functions having argument "ADCxy_COMMON" as parameter.
  1188. * @param __ADCx__ ADC instance
  1189. * @retval ADC common register instance
  1190. */
  1191. #define __HAL_ADC_COMMON_INSTANCE(__ADCx__) \
  1192. __LL_ADC_COMMON_INSTANCE((__ADCx__))
  1193. /**
  1194. * @brief Helper macro to check if all ADC instances sharing the same
  1195. * ADC common instance are disabled.
  1196. * @note This check is required by functions with setting conditioned to
  1197. * ADC state:
  1198. * All ADC instances of the ADC common group must be disabled.
  1199. * Refer to functions having argument "ADCxy_COMMON" as parameter.
  1200. * @note On devices with only 1 ADC common instance, parameter of this macro
  1201. * is useless and can be ignored (parameter kept for compatibility
  1202. * with devices featuring several ADC common instances).
  1203. * @param __ADCXY_COMMON__ ADC common instance
  1204. * (can be set directly from CMSIS definition or by using helper macro @ref __LL_ADC_COMMON_INSTANCE() )
  1205. * @retval Value "0" if all ADC instances sharing the same ADC common instance
  1206. * are disabled.
  1207. * Value "1" if at least one ADC instance sharing the same ADC common instance
  1208. * is enabled.
  1209. */
  1210. #define __HAL_ADC_IS_ENABLED_ALL_COMMON_INSTANCE(__ADCXY_COMMON__) \
  1211. __LL_ADC_IS_ENABLED_ALL_COMMON_INSTANCE((__ADCXY_COMMON__))
  1212. /**
  1213. * @brief Helper macro to define the ADC conversion data full-scale digital
  1214. * value corresponding to the selected ADC resolution.
  1215. * @note ADC conversion data full-scale corresponds to voltage range
  1216. * determined by analog voltage references Vref+ and Vref-
  1217. * (refer to reference manual).
  1218. * @param __ADC_RESOLUTION__ This parameter can be one of the following values:
  1219. * @arg @ref ADC_RESOLUTION_12B
  1220. * @arg @ref ADC_RESOLUTION_10B
  1221. * @arg @ref ADC_RESOLUTION_8B
  1222. * @arg @ref ADC_RESOLUTION_6B
  1223. * @retval ADC conversion data full-scale digital value
  1224. */
  1225. #define __HAL_ADC_DIGITAL_SCALE(__ADC_RESOLUTION__) \
  1226. __LL_ADC_DIGITAL_SCALE((__ADC_RESOLUTION__))
  1227. /**
  1228. * @brief Helper macro to convert the ADC conversion data from
  1229. * a resolution to another resolution.
  1230. * @param __DATA__ ADC conversion data to be converted
  1231. * @param __ADC_RESOLUTION_CURRENT__ Resolution of to the data to be converted
  1232. * This parameter can be one of the following values:
  1233. * @arg @ref ADC_RESOLUTION_12B
  1234. * @arg @ref ADC_RESOLUTION_10B
  1235. * @arg @ref ADC_RESOLUTION_8B
  1236. * @arg @ref ADC_RESOLUTION_6B
  1237. * @param __ADC_RESOLUTION_TARGET__ Resolution of the data after conversion
  1238. * This parameter can be one of the following values:
  1239. * @arg @ref ADC_RESOLUTION_12B
  1240. * @arg @ref ADC_RESOLUTION_10B
  1241. * @arg @ref ADC_RESOLUTION_8B
  1242. * @arg @ref ADC_RESOLUTION_6B
  1243. * @retval ADC conversion data to the requested resolution
  1244. */
  1245. #define __HAL_ADC_CONVERT_DATA_RESOLUTION(__DATA__,\
  1246. __ADC_RESOLUTION_CURRENT__,\
  1247. __ADC_RESOLUTION_TARGET__) \
  1248. __LL_ADC_CONVERT_DATA_RESOLUTION((__DATA__), \
  1249. (__ADC_RESOLUTION_CURRENT__), \
  1250. (__ADC_RESOLUTION_TARGET__))
  1251. /**
  1252. * @brief Helper macro to calculate the voltage (unit: mVolt)
  1253. * corresponding to a ADC conversion data (unit: digital value).
  1254. * @note Analog reference voltage (Vref+) must be either known from
  1255. * user board environment or can be calculated using ADC measurement
  1256. * and ADC helper macro @ref __LL_ADC_CALC_VREFANALOG_VOLTAGE().
  1257. * @param __VREFANALOG_VOLTAGE__ Analog reference voltage (unit: mV)
  1258. * @param __ADC_DATA__ ADC conversion data (resolution 12 bits)
  1259. * (unit: digital value).
  1260. * @param __ADC_RESOLUTION__ This parameter can be one of the following values:
  1261. * @arg @ref ADC_RESOLUTION_12B
  1262. * @arg @ref ADC_RESOLUTION_10B
  1263. * @arg @ref ADC_RESOLUTION_8B
  1264. * @arg @ref ADC_RESOLUTION_6B
  1265. * @retval ADC conversion data equivalent voltage value (unit: mVolt)
  1266. */
  1267. #define __HAL_ADC_CALC_DATA_TO_VOLTAGE(__VREFANALOG_VOLTAGE__,\
  1268. __ADC_DATA__,\
  1269. __ADC_RESOLUTION__) \
  1270. __LL_ADC_CALC_DATA_TO_VOLTAGE((__VREFANALOG_VOLTAGE__), \
  1271. (__ADC_DATA__), \
  1272. (__ADC_RESOLUTION__))
  1273. /**
  1274. * @brief Helper macro to calculate analog reference voltage (Vref+)
  1275. * (unit: mVolt) from ADC conversion data of internal voltage
  1276. * reference VrefInt.
  1277. * @note Computation is using VrefInt calibration value
  1278. * stored in system memory for each device during production.
  1279. * @note This voltage depends on user board environment: voltage level
  1280. * connected to pin Vref+.
  1281. * On devices with small package, the pin Vref+ is not present
  1282. * and internally bonded to pin Vdda.
  1283. * @note On this STM32 serie, calibration data of internal voltage reference
  1284. * VrefInt corresponds to a resolution of 12 bits,
  1285. * this is the recommended ADC resolution to convert voltage of
  1286. * internal voltage reference VrefInt.
  1287. * Otherwise, this macro performs the processing to scale
  1288. * ADC conversion data to 12 bits.
  1289. * @param __VREFINT_ADC_DATA__ ADC conversion data (resolution 12 bits)
  1290. * of internal voltage reference VrefInt (unit: digital value).
  1291. * @param __ADC_RESOLUTION__ This parameter can be one of the following values:
  1292. * @arg @ref ADC_RESOLUTION_12B
  1293. * @arg @ref ADC_RESOLUTION_10B
  1294. * @arg @ref ADC_RESOLUTION_8B
  1295. * @arg @ref ADC_RESOLUTION_6B
  1296. * @retval Analog reference voltage (unit: mV)
  1297. */
  1298. #define __HAL_ADC_CALC_VREFANALOG_VOLTAGE(__VREFINT_ADC_DATA__,\
  1299. __ADC_RESOLUTION__) \
  1300. __LL_ADC_CALC_VREFANALOG_VOLTAGE((__VREFINT_ADC_DATA__), \
  1301. (__ADC_RESOLUTION__))
  1302. /**
  1303. * @brief Helper macro to calculate the temperature (unit: degree Celsius)
  1304. * from ADC conversion data of internal temperature sensor.
  1305. * @note Computation is using temperature sensor calibration values
  1306. * stored in system memory for each device during production.
  1307. * @note Calculation formula:
  1308. * Temperature = ((TS_ADC_DATA - TS_CAL1)
  1309. * * (TS_CAL2_TEMP - TS_CAL1_TEMP))
  1310. * / (TS_CAL2 - TS_CAL1) + TS_CAL1_TEMP
  1311. * with TS_ADC_DATA = temperature sensor raw data measured by ADC
  1312. * Avg_Slope = (TS_CAL2 - TS_CAL1)
  1313. * / (TS_CAL2_TEMP - TS_CAL1_TEMP)
  1314. * TS_CAL1 = equivalent TS_ADC_DATA at temperature
  1315. * TEMP_DEGC_CAL1 (calibrated in factory)
  1316. * TS_CAL2 = equivalent TS_ADC_DATA at temperature
  1317. * TEMP_DEGC_CAL2 (calibrated in factory)
  1318. * Caution: Calculation relevancy under reserve that calibration
  1319. * parameters are correct (address and data).
  1320. * To calculate temperature using temperature sensor
  1321. * datasheet typical values (generic values less, therefore
  1322. * less accurate than calibrated values),
  1323. * use helper macro @ref __LL_ADC_CALC_TEMPERATURE_TYP_PARAMS().
  1324. * @note As calculation input, the analog reference voltage (Vref+) must be
  1325. * defined as it impacts the ADC LSB equivalent voltage.
  1326. * @note Analog reference voltage (Vref+) must be either known from
  1327. * user board environment or can be calculated using ADC measurement
  1328. * and ADC helper macro @ref __LL_ADC_CALC_VREFANALOG_VOLTAGE().
  1329. * @note On this STM32 serie, calibration data of temperature sensor
  1330. * corresponds to a resolution of 12 bits,
  1331. * this is the recommended ADC resolution to convert voltage of
  1332. * temperature sensor.
  1333. * Otherwise, this macro performs the processing to scale
  1334. * ADC conversion data to 12 bits.
  1335. * @param __VREFANALOG_VOLTAGE__ Analog reference voltage (unit: mV)
  1336. * @param __TEMPSENSOR_ADC_DATA__ ADC conversion data of internal
  1337. * temperature sensor (unit: digital value).
  1338. * @param __ADC_RESOLUTION__ ADC resolution at which internal temperature
  1339. * sensor voltage has been measured.
  1340. * This parameter can be one of the following values:
  1341. * @arg @ref ADC_RESOLUTION_12B
  1342. * @arg @ref ADC_RESOLUTION_10B
  1343. * @arg @ref ADC_RESOLUTION_8B
  1344. * @arg @ref ADC_RESOLUTION_6B
  1345. * @retval Temperature (unit: degree Celsius)
  1346. */
  1347. #define __HAL_ADC_CALC_TEMPERATURE(__VREFANALOG_VOLTAGE__,\
  1348. __TEMPSENSOR_ADC_DATA__,\
  1349. __ADC_RESOLUTION__) \
  1350. __LL_ADC_CALC_TEMPERATURE((__VREFANALOG_VOLTAGE__), \
  1351. (__TEMPSENSOR_ADC_DATA__), \
  1352. (__ADC_RESOLUTION__))
  1353. /**
  1354. * @brief Helper macro to calculate the temperature (unit: degree Celsius)
  1355. * from ADC conversion data of internal temperature sensor.
  1356. * @note Computation is using temperature sensor typical values
  1357. * (refer to device datasheet).
  1358. * @note Calculation formula:
  1359. * Temperature = (TS_TYP_CALx_VOLT(uV) - TS_ADC_DATA * Conversion_uV)
  1360. * / Avg_Slope + CALx_TEMP
  1361. * with TS_ADC_DATA = temperature sensor raw data measured by ADC
  1362. * (unit: digital value)
  1363. * Avg_Slope = temperature sensor slope
  1364. * (unit: uV/Degree Celsius)
  1365. * TS_TYP_CALx_VOLT = temperature sensor digital value at
  1366. * temperature CALx_TEMP (unit: mV)
  1367. * Caution: Calculation relevancy under reserve the temperature sensor
  1368. * of the current device has characteristics in line with
  1369. * datasheet typical values.
  1370. * If temperature sensor calibration values are available on
  1371. * on this device (presence of macro __LL_ADC_CALC_TEMPERATURE()),
  1372. * temperature calculation will be more accurate using
  1373. * helper macro @ref __LL_ADC_CALC_TEMPERATURE().
  1374. * @note As calculation input, the analog reference voltage (Vref+) must be
  1375. * defined as it impacts the ADC LSB equivalent voltage.
  1376. * @note Analog reference voltage (Vref+) must be either known from
  1377. * user board environment or can be calculated using ADC measurement
  1378. * and ADC helper macro @ref __LL_ADC_CALC_VREFANALOG_VOLTAGE().
  1379. * @note ADC measurement data must correspond to a resolution of 12bits
  1380. * (full scale digital value 4095). If not the case, the data must be
  1381. * preliminarily rescaled to an equivalent resolution of 12 bits.
  1382. * @param __TEMPSENSOR_TYP_AVGSLOPE__ Device datasheet data: Temperature sensor slope typical value (unit: uV/DegCelsius).
  1383. * On STM32WB, refer to device datasheet parameter "Avg_Slope".
  1384. * @param __TEMPSENSOR_TYP_CALX_V__ Device datasheet data: Temperature sensor voltage typical value (at temperature and Vref+ defined in parameters below) (unit: mV).
  1385. * On STM32WB, refer to device datasheet parameter "V30" (corresponding to TS_CAL1).
  1386. * @param __TEMPSENSOR_CALX_TEMP__ Device datasheet data: Temperature at which temperature sensor voltage (see parameter above) is corresponding (unit: mV)
  1387. * @param __VREFANALOG_VOLTAGE__ Analog voltage reference (Vref+) voltage (unit: mV)
  1388. * @param __TEMPSENSOR_ADC_DATA__ ADC conversion data of internal temperature sensor (unit: digital value).
  1389. * @param __ADC_RESOLUTION__ ADC resolution at which internal temperature sensor voltage has been measured.
  1390. * This parameter can be one of the following values:
  1391. * @arg @ref ADC_RESOLUTION_12B
  1392. * @arg @ref ADC_RESOLUTION_10B
  1393. * @arg @ref ADC_RESOLUTION_8B
  1394. * @arg @ref ADC_RESOLUTION_6B
  1395. * @retval Temperature (unit: degree Celsius)
  1396. */
  1397. #define __HAL_ADC_CALC_TEMPERATURE_TYP_PARAMS(__TEMPSENSOR_TYP_AVGSLOPE__,\
  1398. __TEMPSENSOR_TYP_CALX_V__,\
  1399. __TEMPSENSOR_CALX_TEMP__,\
  1400. __VREFANALOG_VOLTAGE__,\
  1401. __TEMPSENSOR_ADC_DATA__,\
  1402. __ADC_RESOLUTION__) \
  1403. __LL_ADC_CALC_TEMPERATURE_TYP_PARAMS((__TEMPSENSOR_TYP_AVGSLOPE__), \
  1404. (__TEMPSENSOR_TYP_CALX_V__), \
  1405. (__TEMPSENSOR_CALX_TEMP__), \
  1406. (__VREFANALOG_VOLTAGE__), \
  1407. (__TEMPSENSOR_ADC_DATA__), \
  1408. (__ADC_RESOLUTION__))
  1409. /**
  1410. * @}
  1411. */
  1412. /**
  1413. * @}
  1414. */
  1415. /* Include ADC HAL Extended module */
  1416. #include "stm32wbxx_hal_adc_ex.h"
  1417. /* Exported functions --------------------------------------------------------*/
  1418. /** @addtogroup ADC_Exported_Functions
  1419. * @{
  1420. */
  1421. /** @addtogroup ADC_Exported_Functions_Group1
  1422. * @brief Initialization and Configuration functions
  1423. * @{
  1424. */
  1425. /* Initialization and de-initialization functions ****************************/
  1426. HAL_StatusTypeDef HAL_ADC_Init(ADC_HandleTypeDef *hadc);
  1427. HAL_StatusTypeDef HAL_ADC_DeInit(ADC_HandleTypeDef *hadc);
  1428. void HAL_ADC_MspInit(ADC_HandleTypeDef *hadc);
  1429. void HAL_ADC_MspDeInit(ADC_HandleTypeDef *hadc);
  1430. #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1)
  1431. /* Callbacks Register/UnRegister functions ***********************************/
  1432. HAL_StatusTypeDef HAL_ADC_RegisterCallback(ADC_HandleTypeDef *hadc, HAL_ADC_CallbackIDTypeDef CallbackID,
  1433. pADC_CallbackTypeDef pCallback);
  1434. HAL_StatusTypeDef HAL_ADC_UnRegisterCallback(ADC_HandleTypeDef *hadc, HAL_ADC_CallbackIDTypeDef CallbackID);
  1435. #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */
  1436. /**
  1437. * @}
  1438. */
  1439. /** @addtogroup ADC_Exported_Functions_Group2
  1440. * @brief IO operation functions
  1441. * @{
  1442. */
  1443. /* IO operation functions *****************************************************/
  1444. /* Blocking mode: Polling */
  1445. HAL_StatusTypeDef HAL_ADC_Start(ADC_HandleTypeDef *hadc);
  1446. HAL_StatusTypeDef HAL_ADC_Stop(ADC_HandleTypeDef *hadc);
  1447. HAL_StatusTypeDef HAL_ADC_PollForConversion(ADC_HandleTypeDef *hadc, uint32_t Timeout);
  1448. HAL_StatusTypeDef HAL_ADC_PollForEvent(ADC_HandleTypeDef *hadc, uint32_t EventType, uint32_t Timeout);
  1449. /* Non-blocking mode: Interruption */
  1450. HAL_StatusTypeDef HAL_ADC_Start_IT(ADC_HandleTypeDef *hadc);
  1451. HAL_StatusTypeDef HAL_ADC_Stop_IT(ADC_HandleTypeDef *hadc);
  1452. /* Non-blocking mode: DMA */
  1453. HAL_StatusTypeDef HAL_ADC_Start_DMA(ADC_HandleTypeDef *hadc, uint32_t *pData, uint32_t Length);
  1454. HAL_StatusTypeDef HAL_ADC_Stop_DMA(ADC_HandleTypeDef *hadc);
  1455. /* ADC retrieve conversion value intended to be used with polling or interruption */
  1456. uint32_t HAL_ADC_GetValue(ADC_HandleTypeDef *hadc);
  1457. /* ADC IRQHandler and Callbacks used in non-blocking modes (Interruption and DMA) */
  1458. void HAL_ADC_IRQHandler(ADC_HandleTypeDef *hadc);
  1459. void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef *hadc);
  1460. void HAL_ADC_ConvHalfCpltCallback(ADC_HandleTypeDef *hadc);
  1461. void HAL_ADC_LevelOutOfWindowCallback(ADC_HandleTypeDef *hadc);
  1462. void HAL_ADC_ErrorCallback(ADC_HandleTypeDef *hadc);
  1463. /**
  1464. * @}
  1465. */
  1466. /** @addtogroup ADC_Exported_Functions_Group3 Peripheral Control functions
  1467. * @brief Peripheral Control functions
  1468. * @{
  1469. */
  1470. /* Peripheral Control functions ***********************************************/
  1471. HAL_StatusTypeDef HAL_ADC_ConfigChannel(ADC_HandleTypeDef *hadc, ADC_ChannelConfTypeDef *sConfig);
  1472. HAL_StatusTypeDef HAL_ADC_AnalogWDGConfig(ADC_HandleTypeDef *hadc, ADC_AnalogWDGConfTypeDef *AnalogWDGConfig);
  1473. /**
  1474. * @}
  1475. */
  1476. /* Peripheral State functions *************************************************/
  1477. /** @addtogroup ADC_Exported_Functions_Group4
  1478. * @{
  1479. */
  1480. uint32_t HAL_ADC_GetState(ADC_HandleTypeDef *hadc);
  1481. uint32_t HAL_ADC_GetError(ADC_HandleTypeDef *hadc);
  1482. /**
  1483. * @}
  1484. */
  1485. /**
  1486. * @}
  1487. */
  1488. /* Private functions -----------------------------------------------------------*/
  1489. /** @addtogroup ADC_Private_Functions ADC Private Functions
  1490. * @{
  1491. */
  1492. HAL_StatusTypeDef ADC_ConversionStop(ADC_HandleTypeDef *hadc, uint32_t ConversionGroup);
  1493. HAL_StatusTypeDef ADC_Enable(ADC_HandleTypeDef *hadc);
  1494. HAL_StatusTypeDef ADC_Disable(ADC_HandleTypeDef *hadc);
  1495. void ADC_DMAConvCplt(DMA_HandleTypeDef *hdma);
  1496. void ADC_DMAHalfConvCplt(DMA_HandleTypeDef *hdma);
  1497. void ADC_DMAError(DMA_HandleTypeDef *hdma);
  1498. /**
  1499. * @}
  1500. */
  1501. /**
  1502. * @}
  1503. */
  1504. /**
  1505. * @}
  1506. */
  1507. #ifdef __cplusplus
  1508. }
  1509. #endif
  1510. #endif /* STM32WBxx_HAL_ADC_H */
  1511. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/