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.
 
 
 

935 lines
43 KiB

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