stm32f4xx_ll_adc.c 44 KB

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