1 /**
2 ******************************************************************************
3 * @file stm32u0xx_ll_opamp.h
4 * @author MCD Application Team
5 * @brief Header file of OPAMP LL module.
6 ******************************************************************************
7 * @attention
8 *
9 * Copyright (c) 2021 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 STM32U0xx_LL_OPAMP_H
21 #define STM32U0xx_LL_OPAMP_H
22
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26
27 /* Includes ------------------------------------------------------------------*/
28 #include "stm32u0xx.h"
29
30 /** @addtogroup STM32U0xx_LL_Driver
31 * @{
32 */
33
34 #if defined (OPAMP1)
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 power mode: */
49 /* To select into literal LL_OPAMP_POWERMODE_x the relevant bits for: */
50 /* - OPAMP power mode into control register */
51 /* - OPAMP trimming register offset */
52
53 /* Internal register offset for OPAMP trimming configuration */
54 #define OPAMP_POWERMODE_OTR_REGOFFSET 0x00000000U
55 #define OPAMP_POWERMODE_LPOTR_REGOFFSET 0x00000002U
56 #define OPAMP_POWERMODE_OTR_REGOFFSET_MASK (OPAMP_POWERMODE_OTR_REGOFFSET | OPAMP_POWERMODE_LPOTR_REGOFFSET)
57
58 /* Mask for OPAMP power mode into control register */
59 #define OPAMP_POWERMODE_CSR_BIT_MASK (OPAMP_CSR_OPALPM)
60
61 /* Internal mask for OPAMP trimming of transistors differential pair NMOS */
62 /* or PMOS. */
63 /* To select into literal LL_OPAMP_TRIMMING_x the relevant bits for: */
64 /* - OPAMP trimming selection of transistors differential pair */
65 /* - OPAMP trimming values of transistors differential pair */
66 #define OPAMP_TRIMMING_SELECT_MASK (OPAMP_CSR_CALSEL)
67 #define OPAMP_TRIMMING_VALUE_MASK (OPAMP_OTR_TRIMOFFSETP | OPAMP_OTR_TRIMOFFSETN)
68
69 /**
70 * @}
71 */
72
73
74 /* Private macros ------------------------------------------------------------*/
75 /** @defgroup OPAMP_LL_Private_Macros OPAMP Private Macros
76 * @{
77 */
78
79 /**
80 * @brief Driver macro reserved for internal use: set a pointer to
81 * a register from a register basis from which an offset
82 * is applied.
83 * @param __REG__ Register basis from which the offset is applied.
84 * @param __REG_OFFSET__ Offset to be applied (unit: number of registers).
85 * @retval Register address
86 */
87 #define __OPAMP_PTR_REG_OFFSET(__REG__, __REG_OFFSET__) \
88 ((uint32_t *)((uint32_t) ((uint32_t)(&(__REG__)) + ((__REG_OFFSET__) << 1U))))
89 /**
90 * @}
91 */
92
93 /* Exported types ------------------------------------------------------------*/
94 #if defined(USE_FULL_LL_DRIVER)
95 /** @defgroup OPAMP_LL_ES_INIT OPAMP Exported Init structure
96 * @{
97 */
98
99 /**
100 * @brief Structure definition of some features of OPAMP instance.
101 */
102 typedef struct
103 {
104 uint32_t PowerMode; /*!< Set the power mode Normal or Low-Power and the speed mode Normal or High.
105 This parameter can be a value of @ref OPAMP_LL_EC_POWERMODE
106 This feature can be modified afterwards using
107 unitary function @ref LL_OPAMP_SetPowerMode(). */
108
109 uint32_t FunctionalMode; /*!< Set OPAMP functional mode by setting internal connections:
110 OPAMP operation in standalone, follower, ...
111 This parameter can be a value of @ref OPAMP_LL_EC_FUNCTIONAL_MODE
112 @note If OPAMP is configured in mode PGA, the gain can be configured
113 using function @ref LL_OPAMP_SetPGAGain().
114 This feature can be modified afterwards using unitary
115 function @ref LL_OPAMP_SetFunctionalMode(). */
116
117 uint32_t InputNonInverting; /*!< Set OPAMP input non-inverting connection.
118 This parameter can be a value of @ref OPAMP_LL_EC_INPUT_NONINVERTING
119 This feature can be modified afterwards using
120 unitary function @ref LL_OPAMP_SetInputNonInverting(). */
121
122 uint32_t InputInverting; /*!< Set OPAMP inverting input connection.
123 This parameter can be a value of @ref OPAMP_LL_EC_INPUT_INVERTING
124 @note OPAMP inverting input is used with OPAMP in mode
125 standalone or PGA with external capacitors for filtering circuit.
126 Otherwise (OPAMP in mode follower), OPAMP inverting input is not used
127 (not connected to GPIO pin), this parameter is discarded.
128 This feature can be modified afterwards using
129 unitary function @ref LL_OPAMP_SetInputInverting(). */
130
131 } LL_OPAMP_InitTypeDef;
132
133 /**
134 * @}
135 */
136 #endif /* USE_FULL_LL_DRIVER */
137
138 /* Exported constants --------------------------------------------------------*/
139 /** @defgroup OPAMP_LL_Exported_Constants OPAMP Exported Constants
140 * @{
141 */
142
143 /** @defgroup OPAMP_LL_EC_POWERSUPPLY_RANGE OPAMP power supply range
144 * @{
145 */
146 #define LL_OPAMP_POWERSUPPLY_RANGE_LOW 0x00000000U /*!< Power supply range low */
147 #define LL_OPAMP_POWERSUPPLY_RANGE_HIGH (OPAMP_CSR_OPARANGE) /*!< Power supply range high - recommended for performance purpose */
148 /**
149 * @}
150 */
151
152 /** @defgroup OPAMP_LL_EC_POWERMODE OPAMP power mode
153 * @{
154 */
155 #define LL_OPAMP_POWERMODE_NORMALPOWER_NORMALSPEED 0x00000000U /*!< OPAMP power mode normal speed normal */
156 #define LL_OPAMP_POWERMODE_LOWPOWER_NORMALSPEED OPAMP_CSR_OPALPM /*!< OPAMP power mode low-power speed normal */
157 /**
158 * @}
159 */
160
161 /** @defgroup OPAMP_LL_EC_MODE OPAMP mode calibration or functional.
162 * @{
163 */
164 #define LL_OPAMP_MODE_FUNCTIONAL 0x00000000U /*!< OPAMP functional mode */
165 #define LL_OPAMP_MODE_CALIBRATION (OPAMP_CSR_CALON) /*!< OPAMP calibration mode */
166 /**
167 * @}
168 */
169
170 /** @defgroup OPAMP_LL_EC_FUNCTIONAL_MODE OPAMP functional mode
171 * @{
172 */
173 #define LL_OPAMP_MODE_STANDALONE 0x00000000U /*!< OPAMP functional mode, OPAMP operation in standalone */
174 #define LL_OPAMP_MODE_FOLLOWER (OPAMP_CSR_OPAMODE_1 | OPAMP_CSR_OPAMODE_0) /*!< OPAMP functional mode, OPAMP operation in follower */
175 #define LL_OPAMP_MODE_PGA (OPAMP_CSR_OPAMODE_1) /*!< OPAMP functional mode, OPAMP operation in PGA */
176 /**
177 * @}
178 */
179
180 /** @defgroup OPAMP_LL_EC_MODE_PGA_GAIN OPAMP PGA gain (relevant when OPAMP is in functional mode PGA)
181 * @{
182 */
183 #define LL_OPAMP_PGA_GAIN_2 0x00000000U /*!< OPAMP PGA gain 2 */
184 #define LL_OPAMP_PGA_GAIN_4 (OPAMP_CSR_PGA_GAIN_0) /*!< OPAMP PGA gain 4 */
185 #define LL_OPAMP_PGA_GAIN_8 (OPAMP_CSR_PGA_GAIN_1) /*!< OPAMP PGA gain 8 */
186 #define LL_OPAMP_PGA_GAIN_16 (OPAMP_CSR_PGA_GAIN_1 | OPAMP_CSR_PGA_GAIN_0) /*!< OPAMP PGA gain 16 */
187 /**
188 * @}
189 */
190
191 /** @defgroup OPAMP_LL_EC_INPUT_NONINVERTING OPAMP input non-inverting
192 * @{
193 */
194 #define LL_OPAMP_INPUT_NONINVERT_IO0 0x00000000U /*!< OPAMP non inverting input connected to GPIO pin (pin PA0 for OPAMP1) */
195 #define LL_OPAMP_INPUT_NONINV_DAC1_CH1 (OPAMP_CSR_VP_SEL) /*!< OPAMP non inverting input connected to DAC1 channel output(channel1 for OPAMP1) */
196 /**
197 * @}
198 */
199
200 /** @defgroup OPAMP_LL_EC_INPUT_INVERTING OPAMP input inverting
201 * @{
202 */
203 #define LL_OPAMP_INPUT_INVERT_IO0 0x00000000U /*!< OPAMP inverting input connected to GPIO pin (valid also in PGA mode for filtering). 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). */
204 #define LL_OPAMP_INPUT_INVERT_CONNECT_NO (OPAMP_CSR_VM_SEL_1) /*!< OPAMP inverting input not externally connected (intended for OPAMP in mode follower or PGA without external capacitors for filtering) */
205 /**
206 * @}
207 */
208
209
210 /** @defgroup OPAMP_LL_EC_TRIMMING_MODE OPAMP trimming mode
211 * @{
212 */
213 #define LL_OPAMP_TRIMMING_FACTORY 0x00000000U /*!< OPAMP trimming factors set to factory values */
214 #define LL_OPAMP_TRIMMING_USER (OPAMP_CSR_USERTRIM) /*!< OPAMP trimming factors set to user values */
215 /**
216 * @}
217 */
218
219 /** @defgroup OPAMP_LL_EC_TRIMMING_TRANSISTORS_DIFF_PAIR OPAMP trimming of transistors differential pair NMOS or PMOS
220 * @{
221 */
222 #define LL_OPAMP_TRIMMING_NMOS (OPAMP_OTR_TRIMOFFSETN) /*!< OPAMP trimming of transistors differential pair NMOS */
223 #define LL_OPAMP_TRIMMING_PMOS (OPAMP_OTR_TRIMOFFSETP | OPAMP_CSR_CALSEL) /*!< OPAMP trimming of transistors differential pair PMOS */
224 /**
225 * @}
226 */
227
228 /** @defgroup OPAMP_LL_EC_HW_DELAYS Definitions of OPAMP hardware constraints delays
229 * @note Only OPAMP IP HW delays are defined in OPAMP LL driver driver,
230 * not timeout values.
231 * For details on delays values, refer to descriptions in source code
232 * above each literal definition.
233 * @{
234 */
235
236 /* Delay for OPAMP startup time (transition from state disable to enable). */
237 /* Note: OPAMP startup time depends on board application environment: */
238 /* impedance connected to OPAMP output. */
239 /* The delay below is specified under conditions: */
240 /* - OPAMP in mode low power */
241 /* - OPAMP in functional mode follower */
242 /* - load impedance of 4kOhm (min), 50pF (max) */
243 /* Literal set to maximum value (refer to device datasheet, */
244 /* parameter "tWAKEUP"). */
245 /* Unit: us */
246 #define LL_OPAMP_DELAY_STARTUP_US ((uint32_t) 30U) /*!< Delay for OPAMP startup time */
247
248 /**
249 * @}
250 */
251
252 /**
253 * @}
254 */
255
256 /* Exported macro ------------------------------------------------------------*/
257 /** @defgroup OPAMP_LL_Exported_Macros OPAMP Exported Macros
258 * @{
259 */
260 /** @defgroup OPAMP_LL_EM_WRITE_READ Common write and read registers macro
261 * @{
262 */
263 /**
264 * @brief Write a value in OPAMP register
265 * @param __INSTANCE__ OPAMP Instance
266 * @param __REG__ Register to be written
267 * @param __VALUE__ Value to be written in the register
268 * @retval None
269 */
270 #define LL_OPAMP_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG((__INSTANCE__)->__REG__, (__VALUE__))
271
272 /**
273 * @brief Read a value in OPAMP register
274 * @param __INSTANCE__ OPAMP Instance
275 * @param __REG__ Register to be read
276 * @retval Register value
277 */
278 #define LL_OPAMP_ReadReg(__INSTANCE__, __REG__) READ_REG((__INSTANCE__)->__REG__)
279 /**
280 * @}
281 */
282
283 /** @defgroup OPAMP_LL_EM_HELPER_MACRO OPAMP helper macro
284 * @{
285 */
286
287 /**
288 * @brief Helper macro to select the OPAMP common instance
289 * to which is belonging the selected OPAMP instance.
290 * @note OPAMP common register instance can be used to
291 * set parameters common to several OPAMP instances.
292 * Refer to functions having argument "OPAMPxy_COMMON" as parameter.
293 * @param __OPAMPx__ OPAMP instance
294 * @retval OPAMP common instance
295 */
296 #define __LL_OPAMP_COMMON_INSTANCE(__OPAMPx__) (OPAMP1_COMMON)
297
298 /**
299 * @brief Helper macro to check if all OPAMP instances sharing the same
300 * OPAMP common instance are disabled.
301 * @note This check is required by functions with setting conditioned to
302 * OPAMP state:
303 * All OPAMP instances of the OPAMP common group must be disabled.
304 * Refer to functions having argument "OPAMPxy_COMMON" as parameter.
305 * @retval 0: All OPAMP instances sharing the same OPAMP common instance
306 * are disabled.
307 * 1: At least one OPAMP instance sharing the same OPAMP common instance
308 * is enabled
309 */
310 #if defined(OPAMP1) && defined(OPAMP2)
311 #define __LL_OPAMP_IS_ENABLED_ALL_COMMON_INSTANCE() \
312 (LL_OPAMP_IsEnabled(OPAMP1) | \
313 LL_OPAMP_IsEnabled(OPAMP2) )
314 #else
315 #define __LL_OPAMP_IS_ENABLED_ALL_COMMON_INSTANCE() \
316 (LL_OPAMP_IsEnabled(OPAMP1))
317 #endif /* defined(OPAMP1) && defined(OPAMP2) */
318 /**
319 * @}
320 */
321
322 /* Exported functions --------------------------------------------------------*/
323 /** @defgroup OPAMP_LL_Exported_Functions OPAMP Exported Functions
324 * @{
325 */
326
327 /** @defgroup OPAMP_LL_EF_Configuration_opamp_common Configuration of OPAMP hierarchical scope: common OPAMP instances
328 * @{
329 */
330
331 /**
332 * @brief Set OPAMP power range.
333 * @note The OPAMP power range applies to several OPAMP instances
334 * (if several OPAMP instances available on the selected device).
335 * It is mandatory to set already the power range to high for performance purpose.
336 * @note On this STM32 series, setting of this feature is conditioned to
337 * OPAMP state:
338 * All OPAMP instances of the OPAMP common group must be disabled.
339 * This check can be done with function @ref LL_OPAMP_IsEnabled() for each
340 * OPAMP instance.
341 * @note LL_OPAMP_POWERSUPPLY_RANGE_HIGH parameter is highly recommended for performance purpose.
342 * @rmtoll CSR OPARANGE LL_OPAMP_SetCommonPowerRange
343 * @param OPAMPxy_COMMON OPAMP common instance
344 * @param PowerRange This parameter can be one of the following values:
345 * @arg @ref LL_OPAMP_POWERSUPPLY_RANGE_LOW
346 * @arg @ref LL_OPAMP_POWERSUPPLY_RANGE_HIGH
347 * @retval None
348 */
LL_OPAMP_SetCommonPowerRange(OPAMP_Common_TypeDef * OPAMPxy_COMMON,uint32_t PowerRange)349 __STATIC_INLINE void LL_OPAMP_SetCommonPowerRange(OPAMP_Common_TypeDef *OPAMPxy_COMMON, uint32_t PowerRange)
350 {
351 MODIFY_REG(OPAMPxy_COMMON->CSR, OPAMP_CSR_OPARANGE, PowerRange);
352 }
353
354 /**
355 * @brief Get OPAMP power range.
356 * @note The OPAMP power range applies to several OPAMP instances
357 * (if several OPAMP instances available on the selected device).
358 * @rmtoll CSR OPARANGE LL_OPAMP_GetCommonPowerRange
359 * @param OPAMPxy_COMMON OPAMP common instance
360 * @retval Returned value can be one of the following values:
361 * @arg @ref LL_OPAMP_POWERSUPPLY_RANGE_LOW
362 * @arg @ref LL_OPAMP_POWERSUPPLY_RANGE_HIGH
363 */
LL_OPAMP_GetCommonPowerRange(const OPAMP_Common_TypeDef * OPAMPxy_COMMON)364 __STATIC_INLINE uint32_t LL_OPAMP_GetCommonPowerRange(const OPAMP_Common_TypeDef *OPAMPxy_COMMON)
365 {
366 return (uint32_t)(READ_BIT(OPAMPxy_COMMON->CSR, OPAMP_CSR_OPARANGE));
367 }
368
369 /**
370 * @}
371 */
372
373 /** @defgroup OPAMP_LL_EF_CONFIGURATION_OPAMP_INSTANCE Configuration of OPAMP hierarchical scope: OPAMP instance
374 * @{
375 */
376
377 /**
378 * @brief Set OPAMP power mode.
379 * @note The OPAMP must be disabled to change this configuration.
380 * @rmtoll CSR OPALPM LL_OPAMP_SetPowerMode
381 * @param OPAMPx OPAMP instance
382 * @param PowerMode This parameter can be one of the following values:
383 * @arg @ref LL_OPAMP_POWERMODE_NORMALPOWER_NORMALSPEED
384 * @arg @ref LL_OPAMP_POWERMODE_LOWPOWER_NORMALSPEED
385 * @retval None
386 */
LL_OPAMP_SetPowerMode(OPAMP_TypeDef * OPAMPx,uint32_t PowerMode)387 __STATIC_INLINE void LL_OPAMP_SetPowerMode(OPAMP_TypeDef *OPAMPx, uint32_t PowerMode)
388 {
389 MODIFY_REG(OPAMPx->CSR, OPAMP_POWERMODE_CSR_BIT_MASK, PowerMode);
390 }
391
392 /**
393 * @brief Get OPAMP power mode.
394 * @rmtoll CSR OPALPM & HSM LL_OPAMP_GetPowerMode
395 * @param OPAMPx OPAMP instance
396 * @retval Returned value can be one of the following values:
397 * @arg @ref LL_OPAMP_POWERMODE_NORMALPOWER_NORMALSPEED
398 * @arg @ref LL_OPAMP_POWERMODE_LOWPOWER_NORMALSPEED
399 */
LL_OPAMP_GetPowerMode(const OPAMP_TypeDef * OPAMPx)400 __STATIC_INLINE uint32_t LL_OPAMP_GetPowerMode(const OPAMP_TypeDef *OPAMPx)
401 {
402 uint32_t power_mode = (READ_BIT(OPAMPx->CSR, OPAMP_POWERMODE_CSR_BIT_MASK));
403
404 return (uint32_t)(power_mode);
405 }
406
407 /**
408 * @brief Set OPAMP mode calibration or functional.
409 * @note OPAMP mode corresponds to functional or calibration mode:
410 * - functional mode: OPAMP operation in standalone, follower, ...
411 * Set functional mode using function
412 * @ref LL_OPAMP_SetFunctionalMode().
413 * - calibration mode: offset calibration of the selected
414 * transistors differential pair NMOS or PMOS.
415 * @note On this STM32 series, during calibration, OPAMP functional
416 * mode must be set to standalone or follower mode
417 * (in order to open internal connections to resistors
418 * of PGA mode).
419 * Refer to function @ref LL_OPAMP_SetFunctionalMode().
420 * @rmtoll CSR CALON LL_OPAMP_SetMode
421 * @param OPAMPx OPAMP instance
422 * @param Mode This parameter can be one of the following values:
423 * @arg @ref LL_OPAMP_MODE_FUNCTIONAL
424 * @arg @ref LL_OPAMP_MODE_CALIBRATION
425 * @retval None
426 */
LL_OPAMP_SetMode(OPAMP_TypeDef * OPAMPx,uint32_t Mode)427 __STATIC_INLINE void LL_OPAMP_SetMode(OPAMP_TypeDef *OPAMPx, uint32_t Mode)
428 {
429 MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_CALON, Mode);
430 }
431
432 /**
433 * @brief Get OPAMP mode calibration or functional.
434 * @note OPAMP mode corresponds to functional or calibration mode:
435 * - functional mode: OPAMP operation in standalone, follower, ...
436 * Set functional mode using function
437 * @ref LL_OPAMP_SetFunctionalMode().
438 * - calibration mode: offset calibration of the selected
439 * transistors differential pair NMOS or PMOS.
440 * @rmtoll CSR CALON LL_OPAMP_GetMode
441 * @param OPAMPx OPAMP instance
442 * @retval Returned value can be one of the following values:
443 * @arg @ref LL_OPAMP_MODE_FUNCTIONAL
444 * @arg @ref LL_OPAMP_MODE_CALIBRATION
445 */
LL_OPAMP_GetMode(const OPAMP_TypeDef * OPAMPx)446 __STATIC_INLINE uint32_t LL_OPAMP_GetMode(const OPAMP_TypeDef *OPAMPx)
447 {
448 return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_CALON));
449 }
450
451 /**
452 * @brief Set OPAMP functional mode by setting internal connections.
453 * OPAMP operation in standalone, follower, ...
454 * @note This function reset bit of calibration mode to ensure
455 * to be in functional mode, in order to have OPAMP parameters
456 * (inputs selection, ...) set with the corresponding OPAMP mode
457 * to be effective.
458 * @rmtoll CSR OPAMODE LL_OPAMP_SetFunctionalMode
459 * @param OPAMPx OPAMP instance
460 * @param FunctionalMode This parameter can be one of the following values:
461 * @arg @ref LL_OPAMP_MODE_STANDALONE
462 * @arg @ref LL_OPAMP_MODE_FOLLOWER
463 * @arg @ref LL_OPAMP_MODE_PGA
464 * @retval None
465 */
LL_OPAMP_SetFunctionalMode(OPAMP_TypeDef * OPAMPx,uint32_t FunctionalMode)466 __STATIC_INLINE void LL_OPAMP_SetFunctionalMode(OPAMP_TypeDef *OPAMPx, uint32_t FunctionalMode)
467 {
468 /* Note: Bit OPAMP_CSR_CALON reset to ensure to be in functional mode */
469 MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_OPAMODE | OPAMP_CSR_CALON, FunctionalMode);
470 }
471
472 /**
473 * @brief Get OPAMP functional mode from setting of internal connections.
474 * OPAMP operation in standalone, follower, ...
475 * @rmtoll CSR OPAMODE LL_OPAMP_GetFunctionalMode
476 * @param OPAMPx OPAMP instance
477 * @retval Returned value can be one of the following values:
478 * @arg @ref LL_OPAMP_MODE_STANDALONE
479 * @arg @ref LL_OPAMP_MODE_FOLLOWER
480 * @arg @ref LL_OPAMP_MODE_PGA
481 */
LL_OPAMP_GetFunctionalMode(const OPAMP_TypeDef * OPAMPx)482 __STATIC_INLINE uint32_t LL_OPAMP_GetFunctionalMode(const OPAMP_TypeDef *OPAMPx)
483 {
484 return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_OPAMODE));
485 }
486
487 /**
488 * @brief Set OPAMP PGA gain.
489 * @note Preliminarily, OPAMP must be set in mode PGA
490 * using function @ref LL_OPAMP_SetFunctionalMode().
491 * @rmtoll CSR PGGAIN LL_OPAMP_SetPGAGain
492 * @param OPAMPx OPAMP instance
493 * @param PGAGain This parameter can be one of the following values:
494 * @arg @ref LL_OPAMP_PGA_GAIN_2
495 * @arg @ref LL_OPAMP_PGA_GAIN_4
496 * @arg @ref LL_OPAMP_PGA_GAIN_8
497 * @arg @ref LL_OPAMP_PGA_GAIN_16
498 * @retval None
499 */
LL_OPAMP_SetPGAGain(OPAMP_TypeDef * OPAMPx,uint32_t PGAGain)500 __STATIC_INLINE void LL_OPAMP_SetPGAGain(OPAMP_TypeDef *OPAMPx, uint32_t PGAGain)
501 {
502 MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_PGA_GAIN, PGAGain);
503 }
504
505 /**
506 * @brief Get OPAMP PGA gain.
507 * @note Preliminarily, OPAMP must be set in mode PGA
508 * using function @ref LL_OPAMP_SetFunctionalMode().
509 * @rmtoll CSR PGGAIN LL_OPAMP_GetPGAGain
510 * @param OPAMPx OPAMP instance
511 * @retval Returned value can be one of the following values:
512 * @arg @ref LL_OPAMP_PGA_GAIN_2
513 * @arg @ref LL_OPAMP_PGA_GAIN_4
514 * @arg @ref LL_OPAMP_PGA_GAIN_8
515 * @arg @ref LL_OPAMP_PGA_GAIN_16
516 */
LL_OPAMP_GetPGAGain(const OPAMP_TypeDef * OPAMPx)517 __STATIC_INLINE uint32_t LL_OPAMP_GetPGAGain(const OPAMP_TypeDef *OPAMPx)
518 {
519 return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_PGA_GAIN));
520 }
521
522 /**
523 * @}
524 */
525
526 /** @defgroup OPAMP_LL_EF_CONFIGURATION_INPUTS Configuration of OPAMP inputs
527 * @{
528 */
529
530 /**
531 * @brief Set OPAMP non-inverting input connection.
532 * @rmtoll CSR VPSEL LL_OPAMP_SetInputNonInverting
533 * @param OPAMPx OPAMP instance
534 * @param InputNonInverting This parameter can be one of the following values:
535 * @arg @ref LL_OPAMP_INPUT_NONINVERT_IO0
536 * @arg @ref LL_OPAMP_INPUT_NONINV_DAC1_CH1
537 * @retval None
538 */
LL_OPAMP_SetInputNonInverting(OPAMP_TypeDef * OPAMPx,uint32_t InputNonInverting)539 __STATIC_INLINE void LL_OPAMP_SetInputNonInverting(OPAMP_TypeDef *OPAMPx, uint32_t InputNonInverting)
540 {
541 MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_VP_SEL, InputNonInverting);
542 }
543
544 /**
545 * @brief Get OPAMP non-inverting input connection.
546 * @rmtoll CSR VPSEL LL_OPAMP_GetInputNonInverting
547 * @param OPAMPx OPAMP instance
548 * @retval Returned value can be one of the following values:
549 * @arg @ref LL_OPAMP_INPUT_NONINVERT_IO0
550 * @arg @ref LL_OPAMP_INPUT_NONINV_DAC1_CH1
551 */
LL_OPAMP_GetInputNonInverting(const OPAMP_TypeDef * OPAMPx)552 __STATIC_INLINE uint32_t LL_OPAMP_GetInputNonInverting(const OPAMP_TypeDef *OPAMPx)
553 {
554 return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_VP_SEL));
555 }
556
557 /**
558 * @brief Set OPAMP inverting input connection.
559 * @note OPAMP inverting input is used with OPAMP in mode standalone
560 * or PGA with external capacitors for filtering circuit.
561 * Otherwise (OPAMP in mode follower), OPAMP inverting input
562 * is not used (not connected to GPIO pin).
563 * @rmtoll CSR VMSEL LL_OPAMP_SetInputInverting
564 * @param OPAMPx OPAMP instance
565 * @param InputInverting This parameter can be one of the following values:
566 * @arg @ref LL_OPAMP_INPUT_INVERT_IO0
567 * @arg @ref LL_OPAMP_INPUT_INVERT_CONNECT_NO
568 * @retval None
569 */
LL_OPAMP_SetInputInverting(OPAMP_TypeDef * OPAMPx,uint32_t InputInverting)570 __STATIC_INLINE void LL_OPAMP_SetInputInverting(OPAMP_TypeDef *OPAMPx, uint32_t InputInverting)
571 {
572 MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_VM_SEL, InputInverting);
573 }
574
575 /**
576 * @brief Get OPAMP inverting input connection.
577 * @rmtoll CSR VMSEL LL_OPAMP_GetInputInverting
578 * @param OPAMPx OPAMP instance
579 * @retval Returned value can be one of the following values:
580 * @arg @ref LL_OPAMP_INPUT_INVERT_IO0
581 * @arg @ref LL_OPAMP_INPUT_INVERT_CONNECT_NO
582 */
LL_OPAMP_GetInputInverting(const OPAMP_TypeDef * OPAMPx)583 __STATIC_INLINE uint32_t LL_OPAMP_GetInputInverting(const OPAMP_TypeDef *OPAMPx)
584 {
585 return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_VM_SEL));
586 }
587
588 /**
589 * @}
590 */
591
592 /** @defgroup OPAMP_LL_EF_Configuration_Legacy_Functions Configuration of OPAMP, legacy functions name
593 * @{
594 */
595 /* Old functions name kept for legacy purpose, to be replaced by the */
596 /* current functions name. */
LL_OPAMP_SetNonInvertingInput(OPAMP_TypeDef * OPAMPx,uint32_t NonInvertingInput)597 __STATIC_INLINE void LL_OPAMP_SetNonInvertingInput(OPAMP_TypeDef *OPAMPx, uint32_t NonInvertingInput)
598 {
599 LL_OPAMP_SetInputNonInverting(OPAMPx, NonInvertingInput);
600 }
601
LL_OPAMP_SetInvertingInput(OPAMP_TypeDef * OPAMPx,uint32_t InvertingInput)602 __STATIC_INLINE void LL_OPAMP_SetInvertingInput(OPAMP_TypeDef *OPAMPx, uint32_t InvertingInput)
603 {
604 LL_OPAMP_SetInputInverting(OPAMPx, InvertingInput);
605 }
606
607 /**
608 * @}
609 */
610
611 /** @defgroup OPAMP_LL_EF_OPAMP_TRIMMING Configuration and operation of OPAMP trimming
612 * @{
613 */
614
615 /**
616 * @brief Set OPAMP trimming mode.
617 * @rmtoll CSR USERTRIM LL_OPAMP_SetTrimmingMode
618 * @param OPAMPx OPAMP instance
619 * @param TrimmingMode This parameter can be one of the following values:
620 * @arg @ref LL_OPAMP_TRIMMING_FACTORY
621 * @arg @ref LL_OPAMP_TRIMMING_USER
622 * @retval None
623 */
LL_OPAMP_SetTrimmingMode(OPAMP_TypeDef * OPAMPx,uint32_t TrimmingMode)624 __STATIC_INLINE void LL_OPAMP_SetTrimmingMode(OPAMP_TypeDef *OPAMPx, uint32_t TrimmingMode)
625 {
626 MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_USERTRIM, TrimmingMode);
627 }
628
629 /**
630 * @brief Get OPAMP trimming mode.
631 * @rmtoll CSR USERTRIM LL_OPAMP_GetTrimmingMode
632 * @param OPAMPx OPAMP instance
633 * @retval Returned value can be one of the following values:
634 * @arg @ref LL_OPAMP_TRIMMING_FACTORY
635 * @arg @ref LL_OPAMP_TRIMMING_USER
636 */
LL_OPAMP_GetTrimmingMode(const OPAMP_TypeDef * OPAMPx)637 __STATIC_INLINE uint32_t LL_OPAMP_GetTrimmingMode(const OPAMP_TypeDef *OPAMPx)
638 {
639 return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_USERTRIM));
640 }
641
642 /**
643 * @brief Set OPAMP offset to calibrate the selected transistors
644 * differential pair NMOS or PMOS.
645 * @note Preliminarily, OPAMP must be set in mode calibration
646 * using function @ref LL_OPAMP_SetMode().
647 * @rmtoll CSR CALSEL LL_OPAMP_SetCalibrationSelection
648 * @param OPAMPx OPAMP instance
649 * @param TransistorsDiffPair This parameter can be one of the following values:
650 * @arg @ref LL_OPAMP_TRIMMING_NMOS
651 * @arg @ref LL_OPAMP_TRIMMING_PMOS
652 * @retval None
653 */
LL_OPAMP_SetCalibrationSelection(OPAMP_TypeDef * OPAMPx,uint32_t TransistorsDiffPair)654 __STATIC_INLINE void LL_OPAMP_SetCalibrationSelection(OPAMP_TypeDef *OPAMPx, uint32_t TransistorsDiffPair)
655 {
656 /* Parameter used with mask "OPAMP_TRIMMING_SELECT_MASK" because */
657 /* containing other bits reserved for other purpose. */
658 MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_CALSEL, (TransistorsDiffPair & OPAMP_TRIMMING_SELECT_MASK));
659 }
660
661 /**
662 * @brief Get OPAMP offset to calibrate the selected transistors
663 * differential pair NMOS or PMOS.
664 * @note Preliminarily, OPAMP must be set in mode calibration
665 * using function @ref LL_OPAMP_SetMode().
666 * @rmtoll CSR CALSEL LL_OPAMP_GetCalibrationSelection
667 * @param OPAMPx OPAMP instance
668 * @retval Returned value can be one of the following values:
669 * @arg @ref LL_OPAMP_TRIMMING_NMOS
670 * @arg @ref LL_OPAMP_TRIMMING_PMOS
671 */
LL_OPAMP_GetCalibrationSelection(const OPAMP_TypeDef * OPAMPx)672 __STATIC_INLINE uint32_t LL_OPAMP_GetCalibrationSelection(const OPAMP_TypeDef *OPAMPx)
673 {
674 uint32_t CalibrationSelection = (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_CALSEL));
675
676 return (CalibrationSelection |
677 (((CalibrationSelection & OPAMP_CSR_CALSEL) == 0UL) ? OPAMP_OTR_TRIMOFFSETN : OPAMP_OTR_TRIMOFFSETP));
678 }
679
680 /**
681 * @brief Get OPAMP calibration result of toggling output.
682 * @note This functions returns:
683 * 0 if OPAMP calibration output is reset
684 * 1 if OPAMP calibration output is set
685 * @rmtoll CSR CALOUT LL_OPAMP_IsCalibrationOutputSet
686 * @param OPAMPx OPAMP instance
687 * @retval State of bit (1 or 0).
688 */
LL_OPAMP_IsCalibrationOutputSet(const OPAMP_TypeDef * OPAMPx)689 __STATIC_INLINE uint32_t LL_OPAMP_IsCalibrationOutputSet(const OPAMP_TypeDef *OPAMPx)
690 {
691 return ((READ_BIT(OPAMPx->CSR, OPAMP_CSR_CALOUT) == OPAMP_CSR_CALOUT) ? 1UL : 0UL);
692 }
693
694 /**
695 * @brief Set OPAMP trimming factor for the selected transistors
696 * differential pair NMOS or PMOS, corresponding to the selected
697 * power mode.
698 * @rmtoll OTR TRIMOFFSETN LL_OPAMP_SetTrimmingValue
699 * OTR TRIMOFFSETP LL_OPAMP_SetTrimmingValue
700 * LPOTR TRIMLPOFFSETN LL_OPAMP_SetTrimmingValue
701 * LPOTR TRIMLPOFFSETP LL_OPAMP_SetTrimmingValue
702 * @param OPAMPx OPAMP instance
703 * @param PowerMode This parameter can be one of the following values:
704 * @arg @ref LL_OPAMP_POWERMODE_NORMALPOWER_NORMALSPEED
705 * @arg @ref LL_OPAMP_POWERMODE_LOWPOWER_NORMALSPEED
706 * @param TransistorsDiffPair This parameter can be one of the following values:
707 * @arg @ref LL_OPAMP_TRIMMING_NMOS
708 * @arg @ref LL_OPAMP_TRIMMING_PMOS
709 * @param TrimmingValue 0x00...0x1F
710 * @retval None
711 */
LL_OPAMP_SetTrimmingValue(OPAMP_TypeDef * OPAMPx,uint32_t PowerMode,uint32_t TransistorsDiffPair,uint32_t TrimmingValue)712 __STATIC_INLINE void LL_OPAMP_SetTrimmingValue(OPAMP_TypeDef *OPAMPx, uint32_t PowerMode, uint32_t TransistorsDiffPair,
713 uint32_t TrimmingValue)
714 {
715 __IO uint32_t *preg = __OPAMP_PTR_REG_OFFSET(OPAMPx->OTR, (PowerMode & OPAMP_POWERMODE_OTR_REGOFFSET_MASK));
716
717 /* Set bits with position in register depending on parameter */
718 /* "TransistorsDiffPair". */
719 /* Parameter used with mask "OPAMP_TRIMMING_VALUE_MASK" because */
720 /* containing other bits reserved for other purpose. */
721 MODIFY_REG(*preg,
722 (TransistorsDiffPair & OPAMP_TRIMMING_VALUE_MASK),
723 TrimmingValue << (
724 (TransistorsDiffPair == LL_OPAMP_TRIMMING_NMOS) ? OPAMP_OTR_TRIMOFFSETN_Pos : OPAMP_OTR_TRIMOFFSETP_Pos)
725 );
726 }
727
728 /**
729 * @brief Get OPAMP trimming factor for the selected transistors
730 * differential pair NMOS or PMOS, corresponding to the selected
731 * power mode.
732 * @rmtoll OTR TRIMOFFSETN LL_OPAMP_GetTrimmingValue
733 * OTR TRIMOFFSETP LL_OPAMP_GetTrimmingValue
734 * LPOTR TRIMLPOFFSETN LL_OPAMP_GetTrimmingValue
735 * LPOTR TRIMLPOFFSETP LL_OPAMP_GetTrimmingValue
736 * @param OPAMPx OPAMP instance
737 * @param PowerMode This parameter can be one of the following values:
738 * @arg @ref LL_OPAMP_POWERMODE_NORMALPOWER_NORMALSPEED
739 * @arg @ref LL_OPAMP_POWERMODE_LOWPOWER_NORMALSPEED
740 * @param TransistorsDiffPair This parameter can be one of the following values:
741 * @arg @ref LL_OPAMP_TRIMMING_NMOS
742 * @arg @ref LL_OPAMP_TRIMMING_PMOS
743 * @retval 0x0...0x1F
744 */
LL_OPAMP_GetTrimmingValue(const OPAMP_TypeDef * OPAMPx,uint32_t PowerMode,uint32_t TransistorsDiffPair)745 __STATIC_INLINE uint32_t LL_OPAMP_GetTrimmingValue(const OPAMP_TypeDef *OPAMPx, uint32_t PowerMode,
746 uint32_t TransistorsDiffPair)
747 {
748 const __IO uint32_t *preg = __OPAMP_PTR_REG_OFFSET(OPAMPx->OTR, (PowerMode & OPAMP_POWERMODE_OTR_REGOFFSET_MASK));
749
750 /* Retrieve bits with position in register depending on parameter */
751 /* "TransistorsDiffPair". */
752 /* Parameter used with mask "OPAMP_TRIMMING_VALUE_MASK" because */
753 /* containing other bits reserved for other purpose. */
754 return (uint32_t)(
755 READ_BIT(*preg, (TransistorsDiffPair & OPAMP_TRIMMING_VALUE_MASK)) >>
756 (
757 (TransistorsDiffPair == LL_OPAMP_TRIMMING_NMOS) ? OPAMP_OTR_TRIMOFFSETN_Pos : OPAMP_OTR_TRIMOFFSETP_Pos));
758 }
759
760 /**
761 * @}
762 */
763
764 /** @defgroup OPAMP_LL_EF_OPERATION Operation on OPAMP instance
765 * @{
766 */
767 /**
768 * @brief Enable OPAMP instance.
769 * @note After enable from off state, OPAMP requires a delay
770 * to fulfill wake up time specification.
771 * Refer to device datasheet, parameter "tWAKEUP".
772 * @rmtoll CSR OPAMPXEN LL_OPAMP_Enable
773 * @param OPAMPx OPAMP instance
774 * @retval None
775 */
LL_OPAMP_Enable(OPAMP_TypeDef * OPAMPx)776 __STATIC_INLINE void LL_OPAMP_Enable(OPAMP_TypeDef *OPAMPx)
777 {
778 SET_BIT(OPAMPx->CSR, OPAMP_CSR_OPAEN);
779 }
780
781 /**
782 * @brief Disable OPAMP instance.
783 * @rmtoll CSR OPAMPXEN LL_OPAMP_Disable
784 * @param OPAMPx OPAMP instance
785 * @retval None
786 */
LL_OPAMP_Disable(OPAMP_TypeDef * OPAMPx)787 __STATIC_INLINE void LL_OPAMP_Disable(OPAMP_TypeDef *OPAMPx)
788 {
789 CLEAR_BIT(OPAMPx->CSR, OPAMP_CSR_OPAEN);
790 }
791
792 /**
793 * @brief Get OPAMP instance enable state
794 * (0: OPAMP is disabled, 1: OPAMP is enabled)
795 * @rmtoll CSR OPAMPXEN LL_OPAMP_IsEnabled
796 * @param OPAMPx OPAMP instance
797 * @retval State of bit (1 or 0).
798 */
LL_OPAMP_IsEnabled(const OPAMP_TypeDef * OPAMPx)799 __STATIC_INLINE uint32_t LL_OPAMP_IsEnabled(const OPAMP_TypeDef *OPAMPx)
800 {
801 return ((READ_BIT(OPAMPx->CSR, OPAMP_CSR_OPAEN) == (OPAMP_CSR_OPAEN)) ? 1UL : 0UL);
802 }
803
804 /**
805 * @}
806 */
807
808 #if defined(USE_FULL_LL_DRIVER)
809 /** @defgroup OPAMP_LL_EF_Init Initialization and de-initialization functions
810 * @{
811 */
812
813 ErrorStatus LL_OPAMP_DeInit(OPAMP_TypeDef *OPAMPx);
814 ErrorStatus LL_OPAMP_Init(OPAMP_TypeDef *OPAMPx, const LL_OPAMP_InitTypeDef *OPAMP_InitStruct);
815 void LL_OPAMP_StructInit(LL_OPAMP_InitTypeDef *OPAMP_InitStruct);
816
817 /**
818 * @}
819 */
820 #endif /* USE_FULL_LL_DRIVER */
821
822 /**
823 * @}
824 */
825
826 /**
827 * @}
828 */
829
830 #endif /* OPAMP1 */
831
832 /**
833 * @}
834 */
835
836 /**
837 * @}
838 */
839
840 #ifdef __cplusplus
841 }
842 #endif
843
844 #endif /* STM32U0xx_LL_OPAMP_H */
845
846