stm32l4xx_hal_adc.h 120 KB

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