stm32f4xx_ll_adc.c 42 KB

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