stm32h5xx_hal_adc.h 123 KB

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