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.
 
 
 

4072 lines
216 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32l0xx_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) 2016 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 __STM32L0xx_LL_ADC_H
  21. #define __STM32L0xx_LL_ADC_H
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. /* Includes ------------------------------------------------------------------*/
  26. #include "stm32l0xx.h"
  27. /** @addtogroup STM32L0xx_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 trigger: */
  41. /* To select into literal LL_ADC_REG_TRIG_x the relevant bits for: */
  42. /* - regular trigger source */
  43. /* - regular trigger edge */
  44. #define ADC_REG_TRIG_EXT_EDGE_DEFAULT (ADC_CFGR1_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) */
  45. /* Mask containing trigger source masks for each of possible */
  46. /* trigger edge selection duplicated with shifts [0; 4; 8; 12] */
  47. /* corresponding to {SW start; ext trigger; ext trigger; ext trigger}. */
  48. #define ADC_REG_TRIG_SOURCE_MASK (((LL_ADC_REG_TRIG_SOFTWARE & ADC_CFGR1_EXTSEL) << (4U * 0U)) | \
  49. ((ADC_CFGR1_EXTSEL) << (4U * 1U)) | \
  50. ((ADC_CFGR1_EXTSEL) << (4U * 2U)) | \
  51. ((ADC_CFGR1_EXTSEL) << (4U * 3U)) )
  52. /* Mask containing trigger edge masks for each of possible */
  53. /* trigger edge selection duplicated with shifts [0; 4; 8; 12] */
  54. /* corresponding to {SW start; ext trigger; ext trigger; ext trigger}. */
  55. #define ADC_REG_TRIG_EDGE_MASK (((LL_ADC_REG_TRIG_SOFTWARE & ADC_CFGR1_EXTEN) << (4U * 0U)) | \
  56. ((ADC_REG_TRIG_EXT_EDGE_DEFAULT) << (4U * 1U)) | \
  57. ((ADC_REG_TRIG_EXT_EDGE_DEFAULT) << (4U * 2U)) | \
  58. ((ADC_REG_TRIG_EXT_EDGE_DEFAULT) << (4U * 3U)) )
  59. /* Definition of ADC group regular trigger bits information. */
  60. #define ADC_REG_TRIG_EXTSEL_BITOFFSET_POS ((uint32_t) 6U) /* Value equivalent to POSITION_VAL(ADC_CFGR1_EXTSEL) */
  61. #define ADC_REG_TRIG_EXTEN_BITOFFSET_POS ((uint32_t)10U) /* Value equivalent to POSITION_VAL(ADC_CFGR1_EXTEN) */
  62. /* Internal mask for ADC channel: */
  63. /* To select into literal LL_ADC_CHANNEL_x the relevant bits for: */
  64. /* - channel identifier defined by number */
  65. /* - channel identifier defined by bitfield */
  66. /* - channel differentiation between external channels (connected to */
  67. /* GPIO pins) and internal channels (connected to internal paths) */
  68. #define ADC_CHANNEL_ID_NUMBER_MASK (ADC_CFGR1_AWDCH)
  69. #define ADC_CHANNEL_ID_BITFIELD_MASK (ADC_CHSELR_CHSEL)
  70. #define ADC_CHANNEL_ID_NUMBER_BITOFFSET_POS ((uint32_t)26U)/* Value equivalent to POSITION_VAL(ADC_CHANNEL_ID_NUMBER_MASK) */
  71. #define ADC_CHANNEL_ID_MASK (ADC_CHANNEL_ID_NUMBER_MASK | ADC_CHANNEL_ID_BITFIELD_MASK | ADC_CHANNEL_ID_INTERNAL_CH_MASK)
  72. /* Equivalent mask of ADC_CHANNEL_NUMBER_MASK aligned on register LSB (bit 0) */
  73. #define ADC_CHANNEL_ID_NUMBER_MASK_POSBIT0 ((uint32_t)0x0000001FU) /* Equivalent to shift: (ADC_CHANNEL_NUMBER_MASK >> POSITION_VAL(ADC_CHANNEL_NUMBER_MASK)) */
  74. /* Channel differentiation between external and internal channels */
  75. #define ADC_CHANNEL_ID_INTERNAL_CH ((uint32_t)0x80000000U) /* Marker of internal channel */
  76. #define ADC_CHANNEL_ID_INTERNAL_CH_MASK (ADC_CHANNEL_ID_INTERNAL_CH)
  77. /* Definition of channels ID number information to be inserted into */
  78. /* channels literals definition. */
  79. #define ADC_CHANNEL_0_NUMBER ((uint32_t)0x00000000U)
  80. #define ADC_CHANNEL_1_NUMBER ( ADC_CFGR1_AWDCH_0)
  81. #define ADC_CHANNEL_2_NUMBER ( ADC_CFGR1_AWDCH_1 )
  82. #define ADC_CHANNEL_3_NUMBER ( ADC_CFGR1_AWDCH_1 | ADC_CFGR1_AWDCH_0)
  83. #define ADC_CHANNEL_4_NUMBER ( ADC_CFGR1_AWDCH_2 )
  84. #define ADC_CHANNEL_5_NUMBER ( ADC_CFGR1_AWDCH_2 | ADC_CFGR1_AWDCH_0)
  85. #define ADC_CHANNEL_6_NUMBER ( ADC_CFGR1_AWDCH_2 | ADC_CFGR1_AWDCH_1 )
  86. #define ADC_CHANNEL_7_NUMBER ( ADC_CFGR1_AWDCH_2 | ADC_CFGR1_AWDCH_1 | ADC_CFGR1_AWDCH_0)
  87. #define ADC_CHANNEL_8_NUMBER ( ADC_CFGR1_AWDCH_3 )
  88. #define ADC_CHANNEL_9_NUMBER ( ADC_CFGR1_AWDCH_3 | ADC_CFGR1_AWDCH_0)
  89. #define ADC_CHANNEL_10_NUMBER ( ADC_CFGR1_AWDCH_3 | ADC_CFGR1_AWDCH_1 )
  90. #define ADC_CHANNEL_11_NUMBER ( ADC_CFGR1_AWDCH_3 | ADC_CFGR1_AWDCH_1 | ADC_CFGR1_AWDCH_0)
  91. #define ADC_CHANNEL_12_NUMBER ( ADC_CFGR1_AWDCH_3 | ADC_CFGR1_AWDCH_2 )
  92. #define ADC_CHANNEL_13_NUMBER ( ADC_CFGR1_AWDCH_3 | ADC_CFGR1_AWDCH_2 | ADC_CFGR1_AWDCH_0)
  93. #define ADC_CHANNEL_14_NUMBER ( ADC_CFGR1_AWDCH_3 | ADC_CFGR1_AWDCH_2 | ADC_CFGR1_AWDCH_1 )
  94. #define ADC_CHANNEL_15_NUMBER ( ADC_CFGR1_AWDCH_3 | ADC_CFGR1_AWDCH_2 | ADC_CFGR1_AWDCH_1 | ADC_CFGR1_AWDCH_0)
  95. #define ADC_CHANNEL_16_NUMBER (ADC_CFGR1_AWDCH_4 )
  96. #define ADC_CHANNEL_17_NUMBER (ADC_CFGR1_AWDCH_4 | ADC_CFGR1_AWDCH_0)
  97. #define ADC_CHANNEL_18_NUMBER (ADC_CFGR1_AWDCH_4 | ADC_CFGR1_AWDCH_1 )
  98. /* Definition of channels ID bitfield information to be inserted into */
  99. /* channels literals definition. */
  100. #define ADC_CHANNEL_0_BITFIELD (ADC_CHSELR_CHSEL0)
  101. #define ADC_CHANNEL_1_BITFIELD (ADC_CHSELR_CHSEL1)
  102. #define ADC_CHANNEL_2_BITFIELD (ADC_CHSELR_CHSEL2)
  103. #define ADC_CHANNEL_3_BITFIELD (ADC_CHSELR_CHSEL3)
  104. #define ADC_CHANNEL_4_BITFIELD (ADC_CHSELR_CHSEL4)
  105. #define ADC_CHANNEL_5_BITFIELD (ADC_CHSELR_CHSEL5)
  106. #define ADC_CHANNEL_6_BITFIELD (ADC_CHSELR_CHSEL6)
  107. #define ADC_CHANNEL_7_BITFIELD (ADC_CHSELR_CHSEL7)
  108. #define ADC_CHANNEL_8_BITFIELD (ADC_CHSELR_CHSEL8)
  109. #define ADC_CHANNEL_9_BITFIELD (ADC_CHSELR_CHSEL9)
  110. #define ADC_CHANNEL_10_BITFIELD (ADC_CHSELR_CHSEL10)
  111. #define ADC_CHANNEL_11_BITFIELD (ADC_CHSELR_CHSEL11)
  112. #define ADC_CHANNEL_12_BITFIELD (ADC_CHSELR_CHSEL12)
  113. #define ADC_CHANNEL_13_BITFIELD (ADC_CHSELR_CHSEL13)
  114. #define ADC_CHANNEL_14_BITFIELD (ADC_CHSELR_CHSEL14)
  115. #define ADC_CHANNEL_15_BITFIELD (ADC_CHSELR_CHSEL15)
  116. #if defined(ADC_CCR_VLCDEN)
  117. #define ADC_CHANNEL_16_BITFIELD (ADC_CHSELR_CHSEL16)
  118. #endif
  119. #define ADC_CHANNEL_17_BITFIELD (ADC_CHSELR_CHSEL17)
  120. #define ADC_CHANNEL_18_BITFIELD (ADC_CHSELR_CHSEL18)
  121. /* Internal mask for ADC analog watchdog: */
  122. /* To select into literals LL_ADC_AWD_CHANNELx_xxx the relevant bits for: */
  123. /* (concatenation of multiple bits used in different analog watchdogs, */
  124. /* (feature of several watchdogs not available on all STM32 families)). */
  125. /* - analog watchdog 1: monitored channel defined by number, */
  126. /* selection of ADC group (ADC group regular). */
  127. /* Internal register offset for ADC analog watchdog channel configuration */
  128. #define ADC_AWD_CR1_REGOFFSET ((uint32_t)0x00000000U)
  129. #define ADC_AWD_CRX_REGOFFSET_MASK (ADC_AWD_CR1_REGOFFSET)
  130. #define ADC_AWD_CR1_CHANNEL_MASK (ADC_CFGR1_AWDCH | ADC_CFGR1_AWDEN | ADC_CFGR1_AWDSGL)
  131. #define ADC_AWD_CR_ALL_CHANNEL_MASK (ADC_AWD_CR1_CHANNEL_MASK)
  132. /* Internal register offset for ADC analog watchdog threshold configuration */
  133. #define ADC_AWD_TR1_REGOFFSET (ADC_AWD_CR1_REGOFFSET)
  134. #define ADC_AWD_TRX_REGOFFSET_MASK (ADC_AWD_TR1_REGOFFSET)
  135. /* ADC registers bits positions */
  136. #define ADC_CFGR1_RES_BITOFFSET_POS ((uint32_t) 3U) /* Value equivalent to POSITION_VAL(ADC_CFGR1_RES) */
  137. #define ADC_CFGR1_AWDSGL_BITOFFSET_POS ((uint32_t)22U) /* Value equivalent to POSITION_VAL(ADC_CFGR1_AWDSGL) */
  138. #define ADC_TR_HT_BITOFFSET_POS ((uint32_t)16U) /* Value equivalent to POSITION_VAL(ADC_TR_HT) */
  139. #define ADC_CHSELR_CHSEL0_BITOFFSET_POS ((uint32_t) 0U) /* Value equivalent to POSITION_VAL(ADC_CHSELR_CHSEL0) */
  140. #define ADC_CHSELR_CHSEL1_BITOFFSET_POS ((uint32_t) 1U) /* Value equivalent to POSITION_VAL(ADC_CHSELR_CHSEL1) */
  141. #define ADC_CHSELR_CHSEL2_BITOFFSET_POS ((uint32_t) 2U) /* Value equivalent to POSITION_VAL(ADC_CHSELR_CHSEL2) */
  142. #define ADC_CHSELR_CHSEL3_BITOFFSET_POS ((uint32_t) 3U) /* Value equivalent to POSITION_VAL(ADC_CHSELR_CHSEL3) */
  143. #define ADC_CHSELR_CHSEL4_BITOFFSET_POS ((uint32_t) 4U) /* Value equivalent to POSITION_VAL(ADC_CHSELR_CHSEL4) */
  144. #define ADC_CHSELR_CHSEL5_BITOFFSET_POS ((uint32_t) 5U) /* Value equivalent to POSITION_VAL(ADC_CHSELR_CHSEL5) */
  145. #define ADC_CHSELR_CHSEL6_BITOFFSET_POS ((uint32_t) 6U) /* Value equivalent to POSITION_VAL(ADC_CHSELR_CHSEL6) */
  146. #define ADC_CHSELR_CHSEL7_BITOFFSET_POS ((uint32_t) 7U) /* Value equivalent to POSITION_VAL(ADC_CHSELR_CHSEL7) */
  147. #define ADC_CHSELR_CHSEL8_BITOFFSET_POS ((uint32_t) 8U) /* Value equivalent to POSITION_VAL(ADC_CHSELR_CHSEL8) */
  148. #define ADC_CHSELR_CHSEL9_BITOFFSET_POS ((uint32_t) 9U) /* Value equivalent to POSITION_VAL(ADC_CHSELR_CHSEL9) */
  149. #define ADC_CHSELR_CHSEL10_BITOFFSET_POS ((uint32_t)10U) /* Value equivalent to POSITION_VAL(ADC_CHSELR_CHSEL10) */
  150. #define ADC_CHSELR_CHSEL11_BITOFFSET_POS ((uint32_t)11U) /* Value equivalent to POSITION_VAL(ADC_CHSELR_CHSEL11) */
  151. #define ADC_CHSELR_CHSEL12_BITOFFSET_POS ((uint32_t)12U) /* Value equivalent to POSITION_VAL(ADC_CHSELR_CHSEL12) */
  152. #define ADC_CHSELR_CHSEL13_BITOFFSET_POS ((uint32_t)13U) /* Value equivalent to POSITION_VAL(ADC_CHSELR_CHSEL13) */
  153. #define ADC_CHSELR_CHSEL14_BITOFFSET_POS ((uint32_t)14U) /* Value equivalent to POSITION_VAL(ADC_CHSELR_CHSEL14) */
  154. #define ADC_CHSELR_CHSEL15_BITOFFSET_POS ((uint32_t)15U) /* Value equivalent to POSITION_VAL(ADC_CHSELR_CHSEL15) */
  155. #if defined(ADC_CCR_VLCDEN)
  156. #define ADC_CHSELR_CHSEL16_BITOFFSET_POS ((uint32_t)16U) /* Value equivalent to POSITION_VAL(ADC_CHSELR_CHSEL16) */
  157. #endif
  158. #define ADC_CHSELR_CHSEL17_BITOFFSET_POS ((uint32_t)17U) /* Value equivalent to POSITION_VAL(ADC_CHSELR_CHSEL17) */
  159. #define ADC_CHSELR_CHSEL18_BITOFFSET_POS ((uint32_t)18U) /* Value equivalent to POSITION_VAL(ADC_CHSELR_CHSEL18) */
  160. /* ADC registers bits groups */
  161. #define ADC_CR_BITS_PROPERTY_RS (ADC_CR_ADCAL | ADC_CR_ADSTP | 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. */
  162. /* ADC internal channels related definitions */
  163. /* Internal voltage reference VrefInt */
  164. #define VREFINT_CAL_ADDR ((uint16_t*) ((uint32_t)0x1FF80078U)) /* Internal voltage reference, address of parameter VREFINT_CAL: VrefInt ADC raw data acquired at temperature 30 DegC (tolerance: +-5 DegC), Vref+ = 3.0 V (tolerance: +-10 mV). */
  165. #define VREFINT_CAL_VREF ((uint32_t) 3000U) /* Analog voltage reference (Vref+) value with which temperature sensor has been calibrated in production (tolerance: +-10 mV) (unit: mV). */
  166. /* Temperature sensor */
  167. /* Note: On device STM32L011, calibration parameter TS_CAL1 is not available. */
  168. #if !defined(STM32L011xx)
  169. #define TEMPSENSOR_CAL1_ADDR ((uint16_t*) ((uint32_t)0x1FF8007AU)) /* Internal temperature sensor, address of parameter TS_CAL1: On STM32L0, temperature sensor ADC raw data acquired at temperature 30 DegC (tolerance: +-5 DegC), Vref+ = 3.0 V (tolerance: +-10 mV). */
  170. #endif
  171. #define TEMPSENSOR_CAL2_ADDR ((uint16_t*) ((uint32_t)0x1FF8007EU)) /* Internal temperature sensor, address of parameter TS_CAL2: On STM32L0, temperature sensor ADC raw data acquired at temperature 130 DegC (tolerance: +-5 DegC), Vref+ = 3.0 V (tolerance: +-10 mV). */
  172. #if !defined(STM32L011xx)
  173. #define TEMPSENSOR_CAL1_TEMP (( int32_t) 30) /* Internal temperature sensor, temperature at which temperature sensor has been calibrated in production for data into TEMPSENSOR_CAL1_ADDR (tolerance: +-5 DegC) (unit: DegC). */
  174. #endif
  175. #define TEMPSENSOR_CAL2_TEMP (( int32_t) 130) /* Internal temperature sensor, temperature at which temperature sensor has been calibrated in production for data into TEMPSENSOR_CAL2_ADDR (tolerance: +-5 DegC) (unit: DegC). */
  176. #define TEMPSENSOR_CAL_VREFANALOG ((uint32_t) 3000U) /* Analog voltage reference (Vref+) voltage with which temperature sensor has been calibrated in production (+-10 mV) (unit: mV). */
  177. /**
  178. * @}
  179. */
  180. #if defined(USE_FULL_LL_DRIVER)
  181. /* Private macros ------------------------------------------------------------*/
  182. /** @defgroup ADC_LL_Private_Macros ADC Private Macros
  183. * @{
  184. */
  185. /**
  186. * @}
  187. */
  188. #endif
  189. /* Exported types ------------------------------------------------------------*/
  190. #if defined(USE_FULL_LL_DRIVER)
  191. /** @defgroup ADC_LL_ES_INIT ADC Exported Init structure
  192. * @{
  193. */
  194. /**
  195. * @brief Structure definition of some features of ADC common parameters
  196. * and multimode
  197. * (all ADC instances belonging to the same ADC common instance).
  198. * @note The setting of these parameters by function @ref LL_ADC_CommonInit()
  199. * is conditioned to ADC instances state (all ADC instances
  200. * sharing the same ADC common instance):
  201. * All ADC instances sharing the same ADC common instance must be
  202. * disabled.
  203. */
  204. typedef struct
  205. {
  206. uint32_t CommonClock; /*!< Set parameter common to several ADC: Clock source and prescaler.
  207. This parameter can be a value of @ref ADC_LL_EC_COMMON_CLOCK_SOURCE
  208. This feature can be modified afterwards using unitary function @ref LL_ADC_SetCommonClock(). */
  209. } LL_ADC_CommonInitTypeDef;
  210. /**
  211. * @brief Structure definition of some features of ADC instance.
  212. * @note These parameters have an impact on ADC scope: ADC instance.
  213. * Refer to corresponding unitary functions into
  214. * @ref ADC_LL_EF_Configuration_ADC_Instance .
  215. * @note The setting of these parameters by function @ref LL_ADC_Init()
  216. * is conditioned to ADC state:
  217. * ADC instance must be disabled.
  218. * This condition is applied to all ADC features, for efficiency
  219. * and compatibility over all STM32 families. However, the different
  220. * features can be set under different ADC state conditions
  221. * (setting possible with ADC enabled without conversion on going,
  222. * ADC enabled with conversion on going, ...)
  223. * Each feature can be updated afterwards with a unitary function
  224. * and potentially with ADC in a different state than disabled,
  225. * refer to description of each function for setting
  226. * conditioned to ADC state.
  227. */
  228. typedef struct
  229. {
  230. uint32_t Clock; /*!< Set ADC instance clock source and prescaler.
  231. This parameter can be a value of @ref ADC_LL_EC_CLOCK_SOURCE
  232. @note On this STM32 serie, this parameter has some clock ratio constraints:
  233. ADC clock synchronous (from PCLK) with prescaler 1 must be enabled only if PCLK has a 50% duty clock cycle
  234. (APB prescaler configured inside the RCC must be bypassed and the system clock must by 50% duty cycle).
  235. This feature can be modified afterwards using unitary function @ref LL_ADC_SetClock().
  236. For more details, refer to description of this function. */
  237. uint32_t Resolution; /*!< Set ADC resolution.
  238. This parameter can be a value of @ref ADC_LL_EC_RESOLUTION
  239. This feature can be modified afterwards using unitary function @ref LL_ADC_SetResolution(). */
  240. uint32_t DataAlignment; /*!< Set ADC conversion data alignment.
  241. This parameter can be a value of @ref ADC_LL_EC_DATA_ALIGN
  242. This feature can be modified afterwards using unitary function @ref LL_ADC_SetDataAlignment(). */
  243. uint32_t LowPowerMode; /*!< Set ADC low power mode.
  244. This parameter can be a value of @ref ADC_LL_EC_LP_MODE
  245. This feature can be modified afterwards using unitary function @ref LL_ADC_SetLowPowerMode(). */
  246. } LL_ADC_InitTypeDef;
  247. /**
  248. * @brief Structure definition of some features of ADC group regular.
  249. * @note These parameters have an impact on ADC scope: ADC group regular.
  250. * Refer to corresponding unitary functions into
  251. * @ref ADC_LL_EF_Configuration_ADC_Group_Regular
  252. * (functions with prefix "REG").
  253. * @note The setting of these parameters by function @ref LL_ADC_REG_Init()
  254. * is conditioned to ADC state:
  255. * ADC instance must be disabled.
  256. * This condition is applied to all ADC features, for efficiency
  257. * and compatibility over all STM32 families. However, the different
  258. * features can be set under different ADC state conditions
  259. * (setting possible with ADC enabled without conversion on going,
  260. * ADC enabled with conversion on going, ...)
  261. * Each feature can be updated afterwards with a unitary function
  262. * and potentially with ADC in a different state than disabled,
  263. * refer to description of each function for setting
  264. * conditioned to ADC state.
  265. */
  266. typedef struct
  267. {
  268. uint32_t TriggerSource; /*!< Set ADC group regular conversion trigger source: internal (SW start) or from external peripheral (timer event, external interrupt line).
  269. This parameter can be a value of @ref ADC_LL_EC_REG_TRIGGER_SOURCE
  270. @note On this STM32 serie, setting trigger source to external trigger also set trigger polarity to rising edge
  271. (default setting for compatibility with some ADC on other STM32 families having this setting set by HW default value).
  272. In case of need to modify trigger edge, use function @ref LL_ADC_REG_SetTriggerEdge().
  273. This feature can be modified afterwards using unitary function @ref LL_ADC_REG_SetTriggerSource(). */
  274. uint32_t SequencerDiscont; /*!< Set ADC group regular sequencer discontinuous mode: sequence subdivided and scan conversions interrupted every selected number of ranks.
  275. This parameter can be a value of @ref ADC_LL_EC_REG_SEQ_DISCONT_MODE
  276. @note This parameter has an effect only if group regular sequencer is enabled
  277. (several ADC channels enabled in group regular sequencer).
  278. This feature can be modified afterwards using unitary function @ref LL_ADC_REG_SetSequencerDiscont(). */
  279. 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).
  280. This parameter can be a value of @ref ADC_LL_EC_REG_CONTINUOUS_MODE
  281. Note: It is not possible to enable both ADC group regular continuous mode and discontinuous mode.
  282. This feature can be modified afterwards using unitary function @ref LL_ADC_REG_SetContinuousMode(). */
  283. uint32_t DMATransfer; /*!< Set ADC group regular conversion data transfer: no transfer or transfer by DMA, and DMA requests mode.
  284. This parameter can be a value of @ref ADC_LL_EC_REG_DMA_TRANSFER
  285. This feature can be modified afterwards using unitary function @ref LL_ADC_REG_SetDMATransfer(). */
  286. uint32_t Overrun; /*!< Set ADC group regular behavior in case of overrun:
  287. data preserved or overwritten.
  288. This parameter can be a value of @ref ADC_LL_EC_REG_OVR_DATA_BEHAVIOR
  289. This feature can be modified afterwards using unitary function @ref LL_ADC_REG_SetOverrun(). */
  290. } LL_ADC_REG_InitTypeDef;
  291. /**
  292. * @}
  293. */
  294. #endif /* USE_FULL_LL_DRIVER */
  295. /* Exported constants --------------------------------------------------------*/
  296. /** @defgroup ADC_LL_Exported_Constants ADC Exported Constants
  297. * @{
  298. */
  299. /** @defgroup ADC_LL_EC_FLAG ADC flags
  300. * @brief Flags defines which can be used with LL_ADC_ReadReg function
  301. * @{
  302. */
  303. #define LL_ADC_FLAG_ADRDY ADC_ISR_ADRDY /*!< ADC flag ADC instance ready */
  304. #define LL_ADC_FLAG_EOC ADC_ISR_EOC /*!< ADC flag ADC group regular end of unitary conversion */
  305. #define LL_ADC_FLAG_EOS ADC_ISR_EOS /*!< ADC flag ADC group regular end of sequence conversions */
  306. #define LL_ADC_FLAG_OVR ADC_ISR_OVR /*!< ADC flag ADC group regular overrun */
  307. #define LL_ADC_FLAG_EOSMP ADC_ISR_EOSMP /*!< ADC flag ADC group regular end of sampling phase */
  308. #define LL_ADC_FLAG_AWD1 ADC_ISR_AWD /*!< ADC flag ADC analog watchdog 1 */
  309. #define LL_ADC_FLAG_EOCAL ADC_ISR_EOCAL /*!< ADC flag end of calibration */
  310. /**
  311. * @}
  312. */
  313. /** @defgroup ADC_LL_EC_IT ADC interruptions for configuration (interruption enable or disable)
  314. * @brief IT defines which can be used with LL_ADC_ReadReg and LL_ADC_WriteReg functions
  315. * @{
  316. */
  317. #define LL_ADC_IT_ADRDY ADC_IER_ADRDYIE /*!< ADC interruption ADC instance ready */
  318. #define LL_ADC_IT_EOC ADC_IER_EOCIE /*!< ADC interruption ADC group regular end of unitary conversion */
  319. #define LL_ADC_IT_EOS ADC_IER_EOSIE /*!< ADC interruption ADC group regular end of sequence conversions */
  320. #define LL_ADC_IT_OVR ADC_IER_OVRIE /*!< ADC interruption ADC group regular overrun */
  321. #define LL_ADC_IT_EOSMP ADC_IER_EOSMPIE /*!< ADC interruption ADC group regular end of sampling phase */
  322. #define LL_ADC_IT_AWD1 ADC_IER_AWDIE /*!< ADC interruption ADC analog watchdog 1 */
  323. #define LL_ADC_IT_EOCAL ADC_IER_EOCALIE /*!< ADC interruption ADC end of calibration */
  324. /**
  325. * @}
  326. */
  327. /** @defgroup ADC_LL_EC_REGISTERS ADC registers compliant with specific purpose
  328. * @{
  329. */
  330. /* List of ADC registers intended to be used (most commonly) with */
  331. /* DMA transfer. */
  332. /* Refer to function @ref LL_ADC_DMA_GetRegAddr(). */
  333. #define LL_ADC_DMA_REG_REGULAR_DATA ((uint32_t)0x00000000U) /* 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() */
  334. /**
  335. * @}
  336. */
  337. /** @defgroup ADC_LL_EC_COMMON_CLOCK_SOURCE ADC common - Clock source
  338. * @{
  339. */
  340. #define LL_ADC_CLOCK_ASYNC_DIV1 ((uint32_t)0x00000000U) /*!< ADC asynchronous clock without prescaler */
  341. #define LL_ADC_CLOCK_ASYNC_DIV2 (ADC_CCR_PRESC_0) /*!< ADC asynchronous clock with prescaler division by 2. ADC common clock asynchronous prescaler is applied to each ADC instance if the corresponding ADC instance clock is set to clock source asynchronous (refer to function @ref LL_ADC_SetClock() ). */
  342. #define LL_ADC_CLOCK_ASYNC_DIV4 (ADC_CCR_PRESC_1 ) /*!< ADC asynchronous clock with prescaler division by 4. ADC common clock asynchronous prescaler is applied to each ADC instance if the corresponding ADC instance clock is set to clock source asynchronous (refer to function @ref LL_ADC_SetClock() ). */
  343. #define LL_ADC_CLOCK_ASYNC_DIV6 (ADC_CCR_PRESC_1 | ADC_CCR_PRESC_0) /*!< ADC asynchronous clock with prescaler division by 6. ADC common clock asynchronous prescaler is applied to each ADC instance if the corresponding ADC instance clock is set to clock source asynchronous (refer to function @ref LL_ADC_SetClock() ). */
  344. #define LL_ADC_CLOCK_ASYNC_DIV8 (ADC_CCR_PRESC_2 ) /*!< ADC asynchronous clock with prescaler division by 8. ADC common clock asynchronous prescaler is applied to each ADC instance if the corresponding ADC instance clock is set to clock source asynchronous (refer to function @ref LL_ADC_SetClock() ). */
  345. #define LL_ADC_CLOCK_ASYNC_DIV10 (ADC_CCR_PRESC_2 | ADC_CCR_PRESC_0) /*!< ADC asynchronous clock with prescaler division by 10. ADC common clock asynchronous prescaler is applied to each ADC instance if the corresponding ADC instance clock is set to clock source asynchronous (refer to function @ref LL_ADC_SetClock() ). */
  346. #define LL_ADC_CLOCK_ASYNC_DIV12 (ADC_CCR_PRESC_2 | ADC_CCR_PRESC_1 ) /*!< ADC asynchronous clock with prescaler division by 12. ADC common clock asynchronous prescaler is applied to each ADC instance if the corresponding ADC instance clock is set to clock source asynchronous (refer to function @ref LL_ADC_SetClock() ). */
  347. #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. ADC common clock asynchronous prescaler is applied to each ADC instance if the corresponding ADC instance clock is set to clock source asynchronous (refer to function @ref LL_ADC_SetClock() ). */
  348. #define LL_ADC_CLOCK_ASYNC_DIV32 (ADC_CCR_PRESC_3) /*!< ADC asynchronous clock with prescaler division by 32. ADC common clock asynchronous prescaler is applied to each ADC instance if the corresponding ADC instance clock is set to clock source asynchronous (refer to function @ref LL_ADC_SetClock() ). */
  349. #define LL_ADC_CLOCK_ASYNC_DIV64 (ADC_CCR_PRESC_3 | ADC_CCR_PRESC_0) /*!< ADC asynchronous clock with prescaler division by 64. ADC common clock asynchronous prescaler is applied to each ADC instance if the corresponding ADC instance clock is set to clock source asynchronous (refer to function @ref LL_ADC_SetClock() ). */
  350. #define LL_ADC_CLOCK_ASYNC_DIV128 (ADC_CCR_PRESC_3 | ADC_CCR_PRESC_1) /*!< ADC asynchronous clock with prescaler division by 128. ADC common clock asynchronous prescaler is applied to each ADC instance if the corresponding ADC instance clock is set to clock source asynchronous (refer to function @ref LL_ADC_SetClock() ). */
  351. #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. ADC common clock asynchronous prescaler is applied to each ADC instance if the corresponding ADC instance clock is set to clock source asynchronous (refer to function @ref LL_ADC_SetClock() ). */
  352. /**
  353. * @}
  354. */
  355. /** @defgroup ADC_LL_EC_COMMON_CLOCK_FREQ_MODE ADC common - Clock frequency mode
  356. * @{
  357. */
  358. #define LL_ADC_CLOCK_FREQ_MODE_HIGH ((uint32_t)0x00000000U)/*!< ADC clock mode to high frequency. On STM32L0, ADC clock frequency above 2.8MHz. */
  359. #define LL_ADC_CLOCK_FREQ_MODE_LOW (ADC_CCR_LFMEN) /*!< ADC clock mode to low frequency. On STM32L0, ADC clock frequency below 2.8MHz. */
  360. /**
  361. * @}
  362. */
  363. /** @defgroup ADC_LL_EC_COMMON_PATH_INTERNAL ADC common - Measurement path to internal channels
  364. * @{
  365. */
  366. /* Note: Other measurement paths to internal channels may be available */
  367. /* (connections to other peripherals). */
  368. /* If they are not listed below, they do not require any specific */
  369. /* path enable. In this case, Access to measurement path is done */
  370. /* only by selecting the corresponding ADC internal channel. */
  371. #define LL_ADC_PATH_INTERNAL_NONE ((uint32_t)0x00000000U)/*!< ADC measurement pathes all disabled */
  372. #define LL_ADC_PATH_INTERNAL_VREFINT (ADC_CCR_VREFEN) /*!< ADC measurement path to internal channel VrefInt */
  373. #if defined(ADC_CCR_TSEN)
  374. #define LL_ADC_PATH_INTERNAL_TEMPSENSOR (ADC_CCR_TSEN) /*!< ADC measurement path to internal channel temperature sensor */
  375. #endif
  376. #if defined(ADC_CCR_VLCDEN)
  377. #define LL_ADC_PATH_INTERNAL_VLCD (ADC_CCR_VLCDEN) /*!< ADC measurement path to internal channel Vlcd */
  378. #endif
  379. /**
  380. * @}
  381. */
  382. /** @defgroup ADC_LL_EC_CLOCK_SOURCE ADC instance - Clock source
  383. * @{
  384. */
  385. #define LL_ADC_CLOCK_SYNC_PCLK_DIV4 (ADC_CFGR2_CKMODE_1) /*!< ADC synchronous clock derived from AHB clock divided by 4 */
  386. #define LL_ADC_CLOCK_SYNC_PCLK_DIV2 (ADC_CFGR2_CKMODE_0) /*!< ADC synchronous clock derived from AHB clock divided by 2 */
  387. #define LL_ADC_CLOCK_SYNC_PCLK_DIV1 (ADC_CFGR2_CKMODE_1 | ADC_CFGR2_CKMODE_0) /*!< ADC synchronous clock derived from AHB clock not divided */
  388. #define LL_ADC_CLOCK_ASYNC ((uint32_t)0x00000000U) /*!< ADC asynchronous clock. Asynchronous clock prescaler can be configured using function @ref LL_ADC_SetCommonClock(). */
  389. /**
  390. * @}
  391. */
  392. /** @defgroup ADC_LL_EC_RESOLUTION ADC instance - Resolution
  393. * @{
  394. */
  395. #define LL_ADC_RESOLUTION_12B ((uint32_t)0x00000000U) /*!< ADC resolution 12 bits */
  396. #define LL_ADC_RESOLUTION_10B ( ADC_CFGR1_RES_0) /*!< ADC resolution 10 bits */
  397. #define LL_ADC_RESOLUTION_8B (ADC_CFGR1_RES_1 ) /*!< ADC resolution 8 bits */
  398. #define LL_ADC_RESOLUTION_6B (ADC_CFGR1_RES_1 | ADC_CFGR1_RES_0) /*!< ADC resolution 6 bits */
  399. /**
  400. * @}
  401. */
  402. /** @defgroup ADC_LL_EC_DATA_ALIGN ADC instance - Data alignment
  403. * @{
  404. */
  405. #define LL_ADC_DATA_ALIGN_RIGHT ((uint32_t)0x00000000U)/*!< ADC conversion data alignment: right aligned (alignment on data register LSB bit 0)*/
  406. #define LL_ADC_DATA_ALIGN_LEFT (ADC_CFGR1_ALIGN) /*!< ADC conversion data alignment: left aligned (aligment on data register MSB bit 15)*/
  407. /**
  408. * @}
  409. */
  410. /** @defgroup ADC_LL_EC_LP_MODE ADC instance - Low power mode
  411. * @{
  412. */
  413. #define LL_ADC_LP_MODE_NONE ((uint32_t)0x00000000U) /*!< No ADC low power mode activated */
  414. #define LL_ADC_LP_AUTOWAIT (ADC_CFGR1_WAIT) /*!< 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(). */
  415. #define LL_ADC_LP_AUTOPOWEROFF (ADC_CFGR1_AUTOFF) /*!< ADC low power mode auto power-off: the ADC automatically powers-off after a ADC conversion and automatically wakes up when a new ADC conversion is triggered (with startup time between trigger and start of sampling). See description with function @ref LL_ADC_SetLowPowerMode(). */
  416. #define LL_ADC_LP_AUTOWAIT_AUTOPOWEROFF (ADC_CFGR1_WAIT | ADC_CFGR1_AUTOFF) /*!< ADC low power modes auto wait and auto power-off combined. See description with function @ref LL_ADC_SetLowPowerMode(). */
  417. /**
  418. * @}
  419. */
  420. /** @defgroup ADC_LL_EC_GROUPS ADC instance - Groups
  421. * @{
  422. */
  423. #define LL_ADC_GROUP_REGULAR ((uint32_t)0x00000001U) /*!< ADC group regular (available on all STM32 devices) */
  424. /**
  425. * @}
  426. */
  427. /** @defgroup ADC_LL_EC_CHANNEL ADC instance - Channel number
  428. * @{
  429. */
  430. #define LL_ADC_CHANNEL_0 (ADC_CHANNEL_0_NUMBER | ADC_CHANNEL_0_BITFIELD ) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN0 */
  431. #define LL_ADC_CHANNEL_1 (ADC_CHANNEL_1_NUMBER | ADC_CHANNEL_1_BITFIELD ) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN1 */
  432. #define LL_ADC_CHANNEL_2 (ADC_CHANNEL_2_NUMBER | ADC_CHANNEL_2_BITFIELD ) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN2 */
  433. #define LL_ADC_CHANNEL_3 (ADC_CHANNEL_3_NUMBER | ADC_CHANNEL_3_BITFIELD ) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN3 */
  434. #define LL_ADC_CHANNEL_4 (ADC_CHANNEL_4_NUMBER | ADC_CHANNEL_4_BITFIELD ) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN4 */
  435. #define LL_ADC_CHANNEL_5 (ADC_CHANNEL_5_NUMBER | ADC_CHANNEL_5_BITFIELD ) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN5 */
  436. #define LL_ADC_CHANNEL_6 (ADC_CHANNEL_6_NUMBER | ADC_CHANNEL_6_BITFIELD ) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN6 */
  437. #define LL_ADC_CHANNEL_7 (ADC_CHANNEL_7_NUMBER | ADC_CHANNEL_7_BITFIELD ) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN7 */
  438. #define LL_ADC_CHANNEL_8 (ADC_CHANNEL_8_NUMBER | ADC_CHANNEL_8_BITFIELD ) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN8 */
  439. #define LL_ADC_CHANNEL_9 (ADC_CHANNEL_9_NUMBER | ADC_CHANNEL_9_BITFIELD ) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN9 */
  440. #define LL_ADC_CHANNEL_10 (ADC_CHANNEL_10_NUMBER | ADC_CHANNEL_10_BITFIELD) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN10 */
  441. #define LL_ADC_CHANNEL_11 (ADC_CHANNEL_11_NUMBER | ADC_CHANNEL_11_BITFIELD) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN11 */
  442. #define LL_ADC_CHANNEL_12 (ADC_CHANNEL_12_NUMBER | ADC_CHANNEL_12_BITFIELD) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN12 */
  443. #define LL_ADC_CHANNEL_13 (ADC_CHANNEL_13_NUMBER | ADC_CHANNEL_13_BITFIELD) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN13 */
  444. #define LL_ADC_CHANNEL_14 (ADC_CHANNEL_14_NUMBER | ADC_CHANNEL_14_BITFIELD) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN14 */
  445. #define LL_ADC_CHANNEL_15 (ADC_CHANNEL_15_NUMBER | ADC_CHANNEL_15_BITFIELD) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN15 */
  446. #define LL_ADC_CHANNEL_17 (ADC_CHANNEL_17_NUMBER | ADC_CHANNEL_17_BITFIELD) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN17 */
  447. #define LL_ADC_CHANNEL_18 (ADC_CHANNEL_18_NUMBER | ADC_CHANNEL_18_BITFIELD) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN18 */
  448. #define LL_ADC_CHANNEL_VREFINT (LL_ADC_CHANNEL_17 | ADC_CHANNEL_ID_INTERNAL_CH) /*!< ADC internal channel connected to VrefInt: Internal voltage reference. */
  449. #define LL_ADC_CHANNEL_TEMPSENSOR (LL_ADC_CHANNEL_18 | ADC_CHANNEL_ID_INTERNAL_CH) /*!< ADC internal channel connected to Temperature sensor. */
  450. #if defined(ADC_CCR_VLCDEN)
  451. #define LL_ADC_CHANNEL_16 (ADC_CHANNEL_16_NUMBER | ADC_CHANNEL_16_BITFIELD) /*!< ADC external channel (channel connected to GPIO pin) ADCx_IN16 */
  452. #define LL_ADC_CHANNEL_VLCD (LL_ADC_CHANNEL_16 | ADC_CHANNEL_ID_INTERNAL_CH) /*!< ADC internal channel connected to Vlcd: Vlcd voltage through a divider ladder of factor 1/4, 1/3 or 1/2 (set by LCD voltage generator biasing), to have Vlcd always below Vdda. */
  453. #endif
  454. /**
  455. * @}
  456. */
  457. /** @defgroup ADC_LL_EC_REG_TRIGGER_SOURCE ADC group regular - Trigger source
  458. * @{
  459. */
  460. #define LL_ADC_REG_TRIG_SOFTWARE ((uint32_t)0x00000000U) /*!< ADC group regular conversion trigger internal: SW start. */
  461. #define LL_ADC_REG_TRIG_EXT_TIM6_TRGO (ADC_REG_TRIG_EXT_EDGE_DEFAULT) /*!< ADC group regular conversion trigger from external peripheral: TIM6 TRGO. Trigger edge set to rising edge (default setting). */
  462. #define LL_ADC_REG_TRIG_EXT_TIM21_CH2 (ADC_CFGR1_EXTSEL_0 | ADC_REG_TRIG_EXT_EDGE_DEFAULT) /*!< ADC group regular conversion trigger from external peripheral: TIM21 channel 2 event (capture compare: input capture or output capture). Trigger edge set to rising edge (default setting). */
  463. #define LL_ADC_REG_TRIG_EXT_TIM2_TRGO (ADC_CFGR1_EXTSEL_1 | ADC_REG_TRIG_EXT_EDGE_DEFAULT) /*!< ADC group regular conversion trigger from external peripheral: TIM2 TRGO. Trigger edge set to rising edge (default setting). */
  464. #define LL_ADC_REG_TRIG_EXT_TIM2_CH4 (ADC_CFGR1_EXTSEL_1 | ADC_CFGR1_EXTSEL_0 | ADC_REG_TRIG_EXT_EDGE_DEFAULT) /*!< ADC group regular conversion trigger from external peripheral: TIM2 channel 4 event (capture compare: input capture or output capture). Trigger edge set to rising edge (default setting). */
  465. #define LL_ADC_REG_TRIG_EXT_TIM22_TRGO (ADC_CFGR1_EXTSEL_2 | ADC_REG_TRIG_EXT_EDGE_DEFAULT) /*!< ADC group regular conversion trigger from external peripheral: TIM22 TRGO. Trigger edge set to rising edge (default setting). */
  466. #define LL_ADC_REG_TRIG_EXT_TIM3_TRGO (ADC_CFGR1_EXTSEL_2 | ADC_CFGR1_EXTSEL_1 | ADC_REG_TRIG_EXT_EDGE_DEFAULT) /*!< ADC group regular conversion trigger from external peripheral: TIM3 TRG0. Trigger edge set to rising edge (default setting). */
  467. #define LL_ADC_REG_TRIG_EXT_EXTI_LINE11 (ADC_CFGR1_EXTSEL_2 | ADC_CFGR1_EXTSEL_1 | ADC_CFGR1_EXTSEL_0 | 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). */
  468. /* ADC group regular external trigger TIM2_CC3 available only on */
  469. /* STM32L0 devices categories: Cat.1, Cat.2, Cat.5 */
  470. #if defined (STM32L011xx) || defined (STM32L021xx) || \
  471. defined (STM32L031xx) || defined (STM32L041xx) || \
  472. defined (STM32L071xx) || defined (STM32L072xx) || defined (STM32L073xx) || \
  473. defined (STM32L081xx) || defined (STM32L082xx) || defined (STM32L083xx) || \
  474. defined (STM32L010x6) || defined (STM32L010x8) || defined (STM32L010xB)
  475. #define LL_ADC_REG_TRIG_EXT_TIM2_CH3 (ADC_CFGR1_EXTSEL_2 | ADC_CFGR1_EXTSEL_0 | ADC_REG_TRIG_EXT_EDGE_DEFAULT) /*!< ADC group regular conversion trigger from external peripheral: TIM2 channel 4 event (capture compare: input capture or output capture). Trigger edge set to rising edge (default setting). */
  476. #endif
  477. /* ADC group regular external trigger TIM21_TRGO available only on */
  478. /* STM32L0 devices categories: Cat.2, Cat.3, Cat.5 */
  479. #if defined (STM32L031xx) || defined (STM32L041xx) || \
  480. defined (STM32L051xx) || defined (STM32L052xx) || defined (STM32L053xx) || \
  481. defined (STM32L061xx) || defined (STM32L062xx) || defined (STM32L063xx) || \
  482. defined (STM32L071xx) || defined (STM32L072xx) || defined (STM32L073xx) || \
  483. defined (STM32L081xx) || defined (STM32L082xx) || defined (STM32L083xx) || \
  484. defined (STM32L010x6) || defined (STM32L010x8) || defined (STM32L010xB)
  485. #define LL_ADC_REG_TRIG_EXT_TIM21_TRGO (LL_ADC_REG_TRIG_EXT_TIM22_TRGO)
  486. #endif
  487. /**
  488. * @}
  489. */
  490. /** @defgroup ADC_LL_EC_REG_TRIGGER_EDGE ADC group regular - Trigger edge
  491. * @{
  492. */
  493. #define LL_ADC_REG_TRIG_EXT_RISING ( ADC_CFGR1_EXTEN_0) /*!< ADC group regular conversion trigger polarity set to rising edge */
  494. #define LL_ADC_REG_TRIG_EXT_FALLING (ADC_CFGR1_EXTEN_1 ) /*!< ADC group regular conversion trigger polarity set to falling edge */
  495. #define LL_ADC_REG_TRIG_EXT_RISINGFALLING (ADC_CFGR1_EXTEN_1 | ADC_CFGR1_EXTEN_0) /*!< ADC group regular conversion trigger polarity set to both rising and falling edges */
  496. /**
  497. * @}
  498. */
  499. /** @defgroup ADC_LL_EC_REG_CONTINUOUS_MODE ADC group regular - Continuous mode
  500. * @{
  501. */
  502. #define LL_ADC_REG_CONV_SINGLE ((uint32_t)0x00000000U) /*!< ADC conversions are performed in single mode: one conversion per trigger */
  503. #define LL_ADC_REG_CONV_CONTINUOUS (ADC_CFGR1_CONT) /*!< ADC conversions are performed in continuous mode: after the first trigger, following conversions launched successively automatically */
  504. /**
  505. * @}
  506. */
  507. /** @defgroup ADC_LL_EC_REG_DMA_TRANSFER ADC group regular - DMA transfer of ADC conversion data
  508. * @{
  509. */
  510. #define LL_ADC_REG_DMA_TRANSFER_NONE ((uint32_t)0x00000000U) /*!< ADC conversions are not transferred by DMA */
  511. #define LL_ADC_REG_DMA_TRANSFER_LIMITED ( ADC_CFGR1_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. */
  512. #define LL_ADC_REG_DMA_TRANSFER_UNLIMITED (ADC_CFGR1_DMACFG | ADC_CFGR1_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. */
  513. /**
  514. * @}
  515. */
  516. /** @defgroup ADC_LL_EC_REG_OVR_DATA_BEHAVIOR ADC group regular - Overrun behavior on conversion data
  517. * @{
  518. */
  519. #define LL_ADC_REG_OVR_DATA_PRESERVED ((uint32_t)0x00000000U)/*!< ADC group regular behavior in case of overrun: data preserved */
  520. #define LL_ADC_REG_OVR_DATA_OVERWRITTEN (ADC_CFGR1_OVRMOD) /*!< ADC group regular behavior in case of overrun: data overwritten */
  521. /**
  522. * @}
  523. */
  524. /** @defgroup ADC_LL_EC_REG_SEQ_SCAN_DIRECTION ADC group regular - Sequencer scan direction
  525. * @{
  526. */
  527. #define LL_ADC_REG_SEQ_SCAN_DIR_FORWARD ((uint32_t)0x00000000U)/*!< ADC group regular sequencer scan direction forward: from lowest channel number to highest channel number (scan of all ranks, ADC conversion of ranks with channels enabled in sequencer). On some other STM32 families, this setting is not available and the default scan direction is forward. */
  528. #define LL_ADC_REG_SEQ_SCAN_DIR_BACKWARD (ADC_CFGR1_SCANDIR) /*!< ADC group regular sequencer scan direction backward: from highest channel number to lowest channel number (scan of all ranks, ADC conversion of ranks with channels enabled in sequencer) */
  529. /**
  530. * @}
  531. */
  532. /** @defgroup ADC_LL_EC_REG_SEQ_DISCONT_MODE ADC group regular - Sequencer discontinuous mode
  533. * @{
  534. */
  535. #define LL_ADC_REG_SEQ_DISCONT_DISABLE ((uint32_t)0x00000000U) /*!< ADC group regular sequencer discontinuous mode disable */
  536. #define LL_ADC_REG_SEQ_DISCONT_1RANK (ADC_CFGR1_DISCEN) /*!< ADC group regular sequencer discontinuous mode enable with sequence interruption every rank */
  537. /**
  538. * @}
  539. */
  540. /** @defgroup ADC_LL_EC_CHANNEL_SAMPLINGTIME Channel - Sampling time
  541. * @{
  542. */
  543. #define LL_ADC_SAMPLINGTIME_1CYCLE_5 ((uint32_t)0x00000000U) /*!< Sampling time 1.5 ADC clock cycle */
  544. #define LL_ADC_SAMPLINGTIME_3CYCLES_5 (ADC_SMPR_SMP_0) /*!< Sampling time 3.5 ADC clock cycles */
  545. #define LL_ADC_SAMPLINGTIME_7CYCLES_5 (ADC_SMPR_SMP_1) /*!< Sampling time 7.5 ADC clock cycles */
  546. #define LL_ADC_SAMPLINGTIME_12CYCLES_5 (ADC_SMPR_SMP_1 | ADC_SMPR_SMP_0) /*!< Sampling time 12.5 ADC clock cycles */
  547. #define LL_ADC_SAMPLINGTIME_19CYCLES_5 (ADC_SMPR_SMP_2) /*!< Sampling time 19.5 ADC clock cycles */
  548. #define LL_ADC_SAMPLINGTIME_39CYCLES_5 (ADC_SMPR_SMP_2 | ADC_SMPR_SMP_0) /*!< Sampling time 39.5 ADC clock cycles */
  549. #define LL_ADC_SAMPLINGTIME_79CYCLES_5 (ADC_SMPR_SMP_2 | ADC_SMPR_SMP_1) /*!< Sampling time 79.5 ADC clock cycles */
  550. #define LL_ADC_SAMPLINGTIME_160CYCLES_5 (ADC_SMPR_SMP_2 | ADC_SMPR_SMP_1 | ADC_SMPR_SMP_0) /*!< Sampling time 160.5 ADC clock cycles */
  551. /**
  552. * @}
  553. */
  554. /** @defgroup ADC_LL_EC_AWD_NUMBER Analog watchdog - Analog watchdog number
  555. * @{
  556. */
  557. #define LL_ADC_AWD1 (ADC_AWD_CR1_CHANNEL_MASK | ADC_AWD_CR1_REGOFFSET) /*!< ADC analog watchdog number 1 */
  558. /**
  559. * @}
  560. */
  561. /** @defgroup ADC_LL_EC_AWD_CHANNELS Analog watchdog - Monitored channels
  562. * @{
  563. */
  564. #define LL_ADC_AWD_DISABLE ((uint32_t)0x00000000U) /*!< ADC analog watchdog monitoring disabled */
  565. #define LL_ADC_AWD_ALL_CHANNELS_REG ( ADC_CFGR1_AWDEN ) /*!< ADC analog watchdog monitoring of all channels, converted by group regular only */
  566. #define LL_ADC_AWD_CHANNEL_0_REG ((LL_ADC_CHANNEL_0 & ADC_CHANNEL_ID_MASK) | ADC_CFGR1_AWDEN | ADC_CFGR1_AWDSGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN0, converted by group regular only */
  567. #define LL_ADC_AWD_CHANNEL_1_REG ((LL_ADC_CHANNEL_1 & ADC_CHANNEL_ID_MASK) | ADC_CFGR1_AWDEN | ADC_CFGR1_AWDSGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN1, converted by group regular only */
  568. #define LL_ADC_AWD_CHANNEL_2_REG ((LL_ADC_CHANNEL_2 & ADC_CHANNEL_ID_MASK) | ADC_CFGR1_AWDEN | ADC_CFGR1_AWDSGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN2, converted by group regular only */
  569. #define LL_ADC_AWD_CHANNEL_3_REG ((LL_ADC_CHANNEL_3 & ADC_CHANNEL_ID_MASK) | ADC_CFGR1_AWDEN | ADC_CFGR1_AWDSGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN3, converted by group regular only */
  570. #define LL_ADC_AWD_CHANNEL_4_REG ((LL_ADC_CHANNEL_4 & ADC_CHANNEL_ID_MASK) | ADC_CFGR1_AWDEN | ADC_CFGR1_AWDSGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN4, converted by group regular only */
  571. #define LL_ADC_AWD_CHANNEL_5_REG ((LL_ADC_CHANNEL_5 & ADC_CHANNEL_ID_MASK) | ADC_CFGR1_AWDEN | ADC_CFGR1_AWDSGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN5, converted by group regular only */
  572. #define LL_ADC_AWD_CHANNEL_6_REG ((LL_ADC_CHANNEL_6 & ADC_CHANNEL_ID_MASK) | ADC_CFGR1_AWDEN | ADC_CFGR1_AWDSGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN6, converted by group regular only */
  573. #define LL_ADC_AWD_CHANNEL_7_REG ((LL_ADC_CHANNEL_7 & ADC_CHANNEL_ID_MASK) | ADC_CFGR1_AWDEN | ADC_CFGR1_AWDSGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN7, converted by group regular only */
  574. #define LL_ADC_AWD_CHANNEL_8_REG ((LL_ADC_CHANNEL_8 & ADC_CHANNEL_ID_MASK) | ADC_CFGR1_AWDEN | ADC_CFGR1_AWDSGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN8, converted by group regular only */
  575. #define LL_ADC_AWD_CHANNEL_9_REG ((LL_ADC_CHANNEL_9 & ADC_CHANNEL_ID_MASK) | ADC_CFGR1_AWDEN | ADC_CFGR1_AWDSGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN9, converted by group regular only */
  576. #define LL_ADC_AWD_CHANNEL_10_REG ((LL_ADC_CHANNEL_10 & ADC_CHANNEL_ID_MASK) | ADC_CFGR1_AWDEN | ADC_CFGR1_AWDSGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN10, converted by group regular only */
  577. #define LL_ADC_AWD_CHANNEL_11_REG ((LL_ADC_CHANNEL_11 & ADC_CHANNEL_ID_MASK) | ADC_CFGR1_AWDEN | ADC_CFGR1_AWDSGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN11, converted by group regular only */
  578. #define LL_ADC_AWD_CHANNEL_12_REG ((LL_ADC_CHANNEL_12 & ADC_CHANNEL_ID_MASK) | ADC_CFGR1_AWDEN | ADC_CFGR1_AWDSGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN12, converted by group regular only */
  579. #define LL_ADC_AWD_CHANNEL_13_REG ((LL_ADC_CHANNEL_13 & ADC_CHANNEL_ID_MASK) | ADC_CFGR1_AWDEN | ADC_CFGR1_AWDSGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN13, converted by group regular only */
  580. #define LL_ADC_AWD_CHANNEL_14_REG ((LL_ADC_CHANNEL_14 & ADC_CHANNEL_ID_MASK) | ADC_CFGR1_AWDEN | ADC_CFGR1_AWDSGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN14, converted by group regular only */
  581. #define LL_ADC_AWD_CHANNEL_15_REG ((LL_ADC_CHANNEL_15 & ADC_CHANNEL_ID_MASK) | ADC_CFGR1_AWDEN | ADC_CFGR1_AWDSGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN15, converted by group regular only */
  582. #define LL_ADC_AWD_CHANNEL_17_REG ((LL_ADC_CHANNEL_17 & ADC_CHANNEL_ID_MASK) | ADC_CFGR1_AWDEN | ADC_CFGR1_AWDSGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN17, converted by group regular only */
  583. #define LL_ADC_AWD_CHANNEL_18_REG ((LL_ADC_CHANNEL_18 & ADC_CHANNEL_ID_MASK) | ADC_CFGR1_AWDEN | ADC_CFGR1_AWDSGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN18, converted by group regular only */
  584. #define LL_ADC_AWD_CH_VREFINT_REG ((LL_ADC_CHANNEL_VREFINT & ADC_CHANNEL_ID_MASK) | ADC_CFGR1_AWDEN | ADC_CFGR1_AWDSGL) /*!< ADC analog watchdog monitoring of ADC internal channel connected to VrefInt: Internal voltage reference, converted by group regular only */
  585. #define LL_ADC_AWD_CH_TEMPSENSOR_REG ((LL_ADC_CHANNEL_TEMPSENSOR & ADC_CHANNEL_ID_MASK) | ADC_CFGR1_AWDEN | ADC_CFGR1_AWDSGL) /*!< ADC analog watchdog monitoring of ADC internal channel connected to Temperature sensor, converted by group regular only */
  586. #if defined(ADC_CCR_VLCDEN)
  587. #define LL_ADC_AWD_CHANNEL_16_REG ((LL_ADC_CHANNEL_16 & ADC_CHANNEL_ID_MASK) | ADC_CFGR1_AWDEN | ADC_CFGR1_AWDSGL) /*!< ADC analog watchdog monitoring of ADC external channel (channel connected to GPIO pin) ADCx_IN16, converted by group regular only */
  588. #define LL_ADC_AWD_CH_VLCD_REG ((LL_ADC_CHANNEL_VLCD & ADC_CHANNEL_ID_MASK) | ADC_CFGR1_AWDEN | ADC_CFGR1_AWDSGL) /*!< 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 */
  589. #endif
  590. /**
  591. * @}
  592. */
  593. /** @defgroup ADC_LL_EC_AWD_THRESHOLDS Analog watchdog - Thresholds
  594. * @{
  595. */
  596. #define LL_ADC_AWD_THRESHOLD_HIGH (ADC_TR_HT ) /*!< ADC analog watchdog threshold high */
  597. #define LL_ADC_AWD_THRESHOLD_LOW ( ADC_TR_LT) /*!< ADC analog watchdog threshold low */
  598. #define LL_ADC_AWD_THRESHOLDS_HIGH_LOW (ADC_TR_HT | ADC_TR_LT) /*!< ADC analog watchdog both thresholds high and low concatenated into the same data */
  599. /**
  600. * @}
  601. */
  602. /** @defgroup ADC_LL_EC_OVS_SCOPE Oversampling - Oversampling scope
  603. * @{
  604. */
  605. #define LL_ADC_OVS_DISABLE ((uint32_t)0x00000000U) /*!< ADC oversampling disabled. */
  606. #define LL_ADC_OVS_GRP_REGULAR_CONTINUED ( ADC_CFGR2_OVSE) /*!< ADC oversampling on conversions of ADC group regular. Literal suffix "continued" is kept for compatibility with other STM32 devices featuring ADC group injected, in this case other oversampling scope parameters are available. */
  607. /**
  608. * @}
  609. */
  610. /** @defgroup ADC_LL_EC_OVS_DISCONT_MODE Oversampling - Discontinuous mode
  611. * @{
  612. */
  613. #define LL_ADC_OVS_REG_CONT ((uint32_t)0x00000000U)/*!< ADC oversampling discontinuous mode: continuous mode (all conversions of oversampling ratio are done from 1 trigger) */
  614. #define LL_ADC_OVS_REG_DISCONT (ADC_CFGR2_TOVS) /*!< ADC oversampling discontinuous mode: discontinuous mode (each conversion of oversampling ratio needs a trigger) */
  615. /**
  616. * @}
  617. */
  618. /** @defgroup ADC_LL_EC_OVS_RATIO Oversampling - Ratio
  619. * @{
  620. */
  621. #define LL_ADC_OVS_RATIO_2 ((uint32_t)0x00000000U) /*!< 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) */
  622. #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) */
  623. #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) */
  624. #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) */
  625. #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) */
  626. #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) */
  627. #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) */
  628. #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) */
  629. /**
  630. * @}
  631. */
  632. /** @defgroup ADC_LL_EC_OVS_SHIFT Oversampling - Data shift
  633. * @{
  634. */
  635. #define LL_ADC_OVS_SHIFT_NONE ((uint32_t)0x00000000U) /*!< ADC oversampling no shift (sum of the ADC conversions data is not divided to result as the ADC oversampling conversion data) */
  636. #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) */
  637. #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) */
  638. #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) */
  639. #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) */
  640. #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) */
  641. #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) */
  642. #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) */
  643. #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) */
  644. /**
  645. * @}
  646. */
  647. /** @defgroup ADC_LL_EC_HW_DELAYS Definitions of ADC hardware constraints delays
  648. * @note Only ADC peripheral HW delays are defined in ADC LL driver driver,
  649. * not timeout values.
  650. * For details on delays values, refer to descriptions in source code
  651. * above each literal definition.
  652. * @{
  653. */
  654. /* Note: Only ADC peripheral HW delays are defined in ADC LL driver driver, */
  655. /* not timeout values. */
  656. /* Timeout values for ADC operations are dependent to device clock */
  657. /* configuration (system clock versus ADC clock), */
  658. /* and therefore must be defined in user application. */
  659. /* Indications for estimation of ADC timeout delays, for this */
  660. /* STM32 serie: */
  661. /* - ADC calibration time: maximum delay is 83/fADC. */
  662. /* (refer to device datasheet, parameter "tCAL") */
  663. /* - ADC enable time: maximum delay is 1 conversion cycle. */
  664. /* (refer to device datasheet, parameter "tSTAB") */
  665. /* - ADC disable time: maximum delay should be a few ADC clock cycles */
  666. /* - ADC stop conversion time: maximum delay should be a few ADC clock */
  667. /* cycles */
  668. /* - ADC conversion time: duration depending on ADC clock and ADC */
  669. /* configuration. */
  670. /* (refer to device reference manual, section "Timing") */
  671. /* Delay for ADC stabilization time (ADC voltage regulator start-up time) */
  672. /* Delay set to maximum value (refer to device datasheet, */
  673. /* parameter "tUP_LDO"). */
  674. #define LL_ADC_DELAY_INTERNAL_REGUL_STAB_US ((uint32_t) 10U) /*!< Delay for ADC stabilization time (ADC voltage regulator start-up time) */
  675. /* Delay for internal voltage reference stabilization time. */
  676. /* Delay set to maximum value (refer to device datasheet, */
  677. /* parameter "TADC_BUF"). */
  678. /* Unit: us */
  679. #define LL_ADC_DELAY_VREFINT_STAB_US ((uint32_t) 10U) /*!< Delay for internal voltage reference stabilization time */
  680. /* Delay for temperature sensor stabilization time. */
  681. /* Literal set to maximum value (refer to device datasheet, */
  682. /* parameter "tSTART"). */
  683. /* Unit: us */
  684. #define LL_ADC_DELAY_TEMPSENSOR_STAB_US ((uint32_t) 10U) /*!< Delay for temperature sensor stabilization time */
  685. /* Delay required between ADC end of calibration and ADC enable. */
  686. /* Note: On this STM32 serie, a minimum number of ADC clock cycles */
  687. /* are required between ADC end of calibration and ADC enable. */
  688. /* Wait time can be computed in user application by waiting for the */
  689. /* equivalent number of CPU cycles, by taking into account */
  690. /* ratio of CPU clock versus ADC clock prescalers. */
  691. /* Unit: ADC clock cycles. */
  692. #define LL_ADC_DELAY_CALIB_ENABLE_ADC_CYCLES ((uint32_t) 2U) /*!< Delay required between ADC end of calibration and ADC enable */
  693. /**
  694. * @}
  695. */
  696. /**
  697. * @}
  698. */
  699. /* Exported macro ------------------------------------------------------------*/
  700. /** @defgroup ADC_LL_Exported_Macros ADC Exported Macros
  701. * @{
  702. */
  703. /** @defgroup ADC_LL_EM_WRITE_READ Common write and read registers Macros
  704. * @{
  705. */
  706. /**
  707. * @brief Write a value in ADC register
  708. * @param __INSTANCE__ ADC Instance
  709. * @param __REG__ Register to be written
  710. * @param __VALUE__ Value to be written in the register
  711. * @retval None
  712. */
  713. #define LL_ADC_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__))
  714. /**
  715. * @brief Read a value in ADC register
  716. * @param __INSTANCE__ ADC Instance
  717. * @param __REG__ Register to be read
  718. * @retval Register value
  719. */
  720. #define LL_ADC_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
  721. /**
  722. * @}
  723. */
  724. /** @defgroup ADC_LL_EM_HELPER_MACRO ADC helper macro
  725. * @{
  726. */
  727. /**
  728. * @brief Helper macro to get ADC channel number in decimal format
  729. * from literals LL_ADC_CHANNEL_x.
  730. * @note Example:
  731. * __LL_ADC_CHANNEL_TO_DECIMAL_NB(LL_ADC_CHANNEL_4)
  732. * will return decimal number "4".
  733. * @note The input can be a value from functions where a channel
  734. * number is returned, either defined with number
  735. * or with bitfield (only one bit must be set).
  736. * @param __CHANNEL__ This parameter can be one of the following values:
  737. * @arg @ref LL_ADC_CHANNEL_0
  738. * @arg @ref LL_ADC_CHANNEL_1
  739. * @arg @ref LL_ADC_CHANNEL_2
  740. * @arg @ref LL_ADC_CHANNEL_3
  741. * @arg @ref LL_ADC_CHANNEL_4
  742. * @arg @ref LL_ADC_CHANNEL_5
  743. * @arg @ref LL_ADC_CHANNEL_6
  744. * @arg @ref LL_ADC_CHANNEL_7
  745. * @arg @ref LL_ADC_CHANNEL_8
  746. * @arg @ref LL_ADC_CHANNEL_9
  747. * @arg @ref LL_ADC_CHANNEL_10
  748. * @arg @ref LL_ADC_CHANNEL_11
  749. * @arg @ref LL_ADC_CHANNEL_12
  750. * @arg @ref LL_ADC_CHANNEL_13
  751. * @arg @ref LL_ADC_CHANNEL_14
  752. * @arg @ref LL_ADC_CHANNEL_15
  753. * @arg @ref LL_ADC_CHANNEL_16 (1)
  754. * @arg @ref LL_ADC_CHANNEL_17
  755. * @arg @ref LL_ADC_CHANNEL_18
  756. * @arg @ref LL_ADC_CHANNEL_VREFINT
  757. * @arg @ref LL_ADC_CHANNEL_TEMPSENSOR
  758. * @arg @ref LL_ADC_CHANNEL_VLCD (1)
  759. *
  760. * (1) On STM32L0, parameter not available on all devices: only on STM32L053xx, STM32L063xx, STM32L073xx, STM32L083xx.
  761. * @retval Value between Min_Data=0 and Max_Data=18
  762. */
  763. #if defined(ADC_CCR_VLCDEN)
  764. #define __LL_ADC_CHANNEL_TO_DECIMAL_NB(__CHANNEL__) \
  765. ((((__CHANNEL__) & ADC_CHANNEL_ID_BITFIELD_MASK) == 0U) \
  766. ? ( \
  767. ((__CHANNEL__) & ADC_CHANNEL_ID_NUMBER_MASK) >> ADC_CHANNEL_ID_NUMBER_BITOFFSET_POS \
  768. ) \
  769. : \
  770. ( \
  771. (((__CHANNEL__) & ADC_CHSELR_CHSEL0) == ADC_CHSELR_CHSEL0) ? (0U) : \
  772. ( \
  773. (((__CHANNEL__) & ADC_CHSELR_CHSEL1) == ADC_CHSELR_CHSEL1) ? (1U) : \
  774. ( \
  775. (((__CHANNEL__) & ADC_CHSELR_CHSEL2) == ADC_CHSELR_CHSEL2) ? (2U) : \
  776. ( \
  777. (((__CHANNEL__) & ADC_CHSELR_CHSEL3) == ADC_CHSELR_CHSEL3) ? (3U) : \
  778. ( \
  779. (((__CHANNEL__) & ADC_CHSELR_CHSEL4) == ADC_CHSELR_CHSEL4) ? (4U) : \
  780. ( \
  781. (((__CHANNEL__) & ADC_CHSELR_CHSEL5) == ADC_CHSELR_CHSEL5) ? (5U) : \
  782. ( \
  783. (((__CHANNEL__) & ADC_CHSELR_CHSEL6) == ADC_CHSELR_CHSEL6) ? (6U) : \
  784. ( \
  785. (((__CHANNEL__) & ADC_CHSELR_CHSEL7) == ADC_CHSELR_CHSEL7) ? (7U) : \
  786. ( \
  787. (((__CHANNEL__) & ADC_CHSELR_CHSEL8) == ADC_CHSELR_CHSEL8) ? (8U) : \
  788. ( \
  789. (((__CHANNEL__) & ADC_CHSELR_CHSEL9) == ADC_CHSELR_CHSEL9) ? (9U) : \
  790. ( \
  791. (((__CHANNEL__) & ADC_CHSELR_CHSEL10) == ADC_CHSELR_CHSEL10) ? (10U) : \
  792. ( \
  793. (((__CHANNEL__) & ADC_CHSELR_CHSEL11) == ADC_CHSELR_CHSEL11) ? (11U) : \
  794. ( \
  795. (((__CHANNEL__) & ADC_CHSELR_CHSEL12) == ADC_CHSELR_CHSEL12) ? (12U) : \
  796. ( \
  797. (((__CHANNEL__) & ADC_CHSELR_CHSEL13) == ADC_CHSELR_CHSEL13) ? (13U) : \
  798. ( \
  799. (((__CHANNEL__) & ADC_CHSELR_CHSEL14) == ADC_CHSELR_CHSEL14) ? (14U) : \
  800. ( \
  801. (((__CHANNEL__) & ADC_CHSELR_CHSEL15) == ADC_CHSELR_CHSEL15) ? (15U) : \
  802. ( \
  803. (((__CHANNEL__) & ADC_CHSELR_CHSEL16) == ADC_CHSELR_CHSEL16) ? (16U) : \
  804. ( \
  805. (((__CHANNEL__) & ADC_CHSELR_CHSEL17) == ADC_CHSELR_CHSEL17) ? (17U) : \
  806. ( \
  807. (((__CHANNEL__) & ADC_CHSELR_CHSEL18) == ADC_CHSELR_CHSEL18) ? (18U) : \
  808. (0U) \
  809. ) \
  810. ) \
  811. ) \
  812. ) \
  813. ) \
  814. ) \
  815. ) \
  816. ) \
  817. ) \
  818. ) \
  819. ) \
  820. ) \
  821. ) \
  822. ) \
  823. ) \
  824. ) \
  825. ) \
  826. ) \
  827. ) \
  828. )
  829. #else
  830. #define __LL_ADC_CHANNEL_TO_DECIMAL_NB(__CHANNEL__) \
  831. ((((__CHANNEL__) & ADC_CHANNEL_ID_BITFIELD_MASK) == 0U) \
  832. ? ( \
  833. ((__CHANNEL__) & ADC_CHANNEL_ID_NUMBER_MASK) >> ADC_CHANNEL_ID_NUMBER_BITOFFSET_POS \
  834. ) \
  835. : \
  836. ( \
  837. (((__CHANNEL__) & ADC_CHSELR_CHSEL0) == ADC_CHSELR_CHSEL0) ? (0U) : \
  838. ( \
  839. (((__CHANNEL__) & ADC_CHSELR_CHSEL1) == ADC_CHSELR_CHSEL1) ? (1U) : \
  840. ( \
  841. (((__CHANNEL__) & ADC_CHSELR_CHSEL2) == ADC_CHSELR_CHSEL2) ? (2U) : \
  842. ( \
  843. (((__CHANNEL__) & ADC_CHSELR_CHSEL3) == ADC_CHSELR_CHSEL3) ? (3U) : \
  844. ( \
  845. (((__CHANNEL__) & ADC_CHSELR_CHSEL4) == ADC_CHSELR_CHSEL4) ? (4U) : \
  846. ( \
  847. (((__CHANNEL__) & ADC_CHSELR_CHSEL5) == ADC_CHSELR_CHSEL5) ? (5U) : \
  848. ( \
  849. (((__CHANNEL__) & ADC_CHSELR_CHSEL6) == ADC_CHSELR_CHSEL6) ? (6U) : \
  850. ( \
  851. (((__CHANNEL__) & ADC_CHSELR_CHSEL7) == ADC_CHSELR_CHSEL7) ? (7U) : \
  852. ( \
  853. (((__CHANNEL__) & ADC_CHSELR_CHSEL8) == ADC_CHSELR_CHSEL8) ? (8U) : \
  854. ( \
  855. (((__CHANNEL__) & ADC_CHSELR_CHSEL9) == ADC_CHSELR_CHSEL9) ? (9U) : \
  856. ( \
  857. (((__CHANNEL__) & ADC_CHSELR_CHSEL10) == ADC_CHSELR_CHSEL10) ? (10U) : \
  858. ( \
  859. (((__CHANNEL__) & ADC_CHSELR_CHSEL11) == ADC_CHSELR_CHSEL11) ? (11U) : \
  860. ( \
  861. (((__CHANNEL__) & ADC_CHSELR_CHSEL12) == ADC_CHSELR_CHSEL12) ? (12U) : \
  862. ( \
  863. (((__CHANNEL__) & ADC_CHSELR_CHSEL13) == ADC_CHSELR_CHSEL13) ? (13U) : \
  864. ( \
  865. (((__CHANNEL__) & ADC_CHSELR_CHSEL14) == ADC_CHSELR_CHSEL14) ? (14U) : \
  866. ( \
  867. (((__CHANNEL__) & ADC_CHSELR_CHSEL15) == ADC_CHSELR_CHSEL15) ? (15U) : \
  868. ( \
  869. (((__CHANNEL__) & ADC_CHSELR_CHSEL17) == ADC_CHSELR_CHSEL17) ? (17U) : \
  870. ( \
  871. (((__CHANNEL__) & ADC_CHSELR_CHSEL18) == ADC_CHSELR_CHSEL18) ? (18U) : \
  872. (0U) \
  873. ) \
  874. ) \
  875. ) \
  876. ) \
  877. ) \
  878. ) \
  879. ) \
  880. ) \
  881. ) \
  882. ) \
  883. ) \
  884. ) \
  885. ) \
  886. ) \
  887. ) \
  888. ) \
  889. ) \
  890. ) \
  891. )
  892. #endif
  893. /**
  894. * @brief Helper macro to get ADC channel in literal format LL_ADC_CHANNEL_x
  895. * from number in decimal format.
  896. * @note Example:
  897. * __LL_ADC_DECIMAL_NB_TO_CHANNEL(4)
  898. * will return a data equivalent to "LL_ADC_CHANNEL_4".
  899. * @param __DECIMAL_NB__ Value between Min_Data=0 and Max_Data=18
  900. * @retval Returned value can be one of the following values:
  901. * @arg @ref LL_ADC_CHANNEL_0
  902. * @arg @ref LL_ADC_CHANNEL_1
  903. * @arg @ref LL_ADC_CHANNEL_2
  904. * @arg @ref LL_ADC_CHANNEL_3
  905. * @arg @ref LL_ADC_CHANNEL_4
  906. * @arg @ref LL_ADC_CHANNEL_5
  907. * @arg @ref LL_ADC_CHANNEL_6
  908. * @arg @ref LL_ADC_CHANNEL_7
  909. * @arg @ref LL_ADC_CHANNEL_8
  910. * @arg @ref LL_ADC_CHANNEL_9
  911. * @arg @ref LL_ADC_CHANNEL_10
  912. * @arg @ref LL_ADC_CHANNEL_11
  913. * @arg @ref LL_ADC_CHANNEL_12
  914. * @arg @ref LL_ADC_CHANNEL_13
  915. * @arg @ref LL_ADC_CHANNEL_14
  916. * @arg @ref LL_ADC_CHANNEL_15
  917. * @arg @ref LL_ADC_CHANNEL_16 (1)
  918. * @arg @ref LL_ADC_CHANNEL_17
  919. * @arg @ref LL_ADC_CHANNEL_18
  920. * @arg @ref LL_ADC_CHANNEL_VREFINT (2)
  921. * @arg @ref LL_ADC_CHANNEL_TEMPSENSOR (2)
  922. * @arg @ref LL_ADC_CHANNEL_VLCD (1)(2)
  923. *
  924. * (1) On STM32L0, parameter not available on all devices: only on STM32L053xx, STM32L063xx, STM32L073xx, STM32L083xx.\n
  925. * (2) For ADC channel read back from ADC register,
  926. * comparison with internal channel parameter to be done
  927. * using helper macro @ref __LL_ADC_CHANNEL_INTERNAL_TO_EXTERNAL().
  928. */
  929. #define __LL_ADC_DECIMAL_NB_TO_CHANNEL(__DECIMAL_NB__) \
  930. ( \
  931. ((__DECIMAL_NB__) << ADC_CHANNEL_ID_NUMBER_BITOFFSET_POS) | \
  932. (ADC_CHSELR_CHSEL0 << (__DECIMAL_NB__)) \
  933. )
  934. /**
  935. * @brief Helper macro to determine whether the selected channel
  936. * corresponds to literal definitions of driver.
  937. * @note The different literal definitions of ADC channels are:
  938. * - ADC internal channel:
  939. * LL_ADC_CHANNEL_VREFINT, LL_ADC_CHANNEL_TEMPSENSOR, ...
  940. * - ADC external channel (channel connected to a GPIO pin):
  941. * LL_ADC_CHANNEL_1, LL_ADC_CHANNEL_2, ...
  942. * @note The channel parameter must be a value defined from literal
  943. * definition of a ADC internal channel (LL_ADC_CHANNEL_VREFINT,
  944. * LL_ADC_CHANNEL_TEMPSENSOR, ...),
  945. * ADC external channel (LL_ADC_CHANNEL_1, LL_ADC_CHANNEL_2, ...),
  946. * must not be a value from functions where a channel number is
  947. * returned from ADC registers,
  948. * because internal and external channels share the same channel
  949. * number in ADC registers. The differentiation is made only with
  950. * parameters definitions of driver.
  951. * @param __CHANNEL__ This parameter can be one of the following values:
  952. * @arg @ref LL_ADC_CHANNEL_0
  953. * @arg @ref LL_ADC_CHANNEL_1
  954. * @arg @ref LL_ADC_CHANNEL_2
  955. * @arg @ref LL_ADC_CHANNEL_3
  956. * @arg @ref LL_ADC_CHANNEL_4
  957. * @arg @ref LL_ADC_CHANNEL_5
  958. * @arg @ref LL_ADC_CHANNEL_6
  959. * @arg @ref LL_ADC_CHANNEL_7
  960. * @arg @ref LL_ADC_CHANNEL_8
  961. * @arg @ref LL_ADC_CHANNEL_9
  962. * @arg @ref LL_ADC_CHANNEL_10
  963. * @arg @ref LL_ADC_CHANNEL_11
  964. * @arg @ref LL_ADC_CHANNEL_12
  965. * @arg @ref LL_ADC_CHANNEL_13
  966. * @arg @ref LL_ADC_CHANNEL_14
  967. * @arg @ref LL_ADC_CHANNEL_15
  968. * @arg @ref LL_ADC_CHANNEL_16 (1)
  969. * @arg @ref LL_ADC_CHANNEL_17
  970. * @arg @ref LL_ADC_CHANNEL_18
  971. * @arg @ref LL_ADC_CHANNEL_VREFINT
  972. * @arg @ref LL_ADC_CHANNEL_TEMPSENSOR
  973. * @arg @ref LL_ADC_CHANNEL_VLCD (1)
  974. *
  975. * (1) On STM32L0, parameter not available on all devices: only on STM32L053xx, STM32L063xx, STM32L073xx, STM32L083xx.
  976. * @retval Value "0" if the channel corresponds to a parameter definition of a ADC external channel (channel connected to a GPIO pin).
  977. * Value "1" if the channel corresponds to a parameter definition of a ADC internal channel.
  978. */
  979. #define __LL_ADC_IS_CHANNEL_INTERNAL(__CHANNEL__) \
  980. (((__CHANNEL__) & ADC_CHANNEL_ID_INTERNAL_CH_MASK) != 0U)
  981. /**
  982. * @brief Helper macro to convert a channel defined from parameter
  983. * definition of a ADC internal channel (LL_ADC_CHANNEL_VREFINT,
  984. * LL_ADC_CHANNEL_TEMPSENSOR, ...),
  985. * to its equivalent parameter definition of a ADC external channel
  986. * (LL_ADC_CHANNEL_1, LL_ADC_CHANNEL_2, ...).
  987. * @note The channel parameter can be, additionally to a value
  988. * defined from parameter definition of a ADC internal channel
  989. * (LL_ADC_CHANNEL_VREFINT, LL_ADC_CHANNEL_TEMPSENSOR, ...),
  990. * a value defined from parameter definition of
  991. * ADC external channel (LL_ADC_CHANNEL_1, LL_ADC_CHANNEL_2, ...)
  992. * or a value from functions where a channel number is returned
  993. * from ADC registers.
  994. * @param __CHANNEL__ This parameter can be one of the following values:
  995. * @arg @ref LL_ADC_CHANNEL_0
  996. * @arg @ref LL_ADC_CHANNEL_1
  997. * @arg @ref LL_ADC_CHANNEL_2
  998. * @arg @ref LL_ADC_CHANNEL_3
  999. * @arg @ref LL_ADC_CHANNEL_4
  1000. * @arg @ref LL_ADC_CHANNEL_5
  1001. * @arg @ref LL_ADC_CHANNEL_6
  1002. * @arg @ref LL_ADC_CHANNEL_7
  1003. * @arg @ref LL_ADC_CHANNEL_8
  1004. * @arg @ref LL_ADC_CHANNEL_9
  1005. * @arg @ref LL_ADC_CHANNEL_10
  1006. * @arg @ref LL_ADC_CHANNEL_11
  1007. * @arg @ref LL_ADC_CHANNEL_12
  1008. * @arg @ref LL_ADC_CHANNEL_13
  1009. * @arg @ref LL_ADC_CHANNEL_14
  1010. * @arg @ref LL_ADC_CHANNEL_15
  1011. * @arg @ref LL_ADC_CHANNEL_16 (1)
  1012. * @arg @ref LL_ADC_CHANNEL_17
  1013. * @arg @ref LL_ADC_CHANNEL_18
  1014. * @arg @ref LL_ADC_CHANNEL_VREFINT
  1015. * @arg @ref LL_ADC_CHANNEL_TEMPSENSOR
  1016. * @arg @ref LL_ADC_CHANNEL_VLCD (1)
  1017. *
  1018. * (1) On STM32L0, parameter not available on all devices: only on STM32L053xx, STM32L063xx, STM32L073xx, STM32L083xx.
  1019. * @retval Returned value can be one of the following values:
  1020. * @arg @ref LL_ADC_CHANNEL_0
  1021. * @arg @ref LL_ADC_CHANNEL_1
  1022. * @arg @ref LL_ADC_CHANNEL_2
  1023. * @arg @ref LL_ADC_CHANNEL_3
  1024. * @arg @ref LL_ADC_CHANNEL_4
  1025. * @arg @ref LL_ADC_CHANNEL_5
  1026. * @arg @ref LL_ADC_CHANNEL_6
  1027. * @arg @ref LL_ADC_CHANNEL_7
  1028. * @arg @ref LL_ADC_CHANNEL_8
  1029. * @arg @ref LL_ADC_CHANNEL_9
  1030. * @arg @ref LL_ADC_CHANNEL_10
  1031. * @arg @ref LL_ADC_CHANNEL_11
  1032. * @arg @ref LL_ADC_CHANNEL_12
  1033. * @arg @ref LL_ADC_CHANNEL_13
  1034. * @arg @ref LL_ADC_CHANNEL_14
  1035. * @arg @ref LL_ADC_CHANNEL_15
  1036. * @arg @ref LL_ADC_CHANNEL_16
  1037. * @arg @ref LL_ADC_CHANNEL_17
  1038. * @arg @ref LL_ADC_CHANNEL_18
  1039. */
  1040. #define __LL_ADC_CHANNEL_INTERNAL_TO_EXTERNAL(__CHANNEL__) \
  1041. ((__CHANNEL__) & ~ADC_CHANNEL_ID_INTERNAL_CH_MASK)
  1042. /**
  1043. * @brief Helper macro to determine whether the internal channel
  1044. * selected is available on the ADC instance selected.
  1045. * @note The channel parameter must be a value defined from parameter
  1046. * definition of a ADC internal channel (LL_ADC_CHANNEL_VREFINT,
  1047. * LL_ADC_CHANNEL_TEMPSENSOR, ...),
  1048. * must not be a value defined from parameter definition of
  1049. * ADC external channel (LL_ADC_CHANNEL_1, LL_ADC_CHANNEL_2, ...)
  1050. * or a value from functions where a channel number is
  1051. * returned from ADC registers,
  1052. * because internal and external channels share the same channel
  1053. * number in ADC registers. The differentiation is made only with
  1054. * parameters definitions of driver.
  1055. * @param __ADC_INSTANCE__ ADC instance
  1056. * @param __CHANNEL__ This parameter can be one of the following values:
  1057. * @arg @ref LL_ADC_CHANNEL_VREFINT
  1058. * @arg @ref LL_ADC_CHANNEL_TEMPSENSOR
  1059. * @arg @ref LL_ADC_CHANNEL_VLCD (1)
  1060. *
  1061. * (1) On STM32L0, parameter not available on all devices: only on STM32L053xx, STM32L063xx, STM32L073xx, STM32L083xx.
  1062. * @retval Value "0" if the internal channel selected is not available on the ADC instance selected.
  1063. * Value "1" if the internal channel selected is available on the ADC instance selected.
  1064. */
  1065. #if defined(ADC_CCR_VLCDEN)
  1066. #define __LL_ADC_IS_CHANNEL_INTERNAL_AVAILABLE(__ADC_INSTANCE__, __CHANNEL__) \
  1067. ( \
  1068. ((__CHANNEL__) == LL_ADC_CHANNEL_VREFINT) || \
  1069. ((__CHANNEL__) == LL_ADC_CHANNEL_TEMPSENSOR) || \
  1070. ((__CHANNEL__) == LL_ADC_CHANNEL_VLCD) \
  1071. )
  1072. #else
  1073. #define __LL_ADC_IS_CHANNEL_INTERNAL_AVAILABLE(__ADC_INSTANCE__, __CHANNEL__) \
  1074. ( \
  1075. ((__CHANNEL__) == LL_ADC_CHANNEL_VREFINT) || \
  1076. ((__CHANNEL__) == LL_ADC_CHANNEL_TEMPSENSOR) \
  1077. )
  1078. #endif
  1079. /**
  1080. * @brief Helper macro to define ADC analog watchdog parameter:
  1081. * define a single channel to monitor with analog watchdog
  1082. * from sequencer channel and groups definition.
  1083. * @note To be used with function @ref LL_ADC_SetAnalogWDMonitChannels().
  1084. * Example:
  1085. * LL_ADC_SetAnalogWDMonitChannels(
  1086. * ADC1, LL_ADC_AWD1,
  1087. * __LL_ADC_ANALOGWD_CHANNEL_GROUP(LL_ADC_CHANNEL4, LL_ADC_GROUP_REGULAR))
  1088. * @param __CHANNEL__ This parameter can be one of the following values:
  1089. * @arg @ref LL_ADC_CHANNEL_0
  1090. * @arg @ref LL_ADC_CHANNEL_1
  1091. * @arg @ref LL_ADC_CHANNEL_2
  1092. * @arg @ref LL_ADC_CHANNEL_3
  1093. * @arg @ref LL_ADC_CHANNEL_4
  1094. * @arg @ref LL_ADC_CHANNEL_5
  1095. * @arg @ref LL_ADC_CHANNEL_6
  1096. * @arg @ref LL_ADC_CHANNEL_7
  1097. * @arg @ref LL_ADC_CHANNEL_8
  1098. * @arg @ref LL_ADC_CHANNEL_9
  1099. * @arg @ref LL_ADC_CHANNEL_10
  1100. * @arg @ref LL_ADC_CHANNEL_11
  1101. * @arg @ref LL_ADC_CHANNEL_12
  1102. * @arg @ref LL_ADC_CHANNEL_13
  1103. * @arg @ref LL_ADC_CHANNEL_14
  1104. * @arg @ref LL_ADC_CHANNEL_15
  1105. * @arg @ref LL_ADC_CHANNEL_16 (1)
  1106. * @arg @ref LL_ADC_CHANNEL_17
  1107. * @arg @ref LL_ADC_CHANNEL_18
  1108. * @arg @ref LL_ADC_CHANNEL_VREFINT (2)
  1109. * @arg @ref LL_ADC_CHANNEL_TEMPSENSOR (2)
  1110. * @arg @ref LL_ADC_CHANNEL_VLCD (1)(2)
  1111. *
  1112. * (1) On STM32L0, parameter not available on all devices: only on STM32L053xx, STM32L063xx, STM32L073xx, STM32L083xx.\n
  1113. * (2) For ADC channel read back from ADC register,
  1114. * comparison with internal channel parameter to be done
  1115. * using helper macro @ref __LL_ADC_CHANNEL_INTERNAL_TO_EXTERNAL().
  1116. * @param __GROUP__ This parameter can be one of the following values:
  1117. * @arg @ref LL_ADC_GROUP_REGULAR
  1118. * @retval Returned value can be one of the following values:
  1119. * @arg @ref LL_ADC_AWD_DISABLE
  1120. * @arg @ref LL_ADC_AWD_ALL_CHANNELS_REG
  1121. * @arg @ref LL_ADC_AWD_CHANNEL_0_REG
  1122. * @arg @ref LL_ADC_AWD_CHANNEL_1_REG
  1123. * @arg @ref LL_ADC_AWD_CHANNEL_2_REG
  1124. * @arg @ref LL_ADC_AWD_CHANNEL_3_REG
  1125. * @arg @ref LL_ADC_AWD_CHANNEL_4_REG
  1126. * @arg @ref LL_ADC_AWD_CHANNEL_5_REG
  1127. * @arg @ref LL_ADC_AWD_CHANNEL_6_REG
  1128. * @arg @ref LL_ADC_AWD_CHANNEL_7_REG
  1129. * @arg @ref LL_ADC_AWD_CHANNEL_8_REG
  1130. * @arg @ref LL_ADC_AWD_CHANNEL_9_REG
  1131. * @arg @ref LL_ADC_AWD_CHANNEL_10_REG
  1132. * @arg @ref LL_ADC_AWD_CHANNEL_11_REG
  1133. * @arg @ref LL_ADC_AWD_CHANNEL_12_REG
  1134. * @arg @ref LL_ADC_AWD_CHANNEL_13_REG
  1135. * @arg @ref LL_ADC_AWD_CHANNEL_14_REG
  1136. * @arg @ref LL_ADC_AWD_CHANNEL_15_REG
  1137. * @arg @ref LL_ADC_AWD_CHANNEL_16_REG (1)
  1138. * @arg @ref LL_ADC_AWD_CHANNEL_17_REG
  1139. * @arg @ref LL_ADC_AWD_CHANNEL_18_REG
  1140. * @arg @ref LL_ADC_AWD_CH_VREFINT_REG
  1141. * @arg @ref LL_ADC_AWD_CH_TEMPSENSOR_REG
  1142. * @arg @ref LL_ADC_AWD_CH_VLCD_REG (1)
  1143. *
  1144. * (1) On STM32L0, parameter not available on all devices: only on STM32L053xx, STM32L063xx, STM32L073xx, STM32L083xx.
  1145. */
  1146. #define __LL_ADC_ANALOGWD_CHANNEL_GROUP(__CHANNEL__, __GROUP__) \
  1147. (((__CHANNEL__) & ADC_CHANNEL_ID_MASK) | ADC_CFGR1_AWDEN | ADC_CFGR1_AWDSGL)
  1148. /**
  1149. * @brief Helper macro to set the value of ADC analog watchdog threshold high
  1150. * or low in function of ADC resolution, when ADC resolution is
  1151. * different of 12 bits.
  1152. * @note To be used with function @ref LL_ADC_ConfigAnalogWDThresholds()
  1153. * or @ref LL_ADC_SetAnalogWDThresholds().
  1154. * Example, with a ADC resolution of 8 bits, to set the value of
  1155. * analog watchdog threshold high (on 8 bits):
  1156. * LL_ADC_SetAnalogWDThresholds
  1157. * (< ADCx param >,
  1158. * __LL_ADC_ANALOGWD_SET_THRESHOLD_RESOLUTION(LL_ADC_RESOLUTION_8B, <threshold_value_8_bits>)
  1159. * );
  1160. * @param __ADC_RESOLUTION__ This parameter can be one of the following values:
  1161. * @arg @ref LL_ADC_RESOLUTION_12B
  1162. * @arg @ref LL_ADC_RESOLUTION_10B
  1163. * @arg @ref LL_ADC_RESOLUTION_8B
  1164. * @arg @ref LL_ADC_RESOLUTION_6B
  1165. * @param __AWD_THRESHOLD__ Value between Min_Data=0x000 and Max_Data=0xFFF
  1166. * @retval Value between Min_Data=0x000 and Max_Data=0xFFF
  1167. */
  1168. #define __LL_ADC_ANALOGWD_SET_THRESHOLD_RESOLUTION(__ADC_RESOLUTION__, __AWD_THRESHOLD__) \
  1169. ((__AWD_THRESHOLD__) << ((__ADC_RESOLUTION__) >> (ADC_CFGR1_RES_BITOFFSET_POS - 1U )))
  1170. /**
  1171. * @brief Helper macro to get the value of ADC analog watchdog threshold high
  1172. * or low in function of ADC resolution, when ADC resolution is
  1173. * different of 12 bits.
  1174. * @note To be used with function @ref LL_ADC_GetAnalogWDThresholds().
  1175. * Example, with a ADC resolution of 8 bits, to get the value of
  1176. * analog watchdog threshold high (on 8 bits):
  1177. * < threshold_value_6_bits > = __LL_ADC_ANALOGWD_GET_THRESHOLD_RESOLUTION
  1178. * (LL_ADC_RESOLUTION_8B,
  1179. * LL_ADC_GetAnalogWDThresholds(<ADCx param>, LL_ADC_AWD_THRESHOLD_HIGH)
  1180. * );
  1181. * @param __ADC_RESOLUTION__ This parameter can be one of the following values:
  1182. * @arg @ref LL_ADC_RESOLUTION_12B
  1183. * @arg @ref LL_ADC_RESOLUTION_10B
  1184. * @arg @ref LL_ADC_RESOLUTION_8B
  1185. * @arg @ref LL_ADC_RESOLUTION_6B
  1186. * @param __AWD_THRESHOLD_12_BITS__ Value between Min_Data=0x000 and Max_Data=0xFFF
  1187. * @retval Value between Min_Data=0x000 and Max_Data=0xFFF
  1188. */
  1189. #define __LL_ADC_ANALOGWD_GET_THRESHOLD_RESOLUTION(__ADC_RESOLUTION__, __AWD_THRESHOLD_12_BITS__) \
  1190. ((__AWD_THRESHOLD_12_BITS__) >> ((__ADC_RESOLUTION__) >> (ADC_CFGR1_RES_BITOFFSET_POS - 1U )))
  1191. /**
  1192. * @brief Helper macro to get the ADC analog watchdog threshold high
  1193. * or low from raw value containing both thresholds concatenated.
  1194. * @note To be used with function @ref LL_ADC_GetAnalogWDThresholds().
  1195. * Example, to get analog watchdog threshold high from the register raw value:
  1196. * __LL_ADC_ANALOGWD_THRESHOLDS_HIGH_LOW(LL_ADC_AWD_THRESHOLD_HIGH, <raw_value_with_both_thresholds>);
  1197. * @param __AWD_THRESHOLD_TYPE__ This parameter can be one of the following values:
  1198. * @arg @ref LL_ADC_AWD_THRESHOLD_HIGH
  1199. * @arg @ref LL_ADC_AWD_THRESHOLD_LOW
  1200. * @param __AWD_THRESHOLDS__ Value between Min_Data=0x00000000 and Max_Data=0xFFFFFFFF
  1201. * @retval Value between Min_Data=0x000 and Max_Data=0xFFF
  1202. */
  1203. #define __LL_ADC_ANALOGWD_THRESHOLDS_HIGH_LOW(__AWD_THRESHOLD_TYPE__, __AWD_THRESHOLDS__) \
  1204. (((__AWD_THRESHOLD_TYPE__) == LL_ADC_AWD_THRESHOLD_LOW) \
  1205. ? ( \
  1206. (__AWD_THRESHOLDS__) & LL_ADC_AWD_THRESHOLD_LOW \
  1207. ) \
  1208. : \
  1209. ( \
  1210. ((__AWD_THRESHOLDS__) >> ADC_TR_HT_BITOFFSET_POS) & LL_ADC_AWD_THRESHOLD_LOW \
  1211. ) \
  1212. )
  1213. /**
  1214. * @brief Helper macro to select the ADC common instance
  1215. * to which is belonging the selected ADC instance.
  1216. * @note ADC common register instance can be used for:
  1217. * - Set parameters common to several ADC instances
  1218. * - Multimode (for devices with several ADC instances)
  1219. * Refer to functions having argument "ADCxy_COMMON" as parameter.
  1220. * @param __ADCx__ ADC instance
  1221. * @retval ADC common register instance
  1222. */
  1223. #define __LL_ADC_COMMON_INSTANCE(__ADCx__) \
  1224. (ADC1_COMMON)
  1225. /**
  1226. * @brief Helper macro to check if all ADC instances sharing the same
  1227. * ADC common instance are disabled.
  1228. * @note This check is required by functions with setting conditioned to
  1229. * ADC state:
  1230. * All ADC instances of the ADC common group must be disabled.
  1231. * Refer to functions having argument "ADCxy_COMMON" as parameter.
  1232. * @note On devices with only 1 ADC common instance, parameter of this macro
  1233. * is useless and can be ignored (parameter kept for compatibility
  1234. * with devices featuring several ADC common instances).
  1235. * @param __ADCXY_COMMON__ ADC common instance
  1236. * (can be set directly from CMSIS definition or by using helper macro @ref __LL_ADC_COMMON_INSTANCE() )
  1237. * @retval Value "0" if all ADC instances sharing the same ADC common instance
  1238. * are disabled.
  1239. * Value "1" if at least one ADC instance sharing the same ADC common instance
  1240. * is enabled.
  1241. */
  1242. #define __LL_ADC_IS_ENABLED_ALL_COMMON_INSTANCE(__ADCXY_COMMON__) \
  1243. LL_ADC_IsEnabled(ADC1)
  1244. /**
  1245. * @brief Helper macro to define the ADC conversion data full-scale digital
  1246. * value corresponding to the selected ADC resolution.
  1247. * @note ADC conversion data full-scale corresponds to voltage range
  1248. * determined by analog voltage references Vref+ and Vref-
  1249. * (refer to reference manual).
  1250. * @param __ADC_RESOLUTION__ This parameter can be one of the following values:
  1251. * @arg @ref LL_ADC_RESOLUTION_12B
  1252. * @arg @ref LL_ADC_RESOLUTION_10B
  1253. * @arg @ref LL_ADC_RESOLUTION_8B
  1254. * @arg @ref LL_ADC_RESOLUTION_6B
  1255. * @retval ADC conversion data equivalent voltage value (unit: mVolt)
  1256. */
  1257. #define __LL_ADC_DIGITAL_SCALE(__ADC_RESOLUTION__) \
  1258. (((uint32_t)0xFFFU) >> ((__ADC_RESOLUTION__) >> (ADC_CFGR1_RES_BITOFFSET_POS - 1U)))
  1259. /**
  1260. * @brief Helper macro to convert the ADC conversion data from
  1261. * a resolution to another resolution.
  1262. * @param __DATA__ ADC conversion data to be converted
  1263. * @param __ADC_RESOLUTION_CURRENT__ Resolution of to the data to be converted
  1264. * This parameter can be one of the following values:
  1265. * @arg @ref LL_ADC_RESOLUTION_12B
  1266. * @arg @ref LL_ADC_RESOLUTION_10B
  1267. * @arg @ref LL_ADC_RESOLUTION_8B
  1268. * @arg @ref LL_ADC_RESOLUTION_6B
  1269. * @param __ADC_RESOLUTION_TARGET__ Resolution of the data after conversion
  1270. * This parameter can be one of the following values:
  1271. * @arg @ref LL_ADC_RESOLUTION_12B
  1272. * @arg @ref LL_ADC_RESOLUTION_10B
  1273. * @arg @ref LL_ADC_RESOLUTION_8B
  1274. * @arg @ref LL_ADC_RESOLUTION_6B
  1275. * @retval ADC conversion data to the requested resolution
  1276. */
  1277. #define __LL_ADC_CONVERT_DATA_RESOLUTION(__DATA__, __ADC_RESOLUTION_CURRENT__, __ADC_RESOLUTION_TARGET__) \
  1278. (((__DATA__) \
  1279. << ((__ADC_RESOLUTION_CURRENT__) >> (ADC_CFGR1_RES_BITOFFSET_POS - 1U))) \
  1280. >> ((__ADC_RESOLUTION_TARGET__) >> (ADC_CFGR1_RES_BITOFFSET_POS - 1U)) \
  1281. )
  1282. /**
  1283. * @brief Helper macro to calculate the voltage (unit: mVolt)
  1284. * corresponding to a ADC conversion data (unit: digital value).
  1285. * @note Analog reference voltage (Vref+) must be either known from
  1286. * user board environment or can be calculated using ADC measurement
  1287. * and ADC helper macro @ref __LL_ADC_CALC_VREFANALOG_VOLTAGE().
  1288. * @param __VREFANALOG_VOLTAGE__ Analog reference voltage (unit: mV)
  1289. * @param __ADC_DATA__ ADC conversion data (resolution 12 bits)
  1290. * (unit: digital value).
  1291. * @param __ADC_RESOLUTION__ This parameter can be one of the following values:
  1292. * @arg @ref LL_ADC_RESOLUTION_12B
  1293. * @arg @ref LL_ADC_RESOLUTION_10B
  1294. * @arg @ref LL_ADC_RESOLUTION_8B
  1295. * @arg @ref LL_ADC_RESOLUTION_6B
  1296. * @retval ADC conversion data equivalent voltage value (unit: mVolt)
  1297. */
  1298. #define __LL_ADC_CALC_DATA_TO_VOLTAGE(__VREFANALOG_VOLTAGE__,\
  1299. __ADC_DATA__,\
  1300. __ADC_RESOLUTION__) \
  1301. ((__ADC_DATA__) * (__VREFANALOG_VOLTAGE__) \
  1302. / __LL_ADC_DIGITAL_SCALE(__ADC_RESOLUTION__) \
  1303. )
  1304. /**
  1305. * @brief Helper macro to calculate analog reference voltage (Vref+)
  1306. * (unit: mVolt) from ADC conversion data of internal voltage
  1307. * reference VrefInt.
  1308. * @note Computation is using VrefInt calibration value
  1309. * stored in system memory for each device during production.
  1310. * @note This voltage depends on user board environment: voltage level
  1311. * connected to pin Vref+.
  1312. * On devices with small package, the pin Vref+ is not present
  1313. * and internally bonded to pin Vdda.
  1314. * @note On this STM32 serie, calibration data of internal voltage reference
  1315. * VrefInt corresponds to a resolution of 12 bits,
  1316. * this is the recommended ADC resolution to convert voltage of
  1317. * internal voltage reference VrefInt.
  1318. * Otherwise, this macro performs the processing to scale
  1319. * ADC conversion data to 12 bits.
  1320. * @param __VREFINT_ADC_DATA__ ADC conversion data (resolution 12 bits)
  1321. * of internal voltage reference VrefInt (unit: digital value).
  1322. * @param __ADC_RESOLUTION__ This parameter can be one of the following values:
  1323. * @arg @ref LL_ADC_RESOLUTION_12B
  1324. * @arg @ref LL_ADC_RESOLUTION_10B
  1325. * @arg @ref LL_ADC_RESOLUTION_8B
  1326. * @arg @ref LL_ADC_RESOLUTION_6B
  1327. * @retval Analog reference voltage (unit: mV)
  1328. */
  1329. #define __LL_ADC_CALC_VREFANALOG_VOLTAGE(__VREFINT_ADC_DATA__,\
  1330. __ADC_RESOLUTION__) \
  1331. (((uint32_t)(*VREFINT_CAL_ADDR) * VREFINT_CAL_VREF) \
  1332. / __LL_ADC_CONVERT_DATA_RESOLUTION((__VREFINT_ADC_DATA__), \
  1333. (__ADC_RESOLUTION__), \
  1334. LL_ADC_RESOLUTION_12B) \
  1335. )
  1336. /* Note: On device STM32L011, calibration parameter TS_CAL1 is not available. */
  1337. /* Therefore, helper macro __LL_ADC_CALC_TEMPERATURE() is not available.*/
  1338. /* Use helper macro @ref __LL_ADC_CALC_TEMPERATURE_TYP_PARAMS(). */
  1339. /* Note: On device STM32L010xx, temperature sensor is not available. */
  1340. /* Therefore, helper macro related to temperature sensor are */
  1341. /* not available. */
  1342. #if !defined(STM32L011xx) && !defined(STM32L010xB) && !defined(STM32L010x8) && !defined(STM32L010x6) && !defined(STM32L010x4)
  1343. /**
  1344. * @brief Helper macro to calculate the temperature (unit: degree Celsius)
  1345. * from ADC conversion data of internal temperature sensor.
  1346. * @note Computation is using temperature sensor calibration values
  1347. * stored in system memory for each device during production.
  1348. * @note Calculation formula:
  1349. * Temperature = ((TS_ADC_DATA - TS_CAL1)
  1350. * * (TS_CAL2_TEMP - TS_CAL1_TEMP))
  1351. * / (TS_CAL2 - TS_CAL1) + TS_CAL1_TEMP
  1352. * with TS_ADC_DATA = temperature sensor raw data measured by ADC
  1353. * Avg_Slope = (TS_CAL2 - TS_CAL1)
  1354. * / (TS_CAL2_TEMP - TS_CAL1_TEMP)
  1355. * TS_CAL1 = equivalent TS_ADC_DATA at temperature
  1356. * TEMP_DEGC_CAL1 (calibrated in factory)
  1357. * TS_CAL2 = equivalent TS_ADC_DATA at temperature
  1358. * TEMP_DEGC_CAL2 (calibrated in factory)
  1359. * Caution: Calculation relevancy under reserve that calibration
  1360. * parameters are correct (address and data).
  1361. * To calculate temperature using temperature sensor
  1362. * datasheet typical values (generic values less, therefore
  1363. * less accurate than calibrated values),
  1364. * use helper macro @ref __LL_ADC_CALC_TEMPERATURE_TYP_PARAMS().
  1365. * @note As calculation input, the analog reference voltage (Vref+) must be
  1366. * defined as it impacts the ADC LSB equivalent voltage.
  1367. * @note Analog reference voltage (Vref+) must be either known from
  1368. * user board environment or can be calculated using ADC measurement
  1369. * and ADC helper macro @ref __LL_ADC_CALC_VREFANALOG_VOLTAGE().
  1370. * @note On this STM32 serie, calibration data of temperature sensor
  1371. * corresponds to a resolution of 12 bits,
  1372. * this is the recommended ADC resolution to convert voltage of
  1373. * temperature sensor.
  1374. * Otherwise, this macro performs the processing to scale
  1375. * ADC conversion data to 12 bits.
  1376. * @param __VREFANALOG_VOLTAGE__ Analog reference voltage (unit: mV)
  1377. * @param __TEMPSENSOR_ADC_DATA__ ADC conversion data of internal
  1378. * temperature sensor (unit: digital value).
  1379. * @param __ADC_RESOLUTION__ ADC resolution at which internal temperature
  1380. * sensor voltage has been measured.
  1381. * This parameter can be one of the following values:
  1382. * @arg @ref LL_ADC_RESOLUTION_12B
  1383. * @arg @ref LL_ADC_RESOLUTION_10B
  1384. * @arg @ref LL_ADC_RESOLUTION_8B
  1385. * @arg @ref LL_ADC_RESOLUTION_6B
  1386. * @retval Temperature (unit: degree Celsius)
  1387. */
  1388. #define __LL_ADC_CALC_TEMPERATURE(__VREFANALOG_VOLTAGE__,\
  1389. __TEMPSENSOR_ADC_DATA__,\
  1390. __ADC_RESOLUTION__) \
  1391. (((( ((int32_t)((__LL_ADC_CONVERT_DATA_RESOLUTION((__TEMPSENSOR_ADC_DATA__), \
  1392. (__ADC_RESOLUTION__), \
  1393. LL_ADC_RESOLUTION_12B) \
  1394. * (__VREFANALOG_VOLTAGE__)) \
  1395. / TEMPSENSOR_CAL_VREFANALOG) \
  1396. - (int32_t) *TEMPSENSOR_CAL1_ADDR) \
  1397. ) * (int32_t)(TEMPSENSOR_CAL2_TEMP - TEMPSENSOR_CAL1_TEMP) \
  1398. ) / (int32_t)((int32_t)*TEMPSENSOR_CAL2_ADDR - (int32_t)*TEMPSENSOR_CAL1_ADDR) \
  1399. ) + TEMPSENSOR_CAL1_TEMP \
  1400. )
  1401. #endif
  1402. /* Note: On device STM32L010xx, temperature sensor is not available. */
  1403. /* Therefore, helper macro related to temperature sensor are */
  1404. /* not available. */
  1405. #if !defined(STM32L010xB) && !defined(STM32L010x8) && !defined(STM32L010x6) && !defined(STM32L010x4)
  1406. /**
  1407. * @brief Helper macro to calculate the temperature (unit: degree Celsius)
  1408. * from ADC conversion data of internal temperature sensor.
  1409. * @note Computation is using temperature sensor typical values
  1410. * (refer to device datasheet).
  1411. * @note Calculation formula:
  1412. * Temperature = (TS_TYP_CALx_VOLT(uV) - TS_ADC_DATA * Conversion_uV)
  1413. * / Avg_Slope + CALx_TEMP
  1414. * with TS_ADC_DATA = temperature sensor raw data measured by ADC
  1415. * (unit: digital value)
  1416. * Avg_Slope = temperature sensor slope
  1417. * (unit: uV/Degree Celsius)
  1418. * TS_TYP_CALx_VOLT = temperature sensor digital value at
  1419. * temperature CALx_TEMP (unit: mV)
  1420. * Caution: Calculation relevancy under reserve the temperature sensor
  1421. * of the current device has characteristics in line with
  1422. * datasheet typical values.
  1423. * If temperature sensor calibration values are available on
  1424. * on this device (presence of macro __LL_ADC_CALC_TEMPERATURE()),
  1425. * temperature calculation will be more accurate using
  1426. * helper macro @ref __LL_ADC_CALC_TEMPERATURE().
  1427. * @note As calculation input, the analog reference voltage (Vref+) must be
  1428. * defined as it impacts the ADC LSB equivalent voltage.
  1429. * @note Analog reference voltage (Vref+) must be either known from
  1430. * user board environment or can be calculated using ADC measurement
  1431. * and ADC helper macro @ref __LL_ADC_CALC_VREFANALOG_VOLTAGE().
  1432. * @note ADC measurement data must correspond to a resolution of 12bits
  1433. * (full scale digital value 4095). If not the case, the data must be
  1434. * preliminarily rescaled to an equivalent resolution of 12 bits.
  1435. * @param __TEMPSENSOR_TYP_AVGSLOPE__ Device datasheet data: Temperature sensor slope typical value (unit: uV/DegCelsius).
  1436. * On STM32L0, refer to device datasheet parameter "Avg_Slope".
  1437. * @param __TEMPSENSOR_TYP_CALX_V__ Device datasheet data: Temperature sensor voltage typical value (at temperature and Vref+ defined in parameters below) (unit: mV).
  1438. * On STM32L0, refer to device datasheet parameter "V130" (corresponding to TS_CAL2).
  1439. * @param __TEMPSENSOR_CALX_TEMP__ Device datasheet data: Temperature at which temperature sensor voltage (see parameter above) is corresponding (unit: mV)
  1440. * @param __VREFANALOG_VOLTAGE__ Analog voltage reference (Vref+) voltage (unit: mV)
  1441. * @param __TEMPSENSOR_ADC_DATA__ ADC conversion data of internal temperature sensor (unit: digital value).
  1442. * @param __ADC_RESOLUTION__ ADC resolution at which internal temperature sensor voltage has been measured.
  1443. * This parameter can be one of the following values:
  1444. * @arg @ref LL_ADC_RESOLUTION_12B
  1445. * @arg @ref LL_ADC_RESOLUTION_10B
  1446. * @arg @ref LL_ADC_RESOLUTION_8B
  1447. * @arg @ref LL_ADC_RESOLUTION_6B
  1448. * @retval Temperature (unit: degree Celsius)
  1449. */
  1450. #define __LL_ADC_CALC_TEMPERATURE_TYP_PARAMS(__TEMPSENSOR_TYP_AVGSLOPE__,\
  1451. __TEMPSENSOR_TYP_CALX_V__,\
  1452. __TEMPSENSOR_CALX_TEMP__,\
  1453. __VREFANALOG_VOLTAGE__,\
  1454. __TEMPSENSOR_ADC_DATA__,\
  1455. __ADC_RESOLUTION__) \
  1456. ((( ( \
  1457. (int32_t)((((__TEMPSENSOR_ADC_DATA__) * (__VREFANALOG_VOLTAGE__)) \
  1458. / __LL_ADC_DIGITAL_SCALE(__ADC_RESOLUTION__)) \
  1459. * 1000) \
  1460. - \
  1461. (int32_t)(((__TEMPSENSOR_TYP_CALX_V__)) \
  1462. * 1000) \
  1463. ) \
  1464. ) / (__TEMPSENSOR_TYP_AVGSLOPE__) \
  1465. ) + (__TEMPSENSOR_CALX_TEMP__) \
  1466. )
  1467. #endif
  1468. /**
  1469. * @}
  1470. */
  1471. /**
  1472. * @}
  1473. */
  1474. /* Exported functions --------------------------------------------------------*/
  1475. /** @defgroup ADC_LL_Exported_Functions ADC Exported Functions
  1476. * @{
  1477. */
  1478. /** @defgroup ADC_LL_EF_DMA_Management ADC DMA management
  1479. * @{
  1480. */
  1481. /* Note: LL ADC functions to set DMA transfer are located into sections of */
  1482. /* configuration of ADC instance, groups and multimode (if available): */
  1483. /* @ref LL_ADC_REG_SetDMATransfer(), ... */
  1484. /**
  1485. * @brief Function to help to configure DMA transfer from ADC: retrieve the
  1486. * ADC register address from ADC instance and a list of ADC registers
  1487. * intended to be used (most commonly) with DMA transfer.
  1488. * @note These ADC registers are data registers:
  1489. * when ADC conversion data is available in ADC data registers,
  1490. * ADC generates a DMA transfer request.
  1491. * @note This macro is intended to be used with LL DMA driver, refer to
  1492. * function "LL_DMA_ConfigAddresses()".
  1493. * Example:
  1494. * LL_DMA_ConfigAddresses(DMA1,
  1495. * LL_DMA_CHANNEL_1,
  1496. * LL_ADC_DMA_GetRegAddr(ADC1, LL_ADC_DMA_REG_REGULAR_DATA),
  1497. * (uint32_t)&< array or variable >,
  1498. * LL_DMA_DIRECTION_PERIPH_TO_MEMORY);
  1499. * @note For devices with several ADC: in multimode, some devices
  1500. * use a different data register outside of ADC instance scope
  1501. * (common data register). This macro manages this register difference,
  1502. * only ADC instance has to be set as parameter.
  1503. * @rmtoll DR DATA LL_ADC_DMA_GetRegAddr
  1504. * @param ADCx ADC instance
  1505. * @param Register This parameter can be one of the following values:
  1506. * @arg @ref LL_ADC_DMA_REG_REGULAR_DATA
  1507. * @retval ADC register address
  1508. */
  1509. __STATIC_INLINE uint32_t LL_ADC_DMA_GetRegAddr(ADC_TypeDef *ADCx, uint32_t Register)
  1510. {
  1511. /* Retrieve address of register DR */
  1512. return (uint32_t)&(ADCx->DR);
  1513. }
  1514. /**
  1515. * @}
  1516. */
  1517. /** @defgroup ADC_LL_EF_Configuration_ADC_Common Configuration of ADC hierarchical scope: common to several ADC instances
  1518. * @{
  1519. */
  1520. /**
  1521. * @brief Set parameter common to several ADC: Clock source and prescaler.
  1522. * @note On this STM32 serie, setting of this feature is conditioned to
  1523. * ADC state:
  1524. * All ADC instances of the ADC common group must be disabled.
  1525. * This check can be done with function @ref LL_ADC_IsEnabled() for each
  1526. * ADC instance or by using helper macro helper macro
  1527. * @ref __LL_ADC_IS_ENABLED_ALL_COMMON_INSTANCE().
  1528. * @rmtoll CCR PRESC LL_ADC_SetCommonClock
  1529. * @param ADCxy_COMMON ADC common instance
  1530. * (can be set directly from CMSIS definition or by using helper macro @ref __LL_ADC_COMMON_INSTANCE() )
  1531. * @param CommonClock This parameter can be one of the following values:
  1532. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV1 (1)
  1533. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV2 (1)
  1534. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV4 (1)
  1535. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV6 (1)
  1536. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV8 (1)
  1537. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV10 (1)
  1538. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV12 (1)
  1539. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV16 (1)
  1540. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV32 (1)
  1541. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV64 (1)
  1542. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV128 (1)
  1543. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV256 (1)
  1544. *
  1545. * (1) ADC common clock asynchronous prescaler is applied to
  1546. * each ADC instance if the corresponding ADC instance clock
  1547. * is set to clock source asynchronous.
  1548. * (refer to function @ref LL_ADC_SetClock() ).
  1549. * @retval None
  1550. */
  1551. __STATIC_INLINE void LL_ADC_SetCommonClock(ADC_Common_TypeDef *ADCxy_COMMON, uint32_t CommonClock)
  1552. {
  1553. MODIFY_REG(ADCxy_COMMON->CCR, ADC_CCR_PRESC, CommonClock);
  1554. }
  1555. /**
  1556. * @brief Get parameter common to several ADC: Clock source and prescaler.
  1557. * @rmtoll CCR PRESC LL_ADC_GetCommonClock
  1558. * @param ADCxy_COMMON ADC common instance
  1559. * (can be set directly from CMSIS definition or by using helper macro @ref __LL_ADC_COMMON_INSTANCE() )
  1560. * @retval Returned value can be one of the following values:
  1561. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV1 (1)
  1562. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV2 (1)
  1563. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV4 (1)
  1564. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV6 (1)
  1565. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV8 (1)
  1566. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV10 (1)
  1567. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV12 (1)
  1568. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV16 (1)
  1569. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV32 (1)
  1570. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV64 (1)
  1571. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV128 (1)
  1572. * @arg @ref LL_ADC_CLOCK_ASYNC_DIV256 (1)
  1573. *
  1574. * (1) ADC common clock asynchronous prescaler is applied to
  1575. * each ADC instance if the corresponding ADC instance clock
  1576. * is set to clock source asynchronous.
  1577. * (refer to function @ref LL_ADC_SetClock() ).
  1578. */
  1579. __STATIC_INLINE uint32_t LL_ADC_GetCommonClock(ADC_Common_TypeDef *ADCxy_COMMON)
  1580. {
  1581. return (uint32_t)(READ_BIT(ADCxy_COMMON->CCR, ADC_CCR_PRESC));
  1582. }
  1583. /**
  1584. * @brief Set parameter common to several ADC: Clock low frequency mode.
  1585. * Refer to reference manual for alignments formats
  1586. * dependencies to ADC resolutions.
  1587. * @note On this STM32 serie, setting of this feature is conditioned to
  1588. * ADC state:
  1589. * ADC must be disabled or enabled without conversion on going
  1590. * on group regular.
  1591. * @rmtoll CCR LFMEN LL_ADC_SetCommonFrequencyMode
  1592. * @param ADCxy_COMMON ADC common instance
  1593. * (can be set directly from CMSIS definition or by using helper macro @ref __LL_ADC_COMMON_INSTANCE() )
  1594. * @param Resolution This parameter can be one of the following values:
  1595. * @arg @ref LL_ADC_CLOCK_FREQ_MODE_HIGH
  1596. * @arg @ref LL_ADC_CLOCK_FREQ_MODE_LOW
  1597. * @retval None
  1598. */
  1599. __STATIC_INLINE void LL_ADC_SetCommonFrequencyMode(ADC_Common_TypeDef *ADCxy_COMMON, uint32_t Resolution)
  1600. {
  1601. MODIFY_REG(ADCxy_COMMON->CCR, ADC_CCR_LFMEN, Resolution);
  1602. }
  1603. /**
  1604. * @brief Get parameter common to several ADC: Clock low frequency mode.
  1605. * Refer to reference manual for alignments formats
  1606. * dependencies to ADC resolutions.
  1607. * @rmtoll CCR LFMEN LL_ADC_GetCommonFrequencyMode
  1608. * @param ADCxy_COMMON ADC common instance
  1609. * (can be set directly from CMSIS definition or by using helper macro @ref __LL_ADC_COMMON_INSTANCE() )
  1610. * @retval Returned value can be one of the following values:
  1611. * @arg @ref LL_ADC_CLOCK_FREQ_MODE_HIGH
  1612. * @arg @ref LL_ADC_CLOCK_FREQ_MODE_LOW
  1613. */
  1614. __STATIC_INLINE uint32_t LL_ADC_GetCommonFrequencyMode(ADC_Common_TypeDef *ADCxy_COMMON)
  1615. {
  1616. return (uint32_t)(READ_BIT(ADCxy_COMMON->CCR, ADC_CCR_LFMEN));
  1617. }
  1618. /**
  1619. * @brief Set parameter common to several ADC: measurement path to internal
  1620. * channels (VrefInt, temperature sensor, ...).
  1621. * @note One or several values can be selected.
  1622. * Example: (LL_ADC_PATH_INTERNAL_VREFINT |
  1623. * LL_ADC_PATH_INTERNAL_TEMPSENSOR)
  1624. * @note Stabilization time of measurement path to internal channel:
  1625. * After enabling internal paths, before starting ADC conversion,
  1626. * a delay is required for internal voltage reference and
  1627. * temperature sensor stabilization time.
  1628. * Refer to device datasheet.
  1629. * Refer to literal @ref LL_ADC_DELAY_VREFINT_STAB_US.
  1630. * Refer to literal @ref LL_ADC_DELAY_TEMPSENSOR_STAB_US.
  1631. * @note ADC internal channel sampling time constraint:
  1632. * For ADC conversion of internal channels,
  1633. * a sampling time minimum value is required.
  1634. * Refer to device datasheet.
  1635. * @note On this STM32 serie, setting of this feature is conditioned to
  1636. * ADC state:
  1637. * All ADC instances of the ADC common group must be disabled.
  1638. * This check can be done with function @ref LL_ADC_IsEnabled() for each
  1639. * ADC instance or by using helper macro helper macro
  1640. * @ref __LL_ADC_IS_ENABLED_ALL_COMMON_INSTANCE().
  1641. * @rmtoll CCR VREFEN LL_ADC_SetCommonPathInternalCh\n
  1642. * CCR TSEN LL_ADC_SetCommonPathInternalCh\n
  1643. * CCR VLCDEN LL_ADC_SetCommonPathInternalCh
  1644. * @param ADCxy_COMMON ADC common instance
  1645. * (can be set directly from CMSIS definition or by using helper macro @ref __LL_ADC_COMMON_INSTANCE() )
  1646. * @param PathInternal This parameter can be a combination of the following values:
  1647. * @arg @ref LL_ADC_PATH_INTERNAL_NONE
  1648. * @arg @ref LL_ADC_PATH_INTERNAL_VREFINT
  1649. * @arg @ref LL_ADC_PATH_INTERNAL_TEMPSENSOR (2)
  1650. * @arg @ref LL_ADC_PATH_INTERNAL_VLCD (1)
  1651. *
  1652. * (1) value not defined in all devices: only on STM32L053xx, STM32L063xx, STM32L073xx, STM32L083xx.
  1653. * (2) value not defined in all devices: only on STM32L053xx, STM32L063xx, STM32L073xx, STM32L083xx, STM32L04xxx, STM32L03xxx, STM32L02xxx.
  1654. * @retval None
  1655. */
  1656. __STATIC_INLINE void LL_ADC_SetCommonPathInternalCh(ADC_Common_TypeDef *ADCxy_COMMON, uint32_t PathInternal)
  1657. {
  1658. #if defined (ADC_CCR_VLCDEN) && defined (ADC_CCR_TSEN)
  1659. MODIFY_REG(ADCxy_COMMON->CCR, ADC_CCR_VREFEN | ADC_CCR_TSEN | ADC_CCR_VLCDEN, PathInternal);
  1660. #elif defined (ADC_CCR_TSEN)
  1661. MODIFY_REG(ADCxy_COMMON->CCR, ADC_CCR_VREFEN | ADC_CCR_TSEN, PathInternal);
  1662. #else
  1663. MODIFY_REG(ADCxy_COMMON->CCR, ADC_CCR_VREFEN, PathInternal);
  1664. #endif
  1665. }
  1666. /**
  1667. * @brief Get parameter common to several ADC: measurement path to internal
  1668. * channels (VrefInt, temperature sensor, ...).
  1669. * @note One or several values can be selected.
  1670. * Example: (LL_ADC_PATH_INTERNAL_VREFINT |
  1671. * LL_ADC_PATH_INTERNAL_TEMPSENSOR)
  1672. * @rmtoll CCR VREFEN LL_ADC_GetCommonPathInternalCh\n
  1673. * CCR TSEN LL_ADC_GetCommonPathInternalCh\n
  1674. * CCR VLCDEN LL_ADC_GetCommonPathInternalCh
  1675. * @param ADCxy_COMMON ADC common instance
  1676. * (can be set directly from CMSIS definition or by using helper macro @ref __LL_ADC_COMMON_INSTANCE() )
  1677. * @retval Returned value can be a combination of the following values:
  1678. * @arg @ref LL_ADC_PATH_INTERNAL_NONE
  1679. * @arg @ref LL_ADC_PATH_INTERNAL_VREFINT
  1680. * @arg @ref LL_ADC_PATH_INTERNAL_TEMPSENSOR (2)
  1681. * @arg @ref LL_ADC_PATH_INTERNAL_VLCD (1)
  1682. *
  1683. * (1) value not defined in all devices: only on STM32L053xx, STM32L063xx, STM32L073xx, STM32L083xx.
  1684. * (2) value not defined in all devices: only on STM32L053xx, STM32L063xx, STM32L073xx, STM32L083xx, STM32L04xxx, STM32L03xxx, STM32L02xxx.
  1685. */
  1686. __STATIC_INLINE uint32_t LL_ADC_GetCommonPathInternalCh(ADC_Common_TypeDef *ADCxy_COMMON)
  1687. {
  1688. #if defined (ADC_CCR_VLCDEN) && defined (ADC_CCR_TSEN)
  1689. return (uint32_t)(READ_BIT(ADCxy_COMMON->CCR, ADC_CCR_VREFEN | ADC_CCR_TSEN | ADC_CCR_VLCDEN));
  1690. #elif defined (ADC_CCR_TSEN)
  1691. return (uint32_t)(READ_BIT(ADCxy_COMMON->CCR, ADC_CCR_VREFEN | ADC_CCR_TSEN));
  1692. #else
  1693. return (uint32_t)(READ_BIT(ADCxy_COMMON->CCR, ADC_CCR_VREFEN));
  1694. #endif
  1695. }
  1696. /**
  1697. * @}
  1698. */
  1699. /** @defgroup ADC_LL_EF_Configuration_ADC_Instance Configuration of ADC hierarchical scope: ADC instance
  1700. * @{
  1701. */
  1702. /**
  1703. * @brief Set ADC instance clock source and prescaler.
  1704. * @note On this STM32 serie, setting of this feature is conditioned to
  1705. * ADC state:
  1706. * ADC must be disabled.
  1707. * @rmtoll CFGR2 CKMODE LL_ADC_SetClock
  1708. * @param ADCx ADC instance
  1709. * @param ClockSource This parameter can be one of the following values:
  1710. * @arg @ref LL_ADC_CLOCK_SYNC_PCLK_DIV4
  1711. * @arg @ref LL_ADC_CLOCK_SYNC_PCLK_DIV2
  1712. * @arg @ref LL_ADC_CLOCK_SYNC_PCLK_DIV1 (2)
  1713. * @arg @ref LL_ADC_CLOCK_ASYNC (1)
  1714. *
  1715. * (1) Asynchronous clock prescaler can be configured using
  1716. * function @ref LL_ADC_SetCommonClock().\n
  1717. * (2) Caution: This parameter has some clock ratio constraints:
  1718. * This configuration must be enabled only if PCLK has a 50%
  1719. * duty clock cycle (APB prescaler configured inside the RCC
  1720. * must be bypassed and the system clock must by 50% duty
  1721. * cycle).
  1722. * Refer to reference manual.
  1723. * @retval None
  1724. */
  1725. __STATIC_INLINE void LL_ADC_SetClock(ADC_TypeDef *ADCx, uint32_t ClockSource)
  1726. {
  1727. MODIFY_REG(ADCx->CFGR2, ADC_CFGR2_CKMODE, ClockSource);
  1728. }
  1729. /**
  1730. * @brief Get ADC instance clock source and prescaler.
  1731. * @rmtoll CFGR2 CKMODE LL_ADC_GetClock
  1732. * @param ADCx ADC instance
  1733. * @retval Returned value can be one of the following values:
  1734. * @arg @ref LL_ADC_CLOCK_SYNC_PCLK_DIV4
  1735. * @arg @ref LL_ADC_CLOCK_SYNC_PCLK_DIV2
  1736. * @arg @ref LL_ADC_CLOCK_SYNC_PCLK_DIV1 (2)
  1737. * @arg @ref LL_ADC_CLOCK_ASYNC (1)
  1738. *
  1739. * (1) Asynchronous clock prescaler can be retrieved using
  1740. * function @ref LL_ADC_GetCommonClock().\n
  1741. * (2) Caution: This parameter has some clock ratio constraints:
  1742. * This configuration must be enabled only if PCLK has a 50%
  1743. * duty clock cycle (APB prescaler configured inside the RCC
  1744. * must be bypassed and the system clock must by 50% duty
  1745. * cycle).
  1746. * Refer to reference manual.
  1747. */
  1748. __STATIC_INLINE uint32_t LL_ADC_GetClock(ADC_TypeDef *ADCx)
  1749. {
  1750. return (uint32_t)(READ_BIT(ADCx->CFGR2, ADC_CFGR2_CKMODE));
  1751. }
  1752. /**
  1753. * @brief Set ADC calibration factor in the mode single-ended
  1754. * or differential (for devices with differential mode available).
  1755. * @note This function is intended to set calibration parameters
  1756. * without having to perform a new calibration using
  1757. * @ref LL_ADC_StartCalibration().
  1758. * @note On this STM32 serie, setting of this feature is conditioned to
  1759. * ADC state:
  1760. * ADC must be enabled, without calibration on going, without conversion
  1761. * on going on group regular.
  1762. * @rmtoll CALFACT CALFACT LL_ADC_SetCalibrationFactor
  1763. * @param ADCx ADC instance
  1764. * @param CalibrationFactor Value between Min_Data=0x00 and Max_Data=0x7F
  1765. * @retval None
  1766. */
  1767. __STATIC_INLINE void LL_ADC_SetCalibrationFactor(ADC_TypeDef *ADCx, uint32_t CalibrationFactor)
  1768. {
  1769. MODIFY_REG(ADCx->CALFACT,
  1770. ADC_CALFACT_CALFACT,
  1771. CalibrationFactor);
  1772. }
  1773. /**
  1774. * @brief Get ADC calibration factor in the mode single-ended
  1775. * or differential (for devices with differential mode available).
  1776. * @note Calibration factors are set by hardware after performing
  1777. * a calibration run using function @ref LL_ADC_StartCalibration().
  1778. * @rmtoll CALFACT CALFACT LL_ADC_GetCalibrationFactor
  1779. * @param ADCx ADC instance
  1780. * @retval Value between Min_Data=0x00 and Max_Data=0x7F
  1781. */
  1782. __STATIC_INLINE uint32_t LL_ADC_GetCalibrationFactor(ADC_TypeDef *ADCx)
  1783. {
  1784. return (uint32_t)(READ_BIT(ADCx->CALFACT, ADC_CALFACT_CALFACT));
  1785. }
  1786. /**
  1787. * @brief Set ADC resolution.
  1788. * Refer to reference manual for alignments formats
  1789. * dependencies to ADC resolutions.
  1790. * @note On this STM32 serie, setting of this feature is conditioned to
  1791. * ADC state:
  1792. * ADC must be disabled or enabled without conversion on going
  1793. * on group regular.
  1794. * @rmtoll CFGR1 RES LL_ADC_SetResolution
  1795. * @param ADCx ADC instance
  1796. * @param Resolution This parameter can be one of the following values:
  1797. * @arg @ref LL_ADC_RESOLUTION_12B
  1798. * @arg @ref LL_ADC_RESOLUTION_10B
  1799. * @arg @ref LL_ADC_RESOLUTION_8B
  1800. * @arg @ref LL_ADC_RESOLUTION_6B
  1801. * @retval None
  1802. */
  1803. __STATIC_INLINE void LL_ADC_SetResolution(ADC_TypeDef *ADCx, uint32_t Resolution)
  1804. {
  1805. MODIFY_REG(ADCx->CFGR1, ADC_CFGR1_RES, Resolution);
  1806. }
  1807. /**
  1808. * @brief Get ADC resolution.
  1809. * Refer to reference manual for alignments formats
  1810. * dependencies to ADC resolutions.
  1811. * @rmtoll CFGR1 RES LL_ADC_GetResolution
  1812. * @param ADCx ADC instance
  1813. * @retval Returned value can be one of the following values:
  1814. * @arg @ref LL_ADC_RESOLUTION_12B
  1815. * @arg @ref LL_ADC_RESOLUTION_10B
  1816. * @arg @ref LL_ADC_RESOLUTION_8B
  1817. * @arg @ref LL_ADC_RESOLUTION_6B
  1818. */
  1819. __STATIC_INLINE uint32_t LL_ADC_GetResolution(ADC_TypeDef *ADCx)
  1820. {
  1821. return (uint32_t)(READ_BIT(ADCx->CFGR1, ADC_CFGR1_RES));
  1822. }
  1823. /**
  1824. * @brief Set ADC conversion data alignment.
  1825. * @note Refer to reference manual for alignments formats
  1826. * dependencies to ADC resolutions.
  1827. * @note On this STM32 serie, setting of this feature is conditioned to
  1828. * ADC state:
  1829. * ADC must be disabled or enabled without conversion on going
  1830. * on group regular.
  1831. * @rmtoll CFGR1 ALIGN LL_ADC_SetDataAlignment
  1832. * @param ADCx ADC instance
  1833. * @param DataAlignment This parameter can be one of the following values:
  1834. * @arg @ref LL_ADC_DATA_ALIGN_RIGHT
  1835. * @arg @ref LL_ADC_DATA_ALIGN_LEFT
  1836. * @retval None
  1837. */
  1838. __STATIC_INLINE void LL_ADC_SetDataAlignment(ADC_TypeDef *ADCx, uint32_t DataAlignment)
  1839. {
  1840. MODIFY_REG(ADCx->CFGR1, ADC_CFGR1_ALIGN, DataAlignment);
  1841. }
  1842. /**
  1843. * @brief Get ADC conversion data alignment.
  1844. * @note Refer to reference manual for alignments formats
  1845. * dependencies to ADC resolutions.
  1846. * @rmtoll CFGR1 ALIGN LL_ADC_GetDataAlignment
  1847. * @param ADCx ADC instance
  1848. * @retval Returned value can be one of the following values:
  1849. * @arg @ref LL_ADC_DATA_ALIGN_RIGHT
  1850. * @arg @ref LL_ADC_DATA_ALIGN_LEFT
  1851. */
  1852. __STATIC_INLINE uint32_t LL_ADC_GetDataAlignment(ADC_TypeDef *ADCx)
  1853. {
  1854. return (uint32_t)(READ_BIT(ADCx->CFGR1, ADC_CFGR1_ALIGN));
  1855. }
  1856. /**
  1857. * @brief Set ADC low power mode.
  1858. * @note Description of ADC low power modes:
  1859. * - ADC low power mode "auto wait": Dynamic low power mode,
  1860. * ADC conversions occurrences are limited to the minimum necessary
  1861. * in order to reduce power consumption.
  1862. * New ADC conversion starts only when the previous
  1863. * unitary conversion data (for ADC group regular)
  1864. * has been retrieved by user software.
  1865. * In the meantime, ADC remains idle: does not performs any
  1866. * other conversion.
  1867. * This mode allows to automatically adapt the ADC conversions
  1868. * triggers to the speed of the software that reads the data.
  1869. * Moreover, this avoids risk of overrun for low frequency
  1870. * applications.
  1871. * How to use this low power mode:
  1872. * - Do not use with interruption or DMA since these modes
  1873. * have to clear immediately the EOC flag to free the
  1874. * IRQ vector sequencer.
  1875. * - Do use with polling: 1. Start conversion,
  1876. * 2. Later on, when conversion data is needed: poll for end of
  1877. * conversion to ensure that conversion is completed and
  1878. * retrieve ADC conversion data. This will trig another
  1879. * ADC conversion start.
  1880. * - ADC low power mode "auto power-off" (feature available on
  1881. * this device if parameter LL_ADC_LP_MODE_AUTOOFF is available):
  1882. * the ADC automatically powers-off after a conversion and
  1883. * automatically wakes up when a new conversion is triggered
  1884. * (with startup time between trigger and start of sampling).
  1885. * This feature can be combined with low power mode "auto wait".
  1886. * @note With ADC low power mode "auto wait", the ADC conversion data read
  1887. * is corresponding to previous ADC conversion start, independently
  1888. * of delay during which ADC was idle.
  1889. * Therefore, the ADC conversion data may be outdated: does not
  1890. * correspond to the current voltage level on the selected
  1891. * ADC channel.
  1892. * @note On this STM32 serie, setting of this feature is conditioned to
  1893. * ADC state:
  1894. * ADC must be disabled or enabled without conversion on going
  1895. * on group regular.
  1896. * @rmtoll CFGR1 WAIT LL_ADC_SetLowPowerMode\n
  1897. * CFGR1 AUTOFF LL_ADC_SetLowPowerMode
  1898. * @param ADCx ADC instance
  1899. * @param LowPowerMode This parameter can be one of the following values:
  1900. * @arg @ref LL_ADC_LP_MODE_NONE
  1901. * @arg @ref LL_ADC_LP_AUTOWAIT
  1902. * @arg @ref LL_ADC_LP_AUTOPOWEROFF
  1903. * @arg @ref LL_ADC_LP_AUTOWAIT_AUTOPOWEROFF
  1904. * @retval None
  1905. */
  1906. __STATIC_INLINE void LL_ADC_SetLowPowerMode(ADC_TypeDef *ADCx, uint32_t LowPowerMode)
  1907. {
  1908. MODIFY_REG(ADCx->CFGR1, (ADC_CFGR1_WAIT | ADC_CFGR1_AUTOFF), LowPowerMode);
  1909. }
  1910. /**
  1911. * @brief Get ADC low power mode:
  1912. * @note Description of ADC low power modes:
  1913. * - ADC low power mode "auto wait": Dynamic low power mode,
  1914. * ADC conversions occurrences are limited to the minimum necessary
  1915. * in order to reduce power consumption.
  1916. * New ADC conversion starts only when the previous
  1917. * unitary conversion data (for ADC group regular)
  1918. * has been retrieved by user software.
  1919. * In the meantime, ADC remains idle: does not performs any
  1920. * other conversion.
  1921. * This mode allows to automatically adapt the ADC conversions
  1922. * triggers to the speed of the software that reads the data.
  1923. * Moreover, this avoids risk of overrun for low frequency
  1924. * applications.
  1925. * How to use this low power mode:
  1926. * - Do not use with interruption or DMA since these modes
  1927. * have to clear immediately the EOC flag to free the
  1928. * IRQ vector sequencer.
  1929. * - Do use with polling: 1. Start conversion,
  1930. * 2. Later on, when conversion data is needed: poll for end of
  1931. * conversion to ensure that conversion is completed and
  1932. * retrieve ADC conversion data. This will trig another
  1933. * ADC conversion start.
  1934. * - ADC low power mode "auto power-off" (feature available on
  1935. * this device if parameter LL_ADC_LP_MODE_AUTOOFF is available):
  1936. * the ADC automatically powers-off after a conversion and
  1937. * automatically wakes up when a new conversion is triggered
  1938. * (with startup time between trigger and start of sampling).
  1939. * This feature can be combined with low power mode "auto wait".
  1940. * @note With ADC low power mode "auto wait", the ADC conversion data read
  1941. * is corresponding to previous ADC conversion start, independently
  1942. * of delay during which ADC was idle.
  1943. * Therefore, the ADC conversion data may be outdated: does not
  1944. * correspond to the current voltage level on the selected
  1945. * ADC channel.
  1946. * @rmtoll CFGR1 WAIT LL_ADC_GetLowPowerMode\n
  1947. * CFGR1 AUTOFF LL_ADC_GetLowPowerMode
  1948. * @param ADCx ADC instance
  1949. * @retval Returned value can be one of the following values:
  1950. * @arg @ref LL_ADC_LP_MODE_NONE
  1951. * @arg @ref LL_ADC_LP_AUTOWAIT
  1952. * @arg @ref LL_ADC_LP_AUTOPOWEROFF
  1953. * @arg @ref LL_ADC_LP_AUTOWAIT_AUTOPOWEROFF
  1954. */
  1955. __STATIC_INLINE uint32_t LL_ADC_GetLowPowerMode(ADC_TypeDef *ADCx)
  1956. {
  1957. return (uint32_t)(READ_BIT(ADCx->CFGR1, (ADC_CFGR1_WAIT | ADC_CFGR1_AUTOFF)));
  1958. }
  1959. /**
  1960. * @brief Set sampling time common to a group of channels.
  1961. * @note Unit: ADC clock cycles.
  1962. * @note On this STM32 serie, sampling time scope is on ADC instance:
  1963. * Sampling time common to all channels.
  1964. * (on some other STM32 families, sampling time is channel wise)
  1965. * @note In case of internal channel (VrefInt, TempSensor, ...) to be
  1966. * converted:
  1967. * sampling time constraints must be respected (sampling time can be
  1968. * adjusted in function of ADC clock frequency and sampling time
  1969. * setting).
  1970. * Refer to device datasheet for timings values (parameters TS_vrefint,
  1971. * TS_temp, ...).
  1972. * @note Conversion time is the addition of sampling time and processing time.
  1973. * On this STM32 serie, ADC processing time is:
  1974. * - 12.5 ADC clock cycles at ADC resolution 12 bits
  1975. * - 10.5 ADC clock cycles at ADC resolution 10 bits
  1976. * - 8.5 ADC clock cycles at ADC resolution 8 bits
  1977. * - 6.5 ADC clock cycles at ADC resolution 6 bits
  1978. * @note In case of ADC conversion of internal channel (VrefInt,
  1979. * temperature sensor, ...), a sampling time minimum value
  1980. * is required.
  1981. * Refer to device datasheet.
  1982. * @note On this STM32 serie, setting of this feature is conditioned to
  1983. * ADC state:
  1984. * ADC must be disabled or enabled without conversion on going
  1985. * on group regular.
  1986. * @rmtoll SMPR SMP LL_ADC_SetSamplingTimeCommonChannels
  1987. * @param ADCx ADC instance
  1988. * @param SamplingTime This parameter can be one of the following values:
  1989. * @arg @ref LL_ADC_SAMPLINGTIME_1CYCLE_5
  1990. * @arg @ref LL_ADC_SAMPLINGTIME_3CYCLES_5
  1991. * @arg @ref LL_ADC_SAMPLINGTIME_7CYCLES_5
  1992. * @arg @ref LL_ADC_SAMPLINGTIME_12CYCLES_5
  1993. * @arg @ref LL_ADC_SAMPLINGTIME_19CYCLES_5
  1994. * @arg @ref LL_ADC_SAMPLINGTIME_39CYCLES_5
  1995. * @arg @ref LL_ADC_SAMPLINGTIME_79CYCLES_5
  1996. * @arg @ref LL_ADC_SAMPLINGTIME_160CYCLES_5
  1997. * @retval None
  1998. */
  1999. __STATIC_INLINE void LL_ADC_SetSamplingTimeCommonChannels(ADC_TypeDef *ADCx, uint32_t SamplingTime)
  2000. {
  2001. MODIFY_REG(ADCx->SMPR, ADC_SMPR_SMP, SamplingTime);
  2002. }
  2003. /**
  2004. * @brief Get sampling time common to a group of channels.
  2005. * @note Unit: ADC clock cycles.
  2006. * @note On this STM32 serie, sampling time scope is on ADC instance:
  2007. * Sampling time common to all channels.
  2008. * (on some other STM32 families, sampling time is channel wise)
  2009. * @note Conversion time is the addition of sampling time and processing time.
  2010. * Refer to reference manual for ADC processing time of
  2011. * this STM32 serie.
  2012. * @rmtoll SMPR SMP LL_ADC_GetSamplingTimeCommonChannels
  2013. * @param ADCx ADC instance
  2014. * @retval Returned value can be one of the following values:
  2015. * @arg @ref LL_ADC_SAMPLINGTIME_1CYCLE_5
  2016. * @arg @ref LL_ADC_SAMPLINGTIME_3CYCLES_5
  2017. * @arg @ref LL_ADC_SAMPLINGTIME_7CYCLES_5
  2018. * @arg @ref LL_ADC_SAMPLINGTIME_12CYCLES_5
  2019. * @arg @ref LL_ADC_SAMPLINGTIME_19CYCLES_5
  2020. * @arg @ref LL_ADC_SAMPLINGTIME_39CYCLES_5
  2021. * @arg @ref LL_ADC_SAMPLINGTIME_79CYCLES_5
  2022. * @arg @ref LL_ADC_SAMPLINGTIME_160CYCLES_5
  2023. */
  2024. __STATIC_INLINE uint32_t LL_ADC_GetSamplingTimeCommonChannels(ADC_TypeDef *ADCx)
  2025. {
  2026. return (uint32_t)(READ_BIT(ADCx->SMPR, ADC_SMPR_SMP));
  2027. }
  2028. /**
  2029. * @}
  2030. */
  2031. /** @defgroup ADC_LL_EF_Configuration_ADC_Group_Regular Configuration of ADC hierarchical scope: group regular
  2032. * @{
  2033. */
  2034. /**
  2035. * @brief Set ADC group regular conversion trigger source:
  2036. * internal (SW start) or from external peripheral (timer event,
  2037. * external interrupt line).
  2038. * @note On this STM32 serie, setting trigger source to external trigger
  2039. * also set trigger polarity to rising edge
  2040. * (default setting for compatibility with some ADC on other
  2041. * STM32 families having this setting set by HW default value).
  2042. * In case of need to modify trigger edge, use
  2043. * function @ref LL_ADC_REG_SetTriggerEdge().
  2044. * @note Availability of parameters of trigger sources from timer
  2045. * depends on timers availability on the selected device.
  2046. * @note On this STM32 serie, setting of this feature is conditioned to
  2047. * ADC state:
  2048. * ADC must be disabled or enabled without conversion on going
  2049. * on group regular.
  2050. * @rmtoll CFGR1 EXTSEL LL_ADC_REG_SetTriggerSource\n
  2051. * CFGR1 EXTEN LL_ADC_REG_SetTriggerSource
  2052. * @param ADCx ADC instance
  2053. * @param TriggerSource This parameter can be one of the following values:
  2054. * @arg @ref LL_ADC_REG_TRIG_SOFTWARE
  2055. * @arg @ref LL_ADC_REG_TRIG_EXT_TIM6_TRGO
  2056. * @arg @ref LL_ADC_REG_TRIG_EXT_TIM21_CH2
  2057. * @arg @ref LL_ADC_REG_TRIG_EXT_TIM2_TRGO
  2058. * @arg @ref LL_ADC_REG_TRIG_EXT_TIM2_CH4
  2059. * @arg @ref LL_ADC_REG_TRIG_EXT_TIM22_TRGO
  2060. * @arg @ref LL_ADC_REG_TRIG_EXT_TIM2_CH3 (*)
  2061. * @arg @ref LL_ADC_REG_TRIG_EXT_TIM3_TRGO
  2062. * @arg @ref LL_ADC_REG_TRIG_EXT_EXTI_LINE11
  2063. *
  2064. * (*) value not defined in all devices
  2065. * @retval None
  2066. */
  2067. __STATIC_INLINE void LL_ADC_REG_SetTriggerSource(ADC_TypeDef *ADCx, uint32_t TriggerSource)
  2068. {
  2069. MODIFY_REG(ADCx->CFGR1, ADC_CFGR1_EXTEN | ADC_CFGR1_EXTSEL, TriggerSource);
  2070. }
  2071. /**
  2072. * @brief Get ADC group regular conversion trigger source:
  2073. * internal (SW start) or from external peripheral (timer event,
  2074. * external interrupt line).
  2075. * @note To determine whether group regular trigger source is
  2076. * internal (SW start) or external, without detail
  2077. * of which peripheral is selected as external trigger,
  2078. * (equivalent to
  2079. * "if(LL_ADC_REG_GetTriggerSource(ADC1) == LL_ADC_REG_TRIG_SOFTWARE)")
  2080. * use function @ref LL_ADC_REG_IsTriggerSourceSWStart.
  2081. * @note Availability of parameters of trigger sources from timer
  2082. * depends on timers availability on the selected device.
  2083. * @rmtoll CFGR1 EXTSEL LL_ADC_REG_GetTriggerSource\n
  2084. * CFGR1 EXTEN LL_ADC_REG_GetTriggerSource
  2085. * @param ADCx ADC instance
  2086. * @retval Returned value can be one of the following values:
  2087. * @arg @ref LL_ADC_REG_TRIG_SOFTWARE
  2088. * @arg @ref LL_ADC_REG_TRIG_EXT_TIM6_TRGO
  2089. * @arg @ref LL_ADC_REG_TRIG_EXT_TIM21_CH2
  2090. * @arg @ref LL_ADC_REG_TRIG_EXT_TIM2_TRGO
  2091. * @arg @ref LL_ADC_REG_TRIG_EXT_TIM2_CH4
  2092. * @arg @ref LL_ADC_REG_TRIG_EXT_TIM22_TRGO
  2093. * @arg @ref LL_ADC_REG_TRIG_EXT_TIM2_CH3 (*)
  2094. * @arg @ref LL_ADC_REG_TRIG_EXT_TIM3_TRGO
  2095. * @arg @ref LL_ADC_REG_TRIG_EXT_EXTI_LINE11
  2096. *
  2097. * (*) value not defined in all devices
  2098. */
  2099. __STATIC_INLINE uint32_t LL_ADC_REG_GetTriggerSource(ADC_TypeDef *ADCx)
  2100. {
  2101. register uint32_t TriggerSource = READ_BIT(ADCx->CFGR1, ADC_CFGR1_EXTSEL | ADC_CFGR1_EXTEN);
  2102. /* Value for shift of {0; 4; 8; 12} depending on value of bitfield */
  2103. /* corresponding to ADC_CFGR1_EXTEN {0; 1; 2; 3}. */
  2104. register uint32_t ShiftExten = ((TriggerSource & ADC_CFGR1_EXTEN) >> (ADC_REG_TRIG_EXTEN_BITOFFSET_POS - 2U));
  2105. /* Set bitfield corresponding to ADC_CFGR1_EXTEN and ADC_CFGR1_EXTSEL */
  2106. /* to match with triggers literals definition. */
  2107. return ((TriggerSource
  2108. & (ADC_REG_TRIG_SOURCE_MASK >> ShiftExten) & ADC_CFGR1_EXTSEL)
  2109. | ((ADC_REG_TRIG_EDGE_MASK >> ShiftExten) & ADC_CFGR1_EXTEN)
  2110. );
  2111. }
  2112. /**
  2113. * @brief Get ADC group regular conversion trigger source internal (SW start)
  2114. or external.
  2115. * @note In case of group regular trigger source set to external trigger,
  2116. * to determine which peripheral is selected as external trigger,
  2117. * use function @ref LL_ADC_REG_GetTriggerSource().
  2118. * @rmtoll CFGR1 EXTEN LL_ADC_REG_IsTriggerSourceSWStart
  2119. * @param ADCx ADC instance
  2120. * @retval Value "0" if trigger source external trigger
  2121. * Value "1" if trigger source SW start.
  2122. */
  2123. __STATIC_INLINE uint32_t LL_ADC_REG_IsTriggerSourceSWStart(ADC_TypeDef *ADCx)
  2124. {
  2125. return (READ_BIT(ADCx->CFGR1, ADC_CFGR1_EXTEN) == (LL_ADC_REG_TRIG_SOFTWARE & ADC_CFGR1_EXTEN));
  2126. }
  2127. /**
  2128. * @brief Set ADC group regular conversion trigger polarity.
  2129. * @note Applicable only for trigger source set to external trigger.
  2130. * @note On this STM32 serie, setting of this feature is conditioned to
  2131. * ADC state:
  2132. * ADC must be disabled or enabled without conversion on going
  2133. * on group regular.
  2134. * @rmtoll CFGR1 EXTEN LL_ADC_REG_SetTriggerEdge
  2135. * @param ADCx ADC instance
  2136. * @param ExternalTriggerEdge This parameter can be one of the following values:
  2137. * @arg @ref LL_ADC_REG_TRIG_EXT_RISING
  2138. * @arg @ref LL_ADC_REG_TRIG_EXT_FALLING
  2139. * @arg @ref LL_ADC_REG_TRIG_EXT_RISINGFALLING
  2140. * @retval None
  2141. */
  2142. __STATIC_INLINE void LL_ADC_REG_SetTriggerEdge(ADC_TypeDef *ADCx, uint32_t ExternalTriggerEdge)
  2143. {
  2144. MODIFY_REG(ADCx->CFGR1, ADC_CFGR1_EXTEN, ExternalTriggerEdge);
  2145. }
  2146. /**
  2147. * @brief Get ADC group regular conversion trigger polarity.
  2148. * @note Applicable only for trigger source set to external trigger.
  2149. * @rmtoll CFGR1 EXTEN LL_ADC_REG_GetTriggerEdge
  2150. * @param ADCx ADC instance
  2151. * @retval Returned value can be one of the following values:
  2152. * @arg @ref LL_ADC_REG_TRIG_EXT_RISING
  2153. * @arg @ref LL_ADC_REG_TRIG_EXT_FALLING
  2154. * @arg @ref LL_ADC_REG_TRIG_EXT_RISINGFALLING
  2155. */
  2156. __STATIC_INLINE uint32_t LL_ADC_REG_GetTriggerEdge(ADC_TypeDef *ADCx)
  2157. {
  2158. return (uint32_t)(READ_BIT(ADCx->CFGR1, ADC_CFGR1_EXTEN));
  2159. }
  2160. /**
  2161. * @brief Set ADC group regular sequencer scan direction.
  2162. * @note On some other STM32 families, this setting is not available and
  2163. * the default scan direction is forward.
  2164. * @note On this STM32 serie, setting of this feature is conditioned to
  2165. * ADC state:
  2166. * ADC must be disabled or enabled without conversion on going
  2167. * on group regular.
  2168. * @rmtoll CFGR1 SCANDIR LL_ADC_REG_SetSequencerScanDirection
  2169. * @param ADCx ADC instance
  2170. * @param ScanDirection This parameter can be one of the following values:
  2171. * @arg @ref LL_ADC_REG_SEQ_SCAN_DIR_FORWARD
  2172. * @arg @ref LL_ADC_REG_SEQ_SCAN_DIR_BACKWARD
  2173. * @retval None
  2174. */
  2175. __STATIC_INLINE void LL_ADC_REG_SetSequencerScanDirection(ADC_TypeDef *ADCx, uint32_t ScanDirection)
  2176. {
  2177. MODIFY_REG(ADCx->CFGR1, ADC_CFGR1_SCANDIR, ScanDirection);
  2178. }
  2179. /**
  2180. * @brief Get ADC group regular sequencer scan direction.
  2181. * @note On some other STM32 families, this setting is not available and
  2182. * the default scan direction is forward.
  2183. * @rmtoll CFGR1 SCANDIR LL_ADC_REG_GetSequencerScanDirection
  2184. * @param ADCx ADC instance
  2185. * @retval Returned value can be one of the following values:
  2186. * @arg @ref LL_ADC_REG_SEQ_SCAN_DIR_FORWARD
  2187. * @arg @ref LL_ADC_REG_SEQ_SCAN_DIR_BACKWARD
  2188. */
  2189. __STATIC_INLINE uint32_t LL_ADC_REG_GetSequencerScanDirection(ADC_TypeDef *ADCx)
  2190. {
  2191. return (uint32_t)(READ_BIT(ADCx->CFGR1, ADC_CFGR1_SCANDIR));
  2192. }
  2193. /**
  2194. * @brief Set ADC group regular sequencer discontinuous mode:
  2195. * sequence subdivided and scan conversions interrupted every selected
  2196. * number of ranks.
  2197. * @note It is not possible to enable both ADC group regular
  2198. * continuous mode and sequencer discontinuous mode.
  2199. * @note On this STM32 serie, setting of this feature is conditioned to
  2200. * ADC state:
  2201. * ADC must be disabled or enabled without conversion on going
  2202. * on group regular.
  2203. * @rmtoll CFGR1 DISCEN LL_ADC_REG_SetSequencerDiscont\n
  2204. * @param ADCx ADC instance
  2205. * @param SeqDiscont This parameter can be one of the following values:
  2206. * @arg @ref LL_ADC_REG_SEQ_DISCONT_DISABLE
  2207. * @arg @ref LL_ADC_REG_SEQ_DISCONT_1RANK
  2208. * @retval None
  2209. */
  2210. __STATIC_INLINE void LL_ADC_REG_SetSequencerDiscont(ADC_TypeDef *ADCx, uint32_t SeqDiscont)
  2211. {
  2212. MODIFY_REG(ADCx->CFGR1, ADC_CFGR1_DISCEN, SeqDiscont);
  2213. }
  2214. /**
  2215. * @brief Get ADC group regular sequencer discontinuous mode:
  2216. * sequence subdivided and scan conversions interrupted every selected
  2217. * number of ranks.
  2218. * @rmtoll CFGR1 DISCEN LL_ADC_REG_GetSequencerDiscont\n
  2219. * @param ADCx ADC instance
  2220. * @retval Returned value can be one of the following values:
  2221. * @arg @ref LL_ADC_REG_SEQ_DISCONT_DISABLE
  2222. * @arg @ref LL_ADC_REG_SEQ_DISCONT_1RANK
  2223. */
  2224. __STATIC_INLINE uint32_t LL_ADC_REG_GetSequencerDiscont(ADC_TypeDef *ADCx)
  2225. {
  2226. return (uint32_t)(READ_BIT(ADCx->CFGR1, ADC_CFGR1_DISCEN));
  2227. }
  2228. /**
  2229. * @brief Set ADC group regular sequence: channel on rank corresponding to
  2230. * channel number.
  2231. * @note This function performs:
  2232. * - Channels ordering into each rank of scan sequence:
  2233. * rank of each channel is fixed by channel HW number
  2234. * (channel 0 fixed on rank 0, channel 1 fixed on rank1, ...).
  2235. * - Set channels selected by overwriting the current sequencer
  2236. * configuration.
  2237. * @note On this STM32 serie, ADC group regular sequencer is
  2238. * not fully configurable: sequencer length and each rank
  2239. * affectation to a channel are fixed by channel HW number.
  2240. * @note Depending on devices and packages, some channels may not be available.
  2241. * Refer to device datasheet for channels availability.
  2242. * @note On this STM32 serie, to measure internal channels (VrefInt,
  2243. * TempSensor, ...), measurement paths to internal channels must be
  2244. * enabled separately.
  2245. * This can be done using function @ref LL_ADC_SetCommonPathInternalCh().
  2246. * @note On this STM32 serie, setting of this feature is conditioned to
  2247. * ADC state:
  2248. * ADC must be disabled or enabled without conversion on going
  2249. * on group regular.
  2250. * @note One or several values can be selected.
  2251. * Example: (LL_ADC_CHANNEL_4 | LL_ADC_CHANNEL_12 | ...)
  2252. * @rmtoll CHSELR CHSEL0 LL_ADC_REG_SetSequencerChannels\n
  2253. * CHSELR CHSEL1 LL_ADC_REG_SetSequencerChannels\n
  2254. * CHSELR CHSEL2 LL_ADC_REG_SetSequencerChannels\n
  2255. * CHSELR CHSEL3 LL_ADC_REG_SetSequencerChannels\n
  2256. * CHSELR CHSEL4 LL_ADC_REG_SetSequencerChannels\n
  2257. * CHSELR CHSEL5 LL_ADC_REG_SetSequencerChannels\n
  2258. * CHSELR CHSEL6 LL_ADC_REG_SetSequencerChannels\n
  2259. * CHSELR CHSEL7 LL_ADC_REG_SetSequencerChannels\n
  2260. * CHSELR CHSEL8 LL_ADC_REG_SetSequencerChannels\n
  2261. * CHSELR CHSEL9 LL_ADC_REG_SetSequencerChannels\n
  2262. * CHSELR CHSEL10 LL_ADC_REG_SetSequencerChannels\n
  2263. * CHSELR CHSEL11 LL_ADC_REG_SetSequencerChannels\n
  2264. * CHSELR CHSEL12 LL_ADC_REG_SetSequencerChannels\n
  2265. * CHSELR CHSEL13 LL_ADC_REG_SetSequencerChannels\n
  2266. * CHSELR CHSEL14 LL_ADC_REG_SetSequencerChannels\n
  2267. * CHSELR CHSEL15 LL_ADC_REG_SetSequencerChannels\n
  2268. * CHSELR CHSEL16 LL_ADC_REG_SetSequencerChannels\n
  2269. * CHSELR CHSEL17 LL_ADC_REG_SetSequencerChannels\n
  2270. * CHSELR CHSEL18 LL_ADC_REG_SetSequencerChannels
  2271. * @param ADCx ADC instance
  2272. * @param Channel This parameter can be a combination of the following values:
  2273. * @arg @ref LL_ADC_CHANNEL_0
  2274. * @arg @ref LL_ADC_CHANNEL_1
  2275. * @arg @ref LL_ADC_CHANNEL_2
  2276. * @arg @ref LL_ADC_CHANNEL_3
  2277. * @arg @ref LL_ADC_CHANNEL_4
  2278. * @arg @ref LL_ADC_CHANNEL_5
  2279. * @arg @ref LL_ADC_CHANNEL_6
  2280. * @arg @ref LL_ADC_CHANNEL_7
  2281. * @arg @ref LL_ADC_CHANNEL_8
  2282. * @arg @ref LL_ADC_CHANNEL_9
  2283. * @arg @ref LL_ADC_CHANNEL_10
  2284. * @arg @ref LL_ADC_CHANNEL_11
  2285. * @arg @ref LL_ADC_CHANNEL_12
  2286. * @arg @ref LL_ADC_CHANNEL_13
  2287. * @arg @ref LL_ADC_CHANNEL_14
  2288. * @arg @ref LL_ADC_CHANNEL_15
  2289. * @arg @ref LL_ADC_CHANNEL_16 (1)
  2290. * @arg @ref LL_ADC_CHANNEL_17
  2291. * @arg @ref LL_ADC_CHANNEL_18
  2292. * @arg @ref LL_ADC_CHANNEL_VREFINT
  2293. * @arg @ref LL_ADC_CHANNEL_TEMPSENSOR
  2294. * @arg @ref LL_ADC_CHANNEL_VLCD (1)
  2295. *
  2296. * (1) On STM32L0, parameter not available on all devices: only on STM32L053xx, STM32L063xx, STM32L073xx, STM32L083xx.
  2297. * @retval None
  2298. */
  2299. __STATIC_INLINE void LL_ADC_REG_SetSequencerChannels(ADC_TypeDef *ADCx, uint32_t Channel)
  2300. {
  2301. /* Parameter "Channel" is used with masks because containing */
  2302. /* other bits reserved for other purpose. */
  2303. WRITE_REG(ADCx->CHSELR, (Channel & ADC_CHANNEL_ID_BITFIELD_MASK));
  2304. }
  2305. /**
  2306. * @brief Add channel to ADC group regular sequence: channel on rank corresponding to
  2307. * channel number.
  2308. * @note This function performs:
  2309. * - Channels ordering into each rank of scan sequence:
  2310. * rank of each channel is fixed by channel HW number
  2311. * (channel 0 fixed on rank 0, channel 1 fixed on rank1, ...).
  2312. * - Set channels selected by adding them to the current sequencer
  2313. * configuration.
  2314. * @note On this STM32 serie, ADC group regular sequencer is
  2315. * not fully configurable: sequencer length and each rank
  2316. * affectation to a channel are fixed by channel HW number.
  2317. * @note Depending on devices and packages, some channels may not be available.
  2318. * Refer to device datasheet for channels availability.
  2319. * @note On this STM32 serie, to measure internal channels (VrefInt,
  2320. * TempSensor, ...), measurement paths to internal channels must be
  2321. * enabled separately.
  2322. * This can be done using function @ref LL_ADC_SetCommonPathInternalCh().
  2323. * @note On this STM32 serie, setting of this feature is conditioned to
  2324. * ADC state:
  2325. * ADC must be disabled or enabled without conversion on going
  2326. * on group regular.
  2327. * @note One or several values can be selected.
  2328. * Example: (LL_ADC_CHANNEL_4 | LL_ADC_CHANNEL_12 | ...)
  2329. * @rmtoll CHSELR CHSEL0 LL_ADC_REG_SetSequencerChAdd\n
  2330. * CHSELR CHSEL1 LL_ADC_REG_SetSequencerChAdd\n
  2331. * CHSELR CHSEL2 LL_ADC_REG_SetSequencerChAdd\n
  2332. * CHSELR CHSEL3 LL_ADC_REG_SetSequencerChAdd\n
  2333. * CHSELR CHSEL4 LL_ADC_REG_SetSequencerChAdd\n
  2334. * CHSELR CHSEL5 LL_ADC_REG_SetSequencerChAdd\n
  2335. * CHSELR CHSEL6 LL_ADC_REG_SetSequencerChAdd\n
  2336. * CHSELR CHSEL7 LL_ADC_REG_SetSequencerChAdd\n
  2337. * CHSELR CHSEL8 LL_ADC_REG_SetSequencerChAdd\n
  2338. * CHSELR CHSEL9 LL_ADC_REG_SetSequencerChAdd\n
  2339. * CHSELR CHSEL10 LL_ADC_REG_SetSequencerChAdd\n
  2340. * CHSELR CHSEL11 LL_ADC_REG_SetSequencerChAdd\n
  2341. * CHSELR CHSEL12 LL_ADC_REG_SetSequencerChAdd\n
  2342. * CHSELR CHSEL13 LL_ADC_REG_SetSequencerChAdd\n
  2343. * CHSELR CHSEL14 LL_ADC_REG_SetSequencerChAdd\n
  2344. * CHSELR CHSEL15 LL_ADC_REG_SetSequencerChAdd\n
  2345. * CHSELR CHSEL16 LL_ADC_REG_SetSequencerChAdd\n
  2346. * CHSELR CHSEL17 LL_ADC_REG_SetSequencerChAdd\n
  2347. * CHSELR CHSEL18 LL_ADC_REG_SetSequencerChAdd
  2348. * @param ADCx ADC instance
  2349. * @param Channel This parameter can be a combination of the following values:
  2350. * @arg @ref LL_ADC_CHANNEL_0
  2351. * @arg @ref LL_ADC_CHANNEL_1
  2352. * @arg @ref LL_ADC_CHANNEL_2
  2353. * @arg @ref LL_ADC_CHANNEL_3
  2354. * @arg @ref LL_ADC_CHANNEL_4
  2355. * @arg @ref LL_ADC_CHANNEL_5
  2356. * @arg @ref LL_ADC_CHANNEL_6
  2357. * @arg @ref LL_ADC_CHANNEL_7
  2358. * @arg @ref LL_ADC_CHANNEL_8
  2359. * @arg @ref LL_ADC_CHANNEL_9
  2360. * @arg @ref LL_ADC_CHANNEL_10
  2361. * @arg @ref LL_ADC_CHANNEL_11
  2362. * @arg @ref LL_ADC_CHANNEL_12
  2363. * @arg @ref LL_ADC_CHANNEL_13
  2364. * @arg @ref LL_ADC_CHANNEL_14
  2365. * @arg @ref LL_ADC_CHANNEL_15
  2366. * @arg @ref LL_ADC_CHANNEL_16 (1)
  2367. * @arg @ref LL_ADC_CHANNEL_17
  2368. * @arg @ref LL_ADC_CHANNEL_18
  2369. * @arg @ref LL_ADC_CHANNEL_VREFINT
  2370. * @arg @ref LL_ADC_CHANNEL_TEMPSENSOR
  2371. * @arg @ref LL_ADC_CHANNEL_VLCD (1)
  2372. *
  2373. * (1) On STM32L0, parameter not available on all devices: only on STM32L053xx, STM32L063xx, STM32L073xx, STM32L083xx.
  2374. * @retval None
  2375. */
  2376. __STATIC_INLINE void LL_ADC_REG_SetSequencerChAdd(ADC_TypeDef *ADCx, uint32_t Channel)
  2377. {
  2378. /* Parameter "Channel" is used with masks because containing */
  2379. /* other bits reserved for other purpose. */
  2380. SET_BIT(ADCx->CHSELR, (Channel & ADC_CHANNEL_ID_BITFIELD_MASK));
  2381. }
  2382. /**
  2383. * @brief Remove channel to ADC group regular sequence: channel on rank corresponding to
  2384. * channel number.
  2385. * @note This function performs:
  2386. * - Channels ordering into each rank of scan sequence:
  2387. * rank of each channel is fixed by channel HW number
  2388. * (channel 0 fixed on rank 0, channel 1 fixed on rank1, ...).
  2389. * - Set channels selected by removing them to the current sequencer
  2390. * configuration.
  2391. * @note On this STM32 serie, ADC group regular sequencer is
  2392. * not fully configurable: sequencer length and each rank
  2393. * affectation to a channel are fixed by channel HW number.
  2394. * @note Depending on devices and packages, some channels may not be available.
  2395. * Refer to device datasheet for channels availability.
  2396. * @note On this STM32 serie, to measure internal channels (VrefInt,
  2397. * TempSensor, ...), measurement paths to internal channels must be
  2398. * enabled separately.
  2399. * This can be done using function @ref LL_ADC_SetCommonPathInternalCh().
  2400. * @note On this STM32 serie, setting of this feature is conditioned to
  2401. * ADC state:
  2402. * ADC must be disabled or enabled without conversion on going
  2403. * on group regular.
  2404. * @note One or several values can be selected.
  2405. * Example: (LL_ADC_CHANNEL_4 | LL_ADC_CHANNEL_12 | ...)
  2406. * @rmtoll CHSELR CHSEL0 LL_ADC_REG_SetSequencerChRem\n
  2407. * CHSELR CHSEL1 LL_ADC_REG_SetSequencerChRem\n
  2408. * CHSELR CHSEL2 LL_ADC_REG_SetSequencerChRem\n
  2409. * CHSELR CHSEL3 LL_ADC_REG_SetSequencerChRem\n
  2410. * CHSELR CHSEL4 LL_ADC_REG_SetSequencerChRem\n
  2411. * CHSELR CHSEL5 LL_ADC_REG_SetSequencerChRem\n
  2412. * CHSELR CHSEL6 LL_ADC_REG_SetSequencerChRem\n
  2413. * CHSELR CHSEL7 LL_ADC_REG_SetSequencerChRem\n
  2414. * CHSELR CHSEL8 LL_ADC_REG_SetSequencerChRem\n
  2415. * CHSELR CHSEL9 LL_ADC_REG_SetSequencerChRem\n
  2416. * CHSELR CHSEL10 LL_ADC_REG_SetSequencerChRem\n
  2417. * CHSELR CHSEL11 LL_ADC_REG_SetSequencerChRem\n
  2418. * CHSELR CHSEL12 LL_ADC_REG_SetSequencerChRem\n
  2419. * CHSELR CHSEL13 LL_ADC_REG_SetSequencerChRem\n
  2420. * CHSELR CHSEL14 LL_ADC_REG_SetSequencerChRem\n
  2421. * CHSELR CHSEL15 LL_ADC_REG_SetSequencerChRem\n
  2422. * CHSELR CHSEL16 LL_ADC_REG_SetSequencerChRem\n
  2423. * CHSELR CHSEL17 LL_ADC_REG_SetSequencerChRem\n
  2424. * CHSELR CHSEL18 LL_ADC_REG_SetSequencerChRem
  2425. * @param ADCx ADC instance
  2426. * @param Channel This parameter can be a combination of the following values:
  2427. * @arg @ref LL_ADC_CHANNEL_0
  2428. * @arg @ref LL_ADC_CHANNEL_1
  2429. * @arg @ref LL_ADC_CHANNEL_2
  2430. * @arg @ref LL_ADC_CHANNEL_3
  2431. * @arg @ref LL_ADC_CHANNEL_4
  2432. * @arg @ref LL_ADC_CHANNEL_5
  2433. * @arg @ref LL_ADC_CHANNEL_6
  2434. * @arg @ref LL_ADC_CHANNEL_7
  2435. * @arg @ref LL_ADC_CHANNEL_8
  2436. * @arg @ref LL_ADC_CHANNEL_9
  2437. * @arg @ref LL_ADC_CHANNEL_10
  2438. * @arg @ref LL_ADC_CHANNEL_11
  2439. * @arg @ref LL_ADC_CHANNEL_12
  2440. * @arg @ref LL_ADC_CHANNEL_13
  2441. * @arg @ref LL_ADC_CHANNEL_14
  2442. * @arg @ref LL_ADC_CHANNEL_15
  2443. * @arg @ref LL_ADC_CHANNEL_16 (1)
  2444. * @arg @ref LL_ADC_CHANNEL_17
  2445. * @arg @ref LL_ADC_CHANNEL_18
  2446. * @arg @ref LL_ADC_CHANNEL_VREFINT
  2447. * @arg @ref LL_ADC_CHANNEL_TEMPSENSOR
  2448. * @arg @ref LL_ADC_CHANNEL_VLCD (1)
  2449. *
  2450. * (1) On STM32L0, parameter not available on all devices: only on STM32L053xx, STM32L063xx, STM32L073xx, STM32L083xx.
  2451. * @retval None
  2452. */
  2453. __STATIC_INLINE void LL_ADC_REG_SetSequencerChRem(ADC_TypeDef *ADCx, uint32_t Channel)
  2454. {
  2455. /* Parameter "Channel" is used with masks because containing */
  2456. /* other bits reserved for other purpose. */
  2457. CLEAR_BIT(ADCx->CHSELR, (Channel & ADC_CHANNEL_ID_BITFIELD_MASK));
  2458. }
  2459. /**
  2460. * @brief Get ADC group regular sequence: channel on rank corresponding to
  2461. * channel number.
  2462. * @note This function performs:
  2463. * - Channels order reading into each rank of scan sequence:
  2464. * rank of each channel is fixed by channel HW number
  2465. * (channel 0 fixed on rank 0, channel 1 fixed on rank1, ...).
  2466. * @note On this STM32 serie, ADC group regular sequencer is
  2467. * not fully configurable: sequencer length and each rank
  2468. * affectation to a channel are fixed by channel HW number.
  2469. * @note Depending on devices and packages, some channels may not be available.
  2470. * Refer to device datasheet for channels availability.
  2471. * @note On this STM32 serie, to measure internal channels (VrefInt,
  2472. * TempSensor, ...), measurement paths to internal channels must be
  2473. * enabled separately.
  2474. * This can be done using function @ref LL_ADC_SetCommonPathInternalCh().
  2475. * @note On this STM32 serie, setting of this feature is conditioned to
  2476. * ADC state:
  2477. * ADC must be disabled or enabled without conversion on going
  2478. * on group regular.
  2479. * @note One or several values can be retrieved.
  2480. * Example: (LL_ADC_CHANNEL_4 | LL_ADC_CHANNEL_12 | ...)
  2481. * @rmtoll CHSELR CHSEL0 LL_ADC_REG_GetSequencerChannels\n
  2482. * CHSELR CHSEL1 LL_ADC_REG_GetSequencerChannels\n
  2483. * CHSELR CHSEL2 LL_ADC_REG_GetSequencerChannels\n
  2484. * CHSELR CHSEL3 LL_ADC_REG_GetSequencerChannels\n
  2485. * CHSELR CHSEL4 LL_ADC_REG_GetSequencerChannels\n
  2486. * CHSELR CHSEL5 LL_ADC_REG_GetSequencerChannels\n
  2487. * CHSELR CHSEL6 LL_ADC_REG_GetSequencerChannels\n
  2488. * CHSELR CHSEL7 LL_ADC_REG_GetSequencerChannels\n
  2489. * CHSELR CHSEL8 LL_ADC_REG_GetSequencerChannels\n
  2490. * CHSELR CHSEL9 LL_ADC_REG_GetSequencerChannels\n
  2491. * CHSELR CHSEL10 LL_ADC_REG_GetSequencerChannels\n
  2492. * CHSELR CHSEL11 LL_ADC_REG_GetSequencerChannels\n
  2493. * CHSELR CHSEL12 LL_ADC_REG_GetSequencerChannels\n
  2494. * CHSELR CHSEL13 LL_ADC_REG_GetSequencerChannels\n
  2495. * CHSELR CHSEL14 LL_ADC_REG_GetSequencerChannels\n
  2496. * CHSELR CHSEL15 LL_ADC_REG_GetSequencerChannels\n
  2497. * CHSELR CHSEL16 LL_ADC_REG_GetSequencerChannels\n
  2498. * CHSELR CHSEL17 LL_ADC_REG_GetSequencerChannels\n
  2499. * CHSELR CHSEL18 LL_ADC_REG_GetSequencerChannels
  2500. * @param ADCx ADC instance
  2501. * @retval Returned value can be a combination of the following values:
  2502. * @arg @ref LL_ADC_CHANNEL_0
  2503. * @arg @ref LL_ADC_CHANNEL_1
  2504. * @arg @ref LL_ADC_CHANNEL_2
  2505. * @arg @ref LL_ADC_CHANNEL_3
  2506. * @arg @ref LL_ADC_CHANNEL_4
  2507. * @arg @ref LL_ADC_CHANNEL_5
  2508. * @arg @ref LL_ADC_CHANNEL_6
  2509. * @arg @ref LL_ADC_CHANNEL_7
  2510. * @arg @ref LL_ADC_CHANNEL_8
  2511. * @arg @ref LL_ADC_CHANNEL_9
  2512. * @arg @ref LL_ADC_CHANNEL_10
  2513. * @arg @ref LL_ADC_CHANNEL_11
  2514. * @arg @ref LL_ADC_CHANNEL_12
  2515. * @arg @ref LL_ADC_CHANNEL_13
  2516. * @arg @ref LL_ADC_CHANNEL_14
  2517. * @arg @ref LL_ADC_CHANNEL_15
  2518. * @arg @ref LL_ADC_CHANNEL_16 (1)
  2519. * @arg @ref LL_ADC_CHANNEL_17
  2520. * @arg @ref LL_ADC_CHANNEL_18
  2521. * @arg @ref LL_ADC_CHANNEL_VREFINT
  2522. * @arg @ref LL_ADC_CHANNEL_TEMPSENSOR
  2523. * @arg @ref LL_ADC_CHANNEL_VLCD (1)
  2524. *
  2525. * (1) On STM32L0, parameter not available on all devices: only on STM32L053xx, STM32L063xx, STM32L073xx, STM32L083xx.
  2526. */
  2527. __STATIC_INLINE uint32_t LL_ADC_REG_GetSequencerChannels(ADC_TypeDef *ADCx)
  2528. {
  2529. register uint32_t ChannelsBitfield = READ_BIT(ADCx->CHSELR, ADC_CHSELR_CHSEL);
  2530. return ( (((ChannelsBitfield & ADC_CHSELR_CHSEL0) >> ADC_CHSELR_CHSEL0_BITOFFSET_POS) * LL_ADC_CHANNEL_0)
  2531. | (((ChannelsBitfield & ADC_CHSELR_CHSEL1) >> ADC_CHSELR_CHSEL1_BITOFFSET_POS) * LL_ADC_CHANNEL_1)
  2532. | (((ChannelsBitfield & ADC_CHSELR_CHSEL2) >> ADC_CHSELR_CHSEL2_BITOFFSET_POS) * LL_ADC_CHANNEL_2)
  2533. | (((ChannelsBitfield & ADC_CHSELR_CHSEL3) >> ADC_CHSELR_CHSEL3_BITOFFSET_POS) * LL_ADC_CHANNEL_3)
  2534. | (((ChannelsBitfield & ADC_CHSELR_CHSEL4) >> ADC_CHSELR_CHSEL4_BITOFFSET_POS) * LL_ADC_CHANNEL_4)
  2535. | (((ChannelsBitfield & ADC_CHSELR_CHSEL5) >> ADC_CHSELR_CHSEL5_BITOFFSET_POS) * LL_ADC_CHANNEL_5)
  2536. | (((ChannelsBitfield & ADC_CHSELR_CHSEL6) >> ADC_CHSELR_CHSEL6_BITOFFSET_POS) * LL_ADC_CHANNEL_6)
  2537. | (((ChannelsBitfield & ADC_CHSELR_CHSEL7) >> ADC_CHSELR_CHSEL7_BITOFFSET_POS) * LL_ADC_CHANNEL_7)
  2538. | (((ChannelsBitfield & ADC_CHSELR_CHSEL8) >> ADC_CHSELR_CHSEL8_BITOFFSET_POS) * LL_ADC_CHANNEL_8)
  2539. | (((ChannelsBitfield & ADC_CHSELR_CHSEL9) >> ADC_CHSELR_CHSEL9_BITOFFSET_POS) * LL_ADC_CHANNEL_9)
  2540. | (((ChannelsBitfield & ADC_CHSELR_CHSEL10) >> ADC_CHSELR_CHSEL10_BITOFFSET_POS) * LL_ADC_CHANNEL_10)
  2541. | (((ChannelsBitfield & ADC_CHSELR_CHSEL11) >> ADC_CHSELR_CHSEL11_BITOFFSET_POS) * LL_ADC_CHANNEL_11)
  2542. | (((ChannelsBitfield & ADC_CHSELR_CHSEL12) >> ADC_CHSELR_CHSEL12_BITOFFSET_POS) * LL_ADC_CHANNEL_12)
  2543. | (((ChannelsBitfield & ADC_CHSELR_CHSEL13) >> ADC_CHSELR_CHSEL13_BITOFFSET_POS) * LL_ADC_CHANNEL_13)
  2544. | (((ChannelsBitfield & ADC_CHSELR_CHSEL14) >> ADC_CHSELR_CHSEL14_BITOFFSET_POS) * LL_ADC_CHANNEL_14)
  2545. | (((ChannelsBitfield & ADC_CHSELR_CHSEL15) >> ADC_CHSELR_CHSEL15_BITOFFSET_POS) * LL_ADC_CHANNEL_15)
  2546. #if defined(ADC_CCR_VLCDEN)
  2547. | (((ChannelsBitfield & ADC_CHSELR_CHSEL16) >> ADC_CHSELR_CHSEL16_BITOFFSET_POS) * LL_ADC_CHANNEL_16)
  2548. #endif
  2549. | (((ChannelsBitfield & ADC_CHSELR_CHSEL17) >> ADC_CHSELR_CHSEL17_BITOFFSET_POS) * LL_ADC_CHANNEL_17)
  2550. | (((ChannelsBitfield & ADC_CHSELR_CHSEL18) >> ADC_CHSELR_CHSEL18_BITOFFSET_POS) * LL_ADC_CHANNEL_18)
  2551. );
  2552. }
  2553. /**
  2554. * @brief Set ADC continuous conversion mode on ADC group regular.
  2555. * @note Description of ADC continuous conversion mode:
  2556. * - single mode: one conversion per trigger
  2557. * - continuous mode: after the first trigger, following
  2558. * conversions launched successively automatically.
  2559. * @note It is not possible to enable both ADC group regular
  2560. * continuous mode and sequencer discontinuous mode.
  2561. * @note On this STM32 serie, setting of this feature is conditioned to
  2562. * ADC state:
  2563. * ADC must be disabled or enabled without conversion on going
  2564. * on group regular.
  2565. * @rmtoll CFGR1 CONT LL_ADC_REG_SetContinuousMode
  2566. * @param ADCx ADC instance
  2567. * @param Continuous This parameter can be one of the following values:
  2568. * @arg @ref LL_ADC_REG_CONV_SINGLE
  2569. * @arg @ref LL_ADC_REG_CONV_CONTINUOUS
  2570. * @retval None
  2571. */
  2572. __STATIC_INLINE void LL_ADC_REG_SetContinuousMode(ADC_TypeDef *ADCx, uint32_t Continuous)
  2573. {
  2574. MODIFY_REG(ADCx->CFGR1, ADC_CFGR1_CONT, Continuous);
  2575. }
  2576. /**
  2577. * @brief Get ADC continuous conversion mode on ADC group regular.
  2578. * @note Description of ADC continuous conversion mode:
  2579. * - single mode: one conversion per trigger
  2580. * - continuous mode: after the first trigger, following
  2581. * conversions launched successively automatically.
  2582. * @rmtoll CFGR1 CONT LL_ADC_REG_GetContinuousMode
  2583. * @param ADCx ADC instance
  2584. * @retval Returned value can be one of the following values:
  2585. * @arg @ref LL_ADC_REG_CONV_SINGLE
  2586. * @arg @ref LL_ADC_REG_CONV_CONTINUOUS
  2587. */
  2588. __STATIC_INLINE uint32_t LL_ADC_REG_GetContinuousMode(ADC_TypeDef *ADCx)
  2589. {
  2590. return (uint32_t)(READ_BIT(ADCx->CFGR1, ADC_CFGR1_CONT));
  2591. }
  2592. /**
  2593. * @brief Set ADC group regular conversion data transfer: no transfer or
  2594. * transfer by DMA, and DMA requests mode.
  2595. * @note If transfer by DMA selected, specifies the DMA requests
  2596. * mode:
  2597. * - Limited mode (One shot mode): DMA transfer requests are stopped
  2598. * when number of DMA data transfers (number of
  2599. * ADC conversions) is reached.
  2600. * This ADC mode is intended to be used with DMA mode non-circular.
  2601. * - Unlimited mode: DMA transfer requests are unlimited,
  2602. * whatever number of DMA data transfers (number of
  2603. * ADC conversions).
  2604. * This ADC mode is intended to be used with DMA mode circular.
  2605. * @note If ADC DMA requests mode is set to unlimited and DMA is set to
  2606. * mode non-circular:
  2607. * when DMA transfers size will be reached, DMA will stop transfers of
  2608. * ADC conversions data ADC will raise an overrun error
  2609. * (overrun flag and interruption if enabled).
  2610. * @note To configure DMA source address (peripheral address),
  2611. * use function @ref LL_ADC_DMA_GetRegAddr().
  2612. * @note On this STM32 serie, setting of this feature is conditioned to
  2613. * ADC state:
  2614. * ADC must be disabled or enabled without conversion on going
  2615. * on group regular.
  2616. * @rmtoll CFGR1 DMAEN LL_ADC_REG_SetDMATransfer\n
  2617. * CFGR1 DMACFG LL_ADC_REG_SetDMATransfer
  2618. * @param ADCx ADC instance
  2619. * @param DMATransfer This parameter can be one of the following values:
  2620. * @arg @ref LL_ADC_REG_DMA_TRANSFER_NONE
  2621. * @arg @ref LL_ADC_REG_DMA_TRANSFER_LIMITED
  2622. * @arg @ref LL_ADC_REG_DMA_TRANSFER_UNLIMITED
  2623. * @retval None
  2624. */
  2625. __STATIC_INLINE void LL_ADC_REG_SetDMATransfer(ADC_TypeDef *ADCx, uint32_t DMATransfer)
  2626. {
  2627. MODIFY_REG(ADCx->CFGR1, ADC_CFGR1_DMAEN | ADC_CFGR1_DMACFG, DMATransfer);
  2628. }
  2629. /**
  2630. * @brief Get ADC group regular conversion data transfer: no transfer or
  2631. * transfer by DMA, and DMA requests mode.
  2632. * @note If transfer by DMA selected, specifies the DMA requests
  2633. * mode:
  2634. * - Limited mode (One shot mode): DMA transfer requests are stopped
  2635. * when number of DMA data transfers (number of
  2636. * ADC conversions) is reached.
  2637. * This ADC mode is intended to be used with DMA mode non-circular.
  2638. * - Unlimited mode: DMA transfer requests are unlimited,
  2639. * whatever number of DMA data transfers (number of
  2640. * ADC conversions).
  2641. * This ADC mode is intended to be used with DMA mode circular.
  2642. * @note If ADC DMA requests mode is set to unlimited and DMA is set to
  2643. * mode non-circular:
  2644. * when DMA transfers size will be reached, DMA will stop transfers of
  2645. * ADC conversions data ADC will raise an overrun error
  2646. * (overrun flag and interruption if enabled).
  2647. * @note To configure DMA source address (peripheral address),
  2648. * use function @ref LL_ADC_DMA_GetRegAddr().
  2649. * @rmtoll CFGR1 DMAEN LL_ADC_REG_GetDMATransfer\n
  2650. * CFGR1 DMACFG LL_ADC_REG_GetDMATransfer
  2651. * @param ADCx ADC instance
  2652. * @retval Returned value can be one of the following values:
  2653. * @arg @ref LL_ADC_REG_DMA_TRANSFER_NONE
  2654. * @arg @ref LL_ADC_REG_DMA_TRANSFER_LIMITED
  2655. * @arg @ref LL_ADC_REG_DMA_TRANSFER_UNLIMITED
  2656. */
  2657. __STATIC_INLINE uint32_t LL_ADC_REG_GetDMATransfer(ADC_TypeDef *ADCx)
  2658. {
  2659. return (uint32_t)(READ_BIT(ADCx->CFGR1, ADC_CFGR1_DMAEN | ADC_CFGR1_DMACFG));
  2660. }
  2661. /**
  2662. * @brief Set ADC group regular behavior in case of overrun:
  2663. * data preserved or overwritten.
  2664. * @note Compatibility with devices without feature overrun:
  2665. * other devices without this feature have a behavior
  2666. * equivalent to data overwritten.
  2667. * The default setting of overrun is data preserved.
  2668. * Therefore, for compatibility with all devices, parameter
  2669. * overrun should be set to data overwritten.
  2670. * @note On this STM32 serie, setting of this feature is conditioned to
  2671. * ADC state:
  2672. * ADC must be disabled or enabled without conversion on going
  2673. * on group regular.
  2674. * @rmtoll CFGR1 OVRMOD LL_ADC_REG_SetOverrun
  2675. * @param ADCx ADC instance
  2676. * @param Overrun This parameter can be one of the following values:
  2677. * @arg @ref LL_ADC_REG_OVR_DATA_PRESERVED
  2678. * @arg @ref LL_ADC_REG_OVR_DATA_OVERWRITTEN
  2679. * @retval None
  2680. */
  2681. __STATIC_INLINE void LL_ADC_REG_SetOverrun(ADC_TypeDef *ADCx, uint32_t Overrun)
  2682. {
  2683. MODIFY_REG(ADCx->CFGR1, ADC_CFGR1_OVRMOD, Overrun);
  2684. }
  2685. /**
  2686. * @brief Get ADC group regular behavior in case of overrun:
  2687. * data preserved or overwritten.
  2688. * @rmtoll CFGR1 OVRMOD LL_ADC_REG_GetOverrun
  2689. * @param ADCx ADC instance
  2690. * @retval Returned value can be one of the following values:
  2691. * @arg @ref LL_ADC_REG_OVR_DATA_PRESERVED
  2692. * @arg @ref LL_ADC_REG_OVR_DATA_OVERWRITTEN
  2693. */
  2694. __STATIC_INLINE uint32_t LL_ADC_REG_GetOverrun(ADC_TypeDef *ADCx)
  2695. {
  2696. return (uint32_t)(READ_BIT(ADCx->CFGR1, ADC_CFGR1_OVRMOD));
  2697. }
  2698. /**
  2699. * @}
  2700. */
  2701. /** @defgroup ADC_LL_EF_Configuration_ADC_AnalogWatchdog Configuration of ADC transversal scope: analog watchdog
  2702. * @{
  2703. */
  2704. /**
  2705. * @brief Set ADC analog watchdog monitored channels:
  2706. * a single channel or all channels,
  2707. * on ADC group regular.
  2708. * @note Once monitored channels are selected, analog watchdog
  2709. * is enabled.
  2710. * @note In case of need to define a single channel to monitor
  2711. * with analog watchdog from sequencer channel definition,
  2712. * use helper macro @ref __LL_ADC_ANALOGWD_CHANNEL_GROUP().
  2713. * @note On this STM32 serie, there is only 1 kind of analog watchdog
  2714. * instance:
  2715. * - AWD standard (instance AWD1):
  2716. * - channels monitored: can monitor 1 channel or all channels.
  2717. * - groups monitored: ADC group regular.
  2718. * - resolution: resolution is not limited (corresponds to
  2719. * ADC resolution configured).
  2720. * @note On this STM32 serie, setting of this feature is conditioned to
  2721. * ADC state:
  2722. * ADC must be disabled or enabled without conversion on going
  2723. * on group regular.
  2724. * @rmtoll CFGR1 AWDCH LL_ADC_SetAnalogWDMonitChannels\n
  2725. * CFGR1 AWDSGL LL_ADC_SetAnalogWDMonitChannels\n
  2726. * CFGR1 AWDEN LL_ADC_SetAnalogWDMonitChannels
  2727. * @param ADCx ADC instance
  2728. * @param AWDChannelGroup This parameter can be one of the following values:
  2729. * @arg @ref LL_ADC_AWD_DISABLE
  2730. * @arg @ref LL_ADC_AWD_ALL_CHANNELS_REG
  2731. * @arg @ref LL_ADC_AWD_CHANNEL_0_REG
  2732. * @arg @ref LL_ADC_AWD_CHANNEL_1_REG
  2733. * @arg @ref LL_ADC_AWD_CHANNEL_2_REG
  2734. * @arg @ref LL_ADC_AWD_CHANNEL_3_REG
  2735. * @arg @ref LL_ADC_AWD_CHANNEL_4_REG
  2736. * @arg @ref LL_ADC_AWD_CHANNEL_5_REG
  2737. * @arg @ref LL_ADC_AWD_CHANNEL_6_REG
  2738. * @arg @ref LL_ADC_AWD_CHANNEL_7_REG
  2739. * @arg @ref LL_ADC_AWD_CHANNEL_8_REG
  2740. * @arg @ref LL_ADC_AWD_CHANNEL_9_REG
  2741. * @arg @ref LL_ADC_AWD_CHANNEL_10_REG
  2742. * @arg @ref LL_ADC_AWD_CHANNEL_11_REG
  2743. * @arg @ref LL_ADC_AWD_CHANNEL_12_REG
  2744. * @arg @ref LL_ADC_AWD_CHANNEL_13_REG
  2745. * @arg @ref LL_ADC_AWD_CHANNEL_14_REG
  2746. * @arg @ref LL_ADC_AWD_CHANNEL_15_REG
  2747. * @arg @ref LL_ADC_AWD_CHANNEL_16_REG (1)
  2748. * @arg @ref LL_ADC_AWD_CHANNEL_17_REG
  2749. * @arg @ref LL_ADC_AWD_CHANNEL_18_REG
  2750. * @arg @ref LL_ADC_AWD_CH_VREFINT_REG
  2751. * @arg @ref LL_ADC_AWD_CH_TEMPSENSOR_REG
  2752. * @arg @ref LL_ADC_AWD_CH_VLCD_REG (1)
  2753. *
  2754. * (1) On STM32L0, parameter not available on all devices: only on STM32L053xx, STM32L063xx, STM32L073xx, STM32L083xx.
  2755. * @retval None
  2756. */
  2757. __STATIC_INLINE void LL_ADC_SetAnalogWDMonitChannels(ADC_TypeDef *ADCx, uint32_t AWDChannelGroup)
  2758. {
  2759. MODIFY_REG(ADCx->CFGR1,
  2760. (ADC_CFGR1_AWDCH | ADC_CFGR1_AWDSGL | ADC_CFGR1_AWDEN),
  2761. (AWDChannelGroup & ADC_AWD_CR_ALL_CHANNEL_MASK));
  2762. }
  2763. /**
  2764. * @brief Get ADC analog watchdog monitored channel.
  2765. * @note Usage of the returned channel number:
  2766. * - To reinject this channel into another function LL_ADC_xxx:
  2767. * the returned channel number is only partly formatted on definition
  2768. * of literals LL_ADC_CHANNEL_x. Therefore, it has to be compared
  2769. * with parts of literals LL_ADC_CHANNEL_x or using
  2770. * helper macro @ref __LL_ADC_CHANNEL_TO_DECIMAL_NB().
  2771. * Then the selected literal LL_ADC_CHANNEL_x can be used
  2772. * as parameter for another function.
  2773. * - To get the channel number in decimal format:
  2774. * process the returned value with the helper macro
  2775. * @ref __LL_ADC_CHANNEL_TO_DECIMAL_NB().
  2776. * Applicable only when the analog watchdog is set to monitor
  2777. * one channel.
  2778. * @note On this STM32 serie, there is only 1 kind of analog watchdog
  2779. * instance:
  2780. * - AWD standard (instance AWD1):
  2781. * - channels monitored: can monitor 1 channel or all channels.
  2782. * - groups monitored: ADC group regular.
  2783. * - resolution: resolution is not limited (corresponds to
  2784. * ADC resolution configured).
  2785. * @note On this STM32 serie, setting of this feature is conditioned to
  2786. * ADC state:
  2787. * ADC must be disabled or enabled without conversion on going
  2788. * on group regular.
  2789. * @rmtoll CFGR1 AWDCH LL_ADC_GetAnalogWDMonitChannels\n
  2790. * CFGR1 AWDSGL LL_ADC_GetAnalogWDMonitChannels\n
  2791. * CFGR1 AWDEN LL_ADC_GetAnalogWDMonitChannels
  2792. * @param ADCx ADC instance
  2793. * @retval Returned value can be one of the following values:
  2794. * @arg @ref LL_ADC_AWD_DISABLE
  2795. * @arg @ref LL_ADC_AWD_ALL_CHANNELS_REG
  2796. * @arg @ref LL_ADC_AWD_CHANNEL_0_REG
  2797. * @arg @ref LL_ADC_AWD_CHANNEL_1_REG
  2798. * @arg @ref LL_ADC_AWD_CHANNEL_2_REG
  2799. * @arg @ref LL_ADC_AWD_CHANNEL_3_REG
  2800. * @arg @ref LL_ADC_AWD_CHANNEL_4_REG
  2801. * @arg @ref LL_ADC_AWD_CHANNEL_5_REG
  2802. * @arg @ref LL_ADC_AWD_CHANNEL_6_REG
  2803. * @arg @ref LL_ADC_AWD_CHANNEL_7_REG
  2804. * @arg @ref LL_ADC_AWD_CHANNEL_8_REG
  2805. * @arg @ref LL_ADC_AWD_CHANNEL_9_REG
  2806. * @arg @ref LL_ADC_AWD_CHANNEL_10_REG
  2807. * @arg @ref LL_ADC_AWD_CHANNEL_11_REG
  2808. * @arg @ref LL_ADC_AWD_CHANNEL_12_REG
  2809. * @arg @ref LL_ADC_AWD_CHANNEL_13_REG
  2810. * @arg @ref LL_ADC_AWD_CHANNEL_14_REG
  2811. * @arg @ref LL_ADC_AWD_CHANNEL_15_REG
  2812. * @arg @ref LL_ADC_AWD_CHANNEL_16_REG
  2813. * @arg @ref LL_ADC_AWD_CHANNEL_17_REG
  2814. * @arg @ref LL_ADC_AWD_CHANNEL_18_REG
  2815. */
  2816. __STATIC_INLINE uint32_t LL_ADC_GetAnalogWDMonitChannels(ADC_TypeDef *ADCx)
  2817. {
  2818. register uint32_t AWDChannelGroup = READ_BIT(ADCx->CFGR1, (ADC_CFGR1_AWDCH | ADC_CFGR1_AWDSGL | ADC_CFGR1_AWDEN));
  2819. /* Note: Set variable according to channel definition including channel ID */
  2820. /* with bitfield. */
  2821. register uint32_t AWDChannelSingle = ((AWDChannelGroup & ADC_CFGR1_AWDSGL) >> ADC_CFGR1_AWDSGL_BITOFFSET_POS);
  2822. register uint32_t AWDChannelBitField = (ADC_CHANNEL_0_BITFIELD << ((AWDChannelGroup & ADC_CHANNEL_ID_NUMBER_MASK) >> ADC_CHANNEL_ID_NUMBER_BITOFFSET_POS));
  2823. return (AWDChannelGroup | (AWDChannelBitField * AWDChannelSingle));
  2824. }
  2825. /**
  2826. * @brief Set ADC analog watchdog thresholds value of both thresholds
  2827. * high and low.
  2828. * @note If value of only one threshold high or low must be set,
  2829. * use function @ref LL_ADC_SetAnalogWDThresholds().
  2830. * @note In case of ADC resolution different of 12 bits,
  2831. * analog watchdog thresholds data require a specific shift.
  2832. * Use helper macro @ref __LL_ADC_ANALOGWD_SET_THRESHOLD_RESOLUTION().
  2833. * @note On this STM32 serie, there is only 1 kind of analog watchdog
  2834. * instance:
  2835. * - AWD standard (instance AWD1):
  2836. * - channels monitored: can monitor 1 channel or all channels.
  2837. * - groups monitored: ADC group regular.
  2838. * - resolution: resolution is not limited (corresponds to
  2839. * ADC resolution configured).
  2840. * @note On this STM32 serie, setting of this feature is conditioned to
  2841. * ADC state:
  2842. * ADC must be disabled or enabled without conversion on going
  2843. * on group regular.
  2844. * @rmtoll TR HT LL_ADC_ConfigAnalogWDThresholds\n
  2845. * TR LT LL_ADC_ConfigAnalogWDThresholds
  2846. * @param ADCx ADC instance
  2847. * @param AWDThresholdHighValue Value between Min_Data=0x000 and Max_Data=0xFFF
  2848. * @param AWDThresholdLowValue Value between Min_Data=0x000 and Max_Data=0xFFF
  2849. * @retval None
  2850. */
  2851. __STATIC_INLINE void LL_ADC_ConfigAnalogWDThresholds(ADC_TypeDef *ADCx, uint32_t AWDThresholdHighValue, uint32_t AWDThresholdLowValue)
  2852. {
  2853. MODIFY_REG(ADCx->TR,
  2854. ADC_TR_HT | ADC_TR_LT,
  2855. (AWDThresholdHighValue << ADC_TR_HT_BITOFFSET_POS) | AWDThresholdLowValue);
  2856. }
  2857. /**
  2858. * @brief Set ADC analog watchdog threshold value of threshold
  2859. * high or low.
  2860. * @note If values of both thresholds high or low must be set,
  2861. * use function @ref LL_ADC_ConfigAnalogWDThresholds().
  2862. * @note In case of ADC resolution different of 12 bits,
  2863. * analog watchdog thresholds data require a specific shift.
  2864. * Use helper macro @ref __LL_ADC_ANALOGWD_SET_THRESHOLD_RESOLUTION().
  2865. * @note On this STM32 serie, there is only 1 kind of analog watchdog
  2866. * instance:
  2867. * - AWD standard (instance AWD1):
  2868. * - channels monitored: can monitor 1 channel or all channels.
  2869. * - groups monitored: ADC group regular.
  2870. * - resolution: resolution is not limited (corresponds to
  2871. * ADC resolution configured).
  2872. * @note On this STM32 serie, setting of this feature is conditioned to
  2873. * ADC state:
  2874. * ADC must be disabled or enabled without conversion on going
  2875. * on group regular.
  2876. * @rmtoll TR HT LL_ADC_SetAnalogWDThresholds\n
  2877. * TR LT LL_ADC_SetAnalogWDThresholds
  2878. * @param ADCx ADC instance
  2879. * @param AWDThresholdsHighLow This parameter can be one of the following values:
  2880. * @arg @ref LL_ADC_AWD_THRESHOLD_HIGH
  2881. * @arg @ref LL_ADC_AWD_THRESHOLD_LOW
  2882. * @param AWDThresholdValue Value between Min_Data=0x000 and Max_Data=0xFFF
  2883. * @retval None
  2884. */
  2885. __STATIC_INLINE void LL_ADC_SetAnalogWDThresholds(ADC_TypeDef *ADCx, uint32_t AWDThresholdsHighLow, uint32_t AWDThresholdValue)
  2886. {
  2887. /* Parameter "AWDThresholdsHighLow" is used with mask "0x00000010" */
  2888. /* to be equivalent to "POSITION_VAL(AWDThresholdsHighLow)": if threshold */
  2889. /* high is selected, then data is shifted to LSB. Else(threshold low), */
  2890. /* data is not shifted. */
  2891. MODIFY_REG(ADCx->TR,
  2892. AWDThresholdsHighLow,
  2893. AWDThresholdValue << ((AWDThresholdsHighLow >> ADC_TR_HT_BITOFFSET_POS) & ((uint32_t)0x00000010U)));
  2894. }
  2895. /**
  2896. * @brief Get ADC analog watchdog threshold value of threshold high,
  2897. * threshold low or raw data with ADC thresholds high and low
  2898. * concatenated.
  2899. * @note If raw data with ADC thresholds high and low is retrieved,
  2900. * the data of each threshold high or low can be isolated
  2901. * using helper macro:
  2902. * @ref __LL_ADC_ANALOGWD_THRESHOLDS_HIGH_LOW().
  2903. * @note In case of ADC resolution different of 12 bits,
  2904. * analog watchdog thresholds data require a specific shift.
  2905. * Use helper macro @ref __LL_ADC_ANALOGWD_GET_THRESHOLD_RESOLUTION().
  2906. * @rmtoll TR HT LL_ADC_GetAnalogWDThresholds\n
  2907. * TR LT LL_ADC_GetAnalogWDThresholds
  2908. * @param ADCx ADC instance
  2909. * @param AWDThresholdsHighLow This parameter can be one of the following values:
  2910. * @arg @ref LL_ADC_AWD_THRESHOLD_HIGH
  2911. * @arg @ref LL_ADC_AWD_THRESHOLD_LOW
  2912. * @arg @ref LL_ADC_AWD_THRESHOLDS_HIGH_LOW
  2913. * @retval Value between Min_Data=0x000 and Max_Data=0xFFF
  2914. */
  2915. __STATIC_INLINE uint32_t LL_ADC_GetAnalogWDThresholds(ADC_TypeDef *ADCx, uint32_t AWDThresholdsHighLow)
  2916. {
  2917. /* Parameter "AWDThresholdsHighLow" is used with mask "0x00000010" */
  2918. /* to be equivalent to "POSITION_VAL(AWDThresholdsHighLow)": if threshold */
  2919. /* high is selected, then data is shifted to LSB. Else(threshold low or */
  2920. /* both thresholds), data is not shifted. */
  2921. return (uint32_t)(READ_BIT(ADCx->TR,
  2922. (AWDThresholdsHighLow | ADC_TR_LT))
  2923. >> ((~AWDThresholdsHighLow) & ((uint32_t)0x00000010U))
  2924. );
  2925. }
  2926. /**
  2927. * @}
  2928. */
  2929. /** @defgroup ADC_LL_EF_Configuration_ADC_oversampling Configuration of ADC transversal scope: oversampling
  2930. * @{
  2931. */
  2932. /**
  2933. * @brief Set ADC oversampling scope.
  2934. * @note On this STM32 serie, setting of this feature is conditioned to
  2935. * ADC state:
  2936. * ADC must be disabled or enabled without conversion on going
  2937. * on group regular.
  2938. * @rmtoll CFGR2 OVSE LL_ADC_SetOverSamplingScope
  2939. * @param ADCx ADC instance
  2940. * @param OvsScope This parameter can be one of the following values:
  2941. * @arg @ref LL_ADC_OVS_DISABLE
  2942. * @arg @ref LL_ADC_OVS_GRP_REGULAR_CONTINUED
  2943. * @retval None
  2944. */
  2945. __STATIC_INLINE void LL_ADC_SetOverSamplingScope(ADC_TypeDef *ADCx, uint32_t OvsScope)
  2946. {
  2947. MODIFY_REG(ADCx->CFGR2, ADC_CFGR2_OVSE, OvsScope);
  2948. }
  2949. /**
  2950. * @brief Get ADC oversampling scope.
  2951. * @rmtoll CFGR2 OVSE LL_ADC_GetOverSamplingScope
  2952. * @param ADCx ADC instance
  2953. * @retval Returned value can be one of the following values:
  2954. * @arg @ref LL_ADC_OVS_DISABLE
  2955. * @arg @ref LL_ADC_OVS_GRP_REGULAR_CONTINUED
  2956. */
  2957. __STATIC_INLINE uint32_t LL_ADC_GetOverSamplingScope(ADC_TypeDef *ADCx)
  2958. {
  2959. return (uint32_t)(READ_BIT(ADCx->CFGR2, ADC_CFGR2_OVSE));
  2960. }
  2961. /**
  2962. * @brief Set ADC oversampling discontinuous mode (triggered mode)
  2963. * on the selected ADC group.
  2964. * @note Number of oversampled conversions are done either in:
  2965. * - continuous mode (all conversions of oversampling ratio
  2966. * are done from 1 trigger)
  2967. * - discontinuous mode (each conversion of oversampling ratio
  2968. * needs a trigger)
  2969. * @note On this STM32 serie, setting of this feature is conditioned to
  2970. * ADC state:
  2971. * ADC must be disabled or enabled without conversion on going
  2972. * on group regular.
  2973. * @rmtoll CFGR2 TOVS LL_ADC_SetOverSamplingDiscont
  2974. * @param ADCx ADC instance
  2975. * @param OverSamplingDiscont This parameter can be one of the following values:
  2976. * @arg @ref LL_ADC_OVS_REG_CONT
  2977. * @arg @ref LL_ADC_OVS_REG_DISCONT
  2978. * @retval None
  2979. */
  2980. __STATIC_INLINE void LL_ADC_SetOverSamplingDiscont(ADC_TypeDef *ADCx, uint32_t OverSamplingDiscont)
  2981. {
  2982. MODIFY_REG(ADCx->CFGR2, ADC_CFGR2_TOVS, OverSamplingDiscont);
  2983. }
  2984. /**
  2985. * @brief Get ADC oversampling discontinuous mode (triggered mode)
  2986. * on the selected ADC group.
  2987. * @note Number of oversampled conversions are done either in:
  2988. * - continuous mode (all conversions of oversampling ratio
  2989. * are done from 1 trigger)
  2990. * - discontinuous mode (each conversion of oversampling ratio
  2991. * needs a trigger)
  2992. * @rmtoll CFGR2 TOVS LL_ADC_GetOverSamplingDiscont
  2993. * @param ADCx ADC instance
  2994. * @retval Returned value can be one of the following values:
  2995. * @arg @ref LL_ADC_OVS_REG_CONT
  2996. * @arg @ref LL_ADC_OVS_REG_DISCONT
  2997. */
  2998. __STATIC_INLINE uint32_t LL_ADC_GetOverSamplingDiscont(ADC_TypeDef *ADCx)
  2999. {
  3000. return (uint32_t)(READ_BIT(ADCx->CFGR2, ADC_CFGR2_TOVS));
  3001. }
  3002. /**
  3003. * @brief Set ADC oversampling
  3004. * @note This function set the 2 items of oversampling configuration:
  3005. * - ratio
  3006. * - shift
  3007. * @note On this STM32 serie, setting of this feature is conditioned to
  3008. * ADC state:
  3009. * ADC must be disabled or enabled without conversion on going
  3010. * on group regular.
  3011. * @rmtoll CFGR2 OVSS LL_ADC_ConfigOverSamplingRatioShift\n
  3012. * CFGR2 OVSR LL_ADC_ConfigOverSamplingRatioShift
  3013. * @param ADCx ADC instance
  3014. * @param Ratio This parameter can be one of the following values:
  3015. * @arg @ref LL_ADC_OVS_RATIO_2
  3016. * @arg @ref LL_ADC_OVS_RATIO_4
  3017. * @arg @ref LL_ADC_OVS_RATIO_8
  3018. * @arg @ref LL_ADC_OVS_RATIO_16
  3019. * @arg @ref LL_ADC_OVS_RATIO_32
  3020. * @arg @ref LL_ADC_OVS_RATIO_64
  3021. * @arg @ref LL_ADC_OVS_RATIO_128
  3022. * @arg @ref LL_ADC_OVS_RATIO_256
  3023. * @param Shift This parameter can be one of the following values:
  3024. * @arg @ref LL_ADC_OVS_SHIFT_NONE
  3025. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_1
  3026. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_2
  3027. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_3
  3028. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_4
  3029. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_5
  3030. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_6
  3031. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_7
  3032. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_8
  3033. * @retval None
  3034. */
  3035. __STATIC_INLINE void LL_ADC_ConfigOverSamplingRatioShift(ADC_TypeDef *ADCx, uint32_t Ratio, uint32_t Shift)
  3036. {
  3037. MODIFY_REG(ADCx->CFGR2, (ADC_CFGR2_OVSS | ADC_CFGR2_OVSR), (Shift | Ratio));
  3038. }
  3039. /**
  3040. * @brief Get ADC oversampling ratio
  3041. * @rmtoll CFGR2 OVSR LL_ADC_GetOverSamplingRatio
  3042. * @param ADCx ADC instance
  3043. * @retval Ratio This parameter can be one of the following values:
  3044. * @arg @ref LL_ADC_OVS_RATIO_2
  3045. * @arg @ref LL_ADC_OVS_RATIO_4
  3046. * @arg @ref LL_ADC_OVS_RATIO_8
  3047. * @arg @ref LL_ADC_OVS_RATIO_16
  3048. * @arg @ref LL_ADC_OVS_RATIO_32
  3049. * @arg @ref LL_ADC_OVS_RATIO_64
  3050. * @arg @ref LL_ADC_OVS_RATIO_128
  3051. * @arg @ref LL_ADC_OVS_RATIO_256
  3052. */
  3053. __STATIC_INLINE uint32_t LL_ADC_GetOverSamplingRatio(ADC_TypeDef *ADCx)
  3054. {
  3055. return (uint32_t)(READ_BIT(ADCx->CFGR2, ADC_CFGR2_OVSR));
  3056. }
  3057. /**
  3058. * @brief Get ADC oversampling shift
  3059. * @rmtoll CFGR2 OVSS LL_ADC_GetOverSamplingShift
  3060. * @param ADCx ADC instance
  3061. * @retval Shift This parameter can be one of the following values:
  3062. * @arg @ref LL_ADC_OVS_SHIFT_NONE
  3063. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_1
  3064. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_2
  3065. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_3
  3066. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_4
  3067. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_5
  3068. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_6
  3069. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_7
  3070. * @arg @ref LL_ADC_OVS_SHIFT_RIGHT_8
  3071. */
  3072. __STATIC_INLINE uint32_t LL_ADC_GetOverSamplingShift(ADC_TypeDef *ADCx)
  3073. {
  3074. return (uint32_t)(READ_BIT(ADCx->CFGR2, ADC_CFGR2_OVSS));
  3075. }
  3076. /**
  3077. * @}
  3078. */
  3079. /** @defgroup ADC_LL_EF_Operation_ADC_Instance Operation on ADC hierarchical scope: ADC instance
  3080. * @{
  3081. */
  3082. /**
  3083. * @brief Enable ADC instance internal voltage regulator.
  3084. * @note On this STM32 serie, there are three possibilities to enable
  3085. * the voltage regulator:
  3086. * - by enabling it manually
  3087. * using function @ref LL_ADC_EnableInternalRegulator().
  3088. * - by launching a calibration
  3089. * using function @ref LL_ADC_StartCalibration().
  3090. * - by enabling the ADC
  3091. * using function @ref LL_ADC_Enable().
  3092. * @note On this STM32 serie, after ADC internal voltage regulator enable,
  3093. * a delay for ADC internal voltage regulator stabilization
  3094. * is required before performing a ADC calibration or ADC enable.
  3095. * Refer to device datasheet, parameter "tUP_LDO".
  3096. * Refer to literal @ref LL_ADC_DELAY_INTERNAL_REGUL_STAB_US.
  3097. * @note On this STM32 serie, setting of this feature is conditioned to
  3098. * ADC state:
  3099. * ADC must be ADC disabled.
  3100. * @rmtoll CR ADVREGEN LL_ADC_EnableInternalRegulator
  3101. * @param ADCx ADC instance
  3102. * @retval None
  3103. */
  3104. __STATIC_INLINE void LL_ADC_EnableInternalRegulator(ADC_TypeDef *ADCx)
  3105. {
  3106. /* Note: Write register with some additional bits forced to state reset */
  3107. /* instead of modifying only the selected bit for this function, */
  3108. /* to not interfere with bits with HW property "rs". */
  3109. MODIFY_REG(ADCx->CR,
  3110. ADC_CR_BITS_PROPERTY_RS,
  3111. ADC_CR_ADVREGEN);
  3112. }
  3113. /**
  3114. * @brief Disable ADC internal voltage regulator.
  3115. * @note On this STM32 serie, setting of this feature is conditioned to
  3116. * ADC state:
  3117. * ADC must be ADC disabled.
  3118. * @rmtoll CR ADVREGEN LL_ADC_DisableInternalRegulator
  3119. * @param ADCx ADC instance
  3120. * @retval None
  3121. */
  3122. __STATIC_INLINE void LL_ADC_DisableInternalRegulator(ADC_TypeDef *ADCx)
  3123. {
  3124. CLEAR_BIT(ADCx->CR, (ADC_CR_ADVREGEN | ADC_CR_BITS_PROPERTY_RS));
  3125. }
  3126. /**
  3127. * @brief Get the selected ADC instance internal voltage regulator state.
  3128. * @rmtoll CR ADVREGEN LL_ADC_IsInternalRegulatorEnabled
  3129. * @param ADCx ADC instance
  3130. * @retval 0: internal regulator is disabled, 1: internal regulator is enabled.
  3131. */
  3132. __STATIC_INLINE uint32_t LL_ADC_IsInternalRegulatorEnabled(ADC_TypeDef *ADCx)
  3133. {
  3134. return (READ_BIT(ADCx->CR, ADC_CR_ADVREGEN) == (ADC_CR_ADVREGEN));
  3135. }
  3136. /**
  3137. * @brief Enable the selected ADC instance.
  3138. * @note On this STM32 serie, after ADC enable, a delay for
  3139. * ADC internal analog stabilization is required before performing a
  3140. * ADC conversion start.
  3141. * Refer to device datasheet, parameter tSTAB.
  3142. * @note On this STM32 serie, flag LL_ADC_FLAG_ADRDY is raised when the ADC
  3143. * is enabled and when conversion clock is active.
  3144. * (not only core clock: this ADC has a dual clock domain)
  3145. * @note On this STM32 serie, setting of this feature is conditioned to
  3146. * ADC state:
  3147. * ADC must be ADC disabled and ADC internal voltage regulator enabled.
  3148. * @rmtoll CR ADEN LL_ADC_Enable
  3149. * @param ADCx ADC instance
  3150. * @retval None
  3151. */
  3152. __STATIC_INLINE void LL_ADC_Enable(ADC_TypeDef *ADCx)
  3153. {
  3154. /* Note: Write register with some additional bits forced to state reset */
  3155. /* instead of modifying only the selected bit for this function, */
  3156. /* to not interfere with bits with HW property "rs". */
  3157. MODIFY_REG(ADCx->CR,
  3158. ADC_CR_BITS_PROPERTY_RS,
  3159. ADC_CR_ADEN);
  3160. }
  3161. /**
  3162. * @brief Disable the selected ADC instance.
  3163. * @note On this STM32 serie, setting of this feature is conditioned to
  3164. * ADC state:
  3165. * ADC must be not disabled. Must be enabled without conversion on going
  3166. * on group regular.
  3167. * @rmtoll CR ADDIS LL_ADC_Disable
  3168. * @param ADCx ADC instance
  3169. * @retval None
  3170. */
  3171. __STATIC_INLINE void LL_ADC_Disable(ADC_TypeDef *ADCx)
  3172. {
  3173. /* Note: Write register with some additional bits forced to state reset */
  3174. /* instead of modifying only the selected bit for this function, */
  3175. /* to not interfere with bits with HW property "rs". */
  3176. MODIFY_REG(ADCx->CR,
  3177. ADC_CR_BITS_PROPERTY_RS,
  3178. ADC_CR_ADDIS);
  3179. }
  3180. /**
  3181. * @brief Get the selected ADC instance enable state.
  3182. * @note On this STM32 serie, flag LL_ADC_FLAG_ADRDY is raised when the ADC
  3183. * is enabled and when conversion clock is active.
  3184. * (not only core clock: this ADC has a dual clock domain)
  3185. * @rmtoll CR ADEN LL_ADC_IsEnabled
  3186. * @param ADCx ADC instance
  3187. * @retval 0: ADC is disabled, 1: ADC is enabled.
  3188. */
  3189. __STATIC_INLINE uint32_t LL_ADC_IsEnabled(ADC_TypeDef *ADCx)
  3190. {
  3191. return (READ_BIT(ADCx->CR, ADC_CR_ADEN) == (ADC_CR_ADEN));
  3192. }
  3193. /**
  3194. * @brief Get the selected ADC instance disable state.
  3195. * @rmtoll CR ADDIS LL_ADC_IsDisableOngoing
  3196. * @param ADCx ADC instance
  3197. * @retval 0: no ADC disable command on going.
  3198. */
  3199. __STATIC_INLINE uint32_t LL_ADC_IsDisableOngoing(ADC_TypeDef *ADCx)
  3200. {
  3201. return (READ_BIT(ADCx->CR, ADC_CR_ADDIS) == (ADC_CR_ADDIS));
  3202. }
  3203. /**
  3204. * @brief Start ADC calibration in the mode single-ended
  3205. * or differential (for devices with differential mode available).
  3206. * @note On this STM32 serie, a minimum number of ADC clock cycles
  3207. * are required between ADC end of calibration and ADC enable.
  3208. * Refer to literal @ref LL_ADC_DELAY_CALIB_ENABLE_ADC_CYCLES.
  3209. * @note In case of usage of ADC with DMA transfer:
  3210. * On this STM32 serie, ADC DMA transfer request should be disabled
  3211. * during calibration:
  3212. * Calibration factor is available in data register
  3213. * and also transfered by DMA.
  3214. * To not insert ADC calibration factor among ADC conversion data
  3215. * in array variable, DMA transfer must be disabled during
  3216. * calibration.
  3217. * (DMA transfer setting backup and disable before calibration,
  3218. * DMA transfer setting restore after calibration.
  3219. * Refer to functions @ref LL_ADC_REG_GetDMATransfer(),
  3220. * @ref LL_ADC_REG_SetDMATransfer() ).
  3221. * @note On this STM32 serie, setting of this feature is conditioned to
  3222. * ADC state:
  3223. * ADC must be ADC disabled.
  3224. * @rmtoll CR ADCAL LL_ADC_StartCalibration
  3225. * @param ADCx ADC instance
  3226. * @retval None
  3227. */
  3228. __STATIC_INLINE void LL_ADC_StartCalibration(ADC_TypeDef *ADCx)
  3229. {
  3230. /* Note: Write register with some additional bits forced to state reset */
  3231. /* instead of modifying only the selected bit for this function, */
  3232. /* to not interfere with bits with HW property "rs". */
  3233. MODIFY_REG(ADCx->CR,
  3234. ADC_CR_BITS_PROPERTY_RS,
  3235. ADC_CR_ADCAL);
  3236. }
  3237. /**
  3238. * @brief Get ADC calibration state.
  3239. * @rmtoll CR ADCAL LL_ADC_IsCalibrationOnGoing
  3240. * @param ADCx ADC instance
  3241. * @retval 0: calibration complete, 1: calibration in progress.
  3242. */
  3243. __STATIC_INLINE uint32_t LL_ADC_IsCalibrationOnGoing(ADC_TypeDef *ADCx)
  3244. {
  3245. return (READ_BIT(ADCx->CR, ADC_CR_ADCAL) == (ADC_CR_ADCAL));
  3246. }
  3247. /**
  3248. * @}
  3249. */
  3250. /** @defgroup ADC_LL_EF_Operation_ADC_Group_Regular Operation on ADC hierarchical scope: group regular
  3251. * @{
  3252. */
  3253. /**
  3254. * @brief Start ADC group regular conversion.
  3255. * @note On this STM32 serie, this function is relevant for both
  3256. * internal trigger (SW start) and external trigger:
  3257. * - If ADC trigger has been set to software start, ADC conversion
  3258. * starts immediately.
  3259. * - If ADC trigger has been set to external trigger, ADC conversion
  3260. * will start at next trigger event (on the selected trigger edge)
  3261. * following the ADC start conversion command.
  3262. * @note On this STM32 serie, setting of this feature is conditioned to
  3263. * ADC state:
  3264. * ADC must be enabled without conversion on going on group regular,
  3265. * without conversion stop command on going on group regular,
  3266. * without ADC disable command on going.
  3267. * @rmtoll CR ADSTART LL_ADC_REG_StartConversion
  3268. * @param ADCx ADC instance
  3269. * @retval None
  3270. */
  3271. __STATIC_INLINE void LL_ADC_REG_StartConversion(ADC_TypeDef *ADCx)
  3272. {
  3273. /* Note: Write register with some additional bits forced to state reset */
  3274. /* instead of modifying only the selected bit for this function, */
  3275. /* to not interfere with bits with HW property "rs". */
  3276. MODIFY_REG(ADCx->CR,
  3277. ADC_CR_BITS_PROPERTY_RS,
  3278. ADC_CR_ADSTART);
  3279. }
  3280. /**
  3281. * @brief Stop ADC group regular conversion.
  3282. * @note On this STM32 serie, setting of this feature is conditioned to
  3283. * ADC state:
  3284. * ADC must be enabled with conversion on going on group regular,
  3285. * without ADC disable command on going.
  3286. * @rmtoll CR ADSTP LL_ADC_REG_StopConversion
  3287. * @param ADCx ADC instance
  3288. * @retval None
  3289. */
  3290. __STATIC_INLINE void LL_ADC_REG_StopConversion(ADC_TypeDef *ADCx)
  3291. {
  3292. /* Note: Write register with some additional bits forced to state reset */
  3293. /* instead of modifying only the selected bit for this function, */
  3294. /* to not interfere with bits with HW property "rs". */
  3295. MODIFY_REG(ADCx->CR,
  3296. ADC_CR_BITS_PROPERTY_RS,
  3297. ADC_CR_ADSTP);
  3298. }
  3299. /**
  3300. * @brief Get ADC group regular conversion state.
  3301. * @rmtoll CR ADSTART LL_ADC_REG_IsConversionOngoing
  3302. * @param ADCx ADC instance
  3303. * @retval 0: no conversion is on going on ADC group regular.
  3304. */
  3305. __STATIC_INLINE uint32_t LL_ADC_REG_IsConversionOngoing(ADC_TypeDef *ADCx)
  3306. {
  3307. return (READ_BIT(ADCx->CR, ADC_CR_ADSTART) == (ADC_CR_ADSTART));
  3308. }
  3309. /**
  3310. * @brief Get ADC group regular command of conversion stop state
  3311. * @rmtoll CR ADSTP LL_ADC_REG_IsStopConversionOngoing
  3312. * @param ADCx ADC instance
  3313. * @retval 0: no command of conversion stop is on going on ADC group regular.
  3314. */
  3315. __STATIC_INLINE uint32_t LL_ADC_REG_IsStopConversionOngoing(ADC_TypeDef *ADCx)
  3316. {
  3317. return (READ_BIT(ADCx->CR, ADC_CR_ADSTP) == (ADC_CR_ADSTP));
  3318. }
  3319. /**
  3320. * @brief Get ADC group regular conversion data, range fit for
  3321. * all ADC configurations: all ADC resolutions and
  3322. * all oversampling increased data width (for devices
  3323. * with feature oversampling).
  3324. * @rmtoll DR DATA LL_ADC_REG_ReadConversionData32
  3325. * @param ADCx ADC instance
  3326. * @retval Value between Min_Data=0x00000000 and Max_Data=0xFFFFFFFF
  3327. */
  3328. __STATIC_INLINE uint32_t LL_ADC_REG_ReadConversionData32(ADC_TypeDef *ADCx)
  3329. {
  3330. return (uint32_t)(READ_BIT(ADCx->DR, ADC_DR_DATA));
  3331. }
  3332. /**
  3333. * @brief Get ADC group regular conversion data, range fit for
  3334. * ADC resolution 12 bits.
  3335. * @note For devices with feature oversampling: Oversampling
  3336. * can increase data width, function for extended range
  3337. * may be needed: @ref LL_ADC_REG_ReadConversionData32.
  3338. * @rmtoll DR DATA LL_ADC_REG_ReadConversionData12
  3339. * @param ADCx ADC instance
  3340. * @retval Value between Min_Data=0x000 and Max_Data=0xFFF
  3341. */
  3342. __STATIC_INLINE uint16_t LL_ADC_REG_ReadConversionData12(ADC_TypeDef *ADCx)
  3343. {
  3344. return (uint16_t)(READ_BIT(ADCx->DR, ADC_DR_DATA));
  3345. }
  3346. /**
  3347. * @brief Get ADC group regular conversion data, range fit for
  3348. * ADC resolution 10 bits.
  3349. * @note For devices with feature oversampling: Oversampling
  3350. * can increase data width, function for extended range
  3351. * may be needed: @ref LL_ADC_REG_ReadConversionData32.
  3352. * @rmtoll DR DATA LL_ADC_REG_ReadConversionData10
  3353. * @param ADCx ADC instance
  3354. * @retval Value between Min_Data=0x000 and Max_Data=0x3FF
  3355. */
  3356. __STATIC_INLINE uint16_t LL_ADC_REG_ReadConversionData10(ADC_TypeDef *ADCx)
  3357. {
  3358. return (uint16_t)(READ_BIT(ADCx->DR, ADC_DR_DATA));
  3359. }
  3360. /**
  3361. * @brief Get ADC group regular conversion data, range fit for
  3362. * ADC resolution 8 bits.
  3363. * @note For devices with feature oversampling: Oversampling
  3364. * can increase data width, function for extended range
  3365. * may be needed: @ref LL_ADC_REG_ReadConversionData32.
  3366. * @rmtoll DR DATA LL_ADC_REG_ReadConversionData8
  3367. * @param ADCx ADC instance
  3368. * @retval Value between Min_Data=0x00 and Max_Data=0xFF
  3369. */
  3370. __STATIC_INLINE uint8_t LL_ADC_REG_ReadConversionData8(ADC_TypeDef *ADCx)
  3371. {
  3372. return (uint8_t)(READ_BIT(ADCx->DR, ADC_DR_DATA));
  3373. }
  3374. /**
  3375. * @brief Get ADC group regular conversion data, range fit for
  3376. * ADC resolution 6 bits.
  3377. * @note For devices with feature oversampling: Oversampling
  3378. * can increase data width, function for extended range
  3379. * may be needed: @ref LL_ADC_REG_ReadConversionData32.
  3380. * @rmtoll DR DATA LL_ADC_REG_ReadConversionData6
  3381. * @param ADCx ADC instance
  3382. * @retval Value between Min_Data=0x00 and Max_Data=0x3F
  3383. */
  3384. __STATIC_INLINE uint8_t LL_ADC_REG_ReadConversionData6(ADC_TypeDef *ADCx)
  3385. {
  3386. return (uint8_t)(READ_BIT(ADCx->DR, ADC_DR_DATA));
  3387. }
  3388. /**
  3389. * @}
  3390. */
  3391. /** @defgroup ADC_LL_EF_FLAG_Management ADC flag management
  3392. * @{
  3393. */
  3394. /**
  3395. * @brief Get flag ADC ready.
  3396. * @note On this STM32 serie, flag LL_ADC_FLAG_ADRDY is raised when the ADC
  3397. * is enabled and when conversion clock is active.
  3398. * (not only core clock: this ADC has a dual clock domain)
  3399. * @rmtoll ISR ADRDY LL_ADC_IsActiveFlag_ADRDY
  3400. * @param ADCx ADC instance
  3401. * @retval State of bit (1 or 0).
  3402. */
  3403. __STATIC_INLINE uint32_t LL_ADC_IsActiveFlag_ADRDY(ADC_TypeDef *ADCx)
  3404. {
  3405. return (READ_BIT(ADCx->ISR, LL_ADC_FLAG_ADRDY) == (LL_ADC_FLAG_ADRDY));
  3406. }
  3407. /**
  3408. * @brief Get flag ADC group regular end of unitary conversion.
  3409. * @rmtoll ISR EOC LL_ADC_IsActiveFlag_EOC
  3410. * @param ADCx ADC instance
  3411. * @retval State of bit (1 or 0).
  3412. */
  3413. __STATIC_INLINE uint32_t LL_ADC_IsActiveFlag_EOC(ADC_TypeDef *ADCx)
  3414. {
  3415. return (READ_BIT(ADCx->ISR, ADC_ISR_EOC) == (ADC_ISR_EOC));
  3416. }
  3417. /**
  3418. * @brief Get flag ADC group regular end of sequence conversions.
  3419. * @rmtoll ISR EOSEQ LL_ADC_IsActiveFlag_EOS
  3420. * @param ADCx ADC instance
  3421. * @retval State of bit (1 or 0).
  3422. */
  3423. __STATIC_INLINE uint32_t LL_ADC_IsActiveFlag_EOS(ADC_TypeDef *ADCx)
  3424. {
  3425. return (READ_BIT(ADCx->ISR, LL_ADC_FLAG_EOS) == (LL_ADC_FLAG_EOS));
  3426. }
  3427. /**
  3428. * @brief Get flag ADC group regular overrun.
  3429. * @rmtoll ISR OVR LL_ADC_IsActiveFlag_OVR
  3430. * @param ADCx ADC instance
  3431. * @retval State of bit (1 or 0).
  3432. */
  3433. __STATIC_INLINE uint32_t LL_ADC_IsActiveFlag_OVR(ADC_TypeDef *ADCx)
  3434. {
  3435. return (READ_BIT(ADCx->ISR, LL_ADC_FLAG_OVR) == (LL_ADC_FLAG_OVR));
  3436. }
  3437. /**
  3438. * @brief Get flag ADC group regular end of sampling phase.
  3439. * @rmtoll ISR EOSMP LL_ADC_IsActiveFlag_EOSMP
  3440. * @param ADCx ADC instance
  3441. * @retval State of bit (1 or 0).
  3442. */
  3443. __STATIC_INLINE uint32_t LL_ADC_IsActiveFlag_EOSMP(ADC_TypeDef *ADCx)
  3444. {
  3445. return (READ_BIT(ADCx->ISR, LL_ADC_FLAG_EOSMP) == (LL_ADC_FLAG_EOSMP));
  3446. }
  3447. /**
  3448. * @brief Get flag ADC analog watchdog 1 flag
  3449. * @rmtoll ISR AWD LL_ADC_IsActiveFlag_AWD1
  3450. * @param ADCx ADC instance
  3451. * @retval State of bit (1 or 0).
  3452. */
  3453. __STATIC_INLINE uint32_t LL_ADC_IsActiveFlag_AWD1(ADC_TypeDef *ADCx)
  3454. {
  3455. return (READ_BIT(ADCx->ISR, LL_ADC_FLAG_AWD1) == (LL_ADC_FLAG_AWD1));
  3456. }
  3457. /**
  3458. * @brief Get flag ADC end of calibration.
  3459. * @rmtoll ISR EOCAL LL_ADC_IsActiveFlag_EOCAL
  3460. * @param ADCx ADC instance
  3461. * @retval State of bit (1 or 0).
  3462. */
  3463. __STATIC_INLINE uint32_t LL_ADC_IsActiveFlag_EOCAL(ADC_TypeDef *ADCx)
  3464. {
  3465. return (READ_BIT(ADCx->ISR, LL_ADC_FLAG_EOCAL) == (LL_ADC_FLAG_EOCAL));
  3466. }
  3467. /**
  3468. * @brief Clear flag ADC ready.
  3469. * @note On this STM32 serie, flag LL_ADC_FLAG_ADRDY is raised when the ADC
  3470. * is enabled and when conversion clock is active.
  3471. * (not only core clock: this ADC has a dual clock domain)
  3472. * @rmtoll ISR ADRDY LL_ADC_ClearFlag_ADRDY
  3473. * @param ADCx ADC instance
  3474. * @retval None
  3475. */
  3476. __STATIC_INLINE void LL_ADC_ClearFlag_ADRDY(ADC_TypeDef *ADCx)
  3477. {
  3478. WRITE_REG(ADCx->ISR, LL_ADC_FLAG_ADRDY);
  3479. }
  3480. /**
  3481. * @brief Clear flag ADC group regular end of unitary conversion.
  3482. * @rmtoll ISR EOC LL_ADC_ClearFlag_EOC
  3483. * @param ADCx ADC instance
  3484. * @retval None
  3485. */
  3486. __STATIC_INLINE void LL_ADC_ClearFlag_EOC(ADC_TypeDef *ADCx)
  3487. {
  3488. WRITE_REG(ADCx->ISR, LL_ADC_FLAG_EOC);
  3489. }
  3490. /**
  3491. * @brief Clear flag ADC group regular end of sequence conversions.
  3492. * @rmtoll ISR EOSEQ LL_ADC_ClearFlag_EOS
  3493. * @param ADCx ADC instance
  3494. * @retval None
  3495. */
  3496. __STATIC_INLINE void LL_ADC_ClearFlag_EOS(ADC_TypeDef *ADCx)
  3497. {
  3498. WRITE_REG(ADCx->ISR, LL_ADC_FLAG_EOS);
  3499. }
  3500. /**
  3501. * @brief Clear flag ADC group regular overrun.
  3502. * @rmtoll ISR OVR LL_ADC_ClearFlag_OVR
  3503. * @param ADCx ADC instance
  3504. * @retval None
  3505. */
  3506. __STATIC_INLINE void LL_ADC_ClearFlag_OVR(ADC_TypeDef *ADCx)
  3507. {
  3508. WRITE_REG(ADCx->ISR, LL_ADC_FLAG_OVR);
  3509. }
  3510. /**
  3511. * @brief Clear flag ADC group regular end of sampling phase.
  3512. * @rmtoll ISR EOSMP LL_ADC_ClearFlag_EOSMP
  3513. * @param ADCx ADC instance
  3514. * @retval None
  3515. */
  3516. __STATIC_INLINE void LL_ADC_ClearFlag_EOSMP(ADC_TypeDef *ADCx)
  3517. {
  3518. WRITE_REG(ADCx->ISR, LL_ADC_FLAG_EOSMP);
  3519. }
  3520. /**
  3521. * @brief Clear flag ADC analog watchdog 1.
  3522. * @rmtoll ISR AWD LL_ADC_ClearFlag_AWD1
  3523. * @param ADCx ADC instance
  3524. * @retval None
  3525. */
  3526. __STATIC_INLINE void LL_ADC_ClearFlag_AWD1(ADC_TypeDef *ADCx)
  3527. {
  3528. WRITE_REG(ADCx->ISR, LL_ADC_FLAG_AWD1);
  3529. }
  3530. /**
  3531. * @brief Clear flag ADC end of calibration.
  3532. * @rmtoll ISR EOCAL LL_ADC_ClearFlag_EOCAL
  3533. * @param ADCx ADC instance
  3534. * @retval None
  3535. */
  3536. __STATIC_INLINE void LL_ADC_ClearFlag_EOCAL(ADC_TypeDef *ADCx)
  3537. {
  3538. WRITE_REG(ADCx->ISR, LL_ADC_FLAG_EOCAL);
  3539. }
  3540. /**
  3541. * @}
  3542. */
  3543. /** @defgroup ADC_LL_EF_IT_Management ADC IT management
  3544. * @{
  3545. */
  3546. /**
  3547. * @brief Enable ADC ready.
  3548. * @rmtoll IER ADRDYIE LL_ADC_EnableIT_ADRDY
  3549. * @param ADCx ADC instance
  3550. * @retval None
  3551. */
  3552. __STATIC_INLINE void LL_ADC_EnableIT_ADRDY(ADC_TypeDef *ADCx)
  3553. {
  3554. SET_BIT(ADCx->IER, LL_ADC_IT_ADRDY);
  3555. }
  3556. /**
  3557. * @brief Enable interruption ADC group regular end of unitary conversion.
  3558. * @rmtoll IER EOCIE LL_ADC_EnableIT_EOC
  3559. * @param ADCx ADC instance
  3560. * @retval None
  3561. */
  3562. __STATIC_INLINE void LL_ADC_EnableIT_EOC(ADC_TypeDef *ADCx)
  3563. {
  3564. SET_BIT(ADCx->IER, LL_ADC_IT_EOC);
  3565. }
  3566. /**
  3567. * @brief Enable interruption ADC group regular end of sequence conversions.
  3568. * @rmtoll IER EOSEQIE LL_ADC_EnableIT_EOS
  3569. * @param ADCx ADC instance
  3570. * @retval None
  3571. */
  3572. __STATIC_INLINE void LL_ADC_EnableIT_EOS(ADC_TypeDef *ADCx)
  3573. {
  3574. SET_BIT(ADCx->IER, LL_ADC_IT_EOS);
  3575. }
  3576. /**
  3577. * @brief Enable ADC group regular interruption overrun.
  3578. * @rmtoll IER OVRIE LL_ADC_EnableIT_OVR
  3579. * @param ADCx ADC instance
  3580. * @retval None
  3581. */
  3582. __STATIC_INLINE void LL_ADC_EnableIT_OVR(ADC_TypeDef *ADCx)
  3583. {
  3584. SET_BIT(ADCx->IER, LL_ADC_IT_OVR);
  3585. }
  3586. /**
  3587. * @brief Enable interruption ADC group regular end of sampling.
  3588. * @rmtoll IER EOSMPIE LL_ADC_EnableIT_EOSMP
  3589. * @param ADCx ADC instance
  3590. * @retval None
  3591. */
  3592. __STATIC_INLINE void LL_ADC_EnableIT_EOSMP(ADC_TypeDef *ADCx)
  3593. {
  3594. SET_BIT(ADCx->IER, LL_ADC_IT_EOSMP);
  3595. }
  3596. /**
  3597. * @brief Enable interruption ADC analog watchdog 1.
  3598. * @rmtoll IER AWDIE LL_ADC_EnableIT_AWD1
  3599. * @param ADCx ADC instance
  3600. * @retval None
  3601. */
  3602. __STATIC_INLINE void LL_ADC_EnableIT_AWD1(ADC_TypeDef *ADCx)
  3603. {
  3604. SET_BIT(ADCx->IER, LL_ADC_IT_AWD1);
  3605. }
  3606. /**
  3607. * @brief Enable interruption ADC end of calibration.
  3608. * @rmtoll IER EOCALIE LL_ADC_EnableIT_EOCAL
  3609. * @param ADCx ADC instance
  3610. * @retval None
  3611. */
  3612. __STATIC_INLINE void LL_ADC_EnableIT_EOCAL(ADC_TypeDef *ADCx)
  3613. {
  3614. SET_BIT(ADCx->IER, LL_ADC_IT_EOCAL);
  3615. }
  3616. /**
  3617. * @brief Disable interruption ADC ready.
  3618. * @rmtoll IER ADRDYIE LL_ADC_DisableIT_ADRDY
  3619. * @param ADCx ADC instance
  3620. * @retval None
  3621. */
  3622. __STATIC_INLINE void LL_ADC_DisableIT_ADRDY(ADC_TypeDef *ADCx)
  3623. {
  3624. CLEAR_BIT(ADCx->IER, LL_ADC_IT_ADRDY);
  3625. }
  3626. /**
  3627. * @brief Disable interruption ADC group regular end of unitary conversion.
  3628. * @rmtoll IER EOCIE LL_ADC_DisableIT_EOC
  3629. * @param ADCx ADC instance
  3630. * @retval None
  3631. */
  3632. __STATIC_INLINE void LL_ADC_DisableIT_EOC(ADC_TypeDef *ADCx)
  3633. {
  3634. CLEAR_BIT(ADCx->IER, LL_ADC_IT_EOC);
  3635. }
  3636. /**
  3637. * @brief Disable interruption ADC group regular end of sequence conversions.
  3638. * @rmtoll IER EOSEQIE LL_ADC_DisableIT_EOS
  3639. * @param ADCx ADC instance
  3640. * @retval None
  3641. */
  3642. __STATIC_INLINE void LL_ADC_DisableIT_EOS(ADC_TypeDef *ADCx)
  3643. {
  3644. CLEAR_BIT(ADCx->IER, LL_ADC_IT_EOS);
  3645. }
  3646. /**
  3647. * @brief Disable interruption ADC group regular overrun.
  3648. * @rmtoll IER OVRIE LL_ADC_DisableIT_OVR
  3649. * @param ADCx ADC instance
  3650. * @retval None
  3651. */
  3652. __STATIC_INLINE void LL_ADC_DisableIT_OVR(ADC_TypeDef *ADCx)
  3653. {
  3654. CLEAR_BIT(ADCx->IER, LL_ADC_IT_OVR);
  3655. }
  3656. /**
  3657. * @brief Disable interruption ADC group regular end of sampling.
  3658. * @rmtoll IER EOSMPIE LL_ADC_DisableIT_EOSMP
  3659. * @param ADCx ADC instance
  3660. * @retval None
  3661. */
  3662. __STATIC_INLINE void LL_ADC_DisableIT_EOSMP(ADC_TypeDef *ADCx)
  3663. {
  3664. CLEAR_BIT(ADCx->IER, LL_ADC_IT_EOSMP);
  3665. }
  3666. /**
  3667. * @brief Disable interruption ADC analog watchdog 1.
  3668. * @rmtoll IER AWDIE LL_ADC_DisableIT_AWD1
  3669. * @param ADCx ADC instance
  3670. * @retval None
  3671. */
  3672. __STATIC_INLINE void LL_ADC_DisableIT_AWD1(ADC_TypeDef *ADCx)
  3673. {
  3674. CLEAR_BIT(ADCx->IER, LL_ADC_IT_AWD1);
  3675. }
  3676. /**
  3677. * @brief Disable interruption ADC end of calibration.
  3678. * @rmtoll IER EOCALIE LL_ADC_DisableIT_EOCAL
  3679. * @param ADCx ADC instance
  3680. * @retval None
  3681. */
  3682. __STATIC_INLINE void LL_ADC_DisableIT_EOCAL(ADC_TypeDef *ADCx)
  3683. {
  3684. CLEAR_BIT(ADCx->IER, LL_ADC_IT_EOCAL);
  3685. }
  3686. /**
  3687. * @brief Get state of interruption ADC ready
  3688. * (0: interrupt disabled, 1: interrupt enabled).
  3689. * @rmtoll IER ADRDYIE LL_ADC_IsEnabledIT_ADRDY
  3690. * @param ADCx ADC instance
  3691. * @retval State of bit (1 or 0).
  3692. */
  3693. __STATIC_INLINE uint32_t LL_ADC_IsEnabledIT_ADRDY(ADC_TypeDef *ADCx)
  3694. {
  3695. return (READ_BIT(ADCx->IER, LL_ADC_IT_ADRDY) == (LL_ADC_IT_ADRDY));
  3696. }
  3697. /**
  3698. * @brief Get state of interruption ADC group regular end of unitary conversion
  3699. * (0: interrupt disabled, 1: interrupt enabled).
  3700. * @rmtoll IER EOCIE LL_ADC_IsEnabledIT_EOC
  3701. * @param ADCx ADC instance
  3702. * @retval State of bit (1 or 0).
  3703. */
  3704. __STATIC_INLINE uint32_t LL_ADC_IsEnabledIT_EOC(ADC_TypeDef *ADCx)
  3705. {
  3706. return (READ_BIT(ADCx->IER, LL_ADC_IT_EOC) == (LL_ADC_IT_EOC));
  3707. }
  3708. /**
  3709. * @brief Get state of interruption ADC group regular end of sequence conversions
  3710. * (0: interrupt disabled, 1: interrupt enabled).
  3711. * @rmtoll IER EOSEQIE LL_ADC_IsEnabledIT_EOS
  3712. * @param ADCx ADC instance
  3713. * @retval State of bit (1 or 0).
  3714. */
  3715. __STATIC_INLINE uint32_t LL_ADC_IsEnabledIT_EOS(ADC_TypeDef *ADCx)
  3716. {
  3717. return (READ_BIT(ADCx->IER, LL_ADC_IT_EOS) == (LL_ADC_IT_EOS));
  3718. }
  3719. /**
  3720. * @brief Get state of interruption ADC group regular overrun
  3721. * (0: interrupt disabled, 1: interrupt enabled).
  3722. * @rmtoll IER OVRIE LL_ADC_IsEnabledIT_OVR
  3723. * @param ADCx ADC instance
  3724. * @retval State of bit (1 or 0).
  3725. */
  3726. __STATIC_INLINE uint32_t LL_ADC_IsEnabledIT_OVR(ADC_TypeDef *ADCx)
  3727. {
  3728. return (READ_BIT(ADCx->IER, LL_ADC_IT_OVR) == (LL_ADC_IT_OVR));
  3729. }
  3730. /**
  3731. * @brief Get state of interruption ADC group regular end of sampling
  3732. * (0: interrupt disabled, 1: interrupt enabled).
  3733. * @rmtoll IER EOSMPIE LL_ADC_IsEnabledIT_EOSMP
  3734. * @param ADCx ADC instance
  3735. * @retval State of bit (1 or 0).
  3736. */
  3737. __STATIC_INLINE uint32_t LL_ADC_IsEnabledIT_EOSMP(ADC_TypeDef *ADCx)
  3738. {
  3739. return (READ_BIT(ADCx->IER, LL_ADC_IT_EOSMP) == (LL_ADC_IT_EOSMP));
  3740. }
  3741. /**
  3742. * @brief Get state of interruption ADC analog watchdog 1
  3743. * (0: interrupt disabled, 1: interrupt enabled).
  3744. * @rmtoll IER AWDIE LL_ADC_IsEnabledIT_AWD1
  3745. * @param ADCx ADC instance
  3746. * @retval State of bit (1 or 0).
  3747. */
  3748. __STATIC_INLINE uint32_t LL_ADC_IsEnabledIT_AWD1(ADC_TypeDef *ADCx)
  3749. {
  3750. return (READ_BIT(ADCx->IER, LL_ADC_IT_AWD1) == (LL_ADC_IT_AWD1));
  3751. }
  3752. /**
  3753. * @brief Get state of interruption ADC end of calibration
  3754. * (0: interrupt disabled, 1: interrupt enabled).
  3755. * @rmtoll IER EOCALIE LL_ADC_IsEnabledIT_EOCAL
  3756. * @param ADCx ADC instance
  3757. * @retval State of bit (1 or 0).
  3758. */
  3759. __STATIC_INLINE uint32_t LL_ADC_IsEnabledIT_EOCAL(ADC_TypeDef *ADCx)
  3760. {
  3761. return (READ_BIT(ADCx->IER, LL_ADC_IT_EOCAL) == (LL_ADC_IT_EOCAL));
  3762. }
  3763. /**
  3764. * @}
  3765. */
  3766. #if defined(USE_FULL_LL_DRIVER)
  3767. /** @defgroup ADC_LL_EF_Init Initialization and de-initialization functions
  3768. * @{
  3769. */
  3770. /* Initialization of some features of ADC common parameters and multimode */
  3771. ErrorStatus LL_ADC_CommonDeInit(ADC_Common_TypeDef *ADCxy_COMMON);
  3772. ErrorStatus LL_ADC_CommonInit(ADC_Common_TypeDef *ADCxy_COMMON, LL_ADC_CommonInitTypeDef *ADC_CommonInitStruct);
  3773. void LL_ADC_CommonStructInit(LL_ADC_CommonInitTypeDef *ADC_CommonInitStruct);
  3774. /* De-initialization of ADC instance */
  3775. ErrorStatus LL_ADC_DeInit(ADC_TypeDef *ADCx);
  3776. /* Initialization of some features of ADC instance */
  3777. ErrorStatus LL_ADC_Init(ADC_TypeDef *ADCx, LL_ADC_InitTypeDef *ADC_InitStruct);
  3778. void LL_ADC_StructInit(LL_ADC_InitTypeDef *ADC_InitStruct);
  3779. /* Initialization of some features of ADC instance and ADC group regular */
  3780. ErrorStatus LL_ADC_REG_Init(ADC_TypeDef *ADCx, LL_ADC_REG_InitTypeDef *ADC_REG_InitStruct);
  3781. void LL_ADC_REG_StructInit(LL_ADC_REG_InitTypeDef *ADC_REG_InitStruct);
  3782. /**
  3783. * @}
  3784. */
  3785. #endif /* USE_FULL_LL_DRIVER */
  3786. /**
  3787. * @}
  3788. */
  3789. /**
  3790. * @}
  3791. */
  3792. #endif /* ADC1 */
  3793. /**
  3794. * @}
  3795. */
  3796. #ifdef __cplusplus
  3797. }
  3798. #endif
  3799. #endif /* __STM32L0xx_LL_ADC_H */
  3800. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/