STM32L443xx HAL User Manual
|
00001 /** 00002 ****************************************************************************** 00003 * @file stm32l4xx_ll_opamp.h 00004 * @author MCD Application Team 00005 * @brief Header file of OPAMP LL module. 00006 ****************************************************************************** 00007 * @attention 00008 * 00009 * Copyright (c) 2017 STMicroelectronics. 00010 * All rights reserved. 00011 * 00012 * This software is licensed under terms that can be found in the LICENSE file 00013 * in the root directory of this software component. 00014 * If no LICENSE file comes with this software, it is provided AS-IS. 00015 * 00016 ****************************************************************************** 00017 */ 00018 00019 /* Define to prevent recursive inclusion -------------------------------------*/ 00020 #ifndef STM32L4xx_LL_OPAMP_H 00021 #define STM32L4xx_LL_OPAMP_H 00022 00023 #ifdef __cplusplus 00024 extern "C" { 00025 #endif 00026 00027 /* Includes ------------------------------------------------------------------*/ 00028 #include "stm32l4xx.h" 00029 00030 /** @addtogroup STM32L4xx_LL_Driver 00031 * @{ 00032 */ 00033 00034 #if defined (OPAMP1) || defined (OPAMP2) 00035 00036 /** @defgroup OPAMP_LL OPAMP 00037 * @{ 00038 */ 00039 00040 /* Private types -------------------------------------------------------------*/ 00041 /* Private variables ---------------------------------------------------------*/ 00042 00043 /* Private constants ---------------------------------------------------------*/ 00044 /** @defgroup OPAMP_LL_Private_Constants OPAMP Private Constants 00045 * @{ 00046 */ 00047 00048 /* Internal mask for OPAMP power mode: */ 00049 /* To select into literal LL_OPAMP_POWERMODE_x the relevant bits for: */ 00050 /* - OPAMP power mode into control register */ 00051 /* - OPAMP trimming register offset */ 00052 00053 /* Internal register offset for OPAMP trimming configuration */ 00054 #define OPAMP_POWERMODE_OTR_REGOFFSET 0x00000000U 00055 #define OPAMP_POWERMODE_LPOTR_REGOFFSET 0x00000001U 00056 #define OPAMP_POWERMODE_OTR_REGOFFSET_MASK (OPAMP_POWERMODE_OTR_REGOFFSET | OPAMP_POWERMODE_LPOTR_REGOFFSET) 00057 00058 /* Mask for OPAMP power mode into control register */ 00059 #define OPAMP_POWERMODE_CSR_BIT_MASK (OPAMP_CSR_OPALPM) 00060 00061 /* Internal mask for OPAMP trimming of transistors differential pair NMOS */ 00062 /* or PMOS. */ 00063 /* To select into literal LL_OPAMP_TRIMMING_x the relevant bits for: */ 00064 /* - OPAMP trimming selection of transistors differential pair */ 00065 /* - OPAMP trimming values of transistors differential pair */ 00066 #define OPAMP_TRIMMING_SELECT_MASK (OPAMP1_CSR_CALSEL) 00067 #define OPAMP_TRIMMING_VALUE_MASK (OPAMP_OTR_TRIMOFFSETP | OPAMP_OTR_TRIMOFFSETN) 00068 00069 /** 00070 * @} 00071 */ 00072 00073 00074 /* Private macros ------------------------------------------------------------*/ 00075 /** @defgroup OPAMP_LL_Private_Macros OPAMP Private Macros 00076 * @{ 00077 */ 00078 00079 /** 00080 * @brief Driver macro reserved for internal use: set a pointer to 00081 * a register from a register basis from which an offset 00082 * is applied. 00083 * @param __REG__ Register basis from which the offset is applied. 00084 * @param __REG_OFFSET__ Offset to be applied (unit: number of registers). 00085 * @retval Register address 00086 */ 00087 #define __OPAMP_PTR_REG_OFFSET(__REG__, __REG_OFFSET__) \ 00088 ((uint32_t *)((uint32_t) ((uint32_t)(&(__REG__)) + ((__REG_OFFSET__) << 2U)))) 00089 00090 00091 00092 00093 /** 00094 * @} 00095 */ 00096 00097 00098 /* Exported types ------------------------------------------------------------*/ 00099 #if defined(USE_FULL_LL_DRIVER) 00100 /** @defgroup OPAMP_LL_ES_INIT OPAMP Exported Init structure 00101 * @{ 00102 */ 00103 00104 /** 00105 * @brief Structure definition of some features of OPAMP instance. 00106 */ 00107 typedef struct 00108 { 00109 uint32_t PowerMode; /*!< Set OPAMP power mode. 00110 This parameter can be a value of @ref OPAMP_LL_EC_POWERMODE 00111 00112 This feature can be modified afterwards using unitary function @ref LL_OPAMP_SetPowerMode(). */ 00113 00114 uint32_t FunctionalMode; /*!< Set OPAMP functional mode by setting internal connections: OPAMP operation in standalone, follower, ... 00115 This parameter can be a value of @ref OPAMP_LL_EC_FUNCTIONAL_MODE 00116 @note If OPAMP is configured in mode PGA, the gain can be configured using function @ref LL_OPAMP_SetPGAGain(). 00117 00118 This feature can be modified afterwards using unitary function @ref LL_OPAMP_SetFunctionalMode(). */ 00119 00120 uint32_t InputNonInverting; /*!< Set OPAMP input non-inverting connection. 00121 This parameter can be a value of @ref OPAMP_LL_EC_INPUT_NONINVERTING 00122 00123 This feature can be modified afterwards using unitary function @ref LL_OPAMP_SetInputNonInverting(). */ 00124 00125 uint32_t InputInverting; /*!< Set OPAMP inverting input connection. 00126 This parameter can be a value of @ref OPAMP_LL_EC_INPUT_INVERTING 00127 @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. 00128 00129 This feature can be modified afterwards using unitary function @ref LL_OPAMP_SetInputInverting(). */ 00130 00131 } LL_OPAMP_InitTypeDef; 00132 00133 /** 00134 * @} 00135 */ 00136 #endif /* USE_FULL_LL_DRIVER */ 00137 00138 /* Exported constants --------------------------------------------------------*/ 00139 /** @defgroup OPAMP_LL_Exported_Constants OPAMP Exported Constants 00140 * @{ 00141 */ 00142 00143 /** @defgroup OPAMP_LL_EC_POWERSUPPLY_RANGE OPAMP power supply range 00144 * @{ 00145 */ 00146 #define LL_OPAMP_POWERSUPPLY_RANGE_LOW 0x00000000U /*!< Power supply range low. On STM32L4 serie: Vdda lower than 2.4V. */ 00147 #define LL_OPAMP_POWERSUPPLY_RANGE_HIGH (OPAMP1_CSR_OPARANGE) /*!< Power supply range high. On STM32L4 serie: Vdda higher than 2.4V. */ 00148 /** 00149 * @} 00150 */ 00151 00152 /** @defgroup OPAMP_LL_EC_POWERMODE OPAMP power mode 00153 * @{ 00154 */ 00155 #define LL_OPAMP_POWERMODE_NORMALPOWER (OPAMP_POWERMODE_OTR_REGOFFSET) /*!< OPAMP power mode normal */ 00156 #define LL_OPAMP_POWERMODE_LOWPOWER (OPAMP_POWERMODE_LPOTR_REGOFFSET | OPAMP_CSR_OPALPM) /*!< OPAMP power mode low-power */ 00157 00158 #define LL_OPAMP_POWERMODE_NORMAL LL_OPAMP_POWERMODE_NORMALPOWER /*!< OPAMP power mode normal - Old Naming for compatibility */ 00159 00160 /** 00161 * @} 00162 */ 00163 00164 /** @defgroup OPAMP_LL_EC_MODE OPAMP mode calibration or functional. 00165 * @{ 00166 */ 00167 #define LL_OPAMP_MODE_FUNCTIONAL 0x00000000U /*!< OPAMP functional mode */ 00168 #define LL_OPAMP_MODE_CALIBRATION (OPAMP_CSR_CALON) /*!< OPAMP calibration mode */ 00169 /** 00170 * @} 00171 */ 00172 00173 /** @defgroup OPAMP_LL_EC_FUNCTIONAL_MODE OPAMP functional mode 00174 * @{ 00175 */ 00176 #define LL_OPAMP_MODE_STANDALONE 0x00000000U /*!< OPAMP functional mode, OPAMP operation in standalone */ 00177 #define LL_OPAMP_MODE_FOLLOWER (OPAMP_CSR_OPAMODE_1 | OPAMP_CSR_OPAMODE_0) /*!< OPAMP functional mode, OPAMP operation in follower */ 00178 #define LL_OPAMP_MODE_PGA (OPAMP_CSR_OPAMODE_1) /*!< OPAMP functional mode, OPAMP operation in PGA */ 00179 /** 00180 * @} 00181 */ 00182 00183 /** @defgroup OPAMP_LL_EC_MODE_PGA_GAIN OPAMP PGA gain (relevant when OPAMP is in functional mode PGA) 00184 * @{ 00185 */ 00186 #define LL_OPAMP_PGA_GAIN_2 0x00000000U /*!< OPAMP PGA gain 2 */ 00187 #define LL_OPAMP_PGA_GAIN_4 (OPAMP_CSR_PGGAIN_0) /*!< OPAMP PGA gain 4 */ 00188 #define LL_OPAMP_PGA_GAIN_8 (OPAMP_CSR_PGGAIN_1) /*!< OPAMP PGA gain 8 */ 00189 #define LL_OPAMP_PGA_GAIN_16 (OPAMP_CSR_PGGAIN_1 | OPAMP_CSR_PGGAIN_0 ) /*!< OPAMP PGA gain 16 */ 00190 /** 00191 * @} 00192 */ 00193 00194 /** @defgroup OPAMP_LL_EC_INPUT_NONINVERTING OPAMP input non-inverting 00195 * @{ 00196 */ 00197 #define LL_OPAMP_INPUT_NONINVERT_IO0 0x00000000U /*!< OPAMP non inverting input connected to GPIO pin (pin PA0 for OPAMP1, pin PA6 for OPAMP2) */ 00198 #define LL_OPAMP_INPUT_NONINV_DAC1_CH1 (OPAMP1_CSR_VPSEL) /*!< OPAMP non inverting input connected to DAC1 channel1 output */ 00199 /** 00200 * @} 00201 */ 00202 00203 /** @defgroup OPAMP_LL_EC_INPUT_INVERTING OPAMP input inverting 00204 * @{ 00205 */ 00206 #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). */ 00207 #define LL_OPAMP_INPUT_INVERT_IO1 (OPAMP_CSR_VMSEL_0) /*!< OPAMP inverting input (low leakage input) connected to GPIO pin (available only on package BGA132). 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). */ 00208 #define LL_OPAMP_INPUT_INVERT_CONNECT_NO (OPAMP_CSR_VMSEL_1) /*!< OPAMP inverting input not externally connected (intended for OPAMP in mode follower or PGA without external capacitors for filtering) */ 00209 /** 00210 * @} 00211 */ 00212 00213 /** @defgroup OPAMP_LL_EC_INPUT_LEGACY OPAMP inputs legacy literals name 00214 * @{ 00215 */ 00216 #define LL_OPAMP_NONINVERTINGINPUT_IO0 LL_OPAMP_INPUT_NONINVERT_IO0 00217 #define LL_OPAMP_NONINVERTINGINPUT_DAC_CH LL_OPAMP_INPUT_NONINV_DAC1_CH1 00218 00219 #define LL_OPAMP_INVERTINGINPUT_IO0 LL_OPAMP_INPUT_INVERT_IO0 00220 #define LL_OPAMP_INVERTINGINPUT_IO1 LL_OPAMP_INPUT_INVERT_IO1 00221 #define LL_OPAMP_INVERTINGINPUT_CONNECT_NO LL_OPAMP_INPUT_INVERT_CONNECT_NO 00222 00223 #define LL_OPAMP_INPUT_NONINVERT_DAC1_CH1 LL_OPAMP_INPUT_NONINV_DAC1_CH1 00224 /** 00225 * @} 00226 */ 00227 00228 /** @defgroup OPAMP_LL_EC_TRIMMING_MODE OPAMP trimming mode 00229 * @{ 00230 */ 00231 #define LL_OPAMP_TRIMMING_FACTORY 0x00000000U /*!< OPAMP trimming factors set to factory values */ 00232 #define LL_OPAMP_TRIMMING_USER (OPAMP_CSR_USERTRIM) /*!< OPAMP trimming factors set to user values */ 00233 /** 00234 * @} 00235 */ 00236 00237 /** @defgroup OPAMP_LL_EC_TRIMMING_TRANSISTORS_DIFF_PAIR OPAMP trimming of transistors differential pair NMOS or PMOS 00238 * @{ 00239 */ 00240 #define LL_OPAMP_TRIMMING_NMOS (OPAMP_OTR_TRIMOFFSETN) /*!< OPAMP trimming of transistors differential pair NMOS */ 00241 #define LL_OPAMP_TRIMMING_PMOS (OPAMP_OTR_TRIMOFFSETP | OPAMP1_CSR_CALSEL) /*!< OPAMP trimming of transistors differential pair PMOS */ 00242 /** 00243 * @} 00244 */ 00245 00246 /** @defgroup OPAMP_LL_EC_HW_DELAYS Definitions of OPAMP hardware constraints delays 00247 * @note Only OPAMP peripheral HW delays are defined in OPAMP LL driver driver, 00248 * not timeout values. 00249 * For details on delays values, refer to descriptions in source code 00250 * above each literal definition. 00251 * @{ 00252 */ 00253 00254 /* Delay for OPAMP startup time (transition from state disable to enable). */ 00255 /* Note: OPAMP startup time depends on board application environment: */ 00256 /* impedance connected to OPAMP output. */ 00257 /* The delay below is specified under conditions: */ 00258 /* - OPAMP in mode low power */ 00259 /* - OPAMP in functional mode follower */ 00260 /* - load impedance of 4kOhm (min), 50pF (max) */ 00261 /* Literal set to maximum value (refer to device datasheet, */ 00262 /* parameter "tWAKEUP"). */ 00263 /* Unit: us */ 00264 #define LL_OPAMP_DELAY_STARTUP_US ((uint32_t) 30U) /*!< Delay for OPAMP startup time */ 00265 00266 /** 00267 * @} 00268 */ 00269 00270 /** 00271 * @} 00272 */ 00273 00274 /* Exported macro ------------------------------------------------------------*/ 00275 /** @defgroup OPAMP_LL_Exported_Macros OPAMP Exported Macros 00276 * @{ 00277 */ 00278 /** @defgroup OPAMP_LL_EM_WRITE_READ Common write and read registers macro 00279 * @{ 00280 */ 00281 /** 00282 * @brief Write a value in OPAMP register 00283 * @param __INSTANCE__ OPAMP Instance 00284 * @param __REG__ Register to be written 00285 * @param __VALUE__ Value to be written in the register 00286 * @retval None 00287 */ 00288 #define LL_OPAMP_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG((__INSTANCE__)->__REG__, (__VALUE__)) 00289 00290 /** 00291 * @brief Read a value in OPAMP register 00292 * @param __INSTANCE__ OPAMP Instance 00293 * @param __REG__ Register to be read 00294 * @retval Register value 00295 */ 00296 #define LL_OPAMP_ReadReg(__INSTANCE__, __REG__) READ_REG((__INSTANCE__)->__REG__) 00297 /** 00298 * @} 00299 */ 00300 00301 /** @defgroup OPAMP_LL_EM_HELPER_MACRO OPAMP helper macro 00302 * @{ 00303 */ 00304 00305 /** 00306 * @brief Helper macro to select the OPAMP common instance 00307 * to which is belonging the selected OPAMP instance. 00308 * @note OPAMP common register instance can be used to 00309 * set parameters common to several OPAMP instances. 00310 * Refer to functions having argument "OPAMPxy_COMMON" as parameter. 00311 * @param __OPAMPx__ OPAMP instance 00312 * @retval OPAMP common instance 00313 */ 00314 #if defined(OPAMP1) && defined(OPAMP2) 00315 #define __LL_OPAMP_COMMON_INSTANCE(__OPAMPx__) \ 00316 (OPAMP12_COMMON) 00317 #else 00318 #define __LL_OPAMP_COMMON_INSTANCE(__OPAMPx__) \ 00319 (OPAMP1_COMMON) 00320 #endif 00321 00322 /** 00323 * @brief Helper macro to check if all OPAMP instances sharing the same 00324 * OPAMP common instance are disabled. 00325 * @note This check is required by functions with setting conditioned to 00326 * OPAMP state: 00327 * All OPAMP instances of the OPAMP common group must be disabled. 00328 * Refer to functions having argument "OPAMPxy_COMMON" as parameter. 00329 * @retval 0: All OPAMP instances sharing the same OPAMP common instance 00330 * are disabled. 00331 * 1: At least one OPAMP instance sharing the same OPAMP common instance 00332 * is enabled 00333 */ 00334 #if defined(OPAMP1) && defined(OPAMP2) 00335 #define __LL_OPAMP_IS_ENABLED_ALL_COMMON_INSTANCE() \ 00336 (LL_OPAMP_IsEnabled(OPAMP1) | \ 00337 LL_OPAMP_IsEnabled(OPAMP2) ) 00338 #else 00339 #define __LL_OPAMP_IS_ENABLED_ALL_COMMON_INSTANCE() \ 00340 (LL_OPAMP_IsEnabled(OPAMP1)) 00341 #endif 00342 00343 /** 00344 * @} 00345 */ 00346 00347 /** 00348 * @} 00349 */ 00350 00351 /* Exported functions --------------------------------------------------------*/ 00352 /** @defgroup OPAMP_LL_Exported_Functions OPAMP Exported Functions 00353 * @{ 00354 */ 00355 00356 /** @defgroup OPAMP_LL_EF_Configuration_opamp_common Configuration of OPAMP hierarchical scope: common to several OPAMP instances 00357 * @{ 00358 */ 00359 00360 /** 00361 * @brief Set OPAMP power range. 00362 * @note The OPAMP power range applies to several OPAMP instances 00363 * (if several OPAMP instances available on the selected device). 00364 * @note On this STM32 serie, setting of this feature is conditioned to 00365 * OPAMP state: 00366 * All OPAMP instances of the OPAMP common group must be disabled. 00367 * This check can be done with function @ref LL_OPAMP_IsEnabled() for each 00368 * OPAMP instance or by using helper macro 00369 * @ref __LL_OPAMP_IS_ENABLED_ALL_COMMON_INSTANCE(). 00370 * @rmtoll CSR OPARANGE LL_OPAMP_SetCommonPowerRange 00371 * @param OPAMPxy_COMMON OPAMP common instance 00372 * (can be set directly from CMSIS definition or by using helper macro @ref __LL_OPAMP_COMMON_INSTANCE() ) 00373 * @param PowerRange This parameter can be one of the following values: 00374 * @arg @ref LL_OPAMP_POWERSUPPLY_RANGE_LOW 00375 * @arg @ref LL_OPAMP_POWERSUPPLY_RANGE_HIGH 00376 * @retval None 00377 */ 00378 __STATIC_INLINE void LL_OPAMP_SetCommonPowerRange(OPAMP_Common_TypeDef *OPAMPxy_COMMON, uint32_t PowerRange) 00379 { 00380 /* Prevent unused parameter warning */ 00381 (void)(*OPAMPxy_COMMON); 00382 00383 MODIFY_REG(OPAMP1->CSR, OPAMP1_CSR_OPARANGE, PowerRange); 00384 } 00385 00386 /** 00387 * @brief Get OPAMP power range. 00388 * @note The OPAMP power range applies to several OPAMP instances 00389 * (if several OPAMP instances available on the selected device). 00390 * @rmtoll CSR OPARANGE LL_OPAMP_GetCommonPowerRange 00391 * @param OPAMPxy_COMMON OPAMP common instance 00392 * (can be set directly from CMSIS definition or by using helper macro @ref __LL_OPAMP_COMMON_INSTANCE() ) 00393 * @retval Returned value can be one of the following values: 00394 * @arg @ref LL_OPAMP_POWERSUPPLY_RANGE_LOW 00395 * @arg @ref LL_OPAMP_POWERSUPPLY_RANGE_HIGH 00396 */ 00397 __STATIC_INLINE uint32_t LL_OPAMP_GetCommonPowerRange(OPAMP_Common_TypeDef *OPAMPxy_COMMON) 00398 { 00399 /* Prevent unused parameter warning */ 00400 (void)(*OPAMPxy_COMMON); 00401 00402 return (uint32_t)(READ_BIT(OPAMP1->CSR, OPAMP1_CSR_OPARANGE)); 00403 } 00404 00405 /** 00406 * @} 00407 */ 00408 00409 /** @defgroup OPAMP_LL_EF_CONFIGURATION_OPAMP_INSTANCE Configuration of OPAMP hierarchical scope: OPAMP instance 00410 * @{ 00411 */ 00412 00413 /** 00414 * @brief Set OPAMP power mode. 00415 * @note The OPAMP must be disabled to change this configuration. 00416 * @rmtoll CSR OPALPM LL_OPAMP_SetPowerMode 00417 * @param OPAMPx OPAMP instance 00418 * @param PowerMode This parameter can be one of the following values: 00419 * @arg @ref LL_OPAMP_POWERMODE_NORMALPOWER 00420 * @arg @ref LL_OPAMP_POWERMODE_LOWPOWER 00421 * @retval None 00422 */ 00423 __STATIC_INLINE void LL_OPAMP_SetPowerMode(OPAMP_TypeDef *OPAMPx, uint32_t PowerMode) 00424 { 00425 MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_OPALPM, (PowerMode & OPAMP_POWERMODE_CSR_BIT_MASK)); 00426 } 00427 00428 /** 00429 * @brief Get OPAMP power mode. 00430 * @rmtoll CSR OPALPM LL_OPAMP_GetPowerMode 00431 * @param OPAMPx OPAMP instance 00432 * @retval Returned value can be one of the following values: 00433 * @arg @ref LL_OPAMP_POWERMODE_NORMALPOWER 00434 * @arg @ref LL_OPAMP_POWERMODE_LOWPOWER 00435 */ 00436 __STATIC_INLINE uint32_t LL_OPAMP_GetPowerMode(OPAMP_TypeDef *OPAMPx) 00437 { 00438 uint32_t power_mode = (READ_BIT(OPAMPx->CSR, OPAMP_CSR_OPALPM)); 00439 00440 return (uint32_t)(power_mode | (power_mode >> (OPAMP_CSR_OPALPM_Pos))); 00441 } 00442 00443 /** 00444 * @brief Set OPAMP mode calibration or functional. 00445 * @note OPAMP mode corresponds to functional or calibration mode: 00446 * - functional mode: OPAMP operation in standalone, follower, ... 00447 * Set functional mode using function 00448 * @ref LL_OPAMP_SetFunctionalMode(). 00449 * - calibration mode: offset calibration of the selected 00450 * transistors differential pair NMOS or PMOS. 00451 * @note On this STM32 serie, during calibration, OPAMP functional 00452 * mode must be set to standalone or follower mode 00453 * (in order to open internal connections to resistors 00454 * of PGA mode). 00455 * Refer to function @ref LL_OPAMP_SetFunctionalMode(). 00456 * @rmtoll CSR CALON LL_OPAMP_SetMode 00457 * @param OPAMPx OPAMP instance 00458 * @param Mode This parameter can be one of the following values: 00459 * @arg @ref LL_OPAMP_MODE_FUNCTIONAL 00460 * @arg @ref LL_OPAMP_MODE_CALIBRATION 00461 * @retval None 00462 */ 00463 __STATIC_INLINE void LL_OPAMP_SetMode(OPAMP_TypeDef *OPAMPx, uint32_t Mode) 00464 { 00465 MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_CALON, Mode); 00466 } 00467 00468 /** 00469 * @brief Get OPAMP mode calibration or functional. 00470 * @note OPAMP mode corresponds to functional or calibration mode: 00471 * - functional mode: OPAMP operation in standalone, follower, ... 00472 * Set functional mode using function 00473 * @ref LL_OPAMP_SetFunctionalMode(). 00474 * - calibration mode: offset calibration of the selected 00475 * transistors differential pair NMOS or PMOS. 00476 * @rmtoll CSR CALON LL_OPAMP_GetMode 00477 * @param OPAMPx OPAMP instance 00478 * @retval Returned value can be one of the following values: 00479 * @arg @ref LL_OPAMP_MODE_FUNCTIONAL 00480 * @arg @ref LL_OPAMP_MODE_CALIBRATION 00481 */ 00482 __STATIC_INLINE uint32_t LL_OPAMP_GetMode(OPAMP_TypeDef *OPAMPx) 00483 { 00484 return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_CALON)); 00485 } 00486 00487 /** 00488 * @brief Set OPAMP functional mode by setting internal connections. 00489 * OPAMP operation in standalone, follower, ... 00490 * @note This function reset bit of calibration mode to ensure 00491 * to be in functional mode, in order to have OPAMP parameters 00492 * (inputs selection, ...) set with the corresponding OPAMP mode 00493 * to be effective. 00494 * @rmtoll CSR OPAMODE LL_OPAMP_SetFunctionalMode 00495 * @param OPAMPx OPAMP instance 00496 * @param FunctionalMode This parameter can be one of the following values: 00497 * @arg @ref LL_OPAMP_MODE_STANDALONE 00498 * @arg @ref LL_OPAMP_MODE_FOLLOWER 00499 * @arg @ref LL_OPAMP_MODE_PGA 00500 * @retval None 00501 */ 00502 __STATIC_INLINE void LL_OPAMP_SetFunctionalMode(OPAMP_TypeDef *OPAMPx, uint32_t FunctionalMode) 00503 { 00504 /* Note: Bit OPAMP_CSR_CALON reset to ensure to be in functional mode */ 00505 MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_OPAMODE | OPAMP_CSR_CALON, FunctionalMode); 00506 } 00507 00508 /** 00509 * @brief Get OPAMP functional mode from setting of internal connections. 00510 * OPAMP operation in standalone, follower, ... 00511 * @rmtoll CSR OPAMODE LL_OPAMP_GetFunctionalMode 00512 * @param OPAMPx OPAMP instance 00513 * @retval Returned value can be one of the following values: 00514 * @arg @ref LL_OPAMP_MODE_STANDALONE 00515 * @arg @ref LL_OPAMP_MODE_FOLLOWER 00516 * @arg @ref LL_OPAMP_MODE_PGA 00517 */ 00518 __STATIC_INLINE uint32_t LL_OPAMP_GetFunctionalMode(OPAMP_TypeDef *OPAMPx) 00519 { 00520 return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_OPAMODE)); 00521 } 00522 00523 /** 00524 * @brief Set OPAMP PGA gain. 00525 * @note Preliminarily, OPAMP must be set in mode PGA 00526 * using function @ref LL_OPAMP_SetFunctionalMode(). 00527 * @rmtoll CSR PGGAIN LL_OPAMP_SetPGAGain 00528 * @param OPAMPx OPAMP instance 00529 * @param PGAGain This parameter can be one of the following values: 00530 * @arg @ref LL_OPAMP_PGA_GAIN_2 00531 * @arg @ref LL_OPAMP_PGA_GAIN_4 00532 * @arg @ref LL_OPAMP_PGA_GAIN_8 00533 * @arg @ref LL_OPAMP_PGA_GAIN_16 00534 * @retval None 00535 */ 00536 __STATIC_INLINE void LL_OPAMP_SetPGAGain(OPAMP_TypeDef *OPAMPx, uint32_t PGAGain) 00537 { 00538 MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_PGGAIN, PGAGain); 00539 } 00540 00541 /** 00542 * @brief Get OPAMP PGA gain. 00543 * @note Preliminarily, OPAMP must be set in mode PGA 00544 * using function @ref LL_OPAMP_SetFunctionalMode(). 00545 * @rmtoll CSR PGGAIN LL_OPAMP_GetPGAGain 00546 * @param OPAMPx OPAMP instance 00547 * @retval Returned value can be one of the following values: 00548 * @arg @ref LL_OPAMP_PGA_GAIN_2 00549 * @arg @ref LL_OPAMP_PGA_GAIN_4 00550 * @arg @ref LL_OPAMP_PGA_GAIN_8 00551 * @arg @ref LL_OPAMP_PGA_GAIN_16 00552 */ 00553 __STATIC_INLINE uint32_t LL_OPAMP_GetPGAGain(OPAMP_TypeDef *OPAMPx) 00554 { 00555 return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_PGGAIN)); 00556 } 00557 00558 /** 00559 * @} 00560 */ 00561 00562 /** @defgroup OPAMP_LL_EF_CONFIGURATION_INPUTS Configuration of OPAMP inputs 00563 * @{ 00564 */ 00565 00566 /** 00567 * @brief Set OPAMP non-inverting input connection. 00568 * @rmtoll CSR VPSEL LL_OPAMP_SetInputNonInverting 00569 * @param OPAMPx OPAMP instance 00570 * @param InputNonInverting This parameter can be one of the following values: 00571 * @arg @ref LL_OPAMP_INPUT_NONINVERT_IO0 00572 * @arg @ref LL_OPAMP_INPUT_NONINV_DAC1_CH1 00573 * @retval None 00574 */ 00575 __STATIC_INLINE void LL_OPAMP_SetInputNonInverting(OPAMP_TypeDef *OPAMPx, uint32_t InputNonInverting) 00576 { 00577 MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_VPSEL, InputNonInverting); 00578 } 00579 00580 /** 00581 * @brief Get OPAMP non-inverting input connection. 00582 * @rmtoll CSR VPSEL LL_OPAMP_GetInputNonInverting 00583 * @param OPAMPx OPAMP instance 00584 * @retval Returned value can be one of the following values: 00585 * @arg @ref LL_OPAMP_INPUT_NONINVERT_IO0 00586 * @arg @ref LL_OPAMP_INPUT_NONINV_DAC1_CH1 00587 */ 00588 __STATIC_INLINE uint32_t LL_OPAMP_GetInputNonInverting(OPAMP_TypeDef *OPAMPx) 00589 { 00590 return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_VPSEL)); 00591 } 00592 00593 /** 00594 * @brief Set OPAMP inverting input connection. 00595 * @note OPAMP inverting input is used with OPAMP in mode standalone 00596 * or PGA with external capacitors for filtering circuit. 00597 * Otherwise (OPAMP in mode follower), OPAMP inverting input 00598 * is not used (not connected to GPIO pin). 00599 * @rmtoll CSR VMSEL LL_OPAMP_SetInputInverting 00600 * @param OPAMPx OPAMP instance 00601 * @param InputInverting This parameter can be one of the following values: 00602 * @arg @ref LL_OPAMP_INPUT_INVERT_IO0 00603 * @arg @ref LL_OPAMP_INPUT_INVERT_IO1 00604 * @arg @ref LL_OPAMP_INPUT_INVERT_CONNECT_NO 00605 * @retval None 00606 */ 00607 __STATIC_INLINE void LL_OPAMP_SetInputInverting(OPAMP_TypeDef *OPAMPx, uint32_t InputInverting) 00608 { 00609 MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_VMSEL, InputInverting); 00610 } 00611 00612 /** 00613 * @brief Get OPAMP inverting input connection. 00614 * @rmtoll CSR VMSEL LL_OPAMP_GetInputInverting 00615 * @param OPAMPx OPAMP instance 00616 * @retval Returned value can be one of the following values: 00617 * @arg @ref LL_OPAMP_INPUT_INVERT_IO0 00618 * @arg @ref LL_OPAMP_INPUT_INVERT_IO1 00619 * @arg @ref LL_OPAMP_INPUT_INVERT_CONNECT_NO 00620 */ 00621 __STATIC_INLINE uint32_t LL_OPAMP_GetInputInverting(OPAMP_TypeDef *OPAMPx) 00622 { 00623 return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_VMSEL)); 00624 } 00625 00626 /** 00627 * @} 00628 */ 00629 00630 /** @defgroup OPAMP_LL_EF_Configuration_Legacy_Functions Configuration of OPAMP, legacy functions name 00631 * @{ 00632 */ 00633 /* Old functions name kept for legacy purpose, to be replaced by the */ 00634 /* current functions name. */ 00635 __STATIC_INLINE void LL_OPAMP_SetNonInvertingInput(OPAMP_TypeDef *OPAMPx, uint32_t NonInvertingInput) 00636 { 00637 LL_OPAMP_SetInputNonInverting(OPAMPx, NonInvertingInput); 00638 } 00639 00640 __STATIC_INLINE void LL_OPAMP_SetInvertingInput(OPAMP_TypeDef *OPAMPx, uint32_t InvertingInput) 00641 { 00642 LL_OPAMP_SetInputInverting(OPAMPx, InvertingInput); 00643 } 00644 00645 /** 00646 * @} 00647 */ 00648 00649 /** @defgroup OPAMP_LL_EF_OPAMP_TRIMMING Configuration and operation of OPAMP trimming 00650 * @{ 00651 */ 00652 00653 /** 00654 * @brief Set OPAMP trimming mode. 00655 * @rmtoll CSR USERTRIM LL_OPAMP_SetTrimmingMode 00656 * @param OPAMPx OPAMP instance 00657 * @param TrimmingMode This parameter can be one of the following values: 00658 * @arg @ref LL_OPAMP_TRIMMING_FACTORY 00659 * @arg @ref LL_OPAMP_TRIMMING_USER 00660 * @retval None 00661 */ 00662 __STATIC_INLINE void LL_OPAMP_SetTrimmingMode(OPAMP_TypeDef *OPAMPx, uint32_t TrimmingMode) 00663 { 00664 MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_USERTRIM, TrimmingMode); 00665 } 00666 00667 /** 00668 * @brief Get OPAMP trimming mode. 00669 * @rmtoll CSR USERTRIM LL_OPAMP_GetTrimmingMode 00670 * @param OPAMPx OPAMP instance 00671 * @retval Returned value can be one of the following values: 00672 * @arg @ref LL_OPAMP_TRIMMING_FACTORY 00673 * @arg @ref LL_OPAMP_TRIMMING_USER 00674 */ 00675 __STATIC_INLINE uint32_t LL_OPAMP_GetTrimmingMode(OPAMP_TypeDef *OPAMPx) 00676 { 00677 return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_USERTRIM)); 00678 } 00679 00680 /** 00681 * @brief Set OPAMP offset to calibrate the selected transistors 00682 * differential pair NMOS or PMOS. 00683 * @note Preliminarily, OPAMP must be set in mode calibration 00684 * using function @ref LL_OPAMP_SetMode(). 00685 * @rmtoll CSR CALSEL LL_OPAMP_SetCalibrationSelection 00686 * @param OPAMPx OPAMP instance 00687 * @param TransistorsDiffPair This parameter can be one of the following values: 00688 * @arg @ref LL_OPAMP_TRIMMING_NMOS 00689 * @arg @ref LL_OPAMP_TRIMMING_PMOS 00690 * @retval None 00691 */ 00692 __STATIC_INLINE void LL_OPAMP_SetCalibrationSelection(OPAMP_TypeDef *OPAMPx, uint32_t TransistorsDiffPair) 00693 { 00694 /* Parameter used with mask "OPAMP_TRIMMING_SELECT_MASK" because */ 00695 /* containing other bits reserved for other purpose. */ 00696 MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_CALSEL, (TransistorsDiffPair & OPAMP_TRIMMING_SELECT_MASK)); 00697 } 00698 00699 /** 00700 * @brief Get OPAMP offset to calibrate the selected transistors 00701 * differential pair NMOS or PMOS. 00702 * @note Preliminarily, OPAMP must be set in mode calibration 00703 * using function @ref LL_OPAMP_SetMode(). 00704 * @rmtoll CSR CALSEL LL_OPAMP_GetCalibrationSelection 00705 * @param OPAMPx OPAMP instance 00706 * @retval Returned value can be one of the following values: 00707 * @arg @ref LL_OPAMP_TRIMMING_NMOS 00708 * @arg @ref LL_OPAMP_TRIMMING_PMOS 00709 */ 00710 __STATIC_INLINE uint32_t LL_OPAMP_GetCalibrationSelection(OPAMP_TypeDef *OPAMPx) 00711 { 00712 uint32_t CalibrationSelection = (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_CALSEL)); 00713 00714 return (CalibrationSelection | 00715 (((CalibrationSelection & OPAMP_CSR_CALSEL) == 0UL) ? OPAMP_OTR_TRIMOFFSETN : OPAMP_OTR_TRIMOFFSETP)); 00716 } 00717 00718 /** 00719 * @brief Get OPAMP calibration result of toggling output. 00720 * @note This functions returns: 00721 * 0 if OPAMP calibration output is reset 00722 * 1 if OPAMP calibration output is set 00723 * @rmtoll CSR CALOUT LL_OPAMP_IsCalibrationOutputSet 00724 * @param OPAMPx OPAMP instance 00725 * @retval State of bit (1 or 0). 00726 */ 00727 __STATIC_INLINE uint32_t LL_OPAMP_IsCalibrationOutputSet(OPAMP_TypeDef *OPAMPx) 00728 { 00729 return ((READ_BIT(OPAMPx->CSR, OPAMP_CSR_CALOUT) == OPAMP_CSR_CALOUT) ? 1UL : 0UL); 00730 } 00731 00732 /** 00733 * @brief Set OPAMP trimming factor for the selected transistors 00734 * differential pair NMOS or PMOS, corresponding to the selected 00735 * power mode. 00736 * @rmtoll OTR TRIMOFFSETN LL_OPAMP_SetTrimmingValue\n 00737 * OTR TRIMOFFSETP LL_OPAMP_SetTrimmingValue\n 00738 * LPOTR TRIMLPOFFSETN LL_OPAMP_SetTrimmingValue\n 00739 * LPOTR TRIMLPOFFSETP LL_OPAMP_SetTrimmingValue 00740 * @param OPAMPx OPAMP instance 00741 * @param PowerMode This parameter can be one of the following values: 00742 * @arg @ref LL_OPAMP_POWERMODE_NORMALPOWER 00743 * @arg @ref LL_OPAMP_POWERMODE_LOWPOWER 00744 * @param TransistorsDiffPair This parameter can be one of the following values: 00745 * @arg @ref LL_OPAMP_TRIMMING_NMOS 00746 * @arg @ref LL_OPAMP_TRIMMING_PMOS 00747 * @param TrimmingValue 0x00...0x1F 00748 * @retval None 00749 */ 00750 __STATIC_INLINE void LL_OPAMP_SetTrimmingValue(OPAMP_TypeDef* OPAMPx, uint32_t PowerMode, uint32_t TransistorsDiffPair, uint32_t TrimmingValue) 00751 { 00752 __IO uint32_t *preg = __OPAMP_PTR_REG_OFFSET(OPAMPx->OTR, (PowerMode & OPAMP_POWERMODE_OTR_REGOFFSET_MASK)); 00753 00754 /* Set bits with position in register depending on parameter */ 00755 /* "TransistorsDiffPair". */ 00756 /* Parameter used with mask "OPAMP_TRIMMING_VALUE_MASK" because */ 00757 /* containing other bits reserved for other purpose. */ 00758 MODIFY_REG(*preg, 00759 (TransistorsDiffPair & OPAMP_TRIMMING_VALUE_MASK), 00760 TrimmingValue << ((TransistorsDiffPair == LL_OPAMP_TRIMMING_NMOS) ? OPAMP_OTR_TRIMOFFSETN_Pos : OPAMP_OTR_TRIMOFFSETP_Pos)); 00761 } 00762 00763 /** 00764 * @brief Get OPAMP trimming factor for the selected transistors 00765 * differential pair NMOS or PMOS, corresponding to the selected 00766 * power mode. 00767 * @rmtoll OTR TRIMOFFSETN LL_OPAMP_GetTrimmingValue\n 00768 * OTR TRIMOFFSETP LL_OPAMP_GetTrimmingValue\n 00769 * LPOTR TRIMLPOFFSETN LL_OPAMP_GetTrimmingValue\n 00770 * LPOTR TRIMLPOFFSETP LL_OPAMP_GetTrimmingValue 00771 * @param OPAMPx OPAMP instance 00772 * @param PowerMode This parameter can be one of the following values: 00773 * @arg @ref LL_OPAMP_POWERMODE_NORMALPOWER 00774 * @arg @ref LL_OPAMP_POWERMODE_LOWPOWER 00775 * @param TransistorsDiffPair This parameter can be one of the following values: 00776 * @arg @ref LL_OPAMP_TRIMMING_NMOS 00777 * @arg @ref LL_OPAMP_TRIMMING_PMOS 00778 * @retval 0x0...0x1F 00779 */ 00780 __STATIC_INLINE uint32_t LL_OPAMP_GetTrimmingValue(OPAMP_TypeDef* OPAMPx, uint32_t PowerMode, uint32_t TransistorsDiffPair) 00781 { 00782 const __IO uint32_t *preg = __OPAMP_PTR_REG_OFFSET(OPAMPx->OTR, (PowerMode & OPAMP_POWERMODE_OTR_REGOFFSET_MASK)); 00783 00784 /* Retrieve bits with position in register depending on parameter */ 00785 /* "TransistorsDiffPair". */ 00786 /* Parameter used with mask "OPAMP_TRIMMING_VALUE_MASK" because */ 00787 /* containing other bits reserved for other purpose. */ 00788 return (uint32_t)(READ_BIT(*preg, (TransistorsDiffPair & OPAMP_TRIMMING_VALUE_MASK)) 00789 >> ((TransistorsDiffPair == LL_OPAMP_TRIMMING_NMOS) ? OPAMP_OTR_TRIMOFFSETN_Pos : OPAMP_OTR_TRIMOFFSETP_Pos)); 00790 } 00791 00792 /** 00793 * @} 00794 */ 00795 00796 /** @defgroup OPAMP_LL_EF_OPERATION Operation on OPAMP instance 00797 * @{ 00798 */ 00799 /** 00800 * @brief Enable OPAMP instance. 00801 * @note After enable from off state, OPAMP requires a delay 00802 * to fullfill wake up time specification. 00803 * Refer to device datasheet, parameter "tWAKEUP". 00804 * @rmtoll CSR OPAMPXEN LL_OPAMP_Enable 00805 * @param OPAMPx OPAMP instance 00806 * @retval None 00807 */ 00808 __STATIC_INLINE void LL_OPAMP_Enable(OPAMP_TypeDef *OPAMPx) 00809 { 00810 SET_BIT(OPAMPx->CSR, OPAMP_CSR_OPAMPxEN); 00811 } 00812 00813 /** 00814 * @brief Disable OPAMP instance. 00815 * @rmtoll CSR OPAMPXEN LL_OPAMP_Disable 00816 * @param OPAMPx OPAMP instance 00817 * @retval None 00818 */ 00819 __STATIC_INLINE void LL_OPAMP_Disable(OPAMP_TypeDef *OPAMPx) 00820 { 00821 CLEAR_BIT(OPAMPx->CSR, OPAMP_CSR_OPAMPxEN); 00822 } 00823 00824 /** 00825 * @brief Get OPAMP instance enable state 00826 * (0: OPAMP is disabled, 1: OPAMP is enabled) 00827 * @rmtoll CSR OPAMPXEN LL_OPAMP_IsEnabled 00828 * @param OPAMPx OPAMP instance 00829 * @retval State of bit (1 or 0). 00830 */ 00831 __STATIC_INLINE uint32_t LL_OPAMP_IsEnabled(OPAMP_TypeDef *OPAMPx) 00832 { 00833 return ((READ_BIT(OPAMPx->CSR, OPAMP_CSR_OPAMPxEN) == (OPAMP_CSR_OPAMPxEN)) ? 1UL : 0UL); 00834 } 00835 00836 /** 00837 * @} 00838 */ 00839 00840 #if defined(USE_FULL_LL_DRIVER) 00841 /** @defgroup OPAMP_LL_EF_Init Initialization and de-initialization functions 00842 * @{ 00843 */ 00844 00845 ErrorStatus LL_OPAMP_DeInit(OPAMP_TypeDef *OPAMPx); 00846 ErrorStatus LL_OPAMP_Init(OPAMP_TypeDef *OPAMPx, LL_OPAMP_InitTypeDef *OPAMP_InitStruct); 00847 void LL_OPAMP_StructInit(LL_OPAMP_InitTypeDef *OPAMP_InitStruct); 00848 00849 /** 00850 * @} 00851 */ 00852 #endif /* USE_FULL_LL_DRIVER */ 00853 00854 /** 00855 * @} 00856 */ 00857 00858 /** 00859 * @} 00860 */ 00861 00862 #endif /* OPAMP1 || OPAMP2 */ 00863 00864 /** 00865 * @} 00866 */ 00867 00868 #ifdef __cplusplus 00869 } 00870 #endif 00871 00872 #endif /* STM32L4xx_LL_OPAMP_H */