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.
 
 
 

6121 lines
333 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32wbxx_ll_adc.h
  4. * @author MCD Application Team
  5. * @brief Header file of ADC LL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by ST under BSD 3-Clause license,
  13. * the "License"; You may not use this file except in compliance with the
  14. * License. You may obtain a copy of the License at:
  15. * opensource.org/licenses/BSD-3-Clause
  16. *
  17. ******************************************************************************
  18. */
  19. /* Define to prevent recursive inclusion -------------------------------------*/
  20. #ifndef STM32WBxx_LL_ADC_H
  21. #define STM32WBxx_LL_ADC_H
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. /* Includes ------------------------------------------------------------------*/
  26. #include "stm32wbxx.h"
  27. /** @addtogroup STM32WBxx_LL_Driver
  28. * @{
  29. */
  30. #if defined (ADC1)
  31. /** @defgroup ADC_LL ADC
  32. * @{
  33. */
  34. /* Private types -------------------------------------------------------------*/
  35. /* Private variables ---------------------------------------------------------*/
  36. /* Private constants ---------------------------------------------------------*/
  37. /** @defgroup ADC_LL_Private_Constants ADC Private Constants
  38. * @{
  39. */
  40. /* Internal mask for ADC group regular sequencer: */
  41. /* To select into literal LL_ADC_REG_RANK_x the relevant bits for: */
  42. /* - sequencer register offset */
  43. /* - sequencer rank bits position into the selected register */
  44. /* Internal register offset for ADC group regular sequencer configuration */
  45. /* (offset placed into a spare area of literal definition) */
  46. #define ADC_SQR1_REGOFFSET (0x00000000UL)
  47. #define ADC_SQR2_REGOFFSET (0x00000100UL)
  48. #define ADC_SQR3_REGOFFSET (0x00000200UL)
  49. #define ADC_SQR4_REGOFFSET (0x00000300UL)
  50. #define ADC_REG_SQRX_REGOFFSET_MASK (ADC_SQR1_REGOFFSET | ADC_SQR2_REGOFFSET | ADC_SQR3_REGOFFSET | ADC_SQR4_REGOFFSET)
  51. #define ADC_SQRX_REGOFFSET_POS (8UL) /* Position of bits ADC_SQRx_REGOFFSET in ADC_REG_SQRX_REGOFFSET_MASK */
  52. #define ADC_REG_RANK_ID_SQRX_MASK (ADC_CHANNEL_ID_NUMBER_MASK_POSBIT0)
  53. /* Definition of ADC group regular sequencer bits information to be inserted */
  54. /* into ADC group regular sequencer ranks literals definition. */
  55. #define ADC_REG_RANK_1_SQRX_BITOFFSET_POS ( 6UL) /* Value equivalent to bitfield "ADC_SQR1_SQ1" position in register */
  56. #define ADC_REG_RANK_2_SQRX_BITOFFSET_POS (12UL) /* Value equivalent to bitfield "ADC_SQR1_SQ2" position in register */
  57. #define ADC_REG_RANK_3_SQRX_BITOFFSET_POS (18UL) /* Value equivalent to bitfield "ADC_SQR1_SQ3" position in register */
  58. #define ADC_REG_RANK_4_SQRX_BITOFFSET_POS (24UL) /* Value equivalent to bitfield "ADC_SQR1_SQ4" position in register */
  59. #define ADC_REG_RANK_5_SQRX_BITOFFSET_POS ( 0UL) /* Value equivalent to bitfield "ADC_SQR2_SQ5" position in register */
  60. #define ADC_REG_RANK_6_SQRX_BITOFFSET_POS ( 6UL) /* Value equivalent to bitfield "ADC_SQR2_SQ6" position in register */
  61. #define ADC_REG_RANK_7_SQRX_BITOFFSET_POS (12UL) /* Value equivalent to bitfield "ADC_SQR2_SQ7" position in register */
  62. #define ADC_REG_RANK_8_SQRX_BITOFFSET_POS (18UL) /* Value equivalent to bitfield "ADC_SQR2_SQ8" position in register */
  63. #define ADC_REG_RANK_9_SQRX_BITOFFSET_POS (24UL) /* Value equivalent to bitfield "ADC_SQR2_SQ9" position in register */
  64. #define ADC_REG_RANK_10_SQRX_BITOFFSET_POS ( 0UL) /* Value equivalent to bitfield "ADC_SQR3_SQ10" position in register */
  65. #define ADC_REG_RANK_11_SQRX_BITOFFSET_POS ( 6UL) /* Value equivalent to bitfield "ADC_SQR3_SQ11" position in register */
  66. #define ADC_REG_RANK_12_SQRX_BITOFFSET_POS (12UL) /* Value equivalent to bitfield "ADC_SQR3_SQ12" position in register */
  67. #define ADC_REG_RANK_13_SQRX_BITOFFSET_POS (18UL) /* Value equivalent to bitfield "ADC_SQR3_SQ13" position in register */
  68. #define ADC_REG_RANK_14_SQRX_BITOFFSET_POS (24UL) /* Value equivalent to bitfield "ADC_SQR3_SQ14" position in register */
  69. #define ADC_REG_RANK_15_SQRX_BITOFFSET_POS ( 0UL) /* Value equivalent to bitfield "ADC_SQR4_SQ15" position in register */
  70. #define ADC_REG_RANK_16_SQRX_BITOFFSET_POS ( 6UL) /* Value equivalent to bitfield "ADC_SQR4_SQ16" position in register */
  71. /* Internal mask for ADC group injected sequencer: */
  72. /* To select into literal LL_ADC_INJ_RANK_x the relevant bits for: */
  73. /* - data register offset */
  74. /* - sequencer rank bits position into the selected register */
  75. /* Internal register offset for ADC group injected data register */
  76. /* (offset placed into a spare area of literal definition) */
  77. #define ADC_JDR1_REGOFFSET (0x00000000UL)
  78. #define ADC_JDR2_REGOFFSET (0x00000100UL)
  79. #define ADC_JDR3_REGOFFSET (0x00000200UL)
  80. #define ADC_JDR4_REGOFFSET (0x00000300UL)
  81. #define ADC_INJ_JDRX_REGOFFSET_MASK (ADC_JDR1_REGOFFSET | ADC_JDR2_REGOFFSET | ADC_JDR3_REGOFFSET | ADC_JDR4_REGOFFSET)
  82. #define ADC_INJ_RANK_ID_JSQR_MASK (ADC_CHANNEL_ID_NUMBER_MASK_POSBIT0)
  83. #define ADC_JDRX_REGOFFSET_POS (8UL) /* Position of bits ADC_JDRx_REGOFFSET in ADC_INJ_JDRX_REGOFFSET_MASK */
  84. /* Definition of ADC group injected sequencer bits information to be inserted */
  85. /* into ADC group injected sequencer ranks literals definition. */
  86. #define ADC_INJ_RANK_1_JSQR_BITOFFSET_POS ( 8UL) /* Value equivalent to bitfield "ADC_JSQR_JSQ1" position in register */
  87. #define ADC_INJ_RANK_2_JSQR_BITOFFSET_POS (14UL) /* Value equivalent to bitfield "ADC_JSQR_JSQ2" position in register */
  88. #define ADC_INJ_RANK_3_JSQR_BITOFFSET_POS (20UL) /* Value equivalent to bitfield "ADC_JSQR_JSQ3" position in register */
  89. #define ADC_INJ_RANK_4_JSQR_BITOFFSET_POS (26UL) /* Value equivalent to bitfield "ADC_JSQR_JSQ4" position in register */
  90. /* Internal mask for ADC group regular trigger: */
  91. /* To select into literal LL_ADC_REG_TRIG_x the relevant bits for: */
  92. /* - regular trigger source */
  93. /* - regular trigger edge */
  94. #define ADC_REG_TRIG_EXT_EDGE_DEFAULT (ADC_CFGR_EXTEN_0) /* Trigger edge set to rising edge (default setting for compatibility with some ADC on other STM32 families having this setting set by HW default value) */
  95. /* Mask containing trigger source masks for each of possible */
  96. /* trigger edge selection duplicated with shifts [0; 4; 8; 12] */
  97. /* corresponding to {SW start; ext trigger; ext trigger; ext trigger}. */
  98. #define ADC_REG_TRIG_SOURCE_MASK (((LL_ADC_REG_TRIG_SOFTWARE & ADC_CFGR_EXTSEL) << (4U * 0UL)) | \
  99. ((ADC_CFGR_EXTSEL) << (4U * 1UL)) | \
  100. ((ADC_CFGR_EXTSEL) << (4U * 2UL)) | \
  101. ((ADC_CFGR_EXTSEL) << (4U * 3UL)) )
  102. /* Mask containing trigger edge masks for each of possible */
  103. /* trigger edge selection duplicated with shifts [0; 4; 8; 12] */
  104. /* corresponding to {SW start; ext trigger; ext trigger; ext trigger}. */
  105. #define ADC_REG_TRIG_EDGE_MASK (((LL_ADC_REG_TRIG_SOFTWARE & ADC_CFGR_EXTEN) << (4U * 0UL)) | \
  106. ((ADC_REG_TRIG_EXT_EDGE_DEFAULT) << (4U * 1UL)) | \
  107. ((ADC_REG_TRIG_EXT_EDGE_DEFAULT) << (4U * 2UL)) | \
  108. ((ADC_REG_TRIG_EXT_EDGE_DEFAULT) << (4U * 3UL)) )
  109. /* Definition of ADC group regular trigger bits information. */
  110. #define ADC_REG_TRIG_EXTSEL_BITOFFSET_POS ( 6UL) /* Value equivalent to bitfield "ADC_CFGR_EXTSEL" position in register */
  111. #define ADC_REG_TRIG_EXTEN_BITOFFSET_POS (10UL) /* Value equivalent to bitfield "ADC_CFGR_EXTEN" position in register */
  112. /* Internal mask for ADC group injected trigger: */
  113. /* To select into literal LL_ADC_INJ_TRIG_x the relevant bits for: */
  114. /* - injected trigger source */
  115. /* - injected trigger edge */
  116. #define ADC_INJ_TRIG_EXT_EDGE_DEFAULT (ADC_JSQR_JEXTEN_0) /* Trigger edge set to rising edge (default setting for compatibility with some ADC on other STM32 families having this setting set by HW default value) */
  117. /* Mask containing trigger source masks for each of possible */
  118. /* trigger edge selection duplicated with shifts [0; 4; 8; 12] */
  119. /* corresponding to {SW start; ext trigger; ext trigger; ext trigger}. */
  120. #define ADC_INJ_TRIG_SOURCE_MASK (((LL_ADC_INJ_TRIG_SOFTWARE & ADC_JSQR_JEXTSEL) << (4U * 0UL)) | \
  121. ((ADC_JSQR_JEXTSEL) << (4U * 1UL)) | \
  122. ((ADC_JSQR_JEXTSEL) << (4U * 2UL)) | \
  123. ((ADC_JSQR_JEXTSEL) << (4U * 3UL)) )
  124. /* Mask containing trigger edge masks for each of possible */
  125. /* trigger edge selection duplicated with shifts [0; 4; 8; 12] */
  126. /* corresponding to {SW start; ext trigger; ext trigger; ext trigger}. */
  127. #define ADC_INJ_TRIG_EDGE_MASK (((LL_ADC_INJ_TRIG_SOFTWARE & ADC_JSQR_JEXTEN) << (4U * 0UL)) | \
  128. ((ADC_INJ_TRIG_EXT_EDGE_DEFAULT) << (4U * 1UL)) | \
  129. ((ADC_INJ_TRIG_EXT_EDGE_DEFAULT) << (4U * 2UL)) | \
  130. ((ADC_INJ_TRIG_EXT_EDGE_DEFAULT) << (4U * 3UL)) )
  131. /* Definition of ADC group injected trigger bits information. */
  132. #define ADC_INJ_TRIG_EXTSEL_BITOFFSET_POS ( 2UL) /* Value equivalent to bitfield "ADC_JSQR_JEXTSEL" position in register */
  133. #define ADC_INJ_TRIG_EXTEN_BITOFFSET_POS ( 6UL) /* Value equivalent to bitfield "ADC_JSQR_JEXTEN" position in register */
  134. /* Internal mask for ADC channel: */
  135. /* To select into literal LL_ADC_CHANNEL_x the relevant bits for: */
  136. /* - channel identifier defined by number */
  137. /* - channel identifier defined by bitfield */
  138. /* - channel differentiation between external channels (connected to */
  139. /* GPIO pins) and internal channels (connected to internal paths) */
  140. /* - channel sampling time defined by SMPRx register offset */
  141. /* and SMPx bits positions into SMPRx register */
  142. #define ADC_CHANNEL_ID_NUMBER_MASK (ADC_CFGR_AWD1CH)
  143. #define ADC_CHANNEL_ID_BITFIELD_MASK (ADC_AWD2CR_AWD2CH)
  144. #define ADC_CHANNEL_ID_NUMBER_BITOFFSET_POS (26UL)/* Value equivalent to bitfield "ADC_CHANNEL_ID_NUMBER_MASK" position in register */
  145. #define ADC_CHANNEL_ID_MASK (ADC_CHANNEL_ID_NUMBER_MASK | ADC_CHANNEL_ID_BITFIELD_MASK | ADC_CHANNEL_ID_INTERNAL_CH_MASK)
  146. /* Equivalent mask of ADC_CHANNEL_NUMBER_MASK aligned on register LSB (bit 0) */
  147. #define ADC_CHANNEL_ID_NUMBER_MASK_POSBIT0 (ADC_SQR2_SQ5) /* Equivalent to shift: (ADC_CHANNEL_NUMBER_MASK >> [Position of bitfield "ADC_CHANNEL_NUMBER_MASK" in register]) */
  148. /* Channel differentiation between external and internal channels */
  149. #define ADC_CHANNEL_ID_INTERNAL_CH (0x80000000UL) /* Marker of internal channel */
  150. #define ADC_CHANNEL_ID_INTERNAL_CH_2 (0x00080000UL) /* Marker of internal channel for other ADC instances, in case of different ADC internal channels mapped on same channel number on different ADC instances */
  151. #define ADC_CHANNEL_ID_INTERNAL_CH_MASK (ADC_CHANNEL_ID_INTERNAL_CH | ADC_CHANNEL_ID_INTERNAL_CH_2)
  152. /* Internal register offset for ADC channel sampling time configuration */
  153. /* (offset placed into a spare area of literal definition) */
  154. #define ADC_SMPR1_REGOFFSET (0x00000000UL)
  155. #define ADC_SMPR2_REGOFFSET (0x02000000UL)
  156. #define ADC_CHANNEL_SMPRX_REGOFFSET_MASK (ADC_SMPR1_REGOFFSET | ADC_SMPR2_REGOFFSET)
  157. #define ADC_SMPRX_REGOFFSET_POS (25UL) /* Position of bits ADC_SMPRx_REGOFFSET in ADC_CHANNEL_SMPRX_REGOFFSET_MASK */
  158. #define ADC_CHANNEL_SMPx_BITOFFSET_MASK (0x01F00000UL)
  159. #define ADC_CHANNEL_SMPx_BITOFFSET_POS (20UL) /* Value equivalent to bitfield "ADC_CHANNEL_SMPx_BITOFFSET_MASK" position in register */
  160. /* Definition of channels ID number information to be inserted into */
  161. /* channels literals definition. */
  162. #define ADC_CHANNEL_0_NUMBER (0x00000000UL)
  163. #define ADC_CHANNEL_1_NUMBER ( ADC_CFGR_AWD1CH_0)
  164. #define ADC_CHANNEL_2_NUMBER ( ADC_CFGR_AWD1CH_1 )
  165. #define ADC_CHANNEL_3_NUMBER ( ADC_CFGR_AWD1CH_1 | ADC_CFGR_AWD1CH_0)
  166. #define ADC_CHANNEL_4_NUMBER ( ADC_CFGR_AWD1CH_2 )
  167. #define ADC_CHANNEL_5_NUMBER ( ADC_CFGR_AWD1CH_2 | ADC_CFGR_AWD1CH_0)
  168. #define ADC_CHANNEL_6_NUMBER ( ADC_CFGR_AWD1CH_2 | ADC_CFGR_AWD1CH_1 )
  169. #define ADC_CHANNEL_7_NUMBER ( ADC_CFGR_AWD1CH_2 | ADC_CFGR_AWD1CH_1 | ADC_CFGR_AWD1CH_0)
  170. #define ADC_CHANNEL_8_NUMBER ( ADC_CFGR_AWD1CH_3 )
  171. #define ADC_CHANNEL_9_NUMBER ( ADC_CFGR_AWD1CH_3 | ADC_CFGR_AWD1CH_0)
  172. #define ADC_CHANNEL_10_NUMBER ( ADC_CFGR_AWD1CH_3 | ADC_CFGR_AWD1CH_1 )
  173. #define ADC_CHANNEL_11_NUMBER ( ADC_CFGR_AWD1CH_3 | ADC_CFGR_AWD1CH_1 | ADC_CFGR_AWD1CH_0)
  174. #define ADC_CHANNEL_12_NUMBER ( ADC_CFGR_AWD1CH_3 | ADC_CFGR_AWD1CH_2 )
  175. #define ADC_CHANNEL_13_NUMBER ( ADC_CFGR_AWD1CH_3 | ADC_CFGR_AWD1CH_2 | ADC_CFGR_AWD1CH_0)
  176. #define ADC_CHANNEL_14_NUMBER ( ADC_CFGR_AWD1CH_3 | ADC_CFGR_AWD1CH_2 | ADC_CFGR_AWD1CH_1 )
  177. #define ADC_CHANNEL_15_NUMBER ( ADC_CFGR_AWD1CH_3 | ADC_CFGR_AWD1CH_2 | ADC_CFGR_AWD1CH_1 | ADC_CFGR_AWD1CH_0)
  178. #define ADC_CHANNEL_16_NUMBER (ADC_CFGR_AWD1CH_4 )
  179. #define ADC_CHANNEL_17_NUMBER (ADC_CFGR_AWD1CH_4 | ADC_CFGR_AWD1CH_0)
  180. #define ADC_CHANNEL_18_NUMBER (ADC_CFGR_AWD1CH_4 | ADC_CFGR_AWD1CH_1 )
  181. /* Definition of channels ID bitfield information to be inserted into */
  182. /* channels literals definition. */
  183. #define ADC_CHANNEL_0_BITFIELD (ADC_AWD2CR_AWD2CH_0)
  184. #define ADC_CHANNEL_1_BITFIELD (ADC_AWD2CR_AWD2CH_1)
  185. #define ADC_CHANNEL_2_BITFIELD (ADC_AWD2CR_AWD2CH_2)
  186. #define ADC_CHANNEL_3_BITFIELD (ADC_AWD2CR_AWD2CH_3)
  187. #define ADC_CHANNEL_4_BITFIELD (ADC_AWD2CR_AWD2CH_4)
  188. #define ADC_CHANNEL_5_BITFIELD (ADC_AWD2CR_AWD2CH_5)
  189. #define ADC_CHANNEL_6_BITFIELD (ADC_AWD2CR_AWD2CH_6)
  190. #define ADC_CHANNEL_7_BITFIELD (ADC_AWD2CR_AWD2CH_7)
  191. #define ADC_CHANNEL_8_BITFIELD (ADC_AWD2CR_AWD2CH_8)
  192. #define ADC_CHANNEL_9_BITFIELD (ADC_AWD2CR_AWD2CH_9)
  193. #define ADC_CHANNEL_10_BITFIELD (ADC_AWD2CR_AWD2CH_10)
  194. #define ADC_CHANNEL_11_BITFIELD (ADC_AWD2CR_AWD2CH_11)
  195. #define ADC_CHANNEL_12_BITFIELD (ADC_AWD2CR_AWD2CH_12)
  196. #define ADC_CHANNEL_13_BITFIELD (ADC_AWD2CR_AWD2CH_13)
  197. #define ADC_CHANNEL_14_BITFIELD (ADC_AWD2CR_AWD2CH_14)
  198. #define ADC_CHANNEL_15_BITFIELD (ADC_AWD2CR_AWD2CH_15)
  199. #define ADC_CHANNEL_16_BITFIELD (ADC_AWD2CR_AWD2CH_16)
  200. #define ADC_CHANNEL_17_BITFIELD (ADC_AWD2CR_AWD2CH_17)
  201. #define ADC_CHANNEL_18_BITFIELD (ADC_AWD2CR_AWD2CH_18)
  202. /* Definition of channels sampling time information to be inserted into */
  203. /* channels literals definition. */
  204. #define ADC_CHANNEL_0_SMP (ADC_SMPR1_REGOFFSET | (( 0UL) << ADC_CHANNEL_SMPx_BITOFFSET_POS)) /* Value shifted is equivalent to bitfield "ADC_SMPR1_SMP0" position in register */
  205. #define ADC_CHANNEL_1_SMP (ADC_SMPR1_REGOFFSET | (( 3UL) << ADC_CHANNEL_SMPx_BITOFFSET_POS)) /* Value shifted is equivalent to bitfield "ADC_SMPR1_SMP1" position in register */
  206. #define ADC_CHANNEL_2_SMP (ADC_SMPR1_REGOFFSET | (( 6UL) << ADC_CHANNEL_SMPx_BITOFFSET_POS)) /* Value shifted is equivalent to bitfield "ADC_SMPR1_SMP2" position in register */
  207. #define ADC_CHANNEL_3_SMP (ADC_SMPR1_REGOFFSET | (( 9UL) << ADC_CHANNEL_SMPx_BITOFFSET_POS)) /* Value shifted is equivalent to bitfield "ADC_SMPR1_SMP3" position in register */
  208. #define ADC_CHANNEL_4_SMP (ADC_SMPR1_REGOFFSET | ((12UL) << ADC_CHANNEL_SMPx_BITOFFSET_POS)) /* Value shifted is equivalent to bitfield "ADC_SMPR1_SMP4" position in register */
  209. #define ADC_CHANNEL_5_SMP (ADC_SMPR1_REGOFFSET | ((15UL) << ADC_CHANNEL_SMPx_BITOFFSET_POS)) /* Value shifted is equivalent to bitfield "ADC_SMPR1_SMP5" position in register */
  210. #define ADC_CHANNEL_6_SMP (ADC_SMPR1_REGOFFSET | ((18UL) << ADC_CHANNEL_SMPx_BITOFFSET_POS)) /* Value shifted is equivalent to bitfield "ADC_SMPR1_SMP6" position in register */
  211. #define ADC_CHANNEL_7_SMP (ADC_SMPR1_REGOFFSET | ((21UL) << ADC_CHANNEL_SMPx_BITOFFSET_POS)) /* Value shifted is equivalent to bitfield "ADC_SMPR1_SMP7" position in register */
  212. #define ADC_CHANNEL_8_SMP (ADC_SMPR1_REGOFFSET | ((24UL) << ADC_CHANNEL_SMPx_BITOFFSET_POS)) /* Value shifted is equivalent to bitfield "ADC_SMPR1_SMP8" position in register */
  213. #define ADC_CHANNEL_9_SMP (ADC_SMPR1_REGOFFSET | ((27UL) << ADC_CHANNEL_SMPx_BITOFFSET_POS)) /* Value shifted is equivalent to bitfield "ADC_SMPR1_SMP9" position in register */
  214. #define ADC_CHANNEL_10_SMP (ADC_SMPR2_REGOFFSET | (( 0UL) << ADC_CHANNEL_SMPx_BITOFFSET_POS)) /* Value shifted is equivalent to bitfield "ADC_SMPR2_SMP10" position in register */
  215. #define ADC_CHANNEL_11_SMP (ADC_SMPR2_REGOFFSET | (( 3UL) << ADC_CHANNEL_SMPx_BITOFFSET_POS)) /* Value shifted is equivalent to bitfield "ADC_SMPR2_SMP11" position in register */
  216. #define ADC_CHANNEL_12_SMP (ADC_SMPR2_REGOFFSET | (( 6UL) << ADC_CHANNEL_SMPx_BITOFFSET_POS)) /* Value shifted is equivalent to bitfield "ADC_SMPR2_SMP12" position in register */
  217. #define ADC_CHANNEL_13_SMP (ADC_SMPR2_REGOFFSET | (( 9UL) << ADC_CHANNEL_SMPx_BITOFFSET_POS)) /* Value shifted is equivalent to bitfield "ADC_SMPR2_SMP13" position in register */
  218. #define ADC_CHANNEL_14_SMP (ADC_SMPR2_REGOFFSET | ((12UL) << ADC_CHANNEL_SMPx_BITOFFSET_POS)) /* Value shifted is equivalent to bitfield "ADC_SMPR2_SMP14" position in register */
  219. #define ADC_CHANNEL_15_SMP (ADC_SMPR2_REGOFFSET | ((15UL) << ADC_CHANNEL_SMPx_BITOFFSET_POS)) /* Value shifted is equivalent to bitfield "ADC_SMPR2_SMP15" position in register */
  220. #define ADC_CHANNEL_16_SMP (ADC_SMPR2_REGOFFSET | ((18UL) << ADC_CHANNEL_SMPx_BITOFFSET_POS)) /* Value shifted is equivalent to bitfield "ADC_SMPR2_SMP16" position in register */
  221. #define ADC_CHANNEL_17_SMP (ADC_SMPR2_REGOFFSET | ((21UL) << ADC_CHANNEL_SMPx_BITOFFSET_POS)) /* Value shifted is equivalent to bitfield "ADC_SMPR2_SMP17" position in register */
  222. #define ADC_CHANNEL_18_SMP (ADC_SMPR2_REGOFFSET | ((24UL) << ADC_CHANNEL_SMPx_BITOFFSET_POS)) /* Value shifted is equivalent to bitfield "ADC_SMPR2_SMP18" position in register */
  223. /* Internal mask for ADC mode single or differential ended: */
  224. /* To select into literals LL_ADC_SINGLE_ENDED or LL_ADC_SINGLE_DIFFERENTIAL */
  225. /* the relevant bits for: */
  226. /* (concatenation of multiple bits used in different registers) */
  227. /* - ADC calibration: calibration start, calibration factor get or set */
  228. /* - ADC channels: set each ADC channel ending mode */
  229. #define ADC_SINGLEDIFF_CALIB_START_MASK (ADC_CR_ADCALDIF)
  230. #define ADC_SINGLEDIFF_CALIB_FACTOR_MASK (ADC_CALFACT_CALFACT_D | ADC_CALFACT_CALFACT_S)
  231. #define ADC_SINGLEDIFF_CHANNEL_MASK (ADC_CHANNEL_ID_BITFIELD_MASK) /* Equivalent to ADC_DIFSEL_DIFSEL */
  232. #define ADC_SINGLEDIFF_CHANNEL_SHIFT_MASK (ADC_CALFACT_CALFACT_S_4 | ADC_CALFACT_CALFACT_S_3) /* Bits chosen to perform of shift when single mode is selected, shift value out of channels bits range. */
  233. #define ADC_SINGLEDIFF_CALIB_F_BIT_D_MASK (0x00010000UL) /* Selection of 1 bit to discriminate differential mode: mask of bit */
  234. #define ADC_SINGLEDIFF_CALIB_F_BIT_D_POS (16UL) /* Selection of 1 bit to discriminate differential mode: position of bit */
  235. #define ADC_SINGLEDIFF_CALIB_F_BIT_D_SHIFT4 (ADC_SINGLEDIFF_CALIB_F_BIT_D_POS - 4UL) /* Shift of bit ADC_SINGLEDIFF_CALIB_F_BIT_D to position to perform a shift of 4 ranks */
  236. /* Internal mask for ADC analog watchdog: */
  237. /* To select into literals LL_ADC_AWD_CHANNELx_xxx the relevant bits for: */
  238. /* (concatenation of multiple bits used in different analog watchdogs, */
  239. /* (feature of several watchdogs not available on all STM32 families)). */
  240. /* - analog watchdog 1: monitored channel defined by number, */
  241. /* selection of ADC group (ADC groups regular and-or injected). */
  242. /* - analog watchdog 2 and 3: monitored channel defined by bitfield, no */
  243. /* selection on groups. */
  244. /* Internal register offset for ADC analog watchdog channel configuration */
  245. #define ADC_AWD_CR1_REGOFFSET (0x00000000UL)
  246. #define ADC_AWD_CR2_REGOFFSET (0x00100000UL)
  247. #define ADC_AWD_CR3_REGOFFSET (0x00200000UL)
  248. /* Register offset gap between AWD1 and AWD2-AWD3 configuration registers */
  249. /* (Set separately as ADC_AWD_CRX_REGOFFSET to spare 32 bits space */
  250. #define ADC_AWD_CR12_REGOFFSETGAP_MASK (ADC_AWD2CR_AWD2CH_0)
  251. #define ADC_AWD_CR12_REGOFFSETGAP_VAL (0x00000024UL)
  252. #define ADC_AWD_CRX_REGOFFSET_MASK (ADC_AWD_CR1_REGOFFSET | ADC_AWD_CR2_REGOFFSET | ADC_AWD_CR3_REGOFFSET)
  253. #define ADC_AWD_CR1_CHANNEL_MASK (ADC_CFGR_AWD1CH | ADC_CFGR_JAWD1EN | ADC_CFGR_AWD1EN | ADC_CFGR_AWD1SGL)
  254. #define ADC_AWD_CR23_CHANNEL_MASK (ADC_AWD2CR_AWD2CH)
  255. #define ADC_AWD_CR_ALL_CHANNEL_MASK (ADC_AWD_CR1_CHANNEL_MASK | ADC_AWD_CR23_CHANNEL_MASK)
  256. #define ADC_AWD_CRX_REGOFFSET_POS (20UL) /* Position of bits ADC_AWD_CRx_REGOFFSET in ADC_AWD_CRX_REGOFFSET_MASK */
  257. /* Internal register offset for ADC analog watchdog threshold configuration */
  258. #define ADC_AWD_TR1_REGOFFSET (ADC_AWD_CR1_REGOFFSET)
  259. #define ADC_AWD_TR2_REGOFFSET (ADC_AWD_CR2_REGOFFSET)
  260. #define ADC_AWD_TR3_REGOFFSET (ADC_AWD_CR3_REGOFFSET)
  261. #define ADC_AWD_TRX_REGOFFSET_MASK (ADC_AWD_TR1_REGOFFSET | ADC_AWD_TR2_REGOFFSET | ADC_AWD_TR3_REGOFFSET)
  262. #define ADC_AWD_TRX_REGOFFSET_POS (ADC_AWD_CRX_REGOFFSET_POS) /* Position of bits ADC_SQRx_REGOFFSET in ADC_AWD_TRX_REGOFFSET_MASK */
  263. #define ADC_AWD_TRX_BIT_HIGH_MASK (0x00010000UL) /* Selection of 1 bit to discriminate threshold high: mask of bit */
  264. #define ADC_AWD_TRX_BIT_HIGH_POS (16UL) /* Selection of 1 bit to discriminate threshold high: position of bit */
  265. #define ADC_AWD_TRX_BIT_HIGH_SHIFT4 (ADC_AWD_TRX_BIT_HIGH_POS - 4UL) /* Shift of bit ADC_AWD_TRX_BIT_HIGH to position to perform a shift of 4 ranks */
  266. /* Internal mask for ADC offset: */
  267. /* Internal register offset for ADC offset number configuration */
  268. #define ADC_OFR1_REGOFFSET (0x00000000UL)
  269. #define ADC_OFR2_REGOFFSET (0x00000001UL)
  270. #define ADC_OFR3_REGOFFSET (0x00000002UL)
  271. #define ADC_OFR4_REGOFFSET (0x00000003UL)
  272. #define ADC_OFRx_REGOFFSET_MASK (ADC_OFR1_REGOFFSET | ADC_OFR2_REGOFFSET | ADC_OFR3_REGOFFSET | ADC_OFR4_REGOFFSET)
  273. /* ADC registers bits positions */
  274. #define ADC_CFGR_RES_BITOFFSET_POS ( 3UL) /* Value equivalent to bitfield "ADC_CFGR_RES" position in register */
  275. #define ADC_CFGR_AWD1SGL_BITOFFSET_POS (22UL) /* Value equivalent to bitfield "ADC_CFGR_AWD1SGL" position in register */
  276. #define ADC_CFGR_AWD1EN_BITOFFSET_POS (23UL) /* Value equivalent to bitfield "ADC_CFGR_AWD1EN" position in register */
  277. #define ADC_CFGR_JAWD1EN_BITOFFSET_POS (24UL) /* Value equivalent to bitfield "ADC_CFGR_JAWD1EN" position in register */
  278. #define ADC_TR1_HT1_BITOFFSET_POS (16UL) /* Value equivalent to bitfield "ADC_TR1_HT1" position in register */
  279. /* ADC registers bits groups */
  280. #define ADC_CR_BITS_PROPERTY_RS (ADC_CR_ADCAL | ADC_CR_JADSTP | ADC_CR_ADSTP | ADC_CR_JADSTART | ADC_CR_ADSTART | ADC_CR_ADDIS | ADC_CR_ADEN) /* ADC register CR bits with HW property "rs": Software can read as well as set this bit. Writing '0' has no effect on the bit value. */
  281. /* ADC internal channels related definitions */
  282. /* Internal voltage reference VrefInt */
  283. #define VREFINT_CAL_ADDR ((uint16_t*) (0x1FFF75AAUL)) /* Internal voltage reference, address of parameter VREFINT: VrefInt ADC raw data acquired at temperature 30 DegC (tolerance: +-5 DegC), Vref+ = 3.6 V (tolerance: +-10 mV). */
  284. #define VREFINT_CAL_VREF (3600UL) /* Analog voltage reference (Vref+) value with which temperature sensor has been calibrated in production (tolerance: +-10 mV) (unit: mV). */
  285. /* Temperature sensor */
  286. #define TEMPSENSOR_CAL1_ADDR ((uint16_t*) (0x1FFF75A8UL)) /* Internal temperature sensor, address of parameter TS_CAL1: On STM32WB, temperature sensor ADC raw data acquired at temperature 30 DegC (tolerance: +-5 DegC), Vref+ = 3.0 V (tolerance: +-10 mV). */
  287. #define TEMPSENSOR_CAL2_ADDR ((uint16_t*) (0x1FFF75CAUL)) /* Internal temperature sensor, address of parameter TS_CAL2: On STM32WB, temperature sensor ADC raw data acquired at temperature 130 DegC (tolerance: +-5 DegC), Vref+ = 3.0 V (tolerance: +-10 mV). */
  288. #define TEMPSENSOR_CAL1_TEMP (30L) /* Internal temperature sensor, temperature at which temperature sensor has been calibrated in production for data into TEMPSENSOR_CAL1_ADDR (tolerance: +-5 DegC) (unit: DegC). */
  289. #define TEMPSENSOR_CAL2_TEMP (130L) /* Internal temperature sensor, temperature at which temperature sensor has been calibrated in production for data into TEMPSENSOR_CAL2_ADDR (tolerance: +-5 DegC) (unit: DegC). */
  290. #define TEMPSENSOR_CAL_VREFANALOG (3000UL) /* Analog voltage reference (Vref+) voltage with which temperature sensor has been calibrated in production (+-10 mV) (unit: mV). */
  291. /**
  292. * @}
  293. */
  294. /* Private macros ------------------------------------------------------------*/
  295. /** @defgroup ADC_LL_Private_Macros ADC Private Macros
  296. * @{
  297. */
  298. /**
  299. * @brief Driver macro reserved for internal use: set a pointer to
  300. * a register from a register basis from which an offset
  301. * is applied.
  302. * @param __REG__ Register basis from which the offset is applied.
  303. * @param __REG_OFFFSET__ Offset to be applied (unit: number of registers).
  304. * @retval Pointer to register address
  305. */
  306. #define __ADC_PTR_REG_OFFSET(__REG__, __REG_OFFFSET__) \
  307. ((__IO uint32_t *)((uint32_t) ((uint32_t)(&(__REG__)) + ((__REG_OFFFSET__) << 2UL))))
  308. /**
  309. * @}
  310. */
  311. /* Exported types ------------------------------------------------------------*/
  312. #if defined(USE_FULL_LL_DRIVER)
  313. /** @defgroup ADC_LL_ES_INIT ADC Exported Init structure
  314. * @{
  315. */
  316. /**
  317. * @brief Structure definition of some features of ADC common parameters
  318. * and multimode
  319. * (all ADC instances belonging to the same ADC common instance).
  320. * @note The setting of these parameters by function @ref LL_ADC_CommonInit()
  321. * is conditioned to ADC instances state (all ADC instances
  322. * sharing the same ADC common instance):
  323. * All ADC instances sharing the same ADC common instance must be
  324. * disabled.
  325. */
  326. typedef struct
  327. {
  328. uint32_t CommonClock; /*!< Set parameter common to several ADC: Clock source and prescaler.
  329. This parameter can be a value of @ref ADC_LL_EC_COMMON_CLOCK_SOURCE
  330. @note On this STM32 serie, if ADC group injected is used, some
  331. clock ratio constraints between ADC clock and AHB clock
  332. must be respected. Refer to reference manual.
  333. This feature can be modified afterwards using unitary function @ref LL_ADC_SetCommonClock(). */
  334. } LL_ADC_CommonInitTypeDef;
  335. /**
  336. * @brief Structure definition of some features of ADC instance.
  337. * @note These parameters have an impact on ADC scope: ADC instance.
  338. * Affects both group regular and group injected (availability
  339. * of ADC group injected depends on STM32 families).
  340. * Refer to corresponding unitary functions into
  341. * @ref ADC_LL_EF_Configuration_ADC_Instance .
  342. * @note The setting of these parameters by function @ref LL_ADC_Init()
  343. * is conditioned to ADC state:
  344. * ADC instance must be disabled.
  345. * This condition is applied to all ADC features, for efficiency
  346. * and compatibility over all STM32 families. However, the different
  347. * features can be set under different ADC state conditions
  348. * (setting possible with ADC enabled without conversion on going,
  349. * ADC enabled with conversion on going, ...)
  350. * Each feature can be updated afterwards with a unitary function
  351. * and potentially with ADC in a different state than disabled,
  352. * refer to description of each function for setting
  353. * conditioned to ADC state.
  354. */
  355. typedef struct
  356. {
  357. uint32_t Resolution; /*!< Set ADC resolution.
  358. This parameter can be a value of @ref ADC_LL_EC_RESOLUTION
  359. This feature can be modified afterwards using unitary function @ref LL_ADC_SetResolution(). */
  360. uint32_t DataAlignment; /*!< Set ADC conversion data alignment.
  361. This parameter can be a value of @ref ADC_LL_EC_DATA_ALIGN
  362. This feature can be modified afterwards using unitary function @ref LL_ADC_SetDataAlignment(). */
  363. uint32_t LowPowerMode; /*!< Set ADC low power mode.
  364. This parameter can be a value of @ref ADC_LL_EC_LP_MODE
  365. This feature can be modified afterwards using unitary function @ref LL_ADC_SetLowPowerMode(). */
  366. } LL_ADC_InitTypeDef;
  367. /**
  368. * @brief Structure definition of some features of ADC group regular.
  369. * @note These parameters have an impact on ADC scope: ADC group regular.
  370. * Refer to corresponding unitary functions into
  371. * @ref ADC_LL_EF_Configuration_ADC_Group_Regular
  372. * (functions with prefix "REG").
  373. * @note The setting of these parameters by function @ref LL_ADC_REG_Init()
  374. * is conditioned to ADC state:
  375. * ADC instance must be disabled.
  376. * This condition is applied to all ADC features, for efficiency
  377. * and compatibility over all STM32 families. However, the different
  378. * features can be set under different ADC state conditions
  379. * (setting possible with ADC enabled without conversion on going,
  380. * ADC enabled with conversion on going, ...)
  381. * Each feature can be updated afterwards with a unitary function
  382. * and potentially with ADC in a different state than disabled,
  383. * refer to description of each function for setting
  384. * conditioned to ADC state.
  385. */
  386. typedef struct
  387. {
  388. uint32_t TriggerSource; /*!< Set ADC group regular conversion trigger source: internal (SW start) or from external peripheral (timer event, external interrupt line).
  389. This parameter can be a value of @ref ADC_LL_EC_REG_TRIGGER_SOURCE
  390. @note On this STM32 serie, setting trigger source to external trigger also set trigger polarity to rising edge
  391. (default setting for compatibility with some ADC on other STM32 families having this setting set by HW default value).
  392. In case of need to modify trigger edge, use function @ref LL_ADC_REG_SetTriggerEdge().
  393. This feature can be modified afterwards using unitary function @ref LL_ADC_REG_SetTriggerSource(). */
  394. uint32_t SequencerLength; /*!< Set ADC group regular sequencer length.
  395. This parameter can be a value of @ref ADC_LL_EC_REG_SEQ_SCAN_LENGTH
  396. This feature can be modified afterwards using unitary function @ref LL_ADC_REG_SetSequencerLength(). */
  397. uint32_t SequencerDiscont; /*!< Set ADC group regular sequencer discontinuous mode: sequence subdivided and scan conversions interrupted every selected number of ranks.
  398. This parameter can be a value of @ref ADC_LL_EC_REG_SEQ_DISCONT_MODE
  399. @note This parameter has an effect only if group regular sequencer is enabled
  400. (scan length of 2 ranks or more).
  401. This feature can be modified afterwards using unitary function @ref LL_ADC_REG_SetSequencerDiscont(). */
  402. uint32_t ContinuousMode; /*!< Set ADC continuous conversion mode on ADC group regular, whether ADC conversions are performed in single mode (one conversion per trigger) or in continuous mode (after the first trigger, following conversions launched successively automatically).
  403. This parameter can be a value of @ref ADC_LL_EC_REG_CONTINUOUS_MODE
  404. Note: It is not possible to enable both ADC group regular continuous mode and discontinuous mode.
  405. This feature can be modified afterwards using unitary function @ref LL_ADC_REG_SetContinuousMode(). */
  406. uint32_t DMATransfer; /*!< Set ADC group regular conversion data transfer: no transfer or transfer by DMA, and DMA requests mode.
  407. This parameter can be a value of @ref ADC_LL_EC_REG_DMA_TRANSFER
  408. This feature can be modified afterwards using unitary function @ref LL_ADC_REG_SetDMATransfer(). */
  409. uint32_t Overrun; /*!< Set ADC group regular behavior in case of overrun:
  410. data preserved or overwritten.
  411. This parameter can be a value of @ref ADC_LL_EC_REG_OVR_DATA_BEHAVIOR
  412. This feature can be modified afterwards using unitary function @ref LL_ADC_REG_SetOverrun(). */
  413. } LL_ADC_REG_InitTypeDef;
  414. /**
  415. * @brief Structure definition of some features of ADC group injected.
  416. * @note These parameters have an impact on ADC scope: ADC group injected.
  417. * Refer to corresponding unitary functions into
  418. * @ref ADC_LL_EF_Configuration_ADC_Group_Regular
  419. * (functions with prefix "INJ").
  420. * @note The setting of these parameters by function @ref LL_ADC_INJ_Init()
  421. * is conditioned to ADC state:
  422. * ADC instance must be disabled.
  423. * This condition is applied to all ADC features, for efficiency
  424. * and compatibility over all STM32 families. However, the different
  425. * features can be set under different ADC state conditions
  426. * (setting possible with ADC enabled without conversion on going,
  427. * ADC enabled with conversion on going, ...)
  428. * Each feature can be updated afterwards with a unitary function
  429. * and potentially with ADC in a different state than disabled,
  430. * refer to description of each function for setting
  431. * conditioned to ADC state.
  432. */
  433. typedef struct
  434. {
  435. uint32_t TriggerSource; /*!< Set ADC group injected conversion trigger source: internal (SW start) or from external peripheral (timer event, external interrupt line).
  436. This parameter can be a value of @ref ADC_LL_EC_INJ_TRIGGER_SOURCE
  437. @note On this STM32 serie, setting trigger source to external trigger also set trigger polarity to rising edge
  438. (default setting for compatibility with some ADC on other STM32 families having this setting set by HW default value).
  439. In case of need to modify trigger edge, use function @ref LL_ADC_INJ_SetTriggerEdge().
  440. This feature can be modified afterwards using unitary function @ref LL_ADC_INJ_SetTriggerSource(). */
  441. uint32_t SequencerLength; /*!< Set ADC group injected sequencer length.
  442. This parameter can be a value of @ref ADC_LL_EC_INJ_SEQ_SCAN_LENGTH
  443. This feature can be modified afterwards using unitary function @ref LL_ADC_INJ_SetSequencerLength(). */
  444. uint32_t SequencerDiscont; /*!< Set ADC group injected sequencer discontinuous mode: sequence subdivided and scan conversions interrupted every selected number of ranks.
  445. This parameter can be a value of @ref ADC_LL_EC_INJ_SEQ_DISCONT_MODE
  446. @note This parameter has an effect only if group injected sequencer is enabled
  447. (scan length of 2 ranks or more).
  448. This feature can be modified afterwards using unitary function @ref LL_ADC_INJ_SetSequencerDiscont(). */
  449. uint32_t TrigAuto; /*!< Set ADC group injected conversion trigger: independent or from ADC group regular.
  450. This parameter can be a value of @ref ADC_LL_EC_INJ_TRIG_AUTO
  451. Note: This parameter must be set to set to independent trigger if injected trigger source is set to an external trigger.
  452. This feature can be modified afterwards using unitary function @ref LL_ADC_INJ_SetTrigAuto(). */
  453. } LL_ADC_INJ_InitTypeDef;
  454. /**
  455. * @}
  456. */
  457. #endif /* USE_FULL_LL_DRIVER */
  458. /* Exported constants --------------------------------------------------------*/
  459. /** @defgroup ADC_LL_Exported_Constants ADC Exported Constants
  460. * @{
  461. */
  462. /** @defgroup ADC_LL_EC_FLAG ADC flags
  463. * @brief Flags defines which can be used with LL_ADC_ReadReg function
  464. * @{
  465. */
  466. #define LL_ADC_FLAG_ADRDY ADC_ISR_ADRDY /*!< ADC flag ADC instance ready */
  467. #define LL_ADC_FLAG_EOC ADC_ISR_EOC /*!< ADC flag ADC group regular end of unitary conversion */
  468. #define LL_ADC_FLAG_EOS ADC_ISR_EOS /*!< ADC flag ADC group regular end of sequence conversions */
  469. #define LL_ADC_FLAG_OVR ADC_ISR_OVR /*!< ADC flag ADC group regular overrun */
  470. #define LL_ADC_FLAG_EOSMP ADC_ISR_EOSMP /*!< ADC flag ADC group regular end of sampling phase */
  471. #define LL_ADC_FLAG_JEOC ADC_ISR_JEOC /*!< ADC flag ADC group injected end of unitary conversion */
  472. #define LL_ADC_FLAG_JEOS ADC_ISR_JEOS /*!< ADC flag ADC group injected end of sequence conversions */
  473. #define LL_ADC_FLAG_JQOVF ADC_ISR_JQOVF /*!< ADC flag ADC group injected contexts queue overflow */
  474. #define LL_ADC_FLAG_AWD1 ADC_ISR_AWD1 /*!< ADC flag ADC analog watchdog 1 */
  475. #define LL_ADC_FLAG_AWD2 ADC_ISR_AWD2 /*!< ADC flag ADC analog watchdog 2 */
  476. #define LL_ADC_FLAG_AWD3 ADC_ISR_AWD3 /*!< ADC flag ADC analog watchdog 3 */
  477. /**
  478. * @}
  479. */
  480. /** @defgroup ADC_LL_EC_IT ADC interruptions for configuration (interruption enable or disable)
  481. * @brief IT defines which can be used with LL_ADC_ReadReg and LL_ADC_WriteReg functions
  482. * @{
  483. */
  484. #define LL_ADC_IT_ADRDY ADC_IER_ADRDYIE /*!< ADC interruption ADC instance ready */
  485. #define LL_ADC_IT_EOC ADC_IER_EOCIE /*!< ADC interruption ADC group regular end of unitary conversion */
  486. #define LL_ADC_IT_EOS ADC_IER_EOSIE /*!< ADC interruption ADC group regular end of sequence conversions */
  487. #define LL_ADC_IT_OVR ADC_IER_OVRIE /*!< ADC interruption ADC group regular overrun */
  488. #define LL_ADC_IT_EOSMP ADC_IER_EOSMPIE /*!< ADC interruption ADC group regular end of sampling phase */
  489. #define LL_ADC_IT_JEOC ADC_IER_JEOCIE /*!< ADC interruption ADC group injected end of unitary conversion */
  490. #define LL_ADC_IT_JEOS ADC_IER_JEOSIE /*!< ADC interruption ADC group injected end of sequence conversions */
  491. #define LL_ADC_IT_JQOVF ADC_IER_JQOVFIE /*!< ADC interruption ADC group injected contexts queue overflow */
  492. #define LL_ADC_IT_AWD1 ADC_IER_AWD1IE /*!< ADC interruption ADC analog watchdog 1 */
  493. #define LL_ADC_IT_AWD2 ADC_IER_AWD2IE /*!< ADC interruption ADC analog watchdog 2 */
  494. #define LL_ADC_IT_AWD3 ADC_IER_AWD3IE /*!< ADC interruption ADC analog watchdog 3 */
  495. /**
  496. * @}
  497. */
  498. /** @defgroup ADC_LL_EC_REGISTERS ADC registers compliant with specific purpose
  499. * @{
  500. */
  501. /* List of ADC registers intended to be used (most commonly) with */
  502. /* DMA transfer. */
  503. /* Refer to function @ref LL_ADC_DMA_GetRegAddr(). */
  504. #define LL_ADC_DMA_REG_REGULAR_DATA (0x00000000UL) /* ADC group regular conversion data register (corresponding to register DR) to be used with ADC configured in independent mode. Without DMA transfer, register accessed by LL function @ref LL_ADC_REG_ReadConversionData32() and other functions @ref LL_ADC_REG_ReadConversionDatax() */
  505. /**
  506. * @}
  507. */
  508. /** @defgroup ADC_LL_EC_COMMON_CLOCK_SOURCE ADC common - Clock source
  509. * @{
  510. */
  511. #define LL_ADC_CLOCK_SYNC_PCLK_DIV1 (ADC_CCR_CKMODE_0) /*!< ADC synchronous clock derived from AHB clock without prescaler */
  512. #define LL_ADC_CLOCK_SYNC_PCLK_DIV2 (ADC_CCR_CKMODE_1 ) /*!< ADC synchronous clock derived from AHB clock with prescaler division by 2 */
  513. #define LL_ADC_CLOCK_SYNC_PCLK_DIV4 (ADC_CCR_CKMODE_1 | ADC_CCR_CKMODE_0) /*!< ADC synchronous clock derived from AHB clock with prescaler division by 4 */
  514. #define LL_ADC_CLOCK_ASYNC_DIV1 (0x00000000UL) /*!< ADC asynchronous clock without prescaler */
  515. #define LL_ADC_CLOCK_ASYNC_DIV2 (ADC_CCR_PRESC_0) /*!< ADC asynchronous clock with prescaler division by 2 */
  516. #define LL_ADC_CLOCK_ASYNC_DIV4 (ADC_CCR_PRESC_1 ) /*!< ADC asynchronous clock with prescaler division by 4 */
  517. #define LL_ADC_CLOCK_ASYNC_DIV6 (ADC_CCR_PRESC_1 | ADC_CCR_PRESC_0) /*!< ADC asynchronous clock with prescaler division by 6 */
  518. #define LL_ADC_CLOCK_ASYNC_DIV8 (ADC_CCR_PRESC_2 ) /*!< ADC asynchronous clock with prescaler division by 8 */
  519. #define LL_ADC_CLOCK_ASYNC_DIV10 (ADC_CCR_PRESC_2 | ADC_CCR_PRESC_0) /*!< ADC asynchronous clock with prescaler division by 10 */
  520. #define LL_ADC_CLOCK_ASYNC_DIV12 (ADC_CCR_PRESC_2 | ADC_CCR_PRESC_1 ) /*!< ADC asynchronous clock with prescaler division by 12 */
  521. #define LL_ADC_CLOCK_ASYNC_DIV16 (ADC_CCR_PRESC_2 | ADC_CCR_PRESC_1 | ADC_CCR_PRESC_0) /*!< ADC asynchronous clock with prescaler division by 16 */
  522. #define LL_ADC_CLOCK_ASYNC_DIV32 (ADC_CCR_PRESC_3) /*!< ADC asynchronous clock with prescaler division by 32 */
  523. #define LL_ADC_CLOCK_ASYNC_DIV64 (ADC_CCR_PRESC_3 | ADC_CCR_PRESC_0) /*!< ADC asynchronous clock with prescaler division by 64 */
  524. #define LL_ADC_CLOCK_ASYNC_DIV128 (ADC_CCR_PRESC_3 | ADC_CCR_PRESC_1) /*!< ADC asynchronous clock with prescaler division by 128 */
  525. #define LL_ADC_CLOCK_ASYNC_DIV256 (ADC_CCR_PRESC_3 | ADC_CCR_PRESC_1 | ADC_CCR_PRESC_0) /*!< ADC asynchronous clock with prescaler division by 256 */
  526. /**
  527. * @}
  528. */
  529. /** @defgroup ADC_LL_EC_COMMON_PATH_INTERNAL ADC common - Measurement path to internal channels
  530. * @{
  531. */
  532. /* Note: Other measurement paths to internal channels may be available */
  533. /* (connections to other peripherals). */
  534. /* If they are not listed below, they do not require any specific */
  535. /* path enable. In this case, Access to measurement path is done */
  536. /* only by selecting the corresponding ADC internal channel. */
  537. #define LL_ADC_PATH_INTERNAL_NONE (0x00000000UL) /*!< ADC measurement pathes all disabled */
  538. #define LL_ADC_PATH_INTERNAL_VREFINT (ADC_CCR_VREFEN) /*!< ADC measurement path to internal channel VrefInt */
  539. #define LL_ADC_PATH_INTERNAL_TEMPSENSOR (ADC_CCR_TSEN) /*!< ADC measurement path to internal channel temperature sensor */
  540. #define LL_ADC_PATH_INTERNAL_VBAT (ADC_CCR_VBATEN) /*!< ADC measurement path to internal channel Vbat */
  541. /**
  542. * @}
  543. */
  544. /** @defgroup ADC_LL_EC_RESOLUTION ADC instance - Resolution
  545. * @{
  546. */
  547. #define LL_ADC_RESOLUTION_12B (0x00000000UL) /*!< ADC resolution 12 bits */
  548. #define LL_ADC_RESOLUTION_10B ( ADC_CFGR_RES_0) /*!< ADC resolution 10 bits */
  549. #define LL_ADC_RESOLUTION_8B (ADC_CFGR_RES_1 ) /*!< ADC resolution 8 bits */
  550. #define LL_ADC_RESOLUTION_6B (ADC_CFGR_RES_1 | ADC_CFGR_RES_0) /*!< ADC resolution 6 bits */
  551. /**
  552. * @}
  553. */
  554. /** @defgroup ADC_LL_EC_DATA_ALIGN ADC instance - Data alignment
  555. * @{
  556. */
  557. #define LL_ADC_DATA_ALIGN_RIGHT (0x00000000UL) /*!< ADC conversion data alignment: right aligned (alignment on data register LSB bit 0)*/
  558. #define LL_ADC_DATA_ALIGN_LEFT (ADC_CFGR_ALIGN) /*!< ADC conversion data alignment: left aligned (aligment on data register MSB bit 15)*/
  559. /**
  560. * @}
  561. */
  562. /** @defgroup ADC_LL_EC_LP_MODE ADC instance - Low power mode
  563. * @{
  564. */
  565. #define LL_ADC_LP_MODE_NONE (0x00000000UL) /*!< No ADC low power mode activated */
  566. #define LL_ADC_LP_AUTOWAIT (ADC_CFGR_AUTDLY) /*!< ADC low power mode auto delay: Dynamic low power mode, ADC conversions are performed only when necessary (when previous ADC conversion data is read). See description with function @ref LL_ADC_SetLowPowerMode(). */
  567. /**
  568. * @}
  569. */
  570. /** @defgroup ADC_LL_EC_OFFSET_NB ADC instance - Offset number
  571. * @{
  572. */
  573. #define LL_ADC_OFFSET_1 ADC_OFR1_REGOFFSET /*!< ADC offset number 1: ADC channel and offset level to which the offset programmed will be applied (independently of channel mapped on ADC group regular or group injected) */
  574. #define LL_ADC_OFFSET_2 ADC_OFR2_REGOFFSET /*!< ADC offset number 2: ADC channel and offset level to which the offset programmed will be applied (independently of channel mapped on ADC group regular or group injected) */
  575. #define LL_ADC_OFFSET_3 ADC_OFR3_REGOFFSET /*!< ADC offset number 3: ADC channel and offset level to which the offset programmed will be applied (independently of channel mapped on ADC group regular or group injected) */
  576. #define LL_ADC_OFFSET_4 ADC_OFR4_REGOFFSET /*!< ADC offset number 4: ADC channel and offset level to which the offset programmed will be applied (independently of channel mapped on ADC group regular or group injected) */
  577. /**
  578. * @}
  579. */
  580. /** @defgroup ADC_LL_EC_OFFSET_STATE ADC instance - Offset state
  581. * @{
  582. */
  583. #define LL_ADC_OFFSET_DISABLE (0x00000000UL) /*!< ADC offset disabled (among ADC selected offset number 1, 2, 3 or 4) */
  584. #define LL_ADC_OFFSET_ENABLE (ADC_OFR1_OFFSET1_EN) /*!< ADC offset enabled (among ADC selected offset number 1, 2, 3 or 4) */
  585. /**
  586. * @}
  587. */
  588. /** @defgroup ADC_LL_EC_GROUPS ADC instance - Groups
  589. * @{
  590. */
  591. #define LL_ADC_GROUP_REGULAR (0x00000001UL) /*!< ADC group regular (available on all STM32 devices) */
  592. #define LL_ADC_GROUP_INJECTED (0x00000002UL) /*!< ADC group injected (not available on all STM32 devices)*/
  593. #define LL_ADC_GROUP_REGULAR_INJECTED (0x00000003UL) /*!< ADC both groups regular and injected */
  594. /**
  595. * @}
  596. */
  597. /** @defgroup ADC_LL_EC_CHANNEL ADC instance - Channel number
  598. * @{
  599. */
  600. #define LL_ADC_CHANNEL_0 (ADC_CHANNEL_0_NUMBER | ADC_CHANNEL_0_SMP | ADC_CHANNEL_0_BITFIELD ) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN0 */
  601. #define LL_ADC_CHANNEL_1 (ADC_CHANNEL_1_NUMBER | ADC_CHANNEL_1_SMP | ADC_CHANNEL_1_BITFIELD ) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN1 */
  602. #define LL_ADC_CHANNEL_2 (ADC_CHANNEL_2_NUMBER | ADC_CHANNEL_2_SMP | ADC_CHANNEL_2_BITFIELD ) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN2 */
  603. #define LL_ADC_CHANNEL_3 (ADC_CHANNEL_3_NUMBER | ADC_CHANNEL_3_SMP | ADC_CHANNEL_3_BITFIELD ) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN3 */
  604. #define LL_ADC_CHANNEL_4 (ADC_CHANNEL_4_NUMBER | ADC_CHANNEL_4_SMP | ADC_CHANNEL_4_BITFIELD ) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN4 */
  605. #define LL_ADC_CHANNEL_5 (ADC_CHANNEL_5_NUMBER | ADC_CHANNEL_5_SMP | ADC_CHANNEL_5_BITFIELD ) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN5 */
  606. #define LL_ADC_CHANNEL_6 (ADC_CHANNEL_6_NUMBER | ADC_CHANNEL_6_SMP | ADC_CHANNEL_6_BITFIELD ) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN6 */
  607. #define LL_ADC_CHANNEL_7 (ADC_CHANNEL_7_NUMBER | ADC_CHANNEL_7_SMP | ADC_CHANNEL_7_BITFIELD ) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN7 */
  608. #define LL_ADC_CHANNEL_8 (ADC_CHANNEL_8_NUMBER | ADC_CHANNEL_8_SMP | ADC_CHANNEL_8_BITFIELD ) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN8 */
  609. #define LL_ADC_CHANNEL_9 (ADC_CHANNEL_9_NUMBER | ADC_CHANNEL_9_SMP | ADC_CHANNEL_9_BITFIELD ) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN9 */
  610. #define LL_ADC_CHANNEL_10 (ADC_CHANNEL_10_NUMBER | ADC_CHANNEL_10_SMP | ADC_CHANNEL_10_BITFIELD) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN10 */
  611. #define LL_ADC_CHANNEL_11 (ADC_CHANNEL_11_NUMBER | ADC_CHANNEL_11_SMP | ADC_CHANNEL_11_BITFIELD) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN11 */
  612. #define LL_ADC_CHANNEL_12 (ADC_CHANNEL_12_NUMBER | ADC_CHANNEL_12_SMP | ADC_CHANNEL_12_BITFIELD) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN12 */
  613. #define LL_ADC_CHANNEL_13 (ADC_CHANNEL_13_NUMBER | ADC_CHANNEL_13_SMP | ADC_CHANNEL_13_BITFIELD) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN13 */
  614. #define LL_ADC_CHANNEL_14 (ADC_CHANNEL_14_NUMBER | ADC_CHANNEL_14_SMP | ADC_CHANNEL_14_BITFIELD) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN14 */
  615. #define LL_ADC_CHANNEL_15 (ADC_CHANNEL_15_NUMBER | ADC_CHANNEL_15_SMP | ADC_CHANNEL_15_BITFIELD) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN15 */
  616. #define LL_ADC_CHANNEL_16 (ADC_CHANNEL_16_NUMBER | ADC_CHANNEL_16_SMP | ADC_CHANNEL_16_BITFIELD) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN16 */
  617. #define LL_ADC_CHANNEL_17 (ADC_CHANNEL_17_NUMBER | ADC_CHANNEL_17_SMP | ADC_CHANNEL_17_BITFIELD) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN17 */
  618. #define LL_ADC_CHANNEL_18 (ADC_CHANNEL_18_NUMBER | ADC_CHANNEL_18_SMP | ADC_CHANNEL_18_BITFIELD) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN18 */
  619. #define LL_ADC_CHANNEL_VREFINT (LL_ADC_CHANNEL_0 | ADC_CHANNEL_ID_INTERNAL_CH) /*!< ADC internal channel connected to VrefInt: Internal voltage reference. */
  620. #define LL_ADC_CHANNEL_TEMPSENSOR (LL_ADC_CHANNEL_17 | ADC_CHANNEL_ID_INTERNAL_CH) /*!< ADC internal channel connected to Temperature sensor. */
  621. #define LL_ADC_CHANNEL_VBAT (LL_ADC_CHANNEL_18 | ADC_CHANNEL_ID_INTERNAL_CH) /*!< ADC internal channel connected to Vbat/2: Vbat voltage through a divider ladder of factor 1/2 to have Vbat always below Vdda. */
  622. /**
  623. * @}
  624. */
  625. /** @defgroup ADC_LL_EC_REG_TRIGGER_SOURCE ADC group regular - Trigger source
  626. * @{
  627. */
  628. #define LL_ADC_REG_TRIG_SOFTWARE (0x00000000UL) /*!< ADC group regular conversion trigger internal: SW start. */
  629. #define LL_ADC_REG_TRIG_EXT_TIM1_TRGO (ADC_CFGR_EXTSEL_3 | ADC_CFGR_EXTSEL_0 | ADC_REG_TRIG_EXT_EDGE_DEFAULT) /*!< ADC group regular conversion trigger from external peripheral: TIM1 TRGO. Trigger edge set to rising edge (default setting). */
  630. #define LL_ADC_REG_TRIG_EXT_TIM1_TRGO2 (ADC_CFGR_EXTSEL_3 | ADC_CFGR_EXTSEL_1 | ADC_REG_TRIG_EXT_EDGE_DEFAULT) /*!< ADC group regular conversion trigger from external peripheral: TIM1 TRGO2. Trigger edge set to rising edge (default setting). */
  631. #define LL_ADC_REG_TRIG_EXT_TIM1_CH1 (ADC_REG_TRIG_EXT_EDGE_DEFAULT) /*!< ADC group regular conversion trigger from external peripheral: TIM1 channel 1 event (capture compare: input capture or output capture). Trigger edge set to rising edge (default setting). */
  632. #define LL_ADC_REG_TRIG_EXT_TIM1_CH2 (ADC_CFGR_EXTSEL_0 | ADC_REG_TRIG_EXT_EDGE_DEFAULT) /*!< ADC group regular conversion trigger from external peripheral: TIM1 channel 2 event (capture compare: input capture or output capture). Trigger edge set to rising edge (default setting). */
  633. #define LL_ADC_REG_TRIG_EXT_TIM1_CH3 (ADC_CFGR_EXTSEL_1 | ADC_REG_TRIG_EXT_EDGE_DEFAULT) /*!< ADC group regular conversion trigger from external peripheral: TIM1 channel 3 event (capture compare: input capture or output capture). Trigger edge set to rising edge (default setting). */
  634. #define LL_ADC_REG_TRIG_EXT_TIM2_TRGO (ADC_CFGR_EXTSEL_3 | ADC_CFGR_EXTSEL_1 | ADC_CFGR_EXTSEL_0 | ADC_REG_TRIG_EXT_EDGE_DEFAULT) /*!< ADC group regular conversion trigger from external peripheral: TIM2 TRGO. Trigger edge set to rising edge (default setting). */
  635. #define LL_ADC_REG_TRIG_EXT_TIM2_CH2 (ADC_CFGR_EXTSEL_1 | ADC_CFGR_EXTSEL_0 | ADC_REG_TRIG_EXT_EDGE_DEFAULT) /*!< ADC group regular conversion trigger from external peripheral: TIM2 channel 2 event (capture compare: input capture or output capture). Trigger edge set to rising edge (default setting). */
  636. #define LL_ADC_REG_TRIG_EXT_EXTI_LINE11 (ADC_CFGR_EXTSEL_2 | ADC_CFGR_EXTSEL_1 | ADC_REG_TRIG_EXT_EDGE_DEFAULT) /*!< ADC group regular conversion trigger from external peripheral: external interrupt line 11. Trigger edge set to rising edge (default setting). */
  637. /**
  638. * @}
  639. */
  640. /** @defgroup ADC_LL_EC_REG_TRIGGER_EDGE ADC group regular - Trigger edge
  641. * @{
  642. */
  643. #define LL_ADC_REG_TRIG_EXT_RISING ( ADC_CFGR_EXTEN_0) /*!< ADC group regular conversion trigger polarity set to rising edge */
  644. #define LL_ADC_REG_TRIG_EXT_FALLING (ADC_CFGR_EXTEN_1 ) /*!< ADC group regular conversion trigger polarity set to falling edge */
  645. #define LL_ADC_REG_TRIG_EXT_RISINGFALLING (ADC_CFGR_EXTEN_1 | ADC_CFGR_EXTEN_0) /*!< ADC group regular conversion trigger polarity set to both rising and falling edges */
  646. /**
  647. * @}
  648. */
  649. /** @defgroup ADC_LL_EC_REG_CONTINUOUS_MODE ADC group regular - Continuous mode
  650. * @{
  651. */
  652. #define LL_ADC_REG_CONV_SINGLE (0x00000000UL) /*!< ADC conversions are performed in single mode: one conversion per trigger */
  653. #define LL_ADC_REG_CONV_CONTINUOUS (ADC_CFGR_CONT) /*!< ADC conversions are performed in continuous mode: after the first trigger, following conversions launched successively automatically */
  654. /**
  655. * @}
  656. */
  657. /** @defgroup ADC_LL_EC_REG_DMA_TRANSFER ADC group regular - DMA transfer of ADC conversion data
  658. * @{
  659. */
  660. #define LL_ADC_REG_DMA_TRANSFER_NONE (0x00000000UL) /*!< ADC conversions are not transferred by DMA */
  661. #define LL_ADC_REG_DMA_TRANSFER_LIMITED ( ADC_CFGR_DMAEN) /*!< ADC conversion data are transferred by DMA, in limited mode (one shot mode): DMA transfer requests are stopped when number of DMA data transfers (number of ADC conversions) is reached. This ADC mode is intended to be used with DMA mode non-circular. */
  662. #define LL_ADC_REG_DMA_TRANSFER_UNLIMITED (ADC_CFGR_DMACFG | ADC_CFGR_DMAEN) /*!< ADC conversion data are transferred by DMA, in unlimited mode: DMA transfer requests are unlimited, whatever number of DMA data transferred (number of ADC conversions). This ADC mode is intended to be used with DMA mode circular. */
  663. /**
  664. * @}
  665. */
  666. /** @defgroup ADC_LL_EC_REG_OVR_DATA_BEHAVIOR ADC group regular - Overrun behavior on conversion data
  667. * @{
  668. */
  669. #define LL_ADC_REG_OVR_DATA_PRESERVED (0x00000000UL) /*!< ADC group regular behavior in case of overrun: data preserved */
  670. #define LL_ADC_REG_OVR_DATA_OVERWRITTEN (ADC_CFGR_OVRMOD) /*!< ADC group regular behavior in case of overrun: data overwritten */
  671. /**
  672. * @}
  673. */
  674. /** @defgroup ADC_LL_EC_REG_SEQ_SCAN_LENGTH ADC group regular - Sequencer scan length
  675. * @{
  676. */
  677. #define LL_ADC_REG_SEQ_SCAN_DISABLE (0x00000000UL) /*!< ADC group regular sequencer disable (equivalent to sequencer of 1 rank: ADC conversion on only 1 channel) */
  678. #define LL_ADC_REG_SEQ_SCAN_ENABLE_2RANKS ( ADC_SQR1_L_0) /*!< ADC group regular sequencer enable with 2 ranks in the sequence */
  679. #define LL_ADC_REG_SEQ_SCAN_ENABLE_3RANKS ( ADC_SQR1_L_1 ) /*!< ADC group regular sequencer enable with 3 ranks in the sequence */
  680. #define LL_ADC_REG_SEQ_SCAN_ENABLE_4RANKS ( ADC_SQR1_L_1 | ADC_SQR1_L_0) /*!< ADC group regular sequencer enable with 4 ranks in the sequence */
  681. #define LL_ADC_REG_SEQ_SCAN_ENABLE_5RANKS ( ADC_SQR1_L_2 ) /*!< ADC group regular sequencer enable with 5 ranks in the sequence */
  682. #define LL_ADC_REG_SEQ_SCAN_ENABLE_6RANKS ( ADC_SQR1_L_2 | ADC_SQR1_L_0) /*!< ADC group regular sequencer enable with 6 ranks in the sequence */
  683. #define LL_ADC_REG_SEQ_SCAN_ENABLE_7RANKS ( ADC_SQR1_L_2 | ADC_SQR1_L_1 ) /*!< ADC group regular sequencer enable with 7 ranks in the sequence */
  684. #define LL_ADC_REG_SEQ_SCAN_ENABLE_8RANKS ( ADC_SQR1_L_2 | ADC_SQR1_L_1 | ADC_SQR1_L_0) /*!< ADC group regular sequencer enable with 8 ranks in the sequence */
  685. #define LL_ADC_REG_SEQ_SCAN_ENABLE_9RANKS (ADC_SQR1_L_3 ) /*!< ADC group regular sequencer enable with 9 ranks in the sequence */
  686. #define LL_ADC_REG_SEQ_SCAN_ENABLE_10RANKS (ADC_SQR1_L_3 | ADC_SQR1_L_0) /*!< ADC group regular sequencer enable with 10 ranks in the sequence */
  687. #define LL_ADC_REG_SEQ_SCAN_ENABLE_11RANKS (ADC_SQR1_L_3 | ADC_SQR1_L_1 ) /*!< ADC group regular sequencer enable with 11 ranks in the sequence */
  688. #define LL_ADC_REG_SEQ_SCAN_ENABLE_12RANKS (ADC_SQR1_L_3 | ADC_SQR1_L_1 | ADC_SQR1_L_0) /*!< ADC group regular sequencer enable with 12 ranks in the sequence */
  689. #define LL_ADC_REG_SEQ_SCAN_ENABLE_13RANKS (ADC_SQR1_L_3 | ADC_SQR1_L_2 ) /*!< ADC group regular sequencer enable with 13 ranks in the sequence */
  690. #define LL_ADC_REG_SEQ_SCAN_ENABLE_14RANKS (ADC_SQR1_L_3 | ADC_SQR1_L_2 | ADC_SQR1_L_0) /*!< ADC group regular sequencer enable with 14 ranks in the sequence */
  691. #define LL_ADC_REG_SEQ_SCAN_ENABLE_15RANKS (ADC_SQR1_L_3 | ADC_SQR1_L_2 | ADC_SQR1_L_1 ) /*!< ADC group regular sequencer enable with 15 ranks in the sequence */
  692. #define LL_ADC_REG_SEQ_SCAN_ENABLE_16RANKS (ADC_SQR1_L_3 | ADC_SQR1_L_2 | ADC_SQR1_L_1 | ADC_SQR1_L_0) /*!< ADC group regular sequencer enable with 16 ranks in the sequence */
  693. /**
  694. * @}
  695. */
  696. /** @defgroup ADC_LL_EC_REG_SEQ_DISCONT_MODE ADC group regular - Sequencer discontinuous mode
  697. * @{
  698. */
  699. #define LL_ADC_REG_SEQ_DISCONT_DISABLE (0x00000000UL) /*!< ADC group regular sequencer discontinuous mode disable */
  700. #define LL_ADC_REG_SEQ_DISCONT_1RANK ( ADC_CFGR_DISCEN) /*!< ADC group regular sequencer discontinuous mode enable with sequence interruption every rank */
  701. #define LL_ADC_REG_SEQ_DISCONT_2RANKS ( ADC_CFGR_DISCNUM_0 | ADC_CFGR_DISCEN) /*!< ADC group regular sequencer discontinuous mode enabled with sequence interruption every 2 ranks */
  702. #define LL_ADC_REG_SEQ_DISCONT_3RANKS ( ADC_CFGR_DISCNUM_1 | ADC_CFGR_DISCEN) /*!< ADC group regular sequencer discontinuous mode enable with sequence interruption every 3 ranks */
  703. #define LL_ADC_REG_SEQ_DISCONT_4RANKS ( ADC_CFGR_DISCNUM_1 | ADC_CFGR_DISCNUM_0 | ADC_CFGR_DISCEN) /*!< ADC group regular sequencer discontinuous mode enable with sequence interruption every 4 ranks */
  704. #define LL_ADC_REG_SEQ_DISCONT_5RANKS (ADC_CFGR_DISCNUM_2 | ADC_CFGR_DISCEN) /*!< ADC group regular sequencer discontinuous mode enable with sequence interruption every 5 ranks */
  705. #define LL_ADC_REG_SEQ_DISCONT_6RANKS (ADC_CFGR_DISCNUM_2 | ADC_CFGR_DISCNUM_0 | ADC_CFGR_DISCEN) /*!< ADC group regular sequencer discontinuous mode enable with sequence interruption every 6 ranks */
  706. #define LL_ADC_REG_SEQ_DISCONT_7RANKS (ADC_CFGR_DISCNUM_2 | ADC_CFGR_DISCNUM_1 | ADC_CFGR_DISCEN) /*!< ADC group regular sequencer discontinuous mode enable with sequence interruption every 7 ranks */
  707. #define LL_ADC_REG_SEQ_DISCONT_8RANKS (ADC_CFGR_DISCNUM_2 | ADC_CFGR_DISCNUM_1 | ADC_CFGR_DISCNUM_0 | ADC_CFGR_DISCEN) /*!< ADC group regular sequencer discontinuous mode enable with sequence interruption every 8 ranks */
  708. /**
  709. * @}
  710. */
  711. /** @defgroup ADC_LL_EC_REG_SEQ_RANKS ADC group regular - Sequencer ranks
  712. * @{
  713. */
  714. #define LL_ADC_REG_RANK_1 (ADC_SQR1_REGOFFSET | ADC_REG_RANK_1_SQRX_BITOFFSET_POS) /*!< ADC group regular sequencer rank 1 */
  715. #define LL_ADC_REG_RANK_2 (ADC_SQR1_REGOFFSET | ADC_REG_RANK_2_SQRX_BITOFFSET_POS) /*!< ADC group regular sequencer rank 2 */
  716. #define LL_ADC_REG_RANK_3 (ADC_SQR1_REGOFFSET | ADC_REG_RANK_3_SQRX_BITOFFSET_POS) /*!< ADC group regular sequencer rank 3 */
  717. #define LL_ADC_REG_RANK_4 (ADC_SQR1_REGOFFSET | ADC_REG_RANK_4_SQRX_BITOFFSET_POS) /*!< ADC group regular sequencer rank 4 */
  718. #define LL_ADC_REG_RANK_5 (ADC_SQR2_REGOFFSET | ADC_REG_RANK_5_SQRX_BITOFFSET_POS) /*!< ADC group regular sequencer rank 5 */
  719. #define LL_ADC_REG_RANK_6 (ADC_SQR2_REGOFFSET | ADC_REG_RANK_6_SQRX_BITOFFSET_POS) /*!< ADC group regular sequencer rank 6 */
  720. #define LL_ADC_REG_RANK_7 (ADC_SQR2_REGOFFSET | ADC_REG_RANK_7_SQRX_BITOFFSET_POS) /*!< ADC group regular sequencer rank 7 */
  721. #define LL_ADC_REG_RANK_8 (ADC_SQR2_REGOFFSET | ADC_REG_RANK_8_SQRX_BITOFFSET_POS) /*!< ADC group regular sequencer rank 8 */
  722. #define LL_ADC_REG_RANK_9 (ADC_SQR2_REGOFFSET | ADC_REG_RANK_9_SQRX_BITOFFSET_POS) /*!< ADC group regular sequencer rank 9 */
  723. #define LL_ADC_REG_RANK_10 (ADC_SQR3_REGOFFSET | ADC_REG_RANK_10_SQRX_BITOFFSET_POS) /*!< ADC group regular sequencer rank 10 */
  724. #define LL_ADC_REG_RANK_11 (ADC_SQR3_REGOFFSET | ADC_REG_RANK_11_SQRX_BITOFFSET_POS) /*!< ADC group regular sequencer rank 11 */
  725. #define LL_ADC_REG_RANK_12 (ADC_SQR3_REGOFFSET | ADC_REG_RANK_12_SQRX_BITOFFSET_POS) /*!< ADC group regular sequencer rank 12 */
  726. #define LL_ADC_REG_RANK_13 (ADC_SQR3_REGOFFSET | ADC_REG_RANK_13_SQRX_BITOFFSET_POS) /*!< ADC group regular sequencer rank 13 */
  727. #define LL_ADC_REG_RANK_14 (ADC_SQR3_REGOFFSET | ADC_REG_RANK_14_SQRX_BITOFFSET_POS) /*!< ADC group regular sequencer rank 14 */
  728. #define LL_ADC_REG_RANK_15 (ADC_SQR4_REGOFFSET | ADC_REG_RANK_15_SQRX_BITOFFSET_POS) /*!< ADC group regular sequencer rank 15 */
  729. #define LL_ADC_REG_RANK_16 (ADC_SQR4_REGOFFSET | ADC_REG_RANK_16_SQRX_BITOFFSET_POS) /*!< ADC group regular sequencer rank 16 */
  730. /**
  731. * @}
  732. */
  733. /** @defgroup ADC_LL_EC_INJ_TRIGGER_SOURCE ADC group injected - Trigger source
  734. * @{
  735. */
  736. #define LL_ADC_INJ_TRIG_SOFTWARE (0x00000000UL) /*!< ADC group injected conversion trigger internal: SW start.. Trigger edge set to rising edge (default setting). */
  737. #define LL_ADC_INJ_TRIG_EXT_TIM1_TRGO (ADC_INJ_TRIG_EXT_EDGE_DEFAULT) /*!< ADC group injected conversion trigger from external peripheral: TIM1 TRGO. Trigger edge set to rising edge (default setting). */
  738. #define LL_ADC_INJ_TRIG_EXT_TIM1_TRGO2 (ADC_JSQR_JEXTSEL_3 | ADC_INJ_TRIG_EXT_EDGE_DEFAULT) /*!< ADC group injected conversion trigger from external peripheral: TIM1 TRGO2. Trigger edge set to rising edge (default setting). */
  739. #define LL_ADC_INJ_TRIG_EXT_TIM1_CH4 (ADC_JSQR_JEXTSEL_0 | ADC_INJ_TRIG_EXT_EDGE_DEFAULT) /*!< ADC group injected conversion trigger from external peripheral: TIM1 channel 4 event (capture compare: input capture or output capture). Trigger edge set to rising edge (default setting). */
  740. #define LL_ADC_INJ_TRIG_EXT_TIM2_TRGO (ADC_JSQR_JEXTSEL_1 | ADC_INJ_TRIG_EXT_EDGE_DEFAULT) /*!< ADC group injected conversion trigger from external peripheral: TIM2 TRGO. Trigger edge set to rising edge (default setting). */
  741. #define LL_ADC_INJ_TRIG_EXT_TIM2_CH1 (ADC_JSQR_JEXTSEL_1 | ADC_JSQR_JEXTSEL_0 | ADC_INJ_TRIG_EXT_EDGE_DEFAULT) /*!< ADC group injected conversion trigger from external peripheral: TIM2 channel 1 event (capture compare: input capture or output capture). Trigger edge set to rising edge (default setting). */
  742. #define LL_ADC_INJ_TRIG_EXT_EXTI_LINE15 (ADC_JSQR_JEXTSEL_2 | ADC_JSQR_JEXTSEL_1 | ADC_INJ_TRIG_EXT_EDGE_DEFAULT) /*!< ADC group injected conversion trigger from external peripheral: external interrupt line 15. Trigger edge set to rising edge (default setting). */
  743. /**
  744. * @}
  745. */
  746. /** @defgroup ADC_LL_EC_INJ_TRIGGER_EDGE ADC group injected - Trigger edge
  747. * @{
  748. */
  749. #define LL_ADC_INJ_TRIG_EXT_RISING ( ADC_JSQR_JEXTEN_0) /*!< ADC group injected conversion trigger polarity set to rising edge */
  750. #define LL_ADC_INJ_TRIG_EXT_FALLING (ADC_JSQR_JEXTEN_1 ) /*!< ADC group injected conversion trigger polarity set to falling edge */
  751. #define LL_ADC_INJ_TRIG_EXT_RISINGFALLING (ADC_JSQR_JEXTEN_1 | ADC_JSQR_JEXTEN_0) /*!< ADC group injected conversion trigger polarity set to both rising and falling edges */
  752. /**
  753. * @}
  754. */
  755. /** @defgroup ADC_LL_EC_INJ_TRIG_AUTO ADC group injected - Automatic trigger mode
  756. * @{
  757. */
  758. #define LL_ADC_INJ_TRIG_INDEPENDENT (0x00000000UL) /*!< ADC group injected conversion trigger independent. Setting mandatory if ADC group injected injected trigger source is set to an external trigger. */
  759. #define LL_ADC_INJ_TRIG_FROM_GRP_REGULAR (ADC_CFGR_JAUTO) /*!< ADC group injected conversion trigger from ADC group regular. Setting compliant only with group injected trigger source set to SW start, without any further action on ADC group injected conversion start or stop: in this case, ADC group injected is controlled only from ADC group regular. */
  760. /**
  761. * @}
  762. */
  763. /** @defgroup ADC_LL_EC_INJ_CONTEXT_QUEUE ADC group injected - Context queue mode
  764. * @{
  765. */
  766. #define LL_ADC_INJ_QUEUE_2CONTEXTS_LAST_ACTIVE (0x00000000UL) /* Group injected sequence context queue is enabled and can contain up to 2 contexts. When all contexts have been processed, the queue maintains the last context active perpetually. */
  767. #define LL_ADC_INJ_QUEUE_2CONTEXTS_END_EMPTY (ADC_CFGR_JQM) /* Group injected sequence context queue is enabled and can contain up to 2 contexts. When all contexts have been processed, the queue is empty and injected group triggers are disabled. */
  768. #define LL_ADC_INJ_QUEUE_DISABLE (ADC_CFGR_JQDIS) /* Group injected sequence context queue is disabled: only 1 sequence can be configured and is active perpetually. */
  769. /**
  770. * @}
  771. */
  772. /** @defgroup ADC_LL_EC_INJ_SEQ_SCAN_LENGTH ADC group injected - Sequencer scan length
  773. * @{
  774. */
  775. #define LL_ADC_INJ_SEQ_SCAN_DISABLE (0x00000000UL) /*!< ADC group injected sequencer disable (equivalent to sequencer of 1 rank: ADC conversion on only 1 channel) */
  776. #define LL_ADC_INJ_SEQ_SCAN_ENABLE_2RANKS ( ADC_JSQR_JL_0) /*!< ADC group injected sequencer enable with 2 ranks in the sequence */
  777. #define LL_ADC_INJ_SEQ_SCAN_ENABLE_3RANKS (ADC_JSQR_JL_1 ) /*!< ADC group injected sequencer enable with 3 ranks in the sequence */
  778. #define LL_ADC_INJ_SEQ_SCAN_ENABLE_4RANKS (ADC_JSQR_JL_1 | ADC_JSQR_JL_0) /*!< ADC group injected sequencer enable with 4 ranks in the sequence */
  779. /**
  780. * @}
  781. */
  782. /** @defgroup ADC_LL_EC_INJ_SEQ_DISCONT_MODE ADC group injected - Sequencer discontinuous mode
  783. * @{
  784. */
  785. #define LL_ADC_INJ_SEQ_DISCONT_DISABLE (0x00000000UL) /*!< ADC group injected sequencer discontinuous mode disable */
  786. #define LL_ADC_INJ_SEQ_DISCONT_1RANK (ADC_CFGR_JDISCEN) /*!< ADC group injected sequencer discontinuous mode enable with sequence interruption every rank */
  787. /**
  788. * @}
  789. */
  790. /** @defgroup ADC_LL_EC_INJ_SEQ_RANKS ADC group injected - Sequencer ranks
  791. * @{
  792. */
  793. #define LL_ADC_INJ_RANK_1 (ADC_JDR1_REGOFFSET | ADC_INJ_RANK_1_JSQR_BITOFFSET_POS) /*!< ADC group injected sequencer rank 1 */
  794. #define LL_ADC_INJ_RANK_2 (ADC_JDR2_REGOFFSET | ADC_INJ_RANK_2_JSQR_BITOFFSET_POS) /*!< ADC group injected sequencer rank 2 */
  795. #define LL_ADC_INJ_RANK_3 (ADC_JDR3_REGOFFSET | ADC_INJ_RANK_3_JSQR_BITOFFSET_POS) /*!< ADC group injected sequencer rank 3 */
  796. #define LL_ADC_INJ_RANK_4 (ADC_JDR4_REGOFFSET | ADC_INJ_RANK_4_JSQR_BITOFFSET_POS) /*!< ADC group injected sequencer rank 4 */
  797. /**
  798. * @}
  799. */
  800. /** @defgroup ADC_LL_EC_CHANNEL_SAMPLINGTIME Channel - Sampling time
  801. * @{
  802. */
  803. #define LL_ADC_SAMPLINGTIME_2CYCLES_5 (0x00000000UL) /*!< Sampling time 2.5 ADC clock cycles */
  804. #define LL_ADC_SAMPLINGTIME_6CYCLES_5 ( ADC_SMPR2_SMP10_0) /*!< Sampling time 6.5 ADC clock cycles */
  805. #define LL_ADC_SAMPLINGTIME_12CYCLES_5 ( ADC_SMPR2_SMP10_1 ) /*!< Sampling time 12.5 ADC clock cycles */
  806. #define LL_ADC_SAMPLINGTIME_24CYCLES_5 ( ADC_SMPR2_SMP10_1 | ADC_SMPR2_SMP10_0) /*!< Sampling time 24.5 ADC clock cycles */
  807. #define LL_ADC_SAMPLINGTIME_47CYCLES_5 (ADC_SMPR2_SMP10_2 ) /*!< Sampling time 47.5 ADC clock cycles */
  808. #define LL_ADC_SAMPLINGTIME_92CYCLES_5 (ADC_SMPR2_SMP10_2 | ADC_SMPR2_SMP10_0) /*!< Sampling time 92.5 ADC clock cycles */
  809. #define LL_ADC_SAMPLINGTIME_247CYCLES_5 (ADC_SMPR2_SMP10_2 | ADC_SMPR2_SMP10_1 ) /*!< Sampling time 247.5 ADC clock cycles */
  810. #define LL_ADC_SAMPLINGTIME_640CYCLES_5 (ADC_SMPR2_SMP10_2 | ADC_SMPR2_SMP10_1 | ADC_SMPR2_SMP10_0) /*!< Sampling time 640.5 ADC clock cycles */
  811. /**
  812. * @}
  813. */
  814. /** @defgroup ADC_LL_EC_CHANNEL_SINGLE_DIFF_ENDING Channel - Single or differential ending
  815. * @{
  816. */
  817. #define LL_ADC_SINGLE_ENDED ( ADC_CALFACT_CALFACT_S) /*!< ADC channel ending set to single ended (literal also used to set calibration mode) */
  818. #define LL_ADC_DIFFERENTIAL_ENDED (ADC_CR_ADCALDIF | ADC_CALFACT_CALFACT_D) /*!< ADC channel ending set to differential (literal also used to set calibration mode) */
  819. #define LL_ADC_BOTH_SINGLE_DIFF_ENDED (LL_ADC_SINGLE_ENDED | LL_ADC_DIFFERENTIAL_ENDED) /*!< ADC channel ending set to both single ended and differential (literal used only to set calibration factors) */
  820. /**
  821. * @}
  822. */
  823. /** @defgroup ADC_LL_EC_AWD_NUMBER Analog watchdog - Analog watchdog number
  824. * @{
  825. */
  826. #define LL_ADC_AWD1 (ADC_AWD_CR1_CHANNEL_MASK | ADC_AWD_CR1_REGOFFSET) /*!< ADC analog watchdog number 1 */
  827. #define LL_ADC_AWD2 (ADC_AWD_CR23_CHANNEL_MASK | ADC_AWD_CR2_REGOFFSET) /*!< ADC analog watchdog number 2 */
  828. #define LL_ADC_AWD3 (ADC_AWD_CR23_CHANNEL_MASK | ADC_AWD_CR3_REGOFFSET) /*!< ADC analog watchdog number 3 */
  829. /**
  830. * @}
  831. */
  832. /** @defgroup ADC_LL_EC_AWD_CHANNELS Analog watchdog - Monitored channels
  833. * @{
  834. */
  835. #define LL_ADC_AWD_DISABLE (0x00000000UL) /*!< ADC analog watchdog monitoring disabled */
  836. #define LL_ADC_AWD_ALL_CHANNELS_REG (ADC_AWD_CR23_CHANNEL_MASK | ADC_CFGR_AWD1EN ) /*!< ADC analog watchdog monitoring of all channels, converted by group regular only */
  837. #define LL_ADC_AWD_ALL_CHANNELS_INJ (ADC_AWD_CR23_CHANNEL_MASK | ADC_CFGR_JAWD1EN ) /*!< ADC analog watchdog monitoring of all channels, converted by group injected only */
  838. #define LL_ADC_AWD_ALL_CHANNELS_REG_INJ (ADC_AWD_CR23_CHANNEL_MASK | ADC_CFGR_JAWD1EN | ADC_CFGR_AWD1EN ) /*!< ADC analog watchdog monitoring of all channels, converted by either group regular or injected */
  839. #define LL_ADC_AWD_CHANNEL_0_REG ((LL_ADC_CHANNEL_0 & ADC_CHANNEL_ID_MASK) | ADC_CFGR_AWD1EN | ADC_CFGR_AWD1SGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN0, converted by group regular only */
  840. #define LL_ADC_AWD_CHANNEL_0_INJ ((LL_ADC_CHANNEL_0 & ADC_CHANNEL_ID_MASK) | ADC_CFGR_JAWD1EN | ADC_CFGR_AWD1SGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN0, converted by group injected only */
  841. #define LL_ADC_AWD_CHANNEL_0_REG_INJ ((LL_ADC_CHANNEL_0 & ADC_CHANNEL_ID_MASK) | ADC_CFGR_JAWD1EN | ADC_CFGR_AWD1EN | ADC_CFGR_AWD1SGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN0, converted by either group regular or injected */
  842. #define LL_ADC_AWD_CHANNEL_1_REG ((LL_ADC_CHANNEL_1 & ADC_CHANNEL_ID_MASK) | ADC_CFGR_AWD1EN | ADC_CFGR_AWD1SGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN1, converted by group regular only */
  843. #define LL_ADC_AWD_CHANNEL_1_INJ ((LL_ADC_CHANNEL_1 & ADC_CHANNEL_ID_MASK) | ADC_CFGR_JAWD1EN | ADC_CFGR_AWD1SGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN1, converted by group injected only */
  844. #define LL_ADC_AWD_CHANNEL_1_REG_INJ ((LL_ADC_CHANNEL_1 & ADC_CHANNEL_ID_MASK) | ADC_CFGR_JAWD1EN | ADC_CFGR_AWD1EN | ADC_CFGR_AWD1SGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN1, converted by either group regular or injected */
  845. #define LL_ADC_AWD_CHANNEL_2_REG ((LL_ADC_CHANNEL_2 & ADC_CHANNEL_ID_MASK) | ADC_CFGR_AWD1EN | ADC_CFGR_AWD1SGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN2, converted by group regular only */
  846. #define LL_ADC_AWD_CHANNEL_2_INJ ((LL_ADC_CHANNEL_2 & ADC_CHANNEL_ID_MASK) | ADC_CFGR_JAWD1EN | ADC_CFGR_AWD1SGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN2, converted by group injected only */
  847. #define LL_ADC_AWD_CHANNEL_2_REG_INJ ((LL_ADC_CHANNEL_2 & ADC_CHANNEL_ID_MASK) | ADC_CFGR_JAWD1EN | ADC_CFGR_AWD1EN | ADC_CFGR_AWD1SGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN2, converted by either group regular or injected */
  848. #define LL_ADC_AWD_CHANNEL_3_REG ((LL_ADC_CHANNEL_3 & ADC_CHANNEL_ID_MASK) | ADC_CFGR_AWD1EN | ADC_CFGR_AWD1SGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN3, converted by group regular only */
  849. #define LL_ADC_AWD_CHANNEL_3_INJ ((LL_ADC_CHANNEL_3 & ADC_CHANNEL_ID_MASK) | ADC_CFGR_JAWD1EN | ADC_CFGR_AWD1SGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN3, converted by group injected only */
  850. #define LL_ADC_AWD_CHANNEL_3_REG_INJ ((LL_ADC_CHANNEL_3 & ADC_CHANNEL_ID_MASK) | ADC_CFGR_JAWD1EN | ADC_CFGR_AWD1EN | ADC_CFGR_AWD1SGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN3, converted by either group regular or injected */
  851. #define LL_ADC_AWD_CHANNEL_4_REG ((LL_ADC_CHANNEL_4 & ADC_CHANNEL_ID_MASK) | ADC_CFGR_AWD1EN | ADC_CFGR_AWD1SGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN4, converted by group regular only */
  852. #define LL_ADC_AWD_CHANNEL_4_INJ ((LL_ADC_CHANNEL_4 & ADC_CHANNEL_ID_MASK) | ADC_CFGR_JAWD1EN | ADC_CFGR_AWD1SGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN4, converted by group injected only */
  853. #define LL_ADC_AWD_CHANNEL_4_REG_INJ ((LL_ADC_CHANNEL_4 & ADC_CHANNEL_ID_MASK) | ADC_CFGR_JAWD1EN | ADC_CFGR_AWD1EN | ADC_CFGR_AWD1SGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN4, converted by either group regular or injected */
  854. #define LL_ADC_AWD_CHANNEL_5_REG ((LL_ADC_CHANNEL_5 & ADC_CHANNEL_ID_MASK) | ADC_CFGR_AWD1EN | ADC_CFGR_AWD1SGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN5, converted by group regular only */
  855. #define LL_ADC_AWD_CHANNEL_5_INJ ((LL_ADC_CHANNEL_5 & ADC_CHANNEL_ID_MASK) | ADC_CFGR_JAWD1EN | ADC_CFGR_AWD1SGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN5, converted by group injected only */
  856. #define LL_ADC_AWD_CHANNEL_5_REG_INJ ((LL_ADC_CHANNEL_5 & ADC_CHANNEL_ID_MASK) | ADC_CFGR_JAWD1EN | ADC_CFGR_AWD1EN | ADC_CFGR_AWD1SGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN5, converted by either group regular or injected */
  857. #define LL_ADC_AWD_CHANNEL_6_REG ((LL_ADC_CHANNEL_6 & ADC_CHANNEL_ID_MASK) | ADC_CFGR_AWD1EN | ADC_CFGR_AWD1SGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN6, converted by group regular only */
  858. #define LL_ADC_AWD_CHANNEL_6_INJ ((LL_ADC_CHANNEL_6 & ADC_CHANNEL_ID_MASK) | ADC_CFGR_JAWD1EN | ADC_CFGR_AWD1SGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN6, converted by group injected only */
  859. #define LL_ADC_AWD_CHANNEL_6_REG_INJ ((LL_ADC_CHANNEL_6 & ADC_CHANNEL_ID_MASK) | ADC_CFGR_JAWD1EN | ADC_CFGR_AWD1EN | ADC_CFGR_AWD1SGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN6, converted by either group regular or injected */
  860. #define LL_ADC_AWD_CHANNEL_7_REG ((LL_ADC_CHANNEL_7 & ADC_CHANNEL_ID_MASK) | ADC_CFGR_AWD1EN | ADC_CFGR_AWD1SGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN7, converted by group regular only */
  861. #define LL_ADC_AWD_CHANNEL_7_INJ ((LL_ADC_CHANNEL_7 & ADC_CHANNEL_ID_MASK) | ADC_CFGR_JAWD1EN | ADC_CFGR_AWD1SGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN7, converted by group injected only */
  862. #define LL_ADC_AWD_CHANNEL_7_REG_INJ ((LL_ADC_CHANNEL_7 & ADC_CHANNEL_ID_MASK) | ADC_CFGR_JAWD1EN | ADC_CFGR_AWD1EN | ADC_CFGR_AWD1SGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN7, converted by either group regular or injected */
  863. #define LL_ADC_AWD_CHANNEL_8_REG ((LL_ADC_CHANNEL_8 & ADC_CHANNEL_ID_MASK) | ADC_CFGR_AWD1EN | ADC_CFGR_AWD1SGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN8, converted by group regular only */
  864. #define LL_ADC_AWD_CHANNEL_8_INJ ((LL_ADC_CHANNEL_8 & ADC_CHANNEL_ID_MASK) | ADC_CFGR_JAWD1EN | ADC_CFGR_AWD1SGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN8, converted by group injected only */
  865. #define LL_ADC_AWD_CHANNEL_8_REG_INJ ((LL_ADC_CHANNEL_8 & ADC_CHANNEL_ID_MASK) | ADC_CFGR_JAWD1EN | ADC_CFGR_AWD1EN | ADC_CFGR_AWD1SGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN8, converted by either group regular or injected */
  866. #define LL_ADC_AWD_CHANNEL_9_REG ((LL_ADC_CHANNEL_9 & ADC_CHANNEL_ID_MASK) | ADC_CFGR_AWD1EN | ADC_CFGR_AWD1SGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN9, converted by group regular only */
  867. #define LL_ADC_AWD_CHANNEL_9_INJ ((LL_ADC_CHANNEL_9 & ADC_CHANNEL_ID_MASK) | ADC_CFGR_JAWD1EN | ADC_CFGR_AWD1SGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN9, converted by group injected only */
  868. #define LL_ADC_AWD_CHANNEL_9_REG_INJ ((LL_ADC_CHANNEL_9 & ADC_CHANNEL_ID_MASK) | ADC_CFGR_JAWD1EN | ADC_CFGR_AWD1EN | ADC_CFGR_AWD1SGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN9, converted by either group regular or injected */
  869. #define LL_ADC_AWD_CHANNEL_10_REG ((LL_ADC_CHANNEL_10 & ADC_CHANNEL_ID_MASK) | ADC_CFGR_AWD1EN | ADC_CFGR_AWD1SGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN10, converted by group regular only */
  870. #define LL_ADC_AWD_CHANNEL_10_INJ ((LL_ADC_CHANNEL_10 & ADC_CHANNEL_ID_MASK) | ADC_CFGR_JAWD1EN | ADC_CFGR_AWD1SGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN10, converted by group injected only */
  871. #define LL_ADC_AWD_CHANNEL_10_REG_INJ ((LL_ADC_CHANNEL_10 & ADC_CHANNEL_ID_MASK) | ADC_CFGR_JAWD1EN | ADC_CFGR_AWD1EN | ADC_CFGR_AWD1SGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN10, converted by either group regular or injected */
  872. #define LL_ADC_AWD_CHANNEL_11_REG ((LL_ADC_CHANNEL_11 & ADC_CHANNEL_ID_MASK) | ADC_CFGR_AWD1EN | ADC_CFGR_AWD1SGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN11, converted by group regular only */
  873. #define LL_ADC_AWD_CHANNEL_11_INJ ((LL_ADC_CHANNEL_11 & ADC_CHANNEL_ID_MASK) | ADC_CFGR_JAWD1EN | ADC_CFGR_AWD1SGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN11, converted by group injected only */
  874. #define LL_ADC_AWD_CHANNEL_11_REG_INJ ((LL_ADC_CHANNEL_11 & ADC_CHANNEL_ID_MASK) | ADC_CFGR_JAWD1EN | ADC_CFGR_AWD1EN | ADC_CFGR_AWD1SGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN11, converted by either group regular or injected */
  875. #define LL_ADC_AWD_CHANNEL_12_REG ((LL_ADC_CHANNEL_12 & ADC_CHANNEL_ID_MASK) | ADC_CFGR_AWD1EN | ADC_CFGR_AWD1SGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN12, converted by group regular only */
  876. #define LL_ADC_AWD_CHANNEL_12_INJ ((LL_ADC_CHANNEL_12 & ADC_CHANNEL_ID_MASK) | ADC_CFGR_JAWD1EN | ADC_CFGR_AWD1SGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN12, converted by group injected only */
  877. #define LL_ADC_AWD_CHANNEL_12_REG_INJ ((LL_ADC_CHANNEL_12 & ADC_CHANNEL_ID_MASK) | ADC_CFGR_JAWD1EN | ADC_CFGR_AWD1EN | ADC_CFGR_AWD1SGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN12, converted by either group regular or injected */
  878. #define LL_ADC_AWD_CHANNEL_13_REG ((LL_ADC_CHANNEL_13 & ADC_CHANNEL_ID_MASK) | ADC_CFGR_AWD1EN | ADC_CFGR_AWD1SGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN13, converted by group regular only */
  879. #define LL_ADC_AWD_CHANNEL_13_INJ ((LL_ADC_CHANNEL_13 & ADC_CHANNEL_ID_MASK) | ADC_CFGR_JAWD1EN | ADC_CFGR_AWD1SGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN13, converted by group injected only */
  880. #define LL_ADC_AWD_CHANNEL_13_REG_INJ ((LL_ADC_CHANNEL_13 & ADC_CHANNEL_ID_MASK) | ADC_CFGR_JAWD1EN | ADC_CFGR_AWD1EN | ADC_CFGR_AWD1SGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN13, converted by either group regular or injected */
  881. #define LL_ADC_AWD_CHANNEL_14_REG ((LL_ADC_CHANNEL_14 & ADC_CHANNEL_ID_MASK) | ADC_CFGR_AWD1EN | ADC_CFGR_AWD1SGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN14, converted by group regular only */
  882. #define LL_ADC_AWD_CHANNEL_14_INJ ((LL_ADC_CHANNEL_14 & ADC_CHANNEL_ID_MASK) | ADC_CFGR_JAWD1EN | ADC_CFGR_AWD1SGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN14, converted by group injected only */
  883. #define LL_ADC_AWD_CHANNEL_14_REG_INJ ((LL_ADC_CHANNEL_14 & ADC_CHANNEL_ID_MASK) | ADC_CFGR_JAWD1EN | ADC_CFGR_AWD1EN | ADC_CFGR_AWD1SGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN14, converted by either group regular or injected */
  884. #define LL_ADC_AWD_CHANNEL_15_REG ((LL_ADC_CHANNEL_15 & ADC_CHANNEL_ID_MASK) | ADC_CFGR_AWD1EN | ADC_CFGR_AWD1SGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN15, converted by group regular only */
  885. #define LL_ADC_AWD_CHANNEL_15_INJ ((LL_ADC_CHANNEL_15 & ADC_CHANNEL_ID_MASK) | ADC_CFGR_JAWD1EN | ADC_CFGR_AWD1SGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN15, converted by group injected only */
  886. #define LL_ADC_AWD_CHANNEL_15_REG_INJ ((LL_ADC_CHANNEL_15 & ADC_CHANNEL_ID_MASK) | ADC_CFGR_JAWD1EN | ADC_CFGR_AWD1EN | ADC_CFGR_AWD1SGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN15, converted by either group regular or injected */
  887. #define LL_ADC_AWD_CHANNEL_16_REG ((LL_ADC_CHANNEL_16 & ADC_CHANNEL_ID_MASK) | ADC_CFGR_AWD1EN | ADC_CFGR_AWD1SGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN16, converted by group regular only */
  888. #define LL_ADC_AWD_CHANNEL_16_INJ ((LL_ADC_CHANNEL_16 & ADC_CHANNEL_ID_MASK) | ADC_CFGR_JAWD1EN | ADC_CFGR_AWD1SGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN16, converted by group injected only */
  889. #define LL_ADC_AWD_CHANNEL_16_REG_INJ ((LL_ADC_CHANNEL_16 & ADC_CHANNEL_ID_MASK) | ADC_CFGR_JAWD1EN | ADC_CFGR_AWD1EN | ADC_CFGR_AWD1SGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN16, converted by either group regular or injected */
  890. #define LL_ADC_AWD_CHANNEL_17_REG ((LL_ADC_CHANNEL_17 & ADC_CHANNEL_ID_MASK) | ADC_CFGR_AWD1EN | ADC_CFGR_AWD1SGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN17, converted by group regular only */
  891. #define LL_ADC_AWD_CHANNEL_17_INJ ((LL_ADC_CHANNEL_17 & ADC_CHANNEL_ID_MASK) | ADC_CFGR_JAWD1EN | ADC_CFGR_AWD1SGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN17, converted by group injected only */
  892. #define LL_ADC_AWD_CHANNEL_17_REG_INJ ((LL_ADC_CHANNEL_17 & ADC_CHANNEL_ID_MASK) | ADC_CFGR_JAWD1EN | ADC_CFGR_AWD1EN | ADC_CFGR_AWD1SGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN17, converted by either group regular or injected */
  893. #define LL_ADC_AWD_CHANNEL_18_REG ((LL_ADC_CHANNEL_18 & ADC_CHANNEL_ID_MASK) | ADC_CFGR_AWD1EN | ADC_CFGR_AWD1SGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN18, converted by group regular only */
  894. #define LL_ADC_AWD_CHANNEL_18_INJ ((LL_ADC_CHANNEL_18 & ADC_CHANNEL_ID_MASK) | ADC_CFGR_JAWD1EN | ADC_CFGR_AWD1SGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN18, converted by group injected only */
  895. #define LL_ADC_AWD_CHANNEL_18_REG_INJ ((LL_ADC_CHANNEL_18 & ADC_CHANNEL_ID_MASK) | ADC_CFGR_JAWD1EN | ADC_CFGR_AWD1EN | ADC_CFGR_AWD1SGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN18, converted by either group regular or injected */
  896. #define LL_ADC_AWD_CH_VREFINT_REG ((LL_ADC_CHANNEL_VREFINT & ADC_CHANNEL_ID_MASK) | ADC_CFGR_AWD1EN | ADC_CFGR_AWD1SGL) /*!< ADC analog watchdog monitoring of ADC internal channel connected to VrefInt: Internal voltage reference, converted by group regular only */
  897. #define LL_ADC_AWD_CH_VREFINT_INJ ((LL_ADC_CHANNEL_VREFINT & ADC_CHANNEL_ID_MASK) | ADC_CFGR_JAWD1EN | ADC_CFGR_AWD1SGL) /*!< ADC analog watchdog monitoring of ADC internal channel connected to VrefInt: Internal voltage reference, converted by group injected only */
  898. #define LL_ADC_AWD_CH_VREFINT_REG_INJ ((LL_ADC_CHANNEL_VREFINT & ADC_CHANNEL_ID_MASK) | ADC_CFGR_JAWD1EN | ADC_CFGR_AWD1EN | ADC_CFGR_AWD1SGL) /*!< ADC analog watchdog monitoring of ADC internal channel connected to VrefInt: Internal voltage reference, converted by either group regular or injected */
  899. #define LL_ADC_AWD_CH_TEMPSENSOR_REG ((LL_ADC_CHANNEL_TEMPSENSOR & ADC_CHANNEL_ID_MASK) | ADC_CFGR_AWD1EN | ADC_CFGR_AWD1SGL) /*!< ADC analog watchdog monitoring of ADC internal channel connected to Temperature sensor, converted by group regular only */
  900. #define LL_ADC_AWD_CH_TEMPSENSOR_INJ ((LL_ADC_CHANNEL_TEMPSENSOR & ADC_CHANNEL_ID_MASK) | ADC_CFGR_JAWD1EN | ADC_CFGR_AWD1SGL) /*!< ADC analog watchdog monitoring of ADC internal channel connected to Temperature sensor, converted by group injected only */
  901. #define LL_ADC_AWD_CH_TEMPSENSOR_REG_INJ ((LL_ADC_CHANNEL_TEMPSENSOR & ADC_CHANNEL_ID_MASK) | ADC_CFGR_JAWD1EN | ADC_CFGR_AWD1EN | ADC_CFGR_AWD1SGL) /*!< ADC analog watchdog monitoring of ADC internal channel connected to Temperature sensor, converted by either group regular or injected */
  902. #define LL_ADC_AWD_CH_VBAT_REG ((LL_ADC_CHANNEL_VBAT & ADC_CHANNEL_ID_MASK) | ADC_CFGR_AWD1EN | ADC_CFGR_AWD1SGL) /*!< ADC analog watchdog monitoring of ADC internal channel connected to Vbat/3: Vbat voltage through a divider ladder of factor 1/3 to have Vbat always below Vdda, converted by group regular only */
  903. #define LL_ADC_AWD_CH_VBAT_INJ ((LL_ADC_CHANNEL_VBAT & ADC_CHANNEL_ID_MASK) | ADC_CFGR_JAWD1EN | ADC_CFGR_AWD1SGL) /*!< ADC analog watchdog monitoring of ADC internal channel connected to Vbat/3: Vbat voltage through a divider ladder of factor 1/3 to have Vbat always below Vdda, converted by group injected only */
  904. #define LL_ADC_AWD_CH_VBAT_REG_INJ ((LL_ADC_CHANNEL_VBAT & ADC_CHANNEL_ID_MASK) | ADC_CFGR_JAWD1EN | ADC_CFGR_AWD1EN | ADC_CFGR_AWD1SGL) /*!< ADC analog watchdog monitoring of ADC internal channel connected to Vbat/3: Vbat voltage through a divider ladder of factor 1/3 to have Vbat always below Vdda */
  905. /**
  906. * @}
  907. */
  908. /** @defgroup ADC_LL_EC_AWD_THRESHOLDS Analog watchdog - Thresholds
  909. * @{
  910. */
  911. #define LL_ADC_AWD_THRESHOLD_HIGH (ADC_TR1_HT1 ) /*!< ADC analog watchdog threshold high */
  912. #define LL_ADC_AWD_THRESHOLD_LOW ( ADC_TR1_LT1) /*!< ADC analog watchdog threshold low */
  913. #define LL_ADC_AWD_THRESHOLDS_HIGH_LOW (ADC_TR1_HT1 | ADC_TR1_LT1) /*!< ADC analog watchdog both thresholds high and low concatenated into the same data */
  914. /**
  915. * @}
  916. */
  917. /** @defgroup ADC_LL_EC_OVS_SCOPE Oversampling - Oversampling scope
  918. * @{
  919. */
  920. #define LL_ADC_OVS_DISABLE (0x00000000UL) /*!< ADC oversampling disabled. */
  921. #define LL_ADC_OVS_GRP_REGULAR_CONTINUED ( ADC_CFGR2_ROVSE) /*!< ADC oversampling on conversions of ADC group regular. If group injected interrupts group regular: when ADC group injected is triggered, the oversampling on ADC group regular is temporary stopped and continued afterwards. */
  922. #define LL_ADC_OVS_GRP_REGULAR_RESUMED (ADC_CFGR2_ROVSM | ADC_CFGR2_ROVSE) /*!< ADC oversampling on conversions of ADC group regular. If group injected interrupts group regular: when ADC group injected is triggered, the oversampling on ADC group regular is resumed from start (oversampler buffer reset). */
  923. #define LL_ADC_OVS_GRP_INJECTED ( ADC_CFGR2_JOVSE ) /*!< ADC oversampling on conversions of ADC group injected. */
  924. #define LL_ADC_OVS_GRP_INJ_REG_RESUMED ( ADC_CFGR2_JOVSE | ADC_CFGR2_ROVSE) /*!< ADC oversampling on conversions of both ADC groups regular and injected. If group injected interrupting group regular: when ADC group injected is triggered, the oversampling on ADC group regular is resumed from start (oversampler buffer reset). */
  925. /**
  926. * @}
  927. */
  928. /** @defgroup ADC_LL_EC_OVS_DISCONT_MODE Oversampling - Discontinuous mode
  929. * @{
  930. */
  931. #define LL_ADC_OVS_REG_CONT (0x00000000UL) /*!< ADC oversampling discontinuous mode: continuous mode (all conversions of oversampling ratio are done from 1 trigger) */
  932. #define LL_ADC_OVS_REG_DISCONT (ADC_CFGR2_TROVS) /*!< ADC oversampling discontinuous mode: discontinuous mode (each conversion of oversampling ratio needs a trigger) */
  933. /**
  934. * @}
  935. */
  936. /** @defgroup ADC_LL_EC_OVS_RATIO Oversampling - Ratio
  937. * @{
  938. */
  939. #define LL_ADC_OVS_RATIO_2 (0x00000000UL) /*!< ADC oversampling ratio of 2 (2 ADC conversions are performed, sum of these conversions data is computed to result as the ADC oversampling conversion data (before potential shift) */
  940. #define LL_ADC_OVS_RATIO_4 ( ADC_CFGR2_OVSR_0) /*!< ADC oversampling ratio of 4 (4 ADC conversions are performed, sum of these conversions data is computed to result as the ADC oversampling conversion data (before potential shift) */
  941. #define LL_ADC_OVS_RATIO_8 ( ADC_CFGR2_OVSR_1 ) /*!< ADC oversampling ratio of 8 (8 ADC conversions are performed, sum of these conversions data is computed to result as the ADC oversampling conversion data (before potential shift) */
  942. #define LL_ADC_OVS_RATIO_16 ( ADC_CFGR2_OVSR_1 | ADC_CFGR2_OVSR_0) /*!< ADC oversampling ratio of 16 (16 ADC conversions are performed, sum of these conversions data is computed to result as the ADC oversampling conversion data (before potential shift) */
  943. #define LL_ADC_OVS_RATIO_32 (ADC_CFGR2_OVSR_2 ) /*!< ADC oversampling ratio of 32 (32 ADC conversions are performed, sum of these conversions data is computed to result as the ADC oversampling conversion data (before potential shift) */
  944. #define LL_ADC_OVS_RATIO_64 (ADC_CFGR2_OVSR_2 | ADC_CFGR2_OVSR_0) /*!< ADC oversampling ratio of 64 (64 ADC conversions are performed, sum of these conversions data is computed to result as the ADC oversampling conversion data (before potential shift) */
  945. #define LL_ADC_OVS_RATIO_128 (ADC_CFGR2_OVSR_2 | ADC_CFGR2_OVSR_1 ) /*!< ADC oversampling ratio of 128 (128 ADC conversions are performed, sum of these conversions data is computed to result as the ADC oversampling conversion data (before potential shift) */
  946. #define LL_ADC_OVS_RATIO_256 (ADC_CFGR2_OVSR_2 | ADC_CFGR2_OVSR_1 | ADC_CFGR2_OVSR_0) /*!< ADC oversampling ratio of 256 (256 ADC conversions are performed, sum of these conversions data is computed to result as the ADC oversampling conversion data (before potential shift) */
  947. /**
  948. * @}
  949. */
  950. /** @defgroup ADC_LL_EC_OVS_SHIFT Oversampling - Data shift
  951. * @{
  952. */
  953. #define LL_ADC_OVS_SHIFT_NONE (0x00000000UL) /*!< ADC oversampling no shift (sum of the ADC conversions data is not divided to result as the ADC oversampling conversion data) */
  954. #define LL_ADC_OVS_SHIFT_RIGHT_1 ( ADC_CFGR2_OVSS_0) /*!< ADC oversampling shift of 1 (sum of the ADC conversions data is divided by 2 to result as the ADC oversampling conversion data) */
  955. #define LL_ADC_OVS_SHIFT_RIGHT_2 ( ADC_CFGR2_OVSS_1 ) /*!< ADC oversampling shift of 2 (sum of the ADC conversions data is divided by 4 to result as the ADC oversampling conversion data) */
  956. #define LL_ADC_OVS_SHIFT_RIGHT_3 ( ADC_CFGR2_OVSS_1 | ADC_CFGR2_OVSS_0) /*!< ADC oversampling shift of 3 (sum of the ADC conversions data is divided by 8 to result as the ADC oversampling conversion data) */
  957. #define LL_ADC_OVS_SHIFT_RIGHT_4 ( ADC_CFGR2_OVSS_2 ) /*!< ADC oversampling shift of 4 (sum of the ADC conversions data is divided by 16 to result as the ADC oversampling conversion data) */
  958. #define LL_ADC_OVS_SHIFT_RIGHT_5 ( ADC_CFGR2_OVSS_2 | ADC_CFGR2_OVSS_0) /*!< ADC oversampling shift of 5 (sum of the ADC conversions data is divided by 32 to result as the ADC oversampling conversion data) */
  959. #define LL_ADC_OVS_SHIFT_RIGHT_6 ( ADC_CFGR2_OVSS_2 | ADC_CFGR2_OVSS_1 ) /*!< ADC oversampling shift of 6 (sum of the ADC conversions data is divided by 64 to result as the ADC oversampling conversion data) */
  960. #define LL_ADC_OVS_SHIFT_RIGHT_7 ( ADC_CFGR2_OVSS_2 | ADC_CFGR2_OVSS_1 | ADC_CFGR2_OVSS_0) /*!< ADC oversampling shift of 7 (sum of the ADC conversions data is divided by 128 to result as the ADC oversampling conversion data) */
  961. #define LL_ADC_OVS_SHIFT_RIGHT_8 (ADC_CFGR2_OVSS_3 ) /*!< ADC oversampling shift of 8 (sum of the ADC conversions data is divided by 256 to result as the ADC oversampling conversion data) */
  962. /**
  963. * @}
  964. */
  965. /** @defgroup ADC_LL_EC_HW_DELAYS Definitions of ADC hardware constraints delays
  966. * @note Only ADC peripheral HW delays are defined in ADC LL driver driver,
  967. * not timeout values.
  968. * For details on delays values, refer to descriptions in source code
  969. * above each literal definition.
  970. * @{
  971. */
  972. /* Note: Only ADC peripheral HW delays are defined in ADC LL driver driver, */
  973. /* not timeout values. */
  974. /* Timeout values for ADC operations are dependent to device clock */
  975. /* configuration (system clock versus ADC clock), */
  976. /* and therefore must be defined in user application. */
  977. /* Indications for estimation of ADC timeout delays, for this */
  978. /* STM32 serie: */
  979. /* - ADC calibration time: maximum delay is 112/fADC. */
  980. /* (refer to device datasheet, parameter "tCAL") */
  981. /* - ADC enable time: maximum delay is 1 conversion cycle. */
  982. /* (refer to device datasheet, parameter "tSTAB") */
  983. /* - ADC disable time: maximum delay should be a few ADC clock cycles */
  984. /* - ADC stop conversion time: maximum delay should be a few ADC clock */
  985. /* cycles */
  986. /* - ADC conversion time: duration depending on ADC clock and ADC */
  987. /* configuration. */
  988. /* (refer to device reference manual, section "Timing") */
  989. /* Delay for ADC stabilization time (ADC voltage regulator start-up time) */
  990. /* Delay set to maximum value (refer to device datasheet, */
  991. /* parameter "tADCVREG_STUP"). */
  992. /* Unit: us */
  993. #define LL_ADC_DELAY_INTERNAL_REGUL_STAB_US ( 10UL) /*!< Delay for ADC stabilization time (ADC voltage regulator start-up time) */
  994. /* Delay for internal voltage reference stabilization time. */
  995. /* Delay set to maximum value (refer to device datasheet, */
  996. /* parameter "tstart_vrefint"). */
  997. /* Unit: us */
  998. #define LL_ADC_DELAY_VREFINT_STAB_US ( 12UL) /*!< Delay for internal voltage reference stabilization time */
  999. /* Delay for temperature sensor stabilization time. */
  1000. /* Literal set to maximum value (refer to device datasheet, */
  1001. /* parameter "tSTART"). */
  1002. /* Unit: us */
  1003. #define LL_ADC_DELAY_TEMPSENSOR_STAB_US (120UL) /*!< Delay for temperature sensor stabilization time */
  1004. /* Delay required between ADC end of calibration and ADC enable. */
  1005. /* Note: On this STM32 serie, a minimum number of ADC clock cycles */
  1006. /* are required between ADC end of calibration and ADC enable. */
  1007. /* Wait time can be computed in user application by waiting for the */
  1008. /* equivalent number of CPU cycles, by taking into account */
  1009. /* ratio of CPU clock versus ADC clock prescalers. */
  1010. /* Unit: ADC clock cycles. */
  1011. #define LL_ADC_DELAY_CALIB_ENABLE_ADC_CYCLES ( 4UL) /*!< Delay required between ADC end of calibration and ADC enable */
  1012. /**
  1013. * @}
  1014. */
  1015. /**
  1016. * @}
  1017. */
  1018. /* Exported macro ------------------------------------------------------------*/
  1019. /** @defgroup ADC_LL_Exported_Macros ADC Exported Macros
  1020. * @{
  1021. */
  1022. /** @defgroup ADC_LL_EM_WRITE_READ Common write and read registers Macros
  1023. * @{
  1024. */
  1025. /**
  1026. * @brief Write a value in ADC register
  1027. * @param __INSTANCE__ ADC Instance
  1028. * @param __REG__ Register to be written
  1029. * @param __VALUE__ Value to be written in the register
  1030. * @retval None
  1031. */
  1032. #define LL_ADC_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__))
  1033. /**
  1034. * @brief Read a value in ADC register
  1035. * @param __INSTANCE__ ADC Instance
  1036. * @param __REG__ Register to be read
  1037. * @retval Register value
  1038. */
  1039. #define LL_ADC_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
  1040. /**
  1041. * @}
  1042. */
  1043. /** @defgroup ADC_LL_EM_HELPER_MACRO ADC helper macro
  1044. * @{
  1045. */
  1046. /**
  1047. * @brief Helper macro to get ADC channel number in decimal format
  1048. * from literals LL_ADC_CHANNEL_x.
  1049. * @note Example:
  1050. * __LL_ADC_CHANNEL_TO_DECIMAL_NB(LL_ADC_CHANNEL_4)
  1051. * will return decimal number "4".
  1052. * @note The input can be a value from functions where a channel
  1053. * number is returned, either defined with number
  1054. * or with bitfield (only one bit must be set).
  1055. * @param __CHANNEL__ This parameter can be one of the following values:
  1056. * @arg @ref LL_ADC_CHANNEL_0
  1057. * @arg @ref LL_ADC_CHANNEL_1 (7)
  1058. * @arg @ref LL_ADC_CHANNEL_2 (7)
  1059. * @arg @ref LL_ADC_CHANNEL_3 (7)
  1060. * @arg @ref LL_ADC_CHANNEL_4 (7)
  1061. * @arg @ref LL_ADC_CHANNEL_5 (7)
  1062. * @arg @ref LL_ADC_CHANNEL_6
  1063. * @arg @ref LL_ADC_CHANNEL_7
  1064. * @arg @ref LL_ADC_CHANNEL_8
  1065. * @arg @ref LL_ADC_CHANNEL_9
  1066. * @arg @ref LL_ADC_CHANNEL_10
  1067. * @arg @ref LL_ADC_CHANNEL_11
  1068. * @arg @ref LL_ADC_CHANNEL_12
  1069. * @arg @ref LL_ADC_CHANNEL_13
  1070. * @arg @ref LL_ADC_CHANNEL_14
  1071. * @arg @ref LL_ADC_CHANNEL_15
  1072. * @arg @ref LL_ADC_CHANNEL_16
  1073. * @arg @ref LL_ADC_CHANNEL_17
  1074. * @arg @ref LL_ADC_CHANNEL_18
  1075. * @arg @ref LL_ADC_CHANNEL_VREFINT
  1076. * @arg @ref LL_ADC_CHANNEL_TEMPSENSOR
  1077. * @arg @ref LL_ADC_CHANNEL_VBAT
  1078. *
  1079. * (7) On STM32WB, fast channel (0.188 us for 12-bit resolution (ADC conversion rate up to 5.33 Ms/s)).
  1080. * Other channels are slow channels (0.238 us for 12-bit resolution (ADC conversion rate up to 4.21 Ms/s)).
  1081. * @retval Value between Min_Data=0 and Max_Data=18
  1082. */
  1083. #define __LL_ADC_CHANNEL_TO_DECIMAL_NB(__CHANNEL__) \
  1084. ((((__CHANNEL__) & ADC_CHANNEL_ID_BITFIELD_MASK) == 0UL) \
  1085. ? ( \
  1086. ((__CHANNEL__) & ADC_CHANNEL_ID_NUMBER_MASK) >> ADC_CHANNEL_ID_NUMBER_BITOFFSET_POS \
  1087. ) \
  1088. : \
  1089. ( \
  1090. (uint32_t)POSITION_VAL((__CHANNEL__)) \
  1091. ) \
  1092. )
  1093. /**
  1094. * @brief Helper macro to get ADC channel in literal format LL_ADC_CHANNEL_x
  1095. * from number in decimal format.
  1096. * @note Example:
  1097. * __LL_ADC_DECIMAL_NB_TO_CHANNEL(4)
  1098. * will return a data equivalent to "LL_ADC_CHANNEL_4".
  1099. * @param __DECIMAL_NB__ Value between Min_Data=0 and Max_Data=18
  1100. * @retval Returned value can be one of the following values:
  1101. * @arg @ref LL_ADC_CHANNEL_0
  1102. * @arg @ref LL_ADC_CHANNEL_1 (7)
  1103. * @arg @ref LL_ADC_CHANNEL_2 (7)
  1104. * @arg @ref LL_ADC_CHANNEL_3 (7)
  1105. * @arg @ref LL_ADC_CHANNEL_4 (7)
  1106. * @arg @ref LL_ADC_CHANNEL_5 (7)
  1107. * @arg @ref LL_ADC_CHANNEL_6
  1108. * @arg @ref LL_ADC_CHANNEL_7
  1109. * @arg @ref LL_ADC_CHANNEL_8
  1110. * @arg @ref LL_ADC_CHANNEL_9
  1111. * @arg @ref LL_ADC_CHANNEL_10
  1112. * @arg @ref LL_ADC_CHANNEL_11
  1113. * @arg @ref LL_ADC_CHANNEL_12
  1114. * @arg @ref LL_ADC_CHANNEL_13
  1115. * @arg @ref LL_ADC_CHANNEL_14
  1116. * @arg @ref LL_ADC_CHANNEL_15
  1117. * @arg @ref LL_ADC_CHANNEL_16
  1118. * @arg @ref LL_ADC_CHANNEL_17
  1119. * @arg @ref LL_ADC_CHANNEL_18
  1120. * @arg @ref LL_ADC_CHANNEL_VREFINT (1)
  1121. * @arg @ref LL_ADC_CHANNEL_TEMPSENSOR (4)
  1122. * @arg @ref LL_ADC_CHANNEL_VBAT (4)
  1123. *
  1124. * (7) On STM32WB, fast channel (0.188 us for 12-bit resolution (ADC conversion rate up to 5.33 Ms/s)).
  1125. * Other channels are slow channels (0.238 us for 12-bit resolution (ADC conversion rate up to 4.21 Ms/s)).\n
  1126. * (4) For ADC channel read back from ADC register,
  1127. * comparison with internal channel parameter to be done
  1128. * using helper macro @ref __LL_ADC_CHANNEL_INTERNAL_TO_EXTERNAL().
  1129. */
  1130. #define __LL_ADC_DECIMAL_NB_TO_CHANNEL(__DECIMAL_NB__) \
  1131. (((__DECIMAL_NB__) <= 9UL) \
  1132. ? ( \
  1133. ((__DECIMAL_NB__) << ADC_CHANNEL_ID_NUMBER_BITOFFSET_POS) | \
  1134. (ADC_AWD2CR_AWD2CH_0 << (__DECIMAL_NB__)) | \
  1135. (ADC_SMPR1_REGOFFSET | (((3UL * (__DECIMAL_NB__))) << ADC_CHANNEL_SMPx_BITOFFSET_POS)) \
  1136. ) \
  1137. : \
  1138. ( \
  1139. ((__DECIMAL_NB__) << ADC_CHANNEL_ID_NUMBER_BITOFFSET_POS) | \
  1140. (ADC_AWD2CR_AWD2CH_0 << (__DECIMAL_NB__)) | \
  1141. (ADC_SMPR2_REGOFFSET | (((3UL * ((__DECIMAL_NB__) - 10UL))) << ADC_CHANNEL_SMPx_BITOFFSET_POS)) \
  1142. ) \
  1143. )
  1144. /**
  1145. * @brief Helper macro to determine whether the selected channel
  1146. * corresponds to literal definitions of driver.
  1147. * @note The different literal definitions of ADC channels are:
  1148. * - ADC internal channel:
  1149. * LL_ADC_CHANNEL_VREFINT, LL_ADC_CHANNEL_TEMPSENSOR, ...
  1150. * - ADC external channel (channel connected to a GPIO pin):
  1151. * LL_ADC_CHANNEL_1, LL_ADC_CHANNEL_2, ...
  1152. * @note The channel parameter must be a value defined from literal
  1153. * definition of a ADC internal channel (LL_ADC_CHANNEL_VREFINT,
  1154. * LL_ADC_CHANNEL_TEMPSENSOR, ...),
  1155. * ADC external channel (LL_ADC_CHANNEL_1, LL_ADC_CHANNEL_2, ...),
  1156. * must not be a value from functions where a channel number is
  1157. * returned from ADC registers,
  1158. * because internal and external channels share the same channel
  1159. * number in ADC registers. The differentiation is made only with
  1160. * parameters definitions of driver.
  1161. * @param __CHANNEL__ This parameter can be one of the following values:
  1162. * @arg @ref LL_ADC_CHANNEL_0
  1163. * @arg @ref LL_ADC_CHANNEL_1 (7)
  1164. * @arg @ref LL_ADC_CHANNEL_2 (7)
  1165. * @arg @ref LL_ADC_CHANNEL_3 (7)
  1166. * @arg @ref LL_ADC_CHANNEL_4 (7)
  1167. * @arg @ref LL_ADC_CHANNEL_5 (7)
  1168. * @arg @ref LL_ADC_CHANNEL_6
  1169. * @arg @ref LL_ADC_CHANNEL_7
  1170. * @arg @ref LL_ADC_CHANNEL_8
  1171. * @arg @ref LL_ADC_CHANNEL_9
  1172. * @arg @ref LL_ADC_CHANNEL_10
  1173. * @arg @ref LL_ADC_CHANNEL_11
  1174. * @arg @ref LL_ADC_CHANNEL_12
  1175. * @arg @ref LL_ADC_CHANNEL_13
  1176. * @arg @ref LL_ADC_CHANNEL_14
  1177. * @arg @ref LL_ADC_CHANNEL_15
  1178. * @arg @ref LL_ADC_CHANNEL_16
  1179. * @arg @ref LL_ADC_CHANNEL_17
  1180. * @arg @ref LL_ADC_CHANNEL_18
  1181. * @arg @ref LL_ADC_CHANNEL_VREFINT
  1182. * @arg @ref LL_ADC_CHANNEL_TEMPSENSOR
  1183. * @arg @ref LL_ADC_CHANNEL_VBAT
  1184. *
  1185. * (7) On STM32WB, fast channel (0.188 us for 12-bit resolution (ADC conversion rate up to 5.33 Ms/s)).
  1186. * Other channels are slow channels (0.238 us for 12-bit resolution (ADC conversion rate up to 4.21 Ms/s)).
  1187. * @retval Value "0" if the channel corresponds to a parameter definition of a ADC external channel (channel connected to a GPIO pin).
  1188. * Value "1" if the channel corresponds to a parameter definition of a ADC internal channel.
  1189. */
  1190. #define __LL_ADC_IS_CHANNEL_INTERNAL(__CHANNEL__) \
  1191. (((__CHANNEL__) & ADC_CHANNEL_ID_INTERNAL_CH_MASK) != 0UL)
  1192. /**
  1193. * @brief Helper macro to convert a channel defined from parameter
  1194. * definition of a ADC internal channel (LL_ADC_CHANNEL_VREFINT,
  1195. * LL_ADC_CHANNEL_TEMPSENSOR, ...),
  1196. * to its equivalent parameter definition of a ADC external channel
  1197. * (LL_ADC_CHANNEL_1, LL_ADC_CHANNEL_2, ...).
  1198. * @note The channel parameter can be, additionally to a value
  1199. * defined from parameter definition of a ADC internal channel
  1200. * (LL_ADC_CHANNEL_VREFINT, LL_ADC_CHANNEL_TEMPSENSOR, ...),
  1201. * a value defined from parameter definition of
  1202. * ADC external channel (LL_ADC_CHANNEL_1, LL_ADC_CHANNEL_2, ...)
  1203. * or a value from functions where a channel number is returned
  1204. * from ADC registers.
  1205. * @param __CHANNEL__ This parameter can be one of the following values:
  1206. * @arg @ref LL_ADC_CHANNEL_0
  1207. * @arg @ref LL_ADC_CHANNEL_1 (7)
  1208. * @arg @ref LL_ADC_CHANNEL_2 (7)
  1209. * @arg @ref LL_ADC_CHANNEL_3 (7)
  1210. * @arg @ref LL_ADC_CHANNEL_4 (7)
  1211. * @arg @ref LL_ADC_CHANNEL_5 (7)
  1212. * @arg @ref LL_ADC_CHANNEL_6
  1213. * @arg @ref LL_ADC_CHANNEL_7
  1214. * @arg @ref LL_ADC_CHANNEL_8
  1215. * @arg @ref LL_ADC_CHANNEL_9
  1216. * @arg @ref LL_ADC_CHANNEL_10
  1217. * @arg @ref LL_ADC_CHANNEL_11
  1218. * @arg @ref LL_ADC_CHANNEL_12
  1219. * @arg @ref LL_ADC_CHANNEL_13
  1220. * @arg @ref LL_ADC_CHANNEL_14
  1221. * @arg @ref LL_ADC_CHANNEL_15
  1222. * @arg @ref LL_ADC_CHANNEL_16
  1223. * @arg @ref LL_ADC_CHANNEL_17
  1224. * @arg @ref LL_ADC_CHANNEL_18
  1225. * @arg @ref LL_ADC_CHANNEL_VREFINT
  1226. * @arg @ref LL_ADC_CHANNEL_TEMPSENSOR
  1227. * @arg @ref LL_ADC_CHANNEL_VBAT
  1228. *
  1229. * (7) On STM32WB, fast channel (0.188 us for 12-bit resolution (ADC conversion rate up to 5.33 Ms/s)).
  1230. * Other channels are slow channels (0.238 us for 12-bit resolution (ADC conversion rate up to 4.21 Ms/s)).
  1231. * @retval Returned value can be one of the following values:
  1232. * @arg @ref LL_ADC_CHANNEL_0
  1233. * @arg @ref LL_ADC_CHANNEL_1
  1234. * @arg @ref LL_ADC_CHANNEL_2
  1235. * @arg @ref LL_ADC_CHANNEL_3
  1236. * @arg @ref LL_ADC_CHANNEL_4
  1237. * @arg @ref LL_ADC_CHANNEL_5
  1238. * @arg @ref LL_ADC_CHANNEL_6
  1239. * @arg @ref LL_ADC_CHANNEL_7
  1240. * @arg @ref LL_ADC_CHANNEL_8
  1241. * @arg @ref LL_ADC_CHANNEL_9
  1242. * @arg @ref LL_ADC_CHANNEL_10
  1243. * @arg @ref LL_ADC_CHANNEL_11
  1244. * @arg @ref LL_ADC_CHANNEL_12
  1245. * @arg @ref LL_ADC_CHANNEL_13
  1246. * @arg @ref LL_ADC_CHANNEL_14
  1247. * @arg @ref LL_ADC_CHANNEL_15
  1248. * @arg @ref LL_ADC_CHANNEL_16
  1249. * @arg @ref LL_ADC_CHANNEL_17
  1250. * @arg @ref LL_ADC_CHANNEL_18
  1251. */
  1252. #define __LL_ADC_CHANNEL_INTERNAL_TO_EXTERNAL(__CHANNEL__) \
  1253. ((__CHANNEL__) & ~ADC_CHANNEL_ID_INTERNAL_CH_MASK)
  1254. /**
  1255. * @brief Helper macro to determine whether the internal channel
  1256. * selected is available on the ADC instance selected.
  1257. * @note The channel parameter must be a value defined from parameter
  1258. * definition of a ADC internal channel (LL_ADC_CHANNEL_VREFINT,
  1259. * LL_ADC_CHANNEL_TEMPSENSOR, ...),
  1260. * must not be a value defined from parameter definition of
  1261. * ADC external channel (LL_ADC_CHANNEL_1, LL_ADC_CHANNEL_2, ...)
  1262. * or a value from functions where a channel number is
  1263. * returned from ADC registers,
  1264. * because internal and external channels share the same channel
  1265. * number in ADC registers. The differentiation is made only with
  1266. * parameters definitions of driver.
  1267. * @param __ADC_INSTANCE__ ADC instance
  1268. * @param __CHANNEL__ This parameter can be one of the following values:
  1269. * @arg @ref LL_ADC_CHANNEL_VREFINT
  1270. * @arg @ref LL_ADC_CHANNEL_TEMPSENSOR
  1271. * @arg @ref LL_ADC_CHANNEL_VBAT
  1272. * @retval Value "0" if the internal channel selected is not available on the ADC instance selected.
  1273. * Value "1" if the internal channel selected is available on the ADC instance selected.
  1274. */
  1275. #define __LL_ADC_IS_CHANNEL_INTERNAL_AVAILABLE(__ADC_INSTANCE__, __CHANNEL__) \
  1276. ( \
  1277. ((__CHANNEL__) == LL_ADC_CHANNEL_VREFINT) || \
  1278. ((__CHANNEL__) == LL_ADC_CHANNEL_TEMPSENSOR) || \
  1279. ((__CHANNEL__) == LL_ADC_CHANNEL_VBAT) \
  1280. )
  1281. /**
  1282. * @brief Helper macro to define ADC analog watchdog parameter:
  1283. * define a single channel to monitor with analog watchdog
  1284. * from sequencer channel and groups definition.
  1285. * @note To be used with function @ref LL_ADC_SetAnalogWDMonitChannels().
  1286. * Example:
  1287. * LL_ADC_SetAnalogWDMonitChannels(
  1288. * ADC1, LL_ADC_AWD1,
  1289. * __LL_ADC_ANALOGWD_CHANNEL_GROUP(LL_ADC_CHANNEL4, LL_ADC_GROUP_REGULAR))
  1290. * @param __CHANNEL__ This parameter can be one of the following values:
  1291. * @arg @ref LL_ADC_CHANNEL_0
  1292. * @arg @ref LL_ADC_CHANNEL_1 (7)
  1293. * @arg @ref LL_ADC_CHANNEL_2 (7)
  1294. * @arg @ref LL_ADC_CHANNEL_3 (7)
  1295. * @arg @ref LL_ADC_CHANNEL_4 (7)
  1296. * @arg @ref LL_ADC_CHANNEL_5 (7)
  1297. * @arg @ref LL_ADC_CHANNEL_6
  1298. * @arg @ref LL_ADC_CHANNEL_7
  1299. * @arg @ref LL_ADC_CHANNEL_8
  1300. * @arg @ref LL_ADC_CHANNEL_9
  1301. * @arg @ref LL_ADC_CHANNEL_10
  1302. * @arg @ref LL_ADC_CHANNEL_11
  1303. * @arg @ref LL_ADC_CHANNEL_12
  1304. * @arg @ref LL_ADC_CHANNEL_13
  1305. * @arg @ref LL_ADC_CHANNEL_14
  1306. * @arg @ref LL_ADC_CHANNEL_15
  1307. * @arg @ref LL_ADC_CHANNEL_16
  1308. * @arg @ref LL_ADC_CHANNEL_17
  1309. * @arg @ref LL_ADC_CHANNEL_18
  1310. * @arg @ref LL_ADC_CHANNEL_VREFINT (1)
  1311. * @arg @ref LL_ADC_CHANNEL_TEMPSENSOR (4)
  1312. * @arg @ref LL_ADC_CHANNEL_VBAT (4)
  1313. *
  1314. * (7) On STM32WB, fast channel (0.188 us for 12-bit resolution (ADC conversion rate up to 5.33 Ms/s)).
  1315. * Other channels are slow channels (0.238 us for 12-bit resolution (ADC conversion rate up to 4.21 Ms/s)).\n
  1316. * (4) For ADC channel read back from ADC register,
  1317. * comparison with internal channel parameter to be done
  1318. * using helper macro @ref __LL_ADC_CHANNEL_INTERNAL_TO_EXTERNAL().
  1319. * @param __GROUP__ This parameter can be one of the following values:
  1320. * @arg @ref LL_ADC_GROUP_REGULAR
  1321. * @arg @ref LL_ADC_GROUP_INJECTED
  1322. * @arg @ref LL_ADC_GROUP_REGULAR_INJECTED
  1323. * @retval Returned value can be one of the following values:
  1324. * @arg @ref LL_ADC_AWD_DISABLE
  1325. * @arg @ref LL_ADC_AWD_ALL_CHANNELS_REG (0)
  1326. * @arg @ref LL_ADC_AWD_ALL_CHANNELS_INJ (0)
  1327. * @arg @ref LL_ADC_AWD_ALL_CHANNELS_REG_INJ
  1328. * @arg @ref LL_ADC_AWD_CHANNEL_0_REG (0)
  1329. * @arg @ref LL_ADC_AWD_CHANNEL_0_INJ (0)
  1330. * @arg @ref LL_ADC_AWD_CHANNEL_0_REG_INJ
  1331. * @arg @ref LL_ADC_AWD_CHANNEL_1_REG (0)
  1332. * @arg @ref LL_ADC_AWD_CHANNEL_1_INJ (0)
  1333. * @arg @ref LL_ADC_AWD_CHANNEL_1_REG_INJ
  1334. * @arg @ref LL_ADC_AWD_CHANNEL_2_REG (0)
  1335. * @arg @ref LL_ADC_AWD_CHANNEL_2_INJ (0)
  1336. * @arg @ref LL_ADC_AWD_CHANNEL_2_REG_INJ
  1337. * @arg @ref LL_ADC_AWD_CHANNEL_3_REG (0)
  1338. * @arg @ref LL_ADC_AWD_CHANNEL_3_INJ (0)
  1339. * @arg @ref LL_ADC_AWD_CHANNEL_3_REG_INJ
  1340. * @arg @ref LL_ADC_AWD_CHANNEL_4_REG (0)
  1341. * @arg @ref LL_ADC_AWD_CHANNEL_4_INJ (0)
  1342. * @arg @ref LL_ADC_AWD_CHANNEL_4_REG_INJ
  1343. * @arg @ref LL_ADC_AWD_CHANNEL_5_REG (0)
  1344. * @arg @ref LL_ADC_AWD_CHANNEL_5_INJ (0)
  1345. * @arg @ref LL_ADC_AWD_CHANNEL_5_REG_INJ
  1346. * @arg @ref LL_ADC_AWD_CHANNEL_6_REG (0)
  1347. * @arg @ref LL_ADC_AWD_CHANNEL_6_INJ (0)
  1348. * @arg @ref LL_ADC_AWD_CHANNEL_6_REG_INJ
  1349. * @arg @ref LL_ADC_AWD_CHANNEL_7_REG (0)
  1350. * @arg @ref LL_ADC_AWD_CHANNEL_7_INJ (0)
  1351. * @arg @ref LL_ADC_AWD_CHANNEL_7_REG_INJ
  1352. * @arg @ref LL_ADC_AWD_CHANNEL_8_REG (0)
  1353. * @arg @ref LL_ADC_AWD_CHANNEL_8_INJ (0)
  1354. * @arg @ref LL_ADC_AWD_CHANNEL_8_REG_INJ
  1355. * @arg @ref LL_ADC_AWD_CHANNEL_9_REG (0)
  1356. * @arg @ref LL_ADC_AWD_CHANNEL_9_INJ (0)
  1357. * @arg @ref LL_ADC_AWD_CHANNEL_9_REG_INJ
  1358. * @arg @ref LL_ADC_AWD_CHANNEL_10_REG (0)
  1359. * @arg @ref LL_ADC_AWD_CHANNEL_10_INJ (0)
  1360. * @arg @ref LL_ADC_AWD_CHANNEL_10_REG_INJ
  1361. * @arg @ref LL_ADC_AWD_CHANNEL_11_REG (0)
  1362. * @arg @ref LL_ADC_AWD_CHANNEL_11_INJ (0)
  1363. * @arg @ref LL_ADC_AWD_CHANNEL_11_REG_INJ
  1364. * @arg @ref LL_ADC_AWD_CHANNEL_12_REG (0)
  1365. * @arg @ref LL_ADC_AWD_CHANNEL_12_INJ (0)
  1366. * @arg @ref LL_ADC_AWD_CHANNEL_12_REG_INJ
  1367. * @arg @ref LL_ADC_AWD_CHANNEL_13_REG (0)
  1368. * @arg @ref LL_ADC_AWD_CHANNEL_13_INJ (0)
  1369. * @arg @ref LL_ADC_AWD_CHANNEL_13_REG_INJ
  1370. * @arg @ref LL_ADC_AWD_CHANNEL_14_REG (0)
  1371. * @arg @ref LL_ADC_AWD_CHANNEL_14_INJ (0)
  1372. * @arg @ref LL_ADC_AWD_CHANNEL_14_REG_INJ
  1373. * @arg @ref LL_ADC_AWD_CHANNEL_15_REG (0)
  1374. * @arg @ref LL_ADC_AWD_CHANNEL_15_INJ (0)
  1375. * @arg @ref LL_ADC_AWD_CHANNEL_15_REG_INJ
  1376. * @arg @ref LL_ADC_AWD_CHANNEL_16_REG (0)
  1377. * @arg @ref LL_ADC_AWD_CHANNEL_16_INJ (0)
  1378. * @arg @ref LL_ADC_AWD_CHANNEL_16_REG_INJ
  1379. * @arg @ref LL_ADC_AWD_CHANNEL_17_REG (0)
  1380. * @arg @ref LL_ADC_AWD_CHANNEL_17_INJ (0)
  1381. * @arg @ref LL_ADC_AWD_CHANNEL_17_REG_INJ
  1382. * @arg @ref LL_ADC_AWD_CHANNEL_18_REG (0)
  1383. * @arg @ref LL_ADC_AWD_CHANNEL_18_INJ (0)
  1384. * @arg @ref LL_ADC_AWD_CHANNEL_18_REG_INJ
  1385. * @arg @ref LL_ADC_AWD_CH_VREFINT_REG (0)
  1386. * @arg @ref LL_ADC_AWD_CH_VREFINT_INJ (0)
  1387. * @arg @ref LL_ADC_AWD_CH_VREFINT_REG_INJ
  1388. * @arg @ref LL_ADC_AWD_CH_TEMPSENSOR_REG (0)
  1389. * @arg @ref LL_ADC_AWD_CH_TEMPSENSOR_INJ (0)
  1390. * @arg @ref LL_ADC_AWD_CH_TEMPSENSOR_REG_INJ
  1391. * @arg @ref LL_ADC_AWD_CH_VBAT_REG (0)
  1392. * @arg @ref LL_ADC_AWD_CH_VBAT_INJ (0)
  1393. * @arg @ref LL_ADC_AWD_CH_VBAT_REG_INJ
  1394. *
  1395. * (0) On STM32WB, parameter available only on analog watchdog number: AWD1.
  1396. */
  1397. #define __LL_ADC_ANALOGWD_CHANNEL_GROUP(__CHANNEL__, __GROUP__) \
  1398. (((__GROUP__) == LL_ADC_GROUP_REGULAR) \
  1399. ? (((__CHANNEL__) & ADC_CHANNEL_ID_MASK) | ADC_CFGR_AWD1EN | ADC_CFGR_AWD1SGL) \
  1400. : \
  1401. ((__GROUP__) == LL_ADC_GROUP_INJECTED) \
  1402. ? (((__CHANNEL__) & ADC_CHANNEL_ID_MASK) | ADC_CFGR_JAWD1EN | ADC_CFGR_AWD1SGL) \
  1403. : \
  1404. (((__CHANNEL__) & ADC_CHANNEL_ID_MASK) | ADC_CFGR_JAWD1EN | ADC_CFGR_AWD1EN | ADC_CFGR_AWD1SGL) \
  1405. )
  1406. /**
  1407. * @brief Helper macro to set the value of ADC analog watchdog threshold high
  1408. * or low in function of ADC resolution, when ADC resolution is
  1409. * different of 12 bits.
  1410. * @note To be used with function @ref LL_ADC_ConfigAnalogWDThresholds()
  1411. * or @ref LL_ADC_SetAnalogWDThresholds().
  1412. * Example, with a ADC resolution of 8 bits, to set the value of
  1413. * analog watchdog threshold high (on 8 bits):
  1414. * LL_ADC_SetAnalogWDThresholds
  1415. * (< ADCx param >,
  1416. * __LL_ADC_ANALOGWD_SET_THRESHOLD_RESOLUTION(LL_ADC_RESOLUTION_8B, <threshold_value_8_bits>)
  1417. * );
  1418. * @param __ADC_RESOLUTION__ This parameter can be one of the following values:
  1419. * @arg @ref LL_ADC_RESOLUTION_12B
  1420. * @arg @ref LL_ADC_RESOLUTION_10B
  1421. * @arg @ref LL_ADC_RESOLUTION_8B
  1422. * @arg @ref LL_ADC_RESOLUTION_6B
  1423. * @param __AWD_THRESHOLD__ Value between Min_Data=0x000 and Max_Data=0xFFF
  1424. * @retval Value between Min_Data=0x000 and Max_Data=0xFFF
  1425. */
  1426. #define __LL_ADC_ANALOGWD_SET_THRESHOLD_RESOLUTION(__ADC_RESOLUTION__, __AWD_THRESHOLD__) \
  1427. ((__AWD_THRESHOLD__) << ((__ADC_RESOLUTION__) >> (ADC_CFGR_RES_BITOFFSET_POS - 1U )))
  1428. /**
  1429. * @brief Helper macro to get the value of ADC analog watchdog threshold high
  1430. * or low in function of ADC resolution, when ADC resolution is
  1431. * different of 12 bits.
  1432. * @note To be used with function @ref LL_ADC_GetAnalogWDThresholds().
  1433. * Example, with a ADC resolution of 8 bits, to get the value of
  1434. * analog watchdog threshold high (on 8 bits):
  1435. * < threshold_value_6_bits > = __LL_ADC_ANALOGWD_GET_THRESHOLD_RESOLUTION
  1436. * (LL_ADC_RESOLUTION_8B,
  1437. * LL_ADC_GetAnalogWDThresholds(<ADCx param>, LL_ADC_AWD_THRESHOLD_HIGH)
  1438. * );
  1439. * @param __ADC_RESOLUTION__ This parameter can be one of the following values:
  1440. * @arg @ref LL_ADC_RESOLUTION_12B
  1441. * @arg @ref LL_ADC_RESOLUTION_10B
  1442. * @arg @ref LL_ADC_RESOLUTION_8B
  1443. * @arg @ref LL_ADC_RESOLUTION_6B
  1444. * @param __AWD_THRESHOLD_12_BITS__ Value between Min_Data=0x000 and Max_Data=0xFFF
  1445. * @retval Value between Min_Data=0x000 and Max_Data=0xFFF
  1446. */
  1447. #define __LL_ADC_ANALOGWD_GET_THRESHOLD_RESOLUTION(__ADC_RESOLUTION__, __AWD_THRESHOLD_12_BITS__) \
  1448. ((__AWD_THRESHOLD_12_BITS__) >> ((__ADC_RESOLUTION__) >> (ADC_CFGR_RES_BITOFFSET_POS - 1U )))
  1449. /**
  1450. * @brief Helper macro to get the ADC analog watchdog threshold high
  1451. * or low from raw value containing both thresholds concatenated.
  1452. * @note To be used with function @ref LL_ADC_GetAnalogWDThresholds().
  1453. * Example, to get analog watchdog threshold high from the register raw value:
  1454. * __LL_ADC_ANALOGWD_THRESHOLDS_HIGH_LOW(LL_ADC_AWD_THRESHOLD_HIGH, <raw_value_with_both_thresholds>);
  1455. * @param __AWD_THRESHOLD_TYPE__ This parameter can be one of the following values:
  1456. * @arg @ref LL_ADC_AWD_THRESHOLD_HIGH
  1457. * @arg @ref LL_ADC_AWD_THRESHOLD_LOW
  1458. * @param __AWD_THRESHOLDS__ Value between Min_Data=0x00000000 and Max_Data=0xFFFFFFFF
  1459. * @retval Value between Min_Data=0x000 and Max_Data=0xFFF
  1460. */
  1461. #define __LL_ADC_ANALOGWD_THRESHOLDS_HIGH_LOW(__AWD_THRESHOLD_TYPE__, __AWD_THRESHOLDS__) \
  1462. (((__AWD_THRESHOLDS__) >> (((__AWD_THRESHOLD_TYPE__) & ADC_AWD_TRX_BIT_HIGH_MASK) >> ADC_AWD_TRX_BIT_HIGH_SHIFT4)) & LL_ADC_AWD_THRESHOLD_LOW)
  1463. /**
  1464. * @brief Helper macro to set the ADC calibration value with both single ended
  1465. * and differential modes calibration factors concatenated.
  1466. * @note To be used with function @ref LL_ADC_SetCalibrationFactor().
  1467. * Example, to set calibration factors single ended to 0x55
  1468. * and differential ended to 0x2A:
  1469. * LL_ADC_SetCalibrationFactor(
  1470. * ADC1,
  1471. * __LL_ADC_CALIB_FACTOR_SINGLE_DIFF(0x55, 0x2A))
  1472. * @param __CALIB_FACTOR_SINGLE_ENDED__ Value between Min_Data=0x00 and Max_Data=0x7F
  1473. * @param __CALIB_FACTOR_DIFFERENTIAL__ Value between Min_Data=0x00 and Max_Data=0x7F
  1474. * @retval Value between Min_Data=0x00000000 and Max_Data=0xFFFFFFFF
  1475. */
  1476. #define __LL_ADC_CALIB_FACTOR_SINGLE_DIFF(__CALIB_FACTOR_SINGLE_ENDED__, __CALIB_FACTOR_DIFFERENTIAL__) \
  1477. (((__CALIB_FACTOR_DIFFERENTIAL__) << ADC_CALFACT_CALFACT_D_Pos) | (__CALIB_FACTOR_SINGLE_ENDED__))
  1478. /**
  1479. * @brief Helper macro to select the ADC common instance
  1480. * to which is belonging the selected ADC instance.
  1481. * @note ADC common register instance can be used for:
  1482. * - Set parameters common to several ADC instances
  1483. * - Multimode (for devices with several ADC instances)
  1484. * Refer to functions having argument "ADCxy_COMMON" as parameter.
  1485. * @param __ADCx__ ADC instance
  1486. * @retval ADC common register instance
  1487. */
  1488. #if defined(ADC1) && defined(ADC2) && defined(ADC3)
  1489. #define __LL_ADC_COMMON_INSTANCE(__ADCx__) \
  1490. (ADC123_COMMON)
  1491. #elif defined(ADC1) && defined(ADC2)
  1492. #define __LL_ADC_COMMON_INSTANCE(__ADCx__) \
  1493. (ADC12_COMMON)
  1494. #else
  1495. #define __LL_ADC_COMMON_INSTANCE(__ADCx__) \
  1496. (ADC1_COMMON)
  1497. #endif
  1498. /**
  1499. * @brief Helper macro to check if all ADC instances sharing the same
  1500. * ADC common instance are disabled.
  1501. * @note This check is required by functions with setting conditioned to
  1502. * ADC state:
  1503. * All ADC instances of the ADC common group must be disabled.
  1504. * Refer to functions having argument "ADCxy_COMMON" as parameter.
  1505. * @note On devices with only 1 ADC common instance, parameter of this macro
  1506. * is useless and can be ignored (parameter kept for compatibility
  1507. * with devices featuring several ADC common instances).
  1508. * @param __ADCXY_COMMON__ ADC common instance
  1509. * (can be set directly from CMSIS definition or by using helper macro @ref __LL_ADC_COMMON_INSTANCE() )
  1510. * @retval Value "0" if all ADC instances sharing the same ADC common instance
  1511. * are disabled.
  1512. * Value "1" if at least one ADC instance sharing the same ADC common instance
  1513. * is enabled.
  1514. */
  1515. #if defined(ADC1) && defined(ADC2) && defined(ADC3)
  1516. #define __LL_ADC_IS_ENABLED_ALL_COMMON_INSTANCE(__ADCXY_COMMON__) \
  1517. (LL_ADC_IsEnabled(ADC1) | \
  1518. LL_ADC_IsEnabled(ADC2) | \
  1519. LL_ADC_IsEnabled(ADC3) )
  1520. #elif defined(ADC1) && defined(ADC2)
  1521. #define __LL_ADC_IS_ENABLED_ALL_COMMON_INSTANCE(__ADCXY_COMMON__) \
  1522. (LL_ADC_IsEnabled(ADC1) | \
  1523. LL_ADC_IsEnabled(ADC2) )
  1524. #else
  1525. #define __LL_ADC_IS_ENABLED_ALL_COMMON_INSTANCE(__ADCXY_COMMON__) \
  1526. (LL_ADC_IsEnabled(ADC1))
  1527. #endif
  1528. /**
  1529. * @brief Helper macro to define the ADC conversion data full-scale digital
  1530. * value corresponding to the selected ADC resolution.
  1531. * @note ADC conversion data full-scale corresponds to voltage range
  1532. * determined by analog voltage references Vref+ and Vref-
  1533. * (refer to reference manual).
  1534. * @param __ADC_RESOLUTION__ This parameter can be one of the following values:
  1535. * @arg @ref LL_ADC_RESOLUTION_12B
  1536. * @arg @ref LL_ADC_RESOLUTION_10B
  1537. * @arg @ref LL_ADC_RESOLUTION_8B
  1538. * @arg @ref LL_ADC_RESOLUTION_6B
  1539. * @retval ADC conversion data full-scale digital value (unit: digital value of ADC conversion data)
  1540. */
  1541. #define __LL_ADC_DIGITAL_SCALE(__ADC_RESOLUTION__) \
  1542. (0xFFFUL >> ((__ADC_RESOLUTION__) >> (ADC_CFGR_RES_BITOFFSET_POS - 1UL)))
  1543. /**
  1544. * @brief Helper macro to convert the ADC conversion data from
  1545. * a resolution to another resolution.
  1546. * @param __DATA__ ADC conversion data to be converted
  1547. * @param __ADC_RESOLUTION_CURRENT__ Resolution of the data to be converted
  1548. * This parameter can be one of the following values:
  1549. * @arg @ref LL_ADC_RESOLUTION_12B
  1550. * @arg @ref LL_ADC_RESOLUTION_10B
  1551. * @arg @ref LL_ADC_RESOLUTION_8B
  1552. * @arg @ref LL_ADC_RESOLUTION_6B
  1553. * @param __ADC_RESOLUTION_TARGET__ Resolution of the data after conversion
  1554. * This parameter can be one of the following values:
  1555. * @arg @ref LL_ADC_RESOLUTION_12B
  1556. * @arg @ref LL_ADC_RESOLUTION_10B
  1557. * @arg @ref LL_ADC_RESOLUTION_8B
  1558. * @arg @ref LL_ADC_RESOLUTION_6B
  1559. * @retval ADC conversion data to the requested resolution
  1560. */
  1561. #define __LL_ADC_CONVERT_DATA_RESOLUTION(__DATA__,\
  1562. __ADC_RESOLUTION_CURRENT__,\
  1563. __ADC_RESOLUTION_TARGET__) \
  1564. (((__DATA__) \
  1565. << ((__ADC_RESOLUTION_CURRENT__) >> (ADC_CFGR_RES_BITOFFSET_POS - 1UL))) \
  1566. >> ((__ADC_RESOLUTION_TARGET__) >> (ADC_CFGR_RES_BITOFFSET_POS - 1UL)) \
  1567. )
  1568. /**
  1569. * @brief Helper macro to calculate the voltage (unit: mVolt)
  1570. * corresponding to a ADC conversion data (unit: digital value).
  1571. * @note Analog reference voltage (Vref+) must be either known from
  1572. * user board environment or can be calculated using ADC measurement
  1573. * and ADC helper macro @ref __LL_ADC_CALC_VREFANALOG_VOLTAGE().
  1574. * @param __VREFANALOG_VOLTAGE__ Analog reference voltage (unit: mV)
  1575. * @param __ADC_DATA__ ADC conversion data (resolution 12 bits)
  1576. * (unit: digital value).
  1577. * @param __ADC_RESOLUTION__ This parameter can be one of the following values:
  1578. * @arg @ref LL_ADC_RESOLUTION_12B
  1579. * @arg @ref LL_ADC_RESOLUTION_10B
  1580. * @arg @ref LL_ADC_RESOLUTION_8B
  1581. * @arg @ref LL_ADC_RESOLUTION_6B
  1582. * @retval ADC conversion data equivalent voltage value (unit: mVolt)
  1583. */
  1584. #define __LL_ADC_CALC_DATA_TO_VOLTAGE(__VREFANALOG_VOLTAGE__,\
  1585. __ADC_DATA__,\
  1586. __ADC_RESOLUTION__) \
  1587. ((__ADC_DATA__) * (__VREFANALOG_VOLTAGE__) \
  1588. / __LL_ADC_DIGITAL_SCALE(__ADC_RESOLUTION__) \
  1589. )
  1590. /**
  1591. * @brief Helper macro to calculate analog reference voltage (Vref+)
  1592. * (unit: mVolt) from ADC conversion data of internal voltage
  1593. * reference VrefInt.
  1594. * @note Computation is using VrefInt calibration value
  1595. * stored in system memory for each device during production.
  1596. * @note This voltage depends on user board environment: voltage level
  1597. * connected to pin Vref+.
  1598. * On devices with small package, the pin Vref+ is not present
  1599. * and internally bonded to pin Vdda.
  1600. * @note On this STM32 serie, calibration data of internal voltage reference
  1601. * VrefInt corresponds to a resolution of 12 bits,
  1602. * this is the recommended ADC resolution to convert voltage of
  1603. * internal voltage reference VrefInt.
  1604. * Otherwise, this macro performs the processing to scale
  1605. * ADC conversion data to 12 bits.
  1606. * @param __VREFINT_ADC_DATA__ ADC conversion data (resolution 12 bits)
  1607. * of internal voltage reference VrefInt (unit: digital value).
  1608. * @param __ADC_RESOLUTION__ This parameter can be one of the following values:
  1609. * @arg @ref LL_ADC_RESOLUTION_12B
  1610. * @arg @ref LL_ADC_RESOLUTION_10B
  1611. * @arg @ref LL_ADC_RESOLUTION_8B
  1612. * @arg @ref LL_ADC_RESOLUTION_6B
  1613. * @retval Analog reference voltage (unit: mV)
  1614. */
  1615. #define __LL_ADC_CALC_VREFANALOG_VOLTAGE(__VREFINT_ADC_DATA__,\
  1616. __ADC_RESOLUTION__) \
  1617. (((uint32_t)(*VREFINT_CAL_ADDR) * VREFINT_CAL_VREF) \
  1618. / __LL_ADC_CONVERT_DATA_RESOLUTION((__VREFINT_ADC_DATA__), \
  1619. (__ADC_RESOLUTION__), \
  1620. LL_ADC_RESOLUTION_12B) \
  1621. )
  1622. /**
  1623. * @brief Helper macro to calculate the temperature (unit: degree Celsius)
  1624. * from ADC conversion data of internal temperature sensor.
  1625. * @note Computation is using temperature sensor calibration values
  1626. * stored in system memory for each device during production.
  1627. * @note Calculation formula:
  1628. * Temperature = ((TS_ADC_DATA - TS_CAL1)
  1629. * * (TS_CAL2_TEMP - TS_CAL1_TEMP))
  1630. * / (TS_CAL2 - TS_CAL1) + TS_CAL1_TEMP
  1631. * with TS_ADC_DATA = temperature sensor raw data measured by ADC
  1632. * Avg_Slope = (TS_CAL2 - TS_CAL1)
  1633. * / (TS_CAL2_TEMP - TS_CAL1_TEMP)
  1634. * TS_CAL1 = equivalent TS_ADC_DATA at temperature
  1635. * TEMP_DEGC_CAL1 (calibrated in factory)
  1636. * TS_CAL2 = equivalent TS_ADC_DATA at temperature
  1637. * TEMP_DEGC_CAL2 (calibrated in factory)
  1638. * Caution: Calculation relevancy under reserve that calibration
  1639. * parameters are correct (address and data).
  1640. * To calculate temperature using temperature sensor
  1641. * datasheet typical values (generic values less, therefore
  1642. * less accurate than calibrated values),
  1643. * use helper macro @ref __LL_ADC_CALC_TEMPERATURE_TYP_PARAMS().
  1644. * @note As calculation input, the analog reference voltage (Vref+) must be
  1645. * defined as it impacts the ADC LSB equivalent voltage.
  1646. * @note Analog reference voltage (Vref+) must be either known from
  1647. * user board environment or can be calculated using ADC measurement
  1648. * and ADC helper macro @ref __LL_ADC_CALC_VREFANALOG_VOLTAGE().
  1649. * @note On this STM32 serie, calibration data of temperature sensor
  1650. * corresponds to a resolution of 12 bits,
  1651. * this is the recommended ADC resolution to convert voltage of
  1652. * temperature sensor.
  1653. * Otherwise, this macro performs the processing to scale
  1654. * ADC conversion data to 12 bits.
  1655. * @param __VREFANALOG_VOLTAGE__ Analog reference voltage (unit: mV)
  1656. * @param __TEMPSENSOR_ADC_DATA__ ADC conversion data of internal
  1657. * temperature sensor (unit: digital value).
  1658. * @param __ADC_RESOLUTION__ ADC resolution at which internal temperature
  1659. * sensor voltage has been measured.
  1660. * This parameter can be one of the following values:
  1661. * @arg @ref LL_ADC_RESOLUTION_12B
  1662. * @arg @ref LL_ADC_RESOLUTION_10B
  1663. * @arg @ref LL_ADC_RESOLUTION_8B
  1664. * @arg @ref LL_ADC_RESOLUTION_6B
  1665. * @retval Temperature (unit: degree Celsius)
  1666. */
  1667. #define __LL_ADC_CALC_TEMPERATURE(__VREFANALOG_VOLTAGE__,\
  1668. __TEMPSENSOR_ADC_DATA__,\
  1669. __ADC_RESOLUTION__) \
  1670. (((( ((int32_t)((__LL_ADC_CONVERT_DATA_RESOLUTION((__TEMPSENSOR_ADC_DATA__), \
  1671. (__ADC_RESOLUTION__), \
  1672. LL_ADC_RESOLUTION_12B) \
  1673. * (__VREFANALOG_VOLTAGE__)) \
  1674. / TEMPSENSOR_CAL_VREFANALOG) \
  1675. - (int32_t) *TEMPSENSOR_CAL1_ADDR) \
  1676. ) * (int32_t)(TEMPSENSOR_CAL2_TEMP - TEMPSENSOR_CAL1_TEMP) \
  1677. ) / (int32_t)((int32_t)*TEMPSENSOR_CAL2_ADDR - (int32_t)*TEMPSENSOR_CAL1_ADDR) \
  1678. ) + TEMPSENSOR_CAL1_TEMP \
  1679. )
  1680. /**
  1681. * @brief Helper macro to calculate the temperature (unit: degree Celsius)
  1682. * from ADC conversion data of internal temperature sensor.
  1683. * @note Computation is using temperature sensor typical values
  1684. * (refer to device datasheet).
  1685. * @note Calculation formula:
  1686. * Temperature = (TS_TYP_CALx_VOLT(uV) - TS_ADC_DATA * Conversion_uV)
  1687. * / Avg_Slope + CALx_TEMP
  1688. * with TS_ADC_DATA = temperature sensor raw data measured by ADC
  1689. * (unit: digital value)
  1690. * Avg_Slope = temperature sensor slope
  1691. * (unit: uV/Degree Celsius)
  1692. * TS_TYP_CALx_VOLT = temperature sensor digital value at
  1693. * temperature CALx_TEMP (unit: mV)
  1694. * Caution: Calculation relevancy under reserve the temperature sensor
  1695. * of the current device has characteristics in line with
  1696. * datasheet typical values.
  1697. * If temperature sensor calibration values are available on
  1698. * on this device (presence of macro __LL_ADC_CALC_TEMPERATURE()),
  1699. * temperature calculation will be more accurate using
  1700. * helper macro @ref __LL_ADC_CALC_TEMPERATURE().
  1701. * @note As calculation input, the analog reference voltage (Vref+) must be
  1702. * defined as it impacts the ADC LSB equivalent voltage.
  1703. * @note Analog reference voltage (Vref+) must be either known from
  1704. * user board environment or can be calculated using ADC measurement
  1705. * and ADC helper macro @ref __LL_ADC_CALC_VREFANALOG_VOLTAGE().
  1706. * @note ADC measurement data must correspond to a resolution of 12 bits
  1707. * (full scale digital value 4095). If not the case, the data must be
  1708. * preliminarily rescaled to an equivalent resolution of 12 bits.
  1709. * @param __TEMPSENSOR_TYP_AVGSLOPE__ Device datasheet data: Temperature sensor slope typical value (unit: uV/DegCelsius).
  1710. * On STM32WB, refer to device datasheet parameter "Avg_Slope".
  1711. * @param __TEMPSENSOR_TYP_CALX_V__ Device datasheet data: Temperature sensor voltage typical value (at temperature and Vref+ defined in parameters below) (unit: mV).
  1712. * On STM32WB, refer to device datasheet parameter "V30" (corresponding to TS_CAL1).
  1713. * @param __TEMPSENSOR_CALX_TEMP__ Device datasheet data: Temperature at which temperature sensor voltage (see parameter above) is corresponding (unit: mV)
  1714. * @param __VREFANALOG_VOLTAGE__ Analog voltage reference (Vref+) voltage (unit: mV)
  1715. * @param __TEMPSENSOR_ADC_DATA__ ADC conversion data of internal temperature sensor (unit: digital value).
  1716. * @param __ADC_RESOLUTION__ ADC resolution at which internal temperature sensor voltage has been measured.
  1717. * This parameter can be one of the following values:
  1718. * @arg @ref LL_ADC_RESOLUTION_12B
  1719. * @arg @ref LL_ADC_RESOLUTION_10B
  1720. * @arg @ref LL_ADC_RESOLUTION_8B
  1721. * @arg @ref LL_ADC_RESOLUTION_6B
  1722. * @retval Temperature (unit: degree Celsius)
  1723. */
  1724. #define __LL_ADC_CALC_TEMPERATURE_TYP_PARAMS(__TEMPSENSOR_TYP_AVGSLOPE__,\
  1725. __TEMPSENSOR_TYP_CALX_V__,\
  1726. __TEMPSENSOR_CALX_TEMP__,\
  1727. __VREFANALOG_VOLTAGE__,\
  1728. __TEMPSENSOR_ADC_DATA__,\
  1729. __ADC_RESOLUTION__) \
  1730. ((( ( \
  1731. (int32_t)((((__TEMPSENSOR_ADC_DATA__) * (__VREFANALOG_VOLTAGE__)) \
  1732. / __LL_ADC_DIGITAL_SCALE(__ADC_RESOLUTION__)) \
  1733. * 1000UL) \
  1734. - \
  1735. (int32_t)(((__TEMPSENSOR_TYP_CALX_V__)) \
  1736. * 1000UL) \
  1737. ) \
  1738. ) / (int32_t)(__TEMPSENSOR_TYP_AVGSLOPE__) \
  1739. ) + (int32_t)(__TEMPSENSOR_CALX_TEMP__) \
  1740. )
  1741. /**
  1742. * @}
  1743. */
  1744. /**
  1745. * @}
  1746. */
  1747. /* Exported functions --------------------------------------------------------*/
  1748. /** @defgroup ADC_LL_Exported_Functions ADC Exported Functions
  1749. * @{
  1750. */
  1751. /** @defgroup ADC_LL_EF_DMA_Management ADC DMA management
  1752. * @{
  1753. */
  1754. /* Note: LL ADC functions to set DMA transfer are located into sections of */
  1755. /* configuration of ADC instance, groups and multimode (if available): */
  1756. /* @ref LL_ADC_REG_SetDMATransfer(), ... */
  1757. /**
  1758. * @brief Function to help to configure DMA transfer from ADC: retrieve the
  1759. * ADC register address from ADC instance and a list of ADC registers
  1760. * intended to be used (most commonly) with DMA transfer.
  1761. * @note These ADC registers are data registers:
  1762. * when ADC conversion data is available in ADC data registers,
  1763. * ADC generates a DMA transfer request.
  1764. * @note This macro is intended to be used with LL DMA driver, refer to
  1765. * function "LL_DMA_ConfigAddresses()".
  1766. * Example:
  1767. * LL_DMA_ConfigAddresses(DMA1,
  1768. * LL_DMA_CHANNEL_1,
  1769. * LL_ADC_DMA_GetRegAddr(ADC1, LL_ADC_DMA_REG_REGULAR_DATA),
  1770. * (uint32_t)&< array or variable >,
  1771. * LL_DMA_DIRECTION_PERIPH_TO_MEMORY);
  1772. * @note For devices with several ADC: in multimode, some devices
  1773. * use a different data register outside of ADC instance scope
  1774. * (common data register). This macro manages this register difference,
  1775. * only ADC instance has to be set as parameter.
  1776. * @rmtoll DR DATA LL_ADC_DMA_GetRegAddr
  1777. * @param ADCx ADC instance
  1778. * @param Register This parameter can be one of the following values:
  1779. * @arg @ref LL_ADC_DMA_REG_REGULAR_DATA
  1780. * @retval ADC register address
  1781. */
  1782. __STATIC_INLINE uint32_t LL_ADC_DMA_GetRegAddr(ADC_TypeDef *ADCx, uint32_t Register)
  1783. {
  1784. /* Prevent unused argument(s) compilation warning */
  1785. (void)(Register);
  1786. /* Retrieve address of register DR */
  1787. return (uint32_t)&(ADCx->DR);
  1788. }
  1789. /**
  1790. * @}
  1791. */
  1792. /** @defgroup ADC_LL_EF_Configuration_ADC_Common Configuration of ADC hierarchical scope: common to several ADC instances
  1793. * @{
  1794. */
  1795. /**
  1796. * @brief Set parameter common to several ADC: Clock source and prescaler.
  1797. * @note On this STM32 serie, if ADC group injected is used, some
  1798. * clock ratio constraints between ADC clock and AHB clock
  1799. * must be respected.
  1800. * Refer to reference manual.
  1801. * @note On this STM32 serie, setting of this feature is conditioned to
  1802. * ADC state:
  1803. * All ADC instances of the ADC common group must be disabled.
  1804. * This check can be done with function @ref LL_ADC_IsEnabled() for each
  1805. * ADC instance or by using helper macro helper macro
  1806. * @ref __LL_ADC_IS_ENABLED_ALL_COMMON_INSTANCE().
  1807. * @rmtoll CCR CKMODE LL_ADC_SetCommonClock\n
  1808. * CCR PRESC LL_ADC_SetCommonClock
  1809. * @param ADCxy_COMMON ADC common instance
  1810. * (can be set directly from CMSIS definition or by using helper macro @ref __LL_ADC_COMMON_INSTANCE() )
  1811. * @param CommonClock This parameter can be one of the following values:
  1812. * @arg @ref LL_ADC_CLOCK_SYNC_PCLK_DIV1
  1813. * @arg @ref LL_ADC_CLOCK_SYNC_PCLK_DIV2
  1814. * @arg @ref LL_ADC_CLOCK_SYNC_PCLK_DIV4
  1815. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV1
  1816. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV2
  1817. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV4
  1818. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV6
  1819. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV8
  1820. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV10
  1821. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV12
  1822. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV16
  1823. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV32
  1824. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV64
  1825. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV128
  1826. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV256
  1827. * @retval None
  1828. */
  1829. __STATIC_INLINE void LL_ADC_SetCommonClock(ADC_Common_TypeDef *ADCxy_COMMON, uint32_t CommonClock)
  1830. {
  1831. MODIFY_REG(ADCxy_COMMON->CCR, ADC_CCR_CKMODE | ADC_CCR_PRESC, CommonClock);
  1832. }
  1833. /**
  1834. * @brief Get parameter common to several ADC: Clock source and prescaler.
  1835. * @rmtoll CCR CKMODE LL_ADC_GetCommonClock\n
  1836. * CCR PRESC LL_ADC_GetCommonClock
  1837. * @param ADCxy_COMMON ADC common instance
  1838. * (can be set directly from CMSIS definition or by using helper macro @ref __LL_ADC_COMMON_INSTANCE() )
  1839. * @retval Returned value can be one of the following values:
  1840. * @arg @ref LL_ADC_CLOCK_SYNC_PCLK_DIV1
  1841. * @arg @ref LL_ADC_CLOCK_SYNC_PCLK_DIV2
  1842. * @arg @ref LL_ADC_CLOCK_SYNC_PCLK_DIV4
  1843. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV1
  1844. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV2
  1845. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV4
  1846. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV6
  1847. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV8
  1848. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV10
  1849. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV12
  1850. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV16
  1851. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV32
  1852. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV64
  1853. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV128
  1854. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV256
  1855. */
  1856. __STATIC_INLINE uint32_t LL_ADC_GetCommonClock(ADC_Common_TypeDef *ADCxy_COMMON)
  1857. {
  1858. return (uint32_t)(READ_BIT(ADCxy_COMMON->CCR, ADC_CCR_CKMODE | ADC_CCR_PRESC));
  1859. }
  1860. /**
  1861. * @brief Set parameter common to several ADC: measurement path to internal
  1862. * channels (VrefInt, temperature sensor, ...).
  1863. * @note One or several values can be selected.
  1864. * Example: (LL_ADC_PATH_INTERNAL_VREFINT |
  1865. * LL_ADC_PATH_INTERNAL_TEMPSENSOR)
  1866. * @note Stabilization time of measurement path to internal channel:
  1867. * After enabling internal paths, before starting ADC conversion,
  1868. * a delay is required for internal voltage reference and
  1869. * temperature sensor stabilization time.
  1870. * Refer to device datasheet.
  1871. * Refer to literal @ref LL_ADC_DELAY_VREFINT_STAB_US.
  1872. * Refer to literal @ref LL_ADC_DELAY_TEMPSENSOR_STAB_US.
  1873. * @note ADC internal channel sampling time constraint:
  1874. * For ADC conversion of internal channels,
  1875. * a sampling time minimum value is required.
  1876. * Refer to device datasheet.
  1877. * @note On this STM32 serie, setting of this feature is conditioned to
  1878. * ADC state:
  1879. * All ADC instances of the ADC common group must be disabled.
  1880. * This check can be done with function @ref LL_ADC_IsEnabled() for each
  1881. * ADC instance or by using helper macro helper macro
  1882. * @ref __LL_ADC_IS_ENABLED_ALL_COMMON_INSTANCE().
  1883. * @rmtoll CCR VREFEN LL_ADC_SetCommonPathInternalCh\n
  1884. * CCR TSEN LL_ADC_SetCommonPathInternalCh\n
  1885. * CCR VBATEN LL_ADC_SetCommonPathInternalCh
  1886. * @param ADCxy_COMMON ADC common instance
  1887. * (can be set directly from CMSIS definition or by using helper macro @ref __LL_ADC_COMMON_INSTANCE() )
  1888. * @param PathInternal This parameter can be a combination of the following values:
  1889. * @arg @ref LL_ADC_PATH_INTERNAL_NONE
  1890. * @arg @ref LL_ADC_PATH_INTERNAL_VREFINT
  1891. * @arg @ref LL_ADC_PATH_INTERNAL_TEMPSENSOR
  1892. * @arg @ref LL_ADC_PATH_INTERNAL_VBAT
  1893. * @retval None
  1894. */
  1895. __STATIC_INLINE void LL_ADC_SetCommonPathInternalCh(ADC_Common_TypeDef *ADCxy_COMMON, uint32_t PathInternal)
  1896. {
  1897. MODIFY_REG(ADCxy_COMMON->CCR, ADC_CCR_VREFEN | ADC_CCR_TSEN | ADC_CCR_VBATEN, PathInternal);
  1898. }
  1899. /**
  1900. * @brief Get parameter common to several ADC: measurement path to internal
  1901. * channels (VrefInt, temperature sensor, ...).
  1902. * @note One or several values can be selected.
  1903. * Example: (LL_ADC_PATH_INTERNAL_VREFINT |
  1904. * LL_ADC_PATH_INTERNAL_TEMPSENSOR)
  1905. * @rmtoll CCR VREFEN LL_ADC_GetCommonPathInternalCh\n
  1906. * CCR TSEN LL_ADC_GetCommonPathInternalCh\n
  1907. * CCR VBATEN LL_ADC_GetCommonPathInternalCh
  1908. * @param ADCxy_COMMON ADC common instance
  1909. * (can be set directly from CMSIS definition or by using helper macro @ref __LL_ADC_COMMON_INSTANCE() )
  1910. * @retval Returned value can be a combination of the following values:
  1911. * @arg @ref LL_ADC_PATH_INTERNAL_NONE
  1912. * @arg @ref LL_ADC_PATH_INTERNAL_VREFINT
  1913. * @arg @ref LL_ADC_PATH_INTERNAL_TEMPSENSOR
  1914. * @arg @ref LL_ADC_PATH_INTERNAL_VBAT
  1915. */
  1916. __STATIC_INLINE uint32_t LL_ADC_GetCommonPathInternalCh(ADC_Common_TypeDef *ADCxy_COMMON)
  1917. {
  1918. return (uint32_t)(READ_BIT(ADCxy_COMMON->CCR, ADC_CCR_VREFEN | ADC_CCR_TSEN | ADC_CCR_VBATEN));
  1919. }
  1920. /**
  1921. * @}
  1922. */
  1923. /** @defgroup ADC_LL_EF_Configuration_ADC_Instance Configuration of ADC hierarchical scope: ADC instance
  1924. * @{
  1925. */
  1926. /**
  1927. * @brief Set ADC calibration factor in the mode single-ended
  1928. * or differential (for devices with differential mode available).
  1929. * @note This function is intended to set calibration parameters
  1930. * without having to perform a new calibration using
  1931. * @ref LL_ADC_StartCalibration().
  1932. * @note For devices with differential mode available:
  1933. * Calibration of offset is specific to each of
  1934. * single-ended and differential modes
  1935. * (calibration factor must be specified for each of these
  1936. * differential modes, if used afterwards and if the application
  1937. * requires their calibration).
  1938. * @note In case of setting calibration factors of both modes single ended
  1939. * and differential (parameter LL_ADC_BOTH_SINGLE_DIFF_ENDED):
  1940. * both calibration factors must be concatenated.
  1941. * To perform this processing, use helper macro
  1942. * @ref __LL_ADC_CALIB_FACTOR_SINGLE_DIFF().
  1943. * @note On this STM32 serie, setting of this feature is conditioned to
  1944. * ADC state:
  1945. * ADC must be enabled, without calibration on going, without conversion
  1946. * on going on group regular.
  1947. * @rmtoll CALFACT CALFACT_S LL_ADC_SetCalibrationFactor\n
  1948. * CALFACT CALFACT_D LL_ADC_SetCalibrationFactor
  1949. * @param ADCx ADC instance
  1950. * @param SingleDiff This parameter can be one of the following values:
  1951. * @arg @ref LL_ADC_SINGLE_ENDED
  1952. * @arg @ref LL_ADC_DIFFERENTIAL_ENDED
  1953. * @arg @ref LL_ADC_BOTH_SINGLE_DIFF_ENDED
  1954. * @param CalibrationFactor Value between Min_Data=0x00 and Max_Data=0x7F
  1955. * @retval None
  1956. */
  1957. __STATIC_INLINE void LL_ADC_SetCalibrationFactor(ADC_TypeDef *ADCx, uint32_t SingleDiff, uint32_t CalibrationFactor)
  1958. {
  1959. MODIFY_REG(ADCx->CALFACT,
  1960. SingleDiff & ADC_SINGLEDIFF_CALIB_FACTOR_MASK,
  1961. CalibrationFactor << (((SingleDiff & ADC_SINGLEDIFF_CALIB_F_BIT_D_MASK) >> ADC_SINGLEDIFF_CALIB_F_BIT_D_SHIFT4) & ~(SingleDiff & ADC_CALFACT_CALFACT_S)));
  1962. }
  1963. /**
  1964. * @brief Get ADC calibration factor in the mode single-ended
  1965. * or differential (for devices with differential mode available).
  1966. * @note Calibration factors are set by hardware after performing
  1967. * a calibration run using function @ref LL_ADC_StartCalibration().
  1968. * @note For devices with differential mode available:
  1969. * Calibration of offset is specific to each of
  1970. * single-ended and differential modes
  1971. * @rmtoll CALFACT CALFACT_S LL_ADC_GetCalibrationFactor\n
  1972. * CALFACT CALFACT_D LL_ADC_GetCalibrationFactor
  1973. * @param ADCx ADC instance
  1974. * @param SingleDiff This parameter can be one of the following values:
  1975. * @arg @ref LL_ADC_SINGLE_ENDED
  1976. * @arg @ref LL_ADC_DIFFERENTIAL_ENDED
  1977. * @retval Value between Min_Data=0x00 and Max_Data=0x7F
  1978. */
  1979. __STATIC_INLINE uint32_t LL_ADC_GetCalibrationFactor(ADC_TypeDef *ADCx, uint32_t SingleDiff)
  1980. {
  1981. /* Retrieve bits with position in register depending on parameter */
  1982. /* "SingleDiff". */
  1983. /* Parameter used with mask "ADC_SINGLEDIFF_CALIB_FACTOR_MASK" because */
  1984. /* containing other bits reserved for other purpose. */
  1985. return (uint32_t)(READ_BIT(ADCx->CALFACT, (SingleDiff & ADC_SINGLEDIFF_CALIB_FACTOR_MASK)) >> ((SingleDiff & ADC_SINGLEDIFF_CALIB_F_BIT_D_MASK) >> ADC_SINGLEDIFF_CALIB_F_BIT_D_SHIFT4));
  1986. }
  1987. /**
  1988. * @brief Set ADC resolution.
  1989. * Refer to reference manual for alignments formats
  1990. * dependencies to ADC resolutions.
  1991. * @note On this STM32 serie, setting of this feature is conditioned to
  1992. * ADC state:
  1993. * ADC must be disabled or enabled without conversion on going
  1994. * on either groups regular or injected.
  1995. * @rmtoll CFGR RES LL_ADC_SetResolution
  1996. * @param ADCx ADC instance
  1997. * @param Resolution This parameter can be one of the following values:
  1998. * @arg @ref LL_ADC_RESOLUTION_12B
  1999. * @arg @ref LL_ADC_RESOLUTION_10B
  2000. * @arg @ref LL_ADC_RESOLUTION_8B
  2001. * @arg @ref LL_ADC_RESOLUTION_6B
  2002. * @retval None
  2003. */
  2004. __STATIC_INLINE void LL_ADC_SetResolution(ADC_TypeDef *ADCx, uint32_t Resolution)
  2005. {
  2006. MODIFY_REG(ADCx->CFGR, ADC_CFGR_RES, Resolution);
  2007. }
  2008. /**
  2009. * @brief Get ADC resolution.
  2010. * Refer to reference manual for alignments formats
  2011. * dependencies to ADC resolutions.
  2012. * @rmtoll CFGR RES LL_ADC_GetResolution
  2013. * @param ADCx ADC instance
  2014. * @retval Returned value can be one of the following values:
  2015. * @arg @ref LL_ADC_RESOLUTION_12B
  2016. * @arg @ref LL_ADC_RESOLUTION_10B
  2017. * @arg @ref LL_ADC_RESOLUTION_8B
  2018. * @arg @ref LL_ADC_RESOLUTION_6B
  2019. */
  2020. __STATIC_INLINE uint32_t LL_ADC_GetResolution(ADC_TypeDef *ADCx)
  2021. {
  2022. return (uint32_t)(READ_BIT(ADCx->CFGR, ADC_CFGR_RES));
  2023. }
  2024. /**
  2025. * @brief Set ADC conversion data alignment.
  2026. * @note Refer to reference manual for alignments formats
  2027. * dependencies to ADC resolutions.
  2028. * @note On this STM32 serie, setting of this feature is conditioned to
  2029. * ADC state:
  2030. * ADC must be disabled or enabled without conversion on going
  2031. * on either groups regular or injected.
  2032. * @rmtoll CFGR ALIGN LL_ADC_SetDataAlignment
  2033. * @param ADCx ADC instance
  2034. * @param DataAlignment This parameter can be one of the following values:
  2035. * @arg @ref LL_ADC_DATA_ALIGN_RIGHT
  2036. * @arg @ref LL_ADC_DATA_ALIGN_LEFT
  2037. * @retval None
  2038. */
  2039. __STATIC_INLINE void LL_ADC_SetDataAlignment(ADC_TypeDef *ADCx, uint32_t DataAlignment)
  2040. {
  2041. MODIFY_REG(ADCx->CFGR, ADC_CFGR_ALIGN, DataAlignment);
  2042. }
  2043. /**
  2044. * @brief Get ADC conversion data alignment.
  2045. * @note Refer to reference manual for alignments formats
  2046. * dependencies to ADC resolutions.
  2047. * @rmtoll CFGR ALIGN LL_ADC_GetDataAlignment
  2048. * @param ADCx ADC instance
  2049. * @retval Returned value can be one of the following values:
  2050. * @arg @ref LL_ADC_DATA_ALIGN_RIGHT
  2051. * @arg @ref LL_ADC_DATA_ALIGN_LEFT
  2052. */
  2053. __STATIC_INLINE uint32_t LL_ADC_GetDataAlignment(ADC_TypeDef *ADCx)
  2054. {
  2055. return (uint32_t)(READ_BIT(ADCx->CFGR, ADC_CFGR_ALIGN));
  2056. }
  2057. /**
  2058. * @brief Set ADC low power mode.
  2059. * @note Description of ADC low power modes:
  2060. * - ADC low power mode "auto wait": Dynamic low power mode,
  2061. * ADC conversions occurrences are limited to the minimum necessary
  2062. * in order to reduce power consumption.
  2063. * New ADC conversion starts only when the previous
  2064. * unitary conversion data (for ADC group regular)
  2065. * or previous sequence conversions data (for ADC group injected)
  2066. * has been retrieved by user software.
  2067. * In the meantime, ADC remains idle: does not performs any
  2068. * other conversion.
  2069. * This mode allows to automatically adapt the ADC conversions
  2070. * triggers to the speed of the software that reads the data.
  2071. * Moreover, this avoids risk of overrun for low frequency
  2072. * applications.
  2073. * How to use this low power mode:
  2074. * - Do not use with interruption or DMA since these modes
  2075. * have to clear immediately the EOC flag to free the
  2076. * IRQ vector sequencer.
  2077. * - Do use with polling: 1. Start conversion,
  2078. * 2. Later on, when conversion data is needed: poll for end of
  2079. * conversion to ensure that conversion is completed and
  2080. * retrieve ADC conversion data. This will trig another
  2081. * ADC conversion start.
  2082. * - ADC low power mode "auto power-off" (feature available on
  2083. * this device if parameter LL_ADC_LP_AUTOPOWEROFF is available):
  2084. * the ADC automatically powers-off after a conversion and
  2085. * automatically wakes up when a new conversion is triggered
  2086. * (with startup time between trigger and start of sampling).
  2087. * This feature can be combined with low power mode "auto wait".
  2088. * @note With ADC low power mode "auto wait", the ADC conversion data read
  2089. * is corresponding to previous ADC conversion start, independently
  2090. * of delay during which ADC was idle.
  2091. * Therefore, the ADC conversion data may be outdated: does not
  2092. * correspond to the current voltage level on the selected
  2093. * ADC channel.
  2094. * @note On this STM32 serie, setting of this feature is conditioned to
  2095. * ADC state:
  2096. * ADC must be disabled or enabled without conversion on going
  2097. * on either groups regular or injected.
  2098. * @rmtoll CFGR AUTDLY LL_ADC_SetLowPowerMode
  2099. * @param ADCx ADC instance
  2100. * @param LowPowerMode This parameter can be one of the following values:
  2101. * @arg @ref LL_ADC_LP_MODE_NONE
  2102. * @arg @ref LL_ADC_LP_AUTOWAIT
  2103. * @retval None
  2104. */
  2105. __STATIC_INLINE void LL_ADC_SetLowPowerMode(ADC_TypeDef *ADCx, uint32_t LowPowerMode)
  2106. {
  2107. MODIFY_REG(ADCx->CFGR, ADC_CFGR_AUTDLY, LowPowerMode);
  2108. }
  2109. /**
  2110. * @brief Get ADC low power mode:
  2111. * @note Description of ADC low power modes:
  2112. * - ADC low power mode "auto wait": Dynamic low power mode,
  2113. * ADC conversions occurrences are limited to the minimum necessary
  2114. * in order to reduce power consumption.
  2115. * New ADC conversion starts only when the previous
  2116. * unitary conversion data (for ADC group regular)
  2117. * or previous sequence conversions data (for ADC group injected)
  2118. * has been retrieved by user software.
  2119. * In the meantime, ADC remains idle: does not performs any
  2120. * other conversion.
  2121. * This mode allows to automatically adapt the ADC conversions
  2122. * triggers to the speed of the software that reads the data.
  2123. * Moreover, this avoids risk of overrun for low frequency
  2124. * applications.
  2125. * How to use this low power mode:
  2126. * - Do not use with interruption or DMA since these modes
  2127. * have to clear immediately the EOC flag to free the
  2128. * IRQ vector sequencer.
  2129. * - Do use with polling: 1. Start conversion,
  2130. * 2. Later on, when conversion data is needed: poll for end of
  2131. * conversion to ensure that conversion is completed and
  2132. * retrieve ADC conversion data. This will trig another
  2133. * ADC conversion start.
  2134. * - ADC low power mode "auto power-off" (feature available on
  2135. * this device if parameter LL_ADC_LP_AUTOPOWEROFF is available):
  2136. * the ADC automatically powers-off after a conversion and
  2137. * automatically wakes up when a new conversion is triggered
  2138. * (with startup time between trigger and start of sampling).
  2139. * This feature can be combined with low power mode "auto wait".
  2140. * @note With ADC low power mode "auto wait", the ADC conversion data read
  2141. * is corresponding to previous ADC conversion start, independently
  2142. * of delay during which ADC was idle.
  2143. * Therefore, the ADC conversion data may be outdated: does not
  2144. * correspond to the current voltage level on the selected
  2145. * ADC channel.
  2146. * @rmtoll CFGR AUTDLY LL_ADC_GetLowPowerMode
  2147. * @param ADCx ADC instance
  2148. * @retval Returned value can be one of the following values:
  2149. * @arg @ref LL_ADC_LP_MODE_NONE
  2150. * @arg @ref LL_ADC_LP_AUTOWAIT
  2151. */
  2152. __STATIC_INLINE uint32_t LL_ADC_GetLowPowerMode(ADC_TypeDef *ADCx)
  2153. {
  2154. return (uint32_t)(READ_BIT(ADCx->CFGR, ADC_CFGR_AUTDLY));
  2155. }
  2156. /**
  2157. * @brief Set ADC selected offset number 1, 2, 3 or 4.
  2158. * @note This function set the 2 items of offset configuration:
  2159. * - ADC channel to which the offset programmed will be applied
  2160. * (independently of channel mapped on ADC group regular
  2161. * or group injected)
  2162. * - Offset level (offset to be subtracted from the raw
  2163. * converted data).
  2164. * @note Caution: Offset format is dependent to ADC resolution:
  2165. * offset has to be left-aligned on bit 11, the LSB (right bits)
  2166. * are set to 0.
  2167. * @note This function enables the offset, by default. It can be forced
  2168. * to disable state using function LL_ADC_SetOffsetState().
  2169. * @note If a channel is mapped on several offsets numbers, only the offset
  2170. * with the lowest value is considered for the subtraction.
  2171. * @note On this STM32 serie, setting of this feature is conditioned to
  2172. * ADC state:
  2173. * ADC must be disabled or enabled without conversion on going
  2174. * on either groups regular or injected.
  2175. * @note On STM32WB, some fast channels are available: fast analog inputs
  2176. * coming from GPIO pads (ADC_IN1..5).
  2177. * @rmtoll OFR1 OFFSET1_CH LL_ADC_SetOffset\n
  2178. * OFR1 OFFSET1 LL_ADC_SetOffset\n
  2179. * OFR1 OFFSET1_EN LL_ADC_SetOffset\n
  2180. * OFR2 OFFSET2_CH LL_ADC_SetOffset\n
  2181. * OFR2 OFFSET2 LL_ADC_SetOffset\n
  2182. * OFR2 OFFSET2_EN LL_ADC_SetOffset\n
  2183. * OFR3 OFFSET3_CH LL_ADC_SetOffset\n
  2184. * OFR3 OFFSET3 LL_ADC_SetOffset\n
  2185. * OFR3 OFFSET3_EN LL_ADC_SetOffset\n
  2186. * OFR4 OFFSET4_CH LL_ADC_SetOffset\n
  2187. * OFR4 OFFSET4 LL_ADC_SetOffset\n
  2188. * OFR4 OFFSET4_EN LL_ADC_SetOffset
  2189. * @param ADCx ADC instance
  2190. * @param Offsety This parameter can be one of the following values:
  2191. * @arg @ref LL_ADC_OFFSET_1
  2192. * @arg @ref LL_ADC_OFFSET_2
  2193. * @arg @ref LL_ADC_OFFSET_3
  2194. * @arg @ref LL_ADC_OFFSET_4
  2195. * @param Channel This parameter can be one of the following values:
  2196. * @arg @ref LL_ADC_CHANNEL_0
  2197. * @arg @ref LL_ADC_CHANNEL_1 (7)
  2198. * @arg @ref LL_ADC_CHANNEL_2 (7)
  2199. * @arg @ref LL_ADC_CHANNEL_3 (7)
  2200. * @arg @ref LL_ADC_CHANNEL_4 (7)
  2201. * @arg @ref LL_ADC_CHANNEL_5 (7)
  2202. * @arg @ref LL_ADC_CHANNEL_6
  2203. * @arg @ref LL_ADC_CHANNEL_7
  2204. * @arg @ref LL_ADC_CHANNEL_8
  2205. * @arg @ref LL_ADC_CHANNEL_9
  2206. * @arg @ref LL_ADC_CHANNEL_10
  2207. * @arg @ref LL_ADC_CHANNEL_11
  2208. * @arg @ref LL_ADC_CHANNEL_12
  2209. * @arg @ref LL_ADC_CHANNEL_13
  2210. * @arg @ref LL_ADC_CHANNEL_14
  2211. * @arg @ref LL_ADC_CHANNEL_15
  2212. * @arg @ref LL_ADC_CHANNEL_16
  2213. * @arg @ref LL_ADC_CHANNEL_17
  2214. * @arg @ref LL_ADC_CHANNEL_18
  2215. * @arg @ref LL_ADC_CHANNEL_VREFINT
  2216. * @arg @ref LL_ADC_CHANNEL_TEMPSENSOR
  2217. * @arg @ref LL_ADC_CHANNEL_VBAT
  2218. *
  2219. * (7) On STM32WB, fast channel (0.188 us for 12-bit resolution (ADC conversion rate up to 5.33 Ms/s)).
  2220. * Other channels are slow channels (0.238 us for 12-bit resolution (ADC conversion rate up to 4.21 Ms/s)).
  2221. * @param OffsetLevel Value between Min_Data=0x000 and Max_Data=0xFFF
  2222. * @retval None
  2223. */
  2224. __STATIC_INLINE void LL_ADC_SetOffset(ADC_TypeDef *ADCx, uint32_t Offsety, uint32_t Channel, uint32_t OffsetLevel)
  2225. {
  2226. register __IO uint32_t *preg = __ADC_PTR_REG_OFFSET(ADCx->OFR1, Offsety);
  2227. MODIFY_REG(*preg,
  2228. ADC_OFR1_OFFSET1_EN | ADC_OFR1_OFFSET1_CH | ADC_OFR1_OFFSET1,
  2229. ADC_OFR1_OFFSET1_EN | (Channel & ADC_CHANNEL_ID_NUMBER_MASK) | OffsetLevel);
  2230. }
  2231. /**
  2232. * @brief Get for the ADC selected offset number 1, 2, 3 or 4:
  2233. * Channel to which the offset programmed will be applied
  2234. * (independently of channel mapped on ADC group regular
  2235. * or group injected)
  2236. * @note Usage of the returned channel number:
  2237. * - To reinject this channel into another function LL_ADC_xxx:
  2238. * the returned channel number is only partly formatted on definition
  2239. * of literals LL_ADC_CHANNEL_x. Therefore, it has to be compared
  2240. * with parts of literals LL_ADC_CHANNEL_x or using
  2241. * helper macro @ref __LL_ADC_CHANNEL_TO_DECIMAL_NB().
  2242. * Then the selected literal LL_ADC_CHANNEL_x can be used
  2243. * as parameter for another function.
  2244. * - To get the channel number in decimal format:
  2245. * process the returned value with the helper macro
  2246. * @ref __LL_ADC_CHANNEL_TO_DECIMAL_NB().
  2247. * @note On STM32WB, some fast channels are available: fast analog inputs
  2248. * coming from GPIO pads (ADC_IN1..5).
  2249. * @rmtoll OFR1 OFFSET1_CH LL_ADC_GetOffsetChannel\n
  2250. * OFR2 OFFSET2_CH LL_ADC_GetOffsetChannel\n
  2251. * OFR3 OFFSET3_CH LL_ADC_GetOffsetChannel\n
  2252. * OFR4 OFFSET4_CH LL_ADC_GetOffsetChannel
  2253. * @param ADCx ADC instance
  2254. * @param Offsety This parameter can be one of the following values:
  2255. * @arg @ref LL_ADC_OFFSET_1
  2256. * @arg @ref LL_ADC_OFFSET_2
  2257. * @arg @ref LL_ADC_OFFSET_3
  2258. * @arg @ref LL_ADC_OFFSET_4
  2259. * @retval Returned value can be one of the following values:
  2260. * @arg @ref LL_ADC_CHANNEL_0
  2261. * @arg @ref LL_ADC_CHANNEL_1 (7)
  2262. * @arg @ref LL_ADC_CHANNEL_2 (7)
  2263. * @arg @ref LL_ADC_CHANNEL_3 (7)
  2264. * @arg @ref LL_ADC_CHANNEL_4 (7)
  2265. * @arg @ref LL_ADC_CHANNEL_5 (7)
  2266. * @arg @ref LL_ADC_CHANNEL_6
  2267. * @arg @ref LL_ADC_CHANNEL_7
  2268. * @arg @ref LL_ADC_CHANNEL_8
  2269. * @arg @ref LL_ADC_CHANNEL_9
  2270. * @arg @ref LL_ADC_CHANNEL_10
  2271. * @arg @ref LL_ADC_CHANNEL_11
  2272. * @arg @ref LL_ADC_CHANNEL_12
  2273. * @arg @ref LL_ADC_CHANNEL_13
  2274. * @arg @ref LL_ADC_CHANNEL_14
  2275. * @arg @ref LL_ADC_CHANNEL_15
  2276. * @arg @ref LL_ADC_CHANNEL_16
  2277. * @arg @ref LL_ADC_CHANNEL_17
  2278. * @arg @ref LL_ADC_CHANNEL_18
  2279. * @arg @ref LL_ADC_CHANNEL_VREFINT (1)
  2280. * @arg @ref LL_ADC_CHANNEL_TEMPSENSOR (4)
  2281. * @arg @ref LL_ADC_CHANNEL_VBAT (4)
  2282. *
  2283. * (7) On STM32WB, fast channel (0.188 us for 12-bit resolution (ADC conversion rate up to 5.33 Ms/s)).
  2284. * Other channels are slow channels (0.238 us for 12-bit resolution (ADC conversion rate up to 4.21 Ms/s)).\n
  2285. * (4) For ADC channel read back from ADC register,
  2286. * comparison with internal channel parameter to be done
  2287. * using helper macro @ref __LL_ADC_CHANNEL_INTERNAL_TO_EXTERNAL().
  2288. */
  2289. __STATIC_INLINE uint32_t LL_ADC_GetOffsetChannel(ADC_TypeDef *ADCx, uint32_t Offsety)
  2290. {
  2291. register const __IO uint32_t *preg = __ADC_PTR_REG_OFFSET(ADCx->OFR1, Offsety);
  2292. return (uint32_t) READ_BIT(*preg, ADC_OFR1_OFFSET1_CH);
  2293. }
  2294. /**
  2295. * @brief Get for the ADC selected offset number 1, 2, 3 or 4:
  2296. * Offset level (offset to be subtracted from the raw
  2297. * converted data).
  2298. * @note Caution: Offset format is dependent to ADC resolution:
  2299. * offset has to be left-aligned on bit 11, the LSB (right bits)
  2300. * are set to 0.
  2301. * @rmtoll OFR1 OFFSET1 LL_ADC_GetOffsetLevel\n
  2302. * OFR2 OFFSET2 LL_ADC_GetOffsetLevel\n
  2303. * OFR3 OFFSET3 LL_ADC_GetOffsetLevel\n
  2304. * OFR4 OFFSET4 LL_ADC_GetOffsetLevel
  2305. * @param ADCx ADC instance
  2306. * @param Offsety This parameter can be one of the following values:
  2307. * @arg @ref LL_ADC_OFFSET_1
  2308. * @arg @ref LL_ADC_OFFSET_2
  2309. * @arg @ref LL_ADC_OFFSET_3
  2310. * @arg @ref LL_ADC_OFFSET_4
  2311. * @retval Value between Min_Data=0x000 and Max_Data=0xFFF
  2312. */
  2313. __STATIC_INLINE uint32_t LL_ADC_GetOffsetLevel(ADC_TypeDef *ADCx, uint32_t Offsety)
  2314. {
  2315. register const __IO uint32_t *preg = __ADC_PTR_REG_OFFSET(ADCx->OFR1, Offsety);
  2316. return (uint32_t) READ_BIT(*preg, ADC_OFR1_OFFSET1);
  2317. }
  2318. /**
  2319. * @brief Set for the ADC selected offset number 1, 2, 3 or 4:
  2320. * force offset state disable or enable
  2321. * without modifying offset channel or offset value.
  2322. * @note This function should be needed only in case of offset to be
  2323. * enabled-disabled dynamically, and should not be needed in other cases:
  2324. * function LL_ADC_SetOffset() automatically enables the offset.
  2325. * @note On this STM32 serie, setting of this feature is conditioned to
  2326. * ADC state:
  2327. * ADC must be disabled or enabled without conversion on going
  2328. * on either groups regular or injected.
  2329. * @rmtoll OFR1 OFFSET1_EN LL_ADC_SetOffsetState\n
  2330. * OFR2 OFFSET2_EN LL_ADC_SetOffsetState\n
  2331. * OFR3 OFFSET3_EN LL_ADC_SetOffsetState\n
  2332. * OFR4 OFFSET4_EN LL_ADC_SetOffsetState
  2333. * @param ADCx ADC instance
  2334. * @param Offsety This parameter can be one of the following values:
  2335. * @arg @ref LL_ADC_OFFSET_1
  2336. * @arg @ref LL_ADC_OFFSET_2
  2337. * @arg @ref LL_ADC_OFFSET_3
  2338. * @arg @ref LL_ADC_OFFSET_4
  2339. * @param OffsetState This parameter can be one of the following values:
  2340. * @arg @ref LL_ADC_OFFSET_DISABLE
  2341. * @arg @ref LL_ADC_OFFSET_ENABLE
  2342. * @retval None
  2343. */
  2344. __STATIC_INLINE void LL_ADC_SetOffsetState(ADC_TypeDef *ADCx, uint32_t Offsety, uint32_t OffsetState)
  2345. {
  2346. register __IO uint32_t *preg = __ADC_PTR_REG_OFFSET(ADCx->OFR1, Offsety);
  2347. MODIFY_REG(*preg,
  2348. ADC_OFR1_OFFSET1_EN,
  2349. OffsetState);
  2350. }
  2351. /**
  2352. * @brief Get for the ADC selected offset number 1, 2, 3 or 4:
  2353. * offset state disabled or enabled.
  2354. * @rmtoll OFR1 OFFSET1_EN LL_ADC_GetOffsetState\n
  2355. * OFR2 OFFSET2_EN LL_ADC_GetOffsetState\n
  2356. * OFR3 OFFSET3_EN LL_ADC_GetOffsetState\n
  2357. * OFR4 OFFSET4_EN LL_ADC_GetOffsetState
  2358. * @param ADCx ADC instance
  2359. * @param Offsety This parameter can be one of the following values:
  2360. * @arg @ref LL_ADC_OFFSET_1
  2361. * @arg @ref LL_ADC_OFFSET_2
  2362. * @arg @ref LL_ADC_OFFSET_3
  2363. * @arg @ref LL_ADC_OFFSET_4
  2364. * @retval Returned value can be one of the following values:
  2365. * @arg @ref LL_ADC_OFFSET_DISABLE
  2366. * @arg @ref LL_ADC_OFFSET_ENABLE
  2367. */
  2368. __STATIC_INLINE uint32_t LL_ADC_GetOffsetState(ADC_TypeDef *ADCx, uint32_t Offsety)
  2369. {
  2370. register const __IO uint32_t *preg = __ADC_PTR_REG_OFFSET(ADCx->OFR1, Offsety);
  2371. return (uint32_t) READ_BIT(*preg, ADC_OFR1_OFFSET1_EN);
  2372. }
  2373. /**
  2374. * @}
  2375. */
  2376. /** @defgroup ADC_LL_EF_Configuration_ADC_Group_Regular Configuration of ADC hierarchical scope: group regular
  2377. * @{
  2378. */
  2379. /**
  2380. * @brief Set ADC group regular conversion trigger source:
  2381. * internal (SW start) or from external peripheral (timer event,
  2382. * external interrupt line).
  2383. * @note On this STM32 serie, setting trigger source to external trigger
  2384. * also set trigger polarity to rising edge
  2385. * (default setting for compatibility with some ADC on other
  2386. * STM32 families having this setting set by HW default value).
  2387. * In case of need to modify trigger edge, use
  2388. * function @ref LL_ADC_REG_SetTriggerEdge().
  2389. * @note Availability of parameters of trigger sources from timer
  2390. * depends on timers availability on the selected device.
  2391. * @note On this STM32 serie, setting of this feature is conditioned to
  2392. * ADC state:
  2393. * ADC must be disabled or enabled without conversion on going
  2394. * on group regular.
  2395. * @rmtoll CFGR EXTSEL LL_ADC_REG_SetTriggerSource\n
  2396. * CFGR EXTEN LL_ADC_REG_SetTriggerSource
  2397. * @param ADCx ADC instance
  2398. * @param TriggerSource This parameter can be one of the following values:
  2399. * @arg @ref LL_ADC_REG_TRIG_SOFTWARE
  2400. * @arg @ref LL_ADC_REG_TRIG_EXT_TIM1_TRGO
  2401. * @arg @ref LL_ADC_REG_TRIG_EXT_TIM1_TRGO2
  2402. * @arg @ref LL_ADC_REG_TRIG_EXT_TIM1_CH1
  2403. * @arg @ref LL_ADC_REG_TRIG_EXT_TIM1_CH2
  2404. * @arg @ref LL_ADC_REG_TRIG_EXT_TIM1_CH3
  2405. * @arg @ref LL_ADC_REG_TRIG_EXT_TIM2_TRGO
  2406. * @arg @ref LL_ADC_REG_TRIG_EXT_TIM2_CH2
  2407. * @arg @ref LL_ADC_REG_TRIG_EXT_EXTI_LINE11
  2408. * @retval None
  2409. */
  2410. __STATIC_INLINE void LL_ADC_REG_SetTriggerSource(ADC_TypeDef *ADCx, uint32_t TriggerSource)
  2411. {
  2412. MODIFY_REG(ADCx->CFGR, ADC_CFGR_EXTEN | ADC_CFGR_EXTSEL, TriggerSource);
  2413. }
  2414. /**
  2415. * @brief Get ADC group regular conversion trigger source:
  2416. * internal (SW start) or from external peripheral (timer event,
  2417. * external interrupt line).
  2418. * @note To determine whether group regular trigger source is
  2419. * internal (SW start) or external, without detail
  2420. * of which peripheral is selected as external trigger,
  2421. * (equivalent to
  2422. * "if(LL_ADC_REG_GetTriggerSource(ADC1) == LL_ADC_REG_TRIG_SOFTWARE)")
  2423. * use function @ref LL_ADC_REG_IsTriggerSourceSWStart.
  2424. * @note Availability of parameters of trigger sources from timer
  2425. * depends on timers availability on the selected device.
  2426. * @rmtoll CFGR EXTSEL LL_ADC_REG_GetTriggerSource\n
  2427. * CFGR EXTEN LL_ADC_REG_GetTriggerSource
  2428. * @param ADCx ADC instance
  2429. * @retval Returned value can be one of the following values:
  2430. * @arg @ref LL_ADC_REG_TRIG_SOFTWARE
  2431. * @arg @ref LL_ADC_REG_TRIG_EXT_TIM1_TRGO
  2432. * @arg @ref LL_ADC_REG_TRIG_EXT_TIM1_TRGO2
  2433. * @arg @ref LL_ADC_REG_TRIG_EXT_TIM1_CH1
  2434. * @arg @ref LL_ADC_REG_TRIG_EXT_TIM1_CH2
  2435. * @arg @ref LL_ADC_REG_TRIG_EXT_TIM1_CH3
  2436. * @arg @ref LL_ADC_REG_TRIG_EXT_TIM2_TRGO
  2437. * @arg @ref LL_ADC_REG_TRIG_EXT_TIM2_CH2
  2438. * @arg @ref LL_ADC_REG_TRIG_EXT_EXTI_LINE11
  2439. */
  2440. __STATIC_INLINE uint32_t LL_ADC_REG_GetTriggerSource(ADC_TypeDef *ADCx)
  2441. {
  2442. register __IO uint32_t TriggerSource = READ_BIT(ADCx->CFGR, ADC_CFGR_EXTSEL | ADC_CFGR_EXTEN);
  2443. /* Value for shift of {0; 4; 8; 12} depending on value of bitfield */
  2444. /* corresponding to ADC_CFGR_EXTEN {0; 1; 2; 3}. */
  2445. register uint32_t ShiftExten = ((TriggerSource & ADC_CFGR_EXTEN) >> (ADC_REG_TRIG_EXTEN_BITOFFSET_POS - 2UL));
  2446. /* Set bitfield corresponding to ADC_CFGR_EXTEN and ADC_CFGR_EXTSEL */
  2447. /* to match with triggers literals definition. */
  2448. return ((TriggerSource
  2449. & (ADC_REG_TRIG_SOURCE_MASK >> ShiftExten) & ADC_CFGR_EXTSEL)
  2450. | ((ADC_REG_TRIG_EDGE_MASK >> ShiftExten) & ADC_CFGR_EXTEN)
  2451. );
  2452. }
  2453. /**
  2454. * @brief Get ADC group regular conversion trigger source internal (SW start)
  2455. * or external.
  2456. * @note In case of group regular trigger source set to external trigger,
  2457. * to determine which peripheral is selected as external trigger,
  2458. * use function @ref LL_ADC_REG_GetTriggerSource().
  2459. * @rmtoll CFGR EXTEN LL_ADC_REG_IsTriggerSourceSWStart
  2460. * @param ADCx ADC instance
  2461. * @retval Value "0" if trigger source external trigger
  2462. * Value "1" if trigger source SW start.
  2463. */
  2464. __STATIC_INLINE uint32_t LL_ADC_REG_IsTriggerSourceSWStart(ADC_TypeDef *ADCx)
  2465. {
  2466. return ((READ_BIT(ADCx->CFGR, ADC_CFGR_EXTEN) == (LL_ADC_REG_TRIG_SOFTWARE & ADC_CFGR_EXTEN)) ? 1UL : 0UL);
  2467. }
  2468. /**
  2469. * @brief Set ADC group regular conversion trigger polarity.
  2470. * @note Applicable only for trigger source set to external trigger.
  2471. * @note On this STM32 serie, setting of this feature is conditioned to
  2472. * ADC state:
  2473. * ADC must be disabled or enabled without conversion on going
  2474. * on group regular.
  2475. * @rmtoll CFGR EXTEN LL_ADC_REG_SetTriggerEdge
  2476. * @param ADCx ADC instance
  2477. * @param ExternalTriggerEdge This parameter can be one of the following values:
  2478. * @arg @ref LL_ADC_REG_TRIG_EXT_RISING
  2479. * @arg @ref LL_ADC_REG_TRIG_EXT_FALLING
  2480. * @arg @ref LL_ADC_REG_TRIG_EXT_RISINGFALLING
  2481. * @retval None
  2482. */
  2483. __STATIC_INLINE void LL_ADC_REG_SetTriggerEdge(ADC_TypeDef *ADCx, uint32_t ExternalTriggerEdge)
  2484. {
  2485. MODIFY_REG(ADCx->CFGR, ADC_CFGR_EXTEN, ExternalTriggerEdge);
  2486. }
  2487. /**
  2488. * @brief Get ADC group regular conversion trigger polarity.
  2489. * @note Applicable only for trigger source set to external trigger.
  2490. * @rmtoll CFGR EXTEN LL_ADC_REG_GetTriggerEdge
  2491. * @param ADCx ADC instance
  2492. * @retval Returned value can be one of the following values:
  2493. * @arg @ref LL_ADC_REG_TRIG_EXT_RISING
  2494. * @arg @ref LL_ADC_REG_TRIG_EXT_FALLING
  2495. * @arg @ref LL_ADC_REG_TRIG_EXT_RISINGFALLING
  2496. */
  2497. __STATIC_INLINE uint32_t LL_ADC_REG_GetTriggerEdge(ADC_TypeDef *ADCx)
  2498. {
  2499. return (uint32_t)(READ_BIT(ADCx->CFGR, ADC_CFGR_EXTEN));
  2500. }
  2501. /**
  2502. * @brief Set ADC group regular sequencer length and scan direction.
  2503. * @note Description of ADC group regular sequencer features:
  2504. * - For devices with sequencer fully configurable
  2505. * (function "LL_ADC_REG_SetSequencerRanks()" available):
  2506. * sequencer length and each rank affectation to a channel
  2507. * are configurable.
  2508. * This function performs configuration of:
  2509. * - Sequence length: Number of ranks in the scan sequence.
  2510. * - Sequence direction: Unless specified in parameters, sequencer
  2511. * scan direction is forward (from rank 1 to rank n).
  2512. * Sequencer ranks are selected using
  2513. * function "LL_ADC_REG_SetSequencerRanks()".
  2514. * - For devices with sequencer not fully configurable
  2515. * (function "LL_ADC_REG_SetSequencerChannels()" available):
  2516. * sequencer length and each rank affectation to a channel
  2517. * are defined by channel number.
  2518. * This function performs configuration of:
  2519. * - Sequence length: Number of ranks in the scan sequence is
  2520. * defined by number of channels set in the sequence,
  2521. * rank of each channel is fixed by channel HW number.
  2522. * (channel 0 fixed on rank 0, channel 1 fixed on rank1, ...).
  2523. * - Sequence direction: Unless specified in parameters, sequencer
  2524. * scan direction is forward (from lowest channel number to
  2525. * highest channel number).
  2526. * Sequencer ranks are selected using
  2527. * function "LL_ADC_REG_SetSequencerChannels()".
  2528. * @note Sequencer disabled is equivalent to sequencer of 1 rank:
  2529. * ADC conversion on only 1 channel.
  2530. * @note On this STM32 serie, setting of this feature is conditioned to
  2531. * ADC state:
  2532. * ADC must be disabled or enabled without conversion on going
  2533. * on group regular.
  2534. * @rmtoll SQR1 L LL_ADC_REG_SetSequencerLength
  2535. * @param ADCx ADC instance
  2536. * @param SequencerNbRanks This parameter can be one of the following values:
  2537. * @arg @ref LL_ADC_REG_SEQ_SCAN_DISABLE
  2538. * @arg @ref LL_ADC_REG_SEQ_SCAN_ENABLE_2RANKS
  2539. * @arg @ref LL_ADC_REG_SEQ_SCAN_ENABLE_3RANKS
  2540. * @arg @ref LL_ADC_REG_SEQ_SCAN_ENABLE_4RANKS
  2541. * @arg @ref LL_ADC_REG_SEQ_SCAN_ENABLE_5RANKS
  2542. * @arg @ref LL_ADC_REG_SEQ_SCAN_ENABLE_6RANKS
  2543. * @arg @ref LL_ADC_REG_SEQ_SCAN_ENABLE_7RANKS
  2544. * @arg @ref LL_ADC_REG_SEQ_SCAN_ENABLE_8RANKS
  2545. * @arg @ref LL_ADC_REG_SEQ_SCAN_ENABLE_9RANKS
  2546. * @arg @ref LL_ADC_REG_SEQ_SCAN_ENABLE_10RANKS
  2547. * @arg @ref LL_ADC_REG_SEQ_SCAN_ENABLE_11RANKS
  2548. * @arg @ref LL_ADC_REG_SEQ_SCAN_ENABLE_12RANKS
  2549. * @arg @ref LL_ADC_REG_SEQ_SCAN_ENABLE_13RANKS
  2550. * @arg @ref LL_ADC_REG_SEQ_SCAN_ENABLE_14RANKS
  2551. * @arg @ref LL_ADC_REG_SEQ_SCAN_ENABLE_15RANKS
  2552. * @arg @ref LL_ADC_REG_SEQ_SCAN_ENABLE_16RANKS
  2553. * @retval None
  2554. */
  2555. __STATIC_INLINE void LL_ADC_REG_SetSequencerLength(ADC_TypeDef *ADCx, uint32_t SequencerNbRanks)
  2556. {
  2557. MODIFY_REG(ADCx->SQR1, ADC_SQR1_L, SequencerNbRanks);
  2558. }
  2559. /**
  2560. * @brief Get ADC group regular sequencer length and scan direction.
  2561. * @note Description of ADC group regular sequencer features:
  2562. * - For devices with sequencer fully configurable
  2563. * (function "LL_ADC_REG_SetSequencerRanks()" available):
  2564. * sequencer length and each rank affectation to a channel
  2565. * are configurable.
  2566. * This function retrieves:
  2567. * - Sequence length: Number of ranks in the scan sequence.
  2568. * - Sequence direction: Unless specified in parameters, sequencer
  2569. * scan direction is forward (from rank 1 to rank n).
  2570. * Sequencer ranks are selected using
  2571. * function "LL_ADC_REG_SetSequencerRanks()".
  2572. * - For devices with sequencer not fully configurable
  2573. * (function "LL_ADC_REG_SetSequencerChannels()" available):
  2574. * sequencer length and each rank affectation to a channel
  2575. * are defined by channel number.
  2576. * This function retrieves:
  2577. * - Sequence length: Number of ranks in the scan sequence is
  2578. * defined by number of channels set in the sequence,
  2579. * rank of each channel is fixed by channel HW number.
  2580. * (channel 0 fixed on rank 0, channel 1 fixed on rank1, ...).
  2581. * - Sequence direction: Unless specified in parameters, sequencer
  2582. * scan direction is forward (from lowest channel number to
  2583. * highest channel number).
  2584. * Sequencer ranks are selected using
  2585. * function "LL_ADC_REG_SetSequencerChannels()".
  2586. * @note Sequencer disabled is equivalent to sequencer of 1 rank:
  2587. * ADC conversion on only 1 channel.
  2588. * @rmtoll SQR1 L LL_ADC_REG_GetSequencerLength
  2589. * @param ADCx ADC instance
  2590. * @retval Returned value can be one of the following values:
  2591. * @arg @ref LL_ADC_REG_SEQ_SCAN_DISABLE
  2592. * @arg @ref LL_ADC_REG_SEQ_SCAN_ENABLE_2RANKS
  2593. * @arg @ref LL_ADC_REG_SEQ_SCAN_ENABLE_3RANKS
  2594. * @arg @ref LL_ADC_REG_SEQ_SCAN_ENABLE_4RANKS
  2595. * @arg @ref LL_ADC_REG_SEQ_SCAN_ENABLE_5RANKS
  2596. * @arg @ref LL_ADC_REG_SEQ_SCAN_ENABLE_6RANKS
  2597. * @arg @ref LL_ADC_REG_SEQ_SCAN_ENABLE_7RANKS
  2598. * @arg @ref LL_ADC_REG_SEQ_SCAN_ENABLE_8RANKS
  2599. * @arg @ref LL_ADC_REG_SEQ_SCAN_ENABLE_9RANKS
  2600. * @arg @ref LL_ADC_REG_SEQ_SCAN_ENABLE_10RANKS
  2601. * @arg @ref LL_ADC_REG_SEQ_SCAN_ENABLE_11RANKS
  2602. * @arg @ref LL_ADC_REG_SEQ_SCAN_ENABLE_12RANKS
  2603. * @arg @ref LL_ADC_REG_SEQ_SCAN_ENABLE_13RANKS
  2604. * @arg @ref LL_ADC_REG_SEQ_SCAN_ENABLE_14RANKS
  2605. * @arg @ref LL_ADC_REG_SEQ_SCAN_ENABLE_15RANKS
  2606. * @arg @ref LL_ADC_REG_SEQ_SCAN_ENABLE_16RANKS
  2607. */
  2608. __STATIC_INLINE uint32_t LL_ADC_REG_GetSequencerLength(ADC_TypeDef *ADCx)
  2609. {
  2610. return (uint32_t)(READ_BIT(ADCx->SQR1, ADC_SQR1_L));
  2611. }
  2612. /**
  2613. * @brief Set ADC group regular sequencer discontinuous mode:
  2614. * sequence subdivided and scan conversions interrupted every selected
  2615. * number of ranks.
  2616. * @note It is not possible to enable both ADC group regular
  2617. * continuous mode and sequencer discontinuous mode.
  2618. * @note It is not possible to enable both ADC auto-injected mode
  2619. * and ADC group regular sequencer discontinuous mode.
  2620. * @note On this STM32 serie, setting of this feature is conditioned to
  2621. * ADC state:
  2622. * ADC must be disabled or enabled without conversion on going
  2623. * on group regular.
  2624. * @rmtoll CFGR DISCEN LL_ADC_REG_SetSequencerDiscont\n
  2625. * CFGR DISCNUM LL_ADC_REG_SetSequencerDiscont
  2626. * @param ADCx ADC instance
  2627. * @param SeqDiscont This parameter can be one of the following values:
  2628. * @arg @ref LL_ADC_REG_SEQ_DISCONT_DISABLE
  2629. * @arg @ref LL_ADC_REG_SEQ_DISCONT_1RANK
  2630. * @arg @ref LL_ADC_REG_SEQ_DISCONT_2RANKS
  2631. * @arg @ref LL_ADC_REG_SEQ_DISCONT_3RANKS
  2632. * @arg @ref LL_ADC_REG_SEQ_DISCONT_4RANKS
  2633. * @arg @ref LL_ADC_REG_SEQ_DISCONT_5RANKS
  2634. * @arg @ref LL_ADC_REG_SEQ_DISCONT_6RANKS
  2635. * @arg @ref LL_ADC_REG_SEQ_DISCONT_7RANKS
  2636. * @arg @ref LL_ADC_REG_SEQ_DISCONT_8RANKS
  2637. * @retval None
  2638. */
  2639. __STATIC_INLINE void LL_ADC_REG_SetSequencerDiscont(ADC_TypeDef *ADCx, uint32_t SeqDiscont)
  2640. {
  2641. MODIFY_REG(ADCx->CFGR, ADC_CFGR_DISCEN | ADC_CFGR_DISCNUM, SeqDiscont);
  2642. }
  2643. /**
  2644. * @brief Get ADC group regular sequencer discontinuous mode:
  2645. * sequence subdivided and scan conversions interrupted every selected
  2646. * number of ranks.
  2647. * @rmtoll CFGR DISCEN LL_ADC_REG_GetSequencerDiscont\n
  2648. * CFGR DISCNUM LL_ADC_REG_GetSequencerDiscont
  2649. * @param ADCx ADC instance
  2650. * @retval Returned value can be one of the following values:
  2651. * @arg @ref LL_ADC_REG_SEQ_DISCONT_DISABLE
  2652. * @arg @ref LL_ADC_REG_SEQ_DISCONT_1RANK
  2653. * @arg @ref LL_ADC_REG_SEQ_DISCONT_2RANKS
  2654. * @arg @ref LL_ADC_REG_SEQ_DISCONT_3RANKS
  2655. * @arg @ref LL_ADC_REG_SEQ_DISCONT_4RANKS
  2656. * @arg @ref LL_ADC_REG_SEQ_DISCONT_5RANKS
  2657. * @arg @ref LL_ADC_REG_SEQ_DISCONT_6RANKS
  2658. * @arg @ref LL_ADC_REG_SEQ_DISCONT_7RANKS
  2659. * @arg @ref LL_ADC_REG_SEQ_DISCONT_8RANKS
  2660. */
  2661. __STATIC_INLINE uint32_t LL_ADC_REG_GetSequencerDiscont(ADC_TypeDef *ADCx)
  2662. {
  2663. return (uint32_t)(READ_BIT(ADCx->CFGR, ADC_CFGR_DISCEN | ADC_CFGR_DISCNUM));
  2664. }
  2665. /**
  2666. * @brief Set ADC group regular sequence: channel on the selected
  2667. * scan sequence rank.
  2668. * @note This function performs configuration of:
  2669. * - Channels ordering into each rank of scan sequence:
  2670. * whatever channel can be placed into whatever rank.
  2671. * @note On this STM32 serie, ADC group regular sequencer is
  2672. * fully configurable: sequencer length and each rank
  2673. * affectation to a channel are configurable.
  2674. * Refer to description of function @ref LL_ADC_REG_SetSequencerLength().
  2675. * @note Depending on devices and packages, some channels may not be available.
  2676. * Refer to device datasheet for channels availability.
  2677. * @note On this STM32 serie, to measure internal channels (VrefInt,
  2678. * TempSensor, ...), measurement paths to internal channels must be
  2679. * enabled separately.
  2680. * This can be done using function @ref LL_ADC_SetCommonPathInternalCh().
  2681. * @note On this STM32 serie, setting of this feature is conditioned to
  2682. * ADC state:
  2683. * ADC must be disabled or enabled without conversion on going
  2684. * on group regular.
  2685. * @rmtoll SQR1 SQ1 LL_ADC_REG_SetSequencerRanks\n
  2686. * SQR1 SQ2 LL_ADC_REG_SetSequencerRanks\n
  2687. * SQR1 SQ3 LL_ADC_REG_SetSequencerRanks\n
  2688. * SQR1 SQ4 LL_ADC_REG_SetSequencerRanks\n
  2689. * SQR2 SQ5 LL_ADC_REG_SetSequencerRanks\n
  2690. * SQR2 SQ6 LL_ADC_REG_SetSequencerRanks\n
  2691. * SQR2 SQ7 LL_ADC_REG_SetSequencerRanks\n
  2692. * SQR2 SQ8 LL_ADC_REG_SetSequencerRanks\n
  2693. * SQR2 SQ9 LL_ADC_REG_SetSequencerRanks\n
  2694. * SQR3 SQ10 LL_ADC_REG_SetSequencerRanks\n
  2695. * SQR3 SQ11 LL_ADC_REG_SetSequencerRanks\n
  2696. * SQR3 SQ12 LL_ADC_REG_SetSequencerRanks\n
  2697. * SQR3 SQ13 LL_ADC_REG_SetSequencerRanks\n
  2698. * SQR3 SQ14 LL_ADC_REG_SetSequencerRanks\n
  2699. * SQR4 SQ15 LL_ADC_REG_SetSequencerRanks\n
  2700. * SQR4 SQ16 LL_ADC_REG_SetSequencerRanks
  2701. * @param ADCx ADC instance
  2702. * @param Rank This parameter can be one of the following values:
  2703. * @arg @ref LL_ADC_REG_RANK_1
  2704. * @arg @ref LL_ADC_REG_RANK_2
  2705. * @arg @ref LL_ADC_REG_RANK_3
  2706. * @arg @ref LL_ADC_REG_RANK_4
  2707. * @arg @ref LL_ADC_REG_RANK_5
  2708. * @arg @ref LL_ADC_REG_RANK_6
  2709. * @arg @ref LL_ADC_REG_RANK_7
  2710. * @arg @ref LL_ADC_REG_RANK_8
  2711. * @arg @ref LL_ADC_REG_RANK_9
  2712. * @arg @ref LL_ADC_REG_RANK_10
  2713. * @arg @ref LL_ADC_REG_RANK_11
  2714. * @arg @ref LL_ADC_REG_RANK_12
  2715. * @arg @ref LL_ADC_REG_RANK_13
  2716. * @arg @ref LL_ADC_REG_RANK_14
  2717. * @arg @ref LL_ADC_REG_RANK_15
  2718. * @arg @ref LL_ADC_REG_RANK_16
  2719. * @param Channel This parameter can be one of the following values:
  2720. * @arg @ref LL_ADC_CHANNEL_0
  2721. * @arg @ref LL_ADC_CHANNEL_1 (7)
  2722. * @arg @ref LL_ADC_CHANNEL_2 (7)
  2723. * @arg @ref LL_ADC_CHANNEL_3 (7)
  2724. * @arg @ref LL_ADC_CHANNEL_4 (7)
  2725. * @arg @ref LL_ADC_CHANNEL_5 (7)
  2726. * @arg @ref LL_ADC_CHANNEL_6
  2727. * @arg @ref LL_ADC_CHANNEL_7
  2728. * @arg @ref LL_ADC_CHANNEL_8
  2729. * @arg @ref LL_ADC_CHANNEL_9
  2730. * @arg @ref LL_ADC_CHANNEL_10
  2731. * @arg @ref LL_ADC_CHANNEL_11
  2732. * @arg @ref LL_ADC_CHANNEL_12
  2733. * @arg @ref LL_ADC_CHANNEL_13
  2734. * @arg @ref LL_ADC_CHANNEL_14
  2735. * @arg @ref LL_ADC_CHANNEL_15
  2736. * @arg @ref LL_ADC_CHANNEL_16
  2737. * @arg @ref LL_ADC_CHANNEL_17
  2738. * @arg @ref LL_ADC_CHANNEL_18
  2739. * @arg @ref LL_ADC_CHANNEL_VREFINT
  2740. * @arg @ref LL_ADC_CHANNEL_TEMPSENSOR
  2741. * @arg @ref LL_ADC_CHANNEL_VBAT
  2742. *
  2743. * (7) On STM32WB, fast channel (0.188 us for 12-bit resolution (ADC conversion rate up to 5.33 Ms/s)).
  2744. * Other channels are slow channels (0.238 us for 12-bit resolution (ADC conversion rate up to 4.21 Ms/s)).
  2745. * @retval None
  2746. */
  2747. __STATIC_INLINE void LL_ADC_REG_SetSequencerRanks(ADC_TypeDef *ADCx, uint32_t Rank, uint32_t Channel)
  2748. {
  2749. /* Set bits with content of parameter "Channel" with bits position */
  2750. /* in register and register position depending on parameter "Rank". */
  2751. /* Parameters "Rank" and "Channel" are used with masks because containing */
  2752. /* other bits reserved for other purpose. */
  2753. register __IO uint32_t *preg = __ADC_PTR_REG_OFFSET(ADCx->SQR1, ((Rank & ADC_REG_SQRX_REGOFFSET_MASK) >> ADC_SQRX_REGOFFSET_POS));
  2754. MODIFY_REG(*preg,
  2755. ADC_CHANNEL_ID_NUMBER_MASK_POSBIT0 << (Rank & ADC_REG_RANK_ID_SQRX_MASK),
  2756. ((Channel & ADC_CHANNEL_ID_NUMBER_MASK) >> ADC_CHANNEL_ID_NUMBER_BITOFFSET_POS) << (Rank & ADC_REG_RANK_ID_SQRX_MASK));
  2757. }
  2758. /**
  2759. * @brief Get ADC group regular sequence: channel on the selected
  2760. * scan sequence rank.
  2761. * @note On this STM32 serie, ADC group regular sequencer is
  2762. * fully configurable: sequencer length and each rank
  2763. * affectation to a channel are configurable.
  2764. * Refer to description of function @ref LL_ADC_REG_SetSequencerLength().
  2765. * @note Depending on devices and packages, some channels may not be available.
  2766. * Refer to device datasheet for channels availability.
  2767. * @note Usage of the returned channel number:
  2768. * - To reinject this channel into another function LL_ADC_xxx:
  2769. * the returned channel number is only partly formatted on definition
  2770. * of literals LL_ADC_CHANNEL_x. Therefore, it has to be compared
  2771. * with parts of literals LL_ADC_CHANNEL_x or using
  2772. * helper macro @ref __LL_ADC_CHANNEL_TO_DECIMAL_NB().
  2773. * Then the selected literal LL_ADC_CHANNEL_x can be used
  2774. * as parameter for another function.
  2775. * - To get the channel number in decimal format:
  2776. * process the returned value with the helper macro
  2777. * @ref __LL_ADC_CHANNEL_TO_DECIMAL_NB().
  2778. * @rmtoll SQR1 SQ1 LL_ADC_REG_GetSequencerRanks\n
  2779. * SQR1 SQ2 LL_ADC_REG_GetSequencerRanks\n
  2780. * SQR1 SQ3 LL_ADC_REG_GetSequencerRanks\n
  2781. * SQR1 SQ4 LL_ADC_REG_GetSequencerRanks\n
  2782. * SQR2 SQ5 LL_ADC_REG_GetSequencerRanks\n
  2783. * SQR2 SQ6 LL_ADC_REG_GetSequencerRanks\n
  2784. * SQR2 SQ7 LL_ADC_REG_GetSequencerRanks\n
  2785. * SQR2 SQ8 LL_ADC_REG_GetSequencerRanks\n
  2786. * SQR2 SQ9 LL_ADC_REG_GetSequencerRanks\n
  2787. * SQR3 SQ10 LL_ADC_REG_GetSequencerRanks\n
  2788. * SQR3 SQ11 LL_ADC_REG_GetSequencerRanks\n
  2789. * SQR3 SQ12 LL_ADC_REG_GetSequencerRanks\n
  2790. * SQR3 SQ13 LL_ADC_REG_GetSequencerRanks\n
  2791. * SQR3 SQ14 LL_ADC_REG_GetSequencerRanks\n
  2792. * SQR4 SQ15 LL_ADC_REG_GetSequencerRanks\n
  2793. * SQR4 SQ16 LL_ADC_REG_GetSequencerRanks
  2794. * @param ADCx ADC instance
  2795. * @param Rank This parameter can be one of the following values:
  2796. * @arg @ref LL_ADC_REG_RANK_1
  2797. * @arg @ref LL_ADC_REG_RANK_2
  2798. * @arg @ref LL_ADC_REG_RANK_3
  2799. * @arg @ref LL_ADC_REG_RANK_4
  2800. * @arg @ref LL_ADC_REG_RANK_5
  2801. * @arg @ref LL_ADC_REG_RANK_6
  2802. * @arg @ref LL_ADC_REG_RANK_7
  2803. * @arg @ref LL_ADC_REG_RANK_8
  2804. * @arg @ref LL_ADC_REG_RANK_9
  2805. * @arg @ref LL_ADC_REG_RANK_10
  2806. * @arg @ref LL_ADC_REG_RANK_11
  2807. * @arg @ref LL_ADC_REG_RANK_12
  2808. * @arg @ref LL_ADC_REG_RANK_13
  2809. * @arg @ref LL_ADC_REG_RANK_14
  2810. * @arg @ref LL_ADC_REG_RANK_15
  2811. * @arg @ref LL_ADC_REG_RANK_16
  2812. * @retval Returned value can be one of the following values:
  2813. * @arg @ref LL_ADC_CHANNEL_0
  2814. * @arg @ref LL_ADC_CHANNEL_1 (7)
  2815. * @arg @ref LL_ADC_CHANNEL_2 (7)
  2816. * @arg @ref LL_ADC_CHANNEL_3 (7)
  2817. * @arg @ref LL_ADC_CHANNEL_4 (7)
  2818. * @arg @ref LL_ADC_CHANNEL_5 (7)
  2819. * @arg @ref LL_ADC_CHANNEL_6
  2820. * @arg @ref LL_ADC_CHANNEL_7
  2821. * @arg @ref LL_ADC_CHANNEL_8
  2822. * @arg @ref LL_ADC_CHANNEL_9
  2823. * @arg @ref LL_ADC_CHANNEL_10
  2824. * @arg @ref LL_ADC_CHANNEL_11
  2825. * @arg @ref LL_ADC_CHANNEL_12
  2826. * @arg @ref LL_ADC_CHANNEL_13
  2827. * @arg @ref LL_ADC_CHANNEL_14
  2828. * @arg @ref LL_ADC_CHANNEL_15
  2829. * @arg @ref LL_ADC_CHANNEL_16
  2830. * @arg @ref LL_ADC_CHANNEL_17
  2831. * @arg @ref LL_ADC_CHANNEL_18
  2832. * @arg @ref LL_ADC_CHANNEL_VREFINT (1)
  2833. * @arg @ref LL_ADC_CHANNEL_TEMPSENSOR (4)
  2834. * @arg @ref LL_ADC_CHANNEL_VBAT (4)
  2835. *
  2836. * (7) On STM32WB, fast channel (0.188 us for 12-bit resolution (ADC conversion rate up to 5.33 Ms/s)).
  2837. * Other channels are slow channels (0.238 us for 12-bit resolution (ADC conversion rate up to 4.21 Ms/s)).\n
  2838. * (4) For ADC channel read back from ADC register,
  2839. * comparison with internal channel parameter to be done
  2840. * using helper macro @ref __LL_ADC_CHANNEL_INTERNAL_TO_EXTERNAL().
  2841. */
  2842. __STATIC_INLINE uint32_t LL_ADC_REG_GetSequencerRanks(ADC_TypeDef *ADCx, uint32_t Rank)
  2843. {
  2844. register const __IO uint32_t *preg = __ADC_PTR_REG_OFFSET(ADCx->SQR1, ((Rank & ADC_REG_SQRX_REGOFFSET_MASK) >> ADC_SQRX_REGOFFSET_POS));
  2845. return (uint32_t) ((READ_BIT(*preg,
  2846. ADC_CHANNEL_ID_NUMBER_MASK_POSBIT0 << (Rank & ADC_REG_RANK_ID_SQRX_MASK))
  2847. >> (Rank & ADC_REG_RANK_ID_SQRX_MASK)) << ADC_CHANNEL_ID_NUMBER_BITOFFSET_POS
  2848. );
  2849. }
  2850. /**
  2851. * @brief Set ADC continuous conversion mode on ADC group regular.
  2852. * @note Description of ADC continuous conversion mode:
  2853. * - single mode: one conversion per trigger
  2854. * - continuous mode: after the first trigger, following
  2855. * conversions launched successively automatically.
  2856. * @note It is not possible to enable both ADC group regular
  2857. * continuous mode and sequencer discontinuous mode.
  2858. * @note On this STM32 serie, setting of this feature is conditioned to
  2859. * ADC state:
  2860. * ADC must be disabled or enabled without conversion on going
  2861. * on group regular.
  2862. * @rmtoll CFGR CONT LL_ADC_REG_SetContinuousMode
  2863. * @param ADCx ADC instance
  2864. * @param Continuous This parameter can be one of the following values:
  2865. * @arg @ref LL_ADC_REG_CONV_SINGLE
  2866. * @arg @ref LL_ADC_REG_CONV_CONTINUOUS
  2867. * @retval None
  2868. */
  2869. __STATIC_INLINE void LL_ADC_REG_SetContinuousMode(ADC_TypeDef *ADCx, uint32_t Continuous)
  2870. {
  2871. MODIFY_REG(ADCx->CFGR, ADC_CFGR_CONT, Continuous);
  2872. }
  2873. /**
  2874. * @brief Get ADC continuous conversion mode on ADC group regular.
  2875. * @note Description of ADC continuous conversion mode:
  2876. * - single mode: one conversion per trigger
  2877. * - continuous mode: after the first trigger, following
  2878. * conversions launched successively automatically.
  2879. * @rmtoll CFGR CONT LL_ADC_REG_GetContinuousMode
  2880. * @param ADCx ADC instance
  2881. * @retval Returned value can be one of the following values:
  2882. * @arg @ref LL_ADC_REG_CONV_SINGLE
  2883. * @arg @ref LL_ADC_REG_CONV_CONTINUOUS
  2884. */
  2885. __STATIC_INLINE uint32_t LL_ADC_REG_GetContinuousMode(ADC_TypeDef *ADCx)
  2886. {
  2887. return (uint32_t)(READ_BIT(ADCx->CFGR, ADC_CFGR_CONT));
  2888. }
  2889. /**
  2890. * @brief Set ADC group regular conversion data transfer: no transfer or
  2891. * transfer by DMA, and DMA requests mode.
  2892. * @note If transfer by DMA selected, specifies the DMA requests
  2893. * mode:
  2894. * - Limited mode (One shot mode): DMA transfer requests are stopped
  2895. * when number of DMA data transfers (number of
  2896. * ADC conversions) is reached.
  2897. * This ADC mode is intended to be used with DMA mode non-circular.
  2898. * - Unlimited mode: DMA transfer requests are unlimited,
  2899. * whatever number of DMA data transfers (number of
  2900. * ADC conversions).
  2901. * This ADC mode is intended to be used with DMA mode circular.
  2902. * @note If ADC DMA requests mode is set to unlimited and DMA is set to
  2903. * mode non-circular:
  2904. * when DMA transfers size will be reached, DMA will stop transfers of
  2905. * ADC conversions data ADC will raise an overrun error
  2906. * (overrun flag and interruption if enabled).
  2907. * @note To configure DMA source address (peripheral address),
  2908. * use function @ref LL_ADC_DMA_GetRegAddr().
  2909. * @note On this STM32 serie, setting of this feature is conditioned to
  2910. * ADC state:
  2911. * ADC must be disabled or enabled without conversion on going
  2912. * on either groups regular or injected.
  2913. * @rmtoll CFGR DMAEN LL_ADC_REG_SetDMATransfer\n
  2914. * CFGR DMACFG LL_ADC_REG_SetDMATransfer
  2915. * @param ADCx ADC instance
  2916. * @param DMATransfer This parameter can be one of the following values:
  2917. * @arg @ref LL_ADC_REG_DMA_TRANSFER_NONE
  2918. * @arg @ref LL_ADC_REG_DMA_TRANSFER_LIMITED
  2919. * @arg @ref LL_ADC_REG_DMA_TRANSFER_UNLIMITED
  2920. * @retval None
  2921. */
  2922. __STATIC_INLINE void LL_ADC_REG_SetDMATransfer(ADC_TypeDef *ADCx, uint32_t DMATransfer)
  2923. {
  2924. MODIFY_REG(ADCx->CFGR, ADC_CFGR_DMAEN | ADC_CFGR_DMACFG, DMATransfer);
  2925. }
  2926. /**
  2927. * @brief Get ADC group regular conversion data transfer: no transfer or
  2928. * transfer by DMA, and DMA requests mode.
  2929. * @note If transfer by DMA selected, specifies the DMA requests
  2930. * mode:
  2931. * - Limited mode (One shot mode): DMA transfer requests are stopped
  2932. * when number of DMA data transfers (number of
  2933. * ADC conversions) is reached.
  2934. * This ADC mode is intended to be used with DMA mode non-circular.
  2935. * - Unlimited mode: DMA transfer requests are unlimited,
  2936. * whatever number of DMA data transfers (number of
  2937. * ADC conversions).
  2938. * This ADC mode is intended to be used with DMA mode circular.
  2939. * @note If ADC DMA requests mode is set to unlimited and DMA is set to
  2940. * mode non-circular:
  2941. * when DMA transfers size will be reached, DMA will stop transfers of
  2942. * ADC conversions data ADC will raise an overrun error
  2943. * (overrun flag and interruption if enabled).
  2944. * @note To configure DMA source address (peripheral address),
  2945. * use function @ref LL_ADC_DMA_GetRegAddr().
  2946. * @rmtoll CFGR DMAEN LL_ADC_REG_GetDMATransfer\n
  2947. * CFGR DMACFG LL_ADC_REG_GetDMATransfer
  2948. * @param ADCx ADC instance
  2949. * @retval Returned value can be one of the following values:
  2950. * @arg @ref LL_ADC_REG_DMA_TRANSFER_NONE
  2951. * @arg @ref LL_ADC_REG_DMA_TRANSFER_LIMITED
  2952. * @arg @ref LL_ADC_REG_DMA_TRANSFER_UNLIMITED
  2953. */
  2954. __STATIC_INLINE uint32_t LL_ADC_REG_GetDMATransfer(ADC_TypeDef *ADCx)
  2955. {
  2956. return (uint32_t)(READ_BIT(ADCx->CFGR, ADC_CFGR_DMAEN | ADC_CFGR_DMACFG));
  2957. }
  2958. /**
  2959. * @brief Set ADC group regular behavior in case of overrun:
  2960. * data preserved or overwritten.
  2961. * @note Compatibility with devices without feature overrun:
  2962. * other devices without this feature have a behavior
  2963. * equivalent to data overwritten.
  2964. * The default setting of overrun is data preserved.
  2965. * Therefore, for compatibility with all devices, parameter
  2966. * overrun should be set to data overwritten.
  2967. * @note On this STM32 serie, setting of this feature is conditioned to
  2968. * ADC state:
  2969. * ADC must be disabled or enabled without conversion on going
  2970. * on group regular.
  2971. * @rmtoll CFGR OVRMOD LL_ADC_REG_SetOverrun
  2972. * @param ADCx ADC instance
  2973. * @param Overrun This parameter can be one of the following values:
  2974. * @arg @ref LL_ADC_REG_OVR_DATA_PRESERVED
  2975. * @arg @ref LL_ADC_REG_OVR_DATA_OVERWRITTEN
  2976. * @retval None
  2977. */
  2978. __STATIC_INLINE void LL_ADC_REG_SetOverrun(ADC_TypeDef *ADCx, uint32_t Overrun)
  2979. {
  2980. MODIFY_REG(ADCx->CFGR, ADC_CFGR_OVRMOD, Overrun);
  2981. }
  2982. /**
  2983. * @brief Get ADC group regular behavior in case of overrun:
  2984. * data preserved or overwritten.
  2985. * @rmtoll CFGR OVRMOD LL_ADC_REG_GetOverrun
  2986. * @param ADCx ADC instance
  2987. * @retval Returned value can be one of the following values:
  2988. * @arg @ref LL_ADC_REG_OVR_DATA_PRESERVED
  2989. * @arg @ref LL_ADC_REG_OVR_DATA_OVERWRITTEN
  2990. */
  2991. __STATIC_INLINE uint32_t LL_ADC_REG_GetOverrun(ADC_TypeDef *ADCx)
  2992. {
  2993. return (uint32_t)(READ_BIT(ADCx->CFGR, ADC_CFGR_OVRMOD));
  2994. }
  2995. /**
  2996. * @}
  2997. */
  2998. /** @defgroup ADC_LL_EF_Configuration_ADC_Group_Injected Configuration of ADC hierarchical scope: group injected
  2999. * @{
  3000. */
  3001. /**
  3002. * @brief Set ADC group injected conversion trigger source:
  3003. * internal (SW start) or from external peripheral (timer event,
  3004. * external interrupt line).
  3005. * @note On this STM32 serie, setting trigger source to external trigger
  3006. * also set trigger polarity to rising edge
  3007. * (default setting for compatibility with some ADC on other
  3008. * STM32 families having this setting set by HW default value).
  3009. * In case of need to modify trigger edge, use
  3010. * function @ref LL_ADC_INJ_SetTriggerEdge().
  3011. * @note Availability of parameters of trigger sources from timer
  3012. * depends on timers availability on the selected device.
  3013. * @note On this STM32 serie, setting of this feature is conditioned to
  3014. * ADC state:
  3015. * ADC must not be disabled. Can be enabled with or without conversion
  3016. * on going on either groups regular or injected.
  3017. * @rmtoll JSQR JEXTSEL LL_ADC_INJ_SetTriggerSource\n
  3018. * JSQR JEXTEN LL_ADC_INJ_SetTriggerSource
  3019. * @param ADCx ADC instance
  3020. * @param TriggerSource This parameter can be one of the following values:
  3021. * @arg @ref LL_ADC_INJ_TRIG_SOFTWARE
  3022. * @arg @ref LL_ADC_INJ_TRIG_EXT_TIM1_TRGO
  3023. * @arg @ref LL_ADC_INJ_TRIG_EXT_TIM1_TRGO2
  3024. * @arg @ref LL_ADC_INJ_TRIG_EXT_TIM1_CH4
  3025. * @arg @ref LL_ADC_INJ_TRIG_EXT_TIM2_TRGO
  3026. * @arg @ref LL_ADC_INJ_TRIG_EXT_TIM2_CH1
  3027. * @arg @ref LL_ADC_INJ_TRIG_EXT_EXTI_LINE15
  3028. * @retval None
  3029. */
  3030. __STATIC_INLINE void LL_ADC_INJ_SetTriggerSource(ADC_TypeDef *ADCx, uint32_t TriggerSource)
  3031. {
  3032. MODIFY_REG(ADCx->JSQR, ADC_JSQR_JEXTSEL | ADC_JSQR_JEXTEN, TriggerSource);
  3033. }
  3034. /**
  3035. * @brief Get ADC group injected conversion trigger source:
  3036. * internal (SW start) or from external peripheral (timer event,
  3037. * external interrupt line).
  3038. * @note To determine whether group injected trigger source is
  3039. * internal (SW start) or external, without detail
  3040. * of which peripheral is selected as external trigger,
  3041. * (equivalent to
  3042. * "if(LL_ADC_INJ_GetTriggerSource(ADC1) == LL_ADC_INJ_TRIG_SOFTWARE)")
  3043. * use function @ref LL_ADC_INJ_IsTriggerSourceSWStart.
  3044. * @note Availability of parameters of trigger sources from timer
  3045. * depends on timers availability on the selected device.
  3046. * @rmtoll JSQR JEXTSEL LL_ADC_INJ_GetTriggerSource\n
  3047. * JSQR JEXTEN LL_ADC_INJ_GetTriggerSource
  3048. * @param ADCx ADC instance
  3049. * @retval Returned value can be one of the following values:
  3050. * @arg @ref LL_ADC_INJ_TRIG_SOFTWARE
  3051. * @arg @ref LL_ADC_INJ_TRIG_EXT_TIM1_TRGO
  3052. * @arg @ref LL_ADC_INJ_TRIG_EXT_TIM1_TRGO2
  3053. * @arg @ref LL_ADC_INJ_TRIG_EXT_TIM1_CH4
  3054. * @arg @ref LL_ADC_INJ_TRIG_EXT_TIM2_TRGO
  3055. * @arg @ref LL_ADC_INJ_TRIG_EXT_TIM2_CH1
  3056. * @arg @ref LL_ADC_INJ_TRIG_EXT_EXTI_LINE15
  3057. */
  3058. __STATIC_INLINE uint32_t LL_ADC_INJ_GetTriggerSource(ADC_TypeDef *ADCx)
  3059. {
  3060. register __IO uint32_t TriggerSource = READ_BIT(ADCx->JSQR, ADC_JSQR_JEXTSEL | ADC_JSQR_JEXTEN);
  3061. /* Value for shift of {0; 4; 8; 12} depending on value of bitfield */
  3062. /* corresponding to ADC_JSQR_JEXTEN {0; 1; 2; 3}. */
  3063. register uint32_t ShiftJexten = ((TriggerSource & ADC_JSQR_JEXTEN) >> (ADC_INJ_TRIG_EXTEN_BITOFFSET_POS - 2UL));
  3064. /* Set bitfield corresponding to ADC_JSQR_JEXTEN and ADC_JSQR_JEXTSEL */
  3065. /* to match with triggers literals definition. */
  3066. return ((TriggerSource
  3067. & (ADC_INJ_TRIG_SOURCE_MASK >> ShiftJexten) & ADC_JSQR_JEXTSEL)
  3068. | ((ADC_INJ_TRIG_EDGE_MASK >> ShiftJexten) & ADC_JSQR_JEXTEN)
  3069. );
  3070. }
  3071. /**
  3072. * @brief Get ADC group injected conversion trigger source internal (SW start)
  3073. or external
  3074. * @note In case of group injected trigger source set to external trigger,
  3075. * to determine which peripheral is selected as external trigger,
  3076. * use function @ref LL_ADC_INJ_GetTriggerSource.
  3077. * @rmtoll JSQR JEXTEN LL_ADC_INJ_IsTriggerSourceSWStart
  3078. * @param ADCx ADC instance
  3079. * @retval Value "0" if trigger source external trigger
  3080. * Value "1" if trigger source SW start.
  3081. */
  3082. __STATIC_INLINE uint32_t LL_ADC_INJ_IsTriggerSourceSWStart(ADC_TypeDef *ADCx)
  3083. {
  3084. return ((READ_BIT(ADCx->JSQR, ADC_JSQR_JEXTEN) == (LL_ADC_INJ_TRIG_SOFTWARE & ADC_JSQR_JEXTEN)) ? 1UL : 0UL);
  3085. }
  3086. /**
  3087. * @brief Set ADC group injected conversion trigger polarity.
  3088. * Applicable only for trigger source set to external trigger.
  3089. * @note On this STM32 serie, setting of this feature is conditioned to
  3090. * ADC state:
  3091. * ADC must not be disabled. Can be enabled with or without conversion
  3092. * on going on either groups regular or injected.
  3093. * @rmtoll JSQR JEXTEN LL_ADC_INJ_SetTriggerEdge
  3094. * @param ADCx ADC instance
  3095. * @param ExternalTriggerEdge This parameter can be one of the following values:
  3096. * @arg @ref LL_ADC_INJ_TRIG_EXT_RISING
  3097. * @arg @ref LL_ADC_INJ_TRIG_EXT_FALLING
  3098. * @arg @ref LL_ADC_INJ_TRIG_EXT_RISINGFALLING
  3099. * @retval None
  3100. */
  3101. __STATIC_INLINE void LL_ADC_INJ_SetTriggerEdge(ADC_TypeDef *ADCx, uint32_t ExternalTriggerEdge)
  3102. {
  3103. MODIFY_REG(ADCx->JSQR, ADC_JSQR_JEXTEN, ExternalTriggerEdge);
  3104. }
  3105. /**
  3106. * @brief Get ADC group injected conversion trigger polarity.
  3107. * Applicable only for trigger source set to external trigger.
  3108. * @rmtoll JSQR JEXTEN LL_ADC_INJ_GetTriggerEdge
  3109. * @param ADCx ADC instance
  3110. * @retval Returned value can be one of the following values:
  3111. * @arg @ref LL_ADC_INJ_TRIG_EXT_RISING
  3112. * @arg @ref LL_ADC_INJ_TRIG_EXT_FALLING
  3113. * @arg @ref LL_ADC_INJ_TRIG_EXT_RISINGFALLING
  3114. */
  3115. __STATIC_INLINE uint32_t LL_ADC_INJ_GetTriggerEdge(ADC_TypeDef *ADCx)
  3116. {
  3117. return (uint32_t)(READ_BIT(ADCx->JSQR, ADC_JSQR_JEXTEN));
  3118. }
  3119. /**
  3120. * @brief Set ADC group injected sequencer length and scan direction.
  3121. * @note This function performs configuration of:
  3122. * - Sequence length: Number of ranks in the scan sequence.
  3123. * - Sequence direction: Unless specified in parameters, sequencer
  3124. * scan direction is forward (from rank 1 to rank n).
  3125. * @note Sequencer disabled is equivalent to sequencer of 1 rank:
  3126. * ADC conversion on only 1 channel.
  3127. * @note On this STM32 serie, setting of this feature is conditioned to
  3128. * ADC state:
  3129. * ADC must not be disabled. Can be enabled with or without conversion
  3130. * on going on either groups regular or injected.
  3131. * @rmtoll JSQR JL LL_ADC_INJ_SetSequencerLength
  3132. * @param ADCx ADC instance
  3133. * @param SequencerNbRanks This parameter can be one of the following values:
  3134. * @arg @ref LL_ADC_INJ_SEQ_SCAN_DISABLE
  3135. * @arg @ref LL_ADC_INJ_SEQ_SCAN_ENABLE_2RANKS
  3136. * @arg @ref LL_ADC_INJ_SEQ_SCAN_ENABLE_3RANKS
  3137. * @arg @ref LL_ADC_INJ_SEQ_SCAN_ENABLE_4RANKS
  3138. * @retval None
  3139. */
  3140. __STATIC_INLINE void LL_ADC_INJ_SetSequencerLength(ADC_TypeDef *ADCx, uint32_t SequencerNbRanks)
  3141. {
  3142. MODIFY_REG(ADCx->JSQR, ADC_JSQR_JL, SequencerNbRanks);
  3143. }
  3144. /**
  3145. * @brief Get ADC group injected sequencer length and scan direction.
  3146. * @note This function retrieves:
  3147. * - Sequence length: Number of ranks in the scan sequence.
  3148. * - Sequence direction: Unless specified in parameters, sequencer
  3149. * scan direction is forward (from rank 1 to rank n).
  3150. * @note Sequencer disabled is equivalent to sequencer of 1 rank:
  3151. * ADC conversion on only 1 channel.
  3152. * @rmtoll JSQR JL LL_ADC_INJ_GetSequencerLength
  3153. * @param ADCx ADC instance
  3154. * @retval Returned value can be one of the following values:
  3155. * @arg @ref LL_ADC_INJ_SEQ_SCAN_DISABLE
  3156. * @arg @ref LL_ADC_INJ_SEQ_SCAN_ENABLE_2RANKS
  3157. * @arg @ref LL_ADC_INJ_SEQ_SCAN_ENABLE_3RANKS
  3158. * @arg @ref LL_ADC_INJ_SEQ_SCAN_ENABLE_4RANKS
  3159. */
  3160. __STATIC_INLINE uint32_t LL_ADC_INJ_GetSequencerLength(ADC_TypeDef *ADCx)
  3161. {
  3162. return (uint32_t)(READ_BIT(ADCx->JSQR, ADC_JSQR_JL));
  3163. }
  3164. /**
  3165. * @brief Set ADC group injected sequencer discontinuous mode:
  3166. * sequence subdivided and scan conversions interrupted every selected
  3167. * number of ranks.
  3168. * @note It is not possible to enable both ADC group injected
  3169. * auto-injected mode and sequencer discontinuous mode.
  3170. * @rmtoll CFGR JDISCEN LL_ADC_INJ_SetSequencerDiscont
  3171. * @param ADCx ADC instance
  3172. * @param SeqDiscont This parameter can be one of the following values:
  3173. * @arg @ref LL_ADC_INJ_SEQ_DISCONT_DISABLE
  3174. * @arg @ref LL_ADC_INJ_SEQ_DISCONT_1RANK
  3175. * @retval None
  3176. */
  3177. __STATIC_INLINE void LL_ADC_INJ_SetSequencerDiscont(ADC_TypeDef *ADCx, uint32_t SeqDiscont)
  3178. {
  3179. MODIFY_REG(ADCx->CFGR, ADC_CFGR_JDISCEN, SeqDiscont);
  3180. }
  3181. /**
  3182. * @brief Get ADC group injected sequencer discontinuous mode:
  3183. * sequence subdivided and scan conversions interrupted every selected
  3184. * number of ranks.
  3185. * @rmtoll CFGR JDISCEN LL_ADC_INJ_GetSequencerDiscont
  3186. * @param ADCx ADC instance
  3187. * @retval Returned value can be one of the following values:
  3188. * @arg @ref LL_ADC_INJ_SEQ_DISCONT_DISABLE
  3189. * @arg @ref LL_ADC_INJ_SEQ_DISCONT_1RANK
  3190. */
  3191. __STATIC_INLINE uint32_t LL_ADC_INJ_GetSequencerDiscont(ADC_TypeDef *ADCx)
  3192. {
  3193. return (uint32_t)(READ_BIT(ADCx->CFGR, ADC_CFGR_JDISCEN));
  3194. }
  3195. /**
  3196. * @brief Set ADC group injected sequence: channel on the selected
  3197. * sequence rank.
  3198. * @note Depending on devices and packages, some channels may not be available.
  3199. * Refer to device datasheet for channels availability.
  3200. * @note On this STM32 serie, to measure internal channels (VrefInt,
  3201. * TempSensor, ...), measurement paths to internal channels must be
  3202. * enabled separately.
  3203. * This can be done using function @ref LL_ADC_SetCommonPathInternalCh().
  3204. * @note On STM32WB, some fast channels are available: fast analog inputs
  3205. * coming from GPIO pads (ADC_IN1..5).
  3206. * @note On this STM32 serie, setting of this feature is conditioned to
  3207. * ADC state:
  3208. * ADC must not be disabled. Can be enabled with or without conversion
  3209. * on going on either groups regular or injected.
  3210. * @rmtoll JSQR JSQ1 LL_ADC_INJ_SetSequencerRanks\n
  3211. * JSQR JSQ2 LL_ADC_INJ_SetSequencerRanks\n
  3212. * JSQR JSQ3 LL_ADC_INJ_SetSequencerRanks\n
  3213. * JSQR JSQ4 LL_ADC_INJ_SetSequencerRanks
  3214. * @param ADCx ADC instance
  3215. * @param Rank This parameter can be one of the following values:
  3216. * @arg @ref LL_ADC_INJ_RANK_1
  3217. * @arg @ref LL_ADC_INJ_RANK_2
  3218. * @arg @ref LL_ADC_INJ_RANK_3
  3219. * @arg @ref LL_ADC_INJ_RANK_4
  3220. * @param Channel This parameter can be one of the following values:
  3221. * @arg @ref LL_ADC_CHANNEL_0
  3222. * @arg @ref LL_ADC_CHANNEL_1 (7)
  3223. * @arg @ref LL_ADC_CHANNEL_2 (7)
  3224. * @arg @ref LL_ADC_CHANNEL_3 (7)
  3225. * @arg @ref LL_ADC_CHANNEL_4 (7)
  3226. * @arg @ref LL_ADC_CHANNEL_5 (7)
  3227. * @arg @ref LL_ADC_CHANNEL_6
  3228. * @arg @ref LL_ADC_CHANNEL_7
  3229. * @arg @ref LL_ADC_CHANNEL_8
  3230. * @arg @ref LL_ADC_CHANNEL_9
  3231. * @arg @ref LL_ADC_CHANNEL_10
  3232. * @arg @ref LL_ADC_CHANNEL_11
  3233. * @arg @ref LL_ADC_CHANNEL_12
  3234. * @arg @ref LL_ADC_CHANNEL_13
  3235. * @arg @ref LL_ADC_CHANNEL_14
  3236. * @arg @ref LL_ADC_CHANNEL_15
  3237. * @arg @ref LL_ADC_CHANNEL_16
  3238. * @arg @ref LL_ADC_CHANNEL_17
  3239. * @arg @ref LL_ADC_CHANNEL_18
  3240. * @arg @ref LL_ADC_CHANNEL_VREFINT
  3241. * @arg @ref LL_ADC_CHANNEL_TEMPSENSOR
  3242. * @arg @ref LL_ADC_CHANNEL_VBAT
  3243. *
  3244. * (7) On STM32WB, fast channel (0.188 us for 12-bit resolution (ADC conversion rate up to 5.33 Ms/s)).
  3245. * Other channels are slow channels (0.238 us for 12-bit resolution (ADC conversion rate up to 4.21 Ms/s)).
  3246. * @retval None
  3247. */
  3248. __STATIC_INLINE void LL_ADC_INJ_SetSequencerRanks(ADC_TypeDef *ADCx, uint32_t Rank, uint32_t Channel)
  3249. {
  3250. /* Set bits with content of parameter "Channel" with bits position */
  3251. /* in register depending on parameter "Rank". */
  3252. /* Parameters "Rank" and "Channel" are used with masks because containing */
  3253. /* other bits reserved for other purpose. */
  3254. MODIFY_REG(ADCx->JSQR,
  3255. (ADC_CHANNEL_ID_NUMBER_MASK >> ADC_CHANNEL_ID_NUMBER_BITOFFSET_POS) << (Rank & ADC_INJ_RANK_ID_JSQR_MASK),
  3256. ((Channel & ADC_CHANNEL_ID_NUMBER_MASK) >> ADC_CHANNEL_ID_NUMBER_BITOFFSET_POS) << (Rank & ADC_INJ_RANK_ID_JSQR_MASK));
  3257. }
  3258. /**
  3259. * @brief Get ADC group injected sequence: channel on the selected
  3260. * sequence rank.
  3261. * @note Depending on devices and packages, some channels may not be available.
  3262. * Refer to device datasheet for channels availability.
  3263. * @note Usage of the returned channel number:
  3264. * - To reinject this channel into another function LL_ADC_xxx:
  3265. * the returned channel number is only partly formatted on definition
  3266. * of literals LL_ADC_CHANNEL_x. Therefore, it has to be compared
  3267. * with parts of literals LL_ADC_CHANNEL_x or using
  3268. * helper macro @ref __LL_ADC_CHANNEL_TO_DECIMAL_NB().
  3269. * Then the selected literal LL_ADC_CHANNEL_x can be used
  3270. * as parameter for another function.
  3271. * - To get the channel number in decimal format:
  3272. * process the returned value with the helper macro
  3273. * @ref __LL_ADC_CHANNEL_TO_DECIMAL_NB().
  3274. * @rmtoll JSQR JSQ1 LL_ADC_INJ_GetSequencerRanks\n
  3275. * JSQR JSQ2 LL_ADC_INJ_GetSequencerRanks\n
  3276. * JSQR JSQ3 LL_ADC_INJ_GetSequencerRanks\n
  3277. * JSQR JSQ4 LL_ADC_INJ_GetSequencerRanks
  3278. * @param ADCx ADC instance
  3279. * @param Rank This parameter can be one of the following values:
  3280. * @arg @ref LL_ADC_INJ_RANK_1
  3281. * @arg @ref LL_ADC_INJ_RANK_2
  3282. * @arg @ref LL_ADC_INJ_RANK_3
  3283. * @arg @ref LL_ADC_INJ_RANK_4
  3284. * @retval Returned value can be one of the following values:
  3285. * @arg @ref LL_ADC_CHANNEL_0
  3286. * @arg @ref LL_ADC_CHANNEL_1 (7)
  3287. * @arg @ref LL_ADC_CHANNEL_2 (7)
  3288. * @arg @ref LL_ADC_CHANNEL_3 (7)
  3289. * @arg @ref LL_ADC_CHANNEL_4 (7)
  3290. * @arg @ref LL_ADC_CHANNEL_5 (7)
  3291. * @arg @ref LL_ADC_CHANNEL_6
  3292. * @arg @ref LL_ADC_CHANNEL_7
  3293. * @arg @ref LL_ADC_CHANNEL_8
  3294. * @arg @ref LL_ADC_CHANNEL_9
  3295. * @arg @ref LL_ADC_CHANNEL_10
  3296. * @arg @ref LL_ADC_CHANNEL_11
  3297. * @arg @ref LL_ADC_CHANNEL_12
  3298. * @arg @ref LL_ADC_CHANNEL_13
  3299. * @arg @ref LL_ADC_CHANNEL_14
  3300. * @arg @ref LL_ADC_CHANNEL_15
  3301. * @arg @ref LL_ADC_CHANNEL_16
  3302. * @arg @ref LL_ADC_CHANNEL_17
  3303. * @arg @ref LL_ADC_CHANNEL_18
  3304. * @arg @ref LL_ADC_CHANNEL_VREFINT (1)
  3305. * @arg @ref LL_ADC_CHANNEL_TEMPSENSOR (4)
  3306. * @arg @ref LL_ADC_CHANNEL_VBAT (4)
  3307. *
  3308. * (7) On STM32WB, fast channel (0.188 us for 12-bit resolution (ADC conversion rate up to 5.33 Ms/s)).
  3309. * Other channels are slow channels (0.238 us for 12-bit resolution (ADC conversion rate up to 4.21 Ms/s)).\n
  3310. * (4) For ADC channel read back from ADC register,
  3311. * comparison with internal channel parameter to be done
  3312. * using helper macro @ref __LL_ADC_CHANNEL_INTERNAL_TO_EXTERNAL().
  3313. */
  3314. __STATIC_INLINE uint32_t LL_ADC_INJ_GetSequencerRanks(ADC_TypeDef *ADCx, uint32_t Rank)
  3315. {
  3316. return (uint32_t)((READ_BIT(ADCx->JSQR,
  3317. (ADC_CHANNEL_ID_NUMBER_MASK >> ADC_CHANNEL_ID_NUMBER_BITOFFSET_POS) << (Rank & ADC_INJ_RANK_ID_JSQR_MASK))
  3318. >> (Rank & ADC_INJ_RANK_ID_JSQR_MASK)) << ADC_CHANNEL_ID_NUMBER_BITOFFSET_POS
  3319. );
  3320. }
  3321. /**
  3322. * @brief Set ADC group injected conversion trigger:
  3323. * independent or from ADC group regular.
  3324. * @note This mode can be used to extend number of data registers
  3325. * updated after one ADC conversion trigger and with data
  3326. * permanently kept (not erased by successive conversions of scan of
  3327. * ADC sequencer ranks), up to 5 data registers:
  3328. * 1 data register on ADC group regular, 4 data registers
  3329. * on ADC group injected.
  3330. * @note If ADC group injected injected trigger source is set to an
  3331. * external trigger, this feature must be must be set to
  3332. * independent trigger.
  3333. * ADC group injected automatic trigger is compliant only with
  3334. * group injected trigger source set to SW start, without any
  3335. * further action on ADC group injected conversion start or stop:
  3336. * in this case, ADC group injected is controlled only
  3337. * from ADC group regular.
  3338. * @note It is not possible to enable both ADC group injected
  3339. * auto-injected mode and sequencer discontinuous mode.
  3340. * @note On this STM32 serie, setting of this feature is conditioned to
  3341. * ADC state:
  3342. * ADC must be disabled or enabled without conversion on going
  3343. * on either groups regular or injected.
  3344. * @rmtoll CFGR JAUTO LL_ADC_INJ_SetTrigAuto
  3345. * @param ADCx ADC instance
  3346. * @param TrigAuto This parameter can be one of the following values:
  3347. * @arg @ref LL_ADC_INJ_TRIG_INDEPENDENT
  3348. * @arg @ref LL_ADC_INJ_TRIG_FROM_GRP_REGULAR
  3349. * @retval None
  3350. */
  3351. __STATIC_INLINE void LL_ADC_INJ_SetTrigAuto(ADC_TypeDef *ADCx, uint32_t TrigAuto)
  3352. {
  3353. MODIFY_REG(ADCx->CFGR, ADC_CFGR_JAUTO, TrigAuto);
  3354. }
  3355. /**
  3356. * @brief Get ADC group injected conversion trigger:
  3357. * independent or from ADC group regular.
  3358. * @rmtoll CFGR JAUTO LL_ADC_INJ_GetTrigAuto
  3359. * @param ADCx ADC instance
  3360. * @retval Returned value can be one of the following values:
  3361. * @arg @ref LL_ADC_INJ_TRIG_INDEPENDENT
  3362. * @arg @ref LL_ADC_INJ_TRIG_FROM_GRP_REGULAR
  3363. */
  3364. __STATIC_INLINE uint32_t LL_ADC_INJ_GetTrigAuto(ADC_TypeDef *ADCx)
  3365. {
  3366. return (uint32_t)(READ_BIT(ADCx->CFGR, ADC_CFGR_JAUTO));
  3367. }
  3368. /**
  3369. * @brief Set ADC group injected contexts queue mode.
  3370. * @note A context is a setting of group injected sequencer:
  3371. * - group injected trigger
  3372. * - sequencer length
  3373. * - sequencer ranks
  3374. * If contexts queue is disabled:
  3375. * - only 1 sequence can be configured
  3376. * and is active perpetually.
  3377. * If contexts queue is enabled:
  3378. * - up to 2 contexts can be queued
  3379. * and are checked in and out as a FIFO stack (first-in, first-out).
  3380. * - If a new context is set when queues is full, error is triggered
  3381. * by interruption "Injected Queue Overflow".
  3382. * - Two behaviors are possible when all contexts have been processed:
  3383. * the contexts queue can maintain the last context active perpetually
  3384. * or can be empty and injected group triggers are disabled.
  3385. * - Triggers can be only external (not internal SW start)
  3386. * - Caution: The sequence must be fully configured in one time
  3387. * (one write of register JSQR makes a check-in of a new context
  3388. * into the queue).
  3389. * Therefore functions to set separately injected trigger and
  3390. * sequencer channels cannot be used, register JSQR must be set
  3391. * using function @ref LL_ADC_INJ_ConfigQueueContext().
  3392. * @note This parameter can be modified only when no conversion is on going
  3393. * on either groups regular or injected.
  3394. * @note A modification of the context mode (bit JQDIS) causes the contexts
  3395. * queue to be flushed and the register JSQR is cleared.
  3396. * @note On this STM32 serie, setting of this feature is conditioned to
  3397. * ADC state:
  3398. * ADC must be disabled or enabled without conversion on going
  3399. * on either groups regular or injected.
  3400. * @rmtoll CFGR JQM LL_ADC_INJ_SetQueueMode\n
  3401. * CFGR JQDIS LL_ADC_INJ_SetQueueMode
  3402. * @param ADCx ADC instance
  3403. * @param QueueMode This parameter can be one of the following values:
  3404. * @arg @ref LL_ADC_INJ_QUEUE_DISABLE
  3405. * @arg @ref LL_ADC_INJ_QUEUE_2CONTEXTS_LAST_ACTIVE
  3406. * @arg @ref LL_ADC_INJ_QUEUE_2CONTEXTS_END_EMPTY
  3407. * @retval None
  3408. */
  3409. __STATIC_INLINE void LL_ADC_INJ_SetQueueMode(ADC_TypeDef *ADCx, uint32_t QueueMode)
  3410. {
  3411. MODIFY_REG(ADCx->CFGR, ADC_CFGR_JQM | ADC_CFGR_JQDIS, QueueMode);
  3412. }
  3413. /**
  3414. * @brief Get ADC group injected context queue mode.
  3415. * @rmtoll CFGR JQM LL_ADC_INJ_GetQueueMode\n
  3416. * CFGR JQDIS LL_ADC_INJ_GetQueueMode
  3417. * @param ADCx ADC instance
  3418. * @retval Returned value can be one of the following values:
  3419. * @arg @ref LL_ADC_INJ_QUEUE_DISABLE
  3420. * @arg @ref LL_ADC_INJ_QUEUE_2CONTEXTS_LAST_ACTIVE
  3421. * @arg @ref LL_ADC_INJ_QUEUE_2CONTEXTS_END_EMPTY
  3422. */
  3423. __STATIC_INLINE uint32_t LL_ADC_INJ_GetQueueMode(ADC_TypeDef *ADCx)
  3424. {
  3425. return (uint32_t)(READ_BIT(ADCx->CFGR, ADC_CFGR_JQM | ADC_CFGR_JQDIS));
  3426. }
  3427. /**
  3428. * @brief Set one context on ADC group injected that will be checked in
  3429. * contexts queue.
  3430. * @note A context is a setting of group injected sequencer:
  3431. * - group injected trigger
  3432. * - sequencer length
  3433. * - sequencer ranks
  3434. * This function is intended to be used when contexts queue is enabled,
  3435. * because the sequence must be fully configured in one time
  3436. * (functions to set separately injected trigger and sequencer channels
  3437. * cannot be used):
  3438. * Refer to function @ref LL_ADC_INJ_SetQueueMode().
  3439. * @note In the contexts queue, only the active context can be read.
  3440. * The parameters of this function can be read using functions:
  3441. * @arg @ref LL_ADC_INJ_GetTriggerSource()
  3442. * @arg @ref LL_ADC_INJ_GetTriggerEdge()
  3443. * @arg @ref LL_ADC_INJ_GetSequencerRanks()
  3444. * @note On this STM32 serie, to measure internal channels (VrefInt,
  3445. * TempSensor, ...), measurement paths to internal channels must be
  3446. * enabled separately.
  3447. * This can be done using function @ref LL_ADC_SetCommonPathInternalCh().
  3448. * @note On STM32WB, some fast channels are available: fast analog inputs
  3449. * coming from GPIO pads (ADC_IN1..5).
  3450. * @note On this STM32 serie, setting of this feature is conditioned to
  3451. * ADC state:
  3452. * ADC must not be disabled. Can be enabled with or without conversion
  3453. * on going on either groups regular or injected.
  3454. * @rmtoll JSQR JEXTSEL LL_ADC_INJ_ConfigQueueContext\n
  3455. * JSQR JEXTEN LL_ADC_INJ_ConfigQueueContext\n
  3456. * JSQR JL LL_ADC_INJ_ConfigQueueContext\n
  3457. * JSQR JSQ1 LL_ADC_INJ_ConfigQueueContext\n
  3458. * JSQR JSQ2 LL_ADC_INJ_ConfigQueueContext\n
  3459. * JSQR JSQ3 LL_ADC_INJ_ConfigQueueContext\n
  3460. * JSQR JSQ4 LL_ADC_INJ_ConfigQueueContext
  3461. * @param ADCx ADC instance
  3462. * @param TriggerSource This parameter can be one of the following values:
  3463. * @arg @ref LL_ADC_INJ_TRIG_SOFTWARE
  3464. * @arg @ref LL_ADC_INJ_TRIG_EXT_TIM1_TRGO
  3465. * @arg @ref LL_ADC_INJ_TRIG_EXT_TIM1_TRGO2
  3466. * @arg @ref LL_ADC_INJ_TRIG_EXT_TIM1_CH4
  3467. * @arg @ref LL_ADC_INJ_TRIG_EXT_TIM2_TRGO
  3468. * @arg @ref LL_ADC_INJ_TRIG_EXT_TIM2_CH1
  3469. * @arg @ref LL_ADC_INJ_TRIG_EXT_EXTI_LINE15
  3470. * @param ExternalTriggerEdge This parameter can be one of the following values:
  3471. * @arg @ref LL_ADC_INJ_TRIG_EXT_RISING
  3472. * @arg @ref LL_ADC_INJ_TRIG_EXT_FALLING
  3473. * @arg @ref LL_ADC_INJ_TRIG_EXT_RISINGFALLING
  3474. *
  3475. * Note: This parameter is discarded in case of SW start:
  3476. * parameter "TriggerSource" set to "LL_ADC_INJ_TRIG_SOFTWARE".
  3477. * @param SequencerNbRanks This parameter can be one of the following values:
  3478. * @arg @ref LL_ADC_INJ_SEQ_SCAN_DISABLE
  3479. * @arg @ref LL_ADC_INJ_SEQ_SCAN_ENABLE_2RANKS
  3480. * @arg @ref LL_ADC_INJ_SEQ_SCAN_ENABLE_3RANKS
  3481. * @arg @ref LL_ADC_INJ_SEQ_SCAN_ENABLE_4RANKS
  3482. * @param Rank1_Channel This parameter can be one of the following values:
  3483. * @arg @ref LL_ADC_CHANNEL_0
  3484. * @arg @ref LL_ADC_CHANNEL_1 (7)
  3485. * @arg @ref LL_ADC_CHANNEL_2 (7)
  3486. * @arg @ref LL_ADC_CHANNEL_3 (7)
  3487. * @arg @ref LL_ADC_CHANNEL_4 (7)
  3488. * @arg @ref LL_ADC_CHANNEL_5 (7)
  3489. * @arg @ref LL_ADC_CHANNEL_6
  3490. * @arg @ref LL_ADC_CHANNEL_7
  3491. * @arg @ref LL_ADC_CHANNEL_8
  3492. * @arg @ref LL_ADC_CHANNEL_9
  3493. * @arg @ref LL_ADC_CHANNEL_10
  3494. * @arg @ref LL_ADC_CHANNEL_11
  3495. * @arg @ref LL_ADC_CHANNEL_12
  3496. * @arg @ref LL_ADC_CHANNEL_13
  3497. * @arg @ref LL_ADC_CHANNEL_14
  3498. * @arg @ref LL_ADC_CHANNEL_15
  3499. * @arg @ref LL_ADC_CHANNEL_16
  3500. * @arg @ref LL_ADC_CHANNEL_17
  3501. * @arg @ref LL_ADC_CHANNEL_18
  3502. * @arg @ref LL_ADC_CHANNEL_VREFINT
  3503. * @arg @ref LL_ADC_CHANNEL_TEMPSENSOR
  3504. * @arg @ref LL_ADC_CHANNEL_VBAT
  3505. *
  3506. * (7) On STM32WB, fast channel (0.188 us for 12-bit resolution (ADC conversion rate up to 5.33 Ms/s)).
  3507. * Other channels are slow channels (0.238 us for 12-bit resolution (ADC conversion rate up to 4.21 Ms/s)).
  3508. * @param Rank2_Channel This parameter can be one of the following values:
  3509. * @arg @ref LL_ADC_CHANNEL_0
  3510. * @arg @ref LL_ADC_CHANNEL_1 (7)
  3511. * @arg @ref LL_ADC_CHANNEL_2 (7)
  3512. * @arg @ref LL_ADC_CHANNEL_3 (7)
  3513. * @arg @ref LL_ADC_CHANNEL_4 (7)
  3514. * @arg @ref LL_ADC_CHANNEL_5 (7)
  3515. * @arg @ref LL_ADC_CHANNEL_6
  3516. * @arg @ref LL_ADC_CHANNEL_7
  3517. * @arg @ref LL_ADC_CHANNEL_8
  3518. * @arg @ref LL_ADC_CHANNEL_9
  3519. * @arg @ref LL_ADC_CHANNEL_10
  3520. * @arg @ref LL_ADC_CHANNEL_11
  3521. * @arg @ref LL_ADC_CHANNEL_12
  3522. * @arg @ref LL_ADC_CHANNEL_13
  3523. * @arg @ref LL_ADC_CHANNEL_14
  3524. * @arg @ref LL_ADC_CHANNEL_15
  3525. * @arg @ref LL_ADC_CHANNEL_16
  3526. * @arg @ref LL_ADC_CHANNEL_17
  3527. * @arg @ref LL_ADC_CHANNEL_18
  3528. * @arg @ref LL_ADC_CHANNEL_VREFINT
  3529. * @arg @ref LL_ADC_CHANNEL_TEMPSENSOR
  3530. * @arg @ref LL_ADC_CHANNEL_VBAT
  3531. *
  3532. * (7) On STM32WB, fast channel (0.188 us for 12-bit resolution (ADC conversion rate up to 5.33 Ms/s)).
  3533. * Other channels are slow channels (0.238 us for 12-bit resolution (ADC conversion rate up to 4.21 Ms/s)).
  3534. * @param Rank3_Channel This parameter can be one of the following values:
  3535. * @arg @ref LL_ADC_CHANNEL_0
  3536. * @arg @ref LL_ADC_CHANNEL_1 (7)
  3537. * @arg @ref LL_ADC_CHANNEL_2 (7)
  3538. * @arg @ref LL_ADC_CHANNEL_3 (7)
  3539. * @arg @ref LL_ADC_CHANNEL_4 (7)
  3540. * @arg @ref LL_ADC_CHANNEL_5 (7)
  3541. * @arg @ref LL_ADC_CHANNEL_6
  3542. * @arg @ref LL_ADC_CHANNEL_7
  3543. * @arg @ref LL_ADC_CHANNEL_8
  3544. * @arg @ref LL_ADC_CHANNEL_9
  3545. * @arg @ref LL_ADC_CHANNEL_10
  3546. * @arg @ref LL_ADC_CHANNEL_11
  3547. * @arg @ref LL_ADC_CHANNEL_12
  3548. * @arg @ref LL_ADC_CHANNEL_13
  3549. * @arg @ref LL_ADC_CHANNEL_14
  3550. * @arg @ref LL_ADC_CHANNEL_15
  3551. * @arg @ref LL_ADC_CHANNEL_16
  3552. * @arg @ref LL_ADC_CHANNEL_17
  3553. * @arg @ref LL_ADC_CHANNEL_18
  3554. * @arg @ref LL_ADC_CHANNEL_VREFINT
  3555. * @arg @ref LL_ADC_CHANNEL_TEMPSENSOR
  3556. * @arg @ref LL_ADC_CHANNEL_VBAT
  3557. *
  3558. * (7) On STM32WB, fast channel (0.188 us for 12-bit resolution (ADC conversion rate up to 5.33 Ms/s)).
  3559. * Other channels are slow channels (0.238 us for 12-bit resolution (ADC conversion rate up to 4.21 Ms/s)).
  3560. * @param Rank4_Channel This parameter can be one of the following values:
  3561. * @arg @ref LL_ADC_CHANNEL_0
  3562. * @arg @ref LL_ADC_CHANNEL_1 (7)
  3563. * @arg @ref LL_ADC_CHANNEL_2 (7)
  3564. * @arg @ref LL_ADC_CHANNEL_3 (7)
  3565. * @arg @ref LL_ADC_CHANNEL_4 (7)
  3566. * @arg @ref LL_ADC_CHANNEL_5 (7)
  3567. * @arg @ref LL_ADC_CHANNEL_6
  3568. * @arg @ref LL_ADC_CHANNEL_7
  3569. * @arg @ref LL_ADC_CHANNEL_8
  3570. * @arg @ref LL_ADC_CHANNEL_9
  3571. * @arg @ref LL_ADC_CHANNEL_10
  3572. * @arg @ref LL_ADC_CHANNEL_11
  3573. * @arg @ref LL_ADC_CHANNEL_12
  3574. * @arg @ref LL_ADC_CHANNEL_13
  3575. * @arg @ref LL_ADC_CHANNEL_14
  3576. * @arg @ref LL_ADC_CHANNEL_15
  3577. * @arg @ref LL_ADC_CHANNEL_16
  3578. * @arg @ref LL_ADC_CHANNEL_17
  3579. * @arg @ref LL_ADC_CHANNEL_18
  3580. * @arg @ref LL_ADC_CHANNEL_VREFINT
  3581. * @arg @ref LL_ADC_CHANNEL_TEMPSENSOR
  3582. * @arg @ref LL_ADC_CHANNEL_VBAT
  3583. *
  3584. * (7) On STM32WB, fast channel (0.188 us for 12-bit resolution (ADC conversion rate up to 5.33 Ms/s)).
  3585. * Other channels are slow channels (0.238 us for 12-bit resolution (ADC conversion rate up to 4.21 Ms/s)).
  3586. * @retval None
  3587. */
  3588. __STATIC_INLINE void LL_ADC_INJ_ConfigQueueContext(ADC_TypeDef *ADCx,
  3589. uint32_t TriggerSource,
  3590. uint32_t ExternalTriggerEdge,
  3591. uint32_t SequencerNbRanks,
  3592. uint32_t Rank1_Channel,
  3593. uint32_t Rank2_Channel,
  3594. uint32_t Rank3_Channel,
  3595. uint32_t Rank4_Channel)
  3596. {
  3597. /* Set bits with content of parameter "Rankx_Channel" with bits position */
  3598. /* in register depending on literal "LL_ADC_INJ_RANK_x". */
  3599. /* Parameters "Rankx_Channel" and "LL_ADC_INJ_RANK_x" are used with masks */
  3600. /* because containing other bits reserved for other purpose. */
  3601. /* If parameter "TriggerSource" is set to SW start, then parameter */
  3602. /* "ExternalTriggerEdge" is discarded. */
  3603. register uint32_t is_trigger_not_sw = (uint32_t)((TriggerSource != LL_ADC_INJ_TRIG_SOFTWARE) ? 1UL : 0UL);
  3604. MODIFY_REG(ADCx->JSQR ,
  3605. ADC_JSQR_JEXTSEL |
  3606. ADC_JSQR_JEXTEN |
  3607. ADC_JSQR_JSQ4 |
  3608. ADC_JSQR_JSQ3 |
  3609. ADC_JSQR_JSQ2 |
  3610. ADC_JSQR_JSQ1 |
  3611. ADC_JSQR_JL ,
  3612. TriggerSource |
  3613. (ExternalTriggerEdge * (is_trigger_not_sw)) |
  3614. (((Rank4_Channel & ADC_CHANNEL_ID_NUMBER_MASK) >> ADC_CHANNEL_ID_NUMBER_BITOFFSET_POS) << (LL_ADC_INJ_RANK_4 & ADC_INJ_RANK_ID_JSQR_MASK)) |
  3615. (((Rank3_Channel & ADC_CHANNEL_ID_NUMBER_MASK) >> ADC_CHANNEL_ID_NUMBER_BITOFFSET_POS) << (LL_ADC_INJ_RANK_3 & ADC_INJ_RANK_ID_JSQR_MASK)) |
  3616. (((Rank2_Channel & ADC_CHANNEL_ID_NUMBER_MASK) >> ADC_CHANNEL_ID_NUMBER_BITOFFSET_POS) << (LL_ADC_INJ_RANK_2 & ADC_INJ_RANK_ID_JSQR_MASK)) |
  3617. (((Rank1_Channel & ADC_CHANNEL_ID_NUMBER_MASK) >> ADC_CHANNEL_ID_NUMBER_BITOFFSET_POS) << (LL_ADC_INJ_RANK_1 & ADC_INJ_RANK_ID_JSQR_MASK)) |
  3618. SequencerNbRanks
  3619. );
  3620. }
  3621. /**
  3622. * @}
  3623. */
  3624. /** @defgroup ADC_LL_EF_Configuration_Channels Configuration of ADC hierarchical scope: channels
  3625. * @{
  3626. */
  3627. /**
  3628. * @brief Set sampling time of the selected ADC channel
  3629. * Unit: ADC clock cycles.
  3630. * @note On this device, sampling time is on channel scope: independently
  3631. * of channel mapped on ADC group regular or injected.
  3632. * @note In case of internal channel (VrefInt, TempSensor, ...) to be
  3633. * converted:
  3634. * sampling time constraints must be respected (sampling time can be
  3635. * adjusted in function of ADC clock frequency and sampling time
  3636. * setting).
  3637. * Refer to device datasheet for timings values (parameters TS_vrefint,
  3638. * TS_temp, ...).
  3639. * @note Conversion time is the addition of sampling time and processing time.
  3640. * On this STM32 serie, ADC processing time is:
  3641. * - 12.5 ADC clock cycles at ADC resolution 12 bits
  3642. * - 10.5 ADC clock cycles at ADC resolution 10 bits
  3643. * - 8.5 ADC clock cycles at ADC resolution 8 bits
  3644. * - 6.5 ADC clock cycles at ADC resolution 6 bits
  3645. * @note In case of ADC conversion of internal channel (VrefInt,
  3646. * temperature sensor, ...), a sampling time minimum value
  3647. * is required.
  3648. * Refer to device datasheet.
  3649. * @note On this STM32 serie, setting of this feature is conditioned to
  3650. * ADC state:
  3651. * ADC must be disabled or enabled without conversion on going
  3652. * on either groups regular or injected.
  3653. * @rmtoll SMPR1 SMP0 LL_ADC_SetChannelSamplingTime\n
  3654. * SMPR1 SMP1 LL_ADC_SetChannelSamplingTime\n
  3655. * SMPR1 SMP2 LL_ADC_SetChannelSamplingTime\n
  3656. * SMPR1 SMP3 LL_ADC_SetChannelSamplingTime\n
  3657. * SMPR1 SMP4 LL_ADC_SetChannelSamplingTime\n
  3658. * SMPR1 SMP5 LL_ADC_SetChannelSamplingTime\n
  3659. * SMPR1 SMP6 LL_ADC_SetChannelSamplingTime\n
  3660. * SMPR1 SMP7 LL_ADC_SetChannelSamplingTime\n
  3661. * SMPR1 SMP8 LL_ADC_SetChannelSamplingTime\n
  3662. * SMPR1 SMP9 LL_ADC_SetChannelSamplingTime\n
  3663. * SMPR2 SMP10 LL_ADC_SetChannelSamplingTime\n
  3664. * SMPR2 SMP11 LL_ADC_SetChannelSamplingTime\n
  3665. * SMPR2 SMP12 LL_ADC_SetChannelSamplingTime\n
  3666. * SMPR2 SMP13 LL_ADC_SetChannelSamplingTime\n
  3667. * SMPR2 SMP14 LL_ADC_SetChannelSamplingTime\n
  3668. * SMPR2 SMP15 LL_ADC_SetChannelSamplingTime\n
  3669. * SMPR2 SMP16 LL_ADC_SetChannelSamplingTime\n
  3670. * SMPR2 SMP17 LL_ADC_SetChannelSamplingTime\n
  3671. * SMPR2 SMP18 LL_ADC_SetChannelSamplingTime
  3672. * @param ADCx ADC instance
  3673. * @param Channel This parameter can be one of the following values:
  3674. * @arg @ref LL_ADC_CHANNEL_0
  3675. * @arg @ref LL_ADC_CHANNEL_1 (7)
  3676. * @arg @ref LL_ADC_CHANNEL_2 (7)
  3677. * @arg @ref LL_ADC_CHANNEL_3 (7)
  3678. * @arg @ref LL_ADC_CHANNEL_4 (7)
  3679. * @arg @ref LL_ADC_CHANNEL_5 (7)
  3680. * @arg @ref LL_ADC_CHANNEL_6
  3681. * @arg @ref LL_ADC_CHANNEL_7
  3682. * @arg @ref LL_ADC_CHANNEL_8
  3683. * @arg @ref LL_ADC_CHANNEL_9
  3684. * @arg @ref LL_ADC_CHANNEL_10
  3685. * @arg @ref LL_ADC_CHANNEL_11
  3686. * @arg @ref LL_ADC_CHANNEL_12
  3687. * @arg @ref LL_ADC_CHANNEL_13
  3688. * @arg @ref LL_ADC_CHANNEL_14
  3689. * @arg @ref LL_ADC_CHANNEL_15
  3690. * @arg @ref LL_ADC_CHANNEL_16
  3691. * @arg @ref LL_ADC_CHANNEL_17
  3692. * @arg @ref LL_ADC_CHANNEL_18
  3693. * @arg @ref LL_ADC_CHANNEL_VREFINT
  3694. * @arg @ref LL_ADC_CHANNEL_TEMPSENSOR
  3695. * @arg @ref LL_ADC_CHANNEL_VBAT
  3696. *
  3697. * (7) On STM32WB, fast channel (0.188 us for 12-bit resolution (ADC conversion rate up to 5.33 Ms/s)).
  3698. * Other channels are slow channels (0.238 us for 12-bit resolution (ADC conversion rate up to 4.21 Ms/s)).
  3699. * @param SamplingTime This parameter can be one of the following values:
  3700. * @arg @ref LL_ADC_SAMPLINGTIME_2CYCLES_5
  3701. * @arg @ref LL_ADC_SAMPLINGTIME_6CYCLES_5
  3702. * @arg @ref LL_ADC_SAMPLINGTIME_12CYCLES_5
  3703. * @arg @ref LL_ADC_SAMPLINGTIME_24CYCLES_5
  3704. * @arg @ref LL_ADC_SAMPLINGTIME_47CYCLES_5
  3705. * @arg @ref LL_ADC_SAMPLINGTIME_92CYCLES_5
  3706. * @arg @ref LL_ADC_SAMPLINGTIME_247CYCLES_5
  3707. * @arg @ref LL_ADC_SAMPLINGTIME_640CYCLES_5
  3708. * @retval None
  3709. */
  3710. __STATIC_INLINE void LL_ADC_SetChannelSamplingTime(ADC_TypeDef *ADCx, uint32_t Channel, uint32_t SamplingTime)
  3711. {
  3712. /* Set bits with content of parameter "SamplingTime" with bits position */
  3713. /* in register and register position depending on parameter "Channel". */
  3714. /* Parameter "Channel" is used with masks because containing */
  3715. /* other bits reserved for other purpose. */
  3716. register __IO uint32_t *preg = __ADC_PTR_REG_OFFSET(ADCx->SMPR1, ((Channel & ADC_CHANNEL_SMPRX_REGOFFSET_MASK) >> ADC_SMPRX_REGOFFSET_POS));
  3717. MODIFY_REG(*preg,
  3718. ADC_SMPR1_SMP0 << ((Channel & ADC_CHANNEL_SMPx_BITOFFSET_MASK) >> ADC_CHANNEL_SMPx_BITOFFSET_POS),
  3719. SamplingTime << ((Channel & ADC_CHANNEL_SMPx_BITOFFSET_MASK) >> ADC_CHANNEL_SMPx_BITOFFSET_POS));
  3720. }
  3721. /**
  3722. * @brief Get sampling time of the selected ADC channel
  3723. * Unit: ADC clock cycles.
  3724. * @note On this device, sampling time is on channel scope: independently
  3725. * of channel mapped on ADC group regular or injected.
  3726. * @note Conversion time is the addition of sampling time and processing time.
  3727. * On this STM32 serie, ADC processing time is:
  3728. * - 12.5 ADC clock cycles at ADC resolution 12 bits
  3729. * - 10.5 ADC clock cycles at ADC resolution 10 bits
  3730. * - 8.5 ADC clock cycles at ADC resolution 8 bits
  3731. * - 6.5 ADC clock cycles at ADC resolution 6 bits
  3732. * @rmtoll SMPR1 SMP0 LL_ADC_GetChannelSamplingTime\n
  3733. * SMPR1 SMP1 LL_ADC_GetChannelSamplingTime\n
  3734. * SMPR1 SMP2 LL_ADC_GetChannelSamplingTime\n
  3735. * SMPR1 SMP3 LL_ADC_GetChannelSamplingTime\n
  3736. * SMPR1 SMP4 LL_ADC_GetChannelSamplingTime\n
  3737. * SMPR1 SMP5 LL_ADC_GetChannelSamplingTime\n
  3738. * SMPR1 SMP6 LL_ADC_GetChannelSamplingTime\n
  3739. * SMPR1 SMP7 LL_ADC_GetChannelSamplingTime\n
  3740. * SMPR1 SMP8 LL_ADC_GetChannelSamplingTime\n
  3741. * SMPR1 SMP9 LL_ADC_GetChannelSamplingTime\n
  3742. * SMPR2 SMP10 LL_ADC_GetChannelSamplingTime\n
  3743. * SMPR2 SMP11 LL_ADC_GetChannelSamplingTime\n
  3744. * SMPR2 SMP12 LL_ADC_GetChannelSamplingTime\n
  3745. * SMPR2 SMP13 LL_ADC_GetChannelSamplingTime\n
  3746. * SMPR2 SMP14 LL_ADC_GetChannelSamplingTime\n
  3747. * SMPR2 SMP15 LL_ADC_GetChannelSamplingTime\n
  3748. * SMPR2 SMP16 LL_ADC_GetChannelSamplingTime\n
  3749. * SMPR2 SMP17 LL_ADC_GetChannelSamplingTime\n
  3750. * SMPR2 SMP18 LL_ADC_GetChannelSamplingTime
  3751. * @param ADCx ADC instance
  3752. * @param Channel This parameter can be one of the following values:
  3753. * @arg @ref LL_ADC_CHANNEL_0
  3754. * @arg @ref LL_ADC_CHANNEL_1 (7)
  3755. * @arg @ref LL_ADC_CHANNEL_2 (7)
  3756. * @arg @ref LL_ADC_CHANNEL_3 (7)
  3757. * @arg @ref LL_ADC_CHANNEL_4 (7)
  3758. * @arg @ref LL_ADC_CHANNEL_5 (7)
  3759. * @arg @ref LL_ADC_CHANNEL_6
  3760. * @arg @ref LL_ADC_CHANNEL_7
  3761. * @arg @ref LL_ADC_CHANNEL_8
  3762. * @arg @ref LL_ADC_CHANNEL_9
  3763. * @arg @ref LL_ADC_CHANNEL_10
  3764. * @arg @ref LL_ADC_CHANNEL_11
  3765. * @arg @ref LL_ADC_CHANNEL_12
  3766. * @arg @ref LL_ADC_CHANNEL_13
  3767. * @arg @ref LL_ADC_CHANNEL_14
  3768. * @arg @ref LL_ADC_CHANNEL_15
  3769. * @arg @ref LL_ADC_CHANNEL_16
  3770. * @arg @ref LL_ADC_CHANNEL_17
  3771. * @arg @ref LL_ADC_CHANNEL_18
  3772. * @arg @ref LL_ADC_CHANNEL_VREFINT
  3773. * @arg @ref LL_ADC_CHANNEL_TEMPSENSOR
  3774. * @arg @ref LL_ADC_CHANNEL_VBAT
  3775. *
  3776. * (7) On STM32WB, fast channel (0.188 us for 12-bit resolution (ADC conversion rate up to 5.33 Ms/s)).
  3777. * Other channels are slow channels (0.238 us for 12-bit resolution (ADC conversion rate up to 4.21 Ms/s)).
  3778. * @retval Returned value can be one of the following values:
  3779. * @arg @ref LL_ADC_SAMPLINGTIME_2CYCLES_5
  3780. * @arg @ref LL_ADC_SAMPLINGTIME_6CYCLES_5
  3781. * @arg @ref LL_ADC_SAMPLINGTIME_12CYCLES_5
  3782. * @arg @ref LL_ADC_SAMPLINGTIME_24CYCLES_5
  3783. * @arg @ref LL_ADC_SAMPLINGTIME_47CYCLES_5
  3784. * @arg @ref LL_ADC_SAMPLINGTIME_92CYCLES_5
  3785. * @arg @ref LL_ADC_SAMPLINGTIME_247CYCLES_5
  3786. * @arg @ref LL_ADC_SAMPLINGTIME_640CYCLES_5
  3787. */
  3788. __STATIC_INLINE uint32_t LL_ADC_GetChannelSamplingTime(ADC_TypeDef *ADCx, uint32_t Channel)
  3789. {
  3790. register const __IO uint32_t *preg = __ADC_PTR_REG_OFFSET(ADCx->SMPR1, ((Channel & ADC_CHANNEL_SMPRX_REGOFFSET_MASK) >> ADC_SMPRX_REGOFFSET_POS));
  3791. return (uint32_t)(READ_BIT(*preg,
  3792. ADC_SMPR1_SMP0 << ((Channel & ADC_CHANNEL_SMPx_BITOFFSET_MASK) >> ADC_CHANNEL_SMPx_BITOFFSET_POS))
  3793. >> ((Channel & ADC_CHANNEL_SMPx_BITOFFSET_MASK) >> ADC_CHANNEL_SMPx_BITOFFSET_POS)
  3794. );
  3795. }
  3796. /**
  3797. * @brief Set mode single-ended or differential input of the selected
  3798. * ADC channel.
  3799. * @note Channel ending is on channel scope: independently of channel mapped
  3800. * on ADC group regular or injected.
  3801. * In differential mode: Differential measurement is carried out
  3802. * between the selected channel 'i' (positive input) and
  3803. * channel 'i+1' (negative input). Only channel 'i' has to be
  3804. * configured, channel 'i+1' is configured automatically.
  3805. * @note Refer to Reference Manual to ensure the selected channel is
  3806. * available in differential mode.
  3807. * For example, internal channels (VrefInt, TempSensor, ...) are
  3808. * not available in differential mode.
  3809. * @note When configuring a channel 'i' in differential mode,
  3810. * the channel 'i+1' is not usable separately.
  3811. * @note On STM32WB, channels 16, 17, 18 of ADC1
  3812. * are internally fixed to single-ended inputs configuration.
  3813. * @note For ADC channels configured in differential mode, both inputs
  3814. * should be biased at (Vref+)/2 +/-200mV.
  3815. * (Vref+ is the analog voltage reference)
  3816. * @note On this STM32 serie, setting of this feature is conditioned to
  3817. * ADC state:
  3818. * ADC must be ADC disabled.
  3819. * @note One or several values can be selected.
  3820. * Example: (LL_ADC_CHANNEL_4 | LL_ADC_CHANNEL_12 | ...)
  3821. * @rmtoll DIFSEL DIFSEL LL_ADC_SetChannelSingleDiff
  3822. * @param ADCx ADC instance
  3823. * @param Channel This parameter can be one of the following values:
  3824. * @arg @ref LL_ADC_CHANNEL_1
  3825. * @arg @ref LL_ADC_CHANNEL_2
  3826. * @arg @ref LL_ADC_CHANNEL_3
  3827. * @arg @ref LL_ADC_CHANNEL_4
  3828. * @arg @ref LL_ADC_CHANNEL_5
  3829. * @arg @ref LL_ADC_CHANNEL_6
  3830. * @arg @ref LL_ADC_CHANNEL_7
  3831. * @arg @ref LL_ADC_CHANNEL_8
  3832. * @arg @ref LL_ADC_CHANNEL_9
  3833. * @arg @ref LL_ADC_CHANNEL_10
  3834. * @arg @ref LL_ADC_CHANNEL_11
  3835. * @arg @ref LL_ADC_CHANNEL_12
  3836. * @arg @ref LL_ADC_CHANNEL_13
  3837. * @arg @ref LL_ADC_CHANNEL_14
  3838. * @arg @ref LL_ADC_CHANNEL_15
  3839. * @param SingleDiff This parameter can be a combination of the following values:
  3840. * @arg @ref LL_ADC_SINGLE_ENDED
  3841. * @arg @ref LL_ADC_DIFFERENTIAL_ENDED
  3842. * @retval None
  3843. */
  3844. __STATIC_INLINE void LL_ADC_SetChannelSingleDiff(ADC_TypeDef *ADCx, uint32_t Channel, uint32_t SingleDiff)
  3845. {
  3846. /* Bits of channels in single or differential mode are set only for */
  3847. /* differential mode (for single mode, mask of bits allowed to be set is */
  3848. /* shifted out of range of bits of channels in single or differential mode. */
  3849. MODIFY_REG(ADCx->DIFSEL,
  3850. Channel & ADC_SINGLEDIFF_CHANNEL_MASK,
  3851. (Channel & ADC_SINGLEDIFF_CHANNEL_MASK) & (ADC_DIFSEL_DIFSEL >> (SingleDiff & ADC_SINGLEDIFF_CHANNEL_SHIFT_MASK)));
  3852. }
  3853. /**
  3854. * @brief Get mode single-ended or differential input of the selected
  3855. * ADC channel.
  3856. * @note When configuring a channel 'i' in differential mode,
  3857. * the channel 'i+1' is not usable separately.
  3858. * Therefore, to ensure a channel is configured in single-ended mode,
  3859. * the configuration of channel itself and the channel 'i-1' must be
  3860. * read back (to ensure that the selected channel channel has not been
  3861. * configured in differential mode by the previous channel).
  3862. * @note Refer to Reference Manual to ensure the selected channel is
  3863. * available in differential mode.
  3864. * For example, internal channels (VrefInt, TempSensor, ...) are
  3865. * not available in differential mode.
  3866. * @note When configuring a channel 'i' in differential mode,
  3867. * the channel 'i+1' is not usable separately.
  3868. * @note On STM32WB, channels 16, 17, 18 of ADC1
  3869. * are internally fixed to single-ended inputs configuration.
  3870. * @note One or several values can be selected. In this case, the value
  3871. * returned is null if all channels are in single ended-mode.
  3872. * Example: (LL_ADC_CHANNEL_4 | LL_ADC_CHANNEL_12 | ...)
  3873. * @rmtoll DIFSEL DIFSEL LL_ADC_GetChannelSingleDiff
  3874. * @param ADCx ADC instance
  3875. * @param Channel This parameter can be a combination of the following values:
  3876. * @arg @ref LL_ADC_CHANNEL_1
  3877. * @arg @ref LL_ADC_CHANNEL_2
  3878. * @arg @ref LL_ADC_CHANNEL_3
  3879. * @arg @ref LL_ADC_CHANNEL_4
  3880. * @arg @ref LL_ADC_CHANNEL_5
  3881. * @arg @ref LL_ADC_CHANNEL_6
  3882. * @arg @ref LL_ADC_CHANNEL_7
  3883. * @arg @ref LL_ADC_CHANNEL_8
  3884. * @arg @ref LL_ADC_CHANNEL_9
  3885. * @arg @ref LL_ADC_CHANNEL_10
  3886. * @arg @ref LL_ADC_CHANNEL_11
  3887. * @arg @ref LL_ADC_CHANNEL_12
  3888. * @arg @ref LL_ADC_CHANNEL_13
  3889. * @arg @ref LL_ADC_CHANNEL_14
  3890. * @arg @ref LL_ADC_CHANNEL_15
  3891. * @retval 0: channel in single-ended mode, else: channel in differential mode
  3892. */
  3893. __STATIC_INLINE uint32_t LL_ADC_GetChannelSingleDiff(ADC_TypeDef *ADCx, uint32_t Channel)
  3894. {
  3895. return (uint32_t)(READ_BIT(ADCx->DIFSEL, (Channel & ADC_SINGLEDIFF_CHANNEL_MASK)));
  3896. }
  3897. /**
  3898. * @}
  3899. */
  3900. /** @defgroup ADC_LL_EF_Configuration_ADC_AnalogWatchdog Configuration of ADC transversal scope: analog watchdog
  3901. * @{
  3902. */
  3903. /**
  3904. * @brief Set ADC analog watchdog monitored channels:
  3905. * a single channel, multiple channels or all channels,
  3906. * on ADC groups regular and-or injected.
  3907. * @note Once monitored channels are selected, analog watchdog
  3908. * is enabled.
  3909. * @note In case of need to define a single channel to monitor
  3910. * with analog watchdog from sequencer channel definition,
  3911. * use helper macro @ref __LL_ADC_ANALOGWD_CHANNEL_GROUP().
  3912. * @note On this STM32 serie, there are 2 kinds of analog watchdog
  3913. * instance:
  3914. * - AWD standard (instance AWD1):
  3915. * - channels monitored: can monitor 1 channel or all channels.
  3916. * - groups monitored: ADC groups regular and-or injected.
  3917. * - resolution: resolution is not limited (corresponds to
  3918. * ADC resolution configured).
  3919. * - AWD flexible (instances AWD2, AWD3):
  3920. * - channels monitored: flexible on channels monitored, selection is
  3921. * channel wise, from from 1 to all channels.
  3922. * Specificity of this analog watchdog: Multiple channels can
  3923. * be selected. For example:
  3924. * (LL_ADC_AWD_CHANNEL4_REG_INJ | LL_ADC_AWD_CHANNEL5_REG_INJ | ...)
  3925. * - groups monitored: not selection possible (monitoring on both
  3926. * groups regular and injected).
  3927. * Channels selected are monitored on groups regular and injected:
  3928. * LL_ADC_AWD_CHANNELxx_REG_INJ (do not use parameters
  3929. * LL_ADC_AWD_CHANNELxx_REG and LL_ADC_AWD_CHANNELxx_INJ)
  3930. * - resolution: resolution is limited to 8 bits: if ADC resolution is
  3931. * 12 bits the 4 LSB are ignored, if ADC resolution is 10 bits
  3932. * the 2 LSB are ignored.
  3933. * @note On this STM32 serie, setting of this feature is conditioned to
  3934. * ADC state:
  3935. * ADC must be disabled or enabled without conversion on going
  3936. * on either groups regular or injected.
  3937. * @rmtoll CFGR AWD1CH LL_ADC_SetAnalogWDMonitChannels\n
  3938. * CFGR AWD1SGL LL_ADC_SetAnalogWDMonitChannels\n
  3939. * CFGR AWD1EN LL_ADC_SetAnalogWDMonitChannels\n
  3940. * CFGR JAWD1EN LL_ADC_SetAnalogWDMonitChannels\n
  3941. * AWD2CR AWD2CH LL_ADC_SetAnalogWDMonitChannels\n
  3942. * AWD3CR AWD3CH LL_ADC_SetAnalogWDMonitChannels
  3943. * @param ADCx ADC instance
  3944. * @param AWDy This parameter can be one of the following values:
  3945. * @arg @ref LL_ADC_AWD1
  3946. * @arg @ref LL_ADC_AWD2
  3947. * @arg @ref LL_ADC_AWD3
  3948. * @param AWDChannelGroup This parameter can be one of the following values:
  3949. * @arg @ref LL_ADC_AWD_DISABLE
  3950. * @arg @ref LL_ADC_AWD_ALL_CHANNELS_REG (0)
  3951. * @arg @ref LL_ADC_AWD_ALL_CHANNELS_INJ (0)
  3952. * @arg @ref LL_ADC_AWD_ALL_CHANNELS_REG_INJ
  3953. * @arg @ref LL_ADC_AWD_CHANNEL_0_REG (0)
  3954. * @arg @ref LL_ADC_AWD_CHANNEL_0_INJ (0)
  3955. * @arg @ref LL_ADC_AWD_CHANNEL_0_REG_INJ
  3956. * @arg @ref LL_ADC_AWD_CHANNEL_1_REG (0)
  3957. * @arg @ref LL_ADC_AWD_CHANNEL_1_INJ (0)
  3958. * @arg @ref LL_ADC_AWD_CHANNEL_1_REG_INJ
  3959. * @arg @ref LL_ADC_AWD_CHANNEL_2_REG (0)
  3960. * @arg @ref LL_ADC_AWD_CHANNEL_2_INJ (0)
  3961. * @arg @ref LL_ADC_AWD_CHANNEL_2_REG_INJ
  3962. * @arg @ref LL_ADC_AWD_CHANNEL_3_REG (0)
  3963. * @arg @ref LL_ADC_AWD_CHANNEL_3_INJ (0)
  3964. * @arg @ref LL_ADC_AWD_CHANNEL_3_REG_INJ
  3965. * @arg @ref LL_ADC_AWD_CHANNEL_4_REG (0)
  3966. * @arg @ref LL_ADC_AWD_CHANNEL_4_INJ (0)
  3967. * @arg @ref LL_ADC_AWD_CHANNEL_4_REG_INJ
  3968. * @arg @ref LL_ADC_AWD_CHANNEL_5_REG (0)
  3969. * @arg @ref LL_ADC_AWD_CHANNEL_5_INJ (0)
  3970. * @arg @ref LL_ADC_AWD_CHANNEL_5_REG_INJ
  3971. * @arg @ref LL_ADC_AWD_CHANNEL_6_REG (0)
  3972. * @arg @ref LL_ADC_AWD_CHANNEL_6_INJ (0)
  3973. * @arg @ref LL_ADC_AWD_CHANNEL_6_REG_INJ
  3974. * @arg @ref LL_ADC_AWD_CHANNEL_7_REG (0)
  3975. * @arg @ref LL_ADC_AWD_CHANNEL_7_INJ (0)
  3976. * @arg @ref LL_ADC_AWD_CHANNEL_7_REG_INJ
  3977. * @arg @ref LL_ADC_AWD_CHANNEL_8_REG (0)
  3978. * @arg @ref LL_ADC_AWD_CHANNEL_8_INJ (0)
  3979. * @arg @ref LL_ADC_AWD_CHANNEL_8_REG_INJ
  3980. * @arg @ref LL_ADC_AWD_CHANNEL_9_REG (0)
  3981. * @arg @ref LL_ADC_AWD_CHANNEL_9_INJ (0)
  3982. * @arg @ref LL_ADC_AWD_CHANNEL_9_REG_INJ
  3983. * @arg @ref LL_ADC_AWD_CHANNEL_10_REG (0)
  3984. * @arg @ref LL_ADC_AWD_CHANNEL_10_INJ (0)
  3985. * @arg @ref LL_ADC_AWD_CHANNEL_10_REG_INJ
  3986. * @arg @ref LL_ADC_AWD_CHANNEL_11_REG (0)
  3987. * @arg @ref LL_ADC_AWD_CHANNEL_11_INJ (0)
  3988. * @arg @ref LL_ADC_AWD_CHANNEL_11_REG_INJ
  3989. * @arg @ref LL_ADC_AWD_CHANNEL_12_REG (0)
  3990. * @arg @ref LL_ADC_AWD_CHANNEL_12_INJ (0)
  3991. * @arg @ref LL_ADC_AWD_CHANNEL_12_REG_INJ
  3992. * @arg @ref LL_ADC_AWD_CHANNEL_13_REG (0)
  3993. * @arg @ref LL_ADC_AWD_CHANNEL_13_INJ (0)
  3994. * @arg @ref LL_ADC_AWD_CHANNEL_13_REG_INJ
  3995. * @arg @ref LL_ADC_AWD_CHANNEL_14_REG (0)
  3996. * @arg @ref LL_ADC_AWD_CHANNEL_14_INJ (0)
  3997. * @arg @ref LL_ADC_AWD_CHANNEL_14_REG_INJ
  3998. * @arg @ref LL_ADC_AWD_CHANNEL_15_REG (0)
  3999. * @arg @ref LL_ADC_AWD_CHANNEL_15_INJ (0)
  4000. * @arg @ref LL_ADC_AWD_CHANNEL_15_REG_INJ
  4001. * @arg @ref LL_ADC_AWD_CHANNEL_16_REG (0)
  4002. * @arg @ref LL_ADC_AWD_CHANNEL_16_INJ (0)
  4003. * @arg @ref LL_ADC_AWD_CHANNEL_16_REG_INJ
  4004. * @arg @ref LL_ADC_AWD_CHANNEL_17_REG (0)
  4005. * @arg @ref LL_ADC_AWD_CHANNEL_17_INJ (0)
  4006. * @arg @ref LL_ADC_AWD_CHANNEL_17_REG_INJ
  4007. * @arg @ref LL_ADC_AWD_CHANNEL_18_REG (0)
  4008. * @arg @ref LL_ADC_AWD_CHANNEL_18_INJ (0)
  4009. * @arg @ref LL_ADC_AWD_CHANNEL_18_REG_INJ
  4010. * @arg @ref LL_ADC_AWD_CH_VREFINT_REG (0)
  4011. * @arg @ref LL_ADC_AWD_CH_VREFINT_INJ (0)
  4012. * @arg @ref LL_ADC_AWD_CH_VREFINT_REG_INJ
  4013. * @arg @ref LL_ADC_AWD_CH_TEMPSENSOR_REG (0)
  4014. * @arg @ref LL_ADC_AWD_CH_TEMPSENSOR_INJ (0)
  4015. * @arg @ref LL_ADC_AWD_CH_TEMPSENSOR_REG_INJ
  4016. * @arg @ref LL_ADC_AWD_CH_VBAT_REG (0)
  4017. * @arg @ref LL_ADC_AWD_CH_VBAT_INJ (0)
  4018. * @arg @ref LL_ADC_AWD_CH_VBAT_REG_INJ
  4019. *
  4020. * (0) On STM32WB, parameter available only on analog watchdog number: AWD1.
  4021. * @retval None
  4022. */
  4023. __STATIC_INLINE void LL_ADC_SetAnalogWDMonitChannels(ADC_TypeDef *ADCx, uint32_t AWDy, uint32_t AWDChannelGroup)
  4024. {
  4025. /* Set bits with content of parameter "AWDChannelGroup" with bits position */
  4026. /* in register and register position depending on parameter "AWDy". */
  4027. /* Parameters "AWDChannelGroup" and "AWDy" are used with masks because */
  4028. /* containing other bits reserved for other purpose. */
  4029. register __IO uint32_t *preg = __ADC_PTR_REG_OFFSET(ADCx->CFGR, ((AWDy & ADC_AWD_CRX_REGOFFSET_MASK) >> ADC_AWD_CRX_REGOFFSET_POS)
  4030. + ((AWDy & ADC_AWD_CR12_REGOFFSETGAP_MASK) * ADC_AWD_CR12_REGOFFSETGAP_VAL));
  4031. MODIFY_REG(*preg,
  4032. (AWDy & ADC_AWD_CR_ALL_CHANNEL_MASK),
  4033. AWDChannelGroup & AWDy);
  4034. }
  4035. /**
  4036. * @brief Get ADC analog watchdog monitored channel.
  4037. * @note Usage of the returned channel number:
  4038. * - To reinject this channel into another function LL_ADC_xxx:
  4039. * the returned channel number is only partly formatted on definition
  4040. * of literals LL_ADC_CHANNEL_x. Therefore, it has to be compared
  4041. * with parts of literals LL_ADC_CHANNEL_x or using
  4042. * helper macro @ref __LL_ADC_CHANNEL_TO_DECIMAL_NB().
  4043. * Then the selected literal LL_ADC_CHANNEL_x can be used
  4044. * as parameter for another function.
  4045. * - To get the channel number in decimal format:
  4046. * process the returned value with the helper macro
  4047. * @ref __LL_ADC_CHANNEL_TO_DECIMAL_NB().
  4048. * Applicable only when the analog watchdog is set to monitor
  4049. * one channel.
  4050. * @note On this STM32 serie, there are 2 kinds of analog watchdog
  4051. * instance:
  4052. * - AWD standard (instance AWD1):
  4053. * - channels monitored: can monitor 1 channel or all channels.
  4054. * - groups monitored: ADC groups regular and-or injected.
  4055. * - resolution: resolution is not limited (corresponds to
  4056. * ADC resolution configured).
  4057. * - AWD flexible (instances AWD2, AWD3):
  4058. * - channels monitored: flexible on channels monitored, selection is
  4059. * channel wise, from from 1 to all channels.
  4060. * Specificity of this analog watchdog: Multiple channels can
  4061. * be selected. For example:
  4062. * (LL_ADC_AWD_CHANNEL4_REG_INJ | LL_ADC_AWD_CHANNEL5_REG_INJ | ...)
  4063. * - groups monitored: not selection possible (monitoring on both
  4064. * groups regular and injected).
  4065. * Channels selected are monitored on groups regular and injected:
  4066. * LL_ADC_AWD_CHANNELxx_REG_INJ (do not use parameters
  4067. * LL_ADC_AWD_CHANNELxx_REG and LL_ADC_AWD_CHANNELxx_INJ)
  4068. * - resolution: resolution is limited to 8 bits: if ADC resolution is
  4069. * 12 bits the 4 LSB are ignored, if ADC resolution is 10 bits
  4070. * the 2 LSB are ignored.
  4071. * @note On this STM32 serie, setting of this feature is conditioned to
  4072. * ADC state:
  4073. * ADC must be disabled or enabled without conversion on going
  4074. * on either groups regular or injected.
  4075. * @rmtoll CFGR AWD1CH LL_ADC_GetAnalogWDMonitChannels\n
  4076. * CFGR AWD1SGL LL_ADC_GetAnalogWDMonitChannels\n
  4077. * CFGR AWD1EN LL_ADC_GetAnalogWDMonitChannels\n
  4078. * CFGR JAWD1EN LL_ADC_GetAnalogWDMonitChannels\n
  4079. * AWD2CR AWD2CH LL_ADC_GetAnalogWDMonitChannels\n
  4080. * AWD3CR AWD3CH LL_ADC_GetAnalogWDMonitChannels
  4081. * @param ADCx ADC instance
  4082. * @param AWDy This parameter can be one of the following values:
  4083. * @arg @ref LL_ADC_AWD1
  4084. * @arg @ref LL_ADC_AWD2 (1)
  4085. * @arg @ref LL_ADC_AWD3 (1)
  4086. *
  4087. * (1) On this AWD number, monitored channel can be retrieved
  4088. * if only 1 channel is programmed (or none or all channels).
  4089. * This function cannot retrieve monitored channel if
  4090. * multiple channels are programmed simultaneously
  4091. * by bitfield.
  4092. * @retval Returned value can be one of the following values:
  4093. * @arg @ref LL_ADC_AWD_DISABLE
  4094. * @arg @ref LL_ADC_AWD_ALL_CHANNELS_REG (0)
  4095. * @arg @ref LL_ADC_AWD_ALL_CHANNELS_INJ (0)
  4096. * @arg @ref LL_ADC_AWD_ALL_CHANNELS_REG_INJ
  4097. * @arg @ref LL_ADC_AWD_CHANNEL_0_REG (0)
  4098. * @arg @ref LL_ADC_AWD_CHANNEL_0_INJ (0)
  4099. * @arg @ref LL_ADC_AWD_CHANNEL_0_REG_INJ
  4100. * @arg @ref LL_ADC_AWD_CHANNEL_1_REG (0)
  4101. * @arg @ref LL_ADC_AWD_CHANNEL_1_INJ (0)
  4102. * @arg @ref LL_ADC_AWD_CHANNEL_1_REG_INJ
  4103. * @arg @ref LL_ADC_AWD_CHANNEL_2_REG (0)
  4104. * @arg @ref LL_ADC_AWD_CHANNEL_2_INJ (0)
  4105. * @arg @ref LL_ADC_AWD_CHANNEL_2_REG_INJ
  4106. * @arg @ref LL_ADC_AWD_CHANNEL_3_REG (0)
  4107. * @arg @ref LL_ADC_AWD_CHANNEL_3_INJ (0)
  4108. * @arg @ref LL_ADC_AWD_CHANNEL_3_REG_INJ
  4109. * @arg @ref LL_ADC_AWD_CHANNEL_4_REG (0)
  4110. * @arg @ref LL_ADC_AWD_CHANNEL_4_INJ (0)
  4111. * @arg @ref LL_ADC_AWD_CHANNEL_4_REG_INJ
  4112. * @arg @ref LL_ADC_AWD_CHANNEL_5_REG (0)
  4113. * @arg @ref LL_ADC_AWD_CHANNEL_5_INJ (0)
  4114. * @arg @ref LL_ADC_AWD_CHANNEL_5_REG_INJ
  4115. * @arg @ref LL_ADC_AWD_CHANNEL_6_REG (0)
  4116. * @arg @ref LL_ADC_AWD_CHANNEL_6_INJ (0)
  4117. * @arg @ref LL_ADC_AWD_CHANNEL_6_REG_INJ
  4118. * @arg @ref LL_ADC_AWD_CHANNEL_7_REG (0)
  4119. * @arg @ref LL_ADC_AWD_CHANNEL_7_INJ (0)
  4120. * @arg @ref LL_ADC_AWD_CHANNEL_7_REG_INJ
  4121. * @arg @ref LL_ADC_AWD_CHANNEL_8_REG (0)
  4122. * @arg @ref LL_ADC_AWD_CHANNEL_8_INJ (0)
  4123. * @arg @ref LL_ADC_AWD_CHANNEL_8_REG_INJ
  4124. * @arg @ref LL_ADC_AWD_CHANNEL_9_REG (0)
  4125. * @arg @ref LL_ADC_AWD_CHANNEL_9_INJ (0)
  4126. * @arg @ref LL_ADC_AWD_CHANNEL_9_REG_INJ
  4127. * @arg @ref LL_ADC_AWD_CHANNEL_10_REG (0)
  4128. * @arg @ref LL_ADC_AWD_CHANNEL_10_INJ (0)
  4129. * @arg @ref LL_ADC_AWD_CHANNEL_10_REG_INJ
  4130. * @arg @ref LL_ADC_AWD_CHANNEL_11_REG (0)
  4131. * @arg @ref LL_ADC_AWD_CHANNEL_11_INJ (0)
  4132. * @arg @ref LL_ADC_AWD_CHANNEL_11_REG_INJ
  4133. * @arg @ref LL_ADC_AWD_CHANNEL_12_REG (0)
  4134. * @arg @ref LL_ADC_AWD_CHANNEL_12_INJ (0)
  4135. * @arg @ref LL_ADC_AWD_CHANNEL_12_REG_INJ
  4136. * @arg @ref LL_ADC_AWD_CHANNEL_13_REG (0)
  4137. * @arg @ref LL_ADC_AWD_CHANNEL_13_INJ (0)
  4138. * @arg @ref LL_ADC_AWD_CHANNEL_13_REG_INJ
  4139. * @arg @ref LL_ADC_AWD_CHANNEL_14_REG (0)
  4140. * @arg @ref LL_ADC_AWD_CHANNEL_14_INJ (0)
  4141. * @arg @ref LL_ADC_AWD_CHANNEL_14_REG_INJ
  4142. * @arg @ref LL_ADC_AWD_CHANNEL_15_REG (0)
  4143. * @arg @ref LL_ADC_AWD_CHANNEL_15_INJ (0)
  4144. * @arg @ref LL_ADC_AWD_CHANNEL_15_REG_INJ
  4145. * @arg @ref LL_ADC_AWD_CHANNEL_16_REG (0)
  4146. * @arg @ref LL_ADC_AWD_CHANNEL_16_INJ (0)
  4147. * @arg @ref LL_ADC_AWD_CHANNEL_16_REG_INJ
  4148. * @arg @ref LL_ADC_AWD_CHANNEL_17_REG (0)
  4149. * @arg @ref LL_ADC_AWD_CHANNEL_17_INJ (0)
  4150. * @arg @ref LL_ADC_AWD_CHANNEL_17_REG_INJ
  4151. * @arg @ref LL_ADC_AWD_CHANNEL_18_REG (0)
  4152. * @arg @ref LL_ADC_AWD_CHANNEL_18_INJ (0)
  4153. * @arg @ref LL_ADC_AWD_CHANNEL_18_REG_INJ
  4154. *
  4155. * (0) On STM32WB, parameter available only on analog watchdog number: AWD1.
  4156. */
  4157. __STATIC_INLINE uint32_t LL_ADC_GetAnalogWDMonitChannels(ADC_TypeDef *ADCx, uint32_t AWDy)
  4158. {
  4159. register const __IO uint32_t *preg = __ADC_PTR_REG_OFFSET(ADCx->CFGR, ((AWDy & ADC_AWD_CRX_REGOFFSET_MASK) >> ADC_AWD_CRX_REGOFFSET_POS)
  4160. + ((AWDy & ADC_AWD_CR12_REGOFFSETGAP_MASK) * ADC_AWD_CR12_REGOFFSETGAP_VAL));
  4161. register uint32_t AnalogWDMonitChannels = (READ_BIT(*preg, AWDy) & AWDy & ADC_AWD_CR_ALL_CHANNEL_MASK);
  4162. /* If "AnalogWDMonitChannels" == 0, then the selected AWD is disabled */
  4163. /* (parameter value LL_ADC_AWD_DISABLE). */
  4164. /* Else, the selected AWD is enabled and is monitoring a group of channels */
  4165. /* or a single channel. */
  4166. if(AnalogWDMonitChannels != 0UL)
  4167. {
  4168. if(AWDy == LL_ADC_AWD1)
  4169. {
  4170. if((AnalogWDMonitChannels & ADC_CFGR_AWD1SGL) == 0UL)
  4171. {
  4172. /* AWD monitoring a group of channels */
  4173. AnalogWDMonitChannels = (( AnalogWDMonitChannels
  4174. | (ADC_AWD_CR23_CHANNEL_MASK)
  4175. )
  4176. & (~(ADC_CFGR_AWD1CH))
  4177. );
  4178. }
  4179. else
  4180. {
  4181. /* AWD monitoring a single channel */
  4182. AnalogWDMonitChannels = (AnalogWDMonitChannels
  4183. | (ADC_AWD2CR_AWD2CH_0 << (AnalogWDMonitChannels >> ADC_CFGR_AWD1CH_Pos))
  4184. );
  4185. }
  4186. }
  4187. else
  4188. {
  4189. if((AnalogWDMonitChannels & ADC_AWD_CR23_CHANNEL_MASK) == ADC_AWD_CR23_CHANNEL_MASK)
  4190. {
  4191. /* AWD monitoring a group of channels */
  4192. AnalogWDMonitChannels = ( ADC_AWD_CR23_CHANNEL_MASK
  4193. | ((ADC_CFGR_JAWD1EN | ADC_CFGR_AWD1EN))
  4194. );
  4195. }
  4196. else
  4197. {
  4198. /* AWD monitoring a single channel */
  4199. /* AWD monitoring a group of channels */
  4200. AnalogWDMonitChannels = ( AnalogWDMonitChannels
  4201. | (ADC_CFGR_JAWD1EN | ADC_CFGR_AWD1EN | ADC_CFGR_AWD1SGL)
  4202. | (__LL_ADC_CHANNEL_TO_DECIMAL_NB(AnalogWDMonitChannels) << ADC_CFGR_AWD1CH_Pos)
  4203. );
  4204. }
  4205. }
  4206. }
  4207. return AnalogWDMonitChannels;
  4208. }
  4209. /**
  4210. * @brief Set ADC analog watchdog thresholds value of both thresholds
  4211. * high and low.
  4212. * @note If value of only one threshold high or low must be set,
  4213. * use function @ref LL_ADC_SetAnalogWDThresholds().
  4214. * @note In case of ADC resolution different of 12 bits,
  4215. * analog watchdog thresholds data require a specific shift.
  4216. * Use helper macro @ref __LL_ADC_ANALOGWD_SET_THRESHOLD_RESOLUTION().
  4217. * @note On this STM32 serie, there are 2 kinds of analog watchdog
  4218. * instance:
  4219. * - AWD standard (instance AWD1):
  4220. * - channels monitored: can monitor 1 channel or all channels.
  4221. * - groups monitored: ADC groups regular and-or injected.
  4222. * - resolution: resolution is not limited (corresponds to
  4223. * ADC resolution configured).
  4224. * - AWD flexible (instances AWD2, AWD3):
  4225. * - channels monitored: flexible on channels monitored, selection is
  4226. * channel wise, from from 1 to all channels.
  4227. * Specificity of this analog watchdog: Multiple channels can
  4228. * be selected. For example:
  4229. * (LL_ADC_AWD_CHANNEL4_REG_INJ | LL_ADC_AWD_CHANNEL5_REG_INJ | ...)
  4230. * - groups monitored: not selection possible (monitoring on both
  4231. * groups regular and injected).
  4232. * Channels selected are monitored on groups regular and injected:
  4233. * LL_ADC_AWD_CHANNELxx_REG_INJ (do not use parameters
  4234. * LL_ADC_AWD_CHANNELxx_REG and LL_ADC_AWD_CHANNELxx_INJ)
  4235. * - resolution: resolution is limited to 8 bits: if ADC resolution is
  4236. * 12 bits the 4 LSB are ignored, if ADC resolution is 10 bits
  4237. * the 2 LSB are ignored.
  4238. * @note If ADC oversampling is enabled, ADC analog watchdog thresholds are
  4239. * impacted: the comparison of analog watchdog thresholds is done on
  4240. * oversampling final computation (after ratio and shift application):
  4241. * ADC data register bitfield [15:4] (12 most significant bits).
  4242. * @note On this STM32 serie, setting of this feature is conditioned to
  4243. * ADC state:
  4244. * ADC must be disabled or enabled without conversion on going
  4245. * on either groups regular or injected.
  4246. * @rmtoll TR1 HT1 LL_ADC_ConfigAnalogWDThresholds\n
  4247. * TR2 HT2 LL_ADC_ConfigAnalogWDThresholds\n
  4248. * TR3 HT3 LL_ADC_ConfigAnalogWDThresholds\n
  4249. * TR1 LT1 LL_ADC_ConfigAnalogWDThresholds\n
  4250. * TR2 LT2 LL_ADC_ConfigAnalogWDThresholds\n
  4251. * TR3 LT3 LL_ADC_ConfigAnalogWDThresholds
  4252. * @param ADCx ADC instance
  4253. * @param AWDy This parameter can be one of the following values:
  4254. * @arg @ref LL_ADC_AWD1
  4255. * @arg @ref LL_ADC_AWD2
  4256. * @arg @ref LL_ADC_AWD3
  4257. * @param AWDThresholdHighValue Value between Min_Data=0x000 and Max_Data=0xFFF
  4258. * @param AWDThresholdLowValue Value between Min_Data=0x000 and Max_Data=0xFFF
  4259. * @retval None
  4260. */
  4261. __STATIC_INLINE void LL_ADC_ConfigAnalogWDThresholds(ADC_TypeDef *ADCx, uint32_t AWDy, uint32_t AWDThresholdHighValue, uint32_t AWDThresholdLowValue)
  4262. {
  4263. /* Set bits with content of parameter "AWDThresholdxxxValue" with bits */
  4264. /* position in register and register position depending on parameter */
  4265. /* "AWDy". */
  4266. /* Parameters "AWDy" and "AWDThresholdxxxValue" are used with masks because */
  4267. /* containing other bits reserved for other purpose. */
  4268. register __IO uint32_t *preg = __ADC_PTR_REG_OFFSET(ADCx->TR1, ((AWDy & ADC_AWD_TRX_REGOFFSET_MASK) >> ADC_AWD_TRX_REGOFFSET_POS));
  4269. MODIFY_REG(*preg,
  4270. ADC_TR1_HT1 | ADC_TR1_LT1,
  4271. (AWDThresholdHighValue << ADC_TR1_HT1_BITOFFSET_POS) | AWDThresholdLowValue);
  4272. }
  4273. /**
  4274. * @brief Set ADC analog watchdog threshold value of threshold
  4275. * high or low.
  4276. * @note If values of both thresholds high or low must be set,
  4277. * use function @ref LL_ADC_ConfigAnalogWDThresholds().
  4278. * @note In case of ADC resolution different of 12 bits,
  4279. * analog watchdog thresholds data require a specific shift.
  4280. * Use helper macro @ref __LL_ADC_ANALOGWD_SET_THRESHOLD_RESOLUTION().
  4281. * @note On this STM32 serie, there are 2 kinds of analog watchdog
  4282. * instance:
  4283. * - AWD standard (instance AWD1):
  4284. * - channels monitored: can monitor 1 channel or all channels.
  4285. * - groups monitored: ADC groups regular and-or injected.
  4286. * - resolution: resolution is not limited (corresponds to
  4287. * ADC resolution configured).
  4288. * - AWD flexible (instances AWD2, AWD3):
  4289. * - channels monitored: flexible on channels monitored, selection is
  4290. * channel wise, from from 1 to all channels.
  4291. * Specificity of this analog watchdog: Multiple channels can
  4292. * be selected. For example:
  4293. * (LL_ADC_AWD_CHANNEL4_REG_INJ | LL_ADC_AWD_CHANNEL5_REG_INJ | ...)
  4294. * - groups monitored: not selection possible (monitoring on both
  4295. * groups regular and injected).
  4296. * Channels selected are monitored on groups regular and injected:
  4297. * LL_ADC_AWD_CHANNELxx_REG_INJ (do not use parameters
  4298. * LL_ADC_AWD_CHANNELxx_REG and LL_ADC_AWD_CHANNELxx_INJ)
  4299. * - resolution: resolution is limited to 8 bits: if ADC resolution is
  4300. * 12 bits the 4 LSB are ignored, if ADC resolution is 10 bits
  4301. * the 2 LSB are ignored.
  4302. * @note If ADC oversampling is enabled, ADC analog watchdog thresholds are
  4303. * impacted: the comparison of analog watchdog thresholds is done on
  4304. * oversampling final computation (after ratio and shift application):
  4305. * ADC data register bitfield [15:4] (12 most significant bits).
  4306. * @note On this STM32 serie, setting of this feature is conditioned to
  4307. * ADC state:
  4308. * ADC must be disabled or enabled without conversion on going
  4309. * on either ADC groups regular or injected.
  4310. * @rmtoll TR1 HT1 LL_ADC_SetAnalogWDThresholds\n
  4311. * TR2 HT2 LL_ADC_SetAnalogWDThresholds\n
  4312. * TR3 HT3 LL_ADC_SetAnalogWDThresholds\n
  4313. * TR1 LT1 LL_ADC_SetAnalogWDThresholds\n
  4314. * TR2 LT2 LL_ADC_SetAnalogWDThresholds\n
  4315. * TR3 LT3 LL_ADC_SetAnalogWDThresholds
  4316. * @param ADCx ADC instance
  4317. * @param AWDy This parameter can be one of the following values:
  4318. * @arg @ref LL_ADC_AWD1
  4319. * @arg @ref LL_ADC_AWD2
  4320. * @arg @ref LL_ADC_AWD3
  4321. * @param AWDThresholdsHighLow This parameter can be one of the following values:
  4322. * @arg @ref LL_ADC_AWD_THRESHOLD_HIGH
  4323. * @arg @ref LL_ADC_AWD_THRESHOLD_LOW
  4324. * @param AWDThresholdValue Value between Min_Data=0x000 and Max_Data=0xFFF
  4325. * @retval None
  4326. */
  4327. __STATIC_INLINE void LL_ADC_SetAnalogWDThresholds(ADC_TypeDef *ADCx, uint32_t AWDy, uint32_t AWDThresholdsHighLow, uint32_t AWDThresholdValue)
  4328. {
  4329. /* Set bits with content of parameter "AWDThresholdValue" with bits */
  4330. /* position in register and register position depending on parameters */
  4331. /* "AWDThresholdsHighLow" and "AWDy". */
  4332. /* Parameters "AWDy" and "AWDThresholdValue" are used with masks because */
  4333. /* containing other bits reserved for other purpose. */
  4334. register __IO uint32_t *preg = __ADC_PTR_REG_OFFSET(ADCx->TR1, ((AWDy & ADC_AWD_TRX_REGOFFSET_MASK) >> ADC_AWD_TRX_REGOFFSET_POS));
  4335. MODIFY_REG(*preg,
  4336. AWDThresholdsHighLow,
  4337. AWDThresholdValue << ((AWDThresholdsHighLow & ADC_AWD_TRX_BIT_HIGH_MASK) >> ADC_AWD_TRX_BIT_HIGH_SHIFT4));
  4338. }
  4339. /**
  4340. * @brief Get ADC analog watchdog threshold value of threshold high,
  4341. * threshold low or raw data with ADC thresholds high and low
  4342. * concatenated.
  4343. * @note If raw data with ADC thresholds high and low is retrieved,
  4344. * the data of each threshold high or low can be isolated
  4345. * using helper macro:
  4346. * @ref __LL_ADC_ANALOGWD_THRESHOLDS_HIGH_LOW().
  4347. * @note In case of ADC resolution different of 12 bits,
  4348. * analog watchdog thresholds data require a specific shift.
  4349. * Use helper macro @ref __LL_ADC_ANALOGWD_GET_THRESHOLD_RESOLUTION().
  4350. * @rmtoll TR1 HT1 LL_ADC_GetAnalogWDThresholds\n
  4351. * TR2 HT2 LL_ADC_GetAnalogWDThresholds\n
  4352. * TR3 HT3 LL_ADC_GetAnalogWDThresholds\n
  4353. * TR1 LT1 LL_ADC_GetAnalogWDThresholds\n
  4354. * TR2 LT2 LL_ADC_GetAnalogWDThresholds\n
  4355. * TR3 LT3 LL_ADC_GetAnalogWDThresholds
  4356. * @param ADCx ADC instance
  4357. * @param AWDy This parameter can be one of the following values:
  4358. * @arg @ref LL_ADC_AWD1
  4359. * @arg @ref LL_ADC_AWD2
  4360. * @arg @ref LL_ADC_AWD3
  4361. * @param AWDThresholdsHighLow This parameter can be one of the following values:
  4362. * @arg @ref LL_ADC_AWD_THRESHOLD_HIGH
  4363. * @arg @ref LL_ADC_AWD_THRESHOLD_LOW
  4364. * @arg @ref LL_ADC_AWD_THRESHOLDS_HIGH_LOW
  4365. * @retval Value between Min_Data=0x000 and Max_Data=0xFFF
  4366. */
  4367. __STATIC_INLINE uint32_t LL_ADC_GetAnalogWDThresholds(ADC_TypeDef *ADCx, uint32_t AWDy, uint32_t AWDThresholdsHighLow)
  4368. {
  4369. register const __IO uint32_t *preg = __ADC_PTR_REG_OFFSET(ADCx->TR1, ((AWDy & ADC_AWD_TRX_REGOFFSET_MASK) >> ADC_AWD_TRX_REGOFFSET_POS));
  4370. return (uint32_t)(READ_BIT(*preg,
  4371. (AWDThresholdsHighLow | ADC_TR1_LT1))
  4372. >> (((AWDThresholdsHighLow & ADC_AWD_TRX_BIT_HIGH_MASK) >> ADC_AWD_TRX_BIT_HIGH_SHIFT4) & ~(AWDThresholdsHighLow & ADC_TR1_LT1))
  4373. );
  4374. }
  4375. /**
  4376. * @}
  4377. */
  4378. /** @defgroup ADC_LL_EF_Configuration_ADC_oversampling Configuration of ADC transversal scope: oversampling
  4379. * @{
  4380. */
  4381. /**
  4382. * @brief Set ADC oversampling scope: ADC groups regular and-or injected
  4383. * (availability of ADC group injected depends on STM32 families).
  4384. * @note If both groups regular and injected are selected,
  4385. * specify behavior of ADC group injected interrupting
  4386. * group regular: when ADC group injected is triggered,
  4387. * the oversampling on ADC group regular is either
  4388. * temporary stopped and continued, or resumed from start
  4389. * (oversampler buffer reset).
  4390. * @note On this STM32 serie, setting of this feature is conditioned to
  4391. * ADC state:
  4392. * ADC must be disabled or enabled without conversion on going
  4393. * on either groups regular or injected.
  4394. * @rmtoll CFGR2 ROVSE LL_ADC_SetOverSamplingScope\n
  4395. * CFGR2 JOVSE LL_ADC_SetOverSamplingScope\n
  4396. * CFGR2 ROVSM LL_ADC_SetOverSamplingScope
  4397. * @param ADCx ADC instance
  4398. * @param OvsScope This parameter can be one of the following values:
  4399. * @arg @ref LL_ADC_OVS_DISABLE
  4400. * @arg @ref LL_ADC_OVS_GRP_REGULAR_CONTINUED
  4401. * @arg @ref LL_ADC_OVS_GRP_REGULAR_RESUMED
  4402. * @arg @ref LL_ADC_OVS_GRP_INJECTED
  4403. * @arg @ref LL_ADC_OVS_GRP_INJ_REG_RESUMED
  4404. * @retval None
  4405. */
  4406. __STATIC_INLINE void LL_ADC_SetOverSamplingScope(ADC_TypeDef *ADCx, uint32_t OvsScope)
  4407. {
  4408. MODIFY_REG(ADCx->CFGR2, ADC_CFGR2_ROVSE | ADC_CFGR2_JOVSE | ADC_CFGR2_ROVSM, OvsScope);
  4409. }
  4410. /**
  4411. * @brief Get ADC oversampling scope: ADC groups regular and-or injected
  4412. * (availability of ADC group injected depends on STM32 families).
  4413. * @note If both groups regular and injected are selected,
  4414. * specify behavior of ADC group injected interrupting
  4415. * group regular: when ADC group injected is triggered,
  4416. * the oversampling on ADC group regular is either
  4417. * temporary stopped and continued, or resumed from start
  4418. * (oversampler buffer reset).
  4419. * @rmtoll CFGR2 ROVSE LL_ADC_GetOverSamplingScope\n
  4420. * CFGR2 JOVSE LL_ADC_GetOverSamplingScope\n
  4421. * CFGR2 ROVSM LL_ADC_GetOverSamplingScope
  4422. * @param ADCx ADC instance
  4423. * @retval Returned value can be one of the following values:
  4424. * @arg @ref LL_ADC_OVS_DISABLE
  4425. * @arg @ref LL_ADC_OVS_GRP_REGULAR_CONTINUED
  4426. * @arg @ref LL_ADC_OVS_GRP_REGULAR_RESUMED
  4427. * @arg @ref LL_ADC_OVS_GRP_INJECTED
  4428. * @arg @ref LL_ADC_OVS_GRP_INJ_REG_RESUMED
  4429. */
  4430. __STATIC_INLINE uint32_t LL_ADC_GetOverSamplingScope(ADC_TypeDef *ADCx)
  4431. {
  4432. return (uint32_t)(READ_BIT(ADCx->CFGR2, ADC_CFGR2_ROVSE | ADC_CFGR2_JOVSE | ADC_CFGR2_ROVSM));
  4433. }
  4434. /**
  4435. * @brief Set ADC oversampling discontinuous mode (triggered mode)
  4436. * on the selected ADC group.
  4437. * @note Number of oversampled conversions are done either in:
  4438. * - continuous mode (all conversions of oversampling ratio
  4439. * are done from 1 trigger)
  4440. * - discontinuous mode (each conversion of oversampling ratio
  4441. * needs a trigger)
  4442. * @note On this STM32 serie, setting of this feature is conditioned to
  4443. * ADC state:
  4444. * ADC must be disabled or enabled without conversion on going
  4445. * on group regular.
  4446. * @note On this STM32 serie, oversampling discontinuous mode
  4447. * (triggered mode) can be used only when oversampling is
  4448. * set on group regular only and in resumed mode.
  4449. * @rmtoll CFGR2 TROVS LL_ADC_SetOverSamplingDiscont
  4450. * @param ADCx ADC instance
  4451. * @param OverSamplingDiscont This parameter can be one of the following values:
  4452. * @arg @ref LL_ADC_OVS_REG_CONT
  4453. * @arg @ref LL_ADC_OVS_REG_DISCONT
  4454. * @retval None
  4455. */
  4456. __STATIC_INLINE void LL_ADC_SetOverSamplingDiscont(ADC_TypeDef *ADCx, uint32_t OverSamplingDiscont)
  4457. {
  4458. MODIFY_REG(ADCx->CFGR2, ADC_CFGR2_TROVS, OverSamplingDiscont);
  4459. }
  4460. /**
  4461. * @brief Get ADC oversampling discontinuous mode (triggered mode)
  4462. * on the selected ADC group.
  4463. * @note Number of oversampled conversions are done either in:
  4464. * - continuous mode (all conversions of oversampling ratio
  4465. * are done from 1 trigger)
  4466. * - discontinuous mode (each conversion of oversampling ratio
  4467. * needs a trigger)
  4468. * @rmtoll CFGR2 TROVS LL_ADC_GetOverSamplingDiscont
  4469. * @param ADCx ADC instance
  4470. * @retval Returned value can be one of the following values:
  4471. * @arg @ref LL_ADC_OVS_REG_CONT
  4472. * @arg @ref LL_ADC_OVS_REG_DISCONT
  4473. */
  4474. __STATIC_INLINE uint32_t LL_ADC_GetOverSamplingDiscont(ADC_TypeDef *ADCx)
  4475. {
  4476. return (uint32_t)(READ_BIT(ADCx->CFGR2, ADC_CFGR2_TROVS));
  4477. }
  4478. /**
  4479. * @brief Set ADC oversampling
  4480. * (impacting both ADC groups regular and injected)
  4481. * @note This function set the 2 items of oversampling configuration:
  4482. * - ratio
  4483. * - shift
  4484. * @note On this STM32 serie, setting of this feature is conditioned to
  4485. * ADC state:
  4486. * ADC must be disabled or enabled without conversion on going
  4487. * on either groups regular or injected.
  4488. * @rmtoll CFGR2 OVSS LL_ADC_ConfigOverSamplingRatioShift\n
  4489. * CFGR2 OVSR LL_ADC_ConfigOverSamplingRatioShift
  4490. * @param ADCx ADC instance
  4491. * @param Ratio This parameter can be one of the following values:
  4492. * @arg @ref LL_ADC_OVS_RATIO_2
  4493. * @arg @ref LL_ADC_OVS_RATIO_4
  4494. * @arg @ref LL_ADC_OVS_RATIO_8
  4495. * @arg @ref LL_ADC_OVS_RATIO_16
  4496. * @arg @ref LL_ADC_OVS_RATIO_32
  4497. * @arg @ref LL_ADC_OVS_RATIO_64
  4498. * @arg @ref LL_ADC_OVS_RATIO_128
  4499. * @arg @ref LL_ADC_OVS_RATIO_256
  4500. * @param Shift This parameter can be one of the following values:
  4501. * @arg @ref LL_ADC_OVS_SHIFT_NONE
  4502. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_1
  4503. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_2
  4504. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_3
  4505. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_4
  4506. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_5
  4507. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_6
  4508. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_7
  4509. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_8
  4510. * @retval None
  4511. */
  4512. __STATIC_INLINE void LL_ADC_ConfigOverSamplingRatioShift(ADC_TypeDef *ADCx, uint32_t Ratio, uint32_t Shift)
  4513. {
  4514. MODIFY_REG(ADCx->CFGR2, (ADC_CFGR2_OVSS | ADC_CFGR2_OVSR), (Shift | Ratio));
  4515. }
  4516. /**
  4517. * @brief Get ADC oversampling ratio
  4518. * (impacting both ADC groups regular and injected)
  4519. * @rmtoll CFGR2 OVSR LL_ADC_GetOverSamplingRatio
  4520. * @param ADCx ADC instance
  4521. * @retval Ratio This parameter can be one of the following values:
  4522. * @arg @ref LL_ADC_OVS_RATIO_2
  4523. * @arg @ref LL_ADC_OVS_RATIO_4
  4524. * @arg @ref LL_ADC_OVS_RATIO_8
  4525. * @arg @ref LL_ADC_OVS_RATIO_16
  4526. * @arg @ref LL_ADC_OVS_RATIO_32
  4527. * @arg @ref LL_ADC_OVS_RATIO_64
  4528. * @arg @ref LL_ADC_OVS_RATIO_128
  4529. * @arg @ref LL_ADC_OVS_RATIO_256
  4530. */
  4531. __STATIC_INLINE uint32_t LL_ADC_GetOverSamplingRatio(ADC_TypeDef *ADCx)
  4532. {
  4533. return (uint32_t)(READ_BIT(ADCx->CFGR2, ADC_CFGR2_OVSR));
  4534. }
  4535. /**
  4536. * @brief Get ADC oversampling shift
  4537. * (impacting both ADC groups regular and injected)
  4538. * @rmtoll CFGR2 OVSS LL_ADC_GetOverSamplingShift
  4539. * @param ADCx ADC instance
  4540. * @retval Shift This parameter can be one of the following values:
  4541. * @arg @ref LL_ADC_OVS_SHIFT_NONE
  4542. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_1
  4543. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_2
  4544. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_3
  4545. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_4
  4546. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_5
  4547. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_6
  4548. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_7
  4549. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_8
  4550. */
  4551. __STATIC_INLINE uint32_t LL_ADC_GetOverSamplingShift(ADC_TypeDef *ADCx)
  4552. {
  4553. return (uint32_t)(READ_BIT(ADCx->CFGR2, ADC_CFGR2_OVSS));
  4554. }
  4555. /**
  4556. * @}
  4557. */
  4558. /** @defgroup ADC_LL_EF_Operation_ADC_Instance Operation on ADC hierarchical scope: ADC instance
  4559. * @{
  4560. */
  4561. /**
  4562. * @brief Put ADC instance in deep power down state.
  4563. * @note In case of ADC calibration necessary: When ADC is in deep-power-down
  4564. * state, the internal analog calibration is lost. After exiting from
  4565. * deep power down, calibration must be relaunched or calibration factor
  4566. * (preliminarily saved) must be set back into calibration register.
  4567. * @note On this STM32 serie, setting of this feature is conditioned to
  4568. * ADC state:
  4569. * ADC must be ADC disabled.
  4570. * @rmtoll CR DEEPPWD LL_ADC_EnableDeepPowerDown
  4571. * @param ADCx ADC instance
  4572. * @retval None
  4573. */
  4574. __STATIC_INLINE void LL_ADC_EnableDeepPowerDown(ADC_TypeDef *ADCx)
  4575. {
  4576. /* Note: Write register with some additional bits forced to state reset */
  4577. /* instead of modifying only the selected bit for this function, */
  4578. /* to not interfere with bits with HW property "rs". */
  4579. MODIFY_REG(ADCx->CR,
  4580. ADC_CR_BITS_PROPERTY_RS,
  4581. ADC_CR_DEEPPWD);
  4582. }
  4583. /**
  4584. * @brief Disable ADC deep power down mode.
  4585. * @note In case of ADC calibration necessary: When ADC is in deep-power-down
  4586. * state, the internal analog calibration is lost. After exiting from
  4587. * deep power down, calibration must be relaunched or calibration factor
  4588. * (preliminarily saved) must be set back into calibration register.
  4589. * @note On this STM32 serie, setting of this feature is conditioned to
  4590. * ADC state:
  4591. * ADC must be ADC disabled.
  4592. * @rmtoll CR DEEPPWD LL_ADC_DisableDeepPowerDown
  4593. * @param ADCx ADC instance
  4594. * @retval None
  4595. */
  4596. __STATIC_INLINE void LL_ADC_DisableDeepPowerDown(ADC_TypeDef *ADCx)
  4597. {
  4598. /* Note: Write register with some additional bits forced to state reset */
  4599. /* instead of modifying only the selected bit for this function, */
  4600. /* to not interfere with bits with HW property "rs". */
  4601. CLEAR_BIT(ADCx->CR, (ADC_CR_DEEPPWD | ADC_CR_BITS_PROPERTY_RS));
  4602. }
  4603. /**
  4604. * @brief Get the selected ADC instance deep power down state.
  4605. * @rmtoll CR DEEPPWD LL_ADC_IsDeepPowerDownEnabled
  4606. * @param ADCx ADC instance
  4607. * @retval 0: deep power down is disabled, 1: deep power down is enabled.
  4608. */
  4609. __STATIC_INLINE uint32_t LL_ADC_IsDeepPowerDownEnabled(ADC_TypeDef *ADCx)
  4610. {
  4611. return ((READ_BIT(ADCx->CR, ADC_CR_DEEPPWD) == (ADC_CR_DEEPPWD)) ? 1UL : 0UL);
  4612. }
  4613. /**
  4614. * @brief Enable ADC instance internal voltage regulator.
  4615. * @note On this STM32 serie, after ADC internal voltage regulator enable,
  4616. * a delay for ADC internal voltage regulator stabilization
  4617. * is required before performing a ADC calibration or ADC enable.
  4618. * Refer to device datasheet, parameter tADCVREG_STUP.
  4619. * Refer to literal @ref LL_ADC_DELAY_INTERNAL_REGUL_STAB_US.
  4620. * @note On this STM32 serie, setting of this feature is conditioned to
  4621. * ADC state:
  4622. * ADC must be ADC disabled.
  4623. * @rmtoll CR ADVREGEN LL_ADC_EnableInternalRegulator
  4624. * @param ADCx ADC instance
  4625. * @retval None
  4626. */
  4627. __STATIC_INLINE void LL_ADC_EnableInternalRegulator(ADC_TypeDef *ADCx)
  4628. {
  4629. /* Note: Write register with some additional bits forced to state reset */
  4630. /* instead of modifying only the selected bit for this function, */
  4631. /* to not interfere with bits with HW property "rs". */
  4632. MODIFY_REG(ADCx->CR,
  4633. ADC_CR_BITS_PROPERTY_RS,
  4634. ADC_CR_ADVREGEN);
  4635. }
  4636. /**
  4637. * @brief Disable ADC internal voltage regulator.
  4638. * @note On this STM32 serie, setting of this feature is conditioned to
  4639. * ADC state:
  4640. * ADC must be ADC disabled.
  4641. * @rmtoll CR ADVREGEN LL_ADC_DisableInternalRegulator
  4642. * @param ADCx ADC instance
  4643. * @retval None
  4644. */
  4645. __STATIC_INLINE void LL_ADC_DisableInternalRegulator(ADC_TypeDef *ADCx)
  4646. {
  4647. CLEAR_BIT(ADCx->CR, (ADC_CR_ADVREGEN | ADC_CR_BITS_PROPERTY_RS));
  4648. }
  4649. /**
  4650. * @brief Get the selected ADC instance internal voltage regulator state.
  4651. * @rmtoll CR ADVREGEN LL_ADC_IsInternalRegulatorEnabled
  4652. * @param ADCx ADC instance
  4653. * @retval 0: internal regulator is disabled, 1: internal regulator is enabled.
  4654. */
  4655. __STATIC_INLINE uint32_t LL_ADC_IsInternalRegulatorEnabled(ADC_TypeDef *ADCx)
  4656. {
  4657. return ((READ_BIT(ADCx->CR, ADC_CR_ADVREGEN) == (ADC_CR_ADVREGEN)) ? 1UL : 0UL);
  4658. }
  4659. /**
  4660. * @brief Enable the selected ADC instance.
  4661. * @note On this STM32 serie, after ADC enable, a delay for
  4662. * ADC internal analog stabilization is required before performing a
  4663. * ADC conversion start.
  4664. * Refer to device datasheet, parameter tSTAB.
  4665. * @note On this STM32 serie, flag LL_ADC_FLAG_ADRDY is raised when the ADC
  4666. * is enabled and when conversion clock is active.
  4667. * (not only core clock: this ADC has a dual clock domain)
  4668. * @note On this STM32 serie, setting of this feature is conditioned to
  4669. * ADC state:
  4670. * ADC must be ADC disabled and ADC internal voltage regulator enabled.
  4671. * @rmtoll CR ADEN LL_ADC_Enable
  4672. * @param ADCx ADC instance
  4673. * @retval None
  4674. */
  4675. __STATIC_INLINE void LL_ADC_Enable(ADC_TypeDef *ADCx)
  4676. {
  4677. /* Note: Write register with some additional bits forced to state reset */
  4678. /* instead of modifying only the selected bit for this function, */
  4679. /* to not interfere with bits with HW property "rs". */
  4680. MODIFY_REG(ADCx->CR,
  4681. ADC_CR_BITS_PROPERTY_RS,
  4682. ADC_CR_ADEN);
  4683. }
  4684. /**
  4685. * @brief Disable the selected ADC instance.
  4686. * @note On this STM32 serie, setting of this feature is conditioned to
  4687. * ADC state:
  4688. * ADC must be not disabled. Must be enabled without conversion on going
  4689. * on either groups regular or injected.
  4690. * @rmtoll CR ADDIS LL_ADC_Disable
  4691. * @param ADCx ADC instance
  4692. * @retval None
  4693. */
  4694. __STATIC_INLINE void LL_ADC_Disable(ADC_TypeDef *ADCx)
  4695. {
  4696. /* Note: Write register with some additional bits forced to state reset */
  4697. /* instead of modifying only the selected bit for this function, */
  4698. /* to not interfere with bits with HW property "rs". */
  4699. MODIFY_REG(ADCx->CR,
  4700. ADC_CR_BITS_PROPERTY_RS,
  4701. ADC_CR_ADDIS);
  4702. }
  4703. /**
  4704. * @brief Get the selected ADC instance enable state.
  4705. * @note On this STM32 serie, flag LL_ADC_FLAG_ADRDY is raised when the ADC
  4706. * is enabled and when conversion clock is active.
  4707. * (not only core clock: this ADC has a dual clock domain)
  4708. * @rmtoll CR ADEN LL_ADC_IsEnabled
  4709. * @param ADCx ADC instance
  4710. * @retval 0: ADC is disabled, 1: ADC is enabled.
  4711. */
  4712. __STATIC_INLINE uint32_t LL_ADC_IsEnabled(ADC_TypeDef *ADCx)
  4713. {
  4714. return ((READ_BIT(ADCx->CR, ADC_CR_ADEN) == (ADC_CR_ADEN)) ? 1UL : 0UL);
  4715. }
  4716. /**
  4717. * @brief Get the selected ADC instance disable state.
  4718. * @rmtoll CR ADDIS LL_ADC_IsDisableOngoing
  4719. * @param ADCx ADC instance
  4720. * @retval 0: no ADC disable command on going.
  4721. */
  4722. __STATIC_INLINE uint32_t LL_ADC_IsDisableOngoing(ADC_TypeDef *ADCx)
  4723. {
  4724. return ((READ_BIT(ADCx->CR, ADC_CR_ADDIS) == (ADC_CR_ADDIS)) ? 1UL : 0UL);
  4725. }
  4726. /**
  4727. * @brief Start ADC calibration in the mode single-ended
  4728. * or differential (for devices with differential mode available).
  4729. * @note On this STM32 serie, a minimum number of ADC clock cycles
  4730. * are required between ADC end of calibration and ADC enable.
  4731. * Refer to literal @ref LL_ADC_DELAY_CALIB_ENABLE_ADC_CYCLES.
  4732. * @note For devices with differential mode available:
  4733. * Calibration of offset is specific to each of
  4734. * single-ended and differential modes
  4735. * (calibration run must be performed for each of these
  4736. * differential modes, if used afterwards and if the application
  4737. * requires their calibration).
  4738. * @note On this STM32 serie, setting of this feature is conditioned to
  4739. * ADC state:
  4740. * ADC must be ADC disabled.
  4741. * @rmtoll CR ADCAL LL_ADC_StartCalibration\n
  4742. * CR ADCALDIF LL_ADC_StartCalibration
  4743. * @param ADCx ADC instance
  4744. * @param SingleDiff This parameter can be one of the following values:
  4745. * @arg @ref LL_ADC_SINGLE_ENDED
  4746. * @arg @ref LL_ADC_DIFFERENTIAL_ENDED
  4747. * @retval None
  4748. */
  4749. __STATIC_INLINE void LL_ADC_StartCalibration(ADC_TypeDef *ADCx, uint32_t SingleDiff)
  4750. {
  4751. /* Note: Write register with some additional bits forced to state reset */
  4752. /* instead of modifying only the selected bit for this function, */
  4753. /* to not interfere with bits with HW property "rs". */
  4754. MODIFY_REG(ADCx->CR,
  4755. ADC_CR_ADCALDIF | ADC_CR_BITS_PROPERTY_RS,
  4756. ADC_CR_ADCAL | (SingleDiff & ADC_SINGLEDIFF_CALIB_START_MASK));
  4757. }
  4758. /**
  4759. * @brief Get ADC calibration state.
  4760. * @rmtoll CR ADCAL LL_ADC_IsCalibrationOnGoing
  4761. * @param ADCx ADC instance
  4762. * @retval 0: calibration complete, 1: calibration in progress.
  4763. */
  4764. __STATIC_INLINE uint32_t LL_ADC_IsCalibrationOnGoing(ADC_TypeDef *ADCx)
  4765. {
  4766. return ((READ_BIT(ADCx->CR, ADC_CR_ADCAL) == (ADC_CR_ADCAL)) ? 1UL : 0UL);
  4767. }
  4768. /**
  4769. * @}
  4770. */
  4771. /** @defgroup ADC_LL_EF_Operation_ADC_Group_Regular Operation on ADC hierarchical scope: group regular
  4772. * @{
  4773. */
  4774. /**
  4775. * @brief Start ADC group regular conversion.
  4776. * @note On this STM32 serie, this function is relevant for both
  4777. * internal trigger (SW start) and external trigger:
  4778. * - If ADC trigger has been set to software start, ADC conversion
  4779. * starts immediately.
  4780. * - If ADC trigger has been set to external trigger, ADC conversion
  4781. * will start at next trigger event (on the selected trigger edge)
  4782. * following the ADC start conversion command.
  4783. * @note On this STM32 serie, setting of this feature is conditioned to
  4784. * ADC state:
  4785. * ADC must be enabled without conversion on going on group regular,
  4786. * without conversion stop command on going on group regular,
  4787. * without ADC disable command on going.
  4788. * @rmtoll CR ADSTART LL_ADC_REG_StartConversion
  4789. * @param ADCx ADC instance
  4790. * @retval None
  4791. */
  4792. __STATIC_INLINE void LL_ADC_REG_StartConversion(ADC_TypeDef *ADCx)
  4793. {
  4794. /* Note: Write register with some additional bits forced to state reset */
  4795. /* instead of modifying only the selected bit for this function, */
  4796. /* to not interfere with bits with HW property "rs". */
  4797. MODIFY_REG(ADCx->CR,
  4798. ADC_CR_BITS_PROPERTY_RS,
  4799. ADC_CR_ADSTART);
  4800. }
  4801. /**
  4802. * @brief Stop ADC group regular conversion.
  4803. * @note On this STM32 serie, setting of this feature is conditioned to
  4804. * ADC state:
  4805. * ADC must be enabled with conversion on going on group regular,
  4806. * without ADC disable command on going.
  4807. * @rmtoll CR ADSTP LL_ADC_REG_StopConversion
  4808. * @param ADCx ADC instance
  4809. * @retval None
  4810. */
  4811. __STATIC_INLINE void LL_ADC_REG_StopConversion(ADC_TypeDef *ADCx)
  4812. {
  4813. /* Note: Write register with some additional bits forced to state reset */
  4814. /* instead of modifying only the selected bit for this function, */
  4815. /* to not interfere with bits with HW property "rs". */
  4816. MODIFY_REG(ADCx->CR,
  4817. ADC_CR_BITS_PROPERTY_RS,
  4818. ADC_CR_ADSTP);
  4819. }
  4820. /**
  4821. * @brief Get ADC group regular conversion state.
  4822. * @rmtoll CR ADSTART LL_ADC_REG_IsConversionOngoing
  4823. * @param ADCx ADC instance
  4824. * @retval 0: no conversion is on going on ADC group regular.
  4825. */
  4826. __STATIC_INLINE uint32_t LL_ADC_REG_IsConversionOngoing(ADC_TypeDef *ADCx)
  4827. {
  4828. return ((READ_BIT(ADCx->CR, ADC_CR_ADSTART) == (ADC_CR_ADSTART)) ? 1UL : 0UL);
  4829. }
  4830. /**
  4831. * @brief Get ADC group regular command of conversion stop state
  4832. * @rmtoll CR ADSTP LL_ADC_REG_IsStopConversionOngoing
  4833. * @param ADCx ADC instance
  4834. * @retval 0: no command of conversion stop is on going on ADC group regular.
  4835. */
  4836. __STATIC_INLINE uint32_t LL_ADC_REG_IsStopConversionOngoing(ADC_TypeDef *ADCx)
  4837. {
  4838. return ((READ_BIT(ADCx->CR, ADC_CR_ADSTP) == (ADC_CR_ADSTP)) ? 1UL : 0UL);
  4839. }
  4840. /**
  4841. * @brief Get ADC group regular conversion data, range fit for
  4842. * all ADC configurations: all ADC resolutions and
  4843. * all oversampling increased data width (for devices
  4844. * with feature oversampling).
  4845. * @rmtoll DR RDATA LL_ADC_REG_ReadConversionData32
  4846. * @param ADCx ADC instance
  4847. * @retval Value between Min_Data=0x00000000 and Max_Data=0xFFFFFFFF
  4848. */
  4849. __STATIC_INLINE uint32_t LL_ADC_REG_ReadConversionData32(ADC_TypeDef *ADCx)
  4850. {
  4851. return (uint32_t)(READ_BIT(ADCx->DR, ADC_DR_RDATA));
  4852. }
  4853. /**
  4854. * @brief Get ADC group regular conversion data, range fit for
  4855. * ADC resolution 12 bits.
  4856. * @note For devices with feature oversampling: Oversampling
  4857. * can increase data width, function for extended range
  4858. * may be needed: @ref LL_ADC_REG_ReadConversionData32.
  4859. * @rmtoll DR RDATA LL_ADC_REG_ReadConversionData12
  4860. * @param ADCx ADC instance
  4861. * @retval Value between Min_Data=0x000 and Max_Data=0xFFF
  4862. */
  4863. __STATIC_INLINE uint16_t LL_ADC_REG_ReadConversionData12(ADC_TypeDef *ADCx)
  4864. {
  4865. return (uint16_t)(READ_BIT(ADCx->DR, ADC_DR_RDATA));
  4866. }
  4867. /**
  4868. * @brief Get ADC group regular conversion data, range fit for
  4869. * ADC resolution 10 bits.
  4870. * @note For devices with feature oversampling: Oversampling
  4871. * can increase data width, function for extended range
  4872. * may be needed: @ref LL_ADC_REG_ReadConversionData32.
  4873. * @rmtoll DR RDATA LL_ADC_REG_ReadConversionData10
  4874. * @param ADCx ADC instance
  4875. * @retval Value between Min_Data=0x000 and Max_Data=0x3FF
  4876. */
  4877. __STATIC_INLINE uint16_t LL_ADC_REG_ReadConversionData10(ADC_TypeDef *ADCx)
  4878. {
  4879. return (uint16_t)(READ_BIT(ADCx->DR, ADC_DR_RDATA));
  4880. }
  4881. /**
  4882. * @brief Get ADC group regular conversion data, range fit for
  4883. * ADC resolution 8 bits.
  4884. * @note For devices with feature oversampling: Oversampling
  4885. * can increase data width, function for extended range
  4886. * may be needed: @ref LL_ADC_REG_ReadConversionData32.
  4887. * @rmtoll DR RDATA LL_ADC_REG_ReadConversionData8
  4888. * @param ADCx ADC instance
  4889. * @retval Value between Min_Data=0x00 and Max_Data=0xFF
  4890. */
  4891. __STATIC_INLINE uint8_t LL_ADC_REG_ReadConversionData8(ADC_TypeDef *ADCx)
  4892. {
  4893. return (uint8_t)(READ_BIT(ADCx->DR, ADC_DR_RDATA));
  4894. }
  4895. /**
  4896. * @brief Get ADC group regular conversion data, range fit for
  4897. * ADC resolution 6 bits.
  4898. * @note For devices with feature oversampling: Oversampling
  4899. * can increase data width, function for extended range
  4900. * may be needed: @ref LL_ADC_REG_ReadConversionData32.
  4901. * @rmtoll DR RDATA LL_ADC_REG_ReadConversionData6
  4902. * @param ADCx ADC instance
  4903. * @retval Value between Min_Data=0x00 and Max_Data=0x3F
  4904. */
  4905. __STATIC_INLINE uint8_t LL_ADC_REG_ReadConversionData6(ADC_TypeDef *ADCx)
  4906. {
  4907. return (uint8_t)(READ_BIT(ADCx->DR, ADC_DR_RDATA));
  4908. }
  4909. /**
  4910. * @}
  4911. */
  4912. /** @defgroup ADC_LL_EF_Operation_ADC_Group_Injected Operation on ADC hierarchical scope: group injected
  4913. * @{
  4914. */
  4915. /**
  4916. * @brief Start ADC group injected conversion.
  4917. * @note On this STM32 serie, this function is relevant for both
  4918. * internal trigger (SW start) and external trigger:
  4919. * - If ADC trigger has been set to software start, ADC conversion
  4920. * starts immediately.
  4921. * - If ADC trigger has been set to external trigger, ADC conversion
  4922. * will start at next trigger event (on the selected trigger edge)
  4923. * following the ADC start conversion command.
  4924. * @note On this STM32 serie, setting of this feature is conditioned to
  4925. * ADC state:
  4926. * ADC must be enabled without conversion on going on group injected,
  4927. * without conversion stop command on going on group injected,
  4928. * without ADC disable command on going.
  4929. * @rmtoll CR JADSTART LL_ADC_INJ_StartConversion
  4930. * @param ADCx ADC instance
  4931. * @retval None
  4932. */
  4933. __STATIC_INLINE void LL_ADC_INJ_StartConversion(ADC_TypeDef *ADCx)
  4934. {
  4935. /* Note: Write register with some additional bits forced to state reset */
  4936. /* instead of modifying only the selected bit for this function, */
  4937. /* to not interfere with bits with HW property "rs". */
  4938. MODIFY_REG(ADCx->CR,
  4939. ADC_CR_BITS_PROPERTY_RS,
  4940. ADC_CR_JADSTART);
  4941. }
  4942. /**
  4943. * @brief Stop ADC group injected conversion.
  4944. * @note On this STM32 serie, setting of this feature is conditioned to
  4945. * ADC state:
  4946. * ADC must be enabled with conversion on going on group injected,
  4947. * without ADC disable command on going.
  4948. * @rmtoll CR JADSTP LL_ADC_INJ_StopConversion
  4949. * @param ADCx ADC instance
  4950. * @retval None
  4951. */
  4952. __STATIC_INLINE void LL_ADC_INJ_StopConversion(ADC_TypeDef *ADCx)
  4953. {
  4954. /* Note: Write register with some additional bits forced to state reset */
  4955. /* instead of modifying only the selected bit for this function, */
  4956. /* to not interfere with bits with HW property "rs". */
  4957. MODIFY_REG(ADCx->CR,
  4958. ADC_CR_BITS_PROPERTY_RS,
  4959. ADC_CR_JADSTP);
  4960. }
  4961. /**
  4962. * @brief Get ADC group injected conversion state.
  4963. * @rmtoll CR JADSTART LL_ADC_INJ_IsConversionOngoing
  4964. * @param ADCx ADC instance
  4965. * @retval 0: no conversion is on going on ADC group injected.
  4966. */
  4967. __STATIC_INLINE uint32_t LL_ADC_INJ_IsConversionOngoing(ADC_TypeDef *ADCx)
  4968. {
  4969. return ((READ_BIT(ADCx->CR, ADC_CR_JADSTART) == (ADC_CR_JADSTART)) ? 1UL : 0UL);
  4970. }
  4971. /**
  4972. * @brief Get ADC group injected command of conversion stop state
  4973. * @rmtoll CR JADSTP LL_ADC_INJ_IsStopConversionOngoing
  4974. * @param ADCx ADC instance
  4975. * @retval 0: no command of conversion stop is on going on ADC group injected.
  4976. */
  4977. __STATIC_INLINE uint32_t LL_ADC_INJ_IsStopConversionOngoing(ADC_TypeDef *ADCx)
  4978. {
  4979. return ((READ_BIT(ADCx->CR, ADC_CR_JADSTP) == (ADC_CR_JADSTP)) ? 1UL : 0UL);
  4980. }
  4981. /**
  4982. * @brief Get ADC group regular conversion data, range fit for
  4983. * all ADC configurations: all ADC resolutions and
  4984. * all oversampling increased data width (for devices
  4985. * with feature oversampling).
  4986. * @rmtoll JDR1 JDATA LL_ADC_INJ_ReadConversionData32\n
  4987. * JDR2 JDATA LL_ADC_INJ_ReadConversionData32\n
  4988. * JDR3 JDATA LL_ADC_INJ_ReadConversionData32\n
  4989. * JDR4 JDATA LL_ADC_INJ_ReadConversionData32
  4990. * @param ADCx ADC instance
  4991. * @param Rank This parameter can be one of the following values:
  4992. * @arg @ref LL_ADC_INJ_RANK_1
  4993. * @arg @ref LL_ADC_INJ_RANK_2
  4994. * @arg @ref LL_ADC_INJ_RANK_3
  4995. * @arg @ref LL_ADC_INJ_RANK_4
  4996. * @retval Value between Min_Data=0x00000000 and Max_Data=0xFFFFFFFF
  4997. */
  4998. __STATIC_INLINE uint32_t LL_ADC_INJ_ReadConversionData32(ADC_TypeDef *ADCx, uint32_t Rank)
  4999. {
  5000. register const __IO uint32_t *preg = __ADC_PTR_REG_OFFSET(ADCx->JDR1, ((Rank & ADC_INJ_JDRX_REGOFFSET_MASK) >> ADC_JDRX_REGOFFSET_POS));
  5001. return (uint32_t)(READ_BIT(*preg,
  5002. ADC_JDR1_JDATA)
  5003. );
  5004. }
  5005. /**
  5006. * @brief Get ADC group injected conversion data, range fit for
  5007. * ADC resolution 12 bits.
  5008. * @note For devices with feature oversampling: Oversampling
  5009. * can increase data width, function for extended range
  5010. * may be needed: @ref LL_ADC_INJ_ReadConversionData32.
  5011. * @rmtoll JDR1 JDATA LL_ADC_INJ_ReadConversionData12\n
  5012. * JDR2 JDATA LL_ADC_INJ_ReadConversionData12\n
  5013. * JDR3 JDATA LL_ADC_INJ_ReadConversionData12\n
  5014. * JDR4 JDATA LL_ADC_INJ_ReadConversionData12
  5015. * @param ADCx ADC instance
  5016. * @param Rank This parameter can be one of the following values:
  5017. * @arg @ref LL_ADC_INJ_RANK_1
  5018. * @arg @ref LL_ADC_INJ_RANK_2
  5019. * @arg @ref LL_ADC_INJ_RANK_3
  5020. * @arg @ref LL_ADC_INJ_RANK_4
  5021. * @retval Value between Min_Data=0x000 and Max_Data=0xFFF
  5022. */
  5023. __STATIC_INLINE uint16_t LL_ADC_INJ_ReadConversionData12(ADC_TypeDef *ADCx, uint32_t Rank)
  5024. {
  5025. register const __IO uint32_t *preg = __ADC_PTR_REG_OFFSET(ADCx->JDR1, ((Rank & ADC_INJ_JDRX_REGOFFSET_MASK) >> ADC_JDRX_REGOFFSET_POS));
  5026. return (uint16_t)(READ_BIT(*preg,
  5027. ADC_JDR1_JDATA)
  5028. );
  5029. }
  5030. /**
  5031. * @brief Get ADC group injected conversion data, range fit for
  5032. * ADC resolution 10 bits.
  5033. * @note For devices with feature oversampling: Oversampling
  5034. * can increase data width, function for extended range
  5035. * may be needed: @ref LL_ADC_INJ_ReadConversionData32.
  5036. * @rmtoll JDR1 JDATA LL_ADC_INJ_ReadConversionData10\n
  5037. * JDR2 JDATA LL_ADC_INJ_ReadConversionData10\n
  5038. * JDR3 JDATA LL_ADC_INJ_ReadConversionData10\n
  5039. * JDR4 JDATA LL_ADC_INJ_ReadConversionData10
  5040. * @param ADCx ADC instance
  5041. * @param Rank This parameter can be one of the following values:
  5042. * @arg @ref LL_ADC_INJ_RANK_1
  5043. * @arg @ref LL_ADC_INJ_RANK_2
  5044. * @arg @ref LL_ADC_INJ_RANK_3
  5045. * @arg @ref LL_ADC_INJ_RANK_4
  5046. * @retval Value between Min_Data=0x000 and Max_Data=0x3FF
  5047. */
  5048. __STATIC_INLINE uint16_t LL_ADC_INJ_ReadConversionData10(ADC_TypeDef *ADCx, uint32_t Rank)
  5049. {
  5050. register const __IO uint32_t *preg = __ADC_PTR_REG_OFFSET(ADCx->JDR1, ((Rank & ADC_INJ_JDRX_REGOFFSET_MASK) >> ADC_JDRX_REGOFFSET_POS));
  5051. return (uint16_t)(READ_BIT(*preg,
  5052. ADC_JDR1_JDATA)
  5053. );
  5054. }
  5055. /**
  5056. * @brief Get ADC group injected conversion data, range fit for
  5057. * ADC resolution 8 bits.
  5058. * @note For devices with feature oversampling: Oversampling
  5059. * can increase data width, function for extended range
  5060. * may be needed: @ref LL_ADC_INJ_ReadConversionData32.
  5061. * @rmtoll JDR1 JDATA LL_ADC_INJ_ReadConversionData8\n
  5062. * JDR2 JDATA LL_ADC_INJ_ReadConversionData8\n
  5063. * JDR3 JDATA LL_ADC_INJ_ReadConversionData8\n
  5064. * JDR4 JDATA LL_ADC_INJ_ReadConversionData8
  5065. * @param ADCx ADC instance
  5066. * @param Rank This parameter can be one of the following values:
  5067. * @arg @ref LL_ADC_INJ_RANK_1
  5068. * @arg @ref LL_ADC_INJ_RANK_2
  5069. * @arg @ref LL_ADC_INJ_RANK_3
  5070. * @arg @ref LL_ADC_INJ_RANK_4
  5071. * @retval Value between Min_Data=0x00 and Max_Data=0xFF
  5072. */
  5073. __STATIC_INLINE uint8_t LL_ADC_INJ_ReadConversionData8(ADC_TypeDef *ADCx, uint32_t Rank)
  5074. {
  5075. register const __IO uint32_t *preg = __ADC_PTR_REG_OFFSET(ADCx->JDR1, ((Rank & ADC_INJ_JDRX_REGOFFSET_MASK) >> ADC_JDRX_REGOFFSET_POS));
  5076. return (uint8_t)(READ_BIT(*preg,
  5077. ADC_JDR1_JDATA)
  5078. );
  5079. }
  5080. /**
  5081. * @brief Get ADC group injected conversion data, range fit for
  5082. * ADC resolution 6 bits.
  5083. * @note For devices with feature oversampling: Oversampling
  5084. * can increase data width, function for extended range
  5085. * may be needed: @ref LL_ADC_INJ_ReadConversionData32.
  5086. * @rmtoll JDR1 JDATA LL_ADC_INJ_ReadConversionData6\n
  5087. * JDR2 JDATA LL_ADC_INJ_ReadConversionData6\n
  5088. * JDR3 JDATA LL_ADC_INJ_ReadConversionData6\n
  5089. * JDR4 JDATA LL_ADC_INJ_ReadConversionData6
  5090. * @param ADCx ADC instance
  5091. * @param Rank This parameter can be one of the following values:
  5092. * @arg @ref LL_ADC_INJ_RANK_1
  5093. * @arg @ref LL_ADC_INJ_RANK_2
  5094. * @arg @ref LL_ADC_INJ_RANK_3
  5095. * @arg @ref LL_ADC_INJ_RANK_4
  5096. * @retval Value between Min_Data=0x00 and Max_Data=0x3F
  5097. */
  5098. __STATIC_INLINE uint8_t LL_ADC_INJ_ReadConversionData6(ADC_TypeDef *ADCx, uint32_t Rank)
  5099. {
  5100. register const __IO uint32_t *preg = __ADC_PTR_REG_OFFSET(ADCx->JDR1, ((Rank & ADC_INJ_JDRX_REGOFFSET_MASK) >> ADC_JDRX_REGOFFSET_POS));
  5101. return (uint8_t)(READ_BIT(*preg,
  5102. ADC_JDR1_JDATA)
  5103. );
  5104. }
  5105. /**
  5106. * @}
  5107. */
  5108. /** @defgroup ADC_LL_EF_FLAG_Management ADC flag management
  5109. * @{
  5110. */
  5111. /**
  5112. * @brief Get flag ADC ready.
  5113. * @note On this STM32 serie, flag LL_ADC_FLAG_ADRDY is raised when the ADC
  5114. * is enabled and when conversion clock is active.
  5115. * (not only core clock: this ADC has a dual clock domain)
  5116. * @rmtoll ISR ADRDY LL_ADC_IsActiveFlag_ADRDY
  5117. * @param ADCx ADC instance
  5118. * @retval State of bit (1 or 0).
  5119. */
  5120. __STATIC_INLINE uint32_t LL_ADC_IsActiveFlag_ADRDY(ADC_TypeDef *ADCx)
  5121. {
  5122. return ((READ_BIT(ADCx->ISR, LL_ADC_FLAG_ADRDY) == (LL_ADC_FLAG_ADRDY)) ? 1UL : 0UL);
  5123. }
  5124. /**
  5125. * @brief Get flag ADC group regular end of unitary conversion.
  5126. * @rmtoll ISR EOC LL_ADC_IsActiveFlag_EOC
  5127. * @param ADCx ADC instance
  5128. * @retval State of bit (1 or 0).
  5129. */
  5130. __STATIC_INLINE uint32_t LL_ADC_IsActiveFlag_EOC(ADC_TypeDef *ADCx)
  5131. {
  5132. return ((READ_BIT(ADCx->ISR, ADC_ISR_EOC) == (ADC_ISR_EOC)) ? 1UL : 0UL);
  5133. }
  5134. /**
  5135. * @brief Get flag ADC group regular end of sequence conversions.
  5136. * @rmtoll ISR EOS LL_ADC_IsActiveFlag_EOS
  5137. * @param ADCx ADC instance
  5138. * @retval State of bit (1 or 0).
  5139. */
  5140. __STATIC_INLINE uint32_t LL_ADC_IsActiveFlag_EOS(ADC_TypeDef *ADCx)
  5141. {
  5142. return ((READ_BIT(ADCx->ISR, LL_ADC_FLAG_EOS) == (LL_ADC_FLAG_EOS)) ? 1UL : 0UL);
  5143. }
  5144. /**
  5145. * @brief Get flag ADC group regular overrun.
  5146. * @rmtoll ISR OVR LL_ADC_IsActiveFlag_OVR
  5147. * @param ADCx ADC instance
  5148. * @retval State of bit (1 or 0).
  5149. */
  5150. __STATIC_INLINE uint32_t LL_ADC_IsActiveFlag_OVR(ADC_TypeDef *ADCx)
  5151. {
  5152. return ((READ_BIT(ADCx->ISR, LL_ADC_FLAG_OVR) == (LL_ADC_FLAG_OVR)) ? 1UL : 0UL);
  5153. }
  5154. /**
  5155. * @brief Get flag ADC group regular end of sampling phase.
  5156. * @rmtoll ISR EOSMP LL_ADC_IsActiveFlag_EOSMP
  5157. * @param ADCx ADC instance
  5158. * @retval State of bit (1 or 0).
  5159. */
  5160. __STATIC_INLINE uint32_t LL_ADC_IsActiveFlag_EOSMP(ADC_TypeDef *ADCx)
  5161. {
  5162. return ((READ_BIT(ADCx->ISR, LL_ADC_FLAG_EOSMP) == (LL_ADC_FLAG_EOSMP)) ? 1UL : 0UL);
  5163. }
  5164. /**
  5165. * @brief Get flag ADC group injected end of unitary conversion.
  5166. * @rmtoll ISR JEOC LL_ADC_IsActiveFlag_JEOC
  5167. * @param ADCx ADC instance
  5168. * @retval State of bit (1 or 0).
  5169. */
  5170. __STATIC_INLINE uint32_t LL_ADC_IsActiveFlag_JEOC(ADC_TypeDef *ADCx)
  5171. {
  5172. return ((READ_BIT(ADCx->ISR, LL_ADC_FLAG_JEOC) == (LL_ADC_FLAG_JEOC)) ? 1UL : 0UL);
  5173. }
  5174. /**
  5175. * @brief Get flag ADC group injected end of sequence conversions.
  5176. * @rmtoll ISR JEOS LL_ADC_IsActiveFlag_JEOS
  5177. * @param ADCx ADC instance
  5178. * @retval State of bit (1 or 0).
  5179. */
  5180. __STATIC_INLINE uint32_t LL_ADC_IsActiveFlag_JEOS(ADC_TypeDef *ADCx)
  5181. {
  5182. return ((READ_BIT(ADCx->ISR, LL_ADC_FLAG_JEOS) == (LL_ADC_FLAG_JEOS)) ? 1UL : 0UL);
  5183. }
  5184. /**
  5185. * @brief Get flag ADC group injected contexts queue overflow.
  5186. * @rmtoll ISR JQOVF LL_ADC_IsActiveFlag_JQOVF
  5187. * @param ADCx ADC instance
  5188. * @retval State of bit (1 or 0).
  5189. */
  5190. __STATIC_INLINE uint32_t LL_ADC_IsActiveFlag_JQOVF(ADC_TypeDef *ADCx)
  5191. {
  5192. return ((READ_BIT(ADCx->ISR, LL_ADC_FLAG_JQOVF) == (LL_ADC_FLAG_JQOVF)) ? 1UL : 0UL);
  5193. }
  5194. /**
  5195. * @brief Get flag ADC analog watchdog 1 flag
  5196. * @rmtoll ISR AWD1 LL_ADC_IsActiveFlag_AWD1
  5197. * @param ADCx ADC instance
  5198. * @retval State of bit (1 or 0).
  5199. */
  5200. __STATIC_INLINE uint32_t LL_ADC_IsActiveFlag_AWD1(ADC_TypeDef *ADCx)
  5201. {
  5202. return ((READ_BIT(ADCx->ISR, LL_ADC_FLAG_AWD1) == (LL_ADC_FLAG_AWD1)) ? 1UL : 0UL);
  5203. }
  5204. /**
  5205. * @brief Get flag ADC analog watchdog 2.
  5206. * @rmtoll ISR AWD2 LL_ADC_IsActiveFlag_AWD2
  5207. * @param ADCx ADC instance
  5208. * @retval State of bit (1 or 0).
  5209. */
  5210. __STATIC_INLINE uint32_t LL_ADC_IsActiveFlag_AWD2(ADC_TypeDef *ADCx)
  5211. {
  5212. return ((READ_BIT(ADCx->ISR, LL_ADC_FLAG_AWD2) == (LL_ADC_FLAG_AWD2)) ? 1UL : 0UL);
  5213. }
  5214. /**
  5215. * @brief Get flag ADC analog watchdog 3.
  5216. * @rmtoll ISR AWD3 LL_ADC_IsActiveFlag_AWD3
  5217. * @param ADCx ADC instance
  5218. * @retval State of bit (1 or 0).
  5219. */
  5220. __STATIC_INLINE uint32_t LL_ADC_IsActiveFlag_AWD3(ADC_TypeDef *ADCx)
  5221. {
  5222. return ((READ_BIT(ADCx->ISR, LL_ADC_FLAG_AWD3) == (LL_ADC_FLAG_AWD3)) ? 1UL : 0UL);
  5223. }
  5224. /**
  5225. * @brief Clear flag ADC ready.
  5226. * @note On this STM32 serie, flag LL_ADC_FLAG_ADRDY is raised when the ADC
  5227. * is enabled and when conversion clock is active.
  5228. * (not only core clock: this ADC has a dual clock domain)
  5229. * @rmtoll ISR ADRDY LL_ADC_ClearFlag_ADRDY
  5230. * @param ADCx ADC instance
  5231. * @retval None
  5232. */
  5233. __STATIC_INLINE void LL_ADC_ClearFlag_ADRDY(ADC_TypeDef *ADCx)
  5234. {
  5235. WRITE_REG(ADCx->ISR, LL_ADC_FLAG_ADRDY);
  5236. }
  5237. /**
  5238. * @brief Clear flag ADC group regular end of unitary conversion.
  5239. * @rmtoll ISR EOC LL_ADC_ClearFlag_EOC
  5240. * @param ADCx ADC instance
  5241. * @retval None
  5242. */
  5243. __STATIC_INLINE void LL_ADC_ClearFlag_EOC(ADC_TypeDef *ADCx)
  5244. {
  5245. WRITE_REG(ADCx->ISR, LL_ADC_FLAG_EOC);
  5246. }
  5247. /**
  5248. * @brief Clear flag ADC group regular end of sequence conversions.
  5249. * @rmtoll ISR EOS LL_ADC_ClearFlag_EOS
  5250. * @param ADCx ADC instance
  5251. * @retval None
  5252. */
  5253. __STATIC_INLINE void LL_ADC_ClearFlag_EOS(ADC_TypeDef *ADCx)
  5254. {
  5255. WRITE_REG(ADCx->ISR, LL_ADC_FLAG_EOS);
  5256. }
  5257. /**
  5258. * @brief Clear flag ADC group regular overrun.
  5259. * @rmtoll ISR OVR LL_ADC_ClearFlag_OVR
  5260. * @param ADCx ADC instance
  5261. * @retval None
  5262. */
  5263. __STATIC_INLINE void LL_ADC_ClearFlag_OVR(ADC_TypeDef *ADCx)
  5264. {
  5265. WRITE_REG(ADCx->ISR, LL_ADC_FLAG_OVR);
  5266. }
  5267. /**
  5268. * @brief Clear flag ADC group regular end of sampling phase.
  5269. * @rmtoll ISR EOSMP LL_ADC_ClearFlag_EOSMP
  5270. * @param ADCx ADC instance
  5271. * @retval None
  5272. */
  5273. __STATIC_INLINE void LL_ADC_ClearFlag_EOSMP(ADC_TypeDef *ADCx)
  5274. {
  5275. WRITE_REG(ADCx->ISR, LL_ADC_FLAG_EOSMP);
  5276. }
  5277. /**
  5278. * @brief Clear flag ADC group injected end of unitary conversion.
  5279. * @rmtoll ISR JEOC LL_ADC_ClearFlag_JEOC
  5280. * @param ADCx ADC instance
  5281. * @retval None
  5282. */
  5283. __STATIC_INLINE void LL_ADC_ClearFlag_JEOC(ADC_TypeDef *ADCx)
  5284. {
  5285. WRITE_REG(ADCx->ISR, LL_ADC_FLAG_JEOC);
  5286. }
  5287. /**
  5288. * @brief Clear flag ADC group injected end of sequence conversions.
  5289. * @rmtoll ISR JEOS LL_ADC_ClearFlag_JEOS
  5290. * @param ADCx ADC instance
  5291. * @retval None
  5292. */
  5293. __STATIC_INLINE void LL_ADC_ClearFlag_JEOS(ADC_TypeDef *ADCx)
  5294. {
  5295. WRITE_REG(ADCx->ISR, LL_ADC_FLAG_JEOS);
  5296. }
  5297. /**
  5298. * @brief Clear flag ADC group injected contexts queue overflow.
  5299. * @rmtoll ISR JQOVF LL_ADC_ClearFlag_JQOVF
  5300. * @param ADCx ADC instance
  5301. * @retval None
  5302. */
  5303. __STATIC_INLINE void LL_ADC_ClearFlag_JQOVF(ADC_TypeDef *ADCx)
  5304. {
  5305. WRITE_REG(ADCx->ISR, LL_ADC_FLAG_JQOVF);
  5306. }
  5307. /**
  5308. * @brief Clear flag ADC analog watchdog 1.
  5309. * @rmtoll ISR AWD1 LL_ADC_ClearFlag_AWD1
  5310. * @param ADCx ADC instance
  5311. * @retval None
  5312. */
  5313. __STATIC_INLINE void LL_ADC_ClearFlag_AWD1(ADC_TypeDef *ADCx)
  5314. {
  5315. WRITE_REG(ADCx->ISR, LL_ADC_FLAG_AWD1);
  5316. }
  5317. /**
  5318. * @brief Clear flag ADC analog watchdog 2.
  5319. * @rmtoll ISR AWD2 LL_ADC_ClearFlag_AWD2
  5320. * @param ADCx ADC instance
  5321. * @retval None
  5322. */
  5323. __STATIC_INLINE void LL_ADC_ClearFlag_AWD2(ADC_TypeDef *ADCx)
  5324. {
  5325. WRITE_REG(ADCx->ISR, LL_ADC_FLAG_AWD2);
  5326. }
  5327. /**
  5328. * @brief Clear flag ADC analog watchdog 3.
  5329. * @rmtoll ISR AWD3 LL_ADC_ClearFlag_AWD3
  5330. * @param ADCx ADC instance
  5331. * @retval None
  5332. */
  5333. __STATIC_INLINE void LL_ADC_ClearFlag_AWD3(ADC_TypeDef *ADCx)
  5334. {
  5335. WRITE_REG(ADCx->ISR, LL_ADC_FLAG_AWD3);
  5336. }
  5337. /**
  5338. * @}
  5339. */
  5340. /** @defgroup ADC_LL_EF_IT_Management ADC IT management
  5341. * @{
  5342. */
  5343. /**
  5344. * @brief Enable ADC ready.
  5345. * @rmtoll IER ADRDYIE LL_ADC_EnableIT_ADRDY
  5346. * @param ADCx ADC instance
  5347. * @retval None
  5348. */
  5349. __STATIC_INLINE void LL_ADC_EnableIT_ADRDY(ADC_TypeDef *ADCx)
  5350. {
  5351. SET_BIT(ADCx->IER, LL_ADC_IT_ADRDY);
  5352. }
  5353. /**
  5354. * @brief Enable interruption ADC group regular end of unitary conversion.
  5355. * @rmtoll IER EOCIE LL_ADC_EnableIT_EOC
  5356. * @param ADCx ADC instance
  5357. * @retval None
  5358. */
  5359. __STATIC_INLINE void LL_ADC_EnableIT_EOC(ADC_TypeDef *ADCx)
  5360. {
  5361. SET_BIT(ADCx->IER, LL_ADC_IT_EOC);
  5362. }
  5363. /**
  5364. * @brief Enable interruption ADC group regular end of sequence conversions.
  5365. * @rmtoll IER EOSIE LL_ADC_EnableIT_EOS
  5366. * @param ADCx ADC instance
  5367. * @retval None
  5368. */
  5369. __STATIC_INLINE void LL_ADC_EnableIT_EOS(ADC_TypeDef *ADCx)
  5370. {
  5371. SET_BIT(ADCx->IER, LL_ADC_IT_EOS);
  5372. }
  5373. /**
  5374. * @brief Enable ADC group regular interruption overrun.
  5375. * @rmtoll IER OVRIE LL_ADC_EnableIT_OVR
  5376. * @param ADCx ADC instance
  5377. * @retval None
  5378. */
  5379. __STATIC_INLINE void LL_ADC_EnableIT_OVR(ADC_TypeDef *ADCx)
  5380. {
  5381. SET_BIT(ADCx->IER, LL_ADC_IT_OVR);
  5382. }
  5383. /**
  5384. * @brief Enable interruption ADC group regular end of sampling.
  5385. * @rmtoll IER EOSMPIE LL_ADC_EnableIT_EOSMP
  5386. * @param ADCx ADC instance
  5387. * @retval None
  5388. */
  5389. __STATIC_INLINE void LL_ADC_EnableIT_EOSMP(ADC_TypeDef *ADCx)
  5390. {
  5391. SET_BIT(ADCx->IER, LL_ADC_IT_EOSMP);
  5392. }
  5393. /**
  5394. * @brief Enable interruption ADC group injected end of unitary conversion.
  5395. * @rmtoll IER JEOCIE LL_ADC_EnableIT_JEOC
  5396. * @param ADCx ADC instance
  5397. * @retval None
  5398. */
  5399. __STATIC_INLINE void LL_ADC_EnableIT_JEOC(ADC_TypeDef *ADCx)
  5400. {
  5401. SET_BIT(ADCx->IER, LL_ADC_IT_JEOC);
  5402. }
  5403. /**
  5404. * @brief Enable interruption ADC group injected end of sequence conversions.
  5405. * @rmtoll IER JEOSIE LL_ADC_EnableIT_JEOS
  5406. * @param ADCx ADC instance
  5407. * @retval None
  5408. */
  5409. __STATIC_INLINE void LL_ADC_EnableIT_JEOS(ADC_TypeDef *ADCx)
  5410. {
  5411. SET_BIT(ADCx->IER, LL_ADC_IT_JEOS);
  5412. }
  5413. /**
  5414. * @brief Enable interruption ADC group injected context queue overflow.
  5415. * @rmtoll IER JQOVFIE LL_ADC_EnableIT_JQOVF
  5416. * @param ADCx ADC instance
  5417. * @retval None
  5418. */
  5419. __STATIC_INLINE void LL_ADC_EnableIT_JQOVF(ADC_TypeDef *ADCx)
  5420. {
  5421. SET_BIT(ADCx->IER, LL_ADC_IT_JQOVF);
  5422. }
  5423. /**
  5424. * @brief Enable interruption ADC analog watchdog 1.
  5425. * @rmtoll IER AWD1IE LL_ADC_EnableIT_AWD1
  5426. * @param ADCx ADC instance
  5427. * @retval None
  5428. */
  5429. __STATIC_INLINE void LL_ADC_EnableIT_AWD1(ADC_TypeDef *ADCx)
  5430. {
  5431. SET_BIT(ADCx->IER, LL_ADC_IT_AWD1);
  5432. }
  5433. /**
  5434. * @brief Enable interruption ADC analog watchdog 2.
  5435. * @rmtoll IER AWD2IE LL_ADC_EnableIT_AWD2
  5436. * @param ADCx ADC instance
  5437. * @retval None
  5438. */
  5439. __STATIC_INLINE void LL_ADC_EnableIT_AWD2(ADC_TypeDef *ADCx)
  5440. {
  5441. SET_BIT(ADCx->IER, LL_ADC_IT_AWD2);
  5442. }
  5443. /**
  5444. * @brief Enable interruption ADC analog watchdog 3.
  5445. * @rmtoll IER AWD3IE LL_ADC_EnableIT_AWD3
  5446. * @param ADCx ADC instance
  5447. * @retval None
  5448. */
  5449. __STATIC_INLINE void LL_ADC_EnableIT_AWD3(ADC_TypeDef *ADCx)
  5450. {
  5451. SET_BIT(ADCx->IER, LL_ADC_IT_AWD3);
  5452. }
  5453. /**
  5454. * @brief Disable interruption ADC ready.
  5455. * @rmtoll IER ADRDYIE LL_ADC_DisableIT_ADRDY
  5456. * @param ADCx ADC instance
  5457. * @retval None
  5458. */
  5459. __STATIC_INLINE void LL_ADC_DisableIT_ADRDY(ADC_TypeDef *ADCx)
  5460. {
  5461. CLEAR_BIT(ADCx->IER, LL_ADC_IT_ADRDY);
  5462. }
  5463. /**
  5464. * @brief Disable interruption ADC group regular end of unitary conversion.
  5465. * @rmtoll IER EOCIE LL_ADC_DisableIT_EOC
  5466. * @param ADCx ADC instance
  5467. * @retval None
  5468. */
  5469. __STATIC_INLINE void LL_ADC_DisableIT_EOC(ADC_TypeDef *ADCx)
  5470. {
  5471. CLEAR_BIT(ADCx->IER, LL_ADC_IT_EOC);
  5472. }
  5473. /**
  5474. * @brief Disable interruption ADC group regular end of sequence conversions.
  5475. * @rmtoll IER EOSIE LL_ADC_DisableIT_EOS
  5476. * @param ADCx ADC instance
  5477. * @retval None
  5478. */
  5479. __STATIC_INLINE void LL_ADC_DisableIT_EOS(ADC_TypeDef *ADCx)
  5480. {
  5481. CLEAR_BIT(ADCx->IER, LL_ADC_IT_EOS);
  5482. }
  5483. /**
  5484. * @brief Disable interruption ADC group regular overrun.
  5485. * @rmtoll IER OVRIE LL_ADC_DisableIT_OVR
  5486. * @param ADCx ADC instance
  5487. * @retval None
  5488. */
  5489. __STATIC_INLINE void LL_ADC_DisableIT_OVR(ADC_TypeDef *ADCx)
  5490. {
  5491. CLEAR_BIT(ADCx->IER, LL_ADC_IT_OVR);
  5492. }
  5493. /**
  5494. * @brief Disable interruption ADC group regular end of sampling.
  5495. * @rmtoll IER EOSMPIE LL_ADC_DisableIT_EOSMP
  5496. * @param ADCx ADC instance
  5497. * @retval None
  5498. */
  5499. __STATIC_INLINE void LL_ADC_DisableIT_EOSMP(ADC_TypeDef *ADCx)
  5500. {
  5501. CLEAR_BIT(ADCx->IER, LL_ADC_IT_EOSMP);
  5502. }
  5503. /**
  5504. * @brief Disable interruption ADC group regular end of unitary conversion.
  5505. * @rmtoll IER JEOCIE LL_ADC_DisableIT_JEOC
  5506. * @param ADCx ADC instance
  5507. * @retval None
  5508. */
  5509. __STATIC_INLINE void LL_ADC_DisableIT_JEOC(ADC_TypeDef *ADCx)
  5510. {
  5511. CLEAR_BIT(ADCx->IER, LL_ADC_IT_JEOC);
  5512. }
  5513. /**
  5514. * @brief Disable interruption ADC group injected end of sequence conversions.
  5515. * @rmtoll IER JEOSIE LL_ADC_DisableIT_JEOS
  5516. * @param ADCx ADC instance
  5517. * @retval None
  5518. */
  5519. __STATIC_INLINE void LL_ADC_DisableIT_JEOS(ADC_TypeDef *ADCx)
  5520. {
  5521. CLEAR_BIT(ADCx->IER, LL_ADC_IT_JEOS);
  5522. }
  5523. /**
  5524. * @brief Disable interruption ADC group injected context queue overflow.
  5525. * @rmtoll IER JQOVFIE LL_ADC_DisableIT_JQOVF
  5526. * @param ADCx ADC instance
  5527. * @retval None
  5528. */
  5529. __STATIC_INLINE void LL_ADC_DisableIT_JQOVF(ADC_TypeDef *ADCx)
  5530. {
  5531. CLEAR_BIT(ADCx->IER, LL_ADC_IT_JQOVF);
  5532. }
  5533. /**
  5534. * @brief Disable interruption ADC analog watchdog 1.
  5535. * @rmtoll IER AWD1IE LL_ADC_DisableIT_AWD1
  5536. * @param ADCx ADC instance
  5537. * @retval None
  5538. */
  5539. __STATIC_INLINE void LL_ADC_DisableIT_AWD1(ADC_TypeDef *ADCx)
  5540. {
  5541. CLEAR_BIT(ADCx->IER, LL_ADC_IT_AWD1);
  5542. }
  5543. /**
  5544. * @brief Disable interruption ADC analog watchdog 2.
  5545. * @rmtoll IER AWD2IE LL_ADC_DisableIT_AWD2
  5546. * @param ADCx ADC instance
  5547. * @retval None
  5548. */
  5549. __STATIC_INLINE void LL_ADC_DisableIT_AWD2(ADC_TypeDef *ADCx)
  5550. {
  5551. CLEAR_BIT(ADCx->IER, LL_ADC_IT_AWD2);
  5552. }
  5553. /**
  5554. * @brief Disable interruption ADC analog watchdog 3.
  5555. * @rmtoll IER AWD3IE LL_ADC_DisableIT_AWD3
  5556. * @param ADCx ADC instance
  5557. * @retval None
  5558. */
  5559. __STATIC_INLINE void LL_ADC_DisableIT_AWD3(ADC_TypeDef *ADCx)
  5560. {
  5561. CLEAR_BIT(ADCx->IER, LL_ADC_IT_AWD3);
  5562. }
  5563. /**
  5564. * @brief Get state of interruption ADC ready
  5565. * (0: interrupt disabled, 1: interrupt enabled).
  5566. * @rmtoll IER ADRDYIE LL_ADC_IsEnabledIT_ADRDY
  5567. * @param ADCx ADC instance
  5568. * @retval State of bit (1 or 0).
  5569. */
  5570. __STATIC_INLINE uint32_t LL_ADC_IsEnabledIT_ADRDY(ADC_TypeDef *ADCx)
  5571. {
  5572. return ((READ_BIT(ADCx->IER, LL_ADC_IT_ADRDY) == (LL_ADC_IT_ADRDY)) ? 1UL : 0UL);
  5573. }
  5574. /**
  5575. * @brief Get state of interruption ADC group regular end of unitary conversion
  5576. * (0: interrupt disabled, 1: interrupt enabled).
  5577. * @rmtoll IER EOCIE LL_ADC_IsEnabledIT_EOC
  5578. * @param ADCx ADC instance
  5579. * @retval State of bit (1 or 0).
  5580. */
  5581. __STATIC_INLINE uint32_t LL_ADC_IsEnabledIT_EOC(ADC_TypeDef *ADCx)
  5582. {
  5583. return ((READ_BIT(ADCx->IER, LL_ADC_IT_EOC) == (LL_ADC_IT_EOC)) ? 1UL : 0UL);
  5584. }
  5585. /**
  5586. * @brief Get state of interruption ADC group regular end of sequence conversions
  5587. * (0: interrupt disabled, 1: interrupt enabled).
  5588. * @rmtoll IER EOSIE LL_ADC_IsEnabledIT_EOS
  5589. * @param ADCx ADC instance
  5590. * @retval State of bit (1 or 0).
  5591. */
  5592. __STATIC_INLINE uint32_t LL_ADC_IsEnabledIT_EOS(ADC_TypeDef *ADCx)
  5593. {
  5594. return ((READ_BIT(ADCx->IER, LL_ADC_IT_EOS) == (LL_ADC_IT_EOS)) ? 1UL : 0UL);
  5595. }
  5596. /**
  5597. * @brief Get state of interruption ADC group regular overrun
  5598. * (0: interrupt disabled, 1: interrupt enabled).
  5599. * @rmtoll IER OVRIE LL_ADC_IsEnabledIT_OVR
  5600. * @param ADCx ADC instance
  5601. * @retval State of bit (1 or 0).
  5602. */
  5603. __STATIC_INLINE uint32_t LL_ADC_IsEnabledIT_OVR(ADC_TypeDef *ADCx)
  5604. {
  5605. return ((READ_BIT(ADCx->IER, LL_ADC_IT_OVR) == (LL_ADC_IT_OVR)) ? 1UL : 0UL);
  5606. }
  5607. /**
  5608. * @brief Get state of interruption ADC group regular end of sampling
  5609. * (0: interrupt disabled, 1: interrupt enabled).
  5610. * @rmtoll IER EOSMPIE LL_ADC_IsEnabledIT_EOSMP
  5611. * @param ADCx ADC instance
  5612. * @retval State of bit (1 or 0).
  5613. */
  5614. __STATIC_INLINE uint32_t LL_ADC_IsEnabledIT_EOSMP(ADC_TypeDef *ADCx)
  5615. {
  5616. return ((READ_BIT(ADCx->IER, LL_ADC_IT_EOSMP) == (LL_ADC_IT_EOSMP)) ? 1UL : 0UL);
  5617. }
  5618. /**
  5619. * @brief Get state of interruption ADC group injected end of unitary conversion
  5620. * (0: interrupt disabled, 1: interrupt enabled).
  5621. * @rmtoll IER JEOCIE LL_ADC_IsEnabledIT_JEOC
  5622. * @param ADCx ADC instance
  5623. * @retval State of bit (1 or 0).
  5624. */
  5625. __STATIC_INLINE uint32_t LL_ADC_IsEnabledIT_JEOC(ADC_TypeDef *ADCx)
  5626. {
  5627. return ((READ_BIT(ADCx->IER, LL_ADC_IT_JEOC) == (LL_ADC_IT_JEOC)) ? 1UL : 0UL);
  5628. }
  5629. /**
  5630. * @brief Get state of interruption ADC group injected end of sequence conversions
  5631. * (0: interrupt disabled, 1: interrupt enabled).
  5632. * @rmtoll IER JEOSIE LL_ADC_IsEnabledIT_JEOS
  5633. * @param ADCx ADC instance
  5634. * @retval State of bit (1 or 0).
  5635. */
  5636. __STATIC_INLINE uint32_t LL_ADC_IsEnabledIT_JEOS(ADC_TypeDef *ADCx)
  5637. {
  5638. return ((READ_BIT(ADCx->IER, LL_ADC_IT_JEOS) == (LL_ADC_IT_JEOS)) ? 1UL : 0UL);
  5639. }
  5640. /**
  5641. * @brief Get state of interruption ADC group injected context queue overflow interrupt state
  5642. * (0: interrupt disabled, 1: interrupt enabled).
  5643. * @rmtoll IER JQOVFIE LL_ADC_IsEnabledIT_JQOVF
  5644. * @param ADCx ADC instance
  5645. * @retval State of bit (1 or 0).
  5646. */
  5647. __STATIC_INLINE uint32_t LL_ADC_IsEnabledIT_JQOVF(ADC_TypeDef *ADCx)
  5648. {
  5649. return ((READ_BIT(ADCx->IER, LL_ADC_IT_JQOVF) == (LL_ADC_IT_JQOVF)) ? 1UL : 0UL);
  5650. }
  5651. /**
  5652. * @brief Get state of interruption ADC analog watchdog 1
  5653. * (0: interrupt disabled, 1: interrupt enabled).
  5654. * @rmtoll IER AWD1IE LL_ADC_IsEnabledIT_AWD1
  5655. * @param ADCx ADC instance
  5656. * @retval State of bit (1 or 0).
  5657. */
  5658. __STATIC_INLINE uint32_t LL_ADC_IsEnabledIT_AWD1(ADC_TypeDef *ADCx)
  5659. {
  5660. return ((READ_BIT(ADCx->IER, LL_ADC_IT_AWD1) == (LL_ADC_IT_AWD1)) ? 1UL : 0UL);
  5661. }
  5662. /**
  5663. * @brief Get state of interruption Get ADC analog watchdog 2
  5664. * (0: interrupt disabled, 1: interrupt enabled).
  5665. * @rmtoll IER AWD2IE LL_ADC_IsEnabledIT_AWD2
  5666. * @param ADCx ADC instance
  5667. * @retval State of bit (1 or 0).
  5668. */
  5669. __STATIC_INLINE uint32_t LL_ADC_IsEnabledIT_AWD2(ADC_TypeDef *ADCx)
  5670. {
  5671. return ((READ_BIT(ADCx->IER, LL_ADC_IT_AWD2) == (LL_ADC_IT_AWD2)) ? 1UL : 0UL);
  5672. }
  5673. /**
  5674. * @brief Get state of interruption Get ADC analog watchdog 3
  5675. * (0: interrupt disabled, 1: interrupt enabled).
  5676. * @rmtoll IER AWD3IE LL_ADC_IsEnabledIT_AWD3
  5677. * @param ADCx ADC instance
  5678. * @retval State of bit (1 or 0).
  5679. */
  5680. __STATIC_INLINE uint32_t LL_ADC_IsEnabledIT_AWD3(ADC_TypeDef *ADCx)
  5681. {
  5682. return ((READ_BIT(ADCx->IER, LL_ADC_IT_AWD3) == (LL_ADC_IT_AWD3)) ? 1UL : 0UL);
  5683. }
  5684. /**
  5685. * @}
  5686. */
  5687. #if defined(USE_FULL_LL_DRIVER)
  5688. /** @defgroup ADC_LL_EF_Init Initialization and de-initialization functions
  5689. * @{
  5690. */
  5691. /* Initialization of some features of ADC common parameters and multimode */
  5692. ErrorStatus LL_ADC_CommonDeInit(ADC_Common_TypeDef *ADCxy_COMMON);
  5693. ErrorStatus LL_ADC_CommonInit(ADC_Common_TypeDef *ADCxy_COMMON, LL_ADC_CommonInitTypeDef *ADC_CommonInitStruct);
  5694. void LL_ADC_CommonStructInit(LL_ADC_CommonInitTypeDef *ADC_CommonInitStruct);
  5695. /* De-initialization of ADC instance, ADC group regular and ADC group injected */
  5696. /* (availability of ADC group injected depends on STM32 families) */
  5697. ErrorStatus LL_ADC_DeInit(ADC_TypeDef *ADCx);
  5698. /* Initialization of some features of ADC instance */
  5699. ErrorStatus LL_ADC_Init(ADC_TypeDef *ADCx, LL_ADC_InitTypeDef *ADC_InitStruct);
  5700. void LL_ADC_StructInit(LL_ADC_InitTypeDef *ADC_InitStruct);
  5701. /* Initialization of some features of ADC instance and ADC group regular */
  5702. ErrorStatus LL_ADC_REG_Init(ADC_TypeDef *ADCx, LL_ADC_REG_InitTypeDef *ADC_REG_InitStruct);
  5703. void LL_ADC_REG_StructInit(LL_ADC_REG_InitTypeDef *ADC_REG_InitStruct);
  5704. /* Initialization of some features of ADC instance and ADC group injected */
  5705. ErrorStatus LL_ADC_INJ_Init(ADC_TypeDef *ADCx, LL_ADC_INJ_InitTypeDef *ADC_INJ_InitStruct);
  5706. void LL_ADC_INJ_StructInit(LL_ADC_INJ_InitTypeDef *ADC_INJ_InitStruct);
  5707. /**
  5708. * @}
  5709. */
  5710. #endif /* USE_FULL_LL_DRIVER */
  5711. /**
  5712. * @}
  5713. */
  5714. /**
  5715. * @}
  5716. */
  5717. #endif /* ADC1 */
  5718. /**
  5719. * @}
  5720. */
  5721. #ifdef __cplusplus
  5722. }
  5723. #endif
  5724. #endif /* STM32WBxx_LL_ADC_H */
  5725. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/