stm32f3xx_ll_adc.c 100 KB

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