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.
 
 
 

921 lines
42 KiB

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