1 /**
2 ******************************************************************************
3 * @file stm32g4xx_ll_opamp.h
4 * @author MCD Application Team
5 * @brief Header file of OPAMP LL module.
6 ******************************************************************************
7 * @attention
8 *
9 * Copyright (c) 2019 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 STM32G4xx_LL_OPAMP_H
21 #define STM32G4xx_LL_OPAMP_H
22
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26
27 /* Includes ------------------------------------------------------------------*/
28 #include "stm32g4xx.h"
29
30 /** @addtogroup STM32G4xx_LL_Driver
31 * @{
32 */
33
34 #if defined (OPAMP1) || defined (OPAMP2) || defined (OPAMP3) || defined (OPAMP4) || defined (OPAMP5) || defined (OPAMP6)
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 ((__IO uint32_t *)((uint32_t) ((uint32_t)(&(__REG__)) + ((__REG_OFFSET__) << 2))))
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 PowerMode; /*!< Set OPAMP power mode.
97 This parameter can be a value of @ref OPAMP_LL_EC_POWERMODE
98
99 This feature can be modified afterwards using unitary function @ref LL_OPAMP_SetPowerMode(). */
100
101
102 uint32_t FunctionalMode; /*!< Set OPAMP functional mode by setting internal connections: OPAMP operation in standalone, follower, ...
103 This parameter can be a value of @ref OPAMP_LL_EC_FUNCTIONAL_MODE
104 @note If OPAMP is configured in mode PGA, the gain can be configured using function @ref LL_OPAMP_SetPGAGain().
105
106 This feature can be modified afterwards using unitary function @ref LL_OPAMP_SetFunctionalMode(). */
107
108 uint32_t InputNonInverting; /*!< Set OPAMP input non-inverting connection.
109 This parameter can be a value of @ref OPAMP_LL_EC_INPUT_NONINVERTING
110
111 This feature can be modified afterwards using unitary function @ref LL_OPAMP_SetInputNonInverting(). */
112
113 uint32_t InputInverting; /*!< Set OPAMP inverting input connection.
114 This parameter can be a value of @ref OPAMP_LL_EC_INPUT_INVERTING
115 @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.
116
117 This feature can be modified afterwards using unitary function @ref LL_OPAMP_SetInputInverting(). */
118
119 } LL_OPAMP_InitTypeDef;
120
121 /**
122 * @}
123 */
124 #endif /* USE_FULL_LL_DRIVER */
125
126 /* Exported constants --------------------------------------------------------*/
127 /** @defgroup OPAMP_LL_Exported_Constants OPAMP Exported Constants
128 * @{
129 */
130
131 /** @defgroup OPAMP_LL_EC_MODE OPAMP mode calibration or functional.
132 * @{
133 */
134 #define LL_OPAMP_MODE_FUNCTIONAL (0x00000000UL) /*!< OPAMP functional mode */
135 #define LL_OPAMP_MODE_CALIBRATION (OPAMP_CSR_CALON) /*!< OPAMP calibration mode */
136 /**
137 * @}
138 */
139
140 /** @defgroup OPAMP_LL_EC_FUNCTIONAL_MODE OPAMP functional mode
141 * @{
142 */
143 #define LL_OPAMP_MODE_STANDALONE (0x00000000UL) /*!< OPAMP functional mode, OPAMP operation in standalone */
144 #define LL_OPAMP_MODE_FOLLOWER (OPAMP_CSR_VMSEL_1 | OPAMP_CSR_VMSEL_0) /*!< OPAMP functional mode, OPAMP operation in follower */
145 #define LL_OPAMP_MODE_PGA (OPAMP_CSR_VMSEL_1) /*!< OPAMP functional mode, OPAMP operation in PGA */
146 #define LL_OPAMP_MODE_PGA_IO0 (OPAMP_CSR_PGGAIN_4|OPAMP_CSR_VMSEL_1) /*!< In PGA mode, the inverting input is connected to VINM0 for filtering */
147 #define LL_OPAMP_MODE_PGA_IO0_BIAS (OPAMP_CSR_PGGAIN_3|OPAMP_CSR_VMSEL_1) /*!< In PGA mode, the inverting input is connected to VINM0
148 - Input signal on VINM0, bias on VINPx: negative gain
149 - Bias on VINM0, input signal on VINPx: positive gain */
150 #define LL_OPAMP_MODE_PGA_IO0_IO1_BIAS (OPAMP_CSR_PGGAIN_4|OPAMP_CSR_PGGAIN_3|OPAMP_CSR_VMSEL_1) /*!< In PGA mode, the inverting input is connected to VINM0
151 - Input signal on VINM0, bias on VINPx: negative gain
152 - Bias on VINM0, input signal on VINPx: positive gain
153 And VINM1 is connected too for filtering */
154
155 /**
156 * @}
157 */
158
159 /** @defgroup OPAMP_LL_EC_MODE_PGA_GAIN OPAMP PGA gain (relevant when OPAMP is in functional mode PGA)
160 * @note Gain sign:
161 * - is positive if the @ref OPAMP_LL_EC_FUNCTIONAL_MODE configuration is
162 * @ref LL_OPAMP_MODE_PGA or LL_OPAMP_MODE_PGA_IO0
163 * - may be positive or negative if the @ref OPAMP_LL_EC_FUNCTIONAL_MODE configuration is
164 * @ref LL_OPAMP_MODE_PGA_IO0_BIAS or LL_OPAMP_MODE_PGA_IO0_IO1_BIAS
165 * see @ref OPAMP_LL_EC_FUNCTIONAL_MODE for more details
166 * @{
167 */
168 #define LL_OPAMP_PGA_GAIN_2_OR_MINUS_1 (0x00000000UL) /*!< OPAMP PGA gain 2 or -1 */
169 #define LL_OPAMP_PGA_GAIN_4_OR_MINUS_3 ( OPAMP_CSR_PGGAIN_0) /*!< OPAMP PGA gain 4 or -3 */
170 #define LL_OPAMP_PGA_GAIN_8_OR_MINUS_7 ( OPAMP_CSR_PGGAIN_1 ) /*!< OPAMP PGA gain 8 or -7 */
171 #define LL_OPAMP_PGA_GAIN_16_OR_MINUS_15 ( OPAMP_CSR_PGGAIN_1 | OPAMP_CSR_PGGAIN_0) /*!< OPAMP PGA gain 16 or -15 */
172 #define LL_OPAMP_PGA_GAIN_32_OR_MINUS_31 (OPAMP_CSR_PGGAIN_2 ) /*!< OPAMP PGA gain 32 or -31 */
173 #define LL_OPAMP_PGA_GAIN_64_OR_MINUS_63 (OPAMP_CSR_PGGAIN_2 | OPAMP_CSR_PGGAIN_0) /*!< OPAMP PGA gain 64 or -63 */
174 /**
175 * @}
176 */
177
178 /** @defgroup OPAMP_LL_EC_INPUT_NONINVERTING OPAMP input non-inverting
179 * @{
180 */
181 #define LL_OPAMP_INPUT_NONINVERT_IO0 (0x00000000UL) /*!< OPAMP non inverting input connected to I/O VINP0
182 (PA1 for OPAMP1, PA7 for OPAMP2, PB0 for OPAMP3, PB13 for OPAMP4, PB14 for OPAMP5, PB12 for OPAMP6)
183 Note: On this STM32 series, all OPAMPx are not available on all devices. Refer to device datasheet for more details */
184 #define LL_OPAMP_INPUT_NONINVERT_IO1 OPAMP_CSR_VPSEL_0 /*!< OPAMP non inverting input connected to I/O VINP1
185 (PA3 for OPAMP1, PB14 for OPAMP2, PB13 for OPAMP3, PD11 for OPAMP4, PD12 for OPAMP5, PD9 for OPAMP6)
186 Note: On this STM32 series, all OPAMPx are not available on all devices. Refer to device datasheet for more details */
187 #define LL_OPAMP_INPUT_NONINVERT_IO2 OPAMP_CSR_VPSEL_1 /*!< OPAMP non inverting input connected to I/O VINP2
188 (PA7 for OPAMP1, PB0 for OPAMP2, PA1 for OPAMP3, PB11 for OPAMP4, PC3 for OPAMP5, PB13 for OPAMP6)
189 Note: On this STM32 series, all OPAMPx are not available on all devices. Refer to device datasheet for more details */
190 #define LL_OPAMP_INPUT_NONINVERT_IO3 OPAMP_CSR_VPSEL /*!< OPAMP non inverting input connected to I/O VINP3
191 (PD14 for OPAMP2) */
192 #define LL_OPAMP_INPUT_NONINVERT_DAC OPAMP_CSR_VPSEL /*!< OPAMP non inverting input connected internally to DAC channel
193 (DAC3_CH1 for OPAMP1, DAC3_CH2 for OPAMP3, DAC4_CH1 for OPAMP4, DAC4_CH2 for OPAMP5, DAC3_CH1 for OPAMP6)
194 Note: On this STM32 series, all OPAMPx are not available on all devices. Refer to device datasheet for more details */
195 /**
196 * @}
197 */
198
199 /** @defgroup OPAMP_LL_EC_INPUT_INVERTING OPAMP input inverting
200 * @note OPAMP inverting input is used with OPAMP in mode standalone or PGA with negative gain or bias.
201 * Otherwise (OPAMP in mode follower), OPAMP inverting input is not used (not connected to GPIO pin).
202 * @{
203 */
204 #define LL_OPAMP_INPUT_INVERT_IO0 (0x00000000UL) /*!< OPAMP inverting input connected to I/O VINM0
205 (PA3 for OPAMP1, PA5 for OPAMP2, PB2 for OPAMP3, PB10 for OPAMP4, PB15 for OPAMP5, PA1 for OPAMP6)
206 Note: On this STM32 series, all OPAMPx are not available on all devices. Refer to device datasheet for more details */
207 #define LL_OPAMP_INPUT_INVERT_IO1 OPAMP_CSR_VMSEL_0 /*!< OPAMP inverting input connected to I/0 VINM1
208 (PC5 for OPAMP1, PC5 for OPAMP2, PB10 for OPAMP3, PB8 for OPAMP4, PA3 for OPAMP5, PB1 for OPAMP6)
209 Note: On this STM32 series, all OPAMPx are not available on all devices. Refer to device datasheet for more details */
210 #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 with positive gain without bias).
211 Note: On this STM32 series, this literal include cases of value 0x11 for mode follower and value 0x10 for mode PGA. */
212 /**
213 * @}
214 */
215
216 /** @defgroup OPAMP_LL_EC_INPUT_NONINVERTING_SECONDARY OPAMP input non-inverting secondary
217 * @{
218 */
219 #define LL_OPAMP_INPUT_NONINVERT_IO0_SEC (0x00000000UL) /*!< OPAMP secondary non inverting input connected to I/O VINP0
220 (PA1 for OPAMP1, PA7 for OPAMP2, PB0 for OPAMP3, PB13 for OPAMP4, PB14 for OPAMP5, PB12 for OPAMP6)
221 Note: On this STM32 series, all OPAMPx are not available on all devices. Refer to device datasheet for more details */
222 #define LL_OPAMP_INPUT_NONINVERT_IO1_SEC OPAMP_TCMR_VPSSEL_0 /*!< OPAMP secondary non inverting input connected to I/O VINP1
223 (PA3 for OPAMP1, PB14 for OPAMP2, PB13 for OPAMP3, PD11 for OPAMP4, PD12 for OPAMP5, PD9 for OPAMP6)
224 Note: On this STM32 series, all OPAMPx are not available on all devices. Refer to device datasheet for more details */
225 #define LL_OPAMP_INPUT_NONINVERT_IO2_SEC OPAMP_TCMR_VPSSEL_1 /*!< OPAMP secondary non inverting input connected to I/O VINP2
226 (PA7 for OPAMP1, PB0 for OPAMP2, PA1 for OPAMP3, PB11 for OPAMP4, PC3 for OPAMP5, PB13 for OPAMP6)
227 Note: On this STM32 series, all OPAMPx are not available on all devices. Refer to device datasheet for more details */
228 #define LL_OPAMP_INPUT_NONINVERT_IO3_SEC OPAMP_TCMR_VPSSEL /*!< OPAMP secondary non inverting input connected to I/O VINP3
229 (PD14 for OPAMP2) */
230 #define LL_OPAMP_INPUT_NONINVERT_DAC_SEC OPAMP_TCMR_VPSSEL /*!< OPAMP secondary non inverting input connected internally to DAC channel
231 (DAC3_CH1 for OPAMP1, DAC3_CH2 for OPAMP3, DAC4_CH1 for OPAMP4, DAC4_CH2 for OPAMP5, DAC3_CH1 for OPAMP6)
232 Note: On this STM32 series, all OPAMPx are not available on all devices. Refer to device datasheet for more details */
233 /**
234 * @}
235 */
236
237 /** @defgroup OPAMP_LL_EC_INPUT_INVERTING_SECONDARY OPAMP input inverting secondary
238 * @note OPAMP inverting input is used with OPAMP in mode standalone or PGA with negative gain or bias.
239 * Otherwise (OPAMP in mode follower), OPAMP inverting input is not used (not connected to GPIO pin).
240 * @{
241 */
242 #define LL_OPAMP_INPUT_INVERT_IO0_SEC (0x00000000UL) /*!< OPAMP secondary mode is standalone mode - Only applicable if @ref LL_OPAMP_MODE_STANDALONE
243 has been configured by call to @ref LL_OPAMP_Init() or @ref LL_OPAMP_SetFunctionalMode().
244 OPAMP secondary inverting input connected to I/O VINM0.
245 (PA3 for OPAMP1, PA5 for OPAMP2, PB2 for OPAMP3, PB10 for OPAMP4, PB15 for OPAMP5, PA1 for OPAMP6)
246 Note: On this STM32 series, all OPAMPx are not available on all devices. Refer to device datasheet for more details */
247 #define LL_OPAMP_INPUT_INVERT_IO1_SEC OPAMP_TCMR_VMSSEL /*!< OPAMP secondary mode is standalone mode - Only applicable if @ref LL_OPAMP_MODE_STANDALONE
248 has been configured by call to @ref LL_OPAMP_Init() or @ref LL_OPAMP_SetFunctionalMode().
249 OPAMP secondary inverting input connected to I/0 VINM1
250 (PC5 for OPAMP1, PC5 for OPAMP2, PB10 for OPAMP3, PB8 for OPAMP4, PA3 for OPAMP5, PB1 for OPAMP6)
251 Note: On this STM32 series, all OPAMPx are not available on all devices. Refer to device datasheet for more details */
252 #define LL_OPAMP_INPUT_INVERT_PGA_SEC (0x00000000UL) /*!< OPAMP secondary mode is PGA mode - Only applicable if configured mode through call to @ref LL_OPAMP_Init()
253 or @ref LL_OPAMP_SetFunctionalMode() is NOT @ref LL_OPAMP_MODE_STANDALONE.
254 OPAMP secondary inverting input is:
255 - Not connected if configured mode is @ref LL_OPAMP_MODE_FOLLOWER or @ref LL_OPAMP_MODE_PGA
256 - Connected to VINM0 and possibly VINM1 if any of the other modes as been configured
257 (see @ref OPAMP_LL_EC_FUNCTIONAL_MODE description for more details on PGA connection modes) */
258 #define LL_OPAMP_INPUT_INVERT_FOLLOWER_SEC OPAMP_TCMR_VMSSEL /*!< OPAMP secondary mode is Follower mode - Only applicable if configured mode through call to @ref LL_OPAMP_Init()
259 or @ref LL_OPAMP_SetFunctionalMode() is NOT @ref LL_OPAMP_MODE_STANDALONE.
260 OPAMP secondary inverting input is not connected. */
261 /**
262 * @}
263 */
264
265 /** @defgroup OPAMP_LL_EC_INTERNAL_OUPUT_MODE OPAMP internal output mode
266 * @{
267 */
268 #define LL_OPAMP_INTERNAL_OUPUT_DISABLED (0x00000000UL) /*!< OPAMP internal output to ADC disabled. */
269 #define LL_OPAMP_INTERNAL_OUPUT_ENABLED OPAMP_CSR_OPAMPINTEN /*!< OPAMP internal output to ADC enabled.
270 - OPAMP1 internal output is connected to ADC1/Channel13
271 - OPAMP2 internal output is connected to ADC2/Channel16
272 - OPAMP3 internal output is connected to ADC2/Channel18 & ADC3/Channel13
273 - OPAMP4 internal output is connected to ADC5/Channel5
274 - OPAMP5 internal output is connected to ADC5/Channel3
275 - OPAMP6 internal output is connected to ADC4/Channel17
276 Note: On this STM32 series, all OPAMPx are not available on all devices. Refer to device datasheet for more details */
277 /**
278 * @}
279 */
280
281 /** @defgroup OPAMP_LL_EC_INPUT_MUX_MODE OPAMP inputs multiplexer mode
282 * @note The switch can be controlled either by a single timer or a combination of them,
283 * in this case application has to 'ORed' the values below
284 * ex LL_OPAMP_INPUT_MUX_TIM1_CH6 | LL_OPAMP_INPUT_MUX_TIM20_CH6
285 * @{
286 */
287 #define LL_OPAMP_INPUT_MUX_DISABLE (0x00000000UL) /*!< OPAMP inputs timer controlled multiplexer mode disabled. */
288 #define LL_OPAMP_INPUT_MUX_TIM1_CH6 OPAMP_TCMR_T1CMEN /*!< OPAMP inputs timer controlled multiplexer mode enabled, controlled by TIM1 OC6. */
289 #define LL_OPAMP_INPUT_MUX_TIM8_CH6 OPAMP_TCMR_T8CMEN /*!< OPAMP inputs timer controlled multiplexer mode enabled, controlled by TIM8 OC6. */
290 #define LL_OPAMP_INPUT_MUX_TIM20_CH6 OPAMP_TCMR_T20CMEN /*!< OPAMP inputs timer controlled multiplexer mode enabled, controlled by TIM20 OC6.
291 Note: On this STM32 series, TIM20 is not available on all devices. Refer to device datasheet for more details */
292 /**
293 * @}
294 */
295
296 /** @defgroup OPAMP_LL_EC_POWER_MODE OPAMP PowerMode
297 * @{
298 */
299 #define LL_OPAMP_POWERMODE_NORMALSPEED (0x00000000UL) /*!< OPAMP output in normal mode */
300 #define LL_OPAMP_POWERMODE_HIGHSPEED OPAMP_CSR_HIGHSPEEDEN /*!< OPAMP output in highspeed mode */
301
302 #define LL_OPAMP_POWERMODE_NORMAL LL_OPAMP_POWERMODE_NORMALSPEED /*!< OPAMP power mode normal - Old Naming for compatibility */
303
304 /**
305 * @}
306 */
307
308 /** @defgroup OPAMP_LL_EC_TRIMMING_MODE OPAMP trimming mode
309 * @{
310 */
311 #define LL_OPAMP_TRIMMING_FACTORY (0x00000000UL) /*!< OPAMP trimming factors set to factory values */
312 #define LL_OPAMP_TRIMMING_USER OPAMP_CSR_USERTRIM /*!< OPAMP trimming factors set to user values */
313 /**
314 * @}
315 */
316
317 /** @defgroup OPAMP_LL_EC_TRIMMING_TRANSISTORS_DIFF_PAIR OPAMP trimming of transistors differential pair NMOS or PMOS
318 * @{
319 */
320 #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). */
321 #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). */
322 #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). */
323 #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). */
324 #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). */
325 #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). */
326 /**
327 * @}
328 */
329
330 /** @defgroup OPAMP_LL_EC_HW_DELAYS Definitions of OPAMP hardware constraints delays
331 * @note Only OPAMP peripheral HW delays are defined in OPAMP LL driver driver,
332 * not timeout values.
333 * For details on delays values, refer to descriptions in source code
334 * above each literal definition.
335 * @{
336 */
337
338 /* Delay for OPAMP startup time (transition from state disable to enable). */
339 /* Note: OPAMP startup time depends on board application environment: */
340 /* impedance connected to OPAMP output. */
341 /* The delay below is specified under conditions: */
342 /* - OPAMP in functional mode follower */
343 /* - load impedance of 4kOhm (min), 50pF (max) */
344 /* Literal set to maximum value (refer to device datasheet, */
345 /* parameter "tWAKEUP"). */
346 /* Unit: us */
347 #define LL_OPAMP_DELAY_STARTUP_US (6) /*!< Delay for OPAMP startup time */
348 /**
349 * @}
350 */
351
352 /**
353 * @}
354 */
355
356 /* Exported macro ------------------------------------------------------------*/
357 /** @defgroup OPAMP_LL_Exported_Macros OPAMP Exported Macros
358 * @{
359 */
360 /** @defgroup OPAMP_LL_EM_WRITE_READ Common write and read registers macro
361 * @{
362 */
363 /**
364 * @brief Write a value in OPAMP register
365 * @param __INSTANCE__ OPAMP Instance
366 * @param __REG__ Register to be written
367 * @param __VALUE__ Value to be written in the register
368 * @retval None
369 */
370 #define LL_OPAMP_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG((__INSTANCE__)->__REG__, (__VALUE__))
371
372 /**
373 * @brief Read a value in OPAMP register
374 * @param __INSTANCE__ OPAMP Instance
375 * @param __REG__ Register to be read
376 * @retval Register value
377 */
378 #define LL_OPAMP_ReadReg(__INSTANCE__, __REG__) READ_REG((__INSTANCE__)->__REG__)
379 /**
380 * @}
381 */
382
383 /**
384 * @}
385 */
386
387 /* Exported functions --------------------------------------------------------*/
388 /** @defgroup OPAMP_LL_Exported_Functions OPAMP Exported Functions
389 * @{
390 */
391
392 /** @defgroup OPAMP_LL_EF_CONFIGURATION_OPAMP_INSTANCE Configuration of OPAMP hierarchical scope: OPAMP instance
393 * @{
394 */
395
396 /**
397 * @brief Set OPAMP mode calibration or functional.
398 * @note OPAMP mode corresponds to functional or calibration mode:
399 * - functional mode: OPAMP operation in standalone, follower, ...
400 * Set functional mode using function
401 * @ref LL_OPAMP_SetFunctionalMode().
402 * - calibration mode: offset calibration of the selected
403 * transistors differential pair NMOS or PMOS.
404 * @rmtoll CSR CALON LL_OPAMP_SetMode
405 * @param OPAMPx OPAMP instance
406 * @param Mode This parameter can be one of the following values:
407 * @arg @ref LL_OPAMP_MODE_FUNCTIONAL
408 * @arg @ref LL_OPAMP_MODE_CALIBRATION
409 * @retval None
410 */
LL_OPAMP_SetMode(OPAMP_TypeDef * OPAMPx,uint32_t Mode)411 __STATIC_INLINE void LL_OPAMP_SetMode(OPAMP_TypeDef *OPAMPx, uint32_t Mode)
412 {
413 MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_CALON, Mode);
414 }
415
416 /**
417 * @brief Get OPAMP mode calibration or functional.
418 * @note OPAMP mode corresponds to functional or calibration mode:
419 * - functional mode: OPAMP operation in standalone, follower, ...
420 * Set functional mode using function
421 * @ref LL_OPAMP_SetFunctionalMode().
422 * - calibration mode: offset calibration of the selected
423 * transistors differential pair NMOS or PMOS.
424 * @rmtoll CSR CALON LL_OPAMP_GetMode
425 * @param OPAMPx OPAMP instance
426 * @retval Returned value can be one of the following values:
427 * @arg @ref LL_OPAMP_MODE_FUNCTIONAL
428 * @arg @ref LL_OPAMP_MODE_CALIBRATION
429 */
LL_OPAMP_GetMode(OPAMP_TypeDef * OPAMPx)430 __STATIC_INLINE uint32_t LL_OPAMP_GetMode(OPAMP_TypeDef *OPAMPx)
431 {
432 return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_CALON));
433 }
434
435 /**
436 * @brief Set OPAMP functional mode by setting internal connections.
437 * OPAMP operation in standalone, follower, ...
438 * @note This function reset bit of calibration mode to ensure
439 * to be in functional mode, in order to have OPAMP parameters
440 * (inputs selection, ...) set with the corresponding OPAMP mode
441 * to be effective.
442 * @rmtoll CSR VMSEL LL_OPAMP_SetFunctionalMode
443 * @param OPAMPx OPAMP instance
444 * @param FunctionalMode This parameter can be one of the following values:
445 * @arg @ref LL_OPAMP_MODE_STANDALONE
446 * @arg @ref LL_OPAMP_MODE_FOLLOWER
447 * @arg @ref LL_OPAMP_MODE_PGA
448 * @arg @ref LL_OPAMP_MODE_PGA_IO0
449 * @arg @ref LL_OPAMP_MODE_PGA_IO0_BIAS
450 * @arg @ref LL_OPAMP_MODE_PGA_IO0_IO1_BIAS
451 * @retval None
452 */
LL_OPAMP_SetFunctionalMode(OPAMP_TypeDef * OPAMPx,uint32_t FunctionalMode)453 __STATIC_INLINE void LL_OPAMP_SetFunctionalMode(OPAMP_TypeDef *OPAMPx, uint32_t FunctionalMode)
454 {
455 /* Note: Bit OPAMP_CSR_CALON reset to ensure to be in functional mode */
456 MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_PGGAIN_4 | OPAMP_CSR_PGGAIN_3 | OPAMP_CSR_VMSEL | OPAMP_CSR_CALON, FunctionalMode);
457 }
458
459 /**
460 * @brief Get OPAMP functional mode from setting of internal connections.
461 * OPAMP operation in standalone, follower, ...
462 * @rmtoll CSR VMSEL LL_OPAMP_GetFunctionalMode
463 * @param OPAMPx OPAMP instance
464 * @retval Returned value can be one of the following values:
465 * @arg @ref LL_OPAMP_MODE_STANDALONE
466 * @arg @ref LL_OPAMP_MODE_FOLLOWER
467 * @arg @ref LL_OPAMP_MODE_PGA
468 * @arg @ref LL_OPAMP_MODE_PGA_IO0
469 * @arg @ref LL_OPAMP_MODE_PGA_IO0_BIAS
470 * @arg @ref LL_OPAMP_MODE_PGA_IO0_IO1_BIAS
471 */
LL_OPAMP_GetFunctionalMode(OPAMP_TypeDef * OPAMPx)472 __STATIC_INLINE uint32_t LL_OPAMP_GetFunctionalMode(OPAMP_TypeDef *OPAMPx)
473 {
474 return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_PGGAIN_4 | OPAMP_CSR_PGGAIN_3 | OPAMP_CSR_VMSEL));
475 }
476
477 /**
478 * @brief Set OPAMP PGA gain.
479 * @note Preliminarily, OPAMP must be set in mode PGA
480 * using function @ref LL_OPAMP_SetFunctionalMode().
481 * @rmtoll CSR PGGAIN LL_OPAMP_SetPGAGain
482 * @param OPAMPx OPAMP instance
483 * @param PGAGain This parameter can be one of the following values:
484 * @arg @ref LL_OPAMP_PGA_GAIN_2_OR_MINUS_1
485 * @arg @ref LL_OPAMP_PGA_GAIN_4_OR_MINUS_3
486 * @arg @ref LL_OPAMP_PGA_GAIN_8_OR_MINUS_7
487 * @arg @ref LL_OPAMP_PGA_GAIN_16_OR_MINUS_15
488 * @arg @ref LL_OPAMP_PGA_GAIN_32_OR_MINUS_31
489 * @arg @ref LL_OPAMP_PGA_GAIN_64_OR_MINUS_63
490 * @retval None
491 */
LL_OPAMP_SetPGAGain(OPAMP_TypeDef * OPAMPx,uint32_t PGAGain)492 __STATIC_INLINE void LL_OPAMP_SetPGAGain(OPAMP_TypeDef *OPAMPx, uint32_t PGAGain)
493 {
494 MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_PGGAIN_2 | OPAMP_CSR_PGGAIN_1 | OPAMP_CSR_PGGAIN_0, PGAGain);
495 }
496
497 /**
498 * @brief Get OPAMP PGA gain.
499 * @note Preliminarily, OPAMP must be set in mode PGA
500 * using function @ref LL_OPAMP_SetFunctionalMode().
501 * @rmtoll CSR PGGAIN LL_OPAMP_GetPGAGain
502 * @param OPAMPx OPAMP instance
503 * @retval Returned value can be one of the following values:
504 * @arg @ref LL_OPAMP_PGA_GAIN_2_OR_MINUS_1
505 * @arg @ref LL_OPAMP_PGA_GAIN_4_OR_MINUS_3
506 * @arg @ref LL_OPAMP_PGA_GAIN_8_OR_MINUS_7
507 * @arg @ref LL_OPAMP_PGA_GAIN_16_OR_MINUS_15
508 * @arg @ref LL_OPAMP_PGA_GAIN_32_OR_MINUS_31
509 * @arg @ref LL_OPAMP_PGA_GAIN_64_OR_MINUS_63
510 */
LL_OPAMP_GetPGAGain(OPAMP_TypeDef * OPAMPx)511 __STATIC_INLINE uint32_t LL_OPAMP_GetPGAGain(OPAMP_TypeDef *OPAMPx)
512 {
513 return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_PGGAIN_2 | OPAMP_CSR_PGGAIN_1 | OPAMP_CSR_PGGAIN_0));
514 }
515
516 /**
517 * @brief Set OPAMP power mode normal or highspeed.
518 * @note OPAMP highspeed mode allows output stage to have a better slew rate.
519 * @rmtoll CSR HIGHSPEEDEN LL_OPAMP_SetPowerMode
520 * @param OPAMPx OPAMP instance
521 * @param PowerMode This parameter can be one of the following values:
522 * @arg @ref LL_OPAMP_POWERMODE_NORMALSPEED
523 * @arg @ref LL_OPAMP_POWERMODE_HIGHSPEED
524 * @retval None
525 */
LL_OPAMP_SetPowerMode(OPAMP_TypeDef * OPAMPx,uint32_t PowerMode)526 __STATIC_INLINE void LL_OPAMP_SetPowerMode(OPAMP_TypeDef *OPAMPx, uint32_t PowerMode)
527 {
528 MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_HIGHSPEEDEN, PowerMode);
529 }
530
531 /**
532 * @brief Get OPAMP power mode normal or highspeed.
533 * @note OPAMP highspeed mode allows output stage to have a better slew rate.
534 * @rmtoll CSR HIGHSPEEDEN LL_OPAMP_GetPowerMode
535 * @param OPAMPx OPAMP instance
536 * @retval Returned value can be one of the following values:
537 * @arg @ref LL_OPAMP_POWERMODE_NORMALSPEED
538 * @arg @ref LL_OPAMP_POWERMODE_HIGHSPEED
539 */
LL_OPAMP_GetPowerMode(OPAMP_TypeDef * OPAMPx)540 __STATIC_INLINE uint32_t LL_OPAMP_GetPowerMode(OPAMP_TypeDef *OPAMPx)
541 {
542 return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_HIGHSPEEDEN));
543 }
544 /**
545 * @}
546 */
547
548 /** @defgroup OPAMP_LL_EF_CONFIGURATION_INPUTS Configuration of OPAMP inputs
549 * @{
550 */
551
552 /**
553 * @brief Set OPAMP non-inverting input connection.
554 * @rmtoll CSR VPSEL LL_OPAMP_SetInputNonInverting
555 * @param OPAMPx OPAMP instance
556 * @param InputNonInverting This parameter can be one of the following values:
557 * @arg @ref LL_OPAMP_INPUT_NONINVERT_IO0
558 * @arg @ref LL_OPAMP_INPUT_NONINVERT_IO1
559 * @arg @ref LL_OPAMP_INPUT_NONINVERT_IO2
560 * @arg @ref LL_OPAMP_INPUT_NONINVERT_IO3
561 * @arg @ref LL_OPAMP_INPUT_NONINVERT_DAC
562 * @retval None
563 */
LL_OPAMP_SetInputNonInverting(OPAMP_TypeDef * OPAMPx,uint32_t InputNonInverting)564 __STATIC_INLINE void LL_OPAMP_SetInputNonInverting(OPAMP_TypeDef *OPAMPx, uint32_t InputNonInverting)
565 {
566 MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_VPSEL, InputNonInverting);
567 }
568
569 /**
570 * @brief Get OPAMP non-inverting input connection.
571 * @rmtoll CSR VPSEL LL_OPAMP_GetInputNonInverting
572 * @param OPAMPx OPAMP instance
573 * @retval Returned value can be one of the following values:
574 * @arg @ref LL_OPAMP_INPUT_NONINVERT_IO0
575 * @arg @ref LL_OPAMP_INPUT_NONINVERT_IO1
576 * @arg @ref LL_OPAMP_INPUT_NONINVERT_IO2
577 * @arg @ref LL_OPAMP_INPUT_NONINVERT_IO3
578 * @arg @ref LL_OPAMP_INPUT_NONINVERT_DAC
579 */
LL_OPAMP_GetInputNonInverting(OPAMP_TypeDef * OPAMPx)580 __STATIC_INLINE uint32_t LL_OPAMP_GetInputNonInverting(OPAMP_TypeDef *OPAMPx)
581 {
582 return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_VPSEL));
583 }
584
585 /**
586 * @brief Set OPAMP inverting input connection.
587 * @note OPAMP inverting input is used with OPAMP in mode standalone
588 * or PGA with external capacitors for filtering circuit.
589 * Otherwise (OPAMP in mode follower), OPAMP inverting input
590 * is not used (not connected to GPIO pin).
591 * @rmtoll CSR VMSEL LL_OPAMP_SetInputInverting
592 * @param OPAMPx OPAMP instance
593 * @param InputInverting This parameter can be one of the following values:
594 * @arg @ref LL_OPAMP_INPUT_INVERT_IO0
595 * @arg @ref LL_OPAMP_INPUT_INVERT_IO1
596 * @arg @ref LL_OPAMP_INPUT_INVERT_CONNECT_NO
597 * @retval None
598 */
LL_OPAMP_SetInputInverting(OPAMP_TypeDef * OPAMPx,uint32_t InputInverting)599 __STATIC_INLINE void LL_OPAMP_SetInputInverting(OPAMP_TypeDef *OPAMPx, uint32_t InputInverting)
600 {
601 /* Manage cases of OPAMP inverting input not connected (0x10 and 0x11) */
602 /* to not modify OPAMP mode follower or PGA. */
603 /* Bit OPAMP_CSR_VMSEL_1 is set by OPAMP mode (follower, PGA). */
604 MODIFY_REG(OPAMPx->CSR, (~(InputInverting >> 1)) & OPAMP_CSR_VMSEL_0, InputInverting);
605 }
606
607 /**
608 * @brief Get OPAMP inverting input connection.
609 * @rmtoll CSR VMSEL LL_OPAMP_GetInputInverting
610 * @param OPAMPx OPAMP instance
611 * @retval Returned value can be one of the following values:
612 * @arg @ref LL_OPAMP_INPUT_INVERT_IO0
613 * @arg @ref LL_OPAMP_INPUT_INVERT_IO1
614 * @arg @ref LL_OPAMP_INPUT_INVERT_CONNECT_NO
615 */
LL_OPAMP_GetInputInverting(OPAMP_TypeDef * OPAMPx)616 __STATIC_INLINE uint32_t LL_OPAMP_GetInputInverting(OPAMP_TypeDef *OPAMPx)
617 {
618 uint32_t input_inverting = READ_BIT(OPAMPx->CSR, OPAMP_CSR_VMSEL);
619
620 /* Manage cases 0x10 and 0x11 to return the same value: OPAMP inverting */
621 /* input not connected. */
622 return (input_inverting & ~((input_inverting >> 1) & OPAMP_CSR_VMSEL_0));
623 }
624
625 /**
626 * @brief Set OPAMP non-inverting input secondary connection.
627 * @rmtoll TCMR VPSSEL LL_OPAMP_SetInputNonInvertingSecondary
628 * @param OPAMPx OPAMP instance
629 * @param InputNonInverting This parameter can be one of the following values:
630 * @arg @ref LL_OPAMP_INPUT_NONINVERT_IO0_SEC
631 * @arg @ref LL_OPAMP_INPUT_NONINVERT_IO1_SEC
632 * @arg @ref LL_OPAMP_INPUT_NONINVERT_IO2_SEC
633 * @arg @ref LL_OPAMP_INPUT_NONINVERT_IO3_SEC
634 * @arg @ref LL_OPAMP_INPUT_NONINVERT_DAC_SEC
635 * @retval None
636 */
LL_OPAMP_SetInputNonInvertingSecondary(OPAMP_TypeDef * OPAMPx,uint32_t InputNonInverting)637 __STATIC_INLINE void LL_OPAMP_SetInputNonInvertingSecondary(OPAMP_TypeDef *OPAMPx, uint32_t InputNonInverting)
638 {
639 MODIFY_REG(OPAMPx->TCMR, OPAMP_TCMR_VPSSEL, InputNonInverting);
640 }
641
642 /**
643 * @brief Get OPAMP non-inverting input secondary connection.
644 * @rmtoll TCMR VPSSEL LL_OPAMP_GetInputNonInvertingSecondary
645 * @param OPAMPx OPAMP instance
646 * @retval Returned value can be one of the following values:
647 * @arg @ref LL_OPAMP_INPUT_NONINVERT_IO0_SEC
648 * @arg @ref LL_OPAMP_INPUT_NONINVERT_IO1_SEC
649 * @arg @ref LL_OPAMP_INPUT_NONINVERT_IO2_SEC
650 * @arg @ref LL_OPAMP_INPUT_NONINVERT_IO3_SEC
651 * @arg @ref LL_OPAMP_INPUT_NONINVERT_DAC_SEC
652 */
LL_OPAMP_GetInputNonInvertingSecondary(OPAMP_TypeDef * OPAMPx)653 __STATIC_INLINE uint32_t LL_OPAMP_GetInputNonInvertingSecondary(OPAMP_TypeDef *OPAMPx)
654 {
655 return (uint32_t)(READ_BIT(OPAMPx->TCMR, OPAMP_TCMR_VPSSEL));
656 }
657
658 /**
659 * @brief Set OPAMP inverting input secondary connection.
660 * @note OPAMP inverting input is used with OPAMP in mode standalone
661 * or PGA with external capacitors for filtering circuit.
662 * Otherwise (OPAMP in mode follower), OPAMP inverting input
663 * is not used (not connected to GPIO pin).
664 * @rmtoll TCMR VMSSEL LL_OPAMP_SetInputInvertingSecondary
665 * @param OPAMPx OPAMP instance
666 * @param InputInverting This parameter can be one of the following values:
667 * @arg @ref LL_OPAMP_INPUT_INVERT_IO0_SEC
668 * @arg @ref LL_OPAMP_INPUT_INVERT_IO1_SEC
669 * @arg @ref LL_OPAMP_INPUT_INVERT_PGA_SEC
670 * @arg @ref LL_OPAMP_INPUT_INVERT_FOLLOWER_SEC
671 * @retval None
672 */
LL_OPAMP_SetInputInvertingSecondary(OPAMP_TypeDef * OPAMPx,uint32_t InputInverting)673 __STATIC_INLINE void LL_OPAMP_SetInputInvertingSecondary(OPAMP_TypeDef *OPAMPx, uint32_t InputInverting)
674 {
675 MODIFY_REG(OPAMPx->TCMR, OPAMP_TCMR_VMSSEL, InputInverting);
676 }
677
678 /**
679 * @brief Get OPAMP inverting input secondary connection.
680 * @rmtoll TCMR VMSSEL LL_OPAMP_GetInputInvertingSecondary
681 * @param OPAMPx OPAMP instance
682 * @retval Returned value can be one of the following values:
683 * @arg @ref LL_OPAMP_INPUT_INVERT_IO0_SEC
684 * @arg @ref LL_OPAMP_INPUT_INVERT_IO1_SEC
685 * @arg @ref LL_OPAMP_INPUT_INVERT_PGA_SEC
686 * @arg @ref LL_OPAMP_INPUT_INVERT_FOLLOWER_SEC
687 */
LL_OPAMP_GetInputInvertingSecondary(OPAMP_TypeDef * OPAMPx)688 __STATIC_INLINE uint32_t LL_OPAMP_GetInputInvertingSecondary(OPAMP_TypeDef *OPAMPx)
689 {
690 return (uint32_t)(READ_BIT(OPAMPx->TCMR, OPAMP_TCMR_VMSSEL));
691 }
692
693 /**
694 * @brief Set OPAMP inputs multiplexer mode.
695 * @rmtoll TCMR TCMEN LL_OPAMP_SetInputsMuxMode
696 * @param OPAMPx OPAMP instance
697 * @param InputsMuxMode This parameter can be one of the following values:
698 * @arg @ref LL_OPAMP_INPUT_MUX_DISABLE
699 * @arg @ref LL_OPAMP_INPUT_MUX_TIM1_CH6
700 * @arg @ref LL_OPAMP_INPUT_MUX_TIM8_CH6
701 * @arg @ref LL_OPAMP_INPUT_MUX_TIM20_CH6 (1)
702 * On this STM32 series, this value is not available on all devices. Refer to datasheet for details.
703 * @retval None
704 */
LL_OPAMP_SetInputsMuxMode(OPAMP_TypeDef * OPAMPx,uint32_t InputsMuxMode)705 __STATIC_INLINE void LL_OPAMP_SetInputsMuxMode(OPAMP_TypeDef *OPAMPx, uint32_t InputsMuxMode)
706 {
707 MODIFY_REG(OPAMPx->TCMR, OPAMP_TCMR_T1CMEN | OPAMP_TCMR_T8CMEN | OPAMP_TCMR_T20CMEN, InputsMuxMode);
708 }
709
710 /**
711 * @brief Get OPAMP inputs multiplexer mode.
712 * @rmtoll TCMR TCMEN LL_OPAMP_GetInputsMuxMode
713 * @param OPAMPx OPAMP instance
714 * @retval Returned value can be one of the following values:
715 * @arg @ref LL_OPAMP_INPUT_MUX_DISABLE
716 * @arg @ref LL_OPAMP_INPUT_MUX_TIM1_CH6
717 * @arg @ref LL_OPAMP_INPUT_MUX_TIM8_CH6
718 * @arg @ref LL_OPAMP_INPUT_MUX_TIM20_CH6 (1)
719 * On this STM32 series, this value is not available on all devices. Refer to datasheet for details.
720 */
LL_OPAMP_GetInputsMuxMode(OPAMP_TypeDef * OPAMPx)721 __STATIC_INLINE uint32_t LL_OPAMP_GetInputsMuxMode(OPAMP_TypeDef *OPAMPx)
722 {
723 return (uint32_t)(READ_BIT(OPAMPx->TCMR, OPAMP_TCMR_T1CMEN | OPAMP_TCMR_T8CMEN | OPAMP_TCMR_T20CMEN));
724 }
725
726 /**
727 * @brief Set OPAMP internal output.
728 * @note OPAMP internal output is used to link OPAMP output to ADC input internally.
729 * @rmtoll CSR OPAMPINTEN LL_OPAMP_SetInternalOutput
730 * @param OPAMPx OPAMP instance
731 * @param InternalOutput This parameter can be one of the following values:
732 * @arg @ref LL_OPAMP_INTERNAL_OUPUT_DISABLED
733 * @arg @ref LL_OPAMP_INTERNAL_OUPUT_ENABLED
734 * @retval None
735 */
LL_OPAMP_SetInternalOutput(OPAMP_TypeDef * OPAMPx,uint32_t InternalOutput)736 __STATIC_INLINE void LL_OPAMP_SetInternalOutput(OPAMP_TypeDef *OPAMPx, uint32_t InternalOutput)
737 {
738 MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_OPAMPINTEN, InternalOutput);
739 }
740
741 /**
742 * @brief Get OPAMP internal output state.
743 * @rmtoll CSR OPAMPINTEN LL_OPAMP_GetInternalOutput
744 * @param OPAMPx OPAMP instance
745 * @retval Returned value can be one of the following values:
746 * @arg @ref LL_OPAMP_INTERNAL_OUPUT_DISABLED
747 * @arg @ref LL_OPAMP_INTERNAL_OUPUT_ENABLED
748 */
LL_OPAMP_GetInternalOutput(OPAMP_TypeDef * OPAMPx)749 __STATIC_INLINE uint32_t LL_OPAMP_GetInternalOutput(OPAMP_TypeDef *OPAMPx)
750 {
751 return READ_BIT(OPAMPx->CSR, OPAMP_CSR_OPAMPINTEN);
752 }
753
754 /**
755 * @}
756 */
757
758 /** @defgroup OPAMP_LL_EF_OPAMP_TRIMMING Configuration and operation of OPAMP trimming
759 * @{
760 */
761
762 /**
763 * @brief Set OPAMP trimming mode.
764 * @rmtoll CSR USERTRIM LL_OPAMP_SetTrimmingMode
765 * @param OPAMPx OPAMP instance
766 * @param TrimmingMode This parameter can be one of the following values:
767 * @arg @ref LL_OPAMP_TRIMMING_FACTORY
768 * @arg @ref LL_OPAMP_TRIMMING_USER
769 * @retval None
770 */
LL_OPAMP_SetTrimmingMode(OPAMP_TypeDef * OPAMPx,uint32_t TrimmingMode)771 __STATIC_INLINE void LL_OPAMP_SetTrimmingMode(OPAMP_TypeDef *OPAMPx, uint32_t TrimmingMode)
772 {
773 MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_USERTRIM, TrimmingMode);
774 }
775
776 /**
777 * @brief Get OPAMP trimming mode.
778 * @rmtoll CSR USERTRIM LL_OPAMP_GetTrimmingMode
779 * @param OPAMPx OPAMP instance
780 * @retval Returned value can be one of the following values:
781 * @arg @ref LL_OPAMP_TRIMMING_FACTORY
782 * @arg @ref LL_OPAMP_TRIMMING_USER
783 */
LL_OPAMP_GetTrimmingMode(OPAMP_TypeDef * OPAMPx)784 __STATIC_INLINE uint32_t LL_OPAMP_GetTrimmingMode(OPAMP_TypeDef *OPAMPx)
785 {
786 return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_USERTRIM));
787 }
788
789 /**
790 * @brief Set OPAMP offset to calibrate the selected transistors
791 * differential pair NMOS or PMOS.
792 * @note Preliminarily, OPAMP must be set in mode calibration
793 * using function @ref LL_OPAMP_SetMode().
794 * @rmtoll CSR CALSEL LL_OPAMP_SetCalibrationSelection
795 * @param OPAMPx OPAMP instance
796 * @param TransistorsDiffPair This parameter can be one of the following values:
797 * @arg @ref LL_OPAMP_TRIMMING_NMOS (1)
798 * @arg @ref LL_OPAMP_TRIMMING_PMOS (1)
799 * @arg @ref LL_OPAMP_TRIMMING_NMOS_VREF_50PC_VDDA
800 * @arg @ref LL_OPAMP_TRIMMING_PMOS_VREF_3_3PC_VDDA
801 *
802 * (1) Default parameters to be used for calibration
803 * using two trimming steps (one with each transistors differential
804 * pair NMOS and PMOS)
805 * @retval None
806 */
LL_OPAMP_SetCalibrationSelection(OPAMP_TypeDef * OPAMPx,uint32_t TransistorsDiffPair)807 __STATIC_INLINE void LL_OPAMP_SetCalibrationSelection(OPAMP_TypeDef *OPAMPx, uint32_t TransistorsDiffPair)
808 {
809 /* Parameter used with mask "OPAMP_TRIMMING_SELECT_MASK" because */
810 /* containing other bits reserved for other purpose. */
811 MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_CALSEL, (TransistorsDiffPair & OPAMP_TRIMMING_SELECT_MASK));
812 }
813
814 /**
815 * @brief Get OPAMP offset to calibrate the selected transistors
816 * differential pair NMOS or PMOS.
817 * @note Preliminarily, OPAMP must be set in mode calibration
818 * using function @ref LL_OPAMP_SetMode().
819 * @rmtoll CSR CALSEL LL_OPAMP_GetCalibrationSelection
820 * @param OPAMPx OPAMP instance
821 * @retval Returned value can be one of the following values:
822 * @arg @ref LL_OPAMP_TRIMMING_NMOS (1)
823 * @arg @ref LL_OPAMP_TRIMMING_PMOS (1)
824 * @arg @ref LL_OPAMP_TRIMMING_NMOS_VREF_50PC_VDDA
825 * @arg @ref LL_OPAMP_TRIMMING_PMOS_VREF_3_3PC_VDDA
826 *
827 * (1) Default parameters to be used for calibration
828 * using two trimming steps (one with each transistors differential
829 * pair NMOS and PMOS)
830 */
LL_OPAMP_GetCalibrationSelection(OPAMP_TypeDef * OPAMPx)831 __STATIC_INLINE uint32_t LL_OPAMP_GetCalibrationSelection(OPAMP_TypeDef *OPAMPx)
832 {
833 uint32_t CalibrationSelection = (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_CALSEL));
834
835 return (CalibrationSelection |
836 (((CalibrationSelection & OPAMP_CSR_CALSEL_1) == 0UL) ? OPAMP_CSR_TRIMOFFSETP : OPAMP_CSR_TRIMOFFSETN));
837 }
838
839 /**
840 * @brief Get OPAMP calibration result of toggling output.
841 * @note This functions returns:
842 * 0 if OPAMP calibration output is reset
843 * 1 if OPAMP calibration output is set
844 * @rmtoll CSR OUTCAL LL_OPAMP_IsCalibrationOutputSet
845 * @param OPAMPx OPAMP instance
846 * @retval State of bit (1 or 0).
847 */
LL_OPAMP_IsCalibrationOutputSet(OPAMP_TypeDef * OPAMPx)848 __STATIC_INLINE uint32_t LL_OPAMP_IsCalibrationOutputSet(OPAMP_TypeDef *OPAMPx)
849 {
850 return ((READ_BIT(OPAMPx->CSR, OPAMP_CSR_OUTCAL) == OPAMP_CSR_OUTCAL) ? 1UL : 0UL);
851 }
852
853 /**
854 * @brief Set OPAMP trimming factor for the selected transistors
855 * differential pair NMOS or PMOS, corresponding to the selected
856 * power mode.
857 * @rmtoll CSR TRIMOFFSETN LL_OPAMP_SetTrimmingValue\n
858 * CSR TRIMOFFSETP LL_OPAMP_SetTrimmingValue
859 * @param OPAMPx OPAMP instance
860 * @param TransistorsDiffPair This parameter can be one of the following values:
861 * @arg @ref LL_OPAMP_TRIMMING_NMOS
862 * @arg @ref LL_OPAMP_TRIMMING_PMOS
863 * @param TrimmingValue 0x00...0x1F
864 * @retval None
865 */
LL_OPAMP_SetTrimmingValue(OPAMP_TypeDef * OPAMPx,uint32_t TransistorsDiffPair,uint32_t TrimmingValue)866 __STATIC_INLINE void LL_OPAMP_SetTrimmingValue(OPAMP_TypeDef *OPAMPx, uint32_t TransistorsDiffPair,
867 uint32_t TrimmingValue)
868 {
869 MODIFY_REG(OPAMPx->CSR,
870 (TransistorsDiffPair & OPAMP_TRIMMING_VALUE_MASK),
871 TrimmingValue << ((TransistorsDiffPair == LL_OPAMP_TRIMMING_NMOS) ? OPAMP_CSR_TRIMOFFSETN_Pos : OPAMP_CSR_TRIMOFFSETP_Pos));
872 }
873
874 /**
875 * @brief Get OPAMP trimming factor for the selected transistors
876 * differential pair NMOS or PMOS, corresponding to the selected
877 * power mode.
878 * @rmtoll CSR TRIMOFFSETN LL_OPAMP_GetTrimmingValue\n
879 * CSR TRIMOFFSETP LL_OPAMP_GetTrimmingValue
880 * @param OPAMPx OPAMP instance
881 * @param TransistorsDiffPair This parameter can be one of the following values:
882 * @arg @ref LL_OPAMP_TRIMMING_NMOS
883 * @arg @ref LL_OPAMP_TRIMMING_PMOS
884 * @retval 0x0...0x1F
885 */
LL_OPAMP_GetTrimmingValue(OPAMP_TypeDef * OPAMPx,uint32_t TransistorsDiffPair)886 __STATIC_INLINE uint32_t LL_OPAMP_GetTrimmingValue(OPAMP_TypeDef *OPAMPx, uint32_t TransistorsDiffPair)
887 {
888 return (uint32_t)(READ_BIT(OPAMPx->CSR, (TransistorsDiffPair & OPAMP_TRIMMING_VALUE_MASK))
889 >> ((TransistorsDiffPair == LL_OPAMP_TRIMMING_NMOS) ? OPAMP_CSR_TRIMOFFSETN_Pos : OPAMP_CSR_TRIMOFFSETP_Pos));
890 }
891
892 /**
893 * @}
894 */
895
896 /** @defgroup OPAMP_LL_EF_OPERATION Operation on OPAMP instance
897 * @{
898 */
899 /**
900 * @brief Enable OPAMP instance.
901 * @note After enable from off state, OPAMP requires a delay
902 * to fulfill wake up time specification.
903 * Refer to device datasheet, parameter "tWAKEUP".
904 * @rmtoll CSR OPAMPXEN LL_OPAMP_Enable
905 * @param OPAMPx OPAMP instance
906 * @retval None
907 */
LL_OPAMP_Enable(OPAMP_TypeDef * OPAMPx)908 __STATIC_INLINE void LL_OPAMP_Enable(OPAMP_TypeDef *OPAMPx)
909 {
910 SET_BIT(OPAMPx->CSR, OPAMP_CSR_OPAMPxEN);
911 }
912
913 /**
914 * @brief Disable OPAMP instance.
915 * @rmtoll CSR OPAMPXEN LL_OPAMP_Disable
916 * @param OPAMPx OPAMP instance
917 * @retval None
918 */
LL_OPAMP_Disable(OPAMP_TypeDef * OPAMPx)919 __STATIC_INLINE void LL_OPAMP_Disable(OPAMP_TypeDef *OPAMPx)
920 {
921 CLEAR_BIT(OPAMPx->CSR, OPAMP_CSR_OPAMPxEN);
922 }
923
924 /**
925 * @brief Get OPAMP instance enable state
926 * (0: OPAMP is disabled, 1: OPAMP is enabled)
927 * @rmtoll CSR OPAMPXEN LL_OPAMP_IsEnabled
928 * @param OPAMPx OPAMP instance
929 * @retval State of bit (1 or 0).
930 */
LL_OPAMP_IsEnabled(OPAMP_TypeDef * OPAMPx)931 __STATIC_INLINE uint32_t LL_OPAMP_IsEnabled(OPAMP_TypeDef *OPAMPx)
932 {
933 return ((READ_BIT(OPAMPx->CSR, OPAMP_CSR_OPAMPxEN) == (OPAMP_CSR_OPAMPxEN)) ? 1UL : 0UL);
934 }
935
936 /**
937 * @brief Lock OPAMP instance.
938 * @note Once locked, OPAMP configuration can be accessed in read-only.
939 * @note The only way to unlock the OPAMP is a device hardware reset.
940 * @rmtoll CSR LOCK LL_OPAMP_Lock
941 * @param OPAMPx OPAMP instance
942 * @retval None
943 */
LL_OPAMP_Lock(OPAMP_TypeDef * OPAMPx)944 __STATIC_INLINE void LL_OPAMP_Lock(OPAMP_TypeDef *OPAMPx)
945 {
946 SET_BIT(OPAMPx->CSR, OPAMP_CSR_LOCK);
947 }
948
949 /**
950 * @brief Get OPAMP lock state
951 * (0: OPAMP is unlocked, 1: OPAMP is locked).
952 * @note Once locked, OPAMP configuration can be accessed in read-only.
953 * @note The only way to unlock the OPAMP is a device hardware reset.
954 * @rmtoll CSR LOCK LL_OPAMP_IsLocked
955 * @param OPAMPx OPAMP instance
956 * @retval State of bit (1 or 0).
957 */
LL_OPAMP_IsLocked(OPAMP_TypeDef * OPAMPx)958 __STATIC_INLINE uint32_t LL_OPAMP_IsLocked(OPAMP_TypeDef *OPAMPx)
959 {
960 return ((READ_BIT(OPAMPx->CSR, OPAMP_CSR_LOCK) == (OPAMP_CSR_LOCK)) ? 1UL : 0UL);
961 }
962
963 /**
964 * @brief Lock OPAMP instance timer controlled mux
965 * @note Once locked, OPAMP timer controlled mux configuration can be accessed in read-only.
966 * @note The only way to unlock the OPAMP timer controlled mux is a device hardware reset.
967 * @rmtoll TCMR LOCK LL_OPAMP_LockTimerMux
968 * @param OPAMPx OPAMP instance
969 * @retval None
970 */
LL_OPAMP_LockTimerMux(OPAMP_TypeDef * OPAMPx)971 __STATIC_INLINE void LL_OPAMP_LockTimerMux(OPAMP_TypeDef *OPAMPx)
972 {
973 SET_BIT(OPAMPx->TCMR, OPAMP_TCMR_LOCK);
974 }
975
976 /**
977 * @brief Get OPAMP timer controlled mux lock state
978 * (0: OPAMP timer controlled mux is unlocked, 1: OPAMP timer controlled mux is locked).
979 * @note Once locked, OPAMP timer controlled mux configuration can be accessed in read-only.
980 * @note The only way to unlock the OPAMP timer controlled mux is a device hardware reset.
981 * @rmtoll TCMR LOCK LL_OPAMP_IsTimerMuxLocked
982 * @param OPAMPx OPAMP instance
983 * @retval State of bit (1 or 0).
984 */
LL_OPAMP_IsTimerMuxLocked(OPAMP_TypeDef * OPAMPx)985 __STATIC_INLINE uint32_t LL_OPAMP_IsTimerMuxLocked(OPAMP_TypeDef *OPAMPx)
986 {
987 return ((READ_BIT(OPAMPx->TCMR, OPAMP_TCMR_LOCK) == (OPAMP_TCMR_LOCK)) ? 1UL : 0UL);
988 }
989
990 /**
991 * @}
992 */
993
994 #if defined(USE_FULL_LL_DRIVER)
995 /** @defgroup OPAMP_LL_EF_Init Initialization and de-initialization functions
996 * @{
997 */
998
999 ErrorStatus LL_OPAMP_DeInit(OPAMP_TypeDef *OPAMPx);
1000 ErrorStatus LL_OPAMP_Init(OPAMP_TypeDef *OPAMPx, LL_OPAMP_InitTypeDef *OPAMP_InitStruct);
1001 void LL_OPAMP_StructInit(LL_OPAMP_InitTypeDef *OPAMP_InitStruct);
1002
1003 /**
1004 * @}
1005 */
1006 #endif /* USE_FULL_LL_DRIVER */
1007
1008 /**
1009 * @}
1010 */
1011
1012 /**
1013 * @}
1014 */
1015
1016 #endif /* OPAMP1 || OPAMP2 || OPAMP3 || OPAMP4 || OPAMP5 || OPAMP6 */
1017
1018 /**
1019 * @}
1020 */
1021
1022 #ifdef __cplusplus
1023 }
1024 #endif
1025
1026 #endif /* STM32G4xx_LL_OPAMP_H */
1027
1028