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.
 
 
 

1033 lines
66 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32l4xx_hal_adc.h
  4. * @author MCD Application Team
  5. * @version V1.3.0
  6. * @date 29-January-2016
  7. * @brief Header file of ADC HAL module.
  8. ******************************************************************************
  9. * @attention
  10. *
  11. * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
  12. *
  13. * Redistribution and use in source and binary forms, with or without modification,
  14. * are permitted provided that the following conditions are met:
  15. * 1. Redistributions of source code must retain the above copyright notice,
  16. * this list of conditions and the following disclaimer.
  17. * 2. Redistributions in binary form must reproduce the above copyright notice,
  18. * this list of conditions and the following disclaimer in the documentation
  19. * and/or other materials provided with the distribution.
  20. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  21. * may be used to endorse or promote products derived from this software
  22. * without specific prior written permission.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  25. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  27. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  28. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  29. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  30. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  31. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  32. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  33. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. *
  35. ******************************************************************************
  36. */
  37. /* Define to prevent recursive inclusion -------------------------------------*/
  38. #ifndef __STM32L4xx_ADC_H
  39. #define __STM32L4xx_ADC_H
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. /* Includes ------------------------------------------------------------------*/
  44. #include "stm32l4xx_hal_def.h"
  45. /** @addtogroup STM32L4xx_HAL_Driver
  46. * @{
  47. */
  48. /** @addtogroup ADC
  49. * @{
  50. */
  51. /* Exported types ------------------------------------------------------------*/
  52. /** @defgroup ADC_Exported_Types ADC Exported Types
  53. * @{
  54. */
  55. /**
  56. * @brief ADC Regular Conversion Oversampling structure definition
  57. */
  58. typedef struct
  59. {
  60. uint32_t Ratio; /*!< Configures the oversampling ratio.
  61. This parameter can be a value of @ref ADCEx_Oversampling_Ratio */
  62. uint32_t RightBitShift; /*!< Configures the division coefficient for the Oversampler.
  63. This parameter can be a value of @ref ADCEx_Right_Bit_Shift */
  64. uint32_t TriggeredMode; /*!< Selects the regular triggered oversampling mode.
  65. This parameter can be a value of @ref ADCEx_Triggered_Oversampling_Mode */
  66. uint32_t OversamplingStopReset; /*!< Selects the regular oversampling mode.
  67. The oversampling is either temporary stopped or reset upon an injected
  68. sequence interruption.
  69. If oversampling is enabled on both regular and injected groups, this parameter
  70. is discarded and forced to setting "ADC_REGOVERSAMPLING_RESUMED_MODE"
  71. (the oversampling buffer is zeroed during injection sequence).
  72. This parameter can be a value of @ref ADCEx_Regular_Oversampling_Mode */
  73. }ADC_OversamplingTypeDef;
  74. /**
  75. * @brief Structure definition of ADC initialization and regular group
  76. * @note Parameters of this structure are shared within 2 scopes:
  77. * - Scope entire ADC (affects regular and injected groups): ClockPrescaler and ClockDivider, Resolution, DataAlign,
  78. * ScanConvMode, EOCSelection, LowPowerAutoWait.
  79. * - Scope regular group: ContinuousConvMode, NbrOfConversion, DiscontinuousConvMode, NbrOfDiscConversion, ExternalTrigConvEdge,
  80. * ExternalTrigConv, DMAContinuousRequests, Overrun, OversamplingMode, Oversampling.
  81. * @note The setting of these parameters by function HAL_ADC_Init() is conditioned by ADC state.
  82. * ADC state can be either:
  83. * - For all parameters: ADC disabled
  84. * - For all parameters except 'LowPowerAutoWait', 'DMAContinuousRequests' and 'Oversampling': ADC enabled without conversion on going on regular group.
  85. * - For parameters 'LowPowerAutoWait' and 'DMAContinuousRequests': ADC enabled without conversion on going on regular and injected groups.
  86. * If ADC is not in the appropriate state to modify some parameters, these parameters setting is bypassed
  87. * without error reporting (as it can be the expected behaviour in case of intended action to update another parameter
  88. * (which fulfills the ADC state condition) on the fly).
  89. */
  90. typedef struct
  91. {
  92. uint32_t ClockPrescaler; /*!< Selects ADC clock source (asynchronous System/PLLSAI1/PLLSAI2 clocks or synchronous AHB clock) as well as
  93. the division factor applied to the clock.
  94. This parameter can be a value of @ref ADC_ClockPrescaler.
  95. Note: The clock is common for all the ADCs.
  96. 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,
  97. AHB clock frequency /3 for resolution 8 bits, AHB clock frequency /2 for resolution 6 bits.
  98. Note: In case of usage of the ADC dedicated PLL clock, this clock must be preliminarily enabled and prescaler set at RCC top level.
  99. Note: In case of synchronous clock mode based on HCLK/1, the configuration must be enabled only if the AHB clock prescaler is set to 1
  100. and if the system clock has a 50% duty cycle.
  101. Note: This parameter can be modified only if all ADCs are disabled. */
  102. uint32_t Resolution; /*!< Configures the ADC resolution.
  103. This parameter can be a value of @ref ADC_Resolution */
  104. uint32_t DataAlign; /*!< Specifies ADC data alignment (right or left).
  105. See reference manual for alignments formats versus resolutions.
  106. This parameter can be a value of @ref ADC_Data_align */
  107. uint32_t ScanConvMode; /*!< Configures the sequencer of regular and injected groups.
  108. This parameter can be associated to parameter 'DiscontinuousConvMode' to have main sequence subdivided in successive parts.
  109. If disabled: Conversion is performed in single mode (one channel converted, that defined in rank 1).
  110. Parameters 'NbrOfConversion' and 'InjectedNbrOfConversion' are discarded (equivalent to set to 1).
  111. If enabled: Conversions are performed in sequence mode (multiple ranks defined by 'NbrOfConversion' or'InjectedNbrOfConversion').
  112. Scan direction is upward: from rank 1 to rank 'n'.
  113. This parameter can be a value of @ref ADC_Scan_mode */
  114. uint32_t EOCSelection; /*!< Specifies which EOC (End Of Conversion) flag is used for conversion by polling and interruption: end of conversion of each rank or complete sequence.
  115. This parameter can be a value of @ref ADC_EOCSelection. */
  116. uint32_t LowPowerAutoWait; /*!< Selects the dynamic low power Auto Delay: new conversion start only when the previous
  117. conversion (for regular group) or previous sequence (for injected group) has been processed by user software
  118. (EOC bit cleared or DR read for regular conversions, JEOS cleared for injected conversions).
  119. This feature automatically adapts the speed of ADC to the speed of the system that reads the data. Moreover, this avoids risk of overrun
  120. for low frequency applications.
  121. This parameter can be set to ENABLE or DISABLE.
  122. Note: Do not use with interruption or DMA (HAL_ADC_Start_IT(), HAL_ADC_Start_DMA(), HAL_ADCEx_InjectedStart_IT()) when it is necessary
  123. to clear immediately the EOC flag to free the IRQ vector sequencer.
  124. Do use with polling: 1. Start conversion with HAL_ADC_Start() or HAL_ADCEx_InjectedStart(), 2. When conversion data is available: use
  125. HAL_ADC_PollForConversion() to ensure that conversion is completed and HAL_ADC_GetValue() to retrieve conversion result and trig another
  126. conversion. For injected conversion, resort to HAL_ADCEx_InjectedPollForConversion() then HAL_ADCEx_InjectedGetValue() */
  127. uint32_t ContinuousConvMode; /*!< Specifies whether the conversion is performed in single mode (one conversion) or continuous mode for regular group,
  128. after software start or external trigger occurred.
  129. This parameter can be set to ENABLE or DISABLE. */
  130. uint32_t NbrOfConversion; /*!< Specifies the number of ranks that will be converted within the regular group sequencer.
  131. To use the regular group sequencer and convert several ranks, parameter 'ScanConvMode' must be enabled.
  132. This parameter must be a number between Min_Data = 1 and Max_Data = 16.
  133. Note: This parameter must be modified when no conversion is on going on regular group (ADC disabled, or ADC enabled without
  134. continuous mode or external trigger that could launch a conversion). */
  135. uint32_t DiscontinuousConvMode; /*!< Specifies whether the conversions sequence of regular group is performed in Complete-sequence/Discontinuous-sequence (main sequence
  136. subdivided in successive parts).
  137. Discontinuous mode is used only if sequencer is enabled (parameter 'ScanConvMode'). If sequencer is disabled, this parameter is discarded.
  138. Discontinuous mode can be enabled only if continuous mode is disabled.
  139. This parameter can be set to ENABLE or DISABLE. */
  140. uint32_t NbrOfDiscConversion; /*!< Specifies the number of discontinuous conversions in which the main sequence of regular group (parameter NbrOfConversion) will be subdivided.
  141. If parameter 'DiscontinuousConvMode' is disabled, this parameter is discarded.
  142. This parameter must be a number between Min_Data = 1 and Max_Data = 8. */
  143. uint32_t ExternalTrigConv; /*!< Selects the external event used to trigger the conversion start of regular group.
  144. If set to ADC_SOFTWARE_START, external triggers are disabled and software trigger is used instead.
  145. This parameter can be a value of @ref ADC_Regular_External_Trigger_Source.
  146. Caution: external trigger source is common to ADCs. */
  147. uint32_t ExternalTrigConvEdge; /*!< Selects the external trigger edge of regular group.
  148. If set to ADC_EXTERNALTRIGCONVEDGE_NONE, external triggers are disabled and software trigger is used instead.
  149. This parameter can be a value of @ref ADC_Regular_External_Trigger_Source_Edge */
  150. uint32_t DMAContinuousRequests; /*!< Specifies whether the DMA requests are performed in one shot mode (DMA transfer stops when number of conversions is reached)
  151. or in Continuous mode (DMA transfer unlimited, whatever number of conversions).
  152. Note: In continuous mode, DMA must be configured in circular mode. Otherwise an overrun will be triggered when DMA buffer maximum pointer is reached.
  153. This parameter can be set to ENABLE or DISABLE.
  154. Note: This parameter must be modified when no conversion is on going on both regular and injected groups
  155. (ADC disabled, or ADC enabled without continuous mode or external trigger that could launch a conversion). */
  156. uint32_t Overrun; /*!< Select the behaviour in case of overrun: data overwritten or preserved (default).
  157. This parameter applies to regular group only.
  158. This parameter can be a value of @ref ADC_Overrun.
  159. Note: Case of overrun set to data preserved and usage with end on conversion interruption (HAL_Start_IT()): ADC IRQ handler has to clear
  160. end of conversion flags, this induces the release of the preserved data. If needed, this data can be saved by user-developped function
  161. HAL_ADC_ConvCpltCallback() (called before end of conversion flags clear).
  162. Note: Error reporting with respect to the conversion mode:
  163. - 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
  164. overwritten, user can willingly not read all the converted data, this is not considered as an erroneous case.
  165. - Usage with ADC conversion by DMA: Error is reported whatever overrun setting (DMA is expected to process all data from data register). */
  166. uint32_t OversamplingMode; /*!< Specifies whether the oversampling feature is enabled or disabled.
  167. This parameter can be set to ENABLE or DISABLE.
  168. Note: This parameter can be modified only if there is no conversion is ongoing (both ADSTART and JADSTART cleared). */
  169. ADC_OversamplingTypeDef Oversampling; /*!< Specifies the Oversampling parameters.
  170. Caution: this setting overwrites the previous oversampling configuration if oversampling already enabled.
  171. Note: This parameter can be modified only if there is no conversion is ongoing (both ADSTART and JADSTART cleared). */
  172. }ADC_InitTypeDef;
  173. /** @defgroup ADC_States ADC States
  174. * @{
  175. */
  176. /**
  177. * @brief HAL ADC state machine: ADC State bitfield definition
  178. */
  179. /* States of ADC global scope */
  180. #define HAL_ADC_STATE_RESET ((uint32_t)0x00000000) /*!< ADC not yet initialized or disabled */
  181. #define HAL_ADC_STATE_READY ((uint32_t)0x00000001) /*!< ADC peripheral ready for use */
  182. #define HAL_ADC_STATE_BUSY_INTERNAL ((uint32_t)0x00000002) /*!< ADC is busy because of an internal process (initialization, calibration) */
  183. #define HAL_ADC_STATE_TIMEOUT ((uint32_t)0x00000004) /*!< TimeOut occurrence */
  184. /* States of ADC errors */
  185. #define HAL_ADC_STATE_ERROR_INTERNAL ((uint32_t)0x00000010) /*!< Internal error occurrence */
  186. #define HAL_ADC_STATE_ERROR_CONFIG ((uint32_t)0x00000020) /*!< Configuration error occurrence */
  187. #define HAL_ADC_STATE_ERROR_DMA ((uint32_t)0x00000040) /*!< DMA error occurrence */
  188. /* States of ADC regular group */
  189. #define HAL_ADC_STATE_REG_BUSY ((uint32_t)0x00000100) /*!< A regular conversion is ongoing or can occur (either by continuous mode,
  190. external trigger, low power auto power-on, multimode ADC master control) */
  191. #define HAL_ADC_STATE_REG_EOC ((uint32_t)0x00000200) /*!< Regular conversion data available */
  192. #define HAL_ADC_STATE_REG_OVR ((uint32_t)0x00000400) /*!< Overrun occurrence */
  193. #define HAL_ADC_STATE_REG_EOSMP ((uint32_t)0x00000800) /*!< End Of Sampling flag raised */
  194. /* States of ADC injected group */
  195. #define HAL_ADC_STATE_INJ_BUSY ((uint32_t)0x00001000) /*!< An injected conversion is ongoing or can occur (either by auto-injection mode,
  196. external trigger, low power auto power-on, multimode ADC master control) */
  197. #define HAL_ADC_STATE_INJ_EOC ((uint32_t)0x00002000) /*!< Injected conversion data available */
  198. #define HAL_ADC_STATE_INJ_JQOVF ((uint32_t)0x00004000) /*!< Injected queue overflow occurrence */
  199. /* States of ADC analog watchdogs */
  200. #define HAL_ADC_STATE_AWD1 ((uint32_t)0x00010000) /*!< Out-of-window occurrence of Analog Watchdog 1 */
  201. #define HAL_ADC_STATE_AWD2 ((uint32_t)0x00020000) /*!< Out-of-window occurrence of Analog Watchdog 2 */
  202. #define HAL_ADC_STATE_AWD3 ((uint32_t)0x00040000) /*!< Out-of-window occurrence of Analog Watchdog 3 */
  203. /* States of ADC multi-mode */
  204. #define HAL_ADC_STATE_MULTIMODE_SLAVE ((uint32_t)0x00100000) /*!< ADC in multimode slave state, controlled by another ADC master */
  205. /**
  206. * @}
  207. */
  208. /**
  209. * @brief ADC Injection Configuration
  210. */
  211. typedef struct
  212. {
  213. uint32_t ContextQueue; /*!< Injected channel configuration context: build-up over each
  214. HAL_ADCEx_InjectedConfigChannel() call to finally initialize
  215. JSQR register at HAL_ADCEx_InjectedConfigChannel() last call */
  216. uint32_t ChannelCount; /*!< Number of channels in the injected sequence */
  217. }ADC_InjectionConfigTypeDef;
  218. /**
  219. * @brief ADC handle Structure definition
  220. */
  221. typedef struct
  222. {
  223. ADC_TypeDef *Instance; /*!< Register base address */
  224. ADC_InitTypeDef Init; /*!< ADC initialization parameters and regular conversions setting */
  225. DMA_HandleTypeDef *DMA_Handle; /*!< Pointer DMA Handler */
  226. HAL_LockTypeDef Lock; /*!< ADC locking object */
  227. __IO uint32_t State; /*!< ADC communication state (bit-map of ADC states) */
  228. __IO uint32_t ErrorCode; /*!< ADC Error code */
  229. ADC_InjectionConfigTypeDef InjectionConfig ; /*!< ADC injected channel configuration build-up structure */
  230. }ADC_HandleTypeDef;
  231. /**
  232. * @brief Structure definition of ADC channel for regular group
  233. * @note The setting of these parameters with function HAL_ADC_ConfigChannel() is conditioned by ADC state.
  234. * ADC state can be either:
  235. * - For all parameters: ADC disabled (this is the only possible ADC state to modify parameter 'SingleDiff')
  236. * - For all except parameters 'SamplingTime', 'Offset', 'OffsetNumber': ADC enabled without conversion on going on regular group.
  237. * - For parameters 'SamplingTime', 'Offset', 'OffsetNumber': ADC enabled without conversion on going on regular and injected groups.
  238. * If ADC is not in the appropriate state to modify some parameters, these parameters setting is bypassed
  239. * without error reporting (as it can be the expected behaviour in case of intended action to update another parameter
  240. * (which fulfills the ADC state condition) on the fly).
  241. */
  242. typedef struct
  243. {
  244. uint32_t Channel; /*!< Specifies the channel to configure into ADC regular group.
  245. This parameter can be a value of @ref ADC_channels
  246. Note: Depending on devices and ADC instances, some channels may not be available. Refer to device DataSheet for channels availability. */
  247. uint32_t Rank; /*!< Specifies the rank in the regular group sequencer.
  248. This parameter can be a value of @ref ADCEx_regular_rank
  249. Note: to disable a channel or change order of conversion sequencer, rank containing a previous channel setting can be overwritten by
  250. the new channel setting (or parameter number of conversions adjusted) */
  251. uint32_t SamplingTime; /*!< Sampling time value to be set for the selected channel.
  252. Unit: ADC clock cycles
  253. Conversion time is the addition of sampling time and processing time (12.5 ADC clock cycles at ADC resolution 12 bits, 10.5 cycles at 10 bits,
  254. 8.5 cycles at 8 bits, 6.5 cycles at 6 bits).
  255. This parameter can be a value of @ref ADC_sampling_times
  256. Caution: This parameter applies to a channel that can be used in a regular and/or injected group.
  257. It overwrites the last setting.
  258. Note: In case of usage of internal measurement channels (VrefInt/Vbat/TempSensor),
  259. sampling time constraints must be respected (sampling time can be adjusted with respect to the ADC clock frequency and sampling time setting)
  260. Refer to device DataSheet for timings values. */
  261. uint32_t SingleDiff; /*!< Selection of single-ended or differential input.
  262. In differential mode: Differential measurement is carried out between the selected channel 'i' (positive input) and channel 'i+1' (negative input).
  263. Only channel 'i' has to be configured, channel 'i+1' is configured automatically.
  264. This parameter must be a value of @ref ADCEx_SingleDifferential
  265. Caution: This parameter applies to a channel that can be used in a regular and/or injected group.
  266. It overwrites the last setting.
  267. Note: Refer to Reference Manual to ensure the selected channel is available in differential mode.
  268. Note: When configuring a channel 'i' in differential mode, the channel 'i+1' is not usable separately.
  269. Note: This parameter must be modified when ADC is disabled (before ADC start conversion or after ADC stop conversion).
  270. If ADC is enabled, this parameter setting is bypassed without error reporting (as it can be the expected behaviour in case
  271. of another parameter update on the fly) */
  272. uint32_t OffsetNumber; /*!< Selects the offset number
  273. This parameter can be a value of @ref ADCEx_OffsetNumber
  274. Caution: Only one offset is allowed per channel. This parameter overwrites the last setting. */
  275. uint32_t Offset; /*!< Defines the offset to be subtracted from the raw converted data.
  276. Offset value must be a positive number.
  277. 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,
  278. 0x3FF, 0xFF or 0x3F respectively.
  279. Note: This parameter must be modified when no conversion is on going on both regular and injected groups (ADC disabled, or ADC enabled
  280. without continuous mode or external trigger that could launch a conversion). */
  281. }ADC_ChannelConfTypeDef;
  282. /**
  283. * @brief Structure definition of ADC analog watchdog
  284. * @note The setting of these parameters with function HAL_ADC_AnalogWDGConfig() is conditioned by ADC state.
  285. * ADC state can be either: ADC disabled or ADC enabled without conversion on going on regular and injected groups.
  286. */
  287. typedef struct
  288. {
  289. uint32_t WatchdogNumber; /*!< Selects which ADC analog watchdog is applied to the selected channel.
  290. For Analog Watchdog 1: Only 1 channel can be monitored (or overall group of channels by setting parameter 'WatchdogMode')
  291. For Analog Watchdog 2 and 3: Several channels can be monitored (by successive calls of 'HAL_ADC_AnalogWDGConfig()' for each channel)
  292. This parameter can be a value of @ref ADCEx_analog_watchdog_number. */
  293. uint32_t WatchdogMode; /*!< For Analog Watchdog 1: Configures the ADC analog watchdog mode: single channel/overall group of channels, regular/injected group.
  294. For Analog Watchdog 2 and 3: There is no configuration for overall group of channels as AWD1. Set value 'ADC_ANALOGWATCHDOG_NONE' to reset
  295. channels group programmed with parameter 'Channel', set any other value to program the channel(s) to be monitored.
  296. This parameter can be a value of @ref ADCEx_analog_watchdog_mode. */
  297. uint32_t Channel; /*!< Selects which ADC channel to monitor by analog watchdog.
  298. For Analog Watchdog 1: this parameter has an effect only if parameter 'WatchdogMode' is configured on single channel (only 1 channel can be monitored).
  299. For Analog Watchdog 2 and 3: Several channels can be monitored (successive calls of HAL_ADC_AnalogWDGConfig() must be done, one for each channel.
  300. Channels group reset can be done by setting WatchdogMode to 'ADC_ANALOGWATCHDOG_NONE').
  301. This parameter can be a value of @ref ADC_channels. */
  302. uint32_t ITMode; /*!< Specifies whether the analog watchdog is configured in interrupt or polling mode.
  303. This parameter can be set to ENABLE or DISABLE */
  304. uint32_t HighThreshold; /*!< Configures the ADC analog watchdog High threshold value.
  305. 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,
  306. 0x3FF, 0xFF or 0x3F respectively.
  307. Note: Analog watchdog 2 and 3 are limited to a resolution of 8 bits: if ADC resolution is 12 bits
  308. the 4 LSB are ignored, if ADC resolution is 10 bits the 2 LSB are ignored. */
  309. uint32_t LowThreshold; /*!< Configures the ADC analog watchdog Low threshold value.
  310. Depending of ADC resolution selected (12, 10, 8 or 6 bits), this parameter must be a number between Min_Data = 0x000 and Max_Data = 0xFFF, 0x3FF, 0xFF or 0x3F respectively.
  311. Note: Analog watchdog 2 and 3 are limited to a resolution of 8 bits: if ADC resolution is 12 bits
  312. the 4 LSB are ignored, if ADC resolution is 10 bits the 2 LSB are ignored. */
  313. }ADC_AnalogWDGConfTypeDef;
  314. /**
  315. * @}
  316. */
  317. /* Exported constants --------------------------------------------------------*/
  318. /** @defgroup ADC_Exported_Constants ADC Exported Constants
  319. * @{
  320. */
  321. /** @defgroup ADC_Error_Code ADC Error Code
  322. * @{
  323. */
  324. #define HAL_ADC_ERROR_NONE ((uint32_t)0x00) /*!< No error */
  325. #define HAL_ADC_ERROR_INTERNAL ((uint32_t)0x01) /*!< ADC IP internal error: problem of
  326. clocking, enable/disable, erroneous state */
  327. #define HAL_ADC_ERROR_OVR ((uint32_t)0x02) /*!< Overrun error */
  328. #define HAL_ADC_ERROR_DMA ((uint32_t)0x04) /*!< DMA transfer error */
  329. #define HAL_ADC_ERROR_JQOVF ((uint32_t)0x08) /*!< Injected context queue overflow error */
  330. /**
  331. * @}
  332. */
  333. /** @defgroup ADC_ClockPrescaler ADC Clock Prescaler
  334. * @{
  335. */
  336. #define ADC_CLOCK_SYNC_PCLK_DIV1 ((uint32_t)ADC_CCR_CKMODE_0) /*!< ADC synchronous clock derived from AHB clock not divided */
  337. #define ADC_CLOCK_SYNC_PCLK_DIV2 ((uint32_t)ADC_CCR_CKMODE_1) /*!< ADC synchronous clock derived from AHB clock divided by 2 */
  338. #define ADC_CLOCK_SYNC_PCLK_DIV4 ((uint32_t)ADC_CCR_CKMODE) /*!< ADC synchronous clock derived from AHB clock divided by 4 */
  339. #define ADC_CLOCKPRESCALER_PCLK_DIV1 ADC_CLOCK_SYNC_PCLK_DIV1 /*!< Obsolete naming, kept for compatibility with some other devices */
  340. #define ADC_CLOCKPRESCALER_PCLK_DIV2 ADC_CLOCK_SYNC_PCLK_DIV2 /*!< Obsolete naming, kept for compatibility with some other devices */
  341. #define ADC_CLOCKPRESCALER_PCLK_DIV4 ADC_CLOCK_SYNC_PCLK_DIV4 /*!< Obsolete naming, kept for compatibility with some other devices */
  342. #define ADC_CLOCK_ASYNC_DIV1 ((uint32_t)0x00000000) /*!< ADC asynchronous clock not divided */
  343. #define ADC_CLOCK_ASYNC_DIV2 ((uint32_t)ADC_CCR_PRESC_0) /*!< ADC asynchronous clock divided by 2 */
  344. #define ADC_CLOCK_ASYNC_DIV4 ((uint32_t)ADC_CCR_PRESC_1) /*!< ADC asynchronous clock divided by 4 */
  345. #define ADC_CLOCK_ASYNC_DIV6 ((uint32_t)(ADC_CCR_PRESC_1|ADC_CCR_PRESC_0)) /*!< ADC asynchronous clock divided by 6 */
  346. #define ADC_CLOCK_ASYNC_DIV8 ((uint32_t)(ADC_CCR_PRESC_2)) /*!< ADC asynchronous clock divided by 8 */
  347. #define ADC_CLOCK_ASYNC_DIV10 ((uint32_t)(ADC_CCR_PRESC_2|ADC_CCR_PRESC_0)) /*!< ADC asynchronous clock divided by 10 */
  348. #define ADC_CLOCK_ASYNC_DIV12 ((uint32_t)(ADC_CCR_PRESC_2|ADC_CCR_PRESC_1)) /*!< ADC asynchronous clock divided by 12 */
  349. #define ADC_CLOCK_ASYNC_DIV16 ((uint32_t)(ADC_CCR_PRESC_2|ADC_CCR_PRESC_1|ADC_CCR_PRESC_0)) /*!< ADC asynchronous clock divided by 16 */
  350. #define ADC_CLOCK_ASYNC_DIV32 ((uint32_t)(ADC_CCR_PRESC_3)) /*!< ADC asynchronous clock divided by 32 */
  351. #define ADC_CLOCK_ASYNC_DIV64 ((uint32_t)(ADC_CCR_PRESC_3|ADC_CCR_PRESC_0)) /*!< ADC asynchronous clock divided by 64 */
  352. #define ADC_CLOCK_ASYNC_DIV128 ((uint32_t)(ADC_CCR_PRESC_3|ADC_CCR_PRESC_1)) /*!< ADC asynchronous clock divided by 128 */
  353. #define ADC_CLOCK_ASYNC_DIV256 ((uint32_t)(ADC_CCR_PRESC_3|ADC_CCR_PRESC_1|ADC_CCR_PRESC_0)) /*!< ADC asynchronous clock divided by 256 */
  354. /**
  355. * @}
  356. */
  357. /** @defgroup ADC_Resolution ADC Resolution
  358. * @{
  359. */
  360. #define ADC_RESOLUTION_12B ((uint32_t)0x00000000) /*!< ADC 12-bit resolution */
  361. #define ADC_RESOLUTION_10B ((uint32_t)ADC_CFGR_RES_0) /*!< ADC 10-bit resolution */
  362. #define ADC_RESOLUTION_8B ((uint32_t)ADC_CFGR_RES_1) /*!< ADC 8-bit resolution */
  363. #define ADC_RESOLUTION_6B ((uint32_t)ADC_CFGR_RES) /*!< ADC 6-bit resolution */
  364. /**
  365. * @}
  366. */
  367. /** @defgroup ADC_Data_align ADC Data Alignment
  368. * @{
  369. */
  370. #define ADC_DATAALIGN_RIGHT ((uint32_t)0x00000000) /*!< Data right alignment */
  371. #define ADC_DATAALIGN_LEFT ((uint32_t)ADC_CFGR_ALIGN) /*!< Data left alignment */
  372. /**
  373. * @}
  374. */
  375. /** @defgroup ADC_Scan_mode ADC Scan Mode
  376. * @{
  377. */
  378. #define ADC_SCAN_DISABLE ((uint32_t)0x00000000) /*!< Scan mode disabled */
  379. #define ADC_SCAN_ENABLE ((uint32_t)0x00000001) /*!< Scan mode enabled */
  380. /**
  381. * @}
  382. */
  383. /** @defgroup ADC_Regular_External_Trigger_Source_Edge ADC External Trigger Source Edge for Regular Group
  384. * @{
  385. */
  386. #define ADC_EXTERNALTRIGCONVEDGE_NONE ((uint32_t)0x00000000) /*!< Regular conversions hardware trigger detection disabled */
  387. #define ADC_EXTERNALTRIGCONVEDGE_RISING ((uint32_t)ADC_CFGR_EXTEN_0) /*!< Regular conversions hardware trigger detection on the rising edge */
  388. #define ADC_EXTERNALTRIGCONVEDGE_FALLING ((uint32_t)ADC_CFGR_EXTEN_1) /*!< Regular conversions hardware trigger detection on the falling edge */
  389. #define ADC_EXTERNALTRIGCONVEDGE_RISINGFALLING ((uint32_t)ADC_CFGR_EXTEN) /*!< Regular conversions hardware trigger detection on both the rising and falling edges */
  390. /**
  391. * @}
  392. */
  393. /** @defgroup ADC_Regular_External_Trigger_Source ADC External Trigger Source for Regular Group
  394. * @{
  395. */
  396. /* External triggers of ADC regular group */
  397. #define ADC_EXTERNALTRIG_T1_CC1 ((uint32_t)0x00000000) /*!< Event 0 triggers regular group conversion start */
  398. #define ADC_EXTERNALTRIG_T1_CC2 ((uint32_t)ADC_CFGR_EXTSEL_0) /*!< Event 1 triggers regular group conversion start */
  399. #define ADC_EXTERNALTRIG_T1_CC3 ((uint32_t)ADC_CFGR_EXTSEL_1) /*!< Event 2 triggers regular group conversion start */
  400. #define ADC_EXTERNALTRIG_T2_CC2 ((uint32_t)(ADC_CFGR_EXTSEL_1 | ADC_CFGR_EXTSEL_0)) /*!< Event 3 triggers regular group conversion start */
  401. #define ADC_EXTERNALTRIG_T3_TRGO ((uint32_t)ADC_CFGR_EXTSEL_2) /*!< Event 4 triggers regular group conversion start */
  402. #define ADC_EXTERNALTRIG_T4_CC4 ((uint32_t)(ADC_CFGR_EXTSEL_2 | ADC_CFGR_EXTSEL_0)) /*!< Event 5 triggers regular group conversion start */
  403. #define ADC_EXTERNALTRIG_EXT_IT11 ((uint32_t)(ADC_CFGR_EXTSEL_2 | ADC_CFGR_EXTSEL_1)) /*!< Event 6 triggers regular group conversion start */
  404. #define ADC_EXTERNALTRIG_T8_TRGO ((uint32_t)(ADC_CFGR_EXTSEL_2 | ADC_CFGR_EXTSEL_1 | ADC_CFGR_EXTSEL_0)) /*!< Event 7 triggers regular group conversion start */
  405. #define ADC_EXTERNALTRIG_T8_TRGO2 ((uint32_t) ADC_CFGR_EXTSEL_3) /*!< Event 8 triggers regular group conversion start */
  406. #define ADC_EXTERNALTRIG_T1_TRGO ((uint32_t)(ADC_CFGR_EXTSEL_3 | ADC_CFGR_EXTSEL_0)) /*!< Event 9 triggers regular group conversion start */
  407. #define ADC_EXTERNALTRIG_T1_TRGO2 ((uint32_t)(ADC_CFGR_EXTSEL_3 | ADC_CFGR_EXTSEL_1)) /*!< Event 10 triggers regular group conversion start */
  408. #define ADC_EXTERNALTRIG_T2_TRGO ((uint32_t)(ADC_CFGR_EXTSEL_3 | ADC_CFGR_EXTSEL_1 | ADC_CFGR_EXTSEL_0)) /*!< Event 11 triggers regular group conversion start */
  409. #define ADC_EXTERNALTRIG_T4_TRGO ((uint32_t)(ADC_CFGR_EXTSEL_3 | ADC_CFGR_EXTSEL_2)) /*!< Event 12 triggers regular group conversion start */
  410. #define ADC_EXTERNALTRIG_T6_TRGO ((uint32_t)(ADC_CFGR_EXTSEL_3 | ADC_CFGR_EXTSEL_2 | ADC_CFGR_EXTSEL_0)) /*!< Event 13 triggers regular group conversion start */
  411. #define ADC_EXTERNALTRIG_T15_TRGO ((uint32_t)(ADC_CFGR_EXTSEL_3 | ADC_CFGR_EXTSEL_2 | ADC_CFGR_EXTSEL_1)) /*!< Event 14 triggers regular group conversion start */
  412. #define ADC_EXTERNALTRIG_T3_CC4 ((uint32_t)ADC_CFGR_EXTSEL) /*!< Event 15 triggers regular group conversion start */
  413. #define ADC_SOFTWARE_START ((uint32_t)0x00000001) /*!< Software triggers regular group conversion start */
  414. /**
  415. * @}
  416. */
  417. /** @defgroup ADC_EOCSelection ADC End of Regular Sequence/Conversion
  418. * @{
  419. */
  420. #define ADC_EOC_SINGLE_CONV ((uint32_t) ADC_ISR_EOC) /*!< End of conversion flag */
  421. #define ADC_EOC_SEQ_CONV ((uint32_t) ADC_ISR_EOS) /*!< End of sequence flag */
  422. #define ADC_EOC_SINGLE_SEQ_CONV ((uint32_t)(ADC_ISR_EOC | ADC_ISR_EOS)) /*!< Reserved for future use */
  423. /**
  424. * @}
  425. */
  426. /** @defgroup ADC_Overrun ADC overrun
  427. * @{
  428. */
  429. #define ADC_OVR_DATA_PRESERVED ((uint32_t)0x00000000) /*!< Data preserved in case of overrun */
  430. #define ADC_OVR_DATA_OVERWRITTEN ((uint32_t)ADC_CFGR_OVRMOD) /*!< Data overwritten in case of overrun */
  431. /**
  432. * @}
  433. */
  434. /** @defgroup ADC_channels ADC Channels
  435. * @{
  436. */
  437. #define ADC_CHANNEL_0 ((uint32_t)(0x00000000)) /*!< ADC channel 0 */
  438. #define ADC_CHANNEL_1 ((uint32_t)(ADC_SQR3_SQ10_0)) /*!< ADC channel 1 */
  439. #define ADC_CHANNEL_2 ((uint32_t)(ADC_SQR3_SQ10_1)) /*!< ADC channel 2 */
  440. #define ADC_CHANNEL_3 ((uint32_t)(ADC_SQR3_SQ10_1 | ADC_SQR3_SQ10_0)) /*!< ADC channel 3 */
  441. #define ADC_CHANNEL_4 ((uint32_t)(ADC_SQR3_SQ10_2)) /*!< ADC channel 4 */
  442. #define ADC_CHANNEL_5 ((uint32_t)(ADC_SQR3_SQ10_2 | ADC_SQR3_SQ10_0)) /*!< ADC channel 5 */
  443. #define ADC_CHANNEL_6 ((uint32_t)(ADC_SQR3_SQ10_2 | ADC_SQR3_SQ10_1)) /*!< ADC channel 6 */
  444. #define ADC_CHANNEL_7 ((uint32_t)(ADC_SQR3_SQ10_2 | ADC_SQR3_SQ10_1 | ADC_SQR3_SQ10_0)) /*!< ADC channel 7 */
  445. #define ADC_CHANNEL_8 ((uint32_t)(ADC_SQR3_SQ10_3)) /*!< ADC channel 8 */
  446. #define ADC_CHANNEL_9 ((uint32_t)(ADC_SQR3_SQ10_3 | ADC_SQR3_SQ10_0)) /*!< ADC channel 9 */
  447. #define ADC_CHANNEL_10 ((uint32_t)(ADC_SQR3_SQ10_3 | ADC_SQR3_SQ10_1)) /*!< ADC channel 10 */
  448. #define ADC_CHANNEL_11 ((uint32_t)(ADC_SQR3_SQ10_3 | ADC_SQR3_SQ10_1 | ADC_SQR3_SQ10_0)) /*!< ADC channel 11 */
  449. #define ADC_CHANNEL_12 ((uint32_t)(ADC_SQR3_SQ10_3 | ADC_SQR3_SQ10_2)) /*!< ADC channel 12 */
  450. #define ADC_CHANNEL_13 ((uint32_t)(ADC_SQR3_SQ10_3 | ADC_SQR3_SQ10_2 | ADC_SQR3_SQ10_0)) /*!< ADC channel 13 */
  451. #define ADC_CHANNEL_14 ((uint32_t)(ADC_SQR3_SQ10_3 | ADC_SQR3_SQ10_2 | ADC_SQR3_SQ10_1)) /*!< ADC channel 14 */
  452. #define ADC_CHANNEL_15 ((uint32_t)(ADC_SQR3_SQ10_3 | ADC_SQR3_SQ10_2 | ADC_SQR3_SQ10_1 | ADC_SQR3_SQ10_0)) /*!< ADC channel 15 */
  453. #define ADC_CHANNEL_16 ((uint32_t)(ADC_SQR3_SQ10_4)) /*!< ADC channel 16 */
  454. #define ADC_CHANNEL_17 ((uint32_t)(ADC_SQR3_SQ10_4 | ADC_SQR3_SQ10_0)) /*!< ADC channel 17 */
  455. #define ADC_CHANNEL_18 ((uint32_t)(ADC_SQR3_SQ10_4 | ADC_SQR3_SQ10_1)) /*!< ADC channel 18 */
  456. /* Note: VrefInt, TempSensor and Vbat internal channels are not available on all ADC's
  457. (information present in Reference Manual) */
  458. #define ADC_CHANNEL_TEMPSENSOR ADC_CHANNEL_17 /*!< ADC temperature sensor channel */
  459. #define ADC_CHANNEL_VBAT ADC_CHANNEL_18 /*!< ADC Vbat channel */
  460. #define ADC_CHANNEL_VREFINT ADC_CHANNEL_0 /*!< ADC Vrefint channel */
  461. /**
  462. * @}
  463. */
  464. /** @defgroup ADC_sampling_times ADC Sampling Times
  465. * @{
  466. */
  467. #define ADC_SAMPLETIME_2CYCLES_5 ((uint32_t)0x00000000) /*!< Sampling time 2.5 ADC clock cycle */
  468. #define ADC_SAMPLETIME_6CYCLES_5 ((uint32_t)ADC_SMPR2_SMP10_0) /*!< Sampling time 6.5 ADC clock cycles */
  469. #define ADC_SAMPLETIME_12CYCLES_5 ((uint32_t)ADC_SMPR2_SMP10_1) /*!< Sampling time 12.5 ADC clock cycles */
  470. #define ADC_SAMPLETIME_24CYCLES_5 ((uint32_t)(ADC_SMPR2_SMP10_1 | ADC_SMPR2_SMP10_0)) /*!< Sampling time 24.5 ADC clock cycles */
  471. #define ADC_SAMPLETIME_47CYCLES_5 ((uint32_t)ADC_SMPR2_SMP10_2) /*!< Sampling time 47.5 ADC clock cycles */
  472. #define ADC_SAMPLETIME_92CYCLES_5 ((uint32_t)(ADC_SMPR2_SMP10_2 | ADC_SMPR2_SMP10_0)) /*!< Sampling time 92.5 ADC clock cycles */
  473. #define ADC_SAMPLETIME_247CYCLES_5 ((uint32_t)(ADC_SMPR2_SMP10_2 | ADC_SMPR2_SMP10_1)) /*!< Sampling time 247.5 ADC clock cycles */
  474. #define ADC_SAMPLETIME_640CYCLES_5 ((uint32_t)ADC_SMPR2_SMP10) /*!< Sampling time 640.5 ADC clock cycles */
  475. /**
  476. * @}
  477. */
  478. /**
  479. * @}
  480. */
  481. /* Private macros ------------------------------------------------------------*/
  482. /** @defgroup ADC_Private_Macro ADC Private Macros
  483. * @{
  484. */
  485. /**
  486. * @brief Test if conversion trigger of regular group is software start
  487. * or external trigger.
  488. * @param __HANDLE__: ADC handle.
  489. * @retval SET (software start) or RESET (external trigger)
  490. */
  491. #define ADC_IS_SOFTWARE_START_REGULAR(__HANDLE__) \
  492. (((__HANDLE__)->Instance->CFGR & ADC_CFGR_EXTEN) == RESET)
  493. /**
  494. * @brief Return resolution bits in CFGR register RES[1:0] field.
  495. * @param __HANDLE__: ADC handle.
  496. * @retval 2-bit field RES of CFGR register.
  497. */
  498. #define ADC_GET_RESOLUTION(__HANDLE__) (((__HANDLE__)->Instance->CFGR) & ADC_CFGR_RES)
  499. /**
  500. * @brief Clear ADC error code (set it to no error code "HAL_ADC_ERROR_NONE").
  501. * @param __HANDLE__: ADC handle.
  502. * @retval None
  503. */
  504. #define ADC_CLEAR_ERRORCODE(__HANDLE__) ((__HANDLE__)->ErrorCode = HAL_ADC_ERROR_NONE)
  505. /**
  506. * @brief Verification of ADC state: enabled or disabled.
  507. * @param __HANDLE__: ADC handle.
  508. * @retval SET (ADC enabled) or RESET (ADC disabled)
  509. */
  510. #define ADC_IS_ENABLE(__HANDLE__) \
  511. (( ((((__HANDLE__)->Instance->CR) & (ADC_CR_ADEN | ADC_CR_ADDIS)) == ADC_CR_ADEN) && \
  512. ((((__HANDLE__)->Instance->ISR) & ADC_FLAG_RDY) == ADC_FLAG_RDY) \
  513. ) ? SET : RESET)
  514. /**
  515. * @brief Check if conversion is on going on regular group.
  516. * @param __HANDLE__: ADC handle.
  517. * @retval SET (conversion is on going) or RESET (no conversion is on going)
  518. */
  519. #define ADC_IS_CONVERSION_ONGOING_REGULAR(__HANDLE__) \
  520. (( (((__HANDLE__)->Instance->CR) & ADC_CR_ADSTART) == RESET \
  521. ) ? RESET : SET)
  522. /**
  523. * @brief Simultaneously clear and set specific bits of the handle State.
  524. * @note ADC_STATE_CLR_SET() macro is merely aliased to generic macro MODIFY_REG(),
  525. * the first parameter is the ADC handle State, the second parameter is the
  526. * bit field to clear, the third and last parameter is the bit field to set.
  527. * @retval None
  528. */
  529. #define ADC_STATE_CLR_SET MODIFY_REG
  530. /**
  531. * @brief Verify that a given value is aligned with the ADC resolution range.
  532. * @param __RESOLUTION__: ADC resolution (12, 10, 8 or 6 bits).
  533. * @param __ADC_VALUE__: value checked against the resolution.
  534. * @retval SET (__ADC_VALUE__ in line with __RESOLUTION__) or RESET (__ADC_VALUE__ not in line with __RESOLUTION__)
  535. */
  536. #define IS_ADC_RANGE(__RESOLUTION__, __ADC_VALUE__) \
  537. ((((__RESOLUTION__) == ADC_RESOLUTION_12B) && ((__ADC_VALUE__) <= ((uint32_t)0x0FFF))) || \
  538. (((__RESOLUTION__) == ADC_RESOLUTION_10B) && ((__ADC_VALUE__) <= ((uint32_t)0x03FF))) || \
  539. (((__RESOLUTION__) == ADC_RESOLUTION_8B) && ((__ADC_VALUE__) <= ((uint32_t)0x00FF))) || \
  540. (((__RESOLUTION__) == ADC_RESOLUTION_6B) && ((__ADC_VALUE__) <= ((uint32_t)0x003F))) )
  541. /**
  542. * @brief Verify the length of the scheduled regular conversions group.
  543. * @param __LENGTH__: number of programmed conversions.
  544. * @retval SET (__LENGTH__ is within the maximum number of possible programmable regular conversions) or RESET (__LENGTH__ is null or too large)
  545. */
  546. #define IS_ADC_REGULAR_NB_CONV(__LENGTH__) (((__LENGTH__) >= ((uint32_t)1)) && ((__LENGTH__) <= ((uint32_t)16)))
  547. /**
  548. * @brief Verify the number of scheduled regular conversions in discontinuous mode.
  549. * @param NUMBER: number of scheduled regular conversions in discontinuous mode.
  550. * @retval SET (NUMBER is within the maximum number of regular conversions in discontinous mode) or RESET (NUMBER is null or too large)
  551. */
  552. #define IS_ADC_REGULAR_DISCONT_NUMBER(NUMBER) (((NUMBER) >= ((uint32_t)1)) && ((NUMBER) <= ((uint32_t)8)))
  553. /**
  554. * @brief Verify the ADC clock setting.
  555. * @param __ADC_CLOCK__: programmed ADC clock.
  556. * @retval SET (__ADC_CLOCK__ is a valid value) or RESET (__ADC_CLOCK__ is invalid)
  557. */
  558. #define IS_ADC_CLOCKPRESCALER(__ADC_CLOCK__) (((__ADC_CLOCK__) == ADC_CLOCK_SYNC_PCLK_DIV1) || \
  559. ((__ADC_CLOCK__) == ADC_CLOCK_SYNC_PCLK_DIV2) || \
  560. ((__ADC_CLOCK__) == ADC_CLOCK_SYNC_PCLK_DIV4) || \
  561. ((__ADC_CLOCK__) == ADC_CLOCK_ASYNC_DIV1) || \
  562. ((__ADC_CLOCK__) == ADC_CLOCK_ASYNC_DIV2) || \
  563. ((__ADC_CLOCK__) == ADC_CLOCK_ASYNC_DIV4) || \
  564. ((__ADC_CLOCK__) == ADC_CLOCK_ASYNC_DIV6) || \
  565. ((__ADC_CLOCK__) == ADC_CLOCK_ASYNC_DIV8) || \
  566. ((__ADC_CLOCK__) == ADC_CLOCK_ASYNC_DIV10) || \
  567. ((__ADC_CLOCK__) == ADC_CLOCK_ASYNC_DIV12) || \
  568. ((__ADC_CLOCK__) == ADC_CLOCK_ASYNC_DIV16) || \
  569. ((__ADC_CLOCK__) == ADC_CLOCK_ASYNC_DIV32) || \
  570. ((__ADC_CLOCK__) == ADC_CLOCK_ASYNC_DIV64) || \
  571. ((__ADC_CLOCK__) == ADC_CLOCK_ASYNC_DIV128) || \
  572. ((__ADC_CLOCK__) == ADC_CLOCK_ASYNC_DIV256) )
  573. /**
  574. * @brief Verify the ADC resolution setting.
  575. * @param __RESOLUTION__: programmed ADC resolution.
  576. * @retval SET (__RESOLUTION__ is a valid value) or RESET (__RESOLUTION__ is invalid)
  577. */
  578. #define IS_ADC_RESOLUTION(__RESOLUTION__) (((__RESOLUTION__) == ADC_RESOLUTION_12B) || \
  579. ((__RESOLUTION__) == ADC_RESOLUTION_10B) || \
  580. ((__RESOLUTION__) == ADC_RESOLUTION_8B) || \
  581. ((__RESOLUTION__) == ADC_RESOLUTION_6B) )
  582. /**
  583. * @brief Verify the ADC resolution setting when limited to 6 or 8 bits.
  584. * @param __RESOLUTION__: programmed ADC resolution when limited to 6 or 8 bits.
  585. * @retval SET (__RESOLUTION__ is a valid value) or RESET (__RESOLUTION__ is invalid)
  586. */
  587. #define IS_ADC_RESOLUTION_8_6_BITS(__RESOLUTION__) (((__RESOLUTION__) == ADC_RESOLUTION_8B) || \
  588. ((__RESOLUTION__) == ADC_RESOLUTION_6B) )
  589. /**
  590. * @brief Verify the ADC converted data alignment.
  591. * @param __ALIGN__: programmed ADC converted data alignment.
  592. * @retval SET (__ALIGN__ is a valid value) or RESET (__ALIGN__ is invalid)
  593. */
  594. #define IS_ADC_DATA_ALIGN(__ALIGN__) (((__ALIGN__) == ADC_DATAALIGN_RIGHT) || \
  595. ((__ALIGN__) == ADC_DATAALIGN_LEFT) )
  596. /**
  597. * @brief Verify the ADC scan mode.
  598. * @param __SCAN_MODE__: programmed ADC scan mode.
  599. * @retval SET (__SCAN_MODE__ is valid) or RESET (__SCAN_MODE__ is invalid)
  600. */
  601. #define IS_ADC_SCAN_MODE(__SCAN_MODE__) (((__SCAN_MODE__) == ADC_SCAN_DISABLE) || \
  602. ((__SCAN_MODE__) == ADC_SCAN_ENABLE) )
  603. /**
  604. * @brief Verify the ADC edge trigger setting for regular group.
  605. * @param __EDGE__: programmed ADC edge trigger setting.
  606. * @retval SET (__EDGE__ is a valid value) or RESET (__EDGE__ is invalid)
  607. */
  608. #define IS_ADC_EXTTRIG_EDGE(__EDGE__) (((__EDGE__) == ADC_EXTERNALTRIGCONVEDGE_NONE) || \
  609. ((__EDGE__) == ADC_EXTERNALTRIGCONVEDGE_RISING) || \
  610. ((__EDGE__) == ADC_EXTERNALTRIGCONVEDGE_FALLING) || \
  611. ((__EDGE__) == ADC_EXTERNALTRIGCONVEDGE_RISINGFALLING) )
  612. /**
  613. * @brief Verify the ADC regular conversions external trigger.
  614. * @param __REGTRIG__: programmed ADC regular conversions external trigger.
  615. * @retval SET (__REGTRIG__ is a valid value) or RESET (__REGTRIG__ is invalid)
  616. */
  617. #define IS_ADC_EXTTRIG(__REGTRIG__) (((__REGTRIG__) == ADC_EXTERNALTRIG_T1_CC1) || \
  618. ((__REGTRIG__) == ADC_EXTERNALTRIG_T1_CC2) || \
  619. ((__REGTRIG__) == ADC_EXTERNALTRIG_T1_CC3) || \
  620. ((__REGTRIG__) == ADC_EXTERNALTRIG_T2_CC2) || \
  621. ((__REGTRIG__) == ADC_EXTERNALTRIG_T3_TRGO) || \
  622. ((__REGTRIG__) == ADC_EXTERNALTRIG_T4_CC4) || \
  623. ((__REGTRIG__) == ADC_EXTERNALTRIG_EXT_IT11) || \
  624. ((__REGTRIG__) == ADC_EXTERNALTRIG_T8_TRGO) || \
  625. ((__REGTRIG__) == ADC_EXTERNALTRIG_T8_TRGO2) || \
  626. ((__REGTRIG__) == ADC_EXTERNALTRIG_T1_TRGO) || \
  627. ((__REGTRIG__) == ADC_EXTERNALTRIG_T1_TRGO2) || \
  628. ((__REGTRIG__) == ADC_EXTERNALTRIG_T2_TRGO) || \
  629. ((__REGTRIG__) == ADC_EXTERNALTRIG_T4_TRGO) || \
  630. ((__REGTRIG__) == ADC_EXTERNALTRIG_T6_TRGO) || \
  631. ((__REGTRIG__) == ADC_EXTERNALTRIG_T15_TRGO) || \
  632. ((__REGTRIG__) == ADC_EXTERNALTRIG_T3_CC4) || \
  633. \
  634. ((__REGTRIG__) == ADC_SOFTWARE_START) )
  635. /**
  636. * @brief Verify the ADC regular conversions check for converted data availability.
  637. * @param __EOC_SELECTION__: converted data availability check.
  638. * @retval SET (__EOC_SELECTION__ is a valid value) or RESET (__EOC_SELECTION__ is invalid)
  639. */
  640. #define IS_ADC_EOC_SELECTION(__EOC_SELECTION__) (((__EOC_SELECTION__) == ADC_EOC_SINGLE_CONV) || \
  641. ((__EOC_SELECTION__) == ADC_EOC_SEQ_CONV) || \
  642. ((__EOC_SELECTION__) == ADC_EOC_SINGLE_SEQ_CONV) )
  643. /**
  644. * @brief Verify the ADC regular conversions overrun handling.
  645. * @param __OVR__: ADC regular conversions overrun handling.
  646. * @retval SET (__OVR__ is a valid value) or RESET (__OVR__ is invalid)
  647. */
  648. #define IS_ADC_OVERRUN(__OVR__) (((__OVR__) == ADC_OVR_DATA_PRESERVED) || \
  649. ((__OVR__) == ADC_OVR_DATA_OVERWRITTEN) )
  650. /**
  651. * @brief Verify the ADC conversions sampling time.
  652. * @param __TIME__: ADC conversions sampling time.
  653. * @retval SET (__TIME__ is a valid value) or RESET (__TIME__ is invalid)
  654. */
  655. #define IS_ADC_SAMPLE_TIME(__TIME__) (((__TIME__) == ADC_SAMPLETIME_2CYCLE_5) || \
  656. ((__TIME__) == ADC_SAMPLETIME_6CYCLES_5) || \
  657. ((__TIME__) == ADC_SAMPLETIME_12CYCLES_5) || \
  658. ((__TIME__) == ADC_SAMPLETIME_24CYCLES_5) || \
  659. ((__TIME__) == ADC_SAMPLETIME_47CYCLES_5) || \
  660. ((__TIME__) == ADC_SAMPLETIME_92CYCLES_5) || \
  661. ((__TIME__) == ADC_SAMPLETIME_247CYCLES_5) || \
  662. ((__TIME__) == ADC_SAMPLETIME_640CYCLES_5) )
  663. /**
  664. * @}
  665. */
  666. /* Private constants ---------------------------------------------------------*/
  667. /** @defgroup ADC_Private_Constants ADC Private Constants
  668. * @{
  669. */
  670. /* Fixed timeout values for ADC conversion (including sampling time) */
  671. /* Maximum sampling time is 640.5 ADC clock cycle (SMPx[2:0] = 0b111 */
  672. /* Maximum conversion time is 12.5 + Maximum sampling time */
  673. /* or 12.5 + 640.5 = 653 ADC clock cycles */
  674. /* Minimum ADC Clock frequency is 0.14 MHz */
  675. /* Maximum conversion time is */
  676. /* 653 / 0.14 MHz = 4.66 ms */
  677. #define ADC_STOP_CONVERSION_TIMEOUT ((uint32_t) 5) /*!< ADC stop time-out value */
  678. /* Delay for temperature sensor stabilization time. */
  679. /* Maximum delay is 120us (refer device datasheet, parameter tSTART). */
  680. /* Unit: us */
  681. #define ADC_TEMPSENSOR_DELAY_US ((uint32_t) 120)
  682. /**
  683. * @}
  684. */
  685. /* Exported macros -----------------------------------------------------------*/
  686. /** @defgroup ADC_Exported_Macro ADC Exported Macros
  687. * @{
  688. */
  689. /** @brief Reset ADC handle state.
  690. * @param __HANDLE__: ADC handle.
  691. * @retval None
  692. */
  693. #define __HAL_ADC_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_ADC_STATE_RESET)
  694. /** @brief Check whether the specified ADC interrupt source is enabled or not.
  695. * @param __HANDLE__: ADC handle.
  696. * @param __INTERRUPT__: ADC interrupt source to check
  697. * This parameter can be one of the following values:
  698. * @arg @ref ADC_IT_RDY, ADC Ready (ADRDY) interrupt source
  699. * @arg @ref ADC_IT_EOSMP, ADC End of Sampling interrupt source
  700. * @arg @ref ADC_IT_EOC, ADC End of Regular Conversion interrupt source
  701. * @arg @ref ADC_IT_EOS, ADC End of Regular sequence of Conversions interrupt source
  702. * @arg @ref ADC_IT_OVR, ADC overrun interrupt source
  703. * @arg @ref ADC_IT_JEOC, ADC End of Injected Conversion interrupt source
  704. * @arg @ref ADC_IT_JEOS, ADC End of Injected sequence of Conversions interrupt source
  705. * @arg @ref ADC_IT_AWD1, ADC Analog watchdog 1 interrupt source (main analog watchdog)
  706. * @arg @ref ADC_IT_AWD2, ADC Analog watchdog 2 interrupt source (additional analog watchdog)
  707. * @arg @ref ADC_IT_AWD3, ADC Analog watchdog 3 interrupt source (additional analog watchdog)
  708. * @arg @ref ADC_IT_JQOVF, ADC Injected Context Queue Overflow interrupt source.
  709. * @retval State of interruption (SET or RESET)
  710. */
  711. #define __HAL_ADC_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) \
  712. (( ((__HANDLE__)->Instance->IER & (__INTERRUPT__)) == (__INTERRUPT__) \
  713. )? SET : RESET \
  714. )
  715. /**
  716. * @brief Enable an ADC interrupt.
  717. * @param __HANDLE__: ADC handle.
  718. * @param __INTERRUPT__: ADC Interrupt to enable
  719. * This parameter can be one of the following values:
  720. * @arg @ref ADC_IT_RDY, ADC Ready (ADRDY) interrupt source
  721. * @arg @ref ADC_IT_EOSMP, ADC End of Sampling interrupt source
  722. * @arg @ref ADC_IT_EOC, ADC End of Regular Conversion interrupt source
  723. * @arg @ref ADC_IT_EOS, ADC End of Regular sequence of Conversions interrupt source
  724. * @arg @ref ADC_IT_OVR, ADC overrun interrupt source
  725. * @arg @ref ADC_IT_JEOC, ADC End of Injected Conversion interrupt source
  726. * @arg @ref ADC_IT_JEOS, ADC End of Injected sequence of Conversions interrupt source
  727. * @arg @ref ADC_IT_AWD1, ADC Analog watchdog 1 interrupt source (main analog watchdog)
  728. * @arg @ref ADC_IT_AWD2, ADC Analog watchdog 2 interrupt source (additional analog watchdog)
  729. * @arg @ref ADC_IT_AWD3, ADC Analog watchdog 3 interrupt source (additional analog watchdog)
  730. * @arg @ref ADC_IT_JQOVF, ADC Injected Context Queue Overflow interrupt source.
  731. * @retval None
  732. */
  733. #define __HAL_ADC_ENABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->IER) |= (__INTERRUPT__))
  734. /**
  735. * @brief Disable an ADC interrupt.
  736. * @param __HANDLE__: ADC handle.
  737. * @param __INTERRUPT__: ADC Interrupt to disable
  738. * @arg @ref ADC_IT_RDY, ADC Ready (ADRDY) interrupt source
  739. * @arg @ref ADC_IT_EOSMP, ADC End of Sampling interrupt source
  740. * @arg @ref ADC_IT_EOC, ADC End of Regular Conversion interrupt source
  741. * @arg @ref ADC_IT_EOS, ADC End of Regular sequence of Conversions interrupt source
  742. * @arg @ref ADC_IT_OVR, ADC overrun interrupt source
  743. * @arg @ref ADC_IT_JEOC, ADC End of Injected Conversion interrupt source
  744. * @arg @ref ADC_IT_JEOS, ADC End of Injected sequence of Conversions interrupt source
  745. * @arg @ref ADC_IT_AWD1, ADC Analog watchdog 1 interrupt source (main analog watchdog)
  746. * @arg @ref ADC_IT_AWD2, ADC Analog watchdog 2 interrupt source (additional analog watchdog)
  747. * @arg @ref ADC_IT_AWD3, ADC Analog watchdog 3 interrupt source (additional analog watchdog)
  748. * @arg @ref ADC_IT_JQOVF, ADC Injected Context Queue Overflow interrupt source.
  749. * @retval None
  750. */
  751. #define __HAL_ADC_DISABLE_IT(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->IER) &= ~(__INTERRUPT__))
  752. /**
  753. * @brief Check whether the specified ADC flag is set or not.
  754. * @param __HANDLE__: ADC handle.
  755. * @param __FLAG__: ADC flag to check
  756. * This parameter can be one of the following values:
  757. * @arg @ref ADC_FLAG_RDY, ADC Ready (ADRDY) flag
  758. * @arg @ref ADC_FLAG_EOSMP, ADC End of Sampling flag
  759. * @arg @ref ADC_FLAG_EOC, ADC End of Regular Conversion flag
  760. * @arg @ref ADC_FLAG_EOS, ADC End of Regular sequence of Conversions flag
  761. * @arg @ref ADC_FLAG_OVR, ADC overrun flag
  762. * @arg @ref ADC_FLAG_JEOC, ADC End of Injected Conversion flag
  763. * @arg @ref ADC_FLAG_JEOS, ADC End of Injected sequence of Conversions flag
  764. * @arg @ref ADC_FLAG_AWD1, ADC Analog watchdog 1 flag (main analog watchdog)
  765. * @arg @ref ADC_FLAG_AWD2, ADC Analog watchdog 2 flag (additional analog watchdog)
  766. * @arg @ref ADC_FLAG_AWD3, ADC Analog watchdog 3 flag (additional analog watchdog)
  767. * @arg @ref ADC_FLAG_JQOVF, ADC Injected Context Queue Overflow flag.
  768. * @retval The new state of __FLAG__ (TRUE or FALSE).
  769. */
  770. #define __HAL_ADC_GET_FLAG(__HANDLE__, __FLAG__) ((((__HANDLE__)->Instance->ISR) & (__FLAG__)) == (__FLAG__))
  771. /**
  772. * @brief Clear a specified ADC flag.
  773. * @param __HANDLE__: ADC handle.
  774. * @param __FLAG__: ADC flag to clear
  775. * This parameter can be one of the following values:
  776. * @arg @ref ADC_FLAG_RDY, ADC Ready (ADRDY) flag
  777. * @arg @ref ADC_FLAG_EOSMP, ADC End of Sampling flag
  778. * @arg @ref ADC_FLAG_EOC, ADC End of Regular Conversion flag
  779. * @arg @ref ADC_FLAG_EOS, ADC End of Regular sequence of Conversions flag
  780. * @arg @ref ADC_FLAG_OVR, ADC overrun flag
  781. * @arg @ref ADC_FLAG_JEOC, ADC End of Injected Conversion flag
  782. * @arg @ref ADC_FLAG_JEOS, ADC End of Injected sequence of Conversions flag
  783. * @arg @ref ADC_FLAG_AWD1, ADC Analog watchdog 1 flag (main analog watchdog)
  784. * @arg @ref ADC_FLAG_AWD2, ADC Analog watchdog 2 flag (additional analog watchdog)
  785. * @arg @ref ADC_FLAG_AWD3, ADC Analog watchdog 3 flag (additional analog watchdog)
  786. * @arg @ref ADC_FLAG_JQOVF, ADC Injected Context Queue Overflow flag.
  787. * @note Bit cleared bit by writing 1 (writing 0 has no effect on any bit of register ISR).
  788. * @retval None
  789. */
  790. #define __HAL_ADC_CLEAR_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->ISR) = (__FLAG__))
  791. /**
  792. * @}
  793. */
  794. /* Include ADC HAL Extended module */
  795. #include "stm32l4xx_hal_adc_ex.h"
  796. /* Exported functions --------------------------------------------------------*/
  797. /** @addtogroup ADC_Exported_Functions ADC Exported Functions
  798. * @{
  799. */
  800. /** @addtogroup ADC_Exported_Functions_Group1 Initialization and de-initialization functions
  801. * @brief Initialization and Configuration functions
  802. * @{
  803. */
  804. /* Initialization and de-initialization functions **********************************/
  805. HAL_StatusTypeDef HAL_ADC_Init(ADC_HandleTypeDef* hadc);
  806. HAL_StatusTypeDef HAL_ADC_DeInit(ADC_HandleTypeDef *hadc);
  807. void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc);
  808. void HAL_ADC_MspDeInit(ADC_HandleTypeDef* hadc);
  809. /**
  810. * @}
  811. */
  812. /** @addtogroup ADC_Exported_Functions_Group2 Input and Output operation functions
  813. * @brief IO operation functions
  814. * @{
  815. */
  816. /* Blocking mode: Polling */
  817. HAL_StatusTypeDef HAL_ADC_Start(ADC_HandleTypeDef* hadc);
  818. HAL_StatusTypeDef HAL_ADC_Stop(ADC_HandleTypeDef* hadc);
  819. HAL_StatusTypeDef HAL_ADC_PollForConversion(ADC_HandleTypeDef* hadc, uint32_t Timeout);
  820. HAL_StatusTypeDef HAL_ADC_PollForEvent(ADC_HandleTypeDef* hadc, uint32_t EventType, uint32_t Timeout);
  821. /* Non-blocking mode: Interruption */
  822. HAL_StatusTypeDef HAL_ADC_Start_IT(ADC_HandleTypeDef* hadc);
  823. HAL_StatusTypeDef HAL_ADC_Stop_IT(ADC_HandleTypeDef* hadc);
  824. /* Non-blocking mode: DMA */
  825. HAL_StatusTypeDef HAL_ADC_Start_DMA(ADC_HandleTypeDef* hadc, uint32_t* pData, uint32_t Length);
  826. HAL_StatusTypeDef HAL_ADC_Stop_DMA(ADC_HandleTypeDef* hadc);
  827. /* ADC retrieve conversion value intended to be used with polling or interruption */
  828. uint32_t HAL_ADC_GetValue(ADC_HandleTypeDef* hadc);
  829. /* ADC IRQHandler and Callbacks used in non-blocking modes (Interruption and DMA) */
  830. void HAL_ADC_IRQHandler(ADC_HandleTypeDef* hadc);
  831. void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc);
  832. void HAL_ADC_ConvHalfCpltCallback(ADC_HandleTypeDef* hadc);
  833. void HAL_ADC_LevelOutOfWindowCallback(ADC_HandleTypeDef* hadc);
  834. void HAL_ADC_ErrorCallback(ADC_HandleTypeDef *hadc);
  835. /**
  836. * @}
  837. */
  838. /** @addtogroup ADC_Exported_Functions_Group3 Peripheral Control functions
  839. * @brief Peripheral Control functions
  840. * @{
  841. */
  842. /* Peripheral Control functions ***********************************************/
  843. HAL_StatusTypeDef HAL_ADC_ConfigChannel(ADC_HandleTypeDef* hadc, ADC_ChannelConfTypeDef* sConfig);
  844. HAL_StatusTypeDef HAL_ADC_AnalogWDGConfig(ADC_HandleTypeDef* hadc, ADC_AnalogWDGConfTypeDef* AnalogWDGConfig);
  845. /**
  846. * @}
  847. */
  848. /** @defgroup ADC_Exported_Functions_Group4 Peripheral State functions
  849. * @brief ADC Peripheral State functions
  850. * @{
  851. */
  852. /* Peripheral State functions *************************************************/
  853. uint32_t HAL_ADC_GetState(ADC_HandleTypeDef* hadc);
  854. uint32_t HAL_ADC_GetError(ADC_HandleTypeDef *hadc);
  855. /**
  856. * @}
  857. */
  858. /**
  859. * @}
  860. */
  861. /* Private functions -----------------------------------------------------------*/
  862. /** @addtogroup ADC_Private_Functions ADC Private Functions
  863. * @{
  864. */
  865. HAL_StatusTypeDef ADC_ConversionStop(ADC_HandleTypeDef* hadc, uint32_t ConversionGroup);
  866. HAL_StatusTypeDef ADC_Enable(ADC_HandleTypeDef* hadc);
  867. HAL_StatusTypeDef ADC_Disable(ADC_HandleTypeDef* hadc);
  868. void ADC_DMAConvCplt(DMA_HandleTypeDef *hdma);
  869. void ADC_DMAHalfConvCplt(DMA_HandleTypeDef *hdma);
  870. void ADC_DMAError(DMA_HandleTypeDef *hdma);
  871. /**
  872. * @}
  873. */
  874. /**
  875. * @}
  876. */
  877. /**
  878. * @}
  879. */
  880. #ifdef __cplusplus
  881. }
  882. #endif
  883. #endif /*__STM32L4xx_ADC_H */
  884. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/