mbed library sources. Supersedes mbed-src.

Dependents:   Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more

Committer:
AnnaBridge
Date:
Wed Feb 20 22:31:08 2019 +0000
Revision:
189:f392fc9709a3
Parent:
184:08ed48f1de7f
mbed library release version 165

Who changed what in which revision?

UserRevisionLine numberNew contents of line
<> 149:156823d33999 1 /**
<> 149:156823d33999 2 ******************************************************************************
<> 149:156823d33999 3 * @file stm32l1xx_hal_opamp.c
<> 149:156823d33999 4 * @author MCD Application Team
<> 149:156823d33999 5 * @brief OPAMP HAL module driver.
<> 149:156823d33999 6 * This file provides firmware functions to manage the following
<> 149:156823d33999 7 * functionalities of the operational amplifier(s)(OPAMP1, OPAMP2 etc)
<> 149:156823d33999 8 * peripheral:
<> 149:156823d33999 9 * + OPAMP configuration
<> 149:156823d33999 10 * + OPAMP calibration
<> 149:156823d33999 11 * Thanks to
<> 149:156823d33999 12 * + Initialization and de-initialization functions
<> 149:156823d33999 13 * + IO operation functions
<> 149:156823d33999 14 * + Peripheral Control functions
<> 149:156823d33999 15 * + Peripheral State functions
<> 149:156823d33999 16 *
<> 149:156823d33999 17 @verbatim
<> 149:156823d33999 18 ================================================================================
<> 149:156823d33999 19 ##### OPAMP Peripheral Features #####
<> 149:156823d33999 20 ================================================================================
<> 149:156823d33999 21 [..] The device integrates up to 3 operational amplifiers OPAMP1, OPAMP2,
<> 149:156823d33999 22 OPAMP3 (OPAMP3 availability depends on device category)
<> 149:156823d33999 23
<> 149:156823d33999 24 (#) The OPAMP(s) provides several exclusive running modes.
<> 149:156823d33999 25 (++) Standalone mode
<> 149:156823d33999 26 (++) Follower mode
<> 149:156823d33999 27
<> 149:156823d33999 28 (#) All OPAMP (same for all OPAMPs) can operate in
<> 149:156823d33999 29 (++) Either Low range (VDDA < 2.4V) power supply
<> 149:156823d33999 30 (++) Or High range (VDDA > 2.4V) power supply
<> 149:156823d33999 31
<> 149:156823d33999 32 (#) Each OPAMP(s) can be configured in normal and low power mode.
<> 149:156823d33999 33
<> 149:156823d33999 34 (#) The OPAMP(s) provide(s) calibration capabilities.
<> 149:156823d33999 35 (++) Calibration aims at correcting some offset for running mode.
<> 149:156823d33999 36 (++) The OPAMP uses either factory calibration settings OR user defined
<> 149:156823d33999 37 calibration (trimming) settings (i.e. trimming mode).
<> 149:156823d33999 38 (++) The user defined settings can be figured out using self calibration
<> 149:156823d33999 39 handled by HAL_OPAMP_SelfCalibrate, HAL_OPAMPEx_SelfCalibrateAll
<> 149:156823d33999 40 (++) HAL_OPAMP_SelfCalibrate:
<> 149:156823d33999 41 (+++) Runs automatically the calibration in 2 steps: for transistors
<> 149:156823d33999 42 differential pair high (PMOS) or low (NMOS)
<> 149:156823d33999 43 (+++) Enables the user trimming mode
<> 149:156823d33999 44 (+++) Updates the init structure with trimming values with fresh calibration
<> 149:156823d33999 45 results.
<> 149:156823d33999 46 The user may store the calibration results for larger
<> 149:156823d33999 47 (ex monitoring the trimming as a function of temperature
<> 149:156823d33999 48 for instance)
<> 149:156823d33999 49 (+++) For devices having several OPAMPs, HAL_OPAMPEx_SelfCalibrateAll
<> 149:156823d33999 50 runs calibration of all OPAMPs in parallel to save search time.
<> 149:156823d33999 51
<> 149:156823d33999 52 (#) Running mode: Standalone mode
<> 149:156823d33999 53 (++) Gain is set externally (gain depends on external loads).
<> 149:156823d33999 54 (++) Follower mode also possible externally by connecting the inverting input to
<> 149:156823d33999 55 the output.
<> 149:156823d33999 56
<> 149:156823d33999 57 (#) Running mode: Follower mode
<> 149:156823d33999 58 (++) No Inverting Input is connected.
<> 149:156823d33999 59 (++) The OPAMP(s) output(s) are internally connected to inverting input.
<> 149:156823d33999 60
<> 149:156823d33999 61 ##### How to use this driver #####
<> 149:156823d33999 62 ================================================================================
<> 149:156823d33999 63 [..]
<> 149:156823d33999 64
<> 149:156823d33999 65 *** power supply range ***
<> 149:156823d33999 66 ============================================
<> 149:156823d33999 67 [..]
<> 149:156823d33999 68 To run in low power mode:
<> 149:156823d33999 69
<> 149:156823d33999 70 (#) Configure the opamp using HAL_OPAMP_Init() function:
<> 149:156823d33999 71 (++) Select OPAMP_POWERSUPPLY_LOW (VDDA lower than 2.4V)
<> 149:156823d33999 72 (++) Otherwise select OPAMP_POWERSUPPLY_HIGH (VDDA higher than 2.4V)
<> 149:156823d33999 73
<> 149:156823d33999 74 *** low / normal power mode ***
<> 149:156823d33999 75 ============================================
<> 149:156823d33999 76 [..]
<> 149:156823d33999 77 To run in low power mode:
<> 149:156823d33999 78
<> 149:156823d33999 79 (#) Configure the opamp using HAL_OPAMP_Init() function:
<> 149:156823d33999 80 (++) Select OPAMP_POWERMODE_LOWPOWER
<> 149:156823d33999 81 (++) Otherwise select OPAMP_POWERMODE_NORMAL
<> 149:156823d33999 82
<> 149:156823d33999 83 *** Calibration ***
<> 149:156823d33999 84 ============================================
<> 149:156823d33999 85 [..]
<> 149:156823d33999 86 To run the opamp calibration self calibration:
<> 149:156823d33999 87
<> 149:156823d33999 88 (#) Start calibration using HAL_OPAMP_SelfCalibrate.
<> 149:156823d33999 89 Store the calibration results.
<> 149:156823d33999 90
<> 149:156823d33999 91 *** Running mode ***
<> 149:156823d33999 92 ============================================
<> 149:156823d33999 93 [..]
<> 149:156823d33999 94
<> 149:156823d33999 95 To use the opamp, perform the following steps:
<> 149:156823d33999 96
<> 149:156823d33999 97 (#) Fill in the HAL_OPAMP_MspInit() to
<> 149:156823d33999 98 (++) Enable the OPAMP Peripheral clock using macro "__HAL_RCC_OPAMP_CLK_ENABLE()"
<> 149:156823d33999 99 (++) Configure the opamp input AND output in analog mode using
<> 149:156823d33999 100 HAL_GPIO_Init() to map the opamp output to the GPIO pin.
<> 149:156823d33999 101
<> 149:156823d33999 102 (#) Configure the opamp using HAL_OPAMP_Init() function:
<> 149:156823d33999 103 (++) Select the mode
<> 149:156823d33999 104 (++) Select the inverting input
<> 149:156823d33999 105 (++) Select the non-inverting input
<> 149:156823d33999 106 (++) Select either factory or user defined trimming mode.
<> 149:156823d33999 107 (++) If the user defined trimming mode is enabled, select PMOS & NMOS trimming values
<> 149:156823d33999 108 (typ. settings returned by HAL_OPAMP_SelfCalibrate function).
<> 149:156823d33999 109
<> 149:156823d33999 110 (#) Enable the opamp using HAL_OPAMP_Start() function.
<> 149:156823d33999 111
<> 149:156823d33999 112 (#) Disable the opamp using HAL_OPAMP_Stop() function.
<> 149:156823d33999 113
<> 149:156823d33999 114 (#) Lock the opamp in running mode using HAL_OPAMP_Lock() function.
<> 149:156823d33999 115 Caution: On STM32L1, HAL OPAMP lock is software lock only (not
<> 149:156823d33999 116 hardware lock as on some other STM32 devices)
<> 149:156823d33999 117
<> 149:156823d33999 118 (#) If needed, unlock the opamp using HAL_OPAMPEx_Unlock() function.
<> 149:156823d33999 119
<> 149:156823d33999 120 *** Running mode: change of configuration while OPAMP ON ***
<> 149:156823d33999 121 ============================================
<> 149:156823d33999 122 [..]
<> 149:156823d33999 123 To Re-configure OPAMP when OPAMP is ON (change on the fly)
<> 149:156823d33999 124 (#) If needed, Fill in the HAL_OPAMP_MspInit()
<> 149:156823d33999 125 (++) This is the case for instance if you wish to use new OPAMP I/O
<> 149:156823d33999 126
<> 149:156823d33999 127 (#) Configure the opamp using HAL_OPAMP_Init() function:
<> 149:156823d33999 128 (++) As in configure case, selects first the parameters you wish to modify.
<> 149:156823d33999 129
<> 149:156823d33999 130 (#) Change from low power mode to normal power mode (& vice versa) requires
<> 149:156823d33999 131 first HAL_OPAMP_DeInit() (force OPAMP OFF) and then HAL_OPAMP_Init().
<> 149:156823d33999 132 In other words, of OPAMP is ON, HAL_OPAMP_Init can NOT change power mode
<> 149:156823d33999 133 alone.
<> 149:156823d33999 134
<> 149:156823d33999 135 @endverbatim
<> 149:156823d33999 136 ******************************************************************************
<> 149:156823d33999 137 * @attention
<> 149:156823d33999 138 *
AnnaBridge 184:08ed48f1de7f 139 * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
<> 149:156823d33999 140 *
<> 149:156823d33999 141 * Redistribution and use in source and binary forms, with or without modification,
<> 149:156823d33999 142 * are permitted provided that the following conditions are met:
<> 149:156823d33999 143 * 1. Redistributions of source code must retain the above copyright notice,
<> 149:156823d33999 144 * this list of conditions and the following disclaimer.
<> 149:156823d33999 145 * 2. Redistributions in binary form must reproduce the above copyright notice,
<> 149:156823d33999 146 * this list of conditions and the following disclaimer in the documentation
<> 149:156823d33999 147 * and/or other materials provided with the distribution.
<> 149:156823d33999 148 * 3. Neither the name of STMicroelectronics nor the names of its contributors
<> 149:156823d33999 149 * may be used to endorse or promote products derived from this software
<> 149:156823d33999 150 * without specific prior written permission.
<> 149:156823d33999 151 *
<> 149:156823d33999 152 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
<> 149:156823d33999 153 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
<> 149:156823d33999 154 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
<> 149:156823d33999 155 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
<> 149:156823d33999 156 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
<> 149:156823d33999 157 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
<> 149:156823d33999 158 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
<> 149:156823d33999 159 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
<> 149:156823d33999 160 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
<> 149:156823d33999 161 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<> 149:156823d33999 162 *
<> 149:156823d33999 163 ******************************************************************************
<> 149:156823d33999 164 */
<> 149:156823d33999 165
<> 149:156823d33999 166 /*
<> 149:156823d33999 167 Additionnal remark:
<> 149:156823d33999 168 The OPAMPs inverting input can be selected among the list shown by table below.
<> 149:156823d33999 169 The OPAMPs non inverting input can be selected among the list shown by table below.
<> 149:156823d33999 170
<> 149:156823d33999 171 Table 1. OPAMPs inverting/non-inverting inputs for STM32L1 devices:
<> 149:156823d33999 172 +--------------------------------------------------------------------------+
<> 149:156823d33999 173 | | HAL param | OPAMP1 | OPAMP2 | OPAMP3(4) |
<> 149:156823d33999 174 | | name | | | |
<> 149:156823d33999 175 |----------------|------------|--------------|--------------|--------------|
<> 149:156823d33999 176 | Inverting | VM0 | PA2 | PA7 | PC2 |
<> 149:156823d33999 177 | input (1) | VM1 | VINM pin (2) | VINM pin (2) | VINM pin (2) |
<> 149:156823d33999 178 |----------------|------------|--------------|--------------|--------------|
<> 149:156823d33999 179 | Non Inverting | VP0 | PA1 | PA6 | PC1 |
<> 149:156823d33999 180 | input | DAC_CH1 (3)| DAC_CH1 | DAC_CH1 | --- |
<> 149:156823d33999 181 | | DAC_CH2 (3)| --- | DAC_CH2 | DAC_CH2 |
<> 149:156823d33999 182 +--------------------------------------------------------------------------+
<> 149:156823d33999 183 (1): NA in follower mode.
<> 149:156823d33999 184 (2): OPAMP input OPAMPx_VINM are dedicated OPAMP pins, their availability
<> 149:156823d33999 185 depends on device package.
<> 149:156823d33999 186 (3): DAC channels 1 and 2 are connected internally to OPAMP. Nevertheless,
<> 149:156823d33999 187 I/O pins connected to DAC can still be used as DAC output (pins PA4
<> 149:156823d33999 188 and PA5).
<> 149:156823d33999 189 (4): OPAMP3 availability depends on device category.
<> 149:156823d33999 190
<> 149:156823d33999 191 Table 2. OPAMPs outputs for STM32L1 devices:
<> 149:156823d33999 192 +--------------------------------------------------------+
<> 149:156823d33999 193 | | OPAMP1 | OPAMP2 | OPAMP3(4) |
<> 149:156823d33999 194 |-----------------|------------|------------|------------|
<> 149:156823d33999 195 | Output | PA3 | PB0 | PC3 |
<> 149:156823d33999 196 +--------------------------------------------------------+
<> 149:156823d33999 197 (4) : OPAMP3 availability depends on device category
<> 149:156823d33999 198 */
<> 149:156823d33999 199
<> 149:156823d33999 200 /* Includes ------------------------------------------------------------------*/
<> 149:156823d33999 201 #include "stm32l1xx_hal.h"
<> 149:156823d33999 202
<> 149:156823d33999 203 /** @addtogroup STM32L1xx_HAL_Driver
<> 149:156823d33999 204 * @{
<> 149:156823d33999 205 */
<> 149:156823d33999 206
<> 149:156823d33999 207 /** @defgroup OPAMP OPAMP
<> 149:156823d33999 208 * @brief OPAMP module driver
<> 149:156823d33999 209 * @{
<> 149:156823d33999 210 */
<> 149:156823d33999 211
<> 149:156823d33999 212 #ifdef HAL_OPAMP_MODULE_ENABLED
<> 149:156823d33999 213
<> 149:156823d33999 214 #if defined (STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined (STM32L151xE) || defined (STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX) || defined (STM32L162xC) || defined (STM32L152xC) || defined (STM32L151xC)
<> 149:156823d33999 215
<> 149:156823d33999 216 /* Private typedef -----------------------------------------------------------*/
<> 149:156823d33999 217 /* Private define ------------------------------------------------------------*/
<> 149:156823d33999 218 /* Private macro -------------------------------------------------------------*/
<> 149:156823d33999 219 /* Private variables ---------------------------------------------------------*/
<> 149:156823d33999 220 /* Private constants ---------------------------------------------------------*/
<> 149:156823d33999 221 /* Private function prototypes -----------------------------------------------*/
<> 149:156823d33999 222 /* Private functions ---------------------------------------------------------*/
<> 149:156823d33999 223 /* Exported functions --------------------------------------------------------*/
<> 149:156823d33999 224
<> 149:156823d33999 225 /** @defgroup OPAMP_Exported_Functions OPAMP Exported Functions
<> 149:156823d33999 226 * @{
<> 149:156823d33999 227 */
<> 149:156823d33999 228
<> 149:156823d33999 229 /** @defgroup OPAMP_Exported_Functions_Group1 Initialization and de-initialization functions
<> 149:156823d33999 230 * @brief Initialization and Configuration functions
<> 149:156823d33999 231 *
<> 149:156823d33999 232 @verbatim
<> 149:156823d33999 233 ==============================================================================
<> 149:156823d33999 234 ##### Initialization and de-initialization functions #####
<> 149:156823d33999 235 ==============================================================================
<> 149:156823d33999 236 [..] This section provides functions allowing to:
<> 149:156823d33999 237
<> 149:156823d33999 238 @endverbatim
<> 149:156823d33999 239 * @{
<> 149:156823d33999 240 */
<> 149:156823d33999 241
<> 149:156823d33999 242 /**
<> 149:156823d33999 243 * @brief Initializes the OPAMP according to the specified
<> 149:156823d33999 244 * parameters in the OPAMP_InitTypeDef and create the associated handle.
<> 149:156823d33999 245 * @note If the selected opamp is locked, initialization can't be performed.
<> 149:156823d33999 246 * To unlock the configuration, perform a system reset.
<> 149:156823d33999 247 * @param hopamp: OPAMP handle
<> 149:156823d33999 248 * @retval HAL status
<> 149:156823d33999 249 */
<> 149:156823d33999 250 HAL_StatusTypeDef HAL_OPAMP_Init(OPAMP_HandleTypeDef* hopamp)
<> 149:156823d33999 251 {
<> 149:156823d33999 252 HAL_StatusTypeDef status = HAL_OK;
<> 149:156823d33999 253 uint32_t tmp_csr = 0; /* Temporary variable to update register CSR, except bits ANAWSSELx, S7SEL2, OPA_RANGE, OPAxCALOUT */
<> 149:156823d33999 254
<> 149:156823d33999 255 /* Check the OPAMP handle allocation and lock status */
<> 149:156823d33999 256 /* Init not allowed if calibration is ongoing */
<> 149:156823d33999 257 if((hopamp == NULL) || (hopamp->State == HAL_OPAMP_STATE_BUSYLOCKED)
<> 149:156823d33999 258 || (hopamp->State == HAL_OPAMP_STATE_CALIBBUSY) )
<> 149:156823d33999 259 {
<> 149:156823d33999 260 status = HAL_ERROR;
<> 149:156823d33999 261 }
<> 149:156823d33999 262 else
<> 149:156823d33999 263 {
<> 149:156823d33999 264 /* Check the parameter */
<> 149:156823d33999 265 assert_param(IS_OPAMP_ALL_INSTANCE(hopamp->Instance));
<> 149:156823d33999 266
<> 149:156823d33999 267 /* Set OPAMP parameters */
<> 149:156823d33999 268 assert_param(IS_OPAMP_POWER_SUPPLY_RANGE(hopamp->Init.PowerSupplyRange));
<> 149:156823d33999 269 assert_param(IS_OPAMP_POWERMODE(hopamp->Init.PowerMode));
<> 149:156823d33999 270 assert_param(IS_OPAMP_FUNCTIONAL_NORMALMODE(hopamp->Init.Mode));
<> 149:156823d33999 271 assert_param(IS_OPAMP_NONINVERTING_INPUT_CHECK_INSTANCE(hopamp, hopamp->Init.NonInvertingInput));
<> 149:156823d33999 272 assert_param(IS_OPAMP_TRIMMING(hopamp->Init.UserTrimming));
<> 149:156823d33999 273
<> 149:156823d33999 274 if (hopamp->Init.Mode != OPAMP_FOLLOWER_MODE)
<> 149:156823d33999 275 {
<> 149:156823d33999 276 assert_param(IS_OPAMP_INVERTING_INPUT(hopamp->Init.InvertingInput));
<> 149:156823d33999 277 }
<> 149:156823d33999 278
<> 149:156823d33999 279 if (hopamp->Init.UserTrimming == OPAMP_TRIMMING_USER)
<> 149:156823d33999 280 {
<> 149:156823d33999 281 if (hopamp->Init.PowerMode == OPAMP_POWERMODE_NORMAL)
<> 149:156823d33999 282 {
<> 149:156823d33999 283 assert_param(IS_OPAMP_TRIMMINGVALUE(hopamp->Init.TrimmingValueP));
<> 149:156823d33999 284 assert_param(IS_OPAMP_TRIMMINGVALUE(hopamp->Init.TrimmingValueN));
<> 149:156823d33999 285 }
<> 149:156823d33999 286 else
<> 149:156823d33999 287 {
<> 149:156823d33999 288 assert_param(IS_OPAMP_TRIMMINGVALUE(hopamp->Init.TrimmingValuePLowPower));
<> 149:156823d33999 289 assert_param(IS_OPAMP_TRIMMINGVALUE(hopamp->Init.TrimmingValueNLowPower));
<> 149:156823d33999 290 }
<> 149:156823d33999 291 }
<> 149:156823d33999 292
<> 149:156823d33999 293 if(hopamp->State == HAL_OPAMP_STATE_RESET)
<> 149:156823d33999 294 {
<> 149:156823d33999 295 /* Allocate lock resource and initialize it */
<> 149:156823d33999 296 hopamp->Lock = HAL_UNLOCKED;
<> 149:156823d33999 297 }
<> 149:156823d33999 298
<> 149:156823d33999 299 /* Call MSP init function */
<> 149:156823d33999 300 HAL_OPAMP_MspInit(hopamp);
<> 149:156823d33999 301
<> 149:156823d33999 302 /* Set OPAMP parameters */
<> 149:156823d33999 303 /* - Set internal switches in function of: */
<> 149:156823d33999 304 /* - OPAMP selected mode: standalone or follower. */
<> 149:156823d33999 305 /* - Non-inverting input connection */
<> 149:156823d33999 306 /* - Inverting input connection */
<> 149:156823d33999 307 /* - Set power supply range */
<> 149:156823d33999 308 /* - Set power mode and associated calibration parameters */
<> 149:156823d33999 309
<> 149:156823d33999 310 /* Get OPAMP CSR register into temporary variable */
<> 149:156823d33999 311 /* Note: OPAMP register CSR is written directly, independently of OPAMP */
<> 149:156823d33999 312 /* instance, because all OPAMP settings are dispatched in the same */
<> 149:156823d33999 313 /* register. */
<> 149:156823d33999 314 /* Settings of bits for each OPAMP instances are managed case by */
<> 149:156823d33999 315 /* case using macro (OPAMP_CSR_S3SELX(), OPAMP_CSR_ANAWSELX(), ...) */
<> 149:156823d33999 316 tmp_csr = OPAMP->CSR;
<> 149:156823d33999 317
<> 149:156823d33999 318 /* Open all switches on non-inverting input, inverting input and output */
<> 149:156823d33999 319 /* feedback. */
<> 149:156823d33999 320 CLEAR_BIT(tmp_csr, OPAMP_CSR_ALL_SWITCHES(hopamp));
<> 149:156823d33999 321
<> 149:156823d33999 322 /* Set internal switches in function of OPAMP mode selected: standalone */
<> 149:156823d33999 323 /* or follower. */
<> 149:156823d33999 324 /* If follower mode is selected, feedback switch S3 is closed and */
<> 149:156823d33999 325 /* inverting inputs switches are let opened. */
<> 149:156823d33999 326 /* If standalone mode is selected, feedback switch S3 is let opened and */
<> 149:156823d33999 327 /* the selected inverting inputs switch is closed. */
<> 149:156823d33999 328 if (hopamp->Init.Mode == OPAMP_FOLLOWER_MODE)
<> 149:156823d33999 329 {
<> 149:156823d33999 330 /* Follower mode: Close switches S3 and SanB */
<> 149:156823d33999 331 SET_BIT(tmp_csr, OPAMP_CSR_S3SELX(hopamp));
<> 149:156823d33999 332 }
<> 149:156823d33999 333 else
<> 149:156823d33999 334 {
<> 149:156823d33999 335 /* Set internal switches in function of inverting input selected: */
<> 149:156823d33999 336 /* Close switch to connect OPAMP inverting input to the selected */
<> 149:156823d33999 337 /* input: dedicated IO pin or alternative IO pin available on some */
<> 149:156823d33999 338 /* device packages. */
<> 149:156823d33999 339 if (hopamp->Init.InvertingInput == OPAMP_INVERTINGINPUT_IO0)
<> 149:156823d33999 340 {
<> 149:156823d33999 341 /* Close switch to connect OPAMP non-inverting input to */
<> 149:156823d33999 342 /* dedicated IO pin low-leakage. */
<> 149:156823d33999 343 SET_BIT(tmp_csr, OPAMP_CSR_S4SELX(hopamp));
<> 149:156823d33999 344 }
<> 149:156823d33999 345 else
<> 149:156823d33999 346 {
<> 149:156823d33999 347 /* Close switch to connect OPAMP inverting input to alternative */
<> 149:156823d33999 348 /* IO pin available on some device packages. */
<> 149:156823d33999 349 SET_BIT(tmp_csr, OPAMP_CSR_ANAWSELX(hopamp));
<> 149:156823d33999 350 }
<> 149:156823d33999 351 }
<> 149:156823d33999 352
<> 149:156823d33999 353 /* Set internal switches in function of non-inverting input selected: */
<> 149:156823d33999 354 /* Close switch to connect OPAMP non-inverting input to the selected */
<> 149:156823d33999 355 /* input: dedicated IO pin or DAC channel. */
<> 149:156823d33999 356 if (hopamp->Init.NonInvertingInput == OPAMP_NONINVERTINGINPUT_IO0)
<> 149:156823d33999 357 {
<> 149:156823d33999 358 /* Close switch to connect OPAMP non-inverting input to */
<> 149:156823d33999 359 /* dedicated IO pin low-leakage. */
<> 149:156823d33999 360 SET_BIT(tmp_csr, OPAMP_CSR_S5SELX(hopamp));
<> 149:156823d33999 361 }
<> 149:156823d33999 362 else if (hopamp->Init.NonInvertingInput == OPAMP_NONINVERTINGINPUT_DAC_CH1)
<> 149:156823d33999 363 {
<> 149:156823d33999 364
<> 149:156823d33999 365 /* Particular case for connection to DAC channel 1: */
<> 149:156823d33999 366 /* OPAMP_NONINVERTINGINPUT_DAC_CH1 available on OPAMP1 and OPAMP2 only */
<> 149:156823d33999 367 /* (OPAMP3 availability depends on device category). */
<> 149:156823d33999 368 if ((hopamp->Instance == OPAMP1) || (hopamp->Instance == OPAMP2))
<> 149:156823d33999 369 {
<> 149:156823d33999 370 /* Close switch to connect OPAMP non-inverting input to */
<> 149:156823d33999 371 /* DAC channel 1. */
<> 149:156823d33999 372 SET_BIT(tmp_csr, OPAMP_CSR_S6SELX(hopamp));
<> 149:156823d33999 373 }
<> 149:156823d33999 374 else
<> 149:156823d33999 375 {
<> 149:156823d33999 376 /* Set HAL status to error if another OPAMP instance as OPAMP1 or */
<> 149:156823d33999 377 /* OPAMP2 is intended to be connected to DAC channel 2. */
<> 149:156823d33999 378 status = HAL_ERROR;
<> 149:156823d33999 379 }
<> 149:156823d33999 380 }
<> 149:156823d33999 381 else /* if (hopamp->Init.NonInvertingInput == */
<> 149:156823d33999 382 /* OPAMP_NONINVERTINGINPUT_DAC_CH2 ) */
<> 149:156823d33999 383 {
<> 149:156823d33999 384 /* Particular case for connection to DAC channel 2: */
<> 149:156823d33999 385 /* OPAMP_NONINVERTINGINPUT_DAC_CH2 available on OPAMP2 and OPAMP3 only */
<> 149:156823d33999 386 /* (OPAMP3 availability depends on device category). */
<> 149:156823d33999 387 if (hopamp->Instance == OPAMP2)
<> 149:156823d33999 388 {
<> 149:156823d33999 389 /* Close switch to connect OPAMP non-inverting input to */
<> 149:156823d33999 390 /* DAC channel 2. */
<> 149:156823d33999 391 SET_BIT(tmp_csr, OPAMP_CSR_S7SEL2);
<> 149:156823d33999 392 }
<> 149:156823d33999 393 /* If OPAMP3 is selected (if available) */
<> 149:156823d33999 394 else if (hopamp->Instance != OPAMP1)
<> 149:156823d33999 395 {
<> 149:156823d33999 396 /* Close switch to connect OPAMP non-inverting input to */
<> 149:156823d33999 397 /* DAC channel 2. */
<> 149:156823d33999 398 SET_BIT(tmp_csr, OPAMP_CSR_S6SELX(hopamp));
<> 149:156823d33999 399 }
<> 149:156823d33999 400 else
<> 149:156823d33999 401 {
<> 149:156823d33999 402 /* Set HAL status to error if another OPAMP instance as OPAMP2 or */
<> 149:156823d33999 403 /* OPAMP3 (if available) is intended to be connected to DAC channel 2.*/
<> 149:156823d33999 404 status = HAL_ERROR;
<> 149:156823d33999 405 }
<> 149:156823d33999 406 }
<> 149:156823d33999 407
<> 149:156823d33999 408 /* Continue OPAMP configuration if settings of switches are correct */
<> 149:156823d33999 409 if (status != HAL_ERROR)
<> 149:156823d33999 410 {
<> 149:156823d33999 411 /* Set power mode and associated calibration parameters */
<> 149:156823d33999 412 if (hopamp->Init.PowerMode != OPAMP_POWERMODE_LOWPOWER)
<> 149:156823d33999 413 {
<> 149:156823d33999 414 /* Set normal mode */
<> 149:156823d33999 415 CLEAR_BIT(tmp_csr, OPAMP_CSR_OPAXLPM(hopamp));
<> 149:156823d33999 416
<> 149:156823d33999 417 if (hopamp->Init.UserTrimming == OPAMP_TRIMMING_USER)
<> 149:156823d33999 418 {
<> 149:156823d33999 419 /* Set calibration mode (factory or user) and values for */
<> 149:156823d33999 420 /* transistors differential pair high (PMOS) and low (NMOS) for */
<> 149:156823d33999 421 /* normal mode. */
<> 149:156823d33999 422 MODIFY_REG(OPAMP->OTR, OPAMP_OTR_OT_USER |
<> 149:156823d33999 423 OPAMP_OFFSET_TRIM_SET(hopamp, OPAMP_FACTORYTRIMMING_N, OPAMP_TRIM_VALUE_MASK) |
<> 149:156823d33999 424 OPAMP_OFFSET_TRIM_SET(hopamp, OPAMP_FACTORYTRIMMING_P, OPAMP_TRIM_VALUE_MASK) ,
<> 149:156823d33999 425 hopamp->Init.UserTrimming |
<> 149:156823d33999 426 OPAMP_OFFSET_TRIM_SET(hopamp, OPAMP_FACTORYTRIMMING_N, hopamp->Init.TrimmingValueN) |
<> 149:156823d33999 427 OPAMP_OFFSET_TRIM_SET(hopamp, OPAMP_FACTORYTRIMMING_P, hopamp->Init.TrimmingValueP) );
<> 149:156823d33999 428 }
<> 149:156823d33999 429 else
<> 149:156823d33999 430 {
<> 149:156823d33999 431 /* Set calibration mode to factory */
<> 149:156823d33999 432 CLEAR_BIT(OPAMP->OTR, OPAMP_OTR_OT_USER);
<> 149:156823d33999 433 }
<> 149:156823d33999 434
<> 149:156823d33999 435 }
<> 149:156823d33999 436 else
<> 149:156823d33999 437 {
<> 149:156823d33999 438 /* Set low power mode */
<> 149:156823d33999 439 SET_BIT(tmp_csr, OPAMP_CSR_OPAXLPM(hopamp));
<> 149:156823d33999 440
<> 149:156823d33999 441 if (hopamp->Init.UserTrimming == OPAMP_TRIMMING_USER)
<> 149:156823d33999 442 {
<> 149:156823d33999 443 /* Set calibration mode to user trimming */
<> 149:156823d33999 444 SET_BIT(OPAMP->OTR, OPAMP_OTR_OT_USER);
<> 149:156823d33999 445
<> 149:156823d33999 446 /* Set values for transistors differential pair high (PMOS) and low */
<> 149:156823d33999 447 /* (NMOS) for low power mode. */
<> 149:156823d33999 448 MODIFY_REG(OPAMP->LPOTR, OPAMP_OFFSET_TRIM_SET(hopamp, OPAMP_FACTORYTRIMMING_N, OPAMP_TRIM_VALUE_MASK) |
<> 149:156823d33999 449 OPAMP_OFFSET_TRIM_SET(hopamp, OPAMP_FACTORYTRIMMING_P, OPAMP_TRIM_VALUE_MASK) ,
<> 149:156823d33999 450 OPAMP_OFFSET_TRIM_SET(hopamp, OPAMP_FACTORYTRIMMING_N, hopamp->Init.TrimmingValueNLowPower) |
<> 149:156823d33999 451 OPAMP_OFFSET_TRIM_SET(hopamp, OPAMP_FACTORYTRIMMING_P, hopamp->Init.TrimmingValuePLowPower) );
<> 149:156823d33999 452 }
<> 149:156823d33999 453 else
<> 149:156823d33999 454 {
<> 149:156823d33999 455 /* Set calibration mode to factory trimming */
<> 149:156823d33999 456 CLEAR_BIT(OPAMP->OTR, OPAMP_OTR_OT_USER);
<> 149:156823d33999 457 }
<> 149:156823d33999 458
<> 149:156823d33999 459 }
<> 149:156823d33999 460
<> 149:156823d33999 461
<> 149:156823d33999 462 /* Configure the power supply range */
<> 149:156823d33999 463 MODIFY_REG(tmp_csr, OPAMP_CSR_AOP_RANGE,
<> 149:156823d33999 464 hopamp->Init.PowerSupplyRange);
<> 149:156823d33999 465
<> 149:156823d33999 466 /* Set OPAMP CSR register from temporary variable */
<> 149:156823d33999 467 /* This allows to apply all changes on one time, in case of update on */
<> 149:156823d33999 468 /* the fly with OPAMP previously set and running: */
<> 149:156823d33999 469 /* - to avoid hazardous transient switches settings (risk of short */
<> 149:156823d33999 470 /* circuit) */
<> 149:156823d33999 471 /* - to avoid interruption of input signal */
<> 149:156823d33999 472 OPAMP->CSR = tmp_csr;
<> 149:156823d33999 473
<> 149:156823d33999 474
<> 149:156823d33999 475 /* Update the OPAMP state */
<> 149:156823d33999 476 /* If coming from state reset: Update from state RESET to state READY */
<> 149:156823d33999 477 if (hopamp->State == HAL_OPAMP_STATE_RESET)
<> 149:156823d33999 478 {
<> 149:156823d33999 479 hopamp->State = HAL_OPAMP_STATE_READY;
<> 149:156823d33999 480 }
<> 149:156823d33999 481 /* else: OPAMP state remains READY or BUSY state (no update) */
<> 149:156823d33999 482 }
<> 149:156823d33999 483 }
<> 149:156823d33999 484
<> 149:156823d33999 485 return status;
<> 149:156823d33999 486 }
<> 149:156823d33999 487
<> 149:156823d33999 488 /**
<> 149:156823d33999 489 * @brief DeInitializes the OPAMP peripheral
<> 149:156823d33999 490 * @note Deinitialization can be performed if the OPAMP configuration is locked.
<> 149:156823d33999 491 * (the OPAMP lock is SW in STM32L1)
<> 149:156823d33999 492 * @param hopamp: OPAMP handle
<> 149:156823d33999 493 * @retval HAL status
<> 149:156823d33999 494 */
<> 149:156823d33999 495 HAL_StatusTypeDef HAL_OPAMP_DeInit(OPAMP_HandleTypeDef* hopamp)
<> 149:156823d33999 496 {
<> 149:156823d33999 497 HAL_StatusTypeDef status = HAL_OK;
<> 149:156823d33999 498
<> 149:156823d33999 499 /* Check the OPAMP handle allocation */
<> 149:156823d33999 500 /* DeInit not allowed if calibration is ongoing */
<> 149:156823d33999 501 if((hopamp == NULL) || (hopamp->State == HAL_OPAMP_STATE_CALIBBUSY))
<> 149:156823d33999 502 {
<> 149:156823d33999 503 status = HAL_ERROR;
<> 149:156823d33999 504 }
<> 149:156823d33999 505 else
<> 149:156823d33999 506 {
<> 149:156823d33999 507 /* Check the parameter */
<> 149:156823d33999 508 assert_param(IS_OPAMP_ALL_INSTANCE(hopamp->Instance));
<> 149:156823d33999 509
<> 149:156823d33999 510 /* Disable the selected opamp */
<> 149:156823d33999 511 SET_BIT (OPAMP->CSR, OPAMP_CSR_OPAXPD(hopamp));
<> 149:156823d33999 512
<> 149:156823d33999 513 /* Open all switches on non-inverting input, inverting input and output */
<> 149:156823d33999 514 /* feedback. */
<> 149:156823d33999 515 /* Note: OPAMP register CSR is written directly, independently of OPAMP */
<> 149:156823d33999 516 /* instance, because all OPAMP settings are dispatched in the same */
<> 149:156823d33999 517 /* register. */
<> 149:156823d33999 518 /* Settings of bits for each OPAMP instances are managed case by */
<> 149:156823d33999 519 /* case using macro (OPAMP_CSR_S3SELX(), OPAMP_CSR_ANAWSELX(), ...) */
<> 149:156823d33999 520 CLEAR_BIT(OPAMP->CSR, OPAMP_CSR_ALL_SWITCHES(hopamp));
<> 149:156823d33999 521
<> 149:156823d33999 522 /* Note: Registers and bits shared with other OPAMP instances are kept */
<> 149:156823d33999 523 /* unchanged, to not impact other OPAMP while operating on the */
<> 149:156823d33999 524 /* selected OPAMP. */
<> 149:156823d33999 525 /* Unchanged: bit OPAMP_OTR_OT_USER (parameter "UserTrimming") */
<> 149:156823d33999 526 /* bit OPAMP_CSR_AOP_RANGE (parameter "PowerSupplyRange")*/
<> 149:156823d33999 527
<> 149:156823d33999 528 /* DeInit the low level hardware: GPIO, CLOCK and NVIC */
<> 149:156823d33999 529 HAL_OPAMP_MspDeInit(hopamp);
<> 149:156823d33999 530
<> 149:156823d33999 531 /* Update the OPAMP state*/
<> 149:156823d33999 532 hopamp->State = HAL_OPAMP_STATE_RESET;
<> 149:156823d33999 533 }
<> 149:156823d33999 534
<> 149:156823d33999 535 /* Process unlocked */
<> 149:156823d33999 536 __HAL_UNLOCK(hopamp);
<> 149:156823d33999 537
<> 149:156823d33999 538 return status;
<> 149:156823d33999 539 }
<> 149:156823d33999 540
<> 149:156823d33999 541
<> 149:156823d33999 542 /**
<> 149:156823d33999 543 * @brief Initializes the OPAMP MSP.
<> 149:156823d33999 544 * @param hopamp: OPAMP handle
<> 149:156823d33999 545 * @retval None
<> 149:156823d33999 546 */
<> 149:156823d33999 547 __weak void HAL_OPAMP_MspInit(OPAMP_HandleTypeDef* hopamp)
<> 149:156823d33999 548 {
<> 149:156823d33999 549 /* Prevent unused argument(s) compilation warning */
<> 149:156823d33999 550 UNUSED(hopamp);
<> 149:156823d33999 551
<> 149:156823d33999 552 /* NOTE : This function Should not be modified, when the callback is needed,
<> 149:156823d33999 553 the function "HAL_OPAMP_MspInit()" must be implemented in the user file.
<> 149:156823d33999 554 */
<> 149:156823d33999 555 }
<> 149:156823d33999 556
<> 149:156823d33999 557 /**
<> 149:156823d33999 558 * @brief DeInitializes OPAMP MSP.
<> 149:156823d33999 559 * @param hopamp: OPAMP handle
<> 149:156823d33999 560 * @retval None
<> 149:156823d33999 561 */
<> 149:156823d33999 562 __weak void HAL_OPAMP_MspDeInit(OPAMP_HandleTypeDef* hopamp)
<> 149:156823d33999 563 {
<> 149:156823d33999 564 /* Prevent unused argument(s) compilation warning */
<> 149:156823d33999 565 UNUSED(hopamp);
<> 149:156823d33999 566
<> 149:156823d33999 567 /* NOTE : This function Should not be modified, when the callback is needed,
<> 149:156823d33999 568 the function "HAL_OPAMP_MspDeInit()" must be implemented in the user file.
<> 149:156823d33999 569 */
<> 149:156823d33999 570 }
<> 149:156823d33999 571
<> 149:156823d33999 572 /**
<> 149:156823d33999 573 * @}
<> 149:156823d33999 574 */
<> 149:156823d33999 575
<> 149:156823d33999 576
<> 149:156823d33999 577 /** @defgroup OPAMP_Exported_Functions_Group2 IO operation functions
<> 149:156823d33999 578 * @brief IO operation functions
<> 149:156823d33999 579 *
<> 149:156823d33999 580 @verbatim
<> 149:156823d33999 581 ===============================================================================
<> 149:156823d33999 582 ##### IO operation functions #####
<> 149:156823d33999 583 ===============================================================================
<> 149:156823d33999 584 [..]
<> 149:156823d33999 585 This subsection provides a set of functions allowing to manage the OPAMP
<> 149:156823d33999 586 start, stop and calibration actions.
<> 149:156823d33999 587
<> 149:156823d33999 588 @endverbatim
<> 149:156823d33999 589 * @{
<> 149:156823d33999 590 */
<> 149:156823d33999 591
<> 149:156823d33999 592 /**
<> 149:156823d33999 593 * @brief Start the opamp
<> 149:156823d33999 594 * @param hopamp: OPAMP handle
<> 149:156823d33999 595 * @retval HAL status
<> 149:156823d33999 596 */
<> 149:156823d33999 597
<> 149:156823d33999 598 HAL_StatusTypeDef HAL_OPAMP_Start(OPAMP_HandleTypeDef* hopamp)
<> 149:156823d33999 599 {
<> 149:156823d33999 600 HAL_StatusTypeDef status = HAL_OK;
<> 149:156823d33999 601
<> 149:156823d33999 602 /* Check the OPAMP handle allocation */
<> 149:156823d33999 603 /* Check if OPAMP locked */
<> 149:156823d33999 604 if((hopamp == NULL) || (hopamp->State == HAL_OPAMP_STATE_BUSYLOCKED))
<> 149:156823d33999 605 {
<> 149:156823d33999 606 status = HAL_ERROR;
<> 149:156823d33999 607 }
<> 149:156823d33999 608 else
<> 149:156823d33999 609 {
<> 149:156823d33999 610 /* Check the parameter */
<> 149:156823d33999 611 assert_param(IS_OPAMP_ALL_INSTANCE(hopamp->Instance));
<> 149:156823d33999 612
<> 149:156823d33999 613 if(hopamp->State == HAL_OPAMP_STATE_READY)
<> 149:156823d33999 614 {
<> 149:156823d33999 615 /* Enable the selected opamp */
<> 149:156823d33999 616 CLEAR_BIT (OPAMP->CSR, OPAMP_CSR_OPAXPD(hopamp));
<> 149:156823d33999 617
<> 149:156823d33999 618 /* Update the OPAMP state */
<> 149:156823d33999 619 /* From HAL_OPAMP_STATE_READY to HAL_OPAMP_STATE_BUSY */
<> 149:156823d33999 620 hopamp->State = HAL_OPAMP_STATE_BUSY;
<> 149:156823d33999 621 }
<> 149:156823d33999 622 else
<> 149:156823d33999 623 {
<> 149:156823d33999 624 status = HAL_ERROR;
<> 149:156823d33999 625 }
<> 149:156823d33999 626
<> 149:156823d33999 627 }
<> 149:156823d33999 628 return status;
<> 149:156823d33999 629 }
<> 149:156823d33999 630
<> 149:156823d33999 631 /**
<> 149:156823d33999 632 * @brief Stop the opamp
<> 149:156823d33999 633 * @param hopamp: OPAMP handle
<> 149:156823d33999 634 * @retval HAL status
<> 149:156823d33999 635 */
<> 149:156823d33999 636 HAL_StatusTypeDef HAL_OPAMP_Stop(OPAMP_HandleTypeDef* hopamp)
<> 149:156823d33999 637 {
<> 149:156823d33999 638 HAL_StatusTypeDef status = HAL_OK;
<> 149:156823d33999 639
<> 149:156823d33999 640 /* Check the OPAMP handle allocation */
<> 149:156823d33999 641 /* Check if OPAMP locked */
<> 149:156823d33999 642 /* Check if OPAMP calibration ongoing */
<> 149:156823d33999 643 if((hopamp == NULL) || (hopamp->State == HAL_OPAMP_STATE_BUSYLOCKED) \
<> 149:156823d33999 644 || (hopamp->State == HAL_OPAMP_STATE_CALIBBUSY))
<> 149:156823d33999 645 {
<> 149:156823d33999 646 status = HAL_ERROR;
<> 149:156823d33999 647 }
<> 149:156823d33999 648 else
<> 149:156823d33999 649 {
<> 149:156823d33999 650 /* Check the parameter */
<> 149:156823d33999 651 assert_param(IS_OPAMP_ALL_INSTANCE(hopamp->Instance));
<> 149:156823d33999 652
<> 149:156823d33999 653 if(hopamp->State == HAL_OPAMP_STATE_BUSY)
<> 149:156823d33999 654 {
<> 149:156823d33999 655 /* Disable the selected opamp */
<> 149:156823d33999 656 SET_BIT (OPAMP->CSR, OPAMP_CSR_OPAXPD(hopamp));
<> 149:156823d33999 657
<> 149:156823d33999 658 /* Update the OPAMP state*/
<> 149:156823d33999 659 /* From HAL_OPAMP_STATE_BUSY to HAL_OPAMP_STATE_READY*/
<> 149:156823d33999 660 hopamp->State = HAL_OPAMP_STATE_READY;
<> 149:156823d33999 661 }
<> 149:156823d33999 662 else
<> 149:156823d33999 663 {
<> 149:156823d33999 664 status = HAL_ERROR;
<> 149:156823d33999 665 }
<> 149:156823d33999 666 }
<> 149:156823d33999 667 return status;
<> 149:156823d33999 668 }
<> 149:156823d33999 669
<> 149:156823d33999 670 /**
<> 149:156823d33999 671 * @brief Run the self calibration of one OPAMP
<> 149:156823d33999 672 * @note Trimming values (PMOS & NMOS) are updated and user trimming is
<> 149:156823d33999 673 * enabled if calibration is succesful.
<> 149:156823d33999 674 * @note Calibration is performed in the mode specified in OPAMP init
<> 149:156823d33999 675 * structure (mode normal or low-power). To perform calibration for
<> 149:156823d33999 676 * both modes, repeat this function twice after OPAMP init structure
<> 149:156823d33999 677 * accordingly updated.
<> 149:156823d33999 678 * @note Calibration runs about 10 ms.
<> 149:156823d33999 679 * @param hopamp handle
<> 149:156823d33999 680 * @retval Updated offset trimming values (PMOS & NMOS), user trimming is enabled
<> 149:156823d33999 681 * @retval HAL status
<> 149:156823d33999 682 */
<> 149:156823d33999 683 HAL_StatusTypeDef HAL_OPAMP_SelfCalibrate(OPAMP_HandleTypeDef* hopamp)
<> 149:156823d33999 684 {
<> 149:156823d33999 685 HAL_StatusTypeDef status = HAL_OK;
<> 149:156823d33999 686
<> 149:156823d33999 687 uint32_t* opamp_trimmingvalue = 0;
<> 149:156823d33999 688 uint32_t opamp_trimmingvaluen = 0;
<> 149:156823d33999 689 uint32_t opamp_trimmingvaluep = 0;
<> 149:156823d33999 690
<> 149:156823d33999 691 uint32_t trimming_diff_pair = 0; /* Selection of differential transistors pair high or low */
<> 149:156823d33999 692
<> 149:156823d33999 693 __IO uint32_t* tmp_opamp_reg_trimming; /* Selection of register of trimming depending on power mode: OTR or LPOTR */
<> 149:156823d33999 694 uint32_t tmp_opamp_otr_otuser = 0; /* Selection of bit OPAMP_OTR_OT_USER depending on trimming register pointed: OTR or LPOTR */
<> 149:156823d33999 695
<> 149:156823d33999 696 uint32_t tmp_Opaxcalout_DefaultSate = 0; /* Bit OPAMP_CSR_OPAXCALOUT default state when trimming value is 00000b. Used to detect the bit toggling */
<> 149:156823d33999 697
<> 149:156823d33999 698 uint32_t tmp_OpaxSwitchesContextBackup = 0;
<> 149:156823d33999 699
<> 149:156823d33999 700 uint8_t trimming_diff_pair_iteration_count = 0; /* For calibration loop algorithm: to repeat the calibration loop for both differential transistors pair high and low */
<> 149:156823d33999 701 uint8_t delta = 0; /* For calibration loop algorithm: Variable for dichotomy steps value */
<> 149:156823d33999 702 uint8_t final_step_check = 0; /* For calibration loop algorithm: Flag for additional check of last trimming step */
<> 149:156823d33999 703
<> 149:156823d33999 704 /* Check the OPAMP handle allocation */
<> 149:156823d33999 705 /* Check if OPAMP locked */
<> 149:156823d33999 706 if((hopamp == NULL) || (hopamp->State == HAL_OPAMP_STATE_BUSYLOCKED))
<> 149:156823d33999 707 {
<> 149:156823d33999 708 status = HAL_ERROR;
<> 149:156823d33999 709 }
<> 149:156823d33999 710 else
<> 149:156823d33999 711 {
<> 149:156823d33999 712
<> 149:156823d33999 713 /* Check if OPAMP in calibration mode and calibration not yet enable */
<> 149:156823d33999 714 if(hopamp->State == HAL_OPAMP_STATE_READY)
<> 149:156823d33999 715 {
<> 149:156823d33999 716 /* Check the parameter */
<> 149:156823d33999 717 assert_param(IS_OPAMP_ALL_INSTANCE(hopamp->Instance));
<> 149:156823d33999 718 assert_param(IS_OPAMP_POWERMODE(hopamp->Init.PowerMode));
<> 149:156823d33999 719
<> 149:156823d33999 720 /* Update OPAMP state */
<> 149:156823d33999 721 hopamp->State = HAL_OPAMP_STATE_CALIBBUSY;
<> 149:156823d33999 722
<> 149:156823d33999 723 /* Backup of switches configuration to restore it at the end of the */
<> 149:156823d33999 724 /* calibration. */
<> 149:156823d33999 725 tmp_OpaxSwitchesContextBackup = READ_BIT(OPAMP->CSR, OPAMP_CSR_ALL_SWITCHES(hopamp));
<> 149:156823d33999 726
<> 149:156823d33999 727 /* Open all switches on non-inverting input, inverting input and output */
<> 149:156823d33999 728 /* feedback. */
<> 149:156823d33999 729 CLEAR_BIT(OPAMP->CSR, OPAMP_CSR_ALL_SWITCHES(hopamp));
<> 149:156823d33999 730
<> 149:156823d33999 731 /* Set calibration mode to user programmed trimming values */
<> 149:156823d33999 732 SET_BIT(OPAMP->OTR, OPAMP_OTR_OT_USER);
<> 149:156823d33999 733
<> 149:156823d33999 734
<> 149:156823d33999 735 /* Select trimming settings depending on power mode */
<> 149:156823d33999 736 if (hopamp->Init.PowerMode == OPAMP_POWERMODE_NORMAL)
<> 149:156823d33999 737 {
<> 149:156823d33999 738 tmp_opamp_otr_otuser = OPAMP_OTR_OT_USER;
<> 149:156823d33999 739 tmp_opamp_reg_trimming = &OPAMP->OTR;
<> 149:156823d33999 740 }
<> 149:156823d33999 741 else
<> 149:156823d33999 742 {
<> 149:156823d33999 743 tmp_opamp_otr_otuser = 0x00000000;
<> 149:156823d33999 744 tmp_opamp_reg_trimming = &OPAMP->LPOTR;
<> 149:156823d33999 745 }
<> 149:156823d33999 746
<> 149:156823d33999 747
<> 149:156823d33999 748 /* Enable the selected opamp */
<> 149:156823d33999 749 CLEAR_BIT (OPAMP->CSR, OPAMP_CSR_OPAXPD(hopamp));
<> 149:156823d33999 750
<> 149:156823d33999 751 /* Perform trimming for both differential transistors pair high and low */
<> 149:156823d33999 752 for (trimming_diff_pair_iteration_count = 0; trimming_diff_pair_iteration_count <=1; trimming_diff_pair_iteration_count++)
<> 149:156823d33999 753 {
<> 149:156823d33999 754 if (trimming_diff_pair_iteration_count == 0)
<> 149:156823d33999 755 {
<> 149:156823d33999 756 /* Calibration of transistors differential pair high (NMOS) */
<> 149:156823d33999 757 trimming_diff_pair = OPAMP_FACTORYTRIMMING_N;
<> 149:156823d33999 758 opamp_trimmingvalue = &opamp_trimmingvaluen;
<> 149:156823d33999 759
<> 149:156823d33999 760 /* Set bit OPAMP_CSR_OPAXCALOUT default state when trimming value */
<> 149:156823d33999 761 /* is 00000b. Used to detect the bit toggling during trimming. */
<> 149:156823d33999 762 tmp_Opaxcalout_DefaultSate = RESET;
<> 149:156823d33999 763
<> 149:156823d33999 764 /* Enable calibration for N differential pair */
<> 149:156823d33999 765 MODIFY_REG(OPAMP->CSR, OPAMP_CSR_OPAXCAL_L(hopamp),
<> 149:156823d33999 766 OPAMP_CSR_OPAXCAL_H(hopamp) );
<> 149:156823d33999 767 }
<> 149:156823d33999 768 else /* (trimming_diff_pair_iteration_count == 1) */
<> 149:156823d33999 769 {
<> 149:156823d33999 770 /* Calibration of transistors differential pair low (PMOS) */
<> 149:156823d33999 771 trimming_diff_pair = OPAMP_FACTORYTRIMMING_P;
<> 149:156823d33999 772 opamp_trimmingvalue = &opamp_trimmingvaluep;
<> 149:156823d33999 773
<> 149:156823d33999 774 /* Set bit OPAMP_CSR_OPAXCALOUT default state when trimming value */
<> 149:156823d33999 775 /* is 00000b. Used to detect the bit toggling during trimming. */
<> 149:156823d33999 776 tmp_Opaxcalout_DefaultSate = OPAMP_CSR_OPAXCALOUT(hopamp);
<> 149:156823d33999 777
<> 149:156823d33999 778 /* Enable calibration for P differential pair */
<> 149:156823d33999 779 MODIFY_REG(OPAMP->CSR, OPAMP_CSR_OPAXCAL_H(hopamp),
<> 149:156823d33999 780 OPAMP_CSR_OPAXCAL_L(hopamp) );
<> 149:156823d33999 781 }
<> 149:156823d33999 782
<> 149:156823d33999 783
<> 149:156823d33999 784 /* Perform calibration parameter search by dichotomy sweep */
<> 149:156823d33999 785 /* - Delta initial value 16: for 5 dichotomy steps: 16 for the */
<> 149:156823d33999 786 /* initial range, then successive delta sweeps (8, 4, 2, 1). */
<> 149:156823d33999 787 /* can extend the search range to +/- 15 units. */
<> 149:156823d33999 788 /* - Trimming initial value 15: search range will go from 0 to 30 */
<> 149:156823d33999 789 /* (Trimming value 31 is forbidden). */
<> 149:156823d33999 790 /* Note: After dichotomy sweep, the trimming result is determined. */
<> 149:156823d33999 791 /* However, the final trimming step is deduced from previous */
<> 149:156823d33999 792 /* trimming steps tested but is not effectively tested. */
<> 149:156823d33999 793 /* An additional test step (using variable "final_step_check") */
<> 149:156823d33999 794 /* allow to Test the final trimming step. */
<> 149:156823d33999 795 *opamp_trimmingvalue = 15;
<> 149:156823d33999 796 delta = 16;
<> 149:156823d33999 797
<> 149:156823d33999 798 while ((delta != 0) || (final_step_check == 1))
<> 149:156823d33999 799 {
<> 149:156823d33999 800 /* Set candidate trimming */
<> 149:156823d33999 801 MODIFY_REG(*tmp_opamp_reg_trimming, OPAMP_OFFSET_TRIM_SET(hopamp, trimming_diff_pair, OPAMP_TRIM_VALUE_MASK) ,
<> 149:156823d33999 802 OPAMP_OFFSET_TRIM_SET(hopamp, trimming_diff_pair, *opamp_trimmingvalue) | tmp_opamp_otr_otuser);
<> 149:156823d33999 803
<> 149:156823d33999 804 /* Offset trimming time: during calibration, minimum time needed */
<> 149:156823d33999 805 /* between two steps to have 1 mV accuracy. */
<> 149:156823d33999 806 HAL_Delay(OPAMP_TRIMMING_DELAY);
<> 149:156823d33999 807
<> 149:156823d33999 808 /* Set flag for additional check of last trimming step equal to */
<> 149:156823d33999 809 /* dichotomy step before its division by 2 (equivalent to previous */
<> 149:156823d33999 810 /* value of dichotomy step). */
<> 149:156823d33999 811 final_step_check = delta;
<> 149:156823d33999 812
<> 149:156823d33999 813 /* Divide range by 2 to continue dichotomy sweep */
<> 149:156823d33999 814 delta >>= 1;
<> 149:156823d33999 815
<> 149:156823d33999 816 /* Set trimming values for next iteration in function of trimming */
<> 149:156823d33999 817 /* result toggle (versus initial state). */
<> 149:156823d33999 818 /* Note: on the last trimming loop, delta is equal to 0 and */
<> 149:156823d33999 819 /* therefore has no effect. */
<> 149:156823d33999 820 if (READ_BIT(OPAMP->CSR, OPAMP_CSR_OPAXCALOUT(hopamp)) != tmp_Opaxcalout_DefaultSate)
<> 149:156823d33999 821 {
<> 149:156823d33999 822 /* If calibration output is has toggled, try lower trimming */
<> 149:156823d33999 823 *opamp_trimmingvalue -= delta;
<> 149:156823d33999 824 }
<> 149:156823d33999 825 else
<> 149:156823d33999 826 {
<> 149:156823d33999 827 /* If calibration output is has not toggled, try higher trimming */
<> 149:156823d33999 828 *opamp_trimmingvalue += delta;
<> 149:156823d33999 829 }
<> 149:156823d33999 830
<> 149:156823d33999 831 }
<> 149:156823d33999 832
<> 149:156823d33999 833 /* Check trimming result of the selected step and perform final fine */
<> 149:156823d33999 834 /* trimming. */
<> 149:156823d33999 835 /* - If calibration output is has toggled: the current step is */
<> 149:156823d33999 836 /* already optimized. */
<> 149:156823d33999 837 /* - If calibration output is has not toggled: the current step can */
<> 149:156823d33999 838 /* be optimized by incrementing it of one step. */
<> 149:156823d33999 839 if (READ_BIT(OPAMP->CSR, OPAMP_CSR_OPAXCALOUT(hopamp)) == tmp_Opaxcalout_DefaultSate)
<> 149:156823d33999 840 {
<> 149:156823d33999 841 *opamp_trimmingvalue += 1;
<> 149:156823d33999 842
<> 149:156823d33999 843 /* Set final fine trimming */
<> 149:156823d33999 844 MODIFY_REG(*tmp_opamp_reg_trimming, OPAMP_OFFSET_TRIM_SET(hopamp, trimming_diff_pair, OPAMP_TRIM_VALUE_MASK) ,
<> 149:156823d33999 845 OPAMP_OFFSET_TRIM_SET(hopamp, trimming_diff_pair, *opamp_trimmingvalue) | tmp_opamp_otr_otuser);
<> 149:156823d33999 846 }
<> 149:156823d33999 847
<> 149:156823d33999 848 }
<> 149:156823d33999 849
<> 149:156823d33999 850
<> 149:156823d33999 851 /* Disable calibration for P and N differential pairs */
<> 149:156823d33999 852 /* Disable the selected opamp */
<> 149:156823d33999 853 CLEAR_BIT (OPAMP->CSR, (OPAMP_CSR_OPAXCAL_H(hopamp) |
<> 149:156823d33999 854 OPAMP_CSR_OPAXCAL_L(hopamp) |
<> 149:156823d33999 855 OPAMP_CSR_OPAXPD(hopamp)) );
<> 149:156823d33999 856
<> 149:156823d33999 857 /* Backup of switches configuration to restore it at the end of the */
<> 149:156823d33999 858 /* calibration. */
<> 149:156823d33999 859 SET_BIT(OPAMP->CSR, tmp_OpaxSwitchesContextBackup);
<> 149:156823d33999 860
<> 149:156823d33999 861 /* Self calibration is successful */
<> 149:156823d33999 862 /* Store calibration (user trimming) results in init structure. */
<> 149:156823d33999 863
<> 149:156823d33999 864 /* Set user trimming mode */
<> 149:156823d33999 865 hopamp->Init.UserTrimming = OPAMP_TRIMMING_USER;
<> 149:156823d33999 866
<> 149:156823d33999 867 /* Affect calibration parameters depending on mode normal/low power */
<> 149:156823d33999 868 if (hopamp->Init.PowerMode != OPAMP_POWERMODE_LOWPOWER)
<> 149:156823d33999 869 {
<> 149:156823d33999 870 /* Write calibration result N */
<> 149:156823d33999 871 hopamp->Init.TrimmingValueN = opamp_trimmingvaluen;
<> 149:156823d33999 872 /* Write calibration result P */
<> 149:156823d33999 873 hopamp->Init.TrimmingValueP = opamp_trimmingvaluep;
<> 149:156823d33999 874 }
<> 149:156823d33999 875 else
<> 149:156823d33999 876 {
<> 149:156823d33999 877 /* Write calibration result N */
<> 149:156823d33999 878 hopamp->Init.TrimmingValueNLowPower = opamp_trimmingvaluen;
<> 149:156823d33999 879 /* Write calibration result P */
<> 149:156823d33999 880 hopamp->Init.TrimmingValuePLowPower = opamp_trimmingvaluep;
<> 149:156823d33999 881 }
<> 149:156823d33999 882
<> 149:156823d33999 883 /* Update OPAMP state */
<> 149:156823d33999 884 hopamp->State = HAL_OPAMP_STATE_READY;
<> 149:156823d33999 885
<> 149:156823d33999 886 }
<> 149:156823d33999 887
<> 149:156823d33999 888 else
<> 149:156823d33999 889 {
<> 149:156823d33999 890 /* OPAMP can not be calibrated from this mode */
<> 149:156823d33999 891 status = HAL_ERROR;
<> 149:156823d33999 892 }
<> 149:156823d33999 893 }
<> 149:156823d33999 894
<> 149:156823d33999 895 return status;
<> 149:156823d33999 896 }
<> 149:156823d33999 897
<> 149:156823d33999 898 /**
<> 149:156823d33999 899 * @}
<> 149:156823d33999 900 */
<> 149:156823d33999 901
<> 149:156823d33999 902 /**
<> 149:156823d33999 903 * @}
<> 149:156823d33999 904 */
<> 149:156823d33999 905
<> 149:156823d33999 906 /** @defgroup OPAMP_Exported_Functions_Group3 Peripheral Control functions
<> 149:156823d33999 907 * @brief Peripheral Control functions
<> 149:156823d33999 908 *
<> 149:156823d33999 909 @verbatim
<> 149:156823d33999 910 ===============================================================================
<> 149:156823d33999 911 ##### Peripheral Control functions #####
<> 149:156823d33999 912 ===============================================================================
<> 149:156823d33999 913 [..]
<> 149:156823d33999 914 This subsection provides a set of functions allowing to control the OPAMP data
<> 149:156823d33999 915 transfers.
<> 149:156823d33999 916
<> 149:156823d33999 917
<> 149:156823d33999 918
<> 149:156823d33999 919 @endverbatim
<> 149:156823d33999 920 * @{
<> 149:156823d33999 921 */
<> 149:156823d33999 922
<> 149:156823d33999 923 /**
<> 149:156823d33999 924 * @brief Lock the selected opamp configuration.
<> 149:156823d33999 925 * Caution: On STM32L1, HAL OPAMP lock is software lock only
<> 149:156823d33999 926 * (not hardware lock as available on some other STM32 devices)
<> 149:156823d33999 927 * @param hopamp: OPAMP handle
<> 149:156823d33999 928 * @retval HAL status
<> 149:156823d33999 929 */
<> 149:156823d33999 930 HAL_StatusTypeDef HAL_OPAMP_Lock(OPAMP_HandleTypeDef* hopamp)
<> 149:156823d33999 931 {
<> 149:156823d33999 932 HAL_StatusTypeDef status = HAL_OK;
<> 149:156823d33999 933
<> 149:156823d33999 934 /* Check the OPAMP handle allocation */
<> 149:156823d33999 935 /* Check if OPAMP locked */
<> 149:156823d33999 936 /* OPAMP can be locked when enabled and running in normal mode */
<> 149:156823d33999 937 /* It is meaningless otherwise */
<> 149:156823d33999 938 if((hopamp == NULL) || (hopamp->State == HAL_OPAMP_STATE_RESET) \
<> 149:156823d33999 939 || (hopamp->State == HAL_OPAMP_STATE_READY) \
<> 149:156823d33999 940 || (hopamp->State == HAL_OPAMP_STATE_CALIBBUSY)\
<> 149:156823d33999 941 || (hopamp->State == HAL_OPAMP_STATE_BUSYLOCKED))
<> 149:156823d33999 942
<> 149:156823d33999 943 {
<> 149:156823d33999 944 status = HAL_ERROR;
<> 149:156823d33999 945 }
<> 149:156823d33999 946
<> 149:156823d33999 947 else
<> 149:156823d33999 948 {
<> 149:156823d33999 949 /* Check the parameter */
<> 149:156823d33999 950 assert_param(IS_OPAMP_ALL_INSTANCE(hopamp->Instance));
<> 149:156823d33999 951
<> 149:156823d33999 952 /* OPAMP state changed to locked */
<> 149:156823d33999 953 hopamp->State = HAL_OPAMP_STATE_BUSYLOCKED;
<> 149:156823d33999 954 }
<> 149:156823d33999 955 return status;
<> 149:156823d33999 956 }
<> 149:156823d33999 957
<> 149:156823d33999 958 /**
<> 149:156823d33999 959 * @brief Return the OPAMP factory trimming value
<> 149:156823d33999 960 * Caution: On STM32L1 OPAMP, user can retrieve factory trimming if
<> 149:156823d33999 961 * OPAMP has never been set to user trimming before.
<> 149:156823d33999 962 * Therefore, this fonction must be called when OPAMP init
<> 149:156823d33999 963 * parameter "UserTrimming" is set to trimming factory,
<> 149:156823d33999 964 * and before OPAMP calibration (function
<> 149:156823d33999 965 * "HAL_OPAMP_SelfCalibrate()").
<> 149:156823d33999 966 * Otherwise, factory triming value cannot be retrieved and
<> 149:156823d33999 967 * error status is returned.
<> 149:156823d33999 968 * @param hopamp : OPAMP handle
<> 149:156823d33999 969 * @param trimmingoffset : Trimming offset (P or N)
<> 149:156823d33999 970 * This parameter must be a value of @ref OPAMP_FactoryTrimming
<> 149:156823d33999 971 * @note Calibration parameter retrieved is corresponding to the mode
<> 149:156823d33999 972 * specified in OPAMP init structure (mode normal or low-power).
<> 149:156823d33999 973 * To retrieve calibration parameters for both modes, repeat this
<> 149:156823d33999 974 * function after OPAMP init structure accordingly updated.
<> 149:156823d33999 975 * @retval Trimming value (P or N): range: 0->31
<> 149:156823d33999 976 * or OPAMP_FACTORYTRIMMING_DUMMY if trimming value is not available
<> 149:156823d33999 977 *
<> 149:156823d33999 978 */
<> 149:156823d33999 979 HAL_OPAMP_TrimmingValueTypeDef HAL_OPAMP_GetTrimOffset (OPAMP_HandleTypeDef *hopamp, uint32_t trimmingoffset)
<> 149:156823d33999 980 {
<> 149:156823d33999 981 HAL_OPAMP_TrimmingValueTypeDef trimmingvalue;
<> 149:156823d33999 982 __IO uint32_t* tmp_opamp_reg_trimming; /* Selection of register of trimming depending on power mode: OTR or LPOTR */
<> 149:156823d33999 983
<> 149:156823d33999 984 /* Check the OPAMP handle allocation */
<> 149:156823d33999 985 /* Value can be retrieved in HAL_OPAMP_STATE_READY state */
<> 149:156823d33999 986 if((hopamp == NULL) || (hopamp->State == HAL_OPAMP_STATE_RESET)
<> 149:156823d33999 987 || (hopamp->State == HAL_OPAMP_STATE_BUSY)
<> 149:156823d33999 988 || (hopamp->State == HAL_OPAMP_STATE_CALIBBUSY)
<> 149:156823d33999 989 || (hopamp->State == HAL_OPAMP_STATE_BUSYLOCKED))
<> 149:156823d33999 990 {
<> 149:156823d33999 991 trimmingvalue = OPAMP_FACTORYTRIMMING_DUMMY;
<> 149:156823d33999 992 }
<> 149:156823d33999 993 else
<> 149:156823d33999 994 {
<> 149:156823d33999 995 /* Check the parameter */
<> 149:156823d33999 996 assert_param(IS_OPAMP_ALL_INSTANCE(hopamp->Instance));
<> 149:156823d33999 997 assert_param(IS_OPAMP_FACTORYTRIMMING(trimmingoffset));
<> 149:156823d33999 998 assert_param(IS_OPAMP_POWERMODE(hopamp->Init.PowerMode));
<> 149:156823d33999 999
<> 149:156823d33999 1000 /* Check the trimming mode */
<> 149:156823d33999 1001 if (hopamp->Init.UserTrimming == OPAMP_TRIMMING_USER)
<> 149:156823d33999 1002 {
<> 149:156823d33999 1003 /* This fonction must called when OPAMP init parameter "UserTrimming" */
<> 149:156823d33999 1004 /* is set to trimming factory, and before OPAMP calibration (function */
<> 149:156823d33999 1005 /* "HAL_OPAMP_SelfCalibrate()"). */
<> 149:156823d33999 1006 /* Otherwise, factory triming value cannot be retrieved and error */
<> 149:156823d33999 1007 /* status is returned. */
<> 149:156823d33999 1008 trimmingvalue = OPAMP_FACTORYTRIMMING_DUMMY;
<> 149:156823d33999 1009 }
<> 149:156823d33999 1010 else
<> 149:156823d33999 1011 {
<> 149:156823d33999 1012 /* Select trimming settings depending on power mode */
<> 149:156823d33999 1013 if (hopamp->Init.PowerMode == OPAMP_POWERMODE_NORMAL)
<> 149:156823d33999 1014 {
<> 149:156823d33999 1015 tmp_opamp_reg_trimming = &OPAMP->OTR;
<> 149:156823d33999 1016 }
<> 149:156823d33999 1017 else
<> 149:156823d33999 1018 {
<> 149:156823d33999 1019 tmp_opamp_reg_trimming = &OPAMP->LPOTR;
<> 149:156823d33999 1020 }
<> 149:156823d33999 1021
<> 149:156823d33999 1022 /* Get factory trimming */
<> 149:156823d33999 1023 trimmingvalue = ((*tmp_opamp_reg_trimming >> OPAMP_OFFSET_TRIM_BITSPOSITION(hopamp, trimmingoffset)) & OPAMP_TRIM_VALUE_MASK);
<> 149:156823d33999 1024 }
<> 149:156823d33999 1025 }
<> 149:156823d33999 1026
<> 149:156823d33999 1027 return trimmingvalue;
<> 149:156823d33999 1028 }
<> 149:156823d33999 1029
<> 149:156823d33999 1030 /**
<> 149:156823d33999 1031 * @}
<> 149:156823d33999 1032 */
<> 149:156823d33999 1033
<> 149:156823d33999 1034
<> 149:156823d33999 1035 /** @defgroup OPAMP_Exported_Functions_Group4 Peripheral State functions
<> 149:156823d33999 1036 * @brief Peripheral State functions
<> 149:156823d33999 1037 *
<> 149:156823d33999 1038 @verbatim
<> 149:156823d33999 1039 ===============================================================================
<> 149:156823d33999 1040 ##### Peripheral State functions #####
<> 149:156823d33999 1041 ===============================================================================
<> 149:156823d33999 1042 [..]
<> 149:156823d33999 1043 This subsection permit to get in run-time the status of the peripheral.
<> 149:156823d33999 1044
<> 149:156823d33999 1045 @endverbatim
<> 149:156823d33999 1046 * @{
<> 149:156823d33999 1047 */
<> 149:156823d33999 1048
<> 149:156823d33999 1049 /**
<> 149:156823d33999 1050 * @brief Return the OPAMP state
<> 149:156823d33999 1051 * @param hopamp : OPAMP handle
<> 149:156823d33999 1052 * @retval HAL state
<> 149:156823d33999 1053 */
<> 149:156823d33999 1054 HAL_OPAMP_StateTypeDef HAL_OPAMP_GetState(OPAMP_HandleTypeDef* hopamp)
<> 149:156823d33999 1055 {
<> 149:156823d33999 1056 /* Check the OPAMP handle allocation */
<> 149:156823d33999 1057 if(hopamp == NULL)
<> 149:156823d33999 1058 {
<> 149:156823d33999 1059 return HAL_OPAMP_STATE_RESET;
<> 149:156823d33999 1060 }
<> 149:156823d33999 1061
<> 149:156823d33999 1062 /* Check the parameter */
<> 149:156823d33999 1063 assert_param(IS_OPAMP_ALL_INSTANCE(hopamp->Instance));
<> 149:156823d33999 1064
<> 149:156823d33999 1065 return hopamp->State;
<> 149:156823d33999 1066 }
<> 149:156823d33999 1067
<> 149:156823d33999 1068 /**
<> 149:156823d33999 1069 * @}
<> 149:156823d33999 1070 */
<> 149:156823d33999 1071
<> 149:156823d33999 1072 /**
<> 149:156823d33999 1073 * @}
<> 149:156823d33999 1074 */
<> 149:156823d33999 1075
<> 149:156823d33999 1076 #endif /* STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX || STM32L162xC || STM32L152xC || STM32L151xC */
<> 149:156823d33999 1077
<> 149:156823d33999 1078 #endif /* HAL_OPAMP_MODULE_ENABLED */
<> 149:156823d33999 1079 /**
<> 149:156823d33999 1080 * @}
<> 149:156823d33999 1081 */
<> 149:156823d33999 1082
<> 149:156823d33999 1083 /**
<> 149:156823d33999 1084 * @}
<> 149:156823d33999 1085 */
<> 149:156823d33999 1086
<> 149:156823d33999 1087 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/