stm32f3xx_ll_adc.c 97 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000
  1. /**
  2. ******************************************************************************
  3. * @file stm32f3xx_ll_adc.c
  4. * @author MCD Application Team
  5. * @brief ADC LL module driver
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) 2016 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. #if defined(USE_FULL_LL_DRIVER)
  19. /* Includes ------------------------------------------------------------------*/
  20. #include "stm32f3xx_ll_adc.h"
  21. #include "stm32f3xx_ll_bus.h"
  22. #ifdef USE_FULL_ASSERT
  23. #include "stm32_assert.h"
  24. #else
  25. #define assert_param(expr) ((void)0U)
  26. #endif
  27. /** @addtogroup STM32F3xx_LL_Driver
  28. * @{
  29. */
  30. /* Note: Devices of STM32F3 series embed 1 out of 2 different ADC IP. b */
  31. /* - STM32F30x, STM32F31x, STM32F32x, STM32F33x, STM32F35x, STM32F39x: */
  32. /* ADC IP 5Msamples/sec, from 1 to 4 ADC instances and other specific */
  33. /* features (refer to reference manual). */
  34. /* - STM32F37x: */
  35. /* ADC IP 1Msamples/sec, 1 ADC instance */
  36. /* This file contains the drivers of these ADC IP, located in 2 area */
  37. /* delimited by compilation switches. */
  38. #if defined(ADC5_V1_1)
  39. #if defined (ADC1) || defined (ADC2) || defined (ADC3) || defined (ADC4)
  40. /** @addtogroup ADC_LL ADC
  41. * @{
  42. */
  43. /* Private types -------------------------------------------------------------*/
  44. /* Private variables ---------------------------------------------------------*/
  45. /* Private constants ---------------------------------------------------------*/
  46. /** @addtogroup ADC_LL_Private_Constants
  47. * @{
  48. */
  49. /* Definitions of ADC hardware constraints delays */
  50. /* Note: Only ADC IP HW delays are defined in ADC LL driver driver, */
  51. /* not timeout values: */
  52. /* Timeout values for ADC operations are dependent to device clock */
  53. /* configuration (system clock versus ADC clock), */
  54. /* and therefore must be defined in user application. */
  55. /* Refer to @ref ADC_LL_EC_HW_DELAYS for description of ADC timeout */
  56. /* values definition. */
  57. /* Note: ADC timeout values are defined here in CPU cycles to be independent */
  58. /* of device clock setting. */
  59. /* In user application, ADC timeout values should be defined with */
  60. /* temporal values, in function of device clock settings. */
  61. /* Highest ratio CPU clock frequency vs ADC clock frequency: */
  62. /* - ADC clock from synchronous clock with AHB prescaler 512, */
  63. /* APB prescaler 16, ADC prescaler 4. */
  64. /* - ADC clock from asynchronous clock (PLL) with prescaler 1, */
  65. /* with highest ratio CPU clock frequency vs HSI clock frequency: */
  66. /* CPU clock frequency max 72MHz, PLL frequency 72MHz: ratio 1. */
  67. /* Unit: CPU cycles. */
  68. #define ADC_CLOCK_RATIO_VS_CPU_HIGHEST ((uint32_t) 512U * 16U * 4U)
  69. #define ADC_TIMEOUT_DISABLE_CPU_CYCLES (ADC_CLOCK_RATIO_VS_CPU_HIGHEST * 1U)
  70. #define ADC_TIMEOUT_STOP_CONVERSION_CPU_CYCLES (ADC_CLOCK_RATIO_VS_CPU_HIGHEST * 1U)
  71. /**
  72. * @}
  73. */
  74. /* Private macros ------------------------------------------------------------*/
  75. /** @addtogroup ADC_LL_Private_Macros
  76. * @{
  77. */
  78. /* Check of parameters for configuration of ADC hierarchical scope: */
  79. /* common to several ADC instances. */
  80. #define IS_LL_ADC_COMMON_CLOCK(__CLOCK__) \
  81. ( ((__CLOCK__) == LL_ADC_CLOCK_SYNC_PCLK_DIV1) \
  82. || ((__CLOCK__) == LL_ADC_CLOCK_SYNC_PCLK_DIV2) \
  83. || ((__CLOCK__) == LL_ADC_CLOCK_SYNC_PCLK_DIV4) \
  84. || ((__CLOCK__) == LL_ADC_CLOCK_ASYNC_DIV1) \
  85. )
  86. /* Check of parameters for configuration of ADC hierarchical scope: */
  87. /* ADC instance. */
  88. #define IS_LL_ADC_RESOLUTION(__RESOLUTION__) \
  89. ( ((__RESOLUTION__) == LL_ADC_RESOLUTION_12B) \
  90. || ((__RESOLUTION__) == LL_ADC_RESOLUTION_10B) \
  91. || ((__RESOLUTION__) == LL_ADC_RESOLUTION_8B) \
  92. || ((__RESOLUTION__) == LL_ADC_RESOLUTION_6B) \
  93. )
  94. #define IS_LL_ADC_DATA_ALIGN(__DATA_ALIGN__) \
  95. ( ((__DATA_ALIGN__) == LL_ADC_DATA_ALIGN_RIGHT) \
  96. || ((__DATA_ALIGN__) == LL_ADC_DATA_ALIGN_LEFT) \
  97. )
  98. #define IS_LL_ADC_LOW_POWER(__LOW_POWER__) \
  99. ( ((__LOW_POWER__) == LL_ADC_LP_MODE_NONE) \
  100. || ((__LOW_POWER__) == LL_ADC_LP_AUTOWAIT) \
  101. )
  102. /* Check of parameters for configuration of ADC hierarchical scope: */
  103. /* ADC group regular */
  104. #if defined(STM32F303xE) || defined(STM32F398xx)
  105. #define IS_LL_ADC_REG_TRIG_SOURCE(__ADC_INSTANCE__, __REG_TRIG_SOURCE__) \
  106. ((((__ADC_INSTANCE__) == ADC1) || ((__ADC_INSTANCE__) == ADC2)) \
  107. ? ( ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_SOFTWARE) \
  108. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_CH1_ADC12) \
  109. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_CH2_ADC12) \
  110. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_CH3) \
  111. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM2_CH2_ADC12) \
  112. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM3_TRGO_ADC12) \
  113. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM4_CH4_ADC12) \
  114. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_EXTI_LINE11_ADC12) \
  115. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM8_TRGO_ADC12) \
  116. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM8_TRGO2) \
  117. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_TRGO) \
  118. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_TRGO2) \
  119. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM2_TRGO_ADC12) \
  120. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM4_TRGO) \
  121. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM6_TRGO_ADC12) \
  122. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM15_TRGO) \
  123. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM3_CH4_ADC12) \
  124. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM20_TRG0_ADC12) \
  125. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM20_TRG02_ADC12) \
  126. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM20_CH1_ADC12) \
  127. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM20_CH2_ADC12) \
  128. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM20_CH3_ADC12) \
  129. ) \
  130. : \
  131. ( ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_SOFTWARE) \
  132. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM3_CH1_ADC34) \
  133. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM2_CH3_ADC34) \
  134. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_CH3) \
  135. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM8_CH1_ADC34) \
  136. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM8_TRGO__ADC34) \
  137. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_EXTI_LINE2_ADC34) \
  138. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM4_CH1_ADC34) \
  139. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM2_TRGO__ADC34) \
  140. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM8_TRGO2) \
  141. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_TRGO) \
  142. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_TRGO2) \
  143. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM3_TRGO__ADC34) \
  144. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM4_TRGO) \
  145. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM7_TRGO_ADC34) \
  146. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM15_TRGO) \
  147. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM2_CH1_ADC34) \
  148. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM20_TRG0_ADC34) \
  149. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM20_TRG02_ADC34) \
  150. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM20_CH1_ADC34) \
  151. ) \
  152. )
  153. #elif defined(STM32F303xC) || defined(STM32F358xx)
  154. #define IS_LL_ADC_REG_TRIG_SOURCE(__ADC_INSTANCE__, __REG_TRIG_SOURCE__) \
  155. ((((__ADC_INSTANCE__) == ADC1) || ((__ADC_INSTANCE__) == ADC2)) \
  156. ? ( ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_SOFTWARE) \
  157. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_CH1_ADC12) \
  158. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_CH2_ADC12) \
  159. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_CH3) \
  160. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM2_CH2_ADC12) \
  161. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM3_TRGO_ADC12) \
  162. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM4_CH4_ADC12) \
  163. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_EXTI_LINE11_ADC12) \
  164. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM8_TRGO_ADC12) \
  165. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM8_TRGO2) \
  166. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_TRGO) \
  167. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_TRGO2) \
  168. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM2_TRGO_ADC12) \
  169. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM4_TRGO) \
  170. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM6_TRGO_ADC12) \
  171. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM15_TRGO) \
  172. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM3_CH4_ADC12) \
  173. ) \
  174. : \
  175. ( ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_SOFTWARE) \
  176. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM3_CH1_ADC34) \
  177. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM2_CH3_ADC34) \
  178. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_CH3) \
  179. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM8_CH1_ADC34) \
  180. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM8_TRGO__ADC34) \
  181. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_EXTI_LINE2_ADC34) \
  182. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM4_CH1_ADC34) \
  183. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM2_TRGO__ADC34) \
  184. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM8_TRGO2) \
  185. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_TRGO) \
  186. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_TRGO2) \
  187. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM3_TRGO__ADC34) \
  188. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM4_TRGO) \
  189. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM7_TRGO_ADC34) \
  190. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM15_TRGO) \
  191. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM2_CH1_ADC34) \
  192. ) \
  193. )
  194. #elif defined(STM32F303x8) || defined(STM32F328xx)
  195. #define IS_LL_ADC_REG_TRIG_SOURCE(__REG_TRIG_SOURCE__) \
  196. ( ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_SOFTWARE) \
  197. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_CH1) \
  198. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_CH2) \
  199. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_CH3) \
  200. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM2_CH2) \
  201. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM3_TRGO) \
  202. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM4_CH4) \
  203. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_EXTI_LINE11) \
  204. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM8_TRGO) \
  205. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_TRGO) \
  206. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_TRGO2) \
  207. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM2_TRGO) \
  208. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM4_TRGO) \
  209. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM6_TRGO) \
  210. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM15_TRGO) \
  211. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM3_CH4) \
  212. )
  213. #elif defined(STM32F334x8)
  214. #define IS_LL_ADC_REG_TRIG_SOURCE(__REG_TRIG_SOURCE__) \
  215. ( ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_SOFTWARE) \
  216. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_CH1) \
  217. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_CH2) \
  218. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_CH3) \
  219. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM2_CH2) \
  220. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM3_TRGO) \
  221. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_EXTI_LINE11) \
  222. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_HRTIM_TRG1) \
  223. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_HRTIM_TRG3) \
  224. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_TRGO) \
  225. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_TRGO2) \
  226. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM2_TRGO) \
  227. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM6_TRGO) \
  228. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM15_TRGO) \
  229. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM3_CH4) \
  230. )
  231. #elif defined(STM32F302xC) || defined(STM32F302xE)
  232. #define IS_LL_ADC_REG_TRIG_SOURCE(__REG_TRIG_SOURCE__) \
  233. ( ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_SOFTWARE) \
  234. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_CH1) \
  235. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_CH2) \
  236. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_CH3) \
  237. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM2_CH2) \
  238. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM3_TRGO) \
  239. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM4_CH4) \
  240. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_EXTI_LINE11) \
  241. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_TRGO) \
  242. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_TRGO2) \
  243. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM2_TRGO) \
  244. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM4_TRGO) \
  245. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM6_TRGO) \
  246. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM15_TRGO) \
  247. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM3_CH4) \
  248. )
  249. #elif defined(STM32F301x8) || defined(STM32F302x8) || defined(STM32F318xx)
  250. #define IS_LL_ADC_REG_TRIG_SOURCE(__REG_TRIG_SOURCE__) \
  251. ( ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_SOFTWARE) \
  252. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_CH1) \
  253. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_CH2) \
  254. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_CH3) \
  255. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM2_CH2) \
  256. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_EXTI_LINE11) \
  257. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_TRGO) \
  258. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_TRGO2) \
  259. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM2_TRGO) \
  260. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM6_TRGO) \
  261. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM15_TRGO) \
  262. )
  263. #endif
  264. #define IS_LL_ADC_REG_CONTINUOUS_MODE(__REG_CONTINUOUS_MODE__) \
  265. ( ((__REG_CONTINUOUS_MODE__) == LL_ADC_REG_CONV_SINGLE) \
  266. || ((__REG_CONTINUOUS_MODE__) == LL_ADC_REG_CONV_CONTINUOUS) \
  267. )
  268. #define IS_LL_ADC_REG_DMA_TRANSFER(__REG_DMA_TRANSFER__) \
  269. ( ((__REG_DMA_TRANSFER__) == LL_ADC_REG_DMA_TRANSFER_NONE) \
  270. || ((__REG_DMA_TRANSFER__) == LL_ADC_REG_DMA_TRANSFER_LIMITED) \
  271. || ((__REG_DMA_TRANSFER__) == LL_ADC_REG_DMA_TRANSFER_UNLIMITED) \
  272. )
  273. #define IS_LL_ADC_REG_OVR_DATA_BEHAVIOR(__REG_OVR_DATA_BEHAVIOR__) \
  274. ( ((__REG_OVR_DATA_BEHAVIOR__) == LL_ADC_REG_OVR_DATA_PRESERVED) \
  275. || ((__REG_OVR_DATA_BEHAVIOR__) == LL_ADC_REG_OVR_DATA_OVERWRITTEN) \
  276. )
  277. #define IS_LL_ADC_REG_SEQ_SCAN_LENGTH(__REG_SEQ_SCAN_LENGTH__) \
  278. ( ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_DISABLE) \
  279. || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_2RANKS) \
  280. || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_3RANKS) \
  281. || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_4RANKS) \
  282. || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_5RANKS) \
  283. || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_6RANKS) \
  284. || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_7RANKS) \
  285. || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_8RANKS) \
  286. || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_9RANKS) \
  287. || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_10RANKS) \
  288. || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_11RANKS) \
  289. || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_12RANKS) \
  290. || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_13RANKS) \
  291. || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_14RANKS) \
  292. || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_15RANKS) \
  293. || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_16RANKS) \
  294. )
  295. #define IS_LL_ADC_REG_SEQ_SCAN_DISCONT_MODE(__REG_SEQ_DISCONT_MODE__) \
  296. ( ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_DISABLE) \
  297. || ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_1RANK) \
  298. || ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_2RANKS) \
  299. || ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_3RANKS) \
  300. || ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_4RANKS) \
  301. || ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_5RANKS) \
  302. || ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_6RANKS) \
  303. || ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_7RANKS) \
  304. || ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_8RANKS) \
  305. )
  306. /* Check of parameters for configuration of ADC hierarchical scope: */
  307. /* ADC group injected */
  308. #if defined(STM32F303xE) || defined(STM32F398xx)
  309. #define IS_LL_ADC_INJ_TRIG_SOURCE(__ADC_INSTANCE__, __INJ_TRIG_SOURCE__) \
  310. ((((__ADC_INSTANCE__) == ADC1) || ((__ADC_INSTANCE__) == ADC2)) \
  311. ? ( ((__INJ_TRIG_SOURCE__) == LL_ADC_REG_TRIG_SOFTWARE) \
  312. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM1_TRGO) \
  313. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM1_CH4) \
  314. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM2_TRGO_ADC12) \
  315. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM2_CH1_ADC12) \
  316. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM3_CH4_ADC12) \
  317. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM4_TRGO_ADC12) \
  318. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_EXTI_LINE15_ADC12) \
  319. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM8_CH4_ADC12) \
  320. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM1_TRGO2) \
  321. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM8_TRGO) \
  322. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM8_TRGO2) \
  323. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM3_CH3_ADC12) \
  324. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM3_TRGO) \
  325. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM3_CH1_ADC12) \
  326. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM6_TRGO_ADC12) \
  327. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM15_TRGO) \
  328. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM20_TRGO_ADC12) \
  329. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM20_TRGO2_ADC12) \
  330. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM20_CH4_ADC12) \
  331. ) \
  332. : \
  333. ( ((__INJ_TRIG_SOURCE__) == LL_ADC_REG_TRIG_SOFTWARE) \
  334. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM1_TRGO) \
  335. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM1_CH4) \
  336. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM4_CH3_ADC34) \
  337. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM8_CH2_ADC34) \
  338. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM8_CH4__ADC34) \
  339. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM4_CH4_ADC34) \
  340. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM4_TRGO__ADC34) \
  341. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM1_TRGO2) \
  342. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM8_TRGO) \
  343. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM8_TRGO2) \
  344. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM1_CH3_ADC34) \
  345. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM3_TRGO) \
  346. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM2_TRGO__ADC34) \
  347. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM7_TRGO_ADC34) \
  348. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM15_TRGO) \
  349. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM20_TRG_ADC34) \
  350. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM20_TRG2_ADC34) \
  351. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM20_CH2) \
  352. ) \
  353. )
  354. #elif defined(STM32F303xC) || defined(STM32F358xx)
  355. #define IS_LL_ADC_INJ_TRIG_SOURCE(__ADC_INSTANCE__, __INJ_TRIG_SOURCE__) \
  356. ((((__ADC_INSTANCE__) == ADC1) || ((__ADC_INSTANCE__) == ADC2)) \
  357. ? ( ((__INJ_TRIG_SOURCE__) == LL_ADC_REG_TRIG_SOFTWARE) \
  358. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM1_TRGO) \
  359. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM1_CH4) \
  360. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM2_TRGO_ADC12) \
  361. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM2_CH1_ADC12) \
  362. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM3_CH4_ADC12) \
  363. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM4_TRGO_ADC12) \
  364. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_EXTI_LINE15_ADC12) \
  365. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM8_CH4_ADC12) \
  366. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM1_TRGO2) \
  367. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM8_TRGO) \
  368. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM8_TRGO2) \
  369. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM3_CH3_ADC12) \
  370. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM3_TRGO) \
  371. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM3_CH1_ADC12) \
  372. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM6_TRGO_ADC12) \
  373. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM15_TRGO) \
  374. ) \
  375. : \
  376. ( ((__INJ_TRIG_SOURCE__) == LL_ADC_REG_TRIG_SOFTWARE) \
  377. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM1_TRGO) \
  378. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM1_CH4) \
  379. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM4_CH3_ADC34) \
  380. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM8_CH2_ADC34) \
  381. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM8_CH4__ADC34) \
  382. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM4_CH4_ADC34) \
  383. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM4_TRGO__ADC34) \
  384. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM1_TRGO2) \
  385. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM8_TRGO) \
  386. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM8_TRGO2) \
  387. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM1_CH3_ADC34) \
  388. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM3_TRGO) \
  389. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM2_TRGO__ADC34) \
  390. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM7_TRGO_ADC34) \
  391. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM15_TRGO) \
  392. ) \
  393. )
  394. #elif defined(STM32F303x8) || defined(STM32F328xx)
  395. #define IS_LL_ADC_INJ_TRIG_SOURCE(__INJ_TRIG_SOURCE__) \
  396. ( ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_SOFTWARE) \
  397. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM1_TRGO) \
  398. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM1_CH4) \
  399. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM2_TRGO) \
  400. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM2_CH1) \
  401. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM3_CH4) \
  402. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM4_TRGO) \
  403. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_EXTI_LINE15) \
  404. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM8_CH4) \
  405. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM1_TRGO2) \
  406. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM8_TRGO) \
  407. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM8_TRGO2) \
  408. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM3_CH3) \
  409. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM3_TRGO) \
  410. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM3_CH1) \
  411. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM6_TRGO) \
  412. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM15_TRGO) \
  413. )
  414. #elif defined(STM32F334x8)
  415. #define IS_LL_ADC_INJ_TRIG_SOURCE(__INJ_TRIG_SOURCE__) \
  416. ( ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_SOFTWARE) \
  417. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM1_TRGO) \
  418. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM1_CH4) \
  419. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM2_TRGO) \
  420. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM2_CH1) \
  421. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM3_CH4) \
  422. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_EXTI_LINE15) \
  423. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM1_TRGO2) \
  424. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_HRTIM_TRG2) \
  425. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_HRTIM_TRG4) \
  426. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM3_CH3) \
  427. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM3_TRGO) \
  428. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM3_CH1) \
  429. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM6_TRGO) \
  430. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM15_TRGO) \
  431. )
  432. #elif defined(STM32F302xC) || defined(STM32F302xE)
  433. #define IS_LL_ADC_INJ_TRIG_SOURCE(__INJ_TRIG_SOURCE__) \
  434. ( ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_SOFTWARE) \
  435. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM1_TRGO) \
  436. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM1_CH4) \
  437. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM2_TRGO) \
  438. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM2_CH1) \
  439. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM3_CH4) \
  440. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM4_TRGO) \
  441. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_EXTI_LINE15) \
  442. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM1_TRGO2) \
  443. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM3_CH3) \
  444. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM3_TRGO) \
  445. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM3_CH1) \
  446. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM6_TRGO) \
  447. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM15_TRGO) \
  448. )
  449. #elif defined(STM32F301x8) || defined(STM32F302x8) || defined(STM32F318xx)
  450. #define IS_LL_ADC_INJ_TRIG_SOURCE(__INJ_TRIG_SOURCE__) \
  451. ( ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_SOFTWARE) \
  452. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM1_TRGO) \
  453. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM1_CH4) \
  454. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_EXTI_LINE15) \
  455. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM1_TRGO2) \
  456. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM6_TRGO) \
  457. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM15_TRGO) \
  458. )
  459. #endif
  460. #define IS_LL_ADC_INJ_TRIG_EXT_EDGE(__INJ_TRIG_EXT_EDGE__) \
  461. ( ((__INJ_TRIG_EXT_EDGE__) == LL_ADC_INJ_TRIG_EXT_RISING) \
  462. || ((__INJ_TRIG_EXT_EDGE__) == LL_ADC_INJ_TRIG_EXT_FALLING) \
  463. || ((__INJ_TRIG_EXT_EDGE__) == LL_ADC_INJ_TRIG_EXT_RISINGFALLING) \
  464. )
  465. #define IS_LL_ADC_INJ_TRIG_AUTO(__INJ_TRIG_AUTO__) \
  466. ( ((__INJ_TRIG_AUTO__) == LL_ADC_INJ_TRIG_INDEPENDENT) \
  467. || ((__INJ_TRIG_AUTO__) == LL_ADC_INJ_TRIG_FROM_GRP_REGULAR) \
  468. )
  469. #define IS_LL_ADC_INJ_SEQ_SCAN_LENGTH(__INJ_SEQ_SCAN_LENGTH__) \
  470. ( ((__INJ_SEQ_SCAN_LENGTH__) == LL_ADC_INJ_SEQ_SCAN_DISABLE) \
  471. || ((__INJ_SEQ_SCAN_LENGTH__) == LL_ADC_INJ_SEQ_SCAN_ENABLE_2RANKS) \
  472. || ((__INJ_SEQ_SCAN_LENGTH__) == LL_ADC_INJ_SEQ_SCAN_ENABLE_3RANKS) \
  473. || ((__INJ_SEQ_SCAN_LENGTH__) == LL_ADC_INJ_SEQ_SCAN_ENABLE_4RANKS) \
  474. )
  475. #define IS_LL_ADC_INJ_SEQ_SCAN_DISCONT_MODE(__INJ_SEQ_DISCONT_MODE__) \
  476. ( ((__INJ_SEQ_DISCONT_MODE__) == LL_ADC_INJ_SEQ_DISCONT_DISABLE) \
  477. || ((__INJ_SEQ_DISCONT_MODE__) == LL_ADC_INJ_SEQ_DISCONT_1RANK) \
  478. )
  479. #if defined(ADC_MULTIMODE_SUPPORT)
  480. /* Check of parameters for configuration of ADC hierarchical scope: */
  481. /* multimode. */
  482. #define IS_LL_ADC_MULTI_MODE(__MULTI_MODE__) \
  483. ( ((__MULTI_MODE__) == LL_ADC_MULTI_INDEPENDENT) \
  484. || ((__MULTI_MODE__) == LL_ADC_MULTI_DUAL_REG_SIMULT) \
  485. || ((__MULTI_MODE__) == LL_ADC_MULTI_DUAL_REG_INTERL) \
  486. || ((__MULTI_MODE__) == LL_ADC_MULTI_DUAL_INJ_SIMULT) \
  487. || ((__MULTI_MODE__) == LL_ADC_MULTI_DUAL_INJ_ALTERN) \
  488. || ((__MULTI_MODE__) == LL_ADC_MULTI_DUAL_REG_SIM_INJ_SIM) \
  489. || ((__MULTI_MODE__) == LL_ADC_MULTI_DUAL_REG_SIM_INJ_ALT) \
  490. || ((__MULTI_MODE__) == LL_ADC_MULTI_DUAL_REG_INT_INJ_SIM) \
  491. )
  492. #define IS_LL_ADC_MULTI_DMA_TRANSFER(__MULTI_DMA_TRANSFER__) \
  493. ( ((__MULTI_DMA_TRANSFER__) == LL_ADC_MULTI_REG_DMA_EACH_ADC) \
  494. || ((__MULTI_DMA_TRANSFER__) == LL_ADC_MULTI_REG_DMA_LIMIT_RES12_10B) \
  495. || ((__MULTI_DMA_TRANSFER__) == LL_ADC_MULTI_REG_DMA_LIMIT_RES8_6B) \
  496. || ((__MULTI_DMA_TRANSFER__) == LL_ADC_MULTI_REG_DMA_UNLMT_RES12_10B) \
  497. || ((__MULTI_DMA_TRANSFER__) == LL_ADC_MULTI_REG_DMA_UNLMT_RES8_6B) \
  498. )
  499. #define IS_LL_ADC_MULTI_TWOSMP_DELAY(__MULTI_TWOSMP_DELAY__) \
  500. ( ((__MULTI_TWOSMP_DELAY__) == LL_ADC_MULTI_TWOSMP_DELAY_1CYCLE) \
  501. || ((__MULTI_TWOSMP_DELAY__) == LL_ADC_MULTI_TWOSMP_DELAY_2CYCLES) \
  502. || ((__MULTI_TWOSMP_DELAY__) == LL_ADC_MULTI_TWOSMP_DELAY_3CYCLES) \
  503. || ((__MULTI_TWOSMP_DELAY__) == LL_ADC_MULTI_TWOSMP_DELAY_4CYCLES) \
  504. || ((__MULTI_TWOSMP_DELAY__) == LL_ADC_MULTI_TWOSMP_DELAY_5CYCLES) \
  505. || ((__MULTI_TWOSMP_DELAY__) == LL_ADC_MULTI_TWOSMP_DELAY_6CYCLES) \
  506. || ((__MULTI_TWOSMP_DELAY__) == LL_ADC_MULTI_TWOSMP_DELAY_7CYCLES) \
  507. || ((__MULTI_TWOSMP_DELAY__) == LL_ADC_MULTI_TWOSMP_DELAY_8CYCLES) \
  508. || ((__MULTI_TWOSMP_DELAY__) == LL_ADC_MULTI_TWOSMP_DELAY_9CYCLES) \
  509. || ((__MULTI_TWOSMP_DELAY__) == LL_ADC_MULTI_TWOSMP_DELAY_10CYCLES) \
  510. || ((__MULTI_TWOSMP_DELAY__) == LL_ADC_MULTI_TWOSMP_DELAY_11CYCLES) \
  511. || ((__MULTI_TWOSMP_DELAY__) == LL_ADC_MULTI_TWOSMP_DELAY_12CYCLES) \
  512. )
  513. #define IS_LL_ADC_MULTI_MASTER_SLAVE(__MULTI_MASTER_SLAVE__) \
  514. ( ((__MULTI_MASTER_SLAVE__) == LL_ADC_MULTI_MASTER) \
  515. || ((__MULTI_MASTER_SLAVE__) == LL_ADC_MULTI_SLAVE) \
  516. || ((__MULTI_MASTER_SLAVE__) == LL_ADC_MULTI_MASTER_SLAVE) \
  517. )
  518. #endif /* ADC_MULTIMODE_SUPPORT */
  519. /**
  520. * @}
  521. */
  522. /* Private function prototypes -----------------------------------------------*/
  523. /* Exported functions --------------------------------------------------------*/
  524. /** @addtogroup ADC_LL_Exported_Functions
  525. * @{
  526. */
  527. /** @addtogroup ADC_LL_EF_Init
  528. * @{
  529. */
  530. /**
  531. * @brief De-initialize registers of all ADC instances belonging to
  532. * the same ADC common instance to their default reset values.
  533. * @note This function is performing a hard reset, using high level
  534. * clock source RCC ADC reset.
  535. * Caution: On this STM32 series, if several ADC instances are available
  536. * on the selected device, RCC ADC reset will reset
  537. * all ADC instances belonging to the common ADC instance.
  538. * To de-initialize only 1 ADC instance, use
  539. * function @ref LL_ADC_DeInit().
  540. * @param ADCxy_COMMON ADC common instance
  541. * (can be set directly from CMSIS definition or by using helper macro @ref __LL_ADC_COMMON_INSTANCE() )
  542. * @retval An ErrorStatus enumeration value:
  543. * - SUCCESS: ADC common registers are de-initialized
  544. * - ERROR: not applicable
  545. */
  546. ErrorStatus LL_ADC_CommonDeInit(ADC_Common_TypeDef *ADCxy_COMMON)
  547. {
  548. /* Check the parameters */
  549. assert_param(IS_ADC_COMMON_INSTANCE(ADCxy_COMMON));
  550. /* Force reset of ADC clock (core clock) */
  551. #if defined(ADC1) && defined(ADC2) && defined(ADC3) && defined(ADC4)
  552. if(ADCxy_COMMON == ADC12_COMMON)
  553. {
  554. LL_AHB1_GRP1_ForceReset (LL_AHB1_GRP1_PERIPH_ADC12);
  555. }
  556. else
  557. {
  558. LL_AHB1_GRP1_ForceReset (LL_AHB1_GRP1_PERIPH_ADC34);
  559. }
  560. #elif defined(ADC1) && defined(ADC2)
  561. LL_AHB1_GRP1_ForceReset (LL_AHB1_GRP1_PERIPH_ADC12);
  562. #elif defined(ADC1)
  563. LL_AHB1_GRP1_ForceReset (LL_AHB1_GRP1_PERIPH_ADC1);
  564. #endif
  565. /* Release reset of ADC clock (core clock) */
  566. #if defined(ADC1) && defined(ADC2) && defined(ADC3) && defined(ADC4)
  567. if(ADCxy_COMMON == ADC12_COMMON)
  568. {
  569. LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_ADC12);
  570. }
  571. else
  572. {
  573. LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_ADC34);
  574. }
  575. #elif defined(ADC1) && defined(ADC2)
  576. LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_ADC12);
  577. #elif defined(ADC1)
  578. LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_ADC1);
  579. #endif
  580. return SUCCESS;
  581. }
  582. /**
  583. * @brief Initialize some features of ADC common parameters
  584. * (all ADC instances belonging to the same ADC common instance)
  585. * and multimode (for devices with several ADC instances available).
  586. * @note The setting of ADC common parameters is conditioned to
  587. * ADC instances state:
  588. * All ADC instances belonging to the same ADC common instance
  589. * must be disabled.
  590. * @param ADCxy_COMMON ADC common instance
  591. * (can be set directly from CMSIS definition or by using helper macro @ref __LL_ADC_COMMON_INSTANCE() )
  592. * @param ADC_CommonInitStruct Pointer to a @ref LL_ADC_CommonInitTypeDef structure
  593. * @retval An ErrorStatus enumeration value:
  594. * - SUCCESS: ADC common registers are initialized
  595. * - ERROR: ADC common registers are not initialized
  596. */
  597. ErrorStatus LL_ADC_CommonInit(ADC_Common_TypeDef *ADCxy_COMMON, LL_ADC_CommonInitTypeDef *ADC_CommonInitStruct)
  598. {
  599. ErrorStatus status = SUCCESS;
  600. /* Check the parameters */
  601. assert_param(IS_ADC_COMMON_INSTANCE(ADCxy_COMMON));
  602. assert_param(IS_LL_ADC_COMMON_CLOCK(ADC_CommonInitStruct->CommonClock));
  603. #if defined(ADC_MULTIMODE_SUPPORT)
  604. assert_param(IS_LL_ADC_MULTI_MODE(ADC_CommonInitStruct->Multimode));
  605. if(ADC_CommonInitStruct->Multimode != LL_ADC_MULTI_INDEPENDENT)
  606. {
  607. assert_param(IS_LL_ADC_MULTI_DMA_TRANSFER(ADC_CommonInitStruct->MultiDMATransfer));
  608. assert_param(IS_LL_ADC_MULTI_TWOSMP_DELAY(ADC_CommonInitStruct->MultiTwoSamplingDelay));
  609. }
  610. #endif /* ADC_MULTIMODE_SUPPORT */
  611. /* Note: Hardware constraint (refer to description of functions */
  612. /* "LL_ADC_SetCommonXXX()" and "LL_ADC_SetMultiXXX()"): */
  613. /* On this STM32 series, setting of these features is conditioned to */
  614. /* ADC state: */
  615. /* All ADC instances of the ADC common group must be disabled. */
  616. if(__LL_ADC_IS_ENABLED_ALL_COMMON_INSTANCE(ADCxy_COMMON) == 0U)
  617. {
  618. /* Configuration of ADC hierarchical scope: */
  619. /* - common to several ADC */
  620. /* (all ADC instances belonging to the same ADC common instance) */
  621. /* - Set ADC clock (conversion clock) */
  622. /* - multimode (if several ADC instances available on the */
  623. /* selected device) */
  624. /* - Set ADC multimode configuration */
  625. /* - Set ADC multimode DMA transfer */
  626. /* - Set ADC multimode: delay between 2 sampling phases */
  627. #if defined(ADC_MULTIMODE_SUPPORT)
  628. if(ADC_CommonInitStruct->Multimode != LL_ADC_MULTI_INDEPENDENT)
  629. {
  630. MODIFY_REG(ADCxy_COMMON->CCR,
  631. ADC_CCR_CKMODE
  632. | ADC_CCR_DUAL
  633. | ADC_CCR_MDMA
  634. | ADC_CCR_DELAY
  635. ,
  636. ADC_CommonInitStruct->CommonClock
  637. | ADC_CommonInitStruct->Multimode
  638. | ADC_CommonInitStruct->MultiDMATransfer
  639. | ADC_CommonInitStruct->MultiTwoSamplingDelay
  640. );
  641. }
  642. else
  643. {
  644. MODIFY_REG(ADCxy_COMMON->CCR,
  645. ADC_CCR_CKMODE
  646. | ADC_CCR_DUAL
  647. | ADC_CCR_MDMA
  648. | ADC_CCR_DELAY
  649. ,
  650. ADC_CommonInitStruct->CommonClock
  651. | LL_ADC_MULTI_INDEPENDENT
  652. );
  653. }
  654. #else
  655. LL_ADC_SetCommonClock(ADCxy_COMMON, ADC_CommonInitStruct->CommonClock);
  656. #endif
  657. }
  658. else
  659. {
  660. /* Initialization error: One or several ADC instances belonging to */
  661. /* the same ADC common instance are not disabled. */
  662. status = ERROR;
  663. }
  664. return status;
  665. }
  666. /**
  667. * @brief Set each @ref LL_ADC_CommonInitTypeDef field to default value.
  668. * @param ADC_CommonInitStruct Pointer to a @ref LL_ADC_CommonInitTypeDef structure
  669. * whose fields will be set to default values.
  670. * @retval None
  671. */
  672. void LL_ADC_CommonStructInit(LL_ADC_CommonInitTypeDef *ADC_CommonInitStruct)
  673. {
  674. /* Set ADC_CommonInitStruct fields to default values */
  675. /* Set fields of ADC common */
  676. /* (all ADC instances belonging to the same ADC common instance) */
  677. ADC_CommonInitStruct->CommonClock = LL_ADC_CLOCK_SYNC_PCLK_DIV2;
  678. #if defined(ADC_MULTIMODE_SUPPORT)
  679. /* Set fields of ADC multimode */
  680. ADC_CommonInitStruct->Multimode = LL_ADC_MULTI_INDEPENDENT;
  681. ADC_CommonInitStruct->MultiDMATransfer = LL_ADC_MULTI_REG_DMA_EACH_ADC;
  682. ADC_CommonInitStruct->MultiTwoSamplingDelay = LL_ADC_MULTI_TWOSMP_DELAY_1CYCLE;
  683. #endif /* ADC_MULTIMODE_SUPPORT */
  684. }
  685. /**
  686. * @brief De-initialize registers of the selected ADC instance
  687. * to their default reset values.
  688. * @note To reset all ADC instances quickly (perform a hard reset),
  689. * use function @ref LL_ADC_CommonDeInit().
  690. * @note If this functions returns error status, it means that ADC instance
  691. * is in an unknown state.
  692. * In this case, perform a hard reset using high level
  693. * clock source RCC ADC reset.
  694. * Caution: On this STM32 series, if several ADC instances are available
  695. * on the selected device, RCC ADC reset will reset
  696. * all ADC instances belonging to the common ADC instance.
  697. * Refer to function @ref LL_ADC_CommonDeInit().
  698. * @param ADCx ADC instance
  699. * @retval An ErrorStatus enumeration value:
  700. * - SUCCESS: ADC registers are de-initialized
  701. * - ERROR: ADC registers are not de-initialized
  702. */
  703. ErrorStatus LL_ADC_DeInit(ADC_TypeDef *ADCx)
  704. {
  705. ErrorStatus status = SUCCESS;
  706. __IO uint32_t timeout_cpu_cycles = 0U;
  707. /* Check the parameters */
  708. assert_param(IS_ADC_ALL_INSTANCE(ADCx));
  709. /* Disable ADC instance if not already disabled. */
  710. if(LL_ADC_IsEnabled(ADCx) == 1U)
  711. {
  712. /* Set ADC group regular trigger source to SW start to ensure to not */
  713. /* have an external trigger event occurring during the conversion stop */
  714. /* ADC disable process. */
  715. LL_ADC_REG_SetTriggerSource(ADCx, LL_ADC_REG_TRIG_SOFTWARE);
  716. /* Stop potential ADC conversion on going on ADC group regular. */
  717. if(LL_ADC_REG_IsConversionOngoing(ADCx) != 0U)
  718. {
  719. if(LL_ADC_REG_IsStopConversionOngoing(ADCx) == 0U)
  720. {
  721. LL_ADC_REG_StopConversion(ADCx);
  722. }
  723. }
  724. /* Set ADC group injected trigger source to SW start to ensure to not */
  725. /* have an external trigger event occurring during the conversion stop */
  726. /* ADC disable process. */
  727. LL_ADC_INJ_SetTriggerSource(ADCx, LL_ADC_INJ_TRIG_SOFTWARE);
  728. /* Stop potential ADC conversion on going on ADC group injected. */
  729. if(LL_ADC_INJ_IsConversionOngoing(ADCx) != 0U)
  730. {
  731. if(LL_ADC_INJ_IsStopConversionOngoing(ADCx) == 0U)
  732. {
  733. LL_ADC_INJ_StopConversion(ADCx);
  734. }
  735. }
  736. /* Wait for ADC conversions are effectively stopped */
  737. timeout_cpu_cycles = ADC_TIMEOUT_STOP_CONVERSION_CPU_CYCLES;
  738. while (( LL_ADC_REG_IsStopConversionOngoing(ADCx)
  739. | LL_ADC_INJ_IsStopConversionOngoing(ADCx)) == 1U)
  740. {
  741. timeout_cpu_cycles--;
  742. if(timeout_cpu_cycles == 0U)
  743. {
  744. /* Time-out error */
  745. status = ERROR;
  746. }
  747. }
  748. /* Flush group injected contexts queue (register JSQR): */
  749. /* Note: Bit JQM must be set to empty the contexts queue (otherwise */
  750. /* contexts queue is maintained with the last active context). */
  751. LL_ADC_INJ_SetQueueMode(ADCx, LL_ADC_INJ_QUEUE_2CONTEXTS_END_EMPTY);
  752. /* Disable the ADC instance */
  753. LL_ADC_Disable(ADCx);
  754. /* Wait for ADC instance is effectively disabled */
  755. timeout_cpu_cycles = ADC_TIMEOUT_DISABLE_CPU_CYCLES;
  756. while (LL_ADC_IsDisableOngoing(ADCx) == 1U)
  757. {
  758. timeout_cpu_cycles--;
  759. if(timeout_cpu_cycles == 0U)
  760. {
  761. /* Time-out error */
  762. status = ERROR;
  763. }
  764. }
  765. }
  766. /* Check whether ADC state is compliant with expected state */
  767. if(READ_BIT(ADCx->CR,
  768. ( ADC_CR_JADSTP | ADC_CR_ADSTP | ADC_CR_JADSTART | ADC_CR_ADSTART
  769. | ADC_CR_ADDIS | ADC_CR_ADEN )
  770. )
  771. == 0U)
  772. {
  773. /* ========== Reset ADC registers ========== */
  774. /* Reset register IER */
  775. CLEAR_BIT(ADCx->IER,
  776. ( LL_ADC_IT_ADRDY
  777. | LL_ADC_IT_EOC
  778. | LL_ADC_IT_EOS
  779. | LL_ADC_IT_OVR
  780. | LL_ADC_IT_EOSMP
  781. | LL_ADC_IT_JEOC
  782. | LL_ADC_IT_JEOS
  783. | LL_ADC_IT_JQOVF
  784. | LL_ADC_IT_AWD1
  785. | LL_ADC_IT_AWD2
  786. | LL_ADC_IT_AWD3 )
  787. );
  788. /* Reset register ISR */
  789. SET_BIT(ADCx->ISR,
  790. ( LL_ADC_FLAG_ADRDY
  791. | LL_ADC_FLAG_EOC
  792. | LL_ADC_FLAG_EOS
  793. | LL_ADC_FLAG_OVR
  794. | LL_ADC_FLAG_EOSMP
  795. | LL_ADC_FLAG_JEOC
  796. | LL_ADC_FLAG_JEOS
  797. | LL_ADC_FLAG_JQOVF
  798. | LL_ADC_FLAG_AWD1
  799. | LL_ADC_FLAG_AWD2
  800. | LL_ADC_FLAG_AWD3 )
  801. );
  802. /* Reset register CR */
  803. /* - Bits ADC_CR_JADSTP, ADC_CR_ADSTP, ADC_CR_JADSTART, ADC_CR_ADSTART, */
  804. /* ADC_CR_ADCAL, ADC_CR_ADDIS, ADC_CR_ADEN are in */
  805. /* access mode "read-set": no direct reset applicable. */
  806. /* - Reset Calibration mode to default setting (single ended). */
  807. /* - Disable ADC internal voltage regulator. */
  808. /* Note: ADC internal voltage regulator disable is conditioned to */
  809. /* ADC state disabled: already done above. */
  810. /* Sequence to disable voltage regulator: */
  811. /* 1. Set the intermediate state before moving the ADC voltage regulator */
  812. /* to disable state. */
  813. CLEAR_BIT(ADCx->CR, ADC_CR_ADVREGEN_1 | ADC_CR_ADVREGEN_0 | ADC_CR_ADCALDIF);
  814. /* 2. Set ADVREGEN bits to 0x10 */
  815. SET_BIT(ADCx->CR, ADC_CR_ADVREGEN_1);
  816. /* Reset register CFGR */
  817. CLEAR_BIT(ADCx->CFGR,
  818. ( ADC_CFGR_AWD1CH | ADC_CFGR_JAUTO | ADC_CFGR_JAWD1EN
  819. | ADC_CFGR_AWD1EN | ADC_CFGR_AWD1SGL | ADC_CFGR_JQM
  820. | ADC_CFGR_JDISCEN | ADC_CFGR_DISCNUM | ADC_CFGR_DISCEN
  821. | ADC_CFGR_AUTDLY | ADC_CFGR_CONT | ADC_CFGR_OVRMOD
  822. | ADC_CFGR_EXTEN | ADC_CFGR_EXTSEL | ADC_CFGR_ALIGN
  823. | ADC_CFGR_RES | ADC_CFGR_DMACFG | ADC_CFGR_DMAEN )
  824. );
  825. /* Reset register SMPR1 */
  826. CLEAR_BIT(ADCx->SMPR1,
  827. ( ADC_SMPR1_SMP9 | ADC_SMPR1_SMP8 | ADC_SMPR1_SMP7
  828. | ADC_SMPR1_SMP6 | ADC_SMPR1_SMP5 | ADC_SMPR1_SMP4
  829. | ADC_SMPR1_SMP3 | ADC_SMPR1_SMP2 | ADC_SMPR1_SMP1)
  830. );
  831. /* Reset register SMPR2 */
  832. CLEAR_BIT(ADCx->SMPR2,
  833. ( ADC_SMPR2_SMP18 | ADC_SMPR2_SMP17 | ADC_SMPR2_SMP16
  834. | ADC_SMPR2_SMP15 | ADC_SMPR2_SMP14 | ADC_SMPR2_SMP13
  835. | ADC_SMPR2_SMP12 | ADC_SMPR2_SMP11 | ADC_SMPR2_SMP10)
  836. );
  837. /* Reset register TR1 */
  838. MODIFY_REG(ADCx->TR1, ADC_TR1_HT1 | ADC_TR1_LT1, ADC_TR1_HT1);
  839. /* Reset register TR2 */
  840. MODIFY_REG(ADCx->TR2, ADC_TR2_HT2 | ADC_TR2_LT2, ADC_TR2_HT2);
  841. /* Reset register TR3 */
  842. MODIFY_REG(ADCx->TR3, ADC_TR3_HT3 | ADC_TR3_LT3, ADC_TR3_HT3);
  843. /* Reset register SQR1 */
  844. CLEAR_BIT(ADCx->SQR1,
  845. ( ADC_SQR1_SQ4 | ADC_SQR1_SQ3 | ADC_SQR1_SQ2
  846. | ADC_SQR1_SQ1 | ADC_SQR1_L)
  847. );
  848. /* Reset register SQR2 */
  849. CLEAR_BIT(ADCx->SQR2,
  850. ( ADC_SQR2_SQ9 | ADC_SQR2_SQ8 | ADC_SQR2_SQ7
  851. | ADC_SQR2_SQ6 | ADC_SQR2_SQ5)
  852. );
  853. /* Reset register SQR3 */
  854. CLEAR_BIT(ADCx->SQR3,
  855. ( ADC_SQR3_SQ14 | ADC_SQR3_SQ13 | ADC_SQR3_SQ12
  856. | ADC_SQR3_SQ11 | ADC_SQR3_SQ10)
  857. );
  858. /* Reset register SQR4 */
  859. CLEAR_BIT(ADCx->SQR4, ADC_SQR4_SQ16 | ADC_SQR4_SQ15);
  860. /* Reset register JSQR */
  861. CLEAR_BIT(ADCx->JSQR,
  862. ( ADC_JSQR_JL
  863. | ADC_JSQR_JEXTSEL | ADC_JSQR_JEXTEN
  864. | ADC_JSQR_JSQ4 | ADC_JSQR_JSQ3
  865. | ADC_JSQR_JSQ2 | ADC_JSQR_JSQ1 )
  866. );
  867. /* Flush ADC group injected contexts queue */
  868. SET_BIT(ADCx->CFGR, ADC_CFGR_JQM);
  869. CLEAR_BIT(ADCx->CFGR, ADC_CFGR_JQM);
  870. /* Reset register ISR bit JQOVF (set by previous operation on JSQR) */
  871. SET_BIT(ADCx->ISR, LL_ADC_FLAG_JQOVF);
  872. /* Reset register DR */
  873. /* Note: bits in access mode read only, no direct reset applicable */
  874. /* Reset register OFR1 */
  875. CLEAR_BIT(ADCx->OFR1, ADC_OFR1_OFFSET1_EN | ADC_OFR1_OFFSET1_CH | ADC_OFR1_OFFSET1);
  876. /* Reset register OFR2 */
  877. CLEAR_BIT(ADCx->OFR2, ADC_OFR2_OFFSET2_EN | ADC_OFR2_OFFSET2_CH | ADC_OFR2_OFFSET2);
  878. /* Reset register OFR3 */
  879. CLEAR_BIT(ADCx->OFR3, ADC_OFR3_OFFSET3_EN | ADC_OFR3_OFFSET3_CH | ADC_OFR3_OFFSET3);
  880. /* Reset register OFR4 */
  881. CLEAR_BIT(ADCx->OFR4, ADC_OFR4_OFFSET4_EN | ADC_OFR4_OFFSET4_CH | ADC_OFR4_OFFSET4);
  882. /* Reset registers JDR1, JDR2, JDR3, JDR4 */
  883. /* Note: bits in access mode read only, no direct reset applicable */
  884. /* Reset register AWD2CR */
  885. CLEAR_BIT(ADCx->AWD2CR, ADC_AWD2CR_AWD2CH);
  886. /* Reset register AWD3CR */
  887. CLEAR_BIT(ADCx->AWD3CR, ADC_AWD3CR_AWD3CH);
  888. /* Reset register DIFSEL */
  889. CLEAR_BIT(ADCx->DIFSEL, ADC_DIFSEL_DIFSEL);
  890. /* Reset register CALFACT */
  891. CLEAR_BIT(ADCx->CALFACT, ADC_CALFACT_CALFACT_D | ADC_CALFACT_CALFACT_S);
  892. }
  893. else
  894. {
  895. /* ADC instance is in an unknown state */
  896. /* Need to performing a hard reset of ADC instance, using high level */
  897. /* clock source RCC ADC reset. */
  898. /* Caution: On this STM32 series, if several ADC instances are available */
  899. /* on the selected device, RCC ADC reset will reset */
  900. /* all ADC instances belonging to the common ADC instance. */
  901. /* Caution: On this STM32 series, if several ADC instances are available */
  902. /* on the selected device, RCC ADC reset will reset */
  903. /* all ADC instances belonging to the common ADC instance. */
  904. status = ERROR;
  905. }
  906. return status;
  907. }
  908. /**
  909. * @brief Initialize some features of ADC instance.
  910. * @note These parameters have an impact on ADC scope: ADC instance.
  911. * Affects both group regular and group injected (availability
  912. * of ADC group injected depends on STM32 families).
  913. * Refer to corresponding unitary functions into
  914. * @ref ADC_LL_EF_Configuration_ADC_Instance .
  915. * @note The setting of these parameters by function @ref LL_ADC_Init()
  916. * is conditioned to ADC state:
  917. * ADC instance must be disabled.
  918. * This condition is applied to all ADC features, for efficiency
  919. * and compatibility over all STM32 families. However, the different
  920. * features can be set under different ADC state conditions
  921. * (setting possible with ADC enabled without conversion on going,
  922. * ADC enabled with conversion on going, ...)
  923. * Each feature can be updated afterwards with a unitary function
  924. * and potentially with ADC in a different state than disabled,
  925. * refer to description of each function for setting
  926. * conditioned to ADC state.
  927. * @note After using this function, some other features must be configured
  928. * using LL unitary functions.
  929. * The minimum configuration remaining to be done is:
  930. * - Set ADC group regular or group injected sequencer:
  931. * map channel on the selected sequencer rank.
  932. * Refer to function @ref LL_ADC_REG_SetSequencerRanks().
  933. * - Set ADC channel sampling time
  934. * Refer to function LL_ADC_SetChannelSamplingTime();
  935. * @param ADCx ADC instance
  936. * @param ADC_InitStruct Pointer to a @ref LL_ADC_REG_InitTypeDef structure
  937. * @retval An ErrorStatus enumeration value:
  938. * - SUCCESS: ADC registers are initialized
  939. * - ERROR: ADC registers are not initialized
  940. */
  941. ErrorStatus LL_ADC_Init(ADC_TypeDef *ADCx, LL_ADC_InitTypeDef *ADC_InitStruct)
  942. {
  943. ErrorStatus status = SUCCESS;
  944. /* Check the parameters */
  945. assert_param(IS_ADC_ALL_INSTANCE(ADCx));
  946. assert_param(IS_LL_ADC_RESOLUTION(ADC_InitStruct->Resolution));
  947. assert_param(IS_LL_ADC_DATA_ALIGN(ADC_InitStruct->DataAlignment));
  948. assert_param(IS_LL_ADC_LOW_POWER(ADC_InitStruct->LowPowerMode));
  949. /* Note: Hardware constraint (refer to description of this function): */
  950. /* ADC instance must be disabled. */
  951. if(LL_ADC_IsEnabled(ADCx) == 0U)
  952. {
  953. /* Configuration of ADC hierarchical scope: */
  954. /* - ADC instance */
  955. /* - Set ADC data resolution */
  956. /* - Set ADC conversion data alignment */
  957. /* - Set ADC low power mode */
  958. MODIFY_REG(ADCx->CFGR,
  959. ADC_CFGR_RES
  960. | ADC_CFGR_ALIGN
  961. | ADC_CFGR_AUTDLY
  962. ,
  963. ADC_InitStruct->Resolution
  964. | ADC_InitStruct->DataAlignment
  965. | ADC_InitStruct->LowPowerMode
  966. );
  967. }
  968. else
  969. {
  970. /* Initialization error: ADC instance is not disabled. */
  971. status = ERROR;
  972. }
  973. return status;
  974. }
  975. /**
  976. * @brief Set each @ref LL_ADC_InitTypeDef field to default value.
  977. * @param ADC_InitStruct Pointer to a @ref LL_ADC_InitTypeDef structure
  978. * whose fields will be set to default values.
  979. * @retval None
  980. */
  981. void LL_ADC_StructInit(LL_ADC_InitTypeDef *ADC_InitStruct)
  982. {
  983. /* Set ADC_InitStruct fields to default values */
  984. /* Set fields of ADC instance */
  985. ADC_InitStruct->Resolution = LL_ADC_RESOLUTION_12B;
  986. ADC_InitStruct->DataAlignment = LL_ADC_DATA_ALIGN_RIGHT;
  987. ADC_InitStruct->LowPowerMode = LL_ADC_LP_MODE_NONE;
  988. }
  989. /**
  990. * @brief Initialize some features of ADC group regular.
  991. * @note These parameters have an impact on ADC scope: ADC group regular.
  992. * Refer to corresponding unitary functions into
  993. * @ref ADC_LL_EF_Configuration_ADC_Group_Regular
  994. * (functions with prefix "REG").
  995. * @note The setting of these parameters by function @ref LL_ADC_Init()
  996. * is conditioned to ADC state:
  997. * ADC instance must be disabled.
  998. * This condition is applied to all ADC features, for efficiency
  999. * and compatibility over all STM32 families. However, the different
  1000. * features can be set under different ADC state conditions
  1001. * (setting possible with ADC enabled without conversion on going,
  1002. * ADC enabled with conversion on going, ...)
  1003. * Each feature can be updated afterwards with a unitary function
  1004. * and potentially with ADC in a different state than disabled,
  1005. * refer to description of each function for setting
  1006. * conditioned to ADC state.
  1007. * @note After using this function, other features must be configured
  1008. * using LL unitary functions.
  1009. * The minimum configuration remaining to be done is:
  1010. * - Set ADC group regular or group injected sequencer:
  1011. * map channel on the selected sequencer rank.
  1012. * Refer to function @ref LL_ADC_REG_SetSequencerRanks().
  1013. * - Set ADC channel sampling time
  1014. * Refer to function LL_ADC_SetChannelSamplingTime();
  1015. * @param ADCx ADC instance
  1016. * @param ADC_REG_InitStruct Pointer to a @ref LL_ADC_REG_InitTypeDef structure
  1017. * @retval An ErrorStatus enumeration value:
  1018. * - SUCCESS: ADC registers are initialized
  1019. * - ERROR: ADC registers are not initialized
  1020. */
  1021. ErrorStatus LL_ADC_REG_Init(ADC_TypeDef *ADCx, LL_ADC_REG_InitTypeDef *ADC_REG_InitStruct)
  1022. {
  1023. ErrorStatus status = SUCCESS;
  1024. /* Check the parameters */
  1025. assert_param(IS_ADC_ALL_INSTANCE(ADCx));
  1026. #if defined(ADC1) && defined(ADC2) && defined(ADC3) && defined(ADC4)
  1027. assert_param(IS_LL_ADC_REG_TRIG_SOURCE(ADCx, ADC_REG_InitStruct->TriggerSource));
  1028. #else
  1029. assert_param(IS_LL_ADC_REG_TRIG_SOURCE(ADC_REG_InitStruct->TriggerSource));
  1030. #endif
  1031. assert_param(IS_LL_ADC_REG_SEQ_SCAN_LENGTH(ADC_REG_InitStruct->SequencerLength));
  1032. if(ADC_REG_InitStruct->SequencerLength != LL_ADC_REG_SEQ_SCAN_DISABLE)
  1033. {
  1034. assert_param(IS_LL_ADC_REG_SEQ_SCAN_DISCONT_MODE(ADC_REG_InitStruct->SequencerDiscont));
  1035. }
  1036. assert_param(IS_LL_ADC_REG_CONTINUOUS_MODE(ADC_REG_InitStruct->ContinuousMode));
  1037. assert_param(IS_LL_ADC_REG_DMA_TRANSFER(ADC_REG_InitStruct->DMATransfer));
  1038. assert_param(IS_LL_ADC_REG_OVR_DATA_BEHAVIOR(ADC_REG_InitStruct->Overrun));
  1039. /* Note: Hardware constraint (refer to description of this function): */
  1040. /* ADC instance must be disabled. */
  1041. if(LL_ADC_IsEnabled(ADCx) == 0U)
  1042. {
  1043. /* Configuration of ADC hierarchical scope: */
  1044. /* - ADC group regular */
  1045. /* - Set ADC group regular trigger source */
  1046. /* - Set ADC group regular sequencer length */
  1047. /* - Set ADC group regular sequencer discontinuous mode */
  1048. /* - Set ADC group regular continuous mode */
  1049. /* - Set ADC group regular conversion data transfer: no transfer or */
  1050. /* transfer by DMA, and DMA requests mode */
  1051. /* - Set ADC group regular overrun behavior */
  1052. /* Note: On this STM32 series, ADC trigger edge is set to value 0x0 by */
  1053. /* setting of trigger source to SW start. */
  1054. if(ADC_REG_InitStruct->SequencerLength != LL_ADC_REG_SEQ_SCAN_DISABLE)
  1055. {
  1056. MODIFY_REG(ADCx->CFGR,
  1057. ADC_CFGR_EXTSEL
  1058. | ADC_CFGR_EXTEN
  1059. | ADC_CFGR_DISCEN
  1060. | ADC_CFGR_DISCNUM
  1061. | ADC_CFGR_CONT
  1062. | ADC_CFGR_DMAEN
  1063. | ADC_CFGR_DMACFG
  1064. | ADC_CFGR_OVRMOD
  1065. ,
  1066. ADC_REG_InitStruct->TriggerSource
  1067. | ADC_REG_InitStruct->SequencerDiscont
  1068. | ADC_REG_InitStruct->ContinuousMode
  1069. | ADC_REG_InitStruct->DMATransfer
  1070. | ADC_REG_InitStruct->Overrun
  1071. );
  1072. }
  1073. else
  1074. {
  1075. MODIFY_REG(ADCx->CFGR,
  1076. ADC_CFGR_EXTSEL
  1077. | ADC_CFGR_EXTEN
  1078. | ADC_CFGR_DISCEN
  1079. | ADC_CFGR_DISCNUM
  1080. | ADC_CFGR_CONT
  1081. | ADC_CFGR_DMAEN
  1082. | ADC_CFGR_DMACFG
  1083. | ADC_CFGR_OVRMOD
  1084. ,
  1085. ADC_REG_InitStruct->TriggerSource
  1086. | LL_ADC_REG_SEQ_DISCONT_DISABLE
  1087. | ADC_REG_InitStruct->ContinuousMode
  1088. | ADC_REG_InitStruct->DMATransfer
  1089. | ADC_REG_InitStruct->Overrun
  1090. );
  1091. }
  1092. /* Set ADC group regular sequencer length and scan direction */
  1093. LL_ADC_REG_SetSequencerLength(ADCx, ADC_REG_InitStruct->SequencerLength);
  1094. }
  1095. else
  1096. {
  1097. /* Initialization error: ADC instance is not disabled. */
  1098. status = ERROR;
  1099. }
  1100. return status;
  1101. }
  1102. /**
  1103. * @brief Set each @ref LL_ADC_REG_InitTypeDef field to default value.
  1104. * @param ADC_REG_InitStruct Pointer to a @ref LL_ADC_REG_InitTypeDef structure
  1105. * whose fields will be set to default values.
  1106. * @retval None
  1107. */
  1108. void LL_ADC_REG_StructInit(LL_ADC_REG_InitTypeDef *ADC_REG_InitStruct)
  1109. {
  1110. /* Set ADC_REG_InitStruct fields to default values */
  1111. /* Set fields of ADC group regular */
  1112. /* Note: On this STM32 series, ADC trigger edge is set to value 0x0 by */
  1113. /* setting of trigger source to SW start. */
  1114. ADC_REG_InitStruct->TriggerSource = LL_ADC_REG_TRIG_SOFTWARE;
  1115. ADC_REG_InitStruct->SequencerLength = LL_ADC_REG_SEQ_SCAN_DISABLE;
  1116. ADC_REG_InitStruct->SequencerDiscont = LL_ADC_REG_SEQ_DISCONT_DISABLE;
  1117. ADC_REG_InitStruct->ContinuousMode = LL_ADC_REG_CONV_SINGLE;
  1118. ADC_REG_InitStruct->DMATransfer = LL_ADC_REG_DMA_TRANSFER_NONE;
  1119. ADC_REG_InitStruct->Overrun = LL_ADC_REG_OVR_DATA_OVERWRITTEN;
  1120. }
  1121. /**
  1122. * @brief Initialize some features of ADC group injected.
  1123. * @note These parameters have an impact on ADC scope: ADC group injected.
  1124. * Refer to corresponding unitary functions into
  1125. * @ref ADC_LL_EF_Configuration_ADC_Group_Regular
  1126. * (functions with prefix "INJ").
  1127. * @note The setting of these parameters by function @ref LL_ADC_Init()
  1128. * is conditioned to ADC state:
  1129. * ADC instance must be disabled.
  1130. * This condition is applied to all ADC features, for efficiency
  1131. * and compatibility over all STM32 families. However, the different
  1132. * features can be set under different ADC state conditions
  1133. * (setting possible with ADC enabled without conversion on going,
  1134. * ADC enabled with conversion on going, ...)
  1135. * Each feature can be updated afterwards with a unitary function
  1136. * and potentially with ADC in a different state than disabled,
  1137. * refer to description of each function for setting
  1138. * conditioned to ADC state.
  1139. * @note After using this function, other features must be configured
  1140. * using LL unitary functions.
  1141. * The minimum configuration remaining to be done is:
  1142. * - Set ADC group injected sequencer:
  1143. * map channel on the selected sequencer rank.
  1144. * Refer to function @ref LL_ADC_INJ_SetSequencerRanks().
  1145. * - Set ADC channel sampling time
  1146. * Refer to function LL_ADC_SetChannelSamplingTime();
  1147. * @note Caution to ADC group injected contexts queue: On this STM32 series,
  1148. * using successively several times this function will appear has
  1149. * having no effect.
  1150. * This is due to ADC group injected contexts queue (this feature
  1151. * cannot be disabled on this STM32 series).
  1152. * To set several features of ADC group injected, use
  1153. * function @ref LL_ADC_INJ_ConfigQueueContext().
  1154. * @param ADCx ADC instance
  1155. * @param ADC_INJ_InitStruct Pointer to a @ref LL_ADC_INJ_InitTypeDef structure
  1156. * @retval An ErrorStatus enumeration value:
  1157. * - SUCCESS: ADC registers are initialized
  1158. * - ERROR: ADC registers are not initialized
  1159. */
  1160. ErrorStatus LL_ADC_INJ_Init(ADC_TypeDef *ADCx, LL_ADC_INJ_InitTypeDef *ADC_INJ_InitStruct)
  1161. {
  1162. ErrorStatus status = SUCCESS;
  1163. /* Check the parameters */
  1164. assert_param(IS_ADC_ALL_INSTANCE(ADCx));
  1165. #if defined(ADC1) && defined(ADC2) && defined(ADC3) && defined(ADC4)
  1166. assert_param(IS_LL_ADC_INJ_TRIG_SOURCE(ADCx, ADC_INJ_InitStruct->TriggerSource));
  1167. #else
  1168. assert_param(IS_LL_ADC_INJ_TRIG_SOURCE(ADC_INJ_InitStruct->TriggerSource));
  1169. #endif
  1170. assert_param(IS_LL_ADC_INJ_SEQ_SCAN_LENGTH(ADC_INJ_InitStruct->SequencerLength));
  1171. if(ADC_INJ_InitStruct->SequencerLength != LL_ADC_INJ_SEQ_SCAN_DISABLE)
  1172. {
  1173. assert_param(IS_LL_ADC_INJ_SEQ_SCAN_DISCONT_MODE(ADC_INJ_InitStruct->SequencerDiscont));
  1174. }
  1175. assert_param(IS_LL_ADC_INJ_TRIG_AUTO(ADC_INJ_InitStruct->TrigAuto));
  1176. /* Note: Hardware constraint (refer to description of this function): */
  1177. /* ADC instance must be disabled. */
  1178. if(LL_ADC_IsEnabled(ADCx) == 0U)
  1179. {
  1180. /* Configuration of ADC hierarchical scope: */
  1181. /* - ADC group injected */
  1182. /* - Set ADC group injected trigger source */
  1183. /* - Set ADC group injected sequencer length */
  1184. /* - Set ADC group injected sequencer discontinuous mode */
  1185. /* - Set ADC group injected conversion trigger: independent or */
  1186. /* from ADC group regular */
  1187. /* Note: On this STM32 series, ADC trigger edge is set to value 0x0 by */
  1188. /* setting of trigger source to SW start. */
  1189. if(ADC_INJ_InitStruct->SequencerLength != LL_ADC_REG_SEQ_SCAN_DISABLE)
  1190. {
  1191. MODIFY_REG(ADCx->CFGR,
  1192. ADC_CFGR_JDISCEN
  1193. | ADC_CFGR_JAUTO
  1194. ,
  1195. ADC_INJ_InitStruct->SequencerDiscont
  1196. | ADC_INJ_InitStruct->TrigAuto
  1197. );
  1198. }
  1199. else
  1200. {
  1201. MODIFY_REG(ADCx->CFGR,
  1202. ADC_CFGR_JDISCEN
  1203. | ADC_CFGR_JAUTO
  1204. ,
  1205. LL_ADC_REG_SEQ_DISCONT_DISABLE
  1206. | ADC_INJ_InitStruct->TrigAuto
  1207. );
  1208. }
  1209. MODIFY_REG(ADCx->JSQR,
  1210. ADC_JSQR_JEXTSEL
  1211. | ADC_JSQR_JEXTEN
  1212. | ADC_JSQR_JL
  1213. ,
  1214. ADC_INJ_InitStruct->TriggerSource
  1215. | ADC_INJ_InitStruct->SequencerLength
  1216. );
  1217. }
  1218. else
  1219. {
  1220. /* Initialization error: ADC instance is not disabled. */
  1221. status = ERROR;
  1222. }
  1223. return status;
  1224. }
  1225. /**
  1226. * @brief Set each @ref LL_ADC_INJ_InitTypeDef field to default value.
  1227. * @param ADC_INJ_InitStruct Pointer to a @ref LL_ADC_INJ_InitTypeDef structure
  1228. * whose fields will be set to default values.
  1229. * @retval None
  1230. */
  1231. void LL_ADC_INJ_StructInit(LL_ADC_INJ_InitTypeDef *ADC_INJ_InitStruct)
  1232. {
  1233. /* Set ADC_INJ_InitStruct fields to default values */
  1234. /* Set fields of ADC group injected */
  1235. ADC_INJ_InitStruct->TriggerSource = LL_ADC_INJ_TRIG_SOFTWARE;
  1236. ADC_INJ_InitStruct->SequencerLength = LL_ADC_INJ_SEQ_SCAN_DISABLE;
  1237. ADC_INJ_InitStruct->SequencerDiscont = LL_ADC_INJ_SEQ_DISCONT_DISABLE;
  1238. ADC_INJ_InitStruct->TrigAuto = LL_ADC_INJ_TRIG_INDEPENDENT;
  1239. }
  1240. /**
  1241. * @}
  1242. */
  1243. /**
  1244. * @}
  1245. */
  1246. /**
  1247. * @}
  1248. */
  1249. #endif /* ADC1 || ADC2 || ADC3 || ADC4 */
  1250. #endif /* STM32F301x8 || STM32F302x8 || STM32F302xC || STM32F302xE || STM32F303x8 || STM32F303xC || STM32F303xE || STM32F318xx || STM32F328xx || STM32F334x8 || STM32F358xx || STM32F398xx */
  1251. #if defined (ADC1_V2_5)
  1252. #if defined (ADC1)
  1253. /** @addtogroup ADC_LL ADC
  1254. * @{
  1255. */
  1256. /* Private types -------------------------------------------------------------*/
  1257. /* Private variables ---------------------------------------------------------*/
  1258. /* Private constants ---------------------------------------------------------*/
  1259. /* Private macros ------------------------------------------------------------*/
  1260. /** @addtogroup ADC_LL_Private_Macros
  1261. * @{
  1262. */
  1263. /* Check of parameters for configuration of ADC hierarchical scope: */
  1264. /* common to several ADC instances. */
  1265. /* Check of parameters for configuration of ADC hierarchical scope: */
  1266. /* ADC instance. */
  1267. #define IS_LL_ADC_DATA_ALIGN(__DATA_ALIGN__) \
  1268. ( ((__DATA_ALIGN__) == LL_ADC_DATA_ALIGN_RIGHT) \
  1269. || ((__DATA_ALIGN__) == LL_ADC_DATA_ALIGN_LEFT) )
  1270. #define IS_LL_ADC_SCAN_SELECTION(__SCAN_SELECTION__) \
  1271. ( ((__SCAN_SELECTION__) == LL_ADC_SEQ_SCAN_DISABLE) \
  1272. || ((__SCAN_SELECTION__) == LL_ADC_SEQ_SCAN_ENABLE) )
  1273. #define IS_LL_ADC_SEQ_SCAN_MODE(__SEQ_SCAN_MODE__) \
  1274. ( ((__SCAN_MODE__) == LL_ADC_SEQ_SCAN_DISABLE) \
  1275. || ((__SCAN_MODE__) == LL_ADC_SEQ_SCAN_ENABLE) )
  1276. /* Check of parameters for configuration of ADC hierarchical scope: */
  1277. /* ADC group regular */
  1278. #define IS_LL_ADC_REG_TRIG_SOURCE(__REG_TRIG_SOURCE__) \
  1279. ( ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_SOFTWARE) \
  1280. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM2_CH2) \
  1281. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM3_TRGO) \
  1282. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM4_CH2) \
  1283. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM19_TRGO) \
  1284. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM19_CH3) \
  1285. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM19_CH4) \
  1286. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_EXTI_LINE11))
  1287. #define IS_LL_ADC_REG_CONTINUOUS_MODE(__REG_CONTINUOUS_MODE__) \
  1288. ( ((__REG_CONTINUOUS_MODE__) == LL_ADC_REG_CONV_SINGLE) \
  1289. || ((__REG_CONTINUOUS_MODE__) == LL_ADC_REG_CONV_CONTINUOUS))
  1290. #define IS_LL_ADC_REG_DMA_TRANSFER(__REG_DMA_TRANSFER__) \
  1291. ( ((__REG_DMA_TRANSFER__) == LL_ADC_REG_DMA_TRANSFER_NONE) \
  1292. || ((__REG_DMA_TRANSFER__) == LL_ADC_REG_DMA_TRANSFER_UNLIMITED))
  1293. #define IS_LL_ADC_REG_SEQ_SCAN_LENGTH(__REG_SEQ_SCAN_LENGTH__) \
  1294. ( ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_DISABLE) \
  1295. || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_2RANKS) \
  1296. || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_3RANKS) \
  1297. || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_4RANKS) \
  1298. || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_5RANKS) \
  1299. || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_6RANKS) \
  1300. || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_7RANKS) \
  1301. || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_8RANKS) \
  1302. || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_9RANKS) \
  1303. || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_10RANKS) \
  1304. || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_11RANKS) \
  1305. || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_12RANKS) \
  1306. || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_13RANKS) \
  1307. || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_14RANKS) \
  1308. || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_15RANKS) \
  1309. || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_16RANKS))
  1310. #define IS_LL_ADC_REG_SEQ_SCAN_DISCONT_MODE(__REG_SEQ_DISCONT_MODE__) \
  1311. ( ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_DISABLE) \
  1312. || ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_1RANK) \
  1313. || ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_2RANKS) \
  1314. || ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_3RANKS) \
  1315. || ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_4RANKS) \
  1316. || ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_5RANKS) \
  1317. || ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_6RANKS) \
  1318. || ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_7RANKS) \
  1319. || ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_8RANKS) )
  1320. /* Check of parameters for configuration of ADC hierarchical scope: */
  1321. /* ADC group injected */
  1322. #define IS_LL_ADC_INJ_TRIG_SOURCE(__INJ_TRIG_SOURCE__) \
  1323. ( ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_SOFTWARE) \
  1324. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM2_TRGO) \
  1325. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM2_CH1) \
  1326. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM3_CH4) \
  1327. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM4_TRGO) \
  1328. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM19_CH1) \
  1329. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM19_CH2) \
  1330. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_EXTI_LINE15))
  1331. #define IS_LL_ADC_INJ_TRIG_AUTO(__INJ_TRIG_AUTO__) \
  1332. ( ((__INJ_TRIG_AUTO__) == LL_ADC_INJ_TRIG_INDEPENDENT) \
  1333. || ((__INJ_TRIG_AUTO__) == LL_ADC_INJ_TRIG_FROM_GRP_REGULAR))
  1334. #define IS_LL_ADC_INJ_SEQ_SCAN_LENGTH(__INJ_SEQ_SCAN_LENGTH__) \
  1335. ( ((__INJ_SEQ_SCAN_LENGTH__) == LL_ADC_INJ_SEQ_SCAN_DISABLE) \
  1336. || ((__INJ_SEQ_SCAN_LENGTH__) == LL_ADC_INJ_SEQ_SCAN_ENABLE_2RANKS) \
  1337. || ((__INJ_SEQ_SCAN_LENGTH__) == LL_ADC_INJ_SEQ_SCAN_ENABLE_3RANKS) \
  1338. || ((__INJ_SEQ_SCAN_LENGTH__) == LL_ADC_INJ_SEQ_SCAN_ENABLE_4RANKS))
  1339. #define IS_LL_ADC_INJ_SEQ_SCAN_DISCONT_MODE(__INJ_SEQ_DISCONT_MODE__) \
  1340. ( ((__INJ_SEQ_DISCONT_MODE__) == LL_ADC_INJ_SEQ_DISCONT_DISABLE) \
  1341. || ((__INJ_SEQ_DISCONT_MODE__) == LL_ADC_INJ_SEQ_DISCONT_1RANK) )
  1342. /**
  1343. * @}
  1344. */
  1345. /* Private function prototypes -----------------------------------------------*/
  1346. /* Exported functions --------------------------------------------------------*/
  1347. /** @addtogroup ADC_LL_Exported_Functions
  1348. * @{
  1349. */
  1350. /** @addtogroup ADC_LL_EF_Init
  1351. * @{
  1352. */
  1353. /**
  1354. * @brief De-initialize registers of all ADC instances belonging to
  1355. * the same ADC common instance to their default reset values.
  1356. * @param ADCxy_COMMON ADC common instance
  1357. * (can be set directly from CMSIS definition or by using helper macro @ref __LL_ADC_COMMON_INSTANCE() )
  1358. * @retval An ErrorStatus enumeration value:
  1359. * - SUCCESS: ADC common registers are de-initialized
  1360. * - ERROR: not applicable
  1361. */
  1362. ErrorStatus LL_ADC_CommonDeInit(ADC_Common_TypeDef *ADCxy_COMMON)
  1363. {
  1364. /* Check the parameters */
  1365. assert_param(IS_ADC_COMMON_INSTANCE(ADCxy_COMMON));
  1366. /* Force reset of ADC clock (core clock) */
  1367. LL_APB2_GRP1_ForceReset (LL_APB2_GRP1_PERIPH_ADC1);
  1368. /* Release reset of ADC clock (core clock) */
  1369. LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_ADC1);
  1370. return SUCCESS;
  1371. }
  1372. /**
  1373. * @brief De-initialize registers of the selected ADC instance
  1374. * to their default reset values.
  1375. * @note To reset all ADC instances quickly (perform a hard reset),
  1376. * use function @ref LL_ADC_CommonDeInit().
  1377. * @param ADCx ADC instance
  1378. * @retval An ErrorStatus enumeration value:
  1379. * - SUCCESS: ADC registers are de-initialized
  1380. * - ERROR: ADC registers are not de-initialized
  1381. */
  1382. ErrorStatus LL_ADC_DeInit(ADC_TypeDef *ADCx)
  1383. {
  1384. ErrorStatus status = SUCCESS;
  1385. /* Check the parameters */
  1386. assert_param(IS_ADC_ALL_INSTANCE(ADCx));
  1387. /* Disable ADC instance if not already disabled. */
  1388. if(LL_ADC_IsEnabled(ADCx) == 1U)
  1389. {
  1390. /* Set ADC group regular trigger source to SW start to ensure to not */
  1391. /* have an external trigger event occurring during the conversion stop */
  1392. /* ADC disable process. */
  1393. LL_ADC_REG_SetTriggerSource(ADCx, LL_ADC_REG_TRIG_SOFTWARE);
  1394. /* Set ADC group injected trigger source to SW start to ensure to not */
  1395. /* have an external trigger event occurring during the conversion stop */
  1396. /* ADC disable process. */
  1397. LL_ADC_INJ_SetTriggerSource(ADCx, LL_ADC_INJ_TRIG_SOFTWARE);
  1398. /* Disable the ADC instance */
  1399. LL_ADC_Disable(ADCx);
  1400. }
  1401. /* Check whether ADC state is compliant with expected state */
  1402. /* (hardware requirements of bits state to reset registers below) */
  1403. if(READ_BIT(ADCx->CR2, ADC_CR2_ADON) == 0U)
  1404. {
  1405. /* ========== Reset ADC registers ========== */
  1406. /* Reset register SR */
  1407. CLEAR_BIT(ADCx->SR,
  1408. ( LL_ADC_FLAG_STRT
  1409. | LL_ADC_FLAG_JSTRT
  1410. | LL_ADC_FLAG_EOS
  1411. | LL_ADC_FLAG_JEOS
  1412. | LL_ADC_FLAG_AWD1 )
  1413. );
  1414. /* Reset register CR1 */
  1415. CLEAR_BIT(ADCx->CR1,
  1416. ( ADC_CR1_AWDEN | ADC_CR1_JAWDEN
  1417. | ADC_CR1_DISCNUM | ADC_CR1_JDISCEN | ADC_CR1_DISCEN
  1418. | ADC_CR1_JAUTO | ADC_CR1_AWDSGL | ADC_CR1_SCAN
  1419. | ADC_CR1_JEOCIE | ADC_CR1_AWDIE | ADC_CR1_EOCIE
  1420. | ADC_CR1_AWDCH )
  1421. );
  1422. /* Reset register CR2 */
  1423. CLEAR_BIT(ADCx->CR2,
  1424. ( ADC_CR2_TSVREFE
  1425. | ADC_CR2_SWSTART | ADC_CR2_EXTTRIG | ADC_CR2_EXTSEL
  1426. | ADC_CR2_JSWSTART | ADC_CR2_JEXTTRIG | ADC_CR2_JEXTSEL
  1427. | ADC_CR2_ALIGN | ADC_CR2_DMA
  1428. | ADC_CR2_RSTCAL | ADC_CR2_CAL
  1429. | ADC_CR2_CONT | ADC_CR2_ADON )
  1430. );
  1431. /* Reset register SMPR1 */
  1432. CLEAR_BIT(ADCx->SMPR1,
  1433. ( ADC_SMPR1_SMP17 | ADC_SMPR1_SMP16
  1434. | ADC_SMPR1_SMP15 | ADC_SMPR1_SMP14 | ADC_SMPR1_SMP13
  1435. | ADC_SMPR1_SMP12 | ADC_SMPR1_SMP11 | ADC_SMPR1_SMP10)
  1436. );
  1437. /* Reset register SMPR2 */
  1438. CLEAR_BIT(ADCx->SMPR2,
  1439. ( ADC_SMPR2_SMP9
  1440. | ADC_SMPR2_SMP8 | ADC_SMPR2_SMP7 | ADC_SMPR2_SMP6
  1441. | ADC_SMPR2_SMP5 | ADC_SMPR2_SMP4 | ADC_SMPR2_SMP3
  1442. | ADC_SMPR2_SMP2 | ADC_SMPR2_SMP1 | ADC_SMPR2_SMP0)
  1443. );
  1444. /* Reset register JOFR1 */
  1445. CLEAR_BIT(ADCx->JOFR1, ADC_JOFR1_JOFFSET1);
  1446. /* Reset register JOFR2 */
  1447. CLEAR_BIT(ADCx->JOFR2, ADC_JOFR2_JOFFSET2);
  1448. /* Reset register JOFR3 */
  1449. CLEAR_BIT(ADCx->JOFR3, ADC_JOFR3_JOFFSET3);
  1450. /* Reset register JOFR4 */
  1451. CLEAR_BIT(ADCx->JOFR4, ADC_JOFR4_JOFFSET4);
  1452. /* Reset register HTR */
  1453. SET_BIT(ADCx->HTR, ADC_HTR_HT);
  1454. /* Reset register LTR */
  1455. CLEAR_BIT(ADCx->LTR, ADC_LTR_LT);
  1456. /* Reset register SQR1 */
  1457. CLEAR_BIT(ADCx->SQR1,
  1458. ( ADC_SQR1_L
  1459. | ADC_SQR1_SQ16
  1460. | ADC_SQR1_SQ15 | ADC_SQR1_SQ14 | ADC_SQR1_SQ13)
  1461. );
  1462. /* Reset register SQR2 */
  1463. CLEAR_BIT(ADCx->SQR2,
  1464. ( ADC_SQR2_SQ12 | ADC_SQR2_SQ11 | ADC_SQR2_SQ10
  1465. | ADC_SQR2_SQ9 | ADC_SQR2_SQ8 | ADC_SQR2_SQ7)
  1466. );
  1467. /* Reset register JSQR */
  1468. CLEAR_BIT(ADCx->JSQR,
  1469. ( ADC_JSQR_JL
  1470. | ADC_JSQR_JSQ4 | ADC_JSQR_JSQ3
  1471. | ADC_JSQR_JSQ2 | ADC_JSQR_JSQ1 )
  1472. );
  1473. /* Reset register DR */
  1474. /* bits in access mode read only, no direct reset applicable */
  1475. /* Reset registers JDR1, JDR2, JDR3, JDR4 */
  1476. /* bits in access mode read only, no direct reset applicable */
  1477. }
  1478. return status;
  1479. }
  1480. /**
  1481. * @brief Initialize some features of ADC instance.
  1482. * @note These parameters have an impact on ADC scope: ADC instance.
  1483. * Affects both group regular and group injected (availability
  1484. * of ADC group injected depends on STM32 families).
  1485. * Refer to corresponding unitary functions into
  1486. * @ref ADC_LL_EF_Configuration_ADC_Instance .
  1487. * @note The setting of these parameters by function @ref LL_ADC_Init()
  1488. * is conditioned to ADC state:
  1489. * ADC instance must be disabled.
  1490. * This condition is applied to all ADC features, for efficiency
  1491. * and compatibility over all STM32 families. However, the different
  1492. * features can be set under different ADC state conditions
  1493. * (setting possible with ADC enabled without conversion on going,
  1494. * ADC enabled with conversion on going, ...)
  1495. * Each feature can be updated afterwards with a unitary function
  1496. * and potentially with ADC in a different state than disabled,
  1497. * refer to description of each function for setting
  1498. * conditioned to ADC state.
  1499. * @note After using this function, some other features must be configured
  1500. * using LL unitary functions.
  1501. * The minimum configuration remaining to be done is:
  1502. * - Set ADC group regular or group injected sequencer:
  1503. * map channel on the selected sequencer rank.
  1504. * Refer to function @ref LL_ADC_REG_SetSequencerRanks().
  1505. * - Set ADC channel sampling time
  1506. * Refer to function LL_ADC_SetChannelSamplingTime();
  1507. * @param ADCx ADC instance
  1508. * @param ADC_InitStruct Pointer to a @ref LL_ADC_REG_InitTypeDef structure
  1509. * @retval An ErrorStatus enumeration value:
  1510. * - SUCCESS: ADC registers are initialized
  1511. * - ERROR: ADC registers are not initialized
  1512. */
  1513. ErrorStatus LL_ADC_Init(ADC_TypeDef *ADCx, LL_ADC_InitTypeDef *ADC_InitStruct)
  1514. {
  1515. ErrorStatus status = SUCCESS;
  1516. /* Check the parameters */
  1517. assert_param(IS_ADC_ALL_INSTANCE(ADCx));
  1518. assert_param(IS_LL_ADC_DATA_ALIGN(ADC_InitStruct->DataAlignment));
  1519. assert_param(IS_LL_ADC_SCAN_SELECTION(ADC_InitStruct->SequencersScanMode));
  1520. /* Note: Hardware constraint (refer to description of this function): */
  1521. /* ADC instance must be disabled. */
  1522. if(LL_ADC_IsEnabled(ADCx) == 0U)
  1523. {
  1524. /* Configuration of ADC hierarchical scope: */
  1525. /* - ADC instance */
  1526. /* - Set ADC conversion data alignment */
  1527. MODIFY_REG(ADCx->CR1,
  1528. ADC_CR1_SCAN
  1529. ,
  1530. ADC_InitStruct->SequencersScanMode
  1531. );
  1532. MODIFY_REG(ADCx->CR2,
  1533. ADC_CR2_ALIGN
  1534. ,
  1535. ADC_InitStruct->DataAlignment
  1536. );
  1537. }
  1538. else
  1539. {
  1540. /* Initialization error: ADC instance is not disabled. */
  1541. status = ERROR;
  1542. }
  1543. return status;
  1544. }
  1545. /**
  1546. * @brief Set each @ref LL_ADC_InitTypeDef field to default value.
  1547. * @param ADC_InitStruct Pointer to a @ref LL_ADC_InitTypeDef structure
  1548. * whose fields will be set to default values.
  1549. * @retval None
  1550. */
  1551. void LL_ADC_StructInit(LL_ADC_InitTypeDef *ADC_InitStruct)
  1552. {
  1553. /* Set ADC_InitStruct fields to default values */
  1554. /* Set fields of ADC instance */
  1555. ADC_InitStruct->DataAlignment = LL_ADC_DATA_ALIGN_RIGHT;
  1556. /* Enable scan mode to have a generic behavior with ADC of other */
  1557. /* STM32 families, without this setting available: */
  1558. /* ADC group regular sequencer and ADC group injected sequencer depend */
  1559. /* only of their own configuration. */
  1560. ADC_InitStruct->SequencersScanMode = LL_ADC_SEQ_SCAN_ENABLE;
  1561. }
  1562. /**
  1563. * @brief Initialize some features of ADC group regular.
  1564. * @note These parameters have an impact on ADC scope: ADC group regular.
  1565. * Refer to corresponding unitary functions into
  1566. * @ref ADC_LL_EF_Configuration_ADC_Group_Regular
  1567. * (functions with prefix "REG").
  1568. * @note The setting of these parameters by function @ref LL_ADC_Init()
  1569. * is conditioned to ADC state:
  1570. * ADC instance must be disabled.
  1571. * This condition is applied to all ADC features, for efficiency
  1572. * and compatibility over all STM32 families. However, the different
  1573. * features can be set under different ADC state conditions
  1574. * (setting possible with ADC enabled without conversion on going,
  1575. * ADC enabled with conversion on going, ...)
  1576. * Each feature can be updated afterwards with a unitary function
  1577. * and potentially with ADC in a different state than disabled,
  1578. * refer to description of each function for setting
  1579. * conditioned to ADC state.
  1580. * @note After using this function, other features must be configured
  1581. * using LL unitary functions.
  1582. * The minimum configuration remaining to be done is:
  1583. * - Set ADC group regular or group injected sequencer:
  1584. * map channel on the selected sequencer rank.
  1585. * Refer to function @ref LL_ADC_REG_SetSequencerRanks().
  1586. * - Set ADC channel sampling time
  1587. * Refer to function LL_ADC_SetChannelSamplingTime();
  1588. * @param ADCx ADC instance
  1589. * @param ADC_REG_InitStruct Pointer to a @ref LL_ADC_REG_InitTypeDef structure
  1590. * @retval An ErrorStatus enumeration value:
  1591. * - SUCCESS: ADC registers are initialized
  1592. * - ERROR: ADC registers are not initialized
  1593. */
  1594. ErrorStatus LL_ADC_REG_Init(ADC_TypeDef *ADCx, LL_ADC_REG_InitTypeDef *ADC_REG_InitStruct)
  1595. {
  1596. ErrorStatus status = SUCCESS;
  1597. /* Check the parameters */
  1598. assert_param(IS_ADC_ALL_INSTANCE(ADCx));
  1599. assert_param(IS_LL_ADC_REG_TRIG_SOURCE(ADC_REG_InitStruct->TriggerSource));
  1600. assert_param(IS_LL_ADC_REG_SEQ_SCAN_LENGTH(ADC_REG_InitStruct->SequencerLength));
  1601. if(ADC_REG_InitStruct->SequencerLength != LL_ADC_REG_SEQ_SCAN_DISABLE)
  1602. {
  1603. assert_param(IS_LL_ADC_REG_SEQ_SCAN_DISCONT_MODE(ADC_REG_InitStruct->SequencerDiscont));
  1604. }
  1605. /* ADC group regular continuous mode and discontinuous mode */
  1606. /* can not be enabled simultenaeously */
  1607. assert_param((ADC_REG_InitStruct->ContinuousMode == LL_ADC_REG_CONV_SINGLE)
  1608. || (ADC_REG_InitStruct->SequencerDiscont == LL_ADC_REG_SEQ_DISCONT_DISABLE));
  1609. assert_param(IS_LL_ADC_REG_CONTINUOUS_MODE(ADC_REG_InitStruct->ContinuousMode));
  1610. assert_param(IS_LL_ADC_REG_DMA_TRANSFER(ADC_REG_InitStruct->DMATransfer));
  1611. /* Note: Hardware constraint (refer to description of this function): */
  1612. /* ADC instance must be disabled. */
  1613. if(LL_ADC_IsEnabled(ADCx) == 0U)
  1614. {
  1615. /* Configuration of ADC hierarchical scope: */
  1616. /* - ADC group regular */
  1617. /* - Set ADC group regular trigger source */
  1618. /* - Set ADC group regular sequencer length */
  1619. /* - Set ADC group regular sequencer discontinuous mode */
  1620. /* - Set ADC group regular continuous mode */
  1621. /* - Set ADC group regular conversion data transfer: no transfer or */
  1622. /* transfer by DMA, and DMA requests mode */
  1623. /* Note: On this STM32 series, ADC trigger edge is set when starting */
  1624. /* ADC conversion. */
  1625. /* Refer to function @ref LL_ADC_REG_StartConversionExtTrig(). */
  1626. if(ADC_REG_InitStruct->SequencerLength != LL_ADC_REG_SEQ_SCAN_DISABLE)
  1627. {
  1628. MODIFY_REG(ADCx->CR1,
  1629. ADC_CR1_DISCEN
  1630. | ADC_CR1_DISCNUM
  1631. ,
  1632. ADC_REG_InitStruct->SequencerLength
  1633. | ADC_REG_InitStruct->SequencerDiscont
  1634. );
  1635. }
  1636. else
  1637. {
  1638. MODIFY_REG(ADCx->CR1,
  1639. ADC_CR1_DISCEN
  1640. | ADC_CR1_DISCNUM
  1641. ,
  1642. ADC_REG_InitStruct->SequencerLength
  1643. | LL_ADC_REG_SEQ_DISCONT_DISABLE
  1644. );
  1645. }
  1646. MODIFY_REG(ADCx->CR2,
  1647. ADC_CR2_EXTSEL
  1648. | ADC_CR2_CONT
  1649. | ADC_CR2_DMA
  1650. ,
  1651. ADC_REG_InitStruct->TriggerSource
  1652. | ADC_REG_InitStruct->ContinuousMode
  1653. | ADC_REG_InitStruct->DMATransfer
  1654. );
  1655. /* Set ADC group regular sequencer length and scan direction */
  1656. /* Note: Hardware constraint (refer to description of this function): */
  1657. /* Note: If ADC instance feature scan mode is disabled */
  1658. /* (refer to ADC instance initialization structure */
  1659. /* parameter @ref SequencersScanMode */
  1660. /* or function @ref LL_ADC_SetSequencersScanMode() ), */
  1661. /* this parameter is discarded. */
  1662. LL_ADC_REG_SetSequencerLength(ADCx, ADC_REG_InitStruct->SequencerLength);
  1663. }
  1664. else
  1665. {
  1666. /* Initialization error: ADC instance is not disabled. */
  1667. status = ERROR;
  1668. }
  1669. return status;
  1670. }
  1671. /**
  1672. * @brief Set each @ref LL_ADC_REG_InitTypeDef field to default value.
  1673. * @param ADC_REG_InitStruct Pointer to a @ref LL_ADC_REG_InitTypeDef structure
  1674. * whose fields will be set to default values.
  1675. * @retval None
  1676. */
  1677. void LL_ADC_REG_StructInit(LL_ADC_REG_InitTypeDef *ADC_REG_InitStruct)
  1678. {
  1679. /* Set ADC_REG_InitStruct fields to default values */
  1680. /* Set fields of ADC group regular */
  1681. /* Note: On this STM32 series, ADC trigger edge is set when starting */
  1682. /* ADC conversion. */
  1683. /* Refer to function @ref LL_ADC_REG_StartConversionExtTrig(). */
  1684. ADC_REG_InitStruct->TriggerSource = LL_ADC_REG_TRIG_SOFTWARE;
  1685. ADC_REG_InitStruct->SequencerLength = LL_ADC_REG_SEQ_SCAN_DISABLE;
  1686. ADC_REG_InitStruct->SequencerDiscont = LL_ADC_REG_SEQ_DISCONT_DISABLE;
  1687. ADC_REG_InitStruct->ContinuousMode = LL_ADC_REG_CONV_SINGLE;
  1688. ADC_REG_InitStruct->DMATransfer = LL_ADC_REG_DMA_TRANSFER_NONE;
  1689. }
  1690. /**
  1691. * @brief Initialize some features of ADC group injected.
  1692. * @note These parameters have an impact on ADC scope: ADC group injected.
  1693. * Refer to corresponding unitary functions into
  1694. * @ref ADC_LL_EF_Configuration_ADC_Group_Regular
  1695. * (functions with prefix "INJ").
  1696. * @note The setting of these parameters by function @ref LL_ADC_Init()
  1697. * is conditioned to ADC state:
  1698. * ADC instance must be disabled.
  1699. * This condition is applied to all ADC features, for efficiency
  1700. * and compatibility over all STM32 families. However, the different
  1701. * features can be set under different ADC state conditions
  1702. * (setting possible with ADC enabled without conversion on going,
  1703. * ADC enabled with conversion on going, ...)
  1704. * Each feature can be updated afterwards with a unitary function
  1705. * and potentially with ADC in a different state than disabled,
  1706. * refer to description of each function for setting
  1707. * conditioned to ADC state.
  1708. * @note After using this function, other features must be configured
  1709. * using LL unitary functions.
  1710. * The minimum configuration remaining to be done is:
  1711. * - Set ADC group injected sequencer:
  1712. * map channel on the selected sequencer rank.
  1713. * Refer to function @ref LL_ADC_INJ_SetSequencerRanks().
  1714. * - Set ADC channel sampling time
  1715. * Refer to function LL_ADC_SetChannelSamplingTime();
  1716. * @param ADCx ADC instance
  1717. * @param ADC_INJ_InitStruct Pointer to a @ref LL_ADC_INJ_InitTypeDef structure
  1718. * @retval An ErrorStatus enumeration value:
  1719. * - SUCCESS: ADC registers are initialized
  1720. * - ERROR: ADC registers are not initialized
  1721. */
  1722. ErrorStatus LL_ADC_INJ_Init(ADC_TypeDef *ADCx, LL_ADC_INJ_InitTypeDef *ADC_INJ_InitStruct)
  1723. {
  1724. ErrorStatus status = SUCCESS;
  1725. /* Check the parameters */
  1726. assert_param(IS_ADC_ALL_INSTANCE(ADCx));
  1727. assert_param(IS_LL_ADC_INJ_TRIG_SOURCE(ADC_INJ_InitStruct->TriggerSource));
  1728. assert_param(IS_LL_ADC_INJ_SEQ_SCAN_LENGTH(ADC_INJ_InitStruct->SequencerLength));
  1729. if(ADC_INJ_InitStruct->SequencerLength != LL_ADC_INJ_SEQ_SCAN_DISABLE)
  1730. {
  1731. assert_param(IS_LL_ADC_INJ_SEQ_SCAN_DISCONT_MODE(ADC_INJ_InitStruct->SequencerDiscont));
  1732. }
  1733. assert_param(IS_LL_ADC_INJ_TRIG_AUTO(ADC_INJ_InitStruct->TrigAuto));
  1734. /* Note: Hardware constraint (refer to description of this function): */
  1735. /* ADC instance must be disabled. */
  1736. if(LL_ADC_IsEnabled(ADCx) == 0U)
  1737. {
  1738. /* Configuration of ADC hierarchical scope: */
  1739. /* - ADC group injected */
  1740. /* - Set ADC group injected trigger source */
  1741. /* - Set ADC group injected sequencer length */
  1742. /* - Set ADC group injected sequencer discontinuous mode */
  1743. /* - Set ADC group injected conversion trigger: independent or */
  1744. /* from ADC group regular */
  1745. /* Note: On this STM32 series, ADC trigger edge is set when starting */
  1746. /* ADC conversion. */
  1747. /* Refer to function @ref LL_ADC_INJ_StartConversionExtTrig(). */
  1748. if(ADC_INJ_InitStruct->SequencerLength != LL_ADC_REG_SEQ_SCAN_DISABLE)
  1749. {
  1750. MODIFY_REG(ADCx->CR1,
  1751. ADC_CR1_JDISCEN
  1752. | ADC_CR1_JAUTO
  1753. ,
  1754. ADC_INJ_InitStruct->SequencerDiscont
  1755. | ADC_INJ_InitStruct->TrigAuto
  1756. );
  1757. }
  1758. else
  1759. {
  1760. MODIFY_REG(ADCx->CR1,
  1761. ADC_CR1_JDISCEN
  1762. | ADC_CR1_JAUTO
  1763. ,
  1764. LL_ADC_REG_SEQ_DISCONT_DISABLE
  1765. | ADC_INJ_InitStruct->TrigAuto
  1766. );
  1767. }
  1768. MODIFY_REG(ADCx->CR2,
  1769. ADC_CR2_JEXTSEL
  1770. ,
  1771. ADC_INJ_InitStruct->TriggerSource
  1772. );
  1773. /* Note: Hardware constraint (refer to description of this function): */
  1774. /* Note: If ADC instance feature scan mode is disabled */
  1775. /* (refer to ADC instance initialization structure */
  1776. /* parameter @ref SequencersScanMode */
  1777. /* or function @ref LL_ADC_SetSequencersScanMode() ), */
  1778. /* this parameter is discarded. */
  1779. LL_ADC_INJ_SetSequencerLength(ADCx, ADC_INJ_InitStruct->SequencerLength);
  1780. }
  1781. else
  1782. {
  1783. /* Initialization error: ADC instance is not disabled. */
  1784. status = ERROR;
  1785. }
  1786. return status;
  1787. }
  1788. /**
  1789. * @brief Set each @ref LL_ADC_INJ_InitTypeDef field to default value.
  1790. * @param ADC_INJ_InitStruct Pointer to a @ref LL_ADC_INJ_InitTypeDef structure
  1791. * whose fields will be set to default values.
  1792. * @retval None
  1793. */
  1794. void LL_ADC_INJ_StructInit(LL_ADC_INJ_InitTypeDef *ADC_INJ_InitStruct)
  1795. {
  1796. /* Set ADC_INJ_InitStruct fields to default values */
  1797. /* Set fields of ADC group injected */
  1798. ADC_INJ_InitStruct->TriggerSource = LL_ADC_INJ_TRIG_SOFTWARE;
  1799. ADC_INJ_InitStruct->SequencerLength = LL_ADC_INJ_SEQ_SCAN_DISABLE;
  1800. ADC_INJ_InitStruct->SequencerDiscont = LL_ADC_INJ_SEQ_DISCONT_DISABLE;
  1801. ADC_INJ_InitStruct->TrigAuto = LL_ADC_INJ_TRIG_INDEPENDENT;
  1802. }
  1803. /**
  1804. * @}
  1805. */
  1806. /**
  1807. * @}
  1808. */
  1809. /**
  1810. * @}
  1811. */
  1812. #endif /* ADC1 */
  1813. #endif /* STM32F373xC || STM32F378xx */
  1814. /**
  1815. * @}
  1816. */
  1817. #endif /* USE_FULL_LL_DRIVER */