stm32f1xx_ll_adc.c 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886
  1. /**
  2. ******************************************************************************
  3. * @file stm32f1xx_ll_adc.c
  4. * @author MCD Application Team
  5. * @brief ADC LL module driver
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by ST under BSD 3-Clause license,
  13. * the "License"; You may not use this file except in compliance with the
  14. * License. You may obtain a copy of the License at:
  15. * opensource.org/licenses/BSD-3-Clause
  16. *
  17. ******************************************************************************
  18. */
  19. #if defined(USE_FULL_LL_DRIVER)
  20. /* Includes ------------------------------------------------------------------*/
  21. #include "stm32f1xx_ll_adc.h"
  22. #include "stm32f1xx_ll_bus.h"
  23. #ifdef USE_FULL_ASSERT
  24. #include "stm32_assert.h"
  25. #else
  26. #define assert_param(expr) ((void)0U)
  27. #endif
  28. /** @addtogroup STM32F1xx_LL_Driver
  29. * @{
  30. */
  31. #if defined (ADC1) || defined (ADC2) || defined (ADC3)
  32. /** @addtogroup ADC_LL ADC
  33. * @{
  34. */
  35. /* Private types -------------------------------------------------------------*/
  36. /* Private variables ---------------------------------------------------------*/
  37. /* Private constants ---------------------------------------------------------*/
  38. /* Private macros ------------------------------------------------------------*/
  39. /** @addtogroup ADC_LL_Private_Macros
  40. * @{
  41. */
  42. /* Check of parameters for configuration of ADC hierarchical scope: */
  43. /* common to several ADC instances. */
  44. /* Check of parameters for configuration of ADC hierarchical scope: */
  45. /* ADC instance. */
  46. #define IS_LL_ADC_DATA_ALIGN(__DATA_ALIGN__) \
  47. ( ((__DATA_ALIGN__) == LL_ADC_DATA_ALIGN_RIGHT) \
  48. || ((__DATA_ALIGN__) == LL_ADC_DATA_ALIGN_LEFT) \
  49. )
  50. #define IS_LL_ADC_SCAN_SELECTION(__SCAN_SELECTION__) \
  51. ( ((__SCAN_SELECTION__) == LL_ADC_SEQ_SCAN_DISABLE) \
  52. || ((__SCAN_SELECTION__) == LL_ADC_SEQ_SCAN_ENABLE) \
  53. )
  54. #define IS_LL_ADC_SEQ_SCAN_MODE(__SEQ_SCAN_MODE__) \
  55. ( ((__SCAN_MODE__) == LL_ADC_SEQ_SCAN_DISABLE) \
  56. || ((__SCAN_MODE__) == LL_ADC_SEQ_SCAN_ENABLE) \
  57. )
  58. /* Check of parameters for configuration of ADC hierarchical scope: */
  59. /* ADC group regular */
  60. #if defined(ADC3)
  61. #define IS_LL_ADC_REG_TRIG_SOURCE(__ADC_INSTANCE__, __REG_TRIG_SOURCE__) \
  62. ((((__ADC_INSTANCE__) == ADC1) || ((__ADC_INSTANCE__) == ADC2)) \
  63. ? ( ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_SOFTWARE) \
  64. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_CH3) \
  65. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_CH1) \
  66. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_CH2) \
  67. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM2_CH2) \
  68. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM3_TRGO) \
  69. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM4_CH4) \
  70. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_EXTI_LINE11) \
  71. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM8_TRGO) \
  72. ) \
  73. : \
  74. ( ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_SOFTWARE) \
  75. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_CH3) \
  76. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM3_CH1) \
  77. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM2_CH3) \
  78. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM8_CH1) \
  79. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM8_TRGO_ADC3) \
  80. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM5_CH1) \
  81. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM5_CH3) \
  82. ) \
  83. )
  84. #else
  85. #if defined (STM32F101xE) || defined (STM32F105xC) || defined (STM32F107xC)
  86. #define IS_LL_ADC_REG_TRIG_SOURCE(__REG_TRIG_SOURCE__) \
  87. ( ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_SOFTWARE) \
  88. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_CH3) \
  89. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_CH1) \
  90. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_CH2) \
  91. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM2_CH2) \
  92. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM3_TRGO) \
  93. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM4_CH4) \
  94. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_EXTI_LINE11) \
  95. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM8_TRGO) \
  96. )
  97. #else
  98. #define IS_LL_ADC_REG_TRIG_SOURCE(__REG_TRIG_SOURCE__) \
  99. ( ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_SOFTWARE) \
  100. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_CH3) \
  101. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_CH1) \
  102. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_CH2) \
  103. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM2_CH2) \
  104. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM3_TRGO) \
  105. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM4_CH4) \
  106. || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_EXTI_LINE11) \
  107. )
  108. #endif
  109. #endif
  110. #define IS_LL_ADC_REG_CONTINUOUS_MODE(__REG_CONTINUOUS_MODE__) \
  111. ( ((__REG_CONTINUOUS_MODE__) == LL_ADC_REG_CONV_SINGLE) \
  112. || ((__REG_CONTINUOUS_MODE__) == LL_ADC_REG_CONV_CONTINUOUS) \
  113. )
  114. #define IS_LL_ADC_REG_DMA_TRANSFER(__REG_DMA_TRANSFER__) \
  115. ( ((__REG_DMA_TRANSFER__) == LL_ADC_REG_DMA_TRANSFER_NONE) \
  116. || ((__REG_DMA_TRANSFER__) == LL_ADC_REG_DMA_TRANSFER_UNLIMITED) \
  117. )
  118. #define IS_LL_ADC_REG_SEQ_SCAN_LENGTH(__REG_SEQ_SCAN_LENGTH__) \
  119. ( ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_DISABLE) \
  120. || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_2RANKS) \
  121. || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_3RANKS) \
  122. || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_4RANKS) \
  123. || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_5RANKS) \
  124. || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_6RANKS) \
  125. || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_7RANKS) \
  126. || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_8RANKS) \
  127. || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_9RANKS) \
  128. || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_10RANKS) \
  129. || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_11RANKS) \
  130. || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_12RANKS) \
  131. || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_13RANKS) \
  132. || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_14RANKS) \
  133. || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_15RANKS) \
  134. || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_16RANKS) \
  135. )
  136. #define IS_LL_ADC_REG_SEQ_SCAN_DISCONT_MODE(__REG_SEQ_DISCONT_MODE__) \
  137. ( ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_DISABLE) \
  138. || ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_1RANK) \
  139. || ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_2RANKS) \
  140. || ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_3RANKS) \
  141. || ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_4RANKS) \
  142. || ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_5RANKS) \
  143. || ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_6RANKS) \
  144. || ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_7RANKS) \
  145. || ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_8RANKS) \
  146. )
  147. /* Check of parameters for configuration of ADC hierarchical scope: */
  148. /* ADC group injected */
  149. #if defined(ADC3)
  150. #define IS_LL_ADC_INJ_TRIG_SOURCE(__ADC_INSTANCE__, __INJ_TRIG_SOURCE__) \
  151. ((((__ADC_INSTANCE__) == ADC1) || ((__ADC_INSTANCE__) == ADC2)) \
  152. ? ( ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_SOFTWARE) \
  153. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM1_TRGO) \
  154. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM1_CH4) \
  155. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM2_TRGO) \
  156. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM2_CH1) \
  157. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM3_CH4) \
  158. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM4_TRGO) \
  159. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_EXTI_LINE15) \
  160. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM8_CH4) \
  161. ) \
  162. : \
  163. ( ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_SOFTWARE) \
  164. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM1_TRGO) \
  165. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM1_CH4) \
  166. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM4_CH3) \
  167. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM8_CH2) \
  168. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM8_CH4_ADC3) \
  169. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM5_TRGO) \
  170. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM5_CH4) \
  171. ) \
  172. )
  173. #else
  174. #if defined (STM32F101xE) || defined (STM32F105xC) || defined (STM32F107xC)
  175. #define IS_LL_ADC_INJ_TRIG_SOURCE(__INJ_TRIG_SOURCE__) \
  176. ( ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_SOFTWARE) \
  177. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM1_TRGO) \
  178. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM1_CH4) \
  179. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM2_TRGO) \
  180. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM2_CH1) \
  181. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM3_CH4) \
  182. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM4_TRGO) \
  183. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_EXTI_LINE15) \
  184. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM8_CH4) \
  185. )
  186. #else
  187. #define IS_LL_ADC_INJ_TRIG_SOURCE(__INJ_TRIG_SOURCE__) \
  188. ( ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_SOFTWARE) \
  189. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM1_TRGO) \
  190. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM1_CH4) \
  191. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM2_TRGO) \
  192. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM2_CH1) \
  193. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM3_CH4) \
  194. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM4_TRGO) \
  195. || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_EXTI_LINE15) \
  196. )
  197. #endif
  198. #endif
  199. #define IS_LL_ADC_INJ_TRIG_AUTO(__INJ_TRIG_AUTO__) \
  200. ( ((__INJ_TRIG_AUTO__) == LL_ADC_INJ_TRIG_INDEPENDENT) \
  201. || ((__INJ_TRIG_AUTO__) == LL_ADC_INJ_TRIG_FROM_GRP_REGULAR) \
  202. )
  203. #define IS_LL_ADC_INJ_SEQ_SCAN_LENGTH(__INJ_SEQ_SCAN_LENGTH__) \
  204. ( ((__INJ_SEQ_SCAN_LENGTH__) == LL_ADC_INJ_SEQ_SCAN_DISABLE) \
  205. || ((__INJ_SEQ_SCAN_LENGTH__) == LL_ADC_INJ_SEQ_SCAN_ENABLE_2RANKS) \
  206. || ((__INJ_SEQ_SCAN_LENGTH__) == LL_ADC_INJ_SEQ_SCAN_ENABLE_3RANKS) \
  207. || ((__INJ_SEQ_SCAN_LENGTH__) == LL_ADC_INJ_SEQ_SCAN_ENABLE_4RANKS) \
  208. )
  209. #define IS_LL_ADC_INJ_SEQ_SCAN_DISCONT_MODE(__INJ_SEQ_DISCONT_MODE__) \
  210. ( ((__INJ_SEQ_DISCONT_MODE__) == LL_ADC_INJ_SEQ_DISCONT_DISABLE) \
  211. || ((__INJ_SEQ_DISCONT_MODE__) == LL_ADC_INJ_SEQ_DISCONT_1RANK) \
  212. )
  213. #if defined(ADC_MULTIMODE_SUPPORT)
  214. /* Check of parameters for configuration of ADC hierarchical scope: */
  215. /* multimode. */
  216. #define IS_LL_ADC_MULTI_MODE(__MULTI_MODE__) \
  217. ( ((__MULTI_MODE__) == LL_ADC_MULTI_INDEPENDENT) \
  218. || ((__MULTI_MODE__) == LL_ADC_MULTI_DUAL_REG_SIMULT) \
  219. || ((__MULTI_MODE__) == LL_ADC_MULTI_DUAL_REG_INTERL_FAST) \
  220. || ((__MULTI_MODE__) == LL_ADC_MULTI_DUAL_REG_INTERL_SLOW) \
  221. || ((__MULTI_MODE__) == LL_ADC_MULTI_DUAL_INJ_SIMULT) \
  222. || ((__MULTI_MODE__) == LL_ADC_MULTI_DUAL_INJ_ALTERN) \
  223. || ((__MULTI_MODE__) == LL_ADC_MULTI_DUAL_REG_SIM_INJ_SIM) \
  224. || ((__MULTI_MODE__) == LL_ADC_MULTI_DUAL_REG_SIM_INJ_ALT) \
  225. || ((__MULTI_MODE__) == LL_ADC_MULTI_DUAL_REG_INTFAST_INJ_SIM) \
  226. || ((__MULTI_MODE__) == LL_ADC_MULTI_DUAL_REG_INTSLOW_INJ_SIM) \
  227. )
  228. #define IS_LL_ADC_MULTI_MASTER_SLAVE(__MULTI_MASTER_SLAVE__) \
  229. ( ((__MULTI_MASTER_SLAVE__) == LL_ADC_MULTI_MASTER) \
  230. || ((__MULTI_MASTER_SLAVE__) == LL_ADC_MULTI_SLAVE) \
  231. || ((__MULTI_MASTER_SLAVE__) == LL_ADC_MULTI_MASTER_SLAVE) \
  232. )
  233. #endif /* ADC_MULTIMODE_SUPPORT */
  234. /**
  235. * @}
  236. */
  237. /* Private function prototypes -----------------------------------------------*/
  238. /* Exported functions --------------------------------------------------------*/
  239. /** @addtogroup ADC_LL_Exported_Functions
  240. * @{
  241. */
  242. /** @addtogroup ADC_LL_EF_Init
  243. * @{
  244. */
  245. /**
  246. * @brief De-initialize registers of all ADC instances belonging to
  247. * the same ADC common instance to their default reset values.
  248. * @param ADCxy_COMMON ADC common instance
  249. * (can be set directly from CMSIS definition or by using helper macro @ref __LL_ADC_COMMON_INSTANCE() )
  250. * @retval An ErrorStatus enumeration value:
  251. * - SUCCESS: ADC common registers are de-initialized
  252. * - ERROR: not applicable
  253. */
  254. ErrorStatus LL_ADC_CommonDeInit(ADC_Common_TypeDef *ADCxy_COMMON)
  255. {
  256. /* Check the parameters */
  257. assert_param(IS_ADC_COMMON_INSTANCE(ADCxy_COMMON));
  258. /* Force reset of ADC clock (core clock) */
  259. LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_ADC1);
  260. /* Release reset of ADC clock (core clock) */
  261. LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_ADC1);
  262. return SUCCESS;
  263. }
  264. /**
  265. * @brief Initialize some features of ADC common parameters
  266. * (all ADC instances belonging to the same ADC common instance)
  267. * and multimode (for devices with several ADC instances available).
  268. * @note The setting of ADC common parameters is conditioned to
  269. * ADC instances state:
  270. * All ADC instances belonging to the same ADC common instance
  271. * must be disabled.
  272. * @param ADCxy_COMMON ADC common instance
  273. * (can be set directly from CMSIS definition or by using helper macro @ref __LL_ADC_COMMON_INSTANCE() )
  274. * @param ADC_CommonInitStruct Pointer to a @ref LL_ADC_CommonInitTypeDef structure
  275. * @retval An ErrorStatus enumeration value:
  276. * - SUCCESS: ADC common registers are initialized
  277. * - ERROR: ADC common registers are not initialized
  278. */
  279. ErrorStatus LL_ADC_CommonInit(ADC_Common_TypeDef *ADCxy_COMMON, LL_ADC_CommonInitTypeDef *ADC_CommonInitStruct)
  280. {
  281. ErrorStatus status = SUCCESS;
  282. /* Check the parameters */
  283. assert_param(IS_ADC_COMMON_INSTANCE(ADCxy_COMMON));
  284. #if defined(ADC_MULTIMODE_SUPPORT)
  285. assert_param(IS_LL_ADC_MULTI_MODE(ADC_CommonInitStruct->Multimode));
  286. #endif /* ADC_MULTIMODE_SUPPORT */
  287. /* Note: Hardware constraint (refer to description of functions */
  288. /* "LL_ADC_SetCommonXXX()" and "LL_ADC_SetMultiXXX()"): */
  289. /* On this STM32 serie, setting of these features is conditioned to */
  290. /* ADC state: */
  291. /* All ADC instances of the ADC common group must be disabled. */
  292. if(__LL_ADC_IS_ENABLED_ALL_COMMON_INSTANCE(ADCxy_COMMON) == 0U)
  293. {
  294. /* Configuration of ADC hierarchical scope: */
  295. /* - common to several ADC */
  296. /* (all ADC instances belonging to the same ADC common instance) */
  297. /* - multimode (if several ADC instances available on the */
  298. /* selected device) */
  299. /* - Set ADC multimode configuration */
  300. /* - Set ADC multimode DMA transfer */
  301. /* - Set ADC multimode: delay between 2 sampling phases */
  302. #if defined(ADC_MULTIMODE_SUPPORT)
  303. if(ADC_CommonInitStruct->Multimode != LL_ADC_MULTI_INDEPENDENT)
  304. {
  305. MODIFY_REG(ADCxy_COMMON->CR1,
  306. ADC_CR1_DUALMOD,
  307. ADC_CommonInitStruct->Multimode
  308. );
  309. }
  310. else
  311. {
  312. MODIFY_REG(ADCxy_COMMON->CR1,
  313. ADC_CR1_DUALMOD,
  314. LL_ADC_MULTI_INDEPENDENT
  315. );
  316. }
  317. #endif
  318. }
  319. else
  320. {
  321. /* Initialization error: One or several ADC instances belonging to */
  322. /* the same ADC common instance are not disabled. */
  323. status = ERROR;
  324. }
  325. return status;
  326. }
  327. /**
  328. * @brief Set each @ref LL_ADC_CommonInitTypeDef field to default value.
  329. * @param ADC_CommonInitStruct Pointer to a @ref LL_ADC_CommonInitTypeDef structure
  330. * whose fields will be set to default values.
  331. * @retval None
  332. */
  333. void LL_ADC_CommonStructInit(LL_ADC_CommonInitTypeDef *ADC_CommonInitStruct)
  334. {
  335. /* Set ADC_CommonInitStruct fields to default values */
  336. /* Set fields of ADC common */
  337. /* (all ADC instances belonging to the same ADC common instance) */
  338. #if defined(ADC_MULTIMODE_SUPPORT)
  339. /* Set fields of ADC multimode */
  340. ADC_CommonInitStruct->Multimode = LL_ADC_MULTI_INDEPENDENT;
  341. #endif /* ADC_MULTIMODE_SUPPORT */
  342. }
  343. /**
  344. * @brief De-initialize registers of the selected ADC instance
  345. * to their default reset values.
  346. * @note To reset all ADC instances quickly (perform a hard reset),
  347. * use function @ref LL_ADC_CommonDeInit().
  348. * @param ADCx ADC instance
  349. * @retval An ErrorStatus enumeration value:
  350. * - SUCCESS: ADC registers are de-initialized
  351. * - ERROR: ADC registers are not de-initialized
  352. */
  353. ErrorStatus LL_ADC_DeInit(ADC_TypeDef *ADCx)
  354. {
  355. ErrorStatus status = SUCCESS;
  356. /* Check the parameters */
  357. assert_param(IS_ADC_ALL_INSTANCE(ADCx));
  358. /* Disable ADC instance if not already disabled. */
  359. if(LL_ADC_IsEnabled(ADCx) == 1U)
  360. {
  361. /* Set ADC group regular trigger source to SW start to ensure to not */
  362. /* have an external trigger event occurring during the conversion stop */
  363. /* ADC disable process. */
  364. LL_ADC_REG_SetTriggerSource(ADCx, LL_ADC_REG_TRIG_SOFTWARE);
  365. /* Set ADC group injected trigger source to SW start to ensure to not */
  366. /* have an external trigger event occurring during the conversion stop */
  367. /* ADC disable process. */
  368. LL_ADC_INJ_SetTriggerSource(ADCx, LL_ADC_INJ_TRIG_SOFTWARE);
  369. /* Disable the ADC instance */
  370. LL_ADC_Disable(ADCx);
  371. }
  372. /* Check whether ADC state is compliant with expected state */
  373. /* (hardware requirements of bits state to reset registers below) */
  374. if(READ_BIT(ADCx->CR2, ADC_CR2_ADON) == 0U)
  375. {
  376. /* ========== Reset ADC registers ========== */
  377. /* Reset register SR */
  378. CLEAR_BIT(ADCx->SR,
  379. ( LL_ADC_FLAG_STRT
  380. | LL_ADC_FLAG_JSTRT
  381. | LL_ADC_FLAG_EOS
  382. | LL_ADC_FLAG_JEOS
  383. | LL_ADC_FLAG_AWD1 )
  384. );
  385. /* Reset register CR1 */
  386. #if defined (STM32F103x6) || defined (STM32F103xB) || defined (STM32F105xC) || defined (STM32F107xC) || defined (STM32F103xE) || defined (STM32F103xG)
  387. CLEAR_BIT(ADCx->CR1,
  388. ( ADC_CR1_AWDEN | ADC_CR1_JAWDEN | ADC_CR1_DUALMOD
  389. | ADC_CR1_DISCNUM | ADC_CR1_JDISCEN | ADC_CR1_DISCEN
  390. | ADC_CR1_JAUTO | ADC_CR1_AWDSGL | ADC_CR1_SCAN
  391. | ADC_CR1_JEOCIE | ADC_CR1_AWDIE | ADC_CR1_EOCIE
  392. | ADC_CR1_AWDCH )
  393. );
  394. #else
  395. CLEAR_BIT(ADCx->CR1,
  396. ( ADC_CR1_AWDEN | ADC_CR1_JAWDEN | ADC_CR1_DISCNUM
  397. | ADC_CR1_JDISCEN | ADC_CR1_DISCEN | ADC_CR1_JAUTO
  398. | ADC_CR1_AWDSGL | ADC_CR1_SCAN | ADC_CR1_JEOCIE
  399. | ADC_CR1_AWDIE | ADC_CR1_EOCIE | ADC_CR1_AWDCH )
  400. );
  401. #endif
  402. /* Reset register CR2 */
  403. CLEAR_BIT(ADCx->CR2,
  404. ( ADC_CR2_TSVREFE
  405. | ADC_CR2_SWSTART | ADC_CR2_EXTTRIG | ADC_CR2_EXTSEL
  406. | ADC_CR2_JSWSTART | ADC_CR2_JEXTTRIG | ADC_CR2_JEXTSEL
  407. | ADC_CR2_ALIGN | ADC_CR2_DMA
  408. | ADC_CR2_RSTCAL | ADC_CR2_CAL
  409. | ADC_CR2_CONT | ADC_CR2_ADON )
  410. );
  411. /* Reset register SMPR1 */
  412. CLEAR_BIT(ADCx->SMPR1,
  413. ( ADC_SMPR1_SMP17 | ADC_SMPR1_SMP16
  414. | ADC_SMPR1_SMP15 | ADC_SMPR1_SMP14 | ADC_SMPR1_SMP13
  415. | ADC_SMPR1_SMP12 | ADC_SMPR1_SMP11 | ADC_SMPR1_SMP10)
  416. );
  417. /* Reset register SMPR2 */
  418. CLEAR_BIT(ADCx->SMPR2,
  419. ( ADC_SMPR2_SMP9
  420. | ADC_SMPR2_SMP8 | ADC_SMPR2_SMP7 | ADC_SMPR2_SMP6
  421. | ADC_SMPR2_SMP5 | ADC_SMPR2_SMP4 | ADC_SMPR2_SMP3
  422. | ADC_SMPR2_SMP2 | ADC_SMPR2_SMP1 | ADC_SMPR2_SMP0)
  423. );
  424. /* Reset register JOFR1 */
  425. CLEAR_BIT(ADCx->JOFR1, ADC_JOFR1_JOFFSET1);
  426. /* Reset register JOFR2 */
  427. CLEAR_BIT(ADCx->JOFR2, ADC_JOFR2_JOFFSET2);
  428. /* Reset register JOFR3 */
  429. CLEAR_BIT(ADCx->JOFR3, ADC_JOFR3_JOFFSET3);
  430. /* Reset register JOFR4 */
  431. CLEAR_BIT(ADCx->JOFR4, ADC_JOFR4_JOFFSET4);
  432. /* Reset register HTR */
  433. SET_BIT(ADCx->HTR, ADC_HTR_HT);
  434. /* Reset register LTR */
  435. CLEAR_BIT(ADCx->LTR, ADC_LTR_LT);
  436. /* Reset register SQR1 */
  437. CLEAR_BIT(ADCx->SQR1,
  438. ( ADC_SQR1_L
  439. | ADC_SQR1_SQ16
  440. | ADC_SQR1_SQ15 | ADC_SQR1_SQ14 | ADC_SQR1_SQ13)
  441. );
  442. /* Reset register SQR2 */
  443. CLEAR_BIT(ADCx->SQR2,
  444. ( ADC_SQR2_SQ12 | ADC_SQR2_SQ11 | ADC_SQR2_SQ10
  445. | ADC_SQR2_SQ9 | ADC_SQR2_SQ8 | ADC_SQR2_SQ7)
  446. );
  447. /* Reset register JSQR */
  448. CLEAR_BIT(ADCx->JSQR,
  449. ( ADC_JSQR_JL
  450. | ADC_JSQR_JSQ4 | ADC_JSQR_JSQ3
  451. | ADC_JSQR_JSQ2 | ADC_JSQR_JSQ1 )
  452. );
  453. /* Reset register DR */
  454. /* bits in access mode read only, no direct reset applicable */
  455. /* Reset registers JDR1, JDR2, JDR3, JDR4 */
  456. /* bits in access mode read only, no direct reset applicable */
  457. }
  458. return status;
  459. }
  460. /**
  461. * @brief Initialize some features of ADC instance.
  462. * @note These parameters have an impact on ADC scope: ADC instance.
  463. * Affects both group regular and group injected (availability
  464. * of ADC group injected depends on STM32 families).
  465. * Refer to corresponding unitary functions into
  466. * @ref ADC_LL_EF_Configuration_ADC_Instance .
  467. * @note The setting of these parameters by function @ref LL_ADC_Init()
  468. * is conditioned to ADC state:
  469. * ADC instance must be disabled.
  470. * This condition is applied to all ADC features, for efficiency
  471. * and compatibility over all STM32 families. However, the different
  472. * features can be set under different ADC state conditions
  473. * (setting possible with ADC enabled without conversion on going,
  474. * ADC enabled with conversion on going, ...)
  475. * Each feature can be updated afterwards with a unitary function
  476. * and potentially with ADC in a different state than disabled,
  477. * refer to description of each function for setting
  478. * conditioned to ADC state.
  479. * @note After using this function, some other features must be configured
  480. * using LL unitary functions.
  481. * The minimum configuration remaining to be done is:
  482. * - Set ADC group regular or group injected sequencer:
  483. * map channel on the selected sequencer rank.
  484. * Refer to function @ref LL_ADC_REG_SetSequencerRanks().
  485. * - Set ADC channel sampling time
  486. * Refer to function LL_ADC_SetChannelSamplingTime();
  487. * @param ADCx ADC instance
  488. * @param ADC_InitStruct Pointer to a @ref LL_ADC_REG_InitTypeDef structure
  489. * @retval An ErrorStatus enumeration value:
  490. * - SUCCESS: ADC registers are initialized
  491. * - ERROR: ADC registers are not initialized
  492. */
  493. ErrorStatus LL_ADC_Init(ADC_TypeDef *ADCx, LL_ADC_InitTypeDef *ADC_InitStruct)
  494. {
  495. ErrorStatus status = SUCCESS;
  496. /* Check the parameters */
  497. assert_param(IS_ADC_ALL_INSTANCE(ADCx));
  498. assert_param(IS_LL_ADC_DATA_ALIGN(ADC_InitStruct->DataAlignment));
  499. assert_param(IS_LL_ADC_SCAN_SELECTION(ADC_InitStruct->SequencersScanMode));
  500. /* Note: Hardware constraint (refer to description of this function): */
  501. /* ADC instance must be disabled. */
  502. if(LL_ADC_IsEnabled(ADCx) == 0U)
  503. {
  504. /* Configuration of ADC hierarchical scope: */
  505. /* - ADC instance */
  506. /* - Set ADC conversion data alignment */
  507. MODIFY_REG(ADCx->CR1,
  508. ADC_CR1_SCAN
  509. ,
  510. ADC_InitStruct->SequencersScanMode
  511. );
  512. MODIFY_REG(ADCx->CR2,
  513. ADC_CR2_ALIGN
  514. ,
  515. ADC_InitStruct->DataAlignment
  516. );
  517. }
  518. else
  519. {
  520. /* Initialization error: ADC instance is not disabled. */
  521. status = ERROR;
  522. }
  523. return status;
  524. }
  525. /**
  526. * @brief Set each @ref LL_ADC_InitTypeDef field to default value.
  527. * @param ADC_InitStruct Pointer to a @ref LL_ADC_InitTypeDef structure
  528. * whose fields will be set to default values.
  529. * @retval None
  530. */
  531. void LL_ADC_StructInit(LL_ADC_InitTypeDef *ADC_InitStruct)
  532. {
  533. /* Set ADC_InitStruct fields to default values */
  534. /* Set fields of ADC instance */
  535. ADC_InitStruct->DataAlignment = LL_ADC_DATA_ALIGN_RIGHT;
  536. /* Enable scan mode to have a generic behavior with ADC of other */
  537. /* STM32 families, without this setting available: */
  538. /* ADC group regular sequencer and ADC group injected sequencer depend */
  539. /* only of their own configuration. */
  540. ADC_InitStruct->SequencersScanMode = LL_ADC_SEQ_SCAN_ENABLE;
  541. }
  542. /**
  543. * @brief Initialize some features of ADC group regular.
  544. * @note These parameters have an impact on ADC scope: ADC group regular.
  545. * Refer to corresponding unitary functions into
  546. * @ref ADC_LL_EF_Configuration_ADC_Group_Regular
  547. * (functions with prefix "REG").
  548. * @note The setting of these parameters by function @ref LL_ADC_Init()
  549. * is conditioned to ADC state:
  550. * ADC instance must be disabled.
  551. * This condition is applied to all ADC features, for efficiency
  552. * and compatibility over all STM32 families. However, the different
  553. * features can be set under different ADC state conditions
  554. * (setting possible with ADC enabled without conversion on going,
  555. * ADC enabled with conversion on going, ...)
  556. * Each feature can be updated afterwards with a unitary function
  557. * and potentially with ADC in a different state than disabled,
  558. * refer to description of each function for setting
  559. * conditioned to ADC state.
  560. * @note After using this function, other features must be configured
  561. * using LL unitary functions.
  562. * The minimum configuration remaining to be done is:
  563. * - Set ADC group regular or group injected sequencer:
  564. * map channel on the selected sequencer rank.
  565. * Refer to function @ref LL_ADC_REG_SetSequencerRanks().
  566. * - Set ADC channel sampling time
  567. * Refer to function LL_ADC_SetChannelSamplingTime();
  568. * @param ADCx ADC instance
  569. * @param ADC_REG_InitStruct Pointer to a @ref LL_ADC_REG_InitTypeDef structure
  570. * @retval An ErrorStatus enumeration value:
  571. * - SUCCESS: ADC registers are initialized
  572. * - ERROR: ADC registers are not initialized
  573. */
  574. ErrorStatus LL_ADC_REG_Init(ADC_TypeDef *ADCx, LL_ADC_REG_InitTypeDef *ADC_REG_InitStruct)
  575. {
  576. ErrorStatus status = SUCCESS;
  577. /* Check the parameters */
  578. assert_param(IS_ADC_ALL_INSTANCE(ADCx));
  579. #if defined(ADC3)
  580. assert_param(IS_LL_ADC_REG_TRIG_SOURCE(ADCx, ADC_REG_InitStruct->TriggerSource));
  581. #else
  582. assert_param(IS_LL_ADC_REG_TRIG_SOURCE(ADC_REG_InitStruct->TriggerSource));
  583. #endif
  584. assert_param(IS_LL_ADC_REG_SEQ_SCAN_LENGTH(ADC_REG_InitStruct->SequencerLength));
  585. if(ADC_REG_InitStruct->SequencerLength != LL_ADC_REG_SEQ_SCAN_DISABLE)
  586. {
  587. assert_param(IS_LL_ADC_REG_SEQ_SCAN_DISCONT_MODE(ADC_REG_InitStruct->SequencerDiscont));
  588. }
  589. assert_param(IS_LL_ADC_REG_CONTINUOUS_MODE(ADC_REG_InitStruct->ContinuousMode));
  590. assert_param(IS_LL_ADC_REG_DMA_TRANSFER(ADC_REG_InitStruct->DMATransfer));
  591. /* Note: Hardware constraint (refer to description of this function): */
  592. /* ADC instance must be disabled. */
  593. if(LL_ADC_IsEnabled(ADCx) == 0U)
  594. {
  595. /* Configuration of ADC hierarchical scope: */
  596. /* - ADC group regular */
  597. /* - Set ADC group regular trigger source */
  598. /* - Set ADC group regular sequencer length */
  599. /* - Set ADC group regular sequencer discontinuous mode */
  600. /* - Set ADC group regular continuous mode */
  601. /* - Set ADC group regular conversion data transfer: no transfer or */
  602. /* transfer by DMA, and DMA requests mode */
  603. /* Note: On this STM32 serie, ADC trigger edge is set when starting */
  604. /* ADC conversion. */
  605. /* Refer to function @ref LL_ADC_REG_StartConversionExtTrig(). */
  606. if(ADC_REG_InitStruct->SequencerLength != LL_ADC_REG_SEQ_SCAN_DISABLE)
  607. {
  608. MODIFY_REG(ADCx->CR1,
  609. ADC_CR1_DISCEN
  610. | ADC_CR1_DISCNUM
  611. ,
  612. ADC_REG_InitStruct->SequencerLength
  613. | ADC_REG_InitStruct->SequencerDiscont
  614. );
  615. }
  616. else
  617. {
  618. MODIFY_REG(ADCx->CR1,
  619. ADC_CR1_DISCEN
  620. | ADC_CR1_DISCNUM
  621. ,
  622. ADC_REG_InitStruct->SequencerLength
  623. | LL_ADC_REG_SEQ_DISCONT_DISABLE
  624. );
  625. }
  626. MODIFY_REG(ADCx->CR2,
  627. ADC_CR2_EXTSEL
  628. | ADC_CR2_CONT
  629. | ADC_CR2_DMA
  630. ,
  631. ADC_REG_InitStruct->TriggerSource
  632. | ADC_REG_InitStruct->ContinuousMode
  633. | ADC_REG_InitStruct->DMATransfer
  634. );
  635. /* Set ADC group regular sequencer length and scan direction */
  636. /* Note: Hardware constraint (refer to description of this function): */
  637. /* Note: If ADC instance feature scan mode is disabled */
  638. /* (refer to ADC instance initialization structure */
  639. /* parameter @ref SequencersScanMode */
  640. /* or function @ref LL_ADC_SetSequencersScanMode() ), */
  641. /* this parameter is discarded. */
  642. LL_ADC_REG_SetSequencerLength(ADCx, ADC_REG_InitStruct->SequencerLength);
  643. }
  644. else
  645. {
  646. /* Initialization error: ADC instance is not disabled. */
  647. status = ERROR;
  648. }
  649. return status;
  650. }
  651. /**
  652. * @brief Set each @ref LL_ADC_REG_InitTypeDef field to default value.
  653. * @param ADC_REG_InitStruct Pointer to a @ref LL_ADC_REG_InitTypeDef structure
  654. * whose fields will be set to default values.
  655. * @retval None
  656. */
  657. void LL_ADC_REG_StructInit(LL_ADC_REG_InitTypeDef *ADC_REG_InitStruct)
  658. {
  659. /* Set ADC_REG_InitStruct fields to default values */
  660. /* Set fields of ADC group regular */
  661. /* Note: On this STM32 serie, ADC trigger edge is set when starting */
  662. /* ADC conversion. */
  663. /* Refer to function @ref LL_ADC_REG_StartConversionExtTrig(). */
  664. ADC_REG_InitStruct->TriggerSource = LL_ADC_REG_TRIG_SOFTWARE;
  665. ADC_REG_InitStruct->SequencerLength = LL_ADC_REG_SEQ_SCAN_DISABLE;
  666. ADC_REG_InitStruct->SequencerDiscont = LL_ADC_REG_SEQ_DISCONT_DISABLE;
  667. ADC_REG_InitStruct->ContinuousMode = LL_ADC_REG_CONV_SINGLE;
  668. ADC_REG_InitStruct->DMATransfer = LL_ADC_REG_DMA_TRANSFER_NONE;
  669. }
  670. /**
  671. * @brief Initialize some features of ADC group injected.
  672. * @note These parameters have an impact on ADC scope: ADC group injected.
  673. * Refer to corresponding unitary functions into
  674. * @ref ADC_LL_EF_Configuration_ADC_Group_Regular
  675. * (functions with prefix "INJ").
  676. * @note The setting of these parameters by function @ref LL_ADC_Init()
  677. * is conditioned to ADC state:
  678. * ADC instance must be disabled.
  679. * This condition is applied to all ADC features, for efficiency
  680. * and compatibility over all STM32 families. However, the different
  681. * features can be set under different ADC state conditions
  682. * (setting possible with ADC enabled without conversion on going,
  683. * ADC enabled with conversion on going, ...)
  684. * Each feature can be updated afterwards with a unitary function
  685. * and potentially with ADC in a different state than disabled,
  686. * refer to description of each function for setting
  687. * conditioned to ADC state.
  688. * @note After using this function, other features must be configured
  689. * using LL unitary functions.
  690. * The minimum configuration remaining to be done is:
  691. * - Set ADC group injected sequencer:
  692. * map channel on the selected sequencer rank.
  693. * Refer to function @ref LL_ADC_INJ_SetSequencerRanks().
  694. * - Set ADC channel sampling time
  695. * Refer to function LL_ADC_SetChannelSamplingTime();
  696. * @param ADCx ADC instance
  697. * @param ADC_INJ_InitStruct Pointer to a @ref LL_ADC_INJ_InitTypeDef structure
  698. * @retval An ErrorStatus enumeration value:
  699. * - SUCCESS: ADC registers are initialized
  700. * - ERROR: ADC registers are not initialized
  701. */
  702. ErrorStatus LL_ADC_INJ_Init(ADC_TypeDef *ADCx, LL_ADC_INJ_InitTypeDef *ADC_INJ_InitStruct)
  703. {
  704. ErrorStatus status = SUCCESS;
  705. /* Check the parameters */
  706. assert_param(IS_ADC_ALL_INSTANCE(ADCx));
  707. #if defined(ADC3)
  708. assert_param(IS_LL_ADC_INJ_TRIG_SOURCE(ADCx, ADC_INJ_InitStruct->TriggerSource));
  709. #else
  710. assert_param(IS_LL_ADC_INJ_TRIG_SOURCE(ADC_INJ_InitStruct->TriggerSource));
  711. #endif
  712. assert_param(IS_LL_ADC_INJ_SEQ_SCAN_LENGTH(ADC_INJ_InitStruct->SequencerLength));
  713. if(ADC_INJ_InitStruct->SequencerLength != LL_ADC_INJ_SEQ_SCAN_DISABLE)
  714. {
  715. assert_param(IS_LL_ADC_INJ_SEQ_SCAN_DISCONT_MODE(ADC_INJ_InitStruct->SequencerDiscont));
  716. }
  717. assert_param(IS_LL_ADC_INJ_TRIG_AUTO(ADC_INJ_InitStruct->TrigAuto));
  718. /* Note: Hardware constraint (refer to description of this function): */
  719. /* ADC instance must be disabled. */
  720. if(LL_ADC_IsEnabled(ADCx) == 0U)
  721. {
  722. /* Configuration of ADC hierarchical scope: */
  723. /* - ADC group injected */
  724. /* - Set ADC group injected trigger source */
  725. /* - Set ADC group injected sequencer length */
  726. /* - Set ADC group injected sequencer discontinuous mode */
  727. /* - Set ADC group injected conversion trigger: independent or */
  728. /* from ADC group regular */
  729. /* Note: On this STM32 serie, ADC trigger edge is set when starting */
  730. /* ADC conversion. */
  731. /* Refer to function @ref LL_ADC_INJ_StartConversionExtTrig(). */
  732. if(ADC_INJ_InitStruct->SequencerLength != LL_ADC_REG_SEQ_SCAN_DISABLE)
  733. {
  734. MODIFY_REG(ADCx->CR1,
  735. ADC_CR1_JDISCEN
  736. | ADC_CR1_JAUTO
  737. ,
  738. ADC_INJ_InitStruct->SequencerDiscont
  739. | ADC_INJ_InitStruct->TrigAuto
  740. );
  741. }
  742. else
  743. {
  744. MODIFY_REG(ADCx->CR1,
  745. ADC_CR1_JDISCEN
  746. | ADC_CR1_JAUTO
  747. ,
  748. LL_ADC_REG_SEQ_DISCONT_DISABLE
  749. | ADC_INJ_InitStruct->TrigAuto
  750. );
  751. }
  752. MODIFY_REG(ADCx->CR2,
  753. ADC_CR2_JEXTSEL
  754. ,
  755. ADC_INJ_InitStruct->TriggerSource
  756. );
  757. /* Note: Hardware constraint (refer to description of this function): */
  758. /* Note: If ADC instance feature scan mode is disabled */
  759. /* (refer to ADC instance initialization structure */
  760. /* parameter @ref SequencersScanMode */
  761. /* or function @ref LL_ADC_SetSequencersScanMode() ), */
  762. /* this parameter is discarded. */
  763. LL_ADC_INJ_SetSequencerLength(ADCx, ADC_INJ_InitStruct->SequencerLength);
  764. }
  765. else
  766. {
  767. /* Initialization error: ADC instance is not disabled. */
  768. status = ERROR;
  769. }
  770. return status;
  771. }
  772. /**
  773. * @brief Set each @ref LL_ADC_INJ_InitTypeDef field to default value.
  774. * @param ADC_INJ_InitStruct Pointer to a @ref LL_ADC_INJ_InitTypeDef structure
  775. * whose fields will be set to default values.
  776. * @retval None
  777. */
  778. void LL_ADC_INJ_StructInit(LL_ADC_INJ_InitTypeDef *ADC_INJ_InitStruct)
  779. {
  780. /* Set ADC_INJ_InitStruct fields to default values */
  781. /* Set fields of ADC group injected */
  782. ADC_INJ_InitStruct->TriggerSource = LL_ADC_INJ_TRIG_SOFTWARE;
  783. ADC_INJ_InitStruct->SequencerLength = LL_ADC_INJ_SEQ_SCAN_DISABLE;
  784. ADC_INJ_InitStruct->SequencerDiscont = LL_ADC_INJ_SEQ_DISCONT_DISABLE;
  785. ADC_INJ_InitStruct->TrigAuto = LL_ADC_INJ_TRIG_INDEPENDENT;
  786. }
  787. /**
  788. * @}
  789. */
  790. /**
  791. * @}
  792. */
  793. /**
  794. * @}
  795. */
  796. #endif /* ADC1 || ADC2 || ADC3 */
  797. /**
  798. * @}
  799. */
  800. #endif /* USE_FULL_LL_DRIVER */
  801. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/