You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

stm32f1xx_ll_adc.c 41KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896
  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 SQR3 */
  448. CLEAR_BIT(ADCx->SQR3,
  449. ( ADC_SQR3_SQ6 | ADC_SQR3_SQ5 | ADC_SQR3_SQ4
  450. | ADC_SQR3_SQ3 | ADC_SQR3_SQ2 | ADC_SQR3_SQ1)
  451. );
  452. /* Reset register JSQR */
  453. CLEAR_BIT(ADCx->JSQR,
  454. ( ADC_JSQR_JL
  455. | ADC_JSQR_JSQ4 | ADC_JSQR_JSQ3
  456. | ADC_JSQR_JSQ2 | ADC_JSQR_JSQ1 )
  457. );
  458. /* Reset register DR */
  459. /* bits in access mode read only, no direct reset applicable */
  460. /* Reset registers JDR1, JDR2, JDR3, JDR4 */
  461. /* bits in access mode read only, no direct reset applicable */
  462. }
  463. return status;
  464. }
  465. /**
  466. * @brief Initialize some features of ADC instance.
  467. * @note These parameters have an impact on ADC scope: ADC instance.
  468. * Affects both group regular and group injected (availability
  469. * of ADC group injected depends on STM32 families).
  470. * Refer to corresponding unitary functions into
  471. * @ref ADC_LL_EF_Configuration_ADC_Instance .
  472. * @note The setting of these parameters by function @ref LL_ADC_Init()
  473. * is conditioned to ADC state:
  474. * ADC instance must be disabled.
  475. * This condition is applied to all ADC features, for efficiency
  476. * and compatibility over all STM32 families. However, the different
  477. * features can be set under different ADC state conditions
  478. * (setting possible with ADC enabled without conversion on going,
  479. * ADC enabled with conversion on going, ...)
  480. * Each feature can be updated afterwards with a unitary function
  481. * and potentially with ADC in a different state than disabled,
  482. * refer to description of each function for setting
  483. * conditioned to ADC state.
  484. * @note After using this function, some other features must be configured
  485. * using LL unitary functions.
  486. * The minimum configuration remaining to be done is:
  487. * - Set ADC group regular or group injected sequencer:
  488. * map channel on the selected sequencer rank.
  489. * Refer to function @ref LL_ADC_REG_SetSequencerRanks().
  490. * - Set ADC channel sampling time
  491. * Refer to function LL_ADC_SetChannelSamplingTime();
  492. * @param ADCx ADC instance
  493. * @param ADC_InitStruct Pointer to a @ref LL_ADC_REG_InitTypeDef structure
  494. * @retval An ErrorStatus enumeration value:
  495. * - SUCCESS: ADC registers are initialized
  496. * - ERROR: ADC registers are not initialized
  497. */
  498. ErrorStatus LL_ADC_Init(ADC_TypeDef *ADCx, LL_ADC_InitTypeDef *ADC_InitStruct)
  499. {
  500. ErrorStatus status = SUCCESS;
  501. /* Check the parameters */
  502. assert_param(IS_ADC_ALL_INSTANCE(ADCx));
  503. assert_param(IS_LL_ADC_DATA_ALIGN(ADC_InitStruct->DataAlignment));
  504. assert_param(IS_LL_ADC_SCAN_SELECTION(ADC_InitStruct->SequencersScanMode));
  505. /* Note: Hardware constraint (refer to description of this function): */
  506. /* ADC instance must be disabled. */
  507. if(LL_ADC_IsEnabled(ADCx) == 0U)
  508. {
  509. /* Configuration of ADC hierarchical scope: */
  510. /* - ADC instance */
  511. /* - Set ADC conversion data alignment */
  512. MODIFY_REG(ADCx->CR1,
  513. ADC_CR1_SCAN
  514. ,
  515. ADC_InitStruct->SequencersScanMode
  516. );
  517. MODIFY_REG(ADCx->CR2,
  518. ADC_CR2_ALIGN
  519. ,
  520. ADC_InitStruct->DataAlignment
  521. );
  522. }
  523. else
  524. {
  525. /* Initialization error: ADC instance is not disabled. */
  526. status = ERROR;
  527. }
  528. return status;
  529. }
  530. /**
  531. * @brief Set each @ref LL_ADC_InitTypeDef field to default value.
  532. * @param ADC_InitStruct Pointer to a @ref LL_ADC_InitTypeDef structure
  533. * whose fields will be set to default values.
  534. * @retval None
  535. */
  536. void LL_ADC_StructInit(LL_ADC_InitTypeDef *ADC_InitStruct)
  537. {
  538. /* Set ADC_InitStruct fields to default values */
  539. /* Set fields of ADC instance */
  540. ADC_InitStruct->DataAlignment = LL_ADC_DATA_ALIGN_RIGHT;
  541. /* Enable scan mode to have a generic behavior with ADC of other */
  542. /* STM32 families, without this setting available: */
  543. /* ADC group regular sequencer and ADC group injected sequencer depend */
  544. /* only of their own configuration. */
  545. ADC_InitStruct->SequencersScanMode = LL_ADC_SEQ_SCAN_ENABLE;
  546. }
  547. /**
  548. * @brief Initialize some features of ADC group regular.
  549. * @note These parameters have an impact on ADC scope: ADC group regular.
  550. * Refer to corresponding unitary functions into
  551. * @ref ADC_LL_EF_Configuration_ADC_Group_Regular
  552. * (functions with prefix "REG").
  553. * @note The setting of these parameters by function @ref LL_ADC_Init()
  554. * is conditioned to ADC state:
  555. * ADC instance must be disabled.
  556. * This condition is applied to all ADC features, for efficiency
  557. * and compatibility over all STM32 families. However, the different
  558. * features can be set under different ADC state conditions
  559. * (setting possible with ADC enabled without conversion on going,
  560. * ADC enabled with conversion on going, ...)
  561. * Each feature can be updated afterwards with a unitary function
  562. * and potentially with ADC in a different state than disabled,
  563. * refer to description of each function for setting
  564. * conditioned to ADC state.
  565. * @note After using this function, other features must be configured
  566. * using LL unitary functions.
  567. * The minimum configuration remaining to be done is:
  568. * - Set ADC group regular or group injected sequencer:
  569. * map channel on the selected sequencer rank.
  570. * Refer to function @ref LL_ADC_REG_SetSequencerRanks().
  571. * - Set ADC channel sampling time
  572. * Refer to function LL_ADC_SetChannelSamplingTime();
  573. * @param ADCx ADC instance
  574. * @param ADC_REG_InitStruct Pointer to a @ref LL_ADC_REG_InitTypeDef structure
  575. * @retval An ErrorStatus enumeration value:
  576. * - SUCCESS: ADC registers are initialized
  577. * - ERROR: ADC registers are not initialized
  578. */
  579. ErrorStatus LL_ADC_REG_Init(ADC_TypeDef *ADCx, LL_ADC_REG_InitTypeDef *ADC_REG_InitStruct)
  580. {
  581. ErrorStatus status = SUCCESS;
  582. /* Check the parameters */
  583. assert_param(IS_ADC_ALL_INSTANCE(ADCx));
  584. #if defined(ADC3)
  585. assert_param(IS_LL_ADC_REG_TRIG_SOURCE(ADCx, ADC_REG_InitStruct->TriggerSource));
  586. #else
  587. assert_param(IS_LL_ADC_REG_TRIG_SOURCE(ADC_REG_InitStruct->TriggerSource));
  588. #endif
  589. assert_param(IS_LL_ADC_REG_SEQ_SCAN_LENGTH(ADC_REG_InitStruct->SequencerLength));
  590. if(ADC_REG_InitStruct->SequencerLength != LL_ADC_REG_SEQ_SCAN_DISABLE)
  591. {
  592. assert_param(IS_LL_ADC_REG_SEQ_SCAN_DISCONT_MODE(ADC_REG_InitStruct->SequencerDiscont));
  593. }
  594. assert_param(IS_LL_ADC_REG_CONTINUOUS_MODE(ADC_REG_InitStruct->ContinuousMode));
  595. assert_param(IS_LL_ADC_REG_DMA_TRANSFER(ADC_REG_InitStruct->DMATransfer));
  596. /* ADC group regular continuous mode and discontinuous mode */
  597. /* can not be enabled simultenaeously */
  598. assert_param((ADC_REG_InitStruct->ContinuousMode == LL_ADC_REG_CONV_SINGLE)
  599. || (ADC_REG_InitStruct->SequencerDiscont == LL_ADC_REG_SEQ_DISCONT_DISABLE));
  600. /* Note: Hardware constraint (refer to description of this function): */
  601. /* ADC instance must be disabled. */
  602. if(LL_ADC_IsEnabled(ADCx) == 0U)
  603. {
  604. /* Configuration of ADC hierarchical scope: */
  605. /* - ADC group regular */
  606. /* - Set ADC group regular trigger source */
  607. /* - Set ADC group regular sequencer length */
  608. /* - Set ADC group regular sequencer discontinuous mode */
  609. /* - Set ADC group regular continuous mode */
  610. /* - Set ADC group regular conversion data transfer: no transfer or */
  611. /* transfer by DMA, and DMA requests mode */
  612. /* Note: On this STM32 serie, ADC trigger edge is set when starting */
  613. /* ADC conversion. */
  614. /* Refer to function @ref LL_ADC_REG_StartConversionExtTrig(). */
  615. if(ADC_REG_InitStruct->SequencerLength != LL_ADC_REG_SEQ_SCAN_DISABLE)
  616. {
  617. MODIFY_REG(ADCx->CR1,
  618. ADC_CR1_DISCEN
  619. | ADC_CR1_DISCNUM
  620. ,
  621. ADC_REG_InitStruct->SequencerLength
  622. | ADC_REG_InitStruct->SequencerDiscont
  623. );
  624. }
  625. else
  626. {
  627. MODIFY_REG(ADCx->CR1,
  628. ADC_CR1_DISCEN
  629. | ADC_CR1_DISCNUM
  630. ,
  631. ADC_REG_InitStruct->SequencerLength
  632. | LL_ADC_REG_SEQ_DISCONT_DISABLE
  633. );
  634. }
  635. MODIFY_REG(ADCx->CR2,
  636. ADC_CR2_EXTSEL
  637. | ADC_CR2_CONT
  638. | ADC_CR2_DMA
  639. ,
  640. ADC_REG_InitStruct->TriggerSource
  641. | ADC_REG_InitStruct->ContinuousMode
  642. | ADC_REG_InitStruct->DMATransfer
  643. );
  644. /* Set ADC group regular sequencer length and scan direction */
  645. /* Note: Hardware constraint (refer to description of this function): */
  646. /* Note: If ADC instance feature scan mode is disabled */
  647. /* (refer to ADC instance initialization structure */
  648. /* parameter @ref SequencersScanMode */
  649. /* or function @ref LL_ADC_SetSequencersScanMode() ), */
  650. /* this parameter is discarded. */
  651. LL_ADC_REG_SetSequencerLength(ADCx, ADC_REG_InitStruct->SequencerLength);
  652. }
  653. else
  654. {
  655. /* Initialization error: ADC instance is not disabled. */
  656. status = ERROR;
  657. }
  658. return status;
  659. }
  660. /**
  661. * @brief Set each @ref LL_ADC_REG_InitTypeDef field to default value.
  662. * @param ADC_REG_InitStruct Pointer to a @ref LL_ADC_REG_InitTypeDef structure
  663. * whose fields will be set to default values.
  664. * @retval None
  665. */
  666. void LL_ADC_REG_StructInit(LL_ADC_REG_InitTypeDef *ADC_REG_InitStruct)
  667. {
  668. /* Set ADC_REG_InitStruct fields to default values */
  669. /* Set fields of ADC group regular */
  670. /* Note: On this STM32 serie, ADC trigger edge is set when starting */
  671. /* ADC conversion. */
  672. /* Refer to function @ref LL_ADC_REG_StartConversionExtTrig(). */
  673. ADC_REG_InitStruct->TriggerSource = LL_ADC_REG_TRIG_SOFTWARE;
  674. ADC_REG_InitStruct->SequencerLength = LL_ADC_REG_SEQ_SCAN_DISABLE;
  675. ADC_REG_InitStruct->SequencerDiscont = LL_ADC_REG_SEQ_DISCONT_DISABLE;
  676. ADC_REG_InitStruct->ContinuousMode = LL_ADC_REG_CONV_SINGLE;
  677. ADC_REG_InitStruct->DMATransfer = LL_ADC_REG_DMA_TRANSFER_NONE;
  678. }
  679. /**
  680. * @brief Initialize some features of ADC group injected.
  681. * @note These parameters have an impact on ADC scope: ADC group injected.
  682. * Refer to corresponding unitary functions into
  683. * @ref ADC_LL_EF_Configuration_ADC_Group_Regular
  684. * (functions with prefix "INJ").
  685. * @note The setting of these parameters by function @ref LL_ADC_Init()
  686. * is conditioned to ADC state:
  687. * ADC instance must be disabled.
  688. * This condition is applied to all ADC features, for efficiency
  689. * and compatibility over all STM32 families. However, the different
  690. * features can be set under different ADC state conditions
  691. * (setting possible with ADC enabled without conversion on going,
  692. * ADC enabled with conversion on going, ...)
  693. * Each feature can be updated afterwards with a unitary function
  694. * and potentially with ADC in a different state than disabled,
  695. * refer to description of each function for setting
  696. * conditioned to ADC state.
  697. * @note After using this function, other features must be configured
  698. * using LL unitary functions.
  699. * The minimum configuration remaining to be done is:
  700. * - Set ADC group injected sequencer:
  701. * map channel on the selected sequencer rank.
  702. * Refer to function @ref LL_ADC_INJ_SetSequencerRanks().
  703. * - Set ADC channel sampling time
  704. * Refer to function LL_ADC_SetChannelSamplingTime();
  705. * @param ADCx ADC instance
  706. * @param ADC_INJ_InitStruct Pointer to a @ref LL_ADC_INJ_InitTypeDef structure
  707. * @retval An ErrorStatus enumeration value:
  708. * - SUCCESS: ADC registers are initialized
  709. * - ERROR: ADC registers are not initialized
  710. */
  711. ErrorStatus LL_ADC_INJ_Init(ADC_TypeDef *ADCx, LL_ADC_INJ_InitTypeDef *ADC_INJ_InitStruct)
  712. {
  713. ErrorStatus status = SUCCESS;
  714. /* Check the parameters */
  715. assert_param(IS_ADC_ALL_INSTANCE(ADCx));
  716. #if defined(ADC3)
  717. assert_param(IS_LL_ADC_INJ_TRIG_SOURCE(ADCx, ADC_INJ_InitStruct->TriggerSource));
  718. #else
  719. assert_param(IS_LL_ADC_INJ_TRIG_SOURCE(ADC_INJ_InitStruct->TriggerSource));
  720. #endif
  721. assert_param(IS_LL_ADC_INJ_SEQ_SCAN_LENGTH(ADC_INJ_InitStruct->SequencerLength));
  722. if(ADC_INJ_InitStruct->SequencerLength != LL_ADC_INJ_SEQ_SCAN_DISABLE)
  723. {
  724. assert_param(IS_LL_ADC_INJ_SEQ_SCAN_DISCONT_MODE(ADC_INJ_InitStruct->SequencerDiscont));
  725. }
  726. assert_param(IS_LL_ADC_INJ_TRIG_AUTO(ADC_INJ_InitStruct->TrigAuto));
  727. /* Note: Hardware constraint (refer to description of this function): */
  728. /* ADC instance must be disabled. */
  729. if(LL_ADC_IsEnabled(ADCx) == 0U)
  730. {
  731. /* Configuration of ADC hierarchical scope: */
  732. /* - ADC group injected */
  733. /* - Set ADC group injected trigger source */
  734. /* - Set ADC group injected sequencer length */
  735. /* - Set ADC group injected sequencer discontinuous mode */
  736. /* - Set ADC group injected conversion trigger: independent or */
  737. /* from ADC group regular */
  738. /* Note: On this STM32 serie, ADC trigger edge is set when starting */
  739. /* ADC conversion. */
  740. /* Refer to function @ref LL_ADC_INJ_StartConversionExtTrig(). */
  741. if(ADC_INJ_InitStruct->SequencerLength != LL_ADC_REG_SEQ_SCAN_DISABLE)
  742. {
  743. MODIFY_REG(ADCx->CR1,
  744. ADC_CR1_JDISCEN
  745. | ADC_CR1_JAUTO
  746. ,
  747. ADC_INJ_InitStruct->SequencerDiscont
  748. | ADC_INJ_InitStruct->TrigAuto
  749. );
  750. }
  751. else
  752. {
  753. MODIFY_REG(ADCx->CR1,
  754. ADC_CR1_JDISCEN
  755. | ADC_CR1_JAUTO
  756. ,
  757. LL_ADC_REG_SEQ_DISCONT_DISABLE
  758. | ADC_INJ_InitStruct->TrigAuto
  759. );
  760. }
  761. MODIFY_REG(ADCx->CR2,
  762. ADC_CR2_JEXTSEL
  763. ,
  764. ADC_INJ_InitStruct->TriggerSource
  765. );
  766. /* Note: Hardware constraint (refer to description of this function): */
  767. /* Note: If ADC instance feature scan mode is disabled */
  768. /* (refer to ADC instance initialization structure */
  769. /* parameter @ref SequencersScanMode */
  770. /* or function @ref LL_ADC_SetSequencersScanMode() ), */
  771. /* this parameter is discarded. */
  772. LL_ADC_INJ_SetSequencerLength(ADCx, ADC_INJ_InitStruct->SequencerLength);
  773. }
  774. else
  775. {
  776. /* Initialization error: ADC instance is not disabled. */
  777. status = ERROR;
  778. }
  779. return status;
  780. }
  781. /**
  782. * @brief Set each @ref LL_ADC_INJ_InitTypeDef field to default value.
  783. * @param ADC_INJ_InitStruct Pointer to a @ref LL_ADC_INJ_InitTypeDef structure
  784. * whose fields will be set to default values.
  785. * @retval None
  786. */
  787. void LL_ADC_INJ_StructInit(LL_ADC_INJ_InitTypeDef *ADC_INJ_InitStruct)
  788. {
  789. /* Set ADC_INJ_InitStruct fields to default values */
  790. /* Set fields of ADC group injected */
  791. ADC_INJ_InitStruct->TriggerSource = LL_ADC_INJ_TRIG_SOFTWARE;
  792. ADC_INJ_InitStruct->SequencerLength = LL_ADC_INJ_SEQ_SCAN_DISABLE;
  793. ADC_INJ_InitStruct->SequencerDiscont = LL_ADC_INJ_SEQ_DISCONT_DISABLE;
  794. ADC_INJ_InitStruct->TrigAuto = LL_ADC_INJ_TRIG_INDEPENDENT;
  795. }
  796. /**
  797. * @}
  798. */
  799. /**
  800. * @}
  801. */
  802. /**
  803. * @}
  804. */
  805. #endif /* ADC1 || ADC2 || ADC3 */
  806. /**
  807. * @}
  808. */
  809. #endif /* USE_FULL_LL_DRIVER */
  810. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/