stm32f1xx_ll_adc.c 41 KB

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