stm32f1xx_ll_adc.c 40 KB

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