stm32l5xx_hal_adc.h 116 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916
  1. /**
  2. ******************************************************************************
  3. * @file stm32l5xx_hal_adc.h
  4. * @author MCD Application Team
  5. * @brief Header file of ADC HAL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) 2019 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 STM32L5xx_HAL_ADC_H
  20. #define STM32L5xx_HAL_ADC_H
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. /* Includes ------------------------------------------------------------------*/
  25. #include "stm32l5xx_hal_def.h"
  26. /* Include low level driver */
  27. #include "stm32l5xx_ll_adc.h"
  28. /** @addtogroup STM32L5xx_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(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. #define ADC_SAMPLETIME_3CYCLES_5 (ADC_SMPR1_SMPPLUS | LL_ADC_SAMPLINGTIME_2CYCLES_5) /*!< Sampling time 3.5
  650. ADC clock cycles. If selected, this sampling time replaces sampling time
  651. 2.5 ADC clock cycles. These 2 sampling times cannot be used simultaneously. */
  652. /**
  653. * @}
  654. */
  655. /** @defgroup ADC_HAL_EC_CHANNEL ADC instance - Channel number
  656. * @{
  657. */
  658. /* Note: VrefInt, TempSensor and Vbat internal channels are not available on */
  659. /* all ADC instances (refer to Reference Manual). */
  660. #define ADC_CHANNEL_0 (LL_ADC_CHANNEL_0) /*!< External channel (GPIO pin) ADCx_IN0 */
  661. #define ADC_CHANNEL_1 (LL_ADC_CHANNEL_1) /*!< External channel (GPIO pin) ADCx_IN1 */
  662. #define ADC_CHANNEL_2 (LL_ADC_CHANNEL_2) /*!< External channel (GPIO pin) ADCx_IN2 */
  663. #define ADC_CHANNEL_3 (LL_ADC_CHANNEL_3) /*!< External channel (GPIO pin) ADCx_IN3 */
  664. #define ADC_CHANNEL_4 (LL_ADC_CHANNEL_4) /*!< External channel (GPIO pin) ADCx_IN4 */
  665. #define ADC_CHANNEL_5 (LL_ADC_CHANNEL_5) /*!< External channel (GPIO pin) ADCx_IN5 */
  666. #define ADC_CHANNEL_6 (LL_ADC_CHANNEL_6) /*!< External channel (GPIO pin) ADCx_IN6 */
  667. #define ADC_CHANNEL_7 (LL_ADC_CHANNEL_7) /*!< External channel (GPIO pin) ADCx_IN7 */
  668. #define ADC_CHANNEL_8 (LL_ADC_CHANNEL_8) /*!< External channel (GPIO pin) ADCx_IN8 */
  669. #define ADC_CHANNEL_9 (LL_ADC_CHANNEL_9) /*!< External channel (GPIO pin) ADCx_IN9 */
  670. #define ADC_CHANNEL_10 (LL_ADC_CHANNEL_10) /*!< External channel (GPIO pin) ADCx_IN10 */
  671. #define ADC_CHANNEL_11 (LL_ADC_CHANNEL_11) /*!< External channel (GPIO pin) ADCx_IN11 */
  672. #define ADC_CHANNEL_12 (LL_ADC_CHANNEL_12) /*!< External channel (GPIO pin) ADCx_IN12 */
  673. #define ADC_CHANNEL_13 (LL_ADC_CHANNEL_13) /*!< External channel (GPIO pin) ADCx_IN13 */
  674. #define ADC_CHANNEL_14 (LL_ADC_CHANNEL_14) /*!< External channel (GPIO pin) ADCx_IN14 */
  675. #define ADC_CHANNEL_15 (LL_ADC_CHANNEL_15) /*!< External channel (GPIO pin) ADCx_IN15 */
  676. #define ADC_CHANNEL_16 (LL_ADC_CHANNEL_16) /*!< External channel (GPIO pin) ADCx_IN16 */
  677. #define ADC_CHANNEL_17 (LL_ADC_CHANNEL_17) /*!< External channel (GPIO pin) ADCx_IN17 */
  678. #define ADC_CHANNEL_18 (LL_ADC_CHANNEL_18) /*!< External channel (GPIO pin) ADCx_IN18 */
  679. #define ADC_CHANNEL_VREFINT (LL_ADC_CHANNEL_VREFINT) /*!< Internal channel VrefInt: Internal
  680. voltage reference, channel specific to ADC1. */
  681. #define ADC_CHANNEL_TEMPSENSOR (LL_ADC_CHANNEL_TEMPSENSOR) /*!< Internal channel Temperature sensor,
  682. channel specific to ADC1. */
  683. #define ADC_CHANNEL_VBAT (LL_ADC_CHANNEL_VBAT) /*!< Internal channel Vbat/3: Vbat voltage
  684. through a divider ladder of factor 1/3 to have channel voltage always below
  685. Vdda, channel specific to ADC1. */
  686. #define ADC_CHANNEL_DAC1CH1_ADC2 (LL_ADC_CHANNEL_DAC1CH1_ADC2) /*!< Internal channel DAC1 channel 1,
  687. channel specific to ADC2. */
  688. #define ADC_CHANNEL_DAC1CH2_ADC2 (LL_ADC_CHANNEL_DAC1CH2_ADC2) /*!< Internal channel DAC1 channel 2,
  689. channel specific to ADC2. */
  690. /**
  691. * @}
  692. */
  693. /** @defgroup ADC_HAL_EC_AWD_NUMBER Analog watchdog - ADC analog watchdog (AWD) number
  694. * @{
  695. */
  696. #define ADC_ANALOGWATCHDOG_1 (LL_ADC_AWD1) /*!< ADC analog watchdog number 1 */
  697. #define ADC_ANALOGWATCHDOG_2 (LL_ADC_AWD2) /*!< ADC analog watchdog number 2 */
  698. #define ADC_ANALOGWATCHDOG_3 (LL_ADC_AWD3) /*!< ADC analog watchdog number 3 */
  699. /**
  700. * @}
  701. */
  702. /** @defgroup ADC_analog_watchdog_mode ADC analog watchdog (AWD) mode
  703. * @{
  704. */
  705. #define ADC_ANALOGWATCHDOG_NONE (0x00000000UL) /*!< ADC AWD not selected */
  706. #define ADC_ANALOGWATCHDOG_SINGLE_REG (ADC_CFGR_AWD1SGL | ADC_CFGR_AWD1EN) /*!< ADC AWD applied to a regular
  707. group single channel */
  708. #define ADC_ANALOGWATCHDOG_SINGLE_INJEC (ADC_CFGR_AWD1SGL | ADC_CFGR_JAWD1EN) /*!< ADC AWD applied to an
  709. injected group single channel */
  710. #define ADC_ANALOGWATCHDOG_SINGLE_REGINJEC (ADC_CFGR_AWD1SGL | ADC_CFGR_AWD1EN\
  711. | ADC_CFGR_JAWD1EN) /*!< ADC AWD applied to a regular
  712. and injected groups single channel */
  713. #define ADC_ANALOGWATCHDOG_ALL_REG (ADC_CFGR_AWD1EN) /*!< ADC AWD applied to regular
  714. group all channels */
  715. #define ADC_ANALOGWATCHDOG_ALL_INJEC (ADC_CFGR_JAWD1EN) /*!< ADC AWD applied to injected
  716. group all channels */
  717. #define ADC_ANALOGWATCHDOG_ALL_REGINJEC (ADC_CFGR_AWD1EN | ADC_CFGR_JAWD1EN) /*!< ADC AWD applied to regular
  718. and injected groups all channels */
  719. /**
  720. * @}
  721. */
  722. /** @defgroup ADC_HAL_EC_OVS_RATIO Oversampling - Ratio
  723. * @{
  724. */
  725. /**
  726. * @note The oversampling ratio is the number of ADC conversions performed, sum of these conversions data is computed
  727. * to result as the ADC oversampling conversion data (before potential shift)
  728. */
  729. #define ADC_OVERSAMPLING_RATIO_2 (LL_ADC_OVS_RATIO_2) /*!< ADC oversampling ratio 2 */
  730. #define ADC_OVERSAMPLING_RATIO_4 (LL_ADC_OVS_RATIO_4) /*!< ADC oversampling ratio 4 */
  731. #define ADC_OVERSAMPLING_RATIO_8 (LL_ADC_OVS_RATIO_8) /*!< ADC oversampling ratio 8 */
  732. #define ADC_OVERSAMPLING_RATIO_16 (LL_ADC_OVS_RATIO_16) /*!< ADC oversampling ratio 16 */
  733. #define ADC_OVERSAMPLING_RATIO_32 (LL_ADC_OVS_RATIO_32) /*!< ADC oversampling ratio 32 */
  734. #define ADC_OVERSAMPLING_RATIO_64 (LL_ADC_OVS_RATIO_64) /*!< ADC oversampling ratio 64 */
  735. #define ADC_OVERSAMPLING_RATIO_128 (LL_ADC_OVS_RATIO_128) /*!< ADC oversampling ratio 128 */
  736. #define ADC_OVERSAMPLING_RATIO_256 (LL_ADC_OVS_RATIO_256) /*!< ADC oversampling ratio 256 */
  737. /**
  738. * @}
  739. */
  740. /** @defgroup ADC_HAL_EC_OVS_SHIFT Oversampling - Data shift
  741. * @{
  742. */
  743. /**
  744. * @note The sum of the ADC conversions data is divided by "Rightbitshift" number to result as the ADC oversampling
  745. * conversion data)
  746. */
  747. #define ADC_RIGHTBITSHIFT_NONE (LL_ADC_OVS_SHIFT_NONE) /*!< ADC oversampling no shift */
  748. #define ADC_RIGHTBITSHIFT_1 (LL_ADC_OVS_SHIFT_RIGHT_1) /*!< ADC oversampling right shift of 1 ranks */
  749. #define ADC_RIGHTBITSHIFT_2 (LL_ADC_OVS_SHIFT_RIGHT_2) /*!< ADC oversampling right shift of 2 ranks */
  750. #define ADC_RIGHTBITSHIFT_3 (LL_ADC_OVS_SHIFT_RIGHT_3) /*!< ADC oversampling right shift of 3 ranks */
  751. #define ADC_RIGHTBITSHIFT_4 (LL_ADC_OVS_SHIFT_RIGHT_4) /*!< ADC oversampling right shift of 4 ranks */
  752. #define ADC_RIGHTBITSHIFT_5 (LL_ADC_OVS_SHIFT_RIGHT_5) /*!< ADC oversampling right shift of 5 ranks */
  753. #define ADC_RIGHTBITSHIFT_6 (LL_ADC_OVS_SHIFT_RIGHT_6) /*!< ADC oversampling right shift of 6 ranks */
  754. #define ADC_RIGHTBITSHIFT_7 (LL_ADC_OVS_SHIFT_RIGHT_7) /*!< ADC oversampling right shift of 7 ranks */
  755. #define ADC_RIGHTBITSHIFT_8 (LL_ADC_OVS_SHIFT_RIGHT_8) /*!< ADC oversampling right shift of 8 ranks */
  756. /**
  757. * @}
  758. */
  759. /** @defgroup ADC_HAL_EC_OVS_DISCONT_MODE Oversampling - Discontinuous mode
  760. * @{
  761. */
  762. #define ADC_TRIGGEREDMODE_SINGLE_TRIGGER (LL_ADC_OVS_REG_CONT) /*!< ADC oversampling discontinuous mode:
  763. continuous mode (all conversions of OVS ratio are done from 1 trigger) */
  764. #define ADC_TRIGGEREDMODE_MULTI_TRIGGER (LL_ADC_OVS_REG_DISCONT) /*!< ADC oversampling discontinuous mode:
  765. discontinuous mode (each conversion of OVS ratio needs a trigger) */
  766. /**
  767. * @}
  768. */
  769. /** @defgroup ADC_HAL_EC_OVS_SCOPE_REG Oversampling - Oversampling scope for ADC group regular
  770. * @{
  771. */
  772. #define ADC_REGOVERSAMPLING_CONTINUED_MODE (LL_ADC_OVS_GRP_REGULAR_CONTINUED) /*!< Oversampling buffer maintained
  773. during injection sequence */
  774. #define ADC_REGOVERSAMPLING_RESUMED_MODE (LL_ADC_OVS_GRP_REGULAR_RESUMED) /*!< Oversampling buffer zeroed during
  775. injection sequence */
  776. /**
  777. * @}
  778. */
  779. /** @defgroup ADC_Event_type ADC Event type
  780. * @{
  781. */
  782. /**
  783. * @note Analog watchdog 1 is available on all stm32 series
  784. * Analog watchdog 2 and 3 are not available on all series
  785. */
  786. #define ADC_EOSMP_EVENT (ADC_FLAG_EOSMP) /*!< ADC End of Sampling event */
  787. #define ADC_AWD1_EVENT (ADC_FLAG_AWD1) /*!< ADC Analog watchdog 1 event (main analog watchdog) */
  788. #define ADC_AWD2_EVENT (ADC_FLAG_AWD2) /*!< ADC Analog watchdog 2 event (additional analog watchdog) */
  789. #define ADC_AWD3_EVENT (ADC_FLAG_AWD3) /*!< ADC Analog watchdog 3 event (additional analog watchdog) */
  790. #define ADC_OVR_EVENT (ADC_FLAG_OVR) /*!< ADC overrun event */
  791. #define ADC_JQOVF_EVENT (ADC_FLAG_JQOVF) /*!< ADC Injected Context Queue Overflow event */
  792. /**
  793. * @}
  794. */
  795. #define ADC_AWD_EVENT ADC_AWD1_EVENT /*!< ADC Analog watchdog 1 event: Naming for compatibility
  796. with other STM32 devices having only one analog watchdog */
  797. /** @defgroup ADC_interrupts_definition ADC interrupts definition
  798. * @{
  799. */
  800. #define ADC_IT_RDY ADC_IER_ADRDYIE /*!< ADC Ready interrupt source */
  801. #define ADC_IT_EOSMP ADC_IER_EOSMPIE /*!< ADC End of sampling interrupt source */
  802. #define ADC_IT_EOC ADC_IER_EOCIE /*!< ADC End of regular conversion interrupt source */
  803. #define ADC_IT_EOS ADC_IER_EOSIE /*!< ADC End of regular sequence of conversions interrupt source */
  804. #define ADC_IT_OVR ADC_IER_OVRIE /*!< ADC overrun interrupt source */
  805. #define ADC_IT_JEOC ADC_IER_JEOCIE /*!< ADC End of injected conversion interrupt source */
  806. #define ADC_IT_JEOS ADC_IER_JEOSIE /*!< ADC End of injected sequence of conversions interrupt source */
  807. #define ADC_IT_AWD1 ADC_IER_AWD1IE /*!< ADC Analog watchdog 1 interrupt source (main analog watchdog) */
  808. #define ADC_IT_AWD2 ADC_IER_AWD2IE /*!< ADC Analog watchdog 2 interrupt source (additional analog
  809. watchdog) */
  810. #define ADC_IT_AWD3 ADC_IER_AWD3IE /*!< ADC Analog watchdog 3 interrupt source (additional analog
  811. watchdog) */
  812. #define ADC_IT_JQOVF ADC_IER_JQOVFIE /*!< ADC Injected Context Queue Overflow interrupt source */
  813. #define ADC_IT_AWD ADC_IT_AWD1 /*!< Analog watchdog 1 interrupt source: naming for compatibility
  814. with other STM32 series having only one analog watchdog */
  815. /**
  816. * @}
  817. */
  818. /** @defgroup ADC_flags_definition ADC flags definition
  819. * @{
  820. */
  821. #define ADC_FLAG_RDY ADC_ISR_ADRDY /*!< ADC Ready flag */
  822. #define ADC_FLAG_EOSMP ADC_ISR_EOSMP /*!< ADC End of Sampling flag */
  823. #define ADC_FLAG_EOC ADC_ISR_EOC /*!< ADC End of Regular Conversion flag */
  824. #define ADC_FLAG_EOS ADC_ISR_EOS /*!< ADC End of Regular sequence of Conversions flag */
  825. #define ADC_FLAG_OVR ADC_ISR_OVR /*!< ADC overrun flag */
  826. #define ADC_FLAG_JEOC ADC_ISR_JEOC /*!< ADC End of Injected Conversion flag */
  827. #define ADC_FLAG_JEOS ADC_ISR_JEOS /*!< ADC End of Injected sequence of Conversions flag */
  828. #define ADC_FLAG_AWD1 ADC_ISR_AWD1 /*!< ADC Analog watchdog 1 flag (main analog watchdog) */
  829. #define ADC_FLAG_AWD2 ADC_ISR_AWD2 /*!< ADC Analog watchdog 2 flag (additional analog watchdog) */
  830. #define ADC_FLAG_AWD3 ADC_ISR_AWD3 /*!< ADC Analog watchdog 3 flag (additional analog watchdog) */
  831. #define ADC_FLAG_JQOVF ADC_ISR_JQOVF /*!< ADC Injected Context Queue Overflow flag */
  832. /**
  833. * @}
  834. */
  835. /**
  836. * @}
  837. */
  838. /* Private macro -------------------------------------------------------------*/
  839. /** @defgroup ADC_Private_Macros ADC Private Macros
  840. * @{
  841. */
  842. /* Macro reserved for internal HAL driver usage, not intended to be used in */
  843. /* code of final user. */
  844. /**
  845. * @brief Return resolution bits in CFGR register RES[1:0] field.
  846. * @param __HANDLE__ ADC handle
  847. * @retval Value of bitfield RES in CFGR register.
  848. */
  849. #define ADC_GET_RESOLUTION(__HANDLE__) \
  850. (LL_ADC_GetResolution((__HANDLE__)->Instance))
  851. /**
  852. * @brief Clear ADC error code (set it to no error code "HAL_ADC_ERROR_NONE").
  853. * @param __HANDLE__ ADC handle
  854. * @retval None
  855. */
  856. #define ADC_CLEAR_ERRORCODE(__HANDLE__) ((__HANDLE__)->ErrorCode = HAL_ADC_ERROR_NONE)
  857. /**
  858. * @brief Simultaneously clear and set specific bits of the handle State.
  859. * @note ADC_STATE_CLR_SET() macro is merely aliased to generic macro MODIFY_REG(),
  860. * the first parameter is the ADC handle State, the second parameter is the
  861. * bit field to clear, the third and last parameter is the bit field to set.
  862. * @retval None
  863. */
  864. #define ADC_STATE_CLR_SET MODIFY_REG
  865. /**
  866. * @brief Verify that a given value is aligned with the ADC resolution range.
  867. * @param __RESOLUTION__ ADC resolution (12, 10, 8 or 6 bits).
  868. * @param __ADC_VALUE__ value checked against the resolution.
  869. * @retval SET (__ADC_VALUE__ in line with __RESOLUTION__) or RESET (__ADC_VALUE__ not in line with __RESOLUTION__)
  870. */
  871. #define IS_ADC_RANGE(__RESOLUTION__, __ADC_VALUE__) \
  872. ((__ADC_VALUE__) <= __LL_ADC_DIGITAL_SCALE(__RESOLUTION__))
  873. /**
  874. * @brief Verify the length of the scheduled regular conversions group.
  875. * @param __LENGTH__ number of programmed conversions.
  876. * @retval SET (__LENGTH__ is within the maximum number of possible programmable regular conversions)
  877. * or RESET (__LENGTH__ is null or too large)
  878. */
  879. #define IS_ADC_REGULAR_NB_CONV(__LENGTH__) (((__LENGTH__) >= (1UL)) && ((__LENGTH__) <= (16UL)))
  880. /**
  881. * @brief Verify the number of scheduled regular conversions in discontinuous mode.
  882. * @param NUMBER number of scheduled regular conversions in discontinuous mode.
  883. * @retval SET (NUMBER is within the maximum number of regular conversions in discontinuous mode)
  884. * or RESET (NUMBER is null or too large)
  885. */
  886. #define IS_ADC_REGULAR_DISCONT_NUMBER(NUMBER) (((NUMBER) >= (1UL)) && ((NUMBER) <= (8UL)))
  887. /**
  888. * @brief Verify the ADC clock setting.
  889. * @param __ADC_CLOCK__ programmed ADC clock.
  890. * @retval SET (__ADC_CLOCK__ is a valid value) or RESET (__ADC_CLOCK__ is invalid)
  891. */
  892. #define IS_ADC_CLOCKPRESCALER(__ADC_CLOCK__) (((__ADC_CLOCK__) == ADC_CLOCK_SYNC_PCLK_DIV1) || \
  893. ((__ADC_CLOCK__) == ADC_CLOCK_SYNC_PCLK_DIV2) || \
  894. ((__ADC_CLOCK__) == ADC_CLOCK_SYNC_PCLK_DIV4) || \
  895. ((__ADC_CLOCK__) == ADC_CLOCK_ASYNC_DIV1) || \
  896. ((__ADC_CLOCK__) == ADC_CLOCK_ASYNC_DIV2) || \
  897. ((__ADC_CLOCK__) == ADC_CLOCK_ASYNC_DIV4) || \
  898. ((__ADC_CLOCK__) == ADC_CLOCK_ASYNC_DIV6) || \
  899. ((__ADC_CLOCK__) == ADC_CLOCK_ASYNC_DIV8) || \
  900. ((__ADC_CLOCK__) == ADC_CLOCK_ASYNC_DIV10) || \
  901. ((__ADC_CLOCK__) == ADC_CLOCK_ASYNC_DIV12) || \
  902. ((__ADC_CLOCK__) == ADC_CLOCK_ASYNC_DIV16) || \
  903. ((__ADC_CLOCK__) == ADC_CLOCK_ASYNC_DIV32) || \
  904. ((__ADC_CLOCK__) == ADC_CLOCK_ASYNC_DIV64) || \
  905. ((__ADC_CLOCK__) == ADC_CLOCK_ASYNC_DIV128) || \
  906. ((__ADC_CLOCK__) == ADC_CLOCK_ASYNC_DIV256) )
  907. /**
  908. * @brief Verify the ADC resolution setting.
  909. * @param __RESOLUTION__ programmed ADC resolution.
  910. * @retval SET (__RESOLUTION__ is a valid value) or RESET (__RESOLUTION__ is invalid)
  911. */
  912. #define IS_ADC_RESOLUTION(__RESOLUTION__) (((__RESOLUTION__) == ADC_RESOLUTION_12B) || \
  913. ((__RESOLUTION__) == ADC_RESOLUTION_10B) || \
  914. ((__RESOLUTION__) == ADC_RESOLUTION_8B) || \
  915. ((__RESOLUTION__) == ADC_RESOLUTION_6B) )
  916. /**
  917. * @brief Verify the ADC resolution setting when limited to 6 or 8 bits.
  918. * @param __RESOLUTION__ programmed ADC resolution when limited to 6 or 8 bits.
  919. * @retval SET (__RESOLUTION__ is a valid value) or RESET (__RESOLUTION__ is invalid)
  920. */
  921. #define IS_ADC_RESOLUTION_8_6_BITS(__RESOLUTION__) (((__RESOLUTION__) == ADC_RESOLUTION_8B) || \
  922. ((__RESOLUTION__) == ADC_RESOLUTION_6B) )
  923. /**
  924. * @brief Verify the ADC converted data alignment.
  925. * @param __ALIGN__ programmed ADC converted data alignment.
  926. * @retval SET (__ALIGN__ is a valid value) or RESET (__ALIGN__ is invalid)
  927. */
  928. #define IS_ADC_DATA_ALIGN(__ALIGN__) (((__ALIGN__) == ADC_DATAALIGN_RIGHT) || \
  929. ((__ALIGN__) == ADC_DATAALIGN_LEFT) )
  930. /**
  931. * @brief Verify the ADC scan mode.
  932. * @param __SCAN_MODE__ programmed ADC scan mode.
  933. * @retval SET (__SCAN_MODE__ is valid) or RESET (__SCAN_MODE__ is invalid)
  934. */
  935. #define IS_ADC_SCAN_MODE(__SCAN_MODE__) (((__SCAN_MODE__) == ADC_SCAN_DISABLE) || \
  936. ((__SCAN_MODE__) == ADC_SCAN_ENABLE) )
  937. /**
  938. * @brief Verify the ADC edge trigger setting for regular group.
  939. * @param __EDGE__ programmed ADC edge trigger setting.
  940. * @retval SET (__EDGE__ is a valid value) or RESET (__EDGE__ is invalid)
  941. */
  942. #define IS_ADC_EXTTRIG_EDGE(__EDGE__) (((__EDGE__) == ADC_EXTERNALTRIGCONVEDGE_NONE) || \
  943. ((__EDGE__) == ADC_EXTERNALTRIGCONVEDGE_RISING) || \
  944. ((__EDGE__) == ADC_EXTERNALTRIGCONVEDGE_FALLING) || \
  945. ((__EDGE__) == ADC_EXTERNALTRIGCONVEDGE_RISINGFALLING) )
  946. /**
  947. * @brief Verify the ADC regular conversions external trigger.
  948. * @param __HANDLE__ ADC handle
  949. * @param __REGTRIG__ programmed ADC regular conversions external trigger.
  950. * @retval SET (__REGTRIG__ is a valid value) or RESET (__REGTRIG__ is invalid)
  951. */
  952. #define IS_ADC_EXTTRIG(__HANDLE__, __REGTRIG__) (((__REGTRIG__) == ADC_EXTERNALTRIG_T1_CC1) || \
  953. ((__REGTRIG__) == ADC_EXTERNALTRIG_T1_CC2) || \
  954. ((__REGTRIG__) == ADC_EXTERNALTRIG_T1_CC3) || \
  955. ((__REGTRIG__) == ADC_EXTERNALTRIG_T2_CC2) || \
  956. ((__REGTRIG__) == ADC_EXTERNALTRIG_T3_TRGO) || \
  957. ((__REGTRIG__) == ADC_EXTERNALTRIG_T4_CC4) || \
  958. ((__REGTRIG__) == ADC_EXTERNALTRIG_EXT_IT11) || \
  959. ((__REGTRIG__) == ADC_EXTERNALTRIG_T8_TRGO) || \
  960. ((__REGTRIG__) == ADC_EXTERNALTRIG_T8_TRGO2) || \
  961. ((__REGTRIG__) == ADC_EXTERNALTRIG_T1_TRGO) || \
  962. ((__REGTRIG__) == ADC_EXTERNALTRIG_T1_TRGO2) || \
  963. ((__REGTRIG__) == ADC_EXTERNALTRIG_T2_TRGO) || \
  964. ((__REGTRIG__) == ADC_EXTERNALTRIG_T4_TRGO) || \
  965. ((__REGTRIG__) == ADC_EXTERNALTRIG_T6_TRGO) || \
  966. ((__REGTRIG__) == ADC_EXTERNALTRIG_T15_TRGO) || \
  967. ((__REGTRIG__) == ADC_EXTERNALTRIG_T3_CC4) || \
  968. ((__REGTRIG__) == ADC_SOFTWARE_START) )
  969. /**
  970. * @brief Verify the ADC regular conversions check for converted data availability.
  971. * @param __EOC_SELECTION__ converted data availability check.
  972. * @retval SET (__EOC_SELECTION__ is a valid value) or RESET (__EOC_SELECTION__ is invalid)
  973. */
  974. #define IS_ADC_EOC_SELECTION(__EOC_SELECTION__) (((__EOC_SELECTION__) == ADC_EOC_SINGLE_CONV) || \
  975. ((__EOC_SELECTION__) == ADC_EOC_SEQ_CONV) )
  976. /**
  977. * @brief Verify the ADC regular conversions overrun handling.
  978. * @param __OVR__ ADC regular conversions overrun handling.
  979. * @retval SET (__OVR__ is a valid value) or RESET (__OVR__ is invalid)
  980. */
  981. #define IS_ADC_OVERRUN(__OVR__) (((__OVR__) == ADC_OVR_DATA_PRESERVED) || \
  982. ((__OVR__) == ADC_OVR_DATA_OVERWRITTEN) )
  983. /**
  984. * @brief Verify the ADC conversions sampling time.
  985. * @param __TIME__ ADC conversions sampling time.
  986. * @retval SET (__TIME__ is a valid value) or RESET (__TIME__ is invalid)
  987. */
  988. #define IS_ADC_SAMPLE_TIME(__TIME__) (((__TIME__) == ADC_SAMPLETIME_2CYCLES_5) || \
  989. ((__TIME__) == ADC_SAMPLETIME_3CYCLES_5) || \
  990. ((__TIME__) == ADC_SAMPLETIME_6CYCLES_5) || \
  991. ((__TIME__) == ADC_SAMPLETIME_12CYCLES_5) || \
  992. ((__TIME__) == ADC_SAMPLETIME_24CYCLES_5) || \
  993. ((__TIME__) == ADC_SAMPLETIME_47CYCLES_5) || \
  994. ((__TIME__) == ADC_SAMPLETIME_92CYCLES_5) || \
  995. ((__TIME__) == ADC_SAMPLETIME_247CYCLES_5) || \
  996. ((__TIME__) == ADC_SAMPLETIME_640CYCLES_5) )
  997. /**
  998. * @brief Verify the ADC regular channel setting.
  999. * @param __CHANNEL__ programmed ADC regular channel.
  1000. * @retval SET (__CHANNEL__ is valid) or RESET (__CHANNEL__ is invalid)
  1001. */
  1002. #define IS_ADC_REGULAR_RANK(__CHANNEL__) (((__CHANNEL__) == ADC_REGULAR_RANK_1 ) || \
  1003. ((__CHANNEL__) == ADC_REGULAR_RANK_2 ) || \
  1004. ((__CHANNEL__) == ADC_REGULAR_RANK_3 ) || \
  1005. ((__CHANNEL__) == ADC_REGULAR_RANK_4 ) || \
  1006. ((__CHANNEL__) == ADC_REGULAR_RANK_5 ) || \
  1007. ((__CHANNEL__) == ADC_REGULAR_RANK_6 ) || \
  1008. ((__CHANNEL__) == ADC_REGULAR_RANK_7 ) || \
  1009. ((__CHANNEL__) == ADC_REGULAR_RANK_8 ) || \
  1010. ((__CHANNEL__) == ADC_REGULAR_RANK_9 ) || \
  1011. ((__CHANNEL__) == ADC_REGULAR_RANK_10) || \
  1012. ((__CHANNEL__) == ADC_REGULAR_RANK_11) || \
  1013. ((__CHANNEL__) == ADC_REGULAR_RANK_12) || \
  1014. ((__CHANNEL__) == ADC_REGULAR_RANK_13) || \
  1015. ((__CHANNEL__) == ADC_REGULAR_RANK_14) || \
  1016. ((__CHANNEL__) == ADC_REGULAR_RANK_15) || \
  1017. ((__CHANNEL__) == ADC_REGULAR_RANK_16) )
  1018. /**
  1019. * @}
  1020. */
  1021. /* Private constants ---------------------------------------------------------*/
  1022. /** @defgroup ADC_Private_Constants ADC Private Constants
  1023. * @{
  1024. */
  1025. /* Fixed timeout values for ADC conversion (including sampling time) */
  1026. /* Maximum sampling time is 640.5 ADC clock cycle (SMPx[2:0] = 0b111 */
  1027. /* Maximum conversion time is 12.5 + Maximum sampling time */
  1028. /* or 12.5 + 640.5 = 653 ADC clock cycles */
  1029. /* Minimum ADC Clock frequency is 0.14 MHz */
  1030. /* Maximum conversion time is */
  1031. /* 653 / 0.14 MHz = 4.66 ms */
  1032. #define ADC_STOP_CONVERSION_TIMEOUT ( 5UL) /*!< ADC stop time-out value */
  1033. /* Delay for temperature sensor stabilization time. */
  1034. /* Maximum delay is 120us (refer device datasheet, parameter tSTART). */
  1035. /* Unit: us */
  1036. #define ADC_TEMPSENSOR_DELAY_US (LL_ADC_DELAY_TEMPSENSOR_STAB_US)
  1037. /**
  1038. * @}
  1039. */
  1040. /* Exported macro ------------------------------------------------------------*/
  1041. /** @defgroup ADC_Exported_Macros ADC Exported Macros
  1042. * @{
  1043. */
  1044. /* Macro for internal HAL driver usage, and possibly can be used into code of */
  1045. /* final user. */
  1046. /** @defgroup ADC_HAL_EM_HANDLE_IT_FLAG HAL ADC macro to manage HAL ADC handle, IT and flags.
  1047. * @{
  1048. */
  1049. /** @brief Reset ADC handle state.
  1050. * @param __HANDLE__ ADC handle
  1051. * @retval None
  1052. */
  1053. #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1)
  1054. #define __HAL_ADC_RESET_HANDLE_STATE(__HANDLE__) \
  1055. do{ \
  1056. (__HANDLE__)->State = HAL_ADC_STATE_RESET; \
  1057. (__HANDLE__)->MspInitCallback = NULL; \
  1058. (__HANDLE__)->MspDeInitCallback = NULL; \
  1059. } while(0)
  1060. #else
  1061. #define __HAL_ADC_RESET_HANDLE_STATE(__HANDLE__) \
  1062. ((__HANDLE__)->State = HAL_ADC_STATE_RESET)
  1063. #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */
  1064. /**
  1065. * @brief Enable ADC interrupt.
  1066. * @param __HANDLE__ ADC handle
  1067. * @param __INTERRUPT__ ADC Interrupt
  1068. * This parameter can be one of the following values:
  1069. * @arg @ref ADC_IT_RDY ADC Ready interrupt source
  1070. * @arg @ref ADC_IT_EOSMP ADC End of Sampling interrupt source
  1071. * @arg @ref ADC_IT_EOC ADC End of Regular Conversion interrupt source
  1072. * @arg @ref ADC_IT_EOS ADC End of Regular sequence of Conversions interrupt source
  1073. * @arg @ref ADC_IT_OVR ADC overrun interrupt source
  1074. * @arg @ref ADC_IT_JEOC ADC End of Injected Conversion interrupt source
  1075. * @arg @ref ADC_IT_JEOS ADC End of Injected sequence of Conversions interrupt source
  1076. * @arg @ref ADC_IT_AWD1 ADC Analog watchdog 1 interrupt source (main analog watchdog)
  1077. * @arg @ref ADC_IT_AWD2 ADC Analog watchdog 2 interrupt source (additional analog watchdog)
  1078. * @arg @ref ADC_IT_AWD3 ADC Analog watchdog 3 interrupt source (additional analog watchdog)
  1079. * @arg @ref ADC_IT_JQOVF ADC Injected Context Queue Overflow interrupt source.
  1080. * @retval None
  1081. */
  1082. #define __HAL_ADC_ENABLE_IT(__HANDLE__, __INTERRUPT__) \
  1083. (((__HANDLE__)->Instance->IER) |= (__INTERRUPT__))
  1084. /**
  1085. * @brief Disable ADC interrupt.
  1086. * @param __HANDLE__ ADC handle
  1087. * @param __INTERRUPT__ ADC Interrupt
  1088. * This parameter can be one of the following values:
  1089. * @arg @ref ADC_IT_RDY ADC Ready interrupt source
  1090. * @arg @ref ADC_IT_EOSMP ADC End of Sampling interrupt source
  1091. * @arg @ref ADC_IT_EOC ADC End of Regular Conversion interrupt source
  1092. * @arg @ref ADC_IT_EOS ADC End of Regular sequence of Conversions interrupt source
  1093. * @arg @ref ADC_IT_OVR ADC overrun interrupt source
  1094. * @arg @ref ADC_IT_JEOC ADC End of Injected Conversion interrupt source
  1095. * @arg @ref ADC_IT_JEOS ADC End of Injected sequence of Conversions interrupt source
  1096. * @arg @ref ADC_IT_AWD1 ADC Analog watchdog 1 interrupt source (main analog watchdog)
  1097. * @arg @ref ADC_IT_AWD2 ADC Analog watchdog 2 interrupt source (additional analog watchdog)
  1098. * @arg @ref ADC_IT_AWD3 ADC Analog watchdog 3 interrupt source (additional analog watchdog)
  1099. * @arg @ref ADC_IT_JQOVF ADC Injected Context Queue Overflow interrupt source.
  1100. * @retval None
  1101. */
  1102. #define __HAL_ADC_DISABLE_IT(__HANDLE__, __INTERRUPT__) \
  1103. (((__HANDLE__)->Instance->IER) &= ~(__INTERRUPT__))
  1104. /** @brief Checks if the specified ADC interrupt source is enabled or disabled.
  1105. * @param __HANDLE__ ADC handle
  1106. * @param __INTERRUPT__ ADC interrupt source to check
  1107. * This parameter can be one of the following values:
  1108. * @arg @ref ADC_IT_RDY ADC Ready interrupt source
  1109. * @arg @ref ADC_IT_EOSMP ADC End of Sampling interrupt source
  1110. * @arg @ref ADC_IT_EOC ADC End of Regular Conversion interrupt source
  1111. * @arg @ref ADC_IT_EOS ADC End of Regular sequence of Conversions interrupt source
  1112. * @arg @ref ADC_IT_OVR ADC overrun interrupt source
  1113. * @arg @ref ADC_IT_JEOC ADC End of Injected Conversion interrupt source
  1114. * @arg @ref ADC_IT_JEOS ADC End of Injected sequence of Conversions interrupt source
  1115. * @arg @ref ADC_IT_AWD1 ADC Analog watchdog 1 interrupt source (main analog watchdog)
  1116. * @arg @ref ADC_IT_AWD2 ADC Analog watchdog 2 interrupt source (additional analog watchdog)
  1117. * @arg @ref ADC_IT_AWD3 ADC Analog watchdog 3 interrupt source (additional analog watchdog)
  1118. * @arg @ref ADC_IT_JQOVF ADC Injected Context Queue Overflow interrupt source.
  1119. * @retval State of interruption (SET or RESET)
  1120. */
  1121. #define __HAL_ADC_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) \
  1122. (((__HANDLE__)->Instance->IER & (__INTERRUPT__)) == (__INTERRUPT__))
  1123. /**
  1124. * @brief Check whether the specified ADC flag is set or not.
  1125. * @param __HANDLE__ ADC handle
  1126. * @param __FLAG__ ADC flag
  1127. * This parameter can be one of the following values:
  1128. * @arg @ref ADC_FLAG_RDY ADC Ready flag
  1129. * @arg @ref ADC_FLAG_EOSMP ADC End of Sampling flag
  1130. * @arg @ref ADC_FLAG_EOC ADC End of Regular Conversion flag
  1131. * @arg @ref ADC_FLAG_EOS ADC End of Regular sequence of Conversions flag
  1132. * @arg @ref ADC_FLAG_OVR ADC overrun flag
  1133. * @arg @ref ADC_FLAG_JEOC ADC End of Injected Conversion flag
  1134. * @arg @ref ADC_FLAG_JEOS ADC End of Injected sequence of Conversions flag
  1135. * @arg @ref ADC_FLAG_AWD1 ADC Analog watchdog 1 flag (main analog watchdog)
  1136. * @arg @ref ADC_FLAG_AWD2 ADC Analog watchdog 2 flag (additional analog watchdog)
  1137. * @arg @ref ADC_FLAG_AWD3 ADC Analog watchdog 3 flag (additional analog watchdog)
  1138. * @arg @ref ADC_FLAG_JQOVF ADC Injected Context Queue Overflow flag.
  1139. * @retval State of flag (TRUE or FALSE).
  1140. */
  1141. #define __HAL_ADC_GET_FLAG(__HANDLE__, __FLAG__) \
  1142. ((((__HANDLE__)->Instance->ISR) & (__FLAG__)) == (__FLAG__))
  1143. /**
  1144. * @brief Clear the specified ADC flag.
  1145. * @param __HANDLE__ ADC handle
  1146. * @param __FLAG__ ADC flag
  1147. * This parameter can be one of the following values:
  1148. * @arg @ref ADC_FLAG_RDY ADC Ready flag
  1149. * @arg @ref ADC_FLAG_EOSMP ADC End of Sampling flag
  1150. * @arg @ref ADC_FLAG_EOC ADC End of Regular Conversion flag
  1151. * @arg @ref ADC_FLAG_EOS ADC End of Regular sequence of Conversions flag
  1152. * @arg @ref ADC_FLAG_OVR ADC overrun flag
  1153. * @arg @ref ADC_FLAG_JEOC ADC End of Injected Conversion flag
  1154. * @arg @ref ADC_FLAG_JEOS ADC End of Injected sequence of Conversions flag
  1155. * @arg @ref ADC_FLAG_AWD1 ADC Analog watchdog 1 flag (main analog watchdog)
  1156. * @arg @ref ADC_FLAG_AWD2 ADC Analog watchdog 2 flag (additional analog watchdog)
  1157. * @arg @ref ADC_FLAG_AWD3 ADC Analog watchdog 3 flag (additional analog watchdog)
  1158. * @arg @ref ADC_FLAG_JQOVF ADC Injected Context Queue Overflow flag.
  1159. * @retval None
  1160. */
  1161. /* Note: bit cleared bit by writing 1 (writing 0 has no effect on any bit of register ISR) */
  1162. #define __HAL_ADC_CLEAR_FLAG(__HANDLE__, __FLAG__) \
  1163. (((__HANDLE__)->Instance->ISR) = (__FLAG__))
  1164. /**
  1165. * @}
  1166. */
  1167. /** @defgroup ADC_HAL_EM_HELPER_MACRO HAL ADC helper macro
  1168. * @{
  1169. */
  1170. /**
  1171. * @brief Helper macro to get ADC channel number in decimal format
  1172. * from literals ADC_CHANNEL_x.
  1173. * @note Example:
  1174. * __HAL_ADC_CHANNEL_TO_DECIMAL_NB(ADC_CHANNEL_4)
  1175. * will return decimal number "4".
  1176. * @note The input can be a value from functions where a channel
  1177. * number is returned, either defined with number
  1178. * or with bitfield (only one bit must be set).
  1179. * @param __CHANNEL__ This parameter can be one of the following values:
  1180. * @arg @ref ADC_CHANNEL_0 (7)
  1181. * @arg @ref ADC_CHANNEL_1 (7)
  1182. * @arg @ref ADC_CHANNEL_2 (7)
  1183. * @arg @ref ADC_CHANNEL_3 (7)
  1184. * @arg @ref ADC_CHANNEL_4 (7)
  1185. * @arg @ref ADC_CHANNEL_5 (7)
  1186. * @arg @ref ADC_CHANNEL_6
  1187. * @arg @ref ADC_CHANNEL_7
  1188. * @arg @ref ADC_CHANNEL_8
  1189. * @arg @ref ADC_CHANNEL_9
  1190. * @arg @ref ADC_CHANNEL_10
  1191. * @arg @ref ADC_CHANNEL_11
  1192. * @arg @ref ADC_CHANNEL_12
  1193. * @arg @ref ADC_CHANNEL_13
  1194. * @arg @ref ADC_CHANNEL_14
  1195. * @arg @ref ADC_CHANNEL_15
  1196. * @arg @ref ADC_CHANNEL_16
  1197. * @arg @ref ADC_CHANNEL_17
  1198. * @arg @ref ADC_CHANNEL_18
  1199. * @arg @ref ADC_CHANNEL_VREFINT
  1200. * @arg @ref ADC_CHANNEL_TEMPSENSOR
  1201. * @arg @ref ADC_CHANNEL_VBAT
  1202. * @arg @ref ADC_CHANNEL_DAC1CH1_ADC2 (2)(6)
  1203. * @arg @ref ADC_CHANNEL_DAC1CH2_ADC2 (2)(6)
  1204. *
  1205. * (2) On STM32L5, parameter available only on ADC instance: ADC2.\n
  1206. * (6) On STM32L5, parameter available on devices with several ADC instances.\n
  1207. * (7) On STM32L5, fast channel (0.188 us for 12-bit resolution (ADC conversion rate up to 5.33 Ms/s)).
  1208. * Other channels are slow channels (0.238 us for 12-bit resolution (ADC conversion rate up to 4.21 Ms/s)).
  1209. * @retval Value between Min_Data=0 and Max_Data=18
  1210. */
  1211. #define __HAL_ADC_CHANNEL_TO_DECIMAL_NB(__CHANNEL__) \
  1212. __LL_ADC_CHANNEL_TO_DECIMAL_NB((__CHANNEL__))
  1213. /**
  1214. * @brief Helper macro to get ADC channel in literal format ADC_CHANNEL_x
  1215. * from number in decimal format.
  1216. * @note Example:
  1217. * __HAL_ADC_DECIMAL_NB_TO_CHANNEL(4)
  1218. * will return a data equivalent to "ADC_CHANNEL_4".
  1219. * @param __DECIMAL_NB__ Value between Min_Data=0 and Max_Data=18
  1220. * @retval Returned value can be one of the following values:
  1221. * @arg @ref ADC_CHANNEL_0 (7)
  1222. * @arg @ref ADC_CHANNEL_1 (7)
  1223. * @arg @ref ADC_CHANNEL_2 (7)
  1224. * @arg @ref ADC_CHANNEL_3 (7)
  1225. * @arg @ref ADC_CHANNEL_4 (7)
  1226. * @arg @ref ADC_CHANNEL_5 (7)
  1227. * @arg @ref ADC_CHANNEL_6
  1228. * @arg @ref ADC_CHANNEL_7
  1229. * @arg @ref ADC_CHANNEL_8
  1230. * @arg @ref ADC_CHANNEL_9
  1231. * @arg @ref ADC_CHANNEL_10
  1232. * @arg @ref ADC_CHANNEL_11
  1233. * @arg @ref ADC_CHANNEL_12
  1234. * @arg @ref ADC_CHANNEL_13
  1235. * @arg @ref ADC_CHANNEL_14
  1236. * @arg @ref ADC_CHANNEL_15
  1237. * @arg @ref ADC_CHANNEL_16
  1238. * @arg @ref ADC_CHANNEL_17
  1239. * @arg @ref ADC_CHANNEL_18
  1240. * @arg @ref ADC_CHANNEL_VREFINT (1)
  1241. * @arg @ref ADC_CHANNEL_TEMPSENSOR (4)
  1242. * @arg @ref ADC_CHANNEL_VBAT (4)
  1243. * @arg @ref ADC_CHANNEL_DAC1CH1_ADC2 (2)(6)
  1244. * @arg @ref ADC_CHANNEL_DAC1CH2_ADC2 (2)(6)
  1245. *
  1246. * (2) On STM32L5, parameter available only on ADC instance: ADC2.\n
  1247. * (6) On STM32L5, parameter available on devices with several ADC instances.\n
  1248. * (7) On STM32L5, fast channel (0.188 us for 12-bit resolution (ADC conversion rate up to 5.33 Ms/s)).
  1249. * Other channels are slow channels (0.238 us for 12-bit resolution (ADC conversion rate up to
  1250. * 4.21 Ms/s)).\n
  1251. * (1, 2, 3, 4) For ADC channel read back from ADC register,
  1252. * comparison with internal channel parameter to be done
  1253. * using helper macro @ref __LL_ADC_CHANNEL_INTERNAL_TO_EXTERNAL().
  1254. */
  1255. #define __HAL_ADC_DECIMAL_NB_TO_CHANNEL(__DECIMAL_NB__) \
  1256. __LL_ADC_DECIMAL_NB_TO_CHANNEL((__DECIMAL_NB__))
  1257. /**
  1258. * @brief Helper macro to determine whether the selected channel
  1259. * corresponds to literal definitions of driver.
  1260. * @note The different literal definitions of ADC channels are:
  1261. * - ADC internal channel:
  1262. * ADC_CHANNEL_VREFINT, ADC_CHANNEL_TEMPSENSOR, ...
  1263. * - ADC external channel (channel connected to a GPIO pin):
  1264. * ADC_CHANNEL_1, ADC_CHANNEL_2, ...
  1265. * @note The channel parameter must be a value defined from literal
  1266. * definition of a ADC internal channel (ADC_CHANNEL_VREFINT,
  1267. * ADC_CHANNEL_TEMPSENSOR, ...),
  1268. * ADC external channel (ADC_CHANNEL_1, ADC_CHANNEL_2, ...),
  1269. * must not be a value from functions where a channel number is
  1270. * returned from ADC registers,
  1271. * because internal and external channels share the same channel
  1272. * number in ADC registers. The differentiation is made only with
  1273. * parameters definitions of driver.
  1274. * @param __CHANNEL__ This parameter can be one of the following values:
  1275. * @arg @ref ADC_CHANNEL_0 (7)
  1276. * @arg @ref ADC_CHANNEL_1 (7)
  1277. * @arg @ref ADC_CHANNEL_2 (7)
  1278. * @arg @ref ADC_CHANNEL_3 (7)
  1279. * @arg @ref ADC_CHANNEL_4 (7)
  1280. * @arg @ref ADC_CHANNEL_5 (7)
  1281. * @arg @ref ADC_CHANNEL_6
  1282. * @arg @ref ADC_CHANNEL_7
  1283. * @arg @ref ADC_CHANNEL_8
  1284. * @arg @ref ADC_CHANNEL_9
  1285. * @arg @ref ADC_CHANNEL_10
  1286. * @arg @ref ADC_CHANNEL_11
  1287. * @arg @ref ADC_CHANNEL_12
  1288. * @arg @ref ADC_CHANNEL_13
  1289. * @arg @ref ADC_CHANNEL_14
  1290. * @arg @ref ADC_CHANNEL_15
  1291. * @arg @ref ADC_CHANNEL_16
  1292. * @arg @ref ADC_CHANNEL_17
  1293. * @arg @ref ADC_CHANNEL_18
  1294. * @arg @ref ADC_CHANNEL_VREFINT
  1295. * @arg @ref ADC_CHANNEL_TEMPSENSOR
  1296. * @arg @ref ADC_CHANNEL_VBAT
  1297. * @arg @ref ADC_CHANNEL_DAC1CH1_ADC2 (2)(6)
  1298. * @arg @ref ADC_CHANNEL_DAC1CH2_ADC2 (2)(6)
  1299. *
  1300. * (2) On STM32L5, parameter available only on ADC instance: ADC2.\n
  1301. * (6) On STM32L5, parameter available on devices with several ADC instances.\n
  1302. * (7) On STM32L5, fast channel (0.188 us for 12-bit resolution (ADC conversion rate up to 5.33 Ms/s)).
  1303. * Other channels are slow channels (0.238 us for 12-bit resolution (ADC conversion rate up to 4.21 Ms/s)).
  1304. * @retval Value "0" if the channel corresponds to a parameter definition of a ADC external channel (channel
  1305. * connected to a GPIO pin).
  1306. * Value "1" if the channel corresponds to a parameter definition of a ADC internal channel.
  1307. */
  1308. #define __HAL_ADC_IS_CHANNEL_INTERNAL(__CHANNEL__) \
  1309. __LL_ADC_IS_CHANNEL_INTERNAL((__CHANNEL__))
  1310. /**
  1311. * @brief Helper macro to convert a channel defined from parameter
  1312. * definition of a ADC internal channel (ADC_CHANNEL_VREFINT,
  1313. * ADC_CHANNEL_TEMPSENSOR, ...),
  1314. * to its equivalent parameter definition of a ADC external channel
  1315. * (ADC_CHANNEL_1, ADC_CHANNEL_2, ...).
  1316. * @note The channel parameter can be, additionally to a value
  1317. * defined from parameter definition of a ADC internal channel
  1318. * (ADC_CHANNEL_VREFINT, ADC_CHANNEL_TEMPSENSOR, ...),
  1319. * a value defined from parameter definition of
  1320. * ADC external channel (ADC_CHANNEL_1, ADC_CHANNEL_2, ...)
  1321. * or a value from functions where a channel number is returned
  1322. * from ADC registers.
  1323. * @param __CHANNEL__ This parameter can be one of the following values:
  1324. * @arg @ref ADC_CHANNEL_0 (7)
  1325. * @arg @ref ADC_CHANNEL_1 (7)
  1326. * @arg @ref ADC_CHANNEL_2 (7)
  1327. * @arg @ref ADC_CHANNEL_3 (7)
  1328. * @arg @ref ADC_CHANNEL_4 (7)
  1329. * @arg @ref ADC_CHANNEL_5 (7)
  1330. * @arg @ref ADC_CHANNEL_6
  1331. * @arg @ref ADC_CHANNEL_7
  1332. * @arg @ref ADC_CHANNEL_8
  1333. * @arg @ref ADC_CHANNEL_9
  1334. * @arg @ref ADC_CHANNEL_10
  1335. * @arg @ref ADC_CHANNEL_11
  1336. * @arg @ref ADC_CHANNEL_12
  1337. * @arg @ref ADC_CHANNEL_13
  1338. * @arg @ref ADC_CHANNEL_14
  1339. * @arg @ref ADC_CHANNEL_15
  1340. * @arg @ref ADC_CHANNEL_16
  1341. * @arg @ref ADC_CHANNEL_17
  1342. * @arg @ref ADC_CHANNEL_18
  1343. * @arg @ref ADC_CHANNEL_VREFINT
  1344. * @arg @ref ADC_CHANNEL_TEMPSENSOR
  1345. * @arg @ref ADC_CHANNEL_VBAT
  1346. * @arg @ref ADC_CHANNEL_DAC1CH1_ADC2 (2)(6)
  1347. * @arg @ref ADC_CHANNEL_DAC1CH2_ADC2 (2)(6)
  1348. *
  1349. * (2) On STM32L5, parameter available only on ADC instance: ADC2.\n
  1350. * (6) On STM32L5, parameter available on devices with several ADC instances.\n
  1351. * (7) On STM32L5, fast channel (0.188 us for 12-bit resolution (ADC conversion rate up to 5.33 Ms/s)).
  1352. * Other channels are slow channels (0.238 us for 12-bit resolution (ADC conversion rate up to 4.21 Ms/s)).
  1353. * @retval Returned value can be one of the following values:
  1354. * @arg @ref ADC_CHANNEL_0
  1355. * @arg @ref ADC_CHANNEL_1
  1356. * @arg @ref ADC_CHANNEL_2
  1357. * @arg @ref ADC_CHANNEL_3
  1358. * @arg @ref ADC_CHANNEL_4
  1359. * @arg @ref ADC_CHANNEL_5
  1360. * @arg @ref ADC_CHANNEL_6
  1361. * @arg @ref ADC_CHANNEL_7
  1362. * @arg @ref ADC_CHANNEL_8
  1363. * @arg @ref ADC_CHANNEL_9
  1364. * @arg @ref ADC_CHANNEL_10
  1365. * @arg @ref ADC_CHANNEL_11
  1366. * @arg @ref ADC_CHANNEL_12
  1367. * @arg @ref ADC_CHANNEL_13
  1368. * @arg @ref ADC_CHANNEL_14
  1369. * @arg @ref ADC_CHANNEL_15
  1370. * @arg @ref ADC_CHANNEL_16
  1371. * @arg @ref ADC_CHANNEL_17
  1372. * @arg @ref ADC_CHANNEL_18
  1373. */
  1374. #define __HAL_ADC_CHANNEL_INTERNAL_TO_EXTERNAL(__CHANNEL__) \
  1375. __LL_ADC_CHANNEL_INTERNAL_TO_EXTERNAL((__CHANNEL__))
  1376. /**
  1377. * @brief Helper macro to determine whether the internal channel
  1378. * selected is available on the ADC instance selected.
  1379. * @note The channel parameter must be a value defined from parameter
  1380. * definition of a ADC internal channel (ADC_CHANNEL_VREFINT,
  1381. * ADC_CHANNEL_TEMPSENSOR, ...),
  1382. * must not be a value defined from parameter definition of
  1383. * ADC external channel (ADC_CHANNEL_1, ADC_CHANNEL_2, ...)
  1384. * or a value from functions where a channel number is
  1385. * returned from ADC registers,
  1386. * because internal and external channels share the same channel
  1387. * number in ADC registers. The differentiation is made only with
  1388. * parameters definitions of driver.
  1389. * @param __ADC_INSTANCE__ ADC instance
  1390. * @param __CHANNEL__ This parameter can be one of the following values:
  1391. * @arg @ref ADC_CHANNEL_VREFINT
  1392. * @arg @ref ADC_CHANNEL_TEMPSENSOR
  1393. * @arg @ref ADC_CHANNEL_VBAT
  1394. * @arg @ref ADC_CHANNEL_DAC1CH1_ADC2
  1395. * @arg @ref ADC_CHANNEL_DAC1CH2_ADC2
  1396. * @retval Value "0" if the internal channel selected is not available on the ADC instance selected.
  1397. * Value "1" if the internal channel selected is available on the ADC instance selected.
  1398. */
  1399. #define __HAL_ADC_IS_CHANNEL_INTERNAL_AVAILABLE(__ADC_INSTANCE__, __CHANNEL__) \
  1400. __LL_ADC_IS_CHANNEL_INTERNAL_AVAILABLE((__ADC_INSTANCE__), (__CHANNEL__))
  1401. #if defined(ADC_MULTIMODE_SUPPORT)
  1402. /**
  1403. * @brief Helper macro to get the ADC multimode conversion data of ADC master
  1404. * or ADC slave from raw value with both ADC conversion data concatenated.
  1405. * @note This macro is intended to be used when multimode transfer by DMA
  1406. * is enabled: refer to function @ref LL_ADC_SetMultiDMATransfer().
  1407. * In this case the transferred data need to processed with this macro
  1408. * to separate the conversion data of ADC master and ADC slave.
  1409. * @param __ADC_MULTI_MASTER_SLAVE__ This parameter can be one of the following values:
  1410. * @arg @ref LL_ADC_MULTI_MASTER
  1411. * @arg @ref LL_ADC_MULTI_SLAVE
  1412. * @param __ADC_MULTI_CONV_DATA__ Value between Min_Data=0x000 and Max_Data=0xFFF
  1413. * @retval Value between Min_Data=0x000 and Max_Data=0xFFF
  1414. */
  1415. #define __HAL_ADC_MULTI_CONV_DATA_MASTER_SLAVE(__ADC_MULTI_MASTER_SLAVE__, __ADC_MULTI_CONV_DATA__) \
  1416. __LL_ADC_MULTI_CONV_DATA_MASTER_SLAVE((__ADC_MULTI_MASTER_SLAVE__), (__ADC_MULTI_CONV_DATA__))
  1417. #endif /* ADC_MULTIMODE_SUPPORT */
  1418. /**
  1419. * @brief Helper macro to select the ADC common instance
  1420. * to which is belonging the selected ADC instance.
  1421. * @note ADC common register instance can be used for:
  1422. * - Set parameters common to several ADC instances
  1423. * - Multimode (for devices with several ADC instances)
  1424. * Refer to functions having argument "ADCxy_COMMON" as parameter.
  1425. * @param __ADCx__ ADC instance
  1426. * @retval ADC common register instance
  1427. */
  1428. #define __HAL_ADC_COMMON_INSTANCE(__ADCx__) \
  1429. __LL_ADC_COMMON_INSTANCE((__ADCx__))
  1430. /**
  1431. * @brief Helper macro to check if all ADC instances sharing the same
  1432. * ADC common instance are disabled.
  1433. * @note This check is required by functions with setting conditioned to
  1434. * ADC state:
  1435. * All ADC instances of the ADC common group must be disabled.
  1436. * Refer to functions having argument "ADCxy_COMMON" as parameter.
  1437. * @note On devices with only 1 ADC common instance, parameter of this macro
  1438. * is useless and can be ignored (parameter kept for compatibility
  1439. * with devices featuring several ADC common instances).
  1440. * @param __ADCXY_COMMON__ ADC common instance
  1441. * (can be set directly from CMSIS definition or by using helper macro @ref __LL_ADC_COMMON_INSTANCE() )
  1442. * @retval Value "0" if all ADC instances sharing the same ADC common instance
  1443. * are disabled.
  1444. * Value "1" if at least one ADC instance sharing the same ADC common instance
  1445. * is enabled.
  1446. */
  1447. #define __HAL_ADC_IS_ENABLED_ALL_COMMON_INSTANCE(__ADCXY_COMMON__) \
  1448. __LL_ADC_IS_ENABLED_ALL_COMMON_INSTANCE((__ADCXY_COMMON__))
  1449. /**
  1450. * @brief Helper macro to define the ADC conversion data full-scale digital
  1451. * value corresponding to the selected ADC resolution.
  1452. * @note ADC conversion data full-scale corresponds to voltage range
  1453. * determined by analog voltage references Vref+ and Vref-
  1454. * (refer to reference manual).
  1455. * @param __ADC_RESOLUTION__ This parameter can be one of the following values:
  1456. * @arg @ref ADC_RESOLUTION_12B
  1457. * @arg @ref ADC_RESOLUTION_10B
  1458. * @arg @ref ADC_RESOLUTION_8B
  1459. * @arg @ref ADC_RESOLUTION_6B
  1460. * @retval ADC conversion data full-scale digital value
  1461. */
  1462. #define __HAL_ADC_DIGITAL_SCALE(__ADC_RESOLUTION__) \
  1463. __LL_ADC_DIGITAL_SCALE((__ADC_RESOLUTION__))
  1464. /**
  1465. * @brief Helper macro to convert the ADC conversion data from
  1466. * a resolution to another resolution.
  1467. * @param __DATA__ ADC conversion data to be converted
  1468. * @param __ADC_RESOLUTION_CURRENT__ Resolution of to the data to be converted
  1469. * This parameter can be one of the following values:
  1470. * @arg @ref ADC_RESOLUTION_12B
  1471. * @arg @ref ADC_RESOLUTION_10B
  1472. * @arg @ref ADC_RESOLUTION_8B
  1473. * @arg @ref ADC_RESOLUTION_6B
  1474. * @param __ADC_RESOLUTION_TARGET__ Resolution of the data after conversion
  1475. * This parameter can be one of the following values:
  1476. * @arg @ref ADC_RESOLUTION_12B
  1477. * @arg @ref ADC_RESOLUTION_10B
  1478. * @arg @ref ADC_RESOLUTION_8B
  1479. * @arg @ref ADC_RESOLUTION_6B
  1480. * @retval ADC conversion data to the requested resolution
  1481. */
  1482. #define __HAL_ADC_CONVERT_DATA_RESOLUTION(__DATA__,\
  1483. __ADC_RESOLUTION_CURRENT__,\
  1484. __ADC_RESOLUTION_TARGET__) \
  1485. __LL_ADC_CONVERT_DATA_RESOLUTION((__DATA__),\
  1486. (__ADC_RESOLUTION_CURRENT__),\
  1487. (__ADC_RESOLUTION_TARGET__))
  1488. /**
  1489. * @brief Helper macro to calculate the voltage (unit: mVolt)
  1490. * corresponding to a ADC conversion data (unit: digital value).
  1491. * @note Analog reference voltage (Vref+) must be either known from
  1492. * user board environment or can be calculated using ADC measurement
  1493. * and ADC helper macro @ref __LL_ADC_CALC_VREFANALOG_VOLTAGE().
  1494. * @param __VREFANALOG_VOLTAGE__ Analog reference voltage (unit: mV)
  1495. * @param __ADC_DATA__ ADC conversion data (resolution 12 bits)
  1496. * (unit: digital value).
  1497. * @param __ADC_RESOLUTION__ This parameter can be one of the following values:
  1498. * @arg @ref ADC_RESOLUTION_12B
  1499. * @arg @ref ADC_RESOLUTION_10B
  1500. * @arg @ref ADC_RESOLUTION_8B
  1501. * @arg @ref ADC_RESOLUTION_6B
  1502. * @retval ADC conversion data equivalent voltage value (unit: mVolt)
  1503. */
  1504. #define __HAL_ADC_CALC_DATA_TO_VOLTAGE(__VREFANALOG_VOLTAGE__,\
  1505. __ADC_DATA__,\
  1506. __ADC_RESOLUTION__) \
  1507. __LL_ADC_CALC_DATA_TO_VOLTAGE((__VREFANALOG_VOLTAGE__),\
  1508. (__ADC_DATA__),\
  1509. (__ADC_RESOLUTION__))
  1510. /**
  1511. * @brief Helper macro to calculate analog reference voltage (Vref+)
  1512. * (unit: mVolt) from ADC conversion data of internal voltage
  1513. * reference VrefInt.
  1514. * @note Computation is using VrefInt calibration value
  1515. * stored in system memory for each device during production.
  1516. * @note This voltage depends on user board environment: voltage level
  1517. * connected to pin Vref+.
  1518. * On devices with small package, the pin Vref+ is not present
  1519. * and internally bonded to pin Vdda.
  1520. * @note On this STM32 series, calibration data of internal voltage reference
  1521. * VrefInt corresponds to a resolution of 12 bits,
  1522. * this is the recommended ADC resolution to convert voltage of
  1523. * internal voltage reference VrefInt.
  1524. * Otherwise, this macro performs the processing to scale
  1525. * ADC conversion data to 12 bits.
  1526. * @param __VREFINT_ADC_DATA__ ADC conversion data (resolution 12 bits)
  1527. * of internal voltage reference VrefInt (unit: digital value).
  1528. * @param __ADC_RESOLUTION__ This parameter can be one of the following values:
  1529. * @arg @ref ADC_RESOLUTION_12B
  1530. * @arg @ref ADC_RESOLUTION_10B
  1531. * @arg @ref ADC_RESOLUTION_8B
  1532. * @arg @ref ADC_RESOLUTION_6B
  1533. * @retval Analog reference voltage (unit: mV)
  1534. */
  1535. #define __HAL_ADC_CALC_VREFANALOG_VOLTAGE(__VREFINT_ADC_DATA__,\
  1536. __ADC_RESOLUTION__) \
  1537. __LL_ADC_CALC_VREFANALOG_VOLTAGE((__VREFINT_ADC_DATA__),\
  1538. (__ADC_RESOLUTION__))
  1539. /**
  1540. * @brief Helper macro to calculate the temperature (unit: degree Celsius)
  1541. * from ADC conversion data of internal temperature sensor.
  1542. * @note Computation is using temperature sensor calibration values
  1543. * stored in system memory for each device during production.
  1544. * @note Calculation formula:
  1545. * Temperature = ((TS_ADC_DATA - TS_CAL1)
  1546. * * (TS_CAL2_TEMP - TS_CAL1_TEMP))
  1547. * / (TS_CAL2 - TS_CAL1) + TS_CAL1_TEMP
  1548. * with TS_ADC_DATA = temperature sensor raw data measured by ADC
  1549. * Avg_Slope = (TS_CAL2 - TS_CAL1)
  1550. * / (TS_CAL2_TEMP - TS_CAL1_TEMP)
  1551. * TS_CAL1 = equivalent TS_ADC_DATA at temperature
  1552. * TEMP_DEGC_CAL1 (calibrated in factory)
  1553. * TS_CAL2 = equivalent TS_ADC_DATA at temperature
  1554. * TEMP_DEGC_CAL2 (calibrated in factory)
  1555. * Caution: Calculation relevancy under reserve that calibration
  1556. * parameters are correct (address and data).
  1557. * To calculate temperature using temperature sensor
  1558. * datasheet typical values (generic values less, therefore
  1559. * less accurate than calibrated values),
  1560. * use helper macro @ref __LL_ADC_CALC_TEMPERATURE_TYP_PARAMS().
  1561. * @note As calculation input, the analog reference voltage (Vref+) must be
  1562. * defined as it impacts the ADC LSB equivalent voltage.
  1563. * @note Analog reference voltage (Vref+) must be either known from
  1564. * user board environment or can be calculated using ADC measurement
  1565. * and ADC helper macro @ref __LL_ADC_CALC_VREFANALOG_VOLTAGE().
  1566. * @note On this STM32 series, calibration data of temperature sensor
  1567. * corresponds to a resolution of 12 bits,
  1568. * this is the recommended ADC resolution to convert voltage of
  1569. * temperature sensor.
  1570. * Otherwise, this macro performs the processing to scale
  1571. * ADC conversion data to 12 bits.
  1572. * @param __VREFANALOG_VOLTAGE__ Analog reference voltage (unit: mV)
  1573. * @param __TEMPSENSOR_ADC_DATA__ ADC conversion data of internal
  1574. * temperature sensor (unit: digital value).
  1575. * @param __ADC_RESOLUTION__ ADC resolution at which internal temperature
  1576. * sensor voltage has been measured.
  1577. * This parameter can be one of the following values:
  1578. * @arg @ref ADC_RESOLUTION_12B
  1579. * @arg @ref ADC_RESOLUTION_10B
  1580. * @arg @ref ADC_RESOLUTION_8B
  1581. * @arg @ref ADC_RESOLUTION_6B
  1582. * @retval Temperature (unit: degree Celsius)
  1583. */
  1584. #define __HAL_ADC_CALC_TEMPERATURE(__VREFANALOG_VOLTAGE__,\
  1585. __TEMPSENSOR_ADC_DATA__,\
  1586. __ADC_RESOLUTION__) \
  1587. __LL_ADC_CALC_TEMPERATURE((__VREFANALOG_VOLTAGE__),\
  1588. (__TEMPSENSOR_ADC_DATA__),\
  1589. (__ADC_RESOLUTION__))
  1590. /**
  1591. * @brief Helper macro to calculate the temperature (unit: degree Celsius)
  1592. * from ADC conversion data of internal temperature sensor.
  1593. * @note Computation is using temperature sensor typical values
  1594. * (refer to device datasheet).
  1595. * @note Calculation formula:
  1596. * Temperature = (TS_TYP_CALx_VOLT(uV) - TS_ADC_DATA * Conversion_uV)
  1597. * / Avg_Slope + CALx_TEMP
  1598. * with TS_ADC_DATA = temperature sensor raw data measured by ADC
  1599. * (unit: digital value)
  1600. * Avg_Slope = temperature sensor slope
  1601. * (unit: uV/Degree Celsius)
  1602. * TS_TYP_CALx_VOLT = temperature sensor digital value at
  1603. * temperature CALx_TEMP (unit: mV)
  1604. * Caution: Calculation relevancy under reserve the temperature sensor
  1605. * of the current device has characteristics in line with
  1606. * datasheet typical values.
  1607. * If temperature sensor calibration values are available on
  1608. * on this device (presence of macro __LL_ADC_CALC_TEMPERATURE()),
  1609. * temperature calculation will be more accurate using
  1610. * helper macro @ref __LL_ADC_CALC_TEMPERATURE().
  1611. * @note As calculation input, the analog reference voltage (Vref+) must be
  1612. * defined as it impacts the ADC LSB equivalent voltage.
  1613. * @note Analog reference voltage (Vref+) must be either known from
  1614. * user board environment or can be calculated using ADC measurement
  1615. * and ADC helper macro @ref __LL_ADC_CALC_VREFANALOG_VOLTAGE().
  1616. * @note ADC measurement data must correspond to a resolution of 12bits
  1617. * (full scale digital value 4095). If not the case, the data must be
  1618. * preliminarily rescaled to an equivalent resolution of 12 bits.
  1619. * @param __TEMPSENSOR_TYP_AVGSLOPE__ Device datasheet data: Temperature sensor slope typical value
  1620. (unit: uV/DegCelsius).
  1621. * On STM32WB, refer to device datasheet parameter "Avg_Slope".
  1622. * @param __TEMPSENSOR_TYP_CALX_V__ Device datasheet data: Temperature sensor voltage typical value (at
  1623. temperature and Vref+ defined in parameters below) (unit: mV).
  1624. * On STM32WB, refer to device datasheet parameter "V30"
  1625. (corresponding to TS_CAL1).
  1626. * @param __TEMPSENSOR_CALX_TEMP__ Device datasheet data: Temperature at which temperature sensor voltage (see
  1627. parameter above) is corresponding (unit: mV)
  1628. * @param __VREFANALOG_VOLTAGE__ Analog voltage reference (Vref+) voltage (unit: mV)
  1629. * @param __TEMPSENSOR_ADC_DATA__ ADC conversion data of internal temperature sensor (unit: digital value).
  1630. * @param __ADC_RESOLUTION__ ADC resolution at which internal temperature sensor voltage has been measured.
  1631. * This parameter can be one of the following values:
  1632. * @arg @ref ADC_RESOLUTION_12B
  1633. * @arg @ref ADC_RESOLUTION_10B
  1634. * @arg @ref ADC_RESOLUTION_8B
  1635. * @arg @ref ADC_RESOLUTION_6B
  1636. * @retval Temperature (unit: degree Celsius)
  1637. */
  1638. #define __HAL_ADC_CALC_TEMPERATURE_TYP_PARAMS(__TEMPSENSOR_TYP_AVGSLOPE__,\
  1639. __TEMPSENSOR_TYP_CALX_V__,\
  1640. __TEMPSENSOR_CALX_TEMP__,\
  1641. __VREFANALOG_VOLTAGE__,\
  1642. __TEMPSENSOR_ADC_DATA__,\
  1643. __ADC_RESOLUTION__) \
  1644. __LL_ADC_CALC_TEMPERATURE_TYP_PARAMS((__TEMPSENSOR_TYP_AVGSLOPE__),\
  1645. (__TEMPSENSOR_TYP_CALX_V__),\
  1646. (__TEMPSENSOR_CALX_TEMP__),\
  1647. (__VREFANALOG_VOLTAGE__),\
  1648. (__TEMPSENSOR_ADC_DATA__),\
  1649. (__ADC_RESOLUTION__))
  1650. /**
  1651. * @}
  1652. */
  1653. /**
  1654. * @}
  1655. */
  1656. /* Include ADC HAL Extended module */
  1657. #include "stm32l5xx_hal_adc_ex.h"
  1658. /* Exported functions --------------------------------------------------------*/
  1659. /** @addtogroup ADC_Exported_Functions
  1660. * @{
  1661. */
  1662. /** @addtogroup ADC_Exported_Functions_Group1
  1663. * @brief Initialization and Configuration functions
  1664. * @{
  1665. */
  1666. /* Initialization and de-initialization functions ****************************/
  1667. HAL_StatusTypeDef HAL_ADC_Init(ADC_HandleTypeDef *hadc);
  1668. HAL_StatusTypeDef HAL_ADC_DeInit(ADC_HandleTypeDef *hadc);
  1669. void HAL_ADC_MspInit(ADC_HandleTypeDef *hadc);
  1670. void HAL_ADC_MspDeInit(ADC_HandleTypeDef *hadc);
  1671. #if (USE_HAL_ADC_REGISTER_CALLBACKS == 1)
  1672. /* Callbacks Register/UnRegister functions ***********************************/
  1673. HAL_StatusTypeDef HAL_ADC_RegisterCallback(ADC_HandleTypeDef *hadc, HAL_ADC_CallbackIDTypeDef CallbackID,
  1674. pADC_CallbackTypeDef pCallback);
  1675. HAL_StatusTypeDef HAL_ADC_UnRegisterCallback(ADC_HandleTypeDef *hadc, HAL_ADC_CallbackIDTypeDef CallbackID);
  1676. #endif /* USE_HAL_ADC_REGISTER_CALLBACKS */
  1677. /**
  1678. * @}
  1679. */
  1680. /** @addtogroup ADC_Exported_Functions_Group2
  1681. * @brief IO operation functions
  1682. * @{
  1683. */
  1684. /* IO operation functions *****************************************************/
  1685. /* Blocking mode: Polling */
  1686. HAL_StatusTypeDef HAL_ADC_Start(ADC_HandleTypeDef *hadc);
  1687. HAL_StatusTypeDef HAL_ADC_Stop(ADC_HandleTypeDef *hadc);
  1688. HAL_StatusTypeDef HAL_ADC_PollForConversion(ADC_HandleTypeDef *hadc, uint32_t Timeout);
  1689. HAL_StatusTypeDef HAL_ADC_PollForEvent(ADC_HandleTypeDef *hadc, uint32_t EventType, uint32_t Timeout);
  1690. /* Non-blocking mode: Interruption */
  1691. HAL_StatusTypeDef HAL_ADC_Start_IT(ADC_HandleTypeDef *hadc);
  1692. HAL_StatusTypeDef HAL_ADC_Stop_IT(ADC_HandleTypeDef *hadc);
  1693. /* Non-blocking mode: DMA */
  1694. HAL_StatusTypeDef HAL_ADC_Start_DMA(ADC_HandleTypeDef *hadc, uint32_t *pData, uint32_t Length);
  1695. HAL_StatusTypeDef HAL_ADC_Stop_DMA(ADC_HandleTypeDef *hadc);
  1696. /* ADC retrieve conversion value intended to be used with polling or interruption */
  1697. uint32_t HAL_ADC_GetValue(const ADC_HandleTypeDef *hadc);
  1698. /* ADC IRQHandler and Callbacks used in non-blocking modes (Interruption and DMA) */
  1699. void HAL_ADC_IRQHandler(ADC_HandleTypeDef *hadc);
  1700. void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef *hadc);
  1701. void HAL_ADC_ConvHalfCpltCallback(ADC_HandleTypeDef *hadc);
  1702. void HAL_ADC_LevelOutOfWindowCallback(ADC_HandleTypeDef *hadc);
  1703. void HAL_ADC_ErrorCallback(ADC_HandleTypeDef *hadc);
  1704. /**
  1705. * @}
  1706. */
  1707. /** @addtogroup ADC_Exported_Functions_Group3 Peripheral Control functions
  1708. * @brief Peripheral Control functions
  1709. * @{
  1710. */
  1711. /* Peripheral Control functions ***********************************************/
  1712. HAL_StatusTypeDef HAL_ADC_ConfigChannel(ADC_HandleTypeDef *hadc, const ADC_ChannelConfTypeDef *pConfig);
  1713. HAL_StatusTypeDef HAL_ADC_AnalogWDGConfig(ADC_HandleTypeDef *hadc,
  1714. const ADC_AnalogWDGConfTypeDef *pAnalogWDGConfig);
  1715. /**
  1716. * @}
  1717. */
  1718. /* Peripheral State functions *************************************************/
  1719. /** @addtogroup ADC_Exported_Functions_Group4
  1720. * @{
  1721. */
  1722. uint32_t HAL_ADC_GetState(const ADC_HandleTypeDef *hadc);
  1723. uint32_t HAL_ADC_GetError(const ADC_HandleTypeDef *hadc);
  1724. /**
  1725. * @}
  1726. */
  1727. /**
  1728. * @}
  1729. */
  1730. /* Private functions ---------------------------------------------------------*/
  1731. /** @addtogroup ADC_Private_Functions ADC Private Functions
  1732. * @{
  1733. */
  1734. HAL_StatusTypeDef ADC_ConversionStop(ADC_HandleTypeDef *hadc, uint32_t ConversionGroup);
  1735. HAL_StatusTypeDef ADC_Enable(ADC_HandleTypeDef *hadc);
  1736. HAL_StatusTypeDef ADC_Disable(ADC_HandleTypeDef *hadc);
  1737. void ADC_DMAConvCplt(DMA_HandleTypeDef *hdma);
  1738. void ADC_DMAHalfConvCplt(DMA_HandleTypeDef *hdma);
  1739. void ADC_DMAError(DMA_HandleTypeDef *hdma);
  1740. /**
  1741. * @}
  1742. */
  1743. /**
  1744. * @}
  1745. */
  1746. /**
  1747. * @}
  1748. */
  1749. #ifdef __cplusplus
  1750. }
  1751. #endif
  1752. #endif /* STM32L5xx_HAL_ADC_H */