Lancaster University's (short term!) clone of mbed-src for micro:bit. This is a copy of the github branch https://github.com/lancaster-university/mbed-classic

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Fri Aug 14 13:15:17 2015 +0100
Revision:
610:813dcc80987e
Synchronized with git revision 6d84db41c6833e0b9b024741eb0616a5f62d5599

Full URL: https://github.com/mbedmicro/mbed/commit/6d84db41c6833e0b9b024741eb0616a5f62d5599/

DISCO_F746NG - Improvements

Who changed what in which revision?

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