mbed library sources modified for open wear
Dependents: openwear-lifelogger-example
Fork of mbed-src by
targets/cmsis/TARGET_STM/TARGET_NUCLEO_F334R8/stm32f3xx_hal_opamp.c@237:f3da66175598, 2014-06-24 (annotated)
- Committer:
- mbed_official
- Date:
- Tue Jun 24 14:45:08 2014 +0100
- Revision:
- 237:f3da66175598
Synchronized with git revision 8ef659bca81f12dfc896b5a7af7c2abbd1a1b8b7
Full URL: https://github.com/mbedmicro/mbed/commit/8ef659bca81f12dfc896b5a7af7c2abbd1a1b8b7/
[NUCLEO_F334R8] Add platform files
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 237:f3da66175598 | 1 | /** |
mbed_official | 237:f3da66175598 | 2 | ****************************************************************************** |
mbed_official | 237:f3da66175598 | 3 | * @file stm32f3xx_hal_opamp.c |
mbed_official | 237:f3da66175598 | 4 | * @author MCD Application Team |
mbed_official | 237:f3da66175598 | 5 | * @version V1.0.1 |
mbed_official | 237:f3da66175598 | 6 | * @date 18-June-2014 |
mbed_official | 237:f3da66175598 | 7 | * @brief OPAMP HAL module driver. |
mbed_official | 237:f3da66175598 | 8 | * |
mbed_official | 237:f3da66175598 | 9 | * This file provides firmware functions to manage the following |
mbed_official | 237:f3da66175598 | 10 | * functionalities of the operational amplifiers (OPAMP1,...OPAMP4) |
mbed_official | 237:f3da66175598 | 11 | * peripheral: |
mbed_official | 237:f3da66175598 | 12 | * + OPAMP Configuration |
mbed_official | 237:f3da66175598 | 13 | * + OPAMP calibration |
mbed_official | 237:f3da66175598 | 14 | * |
mbed_official | 237:f3da66175598 | 15 | * Thanks to |
mbed_official | 237:f3da66175598 | 16 | * + Initialization/de-initialization functions |
mbed_official | 237:f3da66175598 | 17 | * + I/O operation functions |
mbed_official | 237:f3da66175598 | 18 | * + Peripheral Control functions |
mbed_official | 237:f3da66175598 | 19 | * + Peripheral State functions |
mbed_official | 237:f3da66175598 | 20 | * |
mbed_official | 237:f3da66175598 | 21 | @verbatim |
mbed_official | 237:f3da66175598 | 22 | ================================================================================ |
mbed_official | 237:f3da66175598 | 23 | ##### OPAMP Peripheral Features ##### |
mbed_official | 237:f3da66175598 | 24 | ================================================================================ |
mbed_official | 237:f3da66175598 | 25 | |
mbed_official | 237:f3da66175598 | 26 | [..] The device integrates up to 4 operational amplifiers OPAMP1, OPAMP2, |
mbed_official | 237:f3da66175598 | 27 | OPAMP3 and OPAMP4: |
mbed_official | 237:f3da66175598 | 28 | |
mbed_official | 237:f3da66175598 | 29 | (#) The OPAMP(s) provides several exclusive running modes. |
mbed_official | 237:f3da66175598 | 30 | (+) Standalone mode |
mbed_official | 237:f3da66175598 | 31 | (+) Programmable Gain Amplifier (PGA) mode (Resistor feedback output) |
mbed_official | 237:f3da66175598 | 32 | (+) Follower mode |
mbed_official | 237:f3da66175598 | 33 | |
mbed_official | 237:f3da66175598 | 34 | (#) The OPAMP(s) provide(s) calibration capabilities. |
mbed_official | 237:f3da66175598 | 35 | (+) Calibration aims at correcting some offset for running mode. |
mbed_official | 237:f3da66175598 | 36 | (+) The OPAMP uses either factory calibration settings OR user defined |
mbed_official | 237:f3da66175598 | 37 | calibration (trimming) settings (i.e. trimming mode). |
mbed_official | 237:f3da66175598 | 38 | (+) The user defined settings can be figured out using self calibration |
mbed_official | 237:f3da66175598 | 39 | handled by HAL_OPAMP_SelfCalibrate, HAL_OPAMPEx_SelfCalibrate2opamp |
mbed_official | 237:f3da66175598 | 40 | or HAL_OPAMPEx_SelfCalibrate4opamp |
mbed_official | 237:f3da66175598 | 41 | (+) HAL_OPAMP_SelfCalibrate: |
mbed_official | 237:f3da66175598 | 42 | (++) Runs automatically the calibration in 2 steps. |
mbed_official | 237:f3da66175598 | 43 | (90% of VDDA for NMOS transistors, 10% of VDDA for PMOS transistors). |
mbed_official | 237:f3da66175598 | 44 | (As OPAMP is Rail-to-rail input/output, these 2 steps calibration is |
mbed_official | 237:f3da66175598 | 45 | appropriate and enough in most cases). |
mbed_official | 237:f3da66175598 | 46 | (++) Enables the user trimming mode |
mbed_official | 237:f3da66175598 | 47 | (++) Updates the init structure with trimming values with fresh calibration |
mbed_official | 237:f3da66175598 | 48 | results. |
mbed_official | 237:f3da66175598 | 49 | The user may store the calibration results for larger |
mbed_official | 237:f3da66175598 | 50 | (ex monitoring the trimming as a function of temperature |
mbed_official | 237:f3da66175598 | 51 | for instance) |
mbed_official | 237:f3da66175598 | 52 | (++) for STM32F3 devices having 2 or 4 OPAMPs |
mbed_official | 237:f3da66175598 | 53 | HAL_OPAMPEx_SelfCalibrate2opamp, HAL_OPAMPEx_SelfCalibrate4opamp |
mbed_official | 237:f3da66175598 | 54 | runs calibration of 2 or 4 OPAMPs in parallel. |
mbed_official | 237:f3da66175598 | 55 | |
mbed_official | 237:f3da66175598 | 56 | (#) For any running mode, an additional Timer-controlled Mux (multiplexer) |
mbed_official | 237:f3da66175598 | 57 | mode can be set on top. |
mbed_official | 237:f3da66175598 | 58 | (+) Timer-controlled Mux mode allows Automatic switching between inverting |
mbed_official | 237:f3da66175598 | 59 | and non-inverting input. |
mbed_official | 237:f3da66175598 | 60 | (+) Hence on top of defaults (primary) inverting and non-inverting inputs, |
mbed_official | 237:f3da66175598 | 61 | the user shall select secondary inverting and non inverting inputs. |
mbed_official | 237:f3da66175598 | 62 | (+) TIM1 CC6 provides the alternate switching tempo between defaults |
mbed_official | 237:f3da66175598 | 63 | (primary) and secondary inputs. |
mbed_official | 237:f3da66175598 | 64 | |
mbed_official | 237:f3da66175598 | 65 | (#) Running mode: Standalone mode |
mbed_official | 237:f3da66175598 | 66 | (+) Gain is set externally (gain depends on external loads). |
mbed_official | 237:f3da66175598 | 67 | (+) Follower mode also possible externally by connecting the inverting input to |
mbed_official | 237:f3da66175598 | 68 | the output. |
mbed_official | 237:f3da66175598 | 69 | |
mbed_official | 237:f3da66175598 | 70 | (#) Running mode: Follower mode |
mbed_official | 237:f3da66175598 | 71 | (+) No Inverting Input is connected. |
mbed_official | 237:f3da66175598 | 72 | |
mbed_official | 237:f3da66175598 | 73 | (#) Running mode: Programmable Gain Amplifier (PGA) mode |
mbed_official | 237:f3da66175598 | 74 | (Resistor feedback output) |
mbed_official | 237:f3da66175598 | 75 | (+) The OPAMP(s) output(s) can be internally connected to resistor feedback |
mbed_official | 237:f3da66175598 | 76 | output. |
mbed_official | 237:f3da66175598 | 77 | (+) OPAMP gain is either 2, 4, 8 or 16. |
mbed_official | 237:f3da66175598 | 78 | |
mbed_official | 237:f3da66175598 | 79 | (#) The OPAMPs non inverting input (both default and secondary) can be |
mbed_official | 237:f3da66175598 | 80 | selected among the list shown by table below. |
mbed_official | 237:f3da66175598 | 81 | |
mbed_official | 237:f3da66175598 | 82 | (#) The OPAMPs non inverting input (both default and secondary) can be |
mbed_official | 237:f3da66175598 | 83 | selected among the list shown by table below. |
mbed_official | 237:f3da66175598 | 84 | |
mbed_official | 237:f3da66175598 | 85 | [..] Table 1. OPAMPs inverting/non-inverting inputs for the STM32F3 devices: |
mbed_official | 237:f3da66175598 | 86 | |
mbed_official | 237:f3da66175598 | 87 | +--------------------------------------------------------------+ |
mbed_official | 237:f3da66175598 | 88 | | | | OPAMP1 | OPAMP2 | OPAMP3 | OPAMP4 | |
mbed_official | 237:f3da66175598 | 89 | |-----------------|--------|--------|--------|--------|--------| |
mbed_official | 237:f3da66175598 | 90 | | | No conn| X | X | X | X | |
mbed_official | 237:f3da66175598 | 91 | | Inverting Input | VM0 | PC5 | PC5 | PB10 | PB10 | |
mbed_official | 237:f3da66175598 | 92 | | (1) | VM1 | PA3 | PA5 | PB2 | PD8 | |
mbed_official | 237:f3da66175598 | 93 | |-----------------|--------|--------|--------|--------|--------| |
mbed_official | 237:f3da66175598 | 94 | | | VP0 | PA1 | PA7 | PB0 | PB13 | |
mbed_official | 237:f3da66175598 | 95 | | Non Inverting | VP1 | PA7 | PD14 | PB13 | PD11 | |
mbed_official | 237:f3da66175598 | 96 | | Input | VP2 | PA3 | PB0 | PA1 | PA4 | |
mbed_official | 237:f3da66175598 | 97 | | | VP3 | PA5 | PB14 | PA5 | PB11 | |
mbed_official | 237:f3da66175598 | 98 | +--------------------------------------------------------------+ |
mbed_official | 237:f3da66175598 | 99 | (1): NA in follower mode. |
mbed_official | 237:f3da66175598 | 100 | |
mbed_official | 237:f3da66175598 | 101 | [..] Table 2. OPAMPs outputs for the STM32F3 devices: |
mbed_official | 237:f3da66175598 | 102 | |
mbed_official | 237:f3da66175598 | 103 | +--------------------------------------------------------------+ |
mbed_official | 237:f3da66175598 | 104 | | | | OPAMP1 | OPAMP2 | OPAMP3 | OPAMP4 | |
mbed_official | 237:f3da66175598 | 105 | |-----------------|--------|--------|--------|--------|--------| |
mbed_official | 237:f3da66175598 | 106 | | Output | | PA2 | PA6 | PB1 | PB12 | |
mbed_official | 237:f3da66175598 | 107 | |-----------------|--------|--------|--------|--------|--------| |
mbed_official | 237:f3da66175598 | 108 | |
mbed_official | 237:f3da66175598 | 109 | |
mbed_official | 237:f3da66175598 | 110 | ##### How to use this driver ##### |
mbed_official | 237:f3da66175598 | 111 | ================================================================================ |
mbed_official | 237:f3da66175598 | 112 | [..] |
mbed_official | 237:f3da66175598 | 113 | |
mbed_official | 237:f3da66175598 | 114 | *** Calibration *** |
mbed_official | 237:f3da66175598 | 115 | ============================================ |
mbed_official | 237:f3da66175598 | 116 | To run the opamp calibration self calibration: |
mbed_official | 237:f3da66175598 | 117 | |
mbed_official | 237:f3da66175598 | 118 | (#) Start calibration using HAL_OPAMP_SelfCalibrate. |
mbed_official | 237:f3da66175598 | 119 | Store the calibration results. |
mbed_official | 237:f3da66175598 | 120 | |
mbed_official | 237:f3da66175598 | 121 | *** Running mode *** |
mbed_official | 237:f3da66175598 | 122 | ============================================ |
mbed_official | 237:f3da66175598 | 123 | |
mbed_official | 237:f3da66175598 | 124 | To use the opamp, perform the following steps: |
mbed_official | 237:f3da66175598 | 125 | |
mbed_official | 237:f3da66175598 | 126 | (#) Fill in the HAL_COMP_MspInit() to |
mbed_official | 237:f3da66175598 | 127 | (+) Configure the opamp input AND output in analog mode using |
mbed_official | 237:f3da66175598 | 128 | HAL_GPIO_Init() to map the opamp output to the GPIO pin. |
mbed_official | 237:f3da66175598 | 129 | |
mbed_official | 237:f3da66175598 | 130 | (#) Configure the opamp using HAL_OPAMP_Init() function: |
mbed_official | 237:f3da66175598 | 131 | (+) Select the mode |
mbed_official | 237:f3da66175598 | 132 | (+) Select the inverting input |
mbed_official | 237:f3da66175598 | 133 | (+) Select the non-inverting input |
mbed_official | 237:f3da66175598 | 134 | (+) Select if the Timer controlled Mux mode is enabled/disabled |
mbed_official | 237:f3da66175598 | 135 | (+) If the Timer controlled Mux mode is enabled, select the secondary inverting input |
mbed_official | 237:f3da66175598 | 136 | (+) If the Timer controlled Mux mode is enabled, Select the secondary non-inverting input |
mbed_official | 237:f3da66175598 | 137 | (+) If PGA mode is enabled, Select if inverting input is connected. |
mbed_official | 237:f3da66175598 | 138 | (+) Select either factory or user defined trimming mode. |
mbed_official | 237:f3da66175598 | 139 | (+) If the user defined trimming mode is enabled, select PMOS & NMOS trimming values |
mbed_official | 237:f3da66175598 | 140 | (typ. settings returned by HAL_OPAMP_SelfCalibrate function). |
mbed_official | 237:f3da66175598 | 141 | |
mbed_official | 237:f3da66175598 | 142 | (#) Enable the opamp using HAL_OPAMP_Start() function. |
mbed_official | 237:f3da66175598 | 143 | |
mbed_official | 237:f3da66175598 | 144 | (#) Disable the opamp using HAL_OPAMP_Stop() function. |
mbed_official | 237:f3da66175598 | 145 | |
mbed_official | 237:f3da66175598 | 146 | (#) Lock the opamp in running mode using HAL_OPAMP_Lock() function. From then The configuration |
mbed_official | 237:f3da66175598 | 147 | can only be modified after HW reset. |
mbed_official | 237:f3da66175598 | 148 | |
mbed_official | 237:f3da66175598 | 149 | *** Running mode: change of configuration while OPAMP ON *** |
mbed_official | 237:f3da66175598 | 150 | ============================================ |
mbed_official | 237:f3da66175598 | 151 | To Re-configure OPAMP when OPAMP is ON (change on the fly) |
mbed_official | 237:f3da66175598 | 152 | (#) If needed, Fill in the HAL_OPAMP_MspInit() |
mbed_official | 237:f3da66175598 | 153 | (+) This is the case for instance if youu wish to use new OPAMP I/O |
mbed_official | 237:f3da66175598 | 154 | |
mbed_official | 237:f3da66175598 | 155 | (#) Configure the opamp using HAL_OPAMP_Init() function: |
mbed_official | 237:f3da66175598 | 156 | (+) As in configure case, selects first the parameters you wish to modify. |
mbed_official | 237:f3da66175598 | 157 | |
mbed_official | 237:f3da66175598 | 158 | @endverbatim |
mbed_official | 237:f3da66175598 | 159 | ****************************************************************************** |
mbed_official | 237:f3da66175598 | 160 | * @attention |
mbed_official | 237:f3da66175598 | 161 | * |
mbed_official | 237:f3da66175598 | 162 | * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2> |
mbed_official | 237:f3da66175598 | 163 | * |
mbed_official | 237:f3da66175598 | 164 | * Redistribution and use in source and binary forms, with or without modification, |
mbed_official | 237:f3da66175598 | 165 | * are permitted provided that the following conditions are met: |
mbed_official | 237:f3da66175598 | 166 | * 1. Redistributions of source code must retain the above copyright notice, |
mbed_official | 237:f3da66175598 | 167 | * this list of conditions and the following disclaimer. |
mbed_official | 237:f3da66175598 | 168 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
mbed_official | 237:f3da66175598 | 169 | * this list of conditions and the following disclaimer in the documentation |
mbed_official | 237:f3da66175598 | 170 | * and/or other materials provided with the distribution. |
mbed_official | 237:f3da66175598 | 171 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
mbed_official | 237:f3da66175598 | 172 | * may be used to endorse or promote products derived from this software |
mbed_official | 237:f3da66175598 | 173 | * without specific prior written permission. |
mbed_official | 237:f3da66175598 | 174 | * |
mbed_official | 237:f3da66175598 | 175 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
mbed_official | 237:f3da66175598 | 176 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
mbed_official | 237:f3da66175598 | 177 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
mbed_official | 237:f3da66175598 | 178 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
mbed_official | 237:f3da66175598 | 179 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
mbed_official | 237:f3da66175598 | 180 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
mbed_official | 237:f3da66175598 | 181 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
mbed_official | 237:f3da66175598 | 182 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
mbed_official | 237:f3da66175598 | 183 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
mbed_official | 237:f3da66175598 | 184 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
mbed_official | 237:f3da66175598 | 185 | * |
mbed_official | 237:f3da66175598 | 186 | ****************************************************************************** |
mbed_official | 237:f3da66175598 | 187 | */ |
mbed_official | 237:f3da66175598 | 188 | |
mbed_official | 237:f3da66175598 | 189 | /* Includes ------------------------------------------------------------------*/ |
mbed_official | 237:f3da66175598 | 190 | #include "stm32f3xx_hal.h" |
mbed_official | 237:f3da66175598 | 191 | |
mbed_official | 237:f3da66175598 | 192 | /** @addtogroup STM32F3xx_HAL_Driver |
mbed_official | 237:f3da66175598 | 193 | * @{ |
mbed_official | 237:f3da66175598 | 194 | */ |
mbed_official | 237:f3da66175598 | 195 | |
mbed_official | 237:f3da66175598 | 196 | /** @defgroup OPAMP |
mbed_official | 237:f3da66175598 | 197 | * @brief OPAMP HAL module driver |
mbed_official | 237:f3da66175598 | 198 | * @{ |
mbed_official | 237:f3da66175598 | 199 | */ |
mbed_official | 237:f3da66175598 | 200 | |
mbed_official | 237:f3da66175598 | 201 | #ifdef HAL_OPAMP_MODULE_ENABLED |
mbed_official | 237:f3da66175598 | 202 | |
mbed_official | 237:f3da66175598 | 203 | #if defined (STM32F303xC) || defined (STM32F358xx) || defined (STM32F302xC) || \ |
mbed_official | 237:f3da66175598 | 204 | defined (STM32F303x8) || defined (STM32F328xx) || defined (STM32F302x8) || \ |
mbed_official | 237:f3da66175598 | 205 | defined (STM32F301x8) || defined (STM32F318xx) || defined (STM32F334x8) |
mbed_official | 237:f3da66175598 | 206 | |
mbed_official | 237:f3da66175598 | 207 | /* Private typedef -----------------------------------------------------------*/ |
mbed_official | 237:f3da66175598 | 208 | /* Private define ------------------------------------------------------------*/ |
mbed_official | 237:f3da66175598 | 209 | /* CSR register reset value */ |
mbed_official | 237:f3da66175598 | 210 | #define OPAMP_CSR_RESET_VALUE ((uint32_t)0x00000000) |
mbed_official | 237:f3da66175598 | 211 | |
mbed_official | 237:f3da66175598 | 212 | /* Private macro -------------------------------------------------------------*/ |
mbed_official | 237:f3da66175598 | 213 | /* Private variables ---------------------------------------------------------*/ |
mbed_official | 237:f3da66175598 | 214 | /* Private function prototypes -----------------------------------------------*/ |
mbed_official | 237:f3da66175598 | 215 | /* Private functions ---------------------------------------------------------*/ |
mbed_official | 237:f3da66175598 | 216 | |
mbed_official | 237:f3da66175598 | 217 | /** @defgroup OPAMP_Private_Functions |
mbed_official | 237:f3da66175598 | 218 | * @{ |
mbed_official | 237:f3da66175598 | 219 | */ |
mbed_official | 237:f3da66175598 | 220 | |
mbed_official | 237:f3da66175598 | 221 | /** @defgroup HAL_OPAMP_Group1 Initialization/de-initialization functions |
mbed_official | 237:f3da66175598 | 222 | * @brief Initialization and Configuration functions |
mbed_official | 237:f3da66175598 | 223 | * |
mbed_official | 237:f3da66175598 | 224 | @verbatim |
mbed_official | 237:f3da66175598 | 225 | =============================================================================== |
mbed_official | 237:f3da66175598 | 226 | ##### Initialization/de-initialization functions ##### |
mbed_official | 237:f3da66175598 | 227 | =============================================================================== |
mbed_official | 237:f3da66175598 | 228 | [..] This section provides functions allowing to: |
mbed_official | 237:f3da66175598 | 229 | |
mbed_official | 237:f3da66175598 | 230 | @endverbatim |
mbed_official | 237:f3da66175598 | 231 | * @{ |
mbed_official | 237:f3da66175598 | 232 | */ |
mbed_official | 237:f3da66175598 | 233 | |
mbed_official | 237:f3da66175598 | 234 | /** |
mbed_official | 237:f3da66175598 | 235 | * @brief Initializes the OPAMP according to the specified |
mbed_official | 237:f3da66175598 | 236 | * parameters in the OPAMP_InitTypeDef and create the associated handle. |
mbed_official | 237:f3da66175598 | 237 | * @note If the selected opamp is locked, initialization can't be performed. |
mbed_official | 237:f3da66175598 | 238 | * To unlock the configuration, perform a system reset. |
mbed_official | 237:f3da66175598 | 239 | * @param hopamp: OPAMP handle |
mbed_official | 237:f3da66175598 | 240 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 241 | */ |
mbed_official | 237:f3da66175598 | 242 | HAL_StatusTypeDef HAL_OPAMP_Init(OPAMP_HandleTypeDef *hopamp) |
mbed_official | 237:f3da66175598 | 243 | |
mbed_official | 237:f3da66175598 | 244 | { |
mbed_official | 237:f3da66175598 | 245 | HAL_StatusTypeDef status = HAL_OK; |
mbed_official | 237:f3da66175598 | 246 | |
mbed_official | 237:f3da66175598 | 247 | /* Check the OPAMP handle allocation and lock status */ |
mbed_official | 237:f3da66175598 | 248 | /* Init not allowed if calibration is ongoing */ |
mbed_official | 237:f3da66175598 | 249 | if((hopamp == NULL) || (hopamp->State == HAL_OPAMP_STATE_BUSYLOCKED) \ |
mbed_official | 237:f3da66175598 | 250 | || (hopamp->State == HAL_OPAMP_STATE_CALIBBUSY)) |
mbed_official | 237:f3da66175598 | 251 | { |
mbed_official | 237:f3da66175598 | 252 | return HAL_ERROR; |
mbed_official | 237:f3da66175598 | 253 | } |
mbed_official | 237:f3da66175598 | 254 | else |
mbed_official | 237:f3da66175598 | 255 | { |
mbed_official | 237:f3da66175598 | 256 | |
mbed_official | 237:f3da66175598 | 257 | /* Check the parameter */ |
mbed_official | 237:f3da66175598 | 258 | assert_param(IS_OPAMP_ALL_INSTANCE(hopamp->Instance)); |
mbed_official | 237:f3da66175598 | 259 | |
mbed_official | 237:f3da66175598 | 260 | /* Set OPAMP parameters */ |
mbed_official | 237:f3da66175598 | 261 | assert_param(IS_OPAMP_FUNCTIONAL_NORMALMODE(hopamp->Init.Mode)); |
mbed_official | 237:f3da66175598 | 262 | assert_param(IS_OPAMP_NONINVERTING_INPUT(hopamp->Init.NonInvertingInput)); |
mbed_official | 237:f3da66175598 | 263 | if (((hopamp->Init.Mode) == OPAMP_STANDALONE_MODE) || ((hopamp->Init.Mode) == OPAMP_PGA_MODE)) |
mbed_official | 237:f3da66175598 | 264 | { |
mbed_official | 237:f3da66175598 | 265 | assert_param(IS_OPAMP_INVERTING_INPUT(hopamp->Init.InvertingInput)); |
mbed_official | 237:f3da66175598 | 266 | } |
mbed_official | 237:f3da66175598 | 267 | |
mbed_official | 237:f3da66175598 | 268 | assert_param(IS_OPAMP_TIMERCONTROLLED_MUXMODE(hopamp->Init.TimerControlledMuxmode)); |
mbed_official | 237:f3da66175598 | 269 | |
mbed_official | 237:f3da66175598 | 270 | if ((hopamp->Init.TimerControlledMuxmode) == OPAMP_TIMERCONTROLLEDMUXMODE_ENABLE) |
mbed_official | 237:f3da66175598 | 271 | { |
mbed_official | 237:f3da66175598 | 272 | assert_param(IS_OPAMP_SEC_NONINVERTINGINPUT(hopamp->Init.NonInvertingInputSecondary)); |
mbed_official | 237:f3da66175598 | 273 | if (((hopamp->Init.Mode) == OPAMP_STANDALONE_MODE) || ((hopamp->Init.Mode) == OPAMP_PGA_MODE)) |
mbed_official | 237:f3da66175598 | 274 | { |
mbed_official | 237:f3da66175598 | 275 | assert_param(IS_OPAMP_SEC_INVERTINGINPUT(hopamp->Init.InvertingInputSecondary)); |
mbed_official | 237:f3da66175598 | 276 | } |
mbed_official | 237:f3da66175598 | 277 | } |
mbed_official | 237:f3da66175598 | 278 | |
mbed_official | 237:f3da66175598 | 279 | if ((hopamp->Init.Mode) == OPAMP_PGA_MODE) |
mbed_official | 237:f3da66175598 | 280 | { |
mbed_official | 237:f3da66175598 | 281 | assert_param(IS_OPAMP_PGACONNECT(hopamp->Init.PgaConnect)); |
mbed_official | 237:f3da66175598 | 282 | assert_param(IS_OPAMP_PGA_GAIN(hopamp->Init.PgaGain)); |
mbed_official | 237:f3da66175598 | 283 | } |
mbed_official | 237:f3da66175598 | 284 | |
mbed_official | 237:f3da66175598 | 285 | assert_param(IS_OPAMP_TRIMMING(hopamp->Init.UserTrimming)); |
mbed_official | 237:f3da66175598 | 286 | if ((hopamp->Init.UserTrimming) == OPAMP_TRIMMING_USER) |
mbed_official | 237:f3da66175598 | 287 | { |
mbed_official | 237:f3da66175598 | 288 | assert_param(IS_OPAMP_TRIMMINGVALUE(hopamp->Init.TrimmingValueP)); |
mbed_official | 237:f3da66175598 | 289 | assert_param(IS_OPAMP_TRIMMINGVALUE(hopamp->Init.TrimmingValueN)); |
mbed_official | 237:f3da66175598 | 290 | } |
mbed_official | 237:f3da66175598 | 291 | |
mbed_official | 237:f3da66175598 | 292 | /* Init SYSCFG and the low level hardware to access opamp */ |
mbed_official | 237:f3da66175598 | 293 | __SYSCFG_CLK_ENABLE(); |
mbed_official | 237:f3da66175598 | 294 | |
mbed_official | 237:f3da66175598 | 295 | /* Call MSP init function */ |
mbed_official | 237:f3da66175598 | 296 | HAL_OPAMP_MspInit(hopamp); |
mbed_official | 237:f3da66175598 | 297 | |
mbed_official | 237:f3da66175598 | 298 | /* Set OPAMP parameters */ |
mbed_official | 237:f3da66175598 | 299 | /* Set bits according to hopamp->hopamp->Init.Mode value */ |
mbed_official | 237:f3da66175598 | 300 | /* Set bits according to hopamp->hopamp->Init.InvertingInput value */ |
mbed_official | 237:f3da66175598 | 301 | /* Set bits according to hopamp->hopamp->Init.NonInvertingInput value */ |
mbed_official | 237:f3da66175598 | 302 | /* Set bits according to hopamp->hopamp->Init.TimerControlledMuxmode value */ |
mbed_official | 237:f3da66175598 | 303 | /* Set bits according to hopamp->hopamp->Init.InvertingInputSecondary value */ |
mbed_official | 237:f3da66175598 | 304 | /* Set bits according to hopamp->hopamp->Init.NonInvertingInputSecondary value */ |
mbed_official | 237:f3da66175598 | 305 | /* Set bits according to hopamp->hopamp->Init.PgaConnect value */ |
mbed_official | 237:f3da66175598 | 306 | /* Set bits according to hopamp->hopamp->Init.PgaGain value */ |
mbed_official | 237:f3da66175598 | 307 | /* Set bits according to hopamp->hopamp->Init.UserTrimming value */ |
mbed_official | 237:f3da66175598 | 308 | /* Set bits according to hopamp->hopamp->Init.TrimmingValueP value */ |
mbed_official | 237:f3da66175598 | 309 | /* Set bits according to hopamp->hopamp->Init.TrimmingValueN value */ |
mbed_official | 237:f3da66175598 | 310 | |
mbed_official | 237:f3da66175598 | 311 | |
mbed_official | 237:f3da66175598 | 312 | /* check if OPAMP_PGA_MODE & in Follower mode */ |
mbed_official | 237:f3da66175598 | 313 | /* - InvertingInput */ |
mbed_official | 237:f3da66175598 | 314 | /* - InvertingInputSecondary */ |
mbed_official | 237:f3da66175598 | 315 | /* are Not Applicable */ |
mbed_official | 237:f3da66175598 | 316 | |
mbed_official | 237:f3da66175598 | 317 | if ((hopamp->Init.Mode == OPAMP_PGA_MODE) || (hopamp->Init.Mode == OPAMP_FOLLOWER_MODE)) |
mbed_official | 237:f3da66175598 | 318 | { |
mbed_official | 237:f3da66175598 | 319 | MODIFY_REG(hopamp->Instance->CSR, OPAMP_CSR_UPDATE_PARAMETERS_INIT_MASK, \ |
mbed_official | 237:f3da66175598 | 320 | hopamp->Init.Mode | \ |
mbed_official | 237:f3da66175598 | 321 | hopamp->Init.NonInvertingInput | \ |
mbed_official | 237:f3da66175598 | 322 | hopamp->Init.TimerControlledMuxmode | \ |
mbed_official | 237:f3da66175598 | 323 | hopamp->Init.NonInvertingInputSecondary | \ |
mbed_official | 237:f3da66175598 | 324 | hopamp->Init.PgaConnect | \ |
mbed_official | 237:f3da66175598 | 325 | hopamp->Init.PgaGain | \ |
mbed_official | 237:f3da66175598 | 326 | hopamp->Init.UserTrimming | \ |
mbed_official | 237:f3da66175598 | 327 | (hopamp->Init.TrimmingValueP << OPAMP_INPUT_NONINVERTING) | \ |
mbed_official | 237:f3da66175598 | 328 | (hopamp->Init.TrimmingValueN << OPAMP_INPUT_INVERTING)); |
mbed_official | 237:f3da66175598 | 329 | } |
mbed_official | 237:f3da66175598 | 330 | else |
mbed_official | 237:f3da66175598 | 331 | { |
mbed_official | 237:f3da66175598 | 332 | MODIFY_REG(hopamp->Instance->CSR, OPAMP_CSR_UPDATE_PARAMETERS_INIT_MASK, \ |
mbed_official | 237:f3da66175598 | 333 | hopamp->Init.Mode | \ |
mbed_official | 237:f3da66175598 | 334 | hopamp->Init.InvertingInput | \ |
mbed_official | 237:f3da66175598 | 335 | hopamp->Init.NonInvertingInput | \ |
mbed_official | 237:f3da66175598 | 336 | hopamp->Init.TimerControlledMuxmode | \ |
mbed_official | 237:f3da66175598 | 337 | hopamp->Init.InvertingInputSecondary | \ |
mbed_official | 237:f3da66175598 | 338 | hopamp->Init.NonInvertingInputSecondary | \ |
mbed_official | 237:f3da66175598 | 339 | hopamp->Init.PgaConnect | \ |
mbed_official | 237:f3da66175598 | 340 | hopamp->Init.PgaGain | \ |
mbed_official | 237:f3da66175598 | 341 | hopamp->Init.UserTrimming | \ |
mbed_official | 237:f3da66175598 | 342 | (hopamp->Init.TrimmingValueP << OPAMP_INPUT_NONINVERTING) | \ |
mbed_official | 237:f3da66175598 | 343 | (hopamp->Init.TrimmingValueN << OPAMP_INPUT_INVERTING)); |
mbed_official | 237:f3da66175598 | 344 | } |
mbed_official | 237:f3da66175598 | 345 | /* Update the OPAMP state*/ |
mbed_official | 237:f3da66175598 | 346 | if (hopamp->State == HAL_OPAMP_STATE_RESET) |
mbed_official | 237:f3da66175598 | 347 | { |
mbed_official | 237:f3da66175598 | 348 | /* From RESET state to READY State */ |
mbed_official | 237:f3da66175598 | 349 | hopamp->State = HAL_OPAMP_STATE_READY; |
mbed_official | 237:f3da66175598 | 350 | } |
mbed_official | 237:f3da66175598 | 351 | /* else: remain in READY or BUSY state (no update) */ |
mbed_official | 237:f3da66175598 | 352 | |
mbed_official | 237:f3da66175598 | 353 | return status; |
mbed_official | 237:f3da66175598 | 354 | } |
mbed_official | 237:f3da66175598 | 355 | } |
mbed_official | 237:f3da66175598 | 356 | |
mbed_official | 237:f3da66175598 | 357 | /** |
mbed_official | 237:f3da66175598 | 358 | * @brief DeInitializes the OPAMP peripheral |
mbed_official | 237:f3da66175598 | 359 | * @note Deinitialization can't be performed if the OPAMP configuration is locked. |
mbed_official | 237:f3da66175598 | 360 | * To unlock the configuration, perform a system reset. |
mbed_official | 237:f3da66175598 | 361 | * @param hopamp: OPAMP handle |
mbed_official | 237:f3da66175598 | 362 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 363 | */ |
mbed_official | 237:f3da66175598 | 364 | HAL_StatusTypeDef HAL_OPAMP_DeInit(OPAMP_HandleTypeDef *hopamp) |
mbed_official | 237:f3da66175598 | 365 | { |
mbed_official | 237:f3da66175598 | 366 | HAL_StatusTypeDef status = HAL_OK; |
mbed_official | 237:f3da66175598 | 367 | |
mbed_official | 237:f3da66175598 | 368 | /* Check the OPAMP handle allocation */ |
mbed_official | 237:f3da66175598 | 369 | /* Check if OPAMP locked */ |
mbed_official | 237:f3da66175598 | 370 | /* DeInit not allowed if calibration is ongoing */ |
mbed_official | 237:f3da66175598 | 371 | if((hopamp == NULL) || (hopamp->State == HAL_OPAMP_STATE_BUSYLOCKED) \ |
mbed_official | 237:f3da66175598 | 372 | || (hopamp->State == HAL_OPAMP_STATE_CALIBBUSY)) |
mbed_official | 237:f3da66175598 | 373 | { |
mbed_official | 237:f3da66175598 | 374 | status = HAL_ERROR; |
mbed_official | 237:f3da66175598 | 375 | } |
mbed_official | 237:f3da66175598 | 376 | else |
mbed_official | 237:f3da66175598 | 377 | { |
mbed_official | 237:f3da66175598 | 378 | /* Check the parameter */ |
mbed_official | 237:f3da66175598 | 379 | assert_param(IS_OPAMP_ALL_INSTANCE(hopamp->Instance)); |
mbed_official | 237:f3da66175598 | 380 | |
mbed_official | 237:f3da66175598 | 381 | /* Set OPAMP_CSR register to reset value */ |
mbed_official | 237:f3da66175598 | 382 | WRITE_REG(hopamp->Instance->CSR, OPAMP_CSR_RESET_VALUE); |
mbed_official | 237:f3da66175598 | 383 | |
mbed_official | 237:f3da66175598 | 384 | /* DeInit the low level hardware: GPIO, CLOCK and NVIC */ |
mbed_official | 237:f3da66175598 | 385 | HAL_OPAMP_MspDeInit(hopamp); |
mbed_official | 237:f3da66175598 | 386 | |
mbed_official | 237:f3da66175598 | 387 | /* Update the OPAMP state*/ |
mbed_official | 237:f3da66175598 | 388 | hopamp->State = HAL_OPAMP_STATE_RESET; |
mbed_official | 237:f3da66175598 | 389 | } |
mbed_official | 237:f3da66175598 | 390 | return status; |
mbed_official | 237:f3da66175598 | 391 | } |
mbed_official | 237:f3da66175598 | 392 | |
mbed_official | 237:f3da66175598 | 393 | /** |
mbed_official | 237:f3da66175598 | 394 | * @brief Initializes the OPAMP MSP. |
mbed_official | 237:f3da66175598 | 395 | * @param hopamp: OPAMP handle |
mbed_official | 237:f3da66175598 | 396 | * @retval None |
mbed_official | 237:f3da66175598 | 397 | */ |
mbed_official | 237:f3da66175598 | 398 | __weak void HAL_OPAMP_MspInit(OPAMP_HandleTypeDef *hopamp) |
mbed_official | 237:f3da66175598 | 399 | { |
mbed_official | 237:f3da66175598 | 400 | /* NOTE : This function should not be modified, when the callback is needed, |
mbed_official | 237:f3da66175598 | 401 | the HAL_OPAMP_MspInit could be implemented in the user file |
mbed_official | 237:f3da66175598 | 402 | */ |
mbed_official | 237:f3da66175598 | 403 | |
mbed_official | 237:f3da66175598 | 404 | /* Example */ |
mbed_official | 237:f3da66175598 | 405 | } |
mbed_official | 237:f3da66175598 | 406 | |
mbed_official | 237:f3da66175598 | 407 | /** |
mbed_official | 237:f3da66175598 | 408 | * @brief DeInitializes OPAMP MSP. |
mbed_official | 237:f3da66175598 | 409 | * @param hopamp: OPAMP handle |
mbed_official | 237:f3da66175598 | 410 | * @retval None |
mbed_official | 237:f3da66175598 | 411 | */ |
mbed_official | 237:f3da66175598 | 412 | __weak void HAL_OPAMP_MspDeInit(OPAMP_HandleTypeDef *hopamp) |
mbed_official | 237:f3da66175598 | 413 | { |
mbed_official | 237:f3da66175598 | 414 | /* NOTE : This function should not be modified, when the callback is needed, |
mbed_official | 237:f3da66175598 | 415 | the HAL_OPAMP_MspDeInit could be implemented in the user file |
mbed_official | 237:f3da66175598 | 416 | */ |
mbed_official | 237:f3da66175598 | 417 | |
mbed_official | 237:f3da66175598 | 418 | } |
mbed_official | 237:f3da66175598 | 419 | |
mbed_official | 237:f3da66175598 | 420 | /** |
mbed_official | 237:f3da66175598 | 421 | * @} |
mbed_official | 237:f3da66175598 | 422 | */ |
mbed_official | 237:f3da66175598 | 423 | |
mbed_official | 237:f3da66175598 | 424 | |
mbed_official | 237:f3da66175598 | 425 | /** @defgroup HAL_OPAMP_Group2 I/O operation functions |
mbed_official | 237:f3da66175598 | 426 | * @brief Data transfers functions |
mbed_official | 237:f3da66175598 | 427 | * |
mbed_official | 237:f3da66175598 | 428 | @verbatim |
mbed_official | 237:f3da66175598 | 429 | =============================================================================== |
mbed_official | 237:f3da66175598 | 430 | ##### IO operation functions ##### |
mbed_official | 237:f3da66175598 | 431 | =============================================================================== |
mbed_official | 237:f3da66175598 | 432 | [..] |
mbed_official | 237:f3da66175598 | 433 | This subsection provides a set of functions allowing to manage the OPAMP data |
mbed_official | 237:f3da66175598 | 434 | transfers. |
mbed_official | 237:f3da66175598 | 435 | |
mbed_official | 237:f3da66175598 | 436 | @endverbatim |
mbed_official | 237:f3da66175598 | 437 | * @{ |
mbed_official | 237:f3da66175598 | 438 | */ |
mbed_official | 237:f3da66175598 | 439 | |
mbed_official | 237:f3da66175598 | 440 | /** |
mbed_official | 237:f3da66175598 | 441 | * @brief Start the opamp |
mbed_official | 237:f3da66175598 | 442 | * @param hopamp: OPAMP handle |
mbed_official | 237:f3da66175598 | 443 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 444 | */ |
mbed_official | 237:f3da66175598 | 445 | |
mbed_official | 237:f3da66175598 | 446 | HAL_StatusTypeDef HAL_OPAMP_Start(OPAMP_HandleTypeDef *hopamp) |
mbed_official | 237:f3da66175598 | 447 | { |
mbed_official | 237:f3da66175598 | 448 | HAL_StatusTypeDef status = HAL_OK; |
mbed_official | 237:f3da66175598 | 449 | |
mbed_official | 237:f3da66175598 | 450 | /* Check the OPAMP handle allocation */ |
mbed_official | 237:f3da66175598 | 451 | /* Check if OPAMP locked */ |
mbed_official | 237:f3da66175598 | 452 | if((hopamp == NULL) || (hopamp->State == HAL_OPAMP_STATE_BUSYLOCKED)) |
mbed_official | 237:f3da66175598 | 453 | |
mbed_official | 237:f3da66175598 | 454 | { |
mbed_official | 237:f3da66175598 | 455 | status = HAL_ERROR; |
mbed_official | 237:f3da66175598 | 456 | } |
mbed_official | 237:f3da66175598 | 457 | else |
mbed_official | 237:f3da66175598 | 458 | { |
mbed_official | 237:f3da66175598 | 459 | /* Check the parameter */ |
mbed_official | 237:f3da66175598 | 460 | assert_param(IS_OPAMP_ALL_INSTANCE(hopamp->Instance)); |
mbed_official | 237:f3da66175598 | 461 | |
mbed_official | 237:f3da66175598 | 462 | if(hopamp->State == HAL_OPAMP_STATE_READY) |
mbed_official | 237:f3da66175598 | 463 | { |
mbed_official | 237:f3da66175598 | 464 | /* Enable the selected opamp */ |
mbed_official | 237:f3da66175598 | 465 | SET_BIT (hopamp->Instance->CSR, OPAMP_CSR_OPAMPxEN); |
mbed_official | 237:f3da66175598 | 466 | |
mbed_official | 237:f3da66175598 | 467 | /* Update the OPAMP state*/ |
mbed_official | 237:f3da66175598 | 468 | /* From HAL_OPAMP_STATE_READY to HAL_OPAMP_STATE_BUSY */ |
mbed_official | 237:f3da66175598 | 469 | hopamp->State = HAL_OPAMP_STATE_BUSY; |
mbed_official | 237:f3da66175598 | 470 | } |
mbed_official | 237:f3da66175598 | 471 | else |
mbed_official | 237:f3da66175598 | 472 | { |
mbed_official | 237:f3da66175598 | 473 | status = HAL_ERROR; |
mbed_official | 237:f3da66175598 | 474 | } |
mbed_official | 237:f3da66175598 | 475 | |
mbed_official | 237:f3da66175598 | 476 | |
mbed_official | 237:f3da66175598 | 477 | } |
mbed_official | 237:f3da66175598 | 478 | return status; |
mbed_official | 237:f3da66175598 | 479 | } |
mbed_official | 237:f3da66175598 | 480 | |
mbed_official | 237:f3da66175598 | 481 | /** |
mbed_official | 237:f3da66175598 | 482 | * @brief Stop the opamp |
mbed_official | 237:f3da66175598 | 483 | * @param hopamp: OPAMP handle |
mbed_official | 237:f3da66175598 | 484 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 485 | */ |
mbed_official | 237:f3da66175598 | 486 | HAL_StatusTypeDef HAL_OPAMP_Stop(OPAMP_HandleTypeDef *hopamp) |
mbed_official | 237:f3da66175598 | 487 | { |
mbed_official | 237:f3da66175598 | 488 | HAL_StatusTypeDef status = HAL_OK; |
mbed_official | 237:f3da66175598 | 489 | |
mbed_official | 237:f3da66175598 | 490 | /* Check the OPAMP handle allocation */ |
mbed_official | 237:f3da66175598 | 491 | /* Check if OPAMP locked */ |
mbed_official | 237:f3da66175598 | 492 | /* Check if OPAMP calibration ongoing */ |
mbed_official | 237:f3da66175598 | 493 | if((hopamp == NULL) || (hopamp->State == HAL_OPAMP_STATE_BUSYLOCKED) \ |
mbed_official | 237:f3da66175598 | 494 | || (hopamp->State == HAL_OPAMP_STATE_CALIBBUSY)) |
mbed_official | 237:f3da66175598 | 495 | { |
mbed_official | 237:f3da66175598 | 496 | status = HAL_ERROR; |
mbed_official | 237:f3da66175598 | 497 | } |
mbed_official | 237:f3da66175598 | 498 | else |
mbed_official | 237:f3da66175598 | 499 | { |
mbed_official | 237:f3da66175598 | 500 | /* Check the parameter */ |
mbed_official | 237:f3da66175598 | 501 | assert_param(IS_OPAMP_ALL_INSTANCE(hopamp->Instance)); |
mbed_official | 237:f3da66175598 | 502 | |
mbed_official | 237:f3da66175598 | 503 | if(hopamp->State == HAL_OPAMP_STATE_BUSY) |
mbed_official | 237:f3da66175598 | 504 | { |
mbed_official | 237:f3da66175598 | 505 | /* Disable the selected opamp */ |
mbed_official | 237:f3da66175598 | 506 | CLEAR_BIT (hopamp->Instance->CSR, OPAMP_CSR_OPAMPxEN); |
mbed_official | 237:f3da66175598 | 507 | |
mbed_official | 237:f3da66175598 | 508 | /* Update the OPAMP state*/ |
mbed_official | 237:f3da66175598 | 509 | /* From HAL_OPAMP_STATE_BUSY to HAL_OPAMP_STATE_READY*/ |
mbed_official | 237:f3da66175598 | 510 | hopamp->State = HAL_OPAMP_STATE_READY; |
mbed_official | 237:f3da66175598 | 511 | } |
mbed_official | 237:f3da66175598 | 512 | else |
mbed_official | 237:f3da66175598 | 513 | { |
mbed_official | 237:f3da66175598 | 514 | status = HAL_ERROR; |
mbed_official | 237:f3da66175598 | 515 | } |
mbed_official | 237:f3da66175598 | 516 | } |
mbed_official | 237:f3da66175598 | 517 | return status; |
mbed_official | 237:f3da66175598 | 518 | } |
mbed_official | 237:f3da66175598 | 519 | |
mbed_official | 237:f3da66175598 | 520 | /** |
mbed_official | 237:f3da66175598 | 521 | * @brief Run the self calibration of one OPAMP |
mbed_official | 237:f3da66175598 | 522 | * @param hopamp handle |
mbed_official | 237:f3da66175598 | 523 | * @retval Updated offset trimming values (PMOS & NMOS), user trimming is enabled |
mbed_official | 237:f3da66175598 | 524 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 525 | * @note Calibration runs about 25 ms. |
mbed_official | 237:f3da66175598 | 526 | */ |
mbed_official | 237:f3da66175598 | 527 | |
mbed_official | 237:f3da66175598 | 528 | HAL_StatusTypeDef HAL_OPAMP_SelfCalibrate(OPAMP_HandleTypeDef *hopamp) |
mbed_official | 237:f3da66175598 | 529 | { |
mbed_official | 237:f3da66175598 | 530 | |
mbed_official | 237:f3da66175598 | 531 | HAL_StatusTypeDef status = HAL_OK; |
mbed_official | 237:f3da66175598 | 532 | |
mbed_official | 237:f3da66175598 | 533 | uint32_t trimmingvaluen = 0; |
mbed_official | 237:f3da66175598 | 534 | uint32_t trimmingvaluep = 0; |
mbed_official | 237:f3da66175598 | 535 | uint32_t delta; |
mbed_official | 237:f3da66175598 | 536 | |
mbed_official | 237:f3da66175598 | 537 | /* Check the OPAMP handle allocation */ |
mbed_official | 237:f3da66175598 | 538 | /* Check if OPAMP locked */ |
mbed_official | 237:f3da66175598 | 539 | if((hopamp == NULL) || (hopamp->State == HAL_OPAMP_STATE_BUSYLOCKED)) |
mbed_official | 237:f3da66175598 | 540 | { |
mbed_official | 237:f3da66175598 | 541 | status = HAL_ERROR; |
mbed_official | 237:f3da66175598 | 542 | } |
mbed_official | 237:f3da66175598 | 543 | else |
mbed_official | 237:f3da66175598 | 544 | { |
mbed_official | 237:f3da66175598 | 545 | |
mbed_official | 237:f3da66175598 | 546 | /* Check if OPAMP in calibration mode and calibration not yet enable */ |
mbed_official | 237:f3da66175598 | 547 | if(hopamp->State == HAL_OPAMP_STATE_READY) |
mbed_official | 237:f3da66175598 | 548 | { |
mbed_official | 237:f3da66175598 | 549 | /* Check the parameter */ |
mbed_official | 237:f3da66175598 | 550 | assert_param(IS_OPAMP_ALL_INSTANCE(hopamp->Instance)); |
mbed_official | 237:f3da66175598 | 551 | |
mbed_official | 237:f3da66175598 | 552 | /* Set Calibration mode */ |
mbed_official | 237:f3da66175598 | 553 | /* Non-inverting input connected to calibration reference voltage. */ |
mbed_official | 237:f3da66175598 | 554 | SET_BIT(hopamp->Instance->CSR, OPAMP_CSR_FORCEVP); |
mbed_official | 237:f3da66175598 | 555 | |
mbed_official | 237:f3da66175598 | 556 | /* user trimming values are used for offset calibration */ |
mbed_official | 237:f3da66175598 | 557 | SET_BIT(hopamp->Instance->CSR, OPAMP_CSR_USERTRIM); |
mbed_official | 237:f3da66175598 | 558 | |
mbed_official | 237:f3da66175598 | 559 | /* Enable calibration */ |
mbed_official | 237:f3da66175598 | 560 | SET_BIT (hopamp->Instance->CSR, OPAMP_CSR_CALON); |
mbed_official | 237:f3da66175598 | 561 | |
mbed_official | 237:f3da66175598 | 562 | /* 1st calibration - N */ |
mbed_official | 237:f3da66175598 | 563 | /* Select 90% VREF */ |
mbed_official | 237:f3da66175598 | 564 | MODIFY_REG(hopamp->Instance->CSR, OPAMP_CSR_CALSEL, OPAMP_VREF_90VDDA); |
mbed_official | 237:f3da66175598 | 565 | |
mbed_official | 237:f3da66175598 | 566 | /* Enable the selected opamp */ |
mbed_official | 237:f3da66175598 | 567 | SET_BIT (hopamp->Instance->CSR, OPAMP_CSR_OPAMPxEN); |
mbed_official | 237:f3da66175598 | 568 | |
mbed_official | 237:f3da66175598 | 569 | /* Init trimming counter */ |
mbed_official | 237:f3da66175598 | 570 | /* Medium value */ |
mbed_official | 237:f3da66175598 | 571 | trimmingvaluen = 16; |
mbed_official | 237:f3da66175598 | 572 | delta = 8; |
mbed_official | 237:f3da66175598 | 573 | |
mbed_official | 237:f3da66175598 | 574 | while (delta != 0) |
mbed_official | 237:f3da66175598 | 575 | { |
mbed_official | 237:f3da66175598 | 576 | /* Set candidate trimming */ |
mbed_official | 237:f3da66175598 | 577 | MODIFY_REG(hopamp->Instance->CSR, OPAMP_CSR_TRIMOFFSETN, trimmingvaluen<<OPAMP_INPUT_INVERTING); |
mbed_official | 237:f3da66175598 | 578 | |
mbed_official | 237:f3da66175598 | 579 | /* OFFTRIMmax delay 2 ms as per datasheet (electrical characteristics */ |
mbed_official | 237:f3da66175598 | 580 | /* Offset trim time: during calibration, minimum time needed between */ |
mbed_official | 237:f3da66175598 | 581 | /* two steps to have 1 mV accuracy */ |
mbed_official | 237:f3da66175598 | 582 | HAL_Delay(2); |
mbed_official | 237:f3da66175598 | 583 | |
mbed_official | 237:f3da66175598 | 584 | if ((hopamp->Instance->CSR & OPAMP_CSR_OUTCAL) != RESET) |
mbed_official | 237:f3da66175598 | 585 | { |
mbed_official | 237:f3da66175598 | 586 | /* OPAMP_CSR_OUTCAL is HIGH try higher trimming */ |
mbed_official | 237:f3da66175598 | 587 | trimmingvaluen += delta; |
mbed_official | 237:f3da66175598 | 588 | } |
mbed_official | 237:f3da66175598 | 589 | else |
mbed_official | 237:f3da66175598 | 590 | { |
mbed_official | 237:f3da66175598 | 591 | /* OPAMP_CSR_OUTCAL is LOW try lower trimming */ |
mbed_official | 237:f3da66175598 | 592 | trimmingvaluen -= delta; |
mbed_official | 237:f3da66175598 | 593 | } |
mbed_official | 237:f3da66175598 | 594 | |
mbed_official | 237:f3da66175598 | 595 | delta >>= 1; |
mbed_official | 237:f3da66175598 | 596 | } |
mbed_official | 237:f3da66175598 | 597 | |
mbed_official | 237:f3da66175598 | 598 | /* Still need to check if righ calibration is current value or un step below */ |
mbed_official | 237:f3da66175598 | 599 | /* Indeed the first value that causes the OUTCAL bit to change from 1 to 0 */ |
mbed_official | 237:f3da66175598 | 600 | MODIFY_REG(hopamp->Instance->CSR, OPAMP_CSR_TRIMOFFSETN, trimmingvaluen<<OPAMP_INPUT_INVERTING); |
mbed_official | 237:f3da66175598 | 601 | |
mbed_official | 237:f3da66175598 | 602 | /* OFFTRIMmax delay 2 ms as per datasheet (electrical characteristics */ |
mbed_official | 237:f3da66175598 | 603 | /* Offset trim time: during calibration, minimum time needed between */ |
mbed_official | 237:f3da66175598 | 604 | /* two steps to have 1 mV accuracy */ |
mbed_official | 237:f3da66175598 | 605 | HAL_Delay(2); |
mbed_official | 237:f3da66175598 | 606 | |
mbed_official | 237:f3da66175598 | 607 | if ((hopamp->Instance->CSR & OPAMP_CSR_OUTCAL) != RESET) |
mbed_official | 237:f3da66175598 | 608 | { |
mbed_official | 237:f3da66175598 | 609 | /* OPAMP_CSR_OUTCAL is actually one value more */ |
mbed_official | 237:f3da66175598 | 610 | trimmingvaluen++; |
mbed_official | 237:f3da66175598 | 611 | /* Set right trimming */ |
mbed_official | 237:f3da66175598 | 612 | MODIFY_REG(hopamp->Instance->CSR, OPAMP_CSR_TRIMOFFSETN, trimmingvaluen<<OPAMP_INPUT_INVERTING); |
mbed_official | 237:f3da66175598 | 613 | } |
mbed_official | 237:f3da66175598 | 614 | |
mbed_official | 237:f3da66175598 | 615 | /* 2nd calibration - P */ |
mbed_official | 237:f3da66175598 | 616 | /* Select 10% VREF */ |
mbed_official | 237:f3da66175598 | 617 | MODIFY_REG(hopamp->Instance->CSR, OPAMP_CSR_CALSEL, OPAMP_VREF_10VDDA); |
mbed_official | 237:f3da66175598 | 618 | |
mbed_official | 237:f3da66175598 | 619 | /* Init trimming counter */ |
mbed_official | 237:f3da66175598 | 620 | /* Medium value */ |
mbed_official | 237:f3da66175598 | 621 | trimmingvaluep = 16; |
mbed_official | 237:f3da66175598 | 622 | delta = 8; |
mbed_official | 237:f3da66175598 | 623 | |
mbed_official | 237:f3da66175598 | 624 | while (delta != 0) |
mbed_official | 237:f3da66175598 | 625 | { |
mbed_official | 237:f3da66175598 | 626 | /* Set candidate trimming */ |
mbed_official | 237:f3da66175598 | 627 | MODIFY_REG(hopamp->Instance->CSR, OPAMP_CSR_TRIMOFFSETP, trimmingvaluep<<OPAMP_INPUT_NONINVERTING); |
mbed_official | 237:f3da66175598 | 628 | |
mbed_official | 237:f3da66175598 | 629 | /* OFFTRIMmax delay 2 ms as per datasheet (electrical characteristics */ |
mbed_official | 237:f3da66175598 | 630 | /* Offset trim time: during calibration, minimum time needed between */ |
mbed_official | 237:f3da66175598 | 631 | /* two steps to have 1 mV accuracy */ |
mbed_official | 237:f3da66175598 | 632 | HAL_Delay(2); |
mbed_official | 237:f3da66175598 | 633 | |
mbed_official | 237:f3da66175598 | 634 | if ((hopamp->Instance->CSR & OPAMP_CSR_OUTCAL) != RESET) |
mbed_official | 237:f3da66175598 | 635 | { |
mbed_official | 237:f3da66175598 | 636 | /* OPAMP_CSR_OUTCAL is HIGH try higher trimming */ |
mbed_official | 237:f3da66175598 | 637 | trimmingvaluep += delta; |
mbed_official | 237:f3da66175598 | 638 | } |
mbed_official | 237:f3da66175598 | 639 | else |
mbed_official | 237:f3da66175598 | 640 | { |
mbed_official | 237:f3da66175598 | 641 | trimmingvaluep -= delta; |
mbed_official | 237:f3da66175598 | 642 | } |
mbed_official | 237:f3da66175598 | 643 | |
mbed_official | 237:f3da66175598 | 644 | delta >>= 1; |
mbed_official | 237:f3da66175598 | 645 | } |
mbed_official | 237:f3da66175598 | 646 | |
mbed_official | 237:f3da66175598 | 647 | /* Still need to check if righ calibration is current value or un step below */ |
mbed_official | 237:f3da66175598 | 648 | /* Indeed the first value that causes the OUTCAL bit to change from 1 to 0 */ |
mbed_official | 237:f3da66175598 | 649 | /* Set candidate trimming */ |
mbed_official | 237:f3da66175598 | 650 | MODIFY_REG(hopamp->Instance->CSR, OPAMP_CSR_TRIMOFFSETP, trimmingvaluep<<OPAMP_INPUT_NONINVERTING); |
mbed_official | 237:f3da66175598 | 651 | |
mbed_official | 237:f3da66175598 | 652 | /* OFFTRIMmax delay 2 ms as per datasheet (electrical characteristics */ |
mbed_official | 237:f3da66175598 | 653 | /* Offset trim time: during calibration, minimum time needed between */ |
mbed_official | 237:f3da66175598 | 654 | /* two steps to have 1 mV accuracy */ |
mbed_official | 237:f3da66175598 | 655 | HAL_Delay(2); |
mbed_official | 237:f3da66175598 | 656 | |
mbed_official | 237:f3da66175598 | 657 | if ((hopamp->Instance->CSR & OPAMP_CSR_OUTCAL) != RESET) |
mbed_official | 237:f3da66175598 | 658 | { |
mbed_official | 237:f3da66175598 | 659 | /* OPAMP_CSR_OUTCAL is actually one value more */ |
mbed_official | 237:f3da66175598 | 660 | trimmingvaluep++; |
mbed_official | 237:f3da66175598 | 661 | /* Set right trimming */ |
mbed_official | 237:f3da66175598 | 662 | MODIFY_REG(hopamp->Instance->CSR, OPAMP_CSR_TRIMOFFSETP, trimmingvaluep<<OPAMP_INPUT_NONINVERTING); |
mbed_official | 237:f3da66175598 | 663 | } |
mbed_official | 237:f3da66175598 | 664 | |
mbed_official | 237:f3da66175598 | 665 | /* Disable calibration */ |
mbed_official | 237:f3da66175598 | 666 | CLEAR_BIT (hopamp->Instance->CSR, OPAMP_CSR_CALON); |
mbed_official | 237:f3da66175598 | 667 | |
mbed_official | 237:f3da66175598 | 668 | /* Disable the OPAMP */ |
mbed_official | 237:f3da66175598 | 669 | CLEAR_BIT (hopamp->Instance->CSR, OPAMP_CSR_OPAMPxEN); |
mbed_official | 237:f3da66175598 | 670 | |
mbed_official | 237:f3da66175598 | 671 | /* Set normale operating mode */ |
mbed_official | 237:f3da66175598 | 672 | /* Non-inverting input connected to calibration reference voltage. */ |
mbed_official | 237:f3da66175598 | 673 | CLEAR_BIT(hopamp->Instance->CSR, OPAMP_CSR_FORCEVP); |
mbed_official | 237:f3da66175598 | 674 | |
mbed_official | 237:f3da66175598 | 675 | /* Set normale operating mode */ |
mbed_official | 237:f3da66175598 | 676 | /* Non-inverting input connected to calibration reference voltage. */ |
mbed_official | 237:f3da66175598 | 677 | CLEAR_BIT(hopamp->Instance->CSR, OPAMP_CSR_FORCEVP); |
mbed_official | 237:f3da66175598 | 678 | |
mbed_official | 237:f3da66175598 | 679 | /* Self calibration is successful */ |
mbed_official | 237:f3da66175598 | 680 | /* Store calibration(user timming) results in init structure. */ |
mbed_official | 237:f3da66175598 | 681 | |
mbed_official | 237:f3da66175598 | 682 | /* Write calibration result N */ |
mbed_official | 237:f3da66175598 | 683 | hopamp->Init.TrimmingValueN = trimmingvaluen; |
mbed_official | 237:f3da66175598 | 684 | |
mbed_official | 237:f3da66175598 | 685 | /* Write calibration result P */ |
mbed_official | 237:f3da66175598 | 686 | hopamp->Init.TrimmingValueP = trimmingvaluep; |
mbed_official | 237:f3da66175598 | 687 | |
mbed_official | 237:f3da66175598 | 688 | /* Select user timming mode */ |
mbed_official | 237:f3da66175598 | 689 | /* And updated with calibrated settings */ |
mbed_official | 237:f3da66175598 | 690 | hopamp->Init.UserTrimming = OPAMP_TRIMMING_USER; |
mbed_official | 237:f3da66175598 | 691 | MODIFY_REG(hopamp->Instance->CSR, OPAMP_CSR_TRIMOFFSETP, trimmingvaluep<<OPAMP_INPUT_NONINVERTING); |
mbed_official | 237:f3da66175598 | 692 | MODIFY_REG(hopamp->Instance->CSR, OPAMP_CSR_TRIMOFFSETN, trimmingvaluen<<OPAMP_INPUT_INVERTING); |
mbed_official | 237:f3da66175598 | 693 | } |
mbed_official | 237:f3da66175598 | 694 | |
mbed_official | 237:f3da66175598 | 695 | else |
mbed_official | 237:f3da66175598 | 696 | { |
mbed_official | 237:f3da66175598 | 697 | /* OPAMP can not be calibrated from this mode */ |
mbed_official | 237:f3da66175598 | 698 | status = HAL_ERROR; |
mbed_official | 237:f3da66175598 | 699 | } |
mbed_official | 237:f3da66175598 | 700 | } |
mbed_official | 237:f3da66175598 | 701 | return status; |
mbed_official | 237:f3da66175598 | 702 | } |
mbed_official | 237:f3da66175598 | 703 | |
mbed_official | 237:f3da66175598 | 704 | /** |
mbed_official | 237:f3da66175598 | 705 | * @} |
mbed_official | 237:f3da66175598 | 706 | */ |
mbed_official | 237:f3da66175598 | 707 | |
mbed_official | 237:f3da66175598 | 708 | /** @defgroup HAL_OPAMP_Group3 Peripheral Control functions |
mbed_official | 237:f3da66175598 | 709 | * @brief management functions |
mbed_official | 237:f3da66175598 | 710 | * |
mbed_official | 237:f3da66175598 | 711 | @verbatim |
mbed_official | 237:f3da66175598 | 712 | =============================================================================== |
mbed_official | 237:f3da66175598 | 713 | ##### Peripheral Control functions ##### |
mbed_official | 237:f3da66175598 | 714 | =============================================================================== |
mbed_official | 237:f3da66175598 | 715 | [..] |
mbed_official | 237:f3da66175598 | 716 | This subsection provides a set of functions allowing to control the OPAMP data |
mbed_official | 237:f3da66175598 | 717 | transfers. |
mbed_official | 237:f3da66175598 | 718 | |
mbed_official | 237:f3da66175598 | 719 | |
mbed_official | 237:f3da66175598 | 720 | |
mbed_official | 237:f3da66175598 | 721 | @endverbatim |
mbed_official | 237:f3da66175598 | 722 | * @{ |
mbed_official | 237:f3da66175598 | 723 | */ |
mbed_official | 237:f3da66175598 | 724 | |
mbed_official | 237:f3da66175598 | 725 | /** |
mbed_official | 237:f3da66175598 | 726 | * @brief Lock the selected opamp configuration. |
mbed_official | 237:f3da66175598 | 727 | * @param hopamp: OPAMP handle |
mbed_official | 237:f3da66175598 | 728 | * @retval HAL status |
mbed_official | 237:f3da66175598 | 729 | */ |
mbed_official | 237:f3da66175598 | 730 | HAL_StatusTypeDef HAL_OPAMP_Lock(OPAMP_HandleTypeDef *hopamp) |
mbed_official | 237:f3da66175598 | 731 | { |
mbed_official | 237:f3da66175598 | 732 | HAL_StatusTypeDef status = HAL_OK; |
mbed_official | 237:f3da66175598 | 733 | |
mbed_official | 237:f3da66175598 | 734 | /* Check the OPAMP handle allocation */ |
mbed_official | 237:f3da66175598 | 735 | /* Check if OPAMP locked */ |
mbed_official | 237:f3da66175598 | 736 | /* OPAMP can be locked when enabled and running in normal mode */ |
mbed_official | 237:f3da66175598 | 737 | /* It is meaningless otherwise */ |
mbed_official | 237:f3da66175598 | 738 | if((hopamp == NULL) || (hopamp->State == HAL_OPAMP_STATE_RESET) \ |
mbed_official | 237:f3da66175598 | 739 | || (hopamp->State == HAL_OPAMP_STATE_READY) \ |
mbed_official | 237:f3da66175598 | 740 | || (hopamp->State == HAL_OPAMP_STATE_CALIBBUSY)\ |
mbed_official | 237:f3da66175598 | 741 | || (hopamp->State == HAL_OPAMP_STATE_BUSYLOCKED)) |
mbed_official | 237:f3da66175598 | 742 | |
mbed_official | 237:f3da66175598 | 743 | { |
mbed_official | 237:f3da66175598 | 744 | status = HAL_ERROR; |
mbed_official | 237:f3da66175598 | 745 | } |
mbed_official | 237:f3da66175598 | 746 | |
mbed_official | 237:f3da66175598 | 747 | else |
mbed_official | 237:f3da66175598 | 748 | { |
mbed_official | 237:f3da66175598 | 749 | /* Check the parameter */ |
mbed_official | 237:f3da66175598 | 750 | assert_param(IS_OPAMP_ALL_INSTANCE(hopamp->Instance)); |
mbed_official | 237:f3da66175598 | 751 | |
mbed_official | 237:f3da66175598 | 752 | /* Lock OPAMP */ |
mbed_official | 237:f3da66175598 | 753 | SET_BIT (hopamp->Instance->CSR, OPAMP_CSR_LOCK); |
mbed_official | 237:f3da66175598 | 754 | |
mbed_official | 237:f3da66175598 | 755 | /* OPAMP state changed to locked */ |
mbed_official | 237:f3da66175598 | 756 | hopamp->State = HAL_OPAMP_STATE_BUSYLOCKED; |
mbed_official | 237:f3da66175598 | 757 | } |
mbed_official | 237:f3da66175598 | 758 | return status; |
mbed_official | 237:f3da66175598 | 759 | } |
mbed_official | 237:f3da66175598 | 760 | |
mbed_official | 237:f3da66175598 | 761 | /** |
mbed_official | 237:f3da66175598 | 762 | * @} |
mbed_official | 237:f3da66175598 | 763 | */ |
mbed_official | 237:f3da66175598 | 764 | |
mbed_official | 237:f3da66175598 | 765 | /** @defgroup HAL_OPAMP_Group4 Peripheral State functions |
mbed_official | 237:f3da66175598 | 766 | * @brief Peripheral State functions |
mbed_official | 237:f3da66175598 | 767 | * |
mbed_official | 237:f3da66175598 | 768 | @verbatim |
mbed_official | 237:f3da66175598 | 769 | =============================================================================== |
mbed_official | 237:f3da66175598 | 770 | ##### Peripheral State functions ##### |
mbed_official | 237:f3da66175598 | 771 | =============================================================================== |
mbed_official | 237:f3da66175598 | 772 | [..] |
mbed_official | 237:f3da66175598 | 773 | This subsection permit to get in run-time the status of the peripheral |
mbed_official | 237:f3da66175598 | 774 | and the data flow. |
mbed_official | 237:f3da66175598 | 775 | |
mbed_official | 237:f3da66175598 | 776 | @endverbatim |
mbed_official | 237:f3da66175598 | 777 | * @{ |
mbed_official | 237:f3da66175598 | 778 | */ |
mbed_official | 237:f3da66175598 | 779 | |
mbed_official | 237:f3da66175598 | 780 | /** |
mbed_official | 237:f3da66175598 | 781 | * @brief Return the OPAMP state |
mbed_official | 237:f3da66175598 | 782 | * @param hopamp : OPAMP handle |
mbed_official | 237:f3da66175598 | 783 | * @retval HAL state |
mbed_official | 237:f3da66175598 | 784 | */ |
mbed_official | 237:f3da66175598 | 785 | HAL_OPAMP_StateTypeDef HAL_OPAMP_GetState(OPAMP_HandleTypeDef *hopamp) |
mbed_official | 237:f3da66175598 | 786 | { |
mbed_official | 237:f3da66175598 | 787 | /* Check the OPAMP handle allocation */ |
mbed_official | 237:f3da66175598 | 788 | if(hopamp == NULL) |
mbed_official | 237:f3da66175598 | 789 | { |
mbed_official | 237:f3da66175598 | 790 | return HAL_OPAMP_STATE_RESET; |
mbed_official | 237:f3da66175598 | 791 | } |
mbed_official | 237:f3da66175598 | 792 | |
mbed_official | 237:f3da66175598 | 793 | /* Check the parameter */ |
mbed_official | 237:f3da66175598 | 794 | assert_param(IS_OPAMP_ALL_INSTANCE(hopamp->Instance)); |
mbed_official | 237:f3da66175598 | 795 | |
mbed_official | 237:f3da66175598 | 796 | return hopamp->State; |
mbed_official | 237:f3da66175598 | 797 | } |
mbed_official | 237:f3da66175598 | 798 | |
mbed_official | 237:f3da66175598 | 799 | /** |
mbed_official | 237:f3da66175598 | 800 | * @} |
mbed_official | 237:f3da66175598 | 801 | */ |
mbed_official | 237:f3da66175598 | 802 | |
mbed_official | 237:f3da66175598 | 803 | /** |
mbed_official | 237:f3da66175598 | 804 | * @brief Return the OPAMP factory trimming value |
mbed_official | 237:f3da66175598 | 805 | * @param hopamp : OPAMP handle |
mbed_official | 237:f3da66175598 | 806 | * @param trimmingoffset : Trimming offset (P or N) |
mbed_official | 237:f3da66175598 | 807 | * @retval Trimming value (P or N): range: 0->31 |
mbed_official | 237:f3da66175598 | 808 | * or OPAMP_FACTORYTRIMMING_DUMMY if trimming value is not available |
mbed_official | 237:f3da66175598 | 809 | */ |
mbed_official | 237:f3da66175598 | 810 | |
mbed_official | 237:f3da66175598 | 811 | OPAMP_TrimmingValueTypeDef HAL_OPAMP_GetTrimOffset (OPAMP_HandleTypeDef *hopamp, uint32_t trimmingoffset) |
mbed_official | 237:f3da66175598 | 812 | { |
mbed_official | 237:f3da66175598 | 813 | uint32_t oldusertrimming = 0; |
mbed_official | 237:f3da66175598 | 814 | OPAMP_TrimmingValueTypeDef oldtrimmingvaluep = 0, oldtrimmingvaluen = 0, trimmingvalue = 0; |
mbed_official | 237:f3da66175598 | 815 | |
mbed_official | 237:f3da66175598 | 816 | /* Check the OPAMP handle allocation */ |
mbed_official | 237:f3da66175598 | 817 | /* Value can be retrieved in HAL_OPAMP_STATE_READY state */ |
mbed_official | 237:f3da66175598 | 818 | if((hopamp == NULL) || (hopamp->State == HAL_OPAMP_STATE_RESET) \ |
mbed_official | 237:f3da66175598 | 819 | || (hopamp->State == HAL_OPAMP_STATE_BUSY) \ |
mbed_official | 237:f3da66175598 | 820 | || (hopamp->State == HAL_OPAMP_STATE_CALIBBUSY)\ |
mbed_official | 237:f3da66175598 | 821 | || (hopamp->State == HAL_OPAMP_STATE_BUSYLOCKED)) |
mbed_official | 237:f3da66175598 | 822 | { |
mbed_official | 237:f3da66175598 | 823 | return OPAMP_FACTORYTRIMMING_DUMMY; |
mbed_official | 237:f3da66175598 | 824 | } |
mbed_official | 237:f3da66175598 | 825 | else |
mbed_official | 237:f3da66175598 | 826 | { |
mbed_official | 237:f3da66175598 | 827 | /* Check the parameter */ |
mbed_official | 237:f3da66175598 | 828 | assert_param(IS_OPAMP_ALL_INSTANCE(hopamp->Instance)); |
mbed_official | 237:f3da66175598 | 829 | assert_param(IS_OPAMP_FACTORYTRIMMING(trimmingoffset)); |
mbed_official | 237:f3da66175598 | 830 | |
mbed_official | 237:f3da66175598 | 831 | /* Check the trimming mode */ |
mbed_official | 237:f3da66175598 | 832 | if ((READ_BIT(hopamp->Instance->CSR,OPAMP_CSR_USERTRIM)) != RESET) |
mbed_official | 237:f3da66175598 | 833 | { |
mbed_official | 237:f3da66175598 | 834 | /* User trimming is used */ |
mbed_official | 237:f3da66175598 | 835 | oldusertrimming = OPAMP_TRIMMING_USER; |
mbed_official | 237:f3da66175598 | 836 | /* Store the TrimmingValueP & TrimmingValueN */ |
mbed_official | 237:f3da66175598 | 837 | oldtrimmingvaluep = (hopamp->Instance->CSR & OPAMP_CSR_TRIMOFFSETP) >> OPAMP_INPUT_NONINVERTING; |
mbed_official | 237:f3da66175598 | 838 | oldtrimmingvaluen = (hopamp->Instance->CSR & OPAMP_CSR_TRIMOFFSETN) >> OPAMP_INPUT_INVERTING; |
mbed_official | 237:f3da66175598 | 839 | } |
mbed_official | 237:f3da66175598 | 840 | |
mbed_official | 237:f3da66175598 | 841 | /* Set factory timming mode */ |
mbed_official | 237:f3da66175598 | 842 | CLEAR_BIT (hopamp->Instance->CSR, OPAMP_CSR_USERTRIM); |
mbed_official | 237:f3da66175598 | 843 | |
mbed_official | 237:f3da66175598 | 844 | /* Get factory trimming */ |
mbed_official | 237:f3da66175598 | 845 | if (trimmingoffset == OPAMP_FACTORYTRIMMING_P) |
mbed_official | 237:f3da66175598 | 846 | { |
mbed_official | 237:f3da66175598 | 847 | /* Return TrimOffsetP */ |
mbed_official | 237:f3da66175598 | 848 | trimmingvalue = ((hopamp->Instance->CSR & OPAMP_CSR_TRIMOFFSETP) >> OPAMP_INPUT_NONINVERTING); |
mbed_official | 237:f3da66175598 | 849 | } |
mbed_official | 237:f3da66175598 | 850 | else |
mbed_official | 237:f3da66175598 | 851 | { |
mbed_official | 237:f3da66175598 | 852 | /* Return TrimOffsetN */ |
mbed_official | 237:f3da66175598 | 853 | trimmingvalue = ((hopamp->Instance->CSR & OPAMP_CSR_TRIMOFFSETN) >> OPAMP_INPUT_INVERTING); |
mbed_official | 237:f3da66175598 | 854 | } |
mbed_official | 237:f3da66175598 | 855 | |
mbed_official | 237:f3da66175598 | 856 | /* Restore user trimming configuration if it was formerly set */ |
mbed_official | 237:f3da66175598 | 857 | /* Check if user trimming was used */ |
mbed_official | 237:f3da66175598 | 858 | if (oldusertrimming == OPAMP_TRIMMING_USER) |
mbed_official | 237:f3da66175598 | 859 | { |
mbed_official | 237:f3da66175598 | 860 | /* Restore user trimming */ |
mbed_official | 237:f3da66175598 | 861 | SET_BIT(hopamp->Instance->CSR,OPAMP_CSR_USERTRIM); |
mbed_official | 237:f3da66175598 | 862 | MODIFY_REG(hopamp->Instance->CSR, OPAMP_CSR_TRIMOFFSETP, oldtrimmingvaluep<<OPAMP_INPUT_NONINVERTING); |
mbed_official | 237:f3da66175598 | 863 | MODIFY_REG(hopamp->Instance->CSR, OPAMP_CSR_TRIMOFFSETN, oldtrimmingvaluen<<OPAMP_INPUT_INVERTING); |
mbed_official | 237:f3da66175598 | 864 | } |
mbed_official | 237:f3da66175598 | 865 | } |
mbed_official | 237:f3da66175598 | 866 | return trimmingvalue; |
mbed_official | 237:f3da66175598 | 867 | } |
mbed_official | 237:f3da66175598 | 868 | /** |
mbed_official | 237:f3da66175598 | 869 | * @} |
mbed_official | 237:f3da66175598 | 870 | */ |
mbed_official | 237:f3da66175598 | 871 | |
mbed_official | 237:f3da66175598 | 872 | /** |
mbed_official | 237:f3da66175598 | 873 | * @} |
mbed_official | 237:f3da66175598 | 874 | */ |
mbed_official | 237:f3da66175598 | 875 | |
mbed_official | 237:f3da66175598 | 876 | #endif /* STM32F303xC STM32F358xx STM32F302xC STM32F303x8 STM32F328xx |
mbed_official | 237:f3da66175598 | 877 | STM32F302x8 STM32F301x8 STM32F318xx STM32F334x8 */ |
mbed_official | 237:f3da66175598 | 878 | |
mbed_official | 237:f3da66175598 | 879 | #endif /* HAL_OPAMP_MODULE_ENABLED */ |
mbed_official | 237:f3da66175598 | 880 | /** |
mbed_official | 237:f3da66175598 | 881 | * @} |
mbed_official | 237:f3da66175598 | 882 | */ |
mbed_official | 237:f3da66175598 | 883 | |
mbed_official | 237:f3da66175598 | 884 | /** |
mbed_official | 237:f3da66175598 | 885 | * @} |
mbed_official | 237:f3da66175598 | 886 | */ |
mbed_official | 237:f3da66175598 | 887 | |
mbed_official | 237:f3da66175598 | 888 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |