1 /**
2 **********************************************************************************************************************
3 * @file stm32h5xx_ll_opamp.h
4 * @author MCD Application Team
5 * @brief Header file of OPAMP LL module.
6 **********************************************************************************************************************
7 * @attention
8 *
9 * Copyright (c) 2023 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 __STM32H5xx_LL_OPAMP_H
21 #define __STM32H5xx_LL_OPAMP_H
22
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26
27 /* Includes ----------------------------------------------------------------------------------------------------------*/
28 #include "stm32h5xx.h"
29
30 /** @addtogroup STM32H5xx_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_HSOTR_REGOFFSET 0x00000001U
56 #define OPAMP_POWERMODE_OTR_REGOFFSET_MASK (OPAMP_POWERMODE_OTR_REGOFFSET | OPAMP_POWERMODE_HSOTR_REGOFFSET)
57
58 /* Mask for OPAMP power mode into control register */
59 #define OPAMP_POWERMODE_CSR_BIT_MASK (OPAMP_CSR_OPAHSM)
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 0x00030000U
67 #define OPAMP_TRIMMING_VALUE_MASK (OPAMP_OTR_TRIMOFFSETP | OPAMP_OTR_TRIMOFFSETN)
68
69 /**
70 * @}
71 */
72
73 /* Private macros ----------------------------------------------------------------------------------------------------*/
74 /** @defgroup OPAMP_LL_Private_Macros OPAMP Private Macros
75 * @{
76 */
77
78 /**
79 * @brief Driver macro reserved for internal use: set a pointer to
80 * a register from a register basis from which an offset
81 * is applied.
82 * @param __REG__ Register basis from which the offset is applied.
83 * @param __REG_OFFSET__ Offset to be applied (unit: number of registers).
84 * @retval Register address
85 */
86 #define __OPAMP_PTR_REG_OFFSET(__REG__, __REG_OFFSET__) \
87 ((__IO uint32_t *)((uint32_t) ((uint32_t)(&(__REG__)) + ((__REG_OFFSET__) << 2U))))
88
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 OPAMP power mode.
105 This parameter can be a value of @ref OPAMP_LL_EC_POWER_MODE
106 This feature can be modified afterwards using unitary
107 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 unitar
120 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 standalone or PGA with
125 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 unitary
129 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_MODE OPAMP mode calibration or functional.
144 * @{
145 */
146 #define LL_OPAMP_MODE_FUNCTIONAL 0x00000000U /*!< OPAMP functional mode */
147 #define LL_OPAMP_MODE_CALIBRATION (OPAMP_CSR_CALON) /*!< OPAMP calibration mode */
148 /**
149 * @}
150 */
151
152 /** @defgroup OPAMP_LL_EC_FUNCTIONAL_MODE OPAMP functional mode
153 * @{
154 */
155 #define LL_OPAMP_MODE_STANDALONE 0x00000000U /*!< OPAMP functional mode, OPAMP operation
156 in standalone */
157 #define LL_OPAMP_MODE_FOLLOWER (OPAMP_CSR_VMSEL_1 |\
158 OPAMP_CSR_VMSEL_0) /*!< OPAMP functional mode, OPAMP operation in follower */
159 #define LL_OPAMP_MODE_PGA (OPAMP_CSR_VMSEL_1) /*!< OPAMP functional mode, OPAMP operation in PGA */
160 #define LL_OPAMP_MODE_PGA_IO0 (OPAMP_CSR_PGGAIN_2|\
161 OPAMP_CSR_VMSEL_1) /*!< In PGA mode, the inverting input is connected
162 to VINM0 for filtering */
163 #define LL_OPAMP_MODE_PGA_IO0_BIAS (OPAMP_CSR_PGGAIN_3|\
164 OPAMP_CSR_VMSEL_1) /*!< In PGA mode, the inverting input is
165 connected to VINM0.
166 - Input signal on VINM0, bias on VINPx: negative gain
167 - Bias on VINM0, input signal on VINPx:
168 positive gain */
169 #define LL_OPAMP_MODE_PGA_IO0_IO1_BIAS (OPAMP_CSR_PGGAIN_3|\
170 OPAMP_CSR_PGGAIN_2|\
171 OPAMP_CSR_VMSEL_1) /*!< In PGA mode, the inverting input is
172 connected to VINM0.
173 - Input signal on VINM0, bias on VINPx: negative gain
174 - Bias on VINM0, input signal on VINPx: positive gain
175 And VINM1 is connected too for filtering */
176 /**
177 * @}
178 */
179
180 /** @defgroup OPAMP_LL_EC_MODE_PGA_GAIN OPAMP PGA gain (relevant when OPAMP is in functional mode PGA)
181 * @note Gain sign:
182 * - is positive if the @ref OPAMP_LL_EC_FUNCTIONAL_MODE configuration is
183 * @ref LL_OPAMP_MODE_PGA or LL_OPAMP_MODE_PGA_IO0
184 * - may be positive or negative if the @ref OPAMP_LL_EC_FUNCTIONAL_MODE configuration is
185 * @ref LL_OPAMP_MODE_PGA_IO0_BIAS or LL_OPAMP_MODE_PGA_IO0_IO1_BIAS
186 * see @ref OPAMP_LL_EC_FUNCTIONAL_MODE for more details
187 * @{
188 */
189 #define LL_OPAMP_PGA_GAIN_2_OR_MINUS_1 0x00000000U /*!< OPAMP PGA gain 2 or -1 */
190 #define LL_OPAMP_PGA_GAIN_4_OR_MINUS_3 (OPAMP_CSR_PGGAIN_0) /*!< OPAMP PGA gain 4 or -3 */
191 #define LL_OPAMP_PGA_GAIN_8_OR_MINUS_7 (OPAMP_CSR_PGGAIN_1) /*!< OPAMP PGA gain 8 or -7 */
192 #define LL_OPAMP_PGA_GAIN_16_OR_MINUS_15 (OPAMP_CSR_PGGAIN_1 | OPAMP_CSR_PGGAIN_0) /*!< OPAMP PGA gain 16 or -15 */
193 /**
194 * @}
195 */
196
197 /** @defgroup OPAMP_LL_EC_INPUT_NONINVERTING OPAMP input non-inverting
198 * @{
199 */
200 #define LL_OPAMP_INPUT_NONINVERT_IO0 0x00000000U /*!< OPAMP non inverting input connected to I/O VINP0
201 (PB0 for OPAMP1)
202 Note: On this STM32 series, all OPAMPx are not available on
203 all devices. Refer to device datasheet for more details */
204 #define LL_OPAMP_INPUT_NONINVERT_IO1 OPAMP_CSR_VPSEL_1 /*!< OPAMP non inverting input connected to I/O VINP2
205 (PA0 for OPAMP1)
206 Note: On this STM32 series, all OPAMPx are not available on
207 all devices. Refer to device datasheet for more details */
208 #define LL_OPAMP_INPUT_NONINVERT_DAC OPAMP_CSR_VPSEL_0 /*!< OPAMP non inverting input connected internally to DAC channel
209 (DAC1_CH1 for OPAMP1)
210 Note: On this STM32 series, all OPAMPx are not available on
211 all devices. Refer to device datasheet for more details */
212
213 /**
214 * @}
215 */
216
217 /** @defgroup OPAMP_LL_EC_INPUT_INVERTING OPAMP input inverting
218 * @note OPAMP inverting input is used with OPAMP in mode standalone or PGA with negative gain or bias.
219 * Otherwise (OPAMP in mode follower), OPAMP inverting input is not used (not connected to GPIO pin).
220 * @{
221 */
222 #define LL_OPAMP_INPUT_INVERT_IO0 0x00000000U /*!< OPAMP inverting input connected to I/O VINM0
223 (PC5 for OPAMP1)
224 Note: On this STM32 series, all OPAMPx are not
225 available on all devices. Refer to device datasheet
226 for more details */
227 #define LL_OPAMP_INPUT_INVERT_IO1 OPAMP_CSR_VMSEL_0 /*!< OPAMP inverting input connected to I/0 VINM1
228 (PB1 for OPAMP1)
229 Note: On this STM32 series, all OPAMPx are not
230 available on all devices. Refer to device datasheet
231 for more details */
232 #define LL_OPAMP_INPUT_INVERT_CONNECT_NO OPAMP_CSR_VMSEL_1 /*!< OPAMP inverting input not externally connected
233 (intended for OPAMP in mode follower or PGA with
234 positive gain without bias).
235 Note: On this STM32 series, this literal include cases
236 of value 0x11 for mode follower and value 0x10
237 for mode PGA. */
238 /**
239 * @}
240 */
241
242 /** @defgroup OPAMP_LL_EC_POWER_MODE OPAMP PowerMode
243 * @{
244 */
245 #define LL_OPAMP_POWERMODE_NORMAL (OPAMP_POWERMODE_OTR_REGOFFSET) /*!< OPAMP output in
246 normal mode */
247 #define LL_OPAMP_POWERMODE_HIGHSPEED (OPAMP_POWERMODE_HSOTR_REGOFFSET | OPAMP_CSR_OPAHSM) /*!< OPAMP output in
248 highspeed mode */
249 /**
250 * @}
251 */
252
253 /** @defgroup OPAMP_LL_EC_TRIMMING_MODE OPAMP trimming mode
254 * @{
255 */
256 #define LL_OPAMP_TRIMMING_FACTORY 0x00000000U /*!< OPAMP trimming factors set to factory values */
257 #define LL_OPAMP_TRIMMING_USER OPAMP_CSR_USERTRIM /*!< OPAMP trimming factors set to user values */
258 /**
259 * @}
260 */
261
262 /** @defgroup OPAMP_LL_EC_TRIMMING_TRANSISTORS_DIFF_PAIR OPAMP trimming of transistors differential pair NMOS or PMOS
263 * @{
264 */
265 #define LL_OPAMP_TRIMMING_NMOS_VREF_90PC_VDDA (OPAMP_OTR_TRIMOFFSETN |\
266 ((OPAMP_CSR_CALSEL_1 |\
267 OPAMP_CSR_CALSEL_0) << 4)) /*!< OPAMP trimming of transistors
268 differential pair NMOS (internal
269 reference voltage set to 0.9*Vdda).
270 Default parameters to be used for
271 calibration using two trimming steps
272 (one with each transistors
273 differential pair NMOS and PMOS). */
274 #define LL_OPAMP_TRIMMING_NMOS_VREF_50PC_VDDA (OPAMP_OTR_TRIMOFFSETN |\
275 (OPAMP_CSR_CALSEL_1 << 4)) /*!< OPAMP trimming of transistors
276 differential pair NMOS (internal
277 reference voltage set to 0.5*Vdda). */
278 #define LL_OPAMP_TRIMMING_PMOS_VREF_10PC_VDDA (OPAMP_OTR_TRIMOFFSETP |\
279 (OPAMP_CSR_CALSEL_0 << 4)) /*!< OPAMP trimming of transistors
280 differential pair PMOS (internal
281 reference voltage set to 0.1*Vdda).
282 Default parameters to be used
283 for calibration using two trimming
284 steps (one with each transistors
285 differential pair NMOS and PMOS). */
286 #define LL_OPAMP_TRIMMING_PMOS_VREF_3_3PC_VDDA (OPAMP_OTR_TRIMOFFSETP) /*!< OPAMP trimming of transistors
287 differential pair PMOS (internal
288 reference voltage set to 0.33*Vdda).*/
289 #define LL_OPAMP_TRIMMING_NMOS (LL_OPAMP_TRIMMING_NMOS_VREF_90PC_VDDA) /*!< OPAMP trimming of transistors
290 differential pair NMOS (internal
291 reference voltage setto 0.9*Vdda).
292 Default parameters to be used
293 for calibration using two trimming
294 steps (one with each transistors
295 differential pair NMOS and PMOS). */
296 #define LL_OPAMP_TRIMMING_PMOS (LL_OPAMP_TRIMMING_PMOS_VREF_10PC_VDDA) /*!< OPAMP trimming of transistors
297 differential pair PMOS (internal
298 reference voltage setto 0.1*Vdda).
299 Default parameters to be used for
300 calibration using two trimming
301 steps one with each transistors
302 differential pair NMOS and PMOS). */
303 /**
304 * @}
305 */
306
307 /** @defgroup OPAMP_LL_EC_HW_DELAYS Definitions of OPAMP hardware constraints delays
308 * @note Only OPAMP Peripheral HW delays are defined in OPAMP LL driver driver,
309 * not timeout values.
310 * For details on delays values, refer to descriptions in source code
311 * above each literal definition.
312 * @{
313 */
314
315 /* Delay for OPAMP startup time (transition from state disable to enable). */
316 /* Note: OPAMP startup time depends on board application environment: */
317 /* impedance connected to OPAMP output. */
318 /* The delay below is specified under conditions: */
319 /* - OPAMP in functional mode follower */
320 /* - load impedance of 4kOhm (min), 50pF (max) */
321 /* Literal set to maximum value (refer to device datasheet, */
322 /* parameter "tWAKEUP"). */
323 /* Unit: us */
324 #define LL_OPAMP_DELAY_STARTUP_US (3U) /*!< Delay for OPAMP startup time */
325 /**
326 * @}
327 */
328
329 /**
330 * @}
331 */
332
333 /* Exported macro ----------------------------------------------------------------------------------------------------*/
334 /** @defgroup OPAMP_LL_Exported_Macros OPAMP Exported Macros
335 * @{
336 */
337 /** @defgroup OPAMP_LL_EM_WRITE_READ Common write and read registers macro
338 * @{
339 */
340 /**
341 * @brief Write a value in OPAMP LL_OPAMP_GetPowerModeregister
342 * @param __INSTANCE__ OPAMP Instance
343 * @param __REG__ Register to be written
344 * @param __VALUE__ Value to be written in the register
345 * @retval None
346 */
347 #define LL_OPAMP_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG((__INSTANCE__)->__REG__, (__VALUE__))
348
349 /**
350 * @brief Read a value in OPAMP register
351 * @param __INSTANCE__ OPAMP Instance
352 * @param __REG__ Register to be read
353 * @retval Register value
354 */
355 #define LL_OPAMP_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
356 /**
357 * @}
358 */
359
360 /**
361 * @}
362 */
363
364 /* Exported functions ------------------------------------------------------------------------------------------------*/
365 /** @defgroup OPAMP_LL_Exported_Functions OPAMP Exported Functions
366 * @{
367 */
368
369 /** @defgroup OPAMP_LL_EF_CONFIGURATION_OPAMP_INSTANCE Configuration of OPAMP hierarchical scope: OPAMP instance
370 * @{
371 */
372
373 /**
374 * @brief Set OPAMP mode calibration or functional.
375 * @note OPAMP mode corresponds to functional or calibration mode:
376 * - functional mode: OPAMP operation in standalone, follower, ...
377 * Set functional mode using function
378 * @ref LL_OPAMP_SetFunctionalMode().
379 * - calibration mode: offset calibration of the selected
380 * transistors differential pair NMOS or PMOS.
381 * @rmtoll CSR CALON LL_OPAMP_SetMode
382 * @param OPAMPx OPAMP instance
383 * @param Mode This parameter can be one of the following values:
384 * @arg @ref LL_OPAMP_MODE_FUNCTIONAL
385 * @arg @ref LL_OPAMP_MODE_CALIBRATION
386 * @retval None
387 */
LL_OPAMP_SetMode(OPAMP_TypeDef * OPAMPx,uint32_t Mode)388 __STATIC_INLINE void LL_OPAMP_SetMode(OPAMP_TypeDef *OPAMPx, uint32_t Mode)
389 {
390 MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_CALON, Mode);
391 }
392
393 /**
394 * @brief Get OPAMP mode calibration or functional.
395 * @note OPAMP mode corresponds to functional or calibration mode:
396 * - functional mode: OPAMP operation in standalone, follower, ...
397 * Set functional mode using function
398 * @ref LL_OPAMP_SetFunctionalMode().
399 * - calibration mode: offset calibration of the selected
400 * transistors differential pair NMOS or PMOS.
401 * @rmtoll CSR CALON LL_OPAMP_GetMode
402 * @param OPAMPx OPAMP instance
403 * @retval Returned value can be one of the following values:
404 * @arg @ref LL_OPAMP_MODE_FUNCTIONAL
405 * @arg @ref LL_OPAMP_MODE_CALIBRATION
406 */
LL_OPAMP_GetMode(const OPAMP_TypeDef * OPAMPx)407 __STATIC_INLINE uint32_t LL_OPAMP_GetMode(const OPAMP_TypeDef *OPAMPx)
408 {
409 return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_CALON));
410 }
411
412 /**
413 * @brief Set OPAMP functional mode by setting internal connections.
414 * OPAMP operation in standalone, follower, ...
415 * @note This function reset bit of calibration mode to ensure
416 * to be in functional mode, in order to have OPAMP parameters
417 * (inputs selection, ...) set with the corresponding OPAMP mode
418 * to be effective.
419 * @rmtoll CSR VMSEL LL_OPAMP_SetFunctionalMode
420 * @param OPAMPx OPAMP instance
421 * @param FunctionalMode This parameter can be one of the following values:
422 * @arg @ref LL_OPAMP_MODE_STANDALONE
423 * @arg @ref LL_OPAMP_MODE_FOLLOWER
424 * @arg @ref LL_OPAMP_MODE_PGA
425 * @arg @ref LL_OPAMP_MODE_PGA_IO0
426 * @arg @ref LL_OPAMP_MODE_PGA_IO0_BIAS
427 * @arg @ref LL_OPAMP_MODE_PGA_IO0_IO1_BIAS
428 * @retval None
429 */
LL_OPAMP_SetFunctionalMode(OPAMP_TypeDef * OPAMPx,uint32_t FunctionalMode)430 __STATIC_INLINE void LL_OPAMP_SetFunctionalMode(OPAMP_TypeDef *OPAMPx, uint32_t FunctionalMode)
431 {
432 /* Note: Bit OPAMP_CSR_CALON reset to ensure to be in functional mode */
433 MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_PGGAIN_3 | OPAMP_CSR_PGGAIN_2 | OPAMP_CSR_VMSEL | OPAMP_CSR_CALON, FunctionalMode);
434 }
435
436 /**
437 * @brief Get OPAMP functional mode from setting of internal connections.
438 * OPAMP operation in standalone, follower, ...
439 * @rmtoll CSR VMSEL LL_OPAMP_GetFunctionalMode
440 * @param OPAMPx OPAMP instance
441 * @retval Returned value can be one of the following values:
442 * @arg @ref LL_OPAMP_MODE_STANDALONE
443 * @arg @ref LL_OPAMP_MODE_FOLLOWER
444 * @arg @ref LL_OPAMP_MODE_PGA
445 * @arg @ref LL_OPAMP_MODE_PGA_IO0
446 * @arg @ref LL_OPAMP_MODE_PGA_IO0_BIAS
447 * @arg @ref LL_OPAMP_MODE_PGA_IO0_IO1_BIAS
448 */
LL_OPAMP_GetFunctionalMode(const OPAMP_TypeDef * OPAMPx)449 __STATIC_INLINE uint32_t LL_OPAMP_GetFunctionalMode(const OPAMP_TypeDef *OPAMPx)
450 {
451 return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_PGGAIN_3 | OPAMP_CSR_PGGAIN_2 | OPAMP_CSR_VMSEL));
452 }
453
454 /**
455 * @brief Set OPAMP PGA gain.
456 * @note Preliminarily, OPAMP must be set in mode PGA
457 * using function @ref LL_OPAMP_SetFunctionalMode().
458 * @rmtoll CSR PGGAIN LL_OPAMP_SetPGAGain
459 * @param OPAMPx OPAMP instance
460 * @param PGAGain This parameter can be one of the following values:
461 * @arg @ref LL_OPAMP_PGA_GAIN_2_OR_MINUS_1
462 * @arg @ref LL_OPAMP_PGA_GAIN_4_OR_MINUS_3
463 * @arg @ref LL_OPAMP_PGA_GAIN_8_OR_MINUS_7
464 * @arg @ref LL_OPAMP_PGA_GAIN_16_OR_MINUS_15
465 * @retval None
466 */
LL_OPAMP_SetPGAGain(OPAMP_TypeDef * OPAMPx,uint32_t PGAGain)467 __STATIC_INLINE void LL_OPAMP_SetPGAGain(OPAMP_TypeDef *OPAMPx, uint32_t PGAGain)
468 {
469 MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_PGGAIN_1 | OPAMP_CSR_PGGAIN_0, PGAGain);
470 }
471
472 /**
473 * @brief Get OPAMP PGA gain.
474 * @note Preliminarily, OPAMP must be set in mode PGA
475 * using function @ref LL_OPAMP_SetFunctionalMode().
476 * @rmtoll CSR PGGAIN LL_OPAMP_GetPGAGain
477 * @param OPAMPx OPAMP instance
478 * @retval Returned value can be one of the following values:
479 * @arg @ref LL_OPAMP_PGA_GAIN_2_OR_MINUS_1
480 * @arg @ref LL_OPAMP_PGA_GAIN_4_OR_MINUS_3
481 * @arg @ref LL_OPAMP_PGA_GAIN_8_OR_MINUS_7
482 * @arg @ref LL_OPAMP_PGA_GAIN_16_OR_MINUS_15
483 */
LL_OPAMP_GetPGAGain(const OPAMP_TypeDef * OPAMPx)484 __STATIC_INLINE uint32_t LL_OPAMP_GetPGAGain(const OPAMP_TypeDef *OPAMPx)
485 {
486 return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_PGGAIN_1 | OPAMP_CSR_PGGAIN_0));
487 }
488
489 /**
490 * @brief Set OPAMP power mode normal or highspeed.
491 * @note OPAMP highspeed mode allows output stage to have a better slew rate.
492 * @rmtoll CSR OPAHSM LL_OPAMP_SetPowerMode
493 * @param OPAMPx OPAMP instance
494 * @param PowerMode This parameter can be one of the following values:
495 * @arg @ref LL_OPAMP_POWERMODE_NORMAL
496 * @arg @ref LL_OPAMP_POWERMODE_HIGHSPEED
497 * @retval None
498 */
LL_OPAMP_SetPowerMode(OPAMP_TypeDef * OPAMPx,uint32_t PowerMode)499 __STATIC_INLINE void LL_OPAMP_SetPowerMode(OPAMP_TypeDef *OPAMPx, uint32_t PowerMode)
500 {
501 MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_OPAHSM, (PowerMode & OPAMP_POWERMODE_CSR_BIT_MASK));
502 }
503
504 /**
505 * @brief Get OPAMP power mode normal or highspeed.
506 * @note OPAMP highspeed mode allows output stage to have a better slew rate.
507 * @rmtoll CSR OPAHSM LL_OPAMP_GetPowerMode
508 * @param OPAMPx OPAMP instance
509 * @retval Returned value can be one of the following values:
510 * @arg @ref LL_OPAMP_POWERMODE_NORMAL
511 * @arg @ref LL_OPAMP_POWERMODE_HIGHSPEED
512 */
LL_OPAMP_GetPowerMode(const OPAMP_TypeDef * OPAMPx)513 __STATIC_INLINE uint32_t LL_OPAMP_GetPowerMode(const OPAMP_TypeDef *OPAMPx)
514 {
515 uint32_t power_mode = (READ_BIT(OPAMPx->CSR, OPAMP_CSR_OPAHSM));
516
517 return (uint32_t)(power_mode | (power_mode >> (OPAMP_CSR_OPAHSM_Pos)));
518 }
519 /**
520 * @}
521 */
522
523 /** @defgroup OPAMP_LL_EF_CONFIGURATION_INPUTS Configuration of OPAMP inputs
524 * @{
525 */
526
527 /**
528 * @brief Set OPAMP non-inverting input connection.
529 * @rmtoll CSR VPSEL LL_OPAMP_SetInputNonInverting
530 * @param OPAMPx OPAMP instance
531 * @param InputNonInverting This parameter can be one of the following values:
532 * @arg @ref LL_OPAMP_INPUT_NONINVERT_IO0
533 * @arg @ref LL_OPAMP_INPUT_NONINVERT_IO1
534 * @arg @ref LL_OPAMP_INPUT_NONINVERT_DAC
535 * @retval None
536 */
LL_OPAMP_SetInputNonInverting(OPAMP_TypeDef * OPAMPx,uint32_t InputNonInverting)537 __STATIC_INLINE void LL_OPAMP_SetInputNonInverting(OPAMP_TypeDef *OPAMPx, uint32_t InputNonInverting)
538 {
539 MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_VPSEL, InputNonInverting);
540 }
541
542 /**
543 * @brief Get OPAMP non-inverting input connection.
544 * @rmtoll CSR VPSEL LL_OPAMP_GetInputNonInverting
545 * @param OPAMPx OPAMP instance
546 * @retval Returned value can be one of the following values:
547 * @arg @ref LL_OPAMP_INPUT_NONINVERT_IO0
548 * @arg @ref LL_OPAMP_INPUT_NONINVERT_IO1
549 * @arg @ref LL_OPAMP_INPUT_NONINVERT_DAC
550 */
LL_OPAMP_GetInputNonInverting(const OPAMP_TypeDef * OPAMPx)551 __STATIC_INLINE uint32_t LL_OPAMP_GetInputNonInverting(const OPAMP_TypeDef *OPAMPx)
552 {
553 return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_VPSEL));
554 }
555
556 /**
557 * @brief Set OPAMP inverting input connection.
558 * @note OPAMP inverting input is used with OPAMP in mode standalone
559 * or PGA with external capacitors for filtering circuit.
560 * Otherwise (OPAMP in mode follower), OPAMP inverting input
561 * is not used (not connected to GPIO pin).
562 * @rmtoll CSR VMSEL LL_OPAMP_SetInputInverting
563 * @param OPAMPx OPAMP instance
564 * @param InputInverting This parameter can be one of the following values:
565 * @arg @ref LL_OPAMP_INPUT_INVERT_IO0
566 * @arg @ref LL_OPAMP_INPUT_INVERT_IO1
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 /* Manage cases of OPAMP inverting input not connected (0x10 and 0x11) */
573 /* to not modify OPAMP mode follower or PGA. */
574 /* Bit OPAMP_CSR_VMSEL_1 is set by OPAMP mode (follower, PGA). */
575 MODIFY_REG(OPAMPx->CSR, (~(InputInverting >> 1)) & OPAMP_CSR_VMSEL_0, InputInverting);
576 }
577
578 /**
579 * @brief Get OPAMP inverting input connection.
580 * @rmtoll CSR VMSEL LL_OPAMP_GetInputInverting
581 * @param OPAMPx OPAMP instance
582 * @retval Returned value can be one of the following values:
583 * @arg @ref LL_OPAMP_INPUT_INVERT_IO0
584 * @arg @ref LL_OPAMP_INPUT_INVERT_IO1
585 * @arg @ref LL_OPAMP_INPUT_INVERT_CONNECT_NO
586 */
LL_OPAMP_GetInputInverting(const OPAMP_TypeDef * OPAMPx)587 __STATIC_INLINE uint32_t LL_OPAMP_GetInputInverting(const OPAMP_TypeDef *OPAMPx)
588 {
589 uint32_t input_inverting = READ_BIT(OPAMPx->CSR, OPAMP_CSR_VMSEL);
590
591 /* Manage cases 0x10 and 0x11 to return the same value: OPAMP inverting */
592 /* input not connected. */
593 return (input_inverting & ~((input_inverting >> 1) & OPAMP_CSR_VMSEL_0));
594 }
595
596 /**
597 * @}
598 */
599
600 /** @defgroup OPAMP_LL_EF_OPAMP_TRIMMING Configuration and operation of OPAMP trimming
601 * @{
602 */
603
604 /**
605 * @brief Set OPAMP trimming mode.
606 * @rmtoll CSR USERTRIM LL_OPAMP_SetTrimmingMode
607 * @param OPAMPx OPAMP instance
608 * @param TrimmingMode This parameter can be one of the following values:
609 * @arg @ref LL_OPAMP_TRIMMING_FACTORY
610 * @arg @ref LL_OPAMP_TRIMMING_USER
611 * @retval None
612 */
LL_OPAMP_SetTrimmingMode(OPAMP_TypeDef * OPAMPx,uint32_t TrimmingMode)613 __STATIC_INLINE void LL_OPAMP_SetTrimmingMode(OPAMP_TypeDef *OPAMPx, uint32_t TrimmingMode)
614 {
615 MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_USERTRIM, TrimmingMode);
616 }
617
618 /**
619 * @brief Get OPAMP trimming mode.
620 * @rmtoll CSR USERTRIM LL_OPAMP_GetTrimmingMode
621 * @param OPAMPx OPAMP instance
622 * @retval Returned value can be one of the following values:
623 * @arg @ref LL_OPAMP_TRIMMING_FACTORY
624 * @arg @ref LL_OPAMP_TRIMMING_USER
625 */
LL_OPAMP_GetTrimmingMode(const OPAMP_TypeDef * OPAMPx)626 __STATIC_INLINE uint32_t LL_OPAMP_GetTrimmingMode(const OPAMP_TypeDef *OPAMPx)
627 {
628 return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_USERTRIM));
629 }
630
631 /**
632 * @brief Set OPAMP offset to calibrate the selected transistors
633 * differential pair NMOS or PMOS.
634 * @note Preliminarily, OPAMP must be set in mode calibration
635 * using function @ref LL_OPAMP_SetMode().
636 * @rmtoll CSR CALSEL LL_OPAMP_SetCalibrationSelection
637 * @param OPAMPx OPAMP instance
638 * @param TransistorsDiffPair This parameter can be one of the following values:
639 * @arg @ref LL_OPAMP_TRIMMING_NMOS (1)
640 * @arg @ref LL_OPAMP_TRIMMING_PMOS (1)
641 * @arg @ref LL_OPAMP_TRIMMING_NMOS_VREF_50PC_VDDA
642 * @arg @ref LL_OPAMP_TRIMMING_PMOS_VREF_3_3PC_VDDA
643 *
644 * (1) Default parameters to be used for calibration
645 * using two trimming steps (one with each transistors differential
646 * pair NMOS and PMOS)
647 * @retval None
648 */
LL_OPAMP_SetCalibrationSelection(OPAMP_TypeDef * OPAMPx,uint32_t TransistorsDiffPair)649 __STATIC_INLINE void LL_OPAMP_SetCalibrationSelection(OPAMP_TypeDef *OPAMPx, uint32_t TransistorsDiffPair)
650 {
651 /* Parameter used with mask "OPAMP_TRIMMING_SELECT_MASK" because */
652 /* containing other bits reserved for other purpose. */
653 MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_CALSEL, ((TransistorsDiffPair & OPAMP_TRIMMING_SELECT_MASK) >> 4));
654 }
655
656 /**
657 * @brief Get OPAMP offset to calibrate the selected transistors
658 * differential pair NMOS or PMOS.
659 * @note Preliminarily, OPAMP must be set in mode calibration
660 * using function @ref LL_OPAMP_SetMode().
661 * @rmtoll CSR CALSEL LL_OPAMP_GetCalibrationSelection
662 * @param OPAMPx OPAMP instance
663 * @retval Returned value can be one of the following values:
664 * @arg @ref LL_OPAMP_TRIMMING_NMOS (1)
665 * @arg @ref LL_OPAMP_TRIMMING_PMOS (1)
666 * @arg @ref LL_OPAMP_TRIMMING_NMOS_VREF_50PC_VDDA
667 * @arg @ref LL_OPAMP_TRIMMING_PMOS_VREF_3_3PC_VDDA
668 *
669 * (1) Default parameters to be used for calibration
670 * using two trimming steps (one with each transistors differential
671 * pair NMOS and PMOS)
672 */
LL_OPAMP_GetCalibrationSelection(const OPAMP_TypeDef * OPAMPx)673 __STATIC_INLINE uint32_t LL_OPAMP_GetCalibrationSelection(const OPAMP_TypeDef *OPAMPx)
674 {
675 uint32_t CalibrationSelection = (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_CALSEL));
676
677 return (uint32_t)((CalibrationSelection << 4) |
678 (((CalibrationSelection & OPAMP_CSR_CALSEL_1) == 0UL) ? OPAMP_OTR_TRIMOFFSETP :
679 OPAMP_OTR_TRIMOFFSETN));
680 }
681
682 /**
683 * @brief Get OPAMP calibration result of toggling output.
684 * @note This functions returns:
685 * 0 if OPAMP calibration output is reset
686 * 1 if OPAMP calibration output is set
687 * @rmtoll CSR OUTCAL LL_OPAMP_IsCalibrationOutputSet
688 * @param OPAMPx OPAMP instance
689 * @retval State of bit (1 or 0).
690 */
LL_OPAMP_IsCalibrationOutputSet(const OPAMP_TypeDef * OPAMPx)691 __STATIC_INLINE uint32_t LL_OPAMP_IsCalibrationOutputSet(const OPAMP_TypeDef *OPAMPx)
692 {
693 return ((READ_BIT(OPAMPx->CSR, OPAMP_CSR_CALOUT) == OPAMP_CSR_CALOUT) ? 1UL : 0UL);
694 }
695
696 /**
697 * @brief Set OPAMP trimming factor for the selected transistors
698 * differential pair NMOS or PMOS, corresponding to the selected
699 * power mode.
700 * @rmtoll OTR TRIMOFFSETN LL_OPAMP_SetTrimmingValue\n
701 * OTR TRIMOFFSETP LL_OPAMP_SetTrimmingValue\n
702 * HSOTR TRIMHSOFFSETN LL_OPAMP_SetTrimmingValue\n
703 * HSOTR TRIMHSOFFSETP LL_OPAMP_SetTrimmingValue
704 * @param OPAMPx OPAMP instance
705 * @param PowerMode This parameter can be one of the following values:
706 * @arg @ref LL_OPAMP_POWERMODE_NORMAL
707 * @arg @ref LL_OPAMP_POWERMODE_HIGHSPEED
708 * @param TransistorsDiffPair This parameter can be one of the following values:
709 * @arg @ref LL_OPAMP_TRIMMING_NMOS
710 * @arg @ref LL_OPAMP_TRIMMING_PMOS
711 * @param TrimmingValue 0x00...0x1F
712 * @retval None
713 */
LL_OPAMP_SetTrimmingValue(OPAMP_TypeDef * OPAMPx,uint32_t PowerMode,uint32_t TransistorsDiffPair,uint32_t TrimmingValue)714 __STATIC_INLINE void LL_OPAMP_SetTrimmingValue(OPAMP_TypeDef *OPAMPx, uint32_t PowerMode, uint32_t TransistorsDiffPair,
715 uint32_t TrimmingValue)
716 {
717 __IO uint32_t *preg = __OPAMP_PTR_REG_OFFSET(OPAMPx->OTR, (PowerMode & OPAMP_POWERMODE_OTR_REGOFFSET_MASK));
718
719 /* Set bits with position in register depending on parameter */
720 /* "TransistorsDiffPair". */
721 /* Parameter used with mask "OPAMP_TRIMMING_VALUE_MASK" because */
722 /* containing other bits reserved for other purpose. */
723 MODIFY_REG(*preg,
724 (TransistorsDiffPair & OPAMP_TRIMMING_VALUE_MASK) << 1U,
725 TrimmingValue <<
726 ((TransistorsDiffPair == LL_OPAMP_TRIMMING_NMOS) ? OPAMP_OTR_TRIMOFFSETN_Pos : OPAMP_OTR_TRIMOFFSETP_Pos));
727 }
728
729 /**
730 * @brief Get OPAMP trimming factor for the selected transistors
731 * differential pair NMOS or PMOS, corresponding to the selected
732 * power mode.
733 * @rmtoll OTR TRIMOFFSETN LL_OPAMP_GetTrimmingValue\n
734 * OTR TRIMOFFSETP LL_OPAMP_GetTrimmingValue\n
735 * HSOTR TRIMHSOFFSETN LL_OPAMP_GetTrimmingValue\n
736 * HSOTR TRIMHSOFFSETP LL_OPAMP_GetTrimmingValue
737 * @param OPAMPx OPAMP instance
738 * @param PowerMode This parameter can be one of the following values:
739 * @arg @ref LL_OPAMP_POWERMODE_NORMAL
740 * @arg @ref LL_OPAMP_POWERMODE_HIGHSPEED
741 * @param TransistorsDiffPair This parameter can be one of the following values:
742 * @arg @ref LL_OPAMP_TRIMMING_NMOS
743 * @arg @ref LL_OPAMP_TRIMMING_PMOS
744 * @retval 0x0...0x1F
745 */
LL_OPAMP_GetTrimmingValue(const OPAMP_TypeDef * OPAMPx,uint32_t PowerMode,uint32_t TransistorsDiffPair)746 __STATIC_INLINE uint32_t LL_OPAMP_GetTrimmingValue(const OPAMP_TypeDef *OPAMPx, uint32_t PowerMode,
747 uint32_t TransistorsDiffPair)
748 {
749 const __IO uint32_t *preg = __OPAMP_PTR_REG_OFFSET(OPAMPx->OTR, (PowerMode & OPAMP_POWERMODE_OTR_REGOFFSET_MASK));
750
751 /* Retrieve bits with position in register depending on parameter */
752 /* "TransistorsDiffPair". */
753 /* Parameter used with mask "OPAMP_TRIMMING_VALUE_MASK" because */
754 /* containing other bits reserved for other purpose. */
755 return (uint32_t)(READ_BIT(*preg, (TransistorsDiffPair & OPAMP_TRIMMING_VALUE_MASK))
756 >> ((TransistorsDiffPair == LL_OPAMP_TRIMMING_NMOS) ?
757 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_OPAMPxEN);
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_OPAMPxEN);
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_OPAMPxEN) == (OPAMP_CSR_OPAMPxEN)) ? 1UL : 0UL);
802 }
803 /**
804 * @}
805 */
806
807 #if defined(USE_FULL_LL_DRIVER)
808 /** @defgroup OPAMP_LL_EF_Init Initialization and de-initialization functions
809 * @{
810 */
811
812 ErrorStatus LL_OPAMP_DeInit(OPAMP_TypeDef *OPAMPx);
813 ErrorStatus LL_OPAMP_Init(OPAMP_TypeDef *OPAMPx, const LL_OPAMP_InitTypeDef *OPAMP_InitStruct);
814 void LL_OPAMP_StructInit(LL_OPAMP_InitTypeDef *OPAMP_InitStruct);
815
816 /**
817 * @}
818 */
819 #endif /* USE_FULL_LL_DRIVER */
820
821 /**
822 * @}
823 */
824
825 /**
826 * @}
827 */
828
829 #endif /* OPAMP1 */
830
831 /**
832 * @}
833 */
834
835 #ifdef __cplusplus
836 }
837 #endif
838
839 #endif /* __STM32H5xx_LL_OPAMP_H */
840