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