![]() |
|
|||
File indexing completed on 2025-05-11 08:23:37
0001 /** 0002 ****************************************************************************** 0003 * @file stm32h7xx_ll_opamp.h 0004 * @author MCD Application Team 0005 * @brief Header file of OPAMP LL module. 0006 ****************************************************************************** 0007 * @attention 0008 * 0009 * Copyright (c) 2017 STMicroelectronics. 0010 * All rights reserved. 0011 * 0012 * This software is licensed under terms that can be found in the LICENSE file 0013 * in the root directory of this software component. 0014 * If no LICENSE file comes with this software, it is provided AS-IS. 0015 * 0016 ****************************************************************************** 0017 */ 0018 0019 /* Define to prevent recursive inclusion -------------------------------------*/ 0020 #ifndef __STM32H7xx_LL_OPAMP_H 0021 #define __STM32H7xx_LL_OPAMP_H 0022 0023 #ifdef __cplusplus 0024 extern "C" { 0025 #endif 0026 0027 /* Includes ------------------------------------------------------------------*/ 0028 #include "stm32h7xx.h" 0029 0030 /** @addtogroup STM32H7xx_LL_Driver 0031 * @{ 0032 */ 0033 0034 #if defined (OPAMP1) || defined (OPAMP2) 0035 0036 /** @defgroup OPAMP_LL OPAMP 0037 * @ingroup RTEMSBSPsARMSTM32H7 0038 * @{ 0039 */ 0040 0041 /* Private types -------------------------------------------------------------*/ 0042 /* Private variables ---------------------------------------------------------*/ 0043 0044 /* Private constants ---------------------------------------------------------*/ 0045 /** @defgroup OPAMP_LL_Private_Constants OPAMP Private Constants 0046 * @ingroup RTEMSBSPsARMSTM32H7 0047 * @{ 0048 */ 0049 0050 /* Internal mask for OPAMP power mode: */ 0051 /* To select into literal LL_OPAMP_POWERMODE_x the relevant bits for: */ 0052 /* - OPAMP power mode into control register */ 0053 /* - OPAMP trimming register offset */ 0054 0055 /* Internal register offset for OPAMP trimming configuration */ 0056 #define OPAMP_POWERMODE_OTR_REGOFFSET 0x00000000U 0057 #define OPAMP_POWERMODE_HSOTR_REGOFFSET 0x00000001U 0058 #define OPAMP_POWERMODE_OTR_REGOFFSET_MASK (OPAMP_POWERMODE_OTR_REGOFFSET | OPAMP_POWERMODE_HSOTR_REGOFFSET) 0059 0060 /* Mask for OPAMP power mode into control register */ 0061 #define OPAMP_POWERMODE_CSR_BIT_MASK (OPAMP_CSR_OPAHSM) 0062 0063 /* Internal mask for OPAMP trimming of transistors differential pair NMOS */ 0064 /* or PMOS. */ 0065 /* To select into literal LL_OPAMP_TRIMMING_x the relevant bits for: */ 0066 /* - OPAMP trimming selection of transistors differential pair */ 0067 /* - OPAMP trimming values of transistors differential pair */ 0068 #define OPAMP_TRIMMING_SELECT_MASK 0x00030000U 0069 #define OPAMP_TRIMMING_VALUE_MASK (OPAMP_OTR_TRIMOFFSETP | OPAMP_OTR_TRIMOFFSETN) 0070 0071 /** 0072 * @} 0073 */ 0074 0075 0076 /* Private macros ------------------------------------------------------------*/ 0077 /** @defgroup OPAMP_LL_Private_Macros OPAMP Private Macros 0078 * @ingroup RTEMSBSPsARMSTM32H7 0079 * @{ 0080 */ 0081 0082 /** 0083 * @brief Driver macro reserved for internal use: set a pointer to 0084 * a register from a register basis from which an offset 0085 * is applied. 0086 * @param __REG__ Register basis from which the offset is applied. 0087 * @param __REG_OFFSET__ Offset to be applied (unit: number of registers). 0088 * @retval Register address 0089 */ 0090 #define __OPAMP_PTR_REG_OFFSET(__REG__, __REG_OFFSET__) \ 0091 ((__IO uint32_t *)((uint32_t) ((uint32_t)(&(__REG__)) + ((__REG_OFFSET__) << 2U)))) 0092 0093 0094 0095 /** 0096 * @} 0097 */ 0098 0099 0100 /* Exported types ------------------------------------------------------------*/ 0101 #if defined(USE_FULL_LL_DRIVER) || defined(__rtems__) 0102 /** @defgroup OPAMP_LL_ES_INIT OPAMP Exported Init structure 0103 * @ingroup RTEMSBSPsARMSTM32H7 0104 * @{ 0105 */ 0106 0107 /** 0108 * @brief Structure definition of some features of OPAMP instance. 0109 */ 0110 typedef struct 0111 { 0112 uint32_t PowerMode; /*!< Set OPAMP power mode. 0113 This parameter can be a value of @ref OPAMP_LL_EC_POWER_MODE 0114 0115 This feature can be modified afterwards using unitary function @ref LL_OPAMP_SetPowerMode(). */ 0116 0117 0118 uint32_t FunctionalMode; /*!< Set OPAMP functional mode by setting internal connections: OPAMP operation in standalone, follower, ... 0119 This parameter can be a value of @ref OPAMP_LL_EC_FUNCTIONAL_MODE 0120 @note If OPAMP is configured in mode PGA, the gain can be configured using function @ref LL_OPAMP_SetPGAGain(). 0121 0122 This feature can be modified afterwards using unitary function @ref LL_OPAMP_SetFunctionalMode(). */ 0123 0124 uint32_t InputNonInverting; /*!< Set OPAMP input non-inverting connection. 0125 This parameter can be a value of @ref OPAMP_LL_EC_INPUT_NONINVERTING 0126 0127 This feature can be modified afterwards using unitary function @ref LL_OPAMP_SetInputNonInverting(). */ 0128 0129 uint32_t InputInverting; /*!< Set OPAMP inverting input connection. 0130 This parameter can be a value of @ref OPAMP_LL_EC_INPUT_INVERTING 0131 @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. 0132 0133 This feature can be modified afterwards using unitary function @ref LL_OPAMP_SetInputInverting(). */ 0134 0135 } LL_OPAMP_InitTypeDef; 0136 0137 /** 0138 * @} 0139 */ 0140 #endif /* USE_FULL_LL_DRIVER */ 0141 0142 /* Exported constants --------------------------------------------------------*/ 0143 /** @defgroup OPAMP_LL_Exported_Constants OPAMP Exported Constants 0144 * @ingroup RTEMSBSPsARMSTM32H7 0145 * @{ 0146 */ 0147 0148 /** @defgroup OPAMP_LL_EC_MODE OPAMP mode calibration or functional. 0149 * @ingroup RTEMSBSPsARMSTM32H7 0150 * @{ 0151 */ 0152 #define LL_OPAMP_MODE_FUNCTIONAL 0x00000000U /*!< OPAMP functional mode */ 0153 #define LL_OPAMP_MODE_CALIBRATION (OPAMP_CSR_CALON) /*!< OPAMP calibration mode */ 0154 /** 0155 * @} 0156 */ 0157 0158 /** @defgroup OPAMP_LL_EC_FUNCTIONAL_MODE OPAMP functional mode 0159 * @ingroup RTEMSBSPsARMSTM32H7 0160 * @{ 0161 */ 0162 #define LL_OPAMP_MODE_STANDALONE 0x00000000U /*!< OPAMP functional mode, OPAMP operation in standalone */ 0163 #define LL_OPAMP_MODE_FOLLOWER (OPAMP_CSR_VMSEL_1 | OPAMP_CSR_VMSEL_0) /*!< OPAMP functional mode, OPAMP operation in follower */ 0164 #define LL_OPAMP_MODE_PGA (OPAMP_CSR_VMSEL_1) /*!< OPAMP functional mode, OPAMP operation in PGA */ 0165 #define LL_OPAMP_MODE_PGA_IO0 (OPAMP_CSR_PGGAIN_2|OPAMP_CSR_VMSEL_1) /*!< In PGA mode, the inverting input is connected to VINM0 for filtering */ 0166 #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 0167 - Input signal on VINM0, bias on VINPx: negative gain 0168 - Bias on VINM0, input signal on VINPx: positive gain */ 0169 #define LL_OPAMP_MODE_PGA_IO0_IO1_BIAS (OPAMP_CSR_PGGAIN_3|OPAMP_CSR_PGGAIN_2|OPAMP_CSR_VMSEL_1) /*!< In PGA mode, the inverting input is connected to VINM0 0170 - Input signal on VINM0, bias on VINPx: negative gain 0171 - Bias on VINM0, input signal on VINPx: positive gain 0172 And VINM1 is connected too for filtering */ 0173 0174 /** 0175 * @} 0176 */ 0177 0178 /** @defgroup OPAMP_LL_EC_MODE_PGA_GAIN OPAMP PGA gain (relevant when OPAMP is in functional mode PGA) 0179 * @ingroup RTEMSBSPsARMSTM32H7 0180 * @note Gain sign: 0181 * - is positive if the @ref OPAMP_LL_EC_FUNCTIONAL_MODE configuration is 0182 * @ref LL_OPAMP_MODE_PGA or LL_OPAMP_MODE_PGA_IO0 0183 * - may be positive or negative if the @ref OPAMP_LL_EC_FUNCTIONAL_MODE configuration is 0184 * @ref LL_OPAMP_MODE_PGA_IO0_BIAS or LL_OPAMP_MODE_PGA_IO0_IO1_BIAS 0185 * see @ref OPAMP_LL_EC_FUNCTIONAL_MODE for more details 0186 * @{ 0187 */ 0188 #define LL_OPAMP_PGA_GAIN_2_OR_MINUS_1 0x00000000U /*!< OPAMP PGA gain 2 or -1 */ 0189 #define LL_OPAMP_PGA_GAIN_4_OR_MINUS_3 ( OPAMP_CSR_PGGAIN_0) /*!< OPAMP PGA gain 4 or -3 */ 0190 #define LL_OPAMP_PGA_GAIN_8_OR_MINUS_7 ( OPAMP_CSR_PGGAIN_1 ) /*!< OPAMP PGA gain 8 or -7 */ 0191 #define LL_OPAMP_PGA_GAIN_16_OR_MINUS_15 ( OPAMP_CSR_PGGAIN_1 | OPAMP_CSR_PGGAIN_0) /*!< OPAMP PGA gain 16 or -15 */ 0192 /** 0193 * @} 0194 */ 0195 0196 /** @defgroup OPAMP_LL_EC_INPUT_NONINVERTING OPAMP input non-inverting 0197 * @ingroup RTEMSBSPsARMSTM32H7 0198 * @{ 0199 */ 0200 #define LL_OPAMP_INPUT_NONINVERT_IO0 0x00000000U /*!< OPAMP non inverting input connected to I/O VINP0 0201 (PB0 for OPAMP1, PE9 for OPAMP2) 0202 Note: On this STM32 series, all OPAMPx are not available on all devices. Refer to device datasheet for more details */ 0203 #define LL_OPAMP_INPUT_NONINVERT_DAC OPAMP_CSR_VPSEL_0 /*!< OPAMP non inverting input connected internally to DAC channel 0204 (DAC1_CH1 for OPAMP1, DAC1_CH2 for OPAMP2) 0205 Note: On this STM32 series, all OPAMPx are not available on all devices. Refer to device datasheet for more details */ 0206 #if defined(DAC2) 0207 #define LL_OPAMP_INPUT_NONINVERT_DAC2 OPAMP_CSR_VPSEL_1 /*!< OPAMP non inverting input connected internally to DAC2 channel 0208 (DAC3 only for OPAMP2)*/ 0209 #endif /* DAC2 */ 0210 0211 /** 0212 * @} 0213 */ 0214 0215 /** @defgroup OPAMP_LL_EC_INPUT_INVERTING OPAMP input inverting 0216 * @ingroup RTEMSBSPsARMSTM32H7 0217 * @note OPAMP inverting input is used with OPAMP in mode standalone or PGA with negative gain or bias. 0218 * Otherwise (OPAMP in mode follower), OPAMP inverting input is not used (not connected to GPIO pin). 0219 * @{ 0220 */ 0221 #define LL_OPAMP_INPUT_INVERT_IO0 0x00000000U /*!< OPAMP inverting input connected to I/O VINM0 0222 (PC5 for OPAMP1, PE8 for OPAMP2) 0223 Note: On this STM32 series, all OPAMPx are not available on all devices. Refer to device datasheet for more details */ 0224 #define LL_OPAMP_INPUT_INVERT_IO1 OPAMP_CSR_VMSEL_0 /*!< OPAMP inverting input connected to I/0 VINM1 0225 (PA7 for OPAMP1, PG1 for OPAMP2) 0226 Note: On this STM32 series, all OPAMPx are not available on all devices. Refer to device datasheet for more details */ 0227 #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). 0228 Note: On this STM32 series, this literal include cases of value 0x11 for mode follower and value 0x10 for mode PGA. */ 0229 /** 0230 * @} 0231 */ 0232 0233 0234 0235 /** @defgroup OPAMP_LL_EC_POWER_MODE OPAMP PowerMode 0236 * @ingroup RTEMSBSPsARMSTM32H7 0237 * @{ 0238 */ 0239 #define LL_OPAMP_POWERMODE_NORMAL (OPAMP_POWERMODE_OTR_REGOFFSET) /*!< OPAMP output in normal mode */ 0240 #define LL_OPAMP_POWERMODE_HIGHSPEED (OPAMP_POWERMODE_HSOTR_REGOFFSET | OPAMP_CSR_OPAHSM) /*!< OPAMP output in highspeed mode */ 0241 /** 0242 * @} 0243 */ 0244 0245 /** @defgroup OPAMP_LL_EC_TRIMMING_MODE OPAMP trimming mode 0246 * @ingroup RTEMSBSPsARMSTM32H7 0247 * @{ 0248 */ 0249 #define LL_OPAMP_TRIMMING_FACTORY 0x00000000U /*!< OPAMP trimming factors set to factory values */ 0250 #define LL_OPAMP_TRIMMING_USER OPAMP_CSR_USERTRIM /*!< OPAMP trimming factors set to user values */ 0251 /** 0252 * @} 0253 */ 0254 0255 /** @defgroup OPAMP_LL_EC_TRIMMING_TRANSISTORS_DIFF_PAIR OPAMP trimming of transistors differential pair NMOS or PMOS 0256 * @ingroup RTEMSBSPsARMSTM32H7 0257 * @{ 0258 */ 0259 #define LL_OPAMP_TRIMMING_NMOS_VREF_90PC_VDDA (OPAMP_OTR_TRIMOFFSETN | ((OPAMP_CSR_CALSEL_1 | OPAMP_CSR_CALSEL_0) << 4)) /*!< 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). */ 0260 #define LL_OPAMP_TRIMMING_NMOS_VREF_50PC_VDDA (OPAMP_OTR_TRIMOFFSETN | (OPAMP_CSR_CALSEL_1 << 4)) /*!< OPAMP trimming of transistors differential pair NMOS (internal reference voltage set to 0.5*Vdda). */ 0261 #define LL_OPAMP_TRIMMING_PMOS_VREF_10PC_VDDA (OPAMP_OTR_TRIMOFFSETP | (OPAMP_CSR_CALSEL_0 << 4)) /*!< 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). */ 0262 #define LL_OPAMP_TRIMMING_PMOS_VREF_3_3PC_VDDA (OPAMP_OTR_TRIMOFFSETP ) /*!< OPAMP trimming of transistors differential pair PMOS (internal reference voltage set to 0.33*Vdda). */ 0263 #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). */ 0264 #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). */ 0265 /** 0266 * @} 0267 */ 0268 0269 /** @defgroup OPAMP_LL_EC_HW_DELAYS Definitions of OPAMP hardware constraints delays 0270 * @ingroup RTEMSBSPsARMSTM32H7 0271 * @note Only OPAMP peripheral HW delays are defined in OPAMP LL driver driver, 0272 * not timeout values. 0273 * For details on delays values, refer to descriptions in source code 0274 * above each literal definition. 0275 * @{ 0276 */ 0277 0278 /* Delay for OPAMP startup time (transition from state disable to enable). */ 0279 /* Note: OPAMP startup time depends on board application environment: */ 0280 /* impedance connected to OPAMP output. */ 0281 /* The delay below is specified under conditions: */ 0282 /* - OPAMP in functional mode follower */ 0283 /* - load impedance of 4kOhm (min), 50pF (max) */ 0284 /* Literal set to maximum value (refer to device datasheet, */ 0285 /* parameter "tWAKEUP"). */ 0286 /* Unit: us */ 0287 #define LL_OPAMP_DELAY_STARTUP_US (3U) /*!< Delay for OPAMP startup time */ 0288 /** 0289 * @} 0290 */ 0291 0292 /** 0293 * @} 0294 */ 0295 0296 /* Exported macro ------------------------------------------------------------*/ 0297 /** @defgroup OPAMP_LL_Exported_Macros OPAMP Exported Macros 0298 * @ingroup RTEMSBSPsARMSTM32H7 0299 * @{ 0300 */ 0301 /** @defgroup OPAMP_LL_EM_WRITE_READ Common write and read registers macro 0302 * @ingroup RTEMSBSPsARMSTM32H7 0303 * @{ 0304 */ 0305 /** 0306 * @brief Write a value in OPAMP LL_OPAMP_GetPowerModeregister 0307 * @param __INSTANCE__ OPAMP Instance 0308 * @param __REG__ Register to be written 0309 * @param __VALUE__ Value to be written in the register 0310 * @retval None 0311 */ 0312 #define LL_OPAMP_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG((__INSTANCE__)->__REG__, (__VALUE__)) 0313 0314 /** 0315 * @brief Read a value in OPAMP register 0316 * @param __INSTANCE__ OPAMP Instance 0317 * @param __REG__ Register to be read 0318 * @retval Register value 0319 */ 0320 #define LL_OPAMP_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__) 0321 /** 0322 * @} 0323 */ 0324 /** @defgroup OPAMP_LL_EM_HELPER_MACRO OPAMP helper macro 0325 * @ingroup RTEMSBSPsARMSTM32H7 0326 * @{ 0327 */ 0328 0329 /** 0330 * @brief Helper macro to select the OPAMP common instance 0331 * to which is belonging the selected OPAMP instance. 0332 * @note OPAMP common register instance can be used to 0333 * set parameters common to several OPAMP instances. 0334 * Refer to functions having argument "OPAMPxy_COMMON" as parameter. 0335 * @param __OPAMPx__ OPAMP instance 0336 * @retval OPAMP common instance 0337 */ 0338 #if defined(OPAMP1) && defined(OPAMP2) 0339 #define __LL_OPAMP_COMMON_INSTANCE(__OPAMPx__) \ 0340 (OPAMP12_COMMON) 0341 #endif 0342 0343 /** 0344 * @brief Helper macro to check if all OPAMP instances sharing the same 0345 * OPAMP common instance are disabled. 0346 * @note This check is required by functions with setting conditioned to 0347 * OPAMP state: 0348 * All OPAMP instances of the OPAMP common group must be disabled. 0349 * Refer to functions having argument "OPAMPxy_COMMON" as parameter. 0350 * @retval 0: All OPAMP instances sharing the same OPAMP common instance 0351 * are disabled. 0352 * 1: At least one OPAMP instance sharing the same OPAMP common instance 0353 * is enabled 0354 */ 0355 #if defined(OPAMP1) && defined(OPAMP2) 0356 #define __LL_OPAMP_IS_ENABLED_ALL_COMMON_INSTANCE() \ 0357 (LL_OPAMP_IsEnabled(OPAMP1) | \ 0358 LL_OPAMP_IsEnabled(OPAMP2) ) 0359 #endif 0360 0361 /** 0362 * @} 0363 */ 0364 0365 /** 0366 * @} 0367 */ 0368 0369 /* Exported functions --------------------------------------------------------*/ 0370 /** @defgroup OPAMP_LL_Exported_Functions OPAMP Exported Functions 0371 * @ingroup RTEMSBSPsARMSTM32H7 0372 * @{ 0373 */ 0374 0375 /** @defgroup OPAMP_LL_EF_CONFIGURATION_OPAMP_INSTANCE Configuration of OPAMP hierarchical scope: OPAMP instance 0376 * @ingroup RTEMSBSPsARMSTM32H7 0377 * @{ 0378 */ 0379 0380 /** 0381 * @brief Set OPAMP mode calibration or functional. 0382 * @note OPAMP mode corresponds to functional or calibration mode: 0383 * - functional mode: OPAMP operation in standalone, follower, ... 0384 * Set functional mode using function 0385 * @ref LL_OPAMP_SetFunctionalMode(). 0386 * - calibration mode: offset calibration of the selected 0387 * transistors differential pair NMOS or PMOS. 0388 * @rmtoll CSR CALON LL_OPAMP_SetMode 0389 * @param OPAMPx OPAMP instance 0390 * @param Mode This parameter can be one of the following values: 0391 * @arg @ref LL_OPAMP_MODE_FUNCTIONAL 0392 * @arg @ref LL_OPAMP_MODE_CALIBRATION 0393 * @retval None 0394 */ 0395 __STATIC_INLINE void LL_OPAMP_SetMode(OPAMP_TypeDef *OPAMPx, uint32_t Mode) 0396 { 0397 MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_CALON, Mode); 0398 } 0399 0400 /** 0401 * @brief Get OPAMP mode calibration or functional. 0402 * @note OPAMP mode corresponds to functional or calibration mode: 0403 * - functional mode: OPAMP operation in standalone, follower, ... 0404 * Set functional mode using function 0405 * @ref LL_OPAMP_SetFunctionalMode(). 0406 * - calibration mode: offset calibration of the selected 0407 * transistors differential pair NMOS or PMOS. 0408 * @rmtoll CSR CALON LL_OPAMP_GetMode 0409 * @param OPAMPx OPAMP instance 0410 * @retval Returned value can be one of the following values: 0411 * @arg @ref LL_OPAMP_MODE_FUNCTIONAL 0412 * @arg @ref LL_OPAMP_MODE_CALIBRATION 0413 */ 0414 __STATIC_INLINE uint32_t LL_OPAMP_GetMode(OPAMP_TypeDef *OPAMPx) 0415 { 0416 return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_CALON)); 0417 } 0418 0419 /** 0420 * @brief Set OPAMP functional mode by setting internal connections. 0421 * OPAMP operation in standalone, follower, ... 0422 * @note This function reset bit of calibration mode to ensure 0423 * to be in functional mode, in order to have OPAMP parameters 0424 * (inputs selection, ...) set with the corresponding OPAMP mode 0425 * to be effective. 0426 * @rmtoll CSR VMSEL LL_OPAMP_SetFunctionalMode 0427 * @param OPAMPx OPAMP instance 0428 * @param FunctionalMode This parameter can be one of the following values: 0429 * @arg @ref LL_OPAMP_MODE_STANDALONE 0430 * @arg @ref LL_OPAMP_MODE_FOLLOWER 0431 * @arg @ref LL_OPAMP_MODE_PGA 0432 * @arg @ref LL_OPAMP_MODE_PGA_IO0 0433 * @arg @ref LL_OPAMP_MODE_PGA_IO0_BIAS 0434 * @arg @ref LL_OPAMP_MODE_PGA_IO0_IO1_BIAS 0435 * @retval None 0436 */ 0437 __STATIC_INLINE void LL_OPAMP_SetFunctionalMode(OPAMP_TypeDef *OPAMPx, uint32_t FunctionalMode) 0438 { 0439 /* Note: Bit OPAMP_CSR_CALON reset to ensure to be in functional mode */ 0440 MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_PGGAIN_3 | OPAMP_CSR_PGGAIN_2 | OPAMP_CSR_VMSEL | OPAMP_CSR_CALON, FunctionalMode); 0441 } 0442 0443 /** 0444 * @brief Get OPAMP functional mode from setting of internal connections. 0445 * OPAMP operation in standalone, follower, ... 0446 * @rmtoll CSR VMSEL LL_OPAMP_GetFunctionalMode 0447 * @param OPAMPx OPAMP instance 0448 * @retval Returned value can be one of the following values: 0449 * @arg @ref LL_OPAMP_MODE_STANDALONE 0450 * @arg @ref LL_OPAMP_MODE_FOLLOWER 0451 * @arg @ref LL_OPAMP_MODE_PGA 0452 * @arg @ref LL_OPAMP_MODE_PGA_IO0 0453 * @arg @ref LL_OPAMP_MODE_PGA_IO0_BIAS 0454 * @arg @ref LL_OPAMP_MODE_PGA_IO0_IO1_BIAS 0455 */ 0456 __STATIC_INLINE uint32_t LL_OPAMP_GetFunctionalMode(OPAMP_TypeDef *OPAMPx) 0457 { 0458 return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_PGGAIN_3 | OPAMP_CSR_PGGAIN_2 | OPAMP_CSR_VMSEL)); 0459 } 0460 0461 /** 0462 * @brief Set OPAMP PGA gain. 0463 * @note Preliminarily, OPAMP must be set in mode PGA 0464 * using function @ref LL_OPAMP_SetFunctionalMode(). 0465 * @rmtoll CSR PGGAIN LL_OPAMP_SetPGAGain 0466 * @param OPAMPx OPAMP instance 0467 * @param PGAGain This parameter can be one of the following values: 0468 * @arg @ref LL_OPAMP_PGA_GAIN_2_OR_MINUS_1 0469 * @arg @ref LL_OPAMP_PGA_GAIN_4_OR_MINUS_3 0470 * @arg @ref LL_OPAMP_PGA_GAIN_8_OR_MINUS_7 0471 * @arg @ref LL_OPAMP_PGA_GAIN_16_OR_MINUS_15 0472 * @retval None 0473 */ 0474 __STATIC_INLINE void LL_OPAMP_SetPGAGain(OPAMP_TypeDef *OPAMPx, uint32_t PGAGain) 0475 { 0476 MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_PGGAIN_1 | OPAMP_CSR_PGGAIN_0, PGAGain); 0477 } 0478 0479 /** 0480 * @brief Get OPAMP PGA gain. 0481 * @note Preliminarily, OPAMP must be set in mode PGA 0482 * using function @ref LL_OPAMP_SetFunctionalMode(). 0483 * @rmtoll CSR PGGAIN LL_OPAMP_GetPGAGain 0484 * @param OPAMPx OPAMP instance 0485 * @retval Returned value can be one of the following values: 0486 * @arg @ref LL_OPAMP_PGA_GAIN_2_OR_MINUS_1 0487 * @arg @ref LL_OPAMP_PGA_GAIN_4_OR_MINUS_3 0488 * @arg @ref LL_OPAMP_PGA_GAIN_8_OR_MINUS_7 0489 * @arg @ref LL_OPAMP_PGA_GAIN_16_OR_MINUS_15 0490 */ 0491 __STATIC_INLINE uint32_t LL_OPAMP_GetPGAGain(OPAMP_TypeDef *OPAMPx) 0492 { 0493 return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_PGGAIN_1 | OPAMP_CSR_PGGAIN_0)); 0494 } 0495 0496 /** 0497 * @brief Set OPAMP power mode normal or highspeed. 0498 * @note OPAMP highspeed mode allows output stage to have a better slew rate. 0499 * @rmtoll CSR OPAHSM LL_OPAMP_SetPowerMode 0500 * @param OPAMPx OPAMP instance 0501 * @param PowerMode This parameter can be one of the following values: 0502 * @arg @ref LL_OPAMP_POWERMODE_NORMAL 0503 * @arg @ref LL_OPAMP_POWERMODE_HIGHSPEED 0504 * @retval None 0505 */ 0506 __STATIC_INLINE void LL_OPAMP_SetPowerMode(OPAMP_TypeDef *OPAMPx, uint32_t PowerMode) 0507 { 0508 MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_OPAHSM, (PowerMode & OPAMP_POWERMODE_CSR_BIT_MASK)); 0509 } 0510 0511 /** 0512 * @brief Get OPAMP power mode normal or highspeed. 0513 * @note OPAMP highspeed mode allows output stage to have a better slew rate. 0514 * @rmtoll CSR OPAHSM LL_OPAMP_GetPowerMode 0515 * @param OPAMPx OPAMP instance 0516 * @retval Returned value can be one of the following values: 0517 * @arg @ref LL_OPAMP_POWERMODE_NORMAL 0518 * @arg @ref LL_OPAMP_POWERMODE_HIGHSPEED 0519 */ 0520 __STATIC_INLINE uint32_t LL_OPAMP_GetPowerMode(OPAMP_TypeDef *OPAMPx) 0521 { 0522 uint32_t power_mode = (READ_BIT(OPAMPx->CSR, OPAMP_CSR_OPAHSM)); 0523 0524 return (uint32_t)(power_mode | (power_mode >> (OPAMP_CSR_OPAHSM_Pos))); 0525 } 0526 /** 0527 * @} 0528 */ 0529 0530 /** @defgroup OPAMP_LL_EF_CONFIGURATION_INPUTS Configuration of OPAMP inputs 0531 * @ingroup RTEMSBSPsARMSTM32H7 0532 * @{ 0533 */ 0534 0535 /** 0536 * @brief Set OPAMP non-inverting input connection. 0537 * @rmtoll CSR VPSEL LL_OPAMP_SetInputNonInverting 0538 * @param OPAMPx OPAMP instance 0539 * @param InputNonInverting This parameter can be one of the following values: 0540 * @arg @ref LL_OPAMP_INPUT_NONINVERT_IO0 0541 * @arg @ref LL_OPAMP_INPUT_NONINVERT_DAC 0542 * @arg @ref LL_OPAMP_INPUT_NONINVERT_DAC2 (Only for OPAMP2) 0543 * @retval None 0544 */ 0545 __STATIC_INLINE void LL_OPAMP_SetInputNonInverting(OPAMP_TypeDef *OPAMPx, uint32_t InputNonInverting) 0546 { 0547 MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_VPSEL, InputNonInverting); 0548 } 0549 0550 /** 0551 * @brief Get OPAMP non-inverting input connection. 0552 * @rmtoll CSR VPSEL LL_OPAMP_GetInputNonInverting 0553 * @param OPAMPx OPAMP instance 0554 * @retval Returned value can be one of the following values: 0555 * @arg @ref LL_OPAMP_INPUT_NONINVERT_IO0 0556 * @arg @ref LL_OPAMP_INPUT_NONINVERT_DAC 0557 * @arg @ref LL_OPAMP_INPUT_NONINVERT_DAC2 (Only for OPAMP2) 0558 */ 0559 __STATIC_INLINE uint32_t LL_OPAMP_GetInputNonInverting(OPAMP_TypeDef *OPAMPx) 0560 { 0561 return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_VPSEL)); 0562 } 0563 0564 /** 0565 * @brief Set OPAMP inverting input connection. 0566 * @note OPAMP inverting input is used with OPAMP in mode standalone 0567 * or PGA with external capacitors for filtering circuit. 0568 * Otherwise (OPAMP in mode follower), OPAMP inverting input 0569 * is not used (not connected to GPIO pin). 0570 * @rmtoll CSR VMSEL LL_OPAMP_SetInputInverting 0571 * @param OPAMPx OPAMP instance 0572 * @param InputInverting This parameter can be one of the following values: 0573 * @arg @ref LL_OPAMP_INPUT_INVERT_IO0 0574 * @arg @ref LL_OPAMP_INPUT_INVERT_IO1 0575 * @arg @ref LL_OPAMP_INPUT_INVERT_CONNECT_NO 0576 * @retval None 0577 */ 0578 __STATIC_INLINE void LL_OPAMP_SetInputInverting(OPAMP_TypeDef *OPAMPx, uint32_t InputInverting) 0579 { 0580 /* Manage cases of OPAMP inverting input not connected (0x10 and 0x11) */ 0581 /* to not modify OPAMP mode follower or PGA. */ 0582 /* Bit OPAMP_CSR_VMSEL_1 is set by OPAMP mode (follower, PGA). */ 0583 MODIFY_REG(OPAMPx->CSR, (~(InputInverting >> 1)) & OPAMP_CSR_VMSEL_0, InputInverting); 0584 } 0585 0586 /** 0587 * @brief Get OPAMP inverting input connection. 0588 * @rmtoll CSR VMSEL LL_OPAMP_GetInputInverting 0589 * @param OPAMPx OPAMP instance 0590 * @retval Returned value can be one of the following values: 0591 * @arg @ref LL_OPAMP_INPUT_INVERT_IO0 0592 * @arg @ref LL_OPAMP_INPUT_INVERT_IO1 0593 * @arg @ref LL_OPAMP_INPUT_INVERT_CONNECT_NO 0594 */ 0595 __STATIC_INLINE uint32_t LL_OPAMP_GetInputInverting(OPAMP_TypeDef *OPAMPx) 0596 { 0597 uint32_t input_inverting = READ_BIT(OPAMPx->CSR, OPAMP_CSR_VMSEL); 0598 0599 /* Manage cases 0x10 and 0x11 to return the same value: OPAMP inverting */ 0600 /* input not connected. */ 0601 return (input_inverting & ~((input_inverting >> 1) & OPAMP_CSR_VMSEL_0)); 0602 } 0603 0604 /** 0605 * @} 0606 */ 0607 0608 /** @defgroup OPAMP_LL_EF_OPAMP_TRIMMING Configuration and operation of OPAMP trimming 0609 * @ingroup RTEMSBSPsARMSTM32H7 0610 * @{ 0611 */ 0612 0613 /** 0614 * @brief Set OPAMP trimming mode. 0615 * @rmtoll CSR USERTRIM LL_OPAMP_SetTrimmingMode 0616 * @param OPAMPx OPAMP instance 0617 * @param TrimmingMode This parameter can be one of the following values: 0618 * @arg @ref LL_OPAMP_TRIMMING_FACTORY 0619 * @arg @ref LL_OPAMP_TRIMMING_USER 0620 * @retval None 0621 */ 0622 __STATIC_INLINE void LL_OPAMP_SetTrimmingMode(OPAMP_TypeDef *OPAMPx, uint32_t TrimmingMode) 0623 { 0624 MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_USERTRIM, TrimmingMode); 0625 } 0626 0627 /** 0628 * @brief Get OPAMP trimming mode. 0629 * @rmtoll CSR USERTRIM LL_OPAMP_GetTrimmingMode 0630 * @param OPAMPx OPAMP instance 0631 * @retval Returned value can be one of the following values: 0632 * @arg @ref LL_OPAMP_TRIMMING_FACTORY 0633 * @arg @ref LL_OPAMP_TRIMMING_USER 0634 */ 0635 __STATIC_INLINE uint32_t LL_OPAMP_GetTrimmingMode(OPAMP_TypeDef *OPAMPx) 0636 { 0637 return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_USERTRIM)); 0638 } 0639 0640 /** 0641 * @brief Set OPAMP offset to calibrate the selected transistors 0642 * differential pair NMOS or PMOS. 0643 * @note Preliminarily, OPAMP must be set in mode calibration 0644 * using function @ref LL_OPAMP_SetMode(). 0645 * @rmtoll CSR CALSEL LL_OPAMP_SetCalibrationSelection 0646 * @param OPAMPx OPAMP instance 0647 * @param TransistorsDiffPair This parameter can be one of the following values: 0648 * @arg @ref LL_OPAMP_TRIMMING_NMOS (1) 0649 * @arg @ref LL_OPAMP_TRIMMING_PMOS (1) 0650 * @arg @ref LL_OPAMP_TRIMMING_NMOS_VREF_50PC_VDDA 0651 * @arg @ref LL_OPAMP_TRIMMING_PMOS_VREF_3_3PC_VDDA 0652 * 0653 * (1) Default parameters to be used for calibration 0654 * using two trimming steps (one with each transistors differential 0655 * pair NMOS and PMOS) 0656 * @retval None 0657 */ 0658 __STATIC_INLINE void LL_OPAMP_SetCalibrationSelection(OPAMP_TypeDef *OPAMPx, uint32_t TransistorsDiffPair) 0659 { 0660 /* Parameter used with mask "OPAMP_TRIMMING_SELECT_MASK" because */ 0661 /* containing other bits reserved for other purpose. */ 0662 MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_CALSEL, ((TransistorsDiffPair & OPAMP_TRIMMING_SELECT_MASK) >> 4)); 0663 } 0664 0665 /** 0666 * @brief Get OPAMP offset to calibrate the selected transistors 0667 * differential pair NMOS or PMOS. 0668 * @note Preliminarily, OPAMP must be set in mode calibration 0669 * using function @ref LL_OPAMP_SetMode(). 0670 * @rmtoll CSR CALSEL LL_OPAMP_GetCalibrationSelection 0671 * @param OPAMPx OPAMP instance 0672 * @retval Returned value can be one of the following values: 0673 * @arg @ref LL_OPAMP_TRIMMING_NMOS (1) 0674 * @arg @ref LL_OPAMP_TRIMMING_PMOS (1) 0675 * @arg @ref LL_OPAMP_TRIMMING_NMOS_VREF_50PC_VDDA 0676 * @arg @ref LL_OPAMP_TRIMMING_PMOS_VREF_3_3PC_VDDA 0677 * 0678 * (1) Default parameters to be used for calibration 0679 * using two trimming steps (one with each transistors differential 0680 * pair NMOS and PMOS) 0681 */ 0682 __STATIC_INLINE uint32_t LL_OPAMP_GetCalibrationSelection(OPAMP_TypeDef *OPAMPx) 0683 { 0684 uint32_t CalibrationSelection = (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_CALSEL)); 0685 0686 return (uint32_t)((CalibrationSelection << 4)| 0687 (((CalibrationSelection & OPAMP_CSR_CALSEL_1) == 0UL) ? OPAMP_OTR_TRIMOFFSETN : OPAMP_OTR_TRIMOFFSETP)); 0688 } 0689 0690 /** 0691 * @brief Get OPAMP calibration result of toggling output. 0692 * @note This functions returns: 0693 * 0 if OPAMP calibration output is reset 0694 * 1 if OPAMP calibration output is set 0695 * @rmtoll CSR OUTCAL LL_OPAMP_IsCalibrationOutputSet 0696 * @param OPAMPx OPAMP instance 0697 * @retval State of bit (1 or 0). 0698 */ 0699 __STATIC_INLINE uint32_t LL_OPAMP_IsCalibrationOutputSet(OPAMP_TypeDef *OPAMPx) 0700 { 0701 return ((READ_BIT(OPAMPx->CSR, OPAMP_CSR_CALOUT) == OPAMP_CSR_CALOUT)?1UL:0UL); 0702 } 0703 0704 /** 0705 * @brief Set OPAMP trimming factor for the selected transistors 0706 * differential pair NMOS or PMOS, corresponding to the selected 0707 * power mode. 0708 * @rmtoll OTR TRIMOFFSETN LL_OPAMP_SetTrimmingValue\n 0709 * OTR TRIMOFFSETP LL_OPAMP_SetTrimmingValue\n 0710 * HSOTR TRIMHSOFFSETN LL_OPAMP_SetTrimmingValue\n 0711 * HSOTR TRIMHSOFFSETP LL_OPAMP_SetTrimmingValue 0712 * @param OPAMPx OPAMP instance 0713 * @param PowerMode This parameter can be one of the following values: 0714 * @arg @ref LL_OPAMP_POWERMODE_NORMAL 0715 * @arg @ref LL_OPAMP_POWERMODE_HIGHSPEED 0716 * @param TransistorsDiffPair This parameter can be one of the following values: 0717 * @arg @ref LL_OPAMP_TRIMMING_NMOS 0718 * @arg @ref LL_OPAMP_TRIMMING_PMOS 0719 * @param TrimmingValue 0x00...0x1F 0720 * @retval None 0721 */ 0722 __STATIC_INLINE void LL_OPAMP_SetTrimmingValue(OPAMP_TypeDef* OPAMPx, uint32_t PowerMode, uint32_t TransistorsDiffPair, uint32_t TrimmingValue) 0723 { 0724 __IO uint32_t *preg = __OPAMP_PTR_REG_OFFSET(OPAMPx->OTR, (PowerMode & OPAMP_POWERMODE_OTR_REGOFFSET_MASK)); 0725 0726 /* Set bits with position in register depending on parameter */ 0727 /* "TransistorsDiffPair". */ 0728 /* Parameter used with mask "OPAMP_TRIMMING_VALUE_MASK" because */ 0729 /* containing other bits reserved for other purpose. */ 0730 MODIFY_REG(*preg, 0731 (TransistorsDiffPair & OPAMP_TRIMMING_VALUE_MASK) << 1U, 0732 TrimmingValue << ((TransistorsDiffPair == LL_OPAMP_TRIMMING_NMOS) ? OPAMP_OTR_TRIMOFFSETN_Pos : OPAMP_OTR_TRIMOFFSETP_Pos)); 0733 } 0734 0735 /** 0736 * @brief Get OPAMP trimming factor for the selected transistors 0737 * differential pair NMOS or PMOS, corresponding to the selected 0738 * power mode. 0739 * @rmtoll OTR TRIMOFFSETN LL_OPAMP_GetTrimmingValue\n 0740 * OTR TRIMOFFSETP LL_OPAMP_GetTrimmingValue\n 0741 * HSOTR TRIMHSOFFSETN LL_OPAMP_GetTrimmingValue\n 0742 * HSOTR TRIMHSOFFSETP LL_OPAMP_GetTrimmingValue 0743 * @param OPAMPx OPAMP instance 0744 * @param PowerMode This parameter can be one of the following values: 0745 * @arg @ref LL_OPAMP_POWERMODE_NORMAL 0746 * @arg @ref LL_OPAMP_POWERMODE_HIGHSPEED 0747 * @param TransistorsDiffPair This parameter can be one of the following values: 0748 * @arg @ref LL_OPAMP_TRIMMING_NMOS 0749 * @arg @ref LL_OPAMP_TRIMMING_PMOS 0750 * @retval 0x0...0x1F 0751 */ 0752 __STATIC_INLINE uint32_t LL_OPAMP_GetTrimmingValue(OPAMP_TypeDef* OPAMPx, uint32_t PowerMode, uint32_t TransistorsDiffPair) 0753 { 0754 const __IO uint32_t *preg = __OPAMP_PTR_REG_OFFSET(OPAMPx->OTR, (PowerMode & OPAMP_POWERMODE_OTR_REGOFFSET_MASK)); 0755 0756 /* Retrieve bits with position in register depending on parameter */ 0757 /* "TransistorsDiffPair". */ 0758 /* Parameter used with mask "OPAMP_TRIMMING_VALUE_MASK" because */ 0759 /* containing other bits reserved for other purpose. */ 0760 return (uint32_t)(READ_BIT(*preg, (TransistorsDiffPair & OPAMP_TRIMMING_VALUE_MASK)) 0761 >> ((TransistorsDiffPair == LL_OPAMP_TRIMMING_NMOS) ? OPAMP_OTR_TRIMOFFSETN_Pos : OPAMP_OTR_TRIMOFFSETP_Pos)); 0762 } 0763 0764 /** 0765 * @} 0766 */ 0767 0768 /** @defgroup OPAMP_LL_EF_OPERATION Operation on OPAMP instance 0769 * @ingroup RTEMSBSPsARMSTM32H7 0770 * @{ 0771 */ 0772 /** 0773 * @brief Enable OPAMP instance. 0774 * @note After enable from off state, OPAMP requires a delay 0775 * to fulfill wake up time specification. 0776 * Refer to device datasheet, parameter "tWAKEUP". 0777 * @rmtoll CSR OPAMPXEN LL_OPAMP_Enable 0778 * @param OPAMPx OPAMP instance 0779 * @retval None 0780 */ 0781 __STATIC_INLINE void LL_OPAMP_Enable(OPAMP_TypeDef *OPAMPx) 0782 { 0783 SET_BIT(OPAMPx->CSR, OPAMP_CSR_OPAMPxEN); 0784 } 0785 0786 /** 0787 * @brief Disable OPAMP instance. 0788 * @rmtoll CSR OPAMPXEN LL_OPAMP_Disable 0789 * @param OPAMPx OPAMP instance 0790 * @retval None 0791 */ 0792 __STATIC_INLINE void LL_OPAMP_Disable(OPAMP_TypeDef *OPAMPx) 0793 { 0794 CLEAR_BIT(OPAMPx->CSR, OPAMP_CSR_OPAMPxEN); 0795 } 0796 0797 /** 0798 * @brief Get OPAMP instance enable state 0799 * (0: OPAMP is disabled, 1: OPAMP is enabled) 0800 * @rmtoll CSR OPAMPXEN LL_OPAMP_IsEnabled 0801 * @param OPAMPx OPAMP instance 0802 * @retval State of bit (1 or 0). 0803 */ 0804 __STATIC_INLINE uint32_t LL_OPAMP_IsEnabled(OPAMP_TypeDef *OPAMPx) 0805 { 0806 return ((READ_BIT(OPAMPx->CSR, OPAMP_CSR_OPAMPxEN) == (OPAMP_CSR_OPAMPxEN))?1UL:0UL); 0807 } 0808 /** 0809 * @} 0810 */ 0811 0812 #if defined(USE_FULL_LL_DRIVER) || defined(__rtems__) 0813 /** @defgroup OPAMP_LL_EF_Init Initialization and de-initialization functions 0814 * @ingroup RTEMSBSPsARMSTM32H7 0815 * @{ 0816 */ 0817 0818 ErrorStatus LL_OPAMP_DeInit(OPAMP_TypeDef *OPAMPx); 0819 ErrorStatus LL_OPAMP_Init(OPAMP_TypeDef *OPAMPx, LL_OPAMP_InitTypeDef *OPAMP_InitStruct); 0820 void LL_OPAMP_StructInit(LL_OPAMP_InitTypeDef *OPAMP_InitStruct); 0821 0822 /** 0823 * @} 0824 */ 0825 #endif /* USE_FULL_LL_DRIVER */ 0826 0827 /** 0828 * @} 0829 */ 0830 0831 /** 0832 * @} 0833 */ 0834 0835 #endif /* OPAMP1 || OPAMP2 */ 0836 0837 /** 0838 * @} 0839 */ 0840 0841 #ifdef __cplusplus 0842 } 0843 #endif 0844 0845 #endif /* __STM32H7xx_LL_OPAMP_H */ 0846 0847
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |