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.
 
 
 

6205 lines
338 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 (4)
  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 (4)
  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. * @brief Helper macro to calculate the temperature (unit: degree Celsius)
  1623. * from ADC conversion data of internal temperature sensor.
  1624. * @note Computation is using temperature sensor calibration values
  1625. * stored in system memory for each device during production.
  1626. * @note Calculation formula:
  1627. * Temperature = ((TS_ADC_DATA - TS_CAL1)
  1628. * * (TS_CAL2_TEMP - TS_CAL1_TEMP))
  1629. * / (TS_CAL2 - TS_CAL1) + TS_CAL1_TEMP
  1630. * with TS_ADC_DATA = temperature sensor raw data measured by ADC
  1631. * Avg_Slope = (TS_CAL2 - TS_CAL1)
  1632. * / (TS_CAL2_TEMP - TS_CAL1_TEMP)
  1633. * TS_CAL1 = equivalent TS_ADC_DATA at temperature
  1634. * TEMP_DEGC_CAL1 (calibrated in factory)
  1635. * TS_CAL2 = equivalent TS_ADC_DATA at temperature
  1636. * TEMP_DEGC_CAL2 (calibrated in factory)
  1637. * Caution: Calculation relevancy under reserve that calibration
  1638. * parameters are correct (address and data).
  1639. * To calculate temperature using temperature sensor
  1640. * datasheet typical values (generic values less, therefore
  1641. * less accurate than calibrated values),
  1642. * use helper macro @ref __LL_ADC_CALC_TEMPERATURE_TYP_PARAMS().
  1643. * @note As calculation input, the analog reference voltage (Vref+) must be
  1644. * defined as it impacts the ADC LSB equivalent voltage.
  1645. * @note Analog reference voltage (Vref+) must be either known from
  1646. * user board environment or can be calculated using ADC measurement
  1647. * and ADC helper macro @ref __LL_ADC_CALC_VREFANALOG_VOLTAGE().
  1648. * @note On this STM32 serie, calibration data of temperature sensor
  1649. * corresponds to a resolution of 12 bits,
  1650. * this is the recommended ADC resolution to convert voltage of
  1651. * temperature sensor.
  1652. * Otherwise, this macro performs the processing to scale
  1653. * ADC conversion data to 12 bits.
  1654. * @param __VREFANALOG_VOLTAGE__ Analog reference voltage (unit: mV)
  1655. * @param __TEMPSENSOR_ADC_DATA__ ADC conversion data of internal
  1656. * temperature sensor (unit: digital value).
  1657. * @param __ADC_RESOLUTION__ ADC resolution at which internal temperature
  1658. * sensor voltage has been measured.
  1659. * This parameter can be one of the following values:
  1660. * @arg @ref LL_ADC_RESOLUTION_12B
  1661. * @arg @ref LL_ADC_RESOLUTION_10B
  1662. * @arg @ref LL_ADC_RESOLUTION_8B
  1663. * @arg @ref LL_ADC_RESOLUTION_6B
  1664. * @retval Temperature (unit: degree Celsius)
  1665. */
  1666. #define __LL_ADC_CALC_TEMPERATURE(__VREFANALOG_VOLTAGE__,\
  1667. __TEMPSENSOR_ADC_DATA__,\
  1668. __ADC_RESOLUTION__) \
  1669. (((( ((int32_t)((__LL_ADC_CONVERT_DATA_RESOLUTION((__TEMPSENSOR_ADC_DATA__), \
  1670. (__ADC_RESOLUTION__), \
  1671. LL_ADC_RESOLUTION_12B) \
  1672. * (__VREFANALOG_VOLTAGE__)) \
  1673. / TEMPSENSOR_CAL_VREFANALOG) \
  1674. - (int32_t) *TEMPSENSOR_CAL1_ADDR) \
  1675. ) * (int32_t)(TEMPSENSOR_CAL2_TEMP - TEMPSENSOR_CAL1_TEMP) \
  1676. ) / (int32_t)((int32_t)*TEMPSENSOR_CAL2_ADDR - (int32_t)*TEMPSENSOR_CAL1_ADDR) \
  1677. ) + TEMPSENSOR_CAL1_TEMP \
  1678. )
  1679. /**
  1680. * @brief Helper macro to calculate the temperature (unit: degree Celsius)
  1681. * from ADC conversion data of internal temperature sensor.
  1682. * @note Computation is using temperature sensor typical values
  1683. * (refer to device datasheet).
  1684. * @note Calculation formula:
  1685. * Temperature = (TS_TYP_CALx_VOLT(uV) - TS_ADC_DATA * Conversion_uV)
  1686. * / Avg_Slope + CALx_TEMP
  1687. * with TS_ADC_DATA = temperature sensor raw data measured by ADC
  1688. * (unit: digital value)
  1689. * Avg_Slope = temperature sensor slope
  1690. * (unit: uV/Degree Celsius)
  1691. * TS_TYP_CALx_VOLT = temperature sensor digital value at
  1692. * temperature CALx_TEMP (unit: mV)
  1693. * Caution: Calculation relevancy under reserve the temperature sensor
  1694. * of the current device has characteristics in line with
  1695. * datasheet typical values.
  1696. * If temperature sensor calibration values are available on
  1697. * on this device (presence of macro __LL_ADC_CALC_TEMPERATURE()),
  1698. * temperature calculation will be more accurate using
  1699. * helper macro @ref __LL_ADC_CALC_TEMPERATURE().
  1700. * @note As calculation input, the analog reference voltage (Vref+) must be
  1701. * defined as it impacts the ADC LSB equivalent voltage.
  1702. * @note Analog reference voltage (Vref+) must be either known from
  1703. * user board environment or can be calculated using ADC measurement
  1704. * and ADC helper macro @ref __LL_ADC_CALC_VREFANALOG_VOLTAGE().
  1705. * @note ADC measurement data must correspond to a resolution of 12 bits
  1706. * (full scale digital value 4095). If not the case, the data must be
  1707. * preliminarily rescaled to an equivalent resolution of 12 bits.
  1708. * @param __TEMPSENSOR_TYP_AVGSLOPE__ Device datasheet data: Temperature sensor slope typical value (unit: uV/DegCelsius).
  1709. * On STM32WB, refer to device datasheet parameter "Avg_Slope".
  1710. * @param __TEMPSENSOR_TYP_CALX_V__ Device datasheet data: Temperature sensor voltage typical value (at temperature and Vref+ defined in parameters below) (unit: mV).
  1711. * On STM32WB, refer to device datasheet parameter "V30" (corresponding to TS_CAL1).
  1712. * @param __TEMPSENSOR_CALX_TEMP__ Device datasheet data: Temperature at which temperature sensor voltage (see parameter above) is corresponding (unit: mV)
  1713. * @param __VREFANALOG_VOLTAGE__ Analog voltage reference (Vref+) voltage (unit: mV)
  1714. * @param __TEMPSENSOR_ADC_DATA__ ADC conversion data of internal temperature sensor (unit: digital value).
  1715. * @param __ADC_RESOLUTION__ ADC resolution at which internal temperature sensor voltage has been measured.
  1716. * This parameter can be one of the following values:
  1717. * @arg @ref LL_ADC_RESOLUTION_12B
  1718. * @arg @ref LL_ADC_RESOLUTION_10B
  1719. * @arg @ref LL_ADC_RESOLUTION_8B
  1720. * @arg @ref LL_ADC_RESOLUTION_6B
  1721. * @retval Temperature (unit: degree Celsius)
  1722. */
  1723. #define __LL_ADC_CALC_TEMPERATURE_TYP_PARAMS(__TEMPSENSOR_TYP_AVGSLOPE__,\
  1724. __TEMPSENSOR_TYP_CALX_V__,\
  1725. __TEMPSENSOR_CALX_TEMP__,\
  1726. __VREFANALOG_VOLTAGE__,\
  1727. __TEMPSENSOR_ADC_DATA__,\
  1728. __ADC_RESOLUTION__) \
  1729. ((( ( \
  1730. (int32_t)((((__TEMPSENSOR_ADC_DATA__) * (__VREFANALOG_VOLTAGE__)) \
  1731. / __LL_ADC_DIGITAL_SCALE(__ADC_RESOLUTION__)) \
  1732. * 1000UL) \
  1733. - \
  1734. (int32_t)(((__TEMPSENSOR_TYP_CALX_V__)) \
  1735. * 1000UL) \
  1736. ) \
  1737. ) / (int32_t)(__TEMPSENSOR_TYP_AVGSLOPE__) \
  1738. ) + (int32_t)(__TEMPSENSOR_CALX_TEMP__) \
  1739. )
  1740. /**
  1741. * @}
  1742. */
  1743. /**
  1744. * @}
  1745. */
  1746. /* Exported functions --------------------------------------------------------*/
  1747. /** @defgroup ADC_LL_Exported_Functions ADC Exported Functions
  1748. * @{
  1749. */
  1750. /** @defgroup ADC_LL_EF_DMA_Management ADC DMA management
  1751. * @{
  1752. */
  1753. /* Note: LL ADC functions to set DMA transfer are located into sections of */
  1754. /* configuration of ADC instance, groups and multimode (if available): */
  1755. /* @ref LL_ADC_REG_SetDMATransfer(), ... */
  1756. /**
  1757. * @brief Function to help to configure DMA transfer from ADC: retrieve the
  1758. * ADC register address from ADC instance and a list of ADC registers
  1759. * intended to be used (most commonly) with DMA transfer.
  1760. * @note These ADC registers are data registers:
  1761. * when ADC conversion data is available in ADC data registers,
  1762. * ADC generates a DMA transfer request.
  1763. * @note This macro is intended to be used with LL DMA driver, refer to
  1764. * function "LL_DMA_ConfigAddresses()".
  1765. * Example:
  1766. * LL_DMA_ConfigAddresses(DMA1,
  1767. * LL_DMA_CHANNEL_1,
  1768. * LL_ADC_DMA_GetRegAddr(ADC1, LL_ADC_DMA_REG_REGULAR_DATA),
  1769. * (uint32_t)&< array or variable >,
  1770. * LL_DMA_DIRECTION_PERIPH_TO_MEMORY);
  1771. * @note For devices with several ADC: in multimode, some devices
  1772. * use a different data register outside of ADC instance scope
  1773. * (common data register). This macro manages this register difference,
  1774. * only ADC instance has to be set as parameter.
  1775. * @rmtoll DR DATA LL_ADC_DMA_GetRegAddr
  1776. * @param ADCx ADC instance
  1777. * @param Register This parameter can be one of the following values:
  1778. * @arg @ref LL_ADC_DMA_REG_REGULAR_DATA
  1779. * @retval ADC register address
  1780. */
  1781. __STATIC_INLINE uint32_t LL_ADC_DMA_GetRegAddr(ADC_TypeDef *ADCx, uint32_t Register)
  1782. {
  1783. /* Prevent unused argument(s) compilation warning */
  1784. (void)(Register);
  1785. /* Retrieve address of register DR */
  1786. return (uint32_t)&(ADCx->DR);
  1787. }
  1788. /**
  1789. * @}
  1790. */
  1791. /** @defgroup ADC_LL_EF_Configuration_ADC_Common Configuration of ADC hierarchical scope: common to several ADC instances
  1792. * @{
  1793. */
  1794. /**
  1795. * @brief Set parameter common to several ADC: Clock source and prescaler.
  1796. * @note ADC clock source and prescaler must be selected in function of system clock to not exceed ADC maximum frequency, depending on devices.
  1797. * Example: STM32WB55xx ADC maximum frequency is 64MHz (corresponding to 4.27Msmp/s maximum)
  1798. * Example: STM32WB50xx ADC maximum frequency is 32MHz (corresponding to 2.13Msmp/s maximum)
  1799. * For ADC maximum frequency, refer to datasheet of the selected device.
  1800. * @note On this STM32 serie, if ADC group injected is used, some
  1801. * clock ratio constraints between ADC clock and AHB clock
  1802. * must be respected.
  1803. * Refer to reference manual.
  1804. * @note On this STM32 serie, setting of this feature is conditioned to
  1805. * ADC state:
  1806. * All ADC instances of the ADC common group must be disabled.
  1807. * This check can be done with function @ref LL_ADC_IsEnabled() for each
  1808. * ADC instance or by using helper macro helper macro
  1809. * @ref __LL_ADC_IS_ENABLED_ALL_COMMON_INSTANCE().
  1810. * @rmtoll CCR CKMODE LL_ADC_SetCommonClock\n
  1811. * CCR PRESC LL_ADC_SetCommonClock
  1812. * @param ADCxy_COMMON ADC common instance
  1813. * (can be set directly from CMSIS definition or by using helper macro @ref __LL_ADC_COMMON_INSTANCE() )
  1814. * @param CommonClock This parameter can be one of the following values:
  1815. * @arg @ref LL_ADC_CLOCK_SYNC_PCLK_DIV1
  1816. * @arg @ref LL_ADC_CLOCK_SYNC_PCLK_DIV2
  1817. * @arg @ref LL_ADC_CLOCK_SYNC_PCLK_DIV4
  1818. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV1
  1819. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV2
  1820. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV4
  1821. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV6
  1822. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV8
  1823. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV10
  1824. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV12
  1825. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV16
  1826. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV32
  1827. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV64
  1828. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV128
  1829. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV256
  1830. * @retval None
  1831. */
  1832. __STATIC_INLINE void LL_ADC_SetCommonClock(ADC_Common_TypeDef *ADCxy_COMMON, uint32_t CommonClock)
  1833. {
  1834. MODIFY_REG(ADCxy_COMMON->CCR, ADC_CCR_CKMODE | ADC_CCR_PRESC, CommonClock);
  1835. }
  1836. /**
  1837. * @brief Get parameter common to several ADC: Clock source and prescaler.
  1838. * @rmtoll CCR CKMODE LL_ADC_GetCommonClock\n
  1839. * CCR PRESC LL_ADC_GetCommonClock
  1840. * @param ADCxy_COMMON ADC common instance
  1841. * (can be set directly from CMSIS definition or by using helper macro @ref __LL_ADC_COMMON_INSTANCE() )
  1842. * @retval Returned value can be one of the following values:
  1843. * @arg @ref LL_ADC_CLOCK_SYNC_PCLK_DIV1
  1844. * @arg @ref LL_ADC_CLOCK_SYNC_PCLK_DIV2
  1845. * @arg @ref LL_ADC_CLOCK_SYNC_PCLK_DIV4
  1846. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV1
  1847. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV2
  1848. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV4
  1849. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV6
  1850. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV8
  1851. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV10
  1852. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV12
  1853. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV16
  1854. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV32
  1855. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV64
  1856. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV128
  1857. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV256
  1858. */
  1859. __STATIC_INLINE uint32_t LL_ADC_GetCommonClock(ADC_Common_TypeDef *ADCxy_COMMON)
  1860. {
  1861. return (uint32_t)(READ_BIT(ADCxy_COMMON->CCR, ADC_CCR_CKMODE | ADC_CCR_PRESC));
  1862. }
  1863. /**
  1864. * @brief Set parameter common to several ADC: measurement path to
  1865. * internal channels (VrefInt, temperature sensor, ...).
  1866. * Configure all paths (overwrite current configuration).
  1867. * @note One or several values can be selected.
  1868. * Example: (LL_ADC_PATH_INTERNAL_VREFINT |
  1869. * LL_ADC_PATH_INTERNAL_TEMPSENSOR)
  1870. * The values not selected are removed from configuration.
  1871. * @note Stabilization time of measurement path to internal channel:
  1872. * After enabling internal paths, before starting ADC conversion,
  1873. * a delay is required for internal voltage reference and
  1874. * temperature sensor stabilization time.
  1875. * Refer to device datasheet.
  1876. * Refer to literal @ref LL_ADC_DELAY_VREFINT_STAB_US.
  1877. * Refer to literal @ref LL_ADC_DELAY_TEMPSENSOR_STAB_US.
  1878. * @note ADC internal channel sampling time constraint:
  1879. * For ADC conversion of internal channels,
  1880. * a sampling time minimum value is required.
  1881. * Refer to device datasheet.
  1882. * @note On this STM32 serie, setting of this feature is conditioned to
  1883. * ADC state:
  1884. * All ADC instances of the ADC common group must be disabled.
  1885. * This check can be done with function @ref LL_ADC_IsEnabled() for each
  1886. * ADC instance or by using helper macro helper macro
  1887. * @ref __LL_ADC_IS_ENABLED_ALL_COMMON_INSTANCE().
  1888. * @rmtoll CCR VREFEN LL_ADC_SetCommonPathInternalCh\n
  1889. * CCR TSEN LL_ADC_SetCommonPathInternalCh\n
  1890. * CCR VBATEN LL_ADC_SetCommonPathInternalCh
  1891. * @param ADCxy_COMMON ADC common instance
  1892. * (can be set directly from CMSIS definition or by using helper macro @ref __LL_ADC_COMMON_INSTANCE() )
  1893. * @param PathInternal This parameter can be a combination of the following values:
  1894. * @arg @ref LL_ADC_PATH_INTERNAL_NONE
  1895. * @arg @ref LL_ADC_PATH_INTERNAL_VREFINT
  1896. * @arg @ref LL_ADC_PATH_INTERNAL_TEMPSENSOR
  1897. * @arg @ref LL_ADC_PATH_INTERNAL_VBAT
  1898. * @retval None
  1899. */
  1900. __STATIC_INLINE void LL_ADC_SetCommonPathInternalCh(ADC_Common_TypeDef *ADCxy_COMMON, uint32_t PathInternal)
  1901. {
  1902. MODIFY_REG(ADCxy_COMMON->CCR, ADC_CCR_VREFEN | ADC_CCR_TSEN | ADC_CCR_VBATEN, PathInternal);
  1903. }
  1904. /**
  1905. * @brief Set parameter common to several ADC: measurement path to
  1906. * internal channels (VrefInt, temperature sensor, ...).
  1907. * Add paths to the current configuration.
  1908. * @note One or several values can be selected.
  1909. * Example: (LL_ADC_PATH_INTERNAL_VREFINT |
  1910. * LL_ADC_PATH_INTERNAL_TEMPSENSOR)
  1911. * @note Stabilization time of measurement path to internal channel:
  1912. * After enabling internal paths, before starting ADC conversion,
  1913. * a delay is required for internal voltage reference and
  1914. * temperature sensor stabilization time.
  1915. * Refer to device datasheet.
  1916. * Refer to literal @ref LL_ADC_DELAY_VREFINT_STAB_US.
  1917. * Refer to literal @ref LL_ADC_DELAY_TEMPSENSOR_STAB_US.
  1918. * @note ADC internal channel sampling time constraint:
  1919. * For ADC conversion of internal channels,
  1920. * a sampling time minimum value is required.
  1921. * Refer to device datasheet.
  1922. * @note On this STM32 serie, setting of this feature is conditioned to
  1923. * ADC state:
  1924. * All ADC instances of the ADC common group must be disabled.
  1925. * This check can be done with function @ref LL_ADC_IsEnabled() for each
  1926. * ADC instance or by using helper macro helper macro
  1927. * @ref __LL_ADC_IS_ENABLED_ALL_COMMON_INSTANCE().
  1928. * @rmtoll CCR VREFEN LL_ADC_SetCommonPathInternalChAdd\n
  1929. * CCR TSEN LL_ADC_SetCommonPathInternalChAdd\n
  1930. * CCR VBATEN LL_ADC_SetCommonPathInternalChAdd
  1931. * @param ADCxy_COMMON ADC common instance
  1932. * (can be set directly from CMSIS definition or by using helper macro @ref __LL_ADC_COMMON_INSTANCE() )
  1933. * @param PathInternal This parameter can be a combination of the following values:
  1934. * @arg @ref LL_ADC_PATH_INTERNAL_NONE
  1935. * @arg @ref LL_ADC_PATH_INTERNAL_VREFINT
  1936. * @arg @ref LL_ADC_PATH_INTERNAL_TEMPSENSOR
  1937. * @arg @ref LL_ADC_PATH_INTERNAL_VBAT
  1938. * @retval None
  1939. */
  1940. __STATIC_INLINE void LL_ADC_SetCommonPathInternalChAdd(ADC_Common_TypeDef *ADCxy_COMMON, uint32_t PathInternal)
  1941. {
  1942. SET_BIT(ADCxy_COMMON->CCR, PathInternal);
  1943. }
  1944. /**
  1945. * @brief Set parameter common to several ADC: measurement path to
  1946. * internal channels (VrefInt, temperature sensor, ...).
  1947. * Remove paths to the current configuration.
  1948. * @note One or several values can be selected.
  1949. * Example: (LL_ADC_PATH_INTERNAL_VREFINT |
  1950. * LL_ADC_PATH_INTERNAL_TEMPSENSOR)
  1951. * @note On this STM32 serie, setting of this feature is conditioned to
  1952. * ADC state:
  1953. * All ADC instances of the ADC common group must be disabled.
  1954. * This check can be done with function @ref LL_ADC_IsEnabled() for each
  1955. * ADC instance or by using helper macro helper macro
  1956. * @ref __LL_ADC_IS_ENABLED_ALL_COMMON_INSTANCE().
  1957. * @rmtoll CCR VREFEN LL_ADC_SetCommonPathInternalChRem\n
  1958. * CCR TSEN LL_ADC_SetCommonPathInternalChRem\n
  1959. * CCR VBATEN LL_ADC_SetCommonPathInternalChRem
  1960. * @param ADCxy_COMMON ADC common instance
  1961. * (can be set directly from CMSIS definition or by using helper macro @ref __LL_ADC_COMMON_INSTANCE() )
  1962. * @param PathInternal This parameter can be a combination of the following values:
  1963. * @arg @ref LL_ADC_PATH_INTERNAL_NONE
  1964. * @arg @ref LL_ADC_PATH_INTERNAL_VREFINT
  1965. * @arg @ref LL_ADC_PATH_INTERNAL_TEMPSENSOR
  1966. * @arg @ref LL_ADC_PATH_INTERNAL_VBAT
  1967. * @retval None
  1968. */
  1969. __STATIC_INLINE void LL_ADC_SetCommonPathInternalChRem(ADC_Common_TypeDef *ADCxy_COMMON, uint32_t PathInternal)
  1970. {
  1971. CLEAR_BIT(ADCxy_COMMON->CCR, PathInternal);
  1972. }
  1973. /**
  1974. * @brief Get parameter common to several ADC: measurement path to internal
  1975. * channels (VrefInt, temperature sensor, ...).
  1976. * @note One or several values can be selected.
  1977. * Example: (LL_ADC_PATH_INTERNAL_VREFINT |
  1978. * LL_ADC_PATH_INTERNAL_TEMPSENSOR)
  1979. * @rmtoll CCR VREFEN LL_ADC_GetCommonPathInternalCh\n
  1980. * CCR TSEN LL_ADC_GetCommonPathInternalCh\n
  1981. * CCR VBATEN LL_ADC_GetCommonPathInternalCh
  1982. * @param ADCxy_COMMON ADC common instance
  1983. * (can be set directly from CMSIS definition or by using helper macro @ref __LL_ADC_COMMON_INSTANCE() )
  1984. * @retval Returned value can be a combination of the following values:
  1985. * @arg @ref LL_ADC_PATH_INTERNAL_NONE
  1986. * @arg @ref LL_ADC_PATH_INTERNAL_VREFINT
  1987. * @arg @ref LL_ADC_PATH_INTERNAL_TEMPSENSOR
  1988. * @arg @ref LL_ADC_PATH_INTERNAL_VBAT
  1989. */
  1990. __STATIC_INLINE uint32_t LL_ADC_GetCommonPathInternalCh(ADC_Common_TypeDef *ADCxy_COMMON)
  1991. {
  1992. return (uint32_t)(READ_BIT(ADCxy_COMMON->CCR, ADC_CCR_VREFEN | ADC_CCR_TSEN | ADC_CCR_VBATEN));
  1993. }
  1994. /**
  1995. * @}
  1996. */
  1997. /** @defgroup ADC_LL_EF_Configuration_ADC_Instance Configuration of ADC hierarchical scope: ADC instance
  1998. * @{
  1999. */
  2000. /**
  2001. * @brief Set ADC calibration factor in the mode single-ended
  2002. * or differential (for devices with differential mode available).
  2003. * @note This function is intended to set calibration parameters
  2004. * without having to perform a new calibration using
  2005. * @ref LL_ADC_StartCalibration().
  2006. * @note For devices with differential mode available:
  2007. * Calibration of offset is specific to each of
  2008. * single-ended and differential modes
  2009. * (calibration factor must be specified for each of these
  2010. * differential modes, if used afterwards and if the application
  2011. * requires their calibration).
  2012. * @note In case of setting calibration factors of both modes single ended
  2013. * and differential (parameter LL_ADC_BOTH_SINGLE_DIFF_ENDED):
  2014. * both calibration factors must be concatenated.
  2015. * To perform this processing, use helper macro
  2016. * @ref __LL_ADC_CALIB_FACTOR_SINGLE_DIFF().
  2017. * @note On this STM32 serie, setting of this feature is conditioned to
  2018. * ADC state:
  2019. * ADC must be enabled, without calibration on going, without conversion
  2020. * on going on group regular.
  2021. * @rmtoll CALFACT CALFACT_S LL_ADC_SetCalibrationFactor\n
  2022. * CALFACT CALFACT_D LL_ADC_SetCalibrationFactor
  2023. * @param ADCx ADC instance
  2024. * @param SingleDiff This parameter can be one of the following values:
  2025. * @arg @ref LL_ADC_SINGLE_ENDED
  2026. * @arg @ref LL_ADC_DIFFERENTIAL_ENDED
  2027. * @arg @ref LL_ADC_BOTH_SINGLE_DIFF_ENDED
  2028. * @param CalibrationFactor Value between Min_Data=0x00 and Max_Data=0x7F
  2029. * @retval None
  2030. */
  2031. __STATIC_INLINE void LL_ADC_SetCalibrationFactor(ADC_TypeDef *ADCx, uint32_t SingleDiff, uint32_t CalibrationFactor)
  2032. {
  2033. MODIFY_REG(ADCx->CALFACT,
  2034. SingleDiff & ADC_SINGLEDIFF_CALIB_FACTOR_MASK,
  2035. CalibrationFactor << (((SingleDiff & ADC_SINGLEDIFF_CALIB_F_BIT_D_MASK) >> ADC_SINGLEDIFF_CALIB_F_BIT_D_SHIFT4) & ~(SingleDiff & ADC_CALFACT_CALFACT_S)));
  2036. }
  2037. /**
  2038. * @brief Get ADC calibration factor in the mode single-ended
  2039. * or differential (for devices with differential mode available).
  2040. * @note Calibration factors are set by hardware after performing
  2041. * a calibration run using function @ref LL_ADC_StartCalibration().
  2042. * @note For devices with differential mode available:
  2043. * Calibration of offset is specific to each of
  2044. * single-ended and differential modes
  2045. * @rmtoll CALFACT CALFACT_S LL_ADC_GetCalibrationFactor\n
  2046. * CALFACT CALFACT_D LL_ADC_GetCalibrationFactor
  2047. * @param ADCx ADC instance
  2048. * @param SingleDiff This parameter can be one of the following values:
  2049. * @arg @ref LL_ADC_SINGLE_ENDED
  2050. * @arg @ref LL_ADC_DIFFERENTIAL_ENDED
  2051. * @retval Value between Min_Data=0x00 and Max_Data=0x7F
  2052. */
  2053. __STATIC_INLINE uint32_t LL_ADC_GetCalibrationFactor(ADC_TypeDef *ADCx, uint32_t SingleDiff)
  2054. {
  2055. /* Retrieve bits with position in register depending on parameter */
  2056. /* "SingleDiff". */
  2057. /* Parameter used with mask "ADC_SINGLEDIFF_CALIB_FACTOR_MASK" because */
  2058. /* containing other bits reserved for other purpose. */
  2059. 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));
  2060. }
  2061. /**
  2062. * @brief Set ADC resolution.
  2063. * Refer to reference manual for alignments formats
  2064. * dependencies to ADC resolutions.
  2065. * @note On this STM32 serie, setting of this feature is conditioned to
  2066. * ADC state:
  2067. * ADC must be disabled or enabled without conversion on going
  2068. * on either groups regular or injected.
  2069. * @rmtoll CFGR RES LL_ADC_SetResolution
  2070. * @param ADCx ADC instance
  2071. * @param Resolution This parameter can be one of the following values:
  2072. * @arg @ref LL_ADC_RESOLUTION_12B
  2073. * @arg @ref LL_ADC_RESOLUTION_10B
  2074. * @arg @ref LL_ADC_RESOLUTION_8B
  2075. * @arg @ref LL_ADC_RESOLUTION_6B
  2076. * @retval None
  2077. */
  2078. __STATIC_INLINE void LL_ADC_SetResolution(ADC_TypeDef *ADCx, uint32_t Resolution)
  2079. {
  2080. MODIFY_REG(ADCx->CFGR, ADC_CFGR_RES, Resolution);
  2081. }
  2082. /**
  2083. * @brief Get ADC resolution.
  2084. * Refer to reference manual for alignments formats
  2085. * dependencies to ADC resolutions.
  2086. * @rmtoll CFGR RES LL_ADC_GetResolution
  2087. * @param ADCx ADC instance
  2088. * @retval Returned value can be one of the following values:
  2089. * @arg @ref LL_ADC_RESOLUTION_12B
  2090. * @arg @ref LL_ADC_RESOLUTION_10B
  2091. * @arg @ref LL_ADC_RESOLUTION_8B
  2092. * @arg @ref LL_ADC_RESOLUTION_6B
  2093. */
  2094. __STATIC_INLINE uint32_t LL_ADC_GetResolution(ADC_TypeDef *ADCx)
  2095. {
  2096. return (uint32_t)(READ_BIT(ADCx->CFGR, ADC_CFGR_RES));
  2097. }
  2098. /**
  2099. * @brief Set ADC conversion data alignment.
  2100. * @note Refer to reference manual for alignments formats
  2101. * dependencies to ADC resolutions.
  2102. * @note On this STM32 serie, setting of this feature is conditioned to
  2103. * ADC state:
  2104. * ADC must be disabled or enabled without conversion on going
  2105. * on either groups regular or injected.
  2106. * @rmtoll CFGR ALIGN LL_ADC_SetDataAlignment
  2107. * @param ADCx ADC instance
  2108. * @param DataAlignment This parameter can be one of the following values:
  2109. * @arg @ref LL_ADC_DATA_ALIGN_RIGHT
  2110. * @arg @ref LL_ADC_DATA_ALIGN_LEFT
  2111. * @retval None
  2112. */
  2113. __STATIC_INLINE void LL_ADC_SetDataAlignment(ADC_TypeDef *ADCx, uint32_t DataAlignment)
  2114. {
  2115. MODIFY_REG(ADCx->CFGR, ADC_CFGR_ALIGN, DataAlignment);
  2116. }
  2117. /**
  2118. * @brief Get ADC conversion data alignment.
  2119. * @note Refer to reference manual for alignments formats
  2120. * dependencies to ADC resolutions.
  2121. * @rmtoll CFGR ALIGN LL_ADC_GetDataAlignment
  2122. * @param ADCx ADC instance
  2123. * @retval Returned value can be one of the following values:
  2124. * @arg @ref LL_ADC_DATA_ALIGN_RIGHT
  2125. * @arg @ref LL_ADC_DATA_ALIGN_LEFT
  2126. */
  2127. __STATIC_INLINE uint32_t LL_ADC_GetDataAlignment(ADC_TypeDef *ADCx)
  2128. {
  2129. return (uint32_t)(READ_BIT(ADCx->CFGR, ADC_CFGR_ALIGN));
  2130. }
  2131. /**
  2132. * @brief Set ADC low power mode.
  2133. * @note Description of ADC low power modes:
  2134. * - ADC low power mode "auto wait": Dynamic low power mode,
  2135. * ADC conversions occurrences are limited to the minimum necessary
  2136. * in order to reduce power consumption.
  2137. * New ADC conversion starts only when the previous
  2138. * unitary conversion data (for ADC group regular)
  2139. * or previous sequence conversions data (for ADC group injected)
  2140. * has been retrieved by user software.
  2141. * In the meantime, ADC remains idle: does not performs any
  2142. * other conversion.
  2143. * This mode allows to automatically adapt the ADC conversions
  2144. * triggers to the speed of the software that reads the data.
  2145. * Moreover, this avoids risk of overrun for low frequency
  2146. * applications.
  2147. * How to use this low power mode:
  2148. * - It is not recommended to use with interruption or DMA
  2149. * since these modes have to clear immediately the EOC flag
  2150. * (by CPU to free the IRQ pending event or by DMA).
  2151. * Auto wait will work but fort a very short time, discarding
  2152. * its intended benefit (except specific case of high load of CPU
  2153. * or DMA transfers which can justify usage of auto wait).
  2154. * - Do use with polling: 1. Start conversion,
  2155. * 2. Later on, when conversion data is needed: poll for end of
  2156. * conversion to ensure that conversion is completed and
  2157. * retrieve ADC conversion data. This will trig another
  2158. * ADC conversion start.
  2159. * - ADC low power mode "auto power-off" (feature available on
  2160. * this device if parameter LL_ADC_LP_AUTOPOWEROFF is available):
  2161. * the ADC automatically powers-off after a conversion and
  2162. * automatically wakes up when a new conversion is triggered
  2163. * (with startup time between trigger and start of sampling).
  2164. * This feature can be combined with low power mode "auto wait".
  2165. * @note With ADC low power mode "auto wait", the ADC conversion data read
  2166. * is corresponding to previous ADC conversion start, independently
  2167. * of delay during which ADC was idle.
  2168. * Therefore, the ADC conversion data may be outdated: does not
  2169. * correspond to the current voltage level on the selected
  2170. * ADC channel.
  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. * @rmtoll CFGR AUTDLY LL_ADC_SetLowPowerMode
  2176. * @param ADCx ADC instance
  2177. * @param LowPowerMode This parameter can be one of the following values:
  2178. * @arg @ref LL_ADC_LP_MODE_NONE
  2179. * @arg @ref LL_ADC_LP_AUTOWAIT
  2180. * @retval None
  2181. */
  2182. __STATIC_INLINE void LL_ADC_SetLowPowerMode(ADC_TypeDef *ADCx, uint32_t LowPowerMode)
  2183. {
  2184. MODIFY_REG(ADCx->CFGR, ADC_CFGR_AUTDLY, LowPowerMode);
  2185. }
  2186. /**
  2187. * @brief Get ADC low power mode:
  2188. * @note Description of ADC low power modes:
  2189. * - ADC low power mode "auto wait": Dynamic low power mode,
  2190. * ADC conversions occurrences are limited to the minimum necessary
  2191. * in order to reduce power consumption.
  2192. * New ADC conversion starts only when the previous
  2193. * unitary conversion data (for ADC group regular)
  2194. * or previous sequence conversions data (for ADC group injected)
  2195. * has been retrieved by user software.
  2196. * In the meantime, ADC remains idle: does not performs any
  2197. * other conversion.
  2198. * This mode allows to automatically adapt the ADC conversions
  2199. * triggers to the speed of the software that reads the data.
  2200. * Moreover, this avoids risk of overrun for low frequency
  2201. * applications.
  2202. * How to use this low power mode:
  2203. * - It is not recommended to use with interruption or DMA
  2204. * since these modes have to clear immediately the EOC flag
  2205. * (by CPU to free the IRQ pending event or by DMA).
  2206. * Auto wait will work but fort a very short time, discarding
  2207. * its intended benefit (except specific case of high load of CPU
  2208. * or DMA transfers which can justify usage of auto wait).
  2209. * - Do use with polling: 1. Start conversion,
  2210. * 2. Later on, when conversion data is needed: poll for end of
  2211. * conversion to ensure that conversion is completed and
  2212. * retrieve ADC conversion data. This will trig another
  2213. * ADC conversion start.
  2214. * - ADC low power mode "auto power-off" (feature available on
  2215. * this device if parameter LL_ADC_LP_AUTOPOWEROFF is available):
  2216. * the ADC automatically powers-off after a conversion and
  2217. * automatically wakes up when a new conversion is triggered
  2218. * (with startup time between trigger and start of sampling).
  2219. * This feature can be combined with low power mode "auto wait".
  2220. * @note With ADC low power mode "auto wait", the ADC conversion data read
  2221. * is corresponding to previous ADC conversion start, independently
  2222. * of delay during which ADC was idle.
  2223. * Therefore, the ADC conversion data may be outdated: does not
  2224. * correspond to the current voltage level on the selected
  2225. * ADC channel.
  2226. * @rmtoll CFGR AUTDLY LL_ADC_GetLowPowerMode
  2227. * @param ADCx ADC instance
  2228. * @retval Returned value can be one of the following values:
  2229. * @arg @ref LL_ADC_LP_MODE_NONE
  2230. * @arg @ref LL_ADC_LP_AUTOWAIT
  2231. */
  2232. __STATIC_INLINE uint32_t LL_ADC_GetLowPowerMode(ADC_TypeDef *ADCx)
  2233. {
  2234. return (uint32_t)(READ_BIT(ADCx->CFGR, ADC_CFGR_AUTDLY));
  2235. }
  2236. /**
  2237. * @brief Set ADC selected offset number 1, 2, 3 or 4.
  2238. * @note This function set the 2 items of offset configuration:
  2239. * - ADC channel to which the offset programmed will be applied
  2240. * (independently of channel mapped on ADC group regular
  2241. * or group injected)
  2242. * - Offset level (offset to be subtracted from the raw
  2243. * converted data).
  2244. * @note Caution: Offset format is dependent to ADC resolution:
  2245. * offset has to be left-aligned on bit 11, the LSB (right bits)
  2246. * are set to 0.
  2247. * @note This function enables the offset, by default. It can be forced
  2248. * to disable state using function LL_ADC_SetOffsetState().
  2249. * @note If a channel is mapped on several offsets numbers, only the offset
  2250. * with the lowest value is considered for the subtraction.
  2251. * @note On this STM32 serie, setting of this feature is conditioned to
  2252. * ADC state:
  2253. * ADC must be disabled or enabled without conversion on going
  2254. * on either groups regular or injected.
  2255. * @note On STM32WB, some fast channels are available: fast analog inputs
  2256. * coming from GPIO pads (ADC_IN1..5).
  2257. * @rmtoll OFR1 OFFSET1_CH LL_ADC_SetOffset\n
  2258. * OFR1 OFFSET1 LL_ADC_SetOffset\n
  2259. * OFR1 OFFSET1_EN LL_ADC_SetOffset\n
  2260. * OFR2 OFFSET2_CH LL_ADC_SetOffset\n
  2261. * OFR2 OFFSET2 LL_ADC_SetOffset\n
  2262. * OFR2 OFFSET2_EN LL_ADC_SetOffset\n
  2263. * OFR3 OFFSET3_CH LL_ADC_SetOffset\n
  2264. * OFR3 OFFSET3 LL_ADC_SetOffset\n
  2265. * OFR3 OFFSET3_EN LL_ADC_SetOffset\n
  2266. * OFR4 OFFSET4_CH LL_ADC_SetOffset\n
  2267. * OFR4 OFFSET4 LL_ADC_SetOffset\n
  2268. * OFR4 OFFSET4_EN LL_ADC_SetOffset
  2269. * @param ADCx ADC instance
  2270. * @param Offsety This parameter can be one of the following values:
  2271. * @arg @ref LL_ADC_OFFSET_1
  2272. * @arg @ref LL_ADC_OFFSET_2
  2273. * @arg @ref LL_ADC_OFFSET_3
  2274. * @arg @ref LL_ADC_OFFSET_4
  2275. * @param Channel This parameter can be one of the following values:
  2276. * @arg @ref LL_ADC_CHANNEL_0
  2277. * @arg @ref LL_ADC_CHANNEL_1 (7)
  2278. * @arg @ref LL_ADC_CHANNEL_2 (7)
  2279. * @arg @ref LL_ADC_CHANNEL_3 (7)
  2280. * @arg @ref LL_ADC_CHANNEL_4 (7)
  2281. * @arg @ref LL_ADC_CHANNEL_5 (7)
  2282. * @arg @ref LL_ADC_CHANNEL_6
  2283. * @arg @ref LL_ADC_CHANNEL_7
  2284. * @arg @ref LL_ADC_CHANNEL_8
  2285. * @arg @ref LL_ADC_CHANNEL_9
  2286. * @arg @ref LL_ADC_CHANNEL_10
  2287. * @arg @ref LL_ADC_CHANNEL_11
  2288. * @arg @ref LL_ADC_CHANNEL_12
  2289. * @arg @ref LL_ADC_CHANNEL_13
  2290. * @arg @ref LL_ADC_CHANNEL_14
  2291. * @arg @ref LL_ADC_CHANNEL_15
  2292. * @arg @ref LL_ADC_CHANNEL_16
  2293. * @arg @ref LL_ADC_CHANNEL_17
  2294. * @arg @ref LL_ADC_CHANNEL_18
  2295. * @arg @ref LL_ADC_CHANNEL_VREFINT
  2296. * @arg @ref LL_ADC_CHANNEL_TEMPSENSOR
  2297. * @arg @ref LL_ADC_CHANNEL_VBAT
  2298. *
  2299. * (7) On STM32WB, fast channel (0.188 us for 12-bit resolution (ADC conversion rate up to 5.33 Ms/s)).
  2300. * Other channels are slow channels (0.238 us for 12-bit resolution (ADC conversion rate up to 4.21 Ms/s)).
  2301. * @param OffsetLevel Value between Min_Data=0x000 and Max_Data=0xFFF
  2302. * @retval None
  2303. */
  2304. __STATIC_INLINE void LL_ADC_SetOffset(ADC_TypeDef *ADCx, uint32_t Offsety, uint32_t Channel, uint32_t OffsetLevel)
  2305. {
  2306. register __IO uint32_t *preg = __ADC_PTR_REG_OFFSET(ADCx->OFR1, Offsety);
  2307. MODIFY_REG(*preg,
  2308. ADC_OFR1_OFFSET1_EN | ADC_OFR1_OFFSET1_CH | ADC_OFR1_OFFSET1,
  2309. ADC_OFR1_OFFSET1_EN | (Channel & ADC_CHANNEL_ID_NUMBER_MASK) | OffsetLevel);
  2310. }
  2311. /**
  2312. * @brief Get for the ADC selected offset number 1, 2, 3 or 4:
  2313. * Channel to which the offset programmed will be applied
  2314. * (independently of channel mapped on ADC group regular
  2315. * or group injected)
  2316. * @note Usage of the returned channel number:
  2317. * - To reinject this channel into another function LL_ADC_xxx:
  2318. * the returned channel number is only partly formatted on definition
  2319. * of literals LL_ADC_CHANNEL_x. Therefore, it has to be compared
  2320. * with parts of literals LL_ADC_CHANNEL_x or using
  2321. * helper macro @ref __LL_ADC_CHANNEL_TO_DECIMAL_NB().
  2322. * Then the selected literal LL_ADC_CHANNEL_x can be used
  2323. * as parameter for another function.
  2324. * - To get the channel number in decimal format:
  2325. * process the returned value with the helper macro
  2326. * @ref __LL_ADC_CHANNEL_TO_DECIMAL_NB().
  2327. * @note On STM32WB, some fast channels are available: fast analog inputs
  2328. * coming from GPIO pads (ADC_IN1..5).
  2329. * @rmtoll OFR1 OFFSET1_CH LL_ADC_GetOffsetChannel\n
  2330. * OFR2 OFFSET2_CH LL_ADC_GetOffsetChannel\n
  2331. * OFR3 OFFSET3_CH LL_ADC_GetOffsetChannel\n
  2332. * OFR4 OFFSET4_CH LL_ADC_GetOffsetChannel
  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. * @retval Returned value can be one of the following values:
  2340. * @arg @ref LL_ADC_CHANNEL_0
  2341. * @arg @ref LL_ADC_CHANNEL_1 (7)
  2342. * @arg @ref LL_ADC_CHANNEL_2 (7)
  2343. * @arg @ref LL_ADC_CHANNEL_3 (7)
  2344. * @arg @ref LL_ADC_CHANNEL_4 (7)
  2345. * @arg @ref LL_ADC_CHANNEL_5 (7)
  2346. * @arg @ref LL_ADC_CHANNEL_6
  2347. * @arg @ref LL_ADC_CHANNEL_7
  2348. * @arg @ref LL_ADC_CHANNEL_8
  2349. * @arg @ref LL_ADC_CHANNEL_9
  2350. * @arg @ref LL_ADC_CHANNEL_10
  2351. * @arg @ref LL_ADC_CHANNEL_11
  2352. * @arg @ref LL_ADC_CHANNEL_12
  2353. * @arg @ref LL_ADC_CHANNEL_13
  2354. * @arg @ref LL_ADC_CHANNEL_14
  2355. * @arg @ref LL_ADC_CHANNEL_15
  2356. * @arg @ref LL_ADC_CHANNEL_16
  2357. * @arg @ref LL_ADC_CHANNEL_17
  2358. * @arg @ref LL_ADC_CHANNEL_18
  2359. * @arg @ref LL_ADC_CHANNEL_VREFINT (4)
  2360. * @arg @ref LL_ADC_CHANNEL_TEMPSENSOR (4)
  2361. * @arg @ref LL_ADC_CHANNEL_VBAT (4)
  2362. *
  2363. * (7) On STM32WB, fast channel (0.188 us for 12-bit resolution (ADC conversion rate up to 5.33 Ms/s)).
  2364. * Other channels are slow channels (0.238 us for 12-bit resolution (ADC conversion rate up to 4.21 Ms/s)).\n
  2365. * (4) For ADC channel read back from ADC register,
  2366. * comparison with internal channel parameter to be done
  2367. * using helper macro @ref __LL_ADC_CHANNEL_INTERNAL_TO_EXTERNAL().
  2368. */
  2369. __STATIC_INLINE uint32_t LL_ADC_GetOffsetChannel(ADC_TypeDef *ADCx, uint32_t Offsety)
  2370. {
  2371. register const __IO uint32_t *preg = __ADC_PTR_REG_OFFSET(ADCx->OFR1, Offsety);
  2372. return (uint32_t) READ_BIT(*preg, ADC_OFR1_OFFSET1_CH);
  2373. }
  2374. /**
  2375. * @brief Get for the ADC selected offset number 1, 2, 3 or 4:
  2376. * Offset level (offset to be subtracted from the raw
  2377. * converted data).
  2378. * @note Caution: Offset format is dependent to ADC resolution:
  2379. * offset has to be left-aligned on bit 11, the LSB (right bits)
  2380. * are set to 0.
  2381. * @rmtoll OFR1 OFFSET1 LL_ADC_GetOffsetLevel\n
  2382. * OFR2 OFFSET2 LL_ADC_GetOffsetLevel\n
  2383. * OFR3 OFFSET3 LL_ADC_GetOffsetLevel\n
  2384. * OFR4 OFFSET4 LL_ADC_GetOffsetLevel
  2385. * @param ADCx ADC instance
  2386. * @param Offsety This parameter can be one of the following values:
  2387. * @arg @ref LL_ADC_OFFSET_1
  2388. * @arg @ref LL_ADC_OFFSET_2
  2389. * @arg @ref LL_ADC_OFFSET_3
  2390. * @arg @ref LL_ADC_OFFSET_4
  2391. * @retval Value between Min_Data=0x000 and Max_Data=0xFFF
  2392. */
  2393. __STATIC_INLINE uint32_t LL_ADC_GetOffsetLevel(ADC_TypeDef *ADCx, uint32_t Offsety)
  2394. {
  2395. register const __IO uint32_t *preg = __ADC_PTR_REG_OFFSET(ADCx->OFR1, Offsety);
  2396. return (uint32_t) READ_BIT(*preg, ADC_OFR1_OFFSET1);
  2397. }
  2398. /**
  2399. * @brief Set for the ADC selected offset number 1, 2, 3 or 4:
  2400. * force offset state disable or enable
  2401. * without modifying offset channel or offset value.
  2402. * @note This function should be needed only in case of offset to be
  2403. * enabled-disabled dynamically, and should not be needed in other cases:
  2404. * function LL_ADC_SetOffset() automatically enables the offset.
  2405. * @note On this STM32 serie, setting of this feature is conditioned to
  2406. * ADC state:
  2407. * ADC must be disabled or enabled without conversion on going
  2408. * on either groups regular or injected.
  2409. * @rmtoll OFR1 OFFSET1_EN LL_ADC_SetOffsetState\n
  2410. * OFR2 OFFSET2_EN LL_ADC_SetOffsetState\n
  2411. * OFR3 OFFSET3_EN LL_ADC_SetOffsetState\n
  2412. * OFR4 OFFSET4_EN LL_ADC_SetOffsetState
  2413. * @param ADCx ADC instance
  2414. * @param Offsety This parameter can be one of the following values:
  2415. * @arg @ref LL_ADC_OFFSET_1
  2416. * @arg @ref LL_ADC_OFFSET_2
  2417. * @arg @ref LL_ADC_OFFSET_3
  2418. * @arg @ref LL_ADC_OFFSET_4
  2419. * @param OffsetState This parameter can be one of the following values:
  2420. * @arg @ref LL_ADC_OFFSET_DISABLE
  2421. * @arg @ref LL_ADC_OFFSET_ENABLE
  2422. * @retval None
  2423. */
  2424. __STATIC_INLINE void LL_ADC_SetOffsetState(ADC_TypeDef *ADCx, uint32_t Offsety, uint32_t OffsetState)
  2425. {
  2426. register __IO uint32_t *preg = __ADC_PTR_REG_OFFSET(ADCx->OFR1, Offsety);
  2427. MODIFY_REG(*preg,
  2428. ADC_OFR1_OFFSET1_EN,
  2429. OffsetState);
  2430. }
  2431. /**
  2432. * @brief Get for the ADC selected offset number 1, 2, 3 or 4:
  2433. * offset state disabled or enabled.
  2434. * @rmtoll OFR1 OFFSET1_EN LL_ADC_GetOffsetState\n
  2435. * OFR2 OFFSET2_EN LL_ADC_GetOffsetState\n
  2436. * OFR3 OFFSET3_EN LL_ADC_GetOffsetState\n
  2437. * OFR4 OFFSET4_EN LL_ADC_GetOffsetState
  2438. * @param ADCx ADC instance
  2439. * @param Offsety This parameter can be one of the following values:
  2440. * @arg @ref LL_ADC_OFFSET_1
  2441. * @arg @ref LL_ADC_OFFSET_2
  2442. * @arg @ref LL_ADC_OFFSET_3
  2443. * @arg @ref LL_ADC_OFFSET_4
  2444. * @retval Returned value can be one of the following values:
  2445. * @arg @ref LL_ADC_OFFSET_DISABLE
  2446. * @arg @ref LL_ADC_OFFSET_ENABLE
  2447. */
  2448. __STATIC_INLINE uint32_t LL_ADC_GetOffsetState(ADC_TypeDef *ADCx, uint32_t Offsety)
  2449. {
  2450. register const __IO uint32_t *preg = __ADC_PTR_REG_OFFSET(ADCx->OFR1, Offsety);
  2451. return (uint32_t) READ_BIT(*preg, ADC_OFR1_OFFSET1_EN);
  2452. }
  2453. /**
  2454. * @}
  2455. */
  2456. /** @defgroup ADC_LL_EF_Configuration_ADC_Group_Regular Configuration of ADC hierarchical scope: group regular
  2457. * @{
  2458. */
  2459. /**
  2460. * @brief Set ADC group regular conversion trigger source:
  2461. * internal (SW start) or from external peripheral (timer event,
  2462. * external interrupt line).
  2463. * @note On this STM32 serie, setting trigger source to external trigger
  2464. * also set trigger polarity to rising edge
  2465. * (default setting for compatibility with some ADC on other
  2466. * STM32 families having this setting set by HW default value).
  2467. * In case of need to modify trigger edge, use
  2468. * function @ref LL_ADC_REG_SetTriggerEdge().
  2469. * @note Availability of parameters of trigger sources from timer
  2470. * depends on timers availability on the selected device.
  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 EXTSEL LL_ADC_REG_SetTriggerSource\n
  2476. * CFGR EXTEN LL_ADC_REG_SetTriggerSource
  2477. * @param ADCx ADC instance
  2478. * @param TriggerSource This parameter can be one of the following values:
  2479. * @arg @ref LL_ADC_REG_TRIG_SOFTWARE
  2480. * @arg @ref LL_ADC_REG_TRIG_EXT_TIM1_TRGO
  2481. * @arg @ref LL_ADC_REG_TRIG_EXT_TIM1_TRGO2
  2482. * @arg @ref LL_ADC_REG_TRIG_EXT_TIM1_CH1
  2483. * @arg @ref LL_ADC_REG_TRIG_EXT_TIM1_CH2
  2484. * @arg @ref LL_ADC_REG_TRIG_EXT_TIM1_CH3
  2485. * @arg @ref LL_ADC_REG_TRIG_EXT_TIM2_TRGO
  2486. * @arg @ref LL_ADC_REG_TRIG_EXT_TIM2_CH2
  2487. * @arg @ref LL_ADC_REG_TRIG_EXT_EXTI_LINE11
  2488. * @retval None
  2489. */
  2490. __STATIC_INLINE void LL_ADC_REG_SetTriggerSource(ADC_TypeDef *ADCx, uint32_t TriggerSource)
  2491. {
  2492. MODIFY_REG(ADCx->CFGR, ADC_CFGR_EXTEN | ADC_CFGR_EXTSEL, TriggerSource);
  2493. }
  2494. /**
  2495. * @brief Get ADC group regular conversion trigger source:
  2496. * internal (SW start) or from external peripheral (timer event,
  2497. * external interrupt line).
  2498. * @note To determine whether group regular trigger source is
  2499. * internal (SW start) or external, without detail
  2500. * of which peripheral is selected as external trigger,
  2501. * (equivalent to
  2502. * "if(LL_ADC_REG_GetTriggerSource(ADC1) == LL_ADC_REG_TRIG_SOFTWARE)")
  2503. * use function @ref LL_ADC_REG_IsTriggerSourceSWStart.
  2504. * @note Availability of parameters of trigger sources from timer
  2505. * depends on timers availability on the selected device.
  2506. * @rmtoll CFGR EXTSEL LL_ADC_REG_GetTriggerSource\n
  2507. * CFGR EXTEN LL_ADC_REG_GetTriggerSource
  2508. * @param ADCx ADC instance
  2509. * @retval Returned value can be one of the following values:
  2510. * @arg @ref LL_ADC_REG_TRIG_SOFTWARE
  2511. * @arg @ref LL_ADC_REG_TRIG_EXT_TIM1_TRGO
  2512. * @arg @ref LL_ADC_REG_TRIG_EXT_TIM1_TRGO2
  2513. * @arg @ref LL_ADC_REG_TRIG_EXT_TIM1_CH1
  2514. * @arg @ref LL_ADC_REG_TRIG_EXT_TIM1_CH2
  2515. * @arg @ref LL_ADC_REG_TRIG_EXT_TIM1_CH3
  2516. * @arg @ref LL_ADC_REG_TRIG_EXT_TIM2_TRGO
  2517. * @arg @ref LL_ADC_REG_TRIG_EXT_TIM2_CH2
  2518. * @arg @ref LL_ADC_REG_TRIG_EXT_EXTI_LINE11
  2519. */
  2520. __STATIC_INLINE uint32_t LL_ADC_REG_GetTriggerSource(ADC_TypeDef *ADCx)
  2521. {
  2522. register __IO uint32_t TriggerSource = READ_BIT(ADCx->CFGR, ADC_CFGR_EXTSEL | ADC_CFGR_EXTEN);
  2523. /* Value for shift of {0; 4; 8; 12} depending on value of bitfield */
  2524. /* corresponding to ADC_CFGR_EXTEN {0; 1; 2; 3}. */
  2525. register uint32_t ShiftExten = ((TriggerSource & ADC_CFGR_EXTEN) >> (ADC_REG_TRIG_EXTEN_BITOFFSET_POS - 2UL));
  2526. /* Set bitfield corresponding to ADC_CFGR_EXTEN and ADC_CFGR_EXTSEL */
  2527. /* to match with triggers literals definition. */
  2528. return ((TriggerSource
  2529. & (ADC_REG_TRIG_SOURCE_MASK >> ShiftExten) & ADC_CFGR_EXTSEL)
  2530. | ((ADC_REG_TRIG_EDGE_MASK >> ShiftExten) & ADC_CFGR_EXTEN)
  2531. );
  2532. }
  2533. /**
  2534. * @brief Get ADC group regular conversion trigger source internal (SW start)
  2535. * or external.
  2536. * @note In case of group regular trigger source set to external trigger,
  2537. * to determine which peripheral is selected as external trigger,
  2538. * use function @ref LL_ADC_REG_GetTriggerSource().
  2539. * @rmtoll CFGR EXTEN LL_ADC_REG_IsTriggerSourceSWStart
  2540. * @param ADCx ADC instance
  2541. * @retval Value "0" if trigger source external trigger
  2542. * Value "1" if trigger source SW start.
  2543. */
  2544. __STATIC_INLINE uint32_t LL_ADC_REG_IsTriggerSourceSWStart(ADC_TypeDef *ADCx)
  2545. {
  2546. return ((READ_BIT(ADCx->CFGR, ADC_CFGR_EXTEN) == (LL_ADC_REG_TRIG_SOFTWARE & ADC_CFGR_EXTEN)) ? 1UL : 0UL);
  2547. }
  2548. /**
  2549. * @brief Set ADC group regular conversion trigger polarity.
  2550. * @note Applicable only for trigger source set to external trigger.
  2551. * @note On this STM32 serie, setting of this feature is conditioned to
  2552. * ADC state:
  2553. * ADC must be disabled or enabled without conversion on going
  2554. * on group regular.
  2555. * @rmtoll CFGR EXTEN LL_ADC_REG_SetTriggerEdge
  2556. * @param ADCx ADC instance
  2557. * @param ExternalTriggerEdge This parameter can be one of the following values:
  2558. * @arg @ref LL_ADC_REG_TRIG_EXT_RISING
  2559. * @arg @ref LL_ADC_REG_TRIG_EXT_FALLING
  2560. * @arg @ref LL_ADC_REG_TRIG_EXT_RISINGFALLING
  2561. * @retval None
  2562. */
  2563. __STATIC_INLINE void LL_ADC_REG_SetTriggerEdge(ADC_TypeDef *ADCx, uint32_t ExternalTriggerEdge)
  2564. {
  2565. MODIFY_REG(ADCx->CFGR, ADC_CFGR_EXTEN, ExternalTriggerEdge);
  2566. }
  2567. /**
  2568. * @brief Get ADC group regular conversion trigger polarity.
  2569. * @note Applicable only for trigger source set to external trigger.
  2570. * @rmtoll CFGR EXTEN LL_ADC_REG_GetTriggerEdge
  2571. * @param ADCx ADC instance
  2572. * @retval Returned value can be one of the following values:
  2573. * @arg @ref LL_ADC_REG_TRIG_EXT_RISING
  2574. * @arg @ref LL_ADC_REG_TRIG_EXT_FALLING
  2575. * @arg @ref LL_ADC_REG_TRIG_EXT_RISINGFALLING
  2576. */
  2577. __STATIC_INLINE uint32_t LL_ADC_REG_GetTriggerEdge(ADC_TypeDef *ADCx)
  2578. {
  2579. return (uint32_t)(READ_BIT(ADCx->CFGR, ADC_CFGR_EXTEN));
  2580. }
  2581. /**
  2582. * @brief Set ADC group regular sequencer length and scan direction.
  2583. * @note Description of ADC group regular sequencer features:
  2584. * - For devices with sequencer fully configurable
  2585. * (function "LL_ADC_REG_SetSequencerRanks()" available):
  2586. * sequencer length and each rank affectation to a channel
  2587. * are configurable.
  2588. * This function performs configuration of:
  2589. * - Sequence length: Number of ranks in the scan sequence.
  2590. * - Sequence direction: Unless specified in parameters, sequencer
  2591. * scan direction is forward (from rank 1 to rank n).
  2592. * Sequencer ranks are selected using
  2593. * function "LL_ADC_REG_SetSequencerRanks()".
  2594. * - For devices with sequencer not fully configurable
  2595. * (function "LL_ADC_REG_SetSequencerChannels()" available):
  2596. * sequencer length and each rank affectation to a channel
  2597. * are defined by channel number.
  2598. * This function performs configuration of:
  2599. * - Sequence length: Number of ranks in the scan sequence is
  2600. * defined by number of channels set in the sequence,
  2601. * rank of each channel is fixed by channel HW number.
  2602. * (channel 0 fixed on rank 0, channel 1 fixed on rank1, ...).
  2603. * - Sequence direction: Unless specified in parameters, sequencer
  2604. * scan direction is forward (from lowest channel number to
  2605. * highest channel number).
  2606. * Sequencer ranks are selected using
  2607. * function "LL_ADC_REG_SetSequencerChannels()".
  2608. * @note Sequencer disabled is equivalent to sequencer of 1 rank:
  2609. * ADC conversion on only 1 channel.
  2610. * @note On this STM32 serie, setting of this feature is conditioned to
  2611. * ADC state:
  2612. * ADC must be disabled or enabled without conversion on going
  2613. * on group regular.
  2614. * @rmtoll SQR1 L LL_ADC_REG_SetSequencerLength
  2615. * @param ADCx ADC instance
  2616. * @param SequencerNbRanks This parameter can be one of the following values:
  2617. * @arg @ref LL_ADC_REG_SEQ_SCAN_DISABLE
  2618. * @arg @ref LL_ADC_REG_SEQ_SCAN_ENABLE_2RANKS
  2619. * @arg @ref LL_ADC_REG_SEQ_SCAN_ENABLE_3RANKS
  2620. * @arg @ref LL_ADC_REG_SEQ_SCAN_ENABLE_4RANKS
  2621. * @arg @ref LL_ADC_REG_SEQ_SCAN_ENABLE_5RANKS
  2622. * @arg @ref LL_ADC_REG_SEQ_SCAN_ENABLE_6RANKS
  2623. * @arg @ref LL_ADC_REG_SEQ_SCAN_ENABLE_7RANKS
  2624. * @arg @ref LL_ADC_REG_SEQ_SCAN_ENABLE_8RANKS
  2625. * @arg @ref LL_ADC_REG_SEQ_SCAN_ENABLE_9RANKS
  2626. * @arg @ref LL_ADC_REG_SEQ_SCAN_ENABLE_10RANKS
  2627. * @arg @ref LL_ADC_REG_SEQ_SCAN_ENABLE_11RANKS
  2628. * @arg @ref LL_ADC_REG_SEQ_SCAN_ENABLE_12RANKS
  2629. * @arg @ref LL_ADC_REG_SEQ_SCAN_ENABLE_13RANKS
  2630. * @arg @ref LL_ADC_REG_SEQ_SCAN_ENABLE_14RANKS
  2631. * @arg @ref LL_ADC_REG_SEQ_SCAN_ENABLE_15RANKS
  2632. * @arg @ref LL_ADC_REG_SEQ_SCAN_ENABLE_16RANKS
  2633. * @retval None
  2634. */
  2635. __STATIC_INLINE void LL_ADC_REG_SetSequencerLength(ADC_TypeDef *ADCx, uint32_t SequencerNbRanks)
  2636. {
  2637. MODIFY_REG(ADCx->SQR1, ADC_SQR1_L, SequencerNbRanks);
  2638. }
  2639. /**
  2640. * @brief Get ADC group regular sequencer length and scan direction.
  2641. * @note Description of ADC group regular sequencer features:
  2642. * - For devices with sequencer fully configurable
  2643. * (function "LL_ADC_REG_SetSequencerRanks()" available):
  2644. * sequencer length and each rank affectation to a channel
  2645. * are configurable.
  2646. * This function retrieves:
  2647. * - Sequence length: Number of ranks in the scan sequence.
  2648. * - Sequence direction: Unless specified in parameters, sequencer
  2649. * scan direction is forward (from rank 1 to rank n).
  2650. * Sequencer ranks are selected using
  2651. * function "LL_ADC_REG_SetSequencerRanks()".
  2652. * - For devices with sequencer not fully configurable
  2653. * (function "LL_ADC_REG_SetSequencerChannels()" available):
  2654. * sequencer length and each rank affectation to a channel
  2655. * are defined by channel number.
  2656. * This function retrieves:
  2657. * - Sequence length: Number of ranks in the scan sequence is
  2658. * defined by number of channels set in the sequence,
  2659. * rank of each channel is fixed by channel HW number.
  2660. * (channel 0 fixed on rank 0, channel 1 fixed on rank1, ...).
  2661. * - Sequence direction: Unless specified in parameters, sequencer
  2662. * scan direction is forward (from lowest channel number to
  2663. * highest channel number).
  2664. * Sequencer ranks are selected using
  2665. * function "LL_ADC_REG_SetSequencerChannels()".
  2666. * @note Sequencer disabled is equivalent to sequencer of 1 rank:
  2667. * ADC conversion on only 1 channel.
  2668. * @rmtoll SQR1 L LL_ADC_REG_GetSequencerLength
  2669. * @param ADCx ADC instance
  2670. * @retval Returned value can be one of the following values:
  2671. * @arg @ref LL_ADC_REG_SEQ_SCAN_DISABLE
  2672. * @arg @ref LL_ADC_REG_SEQ_SCAN_ENABLE_2RANKS
  2673. * @arg @ref LL_ADC_REG_SEQ_SCAN_ENABLE_3RANKS
  2674. * @arg @ref LL_ADC_REG_SEQ_SCAN_ENABLE_4RANKS
  2675. * @arg @ref LL_ADC_REG_SEQ_SCAN_ENABLE_5RANKS
  2676. * @arg @ref LL_ADC_REG_SEQ_SCAN_ENABLE_6RANKS
  2677. * @arg @ref LL_ADC_REG_SEQ_SCAN_ENABLE_7RANKS
  2678. * @arg @ref LL_ADC_REG_SEQ_SCAN_ENABLE_8RANKS
  2679. * @arg @ref LL_ADC_REG_SEQ_SCAN_ENABLE_9RANKS
  2680. * @arg @ref LL_ADC_REG_SEQ_SCAN_ENABLE_10RANKS
  2681. * @arg @ref LL_ADC_REG_SEQ_SCAN_ENABLE_11RANKS
  2682. * @arg @ref LL_ADC_REG_SEQ_SCAN_ENABLE_12RANKS
  2683. * @arg @ref LL_ADC_REG_SEQ_SCAN_ENABLE_13RANKS
  2684. * @arg @ref LL_ADC_REG_SEQ_SCAN_ENABLE_14RANKS
  2685. * @arg @ref LL_ADC_REG_SEQ_SCAN_ENABLE_15RANKS
  2686. * @arg @ref LL_ADC_REG_SEQ_SCAN_ENABLE_16RANKS
  2687. */
  2688. __STATIC_INLINE uint32_t LL_ADC_REG_GetSequencerLength(ADC_TypeDef *ADCx)
  2689. {
  2690. return (uint32_t)(READ_BIT(ADCx->SQR1, ADC_SQR1_L));
  2691. }
  2692. /**
  2693. * @brief Set ADC group regular sequencer discontinuous mode:
  2694. * sequence subdivided and scan conversions interrupted every selected
  2695. * number of ranks.
  2696. * @note It is not possible to enable both ADC group regular
  2697. * continuous mode and sequencer discontinuous mode.
  2698. * @note It is not possible to enable both ADC auto-injected mode
  2699. * and ADC group regular sequencer discontinuous mode.
  2700. * @note On this STM32 serie, setting of this feature is conditioned to
  2701. * ADC state:
  2702. * ADC must be disabled or enabled without conversion on going
  2703. * on group regular.
  2704. * @rmtoll CFGR DISCEN LL_ADC_REG_SetSequencerDiscont\n
  2705. * CFGR DISCNUM LL_ADC_REG_SetSequencerDiscont
  2706. * @param ADCx ADC instance
  2707. * @param SeqDiscont This parameter can be one of the following values:
  2708. * @arg @ref LL_ADC_REG_SEQ_DISCONT_DISABLE
  2709. * @arg @ref LL_ADC_REG_SEQ_DISCONT_1RANK
  2710. * @arg @ref LL_ADC_REG_SEQ_DISCONT_2RANKS
  2711. * @arg @ref LL_ADC_REG_SEQ_DISCONT_3RANKS
  2712. * @arg @ref LL_ADC_REG_SEQ_DISCONT_4RANKS
  2713. * @arg @ref LL_ADC_REG_SEQ_DISCONT_5RANKS
  2714. * @arg @ref LL_ADC_REG_SEQ_DISCONT_6RANKS
  2715. * @arg @ref LL_ADC_REG_SEQ_DISCONT_7RANKS
  2716. * @arg @ref LL_ADC_REG_SEQ_DISCONT_8RANKS
  2717. * @retval None
  2718. */
  2719. __STATIC_INLINE void LL_ADC_REG_SetSequencerDiscont(ADC_TypeDef *ADCx, uint32_t SeqDiscont)
  2720. {
  2721. MODIFY_REG(ADCx->CFGR, ADC_CFGR_DISCEN | ADC_CFGR_DISCNUM, SeqDiscont);
  2722. }
  2723. /**
  2724. * @brief Get ADC group regular sequencer discontinuous mode:
  2725. * sequence subdivided and scan conversions interrupted every selected
  2726. * number of ranks.
  2727. * @rmtoll CFGR DISCEN LL_ADC_REG_GetSequencerDiscont\n
  2728. * CFGR DISCNUM LL_ADC_REG_GetSequencerDiscont
  2729. * @param ADCx ADC instance
  2730. * @retval Returned value can be one of the following values:
  2731. * @arg @ref LL_ADC_REG_SEQ_DISCONT_DISABLE
  2732. * @arg @ref LL_ADC_REG_SEQ_DISCONT_1RANK
  2733. * @arg @ref LL_ADC_REG_SEQ_DISCONT_2RANKS
  2734. * @arg @ref LL_ADC_REG_SEQ_DISCONT_3RANKS
  2735. * @arg @ref LL_ADC_REG_SEQ_DISCONT_4RANKS
  2736. * @arg @ref LL_ADC_REG_SEQ_DISCONT_5RANKS
  2737. * @arg @ref LL_ADC_REG_SEQ_DISCONT_6RANKS
  2738. * @arg @ref LL_ADC_REG_SEQ_DISCONT_7RANKS
  2739. * @arg @ref LL_ADC_REG_SEQ_DISCONT_8RANKS
  2740. */
  2741. __STATIC_INLINE uint32_t LL_ADC_REG_GetSequencerDiscont(ADC_TypeDef *ADCx)
  2742. {
  2743. return (uint32_t)(READ_BIT(ADCx->CFGR, ADC_CFGR_DISCEN | ADC_CFGR_DISCNUM));
  2744. }
  2745. /**
  2746. * @brief Set ADC group regular sequence: channel on the selected
  2747. * scan sequence rank.
  2748. * @note This function performs configuration of:
  2749. * - Channels ordering into each rank of scan sequence:
  2750. * whatever channel can be placed into whatever rank.
  2751. * @note On this STM32 serie, ADC group regular sequencer is
  2752. * fully configurable: sequencer length and each rank
  2753. * affectation to a channel are configurable.
  2754. * Refer to description of function @ref LL_ADC_REG_SetSequencerLength().
  2755. * @note Depending on devices and packages, some channels may not be available.
  2756. * Refer to device datasheet for channels availability.
  2757. * @note On this STM32 serie, to measure internal channels (VrefInt,
  2758. * TempSensor, ...), measurement paths to internal channels must be
  2759. * enabled separately.
  2760. * This can be done using function @ref LL_ADC_SetCommonPathInternalCh().
  2761. * @note On this STM32 serie, setting of this feature is conditioned to
  2762. * ADC state:
  2763. * ADC must be disabled or enabled without conversion on going
  2764. * on group regular.
  2765. * @rmtoll SQR1 SQ1 LL_ADC_REG_SetSequencerRanks\n
  2766. * SQR1 SQ2 LL_ADC_REG_SetSequencerRanks\n
  2767. * SQR1 SQ3 LL_ADC_REG_SetSequencerRanks\n
  2768. * SQR1 SQ4 LL_ADC_REG_SetSequencerRanks\n
  2769. * SQR2 SQ5 LL_ADC_REG_SetSequencerRanks\n
  2770. * SQR2 SQ6 LL_ADC_REG_SetSequencerRanks\n
  2771. * SQR2 SQ7 LL_ADC_REG_SetSequencerRanks\n
  2772. * SQR2 SQ8 LL_ADC_REG_SetSequencerRanks\n
  2773. * SQR2 SQ9 LL_ADC_REG_SetSequencerRanks\n
  2774. * SQR3 SQ10 LL_ADC_REG_SetSequencerRanks\n
  2775. * SQR3 SQ11 LL_ADC_REG_SetSequencerRanks\n
  2776. * SQR3 SQ12 LL_ADC_REG_SetSequencerRanks\n
  2777. * SQR3 SQ13 LL_ADC_REG_SetSequencerRanks\n
  2778. * SQR3 SQ14 LL_ADC_REG_SetSequencerRanks\n
  2779. * SQR4 SQ15 LL_ADC_REG_SetSequencerRanks\n
  2780. * SQR4 SQ16 LL_ADC_REG_SetSequencerRanks
  2781. * @param ADCx ADC instance
  2782. * @param Rank This parameter can be one of the following values:
  2783. * @arg @ref LL_ADC_REG_RANK_1
  2784. * @arg @ref LL_ADC_REG_RANK_2
  2785. * @arg @ref LL_ADC_REG_RANK_3
  2786. * @arg @ref LL_ADC_REG_RANK_4
  2787. * @arg @ref LL_ADC_REG_RANK_5
  2788. * @arg @ref LL_ADC_REG_RANK_6
  2789. * @arg @ref LL_ADC_REG_RANK_7
  2790. * @arg @ref LL_ADC_REG_RANK_8
  2791. * @arg @ref LL_ADC_REG_RANK_9
  2792. * @arg @ref LL_ADC_REG_RANK_10
  2793. * @arg @ref LL_ADC_REG_RANK_11
  2794. * @arg @ref LL_ADC_REG_RANK_12
  2795. * @arg @ref LL_ADC_REG_RANK_13
  2796. * @arg @ref LL_ADC_REG_RANK_14
  2797. * @arg @ref LL_ADC_REG_RANK_15
  2798. * @arg @ref LL_ADC_REG_RANK_16
  2799. * @param Channel This parameter can be one of the following values:
  2800. * @arg @ref LL_ADC_CHANNEL_0
  2801. * @arg @ref LL_ADC_CHANNEL_1 (7)
  2802. * @arg @ref LL_ADC_CHANNEL_2 (7)
  2803. * @arg @ref LL_ADC_CHANNEL_3 (7)
  2804. * @arg @ref LL_ADC_CHANNEL_4 (7)
  2805. * @arg @ref LL_ADC_CHANNEL_5 (7)
  2806. * @arg @ref LL_ADC_CHANNEL_6
  2807. * @arg @ref LL_ADC_CHANNEL_7
  2808. * @arg @ref LL_ADC_CHANNEL_8
  2809. * @arg @ref LL_ADC_CHANNEL_9
  2810. * @arg @ref LL_ADC_CHANNEL_10
  2811. * @arg @ref LL_ADC_CHANNEL_11
  2812. * @arg @ref LL_ADC_CHANNEL_12
  2813. * @arg @ref LL_ADC_CHANNEL_13
  2814. * @arg @ref LL_ADC_CHANNEL_14
  2815. * @arg @ref LL_ADC_CHANNEL_15
  2816. * @arg @ref LL_ADC_CHANNEL_16
  2817. * @arg @ref LL_ADC_CHANNEL_17
  2818. * @arg @ref LL_ADC_CHANNEL_18
  2819. * @arg @ref LL_ADC_CHANNEL_VREFINT
  2820. * @arg @ref LL_ADC_CHANNEL_TEMPSENSOR
  2821. * @arg @ref LL_ADC_CHANNEL_VBAT
  2822. *
  2823. * (7) On STM32WB, fast channel (0.188 us for 12-bit resolution (ADC conversion rate up to 5.33 Ms/s)).
  2824. * Other channels are slow channels (0.238 us for 12-bit resolution (ADC conversion rate up to 4.21 Ms/s)).
  2825. * @retval None
  2826. */
  2827. __STATIC_INLINE void LL_ADC_REG_SetSequencerRanks(ADC_TypeDef *ADCx, uint32_t Rank, uint32_t Channel)
  2828. {
  2829. /* Set bits with content of parameter "Channel" with bits position */
  2830. /* in register and register position depending on parameter "Rank". */
  2831. /* Parameters "Rank" and "Channel" are used with masks because containing */
  2832. /* other bits reserved for other purpose. */
  2833. register __IO uint32_t *preg = __ADC_PTR_REG_OFFSET(ADCx->SQR1, ((Rank & ADC_REG_SQRX_REGOFFSET_MASK) >> ADC_SQRX_REGOFFSET_POS));
  2834. MODIFY_REG(*preg,
  2835. ADC_CHANNEL_ID_NUMBER_MASK_POSBIT0 << (Rank & ADC_REG_RANK_ID_SQRX_MASK),
  2836. ((Channel & ADC_CHANNEL_ID_NUMBER_MASK) >> ADC_CHANNEL_ID_NUMBER_BITOFFSET_POS) << (Rank & ADC_REG_RANK_ID_SQRX_MASK));
  2837. }
  2838. /**
  2839. * @brief Get ADC group regular sequence: channel on the selected
  2840. * scan sequence rank.
  2841. * @note On this STM32 serie, ADC group regular sequencer is
  2842. * fully configurable: sequencer length and each rank
  2843. * affectation to a channel are configurable.
  2844. * Refer to description of function @ref LL_ADC_REG_SetSequencerLength().
  2845. * @note Depending on devices and packages, some channels may not be available.
  2846. * Refer to device datasheet for channels availability.
  2847. * @note Usage of the returned channel number:
  2848. * - To reinject this channel into another function LL_ADC_xxx:
  2849. * the returned channel number is only partly formatted on definition
  2850. * of literals LL_ADC_CHANNEL_x. Therefore, it has to be compared
  2851. * with parts of literals LL_ADC_CHANNEL_x or using
  2852. * helper macro @ref __LL_ADC_CHANNEL_TO_DECIMAL_NB().
  2853. * Then the selected literal LL_ADC_CHANNEL_x can be used
  2854. * as parameter for another function.
  2855. * - To get the channel number in decimal format:
  2856. * process the returned value with the helper macro
  2857. * @ref __LL_ADC_CHANNEL_TO_DECIMAL_NB().
  2858. * @rmtoll SQR1 SQ1 LL_ADC_REG_GetSequencerRanks\n
  2859. * SQR1 SQ2 LL_ADC_REG_GetSequencerRanks\n
  2860. * SQR1 SQ3 LL_ADC_REG_GetSequencerRanks\n
  2861. * SQR1 SQ4 LL_ADC_REG_GetSequencerRanks\n
  2862. * SQR2 SQ5 LL_ADC_REG_GetSequencerRanks\n
  2863. * SQR2 SQ6 LL_ADC_REG_GetSequencerRanks\n
  2864. * SQR2 SQ7 LL_ADC_REG_GetSequencerRanks\n
  2865. * SQR2 SQ8 LL_ADC_REG_GetSequencerRanks\n
  2866. * SQR2 SQ9 LL_ADC_REG_GetSequencerRanks\n
  2867. * SQR3 SQ10 LL_ADC_REG_GetSequencerRanks\n
  2868. * SQR3 SQ11 LL_ADC_REG_GetSequencerRanks\n
  2869. * SQR3 SQ12 LL_ADC_REG_GetSequencerRanks\n
  2870. * SQR3 SQ13 LL_ADC_REG_GetSequencerRanks\n
  2871. * SQR3 SQ14 LL_ADC_REG_GetSequencerRanks\n
  2872. * SQR4 SQ15 LL_ADC_REG_GetSequencerRanks\n
  2873. * SQR4 SQ16 LL_ADC_REG_GetSequencerRanks
  2874. * @param ADCx ADC instance
  2875. * @param Rank This parameter can be one of the following values:
  2876. * @arg @ref LL_ADC_REG_RANK_1
  2877. * @arg @ref LL_ADC_REG_RANK_2
  2878. * @arg @ref LL_ADC_REG_RANK_3
  2879. * @arg @ref LL_ADC_REG_RANK_4
  2880. * @arg @ref LL_ADC_REG_RANK_5
  2881. * @arg @ref LL_ADC_REG_RANK_6
  2882. * @arg @ref LL_ADC_REG_RANK_7
  2883. * @arg @ref LL_ADC_REG_RANK_8
  2884. * @arg @ref LL_ADC_REG_RANK_9
  2885. * @arg @ref LL_ADC_REG_RANK_10
  2886. * @arg @ref LL_ADC_REG_RANK_11
  2887. * @arg @ref LL_ADC_REG_RANK_12
  2888. * @arg @ref LL_ADC_REG_RANK_13
  2889. * @arg @ref LL_ADC_REG_RANK_14
  2890. * @arg @ref LL_ADC_REG_RANK_15
  2891. * @arg @ref LL_ADC_REG_RANK_16
  2892. * @retval Returned value can be one of the following values:
  2893. * @arg @ref LL_ADC_CHANNEL_0
  2894. * @arg @ref LL_ADC_CHANNEL_1 (7)
  2895. * @arg @ref LL_ADC_CHANNEL_2 (7)
  2896. * @arg @ref LL_ADC_CHANNEL_3 (7)
  2897. * @arg @ref LL_ADC_CHANNEL_4 (7)
  2898. * @arg @ref LL_ADC_CHANNEL_5 (7)
  2899. * @arg @ref LL_ADC_CHANNEL_6
  2900. * @arg @ref LL_ADC_CHANNEL_7
  2901. * @arg @ref LL_ADC_CHANNEL_8
  2902. * @arg @ref LL_ADC_CHANNEL_9
  2903. * @arg @ref LL_ADC_CHANNEL_10
  2904. * @arg @ref LL_ADC_CHANNEL_11
  2905. * @arg @ref LL_ADC_CHANNEL_12
  2906. * @arg @ref LL_ADC_CHANNEL_13
  2907. * @arg @ref LL_ADC_CHANNEL_14
  2908. * @arg @ref LL_ADC_CHANNEL_15
  2909. * @arg @ref LL_ADC_CHANNEL_16
  2910. * @arg @ref LL_ADC_CHANNEL_17
  2911. * @arg @ref LL_ADC_CHANNEL_18
  2912. * @arg @ref LL_ADC_CHANNEL_VREFINT (4)
  2913. * @arg @ref LL_ADC_CHANNEL_TEMPSENSOR (4)
  2914. * @arg @ref LL_ADC_CHANNEL_VBAT (4)
  2915. *
  2916. * (7) On STM32WB, fast channel (0.188 us for 12-bit resolution (ADC conversion rate up to 5.33 Ms/s)).
  2917. * Other channels are slow channels (0.238 us for 12-bit resolution (ADC conversion rate up to 4.21 Ms/s)).\n
  2918. * (4) For ADC channel read back from ADC register,
  2919. * comparison with internal channel parameter to be done
  2920. * using helper macro @ref __LL_ADC_CHANNEL_INTERNAL_TO_EXTERNAL().
  2921. */
  2922. __STATIC_INLINE uint32_t LL_ADC_REG_GetSequencerRanks(ADC_TypeDef *ADCx, uint32_t Rank)
  2923. {
  2924. register const __IO uint32_t *preg = __ADC_PTR_REG_OFFSET(ADCx->SQR1, ((Rank & ADC_REG_SQRX_REGOFFSET_MASK) >> ADC_SQRX_REGOFFSET_POS));
  2925. return (uint32_t)((READ_BIT(*preg,
  2926. ADC_CHANNEL_ID_NUMBER_MASK_POSBIT0 << (Rank & ADC_REG_RANK_ID_SQRX_MASK))
  2927. >> (Rank & ADC_REG_RANK_ID_SQRX_MASK)) << ADC_CHANNEL_ID_NUMBER_BITOFFSET_POS
  2928. );
  2929. }
  2930. /**
  2931. * @brief Set ADC continuous conversion mode on ADC group regular.
  2932. * @note Description of ADC continuous conversion mode:
  2933. * - single mode: one conversion per trigger
  2934. * - continuous mode: after the first trigger, following
  2935. * conversions launched successively automatically.
  2936. * @note It is not possible to enable both ADC group regular
  2937. * continuous mode and sequencer discontinuous mode.
  2938. * @note On this STM32 serie, setting of this feature is conditioned to
  2939. * ADC state:
  2940. * ADC must be disabled or enabled without conversion on going
  2941. * on group regular.
  2942. * @rmtoll CFGR CONT LL_ADC_REG_SetContinuousMode
  2943. * @param ADCx ADC instance
  2944. * @param Continuous This parameter can be one of the following values:
  2945. * @arg @ref LL_ADC_REG_CONV_SINGLE
  2946. * @arg @ref LL_ADC_REG_CONV_CONTINUOUS
  2947. * @retval None
  2948. */
  2949. __STATIC_INLINE void LL_ADC_REG_SetContinuousMode(ADC_TypeDef *ADCx, uint32_t Continuous)
  2950. {
  2951. MODIFY_REG(ADCx->CFGR, ADC_CFGR_CONT, Continuous);
  2952. }
  2953. /**
  2954. * @brief Get ADC continuous conversion mode on ADC group regular.
  2955. * @note Description of ADC continuous conversion mode:
  2956. * - single mode: one conversion per trigger
  2957. * - continuous mode: after the first trigger, following
  2958. * conversions launched successively automatically.
  2959. * @rmtoll CFGR CONT LL_ADC_REG_GetContinuousMode
  2960. * @param ADCx ADC instance
  2961. * @retval Returned value can be one of the following values:
  2962. * @arg @ref LL_ADC_REG_CONV_SINGLE
  2963. * @arg @ref LL_ADC_REG_CONV_CONTINUOUS
  2964. */
  2965. __STATIC_INLINE uint32_t LL_ADC_REG_GetContinuousMode(ADC_TypeDef *ADCx)
  2966. {
  2967. return (uint32_t)(READ_BIT(ADCx->CFGR, ADC_CFGR_CONT));
  2968. }
  2969. /**
  2970. * @brief Set ADC group regular conversion data transfer: no transfer or
  2971. * transfer by DMA, and DMA requests mode.
  2972. * @note If transfer by DMA selected, specifies the DMA requests
  2973. * mode:
  2974. * - Limited mode (One shot mode): DMA transfer requests are stopped
  2975. * when number of DMA data transfers (number of
  2976. * ADC conversions) is reached.
  2977. * This ADC mode is intended to be used with DMA mode non-circular.
  2978. * - Unlimited mode: DMA transfer requests are unlimited,
  2979. * whatever number of DMA data transfers (number of
  2980. * ADC conversions).
  2981. * This ADC mode is intended to be used with DMA mode circular.
  2982. * @note If ADC DMA requests mode is set to unlimited and DMA is set to
  2983. * mode non-circular:
  2984. * when DMA transfers size will be reached, DMA will stop transfers of
  2985. * ADC conversions data ADC will raise an overrun error
  2986. * (overrun flag and interruption if enabled).
  2987. * @note To configure DMA source address (peripheral address),
  2988. * use function @ref LL_ADC_DMA_GetRegAddr().
  2989. * @note On this STM32 serie, setting of this feature is conditioned to
  2990. * ADC state:
  2991. * ADC must be disabled or enabled without conversion on going
  2992. * on either groups regular or injected.
  2993. * @rmtoll CFGR DMAEN LL_ADC_REG_SetDMATransfer\n
  2994. * CFGR DMACFG LL_ADC_REG_SetDMATransfer
  2995. * @param ADCx ADC instance
  2996. * @param DMATransfer This parameter can be one of the following values:
  2997. * @arg @ref LL_ADC_REG_DMA_TRANSFER_NONE
  2998. * @arg @ref LL_ADC_REG_DMA_TRANSFER_LIMITED
  2999. * @arg @ref LL_ADC_REG_DMA_TRANSFER_UNLIMITED
  3000. * @retval None
  3001. */
  3002. __STATIC_INLINE void LL_ADC_REG_SetDMATransfer(ADC_TypeDef *ADCx, uint32_t DMATransfer)
  3003. {
  3004. MODIFY_REG(ADCx->CFGR, ADC_CFGR_DMAEN | ADC_CFGR_DMACFG, DMATransfer);
  3005. }
  3006. /**
  3007. * @brief Get ADC group regular conversion data transfer: no transfer or
  3008. * transfer by DMA, and DMA requests mode.
  3009. * @note If transfer by DMA selected, specifies the DMA requests
  3010. * mode:
  3011. * - Limited mode (One shot mode): DMA transfer requests are stopped
  3012. * when number of DMA data transfers (number of
  3013. * ADC conversions) is reached.
  3014. * This ADC mode is intended to be used with DMA mode non-circular.
  3015. * - Unlimited mode: DMA transfer requests are unlimited,
  3016. * whatever number of DMA data transfers (number of
  3017. * ADC conversions).
  3018. * This ADC mode is intended to be used with DMA mode circular.
  3019. * @note If ADC DMA requests mode is set to unlimited and DMA is set to
  3020. * mode non-circular:
  3021. * when DMA transfers size will be reached, DMA will stop transfers of
  3022. * ADC conversions data ADC will raise an overrun error
  3023. * (overrun flag and interruption if enabled).
  3024. * @note To configure DMA source address (peripheral address),
  3025. * use function @ref LL_ADC_DMA_GetRegAddr().
  3026. * @rmtoll CFGR DMAEN LL_ADC_REG_GetDMATransfer\n
  3027. * CFGR DMACFG LL_ADC_REG_GetDMATransfer
  3028. * @param ADCx ADC instance
  3029. * @retval Returned value can be one of the following values:
  3030. * @arg @ref LL_ADC_REG_DMA_TRANSFER_NONE
  3031. * @arg @ref LL_ADC_REG_DMA_TRANSFER_LIMITED
  3032. * @arg @ref LL_ADC_REG_DMA_TRANSFER_UNLIMITED
  3033. */
  3034. __STATIC_INLINE uint32_t LL_ADC_REG_GetDMATransfer(ADC_TypeDef *ADCx)
  3035. {
  3036. return (uint32_t)(READ_BIT(ADCx->CFGR, ADC_CFGR_DMAEN | ADC_CFGR_DMACFG));
  3037. }
  3038. /**
  3039. * @brief Set ADC group regular behavior in case of overrun:
  3040. * data preserved or overwritten.
  3041. * @note Compatibility with devices without feature overrun:
  3042. * other devices without this feature have a behavior
  3043. * equivalent to data overwritten.
  3044. * The default setting of overrun is data preserved.
  3045. * Therefore, for compatibility with all devices, parameter
  3046. * overrun should be set to data overwritten.
  3047. * @note On this STM32 serie, setting of this feature is conditioned to
  3048. * ADC state:
  3049. * ADC must be disabled or enabled without conversion on going
  3050. * on group regular.
  3051. * @rmtoll CFGR OVRMOD LL_ADC_REG_SetOverrun
  3052. * @param ADCx ADC instance
  3053. * @param Overrun This parameter can be one of the following values:
  3054. * @arg @ref LL_ADC_REG_OVR_DATA_PRESERVED
  3055. * @arg @ref LL_ADC_REG_OVR_DATA_OVERWRITTEN
  3056. * @retval None
  3057. */
  3058. __STATIC_INLINE void LL_ADC_REG_SetOverrun(ADC_TypeDef *ADCx, uint32_t Overrun)
  3059. {
  3060. MODIFY_REG(ADCx->CFGR, ADC_CFGR_OVRMOD, Overrun);
  3061. }
  3062. /**
  3063. * @brief Get ADC group regular behavior in case of overrun:
  3064. * data preserved or overwritten.
  3065. * @rmtoll CFGR OVRMOD LL_ADC_REG_GetOverrun
  3066. * @param ADCx ADC instance
  3067. * @retval Returned value can be one of the following values:
  3068. * @arg @ref LL_ADC_REG_OVR_DATA_PRESERVED
  3069. * @arg @ref LL_ADC_REG_OVR_DATA_OVERWRITTEN
  3070. */
  3071. __STATIC_INLINE uint32_t LL_ADC_REG_GetOverrun(ADC_TypeDef *ADCx)
  3072. {
  3073. return (uint32_t)(READ_BIT(ADCx->CFGR, ADC_CFGR_OVRMOD));
  3074. }
  3075. /**
  3076. * @}
  3077. */
  3078. /** @defgroup ADC_LL_EF_Configuration_ADC_Group_Injected Configuration of ADC hierarchical scope: group injected
  3079. * @{
  3080. */
  3081. /**
  3082. * @brief Set ADC group injected conversion trigger source:
  3083. * internal (SW start) or from external peripheral (timer event,
  3084. * external interrupt line).
  3085. * @note On this STM32 serie, setting trigger source to external trigger
  3086. * also set trigger polarity to rising edge
  3087. * (default setting for compatibility with some ADC on other
  3088. * STM32 families having this setting set by HW default value).
  3089. * In case of need to modify trigger edge, use
  3090. * function @ref LL_ADC_INJ_SetTriggerEdge().
  3091. * @note Availability of parameters of trigger sources from timer
  3092. * depends on timers availability on the selected device.
  3093. * @note On this STM32 serie, setting of this feature is conditioned to
  3094. * ADC state:
  3095. * ADC must not be disabled. Can be enabled with or without conversion
  3096. * on going on either groups regular or injected.
  3097. * @rmtoll JSQR JEXTSEL LL_ADC_INJ_SetTriggerSource\n
  3098. * JSQR JEXTEN LL_ADC_INJ_SetTriggerSource
  3099. * @param ADCx ADC instance
  3100. * @param TriggerSource This parameter can be one of the following values:
  3101. * @arg @ref LL_ADC_INJ_TRIG_SOFTWARE
  3102. * @arg @ref LL_ADC_INJ_TRIG_EXT_TIM1_TRGO
  3103. * @arg @ref LL_ADC_INJ_TRIG_EXT_TIM1_TRGO2
  3104. * @arg @ref LL_ADC_INJ_TRIG_EXT_TIM1_CH4
  3105. * @arg @ref LL_ADC_INJ_TRIG_EXT_TIM2_TRGO
  3106. * @arg @ref LL_ADC_INJ_TRIG_EXT_TIM2_CH1
  3107. * @arg @ref LL_ADC_INJ_TRIG_EXT_EXTI_LINE15
  3108. * @retval None
  3109. */
  3110. __STATIC_INLINE void LL_ADC_INJ_SetTriggerSource(ADC_TypeDef *ADCx, uint32_t TriggerSource)
  3111. {
  3112. MODIFY_REG(ADCx->JSQR, ADC_JSQR_JEXTSEL | ADC_JSQR_JEXTEN, TriggerSource);
  3113. }
  3114. /**
  3115. * @brief Get ADC group injected conversion trigger source:
  3116. * internal (SW start) or from external peripheral (timer event,
  3117. * external interrupt line).
  3118. * @note To determine whether group injected trigger source is
  3119. * internal (SW start) or external, without detail
  3120. * of which peripheral is selected as external trigger,
  3121. * (equivalent to
  3122. * "if(LL_ADC_INJ_GetTriggerSource(ADC1) == LL_ADC_INJ_TRIG_SOFTWARE)")
  3123. * use function @ref LL_ADC_INJ_IsTriggerSourceSWStart.
  3124. * @note Availability of parameters of trigger sources from timer
  3125. * depends on timers availability on the selected device.
  3126. * @rmtoll JSQR JEXTSEL LL_ADC_INJ_GetTriggerSource\n
  3127. * JSQR JEXTEN LL_ADC_INJ_GetTriggerSource
  3128. * @param ADCx ADC instance
  3129. * @retval Returned value can be one of the following values:
  3130. * @arg @ref LL_ADC_INJ_TRIG_SOFTWARE
  3131. * @arg @ref LL_ADC_INJ_TRIG_EXT_TIM1_TRGO
  3132. * @arg @ref LL_ADC_INJ_TRIG_EXT_TIM1_TRGO2
  3133. * @arg @ref LL_ADC_INJ_TRIG_EXT_TIM1_CH4
  3134. * @arg @ref LL_ADC_INJ_TRIG_EXT_TIM2_TRGO
  3135. * @arg @ref LL_ADC_INJ_TRIG_EXT_TIM2_CH1
  3136. * @arg @ref LL_ADC_INJ_TRIG_EXT_EXTI_LINE15
  3137. */
  3138. __STATIC_INLINE uint32_t LL_ADC_INJ_GetTriggerSource(ADC_TypeDef *ADCx)
  3139. {
  3140. register __IO uint32_t TriggerSource = READ_BIT(ADCx->JSQR, ADC_JSQR_JEXTSEL | ADC_JSQR_JEXTEN);
  3141. /* Value for shift of {0; 4; 8; 12} depending on value of bitfield */
  3142. /* corresponding to ADC_JSQR_JEXTEN {0; 1; 2; 3}. */
  3143. register uint32_t ShiftJexten = ((TriggerSource & ADC_JSQR_JEXTEN) >> (ADC_INJ_TRIG_EXTEN_BITOFFSET_POS - 2UL));
  3144. /* Set bitfield corresponding to ADC_JSQR_JEXTEN and ADC_JSQR_JEXTSEL */
  3145. /* to match with triggers literals definition. */
  3146. return ((TriggerSource
  3147. & (ADC_INJ_TRIG_SOURCE_MASK >> ShiftJexten) & ADC_JSQR_JEXTSEL)
  3148. | ((ADC_INJ_TRIG_EDGE_MASK >> ShiftJexten) & ADC_JSQR_JEXTEN)
  3149. );
  3150. }
  3151. /**
  3152. * @brief Get ADC group injected conversion trigger source internal (SW start)
  3153. or external
  3154. * @note In case of group injected trigger source set to external trigger,
  3155. * to determine which peripheral is selected as external trigger,
  3156. * use function @ref LL_ADC_INJ_GetTriggerSource.
  3157. * @rmtoll JSQR JEXTEN LL_ADC_INJ_IsTriggerSourceSWStart
  3158. * @param ADCx ADC instance
  3159. * @retval Value "0" if trigger source external trigger
  3160. * Value "1" if trigger source SW start.
  3161. */
  3162. __STATIC_INLINE uint32_t LL_ADC_INJ_IsTriggerSourceSWStart(ADC_TypeDef *ADCx)
  3163. {
  3164. return ((READ_BIT(ADCx->JSQR, ADC_JSQR_JEXTEN) == (LL_ADC_INJ_TRIG_SOFTWARE & ADC_JSQR_JEXTEN)) ? 1UL : 0UL);
  3165. }
  3166. /**
  3167. * @brief Set ADC group injected conversion trigger polarity.
  3168. * Applicable only for trigger source set to external trigger.
  3169. * @note On this STM32 serie, setting of this feature is conditioned to
  3170. * ADC state:
  3171. * ADC must not be disabled. Can be enabled with or without conversion
  3172. * on going on either groups regular or injected.
  3173. * @rmtoll JSQR JEXTEN LL_ADC_INJ_SetTriggerEdge
  3174. * @param ADCx ADC instance
  3175. * @param ExternalTriggerEdge This parameter can be one of the following values:
  3176. * @arg @ref LL_ADC_INJ_TRIG_EXT_RISING
  3177. * @arg @ref LL_ADC_INJ_TRIG_EXT_FALLING
  3178. * @arg @ref LL_ADC_INJ_TRIG_EXT_RISINGFALLING
  3179. * @retval None
  3180. */
  3181. __STATIC_INLINE void LL_ADC_INJ_SetTriggerEdge(ADC_TypeDef *ADCx, uint32_t ExternalTriggerEdge)
  3182. {
  3183. MODIFY_REG(ADCx->JSQR, ADC_JSQR_JEXTEN, ExternalTriggerEdge);
  3184. }
  3185. /**
  3186. * @brief Get ADC group injected conversion trigger polarity.
  3187. * Applicable only for trigger source set to external trigger.
  3188. * @rmtoll JSQR JEXTEN LL_ADC_INJ_GetTriggerEdge
  3189. * @param ADCx ADC instance
  3190. * @retval Returned value can be one of the following values:
  3191. * @arg @ref LL_ADC_INJ_TRIG_EXT_RISING
  3192. * @arg @ref LL_ADC_INJ_TRIG_EXT_FALLING
  3193. * @arg @ref LL_ADC_INJ_TRIG_EXT_RISINGFALLING
  3194. */
  3195. __STATIC_INLINE uint32_t LL_ADC_INJ_GetTriggerEdge(ADC_TypeDef *ADCx)
  3196. {
  3197. return (uint32_t)(READ_BIT(ADCx->JSQR, ADC_JSQR_JEXTEN));
  3198. }
  3199. /**
  3200. * @brief Set ADC group injected sequencer length and scan direction.
  3201. * @note This function performs configuration of:
  3202. * - Sequence length: Number of ranks in the scan sequence.
  3203. * - Sequence direction: Unless specified in parameters, sequencer
  3204. * scan direction is forward (from rank 1 to rank n).
  3205. * @note Sequencer disabled is equivalent to sequencer of 1 rank:
  3206. * ADC conversion on only 1 channel.
  3207. * @note On this STM32 serie, setting of this feature is conditioned to
  3208. * ADC state:
  3209. * ADC must not be disabled. Can be enabled with or without conversion
  3210. * on going on either groups regular or injected.
  3211. * @rmtoll JSQR JL LL_ADC_INJ_SetSequencerLength
  3212. * @param ADCx ADC instance
  3213. * @param SequencerNbRanks This parameter can be one of the following values:
  3214. * @arg @ref LL_ADC_INJ_SEQ_SCAN_DISABLE
  3215. * @arg @ref LL_ADC_INJ_SEQ_SCAN_ENABLE_2RANKS
  3216. * @arg @ref LL_ADC_INJ_SEQ_SCAN_ENABLE_3RANKS
  3217. * @arg @ref LL_ADC_INJ_SEQ_SCAN_ENABLE_4RANKS
  3218. * @retval None
  3219. */
  3220. __STATIC_INLINE void LL_ADC_INJ_SetSequencerLength(ADC_TypeDef *ADCx, uint32_t SequencerNbRanks)
  3221. {
  3222. MODIFY_REG(ADCx->JSQR, ADC_JSQR_JL, SequencerNbRanks);
  3223. }
  3224. /**
  3225. * @brief Get ADC group injected sequencer length and scan direction.
  3226. * @note This function retrieves:
  3227. * - Sequence length: Number of ranks in the scan sequence.
  3228. * - Sequence direction: Unless specified in parameters, sequencer
  3229. * scan direction is forward (from rank 1 to rank n).
  3230. * @note Sequencer disabled is equivalent to sequencer of 1 rank:
  3231. * ADC conversion on only 1 channel.
  3232. * @rmtoll JSQR JL LL_ADC_INJ_GetSequencerLength
  3233. * @param ADCx ADC instance
  3234. * @retval Returned value can be one of the following values:
  3235. * @arg @ref LL_ADC_INJ_SEQ_SCAN_DISABLE
  3236. * @arg @ref LL_ADC_INJ_SEQ_SCAN_ENABLE_2RANKS
  3237. * @arg @ref LL_ADC_INJ_SEQ_SCAN_ENABLE_3RANKS
  3238. * @arg @ref LL_ADC_INJ_SEQ_SCAN_ENABLE_4RANKS
  3239. */
  3240. __STATIC_INLINE uint32_t LL_ADC_INJ_GetSequencerLength(ADC_TypeDef *ADCx)
  3241. {
  3242. return (uint32_t)(READ_BIT(ADCx->JSQR, ADC_JSQR_JL));
  3243. }
  3244. /**
  3245. * @brief Set ADC group injected sequencer discontinuous mode:
  3246. * sequence subdivided and scan conversions interrupted every selected
  3247. * number of ranks.
  3248. * @note It is not possible to enable both ADC group injected
  3249. * auto-injected mode and sequencer discontinuous mode.
  3250. * @rmtoll CFGR JDISCEN LL_ADC_INJ_SetSequencerDiscont
  3251. * @param ADCx ADC instance
  3252. * @param SeqDiscont This parameter can be one of the following values:
  3253. * @arg @ref LL_ADC_INJ_SEQ_DISCONT_DISABLE
  3254. * @arg @ref LL_ADC_INJ_SEQ_DISCONT_1RANK
  3255. * @retval None
  3256. */
  3257. __STATIC_INLINE void LL_ADC_INJ_SetSequencerDiscont(ADC_TypeDef *ADCx, uint32_t SeqDiscont)
  3258. {
  3259. MODIFY_REG(ADCx->CFGR, ADC_CFGR_JDISCEN, SeqDiscont);
  3260. }
  3261. /**
  3262. * @brief Get ADC group injected sequencer discontinuous mode:
  3263. * sequence subdivided and scan conversions interrupted every selected
  3264. * number of ranks.
  3265. * @rmtoll CFGR JDISCEN LL_ADC_INJ_GetSequencerDiscont
  3266. * @param ADCx ADC instance
  3267. * @retval Returned value can be one of the following values:
  3268. * @arg @ref LL_ADC_INJ_SEQ_DISCONT_DISABLE
  3269. * @arg @ref LL_ADC_INJ_SEQ_DISCONT_1RANK
  3270. */
  3271. __STATIC_INLINE uint32_t LL_ADC_INJ_GetSequencerDiscont(ADC_TypeDef *ADCx)
  3272. {
  3273. return (uint32_t)(READ_BIT(ADCx->CFGR, ADC_CFGR_JDISCEN));
  3274. }
  3275. /**
  3276. * @brief Set ADC group injected sequence: channel on the selected
  3277. * sequence rank.
  3278. * @note Depending on devices and packages, some channels may not be available.
  3279. * Refer to device datasheet for channels availability.
  3280. * @note On this STM32 serie, to measure internal channels (VrefInt,
  3281. * TempSensor, ...), measurement paths to internal channels must be
  3282. * enabled separately.
  3283. * This can be done using function @ref LL_ADC_SetCommonPathInternalCh().
  3284. * @note On STM32WB, some fast channels are available: fast analog inputs
  3285. * coming from GPIO pads (ADC_IN1..5).
  3286. * @note On this STM32 serie, setting of this feature is conditioned to
  3287. * ADC state:
  3288. * ADC must not be disabled. Can be enabled with or without conversion
  3289. * on going on either groups regular or injected.
  3290. * @rmtoll JSQR JSQ1 LL_ADC_INJ_SetSequencerRanks\n
  3291. * JSQR JSQ2 LL_ADC_INJ_SetSequencerRanks\n
  3292. * JSQR JSQ3 LL_ADC_INJ_SetSequencerRanks\n
  3293. * JSQR JSQ4 LL_ADC_INJ_SetSequencerRanks
  3294. * @param ADCx ADC instance
  3295. * @param Rank This parameter can be one of the following values:
  3296. * @arg @ref LL_ADC_INJ_RANK_1
  3297. * @arg @ref LL_ADC_INJ_RANK_2
  3298. * @arg @ref LL_ADC_INJ_RANK_3
  3299. * @arg @ref LL_ADC_INJ_RANK_4
  3300. * @param Channel This parameter can be one of the following values:
  3301. * @arg @ref LL_ADC_CHANNEL_0
  3302. * @arg @ref LL_ADC_CHANNEL_1 (7)
  3303. * @arg @ref LL_ADC_CHANNEL_2 (7)
  3304. * @arg @ref LL_ADC_CHANNEL_3 (7)
  3305. * @arg @ref LL_ADC_CHANNEL_4 (7)
  3306. * @arg @ref LL_ADC_CHANNEL_5 (7)
  3307. * @arg @ref LL_ADC_CHANNEL_6
  3308. * @arg @ref LL_ADC_CHANNEL_7
  3309. * @arg @ref LL_ADC_CHANNEL_8
  3310. * @arg @ref LL_ADC_CHANNEL_9
  3311. * @arg @ref LL_ADC_CHANNEL_10
  3312. * @arg @ref LL_ADC_CHANNEL_11
  3313. * @arg @ref LL_ADC_CHANNEL_12
  3314. * @arg @ref LL_ADC_CHANNEL_13
  3315. * @arg @ref LL_ADC_CHANNEL_14
  3316. * @arg @ref LL_ADC_CHANNEL_15
  3317. * @arg @ref LL_ADC_CHANNEL_16
  3318. * @arg @ref LL_ADC_CHANNEL_17
  3319. * @arg @ref LL_ADC_CHANNEL_18
  3320. * @arg @ref LL_ADC_CHANNEL_VREFINT
  3321. * @arg @ref LL_ADC_CHANNEL_TEMPSENSOR
  3322. * @arg @ref LL_ADC_CHANNEL_VBAT
  3323. *
  3324. * (7) On STM32WB, fast channel (0.188 us for 12-bit resolution (ADC conversion rate up to 5.33 Ms/s)).
  3325. * Other channels are slow channels (0.238 us for 12-bit resolution (ADC conversion rate up to 4.21 Ms/s)).
  3326. * @retval None
  3327. */
  3328. __STATIC_INLINE void LL_ADC_INJ_SetSequencerRanks(ADC_TypeDef *ADCx, uint32_t Rank, uint32_t Channel)
  3329. {
  3330. /* Set bits with content of parameter "Channel" with bits position */
  3331. /* in register depending on parameter "Rank". */
  3332. /* Parameters "Rank" and "Channel" are used with masks because containing */
  3333. /* other bits reserved for other purpose. */
  3334. MODIFY_REG(ADCx->JSQR,
  3335. (ADC_CHANNEL_ID_NUMBER_MASK >> ADC_CHANNEL_ID_NUMBER_BITOFFSET_POS) << (Rank & ADC_INJ_RANK_ID_JSQR_MASK),
  3336. ((Channel & ADC_CHANNEL_ID_NUMBER_MASK) >> ADC_CHANNEL_ID_NUMBER_BITOFFSET_POS) << (Rank & ADC_INJ_RANK_ID_JSQR_MASK));
  3337. }
  3338. /**
  3339. * @brief Get ADC group injected sequence: channel on the selected
  3340. * sequence rank.
  3341. * @note Depending on devices and packages, some channels may not be available.
  3342. * Refer to device datasheet for channels availability.
  3343. * @note Usage of the returned channel number:
  3344. * - To reinject this channel into another function LL_ADC_xxx:
  3345. * the returned channel number is only partly formatted on definition
  3346. * of literals LL_ADC_CHANNEL_x. Therefore, it has to be compared
  3347. * with parts of literals LL_ADC_CHANNEL_x or using
  3348. * helper macro @ref __LL_ADC_CHANNEL_TO_DECIMAL_NB().
  3349. * Then the selected literal LL_ADC_CHANNEL_x can be used
  3350. * as parameter for another function.
  3351. * - To get the channel number in decimal format:
  3352. * process the returned value with the helper macro
  3353. * @ref __LL_ADC_CHANNEL_TO_DECIMAL_NB().
  3354. * @rmtoll JSQR JSQ1 LL_ADC_INJ_GetSequencerRanks\n
  3355. * JSQR JSQ2 LL_ADC_INJ_GetSequencerRanks\n
  3356. * JSQR JSQ3 LL_ADC_INJ_GetSequencerRanks\n
  3357. * JSQR JSQ4 LL_ADC_INJ_GetSequencerRanks
  3358. * @param ADCx ADC instance
  3359. * @param Rank This parameter can be one of the following values:
  3360. * @arg @ref LL_ADC_INJ_RANK_1
  3361. * @arg @ref LL_ADC_INJ_RANK_2
  3362. * @arg @ref LL_ADC_INJ_RANK_3
  3363. * @arg @ref LL_ADC_INJ_RANK_4
  3364. * @retval Returned value can be one of the following values:
  3365. * @arg @ref LL_ADC_CHANNEL_0
  3366. * @arg @ref LL_ADC_CHANNEL_1 (7)
  3367. * @arg @ref LL_ADC_CHANNEL_2 (7)
  3368. * @arg @ref LL_ADC_CHANNEL_3 (7)
  3369. * @arg @ref LL_ADC_CHANNEL_4 (7)
  3370. * @arg @ref LL_ADC_CHANNEL_5 (7)
  3371. * @arg @ref LL_ADC_CHANNEL_6
  3372. * @arg @ref LL_ADC_CHANNEL_7
  3373. * @arg @ref LL_ADC_CHANNEL_8
  3374. * @arg @ref LL_ADC_CHANNEL_9
  3375. * @arg @ref LL_ADC_CHANNEL_10
  3376. * @arg @ref LL_ADC_CHANNEL_11
  3377. * @arg @ref LL_ADC_CHANNEL_12
  3378. * @arg @ref LL_ADC_CHANNEL_13
  3379. * @arg @ref LL_ADC_CHANNEL_14
  3380. * @arg @ref LL_ADC_CHANNEL_15
  3381. * @arg @ref LL_ADC_CHANNEL_16
  3382. * @arg @ref LL_ADC_CHANNEL_17
  3383. * @arg @ref LL_ADC_CHANNEL_18
  3384. * @arg @ref LL_ADC_CHANNEL_VREFINT (4)
  3385. * @arg @ref LL_ADC_CHANNEL_TEMPSENSOR (4)
  3386. * @arg @ref LL_ADC_CHANNEL_VBAT (4)
  3387. *
  3388. * (7) On STM32WB, fast channel (0.188 us for 12-bit resolution (ADC conversion rate up to 5.33 Ms/s)).
  3389. * Other channels are slow channels (0.238 us for 12-bit resolution (ADC conversion rate up to 4.21 Ms/s)).\n
  3390. * (4) For ADC channel read back from ADC register,
  3391. * comparison with internal channel parameter to be done
  3392. * using helper macro @ref __LL_ADC_CHANNEL_INTERNAL_TO_EXTERNAL().
  3393. */
  3394. __STATIC_INLINE uint32_t LL_ADC_INJ_GetSequencerRanks(ADC_TypeDef *ADCx, uint32_t Rank)
  3395. {
  3396. return (uint32_t)((READ_BIT(ADCx->JSQR,
  3397. (ADC_CHANNEL_ID_NUMBER_MASK >> ADC_CHANNEL_ID_NUMBER_BITOFFSET_POS) << (Rank & ADC_INJ_RANK_ID_JSQR_MASK))
  3398. >> (Rank & ADC_INJ_RANK_ID_JSQR_MASK)) << ADC_CHANNEL_ID_NUMBER_BITOFFSET_POS
  3399. );
  3400. }
  3401. /**
  3402. * @brief Set ADC group injected conversion trigger:
  3403. * independent or from ADC group regular.
  3404. * @note This mode can be used to extend number of data registers
  3405. * updated after one ADC conversion trigger and with data
  3406. * permanently kept (not erased by successive conversions of scan of
  3407. * ADC sequencer ranks), up to 5 data registers:
  3408. * 1 data register on ADC group regular, 4 data registers
  3409. * on ADC group injected.
  3410. * @note If ADC group injected injected trigger source is set to an
  3411. * external trigger, this feature must be must be set to
  3412. * independent trigger.
  3413. * ADC group injected automatic trigger is compliant only with
  3414. * group injected trigger source set to SW start, without any
  3415. * further action on ADC group injected conversion start or stop:
  3416. * in this case, ADC group injected is controlled only
  3417. * from ADC group regular.
  3418. * @note It is not possible to enable both ADC group injected
  3419. * auto-injected mode and sequencer discontinuous mode.
  3420. * @note On this STM32 serie, setting of this feature is conditioned to
  3421. * ADC state:
  3422. * ADC must be disabled or enabled without conversion on going
  3423. * on either groups regular or injected.
  3424. * @rmtoll CFGR JAUTO LL_ADC_INJ_SetTrigAuto
  3425. * @param ADCx ADC instance
  3426. * @param TrigAuto This parameter can be one of the following values:
  3427. * @arg @ref LL_ADC_INJ_TRIG_INDEPENDENT
  3428. * @arg @ref LL_ADC_INJ_TRIG_FROM_GRP_REGULAR
  3429. * @retval None
  3430. */
  3431. __STATIC_INLINE void LL_ADC_INJ_SetTrigAuto(ADC_TypeDef *ADCx, uint32_t TrigAuto)
  3432. {
  3433. MODIFY_REG(ADCx->CFGR, ADC_CFGR_JAUTO, TrigAuto);
  3434. }
  3435. /**
  3436. * @brief Get ADC group injected conversion trigger:
  3437. * independent or from ADC group regular.
  3438. * @rmtoll CFGR JAUTO LL_ADC_INJ_GetTrigAuto
  3439. * @param ADCx ADC instance
  3440. * @retval Returned value can be one of the following values:
  3441. * @arg @ref LL_ADC_INJ_TRIG_INDEPENDENT
  3442. * @arg @ref LL_ADC_INJ_TRIG_FROM_GRP_REGULAR
  3443. */
  3444. __STATIC_INLINE uint32_t LL_ADC_INJ_GetTrigAuto(ADC_TypeDef *ADCx)
  3445. {
  3446. return (uint32_t)(READ_BIT(ADCx->CFGR, ADC_CFGR_JAUTO));
  3447. }
  3448. /**
  3449. * @brief Set ADC group injected contexts queue mode.
  3450. * @note A context is a setting of group injected sequencer:
  3451. * - group injected trigger
  3452. * - sequencer length
  3453. * - sequencer ranks
  3454. * If contexts queue is disabled:
  3455. * - only 1 sequence can be configured
  3456. * and is active perpetually.
  3457. * If contexts queue is enabled:
  3458. * - up to 2 contexts can be queued
  3459. * and are checked in and out as a FIFO stack (first-in, first-out).
  3460. * - If a new context is set when queues is full, error is triggered
  3461. * by interruption "Injected Queue Overflow".
  3462. * - Two behaviors are possible when all contexts have been processed:
  3463. * the contexts queue can maintain the last context active perpetually
  3464. * or can be empty and injected group triggers are disabled.
  3465. * - Triggers can be only external (not internal SW start)
  3466. * - Caution: The sequence must be fully configured in one time
  3467. * (one write of register JSQR makes a check-in of a new context
  3468. * into the queue).
  3469. * Therefore functions to set separately injected trigger and
  3470. * sequencer channels cannot be used, register JSQR must be set
  3471. * using function @ref LL_ADC_INJ_ConfigQueueContext().
  3472. * @note This parameter can be modified only when no conversion is on going
  3473. * on either groups regular or injected.
  3474. * @note A modification of the context mode (bit JQDIS) causes the contexts
  3475. * queue to be flushed and the register JSQR is cleared.
  3476. * @note On this STM32 serie, setting of this feature is conditioned to
  3477. * ADC state:
  3478. * ADC must be disabled or enabled without conversion on going
  3479. * on either groups regular or injected.
  3480. * @rmtoll CFGR JQM LL_ADC_INJ_SetQueueMode\n
  3481. * CFGR JQDIS LL_ADC_INJ_SetQueueMode
  3482. * @param ADCx ADC instance
  3483. * @param QueueMode This parameter can be one of the following values:
  3484. * @arg @ref LL_ADC_INJ_QUEUE_DISABLE
  3485. * @arg @ref LL_ADC_INJ_QUEUE_2CONTEXTS_LAST_ACTIVE
  3486. * @arg @ref LL_ADC_INJ_QUEUE_2CONTEXTS_END_EMPTY
  3487. * @retval None
  3488. */
  3489. __STATIC_INLINE void LL_ADC_INJ_SetQueueMode(ADC_TypeDef *ADCx, uint32_t QueueMode)
  3490. {
  3491. MODIFY_REG(ADCx->CFGR, ADC_CFGR_JQM | ADC_CFGR_JQDIS, QueueMode);
  3492. }
  3493. /**
  3494. * @brief Get ADC group injected context queue mode.
  3495. * @rmtoll CFGR JQM LL_ADC_INJ_GetQueueMode\n
  3496. * CFGR JQDIS LL_ADC_INJ_GetQueueMode
  3497. * @param ADCx ADC instance
  3498. * @retval Returned value can be one of the following values:
  3499. * @arg @ref LL_ADC_INJ_QUEUE_DISABLE
  3500. * @arg @ref LL_ADC_INJ_QUEUE_2CONTEXTS_LAST_ACTIVE
  3501. * @arg @ref LL_ADC_INJ_QUEUE_2CONTEXTS_END_EMPTY
  3502. */
  3503. __STATIC_INLINE uint32_t LL_ADC_INJ_GetQueueMode(ADC_TypeDef *ADCx)
  3504. {
  3505. return (uint32_t)(READ_BIT(ADCx->CFGR, ADC_CFGR_JQM | ADC_CFGR_JQDIS));
  3506. }
  3507. /**
  3508. * @brief Set one context on ADC group injected that will be checked in
  3509. * contexts queue.
  3510. * @note A context is a setting of group injected sequencer:
  3511. * - group injected trigger
  3512. * - sequencer length
  3513. * - sequencer ranks
  3514. * This function is intended to be used when contexts queue is enabled,
  3515. * because the sequence must be fully configured in one time
  3516. * (functions to set separately injected trigger and sequencer channels
  3517. * cannot be used):
  3518. * Refer to function @ref LL_ADC_INJ_SetQueueMode().
  3519. * @note In the contexts queue, only the active context can be read.
  3520. * The parameters of this function can be read using functions:
  3521. * @arg @ref LL_ADC_INJ_GetTriggerSource()
  3522. * @arg @ref LL_ADC_INJ_GetTriggerEdge()
  3523. * @arg @ref LL_ADC_INJ_GetSequencerRanks()
  3524. * @note On this STM32 serie, to measure internal channels (VrefInt,
  3525. * TempSensor, ...), measurement paths to internal channels must be
  3526. * enabled separately.
  3527. * This can be done using function @ref LL_ADC_SetCommonPathInternalCh().
  3528. * @note On STM32WB, some fast channels are available: fast analog inputs
  3529. * coming from GPIO pads (ADC_IN1..5).
  3530. * @note On this STM32 serie, setting of this feature is conditioned to
  3531. * ADC state:
  3532. * ADC must not be disabled. Can be enabled with or without conversion
  3533. * on going on either groups regular or injected.
  3534. * @rmtoll JSQR JEXTSEL LL_ADC_INJ_ConfigQueueContext\n
  3535. * JSQR JEXTEN LL_ADC_INJ_ConfigQueueContext\n
  3536. * JSQR JL LL_ADC_INJ_ConfigQueueContext\n
  3537. * JSQR JSQ1 LL_ADC_INJ_ConfigQueueContext\n
  3538. * JSQR JSQ2 LL_ADC_INJ_ConfigQueueContext\n
  3539. * JSQR JSQ3 LL_ADC_INJ_ConfigQueueContext\n
  3540. * JSQR JSQ4 LL_ADC_INJ_ConfigQueueContext
  3541. * @param ADCx ADC instance
  3542. * @param TriggerSource This parameter can be one of the following values:
  3543. * @arg @ref LL_ADC_INJ_TRIG_SOFTWARE
  3544. * @arg @ref LL_ADC_INJ_TRIG_EXT_TIM1_TRGO
  3545. * @arg @ref LL_ADC_INJ_TRIG_EXT_TIM1_TRGO2
  3546. * @arg @ref LL_ADC_INJ_TRIG_EXT_TIM1_CH4
  3547. * @arg @ref LL_ADC_INJ_TRIG_EXT_TIM2_TRGO
  3548. * @arg @ref LL_ADC_INJ_TRIG_EXT_TIM2_CH1
  3549. * @arg @ref LL_ADC_INJ_TRIG_EXT_EXTI_LINE15
  3550. * @param ExternalTriggerEdge This parameter can be one of the following values:
  3551. * @arg @ref LL_ADC_INJ_TRIG_EXT_RISING
  3552. * @arg @ref LL_ADC_INJ_TRIG_EXT_FALLING
  3553. * @arg @ref LL_ADC_INJ_TRIG_EXT_RISINGFALLING
  3554. *
  3555. * Note: This parameter is discarded in case of SW start:
  3556. * parameter "TriggerSource" set to "LL_ADC_INJ_TRIG_SOFTWARE".
  3557. * @param SequencerNbRanks This parameter can be one of the following values:
  3558. * @arg @ref LL_ADC_INJ_SEQ_SCAN_DISABLE
  3559. * @arg @ref LL_ADC_INJ_SEQ_SCAN_ENABLE_2RANKS
  3560. * @arg @ref LL_ADC_INJ_SEQ_SCAN_ENABLE_3RANKS
  3561. * @arg @ref LL_ADC_INJ_SEQ_SCAN_ENABLE_4RANKS
  3562. * @param Rank1_Channel This parameter can be one of the following values:
  3563. * @arg @ref LL_ADC_CHANNEL_0
  3564. * @arg @ref LL_ADC_CHANNEL_1 (7)
  3565. * @arg @ref LL_ADC_CHANNEL_2 (7)
  3566. * @arg @ref LL_ADC_CHANNEL_3 (7)
  3567. * @arg @ref LL_ADC_CHANNEL_4 (7)
  3568. * @arg @ref LL_ADC_CHANNEL_5 (7)
  3569. * @arg @ref LL_ADC_CHANNEL_6
  3570. * @arg @ref LL_ADC_CHANNEL_7
  3571. * @arg @ref LL_ADC_CHANNEL_8
  3572. * @arg @ref LL_ADC_CHANNEL_9
  3573. * @arg @ref LL_ADC_CHANNEL_10
  3574. * @arg @ref LL_ADC_CHANNEL_11
  3575. * @arg @ref LL_ADC_CHANNEL_12
  3576. * @arg @ref LL_ADC_CHANNEL_13
  3577. * @arg @ref LL_ADC_CHANNEL_14
  3578. * @arg @ref LL_ADC_CHANNEL_15
  3579. * @arg @ref LL_ADC_CHANNEL_16
  3580. * @arg @ref LL_ADC_CHANNEL_17
  3581. * @arg @ref LL_ADC_CHANNEL_18
  3582. * @arg @ref LL_ADC_CHANNEL_VREFINT
  3583. * @arg @ref LL_ADC_CHANNEL_TEMPSENSOR
  3584. * @arg @ref LL_ADC_CHANNEL_VBAT
  3585. *
  3586. * (7) On STM32WB, fast channel (0.188 us for 12-bit resolution (ADC conversion rate up to 5.33 Ms/s)).
  3587. * Other channels are slow channels (0.238 us for 12-bit resolution (ADC conversion rate up to 4.21 Ms/s)).
  3588. * @param Rank2_Channel This parameter can be one of the following values:
  3589. * @arg @ref LL_ADC_CHANNEL_0
  3590. * @arg @ref LL_ADC_CHANNEL_1 (7)
  3591. * @arg @ref LL_ADC_CHANNEL_2 (7)
  3592. * @arg @ref LL_ADC_CHANNEL_3 (7)
  3593. * @arg @ref LL_ADC_CHANNEL_4 (7)
  3594. * @arg @ref LL_ADC_CHANNEL_5 (7)
  3595. * @arg @ref LL_ADC_CHANNEL_6
  3596. * @arg @ref LL_ADC_CHANNEL_7
  3597. * @arg @ref LL_ADC_CHANNEL_8
  3598. * @arg @ref LL_ADC_CHANNEL_9
  3599. * @arg @ref LL_ADC_CHANNEL_10
  3600. * @arg @ref LL_ADC_CHANNEL_11
  3601. * @arg @ref LL_ADC_CHANNEL_12
  3602. * @arg @ref LL_ADC_CHANNEL_13
  3603. * @arg @ref LL_ADC_CHANNEL_14
  3604. * @arg @ref LL_ADC_CHANNEL_15
  3605. * @arg @ref LL_ADC_CHANNEL_16
  3606. * @arg @ref LL_ADC_CHANNEL_17
  3607. * @arg @ref LL_ADC_CHANNEL_18
  3608. * @arg @ref LL_ADC_CHANNEL_VREFINT
  3609. * @arg @ref LL_ADC_CHANNEL_TEMPSENSOR
  3610. * @arg @ref LL_ADC_CHANNEL_VBAT
  3611. *
  3612. * (7) On STM32WB, fast channel (0.188 us for 12-bit resolution (ADC conversion rate up to 5.33 Ms/s)).
  3613. * Other channels are slow channels (0.238 us for 12-bit resolution (ADC conversion rate up to 4.21 Ms/s)).
  3614. * @param Rank3_Channel This parameter can be one of the following values:
  3615. * @arg @ref LL_ADC_CHANNEL_0
  3616. * @arg @ref LL_ADC_CHANNEL_1 (7)
  3617. * @arg @ref LL_ADC_CHANNEL_2 (7)
  3618. * @arg @ref LL_ADC_CHANNEL_3 (7)
  3619. * @arg @ref LL_ADC_CHANNEL_4 (7)
  3620. * @arg @ref LL_ADC_CHANNEL_5 (7)
  3621. * @arg @ref LL_ADC_CHANNEL_6
  3622. * @arg @ref LL_ADC_CHANNEL_7
  3623. * @arg @ref LL_ADC_CHANNEL_8
  3624. * @arg @ref LL_ADC_CHANNEL_9
  3625. * @arg @ref LL_ADC_CHANNEL_10
  3626. * @arg @ref LL_ADC_CHANNEL_11
  3627. * @arg @ref LL_ADC_CHANNEL_12
  3628. * @arg @ref LL_ADC_CHANNEL_13
  3629. * @arg @ref LL_ADC_CHANNEL_14
  3630. * @arg @ref LL_ADC_CHANNEL_15
  3631. * @arg @ref LL_ADC_CHANNEL_16
  3632. * @arg @ref LL_ADC_CHANNEL_17
  3633. * @arg @ref LL_ADC_CHANNEL_18
  3634. * @arg @ref LL_ADC_CHANNEL_VREFINT
  3635. * @arg @ref LL_ADC_CHANNEL_TEMPSENSOR
  3636. * @arg @ref LL_ADC_CHANNEL_VBAT
  3637. *
  3638. * (7) On STM32WB, fast channel (0.188 us for 12-bit resolution (ADC conversion rate up to 5.33 Ms/s)).
  3639. * Other channels are slow channels (0.238 us for 12-bit resolution (ADC conversion rate up to 4.21 Ms/s)).
  3640. * @param Rank4_Channel This parameter can be one of the following values:
  3641. * @arg @ref LL_ADC_CHANNEL_0
  3642. * @arg @ref LL_ADC_CHANNEL_1 (7)
  3643. * @arg @ref LL_ADC_CHANNEL_2 (7)
  3644. * @arg @ref LL_ADC_CHANNEL_3 (7)
  3645. * @arg @ref LL_ADC_CHANNEL_4 (7)
  3646. * @arg @ref LL_ADC_CHANNEL_5 (7)
  3647. * @arg @ref LL_ADC_CHANNEL_6
  3648. * @arg @ref LL_ADC_CHANNEL_7
  3649. * @arg @ref LL_ADC_CHANNEL_8
  3650. * @arg @ref LL_ADC_CHANNEL_9
  3651. * @arg @ref LL_ADC_CHANNEL_10
  3652. * @arg @ref LL_ADC_CHANNEL_11
  3653. * @arg @ref LL_ADC_CHANNEL_12
  3654. * @arg @ref LL_ADC_CHANNEL_13
  3655. * @arg @ref LL_ADC_CHANNEL_14
  3656. * @arg @ref LL_ADC_CHANNEL_15
  3657. * @arg @ref LL_ADC_CHANNEL_16
  3658. * @arg @ref LL_ADC_CHANNEL_17
  3659. * @arg @ref LL_ADC_CHANNEL_18
  3660. * @arg @ref LL_ADC_CHANNEL_VREFINT
  3661. * @arg @ref LL_ADC_CHANNEL_TEMPSENSOR
  3662. * @arg @ref LL_ADC_CHANNEL_VBAT
  3663. *
  3664. * (7) On STM32WB, fast channel (0.188 us for 12-bit resolution (ADC conversion rate up to 5.33 Ms/s)).
  3665. * Other channels are slow channels (0.238 us for 12-bit resolution (ADC conversion rate up to 4.21 Ms/s)).
  3666. * @retval None
  3667. */
  3668. __STATIC_INLINE void LL_ADC_INJ_ConfigQueueContext(ADC_TypeDef *ADCx,
  3669. uint32_t TriggerSource,
  3670. uint32_t ExternalTriggerEdge,
  3671. uint32_t SequencerNbRanks,
  3672. uint32_t Rank1_Channel,
  3673. uint32_t Rank2_Channel,
  3674. uint32_t Rank3_Channel,
  3675. uint32_t Rank4_Channel)
  3676. {
  3677. /* Set bits with content of parameter "Rankx_Channel" with bits position */
  3678. /* in register depending on literal "LL_ADC_INJ_RANK_x". */
  3679. /* Parameters "Rankx_Channel" and "LL_ADC_INJ_RANK_x" are used with masks */
  3680. /* because containing other bits reserved for other purpose. */
  3681. /* If parameter "TriggerSource" is set to SW start, then parameter */
  3682. /* "ExternalTriggerEdge" is discarded. */
  3683. register uint32_t is_trigger_not_sw = (uint32_t)((TriggerSource != LL_ADC_INJ_TRIG_SOFTWARE) ? 1UL : 0UL);
  3684. MODIFY_REG(ADCx->JSQR,
  3685. ADC_JSQR_JEXTSEL |
  3686. ADC_JSQR_JEXTEN |
  3687. ADC_JSQR_JSQ4 |
  3688. ADC_JSQR_JSQ3 |
  3689. ADC_JSQR_JSQ2 |
  3690. ADC_JSQR_JSQ1 |
  3691. ADC_JSQR_JL,
  3692. (TriggerSource & ADC_JSQR_JEXTSEL) |
  3693. (ExternalTriggerEdge * (is_trigger_not_sw)) |
  3694. (((Rank4_Channel & ADC_CHANNEL_ID_NUMBER_MASK) >> ADC_CHANNEL_ID_NUMBER_BITOFFSET_POS) << (LL_ADC_INJ_RANK_4 & ADC_INJ_RANK_ID_JSQR_MASK)) |
  3695. (((Rank3_Channel & ADC_CHANNEL_ID_NUMBER_MASK) >> ADC_CHANNEL_ID_NUMBER_BITOFFSET_POS) << (LL_ADC_INJ_RANK_3 & ADC_INJ_RANK_ID_JSQR_MASK)) |
  3696. (((Rank2_Channel & ADC_CHANNEL_ID_NUMBER_MASK) >> ADC_CHANNEL_ID_NUMBER_BITOFFSET_POS) << (LL_ADC_INJ_RANK_2 & ADC_INJ_RANK_ID_JSQR_MASK)) |
  3697. (((Rank1_Channel & ADC_CHANNEL_ID_NUMBER_MASK) >> ADC_CHANNEL_ID_NUMBER_BITOFFSET_POS) << (LL_ADC_INJ_RANK_1 & ADC_INJ_RANK_ID_JSQR_MASK)) |
  3698. SequencerNbRanks
  3699. );
  3700. }
  3701. /**
  3702. * @}
  3703. */
  3704. /** @defgroup ADC_LL_EF_Configuration_Channels Configuration of ADC hierarchical scope: channels
  3705. * @{
  3706. */
  3707. /**
  3708. * @brief Set sampling time of the selected ADC channel
  3709. * Unit: ADC clock cycles.
  3710. * @note On this device, sampling time is on channel scope: independently
  3711. * of channel mapped on ADC group regular or injected.
  3712. * @note In case of internal channel (VrefInt, TempSensor, ...) to be
  3713. * converted:
  3714. * sampling time constraints must be respected (sampling time can be
  3715. * adjusted in function of ADC clock frequency and sampling time
  3716. * setting).
  3717. * Refer to device datasheet for timings values (parameters TS_vrefint,
  3718. * TS_temp, ...).
  3719. * @note Conversion time is the addition of sampling time and processing time.
  3720. * On this STM32 serie, ADC processing time is:
  3721. * - 12.5 ADC clock cycles at ADC resolution 12 bits
  3722. * - 10.5 ADC clock cycles at ADC resolution 10 bits
  3723. * - 8.5 ADC clock cycles at ADC resolution 8 bits
  3724. * - 6.5 ADC clock cycles at ADC resolution 6 bits
  3725. * @note In case of ADC conversion of internal channel (VrefInt,
  3726. * temperature sensor, ...), a sampling time minimum value
  3727. * is required.
  3728. * Refer to device datasheet.
  3729. * @note On this STM32 serie, setting of this feature is conditioned to
  3730. * ADC state:
  3731. * ADC must be disabled or enabled without conversion on going
  3732. * on either groups regular or injected.
  3733. * @rmtoll SMPR1 SMP0 LL_ADC_SetChannelSamplingTime\n
  3734. * SMPR1 SMP1 LL_ADC_SetChannelSamplingTime\n
  3735. * SMPR1 SMP2 LL_ADC_SetChannelSamplingTime\n
  3736. * SMPR1 SMP3 LL_ADC_SetChannelSamplingTime\n
  3737. * SMPR1 SMP4 LL_ADC_SetChannelSamplingTime\n
  3738. * SMPR1 SMP5 LL_ADC_SetChannelSamplingTime\n
  3739. * SMPR1 SMP6 LL_ADC_SetChannelSamplingTime\n
  3740. * SMPR1 SMP7 LL_ADC_SetChannelSamplingTime\n
  3741. * SMPR1 SMP8 LL_ADC_SetChannelSamplingTime\n
  3742. * SMPR1 SMP9 LL_ADC_SetChannelSamplingTime\n
  3743. * SMPR2 SMP10 LL_ADC_SetChannelSamplingTime\n
  3744. * SMPR2 SMP11 LL_ADC_SetChannelSamplingTime\n
  3745. * SMPR2 SMP12 LL_ADC_SetChannelSamplingTime\n
  3746. * SMPR2 SMP13 LL_ADC_SetChannelSamplingTime\n
  3747. * SMPR2 SMP14 LL_ADC_SetChannelSamplingTime\n
  3748. * SMPR2 SMP15 LL_ADC_SetChannelSamplingTime\n
  3749. * SMPR2 SMP16 LL_ADC_SetChannelSamplingTime\n
  3750. * SMPR2 SMP17 LL_ADC_SetChannelSamplingTime\n
  3751. * SMPR2 SMP18 LL_ADC_SetChannelSamplingTime
  3752. * @param ADCx ADC instance
  3753. * @param Channel This parameter can be one of the following values:
  3754. * @arg @ref LL_ADC_CHANNEL_0
  3755. * @arg @ref LL_ADC_CHANNEL_1 (7)
  3756. * @arg @ref LL_ADC_CHANNEL_2 (7)
  3757. * @arg @ref LL_ADC_CHANNEL_3 (7)
  3758. * @arg @ref LL_ADC_CHANNEL_4 (7)
  3759. * @arg @ref LL_ADC_CHANNEL_5 (7)
  3760. * @arg @ref LL_ADC_CHANNEL_6
  3761. * @arg @ref LL_ADC_CHANNEL_7
  3762. * @arg @ref LL_ADC_CHANNEL_8
  3763. * @arg @ref LL_ADC_CHANNEL_9
  3764. * @arg @ref LL_ADC_CHANNEL_10
  3765. * @arg @ref LL_ADC_CHANNEL_11
  3766. * @arg @ref LL_ADC_CHANNEL_12
  3767. * @arg @ref LL_ADC_CHANNEL_13
  3768. * @arg @ref LL_ADC_CHANNEL_14
  3769. * @arg @ref LL_ADC_CHANNEL_15
  3770. * @arg @ref LL_ADC_CHANNEL_16
  3771. * @arg @ref LL_ADC_CHANNEL_17
  3772. * @arg @ref LL_ADC_CHANNEL_18
  3773. * @arg @ref LL_ADC_CHANNEL_VREFINT
  3774. * @arg @ref LL_ADC_CHANNEL_TEMPSENSOR
  3775. * @arg @ref LL_ADC_CHANNEL_VBAT
  3776. *
  3777. * (7) On STM32WB, fast channel (0.188 us for 12-bit resolution (ADC conversion rate up to 5.33 Ms/s)).
  3778. * Other channels are slow channels (0.238 us for 12-bit resolution (ADC conversion rate up to 4.21 Ms/s)).
  3779. * @param SamplingTime This parameter can be one of the following values:
  3780. * @arg @ref LL_ADC_SAMPLINGTIME_2CYCLES_5
  3781. * @arg @ref LL_ADC_SAMPLINGTIME_6CYCLES_5
  3782. * @arg @ref LL_ADC_SAMPLINGTIME_12CYCLES_5
  3783. * @arg @ref LL_ADC_SAMPLINGTIME_24CYCLES_5
  3784. * @arg @ref LL_ADC_SAMPLINGTIME_47CYCLES_5
  3785. * @arg @ref LL_ADC_SAMPLINGTIME_92CYCLES_5
  3786. * @arg @ref LL_ADC_SAMPLINGTIME_247CYCLES_5
  3787. * @arg @ref LL_ADC_SAMPLINGTIME_640CYCLES_5
  3788. * @retval None
  3789. */
  3790. __STATIC_INLINE void LL_ADC_SetChannelSamplingTime(ADC_TypeDef *ADCx, uint32_t Channel, uint32_t SamplingTime)
  3791. {
  3792. /* Set bits with content of parameter "SamplingTime" with bits position */
  3793. /* in register and register position depending on parameter "Channel". */
  3794. /* Parameter "Channel" is used with masks because containing */
  3795. /* other bits reserved for other purpose. */
  3796. register __IO uint32_t *preg = __ADC_PTR_REG_OFFSET(ADCx->SMPR1, ((Channel & ADC_CHANNEL_SMPRX_REGOFFSET_MASK) >> ADC_SMPRX_REGOFFSET_POS));
  3797. MODIFY_REG(*preg,
  3798. ADC_SMPR1_SMP0 << ((Channel & ADC_CHANNEL_SMPx_BITOFFSET_MASK) >> ADC_CHANNEL_SMPx_BITOFFSET_POS),
  3799. SamplingTime << ((Channel & ADC_CHANNEL_SMPx_BITOFFSET_MASK) >> ADC_CHANNEL_SMPx_BITOFFSET_POS));
  3800. }
  3801. /**
  3802. * @brief Get sampling time of the selected ADC channel
  3803. * Unit: ADC clock cycles.
  3804. * @note On this device, sampling time is on channel scope: independently
  3805. * of channel mapped on ADC group regular or injected.
  3806. * @note Conversion time is the addition of sampling time and processing time.
  3807. * On this STM32 serie, ADC processing time is:
  3808. * - 12.5 ADC clock cycles at ADC resolution 12 bits
  3809. * - 10.5 ADC clock cycles at ADC resolution 10 bits
  3810. * - 8.5 ADC clock cycles at ADC resolution 8 bits
  3811. * - 6.5 ADC clock cycles at ADC resolution 6 bits
  3812. * @rmtoll SMPR1 SMP0 LL_ADC_GetChannelSamplingTime\n
  3813. * SMPR1 SMP1 LL_ADC_GetChannelSamplingTime\n
  3814. * SMPR1 SMP2 LL_ADC_GetChannelSamplingTime\n
  3815. * SMPR1 SMP3 LL_ADC_GetChannelSamplingTime\n
  3816. * SMPR1 SMP4 LL_ADC_GetChannelSamplingTime\n
  3817. * SMPR1 SMP5 LL_ADC_GetChannelSamplingTime\n
  3818. * SMPR1 SMP6 LL_ADC_GetChannelSamplingTime\n
  3819. * SMPR1 SMP7 LL_ADC_GetChannelSamplingTime\n
  3820. * SMPR1 SMP8 LL_ADC_GetChannelSamplingTime\n
  3821. * SMPR1 SMP9 LL_ADC_GetChannelSamplingTime\n
  3822. * SMPR2 SMP10 LL_ADC_GetChannelSamplingTime\n
  3823. * SMPR2 SMP11 LL_ADC_GetChannelSamplingTime\n
  3824. * SMPR2 SMP12 LL_ADC_GetChannelSamplingTime\n
  3825. * SMPR2 SMP13 LL_ADC_GetChannelSamplingTime\n
  3826. * SMPR2 SMP14 LL_ADC_GetChannelSamplingTime\n
  3827. * SMPR2 SMP15 LL_ADC_GetChannelSamplingTime\n
  3828. * SMPR2 SMP16 LL_ADC_GetChannelSamplingTime\n
  3829. * SMPR2 SMP17 LL_ADC_GetChannelSamplingTime\n
  3830. * SMPR2 SMP18 LL_ADC_GetChannelSamplingTime
  3831. * @param ADCx ADC instance
  3832. * @param Channel This parameter can be one of the following values:
  3833. * @arg @ref LL_ADC_CHANNEL_0
  3834. * @arg @ref LL_ADC_CHANNEL_1 (7)
  3835. * @arg @ref LL_ADC_CHANNEL_2 (7)
  3836. * @arg @ref LL_ADC_CHANNEL_3 (7)
  3837. * @arg @ref LL_ADC_CHANNEL_4 (7)
  3838. * @arg @ref LL_ADC_CHANNEL_5 (7)
  3839. * @arg @ref LL_ADC_CHANNEL_6
  3840. * @arg @ref LL_ADC_CHANNEL_7
  3841. * @arg @ref LL_ADC_CHANNEL_8
  3842. * @arg @ref LL_ADC_CHANNEL_9
  3843. * @arg @ref LL_ADC_CHANNEL_10
  3844. * @arg @ref LL_ADC_CHANNEL_11
  3845. * @arg @ref LL_ADC_CHANNEL_12
  3846. * @arg @ref LL_ADC_CHANNEL_13
  3847. * @arg @ref LL_ADC_CHANNEL_14
  3848. * @arg @ref LL_ADC_CHANNEL_15
  3849. * @arg @ref LL_ADC_CHANNEL_16
  3850. * @arg @ref LL_ADC_CHANNEL_17
  3851. * @arg @ref LL_ADC_CHANNEL_18
  3852. * @arg @ref LL_ADC_CHANNEL_VREFINT
  3853. * @arg @ref LL_ADC_CHANNEL_TEMPSENSOR
  3854. * @arg @ref LL_ADC_CHANNEL_VBAT
  3855. *
  3856. * (7) On STM32WB, fast channel (0.188 us for 12-bit resolution (ADC conversion rate up to 5.33 Ms/s)).
  3857. * Other channels are slow channels (0.238 us for 12-bit resolution (ADC conversion rate up to 4.21 Ms/s)).
  3858. * @retval Returned value can be one of the following values:
  3859. * @arg @ref LL_ADC_SAMPLINGTIME_2CYCLES_5
  3860. * @arg @ref LL_ADC_SAMPLINGTIME_6CYCLES_5
  3861. * @arg @ref LL_ADC_SAMPLINGTIME_12CYCLES_5
  3862. * @arg @ref LL_ADC_SAMPLINGTIME_24CYCLES_5
  3863. * @arg @ref LL_ADC_SAMPLINGTIME_47CYCLES_5
  3864. * @arg @ref LL_ADC_SAMPLINGTIME_92CYCLES_5
  3865. * @arg @ref LL_ADC_SAMPLINGTIME_247CYCLES_5
  3866. * @arg @ref LL_ADC_SAMPLINGTIME_640CYCLES_5
  3867. */
  3868. __STATIC_INLINE uint32_t LL_ADC_GetChannelSamplingTime(ADC_TypeDef *ADCx, uint32_t Channel)
  3869. {
  3870. register const __IO uint32_t *preg = __ADC_PTR_REG_OFFSET(ADCx->SMPR1, ((Channel & ADC_CHANNEL_SMPRX_REGOFFSET_MASK) >> ADC_SMPRX_REGOFFSET_POS));
  3871. return (uint32_t)(READ_BIT(*preg,
  3872. ADC_SMPR1_SMP0 << ((Channel & ADC_CHANNEL_SMPx_BITOFFSET_MASK) >> ADC_CHANNEL_SMPx_BITOFFSET_POS))
  3873. >> ((Channel & ADC_CHANNEL_SMPx_BITOFFSET_MASK) >> ADC_CHANNEL_SMPx_BITOFFSET_POS)
  3874. );
  3875. }
  3876. /**
  3877. * @brief Set mode single-ended or differential input of the selected
  3878. * ADC channel.
  3879. * @note Channel ending is on channel scope: independently of channel mapped
  3880. * on ADC group regular or injected.
  3881. * In differential mode: Differential measurement is carried out
  3882. * between the selected channel 'i' (positive input) and
  3883. * channel 'i+1' (negative input). Only channel 'i' has to be
  3884. * configured, channel 'i+1' is configured automatically.
  3885. * @note Refer to Reference Manual to ensure the selected channel is
  3886. * available in differential mode.
  3887. * For example, internal channels (VrefInt, TempSensor, ...) are
  3888. * not available in differential mode.
  3889. * @note When configuring a channel 'i' in differential mode,
  3890. * the channel 'i+1' is not usable separately.
  3891. * @note On STM32WB, channels 16, 17, 18 of ADC1
  3892. * are internally fixed to single-ended inputs configuration.
  3893. * @note For ADC channels configured in differential mode, both inputs
  3894. * should be biased at (Vref+)/2 +/-200mV.
  3895. * (Vref+ is the analog voltage reference)
  3896. * @note On this STM32 serie, setting of this feature is conditioned to
  3897. * ADC state:
  3898. * ADC must be ADC disabled.
  3899. * @note One or several values can be selected.
  3900. * Example: (LL_ADC_CHANNEL_4 | LL_ADC_CHANNEL_12 | ...)
  3901. * @rmtoll DIFSEL DIFSEL LL_ADC_SetChannelSingleDiff
  3902. * @param ADCx ADC instance
  3903. * @param Channel This parameter can be one of the following values:
  3904. * @arg @ref LL_ADC_CHANNEL_1
  3905. * @arg @ref LL_ADC_CHANNEL_2
  3906. * @arg @ref LL_ADC_CHANNEL_3
  3907. * @arg @ref LL_ADC_CHANNEL_4
  3908. * @arg @ref LL_ADC_CHANNEL_5
  3909. * @arg @ref LL_ADC_CHANNEL_6
  3910. * @arg @ref LL_ADC_CHANNEL_7
  3911. * @arg @ref LL_ADC_CHANNEL_8
  3912. * @arg @ref LL_ADC_CHANNEL_9
  3913. * @arg @ref LL_ADC_CHANNEL_10
  3914. * @arg @ref LL_ADC_CHANNEL_11
  3915. * @arg @ref LL_ADC_CHANNEL_12
  3916. * @arg @ref LL_ADC_CHANNEL_13
  3917. * @arg @ref LL_ADC_CHANNEL_14
  3918. * @arg @ref LL_ADC_CHANNEL_15
  3919. * @param SingleDiff This parameter can be a combination of the following values:
  3920. * @arg @ref LL_ADC_SINGLE_ENDED
  3921. * @arg @ref LL_ADC_DIFFERENTIAL_ENDED
  3922. * @retval None
  3923. */
  3924. __STATIC_INLINE void LL_ADC_SetChannelSingleDiff(ADC_TypeDef *ADCx, uint32_t Channel, uint32_t SingleDiff)
  3925. {
  3926. /* Bits of channels in single or differential mode are set only for */
  3927. /* differential mode (for single mode, mask of bits allowed to be set is */
  3928. /* shifted out of range of bits of channels in single or differential mode. */
  3929. MODIFY_REG(ADCx->DIFSEL,
  3930. Channel & ADC_SINGLEDIFF_CHANNEL_MASK,
  3931. (Channel & ADC_SINGLEDIFF_CHANNEL_MASK) & (ADC_DIFSEL_DIFSEL >> (SingleDiff & ADC_SINGLEDIFF_CHANNEL_SHIFT_MASK)));
  3932. }
  3933. /**
  3934. * @brief Get mode single-ended or differential input of the selected
  3935. * ADC channel.
  3936. * @note When configuring a channel 'i' in differential mode,
  3937. * the channel 'i+1' is not usable separately.
  3938. * Therefore, to ensure a channel is configured in single-ended mode,
  3939. * the configuration of channel itself and the channel 'i-1' must be
  3940. * read back (to ensure that the selected channel channel has not been
  3941. * configured in differential mode by the previous channel).
  3942. * @note Refer to Reference Manual to ensure the selected channel is
  3943. * available in differential mode.
  3944. * For example, internal channels (VrefInt, TempSensor, ...) are
  3945. * not available in differential mode.
  3946. * @note When configuring a channel 'i' in differential mode,
  3947. * the channel 'i+1' is not usable separately.
  3948. * @note On STM32WB, channels 16, 17, 18 of ADC1
  3949. * are internally fixed to single-ended inputs configuration.
  3950. * @note One or several values can be selected. In this case, the value
  3951. * returned is null if all channels are in single ended-mode.
  3952. * Example: (LL_ADC_CHANNEL_4 | LL_ADC_CHANNEL_12 | ...)
  3953. * @rmtoll DIFSEL DIFSEL LL_ADC_GetChannelSingleDiff
  3954. * @param ADCx ADC instance
  3955. * @param Channel This parameter can be a combination of the following values:
  3956. * @arg @ref LL_ADC_CHANNEL_1
  3957. * @arg @ref LL_ADC_CHANNEL_2
  3958. * @arg @ref LL_ADC_CHANNEL_3
  3959. * @arg @ref LL_ADC_CHANNEL_4
  3960. * @arg @ref LL_ADC_CHANNEL_5
  3961. * @arg @ref LL_ADC_CHANNEL_6
  3962. * @arg @ref LL_ADC_CHANNEL_7
  3963. * @arg @ref LL_ADC_CHANNEL_8
  3964. * @arg @ref LL_ADC_CHANNEL_9
  3965. * @arg @ref LL_ADC_CHANNEL_10
  3966. * @arg @ref LL_ADC_CHANNEL_11
  3967. * @arg @ref LL_ADC_CHANNEL_12
  3968. * @arg @ref LL_ADC_CHANNEL_13
  3969. * @arg @ref LL_ADC_CHANNEL_14
  3970. * @arg @ref LL_ADC_CHANNEL_15
  3971. * @retval 0: channel in single-ended mode, else: channel in differential mode
  3972. */
  3973. __STATIC_INLINE uint32_t LL_ADC_GetChannelSingleDiff(ADC_TypeDef *ADCx, uint32_t Channel)
  3974. {
  3975. return (uint32_t)(READ_BIT(ADCx->DIFSEL, (Channel & ADC_SINGLEDIFF_CHANNEL_MASK)));
  3976. }
  3977. /**
  3978. * @}
  3979. */
  3980. /** @defgroup ADC_LL_EF_Configuration_ADC_AnalogWatchdog Configuration of ADC transversal scope: analog watchdog
  3981. * @{
  3982. */
  3983. /**
  3984. * @brief Set ADC analog watchdog monitored channels:
  3985. * a single channel, multiple channels or all channels,
  3986. * on ADC groups regular and-or injected.
  3987. * @note Once monitored channels are selected, analog watchdog
  3988. * is enabled.
  3989. * @note In case of need to define a single channel to monitor
  3990. * with analog watchdog from sequencer channel definition,
  3991. * use helper macro @ref __LL_ADC_ANALOGWD_CHANNEL_GROUP().
  3992. * @note On this STM32 serie, there are 2 kinds of analog watchdog
  3993. * instance:
  3994. * - AWD standard (instance AWD1):
  3995. * - channels monitored: can monitor 1 channel or all channels.
  3996. * - groups monitored: ADC groups regular and-or injected.
  3997. * - resolution: resolution is not limited (corresponds to
  3998. * ADC resolution configured).
  3999. * - AWD flexible (instances AWD2, AWD3):
  4000. * - channels monitored: flexible on channels monitored, selection is
  4001. * channel wise, from from 1 to all channels.
  4002. * Specificity of this analog watchdog: Multiple channels can
  4003. * be selected. For example:
  4004. * (LL_ADC_AWD_CHANNEL4_REG_INJ | LL_ADC_AWD_CHANNEL5_REG_INJ | ...)
  4005. * - groups monitored: not selection possible (monitoring on both
  4006. * groups regular and injected).
  4007. * Channels selected are monitored on groups regular and injected:
  4008. * LL_ADC_AWD_CHANNELxx_REG_INJ (do not use parameters
  4009. * LL_ADC_AWD_CHANNELxx_REG and LL_ADC_AWD_CHANNELxx_INJ)
  4010. * - resolution: resolution is limited to 8 bits: if ADC resolution is
  4011. * 12 bits the 4 LSB are ignored, if ADC resolution is 10 bits
  4012. * the 2 LSB are ignored.
  4013. * @note On this STM32 serie, setting of this feature is conditioned to
  4014. * ADC state:
  4015. * ADC must be disabled or enabled without conversion on going
  4016. * on either groups regular or injected.
  4017. * @rmtoll CFGR AWD1CH LL_ADC_SetAnalogWDMonitChannels\n
  4018. * CFGR AWD1SGL LL_ADC_SetAnalogWDMonitChannels\n
  4019. * CFGR AWD1EN LL_ADC_SetAnalogWDMonitChannels\n
  4020. * CFGR JAWD1EN LL_ADC_SetAnalogWDMonitChannels\n
  4021. * AWD2CR AWD2CH LL_ADC_SetAnalogWDMonitChannels\n
  4022. * AWD3CR AWD3CH LL_ADC_SetAnalogWDMonitChannels
  4023. * @param ADCx ADC instance
  4024. * @param AWDy This parameter can be one of the following values:
  4025. * @arg @ref LL_ADC_AWD1
  4026. * @arg @ref LL_ADC_AWD2
  4027. * @arg @ref LL_ADC_AWD3
  4028. * @param AWDChannelGroup This parameter can be one of the following values:
  4029. * @arg @ref LL_ADC_AWD_DISABLE
  4030. * @arg @ref LL_ADC_AWD_ALL_CHANNELS_REG (0)
  4031. * @arg @ref LL_ADC_AWD_ALL_CHANNELS_INJ (0)
  4032. * @arg @ref LL_ADC_AWD_ALL_CHANNELS_REG_INJ
  4033. * @arg @ref LL_ADC_AWD_CHANNEL_0_REG (0)
  4034. * @arg @ref LL_ADC_AWD_CHANNEL_0_INJ (0)
  4035. * @arg @ref LL_ADC_AWD_CHANNEL_0_REG_INJ
  4036. * @arg @ref LL_ADC_AWD_CHANNEL_1_REG (0)
  4037. * @arg @ref LL_ADC_AWD_CHANNEL_1_INJ (0)
  4038. * @arg @ref LL_ADC_AWD_CHANNEL_1_REG_INJ
  4039. * @arg @ref LL_ADC_AWD_CHANNEL_2_REG (0)
  4040. * @arg @ref LL_ADC_AWD_CHANNEL_2_INJ (0)
  4041. * @arg @ref LL_ADC_AWD_CHANNEL_2_REG_INJ
  4042. * @arg @ref LL_ADC_AWD_CHANNEL_3_REG (0)
  4043. * @arg @ref LL_ADC_AWD_CHANNEL_3_INJ (0)
  4044. * @arg @ref LL_ADC_AWD_CHANNEL_3_REG_INJ
  4045. * @arg @ref LL_ADC_AWD_CHANNEL_4_REG (0)
  4046. * @arg @ref LL_ADC_AWD_CHANNEL_4_INJ (0)
  4047. * @arg @ref LL_ADC_AWD_CHANNEL_4_REG_INJ
  4048. * @arg @ref LL_ADC_AWD_CHANNEL_5_REG (0)
  4049. * @arg @ref LL_ADC_AWD_CHANNEL_5_INJ (0)
  4050. * @arg @ref LL_ADC_AWD_CHANNEL_5_REG_INJ
  4051. * @arg @ref LL_ADC_AWD_CHANNEL_6_REG (0)
  4052. * @arg @ref LL_ADC_AWD_CHANNEL_6_INJ (0)
  4053. * @arg @ref LL_ADC_AWD_CHANNEL_6_REG_INJ
  4054. * @arg @ref LL_ADC_AWD_CHANNEL_7_REG (0)
  4055. * @arg @ref LL_ADC_AWD_CHANNEL_7_INJ (0)
  4056. * @arg @ref LL_ADC_AWD_CHANNEL_7_REG_INJ
  4057. * @arg @ref LL_ADC_AWD_CHANNEL_8_REG (0)
  4058. * @arg @ref LL_ADC_AWD_CHANNEL_8_INJ (0)
  4059. * @arg @ref LL_ADC_AWD_CHANNEL_8_REG_INJ
  4060. * @arg @ref LL_ADC_AWD_CHANNEL_9_REG (0)
  4061. * @arg @ref LL_ADC_AWD_CHANNEL_9_INJ (0)
  4062. * @arg @ref LL_ADC_AWD_CHANNEL_9_REG_INJ
  4063. * @arg @ref LL_ADC_AWD_CHANNEL_10_REG (0)
  4064. * @arg @ref LL_ADC_AWD_CHANNEL_10_INJ (0)
  4065. * @arg @ref LL_ADC_AWD_CHANNEL_10_REG_INJ
  4066. * @arg @ref LL_ADC_AWD_CHANNEL_11_REG (0)
  4067. * @arg @ref LL_ADC_AWD_CHANNEL_11_INJ (0)
  4068. * @arg @ref LL_ADC_AWD_CHANNEL_11_REG_INJ
  4069. * @arg @ref LL_ADC_AWD_CHANNEL_12_REG (0)
  4070. * @arg @ref LL_ADC_AWD_CHANNEL_12_INJ (0)
  4071. * @arg @ref LL_ADC_AWD_CHANNEL_12_REG_INJ
  4072. * @arg @ref LL_ADC_AWD_CHANNEL_13_REG (0)
  4073. * @arg @ref LL_ADC_AWD_CHANNEL_13_INJ (0)
  4074. * @arg @ref LL_ADC_AWD_CHANNEL_13_REG_INJ
  4075. * @arg @ref LL_ADC_AWD_CHANNEL_14_REG (0)
  4076. * @arg @ref LL_ADC_AWD_CHANNEL_14_INJ (0)
  4077. * @arg @ref LL_ADC_AWD_CHANNEL_14_REG_INJ
  4078. * @arg @ref LL_ADC_AWD_CHANNEL_15_REG (0)
  4079. * @arg @ref LL_ADC_AWD_CHANNEL_15_INJ (0)
  4080. * @arg @ref LL_ADC_AWD_CHANNEL_15_REG_INJ
  4081. * @arg @ref LL_ADC_AWD_CHANNEL_16_REG (0)
  4082. * @arg @ref LL_ADC_AWD_CHANNEL_16_INJ (0)
  4083. * @arg @ref LL_ADC_AWD_CHANNEL_16_REG_INJ
  4084. * @arg @ref LL_ADC_AWD_CHANNEL_17_REG (0)
  4085. * @arg @ref LL_ADC_AWD_CHANNEL_17_INJ (0)
  4086. * @arg @ref LL_ADC_AWD_CHANNEL_17_REG_INJ
  4087. * @arg @ref LL_ADC_AWD_CHANNEL_18_REG (0)
  4088. * @arg @ref LL_ADC_AWD_CHANNEL_18_INJ (0)
  4089. * @arg @ref LL_ADC_AWD_CHANNEL_18_REG_INJ
  4090. * @arg @ref LL_ADC_AWD_CH_VREFINT_REG (0)
  4091. * @arg @ref LL_ADC_AWD_CH_VREFINT_INJ (0)
  4092. * @arg @ref LL_ADC_AWD_CH_VREFINT_REG_INJ
  4093. * @arg @ref LL_ADC_AWD_CH_TEMPSENSOR_REG (0)
  4094. * @arg @ref LL_ADC_AWD_CH_TEMPSENSOR_INJ (0)
  4095. * @arg @ref LL_ADC_AWD_CH_TEMPSENSOR_REG_INJ
  4096. * @arg @ref LL_ADC_AWD_CH_VBAT_REG (0)
  4097. * @arg @ref LL_ADC_AWD_CH_VBAT_INJ (0)
  4098. * @arg @ref LL_ADC_AWD_CH_VBAT_REG_INJ
  4099. *
  4100. * (0) On STM32WB, parameter available only on analog watchdog number: AWD1.
  4101. * @retval None
  4102. */
  4103. __STATIC_INLINE void LL_ADC_SetAnalogWDMonitChannels(ADC_TypeDef *ADCx, uint32_t AWDy, uint32_t AWDChannelGroup)
  4104. {
  4105. /* Set bits with content of parameter "AWDChannelGroup" with bits position */
  4106. /* in register and register position depending on parameter "AWDy". */
  4107. /* Parameters "AWDChannelGroup" and "AWDy" are used with masks because */
  4108. /* containing other bits reserved for other purpose. */
  4109. register __IO uint32_t *preg = __ADC_PTR_REG_OFFSET(ADCx->CFGR, ((AWDy & ADC_AWD_CRX_REGOFFSET_MASK) >> ADC_AWD_CRX_REGOFFSET_POS)
  4110. + ((AWDy & ADC_AWD_CR12_REGOFFSETGAP_MASK) * ADC_AWD_CR12_REGOFFSETGAP_VAL));
  4111. MODIFY_REG(*preg,
  4112. (AWDy & ADC_AWD_CR_ALL_CHANNEL_MASK),
  4113. AWDChannelGroup & AWDy);
  4114. }
  4115. /**
  4116. * @brief Get ADC analog watchdog monitored channel.
  4117. * @note Usage of the returned channel number:
  4118. * - To reinject this channel into another function LL_ADC_xxx:
  4119. * the returned channel number is only partly formatted on definition
  4120. * of literals LL_ADC_CHANNEL_x. Therefore, it has to be compared
  4121. * with parts of literals LL_ADC_CHANNEL_x or using
  4122. * helper macro @ref __LL_ADC_CHANNEL_TO_DECIMAL_NB().
  4123. * Then the selected literal LL_ADC_CHANNEL_x can be used
  4124. * as parameter for another function.
  4125. * - To get the channel number in decimal format:
  4126. * process the returned value with the helper macro
  4127. * @ref __LL_ADC_CHANNEL_TO_DECIMAL_NB().
  4128. * Applicable only when the analog watchdog is set to monitor
  4129. * one channel.
  4130. * @note On this STM32 serie, there are 2 kinds of analog watchdog
  4131. * instance:
  4132. * - AWD standard (instance AWD1):
  4133. * - channels monitored: can monitor 1 channel or all channels.
  4134. * - groups monitored: ADC groups regular and-or injected.
  4135. * - resolution: resolution is not limited (corresponds to
  4136. * ADC resolution configured).
  4137. * - AWD flexible (instances AWD2, AWD3):
  4138. * - channels monitored: flexible on channels monitored, selection is
  4139. * channel wise, from from 1 to all channels.
  4140. * Specificity of this analog watchdog: Multiple channels can
  4141. * be selected. For example:
  4142. * (LL_ADC_AWD_CHANNEL4_REG_INJ | LL_ADC_AWD_CHANNEL5_REG_INJ | ...)
  4143. * - groups monitored: not selection possible (monitoring on both
  4144. * groups regular and injected).
  4145. * Channels selected are monitored on groups regular and injected:
  4146. * LL_ADC_AWD_CHANNELxx_REG_INJ (do not use parameters
  4147. * LL_ADC_AWD_CHANNELxx_REG and LL_ADC_AWD_CHANNELxx_INJ)
  4148. * - resolution: resolution is limited to 8 bits: if ADC resolution is
  4149. * 12 bits the 4 LSB are ignored, if ADC resolution is 10 bits
  4150. * the 2 LSB are ignored.
  4151. * @note On this STM32 serie, setting of this feature is conditioned to
  4152. * ADC state:
  4153. * ADC must be disabled or enabled without conversion on going
  4154. * on either groups regular or injected.
  4155. * @rmtoll CFGR AWD1CH LL_ADC_GetAnalogWDMonitChannels\n
  4156. * CFGR AWD1SGL LL_ADC_GetAnalogWDMonitChannels\n
  4157. * CFGR AWD1EN LL_ADC_GetAnalogWDMonitChannels\n
  4158. * CFGR JAWD1EN LL_ADC_GetAnalogWDMonitChannels\n
  4159. * AWD2CR AWD2CH LL_ADC_GetAnalogWDMonitChannels\n
  4160. * AWD3CR AWD3CH LL_ADC_GetAnalogWDMonitChannels
  4161. * @param ADCx ADC instance
  4162. * @param AWDy This parameter can be one of the following values:
  4163. * @arg @ref LL_ADC_AWD1
  4164. * @arg @ref LL_ADC_AWD2 (1)
  4165. * @arg @ref LL_ADC_AWD3 (1)
  4166. *
  4167. * (1) On this AWD number, monitored channel can be retrieved
  4168. * if only 1 channel is programmed (or none or all channels).
  4169. * This function cannot retrieve monitored channel if
  4170. * multiple channels are programmed simultaneously
  4171. * by bitfield.
  4172. * @retval Returned value can be one of the following values:
  4173. * @arg @ref LL_ADC_AWD_DISABLE
  4174. * @arg @ref LL_ADC_AWD_ALL_CHANNELS_REG (0)
  4175. * @arg @ref LL_ADC_AWD_ALL_CHANNELS_INJ (0)
  4176. * @arg @ref LL_ADC_AWD_ALL_CHANNELS_REG_INJ
  4177. * @arg @ref LL_ADC_AWD_CHANNEL_0_REG (0)
  4178. * @arg @ref LL_ADC_AWD_CHANNEL_0_INJ (0)
  4179. * @arg @ref LL_ADC_AWD_CHANNEL_0_REG_INJ
  4180. * @arg @ref LL_ADC_AWD_CHANNEL_1_REG (0)
  4181. * @arg @ref LL_ADC_AWD_CHANNEL_1_INJ (0)
  4182. * @arg @ref LL_ADC_AWD_CHANNEL_1_REG_INJ
  4183. * @arg @ref LL_ADC_AWD_CHANNEL_2_REG (0)
  4184. * @arg @ref LL_ADC_AWD_CHANNEL_2_INJ (0)
  4185. * @arg @ref LL_ADC_AWD_CHANNEL_2_REG_INJ
  4186. * @arg @ref LL_ADC_AWD_CHANNEL_3_REG (0)
  4187. * @arg @ref LL_ADC_AWD_CHANNEL_3_INJ (0)
  4188. * @arg @ref LL_ADC_AWD_CHANNEL_3_REG_INJ
  4189. * @arg @ref LL_ADC_AWD_CHANNEL_4_REG (0)
  4190. * @arg @ref LL_ADC_AWD_CHANNEL_4_INJ (0)
  4191. * @arg @ref LL_ADC_AWD_CHANNEL_4_REG_INJ
  4192. * @arg @ref LL_ADC_AWD_CHANNEL_5_REG (0)
  4193. * @arg @ref LL_ADC_AWD_CHANNEL_5_INJ (0)
  4194. * @arg @ref LL_ADC_AWD_CHANNEL_5_REG_INJ
  4195. * @arg @ref LL_ADC_AWD_CHANNEL_6_REG (0)
  4196. * @arg @ref LL_ADC_AWD_CHANNEL_6_INJ (0)
  4197. * @arg @ref LL_ADC_AWD_CHANNEL_6_REG_INJ
  4198. * @arg @ref LL_ADC_AWD_CHANNEL_7_REG (0)
  4199. * @arg @ref LL_ADC_AWD_CHANNEL_7_INJ (0)
  4200. * @arg @ref LL_ADC_AWD_CHANNEL_7_REG_INJ
  4201. * @arg @ref LL_ADC_AWD_CHANNEL_8_REG (0)
  4202. * @arg @ref LL_ADC_AWD_CHANNEL_8_INJ (0)
  4203. * @arg @ref LL_ADC_AWD_CHANNEL_8_REG_INJ
  4204. * @arg @ref LL_ADC_AWD_CHANNEL_9_REG (0)
  4205. * @arg @ref LL_ADC_AWD_CHANNEL_9_INJ (0)
  4206. * @arg @ref LL_ADC_AWD_CHANNEL_9_REG_INJ
  4207. * @arg @ref LL_ADC_AWD_CHANNEL_10_REG (0)
  4208. * @arg @ref LL_ADC_AWD_CHANNEL_10_INJ (0)
  4209. * @arg @ref LL_ADC_AWD_CHANNEL_10_REG_INJ
  4210. * @arg @ref LL_ADC_AWD_CHANNEL_11_REG (0)
  4211. * @arg @ref LL_ADC_AWD_CHANNEL_11_INJ (0)
  4212. * @arg @ref LL_ADC_AWD_CHANNEL_11_REG_INJ
  4213. * @arg @ref LL_ADC_AWD_CHANNEL_12_REG (0)
  4214. * @arg @ref LL_ADC_AWD_CHANNEL_12_INJ (0)
  4215. * @arg @ref LL_ADC_AWD_CHANNEL_12_REG_INJ
  4216. * @arg @ref LL_ADC_AWD_CHANNEL_13_REG (0)
  4217. * @arg @ref LL_ADC_AWD_CHANNEL_13_INJ (0)
  4218. * @arg @ref LL_ADC_AWD_CHANNEL_13_REG_INJ
  4219. * @arg @ref LL_ADC_AWD_CHANNEL_14_REG (0)
  4220. * @arg @ref LL_ADC_AWD_CHANNEL_14_INJ (0)
  4221. * @arg @ref LL_ADC_AWD_CHANNEL_14_REG_INJ
  4222. * @arg @ref LL_ADC_AWD_CHANNEL_15_REG (0)
  4223. * @arg @ref LL_ADC_AWD_CHANNEL_15_INJ (0)
  4224. * @arg @ref LL_ADC_AWD_CHANNEL_15_REG_INJ
  4225. * @arg @ref LL_ADC_AWD_CHANNEL_16_REG (0)
  4226. * @arg @ref LL_ADC_AWD_CHANNEL_16_INJ (0)
  4227. * @arg @ref LL_ADC_AWD_CHANNEL_16_REG_INJ
  4228. * @arg @ref LL_ADC_AWD_CHANNEL_17_REG (0)
  4229. * @arg @ref LL_ADC_AWD_CHANNEL_17_INJ (0)
  4230. * @arg @ref LL_ADC_AWD_CHANNEL_17_REG_INJ
  4231. * @arg @ref LL_ADC_AWD_CHANNEL_18_REG (0)
  4232. * @arg @ref LL_ADC_AWD_CHANNEL_18_INJ (0)
  4233. * @arg @ref LL_ADC_AWD_CHANNEL_18_REG_INJ
  4234. *
  4235. * (0) On STM32WB, parameter available only on analog watchdog number: AWD1.
  4236. */
  4237. __STATIC_INLINE uint32_t LL_ADC_GetAnalogWDMonitChannels(ADC_TypeDef *ADCx, uint32_t AWDy)
  4238. {
  4239. register const __IO uint32_t *preg = __ADC_PTR_REG_OFFSET(ADCx->CFGR, ((AWDy & ADC_AWD_CRX_REGOFFSET_MASK) >> ADC_AWD_CRX_REGOFFSET_POS)
  4240. + ((AWDy & ADC_AWD_CR12_REGOFFSETGAP_MASK) * ADC_AWD_CR12_REGOFFSETGAP_VAL));
  4241. register uint32_t AnalogWDMonitChannels = (READ_BIT(*preg, AWDy) & AWDy & ADC_AWD_CR_ALL_CHANNEL_MASK);
  4242. /* If "AnalogWDMonitChannels" == 0, then the selected AWD is disabled */
  4243. /* (parameter value LL_ADC_AWD_DISABLE). */
  4244. /* Else, the selected AWD is enabled and is monitoring a group of channels */
  4245. /* or a single channel. */
  4246. if (AnalogWDMonitChannels != 0UL)
  4247. {
  4248. if (AWDy == LL_ADC_AWD1)
  4249. {
  4250. if ((AnalogWDMonitChannels & ADC_CFGR_AWD1SGL) == 0UL)
  4251. {
  4252. /* AWD monitoring a group of channels */
  4253. AnalogWDMonitChannels = ((AnalogWDMonitChannels
  4254. | (ADC_AWD_CR23_CHANNEL_MASK)
  4255. )
  4256. & (~(ADC_CFGR_AWD1CH))
  4257. );
  4258. }
  4259. else
  4260. {
  4261. /* AWD monitoring a single channel */
  4262. AnalogWDMonitChannels = (AnalogWDMonitChannels
  4263. | (ADC_AWD2CR_AWD2CH_0 << (AnalogWDMonitChannels >> ADC_CFGR_AWD1CH_Pos))
  4264. );
  4265. }
  4266. }
  4267. else
  4268. {
  4269. if ((AnalogWDMonitChannels & ADC_AWD_CR23_CHANNEL_MASK) == ADC_AWD_CR23_CHANNEL_MASK)
  4270. {
  4271. /* AWD monitoring a group of channels */
  4272. AnalogWDMonitChannels = (ADC_AWD_CR23_CHANNEL_MASK
  4273. | ((ADC_CFGR_JAWD1EN | ADC_CFGR_AWD1EN))
  4274. );
  4275. }
  4276. else
  4277. {
  4278. /* AWD monitoring a single channel */
  4279. /* AWD monitoring a group of channels */
  4280. AnalogWDMonitChannels = (AnalogWDMonitChannels
  4281. | (ADC_CFGR_JAWD1EN | ADC_CFGR_AWD1EN | ADC_CFGR_AWD1SGL)
  4282. | (__LL_ADC_CHANNEL_TO_DECIMAL_NB(AnalogWDMonitChannels) << ADC_CFGR_AWD1CH_Pos)
  4283. );
  4284. }
  4285. }
  4286. }
  4287. return AnalogWDMonitChannels;
  4288. }
  4289. /**
  4290. * @brief Set ADC analog watchdog thresholds value of both thresholds
  4291. * high and low.
  4292. * @note If value of only one threshold high or low must be set,
  4293. * use function @ref LL_ADC_SetAnalogWDThresholds().
  4294. * @note In case of ADC resolution different of 12 bits,
  4295. * analog watchdog thresholds data require a specific shift.
  4296. * Use helper macro @ref __LL_ADC_ANALOGWD_SET_THRESHOLD_RESOLUTION().
  4297. * @note On this STM32 serie, there are 2 kinds of analog watchdog
  4298. * instance:
  4299. * - AWD standard (instance AWD1):
  4300. * - channels monitored: can monitor 1 channel or all channels.
  4301. * - groups monitored: ADC groups regular and-or injected.
  4302. * - resolution: resolution is not limited (corresponds to
  4303. * ADC resolution configured).
  4304. * - AWD flexible (instances AWD2, AWD3):
  4305. * - channels monitored: flexible on channels monitored, selection is
  4306. * channel wise, from from 1 to all channels.
  4307. * Specificity of this analog watchdog: Multiple channels can
  4308. * be selected. For example:
  4309. * (LL_ADC_AWD_CHANNEL4_REG_INJ | LL_ADC_AWD_CHANNEL5_REG_INJ | ...)
  4310. * - groups monitored: not selection possible (monitoring on both
  4311. * groups regular and injected).
  4312. * Channels selected are monitored on groups regular and injected:
  4313. * LL_ADC_AWD_CHANNELxx_REG_INJ (do not use parameters
  4314. * LL_ADC_AWD_CHANNELxx_REG and LL_ADC_AWD_CHANNELxx_INJ)
  4315. * - resolution: resolution is limited to 8 bits: if ADC resolution is
  4316. * 12 bits the 4 LSB are ignored, if ADC resolution is 10 bits
  4317. * the 2 LSB are ignored.
  4318. * @note If ADC oversampling is enabled, ADC analog watchdog thresholds are
  4319. * impacted: the comparison of analog watchdog thresholds is done on
  4320. * oversampling final computation (after ratio and shift application):
  4321. * ADC data register bitfield [15:4] (12 most significant bits).
  4322. * @note On this STM32 serie, setting of this feature is conditioned to
  4323. * ADC state:
  4324. * ADC must be disabled or enabled without conversion on going
  4325. * on either groups regular or injected.
  4326. * @rmtoll TR1 HT1 LL_ADC_ConfigAnalogWDThresholds\n
  4327. * TR2 HT2 LL_ADC_ConfigAnalogWDThresholds\n
  4328. * TR3 HT3 LL_ADC_ConfigAnalogWDThresholds\n
  4329. * TR1 LT1 LL_ADC_ConfigAnalogWDThresholds\n
  4330. * TR2 LT2 LL_ADC_ConfigAnalogWDThresholds\n
  4331. * TR3 LT3 LL_ADC_ConfigAnalogWDThresholds
  4332. * @param ADCx ADC instance
  4333. * @param AWDy This parameter can be one of the following values:
  4334. * @arg @ref LL_ADC_AWD1
  4335. * @arg @ref LL_ADC_AWD2
  4336. * @arg @ref LL_ADC_AWD3
  4337. * @param AWDThresholdHighValue Value between Min_Data=0x000 and Max_Data=0xFFF
  4338. * @param AWDThresholdLowValue Value between Min_Data=0x000 and Max_Data=0xFFF
  4339. * @retval None
  4340. */
  4341. __STATIC_INLINE void LL_ADC_ConfigAnalogWDThresholds(ADC_TypeDef *ADCx, uint32_t AWDy, uint32_t AWDThresholdHighValue,
  4342. uint32_t AWDThresholdLowValue)
  4343. {
  4344. /* Set bits with content of parameter "AWDThresholdxxxValue" with bits */
  4345. /* position in register and register position depending on parameter */
  4346. /* "AWDy". */
  4347. /* Parameters "AWDy" and "AWDThresholdxxxValue" are used with masks because */
  4348. /* containing other bits reserved for other purpose. */
  4349. register __IO uint32_t *preg = __ADC_PTR_REG_OFFSET(ADCx->TR1, ((AWDy & ADC_AWD_TRX_REGOFFSET_MASK) >> ADC_AWD_TRX_REGOFFSET_POS));
  4350. MODIFY_REG(*preg,
  4351. ADC_TR1_HT1 | ADC_TR1_LT1,
  4352. (AWDThresholdHighValue << ADC_TR1_HT1_BITOFFSET_POS) | AWDThresholdLowValue);
  4353. }
  4354. /**
  4355. * @brief Set ADC analog watchdog threshold value of threshold
  4356. * high or low.
  4357. * @note If values of both thresholds high or low must be set,
  4358. * use function @ref LL_ADC_ConfigAnalogWDThresholds().
  4359. * @note In case of ADC resolution different of 12 bits,
  4360. * analog watchdog thresholds data require a specific shift.
  4361. * Use helper macro @ref __LL_ADC_ANALOGWD_SET_THRESHOLD_RESOLUTION().
  4362. * @note On this STM32 serie, there are 2 kinds of analog watchdog
  4363. * instance:
  4364. * - AWD standard (instance AWD1):
  4365. * - channels monitored: can monitor 1 channel or all channels.
  4366. * - groups monitored: ADC groups regular and-or injected.
  4367. * - resolution: resolution is not limited (corresponds to
  4368. * ADC resolution configured).
  4369. * - AWD flexible (instances AWD2, AWD3):
  4370. * - channels monitored: flexible on channels monitored, selection is
  4371. * channel wise, from from 1 to all channels.
  4372. * Specificity of this analog watchdog: Multiple channels can
  4373. * be selected. For example:
  4374. * (LL_ADC_AWD_CHANNEL4_REG_INJ | LL_ADC_AWD_CHANNEL5_REG_INJ | ...)
  4375. * - groups monitored: not selection possible (monitoring on both
  4376. * groups regular and injected).
  4377. * Channels selected are monitored on groups regular and injected:
  4378. * LL_ADC_AWD_CHANNELxx_REG_INJ (do not use parameters
  4379. * LL_ADC_AWD_CHANNELxx_REG and LL_ADC_AWD_CHANNELxx_INJ)
  4380. * - resolution: resolution is limited to 8 bits: if ADC resolution is
  4381. * 12 bits the 4 LSB are ignored, if ADC resolution is 10 bits
  4382. * the 2 LSB are ignored.
  4383. * @note If ADC oversampling is enabled, ADC analog watchdog thresholds are
  4384. * impacted: the comparison of analog watchdog thresholds is done on
  4385. * oversampling final computation (after ratio and shift application):
  4386. * ADC data register bitfield [15:4] (12 most significant bits).
  4387. * @note On this STM32 serie, setting of this feature is conditioned to
  4388. * ADC state:
  4389. * ADC must be disabled or enabled without conversion on going
  4390. * on either ADC groups regular or injected.
  4391. * @rmtoll TR1 HT1 LL_ADC_SetAnalogWDThresholds\n
  4392. * TR2 HT2 LL_ADC_SetAnalogWDThresholds\n
  4393. * TR3 HT3 LL_ADC_SetAnalogWDThresholds\n
  4394. * TR1 LT1 LL_ADC_SetAnalogWDThresholds\n
  4395. * TR2 LT2 LL_ADC_SetAnalogWDThresholds\n
  4396. * TR3 LT3 LL_ADC_SetAnalogWDThresholds
  4397. * @param ADCx ADC instance
  4398. * @param AWDy This parameter can be one of the following values:
  4399. * @arg @ref LL_ADC_AWD1
  4400. * @arg @ref LL_ADC_AWD2
  4401. * @arg @ref LL_ADC_AWD3
  4402. * @param AWDThresholdsHighLow This parameter can be one of the following values:
  4403. * @arg @ref LL_ADC_AWD_THRESHOLD_HIGH
  4404. * @arg @ref LL_ADC_AWD_THRESHOLD_LOW
  4405. * @param AWDThresholdValue Value between Min_Data=0x000 and Max_Data=0xFFF
  4406. * @retval None
  4407. */
  4408. __STATIC_INLINE void LL_ADC_SetAnalogWDThresholds(ADC_TypeDef *ADCx, uint32_t AWDy, uint32_t AWDThresholdsHighLow,
  4409. uint32_t AWDThresholdValue)
  4410. {
  4411. /* Set bits with content of parameter "AWDThresholdValue" with bits */
  4412. /* position in register and register position depending on parameters */
  4413. /* "AWDThresholdsHighLow" and "AWDy". */
  4414. /* Parameters "AWDy" and "AWDThresholdValue" are used with masks because */
  4415. /* containing other bits reserved for other purpose. */
  4416. register __IO uint32_t *preg = __ADC_PTR_REG_OFFSET(ADCx->TR1, ((AWDy & ADC_AWD_TRX_REGOFFSET_MASK) >> ADC_AWD_TRX_REGOFFSET_POS));
  4417. MODIFY_REG(*preg,
  4418. AWDThresholdsHighLow,
  4419. AWDThresholdValue << ((AWDThresholdsHighLow & ADC_AWD_TRX_BIT_HIGH_MASK) >> ADC_AWD_TRX_BIT_HIGH_SHIFT4));
  4420. }
  4421. /**
  4422. * @brief Get ADC analog watchdog threshold value of threshold high,
  4423. * threshold low or raw data with ADC thresholds high and low
  4424. * concatenated.
  4425. * @note If raw data with ADC thresholds high and low is retrieved,
  4426. * the data of each threshold high or low can be isolated
  4427. * using helper macro:
  4428. * @ref __LL_ADC_ANALOGWD_THRESHOLDS_HIGH_LOW().
  4429. * @note In case of ADC resolution different of 12 bits,
  4430. * analog watchdog thresholds data require a specific shift.
  4431. * Use helper macro @ref __LL_ADC_ANALOGWD_GET_THRESHOLD_RESOLUTION().
  4432. * @rmtoll TR1 HT1 LL_ADC_GetAnalogWDThresholds\n
  4433. * TR2 HT2 LL_ADC_GetAnalogWDThresholds\n
  4434. * TR3 HT3 LL_ADC_GetAnalogWDThresholds\n
  4435. * TR1 LT1 LL_ADC_GetAnalogWDThresholds\n
  4436. * TR2 LT2 LL_ADC_GetAnalogWDThresholds\n
  4437. * TR3 LT3 LL_ADC_GetAnalogWDThresholds
  4438. * @param ADCx ADC instance
  4439. * @param AWDy This parameter can be one of the following values:
  4440. * @arg @ref LL_ADC_AWD1
  4441. * @arg @ref LL_ADC_AWD2
  4442. * @arg @ref LL_ADC_AWD3
  4443. * @param AWDThresholdsHighLow This parameter can be one of the following values:
  4444. * @arg @ref LL_ADC_AWD_THRESHOLD_HIGH
  4445. * @arg @ref LL_ADC_AWD_THRESHOLD_LOW
  4446. * @arg @ref LL_ADC_AWD_THRESHOLDS_HIGH_LOW
  4447. * @retval Value between Min_Data=0x000 and Max_Data=0xFFF
  4448. */
  4449. __STATIC_INLINE uint32_t LL_ADC_GetAnalogWDThresholds(ADC_TypeDef *ADCx, uint32_t AWDy, uint32_t AWDThresholdsHighLow)
  4450. {
  4451. register const __IO uint32_t *preg = __ADC_PTR_REG_OFFSET(ADCx->TR1, ((AWDy & ADC_AWD_TRX_REGOFFSET_MASK) >> ADC_AWD_TRX_REGOFFSET_POS));
  4452. return (uint32_t)(READ_BIT(*preg,
  4453. (AWDThresholdsHighLow | ADC_TR1_LT1))
  4454. >> (((AWDThresholdsHighLow & ADC_AWD_TRX_BIT_HIGH_MASK) >> ADC_AWD_TRX_BIT_HIGH_SHIFT4) & ~(AWDThresholdsHighLow & ADC_TR1_LT1))
  4455. );
  4456. }
  4457. /**
  4458. * @}
  4459. */
  4460. /** @defgroup ADC_LL_EF_Configuration_ADC_oversampling Configuration of ADC transversal scope: oversampling
  4461. * @{
  4462. */
  4463. /**
  4464. * @brief Set ADC oversampling scope: ADC groups regular and-or injected
  4465. * (availability of ADC group injected depends on STM32 families).
  4466. * @note If both groups regular and injected are selected,
  4467. * specify behavior of ADC group injected interrupting
  4468. * group regular: when ADC group injected is triggered,
  4469. * the oversampling on ADC group regular is either
  4470. * temporary stopped and continued, or resumed from start
  4471. * (oversampler buffer reset).
  4472. * @note On this STM32 serie, setting of this feature is conditioned to
  4473. * ADC state:
  4474. * ADC must be disabled or enabled without conversion on going
  4475. * on either groups regular or injected.
  4476. * @rmtoll CFGR2 ROVSE LL_ADC_SetOverSamplingScope\n
  4477. * CFGR2 JOVSE LL_ADC_SetOverSamplingScope\n
  4478. * CFGR2 ROVSM LL_ADC_SetOverSamplingScope
  4479. * @param ADCx ADC instance
  4480. * @param OvsScope This parameter can be one of the following values:
  4481. * @arg @ref LL_ADC_OVS_DISABLE
  4482. * @arg @ref LL_ADC_OVS_GRP_REGULAR_CONTINUED
  4483. * @arg @ref LL_ADC_OVS_GRP_REGULAR_RESUMED
  4484. * @arg @ref LL_ADC_OVS_GRP_INJECTED
  4485. * @arg @ref LL_ADC_OVS_GRP_INJ_REG_RESUMED
  4486. * @retval None
  4487. */
  4488. __STATIC_INLINE void LL_ADC_SetOverSamplingScope(ADC_TypeDef *ADCx, uint32_t OvsScope)
  4489. {
  4490. MODIFY_REG(ADCx->CFGR2, ADC_CFGR2_ROVSE | ADC_CFGR2_JOVSE | ADC_CFGR2_ROVSM, OvsScope);
  4491. }
  4492. /**
  4493. * @brief Get ADC oversampling scope: ADC groups regular and-or injected
  4494. * (availability of ADC group injected depends on STM32 families).
  4495. * @note If both groups regular and injected are selected,
  4496. * specify behavior of ADC group injected interrupting
  4497. * group regular: when ADC group injected is triggered,
  4498. * the oversampling on ADC group regular is either
  4499. * temporary stopped and continued, or resumed from start
  4500. * (oversampler buffer reset).
  4501. * @rmtoll CFGR2 ROVSE LL_ADC_GetOverSamplingScope\n
  4502. * CFGR2 JOVSE LL_ADC_GetOverSamplingScope\n
  4503. * CFGR2 ROVSM LL_ADC_GetOverSamplingScope
  4504. * @param ADCx ADC instance
  4505. * @retval Returned value can be one of the following values:
  4506. * @arg @ref LL_ADC_OVS_DISABLE
  4507. * @arg @ref LL_ADC_OVS_GRP_REGULAR_CONTINUED
  4508. * @arg @ref LL_ADC_OVS_GRP_REGULAR_RESUMED
  4509. * @arg @ref LL_ADC_OVS_GRP_INJECTED
  4510. * @arg @ref LL_ADC_OVS_GRP_INJ_REG_RESUMED
  4511. */
  4512. __STATIC_INLINE uint32_t LL_ADC_GetOverSamplingScope(ADC_TypeDef *ADCx)
  4513. {
  4514. return (uint32_t)(READ_BIT(ADCx->CFGR2, ADC_CFGR2_ROVSE | ADC_CFGR2_JOVSE | ADC_CFGR2_ROVSM));
  4515. }
  4516. /**
  4517. * @brief Set ADC oversampling discontinuous mode (triggered mode)
  4518. * on the selected ADC group.
  4519. * @note Number of oversampled conversions are done either in:
  4520. * - continuous mode (all conversions of oversampling ratio
  4521. * are done from 1 trigger)
  4522. * - discontinuous mode (each conversion of oversampling ratio
  4523. * needs a trigger)
  4524. * @note On this STM32 serie, setting of this feature is conditioned to
  4525. * ADC state:
  4526. * ADC must be disabled or enabled without conversion on going
  4527. * on group regular.
  4528. * @note On this STM32 serie, oversampling discontinuous mode
  4529. * (triggered mode) can be used only when oversampling is
  4530. * set on group regular only and in resumed mode.
  4531. * @rmtoll CFGR2 TROVS LL_ADC_SetOverSamplingDiscont
  4532. * @param ADCx ADC instance
  4533. * @param OverSamplingDiscont This parameter can be one of the following values:
  4534. * @arg @ref LL_ADC_OVS_REG_CONT
  4535. * @arg @ref LL_ADC_OVS_REG_DISCONT
  4536. * @retval None
  4537. */
  4538. __STATIC_INLINE void LL_ADC_SetOverSamplingDiscont(ADC_TypeDef *ADCx, uint32_t OverSamplingDiscont)
  4539. {
  4540. MODIFY_REG(ADCx->CFGR2, ADC_CFGR2_TROVS, OverSamplingDiscont);
  4541. }
  4542. /**
  4543. * @brief Get ADC oversampling discontinuous mode (triggered mode)
  4544. * on the selected ADC group.
  4545. * @note Number of oversampled conversions are done either in:
  4546. * - continuous mode (all conversions of oversampling ratio
  4547. * are done from 1 trigger)
  4548. * - discontinuous mode (each conversion of oversampling ratio
  4549. * needs a trigger)
  4550. * @rmtoll CFGR2 TROVS LL_ADC_GetOverSamplingDiscont
  4551. * @param ADCx ADC instance
  4552. * @retval Returned value can be one of the following values:
  4553. * @arg @ref LL_ADC_OVS_REG_CONT
  4554. * @arg @ref LL_ADC_OVS_REG_DISCONT
  4555. */
  4556. __STATIC_INLINE uint32_t LL_ADC_GetOverSamplingDiscont(ADC_TypeDef *ADCx)
  4557. {
  4558. return (uint32_t)(READ_BIT(ADCx->CFGR2, ADC_CFGR2_TROVS));
  4559. }
  4560. /**
  4561. * @brief Set ADC oversampling
  4562. * (impacting both ADC groups regular and injected)
  4563. * @note This function set the 2 items of oversampling configuration:
  4564. * - ratio
  4565. * - shift
  4566. * @note On this STM32 serie, setting of this feature is conditioned to
  4567. * ADC state:
  4568. * ADC must be disabled or enabled without conversion on going
  4569. * on either groups regular or injected.
  4570. * @rmtoll CFGR2 OVSS LL_ADC_ConfigOverSamplingRatioShift\n
  4571. * CFGR2 OVSR LL_ADC_ConfigOverSamplingRatioShift
  4572. * @param ADCx ADC instance
  4573. * @param Ratio This parameter can be one of the following values:
  4574. * @arg @ref LL_ADC_OVS_RATIO_2
  4575. * @arg @ref LL_ADC_OVS_RATIO_4
  4576. * @arg @ref LL_ADC_OVS_RATIO_8
  4577. * @arg @ref LL_ADC_OVS_RATIO_16
  4578. * @arg @ref LL_ADC_OVS_RATIO_32
  4579. * @arg @ref LL_ADC_OVS_RATIO_64
  4580. * @arg @ref LL_ADC_OVS_RATIO_128
  4581. * @arg @ref LL_ADC_OVS_RATIO_256
  4582. * @param Shift This parameter can be one of the following values:
  4583. * @arg @ref LL_ADC_OVS_SHIFT_NONE
  4584. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_1
  4585. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_2
  4586. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_3
  4587. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_4
  4588. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_5
  4589. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_6
  4590. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_7
  4591. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_8
  4592. * @retval None
  4593. */
  4594. __STATIC_INLINE void LL_ADC_ConfigOverSamplingRatioShift(ADC_TypeDef *ADCx, uint32_t Ratio, uint32_t Shift)
  4595. {
  4596. MODIFY_REG(ADCx->CFGR2, (ADC_CFGR2_OVSS | ADC_CFGR2_OVSR), (Shift | Ratio));
  4597. }
  4598. /**
  4599. * @brief Get ADC oversampling ratio
  4600. * (impacting both ADC groups regular and injected)
  4601. * @rmtoll CFGR2 OVSR LL_ADC_GetOverSamplingRatio
  4602. * @param ADCx ADC instance
  4603. * @retval Ratio This parameter can be one of the following values:
  4604. * @arg @ref LL_ADC_OVS_RATIO_2
  4605. * @arg @ref LL_ADC_OVS_RATIO_4
  4606. * @arg @ref LL_ADC_OVS_RATIO_8
  4607. * @arg @ref LL_ADC_OVS_RATIO_16
  4608. * @arg @ref LL_ADC_OVS_RATIO_32
  4609. * @arg @ref LL_ADC_OVS_RATIO_64
  4610. * @arg @ref LL_ADC_OVS_RATIO_128
  4611. * @arg @ref LL_ADC_OVS_RATIO_256
  4612. */
  4613. __STATIC_INLINE uint32_t LL_ADC_GetOverSamplingRatio(ADC_TypeDef *ADCx)
  4614. {
  4615. return (uint32_t)(READ_BIT(ADCx->CFGR2, ADC_CFGR2_OVSR));
  4616. }
  4617. /**
  4618. * @brief Get ADC oversampling shift
  4619. * (impacting both ADC groups regular and injected)
  4620. * @rmtoll CFGR2 OVSS LL_ADC_GetOverSamplingShift
  4621. * @param ADCx ADC instance
  4622. * @retval Shift This parameter can be one of the following values:
  4623. * @arg @ref LL_ADC_OVS_SHIFT_NONE
  4624. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_1
  4625. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_2
  4626. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_3
  4627. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_4
  4628. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_5
  4629. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_6
  4630. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_7
  4631. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_8
  4632. */
  4633. __STATIC_INLINE uint32_t LL_ADC_GetOverSamplingShift(ADC_TypeDef *ADCx)
  4634. {
  4635. return (uint32_t)(READ_BIT(ADCx->CFGR2, ADC_CFGR2_OVSS));
  4636. }
  4637. /**
  4638. * @}
  4639. */
  4640. /** @defgroup ADC_LL_EF_Operation_ADC_Instance Operation on ADC hierarchical scope: ADC instance
  4641. * @{
  4642. */
  4643. /**
  4644. * @brief Put ADC instance in deep power down state.
  4645. * @note In case of ADC calibration necessary: When ADC is in deep-power-down
  4646. * state, the internal analog calibration is lost. After exiting from
  4647. * deep power down, calibration must be relaunched or calibration factor
  4648. * (preliminarily saved) must be set back into calibration register.
  4649. * @note On this STM32 serie, setting of this feature is conditioned to
  4650. * ADC state:
  4651. * ADC must be ADC disabled.
  4652. * @rmtoll CR DEEPPWD LL_ADC_EnableDeepPowerDown
  4653. * @param ADCx ADC instance
  4654. * @retval None
  4655. */
  4656. __STATIC_INLINE void LL_ADC_EnableDeepPowerDown(ADC_TypeDef *ADCx)
  4657. {
  4658. /* Note: Write register with some additional bits forced to state reset */
  4659. /* instead of modifying only the selected bit for this function, */
  4660. /* to not interfere with bits with HW property "rs". */
  4661. MODIFY_REG(ADCx->CR,
  4662. ADC_CR_BITS_PROPERTY_RS,
  4663. ADC_CR_DEEPPWD);
  4664. }
  4665. /**
  4666. * @brief Disable ADC deep power down mode.
  4667. * @note In case of ADC calibration necessary: When ADC is in deep-power-down
  4668. * state, the internal analog calibration is lost. After exiting from
  4669. * deep power down, calibration must be relaunched or calibration factor
  4670. * (preliminarily saved) must be set back into calibration register.
  4671. * @note On this STM32 serie, setting of this feature is conditioned to
  4672. * ADC state:
  4673. * ADC must be ADC disabled.
  4674. * @rmtoll CR DEEPPWD LL_ADC_DisableDeepPowerDown
  4675. * @param ADCx ADC instance
  4676. * @retval None
  4677. */
  4678. __STATIC_INLINE void LL_ADC_DisableDeepPowerDown(ADC_TypeDef *ADCx)
  4679. {
  4680. /* Note: Write register with some additional bits forced to state reset */
  4681. /* instead of modifying only the selected bit for this function, */
  4682. /* to not interfere with bits with HW property "rs". */
  4683. CLEAR_BIT(ADCx->CR, (ADC_CR_DEEPPWD | ADC_CR_BITS_PROPERTY_RS));
  4684. }
  4685. /**
  4686. * @brief Get the selected ADC instance deep power down state.
  4687. * @rmtoll CR DEEPPWD LL_ADC_IsDeepPowerDownEnabled
  4688. * @param ADCx ADC instance
  4689. * @retval 0: deep power down is disabled, 1: deep power down is enabled.
  4690. */
  4691. __STATIC_INLINE uint32_t LL_ADC_IsDeepPowerDownEnabled(ADC_TypeDef *ADCx)
  4692. {
  4693. return ((READ_BIT(ADCx->CR, ADC_CR_DEEPPWD) == (ADC_CR_DEEPPWD)) ? 1UL : 0UL);
  4694. }
  4695. /**
  4696. * @brief Enable ADC instance internal voltage regulator.
  4697. * @note On this STM32 serie, after ADC internal voltage regulator enable,
  4698. * a delay for ADC internal voltage regulator stabilization
  4699. * is required before performing a ADC calibration or ADC enable.
  4700. * Refer to device datasheet, parameter tADCVREG_STUP.
  4701. * Refer to literal @ref LL_ADC_DELAY_INTERNAL_REGUL_STAB_US.
  4702. * @note On this STM32 serie, setting of this feature is conditioned to
  4703. * ADC state:
  4704. * ADC must be ADC disabled.
  4705. * @rmtoll CR ADVREGEN LL_ADC_EnableInternalRegulator
  4706. * @param ADCx ADC instance
  4707. * @retval None
  4708. */
  4709. __STATIC_INLINE void LL_ADC_EnableInternalRegulator(ADC_TypeDef *ADCx)
  4710. {
  4711. /* Note: Write register with some additional bits forced to state reset */
  4712. /* instead of modifying only the selected bit for this function, */
  4713. /* to not interfere with bits with HW property "rs". */
  4714. MODIFY_REG(ADCx->CR,
  4715. ADC_CR_BITS_PROPERTY_RS,
  4716. ADC_CR_ADVREGEN);
  4717. }
  4718. /**
  4719. * @brief Disable ADC internal voltage regulator.
  4720. * @note On this STM32 serie, setting of this feature is conditioned to
  4721. * ADC state:
  4722. * ADC must be ADC disabled.
  4723. * @rmtoll CR ADVREGEN LL_ADC_DisableInternalRegulator
  4724. * @param ADCx ADC instance
  4725. * @retval None
  4726. */
  4727. __STATIC_INLINE void LL_ADC_DisableInternalRegulator(ADC_TypeDef *ADCx)
  4728. {
  4729. CLEAR_BIT(ADCx->CR, (ADC_CR_ADVREGEN | ADC_CR_BITS_PROPERTY_RS));
  4730. }
  4731. /**
  4732. * @brief Get the selected ADC instance internal voltage regulator state.
  4733. * @rmtoll CR ADVREGEN LL_ADC_IsInternalRegulatorEnabled
  4734. * @param ADCx ADC instance
  4735. * @retval 0: internal regulator is disabled, 1: internal regulator is enabled.
  4736. */
  4737. __STATIC_INLINE uint32_t LL_ADC_IsInternalRegulatorEnabled(ADC_TypeDef *ADCx)
  4738. {
  4739. return ((READ_BIT(ADCx->CR, ADC_CR_ADVREGEN) == (ADC_CR_ADVREGEN)) ? 1UL : 0UL);
  4740. }
  4741. /**
  4742. * @brief Enable the selected ADC instance.
  4743. * @note On this STM32 serie, after ADC enable, a delay for
  4744. * ADC internal analog stabilization is required before performing a
  4745. * ADC conversion start.
  4746. * Refer to device datasheet, parameter tSTAB.
  4747. * @note On this STM32 serie, flag LL_ADC_FLAG_ADRDY is raised when the ADC
  4748. * is enabled and when conversion clock is active.
  4749. * (not only core clock: this ADC has a dual clock domain)
  4750. * @note On this STM32 serie, setting of this feature is conditioned to
  4751. * ADC state:
  4752. * ADC must be ADC disabled and ADC internal voltage regulator enabled.
  4753. * @rmtoll CR ADEN LL_ADC_Enable
  4754. * @param ADCx ADC instance
  4755. * @retval None
  4756. */
  4757. __STATIC_INLINE void LL_ADC_Enable(ADC_TypeDef *ADCx)
  4758. {
  4759. /* Note: Write register with some additional bits forced to state reset */
  4760. /* instead of modifying only the selected bit for this function, */
  4761. /* to not interfere with bits with HW property "rs". */
  4762. MODIFY_REG(ADCx->CR,
  4763. ADC_CR_BITS_PROPERTY_RS,
  4764. ADC_CR_ADEN);
  4765. }
  4766. /**
  4767. * @brief Disable the selected ADC instance.
  4768. * @note On this STM32 serie, setting of this feature is conditioned to
  4769. * ADC state:
  4770. * ADC must be not disabled. Must be enabled without conversion on going
  4771. * on either groups regular or injected.
  4772. * @rmtoll CR ADDIS LL_ADC_Disable
  4773. * @param ADCx ADC instance
  4774. * @retval None
  4775. */
  4776. __STATIC_INLINE void LL_ADC_Disable(ADC_TypeDef *ADCx)
  4777. {
  4778. /* Note: Write register with some additional bits forced to state reset */
  4779. /* instead of modifying only the selected bit for this function, */
  4780. /* to not interfere with bits with HW property "rs". */
  4781. MODIFY_REG(ADCx->CR,
  4782. ADC_CR_BITS_PROPERTY_RS,
  4783. ADC_CR_ADDIS);
  4784. }
  4785. /**
  4786. * @brief Get the selected ADC instance enable state.
  4787. * @note On this STM32 serie, flag LL_ADC_FLAG_ADRDY is raised when the ADC
  4788. * is enabled and when conversion clock is active.
  4789. * (not only core clock: this ADC has a dual clock domain)
  4790. * @rmtoll CR ADEN LL_ADC_IsEnabled
  4791. * @param ADCx ADC instance
  4792. * @retval 0: ADC is disabled, 1: ADC is enabled.
  4793. */
  4794. __STATIC_INLINE uint32_t LL_ADC_IsEnabled(ADC_TypeDef *ADCx)
  4795. {
  4796. return ((READ_BIT(ADCx->CR, ADC_CR_ADEN) == (ADC_CR_ADEN)) ? 1UL : 0UL);
  4797. }
  4798. /**
  4799. * @brief Get the selected ADC instance disable state.
  4800. * @rmtoll CR ADDIS LL_ADC_IsDisableOngoing
  4801. * @param ADCx ADC instance
  4802. * @retval 0: no ADC disable command on going.
  4803. */
  4804. __STATIC_INLINE uint32_t LL_ADC_IsDisableOngoing(ADC_TypeDef *ADCx)
  4805. {
  4806. return ((READ_BIT(ADCx->CR, ADC_CR_ADDIS) == (ADC_CR_ADDIS)) ? 1UL : 0UL);
  4807. }
  4808. /**
  4809. * @brief Start ADC calibration in the mode single-ended
  4810. * or differential (for devices with differential mode available).
  4811. * @note On this STM32 serie, a minimum number of ADC clock cycles
  4812. * are required between ADC end of calibration and ADC enable.
  4813. * Refer to literal @ref LL_ADC_DELAY_CALIB_ENABLE_ADC_CYCLES.
  4814. * @note For devices with differential mode available:
  4815. * Calibration of offset is specific to each of
  4816. * single-ended and differential modes
  4817. * (calibration run must be performed for each of these
  4818. * differential modes, if used afterwards and if the application
  4819. * requires their calibration).
  4820. * @note On this STM32 serie, setting of this feature is conditioned to
  4821. * ADC state:
  4822. * ADC must be ADC disabled.
  4823. * @rmtoll CR ADCAL LL_ADC_StartCalibration\n
  4824. * CR ADCALDIF LL_ADC_StartCalibration
  4825. * @param ADCx ADC instance
  4826. * @param SingleDiff This parameter can be one of the following values:
  4827. * @arg @ref LL_ADC_SINGLE_ENDED
  4828. * @arg @ref LL_ADC_DIFFERENTIAL_ENDED
  4829. * @retval None
  4830. */
  4831. __STATIC_INLINE void LL_ADC_StartCalibration(ADC_TypeDef *ADCx, uint32_t SingleDiff)
  4832. {
  4833. /* Note: Write register with some additional bits forced to state reset */
  4834. /* instead of modifying only the selected bit for this function, */
  4835. /* to not interfere with bits with HW property "rs". */
  4836. MODIFY_REG(ADCx->CR,
  4837. ADC_CR_ADCALDIF | ADC_CR_BITS_PROPERTY_RS,
  4838. ADC_CR_ADCAL | (SingleDiff & ADC_SINGLEDIFF_CALIB_START_MASK));
  4839. }
  4840. /**
  4841. * @brief Get ADC calibration state.
  4842. * @rmtoll CR ADCAL LL_ADC_IsCalibrationOnGoing
  4843. * @param ADCx ADC instance
  4844. * @retval 0: calibration complete, 1: calibration in progress.
  4845. */
  4846. __STATIC_INLINE uint32_t LL_ADC_IsCalibrationOnGoing(ADC_TypeDef *ADCx)
  4847. {
  4848. return ((READ_BIT(ADCx->CR, ADC_CR_ADCAL) == (ADC_CR_ADCAL)) ? 1UL : 0UL);
  4849. }
  4850. /**
  4851. * @}
  4852. */
  4853. /** @defgroup ADC_LL_EF_Operation_ADC_Group_Regular Operation on ADC hierarchical scope: group regular
  4854. * @{
  4855. */
  4856. /**
  4857. * @brief Start ADC group regular conversion.
  4858. * @note On this STM32 serie, this function is relevant for both
  4859. * internal trigger (SW start) and external trigger:
  4860. * - If ADC trigger has been set to software start, ADC conversion
  4861. * starts immediately.
  4862. * - If ADC trigger has been set to external trigger, ADC conversion
  4863. * will start at next trigger event (on the selected trigger edge)
  4864. * following the ADC start conversion command.
  4865. * @note On this STM32 serie, setting of this feature is conditioned to
  4866. * ADC state:
  4867. * ADC must be enabled without conversion on going on group regular,
  4868. * without conversion stop command on going on group regular,
  4869. * without ADC disable command on going.
  4870. * @rmtoll CR ADSTART LL_ADC_REG_StartConversion
  4871. * @param ADCx ADC instance
  4872. * @retval None
  4873. */
  4874. __STATIC_INLINE void LL_ADC_REG_StartConversion(ADC_TypeDef *ADCx)
  4875. {
  4876. /* Note: Write register with some additional bits forced to state reset */
  4877. /* instead of modifying only the selected bit for this function, */
  4878. /* to not interfere with bits with HW property "rs". */
  4879. MODIFY_REG(ADCx->CR,
  4880. ADC_CR_BITS_PROPERTY_RS,
  4881. ADC_CR_ADSTART);
  4882. }
  4883. /**
  4884. * @brief Stop ADC group regular conversion.
  4885. * @note On this STM32 serie, setting of this feature is conditioned to
  4886. * ADC state:
  4887. * ADC must be enabled with conversion on going on group regular,
  4888. * without ADC disable command on going.
  4889. * @rmtoll CR ADSTP LL_ADC_REG_StopConversion
  4890. * @param ADCx ADC instance
  4891. * @retval None
  4892. */
  4893. __STATIC_INLINE void LL_ADC_REG_StopConversion(ADC_TypeDef *ADCx)
  4894. {
  4895. /* Note: Write register with some additional bits forced to state reset */
  4896. /* instead of modifying only the selected bit for this function, */
  4897. /* to not interfere with bits with HW property "rs". */
  4898. MODIFY_REG(ADCx->CR,
  4899. ADC_CR_BITS_PROPERTY_RS,
  4900. ADC_CR_ADSTP);
  4901. }
  4902. /**
  4903. * @brief Get ADC group regular conversion state.
  4904. * @rmtoll CR ADSTART LL_ADC_REG_IsConversionOngoing
  4905. * @param ADCx ADC instance
  4906. * @retval 0: no conversion is on going on ADC group regular.
  4907. */
  4908. __STATIC_INLINE uint32_t LL_ADC_REG_IsConversionOngoing(ADC_TypeDef *ADCx)
  4909. {
  4910. return ((READ_BIT(ADCx->CR, ADC_CR_ADSTART) == (ADC_CR_ADSTART)) ? 1UL : 0UL);
  4911. }
  4912. /**
  4913. * @brief Get ADC group regular command of conversion stop state
  4914. * @rmtoll CR ADSTP LL_ADC_REG_IsStopConversionOngoing
  4915. * @param ADCx ADC instance
  4916. * @retval 0: no command of conversion stop is on going on ADC group regular.
  4917. */
  4918. __STATIC_INLINE uint32_t LL_ADC_REG_IsStopConversionOngoing(ADC_TypeDef *ADCx)
  4919. {
  4920. return ((READ_BIT(ADCx->CR, ADC_CR_ADSTP) == (ADC_CR_ADSTP)) ? 1UL : 0UL);
  4921. }
  4922. /**
  4923. * @brief Get ADC group regular conversion data, range fit for
  4924. * all ADC configurations: all ADC resolutions and
  4925. * all oversampling increased data width (for devices
  4926. * with feature oversampling).
  4927. * @rmtoll DR RDATA LL_ADC_REG_ReadConversionData32
  4928. * @param ADCx ADC instance
  4929. * @retval Value between Min_Data=0x00000000 and Max_Data=0xFFFFFFFF
  4930. */
  4931. __STATIC_INLINE uint32_t LL_ADC_REG_ReadConversionData32(ADC_TypeDef *ADCx)
  4932. {
  4933. return (uint32_t)(READ_BIT(ADCx->DR, ADC_DR_RDATA));
  4934. }
  4935. /**
  4936. * @brief Get ADC group regular conversion data, range fit for
  4937. * ADC resolution 12 bits.
  4938. * @note For devices with feature oversampling: Oversampling
  4939. * can increase data width, function for extended range
  4940. * may be needed: @ref LL_ADC_REG_ReadConversionData32.
  4941. * @rmtoll DR RDATA LL_ADC_REG_ReadConversionData12
  4942. * @param ADCx ADC instance
  4943. * @retval Value between Min_Data=0x000 and Max_Data=0xFFF
  4944. */
  4945. __STATIC_INLINE uint16_t LL_ADC_REG_ReadConversionData12(ADC_TypeDef *ADCx)
  4946. {
  4947. return (uint16_t)(READ_BIT(ADCx->DR, ADC_DR_RDATA));
  4948. }
  4949. /**
  4950. * @brief Get ADC group regular conversion data, range fit for
  4951. * ADC resolution 10 bits.
  4952. * @note For devices with feature oversampling: Oversampling
  4953. * can increase data width, function for extended range
  4954. * may be needed: @ref LL_ADC_REG_ReadConversionData32.
  4955. * @rmtoll DR RDATA LL_ADC_REG_ReadConversionData10
  4956. * @param ADCx ADC instance
  4957. * @retval Value between Min_Data=0x000 and Max_Data=0x3FF
  4958. */
  4959. __STATIC_INLINE uint16_t LL_ADC_REG_ReadConversionData10(ADC_TypeDef *ADCx)
  4960. {
  4961. return (uint16_t)(READ_BIT(ADCx->DR, ADC_DR_RDATA));
  4962. }
  4963. /**
  4964. * @brief Get ADC group regular conversion data, range fit for
  4965. * ADC resolution 8 bits.
  4966. * @note For devices with feature oversampling: Oversampling
  4967. * can increase data width, function for extended range
  4968. * may be needed: @ref LL_ADC_REG_ReadConversionData32.
  4969. * @rmtoll DR RDATA LL_ADC_REG_ReadConversionData8
  4970. * @param ADCx ADC instance
  4971. * @retval Value between Min_Data=0x00 and Max_Data=0xFF
  4972. */
  4973. __STATIC_INLINE uint8_t LL_ADC_REG_ReadConversionData8(ADC_TypeDef *ADCx)
  4974. {
  4975. return (uint8_t)(READ_BIT(ADCx->DR, ADC_DR_RDATA));
  4976. }
  4977. /**
  4978. * @brief Get ADC group regular conversion data, range fit for
  4979. * ADC resolution 6 bits.
  4980. * @note For devices with feature oversampling: Oversampling
  4981. * can increase data width, function for extended range
  4982. * may be needed: @ref LL_ADC_REG_ReadConversionData32.
  4983. * @rmtoll DR RDATA LL_ADC_REG_ReadConversionData6
  4984. * @param ADCx ADC instance
  4985. * @retval Value between Min_Data=0x00 and Max_Data=0x3F
  4986. */
  4987. __STATIC_INLINE uint8_t LL_ADC_REG_ReadConversionData6(ADC_TypeDef *ADCx)
  4988. {
  4989. return (uint8_t)(READ_BIT(ADCx->DR, ADC_DR_RDATA));
  4990. }
  4991. /**
  4992. * @}
  4993. */
  4994. /** @defgroup ADC_LL_EF_Operation_ADC_Group_Injected Operation on ADC hierarchical scope: group injected
  4995. * @{
  4996. */
  4997. /**
  4998. * @brief Start ADC group injected conversion.
  4999. * @note On this STM32 serie, this function is relevant for both
  5000. * internal trigger (SW start) and external trigger:
  5001. * - If ADC trigger has been set to software start, ADC conversion
  5002. * starts immediately.
  5003. * - If ADC trigger has been set to external trigger, ADC conversion
  5004. * will start at next trigger event (on the selected trigger edge)
  5005. * following the ADC start conversion command.
  5006. * @note On this STM32 serie, setting of this feature is conditioned to
  5007. * ADC state:
  5008. * ADC must be enabled without conversion on going on group injected,
  5009. * without conversion stop command on going on group injected,
  5010. * without ADC disable command on going.
  5011. * @rmtoll CR JADSTART LL_ADC_INJ_StartConversion
  5012. * @param ADCx ADC instance
  5013. * @retval None
  5014. */
  5015. __STATIC_INLINE void LL_ADC_INJ_StartConversion(ADC_TypeDef *ADCx)
  5016. {
  5017. /* Note: Write register with some additional bits forced to state reset */
  5018. /* instead of modifying only the selected bit for this function, */
  5019. /* to not interfere with bits with HW property "rs". */
  5020. MODIFY_REG(ADCx->CR,
  5021. ADC_CR_BITS_PROPERTY_RS,
  5022. ADC_CR_JADSTART);
  5023. }
  5024. /**
  5025. * @brief Stop ADC group injected conversion.
  5026. * @note On this STM32 serie, setting of this feature is conditioned to
  5027. * ADC state:
  5028. * ADC must be enabled with conversion on going on group injected,
  5029. * without ADC disable command on going.
  5030. * @rmtoll CR JADSTP LL_ADC_INJ_StopConversion
  5031. * @param ADCx ADC instance
  5032. * @retval None
  5033. */
  5034. __STATIC_INLINE void LL_ADC_INJ_StopConversion(ADC_TypeDef *ADCx)
  5035. {
  5036. /* Note: Write register with some additional bits forced to state reset */
  5037. /* instead of modifying only the selected bit for this function, */
  5038. /* to not interfere with bits with HW property "rs". */
  5039. MODIFY_REG(ADCx->CR,
  5040. ADC_CR_BITS_PROPERTY_RS,
  5041. ADC_CR_JADSTP);
  5042. }
  5043. /**
  5044. * @brief Get ADC group injected conversion state.
  5045. * @rmtoll CR JADSTART LL_ADC_INJ_IsConversionOngoing
  5046. * @param ADCx ADC instance
  5047. * @retval 0: no conversion is on going on ADC group injected.
  5048. */
  5049. __STATIC_INLINE uint32_t LL_ADC_INJ_IsConversionOngoing(ADC_TypeDef *ADCx)
  5050. {
  5051. return ((READ_BIT(ADCx->CR, ADC_CR_JADSTART) == (ADC_CR_JADSTART)) ? 1UL : 0UL);
  5052. }
  5053. /**
  5054. * @brief Get ADC group injected command of conversion stop state
  5055. * @rmtoll CR JADSTP LL_ADC_INJ_IsStopConversionOngoing
  5056. * @param ADCx ADC instance
  5057. * @retval 0: no command of conversion stop is on going on ADC group injected.
  5058. */
  5059. __STATIC_INLINE uint32_t LL_ADC_INJ_IsStopConversionOngoing(ADC_TypeDef *ADCx)
  5060. {
  5061. return ((READ_BIT(ADCx->CR, ADC_CR_JADSTP) == (ADC_CR_JADSTP)) ? 1UL : 0UL);
  5062. }
  5063. /**
  5064. * @brief Get ADC group injected conversion data, range fit for
  5065. * all ADC configurations: all ADC resolutions and
  5066. * all oversampling increased data width (for devices
  5067. * with feature oversampling).
  5068. * @rmtoll JDR1 JDATA LL_ADC_INJ_ReadConversionData32\n
  5069. * JDR2 JDATA LL_ADC_INJ_ReadConversionData32\n
  5070. * JDR3 JDATA LL_ADC_INJ_ReadConversionData32\n
  5071. * JDR4 JDATA LL_ADC_INJ_ReadConversionData32
  5072. * @param ADCx ADC instance
  5073. * @param Rank This parameter can be one of the following values:
  5074. * @arg @ref LL_ADC_INJ_RANK_1
  5075. * @arg @ref LL_ADC_INJ_RANK_2
  5076. * @arg @ref LL_ADC_INJ_RANK_3
  5077. * @arg @ref LL_ADC_INJ_RANK_4
  5078. * @retval Value between Min_Data=0x00000000 and Max_Data=0xFFFFFFFF
  5079. */
  5080. __STATIC_INLINE uint32_t LL_ADC_INJ_ReadConversionData32(ADC_TypeDef *ADCx, uint32_t Rank)
  5081. {
  5082. register const __IO uint32_t *preg = __ADC_PTR_REG_OFFSET(ADCx->JDR1, ((Rank & ADC_INJ_JDRX_REGOFFSET_MASK) >> ADC_JDRX_REGOFFSET_POS));
  5083. return (uint32_t)(READ_BIT(*preg,
  5084. ADC_JDR1_JDATA)
  5085. );
  5086. }
  5087. /**
  5088. * @brief Get ADC group injected conversion data, range fit for
  5089. * ADC resolution 12 bits.
  5090. * @note For devices with feature oversampling: Oversampling
  5091. * can increase data width, function for extended range
  5092. * may be needed: @ref LL_ADC_INJ_ReadConversionData32.
  5093. * @rmtoll JDR1 JDATA LL_ADC_INJ_ReadConversionData12\n
  5094. * JDR2 JDATA LL_ADC_INJ_ReadConversionData12\n
  5095. * JDR3 JDATA LL_ADC_INJ_ReadConversionData12\n
  5096. * JDR4 JDATA LL_ADC_INJ_ReadConversionData12
  5097. * @param ADCx ADC instance
  5098. * @param Rank This parameter can be one of the following values:
  5099. * @arg @ref LL_ADC_INJ_RANK_1
  5100. * @arg @ref LL_ADC_INJ_RANK_2
  5101. * @arg @ref LL_ADC_INJ_RANK_3
  5102. * @arg @ref LL_ADC_INJ_RANK_4
  5103. * @retval Value between Min_Data=0x000 and Max_Data=0xFFF
  5104. */
  5105. __STATIC_INLINE uint16_t LL_ADC_INJ_ReadConversionData12(ADC_TypeDef *ADCx, uint32_t Rank)
  5106. {
  5107. register const __IO uint32_t *preg = __ADC_PTR_REG_OFFSET(ADCx->JDR1, ((Rank & ADC_INJ_JDRX_REGOFFSET_MASK) >> ADC_JDRX_REGOFFSET_POS));
  5108. return (uint16_t)(READ_BIT(*preg,
  5109. ADC_JDR1_JDATA)
  5110. );
  5111. }
  5112. /**
  5113. * @brief Get ADC group injected conversion data, range fit for
  5114. * ADC resolution 10 bits.
  5115. * @note For devices with feature oversampling: Oversampling
  5116. * can increase data width, function for extended range
  5117. * may be needed: @ref LL_ADC_INJ_ReadConversionData32.
  5118. * @rmtoll JDR1 JDATA LL_ADC_INJ_ReadConversionData10\n
  5119. * JDR2 JDATA LL_ADC_INJ_ReadConversionData10\n
  5120. * JDR3 JDATA LL_ADC_INJ_ReadConversionData10\n
  5121. * JDR4 JDATA LL_ADC_INJ_ReadConversionData10
  5122. * @param ADCx ADC instance
  5123. * @param Rank This parameter can be one of the following values:
  5124. * @arg @ref LL_ADC_INJ_RANK_1
  5125. * @arg @ref LL_ADC_INJ_RANK_2
  5126. * @arg @ref LL_ADC_INJ_RANK_3
  5127. * @arg @ref LL_ADC_INJ_RANK_4
  5128. * @retval Value between Min_Data=0x000 and Max_Data=0x3FF
  5129. */
  5130. __STATIC_INLINE uint16_t LL_ADC_INJ_ReadConversionData10(ADC_TypeDef *ADCx, uint32_t Rank)
  5131. {
  5132. register const __IO uint32_t *preg = __ADC_PTR_REG_OFFSET(ADCx->JDR1, ((Rank & ADC_INJ_JDRX_REGOFFSET_MASK) >> ADC_JDRX_REGOFFSET_POS));
  5133. return (uint16_t)(READ_BIT(*preg,
  5134. ADC_JDR1_JDATA)
  5135. );
  5136. }
  5137. /**
  5138. * @brief Get ADC group injected conversion data, range fit for
  5139. * ADC resolution 8 bits.
  5140. * @note For devices with feature oversampling: Oversampling
  5141. * can increase data width, function for extended range
  5142. * may be needed: @ref LL_ADC_INJ_ReadConversionData32.
  5143. * @rmtoll JDR1 JDATA LL_ADC_INJ_ReadConversionData8\n
  5144. * JDR2 JDATA LL_ADC_INJ_ReadConversionData8\n
  5145. * JDR3 JDATA LL_ADC_INJ_ReadConversionData8\n
  5146. * JDR4 JDATA LL_ADC_INJ_ReadConversionData8
  5147. * @param ADCx ADC instance
  5148. * @param Rank This parameter can be one of the following values:
  5149. * @arg @ref LL_ADC_INJ_RANK_1
  5150. * @arg @ref LL_ADC_INJ_RANK_2
  5151. * @arg @ref LL_ADC_INJ_RANK_3
  5152. * @arg @ref LL_ADC_INJ_RANK_4
  5153. * @retval Value between Min_Data=0x00 and Max_Data=0xFF
  5154. */
  5155. __STATIC_INLINE uint8_t LL_ADC_INJ_ReadConversionData8(ADC_TypeDef *ADCx, uint32_t Rank)
  5156. {
  5157. register const __IO uint32_t *preg = __ADC_PTR_REG_OFFSET(ADCx->JDR1, ((Rank & ADC_INJ_JDRX_REGOFFSET_MASK) >> ADC_JDRX_REGOFFSET_POS));
  5158. return (uint8_t)(READ_BIT(*preg,
  5159. ADC_JDR1_JDATA)
  5160. );
  5161. }
  5162. /**
  5163. * @brief Get ADC group injected conversion data, range fit for
  5164. * ADC resolution 6 bits.
  5165. * @note For devices with feature oversampling: Oversampling
  5166. * can increase data width, function for extended range
  5167. * may be needed: @ref LL_ADC_INJ_ReadConversionData32.
  5168. * @rmtoll JDR1 JDATA LL_ADC_INJ_ReadConversionData6\n
  5169. * JDR2 JDATA LL_ADC_INJ_ReadConversionData6\n
  5170. * JDR3 JDATA LL_ADC_INJ_ReadConversionData6\n
  5171. * JDR4 JDATA LL_ADC_INJ_ReadConversionData6
  5172. * @param ADCx ADC instance
  5173. * @param Rank This parameter can be one of the following values:
  5174. * @arg @ref LL_ADC_INJ_RANK_1
  5175. * @arg @ref LL_ADC_INJ_RANK_2
  5176. * @arg @ref LL_ADC_INJ_RANK_3
  5177. * @arg @ref LL_ADC_INJ_RANK_4
  5178. * @retval Value between Min_Data=0x00 and Max_Data=0x3F
  5179. */
  5180. __STATIC_INLINE uint8_t LL_ADC_INJ_ReadConversionData6(ADC_TypeDef *ADCx, uint32_t Rank)
  5181. {
  5182. register const __IO uint32_t *preg = __ADC_PTR_REG_OFFSET(ADCx->JDR1, ((Rank & ADC_INJ_JDRX_REGOFFSET_MASK) >> ADC_JDRX_REGOFFSET_POS));
  5183. return (uint8_t)(READ_BIT(*preg,
  5184. ADC_JDR1_JDATA)
  5185. );
  5186. }
  5187. /**
  5188. * @}
  5189. */
  5190. /** @defgroup ADC_LL_EF_FLAG_Management ADC flag management
  5191. * @{
  5192. */
  5193. /**
  5194. * @brief Get flag ADC ready.
  5195. * @note On this STM32 serie, flag LL_ADC_FLAG_ADRDY is raised when the ADC
  5196. * is enabled and when conversion clock is active.
  5197. * (not only core clock: this ADC has a dual clock domain)
  5198. * @rmtoll ISR ADRDY LL_ADC_IsActiveFlag_ADRDY
  5199. * @param ADCx ADC instance
  5200. * @retval State of bit (1 or 0).
  5201. */
  5202. __STATIC_INLINE uint32_t LL_ADC_IsActiveFlag_ADRDY(ADC_TypeDef *ADCx)
  5203. {
  5204. return ((READ_BIT(ADCx->ISR, LL_ADC_FLAG_ADRDY) == (LL_ADC_FLAG_ADRDY)) ? 1UL : 0UL);
  5205. }
  5206. /**
  5207. * @brief Get flag ADC group regular end of unitary conversion.
  5208. * @rmtoll ISR EOC LL_ADC_IsActiveFlag_EOC
  5209. * @param ADCx ADC instance
  5210. * @retval State of bit (1 or 0).
  5211. */
  5212. __STATIC_INLINE uint32_t LL_ADC_IsActiveFlag_EOC(ADC_TypeDef *ADCx)
  5213. {
  5214. return ((READ_BIT(ADCx->ISR, ADC_ISR_EOC) == (ADC_ISR_EOC)) ? 1UL : 0UL);
  5215. }
  5216. /**
  5217. * @brief Get flag ADC group regular end of sequence conversions.
  5218. * @rmtoll ISR EOS LL_ADC_IsActiveFlag_EOS
  5219. * @param ADCx ADC instance
  5220. * @retval State of bit (1 or 0).
  5221. */
  5222. __STATIC_INLINE uint32_t LL_ADC_IsActiveFlag_EOS(ADC_TypeDef *ADCx)
  5223. {
  5224. return ((READ_BIT(ADCx->ISR, LL_ADC_FLAG_EOS) == (LL_ADC_FLAG_EOS)) ? 1UL : 0UL);
  5225. }
  5226. /**
  5227. * @brief Get flag ADC group regular overrun.
  5228. * @rmtoll ISR OVR LL_ADC_IsActiveFlag_OVR
  5229. * @param ADCx ADC instance
  5230. * @retval State of bit (1 or 0).
  5231. */
  5232. __STATIC_INLINE uint32_t LL_ADC_IsActiveFlag_OVR(ADC_TypeDef *ADCx)
  5233. {
  5234. return ((READ_BIT(ADCx->ISR, LL_ADC_FLAG_OVR) == (LL_ADC_FLAG_OVR)) ? 1UL : 0UL);
  5235. }
  5236. /**
  5237. * @brief Get flag ADC group regular end of sampling phase.
  5238. * @rmtoll ISR EOSMP LL_ADC_IsActiveFlag_EOSMP
  5239. * @param ADCx ADC instance
  5240. * @retval State of bit (1 or 0).
  5241. */
  5242. __STATIC_INLINE uint32_t LL_ADC_IsActiveFlag_EOSMP(ADC_TypeDef *ADCx)
  5243. {
  5244. return ((READ_BIT(ADCx->ISR, LL_ADC_FLAG_EOSMP) == (LL_ADC_FLAG_EOSMP)) ? 1UL : 0UL);
  5245. }
  5246. /**
  5247. * @brief Get flag ADC group injected end of unitary conversion.
  5248. * @rmtoll ISR JEOC LL_ADC_IsActiveFlag_JEOC
  5249. * @param ADCx ADC instance
  5250. * @retval State of bit (1 or 0).
  5251. */
  5252. __STATIC_INLINE uint32_t LL_ADC_IsActiveFlag_JEOC(ADC_TypeDef *ADCx)
  5253. {
  5254. return ((READ_BIT(ADCx->ISR, LL_ADC_FLAG_JEOC) == (LL_ADC_FLAG_JEOC)) ? 1UL : 0UL);
  5255. }
  5256. /**
  5257. * @brief Get flag ADC group injected end of sequence conversions.
  5258. * @rmtoll ISR JEOS LL_ADC_IsActiveFlag_JEOS
  5259. * @param ADCx ADC instance
  5260. * @retval State of bit (1 or 0).
  5261. */
  5262. __STATIC_INLINE uint32_t LL_ADC_IsActiveFlag_JEOS(ADC_TypeDef *ADCx)
  5263. {
  5264. return ((READ_BIT(ADCx->ISR, LL_ADC_FLAG_JEOS) == (LL_ADC_FLAG_JEOS)) ? 1UL : 0UL);
  5265. }
  5266. /**
  5267. * @brief Get flag ADC group injected contexts queue overflow.
  5268. * @rmtoll ISR JQOVF LL_ADC_IsActiveFlag_JQOVF
  5269. * @param ADCx ADC instance
  5270. * @retval State of bit (1 or 0).
  5271. */
  5272. __STATIC_INLINE uint32_t LL_ADC_IsActiveFlag_JQOVF(ADC_TypeDef *ADCx)
  5273. {
  5274. return ((READ_BIT(ADCx->ISR, LL_ADC_FLAG_JQOVF) == (LL_ADC_FLAG_JQOVF)) ? 1UL : 0UL);
  5275. }
  5276. /**
  5277. * @brief Get flag ADC analog watchdog 1 flag
  5278. * @rmtoll ISR AWD1 LL_ADC_IsActiveFlag_AWD1
  5279. * @param ADCx ADC instance
  5280. * @retval State of bit (1 or 0).
  5281. */
  5282. __STATIC_INLINE uint32_t LL_ADC_IsActiveFlag_AWD1(ADC_TypeDef *ADCx)
  5283. {
  5284. return ((READ_BIT(ADCx->ISR, LL_ADC_FLAG_AWD1) == (LL_ADC_FLAG_AWD1)) ? 1UL : 0UL);
  5285. }
  5286. /**
  5287. * @brief Get flag ADC analog watchdog 2.
  5288. * @rmtoll ISR AWD2 LL_ADC_IsActiveFlag_AWD2
  5289. * @param ADCx ADC instance
  5290. * @retval State of bit (1 or 0).
  5291. */
  5292. __STATIC_INLINE uint32_t LL_ADC_IsActiveFlag_AWD2(ADC_TypeDef *ADCx)
  5293. {
  5294. return ((READ_BIT(ADCx->ISR, LL_ADC_FLAG_AWD2) == (LL_ADC_FLAG_AWD2)) ? 1UL : 0UL);
  5295. }
  5296. /**
  5297. * @brief Get flag ADC analog watchdog 3.
  5298. * @rmtoll ISR AWD3 LL_ADC_IsActiveFlag_AWD3
  5299. * @param ADCx ADC instance
  5300. * @retval State of bit (1 or 0).
  5301. */
  5302. __STATIC_INLINE uint32_t LL_ADC_IsActiveFlag_AWD3(ADC_TypeDef *ADCx)
  5303. {
  5304. return ((READ_BIT(ADCx->ISR, LL_ADC_FLAG_AWD3) == (LL_ADC_FLAG_AWD3)) ? 1UL : 0UL);
  5305. }
  5306. /**
  5307. * @brief Clear flag ADC ready.
  5308. * @note On this STM32 serie, flag LL_ADC_FLAG_ADRDY is raised when the ADC
  5309. * is enabled and when conversion clock is active.
  5310. * (not only core clock: this ADC has a dual clock domain)
  5311. * @rmtoll ISR ADRDY LL_ADC_ClearFlag_ADRDY
  5312. * @param ADCx ADC instance
  5313. * @retval None
  5314. */
  5315. __STATIC_INLINE void LL_ADC_ClearFlag_ADRDY(ADC_TypeDef *ADCx)
  5316. {
  5317. WRITE_REG(ADCx->ISR, LL_ADC_FLAG_ADRDY);
  5318. }
  5319. /**
  5320. * @brief Clear flag ADC group regular end of unitary conversion.
  5321. * @rmtoll ISR EOC LL_ADC_ClearFlag_EOC
  5322. * @param ADCx ADC instance
  5323. * @retval None
  5324. */
  5325. __STATIC_INLINE void LL_ADC_ClearFlag_EOC(ADC_TypeDef *ADCx)
  5326. {
  5327. WRITE_REG(ADCx->ISR, LL_ADC_FLAG_EOC);
  5328. }
  5329. /**
  5330. * @brief Clear flag ADC group regular end of sequence conversions.
  5331. * @rmtoll ISR EOS LL_ADC_ClearFlag_EOS
  5332. * @param ADCx ADC instance
  5333. * @retval None
  5334. */
  5335. __STATIC_INLINE void LL_ADC_ClearFlag_EOS(ADC_TypeDef *ADCx)
  5336. {
  5337. WRITE_REG(ADCx->ISR, LL_ADC_FLAG_EOS);
  5338. }
  5339. /**
  5340. * @brief Clear flag ADC group regular overrun.
  5341. * @rmtoll ISR OVR LL_ADC_ClearFlag_OVR
  5342. * @param ADCx ADC instance
  5343. * @retval None
  5344. */
  5345. __STATIC_INLINE void LL_ADC_ClearFlag_OVR(ADC_TypeDef *ADCx)
  5346. {
  5347. WRITE_REG(ADCx->ISR, LL_ADC_FLAG_OVR);
  5348. }
  5349. /**
  5350. * @brief Clear flag ADC group regular end of sampling phase.
  5351. * @rmtoll ISR EOSMP LL_ADC_ClearFlag_EOSMP
  5352. * @param ADCx ADC instance
  5353. * @retval None
  5354. */
  5355. __STATIC_INLINE void LL_ADC_ClearFlag_EOSMP(ADC_TypeDef *ADCx)
  5356. {
  5357. WRITE_REG(ADCx->ISR, LL_ADC_FLAG_EOSMP);
  5358. }
  5359. /**
  5360. * @brief Clear flag ADC group injected end of unitary conversion.
  5361. * @rmtoll ISR JEOC LL_ADC_ClearFlag_JEOC
  5362. * @param ADCx ADC instance
  5363. * @retval None
  5364. */
  5365. __STATIC_INLINE void LL_ADC_ClearFlag_JEOC(ADC_TypeDef *ADCx)
  5366. {
  5367. WRITE_REG(ADCx->ISR, LL_ADC_FLAG_JEOC);
  5368. }
  5369. /**
  5370. * @brief Clear flag ADC group injected end of sequence conversions.
  5371. * @rmtoll ISR JEOS LL_ADC_ClearFlag_JEOS
  5372. * @param ADCx ADC instance
  5373. * @retval None
  5374. */
  5375. __STATIC_INLINE void LL_ADC_ClearFlag_JEOS(ADC_TypeDef *ADCx)
  5376. {
  5377. WRITE_REG(ADCx->ISR, LL_ADC_FLAG_JEOS);
  5378. }
  5379. /**
  5380. * @brief Clear flag ADC group injected contexts queue overflow.
  5381. * @rmtoll ISR JQOVF LL_ADC_ClearFlag_JQOVF
  5382. * @param ADCx ADC instance
  5383. * @retval None
  5384. */
  5385. __STATIC_INLINE void LL_ADC_ClearFlag_JQOVF(ADC_TypeDef *ADCx)
  5386. {
  5387. WRITE_REG(ADCx->ISR, LL_ADC_FLAG_JQOVF);
  5388. }
  5389. /**
  5390. * @brief Clear flag ADC analog watchdog 1.
  5391. * @rmtoll ISR AWD1 LL_ADC_ClearFlag_AWD1
  5392. * @param ADCx ADC instance
  5393. * @retval None
  5394. */
  5395. __STATIC_INLINE void LL_ADC_ClearFlag_AWD1(ADC_TypeDef *ADCx)
  5396. {
  5397. WRITE_REG(ADCx->ISR, LL_ADC_FLAG_AWD1);
  5398. }
  5399. /**
  5400. * @brief Clear flag ADC analog watchdog 2.
  5401. * @rmtoll ISR AWD2 LL_ADC_ClearFlag_AWD2
  5402. * @param ADCx ADC instance
  5403. * @retval None
  5404. */
  5405. __STATIC_INLINE void LL_ADC_ClearFlag_AWD2(ADC_TypeDef *ADCx)
  5406. {
  5407. WRITE_REG(ADCx->ISR, LL_ADC_FLAG_AWD2);
  5408. }
  5409. /**
  5410. * @brief Clear flag ADC analog watchdog 3.
  5411. * @rmtoll ISR AWD3 LL_ADC_ClearFlag_AWD3
  5412. * @param ADCx ADC instance
  5413. * @retval None
  5414. */
  5415. __STATIC_INLINE void LL_ADC_ClearFlag_AWD3(ADC_TypeDef *ADCx)
  5416. {
  5417. WRITE_REG(ADCx->ISR, LL_ADC_FLAG_AWD3);
  5418. }
  5419. /**
  5420. * @}
  5421. */
  5422. /** @defgroup ADC_LL_EF_IT_Management ADC IT management
  5423. * @{
  5424. */
  5425. /**
  5426. * @brief Enable ADC ready.
  5427. * @rmtoll IER ADRDYIE LL_ADC_EnableIT_ADRDY
  5428. * @param ADCx ADC instance
  5429. * @retval None
  5430. */
  5431. __STATIC_INLINE void LL_ADC_EnableIT_ADRDY(ADC_TypeDef *ADCx)
  5432. {
  5433. SET_BIT(ADCx->IER, LL_ADC_IT_ADRDY);
  5434. }
  5435. /**
  5436. * @brief Enable interruption ADC group regular end of unitary conversion.
  5437. * @rmtoll IER EOCIE LL_ADC_EnableIT_EOC
  5438. * @param ADCx ADC instance
  5439. * @retval None
  5440. */
  5441. __STATIC_INLINE void LL_ADC_EnableIT_EOC(ADC_TypeDef *ADCx)
  5442. {
  5443. SET_BIT(ADCx->IER, LL_ADC_IT_EOC);
  5444. }
  5445. /**
  5446. * @brief Enable interruption ADC group regular end of sequence conversions.
  5447. * @rmtoll IER EOSIE LL_ADC_EnableIT_EOS
  5448. * @param ADCx ADC instance
  5449. * @retval None
  5450. */
  5451. __STATIC_INLINE void LL_ADC_EnableIT_EOS(ADC_TypeDef *ADCx)
  5452. {
  5453. SET_BIT(ADCx->IER, LL_ADC_IT_EOS);
  5454. }
  5455. /**
  5456. * @brief Enable ADC group regular interruption overrun.
  5457. * @rmtoll IER OVRIE LL_ADC_EnableIT_OVR
  5458. * @param ADCx ADC instance
  5459. * @retval None
  5460. */
  5461. __STATIC_INLINE void LL_ADC_EnableIT_OVR(ADC_TypeDef *ADCx)
  5462. {
  5463. SET_BIT(ADCx->IER, LL_ADC_IT_OVR);
  5464. }
  5465. /**
  5466. * @brief Enable interruption ADC group regular end of sampling.
  5467. * @rmtoll IER EOSMPIE LL_ADC_EnableIT_EOSMP
  5468. * @param ADCx ADC instance
  5469. * @retval None
  5470. */
  5471. __STATIC_INLINE void LL_ADC_EnableIT_EOSMP(ADC_TypeDef *ADCx)
  5472. {
  5473. SET_BIT(ADCx->IER, LL_ADC_IT_EOSMP);
  5474. }
  5475. /**
  5476. * @brief Enable interruption ADC group injected end of unitary conversion.
  5477. * @rmtoll IER JEOCIE LL_ADC_EnableIT_JEOC
  5478. * @param ADCx ADC instance
  5479. * @retval None
  5480. */
  5481. __STATIC_INLINE void LL_ADC_EnableIT_JEOC(ADC_TypeDef *ADCx)
  5482. {
  5483. SET_BIT(ADCx->IER, LL_ADC_IT_JEOC);
  5484. }
  5485. /**
  5486. * @brief Enable interruption ADC group injected end of sequence conversions.
  5487. * @rmtoll IER JEOSIE LL_ADC_EnableIT_JEOS
  5488. * @param ADCx ADC instance
  5489. * @retval None
  5490. */
  5491. __STATIC_INLINE void LL_ADC_EnableIT_JEOS(ADC_TypeDef *ADCx)
  5492. {
  5493. SET_BIT(ADCx->IER, LL_ADC_IT_JEOS);
  5494. }
  5495. /**
  5496. * @brief Enable interruption ADC group injected context queue overflow.
  5497. * @rmtoll IER JQOVFIE LL_ADC_EnableIT_JQOVF
  5498. * @param ADCx ADC instance
  5499. * @retval None
  5500. */
  5501. __STATIC_INLINE void LL_ADC_EnableIT_JQOVF(ADC_TypeDef *ADCx)
  5502. {
  5503. SET_BIT(ADCx->IER, LL_ADC_IT_JQOVF);
  5504. }
  5505. /**
  5506. * @brief Enable interruption ADC analog watchdog 1.
  5507. * @rmtoll IER AWD1IE LL_ADC_EnableIT_AWD1
  5508. * @param ADCx ADC instance
  5509. * @retval None
  5510. */
  5511. __STATIC_INLINE void LL_ADC_EnableIT_AWD1(ADC_TypeDef *ADCx)
  5512. {
  5513. SET_BIT(ADCx->IER, LL_ADC_IT_AWD1);
  5514. }
  5515. /**
  5516. * @brief Enable interruption ADC analog watchdog 2.
  5517. * @rmtoll IER AWD2IE LL_ADC_EnableIT_AWD2
  5518. * @param ADCx ADC instance
  5519. * @retval None
  5520. */
  5521. __STATIC_INLINE void LL_ADC_EnableIT_AWD2(ADC_TypeDef *ADCx)
  5522. {
  5523. SET_BIT(ADCx->IER, LL_ADC_IT_AWD2);
  5524. }
  5525. /**
  5526. * @brief Enable interruption ADC analog watchdog 3.
  5527. * @rmtoll IER AWD3IE LL_ADC_EnableIT_AWD3
  5528. * @param ADCx ADC instance
  5529. * @retval None
  5530. */
  5531. __STATIC_INLINE void LL_ADC_EnableIT_AWD3(ADC_TypeDef *ADCx)
  5532. {
  5533. SET_BIT(ADCx->IER, LL_ADC_IT_AWD3);
  5534. }
  5535. /**
  5536. * @brief Disable interruption ADC ready.
  5537. * @rmtoll IER ADRDYIE LL_ADC_DisableIT_ADRDY
  5538. * @param ADCx ADC instance
  5539. * @retval None
  5540. */
  5541. __STATIC_INLINE void LL_ADC_DisableIT_ADRDY(ADC_TypeDef *ADCx)
  5542. {
  5543. CLEAR_BIT(ADCx->IER, LL_ADC_IT_ADRDY);
  5544. }
  5545. /**
  5546. * @brief Disable interruption ADC group regular end of unitary conversion.
  5547. * @rmtoll IER EOCIE LL_ADC_DisableIT_EOC
  5548. * @param ADCx ADC instance
  5549. * @retval None
  5550. */
  5551. __STATIC_INLINE void LL_ADC_DisableIT_EOC(ADC_TypeDef *ADCx)
  5552. {
  5553. CLEAR_BIT(ADCx->IER, LL_ADC_IT_EOC);
  5554. }
  5555. /**
  5556. * @brief Disable interruption ADC group regular end of sequence conversions.
  5557. * @rmtoll IER EOSIE LL_ADC_DisableIT_EOS
  5558. * @param ADCx ADC instance
  5559. * @retval None
  5560. */
  5561. __STATIC_INLINE void LL_ADC_DisableIT_EOS(ADC_TypeDef *ADCx)
  5562. {
  5563. CLEAR_BIT(ADCx->IER, LL_ADC_IT_EOS);
  5564. }
  5565. /**
  5566. * @brief Disable interruption ADC group regular overrun.
  5567. * @rmtoll IER OVRIE LL_ADC_DisableIT_OVR
  5568. * @param ADCx ADC instance
  5569. * @retval None
  5570. */
  5571. __STATIC_INLINE void LL_ADC_DisableIT_OVR(ADC_TypeDef *ADCx)
  5572. {
  5573. CLEAR_BIT(ADCx->IER, LL_ADC_IT_OVR);
  5574. }
  5575. /**
  5576. * @brief Disable interruption ADC group regular end of sampling.
  5577. * @rmtoll IER EOSMPIE LL_ADC_DisableIT_EOSMP
  5578. * @param ADCx ADC instance
  5579. * @retval None
  5580. */
  5581. __STATIC_INLINE void LL_ADC_DisableIT_EOSMP(ADC_TypeDef *ADCx)
  5582. {
  5583. CLEAR_BIT(ADCx->IER, LL_ADC_IT_EOSMP);
  5584. }
  5585. /**
  5586. * @brief Disable interruption ADC group regular end of unitary conversion.
  5587. * @rmtoll IER JEOCIE LL_ADC_DisableIT_JEOC
  5588. * @param ADCx ADC instance
  5589. * @retval None
  5590. */
  5591. __STATIC_INLINE void LL_ADC_DisableIT_JEOC(ADC_TypeDef *ADCx)
  5592. {
  5593. CLEAR_BIT(ADCx->IER, LL_ADC_IT_JEOC);
  5594. }
  5595. /**
  5596. * @brief Disable interruption ADC group injected end of sequence conversions.
  5597. * @rmtoll IER JEOSIE LL_ADC_DisableIT_JEOS
  5598. * @param ADCx ADC instance
  5599. * @retval None
  5600. */
  5601. __STATIC_INLINE void LL_ADC_DisableIT_JEOS(ADC_TypeDef *ADCx)
  5602. {
  5603. CLEAR_BIT(ADCx->IER, LL_ADC_IT_JEOS);
  5604. }
  5605. /**
  5606. * @brief Disable interruption ADC group injected context queue overflow.
  5607. * @rmtoll IER JQOVFIE LL_ADC_DisableIT_JQOVF
  5608. * @param ADCx ADC instance
  5609. * @retval None
  5610. */
  5611. __STATIC_INLINE void LL_ADC_DisableIT_JQOVF(ADC_TypeDef *ADCx)
  5612. {
  5613. CLEAR_BIT(ADCx->IER, LL_ADC_IT_JQOVF);
  5614. }
  5615. /**
  5616. * @brief Disable interruption ADC analog watchdog 1.
  5617. * @rmtoll IER AWD1IE LL_ADC_DisableIT_AWD1
  5618. * @param ADCx ADC instance
  5619. * @retval None
  5620. */
  5621. __STATIC_INLINE void LL_ADC_DisableIT_AWD1(ADC_TypeDef *ADCx)
  5622. {
  5623. CLEAR_BIT(ADCx->IER, LL_ADC_IT_AWD1);
  5624. }
  5625. /**
  5626. * @brief Disable interruption ADC analog watchdog 2.
  5627. * @rmtoll IER AWD2IE LL_ADC_DisableIT_AWD2
  5628. * @param ADCx ADC instance
  5629. * @retval None
  5630. */
  5631. __STATIC_INLINE void LL_ADC_DisableIT_AWD2(ADC_TypeDef *ADCx)
  5632. {
  5633. CLEAR_BIT(ADCx->IER, LL_ADC_IT_AWD2);
  5634. }
  5635. /**
  5636. * @brief Disable interruption ADC analog watchdog 3.
  5637. * @rmtoll IER AWD3IE LL_ADC_DisableIT_AWD3
  5638. * @param ADCx ADC instance
  5639. * @retval None
  5640. */
  5641. __STATIC_INLINE void LL_ADC_DisableIT_AWD3(ADC_TypeDef *ADCx)
  5642. {
  5643. CLEAR_BIT(ADCx->IER, LL_ADC_IT_AWD3);
  5644. }
  5645. /**
  5646. * @brief Get state of interruption ADC ready
  5647. * (0: interrupt disabled, 1: interrupt enabled).
  5648. * @rmtoll IER ADRDYIE LL_ADC_IsEnabledIT_ADRDY
  5649. * @param ADCx ADC instance
  5650. * @retval State of bit (1 or 0).
  5651. */
  5652. __STATIC_INLINE uint32_t LL_ADC_IsEnabledIT_ADRDY(ADC_TypeDef *ADCx)
  5653. {
  5654. return ((READ_BIT(ADCx->IER, LL_ADC_IT_ADRDY) == (LL_ADC_IT_ADRDY)) ? 1UL : 0UL);
  5655. }
  5656. /**
  5657. * @brief Get state of interruption ADC group regular end of unitary conversion
  5658. * (0: interrupt disabled, 1: interrupt enabled).
  5659. * @rmtoll IER EOCIE LL_ADC_IsEnabledIT_EOC
  5660. * @param ADCx ADC instance
  5661. * @retval State of bit (1 or 0).
  5662. */
  5663. __STATIC_INLINE uint32_t LL_ADC_IsEnabledIT_EOC(ADC_TypeDef *ADCx)
  5664. {
  5665. return ((READ_BIT(ADCx->IER, LL_ADC_IT_EOC) == (LL_ADC_IT_EOC)) ? 1UL : 0UL);
  5666. }
  5667. /**
  5668. * @brief Get state of interruption ADC group regular end of sequence conversions
  5669. * (0: interrupt disabled, 1: interrupt enabled).
  5670. * @rmtoll IER EOSIE LL_ADC_IsEnabledIT_EOS
  5671. * @param ADCx ADC instance
  5672. * @retval State of bit (1 or 0).
  5673. */
  5674. __STATIC_INLINE uint32_t LL_ADC_IsEnabledIT_EOS(ADC_TypeDef *ADCx)
  5675. {
  5676. return ((READ_BIT(ADCx->IER, LL_ADC_IT_EOS) == (LL_ADC_IT_EOS)) ? 1UL : 0UL);
  5677. }
  5678. /**
  5679. * @brief Get state of interruption ADC group regular overrun
  5680. * (0: interrupt disabled, 1: interrupt enabled).
  5681. * @rmtoll IER OVRIE LL_ADC_IsEnabledIT_OVR
  5682. * @param ADCx ADC instance
  5683. * @retval State of bit (1 or 0).
  5684. */
  5685. __STATIC_INLINE uint32_t LL_ADC_IsEnabledIT_OVR(ADC_TypeDef *ADCx)
  5686. {
  5687. return ((READ_BIT(ADCx->IER, LL_ADC_IT_OVR) == (LL_ADC_IT_OVR)) ? 1UL : 0UL);
  5688. }
  5689. /**
  5690. * @brief Get state of interruption ADC group regular end of sampling
  5691. * (0: interrupt disabled, 1: interrupt enabled).
  5692. * @rmtoll IER EOSMPIE LL_ADC_IsEnabledIT_EOSMP
  5693. * @param ADCx ADC instance
  5694. * @retval State of bit (1 or 0).
  5695. */
  5696. __STATIC_INLINE uint32_t LL_ADC_IsEnabledIT_EOSMP(ADC_TypeDef *ADCx)
  5697. {
  5698. return ((READ_BIT(ADCx->IER, LL_ADC_IT_EOSMP) == (LL_ADC_IT_EOSMP)) ? 1UL : 0UL);
  5699. }
  5700. /**
  5701. * @brief Get state of interruption ADC group injected end of unitary conversion
  5702. * (0: interrupt disabled, 1: interrupt enabled).
  5703. * @rmtoll IER JEOCIE LL_ADC_IsEnabledIT_JEOC
  5704. * @param ADCx ADC instance
  5705. * @retval State of bit (1 or 0).
  5706. */
  5707. __STATIC_INLINE uint32_t LL_ADC_IsEnabledIT_JEOC(ADC_TypeDef *ADCx)
  5708. {
  5709. return ((READ_BIT(ADCx->IER, LL_ADC_IT_JEOC) == (LL_ADC_IT_JEOC)) ? 1UL : 0UL);
  5710. }
  5711. /**
  5712. * @brief Get state of interruption ADC group injected end of sequence conversions
  5713. * (0: interrupt disabled, 1: interrupt enabled).
  5714. * @rmtoll IER JEOSIE LL_ADC_IsEnabledIT_JEOS
  5715. * @param ADCx ADC instance
  5716. * @retval State of bit (1 or 0).
  5717. */
  5718. __STATIC_INLINE uint32_t LL_ADC_IsEnabledIT_JEOS(ADC_TypeDef *ADCx)
  5719. {
  5720. return ((READ_BIT(ADCx->IER, LL_ADC_IT_JEOS) == (LL_ADC_IT_JEOS)) ? 1UL : 0UL);
  5721. }
  5722. /**
  5723. * @brief Get state of interruption ADC group injected context queue overflow interrupt state
  5724. * (0: interrupt disabled, 1: interrupt enabled).
  5725. * @rmtoll IER JQOVFIE LL_ADC_IsEnabledIT_JQOVF
  5726. * @param ADCx ADC instance
  5727. * @retval State of bit (1 or 0).
  5728. */
  5729. __STATIC_INLINE uint32_t LL_ADC_IsEnabledIT_JQOVF(ADC_TypeDef *ADCx)
  5730. {
  5731. return ((READ_BIT(ADCx->IER, LL_ADC_IT_JQOVF) == (LL_ADC_IT_JQOVF)) ? 1UL : 0UL);
  5732. }
  5733. /**
  5734. * @brief Get state of interruption ADC analog watchdog 1
  5735. * (0: interrupt disabled, 1: interrupt enabled).
  5736. * @rmtoll IER AWD1IE LL_ADC_IsEnabledIT_AWD1
  5737. * @param ADCx ADC instance
  5738. * @retval State of bit (1 or 0).
  5739. */
  5740. __STATIC_INLINE uint32_t LL_ADC_IsEnabledIT_AWD1(ADC_TypeDef *ADCx)
  5741. {
  5742. return ((READ_BIT(ADCx->IER, LL_ADC_IT_AWD1) == (LL_ADC_IT_AWD1)) ? 1UL : 0UL);
  5743. }
  5744. /**
  5745. * @brief Get state of interruption Get ADC analog watchdog 2
  5746. * (0: interrupt disabled, 1: interrupt enabled).
  5747. * @rmtoll IER AWD2IE LL_ADC_IsEnabledIT_AWD2
  5748. * @param ADCx ADC instance
  5749. * @retval State of bit (1 or 0).
  5750. */
  5751. __STATIC_INLINE uint32_t LL_ADC_IsEnabledIT_AWD2(ADC_TypeDef *ADCx)
  5752. {
  5753. return ((READ_BIT(ADCx->IER, LL_ADC_IT_AWD2) == (LL_ADC_IT_AWD2)) ? 1UL : 0UL);
  5754. }
  5755. /**
  5756. * @brief Get state of interruption Get ADC analog watchdog 3
  5757. * (0: interrupt disabled, 1: interrupt enabled).
  5758. * @rmtoll IER AWD3IE LL_ADC_IsEnabledIT_AWD3
  5759. * @param ADCx ADC instance
  5760. * @retval State of bit (1 or 0).
  5761. */
  5762. __STATIC_INLINE uint32_t LL_ADC_IsEnabledIT_AWD3(ADC_TypeDef *ADCx)
  5763. {
  5764. return ((READ_BIT(ADCx->IER, LL_ADC_IT_AWD3) == (LL_ADC_IT_AWD3)) ? 1UL : 0UL);
  5765. }
  5766. /**
  5767. * @}
  5768. */
  5769. #if defined(USE_FULL_LL_DRIVER)
  5770. /** @defgroup ADC_LL_EF_Init Initialization and de-initialization functions
  5771. * @{
  5772. */
  5773. /* Initialization of some features of ADC common parameters and multimode */
  5774. ErrorStatus LL_ADC_CommonDeInit(ADC_Common_TypeDef *ADCxy_COMMON);
  5775. ErrorStatus LL_ADC_CommonInit(ADC_Common_TypeDef *ADCxy_COMMON, LL_ADC_CommonInitTypeDef *ADC_CommonInitStruct);
  5776. void LL_ADC_CommonStructInit(LL_ADC_CommonInitTypeDef *ADC_CommonInitStruct);
  5777. /* De-initialization of ADC instance, ADC group regular and ADC group injected */
  5778. /* (availability of ADC group injected depends on STM32 families) */
  5779. ErrorStatus LL_ADC_DeInit(ADC_TypeDef *ADCx);
  5780. /* Initialization of some features of ADC instance */
  5781. ErrorStatus LL_ADC_Init(ADC_TypeDef *ADCx, LL_ADC_InitTypeDef *ADC_InitStruct);
  5782. void LL_ADC_StructInit(LL_ADC_InitTypeDef *ADC_InitStruct);
  5783. /* Initialization of some features of ADC instance and ADC group regular */
  5784. ErrorStatus LL_ADC_REG_Init(ADC_TypeDef *ADCx, LL_ADC_REG_InitTypeDef *ADC_REG_InitStruct);
  5785. void LL_ADC_REG_StructInit(LL_ADC_REG_InitTypeDef *ADC_REG_InitStruct);
  5786. /* Initialization of some features of ADC instance and ADC group injected */
  5787. ErrorStatus LL_ADC_INJ_Init(ADC_TypeDef *ADCx, LL_ADC_INJ_InitTypeDef *ADC_INJ_InitStruct);
  5788. void LL_ADC_INJ_StructInit(LL_ADC_INJ_InitTypeDef *ADC_INJ_InitStruct);
  5789. /**
  5790. * @}
  5791. */
  5792. #endif /* USE_FULL_LL_DRIVER */
  5793. /**
  5794. * @}
  5795. */
  5796. /**
  5797. * @}
  5798. */
  5799. #endif /* ADC1 */
  5800. /**
  5801. * @}
  5802. */
  5803. #ifdef __cplusplus
  5804. }
  5805. #endif
  5806. #endif /* STM32WBxx_LL_ADC_H */
  5807. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/