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.

stm32l1xx_ll_adc.c 39KB

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