1 /**
2   ******************************************************************************
3   * @file    stm32f3xx_ll_opamp.h
4   * @author  MCD Application Team
5   * @brief   Header file of OPAMP LL module.
6   ******************************************************************************
7   * @attention
8   *
9   * Copyright (c) 2016 STMicroelectronics.
10   * All rights reserved.
11   *
12   * This software is licensed under terms that can be found in the LICENSE file
13   * in the root directory of this software component.
14   * If no LICENSE file comes with this software, it is provided AS-IS.
15   *
16   ******************************************************************************
17   */
18 
19 /* Define to prevent recursive inclusion -------------------------------------*/
20 #ifndef STM32F3xx_LL_OPAMP_H
21 #define STM32F3xx_LL_OPAMP_H
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 /* Includes ------------------------------------------------------------------*/
28 #include "stm32f3xx.h"
29 
30 /** @addtogroup STM32F3xx_LL_Driver
31   * @{
32   */
33 
34 #if defined (OPAMP1) || defined (OPAMP2) || defined (OPAMP3) || defined (OPAMP4)
35 
36 /** @defgroup OPAMP_LL OPAMP
37   * @{
38   */
39 
40 /* Private types -------------------------------------------------------------*/
41 /* Private variables ---------------------------------------------------------*/
42 
43 /* Private constants ---------------------------------------------------------*/
44 /** @defgroup OPAMP_LL_Private_Constants OPAMP Private Constants
45   * @{
46   */
47 
48 /* Internal mask for OPAMP trimming of transistors differential pair NMOS     */
49 /* or PMOS.                                                                   */
50 /* To select into literal LL_OPAMP_TRIMMING_x the relevant bits for:          */
51 /* - OPAMP trimming selection of transistors differential pair                */
52 /* - OPAMP trimming values of transistors differential pair                   */
53 #define OPAMP_TRIMMING_SELECT_MASK          (OPAMP_CSR_CALSEL)
54 #define OPAMP_TRIMMING_VALUE_MASK           (OPAMP_CSR_TRIMOFFSETN | OPAMP_CSR_TRIMOFFSETP)
55 
56 /**
57   * @}
58   */
59 
60 
61 /* Private macros ------------------------------------------------------------*/
62 /** @defgroup OPAMP_LL_Private_Macros OPAMP Private Macros
63   * @{
64   */
65 
66 /**
67   * @brief  Driver macro reserved for internal use: set a pointer to
68   *         a register from a register basis from which an offset
69   *         is applied.
70   * @param  __REG__ Register basis from which the offset is applied.
71   * @param  __REG_OFFSET__ Offset to be applied (unit: number of registers).
72   * @retval Register address
73 */
74 #define __OPAMP_PTR_REG_OFFSET(__REG__, __REG_OFFSET__)                        \
75  ((uint32_t *)((uint32_t) ((uint32_t)(&(__REG__)) + ((__REG_OFFSET__) << 2U))))
76 
77 
78 
79 
80 /**
81   * @}
82   */
83 
84 
85 /* Exported types ------------------------------------------------------------*/
86 #if defined(USE_FULL_LL_DRIVER)
87 /** @defgroup OPAMP_LL_ES_INIT OPAMP Exported Init structure
88   * @{
89   */
90 
91 /**
92   * @brief  Structure definition of some features of OPAMP instance.
93   */
94 typedef struct
95 {
96   uint32_t FunctionalMode;              /*!< Set OPAMP functional mode by setting internal connections: OPAMP operation in standalone, follower, ...
97                                              This parameter can be a value of @ref OPAMP_LL_EC_FUNCTIONAL_MODE
98                                              @note If OPAMP is configured in mode PGA, the gain can be configured using function @ref LL_OPAMP_SetPGAGain().
99 
100                                              This feature can be modified afterwards using unitary function @ref LL_OPAMP_SetFunctionalMode(). */
101 
102   uint32_t InputNonInverting;           /*!< Set OPAMP input non-inverting connection.
103                                              This parameter can be a value of @ref OPAMP_LL_EC_INPUT_NONINVERTING
104 
105                                              This feature can be modified afterwards using unitary function @ref LL_OPAMP_SetInputNonInverting(). */
106 
107   uint32_t InputInverting;              /*!< Set OPAMP inverting input connection.
108                                              This parameter can be a value of @ref OPAMP_LL_EC_INPUT_INVERTING
109                                              @note OPAMP inverting input is used with OPAMP in mode standalone or PGA with external capacitors for filtering circuit. Otherwise (OPAMP in mode follower), OPAMP inverting input is not used (not connected to GPIO pin), this parameter is discarded.
110 
111                                              This feature can be modified afterwards using unitary function @ref LL_OPAMP_SetInputInverting(). */
112 
113 } LL_OPAMP_InitTypeDef;
114 
115 /**
116   * @}
117   */
118 #endif /* USE_FULL_LL_DRIVER */
119 
120 /* Exported constants --------------------------------------------------------*/
121 /** @defgroup OPAMP_LL_Exported_Constants OPAMP Exported Constants
122   * @{
123   */
124 
125 /** @defgroup OPAMP_LL_EC_MODE OPAMP mode calibration or functional.
126   * @{
127   */
128 #define LL_OPAMP_MODE_FUNCTIONAL        (0x00000000U)                               /*!< OPAMP functional mode */
129 #define LL_OPAMP_MODE_CALIBRATION       (OPAMP_CSR_CALON)                           /*!< OPAMP calibration mode */
130 /**
131   * @}
132   */
133 
134 /** @defgroup OPAMP_LL_EC_FUNCTIONAL_MODE OPAMP functional mode
135   * @{
136   */
137 #define LL_OPAMP_MODE_STANDALONE        (0x00000000U)                               /*!< OPAMP functional mode, OPAMP operation in standalone */
138 #define LL_OPAMP_MODE_FOLLOWER          (OPAMP_CSR_VMSEL_1 | OPAMP_CSR_VMSEL_0)     /*!< OPAMP functional mode, OPAMP operation in follower */
139 #define LL_OPAMP_MODE_PGA               (OPAMP_CSR_VMSEL_1)                         /*!< OPAMP functional mode, OPAMP operation in PGA */
140 #define LL_OPAMP_MODE_PGA_EXT_FILT_IO0  (OPAMP_CSR_PGGAIN_3                      | OPAMP_CSR_VMSEL_1) /*!< OPAMP functional mode, OPAMP operation in PGA with external filtering on OPAMP input IO0. */
141 #define LL_OPAMP_MODE_PGA_EXT_FILT_IO1  (OPAMP_CSR_PGGAIN_3 | OPAMP_CSR_PGGAIN_2 | OPAMP_CSR_VMSEL_1) /*!< OPAMP functional mode, OPAMP operation in PGA with external filtering on OPAMP input IO1. */
142 /**
143   * @}
144   */
145 
146 /** @defgroup OPAMP_LL_EC_MODE_PGA_GAIN OPAMP PGA gain (relevant when OPAMP is in functional mode PGA)
147   * @{
148   */
149 #define LL_OPAMP_PGA_GAIN_2             (0x00000000U)                              /*!< OPAMP PGA gain 2 */
150 #define LL_OPAMP_PGA_GAIN_4             (OPAMP_CSR_PGGAIN_0)                       /*!< OPAMP PGA gain 4 */
151 #define LL_OPAMP_PGA_GAIN_8             (OPAMP_CSR_PGGAIN_1)                       /*!< OPAMP PGA gain 8 */
152 #define LL_OPAMP_PGA_GAIN_16            (OPAMP_CSR_PGGAIN_1 | OPAMP_CSR_PGGAIN_0 ) /*!< OPAMP PGA gain 16 */
153 /**
154   * @}
155   */
156 
157 /** @defgroup OPAMP_LL_EC_INPUT_NONINVERTING OPAMP input non-inverting
158   * @{
159   */
160 #define LL_OPAMP_INPUT_NONINVERT_IO0      (OPAMP_CSR_VPSEL)       /*!< OPAMP non inverting input connected to GPIO pin (pin PA1 for OPAMP1, pin PA7  for OPAMP2, pin PB0  for OPAMP3, pin PB13 for OPAMP4) */
161 #define LL_OPAMP_INPUT_NONINVERT_IO1      (0x00000000)            /*!< OPAMP non inverting input connected to GPIO pin (pin PA7 for OPAMP1, pin PD14 for OPAMP2, pin PB13 for OPAMP3, pin PD11 for OPAMP4) */
162 #define LL_OPAMP_INPUT_NONINVERT_IO2      (OPAMP_CSR_VPSEL_1)     /*!< OPAMP non inverting input connected to GPIO pin (pin PA3 for OPAMP1, pin PB0  for OPAMP2, pin PA1  for OPAMP3, pin PA4  for OPAMP4) */
163 #define LL_OPAMP_INPUT_NONINVERT_IO3      (OPAMP_CSR_VPSEL_0)     /*!< OPAMP non inverting input connected to GPIO pin (pin PA5 for OPAMP1, pin PB14 for OPAMP2, pin PA5  for OPAMP3, pin PB11 for OPAMP4) */
164 #define LL_OPAMP_INPUT_NONINV_DAC1_CH1    (LL_OPAMP_INPUT_NONINVERT_IO3) /*!< OPAMP non inverting input connected to DAC1 channel1 output (specific to OPAMP instances: OPAMP4) */
165 #define LL_OPAMP_INPUT_NONINV_DAC1_CH2    (LL_OPAMP_INPUT_NONINVERT_IO3) /*!< OPAMP non inverting input connected to DAC1 channel2 output (specific to OPAMP instances: OPAMP1, OPAMP3) */
166 /**
167   * @}
168   */
169 
170 /** @defgroup OPAMP_LL_EC_INPUT_INVERTING OPAMP input inverting
171   * @{
172   */
173 #define LL_OPAMP_INPUT_INVERT_IO0        (0x00000000U)           /*!< OPAMP inverting input connected to GPIO pin (pin PC5 for OPAMP1, pin PC5 for OPAMP2, pin PB10  for OPAMP3, pin PB10 for OPAMP4). Note: OPAMP inverting input is used with OPAMP in mode standalone or PGA with external capacitors for filtering circuit. Otherwise (OPAMP in mode follower), OPAMP inverting input is not used (not connected to GPIO pin). */
174 #define LL_OPAMP_INPUT_INVERT_IO1        (OPAMP_CSR_VMSEL_0)     /*!< OPAMP inverting input connected to GPIO pin (pin PA3 for OPAMP1, pin PA5 for OPAMP2, pin PB2   for OPAMP3, pin PD8  for OPAMP4). Note: OPAMP inverting input is used with OPAMP in mode standalone or PGA with external capacitors for filtering circuit. Otherwise (OPAMP in mode follower), OPAMP inverting input is not used (not connected to GPIO pin). */
175 #define LL_OPAMP_INPUT_INVERT_CONNECT_NO (OPAMP_CSR_VMSEL_1)     /*!< OPAMP inverting input not externally connected (intended for OPAMP in mode follower or PGA without external capacitors for filtering). Note: On this STM32 series, this literal include cases of value 0x11 for mode follower and value 0x10 for mode PGA. */
176 /**
177   * @}
178   */
179 
180 /** @defgroup OPAMP_LL_EC_INPUT_NONINVERTING_SECONDARY OPAMP input non-inverting secondary
181   * @{
182   */
183 #define LL_OPAMP_INPUT_NONINVERT_IO0_SEC   (LL_OPAMP_INPUT_NONINVERT_IO0   << (OPAMP_CSR_VPSSEL_Pos - OPAMP_CSR_VPSEL_Pos)) /*!< OPAMP non inverting input secondary connected to GPIO pin (pin PA1 for OPAMP1, pin PA7  for OPAMP2, pin PB0  for OPAMP3, pin PB13 for OPAMP4) */
184 #define LL_OPAMP_INPUT_NONINVERT_IO1_SEC   (LL_OPAMP_INPUT_NONINVERT_IO1   << (OPAMP_CSR_VPSSEL_Pos - OPAMP_CSR_VPSEL_Pos)) /*!< OPAMP non inverting input secondary connected to GPIO pin (pin PA7 for OPAMP1, pin PD14 for OPAMP2, pin PB13 for OPAMP3, pin PD11 for OPAMP4) */
185 #define LL_OPAMP_INPUT_NONINVERT_IO2_SEC   (LL_OPAMP_INPUT_NONINVERT_IO2   << (OPAMP_CSR_VPSSEL_Pos - OPAMP_CSR_VPSEL_Pos)) /*!< OPAMP non inverting input secondary connected to GPIO pin (pin PA3 for OPAMP1, pin PB0  for OPAMP2, pin PA1  for OPAMP3, pin PB11 for OPAMP4) */
186 #define LL_OPAMP_INPUT_NONINVERT_IO3_SEC   (LL_OPAMP_INPUT_NONINVERT_IO3   << (OPAMP_CSR_VPSSEL_Pos - OPAMP_CSR_VPSEL_Pos)) /*!< OPAMP non inverting input secondary connected to GPIO pin (pin PA5 for OPAMP1, pin PD14 for OPAMP2, pin PA5  for OPAMP3, pin PA4  for OPAMP4) */
187 #define LL_OPAMP_INPUT_NONINV_DAC1_CH1_SEC (LL_OPAMP_INPUT_NONINV_DAC1_CH1 << (OPAMP_CSR_VPSSEL_Pos - OPAMP_CSR_VPSEL_Pos)) /*!< OPAMP non inverting input secondary connected to DAC1 channel1 output (specific to OPAMP instances: OPAMP4) */
188 #define LL_OPAMP_INPUT_NONINV_DAC1_CH2_SEC (LL_OPAMP_INPUT_NONINV_DAC1_CH2 << (OPAMP_CSR_VPSSEL_Pos - OPAMP_CSR_VPSEL_Pos)) /*!< OPAMP non inverting input secondary connected to DAC1 channel2 output (specific to OPAMP instances: OPAMP1, OPAMP3) */
189 
190 /**
191   * @}
192   */
193 
194 /** @defgroup OPAMP_LL_EC_INPUT_INVERTING_SECONDARY OPAMP input inverting secondary
195   * @{
196   */
197 #define LL_OPAMP_INPUT_INVERT_IO0_SEC    (LL_OPAMP_INPUT_INVERT_IO0 << (OPAMP_CSR_VMSSEL_Pos - OPAMP_CSR_VMSEL_Pos)) /*!< OPAMP inverting input secondary connected to GPIO pin (pin PC5 for OPAMP1, pin PC5 for OPAMP2, pin PB10  for OPAMP3, pin PB10 for OPAMP4). Note: OPAMP inverting input is used with OPAMP in mode standalone or PGA with external capacitors for filtering circuit. Otherwise (OPAMP in mode follower), OPAMP inverting input is not used (not connected to GPIO pin). */
198 #define LL_OPAMP_INPUT_INVERT_IO1_SEC    (LL_OPAMP_INPUT_INVERT_IO1 << (OPAMP_CSR_VMSSEL_Pos - OPAMP_CSR_VMSEL_Pos)) /*!< OPAMP inverting input secondary connected to GPIO pin (pin PA3 for OPAMP1, pin PA5 for OPAMP2, pin PB2   for OPAMP3, pin PD8  for OPAMP4). Note: OPAMP inverting input is used with OPAMP in mode standalone or PGA with external capacitors for filtering circuit. Otherwise (OPAMP in mode follower), OPAMP inverting input is not used (not connected to GPIO pin). */
199 /**
200   * @}
201   */
202 
203 /** @defgroup OPAMP_LL_EC_INPUT_MUX_MODE OPAMP inputs multiplexer mode
204   * @{
205   */
206 #define LL_OPAMP_INPUT_MUX_DISABLE     (0x00000000U)            /*!< OPAMP inputs multiplexer mode dosabled. */
207 #define LL_OPAMP_INPUT_MUX_TIM1_CH6    (OPAMP_CSR_TCMEN)        /*!< OPAMP inputs multiplexer mode enabled, controlled by TIM1 CC6. */
208 /**
209   * @}
210   */
211 
212 /** @defgroup OPAMP_LL_EC_VREF_OUTPUT OPAMP internal reference voltage path state to output
213   * @{
214   */
215 #define LL_OPAMP_VREF_OUTPUT_DISABLE    (0x00000000U)            /*!< OPAMP internal reference voltage path to output is disabled. */
216 #define LL_OPAMP_VREF_OUTPUT_ENABLE     (OPAMP_CSR_TSTREF)       /*!< OPAMP internal reference voltage path to output is enabled. */
217 /**
218   * @}
219   */
220 
221 /** @defgroup OPAMP_LL_EC_TRIMMING_MODE OPAMP trimming mode
222   * @{
223   */
224 #define LL_OPAMP_TRIMMING_FACTORY       (0x00000000U)           /*!< OPAMP trimming factors set to factory values */
225 #define LL_OPAMP_TRIMMING_USER          (OPAMP_CSR_USERTRIM)    /*!< OPAMP trimming factors set to user values */
226 /**
227   * @}
228   */
229 
230 /** @defgroup OPAMP_LL_EC_TRIMMING_TRANSISTORS_DIFF_PAIR OPAMP trimming of transistors differential pair NMOS or PMOS
231   * @{
232   */
233 #define LL_OPAMP_TRIMMING_NMOS_VREF_90PC_VDDA  (OPAMP_CSR_TRIMOFFSETN | OPAMP_CSR_CALSEL_1 | OPAMP_CSR_CALSEL_0) /*!< OPAMP trimming of transistors differential pair NMOS (internal reference voltage set to 0.9*Vdda). Default parameters to be used for calibration using two trimming steps (one with each transistors differential pair NMOS and PMOS). */
234 #define LL_OPAMP_TRIMMING_NMOS_VREF_50PC_VDDA  (OPAMP_CSR_TRIMOFFSETN | OPAMP_CSR_CALSEL_1                     ) /*!< OPAMP trimming of transistors differential pair NMOS (internal reference voltage set to 0.5*Vdda). */
235 #define LL_OPAMP_TRIMMING_PMOS_VREF_10PC_VDDA  (OPAMP_CSR_TRIMOFFSETP                      | OPAMP_CSR_CALSEL_0) /*!< OPAMP trimming of transistors differential pair PMOS (internal reference voltage set to 0.1*Vdda). Default parameters to be used for calibration using two trimming steps (one with each transistors differential pair NMOS and PMOS). */
236 #define LL_OPAMP_TRIMMING_PMOS_VREF_3_3PC_VDDA (OPAMP_CSR_TRIMOFFSETP                                          ) /*!< OPAMP trimming of transistors differential pair PMOS (internal reference voltage set to 0.33*Vdda). */
237 #define LL_OPAMP_TRIMMING_NMOS          (LL_OPAMP_TRIMMING_NMOS_VREF_90PC_VDDA) /*!< OPAMP trimming of transistors differential pair NMOS (internal reference voltage set to 0.9*Vdda). Default parameters to be used for calibration using two trimming steps (one with each transistors differential pair NMOS and PMOS). */
238 #define LL_OPAMP_TRIMMING_PMOS          (LL_OPAMP_TRIMMING_PMOS_VREF_10PC_VDDA) /*!< OPAMP trimming of transistors differential pair PMOS (internal reference voltage set to 0.1*Vdda). Default parameters to be used for calibration using two trimming steps (one with each transistors differential pair NMOS and PMOS). */
239 /**
240   * @}
241   */
242 
243 /** @defgroup OPAMP_LL_EC_HW_DELAYS  Definitions of OPAMP hardware constraints delays
244   * @note   Only OPAMP peripheral HW delays are defined in OPAMP LL driver driver,
245   *         not timeout values.
246   *         For details on delays values, refer to descriptions in source code
247   *         above each literal definition.
248   * @{
249   */
250 
251 /* Delay for OPAMP startup time (transition from state disable to enable).    */
252 /* Note: OPAMP startup time depends on board application environment:         */
253 /*       impedance connected to OPAMP output.                                 */
254 /*       The delay below is specified under conditions:                       */
255 /*        - OPAMP in functional mode follower                                 */
256 /*        - load impedance of 4kOhm (min), 50pF (max)                         */
257 /* Literal set to maximum value (refer to device datasheet,                   */
258 /* parameter "tWAKEUP").                                                      */
259 /* Unit: us                                                                   */
260 #define LL_OPAMP_DELAY_STARTUP_US         (5U)  /*!< Delay for OPAMP startup time */
261 
262 /**
263   * @}
264   */
265 
266 /**
267   * @}
268   */
269 
270 /* Exported macro ------------------------------------------------------------*/
271 /** @defgroup OPAMP_LL_Exported_Macros OPAMP Exported Macros
272   * @{
273   */
274 /** @defgroup OPAMP_LL_EM_WRITE_READ Common write and read registers macro
275   * @{
276   */
277 /**
278   * @brief  Write a value in OPAMP register
279   * @param  __INSTANCE__ OPAMP Instance
280   * @param  __REG__ Register to be written
281   * @param  __VALUE__ Value to be written in the register
282   * @retval None
283   */
284 #define LL_OPAMP_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG((__INSTANCE__)->__REG__, (__VALUE__))
285 
286 /**
287   * @brief  Read a value in OPAMP register
288   * @param  __INSTANCE__ OPAMP Instance
289   * @param  __REG__ Register to be read
290   * @retval Register value
291   */
292 #define LL_OPAMP_ReadReg(__INSTANCE__, __REG__) READ_REG((__INSTANCE__)->__REG__)
293 /**
294   * @}
295   */
296 
297 /**
298   * @}
299   */
300 
301 /* Exported functions --------------------------------------------------------*/
302 /** @defgroup OPAMP_LL_Exported_Functions OPAMP Exported Functions
303   * @{
304   */
305 
306 /** @defgroup OPAMP_LL_EF_CONFIGURATION_OPAMP_INSTANCE Configuration of OPAMP hierarchical scope: OPAMP instance
307   * @{
308   */
309 
310 /**
311   * @brief  Set OPAMP mode calibration or functional.
312   * @note   OPAMP mode corresponds to functional or calibration mode:
313   *          - functional mode: OPAMP operation in standalone, follower, ...
314   *            Set functional mode using function
315   *            @ref LL_OPAMP_SetFunctionalMode().
316   *          - calibration mode: offset calibration of the selected
317   *            transistors differential pair NMOS or PMOS.
318   * @rmtoll CSR      CALON          LL_OPAMP_SetMode
319   * @param  OPAMPx OPAMP instance
320   * @param  Mode This parameter can be one of the following values:
321   *         @arg @ref LL_OPAMP_MODE_FUNCTIONAL
322   *         @arg @ref LL_OPAMP_MODE_CALIBRATION
323   * @retval None
324   */
LL_OPAMP_SetMode(OPAMP_TypeDef * OPAMPx,uint32_t Mode)325 __STATIC_INLINE void LL_OPAMP_SetMode(OPAMP_TypeDef *OPAMPx, uint32_t Mode)
326 {
327   MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_CALON, Mode);
328 }
329 
330 /**
331   * @brief  Get OPAMP mode calibration or functional.
332   * @note   OPAMP mode corresponds to functional or calibration mode:
333   *          - functional mode: OPAMP operation in standalone, follower, ...
334   *            Set functional mode using function
335   *            @ref LL_OPAMP_SetFunctionalMode().
336   *          - calibration mode: offset calibration of the selected
337   *            transistors differential pair NMOS or PMOS.
338   * @rmtoll CSR      CALON          LL_OPAMP_GetMode
339   * @param  OPAMPx OPAMP instance
340   * @retval Returned value can be one of the following values:
341   *         @arg @ref LL_OPAMP_MODE_FUNCTIONAL
342   *         @arg @ref LL_OPAMP_MODE_CALIBRATION
343   */
LL_OPAMP_GetMode(OPAMP_TypeDef * OPAMPx)344 __STATIC_INLINE uint32_t LL_OPAMP_GetMode(OPAMP_TypeDef *OPAMPx)
345 {
346   return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_CALON));
347 }
348 
349 /**
350   * @brief  Set OPAMP functional mode by setting internal connections.
351   *         OPAMP operation in standalone, follower, ...
352   * @note   This function reset bit of calibration mode to ensure
353   *         to be in functional mode, in order to have OPAMP parameters
354   *         (inputs selection, ...) set with the corresponding OPAMP mode
355   *         to be effective.
356   * @rmtoll CSR      VMSEL          LL_OPAMP_SetFunctionalMode
357   * @param  OPAMPx OPAMP instance
358   * @param  FunctionalMode This parameter can be one of the following values:
359   *         @arg @ref LL_OPAMP_MODE_STANDALONE
360   *         @arg @ref LL_OPAMP_MODE_FOLLOWER
361   *         @arg @ref LL_OPAMP_MODE_PGA
362   *         @arg @ref LL_OPAMP_MODE_PGA_EXT_FILT_IO0
363   *         @arg @ref LL_OPAMP_MODE_PGA_EXT_FILT_IO1
364   * @retval None
365   */
LL_OPAMP_SetFunctionalMode(OPAMP_TypeDef * OPAMPx,uint32_t FunctionalMode)366 __STATIC_INLINE void LL_OPAMP_SetFunctionalMode(OPAMP_TypeDef *OPAMPx, uint32_t FunctionalMode)
367 {
368   /* Note: Bit OPAMP_CSR_CALON reset to ensure to be in functional mode */
369   MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_PGGAIN_3 | OPAMP_CSR_PGGAIN_2 | OPAMP_CSR_VMSEL | OPAMP_CSR_CALON, FunctionalMode);
370 }
371 
372 /**
373   * @brief  Get OPAMP functional mode from setting of internal connections.
374   *         OPAMP operation in standalone, follower, ...
375   * @rmtoll CSR      VMSEL          LL_OPAMP_GetFunctionalMode
376   * @param  OPAMPx OPAMP instance
377   * @retval Returned value can be one of the following values:
378   *         @arg @ref LL_OPAMP_MODE_STANDALONE
379   *         @arg @ref LL_OPAMP_MODE_FOLLOWER
380   *         @arg @ref LL_OPAMP_MODE_PGA
381   *         @arg @ref LL_OPAMP_MODE_PGA_EXT_FILT_IO0
382   *         @arg @ref LL_OPAMP_MODE_PGA_EXT_FILT_IO1
383   */
LL_OPAMP_GetFunctionalMode(OPAMP_TypeDef * OPAMPx)384 __STATIC_INLINE uint32_t LL_OPAMP_GetFunctionalMode(OPAMP_TypeDef *OPAMPx)
385 {
386   return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_PGGAIN_3 | OPAMP_CSR_PGGAIN_2 | OPAMP_CSR_VMSEL));
387 }
388 
389 /**
390   * @brief  Set OPAMP PGA gain.
391   * @note   Preliminarily, OPAMP must be set in mode PGA
392   *         using function @ref LL_OPAMP_SetFunctionalMode().
393   * @rmtoll CSR      PGGAIN         LL_OPAMP_SetPGAGain
394   * @param  OPAMPx OPAMP instance
395   * @param  PGAGain This parameter can be one of the following values:
396   *         @arg @ref LL_OPAMP_PGA_GAIN_2
397   *         @arg @ref LL_OPAMP_PGA_GAIN_4
398   *         @arg @ref LL_OPAMP_PGA_GAIN_8
399   *         @arg @ref LL_OPAMP_PGA_GAIN_16
400   * @retval None
401   */
LL_OPAMP_SetPGAGain(OPAMP_TypeDef * OPAMPx,uint32_t PGAGain)402 __STATIC_INLINE void LL_OPAMP_SetPGAGain(OPAMP_TypeDef *OPAMPx, uint32_t PGAGain)
403 {
404   MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_PGGAIN_1 | OPAMP_CSR_PGGAIN_0, PGAGain);
405 }
406 
407 /**
408   * @brief  Get OPAMP PGA gain.
409   * @note   Preliminarily, OPAMP must be set in mode PGA
410   *         using function @ref LL_OPAMP_SetFunctionalMode().
411   * @rmtoll CSR      PGGAIN         LL_OPAMP_GetPGAGain
412   * @param  OPAMPx OPAMP instance
413   * @retval Returned value can be one of the following values:
414   *         @arg @ref LL_OPAMP_PGA_GAIN_2
415   *         @arg @ref LL_OPAMP_PGA_GAIN_4
416   *         @arg @ref LL_OPAMP_PGA_GAIN_8
417   *         @arg @ref LL_OPAMP_PGA_GAIN_16
418   */
LL_OPAMP_GetPGAGain(OPAMP_TypeDef * OPAMPx)419 __STATIC_INLINE uint32_t LL_OPAMP_GetPGAGain(OPAMP_TypeDef *OPAMPx)
420 {
421   return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_PGGAIN_1 | OPAMP_CSR_PGGAIN_0));
422 }
423 
424 /**
425   * @}
426   */
427 
428 /** @defgroup OPAMP_LL_EF_CONFIGURATION_INPUTS Configuration of OPAMP inputs
429   * @{
430   */
431 
432 /**
433   * @brief  Set OPAMP non-inverting input connection.
434   * @rmtoll CSR      VPSEL          LL_OPAMP_SetInputNonInverting
435   * @param  OPAMPx OPAMP instance
436   * @param  InputNonInverting This parameter can be one of the following values:
437   *         @arg @ref LL_OPAMP_INPUT_NONINVERT_IO0
438   *         @arg @ref LL_OPAMP_INPUT_NONINVERT_IO1
439   *         @arg @ref LL_OPAMP_INPUT_NONINVERT_IO2
440   *         @arg @ref LL_OPAMP_INPUT_NONINVERT_IO3
441   *         @arg @ref LL_OPAMP_INPUT_NONINV_DAC1_CH1 (1)
442   *         @arg @ref LL_OPAMP_INPUT_NONINV_DAC1_CH2 (2)
443   *
444   *         (1) Parameter specific to OPAMP instances: OPAMP4.\n
445   *         (2) Parameter specific to OPAMP instances: OPAMP1, OPAMP3.
446   * @retval None
447   */
LL_OPAMP_SetInputNonInverting(OPAMP_TypeDef * OPAMPx,uint32_t InputNonInverting)448 __STATIC_INLINE void LL_OPAMP_SetInputNonInverting(OPAMP_TypeDef *OPAMPx, uint32_t InputNonInverting)
449 {
450   MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_VPSEL, InputNonInverting);
451 }
452 
453 /**
454   * @brief  Get OPAMP non-inverting input connection.
455   * @rmtoll CSR      VPSEL          LL_OPAMP_GetInputNonInverting
456   * @param  OPAMPx OPAMP instance
457   * @retval Returned value can be one of the following values:
458   *         @arg @ref LL_OPAMP_INPUT_NONINVERT_IO0
459   *         @arg @ref LL_OPAMP_INPUT_NONINVERT_IO1
460   *         @arg @ref LL_OPAMP_INPUT_NONINVERT_IO2
461   *         @arg @ref LL_OPAMP_INPUT_NONINVERT_IO3
462   *         @arg @ref LL_OPAMP_INPUT_NONINV_DAC1_CH1 (1)
463   *         @arg @ref LL_OPAMP_INPUT_NONINV_DAC1_CH2 (2)
464   *
465   *         (1) Parameter specific to OPAMP instances: OPAMP4.\n
466   *         (2) Parameter specific to OPAMP instances: OPAMP1, OPAMP3.
467   */
LL_OPAMP_GetInputNonInverting(OPAMP_TypeDef * OPAMPx)468 __STATIC_INLINE uint32_t LL_OPAMP_GetInputNonInverting(OPAMP_TypeDef *OPAMPx)
469 {
470   return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_VPSEL));
471 }
472 
473 /**
474   * @brief  Set OPAMP inverting input connection.
475   * @note   OPAMP inverting input is used with OPAMP in mode standalone
476   *         or PGA with external capacitors for filtering circuit.
477   *         Otherwise (OPAMP in mode follower), OPAMP inverting input
478   *         is not used (not connected to GPIO pin).
479   * @rmtoll CSR      VMSEL          LL_OPAMP_SetInputInverting
480   * @param  OPAMPx OPAMP instance
481   * @param  InputInverting This parameter can be one of the following values:
482   *         @arg @ref LL_OPAMP_INPUT_INVERT_IO0
483   *         @arg @ref LL_OPAMP_INPUT_INVERT_IO1
484   *         @arg @ref LL_OPAMP_INPUT_INVERT_CONNECT_NO
485   * @retval None
486   */
LL_OPAMP_SetInputInverting(OPAMP_TypeDef * OPAMPx,uint32_t InputInverting)487 __STATIC_INLINE void LL_OPAMP_SetInputInverting(OPAMP_TypeDef *OPAMPx, uint32_t InputInverting)
488 {
489   /* Manage cases of OPAMP inverting input not connected (0x10 and 0x11)      */
490   /* to not modify OPAMP mode follower or PGA.                                */
491   /* Bit OPAMP_CSR_VMSEL_1 is set by OPAMP mode (follower, PGA). */
492   MODIFY_REG(OPAMPx->CSR, (~(InputInverting >> 1)) & OPAMP_CSR_VMSEL_0, InputInverting);
493 }
494 
495 /**
496   * @brief  Get OPAMP inverting input connection.
497   * @rmtoll CSR      VMSEL          LL_OPAMP_GetInputInverting
498   * @param  OPAMPx OPAMP instance
499   * @retval Returned value can be one of the following values:
500   *         @arg @ref LL_OPAMP_INPUT_INVERT_IO0
501   *         @arg @ref LL_OPAMP_INPUT_INVERT_IO1
502   *         @arg @ref LL_OPAMP_INPUT_INVERT_CONNECT_NO
503   */
LL_OPAMP_GetInputInverting(OPAMP_TypeDef * OPAMPx)504 __STATIC_INLINE uint32_t LL_OPAMP_GetInputInverting(OPAMP_TypeDef *OPAMPx)
505 {
506   uint32_t input_inverting = READ_BIT(OPAMPx->CSR, OPAMP_CSR_VMSEL);
507 
508   /* Manage cases 0x10 and 0x11 to return the same value: OPAMP inverting     */
509   /* input not connected.                                                     */
510   return (input_inverting & ~((input_inverting >> 1) & OPAMP_CSR_VMSEL_0));
511 }
512 
513 /**
514   * @brief  Set OPAMP non-inverting input secondary connection.
515   * @rmtoll CSR      VPSSEL         LL_OPAMP_SetInputNonInvertingSecondary
516   * @param  OPAMPx OPAMP instance
517   * @param  InputNonInverting This parameter can be one of the following values:
518   *         @arg @ref LL_OPAMP_INPUT_NONINVERT_IO0_SEC
519   *         @arg @ref LL_OPAMP_INPUT_NONINVERT_IO1_SEC
520   *         @arg @ref LL_OPAMP_INPUT_NONINVERT_IO2_SEC
521   *         @arg @ref LL_OPAMP_INPUT_NONINVERT_IO3_SEC
522   *         @arg @ref LL_OPAMP_INPUT_NONINV_DAC1_CH1_SEC (1)
523   *         @arg @ref LL_OPAMP_INPUT_NONINV_DAC1_CH2_SEC (2)
524   *
525   *         (1) Parameter specific to OPAMP instances: OPAMP4.\n
526   *         (2) Parameter specific to OPAMP instances: OPAMP1, OPAMP3.
527   * @retval None
528   */
LL_OPAMP_SetInputNonInvertingSecondary(OPAMP_TypeDef * OPAMPx,uint32_t InputNonInverting)529 __STATIC_INLINE void LL_OPAMP_SetInputNonInvertingSecondary(OPAMP_TypeDef *OPAMPx, uint32_t InputNonInverting)
530 {
531   MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_VPSSEL, InputNonInverting);
532 }
533 
534 /**
535   * @brief  Get OPAMP non-inverting input secondary connection.
536   * @rmtoll CSR      VPSSEL         LL_OPAMP_GetInputNonInvertingSecondary
537   * @param  OPAMPx OPAMP instance
538   * @retval Returned value can be one of the following values:
539   *         @arg @ref LL_OPAMP_INPUT_NONINVERT_IO0_SEC
540   *         @arg @ref LL_OPAMP_INPUT_NONINVERT_IO1_SEC
541   *         @arg @ref LL_OPAMP_INPUT_NONINVERT_IO2_SEC
542   *         @arg @ref LL_OPAMP_INPUT_NONINVERT_IO3_SEC
543   *         @arg @ref LL_OPAMP_INPUT_NONINV_DAC1_CH1_SEC (1)
544   *         @arg @ref LL_OPAMP_INPUT_NONINV_DAC1_CH2_SEC (2)
545   *
546   *         (1) Parameter specific to OPAMP instances: OPAMP4.\n
547   *         (2) Parameter specific to OPAMP instances: OPAMP1, OPAMP3.
548   */
LL_OPAMP_GetInputNonInvertingSecondary(OPAMP_TypeDef * OPAMPx)549 __STATIC_INLINE uint32_t LL_OPAMP_GetInputNonInvertingSecondary(OPAMP_TypeDef *OPAMPx)
550 {
551   return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_VPSSEL));
552 }
553 
554 /**
555   * @brief  Set OPAMP inverting input secondary connection.
556   * @note   OPAMP inverting input is used with OPAMP in mode standalone
557   *         or PGA with external capacitors for filtering circuit.
558   *         Otherwise (OPAMP in mode follower), OPAMP inverting input
559   *         is not used (not connected to GPIO pin).
560   * @rmtoll CSR      VMSSEL         LL_OPAMP_SetInputInvertingSecondary
561   * @param  OPAMPx OPAMP instance
562   * @param  InputInverting This parameter can be one of the following values:
563   *         @arg @ref LL_OPAMP_INPUT_INVERT_IO0_SEC
564   *         @arg @ref LL_OPAMP_INPUT_INVERT_IO1_SEC
565   * @retval None
566   */
LL_OPAMP_SetInputInvertingSecondary(OPAMP_TypeDef * OPAMPx,uint32_t InputInverting)567 __STATIC_INLINE void LL_OPAMP_SetInputInvertingSecondary(OPAMP_TypeDef *OPAMPx, uint32_t InputInverting)
568 {
569   MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_VMSSEL, InputInverting);
570 }
571 
572 /**
573   * @brief  Get OPAMP inverting input secondary connection.
574   * @rmtoll CSR      VMSSEL         LL_OPAMP_GetInputInvertingSecondary
575   * @param  OPAMPx OPAMP instance
576   * @retval Returned value can be one of the following values:
577   *         @arg @ref LL_OPAMP_INPUT_INVERT_IO0_SEC
578   *         @arg @ref LL_OPAMP_INPUT_INVERT_IO1_SEC
579   */
LL_OPAMP_GetInputInvertingSecondary(OPAMP_TypeDef * OPAMPx)580 __STATIC_INLINE uint32_t LL_OPAMP_GetInputInvertingSecondary(OPAMP_TypeDef *OPAMPx)
581 {
582   return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_VMSSEL));
583 }
584 
585 /**
586   * @brief  Set OPAMP inputs multiplexer mode.
587   * @rmtoll CSR      TCMEN          LL_OPAMP_SetInputsMuxMode
588   * @param  OPAMPx OPAMP instance
589   * @param  InputsMuxMode This parameter can be one of the following values:
590   *         @arg @ref LL_OPAMP_INPUT_MUX_DISABLE
591   *         @arg @ref LL_OPAMP_INPUT_MUX_TIM1_CH6
592   * @retval None
593   */
LL_OPAMP_SetInputsMuxMode(OPAMP_TypeDef * OPAMPx,uint32_t InputsMuxMode)594 __STATIC_INLINE void LL_OPAMP_SetInputsMuxMode(OPAMP_TypeDef *OPAMPx, uint32_t InputsMuxMode)
595 {
596   MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_TCMEN, InputsMuxMode);
597 }
598 
599 /**
600   * @brief  Get OPAMP inputs multiplexer mode.
601   * @rmtoll CSR      TCMEN          LL_OPAMP_GetInputsMuxMode
602   * @param  OPAMPx OPAMP instance
603   * @retval Returned value can be one of the following values:
604   *         @arg @ref LL_OPAMP_INPUT_MUX_DISABLE
605   *         @arg @ref LL_OPAMP_INPUT_MUX_TIM1_CH6
606   */
LL_OPAMP_GetInputsMuxMode(OPAMP_TypeDef * OPAMPx)607 __STATIC_INLINE uint32_t LL_OPAMP_GetInputsMuxMode(OPAMP_TypeDef *OPAMPx)
608 {
609   return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_TCMEN));
610 }
611 
612 /**
613   * @}
614   */
615 
616 /** @defgroup OPAMP_LL_EF_OPAMP_TRIMMING Configuration and operation of OPAMP trimming
617   * @{
618   */
619 
620 /**
621   * @brief  Set OPAMP trimming mode.
622   * @rmtoll CSR      USERTRIM       LL_OPAMP_SetTrimmingMode
623   * @param  OPAMPx OPAMP instance
624   * @param  TrimmingMode This parameter can be one of the following values:
625   *         @arg @ref LL_OPAMP_TRIMMING_FACTORY
626   *         @arg @ref LL_OPAMP_TRIMMING_USER
627   * @retval None
628   */
LL_OPAMP_SetTrimmingMode(OPAMP_TypeDef * OPAMPx,uint32_t TrimmingMode)629 __STATIC_INLINE void LL_OPAMP_SetTrimmingMode(OPAMP_TypeDef *OPAMPx, uint32_t TrimmingMode)
630 {
631   MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_USERTRIM, TrimmingMode);
632 }
633 
634 /**
635   * @brief  Get OPAMP trimming mode.
636   * @rmtoll CSR      USERTRIM       LL_OPAMP_GetTrimmingMode
637   * @param  OPAMPx OPAMP instance
638   * @retval Returned value can be one of the following values:
639   *         @arg @ref LL_OPAMP_TRIMMING_FACTORY
640   *         @arg @ref LL_OPAMP_TRIMMING_USER
641   */
LL_OPAMP_GetTrimmingMode(OPAMP_TypeDef * OPAMPx)642 __STATIC_INLINE uint32_t LL_OPAMP_GetTrimmingMode(OPAMP_TypeDef *OPAMPx)
643 {
644   return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_USERTRIM));
645 }
646 
647 /**
648   * @brief  Set OPAMP offset to calibrate the selected transistors
649   *         differential pair NMOS or PMOS.
650   * @note   Preliminarily, OPAMP must be set in mode calibration
651   *         using function @ref LL_OPAMP_SetMode().
652   * @rmtoll CSR      CALSEL         LL_OPAMP_SetCalibrationSelection
653   * @param  OPAMPx OPAMP instance
654   * @param  TransistorsDiffPair This parameter can be one of the following values:
655   *         @arg @ref LL_OPAMP_TRIMMING_NMOS            (1)
656   *         @arg @ref LL_OPAMP_TRIMMING_PMOS            (1)
657   *         @arg @ref LL_OPAMP_TRIMMING_NMOS_VREF_50PC_VDDA
658   *         @arg @ref LL_OPAMP_TRIMMING_PMOS_VREF_3_3PC_VDDA
659   *
660   *         (1) Default parameters to be used for calibration
661   *             using two trimming steps (one with each transistors differential
662   *             pair NMOS and PMOS)
663   * @retval None
664   */
LL_OPAMP_SetCalibrationSelection(OPAMP_TypeDef * OPAMPx,uint32_t TransistorsDiffPair)665 __STATIC_INLINE void LL_OPAMP_SetCalibrationSelection(OPAMP_TypeDef *OPAMPx, uint32_t TransistorsDiffPair)
666 {
667   /* Parameter used with mask "OPAMP_TRIMMING_SELECT_MASK" because            */
668   /* containing other bits reserved for other purpose.                        */
669   MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_CALSEL, (TransistorsDiffPair & OPAMP_TRIMMING_SELECT_MASK));
670 }
671 
672 /**
673   * @brief  Get OPAMP offset to calibrate the selected transistors
674   *         differential pair NMOS or PMOS.
675   * @note   Preliminarily, OPAMP must be set in mode calibration
676   *         using function @ref LL_OPAMP_SetMode().
677   * @rmtoll CSR      CALSEL         LL_OPAMP_GetCalibrationSelection
678   * @param  OPAMPx OPAMP instance
679   * @retval Returned value can be one of the following values:
680   *         @arg @ref LL_OPAMP_TRIMMING_NMOS            (1)
681   *         @arg @ref LL_OPAMP_TRIMMING_PMOS            (1)
682   *         @arg @ref LL_OPAMP_TRIMMING_NMOS_VREF_50PC_VDDA
683   *         @arg @ref LL_OPAMP_TRIMMING_PMOS_VREF_3_3PC_VDDA
684   *
685   *         (1) Default parameters to be used for calibration
686   *             using two trimming steps (one with each transistors differential
687   *             pair NMOS and PMOS)
688   */
LL_OPAMP_GetCalibrationSelection(OPAMP_TypeDef * OPAMPx)689 __STATIC_INLINE uint32_t LL_OPAMP_GetCalibrationSelection(OPAMP_TypeDef *OPAMPx)
690 {
691   uint32_t CalibrationSelection = (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_CALSEL));
692 
693   return (CalibrationSelection |
694           (((CalibrationSelection & OPAMP_CSR_CALSEL) == 0UL) ? OPAMP_CSR_TRIMOFFSETN : OPAMP_CSR_TRIMOFFSETP));
695 }
696 
697 /**
698   * @brief  Set OPAMP calibration internal reference voltage to output.
699   * @rmtoll CSR      TSTREF         LL_OPAMP_SetCalibrationVrefOutput
700   * @param  OPAMPx OPAMP instance
701   * @param  CalibrationVrefOutput This parameter can be one of the following values:
702   *         @arg @ref LL_OPAMP_VREF_OUTPUT_DISABLE
703   *         @arg @ref LL_OPAMP_VREF_OUTPUT_ENABLE
704   * @retval None
705   */
LL_OPAMP_SetCalibrationVrefOutput(OPAMP_TypeDef * OPAMPx,uint32_t CalibrationVrefOutput)706 __STATIC_INLINE void LL_OPAMP_SetCalibrationVrefOutput(OPAMP_TypeDef *OPAMPx, uint32_t CalibrationVrefOutput)
707 {
708   MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_TSTREF, CalibrationVrefOutput);
709 }
710 
711 /**
712   * @brief  Get OPAMP calibration internal reference voltage to output.
713   * @rmtoll CSR      TSTREF         LL_OPAMP_GetCalibrationVrefOutput
714   * @param  OPAMPx OPAMP instance
715   * @retval Returned value can be one of the following values:
716   *         @arg @ref LL_OPAMP_VREF_OUTPUT_DISABLE
717   *         @arg @ref LL_OPAMP_VREF_OUTPUT_ENABLE
718   */
LL_OPAMP_GetCalibrationVrefOutput(OPAMP_TypeDef * OPAMPx)719 __STATIC_INLINE uint32_t LL_OPAMP_GetCalibrationVrefOutput(OPAMP_TypeDef *OPAMPx)
720 {
721   return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_TSTREF));
722 }
723 
724 /**
725   * @brief  Get OPAMP calibration result of toggling output.
726   * @note   This functions returns:
727   *         0 if OPAMP calibration output is reset
728   *         1 if OPAMP calibration output is set
729   * @rmtoll CSR      OUTCAL         LL_OPAMP_IsCalibrationOutputSet
730   * @param  OPAMPx OPAMP instance
731   * @retval State of bit (1 or 0).
732   */
LL_OPAMP_IsCalibrationOutputSet(OPAMP_TypeDef * OPAMPx)733 __STATIC_INLINE uint32_t LL_OPAMP_IsCalibrationOutputSet(OPAMP_TypeDef *OPAMPx)
734 {
735   return ((READ_BIT(OPAMPx->CSR, OPAMP_CSR_OUTCAL) == OPAMP_CSR_OUTCAL) ? 1UL : 0UL);
736 }
737 
738 /**
739   * @brief  Set OPAMP trimming factor for the selected transistors
740   *         differential pair NMOS or PMOS, corresponding to the selected
741   *         power mode.
742   * @rmtoll CSR      TRIMOFFSETN    LL_OPAMP_SetTrimmingValue\n
743   *         CSR      TRIMOFFSETP    LL_OPAMP_SetTrimmingValue
744   * @param  OPAMPx OPAMP instance
745   * @param  TransistorsDiffPair This parameter can be one of the following values:
746   *         @arg @ref LL_OPAMP_TRIMMING_NMOS
747   *         @arg @ref LL_OPAMP_TRIMMING_PMOS
748   * @param  TrimmingValue 0x00...0x1F
749   * @retval None
750   */
LL_OPAMP_SetTrimmingValue(OPAMP_TypeDef * OPAMPx,uint32_t TransistorsDiffPair,uint32_t TrimmingValue)751 __STATIC_INLINE void LL_OPAMP_SetTrimmingValue(OPAMP_TypeDef* OPAMPx, uint32_t TransistorsDiffPair, uint32_t TrimmingValue)
752 {
753   MODIFY_REG(OPAMPx->CSR,
754              (TransistorsDiffPair & OPAMP_TRIMMING_VALUE_MASK),
755              TrimmingValue << ((TransistorsDiffPair == LL_OPAMP_TRIMMING_NMOS) ? OPAMP_CSR_TRIMOFFSETN_Pos : OPAMP_CSR_TRIMOFFSETP_Pos));
756 }
757 
758 /**
759   * @brief  Get OPAMP trimming factor for the selected transistors
760   *         differential pair NMOS or PMOS, corresponding to the selected
761   *         power mode.
762   * @rmtoll CSR      TRIMOFFSETN    LL_OPAMP_GetTrimmingValue\n
763   *         CSR      TRIMOFFSETP    LL_OPAMP_GetTrimmingValue
764   * @param  OPAMPx OPAMP instance
765   * @param  TransistorsDiffPair This parameter can be one of the following values:
766   *         @arg @ref LL_OPAMP_TRIMMING_NMOS
767   *         @arg @ref LL_OPAMP_TRIMMING_PMOS
768   * @retval 0x0...0x1F
769   */
LL_OPAMP_GetTrimmingValue(OPAMP_TypeDef * OPAMPx,uint32_t TransistorsDiffPair)770 __STATIC_INLINE uint32_t LL_OPAMP_GetTrimmingValue(OPAMP_TypeDef* OPAMPx, uint32_t TransistorsDiffPair)
771 {
772   return (uint32_t)(READ_BIT(OPAMPx->CSR, (TransistorsDiffPair & OPAMP_TRIMMING_VALUE_MASK))
773                     >> ((TransistorsDiffPair == LL_OPAMP_TRIMMING_NMOS) ? OPAMP_CSR_TRIMOFFSETN_Pos : OPAMP_CSR_TRIMOFFSETP_Pos));
774 }
775 
776 /**
777   * @}
778   */
779 
780 /** @defgroup OPAMP_LL_EF_OPERATION Operation on OPAMP instance
781   * @{
782   */
783 /**
784   * @brief  Enable OPAMP instance.
785   * @note   After enable from off state, OPAMP requires a delay
786   *         to fulfill wake up time specification.
787   *         Refer to device datasheet, parameter "tWAKEUP".
788   * @rmtoll CSR      OPAMPXEN       LL_OPAMP_Enable
789   * @param  OPAMPx OPAMP instance
790   * @retval None
791   */
LL_OPAMP_Enable(OPAMP_TypeDef * OPAMPx)792 __STATIC_INLINE void LL_OPAMP_Enable(OPAMP_TypeDef *OPAMPx)
793 {
794   SET_BIT(OPAMPx->CSR, OPAMP_CSR_OPAMPxEN);
795 }
796 
797 /**
798   * @brief  Disable OPAMP instance.
799   * @rmtoll CSR      OPAMPXEN       LL_OPAMP_Disable
800   * @param  OPAMPx OPAMP instance
801   * @retval None
802   */
LL_OPAMP_Disable(OPAMP_TypeDef * OPAMPx)803 __STATIC_INLINE void LL_OPAMP_Disable(OPAMP_TypeDef *OPAMPx)
804 {
805   CLEAR_BIT(OPAMPx->CSR, OPAMP_CSR_OPAMPxEN);
806 }
807 
808 /**
809   * @brief  Get OPAMP instance enable state
810   *         (0: OPAMP is disabled, 1: OPAMP is enabled)
811   * @rmtoll CSR      OPAMPXEN       LL_OPAMP_IsEnabled
812   * @param  OPAMPx OPAMP instance
813   * @retval State of bit (1 or 0).
814   */
LL_OPAMP_IsEnabled(OPAMP_TypeDef * OPAMPx)815 __STATIC_INLINE uint32_t LL_OPAMP_IsEnabled(OPAMP_TypeDef *OPAMPx)
816 {
817   return ((READ_BIT(OPAMPx->CSR, OPAMP_CSR_OPAMPxEN) == (OPAMP_CSR_OPAMPxEN)) ? 1UL : 0UL);
818 }
819 
820 /**
821   * @brief  Lock OPAMP instance.
822   * @note   Once locked, OPAMP configuration can be accessed in read-only.
823   * @note   The only way to unlock the OPAMP is a device hardware reset.
824   * @rmtoll CSR      LOCK           LL_OPAMP_Lock
825   * @param  OPAMPx OPAMP instance
826   * @retval None
827   */
LL_OPAMP_Lock(OPAMP_TypeDef * OPAMPx)828 __STATIC_INLINE void LL_OPAMP_Lock(OPAMP_TypeDef *OPAMPx)
829 {
830   SET_BIT(OPAMPx->CSR, OPAMP_CSR_LOCK);
831 }
832 
833 /**
834   * @brief  Get OPAMP lock state
835   *         (0: OPAMP is unlocked, 1: OPAMP is locked).
836   * @note   Once locked, OPAMP configuration can be accessed in read-only.
837   * @note   The only way to unlock the OPAMP is a device hardware reset.
838   * @rmtoll CSR      LOCK           LL_OPAMP_IsLocked
839   * @param  OPAMPx OPAMP instance
840   * @retval State of bit (1 or 0).
841   */
LL_OPAMP_IsLocked(OPAMP_TypeDef * OPAMPx)842 __STATIC_INLINE uint32_t LL_OPAMP_IsLocked(OPAMP_TypeDef *OPAMPx)
843 {
844   return ((READ_BIT(OPAMPx->CSR, OPAMP_CSR_LOCK) == (OPAMP_CSR_LOCK)) ? 1UL : 0UL);
845 }
846 
847 /**
848   * @}
849   */
850 
851 #if defined(USE_FULL_LL_DRIVER)
852 /** @defgroup OPAMP_LL_EF_Init Initialization and de-initialization functions
853   * @{
854   */
855 
856 ErrorStatus LL_OPAMP_DeInit(OPAMP_TypeDef *OPAMPx);
857 ErrorStatus LL_OPAMP_Init(OPAMP_TypeDef *OPAMPx, LL_OPAMP_InitTypeDef *OPAMP_InitStruct);
858 void        LL_OPAMP_StructInit(LL_OPAMP_InitTypeDef *OPAMP_InitStruct);
859 
860 /**
861   * @}
862   */
863 #endif /* USE_FULL_LL_DRIVER */
864 
865 /**
866   * @}
867   */
868 
869 /**
870   * @}
871   */
872 
873 #endif /* OPAMP1 || OPAMP2 || OPAMP3 || OPAMP4 */
874 
875 /**
876   * @}
877   */
878 
879 #ifdef __cplusplus
880 }
881 #endif
882 
883 #endif /* STM32F3xx_LL_OPAMP_H */
884 
885