Martin Johnson / STM32F3-Discovery

Dependents:   Space_Invaders_Demo neopixels gpio_test_stm32f3_discovery gpio_test_systimer ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers stm32f30x_opamp.c Source File

stm32f30x_opamp.c

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32f30x_opamp.c                         
00004   * @author  MCD Application Team
00005   * @version V1.2.3
00006   * @date    10-July-2015
00007   * @brief   This file provides firmware functions to manage the following 
00008   *          functionalities of the operational amplifiers (OPAMP1,...OPAMP4) peripheral: 
00009   *           + OPAMP Configuration
00010   *           + OPAMP calibration
00011   *
00012   @verbatim
00013   
00014   ==============================================================================
00015                         ##### OPAMP Peripheral Features #####
00016   ==============================================================================
00017                    
00018   [..]
00019       The device integrates 4 operational amplifiers OPAMP1, OPAMP2, OPAMP3 and OPAMP4:
00020               
00021       (+) The OPAMPs non inverting input can be selected among the list shown by
00022           table below.
00023   
00024       (+) The OPAMPs inverting input can be selected among the list shown by
00025           table below.
00026   
00027       (+) The OPAMPs outputs can be internally connected to the inverting input 
00028           (follower mode)
00029       (+) The OPAMPs outputs can be internally connected to resistor feedback
00030           output (Programmable Gain Amplifier mode)
00031   
00032       (+) The OPAMPs outputs can be internally connected to ADC
00033   
00034       (+) The OPAMPs can be calibrated to compensate the offset compensation
00035   
00036       (+) Timer-controlled Mux for automatic switch of inverting and
00037           non-inverting input
00038   
00039   OPAMPs inverting/non-inverting inputs:
00040     +--------------------------------------------------------------+     
00041     |                 |        | OPAMP1 | OPAMP2 | OPAMP3 | OPAMP4 |
00042     |-----------------|--------|--------|--------|--------|--------|
00043     |                 | PGA    |  OK    |  OK    |  OK    |  OK    |
00044     | Inverting Input | Vout   |  OK    |  OK    |  OK    |  OK    |
00045     |                 | IO1    |  PC5   |  PC5   |  PB10  |  PB10  |
00046     |                 | IO2    |  PA3   |  PA5   |  PB2   |  PD8   |
00047     |-----------------|--------|--------|--------|--------|--------|
00048     |                 | IO1    |  PA7   |  PD14  |  PB13  |  PD11  |
00049     |  Non Inverting  | IO2    |  PA5   |  PB14  |  PA5   |  PB11  |
00050     |    Input        | IO3    |  PA3   |  PB0   |  PA1   |  PA4   |
00051     |                 | IO4    |  PA1   |  PA7   |  PB0   |  PB13  |
00052     +--------------------------------------------------------------+  
00053   
00054                         ##### How to use this driver #####
00055   ==============================================================================
00056   [..]
00057   This driver provides functions to configure and program the OPAMP 
00058   of all STM32F30x devices.
00059   
00060   To use the OPAMP, perform the following steps:
00061  
00062   (#) Enable the SYSCFG APB clock to get write access to OPAMP
00063       register using RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
00064   
00065   (#) Configure the OPAMP input in analog mode using GPIO_Init()
00066   
00067   (#) Configure the OPAMP using OPAMP_Init() function:
00068       (++) Select the inverting input
00069       (++) Select the non-inverting inverting input
00070     
00071   (#) Enable the OPAMP using OPAMP_Cmd() function
00072     
00073   @endverbatim
00074       
00075   ******************************************************************************
00076   * @attention
00077   *
00078   * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
00079   *
00080   * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
00081   * You may not use this file except in compliance with the License.
00082   * You may obtain a copy of the License at:
00083   *
00084   *        http://www.st.com/software_license_agreement_liberty_v2
00085   *
00086   * Unless required by applicable law or agreed to in writing, software 
00087   * distributed under the License is distributed on an "AS IS" BASIS, 
00088   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00089   * See the License for the specific language governing permissions and
00090   * limitations under the License.
00091   *
00092   ******************************************************************************
00093   */ 
00094 
00095 /* Includes ------------------------------------------------------------------*/
00096 #include "stm32f30x_opamp.h"
00097 
00098 /** @addtogroup STM32F30x_StdPeriph_Driver
00099   * @{
00100   */
00101 
00102 /** @defgroup OPAMP 
00103   * @brief OPAMP driver modules
00104   * @{
00105   */ 
00106 
00107 /* Private typedef -----------------------------------------------------------*/
00108 /* Private define ------------------------------------------------------------*/
00109 #define OPAMP_CSR_DEFAULT_MASK                    ((uint32_t)0xFFFFFF93)
00110 #define OPAMP_CSR_TIMERMUX_MASK                   ((uint32_t)0xFFFFF8FF)
00111 #define OPAMP_CSR_TRIMMING_MASK                   ((uint32_t)0x0000001F)
00112 
00113 /* Private macro -------------------------------------------------------------*/
00114 /* Private variables ---------------------------------------------------------*/
00115 /* Private function prototypes -----------------------------------------------*/
00116 /* Private functions ---------------------------------------------------------*/
00117 
00118 /** @defgroup OPAMP_Private_Functions
00119   * @{
00120   */
00121 
00122 /** @defgroup OPAMP_Group1 Initialization and Configuration functions
00123  *  @brief   Initialization and Configuration functions 
00124  *
00125 @verbatim   
00126  ===============================================================================
00127              ##### Initialization and Configuration functions #####
00128  ===============================================================================  
00129 
00130 @endverbatim
00131   * @{
00132   */
00133    
00134 /**
00135   * @brief  Deinitializes OPAMP peripheral registers to their default reset values.
00136   * @note   Deinitialization can't be performed if the OPAMP configuration is locked.
00137   *         To unlock the configuration, perform a system reset.
00138   * @param  OPAMP_Selection: the selected OPAMP. 
00139   *          This parameter can be OPAMP_Selection_OPAMPx where x can be 1 to 4
00140   *          to select the OPAMP peripheral.
00141   * @param  None
00142   * @retval None
00143   */
00144 void OPAMP_DeInit(uint32_t OPAMP_Selection)
00145 {
00146   /*!< Set OPAMP_CSR register to reset value */
00147   *(__IO uint32_t *) (OPAMP_BASE + OPAMP_Selection) = ((uint32_t)0x00000000);
00148 }
00149 
00150 /**
00151   * @brief  Initializes the OPAMP peripheral according to the specified parameters
00152   *         in OPAMP_InitStruct
00153   * @note   If the selected OPAMP is locked, initialization can't be performed.
00154   *         To unlock the configuration, perform a system reset.
00155   * @param  OPAMP_Selection: the selected OPAMP. 
00156   *          This parameter can be OPAMP_Selection_OPAMPx where x can be 1 to 4
00157   *          to select the OPAMP peripheral.
00158   * @param  OPAMP_InitStruct: pointer to an OPAMP_InitTypeDef structure that contains 
00159   *         the configuration information for the specified OPAMP peripheral.
00160   *           - OPAMP_InvertingInput specifies the inverting input of OPAMP
00161   *           - OPAMP_NonInvertingInput specifies the non inverting input of OPAMP
00162   * @retval None
00163   */
00164 void OPAMP_Init(uint32_t OPAMP_Selection, OPAMP_InitTypeDef* OPAMP_InitStruct)
00165 {
00166   uint32_t tmpreg = 0;
00167 
00168   /* Check the parameters */
00169   assert_param(IS_OPAMP_ALL_PERIPH(OPAMP_Selection));
00170   assert_param(IS_OPAMP_INVERTING_INPUT(OPAMP_InitStruct->OPAMP_InvertingInput));
00171   assert_param(IS_OPAMP_NONINVERTING_INPUT(OPAMP_InitStruct->OPAMP_NonInvertingInput));
00172 
00173   /*!< Get the OPAMPx_CSR register value */
00174   tmpreg = *(__IO uint32_t *) (OPAMP_BASE + OPAMP_Selection);
00175 
00176   /*!< Clear the inverting and non inverting bits selection bits */
00177   tmpreg &= (uint32_t) (OPAMP_CSR_DEFAULT_MASK);
00178 
00179   /*!< Configure OPAMP: inverting and non inverting inputs */
00180   tmpreg |= (uint32_t)(OPAMP_InitStruct->OPAMP_InvertingInput | OPAMP_InitStruct->OPAMP_NonInvertingInput);
00181 
00182   /*!< Write to OPAMPx_CSR register */
00183   *(__IO uint32_t *) (OPAMP_BASE + OPAMP_Selection) = tmpreg;
00184 }
00185 
00186 /**
00187   * @brief  Fills each OPAMP_InitStruct member with its default value.
00188   * @param  OPAMP_InitStruct: pointer to an OPAMP_InitTypeDef structure which will 
00189   *         be initialized.
00190   * @retval None
00191   */
00192 void OPAMP_StructInit(OPAMP_InitTypeDef* OPAMP_InitStruct)
00193 {
00194   OPAMP_InitStruct->OPAMP_NonInvertingInput = OPAMP_NonInvertingInput_IO1;
00195   OPAMP_InitStruct->OPAMP_InvertingInput = OPAMP_InvertingInput_IO1;
00196 }
00197 
00198 /**
00199   * @brief  Configure the feedback resistor gain.
00200   * @note   If the selected OPAMP is locked, gain configuration can't be performed.
00201   *         To unlock the configuration, perform a system reset.
00202   * @param  OPAMP_Selection: the selected OPAMP. 
00203   *          This parameter can be OPAMP_Selection_OPAMPx where x can be 1 to 4
00204   *          to select the OPAMP peripheral.
00205   * @param  NewState: new state of the OPAMP peripheral.
00206   *         This parameter can be: ENABLE or DISABLE.
00207   * @retval None
00208   */
00209 void OPAMP_PGAConfig(uint32_t OPAMP_Selection, uint32_t OPAMP_PGAGain, uint32_t OPAMP_PGAConnect)
00210 {
00211   /* Check the parameters */
00212   assert_param(IS_OPAMP_ALL_PERIPH(OPAMP_Selection));
00213   assert_param(IS_OPAMP_PGAGAIN(OPAMP_PGAGain));
00214   assert_param(IS_OPAMP_PGACONNECT(OPAMP_PGAConnect));
00215 
00216   /* Reset the configuration bits */
00217   *(__IO uint32_t *) (OPAMP_BASE + OPAMP_Selection) &= (uint32_t)(~OPAMP_CSR_PGGAIN);
00218 
00219   /* Set the new configuration */
00220   *(__IO uint32_t *) (OPAMP_BASE + OPAMP_Selection) |= (uint32_t) (OPAMP_PGAGain | OPAMP_PGAConnect);
00221 }
00222 
00223 /**
00224   * @brief  Configure the OPAMP's internal reference.
00225   * @note   This feature is used when calibration enabled or OPAMP's reference
00226   *         connected to the non inverting input.
00227   * @note   If the selected OPAMP is locked, Vref configuration can't be performed.
00228   *         To unlock the configuration, perform a system reset.  
00229   * @param  OPAMP_Selection: the selected OPAMP. 
00230   *          This parameter can be OPAMP_Selection_OPAMPx where x can be 1 to 4
00231   *          to select the OPAMP peripheral.
00232   * @param  OPAMP_Vref: This parameter can be:
00233   *           OPAMP_Vref_3VDDA: OPMAP Vref = 3.3% VDDA
00234   *           OPAMP_Vref_10VDDA: OPMAP Vref = 10% VDDA
00235   *           OPAMP_Vref_50VDDA: OPMAP Vref = 50% VDDA
00236   *           OPAMP_Vref_90VDDA: OPMAP Vref = 90% VDDA
00237   * @retval None
00238   */
00239 void OPAMP_VrefConfig(uint32_t OPAMP_Selection, uint32_t OPAMP_Vref)
00240 {
00241   uint32_t tmpreg = 0;
00242 
00243   /* Check the parameters */
00244   assert_param(IS_OPAMP_ALL_PERIPH(OPAMP_Selection));
00245   assert_param(IS_OPAMP_VREF(OPAMP_Vref));
00246 
00247   /*!< Get the OPAMPx_CSR register value */
00248   tmpreg = *(__IO uint32_t *) (OPAMP_BASE + OPAMP_Selection);
00249 
00250   /*!< Clear the CALSEL bits */
00251   tmpreg &= (uint32_t) (~OPAMP_CSR_CALSEL);
00252 
00253   /*!< Configure OPAMP reference */
00254   tmpreg |= (uint32_t)(OPAMP_Vref);
00255 
00256   /*!< Write to OPAMPx_CSR register */
00257   *(__IO uint32_t *) (OPAMP_BASE + OPAMP_Selection) = tmpreg;
00258 }
00259 
00260 /**
00261   * @brief  Connect the internal reference to the OPAMP's non inverting input.
00262   * @note   If the selected OPAMP is locked, Vref configuration can't be performed.
00263   *         To unlock the configuration, perform a system reset.  
00264   * @param  OPAMP_Selection: the selected OPAMP. 
00265   *          This parameter can be OPAMP_Selection_OPAMPx where x can be 1 to 4
00266   *          to select the OPAMP peripheral.
00267   * @param  NewState: new state of the OPAMP peripheral.
00268   *         This parameter can be: ENABLE or DISABLE.
00269   * @retval None
00270   */
00271 void OPAMP_VrefConnectNonInvertingInput(uint32_t OPAMP_Selection, FunctionalState NewState)
00272 {
00273   /* Check the parameters */
00274   assert_param(IS_OPAMP_ALL_PERIPH(OPAMP_Selection));
00275   assert_param(IS_FUNCTIONAL_STATE(NewState));
00276 
00277   if (NewState != DISABLE)
00278   {
00279     /* Connect the internal reference to the OPAMP's non inverting input */
00280     *(__IO uint32_t *) (OPAMP_BASE + OPAMP_Selection) |= (uint32_t) (OPAMP_CSR_FORCEVP);
00281   }
00282   else
00283   {
00284     /* Disconnect the internal reference to the OPAMP's non inverting input */
00285     *(__IO uint32_t *) (OPAMP_BASE + OPAMP_Selection) &= (uint32_t)(~OPAMP_CSR_FORCEVP);
00286   }
00287 }
00288 
00289 /**
00290   * @brief  Enables or disables connecting the OPAMP's internal reference to ADC.
00291   * @note   If the selected OPAMP is locked, Vref connection can't be performed.
00292   *         To unlock the configuration, perform a system reset.  
00293   * @param  NewState: new state of the Vrefint output.
00294   *         This parameter can be: ENABLE or DISABLE.
00295   * @retval None
00296   */
00297 void OPAMP_VrefConnectADCCmd(uint32_t OPAMP_Selection, FunctionalState NewState)
00298 {
00299   /* Check the parameters */
00300   assert_param(IS_OPAMP_ALL_PERIPH(OPAMP_Selection));
00301   assert_param(IS_FUNCTIONAL_STATE(NewState));
00302 
00303   if (NewState != DISABLE)
00304   {
00305     /* Enable output internal reference */
00306     *(__IO uint32_t *) (OPAMP_BASE + OPAMP_Selection) |= (uint32_t) (OPAMP_CSR_TSTREF);
00307   }
00308   else
00309   {
00310     /* Disable output internal reference */
00311     *(__IO uint32_t *) (OPAMP_BASE + OPAMP_Selection) &= (uint32_t)(~OPAMP_CSR_TSTREF);
00312   }
00313 }
00314 
00315 /**
00316   * @brief  Configure the OPAMP peripheral (secondary inputs) for timer-controlled
00317   *          mux mode according to the specified parameters in OPAMP_InitStruct.
00318   * @note   If the selected OPAMP is locked, timer-controlled mux configuration
00319   *         can't be performed.
00320   *         To unlock the configuration, perform a system reset.
00321   * @param  OPAMP_Selection: the selected OPAMP. 
00322   *          This parameter can be OPAMP_Selection_OPAMPx where x can be 1 to 4
00323   *          to select the OPAMP peripheral.
00324   * @param  OPAMP_InitStruct: pointer to an OPAMP_InitTypeDef structure that contains 
00325   *         the configuration information for the specified OPAMP peripheral.
00326   *           - OPAMP_InvertingInput specifies the inverting input of OPAMP
00327   *           - OPAMP_NonInvertingInput specifies the non inverting input of OPAMP
00328   * @note   PGA and Vout can't be selected as secondary inverting input.
00329   * @retval None
00330   */
00331 void OPAMP_TimerControlledMuxConfig(uint32_t OPAMP_Selection, OPAMP_InitTypeDef* OPAMP_InitStruct)
00332 {
00333   uint32_t tmpreg = 0;
00334 
00335   /* Check the parameters */
00336   assert_param(IS_OPAMP_ALL_PERIPH(OPAMP_Selection));
00337   assert_param(IS_OPAMP_SECONDARY_INVINPUT(OPAMP_InitStruct->OPAMP_InvertingInput));
00338   assert_param(IS_OPAMP_NONINVERTING_INPUT(OPAMP_InitStruct->OPAMP_NonInvertingInput));
00339 
00340   /*!< Get the OPAMPx_CSR register value */
00341   tmpreg = *(__IO uint32_t *) (OPAMP_BASE + OPAMP_Selection);
00342 
00343   /*!< Clear the secondary inverting bit, secondary non inverting bit and TCMEN bits */
00344   tmpreg &= (uint32_t) (OPAMP_CSR_TIMERMUX_MASK);
00345 
00346   /*!< Configure OPAMP: secondary inverting and non inverting inputs */
00347   tmpreg |= (uint32_t)((uint32_t)(OPAMP_InitStruct->OPAMP_InvertingInput<<3) | (uint32_t)(OPAMP_InitStruct->OPAMP_NonInvertingInput<<7));
00348 
00349   /*!< Write to OPAMPx_CSR register */
00350   *(__IO uint32_t *) (OPAMP_BASE + OPAMP_Selection) = tmpreg;
00351 }
00352 
00353 /**
00354   * @brief  Enable or disable the timer-controlled mux mode.
00355   * @note   If the selected OPAMP is locked, enable/disable can't be performed.
00356   *         To unlock the configuration, perform a system reset.
00357   * @param  OPAMP_Selection: the selected OPAMP. 
00358   *          This parameter can be OPAMP_Selection_OPAMPx where x can be 1 to 4
00359   *          to select the OPAMP peripheral.
00360   * @param  NewState: new state of the OPAMP peripheral.
00361   *         This parameter can be: ENABLE or DISABLE.
00362   * @retval None
00363   */
00364 void OPAMP_TimerControlledMuxCmd(uint32_t OPAMP_Selection, FunctionalState NewState)
00365 {
00366   /* Check the parameters */
00367   assert_param(IS_OPAMP_ALL_PERIPH(OPAMP_Selection));
00368   assert_param(IS_FUNCTIONAL_STATE(NewState));
00369 
00370   if (NewState != DISABLE)
00371   {
00372     /* Enable the timer-controlled Mux mode */
00373     *(__IO uint32_t *) (OPAMP_BASE + OPAMP_Selection) |= (uint32_t) (OPAMP_CSR_TCMEN);
00374   }
00375   else
00376   {
00377     /* Disable the timer-controlled Mux mode */
00378     *(__IO uint32_t *) (OPAMP_BASE + OPAMP_Selection) &= (uint32_t)(~OPAMP_CSR_TCMEN);
00379   }
00380 }
00381 
00382 /**
00383   * @brief  Enable or disable the OPAMP peripheral.
00384   * @note   If the selected OPAMP is locked, enable/disable can't be performed.
00385   *         To unlock the configuration, perform a system reset.
00386   * @param  OPAMP_Selection: the selected OPAMP. 
00387   *          This parameter can be OPAMP_Selection_OPAMPx where x can be 1 to 4
00388   *          to select the OPAMP peripheral.
00389   * @param  NewState: new state of the OPAMP peripheral.
00390   *         This parameter can be: ENABLE or DISABLE.
00391   * @retval None
00392   */
00393 void OPAMP_Cmd(uint32_t OPAMP_Selection, FunctionalState NewState)
00394 {
00395   /* Check the parameters */
00396   assert_param(IS_OPAMP_ALL_PERIPH(OPAMP_Selection));
00397   assert_param(IS_FUNCTIONAL_STATE(NewState));
00398 
00399   if (NewState != DISABLE)
00400   {
00401     /* Enable the selected OPAMPx peripheral */
00402     *(__IO uint32_t *) (OPAMP_BASE + OPAMP_Selection) |= (uint32_t) (OPAMP_CSR_OPAMPxEN);
00403   }
00404   else
00405   {
00406     /* Disable the selected OPAMPx peripheral */
00407     *(__IO uint32_t *) (OPAMP_BASE + OPAMP_Selection) &= (uint32_t)(~OPAMP_CSR_OPAMPxEN);
00408   }
00409 }
00410 
00411 /**
00412   * @brief  Return the output level (high or low) during calibration of the selected OPAMP. 
00413   * @param  OPAMP_Selection: the selected OPAMP. 
00414   *          This parameter can be OPAMP_Selection_OPAMPx where x can be 1 to 4
00415   *          to select the OPAMP peripheral.
00416   *           - OPAMP output is low when the non-inverting input is at a lower
00417   *             voltage than the inverting input
00418   *           - OPAMP output is high when the non-inverting input is at a higher
00419   *             voltage than the inverting input
00420   * @note OPAMP output level is provided only during calibration phase.
00421   * @retval Returns the selected OPAMP output level: low or high.
00422   *       
00423   */
00424 uint32_t OPAMP_GetOutputLevel(uint32_t OPAMP_Selection)
00425 {
00426   uint32_t opampout = 0x0;
00427 
00428   /* Check the parameters */
00429   assert_param(IS_OPAMP_ALL_PERIPH(OPAMP_Selection));
00430 
00431   /* Check if selected OPAMP output is high */
00432   if ((*(__IO uint32_t *) (OPAMP_BASE + OPAMP_Selection) & (OPAMP_CSR_OUTCAL)) != 0)
00433   {
00434     opampout = OPAMP_OutputLevel_High;
00435   }
00436   else
00437   {
00438     opampout = OPAMP_OutputLevel_Low;
00439   }
00440 
00441   /* Return the OPAMP output level */
00442   return (uint32_t)(opampout);
00443 }
00444 
00445 /**
00446   * @brief  Select the trimming mode.
00447   * @param  OffsetTrimming: the selected offset trimming mode. 
00448   *   This parameter  can be one of the following values:
00449   *     @arg OPAMP_Trimming_Factory: factory trimming values are used for offset
00450   *                                  calibration
00451   *     @arg OPAMP_Trimming_User: user trimming values are used for offset
00452   *                               calibration
00453   * @note When OffsetTrimming_User is selected, use OPAMP_OffsetTrimConfig()
00454   *       function or OPAMP_OffsetTrimLowPowerConfig() function to adjust 
00455   *       trimming value.
00456   * @retval None
00457   */
00458 void OPAMP_OffsetTrimModeSelect(uint32_t OPAMP_Selection, uint32_t OPAMP_Trimming)
00459 {
00460   /* Check the parameters */
00461   assert_param(IS_OPAMP_ALL_PERIPH(OPAMP_Selection));
00462   assert_param(IS_OPAMP_TRIMMING(OPAMP_Trimming));
00463 
00464   /* Reset USERTRIM bit */
00465   *(__IO uint32_t *) (OPAMP_BASE + OPAMP_Selection) &= (~(uint32_t) (OPAMP_CSR_USERTRIM));
00466 
00467   /* Select trimming mode */
00468   *(__IO uint32_t *) (OPAMP_BASE + OPAMP_Selection) |= OPAMP_Trimming;
00469 }
00470 
00471 /**
00472   * @brief  Configure the trimming value of the OPAMP.
00473   * @param  OPAMP_Selection: the selected OPAMP. 
00474   *          This parameter can be OPAMP_Selection_OPAMPx where x can be 1 to 4
00475   *          to select the OPAMP peripheral.
00476   * @param  OPAMP_Input: the selected OPAMP input. 
00477   *   This parameter can be one of the following values:
00478   *         @arg OPAMP_Input_Inverting: Inverting input is selected to configure the trimming value
00479   *         @arg OPAMP_Input_NonInverting: Non inverting input is selected to configure the trimming value
00480   * @param  OPAMP_TrimValue: the trimming value. This parameter can be any value lower
00481   *         or equal to 0x0000001F. 
00482   * @retval None
00483   */
00484 void OPAMP_OffsetTrimConfig(uint32_t OPAMP_Selection, uint32_t OPAMP_Input, uint32_t OPAMP_TrimValue)
00485 {
00486   uint32_t tmpreg = 0;
00487 
00488   /* Check the parameters */
00489   assert_param(IS_OPAMP_ALL_PERIPH(OPAMP_Selection));
00490   assert_param(IS_OPAMP_INPUT(OPAMP_Input));
00491   assert_param(IS_OPAMP_TRIMMINGVALUE(OPAMP_TrimValue));
00492 
00493   /*!< Get the OPAMPx_CSR register value */
00494   tmpreg = *(__IO uint32_t *) (OPAMP_BASE + OPAMP_Selection);
00495 
00496   /*!< Clear the trimming bits */
00497   tmpreg &= ((uint32_t)~(OPAMP_CSR_TRIMMING_MASK<<OPAMP_Input));
00498 
00499   /*!< Configure the new trimming value */
00500   tmpreg |= (uint32_t)(OPAMP_TrimValue<<OPAMP_Input);
00501 
00502   /*!< Write to OPAMPx_CSR register */
00503   *(__IO uint32_t *) (OPAMP_BASE + OPAMP_Selection) = tmpreg;
00504 }
00505 
00506 /**
00507   * @brief  Start or stop the calibration of selected OPAMP peripheral.
00508   * @note   If the selected OPAMP is locked, start/stop can't be performed.
00509   *         To unlock the configuration, perform a system reset.
00510   * @param  OPAMP_Selection: the selected OPAMP. 
00511   *          This parameter can be OPAMP_Selection_OPAMPx where x can be 1 to 4
00512   *          to select the OPAMP peripheral.
00513   * @param  NewState: new state of the OPAMP peripheral.
00514   *         This parameter can be: ENABLE or DISABLE.  
00515   * @retval None
00516   */
00517 void OPAMP_StartCalibration(uint32_t OPAMP_Selection, FunctionalState NewState)
00518 {
00519   /* Check the parameters */
00520   assert_param(IS_OPAMP_ALL_PERIPH(OPAMP_Selection));
00521   assert_param(IS_FUNCTIONAL_STATE(NewState));
00522 
00523   if (NewState != DISABLE)
00524   {
00525     /* Start the OPAMPx calibration */
00526     *(__IO uint32_t *) (OPAMP_BASE + OPAMP_Selection) |= (uint32_t) (OPAMP_CSR_CALON);
00527   }
00528   else
00529   {
00530     /* Stop the OPAMPx calibration */
00531     *(__IO uint32_t *) (OPAMP_BASE + OPAMP_Selection) &= (uint32_t)(~OPAMP_CSR_CALON);
00532   }
00533 }
00534 
00535 /**
00536   * @}
00537   */
00538 
00539 /** @defgroup OPAMP_Group2 OPAMP configuration locking function
00540  *  @brief   OPAMP1,...OPAMP4 configuration locking function
00541  *           OPAMP1,...OPAMP4 configuration can be locked each separately.
00542  *           Unlocking is performed by system reset.
00543  *
00544 @verbatim   
00545  ===============================================================================
00546                      ##### Configuration Lock function #####
00547  ===============================================================================  
00548 
00549 @endverbatim
00550   * @{
00551   */
00552 
00553 /**
00554   * @brief  Lock the selected OPAMP configuration.
00555   * @note   Locking the configuration means that all control bits are read-only.
00556   *         To unlock the OPAMP configuration, perform a system reset.
00557   * @param  OPAMP_Selection: the selected OPAMP. 
00558   *          This parameter can be OPAMP_Selection_OPAMPx where x can be 1 to 4
00559   *          to select the OPAMP peripheral.
00560   * @retval None
00561   */
00562 void OPAMP_LockConfig(uint32_t OPAMP_Selection)
00563 {
00564   /* Check the parameter */
00565   assert_param(IS_OPAMP_ALL_PERIPH(OPAMP_Selection));
00566 
00567   /* Set the lock bit corresponding to selected OPAMP */
00568   *(__IO uint32_t *) (OPAMP_BASE + OPAMP_Selection) |= (uint32_t) (OPAMP_CSR_LOCK);
00569 }
00570 
00571 /**
00572   * @}
00573   */
00574 
00575 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/