STM32L443xx HAL User Manual
stm32l4xx_hal_opamp.c
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32l4xx_hal_opamp.c
00004   * @author  MCD Application Team
00005   * @brief   OPAMP HAL module driver.
00006   *          This file provides firmware functions to manage the following
00007   *          functionalities of the operational amplifier(s) peripheral:
00008   *           + Initialization and de-initialization functions
00009   *           + IO operation functions
00010   *           + Peripheral Control functions
00011   *           + Peripheral State functions
00012   *
00013   ******************************************************************************
00014   * @attention
00015   *
00016   * Copyright (c) 2017 STMicroelectronics.
00017   * All rights reserved.
00018   *
00019   * This software is licensed under terms that can be found in the LICENSE file
00020   * in the root directory of this software component.
00021   * If no LICENSE file comes with this software, it is provided AS-IS.
00022   *
00023   ******************************************************************************
00024   @verbatim
00025 ================================================================================
00026           ##### OPAMP Peripheral Features #####
00027 ================================================================================
00028 
00029   [..] The device integrates 1 or 2 operational amplifiers OPAMP1 & OPAMP2
00030 
00031        (#) The OPAMP(s) provide(s) several exclusive running modes.
00032        (++) 1 OPAMP: STM32L412xx STM32L422xx STM32L431xx STM32L432xx STM32L433xx STM32L442xx STM32L443xx
00033        (++) 2 OPAMP: STM32L471xx STM32L475xx STM32L476xx STM32L485xx STM32L486xx
00034 
00035        (#) The OPAMP(s) provide(s) several exclusive running modes.
00036        (++) Standalone mode
00037        (++) Programmable Gain Amplifier (PGA) mode (Resistor feedback output)
00038        (++) Follower mode
00039 
00040        (#) All OPAMP (same for all OPAMPs) can operate in
00041        (++) Either Low range (VDDA < 2.4V) power supply
00042        (++) Or High range (VDDA > 2.4V) power supply
00043 
00044        (#) Each OPAMP(s) can be configured in normal and low power mode.
00045 
00046        (#) The OPAMP(s) provide(s) calibration capabilities.
00047        (++) Calibration aims at correcting some offset for running mode.
00048        (++) The OPAMP uses either factory calibration settings OR user defined
00049            calibration (trimming) settings (i.e. trimming mode).
00050        (++) The user defined settings can be figured out using self calibration
00051            handled by HAL_OPAMP_SelfCalibrate, HAL_OPAMPEx_SelfCalibrateAll
00052        (++) HAL_OPAMP_SelfCalibrate:
00053        (+++) Runs automatically the calibration.
00054        (+++) Enables the user trimming mode
00055        (+++) Updates the init structure with trimming values with fresh calibration
00056             results.
00057             The user may store the calibration results for larger
00058             (ex monitoring the trimming as a function of temperature
00059             for instance)
00060        (+++) HAL_OPAMPEx_SelfCalibrateAll
00061             runs calibration of all OPAMPs in parallel to save search time.
00062 
00063        (#) Running mode: Standalone mode
00064        (++) Gain is set externally (gain depends on external loads).
00065        (++) Follower mode also possible externally by connecting the inverting input to
00066            the output.
00067 
00068        (#) Running mode: Follower mode
00069        (++) No Inverting Input is connected.
00070 
00071        (#) Running mode: Programmable Gain Amplifier (PGA) mode
00072            (Resistor feedback output)
00073        (++) The OPAMP(s) output(s) can be internally connected to resistor feedback
00074            output.
00075        (++) OPAMP gain is either 2, 4, 8 or 16.
00076 
00077        (#) The OPAMPs inverting input can be selected according to the Reference Manual
00078            "OPAMP function description" chapter.
00079 
00080        (#) The OPAMPs non inverting input can be selected according to the Reference Manual
00081            "OPAMP function description" chapter.
00082 
00083 
00084             ##### How to use this driver #####
00085 ================================================================================
00086   [..]
00087 
00088     *** Power supply range ***
00089     ============================================
00090     [..] To run in low power mode:
00091 
00092       (#) Configure the OPAMP using HAL_OPAMP_Init() function:
00093       (++) Select OPAMP_POWERSUPPLY_LOW (VDDA lower than 2.4V)
00094       (++) Otherwise select OPAMP_POWERSUPPLY_HIGH (VDDA higher than 2.4V)
00095 
00096     *** Low / normal power mode ***
00097     ============================================
00098     [..] To run in low power mode:
00099 
00100       (#) Configure the OPAMP using HAL_OPAMP_Init() function:
00101       (++) Select OPAMP_POWERMODE_LOWPOWER
00102       (++) Otherwise select OPAMP_POWERMODE_NORMALPOWER
00103 
00104     *** Calibration ***
00105     ============================================
00106     [..] To run the OPAMP calibration self calibration:
00107 
00108       (#) Start calibration using HAL_OPAMP_SelfCalibrate.
00109            Store the calibration results.
00110 
00111     *** Running mode ***
00112     ============================================
00113 
00114     [..] To use the OPAMP, perform the following steps:
00115 
00116       (#) Fill in the HAL_OPAMP_MspInit() to
00117       (++) Enable the OPAMP Peripheral clock using macro __HAL_RCC_OPAMP_CLK_ENABLE()
00118       (++) Configure the OPAMP input AND output in analog mode using
00119            HAL_GPIO_Init() to map the OPAMP output to the GPIO pin.
00120 
00121       (#) Registrate Callbacks
00122       (++) The compilation define  USE_HAL_OPAMP_REGISTER_CALLBACKS when set to 1
00123            allows the user to configure dynamically the driver callbacks.
00124 
00125       (++) Use Functions HAL_OPAMP_RegisterCallback() to register a user callback,
00126            it allows to register following callbacks:
00127       (+++) MspInitCallback         : OPAMP MspInit.
00128       (+++) MspDeInitCallback       : OPAMP MspFeInit.
00129            This function takes as parameters the HAL peripheral handle, the Callback ID
00130            and a pointer to the user callback function.
00131 
00132       (++) Use function HAL_OPAMP_UnRegisterCallback() to reset a callback to the default
00133            weak (surcharged) function. It allows to reset following callbacks:
00134       (+++) MspInitCallback         : OPAMP MspInit.
00135       (+++) MspDeInitCallback       : OPAMP MspdeInit.
00136       (+++) All Callbacks
00137 
00138       (#) Configure the OPAMP using HAL_OPAMP_Init() function:
00139       (++) Select the mode
00140       (++) Select the inverting input
00141       (++) Select the non-inverting input
00142       (++) If PGA mode is enabled, Select if inverting input is connected.
00143       (++) Select either factory or user defined trimming mode.
00144       (++) If the user-defined trimming mode is enabled, select PMOS & NMOS trimming values
00145           (typically values set by HAL_OPAMP_SelfCalibrate function).
00146 
00147       (#) Enable the OPAMP using HAL_OPAMP_Start() function.
00148 
00149       (#) Disable the OPAMP using HAL_OPAMP_Stop() function.
00150 
00151       (#) Lock the OPAMP in running mode using HAL_OPAMP_Lock() function.
00152           Caution: On STM32L4, HAL OPAMP lock is software lock only (not
00153           hardware lock as on some other STM32 devices)
00154 
00155       (#) If needed, unlock the OPAMP using HAL_OPAMPEx_Unlock() function.
00156 
00157     *** Running mode: change of configuration while OPAMP ON  ***
00158     ============================================
00159     [..] To Re-configure OPAMP when OPAMP is ON (change on the fly)
00160       (#) If needed, fill in the HAL_OPAMP_MspInit()
00161       (++) This is the case for instance if you wish to use new OPAMP I/O
00162 
00163       (#) Configure the OPAMP using HAL_OPAMP_Init() function:
00164       (++) As in configure case, select first the parameters you wish to modify.
00165 
00166       (#) Change from low power mode to normal power mode (& vice versa) requires
00167           first HAL_OPAMP_DeInit() (force OPAMP OFF) and then HAL_OPAMP_Init().
00168           In other words, of OPAMP is ON, HAL_OPAMP_Init can NOT change power mode
00169           alone.
00170 
00171   @endverbatim
00172   ******************************************************************************
00173 
00174       Table 1.  OPAMPs inverting/non-inverting inputs for the STM32L4 devices:
00175       +------------------------------------------------------------------------|
00176       |                 |         | OPAMP1               | OPAMP2              |
00177       |-----------------|---------|----------------------|---------------------|
00178       | Inverting Input | VM_SEL  |                      |                     |
00179       |                 |         |  IO0-> PA1           | IO0-> PA7           |
00180       |                 |         |  LOW LEAKAGE IO (2)  | LOW LEAKAGE IO (2)  |
00181       |                 |         |  Not connected       | Not connected       |
00182       | (1)             |         |    PGA mode only     |   PGA mode only     |
00183       |-----------------|---------|----------------------|---------------------|
00184       |  Non Inverting  | VP_SEL  |                      |                     |
00185       |                 |         |  IO0-> PA0 (GPIO)    | IO0-> PA6  (GPIO)   |
00186       |    Input        |         |  DAC1_OUT1 internal  | DAC1_OUT2 internal  |
00187       +------------------------------------------------------------------------|
00188        (1): NA in follower mode.
00189        (2): Available on some package only (ex. BGA132).
00190 
00191 
00192       Table 2.  OPAMPs outputs for the STM32L4 devices:
00193 
00194       +-------------------------------------------------------------------------
00195       |                 |        | OPAMP1                | OPAMP2              |
00196       |-----------------|--------|-----------------------|---------------------|
00197       | Output          |  VOUT  |  PA3                  |  PB0                |
00198       |                 |        |  & (1) ADC12_IN if    | & (1) ADC12_IN if   |
00199       |                 |        |  connected internally | connected internally|
00200       |-----------------|--------|-----------------------|---------------------|
00201        (1): ADC1 or ADC2 shall select IN15.
00202 
00203   */
00204 
00205 /* Includes ------------------------------------------------------------------*/
00206 #include "stm32l4xx_hal.h"
00207 
00208 /** @addtogroup STM32L4xx_HAL_Driver
00209   * @{
00210   */
00211 
00212 /** @defgroup OPAMP OPAMP
00213   * @brief OPAMP module driver
00214   * @{
00215   */
00216 
00217 #ifdef HAL_OPAMP_MODULE_ENABLED
00218 
00219 /* Private types -------------------------------------------------------------*/
00220 /* Private variables ---------------------------------------------------------*/
00221 /* Private constants ---------------------------------------------------------*/
00222 /** @addtogroup OPAMP_Private_Constants
00223   * @{
00224   */
00225 
00226 /* CSR register reset value */
00227 #define OPAMP_CSR_RESET_VALUE             ((uint32_t)0x00000000)
00228 
00229 #define OPAMP_CSR_RESET_BITS    (OPAMP_CSR_OPAMPxEN | OPAMP_CSR_OPALPM | OPAMP_CSR_OPAMODE \
00230                                | OPAMP_CSR_PGGAIN | OPAMP_CSR_VMSEL | OPAMP_CSR_VPSEL \
00231                                | OPAMP_CSR_CALON | OPAMP_CSR_USERTRIM)
00232 
00233 /* CSR Init masks */
00234 #define OPAMP_CSR_INIT_MASK_PGA (OPAMP_CSR_OPALPM | OPAMP_CSR_OPAMODE| OPAMP_CSR_PGGAIN \
00235                                | OPAMP_CSR_VMSEL | OPAMP_CSR_VPSEL | OPAMP_CSR_USERTRIM)
00236 
00237 #define OPAMP_CSR_INIT_MASK_FOLLOWER (OPAMP_CSR_OPALPM | OPAMP_CSR_OPAMODE| OPAMP_CSR_VPSEL \
00238                                     | OPAMP_CSR_USERTRIM)
00239 
00240 #define OPAMP_CSR_INIT_MASK_STANDALONE (OPAMP_CSR_OPALPM | OPAMP_CSR_OPAMODE| OPAMP_CSR_VPSEL \
00241                                       | OPAMP_CSR_VMSEL | OPAMP_CSR_USERTRIM)
00242 
00243 
00244 /**
00245   * @}
00246   */
00247 
00248 /* Private macros ------------------------------------------------------------*/
00249 /* Private functions ---------------------------------------------------------*/
00250 /* Exported functions --------------------------------------------------------*/
00251 
00252 /** @defgroup OPAMP_Exported_Functions OPAMP Exported Functions
00253   * @{
00254   */
00255 
00256 /** @defgroup OPAMP_Exported_Functions_Group1 Initialization and de-initialization functions
00257  *  @brief    Initialization and Configuration functions
00258  *
00259 @verbatim
00260   ==============================================================================
00261               ##### Initialization and de-initialization functions #####
00262   ==============================================================================
00263 
00264 @endverbatim
00265   * @{
00266   */
00267 
00268 /**
00269   * @brief  Initializes the OPAMP according to the specified
00270   *         parameters in the OPAMP_InitTypeDef and initialize the associated handle.
00271   * @note   If the selected opamp is locked, initialization can't be performed.
00272   *         To unlock the configuration, perform a system reset.
00273   * @param  hopamp OPAMP handle
00274   * @retval HAL status
00275   */
00276 HAL_StatusTypeDef HAL_OPAMP_Init(OPAMP_HandleTypeDef *hopamp)
00277 {
00278   HAL_StatusTypeDef status = HAL_OK;
00279   uint32_t updateotrlpotr;
00280 
00281   /* Check the OPAMP handle allocation and lock status */
00282   /* Init not allowed if calibration is ongoing */
00283   if(hopamp == NULL)
00284   {
00285     return HAL_ERROR;
00286   }
00287   else if(hopamp->State == HAL_OPAMP_STATE_BUSYLOCKED)
00288   {
00289     return HAL_ERROR;
00290   }
00291   else if(hopamp->State == HAL_OPAMP_STATE_CALIBBUSY)
00292   {
00293     return HAL_ERROR;
00294   }
00295   else
00296   {
00297     /* Check the parameter */
00298     assert_param(IS_OPAMP_ALL_INSTANCE(hopamp->Instance));
00299 
00300     /* Set OPAMP parameters */
00301     assert_param(IS_OPAMP_POWER_SUPPLY_RANGE(hopamp->Init.PowerSupplyRange));
00302     assert_param(IS_OPAMP_POWERMODE(hopamp->Init.PowerMode));
00303     assert_param(IS_OPAMP_FUNCTIONAL_NORMALMODE(hopamp->Init.Mode));
00304     assert_param(IS_OPAMP_NONINVERTING_INPUT(hopamp->Init.NonInvertingInput));
00305 
00306 #if (USE_HAL_OPAMP_REGISTER_CALLBACKS == 1)
00307     if(hopamp->State == HAL_OPAMP_STATE_RESET)
00308     {
00309       if(hopamp->MspInitCallback == NULL)
00310       {
00311         hopamp->MspInitCallback               = HAL_OPAMP_MspInit;
00312       }
00313     }
00314 #endif /* USE_HAL_OPAMP_REGISTER_CALLBACKS */
00315 
00316     if ((hopamp->Init.Mode) == OPAMP_STANDALONE_MODE)
00317     {
00318       assert_param(IS_OPAMP_INVERTING_INPUT_STANDALONE(hopamp->Init.InvertingInput));
00319     }
00320 
00321     if ((hopamp->Init.Mode) == OPAMP_PGA_MODE)
00322     {
00323       assert_param(IS_OPAMP_INVERTING_INPUT_PGA(hopamp->Init.InvertingInput));
00324     }
00325 
00326     if ((hopamp->Init.Mode) == OPAMP_PGA_MODE)
00327     {
00328       assert_param(IS_OPAMP_PGA_GAIN(hopamp->Init.PgaGain));
00329     }
00330 
00331     assert_param(IS_OPAMP_TRIMMING(hopamp->Init.UserTrimming));
00332     if ((hopamp->Init.UserTrimming) == OPAMP_TRIMMING_USER)
00333     {
00334       if (hopamp->Init.PowerMode == OPAMP_POWERMODE_NORMALPOWER)
00335       {
00336         assert_param(IS_OPAMP_TRIMMINGVALUE(hopamp->Init.TrimmingValueP));
00337         assert_param(IS_OPAMP_TRIMMINGVALUE(hopamp->Init.TrimmingValueN));
00338       }
00339     else
00340       {
00341         assert_param(IS_OPAMP_TRIMMINGVALUE(hopamp->Init.TrimmingValuePLowPower));
00342         assert_param(IS_OPAMP_TRIMMINGVALUE(hopamp->Init.TrimmingValueNLowPower));
00343       }
00344     }
00345 
00346     if(hopamp->State == HAL_OPAMP_STATE_RESET)
00347     {
00348       /* Allocate lock resource and initialize it */
00349       hopamp->Lock = HAL_UNLOCKED;
00350     }
00351 
00352 #if (USE_HAL_OPAMP_REGISTER_CALLBACKS == 1)
00353     hopamp->MspInitCallback(hopamp);
00354 #else
00355     /* Call MSP init function */
00356     HAL_OPAMP_MspInit(hopamp);
00357 #endif /* USE_HAL_OPAMP_REGISTER_CALLBACKS */
00358 
00359     /* Set operating mode */
00360     CLEAR_BIT(hopamp->Instance->CSR, OPAMP_CSR_CALON);
00361 
00362     if (hopamp->Init.Mode == OPAMP_PGA_MODE)
00363     {
00364       MODIFY_REG(hopamp->Instance->CSR, OPAMP_CSR_INIT_MASK_PGA, \
00365                                         hopamp->Init.PowerMode | \
00366                                         hopamp->Init.Mode | \
00367                                         hopamp->Init.PgaGain | \
00368                                         hopamp->Init.InvertingInput    | \
00369                                         hopamp->Init.NonInvertingInput | \
00370                                         hopamp->Init.UserTrimming);
00371     }
00372 
00373     if (hopamp->Init.Mode == OPAMP_FOLLOWER_MODE)
00374     {
00375     /* In Follower mode InvertingInput is Not Applicable  */
00376     MODIFY_REG(hopamp->Instance->CSR, OPAMP_CSR_INIT_MASK_FOLLOWER, \
00377                                         hopamp->Init.PowerMode | \
00378                                         hopamp->Init.Mode | \
00379                                         hopamp->Init.NonInvertingInput | \
00380                                         hopamp->Init.UserTrimming);
00381     }
00382 
00383     if (hopamp->Init.Mode == OPAMP_STANDALONE_MODE)
00384     {
00385       MODIFY_REG(hopamp->Instance->CSR, OPAMP_CSR_INIT_MASK_STANDALONE, \
00386                                         hopamp->Init.PowerMode | \
00387                                         hopamp->Init.Mode | \
00388                                         hopamp->Init.InvertingInput    | \
00389                                         hopamp->Init.NonInvertingInput | \
00390                                         hopamp->Init.UserTrimming);
00391     }
00392 
00393     if (hopamp->Init.UserTrimming == OPAMP_TRIMMING_USER)
00394     {
00395       /* Set power mode and associated calibration parameters */
00396       if (hopamp->Init.PowerMode != OPAMP_POWERMODE_LOWPOWER)
00397       {
00398         /* OPAMP_POWERMODE_NORMALPOWER */
00399         /* Set calibration mode (factory or user) and values for            */
00400         /* transistors differential pair high (PMOS) and low (NMOS) for     */
00401         /* normal mode.                                                     */
00402         updateotrlpotr = (((hopamp->Init.TrimmingValueP) << (OPAMP_INPUT_NONINVERTING)) \
00403                          | (hopamp->Init.TrimmingValueN));
00404         MODIFY_REG(hopamp->Instance->OTR, OPAMP_OTR_TRIMOFFSETN | OPAMP_OTR_TRIMOFFSETP, updateotrlpotr);
00405       }
00406       else
00407       {
00408         /* OPAMP_POWERMODE_LOWPOWER */
00409         /* transistors differential pair high (PMOS) and low (NMOS) for     */
00410         /* low power mode.                                                     */
00411         updateotrlpotr = (((hopamp->Init.TrimmingValuePLowPower) << (OPAMP_INPUT_NONINVERTING)) \
00412                          | (hopamp->Init.TrimmingValueNLowPower));
00413         MODIFY_REG(hopamp->Instance->LPOTR, OPAMP_OTR_TRIMOFFSETN | OPAMP_OTR_TRIMOFFSETP, updateotrlpotr);
00414       }
00415     }
00416 
00417     /* Configure the power supply range */
00418     /* The OPAMP_CSR_OPARANGE is common configuration for all OPAMPs */
00419     /* bit OPAMP1_CSR_OPARANGE is used for both OPAMPs */
00420     MODIFY_REG(OPAMP1->CSR, OPAMP1_CSR_OPARANGE, hopamp->Init.PowerSupplyRange);
00421 
00422     /* Update the OPAMP state*/
00423     if (hopamp->State == HAL_OPAMP_STATE_RESET)
00424     {
00425       /* From RESET state to READY State */
00426       hopamp->State = HAL_OPAMP_STATE_READY;
00427     }
00428     /* else: remain in READY or BUSY state (no update) */
00429     return status;
00430   }
00431 }
00432 
00433 /**
00434   * @brief  DeInitialize the OPAMP peripheral.
00435   * @note   Deinitialization can be performed if the OPAMP configuration is locked.
00436   *         (the lock is SW in L4)
00437   * @param  hopamp OPAMP handle
00438   * @retval HAL status
00439   */
00440 HAL_StatusTypeDef HAL_OPAMP_DeInit(OPAMP_HandleTypeDef *hopamp)
00441 {
00442   HAL_StatusTypeDef status = HAL_OK;
00443 
00444   /* Check the OPAMP handle allocation */
00445   /* DeInit not allowed if calibration is ongoing */
00446   if(hopamp == NULL)
00447   {
00448     status = HAL_ERROR;
00449   }
00450   else if(hopamp->State == HAL_OPAMP_STATE_CALIBBUSY)
00451   {
00452     status = HAL_ERROR;
00453   }
00454   else
00455   {
00456     /* Check the parameter */
00457     assert_param(IS_OPAMP_ALL_INSTANCE(hopamp->Instance));
00458 
00459     /* Set OPAMP_CSR register to reset value */
00460     /* Mind that OPAMP1_CSR_OPARANGE of CSR of OPAMP1 remains unchanged (applies to both OPAMPs) */
00461     /* OPAMP shall be disabled first separately */
00462     CLEAR_BIT(hopamp->Instance->CSR, OPAMP_CSR_OPAMPxEN);
00463     MODIFY_REG(hopamp->Instance->CSR, OPAMP_CSR_RESET_BITS, OPAMP_CSR_RESET_VALUE);
00464 
00465 #if (USE_HAL_OPAMP_REGISTER_CALLBACKS == 1)
00466   if(hopamp->MspDeInitCallback == NULL)
00467   {
00468     hopamp->MspDeInitCallback = HAL_OPAMP_MspDeInit;
00469   }
00470   /* DeInit the low level hardware */
00471   hopamp->MspDeInitCallback(hopamp);
00472 #else
00473     /* DeInit the low level hardware: GPIO, CLOCK and NVIC */
00474     HAL_OPAMP_MspDeInit(hopamp);
00475 #endif /* USE_HAL_OPAMP_REGISTER_CALLBACKS */
00476     /* Update the OPAMP state*/
00477     hopamp->State = HAL_OPAMP_STATE_RESET;
00478 
00479     /* Process unlocked */
00480     __HAL_UNLOCK(hopamp);
00481   }
00482   return status;
00483 }
00484 
00485 /**
00486   * @brief  Initialize the OPAMP MSP.
00487   * @param  hopamp OPAMP handle
00488   * @retval None
00489   */
00490 __weak void HAL_OPAMP_MspInit(OPAMP_HandleTypeDef *hopamp)
00491 {
00492   /* Prevent unused argument(s) compilation warning */
00493   UNUSED(hopamp);
00494 
00495   /* NOTE : This function should not be modified, when the callback is needed,
00496             the function "HAL_OPAMP_MspInit()" must be implemented in the user file.
00497    */
00498 }
00499 
00500 /**
00501   * @brief  DeInitialize OPAMP MSP.
00502   * @param  hopamp OPAMP handle
00503   * @retval None
00504   */
00505 __weak void HAL_OPAMP_MspDeInit(OPAMP_HandleTypeDef *hopamp)
00506 {
00507   /* Prevent unused argument(s) compilation warning */
00508   UNUSED(hopamp);
00509 
00510   /* NOTE : This function should not be modified, when the callback is needed,
00511             the function "HAL_OPAMP_MspDeInit()" must be implemented in the user file.
00512    */
00513 }
00514 
00515 /**
00516   * @}
00517   */
00518 
00519 
00520 /** @defgroup OPAMP_Exported_Functions_Group2 IO operation functions
00521  *  @brief   IO operation functions
00522  *
00523 @verbatim
00524  ===============================================================================
00525                         ##### IO operation functions #####
00526  ===============================================================================
00527     [..]
00528     This subsection provides a set of functions allowing to manage the OPAMP
00529     start, stop and calibration actions.
00530 
00531 @endverbatim
00532   * @{
00533   */
00534 
00535 /**
00536   * @brief  Start the OPAMP.
00537   * @param  hopamp OPAMP handle
00538   * @retval HAL status
00539   */
00540 
00541 HAL_StatusTypeDef HAL_OPAMP_Start(OPAMP_HandleTypeDef *hopamp)
00542 {
00543   HAL_StatusTypeDef status = HAL_OK;
00544 
00545   /* Check the OPAMP handle allocation */
00546   /* Check if OPAMP locked */
00547   if(hopamp == NULL)
00548   {
00549     status = HAL_ERROR;
00550   }
00551   else if(hopamp->State == HAL_OPAMP_STATE_BUSYLOCKED)
00552   {
00553     status = HAL_ERROR;
00554   }
00555   else
00556   {
00557     /* Check the parameter */
00558     assert_param(IS_OPAMP_ALL_INSTANCE(hopamp->Instance));
00559 
00560     if(hopamp->State == HAL_OPAMP_STATE_READY)
00561     {
00562       /* Enable the selected opamp */
00563       SET_BIT (hopamp->Instance->CSR, OPAMP_CSR_OPAMPxEN);
00564 
00565       /* Update the OPAMP state*/
00566       /* From HAL_OPAMP_STATE_READY to HAL_OPAMP_STATE_BUSY */
00567       hopamp->State = HAL_OPAMP_STATE_BUSY;
00568     }
00569     else
00570     {
00571       status = HAL_ERROR;
00572     }
00573 
00574    }
00575   return status;
00576 }
00577 
00578 /**
00579   * @brief  Stop the OPAMP.
00580   * @param  hopamp OPAMP handle
00581   * @retval HAL status
00582   */
00583 HAL_StatusTypeDef HAL_OPAMP_Stop(OPAMP_HandleTypeDef *hopamp)
00584 {
00585   HAL_StatusTypeDef status = HAL_OK;
00586 
00587   /* Check the OPAMP handle allocation */
00588   /* Check if OPAMP locked */
00589   /* Check if OPAMP calibration ongoing */
00590   if(hopamp == NULL)
00591   {
00592     status = HAL_ERROR;
00593   }
00594   else if(hopamp->State == HAL_OPAMP_STATE_BUSYLOCKED)
00595   {
00596     status = HAL_ERROR;
00597   }
00598   else if(hopamp->State == HAL_OPAMP_STATE_CALIBBUSY)
00599   {
00600     status = HAL_ERROR;
00601   }
00602   else
00603   {
00604     /* Check the parameter */
00605     assert_param(IS_OPAMP_ALL_INSTANCE(hopamp->Instance));
00606 
00607     if(hopamp->State == HAL_OPAMP_STATE_BUSY)
00608     {
00609       /* Disable the selected opamp */
00610       CLEAR_BIT (hopamp->Instance->CSR, OPAMP_CSR_OPAMPxEN);
00611 
00612       /* Update the OPAMP state*/
00613       /* From  HAL_OPAMP_STATE_BUSY to HAL_OPAMP_STATE_READY*/
00614       hopamp->State = HAL_OPAMP_STATE_READY;
00615     }
00616     else
00617     {
00618       status = HAL_ERROR;
00619     }
00620   }
00621   return status;
00622 }
00623 
00624 /**
00625   * @brief  Run the self calibration of one OPAMP.
00626   * @note   Calibration is performed in the mode specified in OPAMP init
00627   *         structure (mode normal or low-power). To perform calibration for
00628   *         both modes, repeat this function twice after OPAMP init structure
00629   *         accordingly updated.
00630   * @note   Calibration runs about 10 ms.
00631   * @param  hopamp handle
00632   * @retval Updated offset trimming values (PMOS & NMOS), user trimming is enabled
00633   * @retval HAL status
00634 
00635   */
00636 
00637 HAL_StatusTypeDef HAL_OPAMP_SelfCalibrate(OPAMP_HandleTypeDef *hopamp)
00638 {
00639 
00640   HAL_StatusTypeDef status = HAL_OK;
00641 
00642   uint32_t trimmingvaluen;
00643   uint32_t trimmingvaluep;
00644   uint32_t delta;
00645   uint32_t opampmode;
00646 
00647   __IO uint32_t* tmp_opamp_reg_trimming;   /* Selection of register of trimming depending on power mode: OTR or LPOTR */
00648 
00649   /* Check the OPAMP handle allocation */
00650   /* Check if OPAMP locked */
00651   if(hopamp == NULL)
00652   {
00653     status = HAL_ERROR;
00654   }
00655   else if(hopamp->State == HAL_OPAMP_STATE_BUSYLOCKED)
00656   {
00657     status = HAL_ERROR;
00658   }
00659   else
00660   {
00661     /* Check if OPAMP in calibration mode and calibration not yet enable */
00662     if(hopamp->State ==  HAL_OPAMP_STATE_READY)
00663     {
00664       /* Check the parameter */
00665       assert_param(IS_OPAMP_ALL_INSTANCE(hopamp->Instance));
00666       assert_param(IS_OPAMP_POWERMODE(hopamp->Init.PowerMode));
00667 
00668       /* Save OPAMP mode as in                                       */
00669       /* STM32L471xx STM32L475xx STM32L476xx STM32L485xx STM32L486xx */
00670       /* the calibration is not working in PGA mode                  */
00671       opampmode = READ_BIT(hopamp->Instance->CSR,OPAMP_CSR_OPAMODE);
00672 
00673       /* Use of standalone mode */
00674       MODIFY_REG(hopamp->Instance->CSR, OPAMP_CSR_OPAMODE, OPAMP_STANDALONE_MODE);
00675 
00676       /*  user trimming values are used for offset calibration */
00677       SET_BIT(hopamp->Instance->CSR, OPAMP_CSR_USERTRIM);
00678 
00679       /* Select trimming settings depending on power mode */
00680       if (hopamp->Init.PowerMode == OPAMP_POWERMODE_NORMALPOWER)
00681       {
00682         tmp_opamp_reg_trimming = &hopamp->Instance->OTR;
00683       }
00684       else
00685       {
00686         tmp_opamp_reg_trimming = &hopamp->Instance->LPOTR;
00687       }
00688 
00689       /* Enable calibration */
00690       SET_BIT (hopamp->Instance->CSR, OPAMP_CSR_CALON);
00691 
00692       /* 1st calibration - N */
00693       CLEAR_BIT (hopamp->Instance->CSR, OPAMP_CSR_CALSEL);
00694 
00695       /* Enable the selected opamp */
00696       SET_BIT (hopamp->Instance->CSR, OPAMP_CSR_OPAMPxEN);
00697 
00698       /* Init trimming counter */
00699       /* Medium value */
00700       trimmingvaluen = 16U;
00701       delta = 8U;
00702 
00703       while (delta != 0U)
00704       {
00705         /* Set candidate trimming */
00706         /* OPAMP_POWERMODE_NORMALPOWER */
00707         MODIFY_REG(*tmp_opamp_reg_trimming, OPAMP_OTR_TRIMOFFSETN, trimmingvaluen);
00708 
00709         /* OFFTRIMmax delay 1 ms as per datasheet (electrical characteristics */
00710         /* Offset trim time: during calibration, minimum time needed between */
00711         /* two steps to have 1 mV accuracy */
00712         HAL_Delay(OPAMP_TRIMMING_DELAY);
00713 
00714         if (READ_BIT(hopamp->Instance->CSR, OPAMP_CSR_CALOUT) != 0U)
00715         {
00716           /* OPAMP_CSR_CALOUT is HIGH try higher trimming */
00717           trimmingvaluen -= delta;
00718         }
00719         else
00720         {
00721           /* OPAMP_CSR_CALOUT is LOW try lower trimming */
00722           trimmingvaluen += delta;
00723         }
00724         /* Divide range by 2 to continue dichotomy sweep */
00725         delta >>= 1U;
00726       }
00727 
00728       /* Still need to check if right calibration is current value or one step below */
00729       /* Indeed the first value that causes the OUTCAL bit to change from 0 to 1  */
00730       /* Set candidate trimming */
00731       MODIFY_REG(*tmp_opamp_reg_trimming, OPAMP_OTR_TRIMOFFSETN, trimmingvaluen);
00732 
00733       /* OFFTRIMmax delay 1 ms as per datasheet (electrical characteristics */
00734       /* Offset trim time: during calibration, minimum time needed between */
00735       /* two steps to have 1 mV accuracy */
00736       HAL_Delay(OPAMP_TRIMMING_DELAY);
00737 
00738       if ((READ_BIT(hopamp->Instance->CSR, OPAMP_CSR_CALOUT)) == 0U)
00739       {
00740         /* Trimming value is actually one value more */
00741         trimmingvaluen++;
00742         /* Set right trimming */
00743         MODIFY_REG(*tmp_opamp_reg_trimming, OPAMP_OTR_TRIMOFFSETN, trimmingvaluen);
00744       }
00745 
00746       /* 2nd calibration - P */
00747       SET_BIT (hopamp->Instance->CSR, OPAMP_CSR_CALSEL);
00748 
00749       /* Init trimming counter */
00750       /* Medium value */
00751       trimmingvaluep = 16U;
00752       delta = 8U;
00753 
00754       while (delta != 0U)
00755       {
00756         /* Set candidate trimming */
00757         /* OPAMP_POWERMODE_NORMALPOWER */
00758         MODIFY_REG(*tmp_opamp_reg_trimming, OPAMP_OTR_TRIMOFFSETP, (trimmingvaluep<<OPAMP_INPUT_NONINVERTING));
00759 
00760         /* OFFTRIMmax delay 1 ms as per datasheet (electrical characteristics */
00761         /* Offset trim time: during calibration, minimum time needed between */
00762         /* two steps to have 1 mV accuracy */
00763         HAL_Delay(OPAMP_TRIMMING_DELAY);
00764 
00765         if (READ_BIT(hopamp->Instance->CSR, OPAMP_CSR_CALOUT) != 0U)
00766         {
00767           /* OPAMP_CSR_CALOUT is HIGH try higher trimming */
00768           trimmingvaluep += delta;
00769         }
00770         else
00771         {
00772           /* OPAMP_CSR_CALOUT  is LOW try lower trimming */
00773           trimmingvaluep -= delta;
00774         }
00775 
00776         /* Divide range by 2 to continue dichotomy sweep */
00777         delta >>= 1U;
00778       }
00779 
00780       /* Still need to check if right calibration is current value or one step below */
00781       /* Indeed the first value that causes the OUTCAL bit to change from 1 to 0  */
00782       /* Set candidate trimming */
00783       MODIFY_REG(*tmp_opamp_reg_trimming, OPAMP_OTR_TRIMOFFSETP, (trimmingvaluep<<OPAMP_INPUT_NONINVERTING));
00784 
00785       /* OFFTRIMmax delay 1 ms as per datasheet (electrical characteristics */
00786       /* Offset trim time: during calibration, minimum time needed between */
00787       /* two steps to have 1 mV accuracy */
00788       HAL_Delay(OPAMP_TRIMMING_DELAY);
00789 
00790       if (READ_BIT(hopamp->Instance->CSR, OPAMP_CSR_CALOUT) != 0U)
00791       {
00792         /* Trimming value is actually one value more */
00793         trimmingvaluep++;
00794         MODIFY_REG(*tmp_opamp_reg_trimming, OPAMP_OTR_TRIMOFFSETP, (trimmingvaluep<<OPAMP_INPUT_NONINVERTING));
00795       }
00796 
00797       /* Disable the OPAMP */
00798       CLEAR_BIT (hopamp->Instance->CSR, OPAMP_CSR_OPAMPxEN);
00799 
00800       /* Disable calibration & set normal mode (operating mode) */
00801       CLEAR_BIT (hopamp->Instance->CSR, OPAMP_CSR_CALON);
00802 
00803       /* Self calibration is successful  */
00804       /* Store calibration(user trimming) results in init structure. */
00805 
00806       /* Set user trimming mode */
00807       hopamp->Init.UserTrimming = OPAMP_TRIMMING_USER;
00808 
00809       /* Affect calibration parameters depending on mode normal/low power */
00810       if (hopamp->Init.PowerMode != OPAMP_POWERMODE_LOWPOWER)
00811       {
00812         /* Write calibration result N */
00813         hopamp->Init.TrimmingValueN = trimmingvaluen;
00814         /* Write calibration result P */
00815         hopamp->Init.TrimmingValueP = trimmingvaluep;
00816       }
00817       else
00818       {
00819         /* Write calibration result N */
00820         hopamp->Init.TrimmingValueNLowPower = trimmingvaluen;
00821         /* Write calibration result P */
00822         hopamp->Init.TrimmingValuePLowPower = trimmingvaluep;
00823       }
00824 
00825     /* Restore OPAMP mode after calibration */
00826     MODIFY_REG(hopamp->Instance->CSR, OPAMP_CSR_OPAMODE, opampmode);
00827     }
00828     else
00829     {
00830       /* OPAMP can not be calibrated from this mode */
00831       status = HAL_ERROR;
00832     }
00833   }
00834   return status;
00835 }
00836 
00837 /**
00838   * @}
00839   */
00840 
00841 /** @defgroup OPAMP_Exported_Functions_Group3 Peripheral Control functions
00842  *  @brief   Peripheral Control functions
00843  *
00844 @verbatim
00845  ===============================================================================
00846                       ##### Peripheral Control functions #####
00847  ===============================================================================
00848     [..]
00849     This subsection provides a set of functions allowing to control the OPAMP data
00850     transfers.
00851 
00852 
00853 
00854 @endverbatim
00855   * @{
00856   */
00857 
00858 /**
00859   * @brief  Lock the selected OPAMP configuration.
00860   * @note   On STM32L4, HAL OPAMP lock is software lock only (in
00861   *         contrast of hardware lock available on some other STM32
00862   *         devices).
00863   * @param  hopamp OPAMP handle
00864   * @retval HAL status
00865   */
00866 HAL_StatusTypeDef HAL_OPAMP_Lock(OPAMP_HandleTypeDef *hopamp)
00867 {
00868   HAL_StatusTypeDef status = HAL_OK;
00869 
00870   /* Check the OPAMP handle allocation */
00871   /* Check if OPAMP locked */
00872   /* OPAMP can be locked when enabled and running in normal mode */
00873   /*   It is meaningless otherwise */
00874   if(hopamp == NULL)
00875   {
00876     status = HAL_ERROR;
00877   }
00878   else if(hopamp->State == HAL_OPAMP_STATE_BUSY)
00879   {
00880     /* Check the parameter */
00881     assert_param(IS_OPAMP_ALL_INSTANCE(hopamp->Instance));
00882 
00883    /* OPAMP state changed to locked */
00884     hopamp->State = HAL_OPAMP_STATE_BUSYLOCKED;
00885   }
00886   else
00887   {
00888     status = HAL_ERROR;
00889   }
00890   return status;
00891 }
00892 
00893 /**
00894   * @brief  Return the OPAMP factory trimming value.
00895   * @note            On STM32L4 OPAMP, user can retrieve factory trimming if
00896   *                  OPAMP has never been set to user trimming before.
00897   *                  Therefore, this function must be called when OPAMP init
00898   *                  parameter "UserTrimming" is set to trimming factory,
00899   *                  and before OPAMP  calibration (function
00900   *                  "HAL_OPAMP_SelfCalibrate()").
00901   *                  Otherwise, factory trimming value cannot be retrieved and
00902   *                  error status is returned.
00903   * @param  hopamp : OPAMP handle
00904   * @param  trimmingoffset : Trimming offset (P or N)
00905   *         This parameter must be a value of @ref OPAMP_FactoryTrimming
00906   * @note   Calibration parameter retrieved is corresponding to the mode
00907   *         specified in OPAMP init structure (mode normal or low-power).
00908   *         To retrieve calibration parameters for both modes, repeat this
00909   *         function after OPAMP init structure accordingly updated.
00910   * @retval Trimming value (P or N): range: 0->31
00911   *         or OPAMP_FACTORYTRIMMING_DUMMY if trimming value is not available
00912   *
00913   */
00914 
00915 HAL_OPAMP_TrimmingValueTypeDef HAL_OPAMP_GetTrimOffset (OPAMP_HandleTypeDef *hopamp, uint32_t trimmingoffset)
00916 {
00917   HAL_OPAMP_TrimmingValueTypeDef trimmingvalue;
00918   __IO uint32_t* tmp_opamp_reg_trimming;  /* Selection of register of trimming depending on power mode: OTR or LPOTR */
00919 
00920   /* Check the OPAMP handle allocation */
00921   /* Value can be retrieved in HAL_OPAMP_STATE_READY state */
00922   if(hopamp == NULL)
00923   {
00924     return OPAMP_FACTORYTRIMMING_DUMMY;
00925   }
00926 
00927   /* Check the OPAMP handle allocation */
00928   /* Value can be retrieved in HAL_OPAMP_STATE_READY state */
00929   if(hopamp->State == HAL_OPAMP_STATE_READY)
00930   {
00931     /* Check the parameter */
00932     assert_param(IS_OPAMP_ALL_INSTANCE(hopamp->Instance));
00933     assert_param(IS_OPAMP_FACTORYTRIMMING(trimmingoffset));
00934     assert_param(IS_OPAMP_POWERMODE(hopamp->Init.PowerMode));
00935 
00936     /* Check the trimming mode */
00937     if (READ_BIT(hopamp->Instance->CSR,OPAMP_CSR_USERTRIM) != 0U)
00938     {
00939       /* This function must called when OPAMP init parameter "UserTrimming"   */
00940       /* is set to trimming factory, and before OPAMP calibration (function   */
00941       /* "HAL_OPAMP_SelfCalibrate()").                                        */
00942       /* Otherwise, factory trimming value cannot be retrieved and error       */
00943       /* status is returned.                                                  */
00944       trimmingvalue = OPAMP_FACTORYTRIMMING_DUMMY;
00945     }
00946     else
00947     {
00948       /* Select trimming settings depending on power mode */
00949       if (hopamp->Init.PowerMode == OPAMP_POWERMODE_NORMALPOWER)
00950       {
00951         tmp_opamp_reg_trimming = &OPAMP->OTR;
00952       }
00953       else
00954       {
00955         tmp_opamp_reg_trimming = &OPAMP->LPOTR;
00956       }
00957 
00958       /* Get factory trimming  */
00959       if (trimmingoffset == OPAMP_FACTORYTRIMMING_P)
00960       {
00961         /* OPAMP_FACTORYTRIMMING_P */
00962         trimmingvalue = ((*tmp_opamp_reg_trimming) & OPAMP_OTR_TRIMOFFSETP) >> OPAMP_INPUT_NONINVERTING;
00963       }
00964       else
00965       {
00966         /* OPAMP_FACTORYTRIMMING_N */
00967         trimmingvalue = (*tmp_opamp_reg_trimming) & OPAMP_OTR_TRIMOFFSETN;
00968       }
00969     }
00970   }
00971   else
00972   {
00973     return OPAMP_FACTORYTRIMMING_DUMMY;
00974   }
00975   return trimmingvalue;
00976 }
00977 
00978 /**
00979   * @}
00980   */
00981 
00982 
00983 /** @defgroup OPAMP_Exported_Functions_Group4 Peripheral State functions
00984  *  @brief   Peripheral State functions
00985  *
00986 @verbatim
00987  ===============================================================================
00988                       ##### Peripheral State functions #####
00989  ===============================================================================
00990     [..]
00991     This subsection permits to get in run-time the status of the peripheral.
00992 
00993 @endverbatim
00994   * @{
00995   */
00996 
00997 /**
00998   * @brief  Return the OPAMP handle state.
00999   * @param  hopamp : OPAMP handle
01000   * @retval HAL state
01001   */
01002 HAL_OPAMP_StateTypeDef HAL_OPAMP_GetState(OPAMP_HandleTypeDef *hopamp)
01003 {
01004   /* Check the OPAMP handle allocation */
01005   if(hopamp == NULL)
01006   {
01007     return HAL_OPAMP_STATE_RESET;
01008   }
01009 
01010   /* Check the parameter */
01011   assert_param(IS_OPAMP_ALL_INSTANCE(hopamp->Instance));
01012 
01013   /* Return OPAMP handle state */
01014   return hopamp->State;
01015 }
01016 
01017 /**
01018   * @}
01019   */
01020 
01021 #if (USE_HAL_OPAMP_REGISTER_CALLBACKS == 1)
01022 /**
01023   * @brief  Register a User OPAMP Callback
01024   *         To be used instead of the weak (surcharged) predefined callback
01025   * @param hopamp : OPAMP handle
01026   * @param CallbackID : ID of the callback to be registered
01027   *        This parameter can be one of the following values:
01028   *          @arg @ref HAL_OPAMP_MSPINIT_CB_ID       OPAMP MspInit callback ID
01029   *          @arg @ref HAL_OPAMP_MSPDEINIT_CB_ID     OPAMP MspDeInit callback ID
01030   * @param pCallback : pointer to the Callback function
01031   * @retval status
01032   */
01033 HAL_StatusTypeDef HAL_OPAMP_RegisterCallback (OPAMP_HandleTypeDef *hopamp, HAL_OPAMP_CallbackIDTypeDef CallbackID, pOPAMP_CallbackTypeDef pCallback)
01034 {
01035   HAL_StatusTypeDef status = HAL_OK;
01036 
01037   if(pCallback == NULL)
01038   {
01039     return HAL_ERROR;
01040   }
01041 
01042   /* Process locked */
01043   __HAL_LOCK(hopamp);
01044 
01045   if(hopamp->State == HAL_OPAMP_STATE_READY)
01046   {
01047     switch (CallbackID)
01048     {
01049     case HAL_OPAMP_MSPINIT_CB_ID :
01050       hopamp->MspInitCallback = pCallback;
01051       break;
01052     case HAL_OPAMP_MSPDEINIT_CB_ID :
01053       hopamp->MspDeInitCallback = pCallback;
01054       break;
01055     default :
01056       /* update return status */
01057       status =  HAL_ERROR;
01058       break;
01059     }
01060   }
01061   else if (hopamp->State == HAL_OPAMP_STATE_RESET)
01062   {
01063     switch (CallbackID)
01064     {
01065     case HAL_OPAMP_MSPINIT_CB_ID :
01066       hopamp->MspInitCallback = pCallback;
01067       break;
01068     case HAL_OPAMP_MSPDEINIT_CB_ID :
01069       hopamp->MspDeInitCallback = pCallback;
01070       break;
01071     default :
01072       /* update return status */
01073       status =  HAL_ERROR;
01074       break;
01075     }
01076   }
01077   else
01078   {
01079     /* update return status */
01080     status =  HAL_ERROR;
01081   }
01082 
01083   /* Release Lock */
01084   __HAL_UNLOCK(hopamp);
01085   return status;
01086 }
01087 
01088 /**
01089   * @brief  Unregister a User OPAMP Callback
01090   *         OPAMP Callback is redirected to the weak (surcharged) predefined callback
01091   * @param hopamp : OPAMP handle
01092   * @param CallbackID : ID of the callback to be unregistered
01093   *        This parameter can be one of the following values:
01094   *          @arg @ref HAL_OPAMP_MSPINIT_CB_ID              OPAMP MSP Init Callback ID
01095   *          @arg @ref HAL_OPAMP_MSPDEINIT_CB_ID            OPAMP MSP DeInit Callback ID
01096   *          @arg @ref HAL_OPAMP_ALL_CB_ID                   OPAMP All Callbacks
01097   * @retval status
01098   */
01099 
01100 HAL_StatusTypeDef HAL_OPAMP_UnRegisterCallback (OPAMP_HandleTypeDef *hopamp, HAL_OPAMP_CallbackIDTypeDef CallbackID)
01101 {
01102   HAL_StatusTypeDef status = HAL_OK;
01103 
01104   /* Process locked */
01105   __HAL_LOCK(hopamp);
01106 
01107   if(hopamp->State == HAL_OPAMP_STATE_READY)
01108   {
01109     switch (CallbackID)
01110     {
01111       case HAL_OPAMP_MSPINIT_CB_ID :
01112       hopamp->MspInitCallback = HAL_OPAMP_MspInit;
01113       break;
01114     case HAL_OPAMP_MSPDEINIT_CB_ID :
01115       hopamp->MspDeInitCallback = HAL_OPAMP_MspDeInit;
01116       break;
01117     case HAL_OPAMP_ALL_CB_ID :
01118       hopamp->MspInitCallback = HAL_OPAMP_MspInit;
01119       hopamp->MspDeInitCallback = HAL_OPAMP_MspDeInit;
01120       break;
01121     default :
01122       /* update return status */
01123       status =  HAL_ERROR;
01124       break;
01125     }
01126   }
01127   else if (hopamp->State == HAL_OPAMP_STATE_RESET)
01128   {
01129     switch (CallbackID)
01130     {
01131     case HAL_OPAMP_MSPINIT_CB_ID :
01132       hopamp->MspInitCallback = HAL_OPAMP_MspInit;
01133       break;
01134     case HAL_OPAMP_MSPDEINIT_CB_ID :
01135       hopamp->MspDeInitCallback = HAL_OPAMP_MspDeInit;
01136       break;
01137     default :
01138       /* update return status */
01139       status =  HAL_ERROR;
01140       break;
01141     }
01142   }
01143   else
01144   {
01145     /* update return status */
01146     status =  HAL_ERROR;
01147   }
01148 
01149   /* Release Lock */
01150   __HAL_UNLOCK(hopamp);
01151   return status;
01152 }
01153 
01154 #endif /* USE_HAL_OPAMP_REGISTER_CALLBACKS */
01155 
01156 
01157 /**
01158   * @}
01159   */
01160 
01161   /**
01162   * @}
01163   */
01164 
01165 #endif /* HAL_OPAMP_MODULE_ENABLED */
01166 /**
01167   * @}
01168   */
01169 
01170 /**
01171   * @}
01172   */