mbed library sources

Fork of mbed-src by mbed official

Committer:
HiAlgoBoost
Date:
Sun Aug 09 05:18:54 2015 +0000
Revision:
603:f00c7e78e8b4
Parent:
394:83f921546702
Evening of August 8th version

Who changed what in which revision?

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