Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:23:09

0001 /**
0002   ******************************************************************************
0003   * @file    stm32h7xx_ll_adc.c
0004   * @author  MCD Application Team
0005   * @brief   ADC LL module driver
0006   ******************************************************************************
0007   * @attention
0008   *
0009   * Copyright (c) 2017 STMicroelectronics.
0010   * All rights reserved.
0011   *
0012   * This software is licensed under terms that can be found in the LICENSE file
0013   * in the root directory of this software component.
0014   * If no LICENSE file comes with this software, it is provided AS-IS.
0015   *
0016   ******************************************************************************
0017   */
0018 #if defined(USE_FULL_LL_DRIVER) || defined(__rtems__)
0019 
0020 /* Includes ------------------------------------------------------------------*/
0021 #include "stm32h7xx_ll_adc.h"
0022 #include "stm32h7xx_ll_bus.h"
0023 
0024 #ifdef  USE_FULL_ASSERT
0025 #include "stm32_assert.h"
0026 #else
0027 #define assert_param(expr) ((void)0U)
0028 #endif
0029 
0030 /** @addtogroup STM32H7xx_LL_Driver
0031   * @{
0032   */
0033 
0034 #if defined (ADC1) || defined (ADC2) || defined (ADC3)
0035 
0036 /** @addtogroup ADC_LL ADC
0037   * @{
0038   */
0039 
0040 /* Private types -------------------------------------------------------------*/
0041 /* Private variables ---------------------------------------------------------*/
0042 /* Private constants ---------------------------------------------------------*/
0043 /** @addtogroup ADC_LL_Private_Constants
0044   * @{
0045   */
0046 
0047 /* Definitions of ADC hardware constraints delays */
0048 /* Note: Only ADC peripheral HW delays are defined in ADC LL driver driver,   */
0049 /*       not timeout values:                                                  */
0050 /*       Timeout values for ADC operations are dependent to device clock      */
0051 /*       configuration (system clock versus ADC clock),                       */
0052 /*       and therefore must be defined in user application.                   */
0053 /*       Refer to @ref ADC_LL_EC_HW_DELAYS for description of ADC timeout     */
0054 /*       values definition.                                                   */
0055 /* Note: ADC timeout values are defined here in CPU cycles to be independent  */
0056 /*       of device clock setting.                                             */
0057 /*       In user application, ADC timeout values should be defined with       */
0058 /*       temporal values, in function of device clock settings.               */
0059 /*       Highest ratio CPU clock frequency vs ADC clock frequency:            */
0060 /*        - ADC clock from synchronous clock with AHB prescaler 512,          */
0061 /*          APB prescaler 16, ADC prescaler 4.                                */
0062 /*        - ADC clock from asynchronous clock (PLL) with prescaler 1,         */
0063 /*          with highest ratio CPU clock frequency vs HSI clock frequency     */
0064 /* Unit: CPU cycles.                                                          */
0065 #define ADC_CLOCK_RATIO_VS_CPU_HIGHEST          (512UL * 16UL * 4UL)
0066 #define ADC_TIMEOUT_DISABLE_CPU_CYCLES          (ADC_CLOCK_RATIO_VS_CPU_HIGHEST * 1UL)
0067 #define ADC_TIMEOUT_STOP_CONVERSION_CPU_CYCLES  (ADC_CLOCK_RATIO_VS_CPU_HIGHEST * 1UL)
0068 
0069 /**
0070   * @}
0071   */
0072 
0073 /* Private macros ------------------------------------------------------------*/
0074 
0075 /** @addtogroup ADC_LL_Private_Macros
0076   * @{
0077   */
0078 
0079 /* Check of parameters for configuration of ADC hierarchical scope:           */
0080 /* common to several ADC instances.                                           */
0081 #define IS_LL_ADC_COMMON_CLOCK(__CLOCK__)                                      \
0082   (   ((__CLOCK__) == LL_ADC_CLOCK_SYNC_PCLK_DIV1)                             \
0083    || ((__CLOCK__) == LL_ADC_CLOCK_SYNC_PCLK_DIV2)                             \
0084    || ((__CLOCK__) == LL_ADC_CLOCK_SYNC_PCLK_DIV4)                             \
0085    || ((__CLOCK__) == LL_ADC_CLOCK_ASYNC_DIV1)                                 \
0086    || ((__CLOCK__) == LL_ADC_CLOCK_ASYNC_DIV2)                                 \
0087    || ((__CLOCK__) == LL_ADC_CLOCK_ASYNC_DIV4)                                 \
0088    || ((__CLOCK__) == LL_ADC_CLOCK_ASYNC_DIV6)                                 \
0089    || ((__CLOCK__) == LL_ADC_CLOCK_ASYNC_DIV8)                                 \
0090    || ((__CLOCK__) == LL_ADC_CLOCK_ASYNC_DIV10)                                \
0091    || ((__CLOCK__) == LL_ADC_CLOCK_ASYNC_DIV12)                                \
0092    || ((__CLOCK__) == LL_ADC_CLOCK_ASYNC_DIV16)                                \
0093    || ((__CLOCK__) == LL_ADC_CLOCK_ASYNC_DIV32)                                \
0094    || ((__CLOCK__) == LL_ADC_CLOCK_ASYNC_DIV64)                                \
0095    || ((__CLOCK__) == LL_ADC_CLOCK_ASYNC_DIV128)                               \
0096    || ((__CLOCK__) == LL_ADC_CLOCK_ASYNC_DIV256)                               \
0097   )
0098 
0099 /* Check of parameters for configuration of ADC hierarchical scope:           */
0100 /* ADC instance.                                                              */
0101 #define IS_LL_ADC_RESOLUTION(__RESOLUTION__)                                   \
0102   (   ((__RESOLUTION__) == LL_ADC_RESOLUTION_16B)                              \
0103    || ((__RESOLUTION__) == LL_ADC_RESOLUTION_14B)                              \
0104    || ((__RESOLUTION__) == LL_ADC_RESOLUTION_12B)                              \
0105    || ((__RESOLUTION__) == LL_ADC_RESOLUTION_10B)                              \
0106    || ((__RESOLUTION__) == LL_ADC_RESOLUTION_8B)                               \
0107   )
0108 
0109 #define IS_LL_ADC_LEFT_BIT_SHIFT(__LEFT_BIT_SHIFT__)                           \
0110   (   ((__LEFT_BIT_SHIFT__) == LL_ADC_LEFT_BIT_SHIFT_NONE)                     \
0111    || ((__LEFT_BIT_SHIFT__) == LL_ADC_LEFT_BIT_SHIFT_1)                        \
0112    || ((__LEFT_BIT_SHIFT__) == LL_ADC_LEFT_BIT_SHIFT_2)                        \
0113    || ((__LEFT_BIT_SHIFT__) == LL_ADC_LEFT_BIT_SHIFT_3)                        \
0114    || ((__LEFT_BIT_SHIFT__) == LL_ADC_LEFT_BIT_SHIFT_4)                        \
0115    || ((__LEFT_BIT_SHIFT__) == LL_ADC_LEFT_BIT_SHIFT_5)                        \
0116    || ((__LEFT_BIT_SHIFT__) == LL_ADC_LEFT_BIT_SHIFT_6)                        \
0117    || ((__LEFT_BIT_SHIFT__) == LL_ADC_LEFT_BIT_SHIFT_7)                        \
0118    || ((__LEFT_BIT_SHIFT__) == LL_ADC_LEFT_BIT_SHIFT_8)                        \
0119    || ((__LEFT_BIT_SHIFT__) == LL_ADC_LEFT_BIT_SHIFT_9)                        \
0120    || ((__LEFT_BIT_SHIFT__) == LL_ADC_LEFT_BIT_SHIFT_10)                       \
0121    || ((__LEFT_BIT_SHIFT__) == LL_ADC_LEFT_BIT_SHIFT_11)                       \
0122    || ((__LEFT_BIT_SHIFT__) == LL_ADC_LEFT_BIT_SHIFT_12)                       \
0123    || ((__LEFT_BIT_SHIFT__) == LL_ADC_LEFT_BIT_SHIFT_13)                       \
0124    || ((__LEFT_BIT_SHIFT__) == LL_ADC_LEFT_BIT_SHIFT_14)                       \
0125    || ((__LEFT_BIT_SHIFT__) == LL_ADC_LEFT_BIT_SHIFT_15)                       \
0126   )
0127 
0128 #define IS_LL_ADC_LOW_POWER(__LOW_POWER__)                                     \
0129   (   ((__LOW_POWER__) == LL_ADC_LP_MODE_NONE)                                 \
0130    || ((__LOW_POWER__) == LL_ADC_LP_AUTOWAIT)                                  \
0131   )
0132 
0133 /* Check of parameters for configuration of ADC hierarchical scope:           */
0134 /* ADC group regular                                                          */
0135 #define IS_LL_ADC_REG_TRIG_SOURCE(__REG_TRIG_SOURCE__)                         \
0136   (   ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_SOFTWARE)                      \
0137    || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_CH1)                  \
0138    || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_CH2)                  \
0139    || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_CH3)                  \
0140    || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM2_CH2)                  \
0141    || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM3_TRGO)                 \
0142    || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM4_CH4)                  \
0143    || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_EXTI_LINE11)               \
0144    || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM8_TRGO)                 \
0145    || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM8_TRGO2)                \
0146    || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_TRGO)                 \
0147    || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_TRGO2)                \
0148    || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM2_TRGO)                 \
0149    || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM4_TRGO)                 \
0150    || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM6_TRGO)                 \
0151    || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM15_TRGO)                \
0152    || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM3_CH4)                  \
0153    || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_HRTIM_TRG1)                \
0154    || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_HRTIM_TRG3)                \
0155    || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_LPTIM1_OUT)                \
0156    || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_LPTIM2_OUT)                \
0157    || ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_LPTIM3_OUT)                \
0158   )
0159 
0160 #define IS_LL_ADC_REG_CONTINUOUS_MODE(__REG_CONTINUOUS_MODE__)                 \
0161   (   ((__REG_CONTINUOUS_MODE__) == LL_ADC_REG_CONV_SINGLE)                    \
0162    || ((__REG_CONTINUOUS_MODE__) == LL_ADC_REG_CONV_CONTINUOUS)                \
0163   )
0164 
0165 #define IS_LL_ADC_REG_DATA_TRANSFER_MODE(__REG_DATA_TRANSFER_MODE__)           \
0166   (   ((__REG_DATA_TRANSFER_MODE__) == LL_ADC_REG_DR_TRANSFER)                 \
0167    || ((__REG_DATA_TRANSFER_MODE__) == LL_ADC_REG_DMA_TRANSFER_LIMITED)        \
0168    || ((__REG_DATA_TRANSFER_MODE__) == LL_ADC_REG_DMA_TRANSFER_UNLIMITED)      \
0169    || ((__REG_DATA_TRANSFER_MODE__) == LL_ADC_REG_DFSDM_TRANSFER)              \
0170   )
0171 
0172 #define IS_LL_ADC_REG_OVR_DATA_BEHAVIOR(__REG_OVR_DATA_BEHAVIOR__)             \
0173   (   ((__REG_OVR_DATA_BEHAVIOR__) == LL_ADC_REG_OVR_DATA_PRESERVED)           \
0174    || ((__REG_OVR_DATA_BEHAVIOR__) == LL_ADC_REG_OVR_DATA_OVERWRITTEN)         \
0175   )
0176 
0177 #define IS_LL_ADC_REG_SEQ_SCAN_LENGTH(__REG_SEQ_SCAN_LENGTH__)                 \
0178   (   ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_DISABLE)               \
0179    || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_2RANKS)         \
0180    || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_3RANKS)         \
0181    || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_4RANKS)         \
0182    || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_5RANKS)         \
0183    || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_6RANKS)         \
0184    || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_7RANKS)         \
0185    || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_8RANKS)         \
0186    || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_9RANKS)         \
0187    || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_10RANKS)        \
0188    || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_11RANKS)        \
0189    || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_12RANKS)        \
0190    || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_13RANKS)        \
0191    || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_14RANKS)        \
0192    || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_15RANKS)        \
0193    || ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_16RANKS)        \
0194   )
0195 
0196 #define IS_LL_ADC_REG_SEQ_SCAN_DISCONT_MODE(__REG_SEQ_DISCONT_MODE__)          \
0197   (   ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_DISABLE)           \
0198    || ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_1RANK)             \
0199    || ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_2RANKS)            \
0200    || ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_3RANKS)            \
0201    || ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_4RANKS)            \
0202    || ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_5RANKS)            \
0203    || ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_6RANKS)            \
0204    || ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_7RANKS)            \
0205    || ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_8RANKS)            \
0206   )
0207 
0208 /* Check of parameters for configuration of ADC hierarchical scope:           */
0209 /* ADC group injected                                                         */
0210 #if defined(STM32H745xx) || defined(STM32H745xG) || defined(STM32H742xx) || defined(STM32H743xx) || defined(STM32H747xG) || defined(STM32H747xx) || defined(STM32H750xx) || defined(STM32H753xx) || defined(STM32H755xx) || defined(STM32H757xx)
0211 #define IS_LL_ADC_INJ_TRIG_SOURCE(__INJ_TRIG_SOURCE__)                         \
0212   (   ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_SOFTWARE)                      \
0213    || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM1_TRGO)                 \
0214    || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM1_CH4)                  \
0215    || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM2_TRGO)                 \
0216    || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM2_CH1)                  \
0217    || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM3_CH4)                  \
0218    || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM4_TRGO)                 \
0219    || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_EXTI_LINE15)               \
0220    || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM8_CH4)                  \
0221    || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM1_TRGO2)                \
0222    || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM8_TRGO)                 \
0223    || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM8_TRGO2)                \
0224    || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM3_CH3)                  \
0225    || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM3_TRGO)                 \
0226    || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM3_CH1)                  \
0227    || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM6_TRGO)                 \
0228    || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM15_TRGO)                \
0229    || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_HRTIM_TRG2)                \
0230    || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_HRTIM_TRG4)                \
0231    || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_LPTIM1_OUT)                \
0232    || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_LPTIM2_OUT)                \
0233    || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_LPTIM3_OUT)                \
0234   )
0235 #else
0236 #define IS_LL_ADC_INJ_TRIG_SOURCE(__INJ_TRIG_SOURCE__)                         \
0237   (   ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_SOFTWARE)                      \
0238    || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM1_TRGO)                 \
0239    || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM1_CH4)                  \
0240    || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM2_TRGO)                 \
0241    || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM2_CH1)                  \
0242    || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM3_CH4)                  \
0243    || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM4_TRGO)                 \
0244    || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_EXTI_LINE15)               \
0245    || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM8_CH4)                  \
0246    || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM1_TRGO2)                \
0247    || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM8_TRGO)                 \
0248    || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM8_TRGO2)                \
0249    || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM3_CH3)                  \
0250    || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM3_TRGO)                 \
0251    || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM3_CH1)                  \
0252    || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM6_TRGO)                 \
0253    || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM15_TRGO)                \
0254    || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_LPTIM1_OUT)                \
0255    || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_LPTIM2_OUT)                \
0256    || ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_LPTIM3_OUT)                \
0257   )
0258 #endif
0259 
0260 #define IS_LL_ADC_INJ_TRIG_EXT_EDGE(__INJ_TRIG_EXT_EDGE__)                     \
0261   (   ((__INJ_TRIG_EXT_EDGE__) == LL_ADC_INJ_TRIG_EXT_RISING)                  \
0262    || ((__INJ_TRIG_EXT_EDGE__) == LL_ADC_INJ_TRIG_EXT_FALLING)                 \
0263    || ((__INJ_TRIG_EXT_EDGE__) == LL_ADC_INJ_TRIG_EXT_RISINGFALLING)           \
0264   )
0265 
0266 #define IS_LL_ADC_INJ_TRIG_AUTO(__INJ_TRIG_AUTO__)                             \
0267   (   ((__INJ_TRIG_AUTO__) == LL_ADC_INJ_TRIG_INDEPENDENT)                     \
0268    || ((__INJ_TRIG_AUTO__) == LL_ADC_INJ_TRIG_FROM_GRP_REGULAR)                \
0269   )
0270 
0271 #define IS_LL_ADC_INJ_SEQ_SCAN_LENGTH(__INJ_SEQ_SCAN_LENGTH__)                 \
0272   (   ((__INJ_SEQ_SCAN_LENGTH__) == LL_ADC_INJ_SEQ_SCAN_DISABLE)               \
0273    || ((__INJ_SEQ_SCAN_LENGTH__) == LL_ADC_INJ_SEQ_SCAN_ENABLE_2RANKS)         \
0274    || ((__INJ_SEQ_SCAN_LENGTH__) == LL_ADC_INJ_SEQ_SCAN_ENABLE_3RANKS)         \
0275    || ((__INJ_SEQ_SCAN_LENGTH__) == LL_ADC_INJ_SEQ_SCAN_ENABLE_4RANKS)         \
0276   )
0277 
0278 #define IS_LL_ADC_INJ_SEQ_SCAN_DISCONT_MODE(__INJ_SEQ_DISCONT_MODE__)          \
0279   (   ((__INJ_SEQ_DISCONT_MODE__) == LL_ADC_INJ_SEQ_DISCONT_DISABLE)           \
0280    || ((__INJ_SEQ_DISCONT_MODE__) == LL_ADC_INJ_SEQ_DISCONT_1RANK)             \
0281   )
0282 
0283 /* Check of parameters for configuration of ADC hierarchical scope:           */
0284 /* multimode.                                                                 */
0285 #define IS_LL_ADC_MULTI_MODE(__MULTI_MODE__)                                   \
0286   (   ((__MULTI_MODE__) == LL_ADC_MULTI_INDEPENDENT)                           \
0287    || ((__MULTI_MODE__) == LL_ADC_MULTI_DUAL_REG_SIMULT)                       \
0288    || ((__MULTI_MODE__) == LL_ADC_MULTI_DUAL_REG_INTERL)                       \
0289    || ((__MULTI_MODE__) == LL_ADC_MULTI_DUAL_INJ_SIMULT)                       \
0290    || ((__MULTI_MODE__) == LL_ADC_MULTI_DUAL_INJ_ALTERN)                       \
0291    || ((__MULTI_MODE__) == LL_ADC_MULTI_DUAL_REG_SIM_INJ_SIM)                  \
0292    || ((__MULTI_MODE__) == LL_ADC_MULTI_DUAL_REG_SIM_INJ_ALT)                  \
0293    || ((__MULTI_MODE__) == LL_ADC_MULTI_DUAL_REG_INT_INJ_SIM)                  \
0294   )
0295 
0296 #define IS_LL_ADC_MULTI_DMA_TRANSFER(__MULTI_DMA_TRANSFER__)                   \
0297   (   ((__MULTI_DMA_TRANSFER__) == LL_ADC_MULTI_REG_DMA_EACH_ADC)              \
0298    || ((__MULTI_DMA_TRANSFER__) == LL_ADC_MULTI_REG_DMA_RES_32_10B)            \
0299    || ((__MULTI_DMA_TRANSFER__) == LL_ADC_MULTI_REG_DMA_RES_8B)                \
0300   )
0301 #define IS_LL_ADC_MULTI_TWOSMP_DELAY(__MULTI_TWOSMP_DELAY__)                    \
0302   (   ((__MULTI_TWOSMP_DELAY__) == LL_ADC_MULTI_TWOSMP_DELAY_1CYCLE_5)          \
0303    || ((__MULTI_TWOSMP_DELAY__) == LL_ADC_MULTI_TWOSMP_DELAY_2CYCLES_5)         \
0304    || ((__MULTI_TWOSMP_DELAY__) == LL_ADC_MULTI_TWOSMP_DELAY_3CYCLES_5)         \
0305    || ((__MULTI_TWOSMP_DELAY__) == LL_ADC_MULTI_TWOSMP_DELAY_4CYCLES_5)         \
0306    || ((__MULTI_TWOSMP_DELAY__) == LL_ADC_MULTI_TWOSMP_DELAY_4CYCLES_5_8_BITS)  \
0307    || ((__MULTI_TWOSMP_DELAY__) == LL_ADC_MULTI_TWOSMP_DELAY_5CYCLES_5)         \
0308    || ((__MULTI_TWOSMP_DELAY__) == LL_ADC_MULTI_TWOSMP_DELAY_5CYCLES_5_10_BITS) \
0309    || ((__MULTI_TWOSMP_DELAY__) == LL_ADC_MULTI_TWOSMP_DELAY_6CYCLES)           \
0310    || ((__MULTI_TWOSMP_DELAY__) == LL_ADC_MULTI_TWOSMP_DELAY_6CYCLES_5)         \
0311    || ((__MULTI_TWOSMP_DELAY__) == LL_ADC_MULTI_TWOSMP_DELAY_6CYCLES_5_12_BITS) \
0312    || ((__MULTI_TWOSMP_DELAY__) == LL_ADC_MULTI_TWOSMP_DELAY_7CYCLES_5)         \
0313    || ((__MULTI_TWOSMP_DELAY__) == LL_ADC_MULTI_TWOSMP_DELAY_8CYCLES)           \
0314    || ((__MULTI_TWOSMP_DELAY__) == LL_ADC_MULTI_TWOSMP_DELAY_9CYCLES)           \
0315   )
0316 
0317 #define IS_LL_ADC_MULTI_MASTER_SLAVE(__MULTI_MASTER_SLAVE__)                   \
0318   (   ((__MULTI_MASTER_SLAVE__) == LL_ADC_MULTI_MASTER)                        \
0319    || ((__MULTI_MASTER_SLAVE__) == LL_ADC_MULTI_SLAVE)                         \
0320    || ((__MULTI_MASTER_SLAVE__) == LL_ADC_MULTI_MASTER_SLAVE)                  \
0321   )
0322 
0323 /**
0324   * @}
0325   */
0326 
0327 
0328 /* Private function prototypes -----------------------------------------------*/
0329 
0330 /* Exported functions --------------------------------------------------------*/
0331 /** @addtogroup ADC_LL_Exported_Functions
0332   * @{
0333   */
0334 
0335 /** @addtogroup ADC_LL_EF_Init
0336   * @{
0337   */
0338 
0339 /**
0340   * @brief  De-initialize registers of all ADC instances belonging to
0341   *         the same ADC common instance to their default reset values.
0342   * @note   This function is performing a hard reset, using high level
0343   *         clock source RCC ADC reset.
0344   *         Caution: On this STM32 series, if several ADC instances are available
0345   *         on the selected device, RCC ADC reset will reset
0346   *         all ADC instances belonging to the common ADC instance.
0347   *         To de-initialize only 1 ADC instance, use
0348   *         function @ref LL_ADC_DeInit().
0349   * @param  ADCxy_COMMON ADC common instance
0350   *         (can be set directly from CMSIS definition or by using helper macro @ref __LL_ADC_COMMON_INSTANCE() )
0351   * @retval An ErrorStatus enumeration value:
0352   *          - SUCCESS: ADC common registers are de-initialized
0353   *          - ERROR: not applicable
0354   */
0355 ErrorStatus LL_ADC_CommonDeInit(ADC_Common_TypeDef *ADCxy_COMMON)
0356 {
0357   /* Check the parameters */
0358   assert_param(IS_ADC_COMMON_INSTANCE(ADCxy_COMMON));
0359 
0360   if (ADCxy_COMMON == ADC12_COMMON)
0361   {
0362     /* Force reset of ADC clock (core clock) */
0363     LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_ADC12);
0364 
0365     /* Release reset of ADC clock (core clock) */
0366     LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_ADC12);
0367   }
0368   else
0369   {
0370 #if defined (ADC3)
0371     /* Force reset of ADC clock (core clock) */
0372     LL_AHB4_GRP1_ForceReset(LL_AHB4_GRP1_PERIPH_ADC3);
0373 
0374     /* Release reset of ADC clock (core clock) */
0375     LL_AHB4_GRP1_ReleaseReset(LL_AHB4_GRP1_PERIPH_ADC3);
0376 #endif
0377   }
0378 
0379   return SUCCESS;
0380 }
0381 
0382 /**
0383   * @brief  Initialize some features of ADC common parameters
0384   *         (all ADC instances belonging to the same ADC common instance)
0385   *         and multimode (for devices with several ADC instances available).
0386   * @note   The setting of ADC common parameters is conditioned to
0387   *         ADC instances state:
0388   *         All ADC instances belonging to the same ADC common instance
0389   *         must be disabled.
0390   * @param  ADCxy_COMMON ADC common instance
0391   *         (can be set directly from CMSIS definition or by using helper macro @ref __LL_ADC_COMMON_INSTANCE() )
0392   * @param  ADC_CommonInitStruct Pointer to a @ref LL_ADC_CommonInitTypeDef structure
0393   * @retval An ErrorStatus enumeration value:
0394   *          - SUCCESS: ADC common registers are initialized
0395   *          - ERROR: ADC common registers are not initialized
0396   */
0397 ErrorStatus LL_ADC_CommonInit(ADC_Common_TypeDef *ADCxy_COMMON, LL_ADC_CommonInitTypeDef *ADC_CommonInitStruct)
0398 {
0399   ErrorStatus status = SUCCESS;
0400 
0401   /* Check the parameters */
0402   assert_param(IS_ADC_COMMON_INSTANCE(ADCxy_COMMON));
0403   assert_param(IS_LL_ADC_COMMON_CLOCK(ADC_CommonInitStruct->CommonClock));
0404 
0405   assert_param(IS_LL_ADC_MULTI_MODE(ADC_CommonInitStruct->Multimode));
0406   if (ADC_CommonInitStruct->Multimode != LL_ADC_MULTI_INDEPENDENT)
0407   {
0408     assert_param(IS_LL_ADC_MULTI_DMA_TRANSFER(ADC_CommonInitStruct->MultiDMATransfer));
0409     assert_param(IS_LL_ADC_MULTI_TWOSMP_DELAY(ADC_CommonInitStruct->MultiTwoSamplingDelay));
0410   }
0411 
0412   /* Note: Hardware constraint (refer to description of functions             */
0413   /*       "LL_ADC_SetCommonXXX()" and "LL_ADC_SetMultiXXX()"):               */
0414   /*       On this STM32 series, setting of these features is conditioned to   */
0415   /*       ADC state:                                                         */
0416   /*       All ADC instances of the ADC common group must be disabled.        */
0417   if (__LL_ADC_IS_ENABLED_ALL_COMMON_INSTANCE(ADCxy_COMMON) == 0UL)
0418   {
0419     /* Configuration of ADC hierarchical scope:                               */
0420     /*  - common to several ADC                                               */
0421     /*    (all ADC instances belonging to the same ADC common instance)       */
0422     /*    - Set ADC clock (conversion clock)                                  */
0423     /*  - multimode (if several ADC instances available on the                */
0424     /*    selected device)                                                    */
0425     /*    - Set ADC multimode configuration                                   */
0426     /*    - Set ADC multimode DMA transfer                                    */
0427     /*    - Set ADC multimode: delay between 2 sampling phases                */
0428     if (ADC_CommonInitStruct->Multimode != LL_ADC_MULTI_INDEPENDENT)
0429     {
0430       MODIFY_REG(ADCxy_COMMON->CCR,
0431                  ADC_CCR_CKMODE
0432                  | ADC_CCR_PRESC
0433                  | ADC_CCR_DUAL
0434                  | ADC_CCR_DAMDF
0435                  | ADC_CCR_DELAY
0436                  ,
0437                  ADC_CommonInitStruct->CommonClock
0438                  | ADC_CommonInitStruct->Multimode
0439                  | ADC_CommonInitStruct->MultiDMATransfer
0440                  | ADC_CommonInitStruct->MultiTwoSamplingDelay
0441                 );
0442     }
0443     else
0444     {
0445       MODIFY_REG(ADCxy_COMMON->CCR,
0446                  ADC_CCR_CKMODE
0447                  | ADC_CCR_PRESC
0448                  | ADC_CCR_DUAL
0449                  | ADC_CCR_DAMDF
0450                  | ADC_CCR_DELAY
0451                  ,
0452                  ADC_CommonInitStruct->CommonClock
0453                  | LL_ADC_MULTI_INDEPENDENT
0454                 );
0455     }
0456   }
0457   else
0458   {
0459     /* Initialization error: One or several ADC instances belonging to        */
0460     /* the same ADC common instance are not disabled.                         */
0461     status = ERROR;
0462   }
0463 
0464   return status;
0465 }
0466 
0467 /**
0468   * @brief  Set each @ref LL_ADC_CommonInitTypeDef field to default value.
0469   * @param  ADC_CommonInitStruct Pointer to a @ref LL_ADC_CommonInitTypeDef structure
0470   *                              whose fields will be set to default values.
0471   * @retval None
0472   */
0473 void LL_ADC_CommonStructInit(LL_ADC_CommonInitTypeDef *ADC_CommonInitStruct)
0474 {
0475   /* Set ADC_CommonInitStruct fields to default values */
0476   /* Set fields of ADC common */
0477   /* (all ADC instances belonging to the same ADC common instance) */
0478   ADC_CommonInitStruct->CommonClock = LL_ADC_CLOCK_SYNC_PCLK_DIV2;
0479 
0480   /* Set fields of ADC multimode */
0481   ADC_CommonInitStruct->Multimode             = LL_ADC_MULTI_INDEPENDENT;
0482   ADC_CommonInitStruct->MultiDMATransfer      = LL_ADC_MULTI_REG_DMA_EACH_ADC;
0483   ADC_CommonInitStruct->MultiTwoSamplingDelay = LL_ADC_MULTI_TWOSMP_DELAY_1CYCLE_5;
0484 }
0485 
0486 /**
0487   * @brief  De-initialize registers of the selected ADC instance
0488   *         to their default reset values.
0489   * @note   To reset all ADC instances quickly (perform a hard reset),
0490   *         use function @ref LL_ADC_CommonDeInit().
0491   * @note   If this functions returns error status, it means that ADC instance
0492   *         is in an unknown state.
0493   *         In this case, perform a hard reset using high level
0494   *         clock source RCC ADC reset.
0495   *         Caution: On this STM32 series, if several ADC instances are available
0496   *         on the selected device, RCC ADC reset will reset
0497   *         all ADC instances belonging to the common ADC instance.
0498   *         Refer to function @ref LL_ADC_CommonDeInit().
0499   * @param  ADCx ADC instance
0500   * @retval An ErrorStatus enumeration value:
0501   *          - SUCCESS: ADC registers are de-initialized
0502   *          - ERROR: ADC registers are not de-initialized
0503   */
0504 ErrorStatus LL_ADC_DeInit(ADC_TypeDef *ADCx)
0505 {
0506   ErrorStatus status = SUCCESS;
0507 
0508   __IO uint32_t timeout_cpu_cycles = 0UL;
0509 
0510   /* Check the parameters */
0511   assert_param(IS_ADC_ALL_INSTANCE(ADCx));
0512 
0513   /* Disable ADC instance if not already disabled.                            */
0514   if (LL_ADC_IsEnabled(ADCx) == 1UL)
0515   {
0516     /* Stop potential ADC conversion on going on ADC group regular.           */
0517     if (LL_ADC_REG_IsConversionOngoing(ADCx) != 0UL)
0518     {
0519       if (LL_ADC_REG_IsStopConversionOngoing(ADCx) == 0UL)
0520       {
0521         LL_ADC_REG_StopConversion(ADCx);
0522       }
0523     }
0524 
0525     /* Stop potential ADC conversion on going on ADC group injected.          */
0526     if (LL_ADC_INJ_IsConversionOngoing(ADCx) != 0UL)
0527     {
0528       if (LL_ADC_INJ_IsStopConversionOngoing(ADCx) == 0UL)
0529       {
0530         LL_ADC_INJ_StopConversion(ADCx);
0531       }
0532     }
0533 
0534     /* Wait for ADC conversions are effectively stopped                       */
0535     timeout_cpu_cycles = ADC_TIMEOUT_STOP_CONVERSION_CPU_CYCLES;
0536     while ((LL_ADC_REG_IsStopConversionOngoing(ADCx)
0537             | LL_ADC_INJ_IsStopConversionOngoing(ADCx)) == 1UL)
0538     {
0539       timeout_cpu_cycles--;
0540       if (timeout_cpu_cycles == 0UL)
0541       {
0542         /* Time-out error */
0543         status = ERROR;
0544         break;
0545       }
0546     }
0547 
0548     /* Flush group injected contexts queue (register JSQR):                   */
0549     /* Note: Bit JQM must be set to empty the contexts queue (otherwise       */
0550     /*       contexts queue is maintained with the last active context).      */
0551     LL_ADC_INJ_SetQueueMode(ADCx, LL_ADC_INJ_QUEUE_2CONTEXTS_END_EMPTY);
0552 
0553     /* Disable the ADC instance */
0554     LL_ADC_Disable(ADCx);
0555 
0556     /* Wait for ADC instance is effectively disabled */
0557     timeout_cpu_cycles = ADC_TIMEOUT_DISABLE_CPU_CYCLES;
0558     while (LL_ADC_IsDisableOngoing(ADCx) == 1UL)
0559     {
0560       timeout_cpu_cycles--;
0561       if (timeout_cpu_cycles == 0UL)
0562       {
0563         /* Time-out error */
0564         status = ERROR;
0565         break;
0566       }
0567     }
0568   }
0569 
0570   /* Check whether ADC state is compliant with expected state */
0571   if (READ_BIT(ADCx->CR,
0572                (ADC_CR_JADSTP | ADC_CR_ADSTP | ADC_CR_JADSTART | ADC_CR_ADSTART
0573                 | ADC_CR_ADDIS | ADC_CR_ADEN)
0574               )
0575       == 0UL)
0576   {
0577     /* ========== Reset ADC registers ========== */
0578     /* Reset register IER */
0579     CLEAR_BIT(ADCx->IER,
0580               (LL_ADC_IT_ADRDY
0581                | LL_ADC_IT_EOC
0582                | LL_ADC_IT_EOS
0583                | LL_ADC_IT_OVR
0584                | LL_ADC_IT_EOSMP
0585                | LL_ADC_IT_JEOC
0586                | LL_ADC_IT_JEOS
0587                | LL_ADC_IT_JQOVF
0588                | LL_ADC_IT_AWD1
0589                | LL_ADC_IT_AWD2
0590                | LL_ADC_IT_AWD3
0591               )
0592              );
0593 
0594     /* Reset register ISR */
0595     SET_BIT(ADCx->ISR,
0596             (LL_ADC_FLAG_ADRDY
0597              | LL_ADC_FLAG_EOC
0598              | LL_ADC_FLAG_EOS
0599              | LL_ADC_FLAG_OVR
0600              | LL_ADC_FLAG_EOSMP
0601              | LL_ADC_FLAG_JEOC
0602              | LL_ADC_FLAG_JEOS
0603              | LL_ADC_FLAG_JQOVF
0604              | LL_ADC_FLAG_AWD1
0605              | LL_ADC_FLAG_AWD2
0606              | LL_ADC_FLAG_AWD3
0607             )
0608            );
0609 
0610     /* Reset register CR */
0611     /*  - Bits ADC_CR_JADSTP, ADC_CR_ADSTP, ADC_CR_JADSTART, ADC_CR_ADSTART,  */
0612     /*    ADC_CR_ADCAL, ADC_CR_ADDIS, ADC_CR_ADEN are in                      */
0613     /*    access mode "read-set": no direct reset applicable.                 */
0614     /*  - Reset Calibration mode to default setting (single ended).           */
0615     /*  - Disable ADC internal voltage regulator.                             */
0616     /*  - Enable ADC deep power down.                                         */
0617     /*    Note: ADC internal voltage regulator disable and ADC deep power     */
0618     /*          down enable are conditioned to ADC state disabled:            */
0619     /*          already done above.                                           */
0620     CLEAR_BIT(ADCx->CR, ADC_CR_ADVREGEN | ADC_CR_ADCALDIF);
0621     SET_BIT(ADCx->CR, ADC_CR_DEEPPWD);
0622 
0623     /* Reset register CFGR */
0624     CLEAR_BIT(ADCx->CFGR,
0625               (ADC_CFGR_AWD1CH  | ADC_CFGR_JAUTO   | ADC_CFGR_JAWD1EN
0626                | ADC_CFGR_AWD1EN  | ADC_CFGR_AWD1SGL | ADC_CFGR_JQM
0627                | ADC_CFGR_JDISCEN | ADC_CFGR_DISCNUM | ADC_CFGR_DISCEN
0628                | ADC_CFGR_AUTDLY  | ADC_CFGR_CONT    | ADC_CFGR_OVRMOD
0629                | ADC_CFGR_EXTEN   | ADC_CFGR_EXTSEL  | ADC_CFGR_RES
0630                | ADC_CFGR_DMNGT)
0631              );
0632 
0633     SET_BIT(ADCx->CFGR, ADC_CFGR_JQDIS);
0634 
0635     /* Reset register CFGR2 */
0636     CLEAR_BIT(ADCx->CFGR2,
0637               (ADC_CFGR2_LSHIFT  | ADC_CFGR2_OVSR    | ADC_CFGR2_RSHIFT1
0638                | ADC_CFGR2_RSHIFT4 | ADC_CFGR2_RSHIFT3 | ADC_CFGR2_RSHIFT2
0639                | ADC_CFGR2_RSHIFT1 | ADC_CFGR2_ROVSM   | ADC_CFGR2_TROVS
0640                | ADC_CFGR2_OVSS    | ADC_CFGR2_JOVSE | ADC_CFGR2_ROVSE)
0641              );
0642 
0643     /* Reset register SMPR1 */
0644     CLEAR_BIT(ADCx->SMPR1,
0645               (ADC_SMPR1_SMP9 | ADC_SMPR1_SMP8 | ADC_SMPR1_SMP7
0646                | ADC_SMPR1_SMP6 | ADC_SMPR1_SMP5 | ADC_SMPR1_SMP4
0647                | ADC_SMPR1_SMP3 | ADC_SMPR1_SMP2 | ADC_SMPR1_SMP1)
0648              );
0649 
0650     /* Reset register SMPR2 */
0651     CLEAR_BIT(ADCx->SMPR2,
0652               (ADC_SMPR2_SMP19 | ADC_SMPR2_SMP18 | ADC_SMPR2_SMP17
0653                | ADC_SMPR2_SMP16 | ADC_SMPR2_SMP15 | ADC_SMPR2_SMP14
0654                | ADC_SMPR2_SMP13 | ADC_SMPR2_SMP12 | ADC_SMPR2_SMP11
0655                | ADC_SMPR2_SMP10)
0656              );
0657 
0658     /* Reset register TR1 */
0659 #if defined(ADC_VER_V5_V90)
0660     if (ADCx == ADC3)
0661     {
0662       /* Reset register TR1 */
0663       MODIFY_REG(ADCx->LTR1_TR1, ADC3_TR1_AWDFILT | ADC3_TR1_HT1 | ADC3_TR1_LT1, ADC3_TR1_HT1);
0664 
0665       /* Reset register TR2 */
0666       MODIFY_REG(ADCx->HTR1_TR2, ADC3_TR2_HT2 | ADC3_TR2_LT2, ADC3_TR2_HT2);
0667 
0668       /* Reset register TR3 */
0669       MODIFY_REG(ADCx->RES1_TR3, ADC3_TR3_HT3 | ADC3_TR3_LT3, ADC3_TR3_HT3);
0670     }
0671     else
0672     {
0673       CLEAR_BIT(ADCx->LTR1_TR1, ADC_LTR_LT);
0674       SET_BIT(ADCx->HTR1_TR2, ADC_HTR_HT);
0675 
0676       CLEAR_BIT(ADCx->LTR2_DIFSEL, ADC_LTR_LT);
0677       SET_BIT(ADCx->HTR2_CALFACT, ADC_HTR_HT);
0678       CLEAR_BIT(ADCx->LTR3_RES10, ADC_LTR_LT);
0679       SET_BIT(ADCx->HTR3_RES11, ADC_HTR_HT);
0680     }
0681 #else
0682     CLEAR_BIT(ADCx->LTR1, ADC_LTR_LT);
0683     SET_BIT(ADCx->HTR1, ADC_HTR_HT);
0684 
0685     CLEAR_BIT(ADCx->LTR2, ADC_LTR_LT);
0686     SET_BIT(ADCx->HTR2, ADC_HTR_HT);
0687     CLEAR_BIT(ADCx->LTR3, ADC_LTR_LT);
0688     SET_BIT(ADCx->HTR3, ADC_HTR_HT);
0689 #endif
0690 
0691     /* Reset register SQR1 */
0692     CLEAR_BIT(ADCx->SQR1,
0693               (ADC_SQR1_SQ4 | ADC_SQR1_SQ3 | ADC_SQR1_SQ2
0694                | ADC_SQR1_SQ1 | ADC_SQR1_L)
0695              );
0696 
0697     /* Reset register SQR2 */
0698     CLEAR_BIT(ADCx->SQR2,
0699               (ADC_SQR2_SQ9 | ADC_SQR2_SQ8 | ADC_SQR2_SQ7
0700                | ADC_SQR2_SQ6 | ADC_SQR2_SQ5)
0701              );
0702 
0703     /* Reset register SQR3 */
0704     CLEAR_BIT(ADCx->SQR3,
0705               (ADC_SQR3_SQ14 | ADC_SQR3_SQ13 | ADC_SQR3_SQ12
0706                | ADC_SQR3_SQ11 | ADC_SQR3_SQ10)
0707              );
0708 
0709     /* Reset register SQR4 */
0710     CLEAR_BIT(ADCx->SQR4, ADC_SQR4_SQ16 | ADC_SQR4_SQ15);
0711 
0712     /* Reset register JSQR */
0713     CLEAR_BIT(ADCx->JSQR,
0714               (ADC_JSQR_JL
0715                | ADC_JSQR_JEXTSEL | ADC_JSQR_JEXTEN
0716                | ADC_JSQR_JSQ4    | ADC_JSQR_JSQ3
0717                | ADC_JSQR_JSQ2    | ADC_JSQR_JSQ1)
0718              );
0719 
0720     /* Reset register DR */
0721     /* Note: bits in access mode read only, no direct reset applicable */
0722 
0723     /* Reset register OFR1 */
0724     CLEAR_BIT(ADCx->OFR1, ADC_OFR1_OFFSET1 | ADC_OFR1_OFFSET1_CH | ADC_OFR1_SSATE);
0725     /* Reset register OFR2 */
0726     CLEAR_BIT(ADCx->OFR2, ADC_OFR2_OFFSET2 | ADC_OFR2_OFFSET2_CH | ADC_OFR2_SSATE);
0727     /* Reset register OFR3 */
0728     CLEAR_BIT(ADCx->OFR3, ADC_OFR3_OFFSET3 | ADC_OFR3_OFFSET3_CH | ADC_OFR3_SSATE);
0729     /* Reset register OFR4 */
0730     CLEAR_BIT(ADCx->OFR4, ADC_OFR4_OFFSET4 | ADC_OFR4_OFFSET4_CH | ADC_OFR4_SSATE);
0731 
0732     /* Reset registers JDR1, JDR2, JDR3, JDR4 */
0733     /* Note: bits in access mode read only, no direct reset applicable */
0734 
0735     /* Reset register AWD2CR */
0736     CLEAR_BIT(ADCx->AWD2CR, ADC_AWD2CR_AWD2CH);
0737 
0738     /* Reset register AWD3CR */
0739     CLEAR_BIT(ADCx->AWD3CR, ADC_AWD3CR_AWD3CH);
0740 
0741     /* Reset register DIFSEL */
0742 #if defined(ADC_VER_V5_V90)
0743     if (ADCx == ADC3)
0744     {
0745       CLEAR_BIT(ADCx->LTR2_DIFSEL, ADC_DIFSEL_DIFSEL);
0746 
0747       /* Reset register CALFACT */
0748       CLEAR_BIT(ADCx->HTR2_CALFACT, ADC_CALFACT_CALFACT_D | ADC_CALFACT_CALFACT_S);
0749     }
0750     else
0751     {
0752       CLEAR_BIT(ADCx->DIFSEL_RES12, ADC_DIFSEL_DIFSEL);
0753 
0754       /* Reset register CALFACT */
0755       CLEAR_BIT(ADCx->CALFACT_RES13, ADC_CALFACT_CALFACT_D | ADC_CALFACT_CALFACT_S);
0756 
0757       /* Reset register CALFACT2 */
0758       CLEAR_BIT(ADCx->CALFACT2_RES14, ADC_CALFACT2_LINCALFACT);
0759     }
0760 #else
0761     CLEAR_BIT(ADCx->DIFSEL, ADC_DIFSEL_DIFSEL);
0762 
0763     /* Reset register CALFACT */
0764     CLEAR_BIT(ADCx->CALFACT, ADC_CALFACT_CALFACT_D | ADC_CALFACT_CALFACT_S);
0765 
0766     /* Reset register CALFACT2 */
0767     CLEAR_BIT(ADCx->CALFACT2, ADC_CALFACT2_LINCALFACT);
0768 #endif
0769   }
0770   else
0771   {
0772     /* ADC instance is in an unknown state */
0773     /* Need to performing a hard reset of ADC instance, using high level      */
0774     /* clock source RCC ADC reset.                                            */
0775     /* Caution: On this STM32 series, if several ADC instances are available   */
0776     /*          on the selected device, RCC ADC reset will reset              */
0777     /*          all ADC instances belonging to the common ADC instance.       */
0778     /* Caution: On this STM32 series, if several ADC instances are available   */
0779     /*          on the selected device, RCC ADC reset will reset              */
0780     /*          all ADC instances belonging to the common ADC instance.       */
0781     status = ERROR;
0782   }
0783 
0784   return status;
0785 }
0786 
0787 /**
0788   * @brief  Initialize some features of ADC instance.
0789   * @note   These parameters have an impact on ADC scope: ADC instance.
0790   *         Affects both group regular and group injected (availability
0791   *         of ADC group injected depends on STM32 families).
0792   *         Refer to corresponding unitary functions into
0793   *         @ref ADC_LL_EF_Configuration_ADC_Instance .
0794   * @note   The setting of these parameters by function @ref LL_ADC_Init()
0795   *         is conditioned to ADC state:
0796   *         ADC instance must be disabled.
0797   *         This condition is applied to all ADC features, for efficiency
0798   *         and compatibility over all STM32 families. However, the different
0799   *         features can be set under different ADC state conditions
0800   *         (setting possible with ADC enabled without conversion on going,
0801   *         ADC enabled with conversion on going, ...)
0802   *         Each feature can be updated afterwards with a unitary function
0803   *         and potentially with ADC in a different state than disabled,
0804   *         refer to description of each function for setting
0805   *         conditioned to ADC state.
0806   * @note   After using this function, some other features must be configured
0807   *         using LL unitary functions.
0808   *         The minimum configuration remaining to be done is:
0809   *          - Set ADC group regular or group injected sequencer:
0810   *            map channel on the selected sequencer rank.
0811   *            Refer to function @ref LL_ADC_REG_SetSequencerRanks().
0812   *          - Set ADC channel sampling time
0813   *            Refer to function LL_ADC_SetChannelSamplingTime();
0814   * @param  ADCx ADC instance
0815   * @param  ADC_InitStruct Pointer to a @ref LL_ADC_REG_InitTypeDef structure
0816   * @retval An ErrorStatus enumeration value:
0817   *          - SUCCESS: ADC registers are initialized
0818   *          - ERROR: ADC registers are not initialized
0819   */
0820 ErrorStatus LL_ADC_Init(ADC_TypeDef *ADCx, LL_ADC_InitTypeDef *ADC_InitStruct)
0821 {
0822   ErrorStatus status = SUCCESS;
0823 
0824   /* Check the parameters */
0825   assert_param(IS_ADC_ALL_INSTANCE(ADCx));
0826 
0827   assert_param(IS_LL_ADC_RESOLUTION(ADC_InitStruct->Resolution));
0828   assert_param(IS_LL_ADC_LEFT_BIT_SHIFT(ADC_InitStruct->LeftBitShift));
0829   assert_param(IS_LL_ADC_LOW_POWER(ADC_InitStruct->LowPowerMode));
0830 
0831   /* Note: Hardware constraint (refer to description of this function):       */
0832   /*       ADC instance must be disabled.                                     */
0833   if (LL_ADC_IsEnabled(ADCx) == 0UL)
0834   {
0835     /* Configuration of ADC hierarchical scope:                               */
0836     /*  - ADC instance                                                        */
0837     /*    - Set ADC data resolution                                           */
0838     /*    - Set ADC conversion data alignment                                 */
0839     /*    - Set ADC low power mode                                            */
0840 #if defined(ADC_VER_V5_V90)
0841     if(ADCx==ADC3)
0842     {
0843       MODIFY_REG(ADCx->CFGR,
0844                  ADC3_CFGR_RES
0845                  | ADC_CFGR_AUTDLY
0846                  ,
0847                  ((__LL_ADC12_RESOLUTION_TO_ADC3(ADC_InitStruct->Resolution)  & (ADC_CFGR_RES_1 | ADC_CFGR_RES_0)) << 1UL)
0848                  | ADC_InitStruct->LowPowerMode
0849                 );
0850     }
0851     else
0852     {
0853     MODIFY_REG(ADCx->CFGR,
0854                ADC_CFGR_RES
0855                | ADC_CFGR_AUTDLY
0856                ,
0857                ADC_InitStruct->Resolution
0858                | ADC_InitStruct->LowPowerMode
0859               );
0860     }
0861 #else
0862     MODIFY_REG(ADCx->CFGR,
0863                ADC_CFGR_RES
0864                | ADC_CFGR_AUTDLY
0865                ,
0866                ADC_InitStruct->Resolution
0867                | ADC_InitStruct->LowPowerMode
0868               );
0869 #endif
0870 
0871     MODIFY_REG(ADCx->CFGR2, ADC_CFGR2_LSHIFT, ADC_InitStruct->LeftBitShift);
0872   }
0873   else
0874   {
0875     /* Initialization error: ADC instance is not disabled. */
0876     status = ERROR;
0877   }
0878   return status;
0879 }
0880 
0881 /**
0882   * @brief  Set each @ref LL_ADC_InitTypeDef field to default value.
0883   * @param  ADC_InitStruct Pointer to a @ref LL_ADC_InitTypeDef structure
0884   *                        whose fields will be set to default values.
0885   * @retval None
0886   */
0887 void LL_ADC_StructInit(LL_ADC_InitTypeDef *ADC_InitStruct)
0888 {
0889   /* Set ADC_InitStruct fields to default values */
0890   /* Set fields of ADC instance */
0891   ADC_InitStruct->Resolution    = LL_ADC_RESOLUTION_16B;
0892   ADC_InitStruct->LeftBitShift  = LL_ADC_LEFT_BIT_SHIFT_NONE;
0893   ADC_InitStruct->LowPowerMode  = LL_ADC_LP_MODE_NONE;
0894 
0895 }
0896 
0897 /**
0898   * @brief  Initialize some features of ADC group regular.
0899   * @note   These parameters have an impact on ADC scope: ADC group regular.
0900   *         Refer to corresponding unitary functions into
0901   *         @ref ADC_LL_EF_Configuration_ADC_Group_Regular
0902   *         (functions with prefix "REG").
0903   * @note   The setting of these parameters by function @ref LL_ADC_Init()
0904   *         is conditioned to ADC state:
0905   *         ADC instance must be disabled.
0906   *         This condition is applied to all ADC features, for efficiency
0907   *         and compatibility over all STM32 families. However, the different
0908   *         features can be set under different ADC state conditions
0909   *         (setting possible with ADC enabled without conversion on going,
0910   *         ADC enabled with conversion on going, ...)
0911   *         Each feature can be updated afterwards with a unitary function
0912   *         and potentially with ADC in a different state than disabled,
0913   *         refer to description of each function for setting
0914   *         conditioned to ADC state.
0915   * @note   After using this function, other features must be configured
0916   *         using LL unitary functions.
0917   *         The minimum configuration remaining to be done is:
0918   *          - Set ADC group regular or group injected sequencer:
0919   *            map channel on the selected sequencer rank.
0920   *            Refer to function @ref LL_ADC_REG_SetSequencerRanks().
0921   *          - Set ADC channel sampling time
0922   *            Refer to function LL_ADC_SetChannelSamplingTime();
0923   * @param  ADCx ADC instance
0924   * @param  ADC_REG_InitStruct Pointer to a @ref LL_ADC_REG_InitTypeDef structure
0925   * @retval An ErrorStatus enumeration value:
0926   *          - SUCCESS: ADC registers are initialized
0927   *          - ERROR: ADC registers are not initialized
0928   */
0929 ErrorStatus LL_ADC_REG_Init(ADC_TypeDef *ADCx, LL_ADC_REG_InitTypeDef *ADC_REG_InitStruct)
0930 {
0931   ErrorStatus status = SUCCESS;
0932 
0933   /* Check the parameters */
0934   assert_param(IS_ADC_ALL_INSTANCE(ADCx));
0935   assert_param(IS_LL_ADC_REG_TRIG_SOURCE(ADC_REG_InitStruct->TriggerSource));
0936   assert_param(IS_LL_ADC_REG_SEQ_SCAN_LENGTH(ADC_REG_InitStruct->SequencerLength));
0937   if (ADC_REG_InitStruct->SequencerLength != LL_ADC_REG_SEQ_SCAN_DISABLE)
0938   {
0939     assert_param(IS_LL_ADC_REG_SEQ_SCAN_DISCONT_MODE(ADC_REG_InitStruct->SequencerDiscont));
0940 
0941     /* ADC group regular continuous mode and discontinuous mode                 */
0942     /* can not be enabled simultenaeously                                       */
0943     assert_param((ADC_REG_InitStruct->ContinuousMode == LL_ADC_REG_CONV_SINGLE)
0944                  || (ADC_REG_InitStruct->SequencerDiscont == LL_ADC_REG_SEQ_DISCONT_DISABLE));
0945   }
0946   assert_param(IS_LL_ADC_REG_CONTINUOUS_MODE(ADC_REG_InitStruct->ContinuousMode));
0947   assert_param(IS_LL_ADC_REG_DATA_TRANSFER_MODE(ADC_REG_InitStruct->DataTransferMode));
0948   assert_param(IS_LL_ADC_REG_OVR_DATA_BEHAVIOR(ADC_REG_InitStruct->Overrun));
0949 
0950   /* Note: Hardware constraint (refer to description of this function):       */
0951   /*       ADC instance must be disabled.                                     */
0952   if (LL_ADC_IsEnabled(ADCx) == 0UL)
0953   {
0954     /* Configuration of ADC hierarchical scope:                               */
0955     /*  - ADC group regular                                                   */
0956     /*    - Set ADC group regular trigger source                              */
0957     /*    - Set ADC group regular sequencer length                            */
0958     /*    - Set ADC group regular sequencer discontinuous mode                */
0959     /*    - Set ADC group regular continuous mode                             */
0960     /*    - Set ADC group regular conversion data transfer: no transfer or    */
0961     /*      transfer by DMA, and DMA requests mode                            */
0962     /*    - Set ADC group regular overrun behavior                            */
0963     /* Note: On this STM32 series, ADC trigger edge is set to value 0x0 by     */
0964     /*       setting of trigger source to SW start.                           */
0965     if (ADC_REG_InitStruct->SequencerLength != LL_ADC_REG_SEQ_SCAN_DISABLE)
0966     {
0967       MODIFY_REG(ADCx->CFGR,
0968                  ADC_CFGR_EXTSEL
0969                  | ADC_CFGR_EXTEN
0970                  | ADC_CFGR_DISCEN
0971                  | ADC_CFGR_DISCNUM
0972                  | ADC_CFGR_CONT
0973                  | ADC_CFGR_DMNGT
0974                  | ADC_CFGR_OVRMOD
0975                  ,
0976                  ADC_REG_InitStruct->TriggerSource
0977                  | ADC_REG_InitStruct->SequencerDiscont
0978                  | ADC_REG_InitStruct->ContinuousMode
0979                  | ADC_REG_InitStruct->DataTransferMode
0980                  | ADC_REG_InitStruct->Overrun
0981                 );
0982     }
0983     else
0984     {
0985       MODIFY_REG(ADCx->CFGR,
0986                  ADC_CFGR_EXTSEL
0987                  | ADC_CFGR_EXTEN
0988                  | ADC_CFGR_DISCEN
0989                  | ADC_CFGR_DISCNUM
0990                  | ADC_CFGR_CONT
0991                  | ADC_CFGR_DMNGT
0992                  | ADC_CFGR_OVRMOD
0993                  ,
0994                  ADC_REG_InitStruct->TriggerSource
0995                  | LL_ADC_REG_SEQ_DISCONT_DISABLE
0996                  | ADC_REG_InitStruct->ContinuousMode
0997                  | ADC_REG_InitStruct->DataTransferMode
0998                  | ADC_REG_InitStruct->Overrun
0999                 );
1000     }
1001 
1002     /* Set ADC group regular sequencer length and scan direction */
1003     LL_ADC_REG_SetSequencerLength(ADCx, ADC_REG_InitStruct->SequencerLength);
1004   }
1005   else
1006   {
1007     /* Initialization error: ADC instance is not disabled. */
1008     status = ERROR;
1009   }
1010   return status;
1011 }
1012 
1013 /**
1014   * @brief  Set each @ref LL_ADC_REG_InitTypeDef field to default value.
1015   * @param  ADC_REG_InitStruct Pointer to a @ref LL_ADC_REG_InitTypeDef structure
1016   *                            whose fields will be set to default values.
1017   * @retval None
1018   */
1019 void LL_ADC_REG_StructInit(LL_ADC_REG_InitTypeDef *ADC_REG_InitStruct)
1020 {
1021   /* Set ADC_REG_InitStruct fields to default values */
1022   /* Set fields of ADC group regular */
1023   /* Note: On this STM32 series, ADC trigger edge is set to value 0x0 by       */
1024   /*       setting of trigger source to SW start.                             */
1025   ADC_REG_InitStruct->TriggerSource    = LL_ADC_REG_TRIG_SOFTWARE;
1026   ADC_REG_InitStruct->SequencerLength  = LL_ADC_REG_SEQ_SCAN_DISABLE;
1027   ADC_REG_InitStruct->SequencerDiscont = LL_ADC_REG_SEQ_DISCONT_DISABLE;
1028   ADC_REG_InitStruct->ContinuousMode   = LL_ADC_REG_CONV_SINGLE;
1029   ADC_REG_InitStruct->DataTransferMode = LL_ADC_REG_DR_TRANSFER;
1030   ADC_REG_InitStruct->Overrun          = LL_ADC_REG_OVR_DATA_OVERWRITTEN;
1031 }
1032 
1033 /**
1034   * @brief  Initialize some features of ADC group injected.
1035   * @note   These parameters have an impact on ADC scope: ADC group injected.
1036   *         Refer to corresponding unitary functions into
1037   *         @ref ADC_LL_EF_Configuration_ADC_Group_Regular
1038   *         (functions with prefix "INJ").
1039   * @note   The setting of these parameters by function @ref LL_ADC_Init()
1040   *         is conditioned to ADC state:
1041   *         ADC instance must be disabled.
1042   *         This condition is applied to all ADC features, for efficiency
1043   *         and compatibility over all STM32 families. However, the different
1044   *         features can be set under different ADC state conditions
1045   *         (setting possible with ADC enabled without conversion on going,
1046   *         ADC enabled with conversion on going, ...)
1047   *         Each feature can be updated afterwards with a unitary function
1048   *         and potentially with ADC in a different state than disabled,
1049   *         refer to description of each function for setting
1050   *         conditioned to ADC state.
1051   * @note   After using this function, other features must be configured
1052   *         using LL unitary functions.
1053   *         The minimum configuration remaining to be done is:
1054   *          - Set ADC group injected sequencer:
1055   *            map channel on the selected sequencer rank.
1056   *            Refer to function @ref LL_ADC_INJ_SetSequencerRanks().
1057   *          - Set ADC channel sampling time
1058   *            Refer to function LL_ADC_SetChannelSamplingTime();
1059   * @param  ADCx ADC instance
1060   * @param  ADC_INJ_InitStruct Pointer to a @ref LL_ADC_INJ_InitTypeDef structure
1061   * @retval An ErrorStatus enumeration value:
1062   *          - SUCCESS: ADC registers are initialized
1063   *          - ERROR: ADC registers are not initialized
1064   */
1065 ErrorStatus LL_ADC_INJ_Init(ADC_TypeDef *ADCx, LL_ADC_INJ_InitTypeDef *ADC_INJ_InitStruct)
1066 {
1067   ErrorStatus status = SUCCESS;
1068 
1069   /* Check the parameters */
1070   assert_param(IS_ADC_ALL_INSTANCE(ADCx));
1071   assert_param(IS_LL_ADC_INJ_TRIG_SOURCE(ADC_INJ_InitStruct->TriggerSource));
1072   assert_param(IS_LL_ADC_INJ_SEQ_SCAN_LENGTH(ADC_INJ_InitStruct->SequencerLength));
1073   if (ADC_INJ_InitStruct->SequencerLength != LL_ADC_INJ_SEQ_SCAN_DISABLE)
1074   {
1075     assert_param(IS_LL_ADC_INJ_SEQ_SCAN_DISCONT_MODE(ADC_INJ_InitStruct->SequencerDiscont));
1076   }
1077   assert_param(IS_LL_ADC_INJ_TRIG_AUTO(ADC_INJ_InitStruct->TrigAuto));
1078 
1079   /* Note: Hardware constraint (refer to description of this function):       */
1080   /*       ADC instance must be disabled.                                     */
1081   if (LL_ADC_IsEnabled(ADCx) == 0UL)
1082   {
1083     /* Configuration of ADC hierarchical scope:                               */
1084     /*  - ADC group injected                                                  */
1085     /*    - Set ADC group injected trigger source                             */
1086     /*    - Set ADC group injected sequencer length                           */
1087     /*    - Set ADC group injected sequencer discontinuous mode               */
1088     /*    - Set ADC group injected conversion trigger: independent or         */
1089     /*      from ADC group regular                                            */
1090     /* Note: On this STM32 series, ADC trigger edge is set to value 0x0 by     */
1091     /*       setting of trigger source to SW start.                           */
1092     if (ADC_INJ_InitStruct->SequencerLength != LL_ADC_REG_SEQ_SCAN_DISABLE)
1093     {
1094       MODIFY_REG(ADCx->CFGR,
1095                  ADC_CFGR_JDISCEN
1096                  | ADC_CFGR_JAUTO
1097                  ,
1098                  ADC_INJ_InitStruct->SequencerDiscont
1099                  | ADC_INJ_InitStruct->TrigAuto
1100                 );
1101     }
1102     else
1103     {
1104       MODIFY_REG(ADCx->CFGR,
1105                  ADC_CFGR_JDISCEN
1106                  | ADC_CFGR_JAUTO
1107                  ,
1108                  LL_ADC_REG_SEQ_DISCONT_DISABLE
1109                  | ADC_INJ_InitStruct->TrigAuto
1110                 );
1111     }
1112 
1113     MODIFY_REG(ADCx->JSQR,
1114                ADC_JSQR_JEXTSEL
1115                | ADC_JSQR_JEXTEN
1116                | ADC_JSQR_JL
1117                ,
1118                ADC_INJ_InitStruct->TriggerSource
1119                | ADC_INJ_InitStruct->SequencerLength
1120               );
1121   }
1122   else
1123   {
1124     /* Initialization error: ADC instance is not disabled. */
1125     status = ERROR;
1126   }
1127   return status;
1128 }
1129 
1130 /**
1131   * @brief  Set each @ref LL_ADC_INJ_InitTypeDef field to default value.
1132   * @param  ADC_INJ_InitStruct Pointer to a @ref LL_ADC_INJ_InitTypeDef structure
1133   *                            whose fields will be set to default values.
1134   * @retval None
1135   */
1136 void LL_ADC_INJ_StructInit(LL_ADC_INJ_InitTypeDef *ADC_INJ_InitStruct)
1137 {
1138   /* Set ADC_INJ_InitStruct fields to default values */
1139   /* Set fields of ADC group injected */
1140   ADC_INJ_InitStruct->TriggerSource    = LL_ADC_INJ_TRIG_SOFTWARE;
1141   ADC_INJ_InitStruct->SequencerLength  = LL_ADC_INJ_SEQ_SCAN_DISABLE;
1142   ADC_INJ_InitStruct->SequencerDiscont = LL_ADC_INJ_SEQ_DISCONT_DISABLE;
1143   ADC_INJ_InitStruct->TrigAuto         = LL_ADC_INJ_TRIG_INDEPENDENT;
1144 }
1145 
1146 /**
1147   * @}
1148   */
1149 
1150 /**
1151   * @}
1152   */
1153 
1154 /**
1155   * @}
1156   */
1157 
1158 #endif /* ADC1 || ADC2 || ADC3 */
1159 
1160 /**
1161   * @}
1162   */
1163 
1164 #endif /* USE_FULL_LL_DRIVER */
1165